Fix GNU C++ version check
[LibreOffice.git] / winaccessibility / source / service / AccObject.cxx
blobaafb82bd7fa9e65dc260ddd9cda089b6d58d169f
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 <com/sun/star/uno/Sequence.h>
21 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
22 #include <com/sun/star/accessibility/AccessibleRole.hpp>
23 #include <com/sun/star/accessibility/XAccessibleValue.hpp>
24 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
25 #include <com/sun/star/accessibility/XAccessibleText.hpp>
27 #include <o3tl/char16_t2wchar_t.hxx>
28 #include <o3tl/safeint.hxx>
29 #include <sal/log.hxx>
31 #include <stdlib.h>
32 #include <memory.h>
33 #include <stdio.h>
34 #include <algorithm>
35 #include <assert.h>
37 #include <AccObject.hxx>
38 #include <AccEventListener.hxx>
40 #if defined __clang__
41 #pragma clang diagnostic push
42 #pragma clang diagnostic ignored "-Wextra-tokens"
43 // "#endif !_MIDL_USE_GUIDDEF_" in midl-generated code
44 #endif
45 #include <UAccCOM_i.c>
46 #if defined __clang__
47 #pragma clang diagnostic pop
48 #endif
50 using namespace com::sun::star::uno;
51 using namespace com::sun::star::accessibility;
53 constexpr DWORD MSAA_NO_STATE = 0x00000000;
55 namespace {
57 /**
58 * Map a UNO accessible role to an IAccessible2 role.
59 * @param nUnoRole The UNO role (css::accessibility::AccessibleRole).
60 * @return IAccessible2 role.
62 short lcl_mapToIAccessible2Role(sal_Int16 nUnoRole)
64 switch(nUnoRole)
66 case css::accessibility::AccessibleRole::UNKNOWN:
67 return IA2_ROLE_UNKNOWN;
68 case css::accessibility::AccessibleRole::ALERT:
69 return ROLE_SYSTEM_DIALOG;
70 case css::accessibility::AccessibleRole::BLOCK_QUOTE:
71 return IA2_ROLE_BLOCK_QUOTE;
72 case css::accessibility::AccessibleRole::COLUMN_HEADER:
73 return ROLE_SYSTEM_COLUMNHEADER;
74 case css::accessibility::AccessibleRole::CANVAS:
75 return IA2_ROLE_CANVAS;
76 case css::accessibility::AccessibleRole::CHECK_BOX:
77 return ROLE_SYSTEM_CHECKBUTTON;
78 case css::accessibility::AccessibleRole::CHECK_MENU_ITEM:
79 return IA2_ROLE_CHECK_MENU_ITEM;
80 case css::accessibility::AccessibleRole::COLOR_CHOOSER:
81 return IA2_ROLE_COLOR_CHOOSER;
82 case css::accessibility::AccessibleRole::COMBO_BOX:
83 return ROLE_SYSTEM_COMBOBOX;
84 case css::accessibility::AccessibleRole::DATE_EDITOR:
85 return IA2_ROLE_DATE_EDITOR;
86 case css::accessibility::AccessibleRole::DESKTOP_ICON:
87 return IA2_ROLE_DESKTOP_ICON;
88 case css::accessibility::AccessibleRole::DESKTOP_PANE:
89 return IA2_ROLE_DESKTOP_PANE;
90 case css::accessibility::AccessibleRole::DIRECTORY_PANE:
91 return IA2_ROLE_DIRECTORY_PANE;
92 case css::accessibility::AccessibleRole::DIALOG:
93 return ROLE_SYSTEM_DIALOG;
94 case css::accessibility::AccessibleRole::DOCUMENT:
95 return ROLE_SYSTEM_DOCUMENT;
96 case css::accessibility::AccessibleRole::EMBEDDED_OBJECT:
97 return IA2_ROLE_EMBEDDED_OBJECT;
98 case css::accessibility::AccessibleRole::END_NOTE:
99 return IA2_ROLE_ENDNOTE;
100 case css::accessibility::AccessibleRole::FILE_CHOOSER:
101 return IA2_ROLE_FILE_CHOOSER;
102 case css::accessibility::AccessibleRole::FILLER:
103 return ROLE_SYSTEM_WHITESPACE;
104 case css::accessibility::AccessibleRole::FONT_CHOOSER:
105 return IA2_ROLE_FONT_CHOOSER;
106 case css::accessibility::AccessibleRole::FOOTER:
107 return IA2_ROLE_FOOTER;
108 case css::accessibility::AccessibleRole::FOOTNOTE:
109 return IA2_ROLE_FOOTNOTE;
110 case css::accessibility::AccessibleRole::FRAME:
111 return IA2_ROLE_FRAME;
112 case css::accessibility::AccessibleRole::GLASS_PANE:
113 return IA2_ROLE_GLASS_PANE;
114 case css::accessibility::AccessibleRole::GRAPHIC:
115 return ROLE_SYSTEM_GRAPHIC;
116 case css::accessibility::AccessibleRole::GROUP_BOX:
117 return ROLE_SYSTEM_GROUPING;
118 case css::accessibility::AccessibleRole::HEADER:
119 return IA2_ROLE_HEADER;
120 case css::accessibility::AccessibleRole::HEADING:
121 return IA2_ROLE_HEADING;
122 case css::accessibility::AccessibleRole::HYPER_LINK:
123 return ROLE_SYSTEM_TEXT;
124 case css::accessibility::AccessibleRole::ICON:
125 return IA2_ROLE_ICON;
126 case css::accessibility::AccessibleRole::INTERNAL_FRAME:
127 return IA2_ROLE_INTERNAL_FRAME;
128 case css::accessibility::AccessibleRole::LABEL:
129 return ROLE_SYSTEM_STATICTEXT;
130 case css::accessibility::AccessibleRole::LAYERED_PANE:
131 return IA2_ROLE_LAYERED_PANE;
132 case css::accessibility::AccessibleRole::LIST:
133 return ROLE_SYSTEM_LIST;
134 case css::accessibility::AccessibleRole::LIST_ITEM:
135 return ROLE_SYSTEM_LISTITEM;
136 case css::accessibility::AccessibleRole::MENU:
137 return ROLE_SYSTEM_MENUITEM;
138 case css::accessibility::AccessibleRole::MENU_BAR:
139 return ROLE_SYSTEM_MENUBAR;
140 case css::accessibility::AccessibleRole::MENU_ITEM:
141 return ROLE_SYSTEM_MENUITEM;
142 case css::accessibility::AccessibleRole::OPTION_PANE:
143 return IA2_ROLE_OPTION_PANE;
144 case css::accessibility::AccessibleRole::PAGE_TAB:
145 return ROLE_SYSTEM_PAGETAB;
146 case css::accessibility::AccessibleRole::PAGE_TAB_LIST:
147 return ROLE_SYSTEM_PAGETABLIST;
148 case css::accessibility::AccessibleRole::PANEL:
149 return IA2_ROLE_OPTION_PANE;
150 case css::accessibility::AccessibleRole::PARAGRAPH:
151 return IA2_ROLE_PARAGRAPH;
152 case css::accessibility::AccessibleRole::PASSWORD_TEXT:
153 return ROLE_SYSTEM_TEXT;
154 case css::accessibility::AccessibleRole::POPUP_MENU:
155 return ROLE_SYSTEM_MENUPOPUP;
156 case css::accessibility::AccessibleRole::PUSH_BUTTON:
157 return ROLE_SYSTEM_PUSHBUTTON;
158 case css::accessibility::AccessibleRole::PROGRESS_BAR:
159 return ROLE_SYSTEM_PROGRESSBAR;
160 case css::accessibility::AccessibleRole::RADIO_BUTTON:
161 return ROLE_SYSTEM_RADIOBUTTON;
162 case css::accessibility::AccessibleRole::RADIO_MENU_ITEM:
163 return IA2_ROLE_RADIO_MENU_ITEM;
164 case css::accessibility::AccessibleRole::ROW_HEADER:
165 return ROLE_SYSTEM_ROWHEADER;
166 case css::accessibility::AccessibleRole::ROOT_PANE:
167 return IA2_ROLE_ROOT_PANE;
168 case css::accessibility::AccessibleRole::SCROLL_BAR:
169 return ROLE_SYSTEM_SCROLLBAR;
170 case css::accessibility::AccessibleRole::SCROLL_PANE:
171 return IA2_ROLE_SCROLL_PANE;
172 case css::accessibility::AccessibleRole::SHAPE:
173 return IA2_ROLE_SHAPE;
174 case css::accessibility::AccessibleRole::SEPARATOR:
175 return ROLE_SYSTEM_SEPARATOR;
176 case css::accessibility::AccessibleRole::SLIDER:
177 return ROLE_SYSTEM_SLIDER;
178 case css::accessibility::AccessibleRole::SPIN_BOX:
179 return ROLE_SYSTEM_SPINBUTTON;
180 case css::accessibility::AccessibleRole::SPLIT_PANE:
181 return IA2_ROLE_SPLIT_PANE;
182 case css::accessibility::AccessibleRole::STATUS_BAR:
183 return ROLE_SYSTEM_STATUSBAR;
184 case css::accessibility::AccessibleRole::TABLE:
185 return ROLE_SYSTEM_TABLE;
186 case css::accessibility::AccessibleRole::TABLE_CELL:
187 return ROLE_SYSTEM_CELL;
188 case css::accessibility::AccessibleRole::TEXT:
189 return ROLE_SYSTEM_TEXT;
190 case css::accessibility::AccessibleRole::TEXT_FRAME:
191 return IA2_ROLE_TEXT_FRAME;
192 case css::accessibility::AccessibleRole::TOGGLE_BUTTON:
193 return ROLE_SYSTEM_PUSHBUTTON;
194 case css::accessibility::AccessibleRole::TOOL_BAR:
195 return ROLE_SYSTEM_TOOLBAR;
196 case css::accessibility::AccessibleRole::TOOL_TIP:
197 return ROLE_SYSTEM_TOOLTIP;
198 case css::accessibility::AccessibleRole::TREE:
199 return ROLE_SYSTEM_OUTLINE;
200 case css::accessibility::AccessibleRole::VIEW_PORT:
201 return IA2_ROLE_VIEW_PORT;
202 case css::accessibility::AccessibleRole::WINDOW:
203 return ROLE_SYSTEM_WINDOW;
204 case css::accessibility::AccessibleRole::BUTTON_DROPDOWN:
205 return ROLE_SYSTEM_BUTTONDROPDOWN;
206 case css::accessibility::AccessibleRole::BUTTON_MENU:
207 return ROLE_SYSTEM_BUTTONMENU;
208 case css::accessibility::AccessibleRole::CAPTION:
209 return IA2_ROLE_CAPTION;
210 case css::accessibility::AccessibleRole::CHART:
211 return IA2_ROLE_SHAPE;
212 case css::accessibility::AccessibleRole::EDIT_BAR:
213 return IA2_ROLE_EDITBAR;
214 case css::accessibility::AccessibleRole::FORM:
215 return IA2_ROLE_FORM;
216 case css::accessibility::AccessibleRole::IMAGE_MAP:
217 return IA2_ROLE_IMAGE_MAP;
218 case css::accessibility::AccessibleRole::NOTE:
219 return IA2_ROLE_NOTE;
220 case css::accessibility::AccessibleRole::PAGE:
221 return IA2_ROLE_PAGE;
222 case css::accessibility::AccessibleRole::RULER:
223 return IA2_ROLE_RULER;
224 case css::accessibility::AccessibleRole::SECTION:
225 return IA2_ROLE_SECTION;
226 case css::accessibility::AccessibleRole::TREE_ITEM:
227 return ROLE_SYSTEM_OUTLINEITEM;
228 case css::accessibility::AccessibleRole::TREE_TABLE:
229 return ROLE_SYSTEM_OUTLINE;
230 case css::accessibility::AccessibleRole::COMMENT:
231 return IA2_ROLE_TEXT_FRAME;
232 case css::accessibility::AccessibleRole::COMMENT_END:
233 return IA2_ROLE_TEXT_FRAME;
234 case css::accessibility::AccessibleRole::DOCUMENT_PRESENTATION:
235 return ROLE_SYSTEM_DOCUMENT;
236 case css::accessibility::AccessibleRole::DOCUMENT_SPREADSHEET:
237 return ROLE_SYSTEM_DOCUMENT;
238 case css::accessibility::AccessibleRole::DOCUMENT_TEXT:
239 return ROLE_SYSTEM_DOCUMENT;
240 case css::accessibility::AccessibleRole::STATIC:
241 return ROLE_SYSTEM_STATICTEXT;
242 case css::accessibility::AccessibleRole::NOTIFICATION:
243 return ROLE_SYSTEM_ALERT;
244 default:
245 SAL_WARN("iacc2", "Unmapped role: " << nUnoRole);
246 return IA2_ROLE_UNKNOWN;
253 * Constructor.
254 * @param pXAcc Uno XAccessible interface of control.
255 * @param pManager The accessible object manager kept in all listeners.
256 * @param listener listener that registers in UNO system.
257 * @return.
259 AccObject::AccObject(XAccessible* pAcc, AccObjectWinManager* pManager) :
260 m_resID (0),
261 m_pParantID (nullptr),
262 m_pIMAcc (UAccCOMCreateInstance()),
263 m_pParentObj(nullptr),
264 m_pListener (nullptr),
265 m_xAccRef( pAcc )
267 assert(m_pIMAcc);
269 m_xAccContextRef = m_xAccRef->getAccessibleContext();
270 m_accRole = m_xAccContextRef -> getAccessibleRole();
272 m_pIMAcc->SetXAccessible(reinterpret_cast<hyper>(m_xAccRef.get()));
273 m_pIMAcc->Put_XAccObjectManager(reinterpret_cast<hyper>(pManager));
276 * Destructor.
277 * @param
278 * @return
280 AccObject::~AccObject()
282 m_xAccRef = nullptr;
283 m_xAccContextRef = nullptr;
288 * Insert a child element.
289 * @param pChild Child element that should be inserted into child list.
290 * @return
292 void AccObject::InsertChild(AccObject* pChild)
294 std::vector<AccObject*>::iterator iter;
295 iter = std::find(m_childrenList.begin(),m_childrenList.end(),pChild);
296 if(iter!=m_childrenList.end())
297 return;
299 m_childrenList.push_back(pChild);
301 pChild->SetParentObj(this);
305 * Delete a child element
306 * @param pChild Child element that should be inserted into child list.
307 * @param pos Insert position.
308 * @return
310 void AccObject::DeleteChild( AccObject* pChild )
312 std::vector<AccObject*>::iterator iter;
313 iter = std::find(m_childrenList.begin(),m_childrenList.end(),pChild);
314 if(iter!=m_childrenList.end())
316 m_childrenList.erase(iter);
317 pChild->SetParentObj(nullptr);
322 * In order to windows API WindowFromAccessibleObject, we sometimes to set a pure
323 * top window accessible object created by windows system as top ancestor.
324 * @param.
325 * @return
327 void AccObject::UpdateValidWindow() { m_pIMAcc->Put_XAccWindowHandle(m_pParantID); }
330 * Update value property to com object.
331 * @param
332 * @return
334 void AccObject::UpdateValue()
336 if (!m_xAccContextRef.is())
338 assert(false);
339 return ;
342 Reference< XAccessibleValue > pRValue(m_xAccContextRef,UNO_QUERY);
343 Any pAny;
344 if( pRValue.is() )
346 pAny = pRValue->getCurrentValue();
349 SetValue( pAny );
353 * Set value property via pAny.
354 * @param pAny New value.
355 * @return
357 void AccObject::SetValue( Any pAny )
359 if (!m_xAccContextRef.is())
361 assert(false);
362 return ;
364 Reference< XAccessibleText > pRText(m_xAccContextRef,UNO_QUERY);
365 OUString val;
366 switch(m_accRole)
368 case AccessibleRole::SPIN_BOX:
369 // 3. date editor's msaa value should be the same as spinbox
370 case AccessibleRole::DATE_EDITOR:
371 case AccessibleRole::TEXT:
372 case AccessibleRole::BLOCK_QUOTE:
373 case AccessibleRole::PARAGRAPH:
374 case AccessibleRole::HEADING:
375 case AccessibleRole::TABLE_CELL:
377 if(pRText)
379 val = pRText->getText();
381 m_pIMAcc->Put_XAccValue( o3tl::toW(val.getStr()) );
382 break;
383 case AccessibleRole::TREE_ITEM:
384 //case CHECK_BOX: //Commented by Li Xing to disable the value for general checkbox
385 case AccessibleRole::COMBO_BOX:
386 case AccessibleRole::NOTE:
387 case AccessibleRole::SCROLL_BAR:
388 m_pIMAcc->Put_XAccValue( o3tl::toW(GetMAccessibleValueFromAny(pAny).getStr()) );
389 break ;
390 // Added by Li Xing, only the checkbox in tree should have the value.
391 case AccessibleRole::CHECK_BOX:
392 if( ( m_pParentObj !=nullptr ) && (AccessibleRole::TREE == m_pParentObj->m_accRole || AccessibleRole::TREE_ITEM == m_pParentObj->m_accRole ))
393 m_pIMAcc->Put_XAccValue( o3tl::toW(GetMAccessibleValueFromAny(pAny).getStr()) );
394 break;
395 default:
396 break;
399 return;
402 OUString AccObject::GetMAccessibleValueFromAny(Any pAny)
404 OUString strValue;
406 if(pAny.getValueType() == cppu::UnoType<cppu::UnoUnsignedShortType>::get() )
408 sal_uInt16 val;
409 if (pAny >>= val)
411 strValue=OUString::number(val);
415 else if(pAny.getValueType() == cppu::UnoType<OUString>::get())
418 pAny >>= strValue ;
421 else if(pAny.getValueType() == cppu::UnoType<Sequence< OUString >>::get())
423 Sequence< OUString > val;
424 if (pAny >>= val)
426 for (const OUString& rElem : val)
427 strValue += rElem;
430 else if(pAny.getValueType() == cppu::UnoType<double>::get())
432 double val;
433 if (pAny >>= val)
435 strValue=OUString::number(val);
438 else if(pAny.getValueType() == cppu::UnoType<sal_Int32>::get())
440 sal_Int32 val;
441 if (pAny >>= val)
443 strValue=OUString::number(val);
446 else if (pAny.getValueType() == cppu::UnoType<css::accessibility::TextSegment>::get())
448 css::accessibility::TextSegment val;
449 if (pAny >>= val)
451 OUString realVal(val.SegmentText);
452 strValue = realVal;
457 return strValue;
461 * Get role property via pAny
462 * @param
463 * @return accessible role
465 short AccObject::GetRole() const
467 return m_accRole;
471 * Get MSAA state from UNO state
472 * @Role nState UNO state.
473 * @return
475 DWORD AccObject::GetMSAAStateFromUNO(sal_Int64 nState)
477 if( !m_xAccContextRef.is() )
479 assert(false);
480 return MSAA_NO_STATE;
483 switch( nState )
485 case AccessibleStateType::BUSY:
486 return STATE_SYSTEM_BUSY;
487 case AccessibleStateType::CHECKED:
488 if (m_accRole == AccessibleRole::PUSH_BUTTON || m_accRole == AccessibleRole::TOGGLE_BUTTON)
489 return STATE_SYSTEM_PRESSED;
490 return STATE_SYSTEM_CHECKED;
491 case AccessibleStateType::DEFUNC:
492 return STATE_SYSTEM_UNAVAILABLE;
493 case AccessibleStateType::EXPANDED:
494 return STATE_SYSTEM_EXPANDED;
495 case AccessibleStateType::FOCUSABLE:
496 return STATE_SYSTEM_FOCUSABLE;
497 case AccessibleStateType::FOCUSED:
498 return STATE_SYSTEM_FOCUSED;
499 case AccessibleStateType::INDETERMINATE:
500 return STATE_SYSTEM_MIXED;
501 case AccessibleStateType::MULTI_SELECTABLE:
502 return STATE_SYSTEM_MULTISELECTABLE;
503 case AccessibleStateType::PRESSED:
504 return STATE_SYSTEM_PRESSED;
505 case AccessibleStateType::RESIZABLE:
506 return STATE_SYSTEM_SIZEABLE;
507 case AccessibleStateType::SELECTABLE:
508 if (m_accRole == AccessibleRole::MENU || m_accRole == AccessibleRole::MENU_ITEM)
509 return MSAA_NO_STATE;
510 return STATE_SYSTEM_SELECTABLE;
511 case AccessibleStateType::SELECTED:
512 if (m_accRole == AccessibleRole::MENU || m_accRole == AccessibleRole::MENU_ITEM)
513 return MSAA_NO_STATE;
514 return STATE_SYSTEM_SELECTED;
515 case AccessibleStateType::ARMED:
516 return STATE_SYSTEM_FOCUSED;
517 case AccessibleStateType::EXPANDABLE:
519 if (m_accRole == AccessibleRole::PUSH_BUTTON
520 || m_accRole == AccessibleRole::TOGGLE_BUTTON
521 || m_accRole == AccessibleRole::BUTTON_DROPDOWN)
522 return STATE_SYSTEM_HASPOPUP;
524 if (!(m_xAccContextRef->getAccessibleStateSet() & AccessibleStateType::EXPANDED))
525 return STATE_SYSTEM_COLLAPSED;
527 return MSAA_NO_STATE;
529 //Remove the SENSITIVE state mapping. There is no corresponding MSAA state.
530 //case SENSITIVE:
531 // IState = STATE_SYSTEM_PROTECTED;
532 case AccessibleStateType::EDITABLE:
533 m_pIMAcc->DecreaseState(STATE_SYSTEM_READONLY);
534 return MSAA_NO_STATE;
535 case AccessibleStateType::OFFSCREEN:
536 return STATE_SYSTEM_OFFSCREEN;
537 case AccessibleStateType::MOVEABLE:
538 return STATE_SYSTEM_MOVEABLE;
539 case AccessibleStateType::COLLAPSE:
540 return STATE_SYSTEM_COLLAPSED;
541 break;
542 case AccessibleStateType::DEFAULT:
543 return STATE_SYSTEM_DEFAULT;
544 default:
545 return MSAA_NO_STATE;
550 * Decrease state of com object
551 * @param xState The lost state.
552 * @return
554 void AccObject::DecreaseState( sal_Int64 xState )
556 if (xState == AccessibleStateType::FOCUSABLE)
558 if (m_accRole == AccessibleRole::MENU_ITEM || m_accRole == AccessibleRole::RADIO_MENU_ITEM
559 || m_accRole == AccessibleRole::CHECK_MENU_ITEM)
560 return;
561 else
563 if (m_accRole == AccessibleRole::TOGGLE_BUTTON
564 || m_accRole == AccessibleRole::PUSH_BUTTON
565 || m_accRole == AccessibleRole::BUTTON_DROPDOWN)
567 if ((m_pParentObj != nullptr)
568 && (AccessibleRole::TOOL_BAR == m_pParentObj->m_accRole))
569 return;
574 else if( xState == AccessibleStateType::VISIBLE )
576 m_pIMAcc->IncreaseState( STATE_SYSTEM_INVISIBLE );
578 else if( xState == AccessibleStateType::SHOWING )
580 m_pIMAcc->IncreaseState( STATE_SYSTEM_OFFSCREEN );
583 DWORD msState = GetMSAAStateFromUNO(xState);
584 if (msState != MSAA_NO_STATE)
585 m_pIMAcc->DecreaseState(msState);
589 * Increase state of com object
590 * @param xState The new state.
591 * @return
593 void AccObject::IncreaseState( sal_Int64 xState )
595 if( xState == AccessibleStateType::VISIBLE )
597 m_pIMAcc->DecreaseState( STATE_SYSTEM_INVISIBLE );
599 else if( xState == AccessibleStateType::SHOWING )
601 m_pIMAcc->DecreaseState( STATE_SYSTEM_OFFSCREEN );
605 DWORD msState = GetMSAAStateFromUNO(xState);
606 if (msState != MSAA_NO_STATE)
607 m_pIMAcc->IncreaseState( msState );
611 * Get next child element
612 * @param
613 * @return AccObject Object interface.
615 AccObject* AccObject::NextChild()
617 IAccChildList::iterator pInd = m_childrenList.begin();
618 if( pInd != m_childrenList.end() )
619 return *pInd;
620 return nullptr;
624 * update role information from uno to com
625 * @param
626 * @return
628 void AccObject::UpdateRole()
630 const sal_Int16 nUnoRole = m_xAccContextRef->getAccessibleRole();
631 short nIA2Role = lcl_mapToIAccessible2Role(nUnoRole);
632 m_pIMAcc->Put_XAccRole(nIA2Role);
636 * update state information from uno to com
637 * @param
638 * @return
640 void AccObject::UpdateState()
642 XAccessibleContext* pContext = m_xAccContextRef.get();
643 sal_Int64 nRState = pContext->getAccessibleStateSet();
645 m_pIMAcc->SetState(0);
647 if (m_accRole == AccessibleRole::POPUP_MENU)
649 return;
652 bool isEnable = false;
653 bool isShowing = false;
654 bool isEditable = false;
655 bool isVisible = false;
657 for (int i=0; i<63; ++i)
659 sal_Int64 nState = sal_Int64(1) << i;
660 if (!(nState & nRState))
661 continue;
662 if (nState == AccessibleStateType::ENABLED)
663 isEnable = true;
664 else if (nState == AccessibleStateType::SHOWING)
665 isShowing = true;
666 else if (nState == AccessibleStateType::VISIBLE)
667 isVisible = true;
668 else if (nState == AccessibleStateType::EDITABLE)
669 isEditable = true;
670 IncreaseState(nState);
673 bool bIsMenuItem = m_accRole == AccessibleRole::MENU_ITEM
674 || m_accRole == AccessibleRole::RADIO_MENU_ITEM
675 || m_accRole == AccessibleRole::CHECK_MENU_ITEM;
677 if(bIsMenuItem)
679 if(!(isShowing && isVisible) )
681 m_pIMAcc->IncreaseState( STATE_SYSTEM_INVISIBLE );
684 else
686 if(!(isShowing || isVisible) )
687 m_pIMAcc->IncreaseState( STATE_SYSTEM_INVISIBLE );
690 switch(m_accRole)
692 case AccessibleRole::LABEL:
693 case AccessibleRole::STATIC:
694 case AccessibleRole::NOTIFICATION:
695 case AccessibleRole::TEXT:
696 // 2. editable combobox -> readonly ------ bridge
697 case AccessibleRole::EMBEDDED_OBJECT:
698 case AccessibleRole::END_NOTE:
699 case AccessibleRole::FOOTER:
700 case AccessibleRole::FOOTNOTE:
701 case AccessibleRole::GRAPHIC:
702 case AccessibleRole::HEADER:
703 case AccessibleRole::HEADING:
705 //Image Map
706 case AccessibleRole::BLOCK_QUOTE:
707 case AccessibleRole::PARAGRAPH:
708 case AccessibleRole::PASSWORD_TEXT:
709 case AccessibleRole::SHAPE:
710 case AccessibleRole::SPIN_BOX:
711 case AccessibleRole::TABLE:
712 case AccessibleRole::TABLE_CELL:
713 case AccessibleRole::TEXT_FRAME:
714 case AccessibleRole::DATE_EDITOR:
715 case AccessibleRole::DOCUMENT:
716 case AccessibleRole::COLUMN_HEADER:
718 if(!isEditable)
719 m_pIMAcc->IncreaseState( STATE_SYSTEM_READONLY );
721 break;
722 default:
723 break;
726 if (!isEnable)
727 m_pIMAcc->IncreaseState( STATE_SYSTEM_UNAVAILABLE );
729 switch(m_accRole)
731 case AccessibleRole::POPUP_MENU:
732 case AccessibleRole::MENU:
733 if( pContext->getAccessibleChildCount() > 0 )
734 m_pIMAcc->IncreaseState( STATE_SYSTEM_HASPOPUP );
735 break;
736 case AccessibleRole::PASSWORD_TEXT:
737 m_pIMAcc->IncreaseState( STATE_SYSTEM_PROTECTED );
738 break;
739 default:
740 break;
745 * Public method to mapping information between MSAA and UNO.
746 * @param
747 * @return If the method is correctly processed.
749 bool AccObject::UpdateAccessibleInfoFromUnoToMSAA()
751 if (!m_xAccContextRef.is())
753 assert(false);
754 return false;
757 UpdateValue();
759 UpdateRole();
761 UpdateState();
763 return true;
768 * Set self to focus object in parent child list
769 * @param
770 * @return
772 void AccObject::setFocus()
774 IncreaseState(AccessibleStateType::FOCUSED);
775 m_pIMAcc->Put_XAccFocus(CHILDID_SELF);
777 UpdateRole();
781 * Unset self from focus object in parent child list.
782 * @param
783 * @return
785 void AccObject::unsetFocus()
787 DecreaseState(AccessibleStateType::FOCUSED);
788 m_pIMAcc->Put_XAccFocus(UACC_NO_FOCUS);
791 void AccObject::NotifyDestroy() { m_pIMAcc->NotifyDestroy(); }
793 void AccObject::SetParentObj(AccObject* pParentAccObj)
795 m_pParentObj = pParentAccObj;
797 if (m_pParentObj)
798 m_pIMAcc->Put_XAccParent(m_pParentObj->GetIMAccessible());
799 else
800 m_pIMAcc->Put_XAccParent(nullptr);
802 //ResID means ChildID in MSAA
803 void AccObject::SetResID(long id)
805 m_resID = id;
806 m_pIMAcc->Put_XAccChildID(m_resID);
808 //return COM interface in acc object
809 IMAccessible* AccObject::GetIMAccessible()
811 return m_pIMAcc;
814 Reference<XAccessible> const& AccObject::GetXAccessible()
816 return m_xAccRef;
819 void AccObject::SetParentHWND(HWND hWnd)
821 m_pParantID = hWnd;
824 rtl::Reference<AccEventListener> AccObject::SetListener(rtl::Reference<AccEventListener> const& pListener)
826 rtl::Reference<AccEventListener> pRet(m_pListener);
827 m_pListener = pListener;
828 return pRet;
831 long AccObject::GetResID()
833 return m_resID;
836 HWND AccObject::GetParentHWND()
838 return m_pParantID;
841 AccObject* AccObject::GetParentObj()
843 return m_pParentObj;
846 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */