/src/libreoffice/vcl/source/accessibility/accessiblemenubasecomponent.cxx
Line | Count | Source (jump to first uncovered line) |
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/accessiblemenubasecomponent.hxx> |
21 | | #include <accessibility/vclxaccessiblemenu.hxx> |
22 | | #include <accessibility/vclxaccessiblemenuitem.hxx> |
23 | | #include <accessibility/vclxaccessiblemenuseparator.hxx> |
24 | | |
25 | | #include <com/sun/star/accessibility/AccessibleEventId.hpp> |
26 | | #include <com/sun/star/accessibility/AccessibleRole.hpp> |
27 | | #include <com/sun/star/accessibility/AccessibleStateType.hpp> |
28 | | #include <comphelper/accessiblecontexthelper.hxx> |
29 | | #include <cppuhelper/supportsservice.hxx> |
30 | | #include <o3tl/safeint.hxx> |
31 | | #include <vcl/menu.hxx> |
32 | | #include <vcl/unohelp.hxx> |
33 | | #include <vcl/vclevent.hxx> |
34 | | |
35 | | #include <array> |
36 | | |
37 | | using namespace ::com::sun::star; |
38 | | using namespace ::com::sun::star::lang; |
39 | | using namespace ::com::sun::star::uno; |
40 | | using namespace ::com::sun::star::accessibility; |
41 | | using namespace ::comphelper; |
42 | | |
43 | | |
44 | | // OAccessibleMenuBaseComponent |
45 | | |
46 | | |
47 | | OAccessibleMenuBaseComponent::OAccessibleMenuBaseComponent( Menu* pMenu ) |
48 | 0 | :m_pMenu( pMenu ) |
49 | 0 | ,m_bEnabled( false ) |
50 | 0 | ,m_bFocused( false ) |
51 | 0 | ,m_bVisible( false ) |
52 | 0 | ,m_bSelected( false ) |
53 | 0 | ,m_bChecked( false ) |
54 | 0 | { |
55 | 0 | if ( m_pMenu ) |
56 | 0 | { |
57 | 0 | m_aAccessibleChildren.assign( m_pMenu->GetItemCount(), rtl::Reference< OAccessibleMenuItemComponent >() ); |
58 | 0 | m_pMenu->AddEventListener( LINK( this, OAccessibleMenuBaseComponent, MenuEventListener ) ); |
59 | 0 | } |
60 | 0 | } |
61 | | |
62 | | |
63 | | OAccessibleMenuBaseComponent::~OAccessibleMenuBaseComponent() |
64 | 0 | { |
65 | 0 | if ( m_pMenu ) |
66 | 0 | m_pMenu->RemoveEventListener( LINK( this, OAccessibleMenuBaseComponent, MenuEventListener ) ); |
67 | 0 | } |
68 | | |
69 | | |
70 | | bool OAccessibleMenuBaseComponent::IsEnabled() |
71 | 0 | { |
72 | 0 | return false; |
73 | 0 | } |
74 | | |
75 | | |
76 | | bool OAccessibleMenuBaseComponent::IsFocused() |
77 | 0 | { |
78 | 0 | return false; |
79 | 0 | } |
80 | | |
81 | | |
82 | | bool OAccessibleMenuBaseComponent::IsVisible() |
83 | 0 | { |
84 | 0 | return false; |
85 | 0 | } |
86 | | |
87 | | |
88 | | bool OAccessibleMenuBaseComponent::IsSelected() |
89 | 0 | { |
90 | 0 | return false; |
91 | 0 | } |
92 | | |
93 | | |
94 | | bool OAccessibleMenuBaseComponent::IsChecked() |
95 | 0 | { |
96 | 0 | return false; |
97 | 0 | } |
98 | | |
99 | | |
100 | | void OAccessibleMenuBaseComponent::SetStates() |
101 | 0 | { |
102 | 0 | m_bEnabled = IsEnabled(); |
103 | 0 | m_bFocused = IsFocused(); |
104 | 0 | m_bVisible = IsVisible(); |
105 | 0 | m_bSelected = IsSelected(); |
106 | 0 | m_bChecked = IsChecked(); |
107 | 0 | } |
108 | | |
109 | | |
110 | | void OAccessibleMenuBaseComponent::SetEnabled( bool bEnabled ) |
111 | 0 | { |
112 | 0 | if ( m_bEnabled == bEnabled ) |
113 | 0 | return; |
114 | | |
115 | 0 | sal_Int64 nStateType=AccessibleStateType::ENABLED; |
116 | 0 | if (IsMenuHideDisabledEntries()) |
117 | 0 | { |
118 | 0 | nStateType = AccessibleStateType::VISIBLE; |
119 | 0 | } |
120 | 0 | std::array<Any, 2> aOldValue, aNewValue; |
121 | 0 | if ( m_bEnabled ) |
122 | 0 | { |
123 | 0 | aOldValue[0] <<= AccessibleStateType::SENSITIVE; |
124 | 0 | aOldValue[1] <<= nStateType; |
125 | 0 | } |
126 | 0 | else |
127 | 0 | { |
128 | 0 | aNewValue[0] <<= nStateType; |
129 | 0 | aNewValue[1] <<= AccessibleStateType::SENSITIVE; |
130 | 0 | } |
131 | 0 | m_bEnabled = bEnabled; |
132 | 0 | NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[0], aNewValue[0] ); |
133 | 0 | NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[1], aNewValue[1] ); |
134 | 0 | } |
135 | | |
136 | | |
137 | | void OAccessibleMenuBaseComponent::SetFocused( bool bFocused ) |
138 | 0 | { |
139 | 0 | if ( m_bFocused != bFocused ) |
140 | 0 | { |
141 | 0 | Any aOldValue, aNewValue; |
142 | 0 | if ( m_bFocused ) |
143 | 0 | aOldValue <<= AccessibleStateType::FOCUSED; |
144 | 0 | else |
145 | 0 | aNewValue <<= AccessibleStateType::FOCUSED; |
146 | 0 | m_bFocused = bFocused; |
147 | 0 | NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); |
148 | 0 | } |
149 | 0 | } |
150 | | |
151 | | |
152 | | void OAccessibleMenuBaseComponent::SetVisible( bool bVisible ) |
153 | 0 | { |
154 | 0 | if ( m_bVisible != bVisible ) |
155 | 0 | { |
156 | 0 | Any aOldValue, aNewValue; |
157 | 0 | if ( m_bVisible ) |
158 | 0 | aOldValue <<= AccessibleStateType::VISIBLE; |
159 | 0 | else |
160 | 0 | aNewValue <<= AccessibleStateType::VISIBLE; |
161 | 0 | m_bVisible = bVisible; |
162 | 0 | NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); |
163 | 0 | } |
164 | 0 | } |
165 | | |
166 | | |
167 | | void OAccessibleMenuBaseComponent::SetSelected( bool bSelected ) |
168 | 0 | { |
169 | 0 | if ( m_bSelected != bSelected ) |
170 | 0 | { |
171 | 0 | Any aOldValue, aNewValue; |
172 | 0 | if ( m_bSelected ) |
173 | 0 | aOldValue <<= AccessibleStateType::SELECTED; |
174 | 0 | else |
175 | 0 | aNewValue <<= AccessibleStateType::SELECTED; |
176 | 0 | m_bSelected = bSelected; |
177 | 0 | NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); |
178 | 0 | } |
179 | 0 | } |
180 | | |
181 | | |
182 | | void OAccessibleMenuBaseComponent::SetChecked( bool bChecked ) |
183 | 0 | { |
184 | 0 | if ( m_bChecked != bChecked ) |
185 | 0 | { |
186 | 0 | Any aOldValue, aNewValue; |
187 | 0 | if ( m_bChecked ) |
188 | 0 | aOldValue <<= AccessibleStateType::CHECKED; |
189 | 0 | else |
190 | 0 | aNewValue <<= AccessibleStateType::CHECKED; |
191 | 0 | m_bChecked = bChecked; |
192 | 0 | NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); |
193 | 0 | } |
194 | 0 | } |
195 | | |
196 | | |
197 | | void OAccessibleMenuBaseComponent::UpdateEnabled( sal_Int32 i, bool bEnabled ) |
198 | 0 | { |
199 | 0 | if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() ) |
200 | 0 | { |
201 | 0 | rtl::Reference< OAccessibleMenuBaseComponent > xChild( m_aAccessibleChildren[i] ); |
202 | 0 | if ( xChild.is() ) |
203 | 0 | xChild->SetEnabled( bEnabled ); |
204 | 0 | } |
205 | 0 | } |
206 | | |
207 | | |
208 | | void OAccessibleMenuBaseComponent::UpdateFocused( sal_Int32 i, bool bFocused ) |
209 | 0 | { |
210 | 0 | if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() ) |
211 | 0 | { |
212 | 0 | rtl::Reference< OAccessibleMenuBaseComponent > xChild( m_aAccessibleChildren[i] ); |
213 | 0 | if ( xChild.is() ) |
214 | 0 | xChild->SetFocused( bFocused ); |
215 | 0 | } |
216 | 0 | } |
217 | | |
218 | | |
219 | | void OAccessibleMenuBaseComponent::UpdateVisible() |
220 | 0 | { |
221 | 0 | SetVisible( IsVisible() ); |
222 | 0 | for (const rtl::Reference<OAccessibleMenuItemComponent>& xChild : m_aAccessibleChildren) |
223 | 0 | { |
224 | 0 | if ( xChild.is() ) |
225 | 0 | xChild->SetVisible( xChild->IsVisible() ); |
226 | 0 | } |
227 | 0 | } |
228 | | |
229 | | |
230 | | void OAccessibleMenuBaseComponent::UpdateSelected( sal_Int32 i, bool bSelected ) |
231 | 0 | { |
232 | 0 | NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() ); |
233 | |
|
234 | 0 | if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() ) |
235 | 0 | { |
236 | 0 | rtl::Reference< OAccessibleMenuBaseComponent > xChild( m_aAccessibleChildren[i] ); |
237 | 0 | if ( xChild.is() ) |
238 | 0 | xChild->SetSelected( bSelected ); |
239 | 0 | } |
240 | 0 | } |
241 | | |
242 | | |
243 | | void OAccessibleMenuBaseComponent::UpdateChecked( sal_Int32 i, bool bChecked ) |
244 | 0 | { |
245 | 0 | if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() ) |
246 | 0 | { |
247 | 0 | rtl::Reference< OAccessibleMenuBaseComponent > xChild( m_aAccessibleChildren[i] ); |
248 | 0 | if ( xChild.is() ) |
249 | 0 | xChild->SetChecked( bChecked ); |
250 | 0 | } |
251 | 0 | } |
252 | | |
253 | | |
254 | | void OAccessibleMenuBaseComponent::UpdateAccessibleName( sal_Int32 i ) |
255 | 0 | { |
256 | 0 | if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() ) |
257 | 0 | { |
258 | 0 | rtl::Reference< OAccessibleMenuBaseComponent > xChild( m_aAccessibleChildren[i] ); |
259 | 0 | if ( xChild.is() ) |
260 | 0 | { |
261 | 0 | OAccessibleMenuItemComponent* pComp = static_cast< OAccessibleMenuItemComponent* >( xChild.get() ); |
262 | 0 | if ( pComp ) |
263 | 0 | pComp->SetAccessibleName( pComp->GetAccessibleName() ); |
264 | 0 | } |
265 | 0 | } |
266 | 0 | } |
267 | | |
268 | | void OAccessibleMenuBaseComponent::UpdateItemRole(sal_Int32 i) |
269 | 0 | { |
270 | 0 | if (i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size()) |
271 | 0 | return; |
272 | | |
273 | 0 | rtl::Reference<OAccessibleMenuItemComponent> xChild(m_aAccessibleChildren[i]); |
274 | 0 | if (!xChild.is()) |
275 | 0 | return; |
276 | | |
277 | 0 | xChild->NotifyAccessibleEvent(AccessibleEventId::ROLE_CHANGED, Any(), Any()); |
278 | 0 | } |
279 | | |
280 | | void OAccessibleMenuBaseComponent::UpdateItemText( sal_Int32 i ) |
281 | 0 | { |
282 | 0 | if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() ) |
283 | 0 | { |
284 | 0 | rtl::Reference< OAccessibleMenuItemComponent > xChild( m_aAccessibleChildren[i] ); |
285 | 0 | if ( xChild.is() ) |
286 | 0 | xChild->SetItemText( xChild->GetItemText() ); |
287 | 0 | } |
288 | 0 | } |
289 | | |
290 | | |
291 | | sal_Int64 OAccessibleMenuBaseComponent::GetChildCount() const |
292 | 0 | { |
293 | 0 | return m_aAccessibleChildren.size(); |
294 | 0 | } |
295 | | |
296 | | |
297 | | Reference< XAccessible > OAccessibleMenuBaseComponent::GetChild( sal_Int64 i ) |
298 | 0 | { |
299 | 0 | rtl::Reference< OAccessibleMenuItemComponent > xChild = m_aAccessibleChildren[i]; |
300 | 0 | if ( !xChild.is() ) |
301 | 0 | { |
302 | 0 | if ( m_pMenu ) |
303 | 0 | { |
304 | | // create a new child |
305 | 0 | if ( m_pMenu->GetItemType( static_cast<sal_uInt16>(i) ) == MenuItemType::SEPARATOR ) |
306 | 0 | { |
307 | 0 | xChild = new VCLXAccessibleMenuSeparator(m_pMenu, static_cast<sal_uInt16>(i)); |
308 | 0 | } |
309 | 0 | else |
310 | 0 | { |
311 | 0 | PopupMenu* pPopupMenu = m_pMenu->GetPopupMenu( m_pMenu->GetItemId( static_cast<sal_uInt16>(i) ) ); |
312 | 0 | if ( pPopupMenu ) |
313 | 0 | { |
314 | 0 | xChild = new VCLXAccessibleMenu(m_pMenu, static_cast<sal_uInt16>(i), pPopupMenu); |
315 | 0 | pPopupMenu->SetAccessible(xChild); |
316 | 0 | } |
317 | 0 | else |
318 | 0 | { |
319 | 0 | xChild = new VCLXAccessibleMenuItem(m_pMenu, static_cast<sal_uInt16>(i)); |
320 | 0 | } |
321 | 0 | } |
322 | | |
323 | | // set states |
324 | 0 | xChild->SetStates(); |
325 | | |
326 | | // insert into menu item list |
327 | 0 | m_aAccessibleChildren[i] = xChild; |
328 | 0 | } |
329 | 0 | } |
330 | |
|
331 | 0 | return xChild; |
332 | 0 | } |
333 | | |
334 | | |
335 | | Reference< XAccessible > OAccessibleMenuBaseComponent::GetChildAt( const awt::Point& rPoint ) |
336 | 0 | { |
337 | 0 | for ( sal_Int64 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i ) |
338 | 0 | { |
339 | 0 | Reference< XAccessible > xAcc = getAccessibleChild( i ); |
340 | 0 | if ( xAcc.is() ) |
341 | 0 | { |
342 | 0 | Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY ); |
343 | 0 | if ( xComp.is() ) |
344 | 0 | { |
345 | 0 | tools::Rectangle aRect = vcl::unohelper::ConvertToVCLRect(xComp->getBounds()); |
346 | 0 | Point aPos = vcl::unohelper::ConvertToVCLPoint(rPoint); |
347 | 0 | if ( aRect.Contains( aPos ) ) |
348 | 0 | { |
349 | 0 | return xAcc; |
350 | 0 | } |
351 | 0 | } |
352 | 0 | } |
353 | 0 | } |
354 | | |
355 | 0 | return nullptr; |
356 | 0 | } |
357 | | |
358 | | |
359 | | void OAccessibleMenuBaseComponent::InsertChild( sal_Int32 i ) |
360 | 0 | { |
361 | 0 | if ( i < 0 ) |
362 | 0 | return; |
363 | | |
364 | 0 | if ( o3tl::make_unsigned(i) > m_aAccessibleChildren.size() ) |
365 | 0 | i = m_aAccessibleChildren.size(); |
366 | | |
367 | | // insert entry in child list |
368 | 0 | m_aAccessibleChildren.insert( m_aAccessibleChildren.begin() + i, rtl::Reference< OAccessibleMenuItemComponent >() ); |
369 | | |
370 | | // update item position of accessible children |
371 | 0 | for ( sal_uInt32 j = i, nCount = m_aAccessibleChildren.size(); j < nCount; ++j ) |
372 | 0 | { |
373 | 0 | rtl::Reference< OAccessibleMenuItemComponent > xAcc( m_aAccessibleChildren[j] ); |
374 | 0 | if ( xAcc.is() ) |
375 | 0 | xAcc->SetItemPos( static_cast<sal_uInt16>(j) ); |
376 | 0 | } |
377 | | |
378 | | // send accessible child event |
379 | 0 | Reference< XAccessible > xChild( GetChild( i ) ); |
380 | 0 | if ( xChild.is() ) |
381 | 0 | { |
382 | 0 | Any aOldValue, aNewValue; |
383 | 0 | aNewValue <<= xChild; |
384 | 0 | NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue ); |
385 | 0 | } |
386 | 0 | } |
387 | | |
388 | | |
389 | | void OAccessibleMenuBaseComponent::RemoveChild( sal_Int32 i ) |
390 | 0 | { |
391 | 0 | if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() ) |
392 | 0 | return; |
393 | | |
394 | | // keep the accessible of the removed item |
395 | 0 | rtl::Reference< OAccessibleMenuItemComponent > xChild( m_aAccessibleChildren[i] ); |
396 | | |
397 | | // remove entry in child list |
398 | 0 | m_aAccessibleChildren.erase( m_aAccessibleChildren.begin() + i ); |
399 | | |
400 | | // update item position of accessible children |
401 | 0 | for ( sal_uInt32 j = i, nCount = m_aAccessibleChildren.size(); j < nCount; ++j ) |
402 | 0 | { |
403 | 0 | rtl::Reference< OAccessibleMenuItemComponent > xAcc( m_aAccessibleChildren[j] ); |
404 | 0 | if ( xAcc.is() ) |
405 | 0 | xAcc->SetItemPos( static_cast<sal_uInt16>(j) ); |
406 | 0 | } |
407 | | |
408 | | // send accessible child event |
409 | 0 | if ( xChild.is() ) |
410 | 0 | { |
411 | 0 | Any aOldValue, aNewValue; |
412 | 0 | aOldValue <<= uno::Reference<XAccessible>(xChild); |
413 | 0 | NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue ); |
414 | |
|
415 | 0 | xChild->dispose(); |
416 | 0 | } |
417 | 0 | } |
418 | | |
419 | | |
420 | | bool OAccessibleMenuBaseComponent::IsHighlighted() |
421 | 0 | { |
422 | 0 | return false; |
423 | 0 | } |
424 | | |
425 | | |
426 | | bool OAccessibleMenuBaseComponent::IsChildHighlighted() |
427 | 0 | { |
428 | 0 | bool bChildHighlighted = false; |
429 | |
|
430 | 0 | for (const rtl::Reference<OAccessibleMenuItemComponent>& xChild : m_aAccessibleChildren) |
431 | 0 | { |
432 | 0 | if ( xChild.is() && xChild->IsHighlighted() ) |
433 | 0 | { |
434 | 0 | bChildHighlighted = true; |
435 | 0 | break; |
436 | 0 | } |
437 | 0 | } |
438 | |
|
439 | 0 | return bChildHighlighted; |
440 | 0 | } |
441 | | |
442 | | |
443 | | void OAccessibleMenuBaseComponent::SelectChild( sal_Int32 i ) |
444 | 0 | { |
445 | | // open the menu |
446 | 0 | if ( getAccessibleRole() == AccessibleRole::MENU && !IsPopupMenuOpen() ) |
447 | 0 | Click(); |
448 | | |
449 | | // highlight the child |
450 | 0 | if ( m_pMenu ) |
451 | 0 | m_pMenu->HighlightItem( static_cast<sal_uInt16>(i) ); |
452 | 0 | } |
453 | | |
454 | | |
455 | | void OAccessibleMenuBaseComponent::DeSelectAll() |
456 | 0 | { |
457 | 0 | if ( m_pMenu ) |
458 | 0 | m_pMenu->DeHighlight(); |
459 | 0 | } |
460 | | |
461 | | |
462 | | bool OAccessibleMenuBaseComponent::IsChildSelected( sal_Int32 i ) |
463 | 0 | { |
464 | 0 | bool bSelected = false; |
465 | |
|
466 | 0 | if ( m_pMenu && m_pMenu->IsHighlighted( static_cast<sal_uInt16>(i) ) ) |
467 | 0 | bSelected = true; |
468 | |
|
469 | 0 | return bSelected; |
470 | 0 | } |
471 | | |
472 | | |
473 | | void OAccessibleMenuBaseComponent::Click() |
474 | 0 | { |
475 | 0 | } |
476 | | |
477 | | |
478 | | bool OAccessibleMenuBaseComponent::IsPopupMenuOpen() |
479 | 0 | { |
480 | 0 | return false; |
481 | 0 | } |
482 | | |
483 | | |
484 | | IMPL_LINK( OAccessibleMenuBaseComponent, MenuEventListener, VclMenuEvent&, rEvent, void ) |
485 | 0 | { |
486 | 0 | OSL_ENSURE( rEvent.GetMenu(), "OAccessibleMenuBaseComponent - Menu?" ); |
487 | 0 | ProcessMenuEvent( rEvent ); |
488 | 0 | } |
489 | | |
490 | | |
491 | | void OAccessibleMenuBaseComponent::ProcessMenuEvent( const VclMenuEvent& rVclMenuEvent ) |
492 | 0 | { |
493 | 0 | sal_uInt16 nItemPos = rVclMenuEvent.GetItemPos(); |
494 | |
|
495 | 0 | switch ( rVclMenuEvent.GetId() ) |
496 | 0 | { |
497 | 0 | case VclEventId::MenuShow: |
498 | 0 | case VclEventId::MenuHide: |
499 | 0 | { |
500 | 0 | UpdateVisible(); |
501 | 0 | } |
502 | 0 | break; |
503 | 0 | case VclEventId::MenuHighlight: |
504 | 0 | { |
505 | 0 | SetFocused( false ); |
506 | 0 | UpdateFocused( nItemPos, true ); |
507 | 0 | UpdateSelected( nItemPos, true ); |
508 | 0 | } |
509 | 0 | break; |
510 | 0 | case VclEventId::MenuDehighlight: |
511 | 0 | { |
512 | 0 | UpdateFocused( nItemPos, false ); |
513 | 0 | UpdateSelected( nItemPos, false ); |
514 | 0 | } |
515 | 0 | break; |
516 | 0 | case VclEventId::MenuSubmenuActivate: |
517 | 0 | { |
518 | 0 | } |
519 | 0 | break; |
520 | 0 | case VclEventId::MenuSubmenuDeactivate: |
521 | 0 | { |
522 | 0 | UpdateFocused( nItemPos, true ); |
523 | 0 | } |
524 | 0 | break; |
525 | 0 | case VclEventId::MenuEnable: |
526 | 0 | { |
527 | 0 | UpdateEnabled( nItemPos, true ); |
528 | 0 | } |
529 | 0 | break; |
530 | 0 | case VclEventId::MenuDisable: |
531 | 0 | { |
532 | 0 | UpdateEnabled( nItemPos, false ); |
533 | 0 | } |
534 | 0 | break; |
535 | 0 | case VclEventId::MenuSubmenuChanged: |
536 | 0 | { |
537 | 0 | RemoveChild( nItemPos ); |
538 | 0 | InsertChild( nItemPos ); |
539 | 0 | } |
540 | 0 | break; |
541 | 0 | case VclEventId::MenuInsertItem: |
542 | 0 | { |
543 | 0 | InsertChild( nItemPos ); |
544 | 0 | } |
545 | 0 | break; |
546 | 0 | case VclEventId::MenuRemoveItem: |
547 | 0 | { |
548 | 0 | RemoveChild( nItemPos ); |
549 | 0 | } |
550 | 0 | break; |
551 | 0 | case VclEventId::MenuAccessibleNameChanged: |
552 | 0 | { |
553 | 0 | UpdateAccessibleName( nItemPos ); |
554 | 0 | } |
555 | 0 | break; |
556 | 0 | case VclEventId::MenuItemRoleChanged: |
557 | 0 | { |
558 | 0 | UpdateItemRole(nItemPos); |
559 | 0 | } |
560 | 0 | break; |
561 | 0 | case VclEventId::MenuItemTextChanged: |
562 | 0 | { |
563 | 0 | UpdateAccessibleName( nItemPos ); |
564 | 0 | UpdateItemText( nItemPos ); |
565 | 0 | } |
566 | 0 | break; |
567 | 0 | case VclEventId::MenuItemChecked: |
568 | 0 | { |
569 | 0 | UpdateChecked( nItemPos, true ); |
570 | 0 | } |
571 | 0 | break; |
572 | 0 | case VclEventId::MenuItemUnchecked: |
573 | 0 | { |
574 | 0 | UpdateChecked( nItemPos, false ); |
575 | 0 | } |
576 | 0 | break; |
577 | 0 | case VclEventId::ObjectDying: |
578 | 0 | { |
579 | 0 | if ( m_pMenu ) |
580 | 0 | { |
581 | 0 | m_pMenu->RemoveEventListener( LINK( this, OAccessibleMenuBaseComponent, MenuEventListener ) ); |
582 | |
|
583 | 0 | m_pMenu = nullptr; |
584 | | |
585 | | // dispose all menu items |
586 | 0 | for (const rtl::Reference<OAccessibleMenuItemComponent>& xComponent : m_aAccessibleChildren) |
587 | 0 | { |
588 | 0 | if ( xComponent.is() ) |
589 | 0 | xComponent->dispose(); |
590 | 0 | } |
591 | 0 | m_aAccessibleChildren.clear(); |
592 | 0 | } |
593 | 0 | } |
594 | 0 | break; |
595 | 0 | default: |
596 | 0 | { |
597 | 0 | } |
598 | 0 | break; |
599 | 0 | } |
600 | 0 | } |
601 | | |
602 | | |
603 | | // XComponent |
604 | | |
605 | | |
606 | | void OAccessibleMenuBaseComponent::disposing() |
607 | 0 | { |
608 | 0 | OAccessible::disposing(); |
609 | |
|
610 | 0 | if ( !m_pMenu ) |
611 | 0 | return; |
612 | | |
613 | 0 | m_pMenu->RemoveEventListener( LINK( this, OAccessibleMenuBaseComponent, MenuEventListener ) ); |
614 | |
|
615 | 0 | m_pMenu = nullptr; |
616 | | |
617 | | // dispose all menu items |
618 | 0 | for (const rtl::Reference<OAccessibleMenuItemComponent>& xComponent : m_aAccessibleChildren) |
619 | 0 | { |
620 | 0 | if ( xComponent.is() ) |
621 | 0 | xComponent->dispose(); |
622 | 0 | } |
623 | 0 | m_aAccessibleChildren.clear(); |
624 | 0 | } |
625 | | |
626 | | |
627 | | // XServiceInfo |
628 | | |
629 | | |
630 | | sal_Bool OAccessibleMenuBaseComponent::supportsService( const OUString& rServiceName ) |
631 | 0 | { |
632 | 0 | return cppu::supportsService(this, rServiceName); |
633 | 0 | } |
634 | | |
635 | | // XAccessibleContext |
636 | | |
637 | | |
638 | | sal_Int64 OAccessibleMenuBaseComponent::getAccessibleStateSet( ) |
639 | 0 | { |
640 | 0 | OExternalLockGuard aGuard( this ); |
641 | |
|
642 | 0 | sal_Int64 nStateSet = 0; |
643 | |
|
644 | 0 | if ( !rBHelper.bDisposed && !rBHelper.bInDispose ) |
645 | 0 | { |
646 | 0 | FillAccessibleStateSet( nStateSet ); |
647 | 0 | } |
648 | 0 | else |
649 | 0 | { |
650 | 0 | nStateSet |= AccessibleStateType::DEFUNC; |
651 | 0 | } |
652 | |
|
653 | 0 | return nStateSet; |
654 | 0 | } |
655 | | |
656 | | |
657 | | bool OAccessibleMenuBaseComponent::IsMenuHideDisabledEntries() |
658 | 0 | { |
659 | 0 | return false; |
660 | 0 | } |
661 | | |
662 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |