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.

439 lines
13 KiB

  1. //****************************************************************************
  2. //
  3. // Copyright (c) 2001-2002, Microsoft Corporation
  4. //
  5. // File: AccessibleWrapper.cpp
  6. //
  7. // Copied from nt\shell\themes\themeui\SettingsPg.h
  8. //
  9. //****************************************************************************
  10. #include "stdafx.h"
  11. #include "SchedMat.h"
  12. #include "AccessibleWrapper.h"
  13. #include "SchedBas.h"
  14. // Pointer to IAccessible object must not be NULL.
  15. CAccessibleWrapper::CAccessibleWrapper (HWND hwnd, IAccessible * pAcc)
  16. : m_ref( 1 ),
  17. m_pAcc( pAcc ),
  18. m_hwnd( hwnd )
  19. {
  20. ASSERT( m_pAcc );
  21. m_pAcc->AddRef();
  22. }
  23. CAccessibleWrapper::~CAccessibleWrapper()
  24. {
  25. m_pAcc->Release();
  26. }
  27. // IUnknown
  28. // Implement refcounting ourselves
  29. // Also implement QI ourselves, so that we return a ptr back to the wrapper.
  30. STDMETHODIMP CAccessibleWrapper::QueryInterface(REFIID riid, void** ppv)
  31. {
  32. *ppv = NULL;
  33. if ((riid == IID_IUnknown) ||
  34. (riid == IID_IDispatch) ||
  35. (riid == IID_IAccessible))
  36. {
  37. *ppv = (IAccessible *) this;
  38. }
  39. else
  40. return(E_NOINTERFACE);
  41. AddRef();
  42. return(NOERROR);
  43. }
  44. STDMETHODIMP_(ULONG) CAccessibleWrapper::AddRef()
  45. {
  46. return ++m_ref;
  47. }
  48. STDMETHODIMP_(ULONG) CAccessibleWrapper::Release()
  49. {
  50. ULONG ulRet = --m_ref;
  51. if( ulRet == 0 )
  52. delete this;
  53. return ulRet;
  54. }
  55. // IDispatch
  56. // - pass all through m_pAcc
  57. STDMETHODIMP CAccessibleWrapper::GetTypeInfoCount(UINT* pctinfo)
  58. {
  59. return m_pAcc->GetTypeInfoCount(pctinfo);
  60. }
  61. STDMETHODIMP CAccessibleWrapper::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
  62. {
  63. return m_pAcc->GetTypeInfo(itinfo, lcid, pptinfo);
  64. }
  65. STDMETHODIMP CAccessibleWrapper::GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames,
  66. LCID lcid, DISPID* rgdispid)
  67. {
  68. return m_pAcc->GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid);
  69. }
  70. STDMETHODIMP CAccessibleWrapper::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
  71. DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo,
  72. UINT* puArgErr)
  73. {
  74. return m_pAcc->Invoke(dispidMember, riid, lcid, wFlags,
  75. pdispparams, pvarResult, pexcepinfo,
  76. puArgErr);
  77. }
  78. // IAccessible
  79. // - pass all through m_pAcc
  80. STDMETHODIMP CAccessibleWrapper::get_accParent(IDispatch ** ppdispParent)
  81. {
  82. return m_pAcc->get_accParent(ppdispParent);
  83. }
  84. STDMETHODIMP CAccessibleWrapper::get_accChildCount(long* pChildCount)
  85. {
  86. return m_pAcc->get_accChildCount(pChildCount);
  87. }
  88. STDMETHODIMP CAccessibleWrapper::get_accChild(VARIANT varChild, IDispatch ** ppdispChild)
  89. {
  90. return m_pAcc->get_accChild(varChild, ppdispChild);
  91. }
  92. STDMETHODIMP CAccessibleWrapper::get_accName(VARIANT varChild, BSTR* pszName)
  93. {
  94. if ( !pszName )
  95. return E_POINTER;
  96. if ( VT_I4 == varChild.vt && CHILDID_SELF == varChild.lVal )
  97. {
  98. const size_t bufLen = 256;
  99. WCHAR szName[bufLen];
  100. if ( 0 == SendMessage (m_hwnd, SCHEDMSG_GETSELDESCRIPTION, bufLen,
  101. (LPARAM) szName) )
  102. {
  103. *pszName = SysAllocString (szName);
  104. if ( *pszName )
  105. return S_OK;
  106. else
  107. return E_OUTOFMEMORY;
  108. }
  109. else
  110. return E_FAIL;
  111. }
  112. else
  113. return m_pAcc->get_accName(varChild, pszName);
  114. }
  115. // NOTICE-2002/02/18-artm CString methods can throw out of memory exceptions.
  116. //
  117. // There is not a good way to handle these exceptions at this level. The caller
  118. // is responsible for handling these exceptions.
  119. STDMETHODIMP CAccessibleWrapper::get_accValue(VARIANT varChild, BSTR* pszValue)
  120. {
  121. // varChild.lVal specifies which sub-part of the component
  122. // is being queried.
  123. // CHILDID_SELF (0) specifies the overall component - other
  124. // non-0 values specify a child.
  125. if ( !pszValue )
  126. return E_POINTER;
  127. if( varChild.vt == VT_I4 && varChild.lVal == CHILDID_SELF )
  128. {
  129. LRESULT nPercentage = SendMessage (m_hwnd, SCHEDMSG_GETPERCENTAGE,
  130. 0, 0L);
  131. CString szValue;
  132. // FUTURE-2002/02/18-artm Check return value from LoadString().
  133. // The code is "okay" as is b/c a failed LoadString() sets the CString
  134. // to the empty string (if the failure comes from not finding the resource).
  135. // Therefore, SysAllocString() at the end of the function will return
  136. // NULL when the resource string cannot be found, and this function
  137. // will report E_OUTOFMEMORY.
  138. //
  139. // However, this behavior relies heavily on undocumented behavior of CString
  140. // and is not immediately obvious. Should be changed in future to check the
  141. // return values.
  142. if ( -1 == nPercentage )
  143. {
  144. szValue.LoadString (IDS_MATRIX_ACC_VALUE_MULTIPLE_CELLS);
  145. }
  146. else
  147. {
  148. HWND hwndParent = GetParent (m_hwnd);
  149. if ( hwndParent )
  150. {
  151. LRESULT nIDD = SendMessage (hwndParent, BASEDLGMSG_GETIDD, 0, 0);
  152. switch ( nIDD )
  153. {
  154. case IDD_REPLICATION_SCHEDULE:
  155. if ( 0 == nPercentage )
  156. szValue.LoadString (IDS_REPLICATION_NOT_AVAILABLE);
  157. else
  158. szValue.LoadString (IDS_REPLICATION_AVAILABLE);
  159. break;
  160. case IDD_DS_SCHEDULE:
  161. switch (nPercentage)
  162. {
  163. case 0:
  164. szValue.LoadString (IDS_DO_NOT_REPLICATE);
  165. break;
  166. case 25:
  167. szValue.LoadString (IDS_REPLICATE_ONCE_PER_HOUR);
  168. break;
  169. case 50:
  170. szValue.LoadString (IDS_REPLICATE_TWICE_PER_HOUR);
  171. break;
  172. case 100:
  173. szValue.LoadString (IDS_REPLICATE_FOUR_TIMES_PER_HOUR);
  174. break;
  175. default:
  176. break;
  177. }
  178. break;
  179. case IDD_DIRSYNC_SCHEDULE:
  180. if ( 0 == nPercentage )
  181. szValue.LoadString (IDS_DONT_SYNCHRONIZE);
  182. else
  183. szValue.LoadString (IDS_SYNCHRONIZE);
  184. break;
  185. case IDD_DIALIN_HOURS:
  186. case IDD_LOGON_HOURS:
  187. if ( 0 == nPercentage )
  188. szValue.LoadString (IDS_LOGON_DENIED);
  189. else
  190. szValue.LoadString (IDS_LOGON_PERMITTED);
  191. break;
  192. default:
  193. break;
  194. }
  195. }
  196. }
  197. *pszValue = SysAllocString (szValue);
  198. if ( *pszValue )
  199. return S_OK;
  200. else
  201. return E_OUTOFMEMORY;
  202. }
  203. else
  204. {
  205. // Pass requests about the sub-components to the
  206. // 'original' IAccessible for us).
  207. return m_pAcc->get_accValue(varChild, pszValue);
  208. }
  209. }
  210. // NOTICE-2002/02/18-artm CString methods can throw out of memory exceptions.
  211. //
  212. // There is not a good way to handle these exceptions at this level. The caller
  213. // is responsible for handling these exceptions.
  214. STDMETHODIMP CAccessibleWrapper::get_accDescription(VARIANT varChild, BSTR* pbstrDescription)
  215. {
  216. if ( !pbstrDescription )
  217. return E_POINTER;
  218. // NTRAID#NTBUG-547327-2002/02/19-artm Need to check that have a valid pointer.
  219. if ( varChild.vt == VT_I4 && varChild.lVal == CHILDID_SELF )
  220. {
  221. CString szDescription;
  222. HWND hwndParent = GetParent (m_hwnd);
  223. if ( hwndParent )
  224. {
  225. // FUTURE-2002/02/18-artm Check return value from LoadString().
  226. // The code is "okay" as is b/c a failed LoadString() sets the CString
  227. // to the empty string (if the failure comes from not finding the resource).
  228. // Therefore, SysAllocString() at the end of the function will return
  229. // NULL when the resource string cannot be found, and this function
  230. // will report E_OUTOFMEMORY.
  231. //
  232. // However, this behavior relies heavily on undocumented behavior of CString
  233. // and is not immediately obvious. Should be changed in future to check the
  234. // return values.
  235. LRESULT nIDD = SendMessage (hwndParent, BASEDLGMSG_GETIDD, 0, 0);
  236. switch ( nIDD )
  237. {
  238. case IDD_REPLICATION_SCHEDULE:
  239. szDescription.LoadString (IDS_REPLICATION_SCHEDULE_ACC_DESCRIPTION);
  240. break;
  241. case IDD_DS_SCHEDULE:
  242. szDescription.LoadString (IDS_DS_SCHEDULE_ACC_DESCRIPTION);
  243. break;
  244. case IDD_DIRSYNC_SCHEDULE:
  245. szDescription.LoadString (IDS_DIRSYNC_SCHEDULE_ACC_DESCRIPTION);
  246. break;
  247. case IDD_DIALIN_HOURS:
  248. szDescription.LoadString (IDS_DIALIN_HOURS_ACC_DESCRIPTION);
  249. break;
  250. case IDD_LOGON_HOURS:
  251. szDescription.LoadString (IDS_LOGON_HOURS_ACC_DESCRIPTION);
  252. break;
  253. default:
  254. break;
  255. }
  256. }
  257. *pbstrDescription = SysAllocString (szDescription);
  258. if ( *pbstrDescription )
  259. return S_OK;
  260. else
  261. return E_OUTOFMEMORY;
  262. }
  263. else
  264. {
  265. return m_pAcc->get_accDescription(varChild, pbstrDescription);
  266. }
  267. }
  268. STDMETHODIMP CAccessibleWrapper::get_accRole(VARIANT varChild, VARIANT *pvarRole)
  269. {
  270. if ( !pvarRole )
  271. return E_POINTER;
  272. if ( VT_I4 == varChild.vt && CHILDID_SELF == varChild.lVal )
  273. {
  274. // reset the out variable
  275. V_VT(pvarRole) = VT_EMPTY;
  276. V_VT(pvarRole) = VT_I4;
  277. V_I4(pvarRole) = ROLE_SYSTEM_TABLE;
  278. return S_OK;
  279. }
  280. else
  281. return m_pAcc->get_accRole(varChild, pvarRole);
  282. }
  283. STDMETHODIMP CAccessibleWrapper::get_accState(VARIANT varChild, VARIANT *pvarState)
  284. {
  285. if ( !pvarState )
  286. return E_POINTER;
  287. if ( VT_I4 == varChild.vt && CHILDID_SELF == varChild.lVal )
  288. {
  289. // reset the out variable
  290. V_VT(pvarState) = VT_EMPTY;
  291. V_VT(pvarState) = VT_I4;
  292. V_I4(pvarState) = STATE_SYSTEM_FOCUSED | STATE_SYSTEM_FOCUSABLE |
  293. STATE_SYSTEM_MULTISELECTABLE | STATE_SYSTEM_SELECTABLE |
  294. STATE_SYSTEM_SELECTED;
  295. return S_OK;
  296. }
  297. else
  298. return m_pAcc->get_accState(varChild, pvarState);
  299. }
  300. STDMETHODIMP CAccessibleWrapper::get_accHelp(VARIANT varChild, BSTR* pszHelp)
  301. {
  302. return m_pAcc->get_accHelp(varChild, pszHelp);
  303. }
  304. STDMETHODIMP CAccessibleWrapper::get_accHelpTopic(BSTR* pszHelpFile, VARIANT varChild, long* pidTopic)
  305. {
  306. return m_pAcc->get_accHelpTopic(pszHelpFile, varChild, pidTopic);
  307. }
  308. STDMETHODIMP CAccessibleWrapper::get_accKeyboardShortcut(VARIANT varChild, BSTR* pszKeyboardShortcut)
  309. {
  310. return m_pAcc->get_accKeyboardShortcut(varChild, pszKeyboardShortcut);
  311. }
  312. STDMETHODIMP CAccessibleWrapper::get_accFocus(VARIANT * pvarFocusChild)
  313. {
  314. return m_pAcc->get_accFocus(pvarFocusChild);
  315. }
  316. STDMETHODIMP CAccessibleWrapper::get_accSelection(VARIANT * pvarSelectedChildren)
  317. {
  318. return m_pAcc->get_accSelection(pvarSelectedChildren);
  319. }
  320. STDMETHODIMP CAccessibleWrapper::get_accDefaultAction(VARIANT varChild, BSTR* pszDefaultAction)
  321. {
  322. return m_pAcc->get_accDefaultAction(varChild, pszDefaultAction);
  323. }
  324. STDMETHODIMP CAccessibleWrapper::accSelect(long flagsSel, VARIANT varChild)
  325. {
  326. return m_pAcc->accSelect(flagsSel, varChild);
  327. }
  328. STDMETHODIMP CAccessibleWrapper::accLocation(long* pxLeft, long* pyTop, long* pcxWidth, long* pcyHeight, VARIANT varChild)
  329. {
  330. return m_pAcc->accLocation(pxLeft, pyTop, pcxWidth, pcyHeight, varChild);
  331. }
  332. STDMETHODIMP CAccessibleWrapper::accNavigate(long navDir, VARIANT varStart, VARIANT * pvarEndUpAt)
  333. {
  334. return m_pAcc->accNavigate(navDir, varStart, pvarEndUpAt);
  335. }
  336. STDMETHODIMP CAccessibleWrapper::accHitTest(long xLeft, long yTop, VARIANT * pvarChildAtPoint)
  337. {
  338. return m_pAcc->accHitTest(xLeft, yTop, pvarChildAtPoint);
  339. }
  340. STDMETHODIMP CAccessibleWrapper::accDoDefaultAction(VARIANT varChild)
  341. {
  342. return m_pAcc->accDoDefaultAction(varChild);
  343. }
  344. STDMETHODIMP CAccessibleWrapper::put_accName(VARIANT varChild, BSTR szName)
  345. {
  346. return m_pAcc->put_accName(varChild, szName);
  347. }
  348. STDMETHODIMP CAccessibleWrapper::put_accValue(VARIANT varChild, BSTR pszValue)
  349. {
  350. return m_pAcc->put_accValue(varChild, pszValue);
  351. }