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.

384 lines
12 KiB

  1. // MSConfigCtl.h : Declaration of the CMSConfigCtl
  2. #ifndef __MSCONFIGCTL_H_
  3. #define __MSCONFIGCTL_H_
  4. #include "resource.h" // main symbols
  5. #include <atlctl.h>
  6. #include "pagegeneral.h"
  7. #include "pagebootini.h"
  8. #include "pageini.h"
  9. #include "pageinternational.h"
  10. #include "pageregistry.h"
  11. #include "pageservices.h"
  12. #include "pagestartup.h"
  13. #include "msconfigstate.h"
  14. #include "undolog.h"
  15. //=============================================================================
  16. // This class implements the main control for MSConfig. Each page of the
  17. // tab control will be implemented by a distinct object - the objects
  18. // are created here and the tabs are added to the tab control.
  19. //=============================================================================
  20. class ATL_NO_VTABLE CMSConfigCtl :
  21. public CComObjectRootEx<CComSingleThreadModel>,
  22. public IDispatchImpl<IMSConfigCtl, &IID_IMSConfigCtl, &LIBID_MSCONFIGLib>,
  23. public CComCompositeControl<CMSConfigCtl>,
  24. public IPersistStreamInitImpl<CMSConfigCtl>,
  25. public IOleControlImpl<CMSConfigCtl>,
  26. public IOleObjectImpl<CMSConfigCtl>,
  27. public IOleInPlaceActiveObjectImpl<CMSConfigCtl>,
  28. public IViewObjectExImpl<CMSConfigCtl>,
  29. public IOleInPlaceObjectWindowlessImpl<CMSConfigCtl>,
  30. public IPersistStorageImpl<CMSConfigCtl>,
  31. public ISpecifyPropertyPagesImpl<CMSConfigCtl>,
  32. public IQuickActivateImpl<CMSConfigCtl>,
  33. public IDataObjectImpl<CMSConfigCtl>,
  34. public IProvideClassInfo2Impl<&CLSID_MSConfigCtl, NULL, &LIBID_MSCONFIGLib>,
  35. public CComCoClass<CMSConfigCtl, &CLSID_MSConfigCtl>
  36. {
  37. public:
  38. CMSConfigCtl() :
  39. m_hwndParent(NULL),
  40. m_fDoNotRun(FALSE),
  41. m_fRunningInHelpCtr(FALSE)
  42. {
  43. m_bWindowOnly = TRUE;
  44. CalcExtent(m_sizeExtent);
  45. }
  46. DECLARE_REGISTRY_RESOURCEID(IDR_MSCONFIGCTL)
  47. DECLARE_PROTECT_FINAL_CONSTRUCT()
  48. BEGIN_COM_MAP(CMSConfigCtl)
  49. COM_INTERFACE_ENTRY(IMSConfigCtl)
  50. COM_INTERFACE_ENTRY(IDispatch)
  51. COM_INTERFACE_ENTRY(IViewObjectEx)
  52. COM_INTERFACE_ENTRY(IViewObject2)
  53. COM_INTERFACE_ENTRY(IViewObject)
  54. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  55. COM_INTERFACE_ENTRY(IOleInPlaceObject)
  56. COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
  57. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  58. COM_INTERFACE_ENTRY(IOleControl)
  59. COM_INTERFACE_ENTRY(IOleObject)
  60. COM_INTERFACE_ENTRY(IPersistStreamInit)
  61. COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
  62. COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
  63. COM_INTERFACE_ENTRY(IQuickActivate)
  64. COM_INTERFACE_ENTRY(IPersistStorage)
  65. COM_INTERFACE_ENTRY(IDataObject)
  66. COM_INTERFACE_ENTRY(IProvideClassInfo)
  67. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  68. END_COM_MAP()
  69. BEGIN_PROP_MAP(CMSConfigCtl)
  70. PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
  71. PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
  72. // Example entries
  73. // PROP_ENTRY("Property Description", dispid, clsid)
  74. // PROP_PAGE(CLSID_StockColorPage)
  75. END_PROP_MAP()
  76. BEGIN_MSG_MAP(CMSConfigCtl)
  77. CHAIN_MSG_MAP(CComCompositeControl<CMSConfigCtl>)
  78. MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
  79. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  80. NOTIFY_HANDLER(IDC_MSCONFIGTAB, TCN_SELCHANGE, OnSelChangeMSConfigTab)
  81. NOTIFY_HANDLER(IDC_MSCONFIGTAB, TCN_SELCHANGING, OnSelChangingMSConfigTab)
  82. COMMAND_HANDLER(IDC_BUTTONCANCEL, BN_CLICKED, OnClickedButtonCancel)
  83. COMMAND_HANDLER(IDC_BUTTONOK, BN_CLICKED, OnClickedButtonOK)
  84. END_MSG_MAP()
  85. // Handler prototypes:
  86. // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  87. // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  88. // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  89. BEGIN_SINK_MAP(CMSConfigCtl)
  90. //Make sure the Event Handlers have __stdcall calling convention
  91. END_SINK_MAP()
  92. STDMETHOD(OnAmbientPropertyChange)(DISPID dispid)
  93. {
  94. if (dispid == DISPID_AMBIENT_BACKCOLOR)
  95. {
  96. SetBackgroundColorFromAmbient();
  97. FireViewChange();
  98. }
  99. return IOleControlImpl<CMSConfigCtl>::OnAmbientPropertyChange(dispid);
  100. }
  101. // IViewObjectEx
  102. DECLARE_VIEW_STATUS(0)
  103. // IMSConfigCtl
  104. public:
  105. STDMETHOD(SetParentHWND)(DWORD_PTR dwHWND);
  106. //-------------------------------------------------------------------------
  107. // When the control is initialized (we'll catch the dialog init message),
  108. // the classes which implement each individual page of the tab control
  109. // should be created and added to the control.
  110. //-------------------------------------------------------------------------
  111. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  112. {
  113. // Determine where this control is being created. If it's a normal
  114. // web page (http:), then we shouldn't work at all. If it's in Help Center
  115. // (hcp:), then we should present a limited functionality. If we're
  116. // hosted in an executable, we should present full functionality.
  117. CheckRunState();
  118. if (m_fDoNotRun)
  119. {
  120. ::ShowWindow(GetDlgItem(IDC_BUTTONOK), SW_HIDE);
  121. ::ShowWindow(GetDlgItem(IDC_BUTTONCANCEL), SW_HIDE);
  122. ::ShowWindow(GetDlgItem(IDC_BUTTONAPPLY), SW_HIDE);
  123. ::ShowWindow(GetDlgItem(IDC_PLACEHOLDER), SW_HIDE);
  124. ::ShowWindow(GetDlgItem(IDC_MSCONFIGTAB), SW_HIDE);
  125. ::ShowWindow(GetDlgItem(IDC_STATICWONTRUN), SW_SHOW);
  126. return 0;
  127. }
  128. else if (m_fRunningInHelpCtr)
  129. {
  130. ::ShowWindow(GetDlgItem(IDC_BUTTONOK), SW_HIDE);
  131. ::ShowWindow(GetDlgItem(IDC_BUTTONCANCEL), SW_HIDE);
  132. }
  133. ::EnableWindow(GetDlgItem(IDC_BUTTONAPPLY), FALSE);
  134. // Get a window for the static control on the dialog which is going
  135. // to serve as a size rect for the property pages. Hide it, and get
  136. // the rectangle for it.
  137. RECT rectTabPage;
  138. m_wndPlaceHolder.Attach(GetDlgItem(IDC_PLACEHOLDER));
  139. m_wndPlaceHolder.ShowWindow(SW_HIDE);
  140. m_wndPlaceHolder.GetWindowRect(&rectTabPage);
  141. ScreenToClient(&rectTabPage);
  142. // Load all of the tab pages into the tab control, then select the
  143. // first one.
  144. BOOL bDummy;
  145. LoadTabPages(rectTabPage);
  146. TabCtrl_SetCurSel(GetDlgItem(IDC_MSCONFIGTAB), 0);
  147. OnSelChangeMSConfigTab(0, NULL, bDummy);
  148. return 0;
  149. }
  150. //-------------------------------------------------------------------------
  151. // Determine where the control is being created, and set the member
  152. // variables m_fRunningInHelpCtr and m_fDoNotRun appropriately.
  153. //-------------------------------------------------------------------------
  154. void CheckRunState()
  155. {
  156. m_fRunningInHelpCtr = m_fDoNotRun = FALSE;
  157. CComPtr<IOleContainer> spContainer;
  158. m_spClientSite->GetContainer(&spContainer);
  159. CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spHTMLDocument(spContainer);
  160. if (spHTMLDocument)
  161. {
  162. BSTR bstrURL;
  163. if (SUCCEEDED(spHTMLDocument->get_URL(&bstrURL)))
  164. {
  165. CString strURL(bstrURL);
  166. strURL.MakeLower();
  167. if (strURL.Left(5) == CString(_T("http:")))
  168. m_fDoNotRun = TRUE;
  169. else if (strURL.Left(5) == CString(_T("file:")))
  170. m_fDoNotRun = TRUE;
  171. else if (strURL.Left(4) == CString(_T("hcp:")))
  172. m_fRunningInHelpCtr = TRUE;
  173. // Include the following when we want to test the control
  174. // using a local URL.
  175. //
  176. // if (strURL.Left(5) == CString(_T("file:")))
  177. // m_fDoNotRun = FALSE;
  178. SysFreeString(bstrURL);
  179. }
  180. }
  181. }
  182. //-------------------------------------------------------------------------
  183. // Load each of the pages which are going to be put on the tab control.
  184. // Each one will get a chance to elect to not participate (for example if
  185. // it doesn't apply to this OS).
  186. //-------------------------------------------------------------------------
  187. void LoadTabPages(RECT & rectTabPage)
  188. {
  189. int iTabIndex = 0;
  190. if (m_pageGeneral.IsValid(&m_state))
  191. {
  192. m_pageGeneral.Create(this->m_hWnd, rectTabPage);
  193. m_pageGeneral.MoveWindow(&rectTabPage);
  194. AddTab(iTabIndex++, (CWindow *)&m_pageGeneral, m_pageGeneral.GetCaption());
  195. }
  196. if (m_pageSystemIni.IsValid(&m_state, _T("system.ini")))
  197. {
  198. m_pageSystemIni.Create(this->m_hWnd, rectTabPage);
  199. m_pageSystemIni.MoveWindow(&rectTabPage);
  200. AddTab(iTabIndex++, (CWindow *)&m_pageSystemIni, m_pageSystemIni.GetCaption());
  201. }
  202. if (m_pageWinIni.IsValid(&m_state, _T("win.ini")))
  203. {
  204. m_pageWinIni.Create(this->m_hWnd, rectTabPage);
  205. m_pageWinIni.MoveWindow(&rectTabPage);
  206. AddTab(iTabIndex++, (CWindow *)&m_pageWinIni, m_pageWinIni.GetCaption());
  207. }
  208. if (m_pageBootIni.IsValid(&m_state))
  209. {
  210. m_pageBootIni.Create(this->m_hWnd, rectTabPage);
  211. m_pageBootIni.MoveWindow(&rectTabPage);
  212. AddTab(iTabIndex++, (CWindow *)&m_pageBootIni, m_pageBootIni.GetCaption());
  213. }
  214. if (m_pageStartup.IsValid(&m_state))
  215. {
  216. m_pageStartup.Create(this->m_hWnd, rectTabPage);
  217. m_pageStartup.MoveWindow(&rectTabPage);
  218. AddTab(iTabIndex++, (CWindow *)&m_pageStartup, m_pageStartup.GetCaption());
  219. }
  220. if (m_pageServices.IsValid(&m_state))
  221. {
  222. m_pageServices.Create(this->m_hWnd, rectTabPage);
  223. m_pageServices.MoveWindow(&rectTabPage);
  224. AddTab(iTabIndex++, (CWindow *)&m_pageServices, m_pageServices.GetCaption());
  225. }
  226. if (m_pageRegistry.IsValid(&m_state))
  227. {
  228. m_pageRegistry.Create(this->m_hWnd, rectTabPage);
  229. m_pageRegistry.MoveWindow(&rectTabPage);
  230. AddTab(iTabIndex++, (CWindow *)&m_pageRegistry, m_pageRegistry.GetCaption());
  231. }
  232. if (m_pageInternational.IsValid(&m_state))
  233. {
  234. m_pageInternational.Create(this->m_hWnd, rectTabPage);
  235. m_pageInternational.MoveWindow(&rectTabPage);
  236. AddTab(iTabIndex++, (CWindow *)&m_pageInternational, m_pageInternational.GetCaption());
  237. }
  238. }
  239. //-------------------------------------------------------------------------
  240. // Creates a new tab in the tab control using the provided CWindow.
  241. //-------------------------------------------------------------------------
  242. void AddTab(int iTabIndex, CWindow * pPage, LPCTSTR szName)
  243. {
  244. pPage->ShowWindow(SW_HIDE);
  245. TCITEM tci;
  246. tci.mask = TCIF_PARAM | TCIF_TEXT;
  247. tci.pszText = (LPTSTR)szName;
  248. tci.lParam = (LPARAM)pPage;
  249. TabCtrl_InsertItem(GetDlgItem(IDC_MSCONFIGTAB), iTabIndex, &tci);
  250. }
  251. //-------------------------------------------------------------------------
  252. // When the user selects a new tab, we hide the CWindow associated with
  253. // the old tab and show the CWindow associated with the new tab.
  254. //-------------------------------------------------------------------------
  255. LRESULT OnSelChangeMSConfigTab(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  256. {
  257. CWindow * pNewWindow = GetTabWindow(TabCtrl_GetCurSel(GetDlgItem(IDC_MSCONFIGTAB)));
  258. ASSERT(pNewWindow);
  259. if (pNewWindow)
  260. pNewWindow->ShowWindow(SW_SHOW);
  261. return 0;
  262. }
  263. LRESULT OnSelChangingMSConfigTab(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  264. {
  265. CWindow * pOldWindow = GetTabWindow(TabCtrl_GetCurSel(GetDlgItem(IDC_MSCONFIGTAB)));
  266. ASSERT(pOldWindow);
  267. if (pOldWindow)
  268. pOldWindow->ShowWindow(SW_HIDE);
  269. return 0;
  270. }
  271. //-------------------------------------------------------------------------
  272. // Get the CWindow pointer for the specified tab (it's stored in the
  273. // lParam attribute of the tab).
  274. //-------------------------------------------------------------------------
  275. CWindow * GetTabWindow(int iTabIndex)
  276. {
  277. TCITEM tci;
  278. tci.mask = TCIF_PARAM;
  279. tci.lParam = 0;
  280. if (TabCtrl_GetItem(GetDlgItem(IDC_MSCONFIGTAB), iTabIndex, &tci))
  281. return (CWindow *)tci.lParam;
  282. return NULL;
  283. }
  284. enum { IDD = IDD_MSCONFIGCTL };
  285. LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  286. {
  287. if (m_fDoNotRun)
  288. return 0;
  289. return 0;
  290. }
  291. //-------------------------------------------------------------------------
  292. // Handle user clicks on the OK or Cancel buttons.
  293. //-------------------------------------------------------------------------
  294. LRESULT OnClickedButtonCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  295. {
  296. if (m_hwndParent != NULL)
  297. ::PostMessage(m_hwndParent, WM_CLOSE, 0, 0);
  298. return 0;
  299. }
  300. LRESULT OnClickedButtonOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  301. {
  302. if (m_hwndParent != NULL)
  303. ::PostMessage(m_hwndParent, WM_CLOSE, 0, 0);
  304. return 0;
  305. }
  306. private:
  307. CWindow m_wndPlaceHolder; // hidden, used to place property pages
  308. HWND m_hwndParent; // if the parent window is set, we can send messages
  309. BOOL m_fDoNotRun; // should we present a UI
  310. BOOL m_fRunningInHelpCtr; // is control loaded in HelpCtr
  311. CPageIni m_pageWinIni; // "win.ini" tab
  312. CPageIni m_pageSystemIni; // "system.ini" tab
  313. CPageGeneral m_pageGeneral; // "general" tab
  314. CPageBootIni m_pageBootIni; // "boot.ini" tab
  315. CPageServices m_pageServices; // "services" tab
  316. CPageStartup m_pageStartup; // "startup" tab
  317. CPageRegistry m_pageRegistry; // "registry" tab
  318. CPageInternational m_pageInternational; // "international" tab
  319. CMSConfigState m_state; // state variable shared between pages
  320. };
  321. #endif //__MSCONFIGCTL_H_