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.

397 lines
14 KiB

  1. #ifndef __MARSWIN_H
  2. #define __MARSWIN_H
  3. #include "marsevt.h"
  4. #include "profsvc.h"
  5. //
  6. // The compiler doesn't like this perfectly correct code:
  7. //
  8. // MESSAGE_RANGE_HANDLER(0, 0xFFFF, ForwardToMarsHost);
  9. //
  10. #pragma warning(disable:4296) // expression is always true/false
  11. EXTERN_C const GUID CLASS_CMarsWindow;
  12. EXTERN_C const GUID CLASS_CMarsDocument;
  13. const LONG FLASH_TIMER_ID = 42;
  14. class CMarsPanel;
  15. struct CMarsEventSink
  16. {
  17. CComPtr<IDispatch> m_spDispatchSink;
  18. CComPtr<IUnknown> m_spUnknownOwner;
  19. CMarsEventSink *m_pNext;
  20. BOOL m_fPendingDelete : 1; // Needs to be deleted ASAP
  21. CMarsEventSink(IDispatch *pDispatchSink, IUnknown *pUnknownOwner, CMarsEventSink *pNext)
  22. {
  23. m_spDispatchSink = pDispatchSink;
  24. m_spUnknownOwner = pUnknownOwner;
  25. m_pNext = pNext;
  26. }
  27. };
  28. struct CEventSinkList
  29. {
  30. CMarsEventSink *m_pEventSinks;
  31. int m_cBusyLock; // Not safe to delete items in the list
  32. BOOL m_fPendingDeletes : 1; // Have items to delete
  33. void DoPendingDeletes()
  34. {
  35. if (m_fPendingDeletes)
  36. {
  37. CMarsEventSink **ppNextEventSink = &m_pEventSinks;
  38. CMarsEventSink *pEventSink;
  39. while (*ppNextEventSink)
  40. {
  41. pEventSink = *ppNextEventSink;
  42. if (pEventSink->m_fPendingDelete)
  43. {
  44. *ppNextEventSink = pEventSink->m_pNext;
  45. if (pEventSink->m_pNext)
  46. {
  47. ppNextEventSink = &pEventSink->m_pNext->m_pNext;
  48. }
  49. delete pEventSink;
  50. }
  51. else
  52. {
  53. ppNextEventSink = &pEventSink->m_pNext;
  54. }
  55. }
  56. m_fPendingDeletes = FALSE;
  57. }
  58. }
  59. ~CEventSinkList()
  60. {
  61. CMarsEventSink *pEventSink = m_pEventSinks;
  62. while (NULL != pEventSink)
  63. {
  64. CMarsEventSink *pNextSink = pEventSink->m_pNext;
  65. delete pEventSink;
  66. pEventSink = pNextSink;
  67. }
  68. }
  69. };
  70. struct CMarsPanelProp
  71. {
  72. CComPtr<IUnknown> m_spUnknownOwner;
  73. CComVariant m_var;
  74. CMarsPanelProp(VARIANT& var, IUnknown *pUnknownOwner)
  75. {
  76. m_var = var;
  77. m_spUnknownOwner = pUnknownOwner;
  78. }
  79. };
  80. class CMarsDocument : public CMarsComObject,
  81. public IServiceProvider
  82. {
  83. protected:
  84. virtual ~CMarsDocument();
  85. CMarsDocument();
  86. HRESULT DoPassivate();
  87. HRESULT Init(CMarsWindow *pMarsWindow, CMarsPanel *pHostPanel);
  88. public:
  89. // IUnknown
  90. STDMETHOD_(ULONG, AddRef)();
  91. STDMETHOD_(ULONG, Release)();
  92. STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject);
  93. // IServiceProvider
  94. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppv);
  95. static HRESULT CreateInstance(CMarsWindow *pMarsWindow, CMarsPanel *pHostPanel, CMarsDocument **ppObj);
  96. // Panel/Place methods
  97. HRESULT ReadPanelDefinition(LPCWSTR pwszUrl);
  98. class CPanelCollection *GetPanels() { ATLASSERT(m_spPanels); return m_spPanels; }
  99. class CPlaceCollection *GetPlaces() { ATLASSERT(m_spPlaces); return m_spPlaces; }
  100. HRESULT GetPlaces(IMarsPlaceCollection **ppPlaces);
  101. // Window that the document is in.
  102. CWindow *Window() { return &m_cwndDocument; }
  103. // Window that the application is in.
  104. CMarsWindow *MarsWindow() { ATLASSERT(m_spMarsWindow); return m_spMarsWindow; }
  105. void ForwardMessageToChildren(UINT uMsg, WPARAM wParam, LPARAM lParam);
  106. static HRESULT GetFromUnknown(IUnknown *punk, CMarsDocument **ppMarsDocument)
  107. {
  108. return IUnknown_QueryService(punk, SID_SMarsDocument, CLASS_CMarsDocument, (void **)ppMarsDocument);
  109. }
  110. private:
  111. // Topmost application window + app services
  112. CComClassPtr<CMarsWindow> m_spMarsWindow;
  113. // Panels and places within this document
  114. CComClassPtr<class CPanelCollection> m_spPanels;
  115. CComClassPtr<class CPlaceCollection> m_spPlaces;
  116. // Window for this document (either CMarsWindow or CPanel)
  117. CWindow m_cwndDocument;
  118. // Panel that this doc is hosted in (if any)
  119. CComClassPtr<class CMarsPanel> m_spHostPanel;
  120. };
  121. typedef MarsIDispatchImpl<IMarsWindowOM, &IID_IMarsWindowOM> IMarsWindowOMImpl;
  122. class CMarsWindow :
  123. public CMarsDocument,
  124. public CWindowImpl<CMarsWindow>,
  125. public IMarsWindowOMImpl,
  126. public IProfferServiceImpl,
  127. public IOleInPlaceFrame
  128. {
  129. protected:
  130. virtual ~CMarsWindow();
  131. CMarsWindow();
  132. HRESULT DoPassivate();
  133. HRESULT Init(IMarsHost *pMarsHost, MARSTHREADPARAM *pThreadParam);
  134. HRESULT Startup();
  135. void DoShowWindow(int nCmdShow);
  136. public:
  137. static HRESULT CreateInstance(IMarsHost *pMarsHost, MARSTHREADPARAM *pThreadParam, CMarsWindow **ppObj);
  138. // IUnknown
  139. STDMETHOD_(ULONG, AddRef)();
  140. STDMETHOD_(ULONG, Release)();
  141. STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject);
  142. // IDispatch
  143. IMPLEMENT_IDISPATCH_DELEGATE_TO_BASE(IMarsWindowOMImpl);
  144. // IMarsWindowOM
  145. STDMETHOD(get_active)(VARIANT_BOOL *pbActive);
  146. STDMETHOD(get_minimized)(VARIANT_BOOL *pbMinimized);
  147. STDMETHOD(put_minimized)(VARIANT_BOOL bMinimized);
  148. STDMETHOD(get_maximized)(VARIANT_BOOL *pbMaximized);
  149. STDMETHOD(put_maximized)(VARIANT_BOOL bMaximized);
  150. STDMETHOD(get_title)(BSTR *pbstrTitle);
  151. STDMETHOD(put_title)(BSTR bstrTitle);
  152. STDMETHOD(get_height)(long *plHeight);
  153. STDMETHOD(put_height)(long lHeight);
  154. STDMETHOD(get_width)(long *plWidth);
  155. STDMETHOD(put_width)(long lWidth);
  156. STDMETHOD(get_x)(long *plX);
  157. STDMETHOD(put_x)(long lX);
  158. STDMETHOD(get_y)(long *plY);
  159. STDMETHOD(put_y)(long lY);
  160. STDMETHOD(get_visible)(VARIANT_BOOL *pbVisible);
  161. STDMETHOD(put_visible)(VARIANT_BOOL bVisible);
  162. STDMETHOD(get_panels)(IMarsPanelCollection **ppPanels);
  163. STDMETHOD(get_places)(IMarsPlaceCollection **ppPlaces);
  164. STDMETHOD(setWindowDimensions)( /*[in]*/ long lX, /*[in]*/ long lY, /*[in]*/ long lW, /*[in]*/ long lH );
  165. STDMETHOD(close)();
  166. STDMETHOD(refreshLayout)();
  167. // IServiceProvider methods
  168. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppv);
  169. // IOleWindow
  170. STDMETHODIMP GetWindow(HWND *phwnd);
  171. STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode);
  172. // IOleInPlaceUIWindow
  173. STDMETHODIMP GetBorder(LPRECT lprectBorder);
  174. STDMETHODIMP RequestBorderSpace(LPCBORDERWIDTHS pborderwidths);
  175. STDMETHODIMP SetBorderSpace(LPCBORDERWIDTHS pborderwidths);
  176. STDMETHODIMP SetActiveObject(IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName);
  177. // IOleInPlaceFrame
  178. STDMETHODIMP InsertMenus(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths);
  179. STDMETHODIMP SetMenu(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject);
  180. STDMETHODIMP RemoveMenus(HMENU hmenuShared);
  181. STDMETHODIMP SetStatusText(LPCOLESTR pszStatusText);
  182. STDMETHODIMP EnableModeless(BOOL fEnable);
  183. STDMETHODIMP TranslateAccelerator(LPMSG lpmsg, WORD wID);
  184. // CWindowImpl
  185. static CWndClassInfo& GetWndClassInfo()
  186. {
  187. static CWndClassInfo wc =
  188. {
  189. { sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, StartWindowProc,
  190. 0, 0, NULL, NULL, NULL,
  191. (HBRUSH)(COLOR_WINDOW + 1), NULL, _T("PCHShell Window"), NULL },
  192. NULL, NULL, IDC_ARROW, TRUE, 0, _T("")
  193. };
  194. return wc;
  195. }
  196. BEGIN_MSG_MAP(CMarsWindow)
  197. MESSAGE_RANGE_HANDLER(0, 0xFFFF , ForwardToMarsHost);
  198. MESSAGE_HANDLER (WM_CREATE , OnCreate );
  199. MESSAGE_HANDLER (WM_SIZE , OnSize );
  200. MESSAGE_HANDLER (WM_CLOSE , OnClose );
  201. MESSAGE_HANDLER (WM_NCCALCSIZE , OnNCCalcSize );
  202. MESSAGE_HANDLER (WM_NCACTIVATE , OnNCActivate );
  203. MESSAGE_HANDLER (WM_ACTIVATE , OnActivate );
  204. MESSAGE_HANDLER (WM_ERASEBKGND , OnEraseBkgnd );
  205. MESSAGE_HANDLER (WM_PAINT , OnPaint );
  206. MESSAGE_HANDLER (WM_NCPAINT , OnNCPaint );
  207. MESSAGE_HANDLER (WM_PALETTECHANGED , OnPaletteChanged );
  208. MESSAGE_HANDLER (WM_QUERYNEWPALETTE, OnQueryNewPalette);
  209. MESSAGE_HANDLER (WM_SYSCOLORCHANGE , OnSysColorChange );
  210. MESSAGE_HANDLER (WM_DISPLAYCHANGE , OnDisplayChange );
  211. MESSAGE_HANDLER (WM_SYSCOMMAND , OnSysCommand );
  212. MESSAGE_HANDLER (WM_SETFOCUS , OnSetFocus );
  213. MESSAGE_HANDLER (WM_SETTEXT , OnSetText );
  214. MESSAGE_HANDLER (WM_GETMINMAXINFO , OnGetMinMaxInfo );
  215. END_MSG_MAP()
  216. // Window message handlers
  217. BOOL PreTranslateMessage (MSG &msg);
  218. BOOL TranslateAccelerator(MSG &msg);
  219. LRESULT ForwardToMarsHost(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  220. LRESULT OnCreate (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  221. LRESULT OnSize (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  222. LRESULT OnClose (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  223. LRESULT OnNCCalcSize (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  224. LRESULT OnNCActivate (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  225. LRESULT OnActivate (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  226. LRESULT OnEraseBkgnd (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  227. LRESULT OnPaint (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  228. LRESULT OnNCPaint (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  229. LRESULT OnPaletteChanged (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  230. LRESULT OnQueryNewPalette(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  231. LRESULT OnSysColorChange (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  232. LRESULT OnDisplayChange (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  233. LRESULT OnSysCommand (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  234. LRESULT OnSetFocus (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  235. LRESULT OnSetText (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  236. LRESULT OnGetMinMaxInfo (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  237. ////////////////////////////////////////
  238. void GetMinMaxInfo( CPanelCollection *spPanels, int pos, POINT& ptMin, POINT& ptMax );
  239. void FixLayout ( CPanelCollection *spPanels, int index, RECT rcClient, POINT& ptDiff );
  240. bool CanLayout( /*[in]*/ RECT rcClient );
  241. void FixLayout( /*[in]*/ RECT rcClient );
  242. ////////////////////////////////////////
  243. void OnFinalMessage (HWND hWnd);
  244. // Eventing Methods
  245. STDMETHODIMP ReleaseOwnedObjects(IUnknown *pUnknownOwner);
  246. void CancelEvent(VARIANT_BOOL bCancel) { m_bEventCancelled = bCancel; }
  247. VARIANT_BOOL IsEventCancelled() { return m_bEventCancelled; }
  248. void OnTransitionComplete();
  249. void SetFirstPlace( LPCWSTR szPlace );
  250. // Other methods
  251. HRESULT Passivate();
  252. BOOL IsWindowActive() { return m_fActiveWindow; }
  253. void ShowTitleBar(BOOL fShowTitleBar);
  254. STDMETHODIMP GetSetting(BSTR bstrSubPath, BSTR bstrName, VARIANT *pvarVal);
  255. STDMETHODIMP PutSetting(BSTR bstrSubPath, BSTR bstrName, VARIANT varVal);
  256. STDMETHODIMP PutProperty(BSTR bstrName, VARIANT varVal, IUnknown *punkOwner);
  257. STDMETHODIMP GetProperty(BSTR bstrName, VARIANT *pvarVal);
  258. VARIANT_BOOL get_SingleButtonMouse() { return m_bSingleButtonMouse; }
  259. void put_SingleButtonMouse(VARIANT_BOOL bVal) { m_bSingleButtonMouse = bVal; }
  260. void SpinMessageLoop( BOOL fWait );
  261. HRESULT NotifyHost(MARSHOSTEVENT event, IUnknown *punk, LPARAM lParam)
  262. {
  263. HRESULT hr;
  264. if(m_spMarsHost)
  265. {
  266. hr = m_spMarsHost->OnHostNotify(event, punk, lParam);
  267. if(hr == E_NOTIMPL)
  268. {
  269. hr = S_OK;
  270. }
  271. }
  272. else
  273. {
  274. hr = S_OK;
  275. }
  276. return hr;
  277. }
  278. void GetAccelerators(HACCEL *phAccel, UINT *pcAccel)
  279. {
  280. if (!m_hAccel)
  281. {
  282. ACCEL ac = { 0,0,0 };
  283. m_hAccel = CreateAcceleratorTable(&ac, 1);
  284. }
  285. *phAccel = m_hAccel;
  286. *pcAccel = m_hAccel ? 1 : 0;
  287. }
  288. MARSTHREADPARAM *GetThreadParam()
  289. {
  290. ATLASSERT(m_pThreadParam);
  291. return m_pThreadParam;
  292. };
  293. static HRESULT GetFromUnknown(IUnknown *punk, CMarsWindow **ppMarsWindow)
  294. {
  295. return IUnknown_QueryService(punk, SID_SMarsWindow, CLASS_CMarsWindow, (void **) ppMarsWindow);
  296. }
  297. bool InitWindowPosition( CGlobalSettingsRegKey& regkey, BOOL fWrite );
  298. void SaveWindowPosition( CGlobalSettingsRegKey& regkey );
  299. void LoadWindowPosition( CGlobalSettingsRegKey& regkey, BOOL fAllowMaximized, WINDOWPLACEMENT& wp, BOOL& fMaximized );
  300. protected:
  301. HWND m_hwndFocus;
  302. BOOL m_fActiveWindow : 1; // Are we the active window?
  303. BOOL m_fShowTitleBar : 1;
  304. BOOL m_fStartMaximized : 1; // Will we start off maximized?
  305. BOOL m_fUIPanelsReady : 1; // Have all our UI panels finished loading yet?
  306. BOOL m_fDeferMakeVisible : 1; // Did someone put_visible(TRUE) before the UI was ready?
  307. BOOL m_fEnableModeless : 1; // Should modeless dlgs and stuff be enabled?
  308. BOOL m_fLayoutLocked : 1; // When minimized, layout is locked.
  309. HACCEL m_hAccel;
  310. VARIANT_BOOL m_bEventCancelled;
  311. VARIANT_BOOL m_bSingleButtonMouse;
  312. CComPtr<IMarsHost> m_spMarsHost;
  313. MARSTHREADPARAM* m_pThreadParam;
  314. CComBSTR m_bstrFirstPlace;
  315. };
  316. #endif // __MARSWIN_H