Back to index

lightning-sunbird  0.9+nobinonly
nsMaiInterfaceSelection.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* vim:expandtab:shiftwidth=4:tabstop=4:
00003  */
00004 /* ***** BEGIN LICENSE BLOCK *****
00005  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  *
00008  * The contents of this file are subject to the Mozilla Public
00009  * License Version 1.1 (the "License"); you may not use this file
00010  * except in compliance with the License. You may obtain a copy of
00011  * the License at http://www.mozilla.org/MPL/
00012  *
00013  * Software distributed under the License is distributed on an "AS
00014  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
00015  * implied. See the License for the specific language governing
00016  * rights and limitations under the License.
00017  *
00018  * The Original Code is mozilla.org code.
00019  *
00020  * The Initial Developer of the Original Code is Sun Microsystems, Inc.
00021  * Portions created by Sun Microsystems are Copyright (C) 2002 Sun
00022  * Microsystems, Inc. All Rights Reserved.
00023  *
00024  * Original Author: Silvia Zhao (silvia.zhao@sun.com)
00025  *
00026  * Contributor(s): 
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either the GNU General Public License Version 2 or later (the "GPL"), or
00030  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the NPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the NPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 #include "nsMaiInterfaceSelection.h"
00043 
00044 G_BEGIN_DECLS
00045 
00046 /* selection interface callbacks */
00047 
00048 static void interfaceInitCB(AtkSelectionIface *aIface);
00049 static gboolean addSelectionCB(AtkSelection *aSelection,
00050                                gint i);
00051 static gboolean clearSelectionCB(AtkSelection *aSelection);
00052 static AtkObject *refSelectionCB(AtkSelection *aSelection,
00053                                  gint i);
00054 static gint getSelectionCountCB(AtkSelection *aSelection);
00055 static gboolean isChildSelectedCB(AtkSelection *aSelection,
00056                                   gint i);
00057 static gboolean removeSelectionCB(AtkSelection *aSelection,
00058                                   gint i);
00059 static gboolean selectAllSelectionCB(AtkSelection *aSelection);
00060 
00061 G_END_DECLS
00062 
00063 MaiInterfaceSelection::MaiInterfaceSelection(nsAccessibleWrap* aAccWrap):
00064     MaiInterface(aAccWrap)
00065 {
00066 }
00067 
00068 MaiInterfaceSelection::~MaiInterfaceSelection()
00069 {
00070 }
00071 
00072 MaiInterfaceType
00073 MaiInterfaceSelection::GetType()
00074 {
00075     return MAI_INTERFACE_SELECTION;
00076 }
00077 
00078 const GInterfaceInfo *
00079 MaiInterfaceSelection::GetInterfaceInfo()
00080 {
00081     static const GInterfaceInfo atk_if_selection_info = {
00082         (GInterfaceInitFunc) interfaceInitCB,
00083         (GInterfaceFinalizeFunc) NULL,
00084         NULL
00085     };
00086     return &atk_if_selection_info;
00087 }
00088 
00089 /* static functions */
00090 
00091 void
00092 interfaceInitCB(AtkSelectionIface *aIface)
00093 {
00094     NS_ASSERTION(aIface, "Invalid aIface");
00095     if (!aIface)
00096         return;
00097 
00098     aIface->add_selection = addSelectionCB;
00099     aIface->clear_selection = clearSelectionCB;
00100     aIface->ref_selection = refSelectionCB;
00101     aIface->get_selection_count = getSelectionCountCB;
00102     aIface->is_child_selected = isChildSelectedCB;
00103     aIface->remove_selection = removeSelectionCB;
00104     aIface->select_all_selection = selectAllSelectionCB;
00105 }
00106 
00107 gboolean
00108 addSelectionCB(AtkSelection *aSelection, gint i)
00109 {
00110     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
00111     NS_ENSURE_TRUE(accWrap, FALSE);
00112 
00113     nsCOMPtr<nsIAccessibleSelectable> accSelection;
00114     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
00115                             getter_AddRefs(accSelection));
00116     NS_ENSURE_TRUE(accSelection, FALSE);
00117 
00118     return NS_SUCCEEDED(accSelection->AddChildToSelection(i));
00119 }
00120 
00121 gboolean
00122 clearSelectionCB(AtkSelection *aSelection)
00123 {
00124     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
00125     NS_ENSURE_TRUE(accWrap, FALSE);
00126 
00127     nsCOMPtr<nsIAccessibleSelectable> accSelection;
00128     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
00129                             getter_AddRefs(accSelection));
00130     NS_ENSURE_TRUE(accSelection, FALSE);
00131 
00132     return NS_SUCCEEDED(accSelection->ClearSelection());
00133 }
00134 
00135 AtkObject *
00136 refSelectionCB(AtkSelection *aSelection, gint i)
00137 {
00138     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
00139     NS_ENSURE_TRUE(accWrap, nsnull);
00140 
00141     nsCOMPtr<nsIAccessibleSelectable> accSelection;
00142     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
00143                             getter_AddRefs(accSelection));
00144     NS_ENSURE_TRUE(accSelection, nsnull);
00145 
00146     AtkObject *atkObj = nsnull;
00147     nsCOMPtr<nsIAccessible> accSelect;
00148     nsresult rv = accSelection->RefSelection(i, getter_AddRefs(accSelect));
00149     if (NS_SUCCEEDED(rv) && accSelect) {
00150         nsIAccessible *tmpAcc = accSelect;
00151         nsAccessibleWrap *refAccWrap =
00152             NS_STATIC_CAST(nsAccessibleWrap *, tmpAcc);
00153         atkObj = refAccWrap->GetAtkObject();
00154         if (atkObj)
00155             g_object_ref(atkObj);
00156     }
00157     return atkObj;
00158 }
00159 
00160 gint
00161 getSelectionCountCB(AtkSelection *aSelection)
00162 {
00163     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
00164     NS_ENSURE_TRUE(accWrap, -1);
00165 
00166     nsCOMPtr<nsIAccessibleSelectable> accSelection;
00167     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
00168                             getter_AddRefs(accSelection));
00169     NS_ENSURE_TRUE(accSelection, -1);
00170 
00171     PRInt32 num = 0;
00172     nsresult rv = accSelection->GetSelectionCount(&num);
00173     return (NS_FAILED(rv)) ? -1 : num;
00174 }
00175 
00176 gboolean
00177 isChildSelectedCB(AtkSelection *aSelection, gint i)
00178 {
00179     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
00180     NS_ENSURE_TRUE(accWrap, FALSE);
00181 
00182     nsCOMPtr<nsIAccessibleSelectable> accSelection;
00183     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
00184                             getter_AddRefs(accSelection));
00185     NS_ENSURE_TRUE(accSelection, FALSE);
00186 
00187     PRBool result = FALSE;
00188     nsresult rv = accSelection->IsChildSelected(i, &result);
00189     return (NS_FAILED(rv)) ? FALSE : result;
00190 }
00191 
00192 gboolean
00193 removeSelectionCB(AtkSelection *aSelection, gint i)
00194 {
00195     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
00196     NS_ENSURE_TRUE(accWrap, FALSE);
00197 
00198     nsCOMPtr<nsIAccessibleSelectable> accSelection;
00199     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
00200                             getter_AddRefs(accSelection));
00201     NS_ENSURE_TRUE(accSelection, FALSE);
00202 
00203     nsresult rv = accSelection->RemoveChildFromSelection(i);
00204     return (NS_FAILED(rv)) ? FALSE : TRUE;
00205 }
00206 
00207 gboolean
00208 selectAllSelectionCB(AtkSelection *aSelection)
00209 {
00210     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
00211     NS_ENSURE_TRUE(accWrap, FALSE);
00212 
00213     nsCOMPtr<nsIAccessibleSelectable> accSelection;
00214     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
00215                             getter_AddRefs(accSelection));
00216     NS_ENSURE_TRUE(accSelection, FALSE);
00217 
00218     PRBool result = FALSE;
00219     nsresult rv = accSelection->SelectAllSelection(&result);
00220     return (NS_FAILED(rv)) ? FALSE : result;
00221 }