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.

306 lines
10 KiB

  1. #ifndef __CompWnd_h__
  2. #define __CompWnd_h__
  3. // This is included to get INmApplet and IComponentWnd
  4. #include "NmCtl1.h"
  5. // This is to get the defs for CProxyIComponentWndEvent
  6. #include "CPCompWndEvent.h"
  7. class ATL_NO_VTABLE CComponentWnd :
  8. public CComObjectRootEx<CComSingleThreadModel>,
  9. public CComCoClass<CComponentWnd, &CLSID_NmAppletFrame>,
  10. public IConnectionPointContainerImpl<CComponentWnd>,
  11. public CProxyIComponentWndEvent<CComponentWnd>,
  12. public CWindowImpl<CComponentWnd>,
  13. public IOleClientSite,
  14. public IOleInPlaceSite,
  15. public IComponentWnd,
  16. public IOleInPlaceFrame,
  17. public INmAppletClientSite
  18. {
  19. // Some Constants
  20. CONSTANT( WND_DEFAULT_WIDTH = 500 );
  21. CONSTANT( WND_DEFAULT_HEIGHT = 300 );
  22. CONSTANT( TOOLBAR_MASK_COLOR = (RGB(255, 0, 255)) );
  23. enum eWndID {
  24. StatusWndID = 1,
  25. #if CompWnd_HasFileMenuAndToolbar
  26. ReBarWndID,
  27. ToolBarWndID
  28. #endif // CompWnd_HasFileMenuAndToolbar
  29. };
  30. #if CompWnd_HasFileMenuAndToolbar
  31. enum eIconIDs {
  32. II_FILE_OPEN = 1,
  33. II_FILE_SAVE = 2,
  34. II_EDIT_CUT = 3,
  35. II_EDIT_COPY = 4,
  36. II_EDIT_PASTE = 5,
  37. II_FILE_PRINT = 6
  38. };
  39. #endif // #if CompWnd_HasFileMenuAndToolbar
  40. public:
  41. // Gconstruction / destruction
  42. CComponentWnd( void );
  43. ~CComponentWnd( void );
  44. //static HRESULT CreateInstance( IComponentWnd** ppNewWnd, REFIID riid, bool bCreate );
  45. protected:
  46. BEGIN_COM_MAP(CComponentWnd)
  47. COM_INTERFACE_ENTRY(IOleClientSite)
  48. COM_INTERFACE_ENTRY(IOleInPlaceFrame)
  49. COM_INTERFACE_ENTRY(IOleInPlaceSite)
  50. COM_INTERFACE_ENTRY2(IOleWindow,IOleInPlaceFrame)
  51. COM_INTERFACE_ENTRY(IOleInPlaceUIWindow)
  52. COM_INTERFACE_ENTRY(IComponentWnd)
  53. COM_INTERFACE_ENTRY(INmAppletClientSite)
  54. COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  55. END_COM_MAP()
  56. BEGIN_CONNECTION_POINT_MAP(CComponentWnd)
  57. CONNECTION_POINT_ENTRY(IID_IComponentWndEvent)
  58. END_CONNECTION_POINT_MAP()
  59. BEGIN_MSG_MAP(CComponentWnd)
  60. MESSAGE_HANDLER(WM_NCDESTROY,OnNcDestroy)
  61. MESSAGE_HANDLER(WM_SIZE, OnSize)
  62. MESSAGE_HANDLER(WM_CLOSE, OnClose)
  63. MESSAGE_HANDLER(WM_CREATE, OnCreate)
  64. MESSAGE_HANDLER(WM_MENUSELECT, OnMenuSelect)
  65. MESSAGE_HANDLER(WM_ACTIVATE, OnActivate);
  66. MESSAGE_HANDLER(WM_COMMAND, OnCommand);
  67. MESSAGE_HANDLER(WM_GETMINMAXINFO, OnGetMinMax);
  68. #if CompWnd_HasFileMenuAndToolbar
  69. COMMAND_ID_HANDLER(ID_FILE_OPEN, cmdFileOpen )
  70. COMMAND_ID_HANDLER(ID_FILE_SAVE, cmdFileSave )
  71. COMMAND_ID_HANDLER(ID_FILE_SAVEAS, cmdFileSaveAs )
  72. COMMAND_ID_HANDLER(ID_FILE_PRINT, cmdFilePrint )
  73. COMMAND_ID_HANDLER(ID_VIEW_TOOLBAR, cmdViewToolBar )
  74. #endif //CompWnd_HasFileMenuAndToolbar
  75. NOTIFY_CODE_HANDLER(TTN_NEEDTEXT, OnNotifyCode_TTN_NEEDTEXT)
  76. ALT_MSG_MAP(StatusWndID)
  77. MESSAGE_HANDLER(WM_NCDESTROY,OnNcDestroy)
  78. MESSAGE_HANDLER(WM_CREATE, OnCreate)
  79. #if CompWnd_HasFileMenuAndToolbar
  80. ALT_MSG_MAP(ReBarWndID)
  81. MESSAGE_HANDLER(WM_NCDESTROY,OnNcDestroy)
  82. MESSAGE_HANDLER(WM_CREATE, OnCreate)
  83. ALT_MSG_MAP(ToolBarWndID)
  84. MESSAGE_HANDLER(WM_NCDESTROY,OnNcDestroy)
  85. MESSAGE_HANDLER(WM_CREATE, OnCreate)
  86. #endif // CompWnd_HasFileMenuAndToolbar
  87. END_MSG_MAP()
  88. DECLARE_REGISTRY_RESOURCEID(IDR_COMPWND)
  89. private:
  90. // Message handlers
  91. LRESULT OnNcDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  92. LRESULT OnMenuSelect(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  93. LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult );
  94. LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult );
  95. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult );
  96. LRESULT OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult );
  97. LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult );
  98. LRESULT OnGetMinMax(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult );
  99. // Command handlers
  100. #if CompWnd_HasFileMenuAndToolbar
  101. LRESULT cmdFileOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  102. LRESULT cmdFileSave(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  103. LRESULT cmdFileSaveAs(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  104. LRESULT cmdFilePrint(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  105. #endif // CompWnd_HasFileMenuAndToolbar
  106. LRESULT cmdViewStatusBar(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  107. LRESULT cmdViewToolBar(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  108. LRESULT cmdHelpHelpTopics(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  109. // Notification handlers
  110. LRESULT OnNotifyCode_TTN_NEEDTEXT(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  111. // IComponentWnd
  112. public:
  113. STDMETHOD(put_CLSID)(/*[in]*/ REFIID riid );
  114. STDMETHOD(get_ControlUnknown)(/*[out]*/ LPUNKNOWN* ppUnk );
  115. STDMETHOD(Create)();
  116. STDMETHOD(Show)(/*[in]*/ BOOL bShow );
  117. STDMETHOD(SetFocus)();
  118. STDMETHOD(Destroy)();
  119. STDMETHOD(SetWindowPos)(LPCRECT pcRect, UINT nFlags );
  120. STDMETHOD(GetWindowRect)(LPRECT pRect);
  121. STDMETHOD(IsChildWindow)(IN HWND hWnd );
  122. STDMETHOD(ShiftFocus)(IN HWND hWndCur, IN BOOL bForward );
  123. // IOleClientSite
  124. public:
  125. STDMETHOD(SaveObject)(void);
  126. STDMETHOD(GetMoniker)(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk);
  127. STDMETHOD(GetContainer)(IOleContainer **ppContainer);
  128. STDMETHOD(ShowObject)(void);
  129. STDMETHOD(OnShowWindow)(BOOL fShow);
  130. STDMETHOD(RequestNewObjectLayout)(void);
  131. // INmAppletClientSite
  132. public:
  133. STDMETHOD(SetStatusBarVisible)(BOOL fShow);
  134. STDMETHOD(SetIcons)(/*[in]*/HICON hIconSmall, /*[in]*/HICON hIconBig );
  135. STDMETHOD(SetWindowText)(/*[in]*/LPCTSTR lpszCaption );
  136. // IOleInPlaceSite
  137. public:
  138. STDMETHOD(CanInPlaceActivate)(void);
  139. STDMETHOD(OnInPlaceActivate)(void);
  140. STDMETHOD(OnUIActivate)(void);
  141. STDMETHOD(GetWindowContext)(IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc,
  142. LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo);
  143. STDMETHOD(Scroll)(SIZE scrollExtant);
  144. STDMETHOD(OnUIDeactivate)(BOOL fUndoable);
  145. STDMETHOD(OnInPlaceDeactivate)( void);
  146. STDMETHOD(DiscardUndoState)( void);
  147. STDMETHOD(DeactivateAndUndo)( void);
  148. STDMETHOD(OnPosRectChange)(LPCRECT lprcPosRect);
  149. // IOleWindow
  150. public:
  151. STDMETHOD (GetWindow) (HWND * phwnd);
  152. STDMETHOD (ContextSensitiveHelp) (BOOL fEnterMode);
  153. // IOleInPlaceUIWindow
  154. public:
  155. STDMETHOD (GetBorder)(LPRECT lprectBorder);
  156. STDMETHOD (RequestBorderSpace)(LPCBORDERWIDTHS lpborderwidths);
  157. STDMETHOD (SetBorderSpace)(LPCBORDERWIDTHS lpborderwidths);
  158. STDMETHOD (SetActiveObject)(IOleInPlaceActiveObject * pActiveObject,
  159. LPCOLESTR lpszObjName);
  160. //IOleInPlaceFrame
  161. public:
  162. STDMETHOD (InsertMenus)(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths);
  163. STDMETHOD (SetMenu)(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject);
  164. STDMETHOD (RemoveMenus)(HMENU hmenuShared);
  165. STDMETHOD (SetStatusText)(LPCOLESTR pszStatusText);
  166. STDMETHOD (EnableModeless)(BOOL fEnable);
  167. STDMETHOD (TranslateAccelerator)(LPMSG lpmsg, WORD wID);
  168. private:
  169. // Helper Fns
  170. HRESULT _CreateStatusBar( void );
  171. #if CompWnd_HasFileMenuAndToolbar
  172. HRESULT _CreateReBar( void );
  173. HRESULT _CreateToolBar( void );
  174. #endif // CompWnd_HasFileMenuAndToolbar
  175. HIMAGELIST _SetTbImageList( int ImListID, int WndMsg );
  176. HIMAGELIST _SetTbImageListSpecialCaseFor_TB_SETDISABLEDIMAGELIST( int ImListID );
  177. HRESULT _GetControlRect( LPRECT prc );
  178. void _InitMenuAndToolbar( void );
  179. bool _IsStatusBarVisibleFlagSet( void );
  180. #if CompWnd_HasFileMenuAndToolbar
  181. bool _IsToolBarVisibleFlagSet( void );
  182. bool _IsReBarVisibleFlagSet( void );
  183. #endif// CompWnd_HasFileMenuAndToolbar
  184. HRESULT _SetMenuItemCheck( UINT idItem, bool bChecked = true );
  185. protected:
  186. // Data members
  187. IOleInPlaceActiveObject* m_pCtlInPlaceActiveObject;
  188. bool m_bSharedMenuActive;
  189. HOLEMENU m_holemenu;
  190. IOleObject* m_pOleObject;
  191. CComPtr<INmApplet> m_spNmApplet;
  192. bool m_bInPlaceActive;
  193. CLSID m_ControlCLSID;
  194. bool m_bCLSIDSet;
  195. CContainedWindow m_hWndStatusBar;
  196. #if CompWnd_HasFileMenuAndToolbar
  197. CContainedWindow m_hWndReBar;
  198. CContainedWindow m_hWndToolBar;
  199. #endif // CompWnd_HasFileMenuAndToolbar
  200. HIMAGELIST m_himlTbButtonNormal;
  201. HIMAGELIST m_himlTbButtonHot;
  202. HIMAGELIST m_himlTbButtonDisabled;
  203. int m_cxToolBarButton;
  204. int m_cyToolBarButton;
  205. int m_cxToolBarButtonBitmap;
  206. int m_cyToolBarButtonBitmap;
  207. int m_IDToolbarBitmap;
  208. int m_IDToolbarBitmapHot;
  209. RECT m_rcComponentToolbarSpace;
  210. };
  211. inline HRESULT MoveMenuToSharedMenu( HMENU hMenu, HMENU hMenuShared, int MenuBarIndex, int InsertionIndex )
  212. {
  213. DBGENTRY(MoveMenuToSharedMenu);
  214. HRESULT hr = S_OK;
  215. if( IsMenu( hMenu ) && IsMenu( hMenuShared ) )
  216. {
  217. TCHAR szMenuItem[ MAX_PATH ] = TEXT("");
  218. int cbMenuItem = 0;
  219. MENUITEMINFO mii;
  220. ClearStruct( &mii );
  221. mii.cbSize = sizeof(MENUITEMINFO);
  222. mii.fMask = MIIM_DATA | MIIM_SUBMENU | MIIM_TYPE;
  223. mii.fType = MFT_STRING;
  224. cbMenuItem = GetMenuString( hMenu, MenuBarIndex, szMenuItem, MAX_PATH, MF_BYPOSITION );
  225. if( 0 != cbMenuItem )
  226. {
  227. mii.cch = 1 + cbMenuItem;
  228. mii.dwTypeData = szMenuItem;
  229. mii.hSubMenu = GetSubMenu( hMenu, MenuBarIndex );
  230. RemoveMenu( hMenu, MenuBarIndex, MF_BYPOSITION );
  231. if( 0 == InsertMenuItem( hMenuShared, InsertionIndex, TRUE, &mii ) )
  232. {
  233. ERROR_OUT(("InsertMenuItem failed"));
  234. hr = HRESULT_FROM_WIN32(GetLastError());
  235. }
  236. }
  237. else
  238. {
  239. ERROR_OUT(("GetMenuString failed"));
  240. hr = E_FAIL;
  241. }
  242. }
  243. else
  244. {
  245. ERROR_OUT(("Passed a bad menu handle"));
  246. hr = E_HANDLE;
  247. }
  248. DBGEXIT_HR( MoveMenuToSharedMenu, hr );
  249. return hr;
  250. }
  251. #endif // __CompWnd_h__