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();
597 *ppDispChild
= objectIA
;
602 return S_FALSE
; // Indicates it's not an accessible object
608 // Retrieves the number of children that belong to this object.
609 // All objects must support this property.
611 STDMETHODIMP
wxIAccessible::get_accChildCount ( long* pCountChildren
)
613 wxASSERT (m_pAccessible
!= NULL
);
618 wxAccStatus status
= m_pAccessible
->GetChildCount(& childCount
);
619 if (status
== wxACC_FAIL
)
622 if (status
== wxACC_NOT_IMPLEMENTED
)
624 // Use standard interface instead.
625 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
629 return stdInterface
->get_accChildCount (pCountChildren
);
633 * pCountChildren
= (long) childCount
;
640 // Retrieves the IDispatch interface of the object's parent.
641 // All objects support this property.
643 STDMETHODIMP
wxIAccessible::get_accParent ( IDispatch
** ppDispParent
)
645 wxASSERT (m_pAccessible
!= NULL
);
649 wxAccessible
* parent
= NULL
;
650 wxAccStatus status
= m_pAccessible
->GetParent(& parent
);
651 if (status
== wxACC_FAIL
)
654 if (status
== wxACC_NOT_IMPLEMENTED
)
656 // Use standard interface instead.
657 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
661 return stdInterface
->get_accParent (ppDispParent
);
667 wxIAccessible
* objectIA
= parent
->GetIAccessible();
671 if (objectIA
->QueryInterface(IID_IDispatch
, (LPVOID
*) ppDispParent
) != S_OK
)
674 (*ppDispParent
)->AddRef();
677 wxIAccessible* objectIA = parent->GetIAccessible();
681 *ppDispParent = objectIA;
687 *ppDispParent
= NULL
;
695 // Performs the object's default action. Not all objects have a default
698 STDMETHODIMP
wxIAccessible::accDoDefaultAction(VARIANT varID
)
700 wxASSERT (m_pAccessible
!= NULL
);
704 if (varID
.vt
!= VT_I4
)
707 wxAccStatus status
= m_pAccessible
->DoDefaultAction(varID
.lVal
);
708 if (status
== wxACC_FAIL
)
711 if (status
== wxACC_NOT_SUPPORTED
)
712 return DISP_E_MEMBERNOTFOUND
;
714 if (status
== wxACC_NOT_IMPLEMENTED
)
716 // Use standard interface instead.
717 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
721 return stdInterface
->accDoDefaultAction(varID
);
726 // Retrieves a string that describes the object's default action.
727 // Not all objects have a default action.
729 STDMETHODIMP
wxIAccessible::get_accDefaultAction ( VARIANT varID
, BSTR
* pszDefaultAction
)
731 wxASSERT (m_pAccessible
!= NULL
);
735 if (varID
.vt
!= VT_I4
)
738 wxString defaultAction
;
739 wxAccStatus status
= m_pAccessible
->GetDefaultAction(varID
.lVal
, & defaultAction
);
740 if (status
== wxACC_FAIL
)
743 if (status
== wxACC_NOT_SUPPORTED
)
744 return DISP_E_MEMBERNOTFOUND
;
746 if (status
== wxACC_NOT_IMPLEMENTED
)
748 // Use standard interface instead.
749 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
753 return stdInterface
->get_accDefaultAction (varID
, pszDefaultAction
);
757 if (defaultAction
.IsEmpty())
759 * pszDefaultAction
= NULL
;
764 wxBasicString
basicString(defaultAction
);
765 * pszDefaultAction
= basicString
.Get();
772 // Retrieves a string that describes the visual appearance of the specified object.
773 // Not all objects have a description.
775 STDMETHODIMP
wxIAccessible::get_accDescription ( VARIANT varID
, BSTR
* pszDescription
)
777 wxASSERT (m_pAccessible
!= NULL
);
781 if (varID
.vt
!= VT_I4
)
784 wxString description
;
785 wxAccStatus status
= m_pAccessible
->GetDescription(varID
.lVal
, & description
);
786 if (status
== wxACC_FAIL
)
789 if (status
== wxACC_NOT_IMPLEMENTED
)
791 // Use standard interface instead.
792 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
796 return stdInterface
->get_accDescription (varID
, pszDescription
);
800 if (description
.IsEmpty())
802 * pszDescription
= NULL
;
807 wxBasicString
basicString(description
);
808 * pszDescription
= basicString
.Get();
815 // Retrieves an object's Help property string.
816 // Not all objects support this property.
818 STDMETHODIMP
wxIAccessible::get_accHelp ( VARIANT varID
, BSTR
* pszHelp
)
820 wxASSERT (m_pAccessible
!= NULL
);
824 if (varID
.vt
!= VT_I4
)
828 wxAccStatus status
= m_pAccessible
->GetHelpText(varID
.lVal
, & helpString
);
829 if (status
== wxACC_FAIL
)
832 if (status
== wxACC_NOT_IMPLEMENTED
)
834 // Use standard interface instead.
835 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
839 return stdInterface
->get_accHelp (varID
, pszHelp
);
843 if (helpString
.IsEmpty())
850 wxBasicString
basicString(helpString
);
851 * pszHelp
= basicString
.Get();
858 // Retrieves the full path of the WinHelp file associated with the specified
859 // object and the identifier of the appropriate topic within that file.
860 // Not all objects support this property.
861 // NOTE: not supported by wxWindows at this time. Use
862 // GetHelpText instead.
864 STDMETHODIMP
wxIAccessible::get_accHelpTopic ( BSTR
* pszHelpFile
, VARIANT varChild
, long* pidTopic
)
866 wxASSERT (m_pAccessible
!= NULL
);
870 if (varChild
.vt
!= VT_I4
)
873 wxAccStatus status
= wxACC_NOT_IMPLEMENTED
;
874 if (status
== wxACC_FAIL
)
877 if (status
== wxACC_NOT_IMPLEMENTED
)
879 // Use standard interface instead.
880 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
884 return stdInterface
->get_accHelpTopic (pszHelpFile
, varChild
, pidTopic
);
889 // Retrieves the specified object's shortcut key or access key, also known as
890 // the mnemonic. All objects that have a shortcut key or access key support
893 STDMETHODIMP
wxIAccessible::get_accKeyboardShortcut ( VARIANT varID
, BSTR
* pszKeyboardShortcut
)
895 *pszKeyboardShortcut
= NULL
;
897 wxASSERT (m_pAccessible
!= NULL
);
901 if (varID
.vt
!= VT_I4
)
904 wxString keyboardShortcut
;
905 wxAccStatus status
= m_pAccessible
->GetHelpText(varID
.lVal
, & keyboardShortcut
);
906 if (status
== wxACC_FAIL
)
909 if (status
== wxACC_NOT_IMPLEMENTED
)
911 // Use standard interface instead.
912 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
916 return stdInterface
->get_accKeyboardShortcut(varID
, pszKeyboardShortcut
);
920 if (keyboardShortcut
.IsEmpty())
922 * pszKeyboardShortcut
= NULL
;
927 wxBasicString
basicString(keyboardShortcut
);
928 * pszKeyboardShortcut
= basicString
.Get();
935 // Retrieves the name of the specified object.
936 // All objects support this property.
938 STDMETHODIMP
wxIAccessible::get_accName ( VARIANT varID
, BSTR
* pszName
)
942 wxASSERT (m_pAccessible
!= NULL
);
946 if (varID
.vt
!= VT_I4
)
951 wxAccStatus status
= m_pAccessible
->GetName(varID
.lVal
, & name
);
953 if (status
== wxACC_FAIL
)
956 if (status
== wxACC_NOT_IMPLEMENTED
)
958 // Use standard interface instead.
959 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
963 return stdInterface
->get_accName (varID
, pszName
);
967 wxBasicString
basicString(name
);
968 *pszName
= basicString
.Get();
974 // Retrieves information that describes the role of the specified object.
975 // All objects support this property.
977 STDMETHODIMP
wxIAccessible::get_accRole ( VARIANT varID
, VARIANT
* pVarRole
)
979 wxASSERT (m_pAccessible
!= NULL
);
983 if (varID
.vt
!= VT_I4
)
986 VariantInit(pVarRole
);
988 wxAccRole role
= wxROLE_NONE
;
990 wxAccStatus status
= m_pAccessible
->GetRole(varID
.lVal
, & role
);
992 if (status
== wxACC_FAIL
)
995 if (status
== wxACC_NOT_IMPLEMENTED
)
997 // Use standard interface instead.
998 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
1002 return stdInterface
->get_accRole (varID
, pVarRole
);
1006 if (role
== wxROLE_NONE
)
1008 pVarRole
->vt
= VT_EMPTY
;
1012 pVarRole
->lVal
= wxConvertToWindowsRole(role
);
1013 pVarRole
->vt
= VT_I4
;
1020 // Retrieves the current state of the specified object.
1021 // All objects support this property.
1023 STDMETHODIMP
wxIAccessible::get_accState ( VARIANT varID
, VARIANT
* pVarState
)
1025 wxASSERT (m_pAccessible
!= NULL
);
1029 if (varID
.vt
!= VT_I4
)
1030 return E_INVALIDARG
;
1034 wxAccStatus status
= m_pAccessible
->GetState(varID
.lVal
, & wxstate
);
1035 if (status
== wxACC_FAIL
)
1038 if (status
== wxACC_NOT_IMPLEMENTED
)
1040 // Use standard interface instead.
1041 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
1045 return stdInterface
->get_accState (varID
, pVarState
);
1049 long state
= wxConvertToWindowsState(wxstate
);
1050 pVarState
->lVal
= state
;
1051 pVarState
->vt
= VT_I4
;
1057 // Retrieves the value of the specified object.
1058 // Not all objects have a value.
1060 STDMETHODIMP
wxIAccessible::get_accValue ( VARIANT varID
, BSTR
* pszValue
)
1062 wxASSERT (m_pAccessible
!= NULL
);
1066 if (varID
.vt
!= VT_I4
)
1067 return E_INVALIDARG
;
1071 wxAccStatus status
= m_pAccessible
->GetValue(varID
.lVal
, & strValue
);
1073 if (status
== wxACC_FAIL
)
1076 if (status
== wxACC_NOT_IMPLEMENTED
)
1078 // Use standard interface instead.
1079 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
1083 return stdInterface
->get_accValue (varID
, pszValue
);
1087 wxBasicString
basicString(strValue
);
1088 * pszValue
= basicString
.Get();
1094 // Modifies the selection or moves the keyboard focus of the
1095 // specified object. All objects that select or receive the
1096 // keyboard focus must support this method.
1098 STDMETHODIMP
wxIAccessible::accSelect ( long flagsSelect
, VARIANT varID
)
1100 wxASSERT (m_pAccessible
!= NULL
);
1104 if (varID
.vt
!= VT_I4
)
1105 return E_INVALIDARG
;
1107 wxAccSelectionFlags wxsel
= wxConvertFromWindowsSelFlag(flagsSelect
);
1109 wxAccStatus status
= m_pAccessible
->Select(varID
.lVal
, wxsel
);
1110 if (status
== wxACC_FAIL
)
1113 if (status
== wxACC_NOT_IMPLEMENTED
)
1115 // Use standard interface instead.
1116 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
1120 return stdInterface
->accSelect ( flagsSelect
, varID
);
1128 // Retrieves the object that has the keyboard focus. All objects
1129 // that receive the keyboard focus must support this property.
1131 STDMETHODIMP
wxIAccessible::get_accFocus ( VARIANT
* pVarID
)
1133 wxASSERT (m_pAccessible
!= NULL
);
1137 wxAccessible
* childObject
= NULL
;
1139 VariantInit(pVarID
);
1141 wxAccStatus status
= m_pAccessible
->GetFocus(& childId
, & childObject
);
1142 if (status
== wxACC_FAIL
)
1145 if (status
== wxACC_NOT_IMPLEMENTED
)
1147 // Use standard interface instead.
1148 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
1152 return stdInterface
->get_accFocus (pVarID
);
1156 if (childObject
== m_pAccessible
)
1159 pVarID
->lVal
= CHILDID_SELF
;
1164 wxIAccessible
* childIA
= childObject
->GetIAccessible();
1168 if (childIA
->QueryInterface(IID_IDispatch
, (LPVOID
*) pVarID
->pdispVal
) != S_OK
)
1171 pVarID
->vt
= VT_DISPATCH
;
1172 pVarID
->pdispVal
->AddRef();
1176 else if (childId
> 0)
1179 pVarID
->lVal
= childId
;
1184 pVarID
->vt
= VT_EMPTY
;
1191 // Retrieves the selected children of this object. All objects
1192 // selected must support this property.
1194 STDMETHODIMP
wxIAccessible::get_accSelection ( VARIANT
* pVarChildren
)
1196 wxASSERT (m_pAccessible
!= NULL
);
1200 VariantInit(pVarChildren
);
1202 wxVariant selections
;
1203 wxAccStatus status
= m_pAccessible
->GetSelections(& selections
);
1204 if (status
== wxACC_FAIL
)
1207 if (status
== wxACC_NOT_IMPLEMENTED
)
1209 // Use standard interface instead.
1210 IAccessible
* stdInterface
= (IAccessible
*)m_pAccessible
->GetIAccessibleStd();
1214 return stdInterface
->get_accSelection (pVarChildren
);
1218 if (selections
.GetType() == wxT("long"))
1220 pVarChildren
->vt
= VT_I4
;
1221 pVarChildren
->lVal
= selections
.GetLong();
1225 else if (selections
.GetType() == wxT("void*"))
1227 wxAccessible
* childObject
= (wxAccessible
*) selections
.GetVoidPtr();
1228 wxIAccessible
* childIA
= childObject
->GetIAccessible();
1232 if (childIA
->QueryInterface(IID_IDispatch
, (LPVOID
*) pVarChildren
->pdispVal
) != S_OK
)
1235 pVarChildren
->vt
= VT_DISPATCH
;
1236 pVarChildren
->pdispVal
->AddRef();
1240 else if (selections
.GetType() == wxT("list"))
1242 // TODO: should we AddRef for every "void*" member??
1244 wxIEnumVARIANT
* enumVariant
= new wxIEnumVARIANT(selections
);
1245 enumVariant
->AddRef();
1247 pVarChildren
->vt
= VT_UNKNOWN
;
1248 pVarChildren
->punkVal
= enumVariant
;
1259 STDMETHODIMP
wxIAccessible::GetTypeInfo(unsigned int typeInfo
, LCID lcid
, ITypeInfo
** ppTypeInfo
)
1265 // Get type info count
1267 STDMETHODIMP
wxIAccessible::GetTypeInfoCount(unsigned int* typeInfoCount
)
1275 STDMETHODIMP
wxIAccessible::GetIDsOfNames(REFIID riid
, OLECHAR
** names
, unsigned int cNames
,
1276 LCID lcid
, DISPID
* dispId
)
1283 STDMETHODIMP
wxIAccessible::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1284 WORD wFlags
, DISPPARAMS
*pDispParams
,
1285 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
,
1286 unsigned int *puArgErr
)
1291 // ----------------------------------------------------------------------------
1292 // wxAccessible implementation
1293 // ----------------------------------------------------------------------------
1297 // common part of all ctors
1298 void wxAccessible::Init()
1300 m_pIAccessibleStd
= NULL
;
1301 m_pIAccessible
= new wxIAccessible(this);
1302 m_pIAccessible
->AddRef();
1305 wxAccessible::wxAccessible(wxWindow
* win
)
1306 : wxAccessibleBase(win
)
1311 wxAccessible::~wxAccessible()
1313 m_pIAccessible
->Release();
1314 if (m_pIAccessibleStd
)
1315 ((IAccessible
*)m_pIAccessibleStd
)->Release();
1318 // Gets or creates a standard interface for this object.
1319 void* wxAccessible::GetIAccessibleStd()
1321 if (m_pIAccessibleStd
)
1322 return m_pIAccessibleStd
;
1327 HRESULT retCode
= ::CreateStdAccessibleProxy((HWND
) GetWindow()->GetHWND(),
1328 wxT("wxWindowClass"), OBJID_CLIENT
, IID_IAccessible
, (void**) & m_pIAccessibleStd
);
1330 HRESULT retCode
= ::CreateStdAccessibleObject((HWND
) GetWindow()->GetHWND(),
1331 OBJID_CLIENT
, IID_IAccessible
, (void**) & m_pIAccessibleStd
);
1333 if (retCode
== S_OK
)
1334 return m_pIAccessibleStd
;
1337 m_pIAccessibleStd
= NULL
;
1346 // Convert to Windows role
1347 int wxConvertToWindowsRole(wxAccRole wxrole
)
1351 case wxROLE_SYSTEM_ALERT
:
1352 return ROLE_SYSTEM_ALERT
;
1353 case wxROLE_SYSTEM_ANIMATION
:
1354 return ROLE_SYSTEM_ANIMATION
;
1355 case wxROLE_SYSTEM_APPLICATION
:
1356 return ROLE_SYSTEM_APPLICATION
;
1357 case wxROLE_SYSTEM_BORDER
:
1358 return ROLE_SYSTEM_BORDER
;
1359 case wxROLE_SYSTEM_BUTTONDROPDOWN
:
1360 return ROLE_SYSTEM_BUTTONDROPDOWN
;
1361 case wxROLE_SYSTEM_BUTTONDROPDOWNGRID
:
1362 return ROLE_SYSTEM_BUTTONDROPDOWNGRID
;
1363 case wxROLE_SYSTEM_BUTTONMENU
:
1364 return ROLE_SYSTEM_BUTTONMENU
;
1365 case wxROLE_SYSTEM_CARET
:
1366 return ROLE_SYSTEM_CARET
;
1367 case wxROLE_SYSTEM_CELL
:
1368 return ROLE_SYSTEM_CELL
;
1369 case wxROLE_SYSTEM_CHARACTER
:
1370 return ROLE_SYSTEM_CHARACTER
;
1371 case wxROLE_SYSTEM_CHART
:
1372 return ROLE_SYSTEM_CHART
;
1373 case wxROLE_SYSTEM_CHECKBUTTON
:
1374 return ROLE_SYSTEM_CHECKBUTTON
;
1375 case wxROLE_SYSTEM_CLIENT
:
1376 return ROLE_SYSTEM_CLIENT
;
1377 case wxROLE_SYSTEM_CLOCK
:
1378 return ROLE_SYSTEM_CLOCK
;
1379 case wxROLE_SYSTEM_COLUMN
:
1380 return ROLE_SYSTEM_COLUMN
;
1381 case wxROLE_SYSTEM_COLUMNHEADER
:
1382 return ROLE_SYSTEM_COLUMNHEADER
;
1383 case wxROLE_SYSTEM_COMBOBOX
:
1384 return ROLE_SYSTEM_COMBOBOX
;
1385 case wxROLE_SYSTEM_CURSOR
:
1386 return ROLE_SYSTEM_CURSOR
;
1387 case wxROLE_SYSTEM_DIAGRAM
:
1388 return ROLE_SYSTEM_DIAGRAM
;
1389 case wxROLE_SYSTEM_DIAL
:
1390 return ROLE_SYSTEM_DIAL
;
1391 case wxROLE_SYSTEM_DIALOG
:
1392 return ROLE_SYSTEM_DIALOG
;
1393 case wxROLE_SYSTEM_DOCUMENT
:
1394 return ROLE_SYSTEM_DOCUMENT
;
1395 case wxROLE_SYSTEM_DROPLIST
:
1396 return ROLE_SYSTEM_DROPLIST
;
1397 case wxROLE_SYSTEM_EQUATION
:
1398 return ROLE_SYSTEM_EQUATION
;
1399 case wxROLE_SYSTEM_GRAPHIC
:
1400 return ROLE_SYSTEM_GRAPHIC
;
1401 case wxROLE_SYSTEM_GRIP
:
1402 return ROLE_SYSTEM_GRIP
;
1403 case wxROLE_SYSTEM_GROUPING
:
1404 return ROLE_SYSTEM_GROUPING
;
1405 case wxROLE_SYSTEM_HELPBALLOON
:
1406 return ROLE_SYSTEM_HELPBALLOON
;
1407 case wxROLE_SYSTEM_HOTKEYFIELD
:
1408 return ROLE_SYSTEM_HOTKEYFIELD
;
1409 case wxROLE_SYSTEM_INDICATOR
:
1410 return ROLE_SYSTEM_INDICATOR
;
1411 case wxROLE_SYSTEM_LINK
:
1412 return ROLE_SYSTEM_LINK
;
1413 case wxROLE_SYSTEM_LIST
:
1414 return ROLE_SYSTEM_LIST
;
1415 case wxROLE_SYSTEM_LISTITEM
:
1416 return ROLE_SYSTEM_LISTITEM
;
1417 case wxROLE_SYSTEM_MENUBAR
:
1418 return ROLE_SYSTEM_MENUBAR
;
1419 case wxROLE_SYSTEM_MENUITEM
:
1420 return ROLE_SYSTEM_MENUITEM
;
1421 case wxROLE_SYSTEM_MENUPOPUP
:
1422 return ROLE_SYSTEM_MENUPOPUP
;
1423 case wxROLE_SYSTEM_OUTLINE
:
1424 return ROLE_SYSTEM_OUTLINE
;
1425 case wxROLE_SYSTEM_OUTLINEITEM
:
1426 return ROLE_SYSTEM_OUTLINEITEM
;
1427 case wxROLE_SYSTEM_PAGETAB
:
1428 return ROLE_SYSTEM_PAGETAB
;
1429 case wxROLE_SYSTEM_PAGETABLIST
:
1430 return ROLE_SYSTEM_PAGETABLIST
;
1431 case wxROLE_SYSTEM_PANE
:
1432 return ROLE_SYSTEM_PANE
;
1433 case wxROLE_SYSTEM_PROGRESSBAR
:
1434 return ROLE_SYSTEM_PROGRESSBAR
;
1435 case wxROLE_SYSTEM_PROPERTYPAGE
:
1436 return ROLE_SYSTEM_PROPERTYPAGE
;
1437 case wxROLE_SYSTEM_PUSHBUTTON
:
1438 return ROLE_SYSTEM_PUSHBUTTON
;
1439 case wxROLE_SYSTEM_RADIOBUTTON
:
1440 return ROLE_SYSTEM_RADIOBUTTON
;
1441 case wxROLE_SYSTEM_ROW
:
1442 return ROLE_SYSTEM_ROW
;
1443 case wxROLE_SYSTEM_ROWHEADER
:
1444 return ROLE_SYSTEM_ROWHEADER
;
1445 case wxROLE_SYSTEM_SCROLLBAR
:
1446 return ROLE_SYSTEM_SCROLLBAR
;
1447 case wxROLE_SYSTEM_SEPARATOR
:
1448 return ROLE_SYSTEM_SEPARATOR
;
1449 case wxROLE_SYSTEM_SLIDER
:
1450 return ROLE_SYSTEM_SLIDER
;
1451 case wxROLE_SYSTEM_SOUND
:
1452 return ROLE_SYSTEM_SOUND
;
1453 case wxROLE_SYSTEM_SPINBUTTON
:
1454 return ROLE_SYSTEM_SPINBUTTON
;
1455 case wxROLE_SYSTEM_STATICTEXT
:
1456 return ROLE_SYSTEM_STATICTEXT
;
1457 case wxROLE_SYSTEM_STATUSBAR
:
1458 return ROLE_SYSTEM_STATUSBAR
;
1459 case wxROLE_SYSTEM_TABLE
:
1460 return ROLE_SYSTEM_TABLE
;
1461 case wxROLE_SYSTEM_TEXT
:
1462 return ROLE_SYSTEM_TEXT
;
1463 case wxROLE_SYSTEM_TITLEBAR
:
1464 return ROLE_SYSTEM_TITLEBAR
;
1465 case wxROLE_SYSTEM_TOOLBAR
:
1466 return ROLE_SYSTEM_TOOLBAR
;
1467 case wxROLE_SYSTEM_TOOLTIP
:
1468 return ROLE_SYSTEM_TOOLTIP
;
1469 case wxROLE_SYSTEM_WHITESPACE
:
1470 return ROLE_SYSTEM_WHITESPACE
;
1471 case wxROLE_SYSTEM_WINDOW
:
1472 return ROLE_SYSTEM_WINDOW
;
1477 // Convert to Windows state
1478 long wxConvertToWindowsState(long wxstate
)
1481 if (wxstate
& wxACC_STATE_SYSTEM_ALERT_HIGH
)
1482 state
|= STATE_SYSTEM_ALERT_HIGH
;
1484 if (wxstate
& wxACC_STATE_SYSTEM_ALERT_MEDIUM
)
1485 state
|= STATE_SYSTEM_ALERT_MEDIUM
;
1487 if (wxstate
& wxACC_STATE_SYSTEM_ALERT_LOW
)
1488 state
|= STATE_SYSTEM_ALERT_LOW
;
1490 if (wxstate
& wxACC_STATE_SYSTEM_ANIMATED
)
1491 state
|= STATE_SYSTEM_ANIMATED
;
1493 if (wxstate
& wxACC_STATE_SYSTEM_BUSY
)
1494 state
|= STATE_SYSTEM_BUSY
;
1496 if (wxstate
& wxACC_STATE_SYSTEM_CHECKED
)
1497 state
|= STATE_SYSTEM_CHECKED
;
1499 if (wxstate
& wxACC_STATE_SYSTEM_COLLAPSED
)
1500 state
|= STATE_SYSTEM_COLLAPSED
;
1502 if (wxstate
& wxACC_STATE_SYSTEM_DEFAULT
)
1503 state
|= STATE_SYSTEM_DEFAULT
;
1505 if (wxstate
& wxACC_STATE_SYSTEM_EXPANDED
)
1506 state
|= STATE_SYSTEM_EXPANDED
;
1508 if (wxstate
& wxACC_STATE_SYSTEM_EXTSELECTABLE
)
1509 state
|= STATE_SYSTEM_EXTSELECTABLE
;
1511 if (wxstate
& wxACC_STATE_SYSTEM_FLOATING
)
1512 state
|= STATE_SYSTEM_FLOATING
;
1514 if (wxstate
& wxACC_STATE_SYSTEM_FOCUSABLE
)
1515 state
|= STATE_SYSTEM_FOCUSABLE
;
1517 if (wxstate
& wxACC_STATE_SYSTEM_FOCUSED
)
1518 state
|= STATE_SYSTEM_FOCUSED
;
1520 if (wxstate
& wxACC_STATE_SYSTEM_HOTTRACKED
)
1521 state
|= STATE_SYSTEM_HOTTRACKED
;
1523 if (wxstate
& wxACC_STATE_SYSTEM_INVISIBLE
)
1524 state
|= STATE_SYSTEM_INVISIBLE
;
1526 if (wxstate
& wxACC_STATE_SYSTEM_INVISIBLE
)
1527 state
|= STATE_SYSTEM_INVISIBLE
;
1529 if (wxstate
& wxACC_STATE_SYSTEM_MIXED
)
1530 state
|= STATE_SYSTEM_MIXED
;
1532 if (wxstate
& wxACC_STATE_SYSTEM_MULTISELECTABLE
)
1533 state
|= STATE_SYSTEM_MULTISELECTABLE
;
1535 if (wxstate
& wxACC_STATE_SYSTEM_OFFSCREEN
)
1536 state
|= STATE_SYSTEM_OFFSCREEN
;
1538 if (wxstate
& wxACC_STATE_SYSTEM_PRESSED
)
1539 state
|= STATE_SYSTEM_PRESSED
;
1541 // if (wxstate & wxACC_STATE_SYSTEM_PROTECTED)
1542 // state |= STATE_SYSTEM_PROTECTED;
1544 if (wxstate
& wxACC_STATE_SYSTEM_READONLY
)
1545 state
|= STATE_SYSTEM_READONLY
;
1547 if (wxstate
& wxACC_STATE_SYSTEM_SELECTABLE
)
1548 state
|= STATE_SYSTEM_SELECTABLE
;
1550 if (wxstate
& wxACC_STATE_SYSTEM_SELECTED
)
1551 state
|= STATE_SYSTEM_SELECTED
;
1553 if (wxstate
& wxACC_STATE_SYSTEM_SELFVOICING
)
1554 state
|= STATE_SYSTEM_SELFVOICING
;
1556 if (wxstate
& wxACC_STATE_SYSTEM_UNAVAILABLE
)
1557 state
|= STATE_SYSTEM_UNAVAILABLE
;
1562 // Convert to Windows selection flag
1563 int wxConvertToWindowsSelFlag(wxAccSelectionFlags wxsel
)
1567 if (sel
& wxACC_SEL_TAKEFOCUS
)
1568 sel
|= SELFLAG_TAKEFOCUS
;
1569 if (sel
& wxACC_SEL_TAKESELECTION
)
1570 sel
|= SELFLAG_TAKESELECTION
;
1571 if (sel
& wxACC_SEL_EXTENDSELECTION
)
1572 sel
|= SELFLAG_EXTENDSELECTION
;
1573 if (sel
& wxACC_SEL_ADDSELECTION
)
1574 sel
|= SELFLAG_ADDSELECTION
;
1575 if (sel
& wxACC_SEL_REMOVESELECTION
)
1576 sel
|= SELFLAG_REMOVESELECTION
;
1580 // Convert from Windows selection flag
1581 wxAccSelectionFlags
wxConvertFromWindowsSelFlag(int sel
)
1585 if (sel
& SELFLAG_TAKEFOCUS
)
1586 wxsel
|= wxACC_SEL_TAKEFOCUS
;
1587 if (sel
& SELFLAG_TAKESELECTION
)
1588 wxsel
|= wxACC_SEL_TAKESELECTION
;
1589 if (sel
& SELFLAG_EXTENDSELECTION
)
1590 wxsel
|= wxACC_SEL_EXTENDSELECTION
;
1591 if (sel
& SELFLAG_ADDSELECTION
)
1592 wxsel
|= wxACC_SEL_ADDSELECTION
;
1593 if (sel
& SELFLAG_REMOVESELECTION
)
1594 wxsel
|= wxACC_SEL_REMOVESELECTION
;
1595 return (wxAccSelectionFlags
) wxsel
;
1599 #endif //USE_ACCESSIBILITY