1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=2 et sw=2 tw=80: */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Sun Microsystems, Inc.
20 : * Portions created by the Initial Developer are Copyright (C) 2002
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Silvia Zhao (silvia.zhao@sun.com)
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "nsMaiInterfaceSelection.h"
41 :
42 : void
43 0 : selectionInterfaceInitCB(AtkSelectionIface *aIface)
44 : {
45 0 : NS_ASSERTION(aIface, "Invalid aIface");
46 0 : if (!aIface)
47 0 : return;
48 :
49 0 : aIface->add_selection = addSelectionCB;
50 0 : aIface->clear_selection = clearSelectionCB;
51 0 : aIface->ref_selection = refSelectionCB;
52 0 : aIface->get_selection_count = getSelectionCountCB;
53 0 : aIface->is_child_selected = isChildSelectedCB;
54 0 : aIface->remove_selection = removeSelectionCB;
55 0 : aIface->select_all_selection = selectAllSelectionCB;
56 : }
57 :
58 : gboolean
59 0 : addSelectionCB(AtkSelection *aSelection, gint i)
60 : {
61 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
62 0 : if (!accWrap || !accWrap->IsSelect())
63 0 : return FALSE;
64 :
65 0 : return accWrap->AddItemToSelection(i);
66 : }
67 :
68 : gboolean
69 0 : clearSelectionCB(AtkSelection *aSelection)
70 : {
71 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
72 0 : if (!accWrap || !accWrap->IsSelect())
73 0 : return FALSE;
74 :
75 0 : return accWrap->UnselectAll();
76 : }
77 :
78 : AtkObject *
79 0 : refSelectionCB(AtkSelection *aSelection, gint i)
80 : {
81 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
82 0 : if (!accWrap || !accWrap->IsSelect())
83 0 : return nsnull;
84 :
85 0 : nsAccessible* selectedItem = accWrap->GetSelectedItem(i);
86 0 : if (!selectedItem)
87 0 : return nsnull;
88 :
89 0 : AtkObject* atkObj = nsAccessibleWrap::GetAtkObject(selectedItem);
90 0 : if (atkObj) {
91 0 : g_object_ref(atkObj);
92 : }
93 0 : return atkObj;
94 : }
95 :
96 : gint
97 0 : getSelectionCountCB(AtkSelection *aSelection)
98 : {
99 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
100 0 : if (!accWrap || !accWrap->IsSelect())
101 0 : return -1;
102 :
103 0 : return accWrap->SelectedItemCount();
104 : }
105 :
106 : gboolean
107 0 : isChildSelectedCB(AtkSelection *aSelection, gint i)
108 : {
109 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
110 0 : if (!accWrap || !accWrap->IsSelect())
111 0 : return FALSE;
112 :
113 0 : return accWrap->IsItemSelected(i);
114 : }
115 :
116 : gboolean
117 0 : removeSelectionCB(AtkSelection *aSelection, gint i)
118 : {
119 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
120 0 : if (!accWrap || !accWrap->IsSelect())
121 0 : return FALSE;
122 :
123 0 : return accWrap->RemoveItemFromSelection(i);
124 : }
125 :
126 : gboolean
127 0 : selectAllSelectionCB(AtkSelection *aSelection)
128 : {
129 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
130 0 : if (!accWrap || !accWrap->IsSelect())
131 0 : return FALSE;
132 :
133 0 : return accWrap->SelectAll();
134 : }
|