Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.5 KiB

  1. #include <oleacc.h>
  2. // Generic CAccessibleWrapper class - just calls through on all methods.
  3. // Add overriding behavior in classes derived from this.
  4. class CAccessibleWrapper: public IAccessible,
  5. public IOleWindow,
  6. public IEnumVARIANT
  7. {
  8. private:
  9. // We need to do our own refcounting for this wrapper object
  10. LONG _cRef;
  11. // Need ptr to the IAccessible - also keep around ptrs to EnumVar and
  12. // OleWindow as part of this object, so we can filter those interfaces
  13. // and trap their QI's...
  14. // (We leave pEnumVar and OleWin as NULL until we need them)
  15. IAccessible *_pAcc;
  16. IEnumVARIANT *_pEnumVar;
  17. IOleWindow *_pOleWin;
  18. public:
  19. CAccessibleWrapper(IAccessible *pAcc);
  20. virtual ~CAccessibleWrapper();
  21. // IUnknown
  22. STDMETHODIMP QueryInterface(REFIID riid, void** ppv);
  23. STDMETHODIMP_(ULONG) AddRef();
  24. STDMETHODIMP_(ULONG) Release();
  25. // IDispatch
  26. STDMETHODIMP GetTypeInfoCount(UINT* pctinfo);
  27. STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo);
  28. STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames,
  29. LCID lcid, DISPID* rgdispid);
  30. STDMETHODIMP Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags,
  31. DISPPARAMS* pdp, VARIANT* pvarResult,
  32. EXCEPINFO* pxi, UINT* puArgErr);
  33. // IAccessible
  34. STDMETHODIMP get_accParent(IDispatch ** ppdispParent);
  35. STDMETHODIMP get_accChildCount(long* pChildCount);
  36. STDMETHODIMP get_accChild(VARIANT varChild, IDispatch ** ppdispChild);
  37. STDMETHODIMP get_accName(VARIANT varChild, BSTR* pszName);
  38. STDMETHODIMP get_accValue(VARIANT varChild, BSTR* pszValue);
  39. STDMETHODIMP get_accDescription(VARIANT varChild, BSTR* pszDescription);
  40. STDMETHODIMP get_accRole(VARIANT varChild, VARIANT *pvarRole);
  41. STDMETHODIMP get_accState(VARIANT varChild, VARIANT *pvarState);
  42. STDMETHODIMP get_accHelp(VARIANT varChild, BSTR* pszHelp);
  43. STDMETHODIMP get_accHelpTopic(BSTR* pszHelpFile, VARIANT varChild, long* pidTopic);
  44. STDMETHODIMP get_accKeyboardShortcut(VARIANT varChild, BSTR* pszKeyboardShortcut);
  45. STDMETHODIMP get_accFocus(VARIANT * pvarFocusChild);
  46. STDMETHODIMP get_accSelection(VARIANT * pvarSelectedChildren);
  47. STDMETHODIMP get_accDefaultAction(VARIANT varChild, BSTR* pszDefaultAction);
  48. STDMETHODIMP accSelect(long flagsSel, VARIANT varChild);
  49. STDMETHODIMP accLocation(long* pxLeft, long* pyTop, long* pcxWidth, long* pcyHeight, VARIANT varChild);
  50. STDMETHODIMP accNavigate(long navDir, VARIANT varStart, VARIANT * pvarEndUpAt);
  51. STDMETHODIMP accHitTest(long xLeft, long yTop, VARIANT * pvarChildAtPoint);
  52. STDMETHODIMP accDoDefaultAction(VARIANT varChild);
  53. STDMETHODIMP put_accName(VARIANT varChild, BSTR szName);
  54. STDMETHODIMP put_accValue(VARIANT varChild, BSTR pszValue);
  55. // IEnumVARIANT
  56. STDMETHODIMP Next(ULONG celt, VARIANT* rgvar, ULONG * pceltFetched);
  57. STDMETHODIMP Skip(ULONG celt);
  58. STDMETHODIMP Reset(void);
  59. STDMETHODIMP Clone(IEnumVARIANT ** ppenum);
  60. // IOleWindow
  61. STDMETHODIMP GetWindow(HWND* phwnd);
  62. STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode);
  63. };
  64. template <class T>
  65. static LRESULT CALLBACK AccessibleSubWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, WPARAM uID, ULONG_PTR dwRefData)
  66. {
  67. switch (uMsg)
  68. {
  69. case WM_GETOBJECT:
  70. if (lParam == OBJID_CLIENT)
  71. {
  72. CAccessibleWrapper *pWrapAcc = NULL;
  73. IAccessible *pAcc = NULL;
  74. HRESULT hr = CreateStdAccessibleObject(hWnd, OBJID_CLIENT, IID_PPV_ARG(IAccessible, &pAcc));
  75. if (SUCCEEDED(hr) && pAcc)
  76. {
  77. pWrapAcc = new T(pAcc, dwRefData);
  78. pAcc->Release();
  79. if (pWrapAcc != NULL)
  80. {
  81. LRESULT lres = LresultFromObject(IID_IAccessible, wParam, SAFECAST(pWrapAcc, IAccessible*));
  82. pWrapAcc->Release();
  83. return lres;
  84. }
  85. }
  86. }
  87. break;
  88. case WM_DESTROY:
  89. RemoveWindowSubclass(hWnd, AccessibleSubWndProc<T>, uID);
  90. break;
  91. }
  92. return DefSubclassProc(hWnd, uMsg, wParam, lParam);
  93. }
  94. template <class T>
  95. static STDMETHODIMP WrapAccessibleControl(HWND hWnd, ULONG_PTR dwRefData=0)
  96. {
  97. if (SetWindowSubclass(hWnd, AccessibleSubWndProc<T>, 0, dwRefData))
  98. {
  99. return S_OK;
  100. }
  101. return E_FAIL;
  102. }