bump product version to 5.0.4.1
[LibreOffice.git] / vcl / unx / gtk / a11y / atkselection.cxx
blob7e7f3fddebec865231332ce7caa1bbe3b1202a8b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "atkwrapper.hxx"
22 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
24 #include <stdio.h>
26 using namespace ::com::sun::star;
28 static accessibility::XAccessibleSelection*
29 getSelection( AtkSelection *pSelection ) throw (uno::RuntimeException)
31 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pSelection );
32 if( pWrap )
34 if( !pWrap->mpSelection && pWrap->mpContext )
36 uno::Any any = pWrap->mpContext->queryInterface( cppu::UnoType<accessibility::XAccessibleSelection>::get() );
37 pWrap->mpSelection = static_cast< accessibility::XAccessibleSelection * > (any.pReserved);
38 pWrap->mpSelection->acquire();
41 return pWrap->mpSelection;
44 return NULL;
47 extern "C" {
49 static gboolean
50 selection_add_selection( AtkSelection *selection,
51 gint i )
53 try {
54 accessibility::XAccessibleSelection* pSelection = getSelection( selection );
55 if( pSelection )
57 pSelection->selectAccessibleChild( i );
58 return TRUE;
61 catch(const uno::Exception&) {
62 g_warning( "Exception in selectAccessibleChild()" );
65 return FALSE;
68 static gboolean
69 selection_clear_selection( AtkSelection *selection )
71 try {
72 accessibility::XAccessibleSelection* pSelection = getSelection( selection );
73 if( pSelection )
75 pSelection->clearAccessibleSelection();
76 return TRUE;
79 catch(const uno::Exception&) {
80 g_warning( "Exception in selectAccessibleChild()" );
83 return FALSE;
86 static AtkObject*
87 selection_ref_selection( AtkSelection *selection,
88 gint i )
90 try {
91 accessibility::XAccessibleSelection* pSelection = getSelection( selection );
92 if( pSelection )
93 return atk_object_wrapper_ref( pSelection->getSelectedAccessibleChild( i ) );
95 catch(const uno::Exception&) {
96 g_warning( "Exception in getSelectedAccessibleChild()" );
99 return NULL;
102 static gint
103 selection_get_selection_count( AtkSelection *selection)
105 try {
106 accessibility::XAccessibleSelection* pSelection = getSelection( selection );
107 if( pSelection )
108 return pSelection->getSelectedAccessibleChildCount();
110 catch(const uno::Exception&) {
111 g_warning( "Exception in getSelectedAccessibleChildCount()" );
114 return -1;
117 static gboolean
118 selection_is_child_selected( AtkSelection *selection,
119 gint i)
121 try {
122 accessibility::XAccessibleSelection* pSelection = getSelection( selection );
123 if( pSelection )
124 return pSelection->isAccessibleChildSelected( i );
126 catch(const uno::Exception&) {
127 g_warning( "Exception in getSelectedAccessibleChildCount()" );
130 return FALSE;
133 static gboolean
134 selection_remove_selection( AtkSelection *selection,
135 gint i )
137 try {
138 accessibility::XAccessibleSelection* pSelection = getSelection( selection );
139 if( pSelection )
141 pSelection->deselectAccessibleChild( i );
142 return TRUE;
145 catch(const uno::Exception&) {
146 g_warning( "Exception in getSelectedAccessibleChildCount()" );
149 return FALSE;
152 static gboolean
153 selection_select_all_selection( AtkSelection *selection)
155 try {
156 accessibility::XAccessibleSelection* pSelection = getSelection( selection );
157 if( pSelection )
159 pSelection->selectAllAccessibleChildren();
160 return TRUE;
163 catch(const uno::Exception&) {
164 g_warning( "Exception in getSelectedAccessibleChildCount()" );
167 return FALSE;
170 } // extern "C"
172 void
173 selectionIfaceInit( AtkSelectionIface *iface)
175 g_return_if_fail (iface != NULL);
177 iface->add_selection = selection_add_selection;
178 iface->clear_selection = selection_clear_selection;
179 iface->ref_selection = selection_ref_selection;
180 iface->get_selection_count = selection_get_selection_count;
181 iface->is_child_selected = selection_is_child_selected;
182 iface->remove_selection = selection_remove_selection;
183 iface->select_all_selection = selection_select_all_selection;
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */