Source code of Windows XP (NT5)
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.

167 lines
3.8 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: customlbacc.cpp
  6. //
  7. // Creator: weiw
  8. //
  9. // Purpose: custom list box accessibility file
  10. //
  11. //=======================================================================
  12. #include <pch.h>
  13. #pragma hdrstop
  14. BSTR GetMYLBItemTitle(DWORD idChild)
  15. {
  16. //DEBUGMSG("GetMYLBItemTitle() called");
  17. static LPCTSTR tszDefItemTitle = _T("");
  18. LRESULT lr = SendMessage(ghWndList, LB_GETITEMDATA, idChild, 0);
  19. if (LB_ERR == lr)
  20. {
  21. return SysAllocString(tszDefItemTitle);
  22. }
  23. LBITEM *pItem = (LBITEM*) lr;
  24. return SysAllocString(pItem->szTitle);
  25. }
  26. BSTR GetMYLBItemDesc(DWORD idChild)
  27. {
  28. //DEBUGMSG("GetMYLBItemDesc() called");
  29. static LPCTSTR tszDefItemDesc = _T("");
  30. _bstr_t bstrItemDesc;
  31. BSTR bsRet = NULL;
  32. LRESULT lr = SendMessage(ghWndList, LB_GETITEMDATA, idChild, 0);
  33. try
  34. {
  35. if (LB_ERR == lr)
  36. {
  37. bstrItemDesc = _bstr_t(tszDefItemDesc);
  38. }
  39. else
  40. {
  41. LBITEM *pItem = (LBITEM*) lr;
  42. bstrItemDesc = _bstr_t(pItem->pszDescription);
  43. if (pItem->bRTF)
  44. {
  45. DEBUGMSG("GetMYLBItemDesc() Item got RTF, adding %S", gtszRTFShortcut);
  46. bstrItemDesc += _bstr_t(gtszRTFShortcut);
  47. }
  48. }
  49. bsRet = bstrItemDesc.copy();
  50. }
  51. catch (...)
  52. {
  53. DEBUGMSG("GetMYLBItemDesc() got _bstr_t exception");
  54. }
  55. return bsRet;
  56. }
  57. DWORD GetMYLBItemState(DWORD idChild)
  58. {
  59. //DEBUGMSG("GetMYLBItemState() called");
  60. DWORD dwState = STATE_SYSTEM_FOCUSABLE|STATE_SYSTEM_SELECTABLE;
  61. LRESULT lr = SendMessage(ghWndList, LB_GETITEMDATA, idChild, 0);
  62. if (LB_ERR == lr)
  63. {
  64. goto done;
  65. }
  66. LBITEM *pItem = (LBITEM*) lr;
  67. if (pItem->bSelect)
  68. {
  69. dwState |= STATE_SYSTEM_CHECKED;
  70. }
  71. if (idChild == gFocusItemId)
  72. {
  73. dwState |= STATE_SYSTEM_FOCUSED|STATE_SYSTEM_SELECTED;
  74. }
  75. done:
  76. return dwState;
  77. }
  78. HRESULT STDMETHODCALLTYPE MYLBAccPropServer::GetPropValue (
  79. const BYTE * pIDString,
  80. DWORD dwIDStringLen,
  81. MSAAPROPID idProp,
  82. VARIANT * pvarValue,
  83. BOOL * pfGotProp )
  84. {
  85. HRESULT hr = S_OK;
  86. BOOL fHoldMYLB = FALSE;
  87. //DEBUGMSG("MYLBAccPropServer::GetPropValue() starts");
  88. if (NULL == pvarValue || NULL == pfGotProp)
  89. {
  90. hr = E_INVALIDARG;
  91. goto done;
  92. }
  93. pvarValue->vt = VT_EMPTY;
  94. *pfGotProp = FALSE;
  95. if (!(fHoldMYLB = TryEnterCriticalSection(&gcsClient))||
  96. ! IsWindow( ghWndList ) ||
  97. GetProp( ghWndList, MYLBALIVEPROP) != (HANDLE)TRUE )
  98. {
  99. DEBUGMSG("GetPropValue() MYLB is not alive any more");
  100. hr = RPC_E_DISCONNECTED;
  101. goto done;
  102. }
  103. HWND hwnd;
  104. DWORD idObject;
  105. DWORD idChild;
  106. if( S_OK != m_pAccPropSvc->DecomposeHwndIdentityString( pIDString, dwIDStringLen,
  107. & hwnd, & idObject, & idChild ) )
  108. {
  109. // problem decomposing identity string - return early...
  110. goto done;
  111. }
  112. if( idChild != CHILDID_SELF )
  113. {
  114. DEBUGMSG("MYLBAccPropServer::GetPropValue() for child Id %lu", idChild);
  115. if (PROPID_ACC_NAME == idProp)
  116. {
  117. pvarValue->bstrVal = GetMYLBItemTitle(idChild-1);
  118. if (NULL == pvarValue->bstrVal)
  119. {
  120. goto done;
  121. }
  122. pvarValue->vt = VT_BSTR;
  123. *pfGotProp = TRUE;
  124. }
  125. else if (PROPID_ACC_STATE == idProp)
  126. {
  127. pvarValue->vt = VT_I4;
  128. pvarValue->lVal = GetMYLBItemState(idChild-1);
  129. *pfGotProp = TRUE;
  130. }
  131. else if (PROPID_ACC_ROLE == idProp)
  132. {
  133. pvarValue->vt = VT_I4;
  134. pvarValue->lVal = ROLE_SYSTEM_CHECKBUTTON;
  135. *pfGotProp = TRUE;
  136. }
  137. else if (PROPID_ACC_DESCRIPTION == idProp)
  138. {
  139. pvarValue->bstrVal = GetMYLBItemDesc(idChild-1);
  140. if (NULL == pvarValue->bstrVal)
  141. {
  142. goto done;
  143. }
  144. pvarValue->vt = VT_BSTR;
  145. *pfGotProp = TRUE;
  146. }
  147. }
  148. done:
  149. if (fHoldMYLB)
  150. {
  151. LeaveCriticalSection(&gcsClient);
  152. }
  153. //DEBUGMSG("MYLBAccPropServer::GetPropValue() ends");
  154. return hr;
  155. }