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.

431 lines
10 KiB

  1. //
  2. // lbmenu.cpp
  3. //
  4. #include "private.h"
  5. #include "globals.h"
  6. #include "utbmenu.h"
  7. #include "cuimenu.h"
  8. #include "xstring.h"
  9. #include "tipbar.h"
  10. #include "helpers.h"
  11. //////////////////////////////////////////////////////////////////////////////
  12. //
  13. // CUTBMenuWnd
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Initialize
  19. //
  20. //----------------------------------------------------------------------------
  21. CUIFObject *CUTBMenuWnd::Initialize()
  22. {
  23. Assert(!_pTipbarAcc);
  24. _pTipbarAcc = new CTipbarAccessible(this);
  25. return CUIFObject::Initialize();
  26. }
  27. //+---------------------------------------------------------------------------
  28. //
  29. // OnCreate
  30. //
  31. //----------------------------------------------------------------------------
  32. void CUTBMenuWnd::OnCreate(HWND hWnd)
  33. {
  34. if (_pTipbarAcc)
  35. {
  36. _pTipbarAcc->SetWindow(hWnd);
  37. }
  38. }
  39. //+---------------------------------------------------------------------------
  40. //
  41. // OnDestroy
  42. //
  43. //----------------------------------------------------------------------------
  44. void CUTBMenuWnd::OnDestroy(HWND hWnd)
  45. {
  46. //
  47. // MSAA support
  48. //
  49. if (_pTipbarAcc)
  50. {
  51. _pTipbarAcc->NotifyWinEvent( EVENT_OBJECT_DESTROY, this);
  52. _pTipbarAcc->ClearAccItems();
  53. _pTipbarAcc->Release();
  54. _pTipbarAcc = NULL;
  55. }
  56. CoUninit();
  57. }
  58. //+---------------------------------------------------------------------------
  59. //
  60. // OnShowWindow
  61. //
  62. //----------------------------------------------------------------------------
  63. LRESULT CUTBMenuWnd::OnShowWindow( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  64. {
  65. //
  66. // MSAA support
  67. //
  68. if (_pTipbarAcc)
  69. {
  70. if (wParam)
  71. {
  72. _pTipbarAcc->NotifyWinEvent( EVENT_OBJECT_SHOW ,this);
  73. //
  74. // MSCANDUI does this.
  75. //
  76. // REVIEW: KOJIW: Unless we send notify EVENT_OBJECT_FOCUS,
  77. // we never receive WM_GETOBJECT message. Why???
  78. //
  79. _pTipbarAcc->NotifyWinEvent( EVENT_OBJECT_FOCUS ,this);
  80. }
  81. else
  82. {
  83. _pTipbarAcc->NotifyWinEvent( EVENT_OBJECT_HIDE ,this);
  84. }
  85. }
  86. return CUIFMenu::OnShowWindow( hWnd, uMsg, wParam, lParam );
  87. }
  88. //+---------------------------------------------------------------------------
  89. //
  90. // CTipbarWnd::OnTimer
  91. //
  92. //----------------------------------------------------------------------------
  93. void CUTBMenuWnd::OnTimer(UINT uId)
  94. {
  95. switch (uId)
  96. {
  97. case TIPWND_TIMER_DOACCDEFAULTACTION:
  98. //
  99. // MSAA support
  100. //
  101. ::KillTimer(GetWnd(), TIPWND_TIMER_DOACCDEFAULTACTION);
  102. if (_pTipbarAcc && _nDoAccDefaultActionItemId)
  103. {
  104. _pTipbarAcc->DoDefaultActionReal(_nDoAccDefaultActionItemId);
  105. _nDoAccDefaultActionItemId = 0;
  106. }
  107. break;
  108. default:
  109. break;
  110. }
  111. return;
  112. }
  113. //+---------------------------------------------------------------------------
  114. //
  115. // OnGetObject
  116. //
  117. //----------------------------------------------------------------------------
  118. LRESULT CUTBMenuWnd::OnGetObject( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  119. {
  120. LRESULT lResult = (LRESULT)0;
  121. switch (lParam)
  122. {
  123. //
  124. // We process the OBJID_CLIENT object identifier;
  125. // this is the client area of our application
  126. // window.
  127. //
  128. case OBJID_CLIENT:
  129. {
  130. HRESULT hr;
  131. if (_pTipbarAcc == NULL)
  132. {
  133. return E_OUTOFMEMORY;
  134. }
  135. if (!_pTipbarAcc->IsInitialized())
  136. {
  137. //
  138. //
  139. //
  140. hr = EnsureCoInit();
  141. if (FAILED(hr))
  142. {
  143. break;
  144. }
  145. //
  146. // Initialize our Accessible object. If the
  147. // initialization fails, delete the Accessible
  148. // object and return the failure code.
  149. //
  150. hr = _pTipbarAcc->Initialize();
  151. if (FAILED(hr))
  152. {
  153. _pTipbarAcc->Release();
  154. _pTipbarAcc = NULL;
  155. lResult = (LRESULT)hr;
  156. break;
  157. }
  158. //
  159. // Send an EVENT_OBJECT_CREATE WinEvent for the
  160. // creation of the Accessible object for the
  161. // client area.
  162. //
  163. _pTipbarAcc->NotifyWinEvent( EVENT_OBJECT_CREATE , this);
  164. }
  165. //
  166. // Call LresultFromObject() to create reference to
  167. // our Accessible object that MSAA will marshal to
  168. // the client.
  169. //
  170. lResult = _pTipbarAcc->CreateRefToAccObj( wParam );
  171. break;
  172. }
  173. }
  174. return lResult;
  175. }
  176. //+---------------------------------------------------------------------------
  177. //
  178. // StartDoDefaultActionTimer
  179. //
  180. //----------------------------------------------------------------------------
  181. BOOL CUTBMenuWnd::StartDoAccDefaultActionTimer(CUTBMenuItem *pItem)
  182. {
  183. if (!_pTipbarAcc)
  184. return FALSE;
  185. _nDoAccDefaultActionItemId = _pTipbarAcc->GetIDOfItem(pItem);
  186. if ((_nDoAccDefaultActionItemId == 0) || (_nDoAccDefaultActionItemId == -1))
  187. return FALSE;
  188. if (IsWindow(GetWnd()))
  189. {
  190. ::KillTimer(GetWnd(), TIPWND_TIMER_DOACCDEFAULTACTION);
  191. ::SetTimer(GetWnd(),
  192. TIPWND_TIMER_DOACCDEFAULTACTION,
  193. g_uTimerElapseDOACCDEFAULTACTION,
  194. NULL);
  195. }
  196. return TRUE;
  197. }
  198. //////////////////////////////////////////////////////////////////////////////
  199. //
  200. // CUIModalMenu
  201. //
  202. //////////////////////////////////////////////////////////////////////////////
  203. //+---------------------------------------------------------------------------
  204. //
  205. // CancelMenu
  206. //
  207. //----------------------------------------------------------------------------
  208. void CModalMenu::CancelMenu()
  209. {
  210. if (_pCuiMenu)
  211. _pCuiMenu->CancelMenu();
  212. }
  213. //+---------------------------------------------------------------------------
  214. //
  215. // CreateMenu
  216. //
  217. //----------------------------------------------------------------------------
  218. void CModalMenu::PostKey(BOOL fUp, WPARAM wParam, LPARAM lParam)
  219. {
  220. Assert(_pCuiMenu);
  221. _pCuiMenu->PostKey(fUp, wParam, lParam);
  222. }
  223. //////////////////////////////////////////////////////////////////////////////
  224. //
  225. // CUTBLBarMenuItem
  226. //
  227. //////////////////////////////////////////////////////////////////////////////
  228. BOOL CUTBLBarMenuItem::InsertToUI(CUTBMenuWnd *pCuiMenu)
  229. {
  230. UINT uFlags = MF_BYPOSITION;
  231. if (_dwFlags & TF_LBMENUF_SEPARATOR)
  232. {
  233. uFlags |= MF_SEPARATOR;
  234. pCuiMenu->InsertSeparator();
  235. return TRUE;
  236. }
  237. if (_dwFlags & TF_LBMENUF_SUBMENU)
  238. {
  239. Assert(_pUTBMenu);
  240. CUTBMenuWnd *pCuiMenuSub;
  241. CUTBMenuItem *pCuiItem;
  242. pCuiMenuSub = ((CUTBLBarMenu *)_pSubMenu)->CreateMenuUI();
  243. if (!pCuiMenuSub)
  244. return FALSE;
  245. pCuiItem = new CUTBMenuItem(pCuiMenu);
  246. if (!pCuiItem)
  247. {
  248. delete pCuiMenuSub;
  249. return FALSE;
  250. }
  251. pCuiItem->Initialize();
  252. pCuiItem->Init((UINT)-1, _bstr);
  253. pCuiItem->SetSub(pCuiMenuSub);
  254. if (_hbmp)
  255. pCuiItem->SetBitmap(_hbmp);
  256. if (_hbmpMask)
  257. pCuiItem->SetBitmapMask(_hbmpMask);
  258. pCuiMenu->InsertItem(pCuiItem);
  259. if (pCuiMenu->GetAccessible())
  260. pCuiMenu->GetAccessible()->AddAccItem(pCuiItem);
  261. return TRUE;
  262. }
  263. CUTBMenuItem *pCuiItem = new CUTBMenuItem(pCuiMenu);
  264. if (!pCuiItem)
  265. {
  266. return FALSE;
  267. }
  268. pCuiItem->Initialize();
  269. pCuiItem->Init(_uId, _bstr);
  270. if (_dwFlags & TF_LBMENUF_GRAYED)
  271. pCuiItem->Gray(TRUE);
  272. if (_dwFlags & TF_LBMENUF_CHECKED)
  273. pCuiItem->Check(TRUE);
  274. else if (_dwFlags & TF_LBMENUF_RADIOCHECKED)
  275. pCuiItem->RadioCheck(TRUE);
  276. if (_hbmp)
  277. pCuiItem->SetBitmap(_hbmp);
  278. if (_hbmpMask)
  279. pCuiItem->SetBitmapMask(_hbmpMask);
  280. pCuiMenu->InsertItem(pCuiItem);
  281. if (pCuiMenu->GetAccessible())
  282. pCuiMenu->GetAccessible()->AddAccItem(pCuiItem);
  283. return TRUE;
  284. }
  285. //////////////////////////////////////////////////////////////////////////////
  286. //
  287. // CUTBLBarMenu
  288. //
  289. //////////////////////////////////////////////////////////////////////////////
  290. //+---------------------------------------------------------------------------
  291. //
  292. // ctor
  293. //
  294. //----------------------------------------------------------------------------
  295. CUTBLBarMenu::CUTBLBarMenu(HINSTANCE hInst)
  296. {
  297. _hInst = hInst;
  298. }
  299. //+---------------------------------------------------------------------------
  300. //
  301. // dtor
  302. //
  303. //----------------------------------------------------------------------------
  304. CUTBLBarMenu::~CUTBLBarMenu()
  305. {
  306. }
  307. //+---------------------------------------------------------------------------
  308. //
  309. // ShowPopup
  310. //
  311. //----------------------------------------------------------------------------
  312. UINT CUTBLBarMenu::ShowPopup(CUIFWindow *pcuiWndParent, const POINT pt, const RECT *prcArea)
  313. {
  314. if (_pCuiMenu)
  315. return 0;
  316. _pCuiMenu = CreateMenuUI();
  317. if (!_pCuiMenu)
  318. return CUI_MENU_UNSELECTED;
  319. UINT uRet = _pCuiMenu->ShowModalPopup(pcuiWndParent, prcArea, TRUE);
  320. delete _pCuiMenu;
  321. _pCuiMenu = NULL;
  322. return uRet;
  323. }
  324. //+---------------------------------------------------------------------------
  325. //
  326. // CreateMenu
  327. //
  328. //----------------------------------------------------------------------------
  329. CUTBMenuWnd *CUTBLBarMenu::CreateMenuUI()
  330. {
  331. CUTBMenuWnd *pCuiMenu = new CUTBMenuWnd(_hInst, g_dwMenuStyle, 0);
  332. if (!pCuiMenu)
  333. return pCuiMenu;
  334. pCuiMenu->Initialize();
  335. int i;
  336. for (i = 0; i < _rgItem.Count(); i++)
  337. {
  338. CUTBLBarMenuItem *pItem = (CUTBLBarMenuItem *)_rgItem.Get(i);
  339. pItem->InsertToUI(pCuiMenu);
  340. }
  341. return pCuiMenu;
  342. }