/src/libreoffice/vcl/source/accessibility/vclxaccessiblemenu.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <accessibility/vclxaccessiblemenu.hxx> |
21 | | |
22 | | #include <com/sun/star/accessibility/AccessibleRole.hpp> |
23 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
24 | | #include <comphelper/accessiblecontexthelper.hxx> |
25 | | #include <vcl/menu.hxx> |
26 | | |
27 | | |
28 | | using namespace ::com::sun::star; |
29 | | using namespace ::com::sun::star::lang; |
30 | | using namespace ::com::sun::star::uno; |
31 | | using namespace ::com::sun::star::accessibility; |
32 | | using namespace ::comphelper; |
33 | | |
34 | | |
35 | | // VCLXAccessibleMenu |
36 | | |
37 | | |
38 | | bool VCLXAccessibleMenu::IsFocused() |
39 | 0 | { |
40 | 0 | bool bFocused = false; |
41 | |
|
42 | 0 | if ( IsHighlighted() && !IsChildHighlighted() ) |
43 | 0 | bFocused = true; |
44 | |
|
45 | 0 | return bFocused; |
46 | 0 | } |
47 | | |
48 | | |
49 | | bool VCLXAccessibleMenu::IsPopupMenuOpen() |
50 | 0 | { |
51 | 0 | bool bPopupMenuOpen = false; |
52 | |
|
53 | 0 | if ( m_pParent ) |
54 | 0 | { |
55 | 0 | PopupMenu* pPopupMenu = m_pParent->GetPopupMenu( m_pParent->GetItemId( m_nItemPos ) ); |
56 | 0 | if ( pPopupMenu && pPopupMenu->IsMenuVisible() ) |
57 | 0 | bPopupMenuOpen = true; |
58 | 0 | } |
59 | |
|
60 | 0 | return bPopupMenuOpen; |
61 | 0 | } |
62 | | |
63 | | |
64 | | // XServiceInfo |
65 | | |
66 | | |
67 | | OUString VCLXAccessibleMenu::getImplementationName() |
68 | 0 | { |
69 | 0 | return u"com.sun.star.comp.toolkit.AccessibleMenu"_ustr; |
70 | 0 | } |
71 | | |
72 | | |
73 | | Sequence< OUString > VCLXAccessibleMenu::getSupportedServiceNames() |
74 | 0 | { |
75 | 0 | return { u"com.sun.star.awt.AccessibleMenu"_ustr }; |
76 | 0 | } |
77 | | |
78 | | |
79 | | // XAccessibleContext |
80 | | |
81 | | |
82 | | sal_Int64 VCLXAccessibleMenu::getAccessibleChildCount( ) |
83 | 0 | { |
84 | 0 | OExternalLockGuard aGuard( this ); |
85 | |
|
86 | 0 | return GetChildCount(); |
87 | 0 | } |
88 | | |
89 | | |
90 | | Reference< XAccessible > VCLXAccessibleMenu::getAccessibleChild( sal_Int64 i ) |
91 | 0 | { |
92 | 0 | OExternalLockGuard aGuard( this ); |
93 | |
|
94 | 0 | if ( i < 0 || i >= GetChildCount() ) |
95 | 0 | throw IndexOutOfBoundsException(); |
96 | | |
97 | 0 | return GetChild( i ); |
98 | 0 | } |
99 | | |
100 | | |
101 | | sal_Int16 VCLXAccessibleMenu::getAccessibleRole( ) |
102 | 0 | { |
103 | 0 | OExternalLockGuard aGuard( this ); |
104 | |
|
105 | 0 | return AccessibleRole::MENU; |
106 | 0 | } |
107 | | |
108 | | |
109 | | // XAccessibleComponent |
110 | | |
111 | | |
112 | | Reference< XAccessible > VCLXAccessibleMenu::getAccessibleAtPoint( const awt::Point& rPoint ) |
113 | 0 | { |
114 | 0 | OExternalLockGuard aGuard( this ); |
115 | |
|
116 | 0 | return GetChildAt( rPoint ); |
117 | 0 | } |
118 | | |
119 | | |
120 | | // XAccessibleSelection |
121 | | |
122 | | |
123 | | void VCLXAccessibleMenu::selectAccessibleChild( sal_Int64 nChildIndex ) |
124 | 0 | { |
125 | 0 | OExternalLockGuard aGuard( this ); |
126 | |
|
127 | 0 | if ( nChildIndex < 0 || nChildIndex >= GetChildCount() ) |
128 | 0 | throw IndexOutOfBoundsException(); |
129 | | |
130 | 0 | SelectChild( nChildIndex ); |
131 | 0 | } |
132 | | |
133 | | |
134 | | sal_Bool VCLXAccessibleMenu::isAccessibleChildSelected( sal_Int64 nChildIndex ) |
135 | 0 | { |
136 | 0 | OExternalLockGuard aGuard( this ); |
137 | |
|
138 | 0 | if ( nChildIndex < 0 || nChildIndex >= GetChildCount() ) |
139 | 0 | throw IndexOutOfBoundsException(); |
140 | | |
141 | 0 | return IsChildSelected( nChildIndex ); |
142 | 0 | } |
143 | | |
144 | | |
145 | | void VCLXAccessibleMenu::clearAccessibleSelection( ) |
146 | 0 | { |
147 | 0 | OExternalLockGuard aGuard( this ); |
148 | |
|
149 | 0 | DeSelectAll(); |
150 | 0 | } |
151 | | |
152 | | |
153 | | void VCLXAccessibleMenu::selectAllAccessibleChildren( ) |
154 | 0 | { |
155 | | // This method makes no sense in a menu, and so does nothing. |
156 | 0 | } |
157 | | |
158 | | |
159 | | sal_Int64 VCLXAccessibleMenu::getSelectedAccessibleChildCount( ) |
160 | 0 | { |
161 | 0 | OExternalLockGuard aGuard( this ); |
162 | |
|
163 | 0 | return implGetSelectedAccessibleChildCount(); |
164 | 0 | } |
165 | | |
166 | | sal_Int64 VCLXAccessibleMenu::implGetSelectedAccessibleChildCount( ) |
167 | 0 | { |
168 | 0 | sal_Int64 nRet = 0; |
169 | |
|
170 | 0 | for ( sal_Int64 i = 0, nCount = GetChildCount(); i < nCount; i++ ) |
171 | 0 | { |
172 | 0 | if ( IsChildSelected( i ) ) |
173 | 0 | ++nRet; |
174 | 0 | } |
175 | |
|
176 | 0 | return nRet; |
177 | 0 | } |
178 | | |
179 | | Reference< XAccessible > VCLXAccessibleMenu::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex ) |
180 | 0 | { |
181 | 0 | OExternalLockGuard aGuard( this ); |
182 | |
|
183 | 0 | if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() ) |
184 | 0 | throw IndexOutOfBoundsException(); |
185 | | |
186 | 0 | Reference< XAccessible > xChild; |
187 | |
|
188 | 0 | for ( sal_Int64 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ ) |
189 | 0 | { |
190 | 0 | if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) ) |
191 | 0 | { |
192 | 0 | xChild = GetChild( i ); |
193 | 0 | break; |
194 | 0 | } |
195 | 0 | } |
196 | |
|
197 | 0 | return xChild; |
198 | 0 | } |
199 | | |
200 | | |
201 | | void VCLXAccessibleMenu::deselectAccessibleChild( sal_Int64 nChildIndex ) |
202 | 0 | { |
203 | 0 | OExternalLockGuard aGuard( this ); |
204 | |
|
205 | 0 | if ( nChildIndex < 0 || nChildIndex >= GetChildCount() ) |
206 | 0 | throw IndexOutOfBoundsException(); |
207 | | |
208 | 0 | DeSelectAll(); |
209 | 0 | } |
210 | | |
211 | | |
212 | | OUString VCLXAccessibleMenu::getAccessibleActionDescription ( sal_Int32 nIndex ) |
213 | 0 | { |
214 | 0 | OExternalLockGuard aGuard( this ); |
215 | |
|
216 | 0 | if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) |
217 | 0 | throw IndexOutOfBoundsException(); |
218 | | |
219 | 0 | return OUString( ); |
220 | 0 | } |
221 | | |
222 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |