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