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.

290 lines
11 KiB

  1. // DeskMovr.h : Declaration of the CDeskMovr
  2. #ifndef __DESKMOVR_H_
  3. #define __DESKMOVR_H_
  4. #include "resource.h" // main symbols
  5. #include "admovr2.h"
  6. #include "stdafx.h"
  7. #define IDR_BOGUS_MOVR_REG 23
  8. // Function prototypes
  9. typedef HRESULT (CALLBACK FAR * LPFNCOMPENUM)(COMPONENT * pComp, LPVOID lpvData, DWORD dwData);
  10. typedef HRESULT (CALLBACK FAR * LPFNELEMENUM)(IHTMLElement * pielem, LPVOID lpvData, LONG lData);
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CDeskMovr
  13. class ATL_NO_VTABLE CDeskMovr :
  14. public CComObjectRootEx<CComSingleThreadModel>,
  15. public CComCoClass<CDeskMovr,&CLSID_DeskMovr>,
  16. public CComControl<CDeskMovr>,
  17. public IDeskMovr,
  18. public IOleObjectImpl<CDeskMovr>,
  19. public IPersistPropertyBag,
  20. public IOleControlImpl<CDeskMovr>,
  21. public IOleInPlaceActiveObjectImpl<CDeskMovr>,
  22. public IViewObjectExImpl<CDeskMovr>,
  23. public IOleInPlaceObjectWindowlessImpl<CDeskMovr>,
  24. public IQuickActivateImpl<CDeskMovr>
  25. {
  26. public:
  27. CDeskMovr(void);
  28. ~CDeskMovr(void);
  29. DECLARE_REGISTRY_RESOURCEID(IDR_BOGUS_MOVR_REG)
  30. DECLARE_WND_CLASS(TEXT("DeskMover"));
  31. BEGIN_COM_MAP(CDeskMovr)
  32. COM_INTERFACE_ENTRY(IDeskMovr)
  33. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject, IViewObjectEx)
  34. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject2, IViewObjectEx)
  35. COM_INTERFACE_ENTRY_IMPL(IViewObjectEx)
  36. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleWindow, IOleInPlaceObjectWindowless)
  37. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless)
  38. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceObjectWindowless)
  39. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceActiveObject)
  40. COM_INTERFACE_ENTRY_IMPL(IOleControl)
  41. COM_INTERFACE_ENTRY_IMPL(IOleObject)
  42. COM_INTERFACE_ENTRY(IPersistPropertyBag)
  43. COM_INTERFACE_ENTRY_IMPL(IQuickActivate)
  44. END_COM_MAP()
  45. BEGIN_PROPERTY_MAP(CDeskMovr)
  46. // Example entries
  47. // PROP_ENTRY("Property Description", dispid, clsid)
  48. // PROP_PAGE(CLSID_StockColorPage)
  49. END_PROPERTY_MAP()
  50. BEGIN_MSG_MAP(CDeskMovr)
  51. MESSAGE_HANDLER(WM_PAINT, OnPaint)
  52. MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
  53. MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
  54. MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
  55. MESSAGE_HANDLER(WM_LBUTTONDOWN, OnMouseDown)
  56. MESSAGE_HANDLER(WM_LBUTTONUP, OnMouseUp)
  57. MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
  58. MESSAGE_HANDLER(WM_CAPTURECHANGED, OnCaptureChanged)
  59. MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
  60. ALT_MSG_MAP(1)
  61. MESSAGE_HANDLER(WM_TIMER, OnTimer)
  62. END_MSG_MAP()
  63. // IOleInPlaceObject
  64. virtual STDMETHODIMP InPlaceDeactivate(void);
  65. // IOleObject
  66. STDMETHODIMP GetMiscStatus(DWORD dwAspect, DWORD *pdwStatus);
  67. virtual STDMETHODIMP SetClientSite(IOleClientSite *pClientSite);
  68. // IOleControl method we override to identify a safe time hook up with our partner and
  69. // party on the Trident OM
  70. virtual STDMETHODIMP FreezeEvents(BOOL bFreeze);
  71. // IViewObjectEx
  72. virtual STDMETHODIMP GetViewStatus(DWORD* pdwStatus)
  73. {
  74. ATLTRACE(_T("IViewObjectExImpl::GetViewStatus\n"));
  75. *pdwStatus = VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE;
  76. return S_OK;
  77. }
  78. // IQuickActivate
  79. virtual STDMETHODIMP QuickActivate(QACONTAINER *pQACont, QACONTROL *pQACtrl);
  80. void OnKeyboardHook(WPARAM wParam, LPARAM lParam);
  81. public:
  82. HRESULT OnDraw(ATL_DRAWINFO& di);
  83. // IPersistPropertyBag
  84. // IPersist
  85. virtual STDMETHODIMP GetClassID(CLSID *pClassID)
  86. {
  87. *pClassID = CComCoClass<CDeskMovr,&CLSID_DeskMovr>::GetObjectCLSID();
  88. return S_OK;
  89. }
  90. // IPersistPropertyBag
  91. //
  92. virtual STDMETHODIMP InitNew()
  93. {
  94. ATLTRACE(_T("CDeskMovr::InitNew\n"));
  95. return S_OK;
  96. }
  97. virtual STDMETHODIMP Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog);
  98. virtual STDMETHODIMP Save(LPPROPERTYBAG pPropBag, BOOL fClearDirty, BOOL fSaveAllProperties);
  99. HWND Create(HWND hWndParent, RECT& rcPos, LPCTSTR szWindowName = NULL,
  100. DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, DWORD dwExStyle = 0,
  101. UINT nID = 0)
  102. {
  103. // We override this method inorder to add the WS_CLIPSIBLINGS bit
  104. // to dwStyle, which is needed to prevent the IFrames from flashing
  105. // when the windowed control is moved over them.
  106. ATOM atom = GetWndClassInfo().Register(&m_pfnSuperWindowProc);
  107. return CWindowImplBase::Create(hWndParent, rcPos, szWindowName, dwStyle, dwExStyle,
  108. nID, atom);
  109. }
  110. HRESULT SmartActivateMovr(HRESULT hrPropagate);
  111. protected:
  112. void DeactivateMovr(BOOL fDestroy); // stop timer, release interfaces
  113. HRESULT ActivateMovr(); // start timer, secure interfaces
  114. STDMETHODIMP GetOurStyle(void); // get our control extender's style obj
  115. void _ChangeCapture(BOOL fSet);
  116. BOOL FFindTargetElement( IHTMLElement *pielem, IHTMLElement **ppielem );
  117. HRESULT MoveSelfToTarget( IHTMLElement *pielem, POINT * pptDoc );
  118. void TrackTarget(POINT * pptDoc);
  119. LRESULT OnPaint( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  120. LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  121. LRESULT OnMouseDown( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  122. LRESULT OnMouseUp( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  123. LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  124. LRESULT OnCaptureChanged( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  125. LRESULT OnTimer( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  126. LRESULT OnSetCursor( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  127. HRESULT MoveSelfAndTarget( LONG x, LONG y );
  128. BOOL TrackCaption( POINT * pptDoc );
  129. void DrawCaptionButton(HDC hdc, LPRECT lprc, UINT uType, UINT uState, BOOL fErase);
  130. void DrawCaption(HDC hdc, UINT uDrawFlags, int x, int y);
  131. void UpdateCaption(UINT uDrawFlags);
  132. void CheckCaptionState(int x, int y);
  133. HRESULT _DisplayContextMenu(void);
  134. HRESULT _GetHTMLDoc(IOleClientSite * pocs, IHTMLDocument2 ** pphd2);
  135. HRESULT _IsInElement(HWND hwndParent, POINT * ppt, IHTMLElement ** pphe);
  136. HRESULT _GetZOrderSlot(LONG * plZOrderSlot, BOOL fTop);
  137. HRESULT _HandleZoom(LONG lCommand);
  138. HRESULT _EnumComponents(LPFNCOMPENUM lpfn, LPVOID lpvData, DWORD dwData);
  139. HRESULT _EnumElements(LPFNELEMENUM lpfn, LPVOID lpvData, DWORD dwData);
  140. HRESULT _TrackElement(POINT * ppt, IHTMLElement * pielem, BOOL * fDidWork);
  141. void _MapPoints(int * px, int * py);
  142. int CountActiveCaptions();
  143. // private state information.
  144. //
  145. BOOL m_fEnabled;
  146. long m_lInterval;
  147. int m_cxBorder;
  148. int m_cyBorder;
  149. int m_cyCaption;
  150. int m_cySysCaption;
  151. int m_cyCaptionShow;
  152. int m_cySMBorder;
  153. int m_cxSMBorder;
  154. CContainedWindow m_TimerWnd; // if we're timer-driven, we need this in case we're windowless
  155. enum DragMode {
  156. dmNull = 0, // no dragable part
  157. dmMenu, // caption drop down button for menu
  158. dmClose, // caption button for close
  159. dmRestore, // caption button for restore
  160. dmFullScreen, // caption button for full screen
  161. dmSplit, // caption button for split
  162. // all gadgets on the caption bar should appear before dmMove!
  163. dmMove, // move the component
  164. dmSizeWHBR, // resize width and height from bottom right corner
  165. dmSizeWHTL, // resize width and height from top left corner
  166. dmSizeWHTR, // resize width and height from top right corner
  167. dmSizeWHBL, // resize width and height from bottom left corner
  168. dmSizeTop, // resize from the top edge
  169. dmSizeBottom, // resize from the bottom edge
  170. dmSizeLeft, // resize from the left edge
  171. dmSizeRight, // resize from the right edge
  172. cDragModes // count of drag modes, including dmNull
  173. };
  174. BITBOOL m_fCanResizeX; // Whether this component can be resized in X Direction?
  175. BITBOOL m_fCanResizeY; // Whether this component can be resized in Y Direction?
  176. HRESULT InitAttributes(IHTMLElement *pielem);
  177. HRESULT GetParentWindow(void);
  178. DragMode m_dmCur; // current drag mode, or dmNull if none.
  179. DragMode m_dmTrack; // last drag mode seen by TrackCaption
  180. RECT m_rectInner; // area inside frame, in local coords
  181. RECT m_rectOuter; // outer bounds of mover, in local coords
  182. RECT m_rectCaption; // rect of our pseudo-caption, in local coords
  183. SIZE m_sizeCorner; // size of the corner areas of the frame
  184. BOOL GetCaptionButtonRect(DragMode dm, LPRECT lprc);
  185. void SyncRectsToTarget(void);
  186. DragMode DragModeFromPoint( POINT pt );
  187. HCURSOR CursorFromDragMode( DragMode dm );
  188. HRESULT SizeSelfAndTarget(POINT ptDoc);
  189. void DismissSelfNow(void);
  190. BOOL HandleNonMoveSize(DragMode dm);
  191. HCURSOR m_hcursor;
  192. LONG m_top;
  193. LONG m_left;
  194. LONG m_width;
  195. LONG m_height;
  196. BOOL m_fTimer; // do we have a timer running?
  197. UINT m_uiTimerID;
  198. POINT m_ptMouseCursor; // Mouse cursor at timer
  199. BSTR m_bstrTargetName; // name attribute on targetted html elements
  200. IHTMLStyle *m_pistyle; // our control's style object
  201. IHTMLStyle *m_pistyleTarget; // The style object of our current target, also how we ID it
  202. IHTMLElement *m_pielemTarget; // This interface on the target is how we move and resize it
  203. LONG m_iSrcTarget; // get_sourceIndex value for the current target
  204. BOOL m_fCaptured; // true if mouse-capture/ move operation in progress
  205. LONG m_dx; // delta from mouse down to corner of active gadget
  206. LONG m_dy; // delta from mouse down to corner of active gadget};
  207. DWORD m_CaptionState;
  208. HWND m_hwndParent;
  209. LONG m_zIndexTop;
  210. LONG m_zIndexBottom;
  211. LONG m_cSkipTimer; // Used to allow the dismissal of the mover to take two timer periods.
  212. DWORD m_ItemState;
  213. };
  214. // Defines for DrawCaption
  215. #define DMDC_CAPTION 0x0001
  216. #define DMDC_MENU 0x0002
  217. #define DMDC_CLOSE 0x0004
  218. #define DMDC_RESTORE 0x0008
  219. #define DMDC_FULLSCREEN 0x0010
  220. #define DMDC_SPLIT 0x0020
  221. #define DMDC_ALL (DMDC_CAPTION | DMDC_MENU | DMDC_CLOSE | DMDC_SPLIT | DMDC_FULLSCREEN | DMDC_RESTORE)
  222. // Defines for CaptionState
  223. #define CS_MENUTRACKED 0x00000001
  224. #define CS_MENUPUSHED 0x00000002
  225. #define CS_CLOSETRACKED 0x00000004
  226. #define CS_CLOSEPUSHED 0x00000008
  227. #define CS_RESTORETRACKED 0x00000010
  228. #define CS_RESTOREPUSHED 0x00000020
  229. #define CS_FULLSCREENTRACKED 0x00000040
  230. #define CS_FULLSCREENPUSHED 0x00000080
  231. #define CS_SPLITTRACKED 0x00000100
  232. #define CS_SPLITPUSHED 0x00000200
  233. #endif //__DESKMOVR_H_