bump product version to 5.0.4.1
[LibreOffice.git] / winaccessibility / source / service / AccObject.cxx
blob17d35bdd52943410598673d0646ba09192c16944
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 <stdlib.h>
28 #include <memory.h>
29 #include <stdio.h>
30 #include <algorithm>
31 #include <assert.h>
33 #include "AccObject.hxx"
34 #include "AccEventListener.hxx"
35 #include "UAccCOM_i.c"
36 #include "AccResource.hxx"
39 using namespace std;
40 using namespace com::sun::star::uno;
41 using namespace com::sun::star::accessibility;
42 using namespace com::sun::star::accessibility::AccessibleRole;
43 using namespace com::sun::star::accessibility::AccessibleStateType;
45 //Role mapping table,left side is UNO role, right side is MSAA role
46 const short ROLE_TABLE[][2] =
48 {UNKNOWN, IA2_ROLE_UNKNOWN},
49 {ALERT , ROLE_SYSTEM_DIALOG},
50 {COLUMN_HEADER , ROLE_SYSTEM_COLUMNHEADER},
51 //{CANVAS , ROLE_SYSTEM_CLIENT},
52 {CANVAS , IA2_ROLE_CANVAS},
53 {CHECK_BOX , ROLE_SYSTEM_CHECKBUTTON},
54 {CHECK_MENU_ITEM , IA2_ROLE_CHECK_MENU_ITEM},
55 {COLOR_CHOOSER, IA2_ROLE_COLOR_CHOOSER},
56 {COMBO_BOX , ROLE_SYSTEM_COMBOBOX},
57 {DATE_EDITOR , IA2_ROLE_DATE_EDITOR},
58 {DESKTOP_ICON , IA2_ROLE_DESKTOP_ICON},
59 {DESKTOP_PANE, IA2_ROLE_DESKTOP_PANE},
60 {DIRECTORY_PANE, IA2_ROLE_DIRECTORY_PANE},
61 {DIALOG, ROLE_SYSTEM_DIALOG},
62 {DOCUMENT, ROLE_SYSTEM_DOCUMENT},
63 {EMBEDDED_OBJECT , IA2_ROLE_EMBEDDED_OBJECT },
64 {END_NOTE , IA2_ROLE_ENDNOTE },
65 {FILE_CHOOSER , IA2_ROLE_FILE_CHOOSER },
66 {FILLER, ROLE_SYSTEM_WHITESPACE},
67 {FONT_CHOOSER, IA2_ROLE_FONT_CHOOSER},
68 {FOOTER, IA2_ROLE_FOOTER},
69 {FOOTNOTE, IA2_ROLE_FOOTNOTE},
70 //{FRAME, IA2_ROLE_FRAME},
71 {FRAME, ROLE_SYSTEM_DIALOG},
72 {GLASS_PANE , IA2_ROLE_GLASS_PANE},
73 {GRAPHIC , ROLE_SYSTEM_GRAPHIC},
74 {GROUP_BOX, ROLE_SYSTEM_GROUPING},
75 {HEADER , IA2_ROLE_HEADER},
76 {HEADING , IA2_ROLE_HEADING},
77 {HYPER_LINK , ROLE_SYSTEM_TEXT},
78 {ICON , IA2_ROLE_ICON},
79 {INTERNAL_FRAME, IA2_ROLE_INTERNAL_FRAME},
80 {LABEL, ROLE_SYSTEM_STATICTEXT},
81 {LAYERED_PANE , IA2_ROLE_LAYERED_PANE},
82 {LIST , ROLE_SYSTEM_LIST},
83 {LIST_ITEM , ROLE_SYSTEM_LISTITEM},
84 //{MENU , ROLE_SYSTEM_MENUPOPUP},
85 {MENU, ROLE_SYSTEM_MENUITEM},
86 {MENU_BAR, ROLE_SYSTEM_MENUBAR},
87 {MENU_ITEM, ROLE_SYSTEM_MENUITEM},
88 {OPTION_PANE , IA2_ROLE_OPTION_PANE},
89 {PAGE_TAB, ROLE_SYSTEM_PAGETAB},
90 {PAGE_TAB_LIST, ROLE_SYSTEM_PAGETABLIST},
91 {PANEL, IA2_ROLE_OPTION_PANE},
92 {PARAGRAPH, IA2_ROLE_PARAGRAPH},
93 {PASSWORD_TEXT, ROLE_SYSTEM_TEXT},
94 {POPUP_MENU, ROLE_SYSTEM_MENUPOPUP},
95 {PUSH_BUTTON, ROLE_SYSTEM_PUSHBUTTON},
96 {PROGRESS_BAR, ROLE_SYSTEM_PROGRESSBAR},
97 {RADIO_BUTTON, ROLE_SYSTEM_RADIOBUTTON},
98 {RADIO_MENU_ITEM, IA2_ROLE_RADIO_MENU_ITEM},
99 {ROW_HEADER , ROLE_SYSTEM_ROWHEADER},
100 {ROOT_PANE, IA2_ROLE_ROOT_PANE},
101 {SCROLL_BAR , ROLE_SYSTEM_SCROLLBAR},
102 {SCROLL_PANE , IA2_ROLE_SCROLL_PANE},
103 {SHAPE, IA2_ROLE_SHAPE},
104 {SEPARATOR , ROLE_SYSTEM_SEPARATOR},
105 {SLIDER , ROLE_SYSTEM_SLIDER},
106 {SPIN_BOX , ROLE_SYSTEM_SPINBUTTON},
107 {SPLIT_PANE, IA2_ROLE_SPLIT_PANE},
108 {STATUS_BAR, ROLE_SYSTEM_STATUSBAR},
109 {TABLE, ROLE_SYSTEM_TABLE},
110 {TABLE_CELL , ROLE_SYSTEM_CELL},
111 {TEXT, ROLE_SYSTEM_TEXT},
112 {TEXT_FRAME , IA2_ROLE_TEXT_FRAME},
113 //for change toggle button to push button for jaws
114 {TOGGLE_BUTTON, ROLE_SYSTEM_PUSHBUTTON},
116 {TOOL_BAR, ROLE_SYSTEM_TOOLBAR},
117 {TOOL_TIP, ROLE_SYSTEM_TOOLTIP},
118 {TREE , ROLE_SYSTEM_OUTLINE},
119 {VIEW_PORT , IA2_ROLE_VIEW_PORT},
120 {WINDOW, ROLE_SYSTEM_WINDOW},
121 {BUTTON_DROPDOWN, ROLE_SYSTEM_BUTTONDROPDOWN},
122 {BUTTON_MENU, ROLE_SYSTEM_BUTTONMENU},
123 {CAPTION, IA2_ROLE_CAPTION},
124 {CHART, IA2_ROLE_SHAPE},
125 {EDIT_BAR, IA2_ROLE_EDITBAR},
126 {FORM, IA2_ROLE_FORM},
127 {IMAGE_MAP , IA2_ROLE_IMAGE_MAP},
128 {NOTE, IA2_ROLE_NOTE},
129 {PAGE, IA2_ROLE_PAGE},
130 {RULER , IA2_ROLE_RULER},
131 {SECTION, IA2_ROLE_SECTION},
132 {TREE_ITEM , ROLE_SYSTEM_OUTLINEITEM},
133 {TREE_TABLE, ROLE_SYSTEM_OUTLINE},
134 {COMMENT, IA2_ROLE_TEXT_FRAME },
135 {COMMENT_END, IA2_ROLE_TEXT_FRAME },
136 {DOCUMENT_PRESENTATION, ROLE_SYSTEM_DOCUMENT },
137 {DOCUMENT_SPREADSHEET, ROLE_SYSTEM_DOCUMENT },
138 {DOCUMENT_TEXT, ROLE_SYSTEM_DOCUMENT }
143 * Constructor.
144 * @param pXAcc Uno XAccessible interface of control.
145 * @param Agent The agent kept in all listeners,it's the sole interface by which
146 * listener communicate with windows manager.
147 * @param listener listener that registers in UNO system.
148 * @return.
150 AccObject::AccObject(XAccessible* pAcc, AccObjectManagerAgent* pAgent,
151 AccEventListener* pListener) :
152 m_pIMAcc (NULL),
153 m_resID (NULL),
154 m_pParantID (NULL),
155 m_pParentObj(NULL),
156 m_pListener (pListener),
157 m_bShouldDestroy(sal_False),
158 m_xAccRef( pAcc )
160 ImplInitializeCreateObj();
162 m_xAccContextRef = m_xAccRef->getAccessibleContext();
163 m_xAccActionRef = Reference< XAccessibleAction > (m_xAccContextRef,UNO_QUERY);
164 m_accRole = m_xAccContextRef -> getAccessibleRole();
165 if( m_pIMAcc )
167 m_pIMAcc->SetXAccessible(reinterpret_cast<hyper>(m_xAccRef.get()));
168 m_pIMAcc->Put_XAccAgent(reinterpret_cast<hyper>(pAgent));
169 m_pIMAcc->SetDefaultAction(reinterpret_cast<hyper>(m_xAccActionRef.get()));
173 * Destructor.
174 * @param
175 * @return
177 AccObject::~AccObject()
179 m_pIMAcc = NULL;
180 m_xAccRef = NULL;
181 m_xAccActionRef = NULL;
182 m_xAccContextRef = NULL;
188 * Insert a child element.
189 * @param pChild Child element that should be inserted into child list.
190 * @param pos Insert position.
191 * @return
193 void AccObject::InsertChild( AccObject* pChild,short pos )
196 std::vector<AccObject*>::iterator iter;
197 iter = std::find(m_childrenList.begin(),m_childrenList.end(),pChild);
198 if(iter!=m_childrenList.end())
199 return;
200 if(LAST_CHILD==pos)
202 m_childrenList.push_back(pChild);
204 else
206 std::vector<AccObject*>::iterator iter=m_childrenList.begin()+pos;
207 m_childrenList.insert(iter,pChild);
210 pChild->SetParentObj(this);
214 * Delete a child element
215 * @param pChild Child element that should be inserted into child list.
216 * @param pos Insert position.
217 * @return
219 void AccObject::DeleteChild( AccObject* pChild )
221 std::vector<AccObject*>::iterator iter;
222 iter = std::find(m_childrenList.begin(),m_childrenList.end(),pChild);
223 if(iter!=m_childrenList.end())
225 m_childrenList.erase(iter);
226 if(m_pIMAcc)
227 pChild->SetParentObj(NULL);
232 * In order to windows API WindowFromAccessibleObject,we sometimes to set a pure
233 * top window accessible object created by windows system as top ancestor.
234 * @param.
235 * @return
237 void AccObject::UpdateValidWindow()
239 if(m_pIMAcc)
240 m_pIMAcc->Put_XAccWindowHandle(m_pParantID);
244 * Translate all UNO basic information into MSAA com information.
245 * @param
246 * @return If the method is correctly processed.
248 void AccObject::ImplInitializeCreateObj()
250 m_pIMAcc = UAccCOMCreateInstance();
252 assert(m_pIMAcc);
256 * Update name property to com object.
257 * @param
258 * @return
260 void AccObject::UpdateName( )
262 if (!m_pIMAcc)
264 return;
267 if( ( TEXT_FRAME == m_accRole ) && ( m_pParentObj !=NULL )&& ( SCROLL_PANE == m_pParentObj -> m_accRole ) )
268 m_pIMAcc->Put_XAccName( m_pParentObj->m_xAccContextRef->getAccessibleName().getStr() );
269 //IAccessibility2 Implementation 2009-----
270 if ( PARAGRAPH == m_accRole)
272 ::rtl::OUString emptyStr("");
273 m_pIMAcc->Put_XAccName(emptyStr.getStr());
275 //-----IAccessibility2 Implementation 2009
276 else
277 m_pIMAcc->Put_XAccName(m_xAccContextRef->getAccessibleName().getStr());
279 return ;
282 * Update description property to com object.
283 * no content for update description
284 * @param
285 * @return
287 void AccObject::UpdateDescription()
289 if (!m_pIMAcc)
291 return;
294 m_pIMAcc->Put_XAccDescription(m_xAccContextRef->getAccessibleDescription().getStr());
295 return ;
299 * Update default action property to com object.
300 * @param
301 * @return
303 void AccObject::UpdateAction()
305 m_xAccActionRef = Reference< XAccessibleAction > (m_xAccContextRef,UNO_QUERY);
307 if( m_xAccActionRef.is() && m_pIMAcc )
309 if( m_xAccActionRef->getAccessibleActionCount() > 0 )
311 UpdateDefaultAction( );
312 m_pIMAcc->SetDefaultAction(
313 reinterpret_cast<hyper>(m_xAccActionRef.get()));
319 * Update value property to com object.
320 * @param
321 * @return
323 void AccObject::UpdateValue()
325 if( NULL == m_pIMAcc || !m_xAccContextRef.is() )
327 assert(false);
328 return ;
331 Reference< XAccessibleValue > pRValue(m_xAccContextRef.get(),UNO_QUERY);
332 Any pAny;
333 if( pRValue.is() )
335 pAny = pRValue->getCurrentValue();
338 SetValue( pAny );
342 * Set special default action description string via UNO role.
343 * @param Role UNO role
344 * @return
346 void AccObject::UpdateDefaultAction( )
348 if(!m_xAccActionRef.is())
349 return ;
351 switch(m_accRole)
353 case PUSH_BUTTON:
354 case TOGGLE_BUTTON:
355 case RADIO_BUTTON:
356 case MENU_ITEM:
357 case RADIO_MENU_ITEM:
358 case CHECK_MENU_ITEM:
359 case LIST_ITEM:
360 case CHECK_BOX:
361 case TREE_ITEM:
362 case BUTTON_DROPDOWN:
363 m_pIMAcc->Put_ActionDescription( m_xAccActionRef->getAccessibleActionDescription((sal_Int32)0).getStr() );
364 return;
369 * Set value property via pAny.
370 * @param pAny New value.
371 * @return
373 void AccObject::SetValue( Any pAny )
375 unsigned short pUNumberString[100];
376 memset( pUNumberString, 0 , sizeof( pUNumberString) );
378 if( NULL == m_pIMAcc || !m_xAccContextRef.is() )
380 assert(false);
381 return ;
383 Reference< XAccessibleText > pRText(m_xAccContextRef,UNO_QUERY);
384 ::rtl::OUString val;
385 switch(m_accRole)
387 case SPIN_BOX:
388 // 3. date editor's msaa value should be the same as spinbox
389 case DATE_EDITOR:
390 case TEXT:
391 case PARAGRAPH:
392 case HEADING:
393 case TABLE_CELL:
395 if(pRText.get())
397 val = pRText->getText();
399 m_pIMAcc->Put_XAccValue( val.getStr() );
400 break;
401 case TREE_ITEM:
402 //case CHECK_BOX: //Commented by Li Xing to disable the value for general checkbox
403 case COMBO_BOX:
404 case NOTE:
405 case SCROLL_BAR:
406 m_pIMAcc->Put_XAccValue( GetMAccessibleValueFromAny(pAny).getStr() );
407 break ;
408 // Added by Li Xing, only the checkbox in tree should have the value.
409 case CHECK_BOX:
410 if( ( m_pParentObj !=NULL ) && (TREE == m_pParentObj->m_accRole || TREE_ITEM == m_pParentObj->m_accRole ))
411 m_pIMAcc->Put_XAccValue( GetMAccessibleValueFromAny(pAny).getStr() );
412 break;
413 default:
414 break;
417 return;
421 ::rtl::OUString AccObject::GetMAccessibleValueFromAny(Any pAny)
423 ::rtl::OUString strValue;
425 if(NULL == m_pIMAcc)
426 return strValue;
428 if(pAny.getValueType() == cppu::UnoType<cppu::UnoUnsignedShortType>::get() )
430 sal_uInt16 val;
431 if (pAny >>= val)
433 strValue=::rtl::OUString::number(val);
437 else if(pAny.getValueType() == cppu::UnoType<rtl::OUString>::get())
440 pAny >>= strValue ;
443 else if(pAny.getValueType() == cppu::UnoType<Sequence< ::rtl::OUString >>::get())
445 Sequence< ::rtl::OUString > val;
446 if (pAny >>= val)
449 int count = val.getLength();
451 for( int iIndex = 0;iIndex < count;iIndex++ )
453 strValue += val[iIndex];
458 else if(pAny.getValueType() == cppu::UnoType<double>::get())
460 double val;
461 if (pAny >>= val)
463 strValue=::rtl::OUString::number(val);
466 else if(pAny.getValueType() == cppu::UnoType<sal_Int32>::get())
468 sal_Int32 val;
469 if (pAny >>= val)
471 strValue=::rtl::OUString::number(val);
474 else if (pAny.getValueType() == cppu::UnoType<com::sun::star::accessibility::TextSegment>::get())
476 com::sun::star::accessibility::TextSegment val;
477 if (pAny >>= val)
479 ::rtl::OUString realVal(val.SegmentText);
480 strValue = realVal;
485 return strValue;
488 * Set name property via pAny.
489 * @param pAny New accessible name.
490 * @return
492 void AccObject::SetName( Any pAny)
494 if( NULL == m_pIMAcc )
495 return ;
497 m_pIMAcc->Put_XAccName( GetMAccessibleValueFromAny(pAny).getStr() );
502 * Set description property via pAny.
503 * @param pAny New accessible description.
504 * @return
506 void AccObject::SetDescription( Any pAny )
508 if( NULL == m_pIMAcc )
509 return ;
510 m_pIMAcc->Put_XAccDescription( GetMAccessibleValueFromAny(pAny).getStr() );
514 * Set role property via pAny
515 * @param Role New accessible role.
516 * @return
518 void AccObject::SetRole( short Role )
520 if( NULL == m_pIMAcc )
521 return ;
522 m_pIMAcc->Put_XAccRole( Role );
526 * Get role property via pAny
527 * @param
528 * @return accessible role
530 short AccObject::GetRole() const
532 return m_accRole;
536 * Get MSAA state from UNO state
537 * @Role xState UNO state.
538 * @return
540 DWORD AccObject::GetMSAAStateFromUNO(short xState)
542 DWORD IState = UNO_MSAA_UNMAPPING;
544 if( !m_xAccContextRef.is() )
546 assert(false);
547 return IState;
549 short Role = m_accRole;
551 switch( xState )
553 case BUSY:
554 IState = STATE_SYSTEM_BUSY;
555 break;
556 case CHECKED:
557 if( Role == PUSH_BUTTON || Role == TOGGLE_BUTTON )
559 IState = STATE_SYSTEM_PRESSED;
561 else
562 IState = STATE_SYSTEM_CHECKED;
563 break;
564 case DEFUNC:
565 IState = STATE_SYSTEM_UNAVAILABLE;
566 break;
567 case EXPANDED:
568 IState = STATE_SYSTEM_EXPANDED;
569 break;
570 case FOCUSABLE:
571 IState = STATE_SYSTEM_FOCUSABLE;
572 break;
573 case FOCUSED:
574 IState = STATE_SYSTEM_FOCUSED;
575 break;
576 case INDETERMINATE:
577 IState = STATE_SYSTEM_MIXED;
578 break;
579 case MULTI_SELECTABLE:
580 IState = STATE_SYSTEM_MULTISELECTABLE;
581 break;
582 case PRESSED:
583 IState = STATE_SYSTEM_PRESSED;
584 break;
585 case RESIZABLE:
586 IState = STATE_SYSTEM_SIZEABLE;
587 break;
588 case SELECTABLE:
589 if( m_accRole == MENU || m_accRole == MENU_ITEM)
591 IState = UNO_MSAA_UNMAPPING;
593 else
595 IState = STATE_SYSTEM_SELECTABLE;
597 break;
598 case SELECTED:
599 if( m_accRole == MENU || m_accRole == MENU_ITEM )
601 IState = UNO_MSAA_UNMAPPING;
603 else
605 IState = STATE_SYSTEM_SELECTED;
607 break;
608 case ARMED:
609 IState = STATE_SYSTEM_FOCUSED;
610 break;
611 case EXPANDABLE:
613 sal_Bool isExpanded = sal_True;
614 sal_Bool isExpandable = sal_True;
615 if( Role == PUSH_BUTTON || Role == TOGGLE_BUTTON || BUTTON_DROPDOWN == Role )
617 IState = STATE_SYSTEM_HASPOPUP;
619 else
621 GetExpandedState(&isExpandable,&isExpanded);
622 if(!isExpanded)
623 IState = STATE_SYSTEM_COLLAPSED;
626 break;
627 //Remove the SENSITIVE state mapping. There is no corresponding MSAA state.
628 //case SENSITIVE:
629 // IState = STATE_SYSTEM_PROTECTED;
630 case EDITABLE:
631 if( m_pIMAcc )
633 m_pIMAcc->DecreaseState( STATE_SYSTEM_READONLY );
635 break;
636 case OFFSCREEN:
637 IState = STATE_SYSTEM_OFFSCREEN;
638 break;
639 case MOVEABLE:
640 IState = STATE_SYSTEM_MOVEABLE;
641 break;
642 case COLLAPSE:
643 IState = STATE_SYSTEM_COLLAPSED;
644 break;
645 case DEFAULT:
646 IState = STATE_SYSTEM_DEFAULT;
647 break;
648 default:
649 break;
652 return IState;
656 * Decrease state of com object
657 * @param xState The lost state.
658 * @return
660 void AccObject::DecreaseState( short xState )
662 if( NULL == m_pIMAcc )
664 return;
667 if( xState == FOCUSABLE)
669 short Role = m_accRole ;
670 if(Role == MENU_ITEM
671 || Role == RADIO_MENU_ITEM
672 || Role == CHECK_MENU_ITEM)
673 return;
674 else
676 if (Role == TOGGLE_BUTTON || Role == PUSH_BUTTON || BUTTON_DROPDOWN == Role)
678 if( ( m_pParentObj !=NULL ) && (TOOL_BAR == m_pParentObj->m_accRole ) )
679 return;
684 else if( xState == AccessibleStateType::VISIBLE )
686 m_pIMAcc->IncreaseState( STATE_SYSTEM_INVISIBLE );
688 else if( xState == AccessibleStateType::SHOWING )
690 m_pIMAcc->IncreaseState( STATE_SYSTEM_OFFSCREEN );
693 DWORD msState = GetMSAAStateFromUNO(xState);
694 if(msState!=UNO_MSAA_UNMAPPING)
695 m_pIMAcc->DecreaseState(msState);
699 * Increase state of com object
700 * @param xState The new state.
701 * @return
703 void AccObject::IncreaseState( short xState )
705 if( NULL == m_pIMAcc )
707 assert(false);
708 return;
712 if( xState == AccessibleStateType::VISIBLE )
714 m_pIMAcc->DecreaseState( STATE_SYSTEM_INVISIBLE );
716 else if( xState == AccessibleStateType::SHOWING )
718 m_pIMAcc->DecreaseState( STATE_SYSTEM_OFFSCREEN );
722 DWORD msState = GetMSAAStateFromUNO(xState);
723 if(msState!=UNO_MSAA_UNMAPPING)
724 m_pIMAcc->IncreaseState( msState );
728 * Get next child element
729 * @param
730 * @return AccObject Object interface.
732 AccObject* AccObject::NextChild()
734 IAccChildList::iterator pInd = m_childrenList.begin();
735 if( pInd != m_childrenList.end() )
736 return *pInd;
737 return NULL;
740 * update action description desc
741 * @param
742 * @return
744 void AccObject::UpdateActionDesc()
746 if (!m_pIMAcc)
748 return;
751 ::rtl::OUString pXString = m_xAccContextRef->getAccessibleDescription();
752 m_pIMAcc->Put_XAccDescription(pXString.getStr());
753 long Role = m_accRole;
755 if( Role == PUSH_BUTTON || Role == RADIO_BUTTON || Role == MENU_ITEM ||
756 Role == LIST_ITEM || Role == CHECK_BOX || Role == TREE_ITEM ||
757 Role == CHECK_MENU_ITEM || Role == RADIO_MENU_ITEM )
759 UpdateDefaultAction( );
761 else
764 if( m_xAccActionRef.is() )
766 if( m_xAccActionRef->getAccessibleActionCount() > 0 )
768 if (!(Role == SPIN_BOX || Role == COMBO_BOX || Role == DATE_EDITOR ||
769 Role == EDIT_BAR || Role == PASSWORD_TEXT || Role == TEXT))
771 pXString = m_xAccActionRef->getAccessibleActionDescription( 0 );
772 //Solution:If string length is more than zero,action will will be set.
773 if( pXString.getLength() > 0)
774 m_pIMAcc->Put_ActionDescription( pXString.getStr() );
782 * update role information from uno to com
783 * @param
784 * @return
786 void AccObject::UpdateRole()
788 if (!m_pIMAcc)
790 return;
793 XAccessibleContext* pContext = m_xAccContextRef.get();
794 m_pIMAcc->Put_XAccRole( ROLE_SYSTEM_WINDOW );
795 short iRoleIndex = pContext->getAccessibleRole();
796 if ((0 <= iRoleIndex) && (iRoleIndex < SAL_N_ELEMENTS(ROLE_TABLE)))
798 short iIA2Role = ROLE_TABLE[iRoleIndex][1] ;
799 m_pIMAcc->Put_XAccRole( iIA2Role );
804 * update state information from uno to com
805 * @param
806 * @return
808 void AccObject::UpdateState()
810 if (!m_pIMAcc)
812 return;
815 XAccessibleContext* pContext = m_xAccContextRef.get();
816 Reference< XAccessibleStateSet > pRState = pContext->getAccessibleStateSet();
817 if( !pRState.is() )
819 assert(false);
820 return ;
823 m_pIMAcc->SetState(0L);
825 if ( m_accRole == POPUP_MENU )
827 return;
830 Sequence<short> pStates = pRState->getStates();
831 int count = pStates.getLength();
833 sal_Bool isEnable = sal_False;
834 sal_Bool isShowing = sal_False;
835 sal_Bool isEditable = sal_False;
836 sal_Bool isVisible = sal_False;
837 sal_Bool isFocusable = sal_False;
839 for( int iIndex = 0;iIndex < count;iIndex++ )
841 if( pStates[iIndex] == ENABLED )
842 isEnable = sal_True;
843 else if( pStates[iIndex] == SHOWING)
844 isShowing = sal_True;
845 else if( pStates[iIndex] == VISIBLE)
846 isVisible = sal_True;
847 else if( pStates[iIndex] == EDITABLE )
848 isEditable = sal_True;
849 else if (pStates[iIndex] == FOCUSABLE)
850 isFocusable = sal_True;
851 IncreaseState( pStates[iIndex]);
853 sal_Bool bIsMenuItem = m_accRole == MENU_ITEM || m_accRole == RADIO_MENU_ITEM || m_accRole == CHECK_MENU_ITEM;
855 if(bIsMenuItem)
857 if(!(isShowing && isVisible) )
859 m_pIMAcc->IncreaseState( STATE_SYSTEM_INVISIBLE );
860 m_pIMAcc->DecreaseState( STATE_SYSTEM_FOCUSABLE );
863 else
865 if(!(isShowing || isVisible) )
866 m_pIMAcc->IncreaseState( STATE_SYSTEM_INVISIBLE );
869 short Role = m_accRole;
871 if( m_pIMAcc )
873 switch(m_accRole)
875 case LABEL:
876 m_pIMAcc->IncreaseState( STATE_SYSTEM_READONLY );
877 break;
878 case TEXT:
879 // 2. editable combobox -> readonly ------ bridge
880 case EMBEDDED_OBJECT:
881 case END_NOTE:
882 case FOOTER:
883 case FOOTNOTE:
884 case GRAPHIC:
885 case HEADER:
886 case HEADING:
888 //Image Map
889 case PARAGRAPH:
890 case PASSWORD_TEXT:
891 case SHAPE:
892 case SPIN_BOX:
893 case TABLE:
894 case TABLE_CELL:
895 case TEXT_FRAME:
896 case DATE_EDITOR:
897 case DOCUMENT:
898 case COLUMN_HEADER:
900 if(!isEditable)
901 m_pIMAcc->IncreaseState( STATE_SYSTEM_READONLY );
903 break;
904 default:
905 break;
909 if( isEnable )
912 if(!(Role == FILLER || Role == END_NOTE || Role == FOOTER || Role == FOOTNOTE || Role == GROUP_BOX || Role == RULER
913 || Role == HEADER || Role == ICON || Role == INTERNAL_FRAME || Role == LABEL || Role == LAYERED_PANE
914 || Role == SCROLL_BAR || Role == SCROLL_PANE || Role == SPLIT_PANE || Role == STATUS_BAR || Role == TOOL_TIP))
916 if( SEPARATOR == Role )
918 if( ( m_pParentObj != NULL ) && ( MENU == m_pParentObj->m_accRole || POPUP_MENU == m_pParentObj->m_accRole ))
919 IncreaseState( FOCUSABLE );
922 else if (TABLE_CELL == Role || TABLE == Role || PANEL == Role || OPTION_PANE == Role ||
923 COLUMN_HEADER == Role)
925 if (isFocusable)
926 IncreaseState( FOCUSABLE );
928 else
930 if(bIsMenuItem)
932 if ( isShowing && isVisible)
934 IncreaseState( FOCUSABLE );
937 else
939 IncreaseState( FOCUSABLE );
944 else
946 m_pIMAcc->IncreaseState( STATE_SYSTEM_UNAVAILABLE );
947 if( !((Role == MENU_ITEM) ||
948 (Role == RADIO_MENU_ITEM) ||
949 (Role == CHECK_MENU_ITEM)) )
951 if ( Role == TOGGLE_BUTTON || Role == PUSH_BUTTON || BUTTON_DROPDOWN == Role)
953 if(( m_pParentObj != NULL )&& (TOOL_BAR == m_pParentObj->m_accRole ) )
954 IncreaseState( FOCUSABLE );
955 else
956 DecreaseState( FOCUSABLE );
958 else
959 DecreaseState( FOCUSABLE );
961 else if( isShowing || isVisible )
963 IncreaseState( FOCUSABLE );
967 if( m_pIMAcc )
969 switch(m_accRole)
971 case POPUP_MENU:
972 case MENU:
973 if( pContext->getAccessibleChildCount() > 0 )
974 m_pIMAcc->IncreaseState( STATE_SYSTEM_HASPOPUP );
975 break;
976 case PASSWORD_TEXT:
977 m_pIMAcc->IncreaseState( STATE_SYSTEM_PROTECTED );
978 break;
979 default:
980 break;
986 * update location information from uno to com
987 * @param
988 * @return
990 void AccObject::UpdateLocation()
992 if (!m_pIMAcc)
994 return;
996 XAccessibleContext* pContext = m_xAccContextRef.get();
998 Reference< XAccessibleComponent > pRComponent(pContext,UNO_QUERY);
999 if( pRComponent.is() )
1001 ::com::sun::star::awt::Point pCPoint = pRComponent->getLocationOnScreen();
1002 ::com::sun::star::awt::Size pCSize = pRComponent->getSize();
1003 Location tempLocation;
1004 tempLocation.m_dLeft = pCPoint.X;
1005 tempLocation.m_dTop = pCPoint.Y;
1006 tempLocation.m_dWidth = pCSize.Width;
1007 tempLocation.m_dHeight = pCSize.Height;
1008 m_pIMAcc->Put_XAccLocation( tempLocation );
1015 * Public method to mapping information between MSAA and UNO.
1016 * @param
1017 * @return If the method is correctly processed.
1019 sal_Bool AccObject:: UpdateAccessibleInfoFromUnoToMSAA ( )
1021 if( NULL == m_pIMAcc || !m_xAccContextRef.is() )
1023 assert(false);
1024 return sal_False;
1027 UpdateName();
1029 UpdateValue();
1031 UpdateActionDesc();
1033 UpdateRole();
1035 UpdateLocation();
1037 UpdateState();
1039 return sal_True;
1043 * Add a child selected element.
1044 * @param pAccObj Child object pointer.
1045 * @return
1047 void AccObject::AddSelect( long index, AccObject* accObj)
1049 m_selectionList.insert(IAccSelectionList::value_type(index,accObj));
1052 IAccSelectionList& AccObject::GetSelection()
1054 return m_selectionList;
1059 * Set self to focus object in parant child list
1060 * @param
1061 * @return
1063 void AccObject::setFocus()
1065 if(m_pIMAcc)
1067 IncreaseState(FOCUSED);
1068 m_pIMAcc->Put_XAccFocus(CHILDID_SELF);
1070 UpdateRole();
1075 * Unset self from focus object in parant child list.
1076 * @param
1077 * @return
1079 void AccObject::unsetFocus()
1081 if(m_pIMAcc)
1083 DecreaseState( FOCUSED );
1084 m_pIMAcc->Put_XAccFocus(UACC_NO_FOCUS);
1088 void AccObject::GetExpandedState( sal_Bool* isExpandable, sal_Bool* isExpanded)
1090 *isExpanded = sal_False;
1091 *isExpandable = sal_False;
1093 if( !m_xAccContextRef.is() )
1095 return;
1097 Reference< XAccessibleStateSet > pRState = m_xAccContextRef->getAccessibleStateSet();
1098 if( !pRState.is() )
1100 return;
1103 Sequence<short> pStates = pRState->getStates();
1104 int count = pStates.getLength();
1106 for( int iIndex = 0;iIndex < count;iIndex++ )
1108 if( EXPANDED == pStates[iIndex] )
1110 *isExpanded = sal_True;
1112 else if( EXPANDABLE == pStates[iIndex] )
1114 *isExpandable = sal_True;
1119 void AccObject::NotifyDestroy(sal_Bool ifDelete)
1121 m_bShouldDestroy=ifDelete;
1122 if(m_pIMAcc)
1123 m_pIMAcc->NotifyDestroy(m_bShouldDestroy);
1126 void AccObject::SetParentObj(AccObject* pParentAccObj)
1128 m_pParentObj = pParentAccObj;
1130 if(m_pIMAcc)
1132 if(m_pParentObj)
1134 m_pIMAcc->Put_XAccParent(m_pParentObj->GetIMAccessible());
1136 else
1138 m_pIMAcc->Put_XAccParent(NULL);
1142 //ResID means ChildID in MSAA
1143 void AccObject::SetResID(long id)
1145 m_resID = id;
1146 if(m_pIMAcc)
1147 m_pIMAcc->Put_XAccChildID(m_resID);
1149 //return COM interface in acc object
1150 IMAccessible* AccObject::GetIMAccessible()
1152 return m_pIMAcc;
1155 Reference<XAccessible> const& AccObject::GetXAccessible()
1157 return m_xAccRef;
1160 void AccObject::SetParentHWND(HWND hWnd)
1162 m_pParantID = hWnd;
1165 void AccObject::SetListener(rtl::Reference<AccEventListener> const& pListener)
1167 m_pListener = pListener;
1170 AccEventListener* AccObject::getListener()
1172 return m_pListener.get();
1175 long AccObject::GetResID()
1177 return m_resID;
1180 HWND AccObject::GetParentHWND()
1182 return m_pParantID;
1185 AccObject* AccObject::GetParentObj()
1187 return m_pParentObj;
1189 sal_Bool AccObject::ifShouldDestroy()
1191 return m_bShouldDestroy;
1194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */