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.

222 lines
7.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 2001.
  5. //
  6. // File: Toolbar.h
  7. //
  8. // Contents: declaration of CToolbar
  9. //
  10. //----------------------------------------------------------------------------
  11. #ifndef _NUSRMGR_TOOLBAR_H_
  12. #define _NUSRMGR_TOOLBAR_H_
  13. #include "resource.h" // main symbols
  14. #include <atlctl.h>
  15. #define NAVBAR_CX 24
  16. #define PWM_UPDATESIZE (WM_APP + 143)
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CToolbar
  19. class ATL_NO_VTABLE CToolbar :
  20. public CComObjectRootEx<CComSingleThreadModel>,
  21. public IDispatchImpl<IToolbar, &IID_IToolbar, &LIBID_NUSRMGRLib>,
  22. public CComControl<CToolbar>,
  23. public IOleControlImpl<CToolbar>,
  24. public IOleObjectImpl<CToolbar>,
  25. public IOleInPlaceActiveObjectImpl<CToolbar>,
  26. public IViewObjectExImpl<CToolbar>,
  27. public IOleInPlaceObjectWindowlessImpl<CToolbar>,
  28. public IConnectionPointImpl<CToolbar, &DIID_DToolbarEvents>,
  29. //public IPropertyNotifySinkCP<CToolbar>,
  30. public IConnectionPointContainerImpl<CToolbar>,
  31. public IProvideClassInfo2Impl<&CLSID_Toolbar, &DIID_DToolbarEvents, &LIBID_NUSRMGRLib>,
  32. public CComCoClass<CToolbar, &CLSID_Toolbar>
  33. {
  34. public:
  35. CToolbar() :
  36. m_ctlToolbar(_T("ToolbarWindow32"), this, 1),
  37. m_hAccel(NULL), m_pFont(NULL), m_hFont(NULL),
  38. m_himlNBDef(NULL), m_himlNBHot(NULL)
  39. {
  40. m_bWindowOnly = TRUE;
  41. m_bRecomposeOnResize = TRUE;
  42. // This is an educated guess based on the usual height (the width
  43. // doesn't matter).
  44. m_sizeExtent.cx = 5000;
  45. m_sizeExtent.cy = 688; // 26px @ 96dpi
  46. m_sizeNatural.cx = -1;
  47. m_sizeNatural.cy = -1;
  48. }
  49. ~CToolbar()
  50. {
  51. _ClearAmbientFont();
  52. if (m_himlNBDef)
  53. ImageList_Destroy(m_himlNBDef);
  54. if (m_himlNBHot)
  55. ImageList_Destroy(m_himlNBHot);
  56. }
  57. DECLARE_WND_CLASS_EX(_T("UserAccounts.Toolbar"), CS_DBLCLKS, -1)
  58. DECLARE_REGISTRY_RESOURCEID((UINT)0)
  59. DECLARE_NOT_AGGREGATABLE(CToolbar)
  60. //DECLARE_PROTECT_FINAL_CONSTRUCT()
  61. BEGIN_COM_MAP(CToolbar)
  62. COM_INTERFACE_ENTRY(IToolbar)
  63. COM_INTERFACE_ENTRY(IDispatch)
  64. COM_INTERFACE_ENTRY(IViewObjectEx)
  65. COM_INTERFACE_ENTRY(IViewObject2)
  66. COM_INTERFACE_ENTRY(IViewObject)
  67. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  68. COM_INTERFACE_ENTRY(IOleInPlaceObject)
  69. COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
  70. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  71. COM_INTERFACE_ENTRY(IOleControl)
  72. COM_INTERFACE_ENTRY(IOleObject)
  73. COM_INTERFACE_ENTRY(IConnectionPointContainer)
  74. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  75. COM_INTERFACE_ENTRY(IProvideClassInfo)
  76. END_COM_MAP()
  77. BEGIN_CONNECTION_POINT_MAP(CToolbar)
  78. CONNECTION_POINT_ENTRY(DIID_DToolbarEvents)
  79. //CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
  80. END_CONNECTION_POINT_MAP()
  81. BEGIN_MSG_MAP(CToolbar)
  82. NOTIFY_CODE_HANDLER(TBN_GETINFOTIP, _OnGetInfoTip)
  83. MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
  84. COMMAND_RANGE_HANDLER(ID_BACK, ID_HOME, _OnButtonClick)
  85. MESSAGE_HANDLER(WM_APPCOMMAND, _OnAppCommand)
  86. MESSAGE_HANDLER(WM_CREATE, _OnCreate)
  87. MESSAGE_HANDLER(WM_DESTROY, _OnDestroy)
  88. MESSAGE_HANDLER(PWM_UPDATESIZE, _UpdateSize)
  89. CHAIN_MSG_MAP(CComControl<CToolbar>)
  90. ALT_MSG_MAP(1)
  91. // Replace this with message map entries for superclassed ToolbarWindow32
  92. END_MSG_MAP()
  93. // Handler prototypes:
  94. // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  95. // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  96. // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  97. LRESULT _OnGetInfoTip(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
  98. {
  99. LPNMTBGETINFOTIP pgit = (LPNMTBGETINFOTIP)pnmh;
  100. ::LoadString(_Module.GetResourceInstance(),
  101. pgit->iItem + (IDS_TOOLTIP_BACK - ID_BACK),
  102. pgit->pszText,
  103. pgit->cchTextMax);
  104. return 0;
  105. }
  106. LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  107. {
  108. LRESULT lRes = CComControl<CToolbar>::OnSetFocus(uMsg, wParam, lParam, bHandled);
  109. if (m_bInPlaceActive)
  110. {
  111. DoVerbUIActivate(&m_rcPos, NULL);
  112. if(!IsChild(::GetFocus()))
  113. m_ctlToolbar.SetFocus();
  114. }
  115. return lRes;
  116. }
  117. LRESULT _OnButtonClick(WORD, WORD wID, HWND, BOOL&)
  118. {
  119. Fire_OnButtonClick(wID - ID_BACK);
  120. return 0;
  121. }
  122. LRESULT _OnAppCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  123. LRESULT _OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  124. LRESULT _OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  125. LRESULT _UpdateSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  126. // IOleInPlaceObject
  127. STDMETHOD(SetObjectRects)(LPCRECT prcPos, LPCRECT prcClip)
  128. {
  129. IOleInPlaceObjectWindowlessImpl<CToolbar>::SetObjectRects(prcPos, prcClip);
  130. m_ctlToolbar.SetWindowPos(NULL, 0, 0,
  131. prcPos->right - prcPos->left,
  132. prcPos->bottom - prcPos->top,
  133. SWP_NOZORDER | SWP_NOACTIVATE);
  134. return S_OK;
  135. }
  136. // IViewObjectEx
  137. DECLARE_VIEW_STATUS(0)
  138. // IOleControl
  139. STDMETHOD(GetControlInfo)(CONTROLINFO *pci)
  140. {
  141. if (!pci)
  142. return E_POINTER;
  143. pci->hAccel = m_hAccel;
  144. pci->cAccel = m_hAccel ? 3 : 0;
  145. pci->dwFlags = 0;
  146. return S_OK;
  147. }
  148. STDMETHOD(OnAmbientPropertyChange)(DISPID dispid);
  149. STDMETHOD(OnMnemonic)(MSG *pMsg)
  150. {
  151. WORD wID;
  152. if (m_hAccel && ::IsAccelerator(m_hAccel, 3, pMsg, &wID))
  153. {
  154. Fire_OnButtonClick(wID - ID_BACK);
  155. return S_OK;
  156. }
  157. return S_FALSE;
  158. }
  159. // IOleInPlaceActiveObject
  160. STDMETHOD(TranslateAccelerator)(MSG *pMsg)
  161. {
  162. HRESULT hr = IOleInPlaceActiveObjectImpl<CToolbar>::TranslateAccelerator(pMsg);
  163. if (S_FALSE == hr)
  164. {
  165. hr = OnMnemonic(pMsg);
  166. }
  167. return hr;
  168. }
  169. // IOleObject
  170. STDMETHOD(GetMiscStatus)(DWORD /*dwAspect*/, DWORD *pdwStatus)
  171. {
  172. if (!pdwStatus)
  173. return E_POINTER;
  174. *pdwStatus = OLEMISC_RECOMPOSEONRESIZE | OLEMISC_CANTLINKINSIDE | OLEMISC_INSIDEOUT | OLEMISC_ACTIVATEWHENVISIBLE | OLEMISC_SETCLIENTSITEFIRST;
  175. return S_OK;
  176. }
  177. // IToolbar
  178. STDMETHOD(get_enabled)(/*[in]*/ VARIANT vIndex, /*[out, retval]*/ VARIANT_BOOL *pVal);
  179. STDMETHOD(put_enabled)(/*[in]*/ VARIANT vIndex, /*[in]*/ VARIANT_BOOL newVal);
  180. // DToolbarEvents
  181. void Fire_OnButtonClick(int buttonIndex);
  182. private:
  183. void _ClearAmbientFont(void);
  184. void _GetAmbientFont(void);
  185. private:
  186. CContainedWindow m_ctlToolbar;
  187. HACCEL m_hAccel;
  188. IFont *m_pFont;
  189. HFONT m_hFont;
  190. HIMAGELIST m_himlNBDef;
  191. HIMAGELIST m_himlNBHot;
  192. };
  193. #endif //_NUSRMGR_TOOLBAR_H_