xref: /aoo42x/main/vcl/unx/gtk/a11y/atkselection.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 
31 #include "atkwrapper.hxx"
32 
33 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
34 
35 #include <stdio.h>
36 
37 using namespace ::com::sun::star;
38 
39 static accessibility::XAccessibleSelection*
40     getSelection( AtkSelection *pSelection ) throw (uno::RuntimeException)
41 {
42     AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pSelection );
43     if( pWrap )
44     {
45         if( !pWrap->mpSelection && pWrap->mpContext )
46         {
47             uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleSelection::static_type(NULL) );
48             pWrap->mpSelection = reinterpret_cast< accessibility::XAccessibleSelection * > (any.pReserved);
49             pWrap->mpSelection->acquire();
50         }
51 
52         return pWrap->mpSelection;
53     }
54 
55     return NULL;
56 }
57 
58 extern "C" {
59 
60 static gboolean
61 selection_add_selection( AtkSelection *selection,
62                          gint          i )
63 {
64     try {
65         accessibility::XAccessibleSelection* pSelection = getSelection( selection );
66         if( pSelection )
67         {
68             pSelection->selectAccessibleChild( i );
69             return TRUE;
70         }
71     }
72     catch(const uno::Exception& e) {
73         g_warning( "Exception in selectAccessibleChild()" );
74     }
75 
76     return FALSE;
77 }
78 
79 static gboolean
80 selection_clear_selection( AtkSelection *selection )
81 {
82     try {
83         accessibility::XAccessibleSelection* pSelection = getSelection( selection );
84         if( pSelection )
85         {
86             pSelection->clearAccessibleSelection();
87             return TRUE;
88         }
89     }
90     catch(const uno::Exception& e) {
91         g_warning( "Exception in selectAccessibleChild()" );
92     }
93 
94     return FALSE;
95 }
96 
97 static AtkObject*
98 selection_ref_selection( AtkSelection *selection,
99                          gint          i )
100 {
101     try {
102         accessibility::XAccessibleSelection* pSelection = getSelection( selection );
103         if( pSelection )
104             return atk_object_wrapper_ref( pSelection->getSelectedAccessibleChild( i ) );
105     }
106     catch(const uno::Exception& e) {
107         g_warning( "Exception in getSelectedAccessibleChild()" );
108     }
109 
110     return NULL;
111 }
112 
113 static gint
114 selection_get_selection_count( AtkSelection   *selection)
115 {
116     try {
117         accessibility::XAccessibleSelection* pSelection = getSelection( selection );
118         if( pSelection )
119             return pSelection->getSelectedAccessibleChildCount();
120     }
121     catch(const uno::Exception& e) {
122         g_warning( "Exception in getSelectedAccessibleChildCount()" );
123     }
124 
125     return -1;
126 }
127 
128 static gboolean
129 selection_is_child_selected( AtkSelection   *selection,
130                               gint           i)
131 {
132     try {
133         accessibility::XAccessibleSelection* pSelection = getSelection( selection );
134         if( pSelection )
135             return pSelection->isAccessibleChildSelected( i );
136     }
137     catch(const uno::Exception& e) {
138         g_warning( "Exception in getSelectedAccessibleChildCount()" );
139     }
140 
141     return FALSE;
142 }
143 
144 static gboolean
145 selection_remove_selection( AtkSelection *selection,
146                             gint           i )
147 {
148     try {
149         accessibility::XAccessibleSelection* pSelection = getSelection( selection );
150         if( pSelection )
151         {
152             pSelection->deselectAccessibleChild( i );
153             return TRUE;
154         }
155     }
156     catch(const uno::Exception& e) {
157         g_warning( "Exception in getSelectedAccessibleChildCount()" );
158     }
159 
160     return FALSE;
161 }
162 
163 static gboolean
164 selection_select_all_selection( AtkSelection   *selection)
165 {
166     try {
167         accessibility::XAccessibleSelection* pSelection = getSelection( selection );
168         if( pSelection )
169         {
170             pSelection->selectAllAccessibleChildren();
171             return TRUE;
172         }
173     }
174     catch(const uno::Exception& e) {
175         g_warning( "Exception in getSelectedAccessibleChildCount()" );
176     }
177 
178     return FALSE;
179 }
180 
181 } // extern "C"
182 
183 void
184 selectionIfaceInit( AtkSelectionIface *iface)
185 {
186   g_return_if_fail (iface != NULL);
187 
188   iface->add_selection = selection_add_selection;
189   iface->clear_selection = selection_clear_selection;
190   iface->ref_selection = selection_ref_selection;
191   iface->get_selection_count = selection_get_selection_count;
192   iface->is_child_selected = selection_is_child_selected;
193   iface->remove_selection = selection_remove_selection;
194   iface->select_all_selection = selection_select_all_selection;
195 }
196