1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/ole/access.cpp
3 // Purpose: implementation of wxIAccessible and wxAccessible
4 // Author: Julian Smart
8 // Copyright: (c) 2003 Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "access.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
27 #if defined(__BORLANDC__)
31 #include "wx/window.h"
36 #if wxUSE_OLE && wxUSE_ACCESSIBILITY
39 #include "wx/access.h"
43 // for some compilers, the entire ole2.h must be included, not only oleauto.h
44 #if wxUSE_NORLANDER_HEADERS || defined(__WATCOMC__)
51 #include "wx/msw/ole/oleutils.h"
54 #define CHILDID_SELF 0
58 #define OBJID_CLIENT 0xFFFFFFFC
61 // Convert to Windows role
62 int wxConvertToWindowsRole(wxAccRole wxrole
);
64 // Convert to Windows state
65 long wxConvertToWindowsState(long wxstate
);
67 // Convert to Windows selection flag
68 int wxConvertToWindowsSelFlag(wxAccSelectionFlags sel
);
70 // Convert from Windows selection flag
71 wxAccSelectionFlags
wxConvertFromWindowsSelFlag(int sel
);
73 // ----------------------------------------------------------------------------
74 // wxIEnumVARIANT interface implementation
75 // ----------------------------------------------------------------------------
77 class wxIEnumVARIANT
: public IEnumVARIANT
80 wxIEnumVARIANT(const wxVariant
& variant
);
83 DECLARE_IUNKNOWN_METHODS
;
86 STDMETHODIMP
Next(ULONG celt
, VARIANT
*rgelt
, ULONG
*pceltFetched
);
87 STDMETHODIMP
Skip(ULONG celt
);
89 STDMETHODIMP
Clone(IEnumVARIANT
**ppenum
);
92 wxVariant m_variant
; // List of further variants
93 int m_nCurrent
; // Current enum position
95 DECLARE_NO_COPY_CLASS(wxIEnumVARIANT
)
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 BEGIN_IID_TABLE(wxIEnumVARIANT
)
107 IMPLEMENT_IUNKNOWN_METHODS(wxIEnumVARIANT
)
109 // wxVariant contains a list of further variants.
110 wxIEnumVARIANT::wxIEnumVARIANT(const wxVariant
& variant
)
115 STDMETHODIMP
wxIEnumVARIANT::Next(ULONG celt
,
119 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIEnumVARIANT::Next"));
122 // we only return 1 element at a time - mainly because I'm too lazy to
123 // implement something which you're never asked for anyhow
127 if (m_variant
.GetType() != wxT("list"))
130 if ( m_nCurrent
< (int) m_variant
.GetList().GetCount() ) {
131 if (!wxConvertVariantToOle(m_variant
[m_nCurrent
++], rgelt
[0]))
136 // TODO: should we AddRef if this is an object?
147 STDMETHODIMP
wxIEnumVARIANT::Skip(ULONG celt
)
149 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIEnumVARIANT::Skip"));
151 if (m_variant
.GetType() != wxT("list"))
155 if ( m_nCurrent
< (int) m_variant
.GetList().GetCount() )
158 // no, can't skip this many elements
164 STDMETHODIMP
wxIEnumVARIANT::Reset()
166 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIEnumVARIANT::Reset"));
173 STDMETHODIMP
wxIEnumVARIANT::Clone(IEnumVARIANT
**ppenum
)
175 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIEnumVARIANT::Clone"));
177 wxIEnumVARIANT
*pNew
= new wxIEnumVARIANT(m_variant
);
185 // ----------------------------------------------------------------------------
186 // wxIAccessible implementation of IAccessible interface
187 // ----------------------------------------------------------------------------
189 class wxIAccessible
: public IAccessible
192 wxIAccessible(wxAccessible
*pAccessible
);
194 DECLARE_IUNKNOWN_METHODS
;
198 // Navigation and Hierarchy
200 // Retrieves the child element or child object at a given point on the screen.
201 // All visual objects support this method; sound objects do not support it.
203 STDMETHODIMP
accHitTest(long xLeft
, long yLeft
, VARIANT
* pVarID
);
205 // Retrieves the specified object's current screen location. All visual objects must
206 // support this method; sound objects do not support it.
208 STDMETHODIMP
accLocation ( long* pxLeft
, long* pyTop
, long* pcxWidth
, long* pcyHeight
, VARIANT varID
);
210 // Traverses to another user interface element within a container and retrieves the object.
211 // All visual objects must support this method.
213 STDMETHODIMP
accNavigate ( long navDir
, VARIANT varStart
, VARIANT
* pVarEnd
);
215 // Retrieves the address of an IDispatch interface for the specified child.
216 // All objects must support this property.
218 STDMETHODIMP
get_accChild ( VARIANT varChildID
, IDispatch
** ppDispChild
);
220 // Retrieves the number of children that belong to this object.
221 // All objects must support this property.
223 STDMETHODIMP
get_accChildCount ( long* pCountChildren
);
225 // Retrieves the IDispatch interface of the object's parent.
226 // All objects support this property.
228 STDMETHODIMP
get_accParent ( IDispatch
** ppDispParent
);
230 // Descriptive Properties and Methods
232 // Performs the object's default action. Not all objects have a default
235 STDMETHODIMP
accDoDefaultAction(VARIANT varID
);
237 // Retrieves a string that describes the object's default action.
238 // Not all objects have a default action.
240 STDMETHODIMP
get_accDefaultAction ( VARIANT varID
, BSTR
* pszDefaultAction
);
242 // Retrieves a string that describes the visual appearance of the specified object.
243 // Not all objects have a description.
245 STDMETHODIMP
get_accDescription ( VARIANT varID
, BSTR
* pszDescription
);
247 // Retrieves an object's Help property string.
248 // Not all objects support this property.
250 STDMETHODIMP
get_accHelp ( VARIANT varID
, BSTR
* pszHelp
);
252 // Retrieves the full path of the WinHelp file associated with the specified
253 // object and the identifier of the appropriate topic within that file.
254 // Not all objects support this property.
256 STDMETHODIMP
get_accHelpTopic ( BSTR
* pszHelpFile
, VARIANT varChild
, long* pidTopic
);
258 // Retrieves the specified object's shortcut key or access key, also known as
259 // the mnemonic. All objects that have a shortcut key or access key support
262 STDMETHODIMP
get_accKeyboardShortcut ( VARIANT varID
, BSTR
* pszKeyboardShortcut
);
264 // Retrieves the name of the specified object.
265 // All objects support this property.
267 STDMETHODIMP
get_accName ( VARIANT varID
, BSTR
* pszName
);
269 // Retrieves information that describes the role of the specified object.
270 // All objects support this property.
272 STDMETHODIMP
get_accRole ( VARIANT varID
, VARIANT
* pVarRole
);
274 // Retrieves the current state of the specified object.
275 // All objects support this property.
277 STDMETHODIMP
get_accState ( VARIANT varID
, VARIANT
* pVarState
);
279 // Retrieves the value of the specified object.
280 // Not all objects have a value.
282 STDMETHODIMP
get_accValue ( VARIANT varID
, BSTR
* pszValue
);
284 // Selection and Focus
286 // Modifies the selection or moves the keyboard focus of the
287 // specified object. All objects that select or receive the
288 // keyboard focus must support this method.
290 STDMETHODIMP
accSelect ( long flagsSelect
, VARIANT varID
);
292 // Retrieves the object that has the keyboard focus. All objects
293 // that receive the keyboard focus must support this property.
295 STDMETHODIMP
get_accFocus ( VARIANT
* pVarID
);
297 // Retrieves the selected children of this object. All objects
298 // selected must support this property.
300 STDMETHODIMP
get_accSelection ( VARIANT
* pVarChildren
);
304 STDMETHODIMP
put_accName(VARIANT varChild
, BSTR szName
) { return E_FAIL
; }
305 STDMETHODIMP
put_accValue(VARIANT varChild
, BSTR szName
) { return E_FAIL
; }
311 STDMETHODIMP
GetTypeInfo(unsigned int typeInfo
, LCID lcid
, ITypeInfo
** ppTypeInfo
);
313 // Get type info count
315 STDMETHODIMP
GetTypeInfoCount(unsigned int* typeInfoCount
);
319 STDMETHODIMP
GetIDsOfNames(REFIID riid
, OLECHAR
** names
, unsigned int cNames
,
320 LCID lcid
, DISPID
* dispId
);
324 STDMETHODIMP
Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
325 WORD wFlags
, DISPPARAMS
*pDispParams
,
326 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
,
327 unsigned int *puArgErr
);
330 wxAccessible
*m_pAccessible
; // pointer to C++ class we belong to
332 DECLARE_NO_COPY_CLASS(wxIAccessible
)
335 // ============================================================================
337 // ============================================================================
339 // ----------------------------------------------------------------------------
340 // wxIAccessible implementation
341 // ----------------------------------------------------------------------------
342 BEGIN_IID_TABLE(wxIAccessible
)
348 IMPLEMENT_IUNKNOWN_METHODS(wxIAccessible
)
350 wxIAccessible::wxIAccessible(wxAccessible
*pAccessible
)
352 wxASSERT( pAccessible
!= NULL
);
354 m_pAccessible
= pAccessible
;
357 // Retrieves the child element or child object at a given point on the screen.
358 // All visual objects support this method; sound objects do not support it.
360 STDMETHODIMP
wxIAccessible::accHitTest(long xLeft
, long yLeft
, VARIANT
* pVarID
)
362 wxASSERT (m_pAccessible
!= NULL
);
366 wxAccessible
* childObject
= NULL
;
370 wxAccStatus status
= m_pAccessible
->HitTest(wxPoint(xLeft
, yLeft
), & childId
, & childObject
);
372 if (status
== wxACC_FAIL
)
375 if (status
== wxACC_NOT_IMPLEMENTED
)
377 // Use standard interface instead.
378 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
382 return stdInterface
->accHitTest(xLeft
, yLeft
, pVarID
);
387 if (childObject
== m_pAccessible
)
390 pVarID
->lVal
= CHILDID_SELF
;
395 wxIAccessible
* childIA
= childObject
->GetIAccessible();
399 if (childIA
->QueryInterface(IID_IDispatch
, (LPVOID
*) pVarID
->pdispVal
) != S_OK
)
402 pVarID
->vt
= VT_DISPATCH
;
403 pVarID
->pdispVal
->AddRef();
407 else if (childId
> 0)
410 pVarID
->lVal
= childId
;
415 pVarID
->vt
= VT_EMPTY
;
422 // Retrieves the specified object's current screen location. All visual objects must
423 // support this method; sound objects do not support it.
425 STDMETHODIMP
wxIAccessible::accLocation ( long* pxLeft
, long* pyTop
, long* pcxWidth
, long* pcyHeight
, VARIANT varID
)
427 wxASSERT (m_pAccessible
!= NULL
);
433 wxAccStatus status
= m_pAccessible
->GetLocation(rect
, varID
.lVal
);
434 if (status
== wxACC_FAIL
)
437 if (status
== wxACC_NOT_IMPLEMENTED
)
439 // Use standard interface instead.
440 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
444 return stdInterface
->accLocation(pxLeft
, pyTop
, pcxWidth
, pcyHeight
, varID
);
450 *pcxWidth
= rect
.width
;
451 *pcyHeight
= rect
.height
;
458 // Traverses to another user interface element within a container and retrieves the object.
459 // All visual objects must support this method.
461 STDMETHODIMP
wxIAccessible::accNavigate ( long navDir
, VARIANT varStart
, VARIANT
* pVarEnd
)
463 wxASSERT (m_pAccessible
!= NULL
);
467 if (varStart
.vt
!= VT_I4
)
470 wxAccessible
* elementObject
= NULL
;
472 VariantInit(pVarEnd
);
473 wxNavDir navDirWX
= wxNAVDIR_FIRSTCHILD
;
478 navDirWX
= wxNAVDIR_DOWN
;
481 case NAVDIR_FIRSTCHILD
:
482 navDirWX
= wxNAVDIR_FIRSTCHILD
;
485 case NAVDIR_LASTCHILD
:
486 navDirWX
= wxNAVDIR_LASTCHILD
;
490 navDirWX
= wxNAVDIR_LEFT
;
494 navDirWX
= wxNAVDIR_NEXT
;
497 case NAVDIR_PREVIOUS
:
498 navDirWX
= wxNAVDIR_PREVIOUS
;
502 navDirWX
= wxNAVDIR_RIGHT
;
506 navDirWX
= wxNAVDIR_UP
;
510 wxAccStatus status
= m_pAccessible
->Navigate(navDirWX
, varStart
.lVal
, & elementId
,
513 if (status
== wxACC_FAIL
)
516 if (status
== wxACC_NOT_IMPLEMENTED
)
518 // Use standard interface instead.
519 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
523 return stdInterface
->accNavigate ( navDir
, varStart
, pVarEnd
);
529 wxIAccessible
* objectIA
= elementObject
->GetIAccessible();
533 if (objectIA
->QueryInterface(IID_IDispatch
, (LPVOID
*) pVarEnd
->pdispVal
) != S_OK
)
536 pVarEnd
->vt
= VT_DISPATCH
;
537 pVarEnd
->pdispVal
->AddRef();
540 else if (elementId
> 0)
543 pVarEnd
->lVal
= elementId
;
548 pVarEnd
->vt
= VT_EMPTY
;
556 // Retrieves the address of an IDispatch interface for the specified child.
557 // All objects must support this property.
559 STDMETHODIMP
wxIAccessible::get_accChild ( VARIANT varChildID
, IDispatch
** ppDispChild
)
561 wxASSERT (m_pAccessible
!= NULL
);
565 if (varChildID
.vt
!= VT_I4
)
568 if (varChildID
.lVal
== CHILDID_SELF
)
575 wxAccessible
* child
= NULL
;
577 wxAccStatus status
= m_pAccessible
->GetChild(varChildID
.lVal
, & child
);
578 if (status
== wxACC_FAIL
)
581 if (status
== wxACC_NOT_IMPLEMENTED
)
583 // Use standard interface instead.
584 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
588 return stdInterface
->get_accChild (varChildID
, ppDispChild
);
594 wxIAccessible
* objectIA
= child
->GetIAccessible();
598 if (objectIA
->QueryInterface(IID_IDispatch
, (LPVOID
*) ppDispChild
) != S_OK
)
601 (*ppDispChild
)->AddRef();
605 return S_FALSE
; // Indicates it's not an accessible object
611 // Retrieves the number of children that belong to this object.
612 // All objects must support this property.
614 STDMETHODIMP
wxIAccessible::get_accChildCount ( long* pCountChildren
)
616 wxASSERT (m_pAccessible
!= NULL
);
621 wxAccStatus status
= m_pAccessible
->GetChildCount(& childCount
);
622 if (status
== wxACC_FAIL
)
625 if (status
== wxACC_NOT_IMPLEMENTED
)
627 // Use standard interface instead.
628 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
632 return stdInterface
->get_accChildCount (pCountChildren
);
636 * pCountChildren
= (long) childCount
;
643 // Retrieves the IDispatch interface of the object's parent.
644 // All objects support this property.
646 STDMETHODIMP
wxIAccessible::get_accParent ( IDispatch
** ppDispParent
)
648 wxASSERT (m_pAccessible
!= NULL
);
652 wxAccessible
* parent
= NULL
;
653 wxAccStatus status
= m_pAccessible
->GetParent(& parent
);
654 if (status
== wxACC_FAIL
)
657 if (status
== wxACC_NOT_IMPLEMENTED
)
659 // Use standard interface instead.
660 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
664 return stdInterface
->get_accParent (ppDispParent
);
670 wxIAccessible
* objectIA
= parent
->GetIAccessible();
674 if (objectIA
->QueryInterface(IID_IDispatch
, (LPVOID
*) ppDispParent
) != S_OK
)
677 (*ppDispParent
)->AddRef();
680 wxIAccessible* objectIA = parent->GetIAccessible();
684 *ppDispParent = objectIA;
690 *ppDispParent
= NULL
;
698 // Performs the object's default action. Not all objects have a default
701 STDMETHODIMP
wxIAccessible::accDoDefaultAction(VARIANT varID
)
703 wxASSERT (m_pAccessible
!= NULL
);
707 if (varID
.vt
!= VT_I4
)
710 wxAccStatus status
= m_pAccessible
->DoDefaultAction(varID
.lVal
);
711 if (status
== wxACC_FAIL
)
714 if (status
== wxACC_NOT_SUPPORTED
)
715 return DISP_E_MEMBERNOTFOUND
;
717 if (status
== wxACC_NOT_IMPLEMENTED
)
719 // Use standard interface instead.
720 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
724 return stdInterface
->accDoDefaultAction(varID
);
729 // Retrieves a string that describes the object's default action.
730 // Not all objects have a default action.
732 STDMETHODIMP
wxIAccessible::get_accDefaultAction ( VARIANT varID
, BSTR
* pszDefaultAction
)
734 wxASSERT (m_pAccessible
!= NULL
);
738 if (varID
.vt
!= VT_I4
)
741 wxString defaultAction
;
742 wxAccStatus status
= m_pAccessible
->GetDefaultAction(varID
.lVal
, & defaultAction
);
743 if (status
== wxACC_FAIL
)
746 if (status
== wxACC_NOT_SUPPORTED
)
747 return DISP_E_MEMBERNOTFOUND
;
749 if (status
== wxACC_NOT_IMPLEMENTED
)
751 // Use standard interface instead.
752 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
756 return stdInterface
->get_accDefaultAction (varID
, pszDefaultAction
);
760 if (defaultAction
.IsEmpty())
762 * pszDefaultAction
= NULL
;
767 wxBasicString
basicString(defaultAction
);
768 * pszDefaultAction
= basicString
.Get();
775 // Retrieves a string that describes the visual appearance of the specified object.
776 // Not all objects have a description.
778 STDMETHODIMP
wxIAccessible::get_accDescription ( VARIANT varID
, BSTR
* pszDescription
)
780 wxASSERT (m_pAccessible
!= NULL
);
784 if (varID
.vt
!= VT_I4
)
787 wxString description
;
788 wxAccStatus status
= m_pAccessible
->GetDescription(varID
.lVal
, & description
);
789 if (status
== wxACC_FAIL
)
792 if (status
== wxACC_NOT_IMPLEMENTED
)
794 // Use standard interface instead.
795 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
799 return stdInterface
->get_accDescription (varID
, pszDescription
);
803 if (description
.IsEmpty())
805 * pszDescription
= NULL
;
810 wxBasicString
basicString(description
);
811 * pszDescription
= basicString
.Get();
818 // Retrieves an object's Help property string.
819 // Not all objects support this property.
821 STDMETHODIMP
wxIAccessible::get_accHelp ( VARIANT varID
, BSTR
* pszHelp
)
823 wxASSERT (m_pAccessible
!= NULL
);
827 if (varID
.vt
!= VT_I4
)
831 wxAccStatus status
= m_pAccessible
->GetHelpText(varID
.lVal
, & helpString
);
832 if (status
== wxACC_FAIL
)
835 if (status
== wxACC_NOT_IMPLEMENTED
)
837 // Use standard interface instead.
838 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
842 return stdInterface
->get_accHelp (varID
, pszHelp
);
846 if (helpString
.IsEmpty())
853 wxBasicString
basicString(helpString
);
854 * pszHelp
= basicString
.Get();
861 // Retrieves the full path of the WinHelp file associated with the specified
862 // object and the identifier of the appropriate topic within that file.
863 // Not all objects support this property.
864 // NOTE: not supported by wxWindows at this time. Use
865 // GetHelpText instead.
867 STDMETHODIMP
wxIAccessible::get_accHelpTopic ( BSTR
* pszHelpFile
, VARIANT varChild
, long* pidTopic
)
869 wxASSERT (m_pAccessible
!= NULL
);
873 if (varChild
.vt
!= VT_I4
)
876 wxAccStatus status
= wxACC_NOT_IMPLEMENTED
;
877 if (status
== wxACC_FAIL
)
880 if (status
== wxACC_NOT_IMPLEMENTED
)
882 // Use standard interface instead.
883 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
887 return stdInterface
->get_accHelpTopic (pszHelpFile
, varChild
, pidTopic
);
892 // Retrieves the specified object's shortcut key or access key, also known as
893 // the mnemonic. All objects that have a shortcut key or access key support
896 STDMETHODIMP
wxIAccessible::get_accKeyboardShortcut ( VARIANT varID
, BSTR
* pszKeyboardShortcut
)
898 *pszKeyboardShortcut
= NULL
;
900 wxASSERT (m_pAccessible
!= NULL
);
904 if (varID
.vt
!= VT_I4
)
907 wxString keyboardShortcut
;
908 wxAccStatus status
= m_pAccessible
->GetHelpText(varID
.lVal
, & keyboardShortcut
);
909 if (status
== wxACC_FAIL
)
912 if (status
== wxACC_NOT_IMPLEMENTED
)
914 // Use standard interface instead.
915 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
919 return stdInterface
->get_accKeyboardShortcut(varID
, pszKeyboardShortcut
);
923 if (keyboardShortcut
.IsEmpty())
925 * pszKeyboardShortcut
= NULL
;
930 wxBasicString
basicString(keyboardShortcut
);
931 * pszKeyboardShortcut
= basicString
.Get();
938 // Retrieves the name of the specified object.
939 // All objects support this property.
941 STDMETHODIMP
wxIAccessible::get_accName ( VARIANT varID
, BSTR
* pszName
)
945 wxASSERT (m_pAccessible
!= NULL
);
949 if (varID
.vt
!= VT_I4
)
954 wxAccStatus status
= m_pAccessible
->GetName(varID
.lVal
, & name
);
956 if (status
== wxACC_FAIL
)
959 if (status
== wxACC_NOT_IMPLEMENTED
)
961 // Use standard interface instead.
962 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
966 return stdInterface
->get_accName (varID
, pszName
);
970 wxBasicString
basicString(name
);
971 *pszName
= basicString
.Get();
977 // Retrieves information that describes the role of the specified object.
978 // All objects support this property.
980 STDMETHODIMP
wxIAccessible::get_accRole ( VARIANT varID
, VARIANT
* pVarRole
)
982 wxASSERT (m_pAccessible
!= NULL
);
986 if (varID
.vt
!= VT_I4
)
989 VariantInit(pVarRole
);
991 wxAccRole role
= wxROLE_NONE
;
993 wxAccStatus status
= m_pAccessible
->GetRole(varID
.lVal
, & role
);
995 if (status
== wxACC_FAIL
)
998 if (status
== wxACC_NOT_IMPLEMENTED
)
1000 // Use standard interface instead.
1001 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
1005 return stdInterface
->get_accRole (varID
, pVarRole
);
1009 if (role
== wxROLE_NONE
)
1011 pVarRole
->vt
= VT_EMPTY
;
1015 pVarRole
->lVal
= wxConvertToWindowsRole(role
);
1016 pVarRole
->vt
= VT_I4
;
1023 // Retrieves the current state of the specified object.
1024 // All objects support this property.
1026 STDMETHODIMP
wxIAccessible::get_accState ( VARIANT varID
, VARIANT
* pVarState
)
1028 wxASSERT (m_pAccessible
!= NULL
);
1032 if (varID
.vt
!= VT_I4
)
1033 return E_INVALIDARG
;
1037 wxAccStatus status
= m_pAccessible
->GetState(varID
.lVal
, & wxstate
);
1038 if (status
== wxACC_FAIL
)
1041 if (status
== wxACC_NOT_IMPLEMENTED
)
1043 // Use standard interface instead.
1044 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
1048 return stdInterface
->get_accState (varID
, pVarState
);
1052 long state
= wxConvertToWindowsState(wxstate
);
1053 pVarState
->lVal
= state
;
1054 pVarState
->vt
= VT_I4
;
1060 // Retrieves the value of the specified object.
1061 // Not all objects have a value.
1063 STDMETHODIMP
wxIAccessible::get_accValue ( VARIANT varID
, BSTR
* pszValue
)
1065 wxASSERT (m_pAccessible
!= NULL
);
1069 if (varID
.vt
!= VT_I4
)
1070 return E_INVALIDARG
;
1074 wxAccStatus status
= m_pAccessible
->GetValue(varID
.lVal
, & strValue
);
1076 if (status
== wxACC_FAIL
)
1079 if (status
== wxACC_NOT_IMPLEMENTED
)
1081 // Use standard interface instead.
1082 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
1086 return stdInterface
->get_accValue (varID
, pszValue
);
1090 wxBasicString
basicString(strValue
);
1091 * pszValue
= basicString
.Get();
1097 // Modifies the selection or moves the keyboard focus of the
1098 // specified object. All objects that select or receive the
1099 // keyboard focus must support this method.
1101 STDMETHODIMP
wxIAccessible::accSelect ( long flagsSelect
, VARIANT varID
)
1103 wxASSERT (m_pAccessible
!= NULL
);
1107 if (varID
.vt
!= VT_I4
)
1108 return E_INVALIDARG
;
1110 wxAccSelectionFlags wxsel
= wxConvertFromWindowsSelFlag(flagsSelect
);
1112 wxAccStatus status
= m_pAccessible
->Select(varID
.lVal
, wxsel
);
1113 if (status
== wxACC_FAIL
)
1116 if (status
== wxACC_NOT_IMPLEMENTED
)
1118 // Use standard interface instead.
1119 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
1123 return stdInterface
->accSelect ( flagsSelect
, varID
);
1131 // Retrieves the object that has the keyboard focus. All objects
1132 // that receive the keyboard focus must support this property.
1134 STDMETHODIMP
wxIAccessible::get_accFocus ( VARIANT
* pVarID
)
1136 wxASSERT (m_pAccessible
!= NULL
);
1140 wxAccessible
* childObject
= NULL
;
1142 VariantInit(pVarID
);
1144 wxAccStatus status
= m_pAccessible
->GetFocus(& childId
, & childObject
);
1145 if (status
== wxACC_FAIL
)
1148 if (status
== wxACC_NOT_IMPLEMENTED
)
1150 // Use standard interface instead.
1151 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
1155 return stdInterface
->get_accFocus (pVarID
);
1159 if (childObject
== m_pAccessible
)
1162 pVarID
->lVal
= CHILDID_SELF
;
1167 wxIAccessible
* childIA
= childObject
->GetIAccessible();
1171 if (childIA
->QueryInterface(IID_IDispatch
, (LPVOID
*) pVarID
->pdispVal
) != S_OK
)
1174 pVarID
->vt
= VT_DISPATCH
;
1175 pVarID
->pdispVal
->AddRef();
1179 else if (childId
> 0)
1182 pVarID
->lVal
= childId
;
1187 pVarID
->vt
= VT_EMPTY
;
1194 // Retrieves the selected children of this object. All objects
1195 // selected must support this property.
1197 STDMETHODIMP
wxIAccessible::get_accSelection ( VARIANT
* pVarChildren
)
1199 wxASSERT (m_pAccessible
!= NULL
);
1203 VariantInit(pVarChildren
);
1205 wxVariant selections
;
1206 wxAccStatus status
= m_pAccessible
->GetSelections(& selections
);
1207 if (status
== wxACC_FAIL
)
1210 if (status
== wxACC_NOT_IMPLEMENTED
)
1212 // Use standard interface instead.
1213 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
1217 return stdInterface
->get_accSelection (pVarChildren
);
1221 if (selections
.GetType() == wxT("long"))
1223 pVarChildren
->vt
= VT_I4
;
1224 pVarChildren
->lVal
= selections
.GetLong();
1228 else if (selections
.GetType() == wxT("void*"))
1230 wxAccessible
* childObject
= (wxAccessible
*) selections
.GetVoidPtr();
1231 wxIAccessible
* childIA
= childObject
->GetIAccessible();
1235 if (childIA
->QueryInterface(IID_IDispatch
, (LPVOID
*) pVarChildren
->pdispVal
) != S_OK
)
1238 pVarChildren
->vt
= VT_DISPATCH
;
1239 pVarChildren
->pdispVal
->AddRef();
1243 else if (selections
.GetType() == wxT("list"))
1245 // TODO: should we AddRef for every "void*" member??
1247 wxIEnumVARIANT
* enumVariant
= new wxIEnumVARIANT(selections
);
1248 enumVariant
->AddRef();
1250 pVarChildren
->vt
= VT_UNKNOWN
;
1251 pVarChildren
->punkVal
= enumVariant
;
1262 STDMETHODIMP
wxIAccessible::GetTypeInfo(unsigned int typeInfo
, LCID lcid
, ITypeInfo
** ppTypeInfo
)
1268 // Get type info count
1270 STDMETHODIMP
wxIAccessible::GetTypeInfoCount(unsigned int* typeInfoCount
)
1278 STDMETHODIMP
wxIAccessible::GetIDsOfNames(REFIID riid
, OLECHAR
** names
, unsigned int cNames
,
1279 LCID lcid
, DISPID
* dispId
)
1286 STDMETHODIMP
wxIAccessible::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1287 WORD wFlags
, DISPPARAMS
*pDispParams
,
1288 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
,
1289 unsigned int *puArgErr
)
1294 // ----------------------------------------------------------------------------
1295 // wxAccessible implementation
1296 // ----------------------------------------------------------------------------
1300 // common part of all ctors
1301 void wxAccessible::Init()
1303 m_pIAccessibleStd
= NULL
;
1304 m_pIAccessible
= new wxIAccessible(this);
1305 m_pIAccessible
->AddRef();
1308 wxAccessible::wxAccessible(wxWindow
* win
)
1309 : wxAccessibleBase(win
)
1314 wxAccessible::~wxAccessible()
1316 m_pIAccessible
->Release();
1317 if (m_pIAccessibleStd
)
1318 ((IAccessible
*)m_pIAccessibleStd
)->Release();
1321 // Gets or creates a standard interface for this object.
1322 void* wxAccessible::GetIAccessibleStd()
1324 if (m_pIAccessibleStd
)
1325 return m_pIAccessibleStd
;
1330 HRESULT retCode
= ::CreateStdAccessibleProxy((HWND
) GetWindow()->GetHWND(),
1331 wxT("wxWindowClass"), OBJID_CLIENT
, IID_IAccessible
, (void**) & m_pIAccessibleStd
);
1333 HRESULT retCode
= ::CreateStdAccessibleObject((HWND
) GetWindow()->GetHWND(),
1334 OBJID_CLIENT
, IID_IAccessible
, (void**) & m_pIAccessibleStd
);
1336 if (retCode
== S_OK
)
1337 return m_pIAccessibleStd
;
1340 m_pIAccessibleStd
= NULL
;
1349 // Convert to Windows role
1350 int wxConvertToWindowsRole(wxAccRole wxrole
)
1354 case wxROLE_SYSTEM_ALERT
:
1355 return ROLE_SYSTEM_ALERT
;
1356 case wxROLE_SYSTEM_ANIMATION
:
1357 return ROLE_SYSTEM_ANIMATION
;
1358 case wxROLE_SYSTEM_APPLICATION
:
1359 return ROLE_SYSTEM_APPLICATION
;
1360 case wxROLE_SYSTEM_BORDER
:
1361 return ROLE_SYSTEM_BORDER
;
1362 case wxROLE_SYSTEM_BUTTONDROPDOWN
:
1363 return ROLE_SYSTEM_BUTTONDROPDOWN
;
1364 case wxROLE_SYSTEM_BUTTONDROPDOWNGRID
:
1365 return ROLE_SYSTEM_BUTTONDROPDOWNGRID
;
1366 case wxROLE_SYSTEM_BUTTONMENU
:
1367 return ROLE_SYSTEM_BUTTONMENU
;
1368 case wxROLE_SYSTEM_CARET
:
1369 return ROLE_SYSTEM_CARET
;
1370 case wxROLE_SYSTEM_CELL
:
1371 return ROLE_SYSTEM_CELL
;
1372 case wxROLE_SYSTEM_CHARACTER
:
1373 return ROLE_SYSTEM_CHARACTER
;
1374 case wxROLE_SYSTEM_CHART
:
1375 return ROLE_SYSTEM_CHART
;
1376 case wxROLE_SYSTEM_CHECKBUTTON
:
1377 return ROLE_SYSTEM_CHECKBUTTON
;
1378 case wxROLE_SYSTEM_CLIENT
:
1379 return ROLE_SYSTEM_CLIENT
;
1380 case wxROLE_SYSTEM_CLOCK
:
1381 return ROLE_SYSTEM_CLOCK
;
1382 case wxROLE_SYSTEM_COLUMN
:
1383 return ROLE_SYSTEM_COLUMN
;
1384 case wxROLE_SYSTEM_COLUMNHEADER
:
1385 return ROLE_SYSTEM_COLUMNHEADER
;
1386 case wxROLE_SYSTEM_COMBOBOX
:
1387 return ROLE_SYSTEM_COMBOBOX
;
1388 case wxROLE_SYSTEM_CURSOR
:
1389 return ROLE_SYSTEM_CURSOR
;
1390 case wxROLE_SYSTEM_DIAGRAM
:
1391 return ROLE_SYSTEM_DIAGRAM
;
1392 case wxROLE_SYSTEM_DIAL
:
1393 return ROLE_SYSTEM_DIAL
;
1394 case wxROLE_SYSTEM_DIALOG
:
1395 return ROLE_SYSTEM_DIALOG
;
1396 case wxROLE_SYSTEM_DOCUMENT
:
1397 return ROLE_SYSTEM_DOCUMENT
;
1398 case wxROLE_SYSTEM_DROPLIST
:
1399 return ROLE_SYSTEM_DROPLIST
;
1400 case wxROLE_SYSTEM_EQUATION
:
1401 return ROLE_SYSTEM_EQUATION
;
1402 case wxROLE_SYSTEM_GRAPHIC
:
1403 return ROLE_SYSTEM_GRAPHIC
;
1404 case wxROLE_SYSTEM_GRIP
:
1405 return ROLE_SYSTEM_GRIP
;
1406 case wxROLE_SYSTEM_GROUPING
:
1407 return ROLE_SYSTEM_GROUPING
;
1408 case wxROLE_SYSTEM_HELPBALLOON
:
1409 return ROLE_SYSTEM_HELPBALLOON
;
1410 case wxROLE_SYSTEM_HOTKEYFIELD
:
1411 return ROLE_SYSTEM_HOTKEYFIELD
;
1412 case wxROLE_SYSTEM_INDICATOR
:
1413 return ROLE_SYSTEM_INDICATOR
;
1414 case wxROLE_SYSTEM_LINK
:
1415 return ROLE_SYSTEM_LINK
;
1416 case wxROLE_SYSTEM_LIST
:
1417 return ROLE_SYSTEM_LIST
;
1418 case wxROLE_SYSTEM_LISTITEM
:
1419 return ROLE_SYSTEM_LISTITEM
;
1420 case wxROLE_SYSTEM_MENUBAR
:
1421 return ROLE_SYSTEM_MENUBAR
;
1422 case wxROLE_SYSTEM_MENUITEM
:
1423 return ROLE_SYSTEM_MENUITEM
;
1424 case wxROLE_SYSTEM_MENUPOPUP
:
1425 return ROLE_SYSTEM_MENUPOPUP
;
1426 case wxROLE_SYSTEM_OUTLINE
:
1427 return ROLE_SYSTEM_OUTLINE
;
1428 case wxROLE_SYSTEM_OUTLINEITEM
:
1429 return ROLE_SYSTEM_OUTLINEITEM
;
1430 case wxROLE_SYSTEM_PAGETAB
:
1431 return ROLE_SYSTEM_PAGETAB
;
1432 case wxROLE_SYSTEM_PAGETABLIST
:
1433 return ROLE_SYSTEM_PAGETABLIST
;
1434 case wxROLE_SYSTEM_PANE
:
1435 return ROLE_SYSTEM_PANE
;
1436 case wxROLE_SYSTEM_PROGRESSBAR
:
1437 return ROLE_SYSTEM_PROGRESSBAR
;
1438 case wxROLE_SYSTEM_PROPERTYPAGE
:
1439 return ROLE_SYSTEM_PROPERTYPAGE
;
1440 case wxROLE_SYSTEM_PUSHBUTTON
:
1441 return ROLE_SYSTEM_PUSHBUTTON
;
1442 case wxROLE_SYSTEM_RADIOBUTTON
:
1443 return ROLE_SYSTEM_RADIOBUTTON
;
1444 case wxROLE_SYSTEM_ROW
:
1445 return ROLE_SYSTEM_ROW
;
1446 case wxROLE_SYSTEM_ROWHEADER
:
1447 return ROLE_SYSTEM_ROWHEADER
;
1448 case wxROLE_SYSTEM_SCROLLBAR
:
1449 return ROLE_SYSTEM_SCROLLBAR
;
1450 case wxROLE_SYSTEM_SEPARATOR
:
1451 return ROLE_SYSTEM_SEPARATOR
;
1452 case wxROLE_SYSTEM_SLIDER
:
1453 return ROLE_SYSTEM_SLIDER
;
1454 case wxROLE_SYSTEM_SOUND
:
1455 return ROLE_SYSTEM_SOUND
;
1456 case wxROLE_SYSTEM_SPINBUTTON
:
1457 return ROLE_SYSTEM_SPINBUTTON
;
1458 case wxROLE_SYSTEM_STATICTEXT
:
1459 return ROLE_SYSTEM_STATICTEXT
;
1460 case wxROLE_SYSTEM_STATUSBAR
:
1461 return ROLE_SYSTEM_STATUSBAR
;
1462 case wxROLE_SYSTEM_TABLE
:
1463 return ROLE_SYSTEM_TABLE
;
1464 case wxROLE_SYSTEM_TEXT
:
1465 return ROLE_SYSTEM_TEXT
;
1466 case wxROLE_SYSTEM_TITLEBAR
:
1467 return ROLE_SYSTEM_TITLEBAR
;
1468 case wxROLE_SYSTEM_TOOLBAR
:
1469 return ROLE_SYSTEM_TOOLBAR
;
1470 case wxROLE_SYSTEM_TOOLTIP
:
1471 return ROLE_SYSTEM_TOOLTIP
;
1472 case wxROLE_SYSTEM_WHITESPACE
:
1473 return ROLE_SYSTEM_WHITESPACE
;
1474 case wxROLE_SYSTEM_WINDOW
:
1475 return ROLE_SYSTEM_WINDOW
;
1480 // Convert to Windows state
1481 long wxConvertToWindowsState(long wxstate
)
1484 if (wxstate
& wxACC_STATE_SYSTEM_ALERT_HIGH
)
1485 state
|= STATE_SYSTEM_ALERT_HIGH
;
1487 if (wxstate
& wxACC_STATE_SYSTEM_ALERT_MEDIUM
)
1488 state
|= STATE_SYSTEM_ALERT_MEDIUM
;
1490 if (wxstate
& wxACC_STATE_SYSTEM_ALERT_LOW
)
1491 state
|= STATE_SYSTEM_ALERT_LOW
;
1493 if (wxstate
& wxACC_STATE_SYSTEM_ANIMATED
)
1494 state
|= STATE_SYSTEM_ANIMATED
;
1496 if (wxstate
& wxACC_STATE_SYSTEM_BUSY
)
1497 state
|= STATE_SYSTEM_BUSY
;
1499 if (wxstate
& wxACC_STATE_SYSTEM_CHECKED
)
1500 state
|= STATE_SYSTEM_CHECKED
;
1502 if (wxstate
& wxACC_STATE_SYSTEM_COLLAPSED
)
1503 state
|= STATE_SYSTEM_COLLAPSED
;
1505 if (wxstate
& wxACC_STATE_SYSTEM_DEFAULT
)
1506 state
|= STATE_SYSTEM_DEFAULT
;
1508 if (wxstate
& wxACC_STATE_SYSTEM_EXPANDED
)
1509 state
|= STATE_SYSTEM_EXPANDED
;
1511 if (wxstate
& wxACC_STATE_SYSTEM_EXTSELECTABLE
)
1512 state
|= STATE_SYSTEM_EXTSELECTABLE
;
1514 if (wxstate
& wxACC_STATE_SYSTEM_FLOATING
)
1515 state
|= STATE_SYSTEM_FLOATING
;
1517 if (wxstate
& wxACC_STATE_SYSTEM_FOCUSABLE
)
1518 state
|= STATE_SYSTEM_FOCUSABLE
;
1520 if (wxstate
& wxACC_STATE_SYSTEM_FOCUSED
)
1521 state
|= STATE_SYSTEM_FOCUSED
;
1523 if (wxstate
& wxACC_STATE_SYSTEM_HOTTRACKED
)
1524 state
|= STATE_SYSTEM_HOTTRACKED
;
1526 if (wxstate
& wxACC_STATE_SYSTEM_INVISIBLE
)
1527 state
|= STATE_SYSTEM_INVISIBLE
;
1529 if (wxstate
& wxACC_STATE_SYSTEM_INVISIBLE
)
1530 state
|= STATE_SYSTEM_INVISIBLE
;
1532 if (wxstate
& wxACC_STATE_SYSTEM_MIXED
)
1533 state
|= STATE_SYSTEM_MIXED
;
1535 if (wxstate
& wxACC_STATE_SYSTEM_MULTISELECTABLE
)
1536 state
|= STATE_SYSTEM_MULTISELECTABLE
;
1538 if (wxstate
& wxACC_STATE_SYSTEM_OFFSCREEN
)
1539 state
|= STATE_SYSTEM_OFFSCREEN
;
1541 if (wxstate
& wxACC_STATE_SYSTEM_PRESSED
)
1542 state
|= STATE_SYSTEM_PRESSED
;
1544 // if (wxstate & wxACC_STATE_SYSTEM_PROTECTED)
1545 // state |= STATE_SYSTEM_PROTECTED;
1547 if (wxstate
& wxACC_STATE_SYSTEM_READONLY
)
1548 state
|= STATE_SYSTEM_READONLY
;
1550 if (wxstate
& wxACC_STATE_SYSTEM_SELECTABLE
)
1551 state
|= STATE_SYSTEM_SELECTABLE
;
1553 if (wxstate
& wxACC_STATE_SYSTEM_SELECTED
)
1554 state
|= STATE_SYSTEM_SELECTED
;
1556 if (wxstate
& wxACC_STATE_SYSTEM_SELFVOICING
)
1557 state
|= STATE_SYSTEM_SELFVOICING
;
1559 if (wxstate
& wxACC_STATE_SYSTEM_UNAVAILABLE
)
1560 state
|= STATE_SYSTEM_UNAVAILABLE
;
1565 // Convert to Windows selection flag
1566 int wxConvertToWindowsSelFlag(wxAccSelectionFlags wxsel
)
1570 if (sel
& wxACC_SEL_TAKEFOCUS
)
1571 sel
|= SELFLAG_TAKEFOCUS
;
1572 if (sel
& wxACC_SEL_TAKESELECTION
)
1573 sel
|= SELFLAG_TAKESELECTION
;
1574 if (sel
& wxACC_SEL_EXTENDSELECTION
)
1575 sel
|= SELFLAG_EXTENDSELECTION
;
1576 if (sel
& wxACC_SEL_ADDSELECTION
)
1577 sel
|= SELFLAG_ADDSELECTION
;
1578 if (sel
& wxACC_SEL_REMOVESELECTION
)
1579 sel
|= SELFLAG_REMOVESELECTION
;
1583 // Convert from Windows selection flag
1584 wxAccSelectionFlags
wxConvertFromWindowsSelFlag(int sel
)
1588 if (sel
& SELFLAG_TAKEFOCUS
)
1589 wxsel
|= wxACC_SEL_TAKEFOCUS
;
1590 if (sel
& SELFLAG_TAKESELECTION
)
1591 wxsel
|= wxACC_SEL_TAKESELECTION
;
1592 if (sel
& SELFLAG_EXTENDSELECTION
)
1593 wxsel
|= wxACC_SEL_EXTENDSELECTION
;
1594 if (sel
& SELFLAG_ADDSELECTION
)
1595 wxsel
|= wxACC_SEL_ADDSELECTION
;
1596 if (sel
& SELFLAG_REMOVESELECTION
)
1597 wxsel
|= wxACC_SEL_REMOVESELECTION
;
1598 return (wxAccSelectionFlags
) wxsel
;
1602 #endif //USE_ACCESSIBILITY