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.

302 lines
8.8 KiB

  1. // DfrgCtl.h : Declaration of the CDfrgCtl
  2. #ifndef __DFRGCTL_H_
  3. #define __DFRGCTL_H_
  4. #pragma warning( disable: 4530 )
  5. #include "resource.h" // main symbols
  6. #include "ESButton.h"
  7. #include "ListView.h"
  8. #include "graphix.h"
  9. #include <vector>
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CDfrgCtl
  12. class ATL_NO_VTABLE CDfrgCtl :
  13. public CComObjectRootEx<CComSingleThreadModel>
  14. ,public CComCoClass<CDfrgCtl, &CLSID_DfrgCtl>
  15. ,public CComControl<CDfrgCtl>
  16. ,public CStockPropImpl<CDfrgCtl, IDfrgCtl, &IID_IDfrgCtl, &LIBID_DFRGUILib>
  17. ,public IProvideClassInfo2Impl<&CLSID_DfrgCtl, NULL, &LIBID_DFRGUILib> // needed
  18. ,public IPersistStreamInitImpl<CDfrgCtl>
  19. ,public IPersistStorageImpl<CDfrgCtl>
  20. ,public IQuickActivateImpl<CDfrgCtl>
  21. ,public IOleControlImpl<CDfrgCtl> // needed
  22. ,public IOleObjectImpl<CDfrgCtl> // needed
  23. ,public IOleInPlaceActiveObjectImpl<CDfrgCtl>
  24. ,public IViewObjectExImpl<CDfrgCtl>
  25. ,public IOleInPlaceObjectWindowlessImpl<CDfrgCtl>
  26. ,public IDataObjectImpl<CDfrgCtl>
  27. ,public ISupportErrorInfo
  28. ,public ISpecifyPropertyPagesImpl<CDfrgCtl>
  29. ,public IConnectionPointContainerImpl<CDfrgCtl>
  30. ,public IConnectionPointImpl<CDfrgCtl,&IID_IDfrgEvents>
  31. {
  32. public:
  33. CDfrgCtl();
  34. virtual ~CDfrgCtl();
  35. DECLARE_REGISTRY_RESOURCEID(IDR_DFRGCTL)
  36. BEGIN_COM_MAP(CDfrgCtl)
  37. COM_INTERFACE_ENTRY(IDfrgCtl)
  38. COM_INTERFACE_ENTRY(IDispatch)
  39. COM_INTERFACE_ENTRY_IMPL(IViewObjectEx)
  40. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject2, IViewObjectEx)
  41. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject, IViewObjectEx)
  42. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless)
  43. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleWindow, IOleInPlaceObjectWindowless)
  44. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceActiveObject)
  45. COM_INTERFACE_ENTRY_IMPL(IOleControl)
  46. COM_INTERFACE_ENTRY_IMPL(IOleObject)
  47. COM_INTERFACE_ENTRY_IMPL(IQuickActivate)
  48. COM_INTERFACE_ENTRY_IMPL(IPersistStorage)
  49. COM_INTERFACE_ENTRY_IMPL(IPersistStreamInit)
  50. COM_INTERFACE_ENTRY(IProvideClassInfo)
  51. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  52. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceObjectWindowless)
  53. COM_INTERFACE_ENTRY_IMPL(IDataObject)
  54. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  55. COM_INTERFACE_ENTRY_IMPL(ISpecifyPropertyPages)
  56. COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  57. END_COM_MAP()
  58. BEGIN_PROPERTY_MAP(CDfrgCtl)
  59. // Example entries
  60. // PROP_ENTRY("Property Description", dispid, clsid)
  61. PROP_PAGE(CLSID_StockColorPage)
  62. END_PROPERTY_MAP()
  63. BEGIN_MSG_MAP(CDfrgCtl)
  64. MESSAGE_HANDLER(WM_PAINT, OnPaint)
  65. MESSAGE_HANDLER(WM_SIZE, OnSize)
  66. MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
  67. MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
  68. MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
  69. MESSAGE_HANDLER(WM_TIMER, OnTimer)
  70. MESSAGE_HANDLER(WM_COMMAND, OnCommand)
  71. MESSAGE_HANDLER(WM_CLOSE, OnClose)
  72. MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
  73. MESSAGE_HANDLER(WM_CONTEXTMENU, OnContextMenu)
  74. END_MSG_MAP()
  75. BEGIN_CONNECTION_POINT_MAP(CDfrgCtl)
  76. CONNECTION_POINT_ENTRY(IID_IDfrgEvents)
  77. END_CONNECTION_POINT_MAP()
  78. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  79. // IViewObjectEx
  80. STDMETHOD(GetViewStatus)(DWORD* pdwStatus)
  81. {
  82. ATLTRACE(_T("IViewObjectExImpl::GetViewStatus\n"));
  83. *pdwStatus = VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE;
  84. return S_OK;
  85. }
  86. // IDfrgCtl
  87. public:
  88. STDMETHOD(get_IsVolListLocked)(/*[out, retval]*/ BOOL *pVal);
  89. STDMETHOD(get_IsDefragInProcess)(/*[out, retval]*/ BOOL *pVal);
  90. STDMETHOD(get_IsEngineRunning)(/*[out, retval]*/ BOOL *pVal);
  91. STDMETHOD(get_IsEnginePaused)(/*[out, retval]*/ BOOL *pVal);
  92. STDMETHOD(get_ReportStatus)(/*[out, retval]*/ BOOL *pVal);
  93. STDMETHOD(get_EngineState)(/*[out, retval]*/ short *pVal);
  94. HRESULT OnNotify(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult);
  95. HRESULT OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult);
  96. HRESULT OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult);
  97. HRESULT OnSizing(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult);
  98. HRESULT OnExitSizeMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult);
  99. HRESULT OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult);
  100. HRESULT OnEraseBkgnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult);
  101. HRESULT SizeWindow();
  102. HRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult);
  103. HRESULT OnFontChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult);
  104. HRESULT OnContextMenu(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult);
  105. HRESULT RefreshListViewRow(CVolume *pVolume);
  106. #ifdef ESI_PROGRESS_BAR
  107. void InvalidateProgressBar(void);
  108. #endif
  109. HRESULT OnTimer(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& lResult);
  110. STDMETHOD(get_Command)(/*[out, retval]*/ short *pVal);
  111. STDMETHOD(put_Command)(/*[in]*/ short newVal);
  112. HRESULT CreateButtons(void);
  113. BOOL PaintClusterMap(IN BOOL bPartialRedraw, HDC WorkDC);
  114. void InvalidateGraphicsWindow(void);
  115. BOOL SizeGraphicsWindow(void);
  116. BOOL DrawButtons(HDC);
  117. void SizeLegend(void);
  118. void SizeButtons(void);
  119. void SetButtonState(void);
  120. HRESULT PreviousTab();
  121. HRESULT NextTab();
  122. STDMETHOD(TranslateAccelerator)(LPMSG pMsg);
  123. LRESULT OnSetFocus(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  124. LRESULT OnKillFocus(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  125. //
  126. // Status change handler.
  127. //
  128. void SendStatusChange( LPCTSTR pszStatus );
  129. //
  130. // Send to advises when control has changed OKToRun property.
  131. //
  132. void SendOKToRun( BOOL bOK );
  133. // these are public cause they are used by the PostMsg
  134. public:
  135. STDMETHOD(get_Enabled)(/*[out, retval]*/ BOOL *pVal);
  136. STDMETHOD(put_Enabled)(/*[in]*/ BOOL newVal);
  137. STDMETHOD(get_IsOkToRun)(/*[out, retval]*/ BOOL *pVal);
  138. BOOL m_bPartialRedraw;
  139. // the graphics wells
  140. RECT rcAnalyzeDisp;
  141. RECT rcDefragDisp;
  142. /////////////////////////////////
  143. // The volume list container
  144. // is public so that PostMessageLocal can see it
  145. /////////////////////////////////
  146. CVolList m_VolumeList;
  147. private:
  148. // used to prevent more than one instance of the control from running
  149. BOOL m_bStart;
  150. BOOL m_bNeedMultiInstanceMessage;
  151. BOOL m_bNeedIllegalVolumeMessage;
  152. DWORD m_dwInstanceRegister;
  153. BOOL m_IsOkToRun;
  154. HANDLE m_hIsOkToRunSemaphore;
  155. HFONT m_hFont;
  156. UINT m_FontHeight;
  157. UINT GetStringWidth(PTCHAR stringBuf, HDC WorkDC);
  158. BOOL IsOnlyInstance();
  159. /////////////////////////////////
  160. // The entire graphics area
  161. /////////////////////////////////
  162. BOOL DrawSingleInstanceScreen(HDC);
  163. RECT m_rcCtlRect;
  164. int m_Margin;
  165. /////////////////////////////////
  166. // Progress Bar
  167. /////////////////////////////////
  168. #ifdef ESI_PROGRESS_BAR
  169. BOOL DrawProgressBar(HDC);
  170. RECT rcProgressBarBG;
  171. RECT rcProgressBar;
  172. BOOL m_IsProgressBarMoved;
  173. int m_ProgressBarOffset; // offset top and bottom in legend window
  174. int m_ProgressBarLength;
  175. #endif
  176. /////////////////////////////////
  177. // Legend
  178. /////////////////////////////////
  179. BOOL DrawLegend(HDC);
  180. RECT rcLegendBG;
  181. int m_LegendTextWidth; // length of all the text if on 1 line
  182. int m_LegendGraphicSpacer;
  183. int m_LegendHeight;
  184. int m_LegendTextSpacer;
  185. int m_LegendTopSpace;
  186. int m_EtchedLineOffset;
  187. int m_BitmapVOffset; // space above and below the legend bitmaps
  188. /////////////////////////////////
  189. // Graphics Area
  190. /////////////////////////////////
  191. BOOL PaintGraphicsWindow(HDC);
  192. RECT rcGraphicsBG; // total BG
  193. // borders around the graphic wells
  194. RECT rcAnalyzeBorder;
  195. RECT rcDefragBorder;
  196. UINT m_GraphicWellSpacer;
  197. UINT m_GraphicWellHeight;
  198. /////////////////////////////////
  199. // Buttons
  200. /////////////////////////////////
  201. BOOL m_ButtonsLocked;
  202. RECT rcButtonBG;
  203. // position of the buttons
  204. // in absolute coodinates
  205. RECT rcDefragButton;
  206. RECT rcAnalyzeButton;
  207. RECT rcPauseButton;
  208. RECT rcCancelButton;
  209. RECT rcReportButton;
  210. // the buttons
  211. HRESULT DestroyButtons(void);
  212. BOOL m_bHaveButtons;
  213. UINT m_ButtonTopBottomSpacer;
  214. UINT m_ButtonHeight;
  215. UINT m_ButtonWidth;
  216. UINT m_ButtonSpacer;
  217. ESButton* m_pAnalyzeButton;
  218. ESButton* m_pDefragButton;
  219. ESButton* m_pPauseButton;
  220. ESButton* m_pStopButton;
  221. ESButton* m_pReportButton;
  222. HRESULT HandleEnterKeyPress();
  223. /////////////////////////////////
  224. // Listview
  225. /////////////////////////////////
  226. CESIListView m_ListView;
  227. RECT rcListView;
  228. // Pointer to CBmp class that holds all the legend bitmap squares
  229. CBmp* m_pLegend;
  230. struct legendData {
  231. int length; // length of legend text plus bitmap plus spacers
  232. VString text; // legend entry text
  233. RECT rcBmp; // rectangle that defines location of bitmap
  234. } m_LegendData[7];
  235. };
  236. using namespace std;
  237. typedef vector< HWND, allocator<HWND> > HWNDVECTOR;
  238. class CTabEnumerator
  239. {
  240. public:
  241. CTabEnumerator( HWND hWndParent, bool fForward )
  242. {
  243. m_hWndParent = hWndParent;
  244. m_fForward = fForward;
  245. };
  246. HWND GetNextTabWindow();
  247. void AddChild( HWND hWnd )
  248. {
  249. //
  250. // Only add this if it is a top-level child.
  251. //
  252. if ( GetParent( hWnd ) == m_hWndParent && IsWindowEnabled( hWnd ) )
  253. m_Children.push_back( hWnd );
  254. }
  255. protected:
  256. HWND m_hWndParent;
  257. HWNDVECTOR m_Children;
  258. bool m_fForward;
  259. };
  260. #endif //__DFRGCTL_H_