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.

554 lines
18 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1999 - 1999
  5. *
  6. * File: fldrsnap.h
  7. *
  8. * Contents: Header file for built-in snapins that implement
  9. * the Folder, ActiveX Control, and Web Link nodes.
  10. * These replace earlier code that had special "built-in"
  11. * nodetypes.
  12. *
  13. * History: 23-Jul-98 vivekj Created
  14. *
  15. *--------------------------------------------------------------------------*/
  16. #ifndef __FOLDERSNAPIN_H_
  17. #define __FOLDERSNAPIN_H_
  18. extern const CLSID CLSID_FolderSnapin;
  19. extern const CLSID CLSID_OCXSnapin;
  20. extern const CLSID CLSID_HTMLSnapin;
  21. extern LPCTSTR szClsid_FolderSnapin;
  22. extern LPCTSTR szClsid_HTMLSnapin;
  23. extern LPCTSTR szClsid_OCXSnapin;
  24. // forward decls
  25. class CHTMLPage1;
  26. class CHTMLPage2;
  27. class CActiveXPage0;
  28. class CActiveXPage1;
  29. class CActiveXPage2;
  30. HRESULT WINAPI IPersistStreamFunc(void* pv, REFIID riid, LPVOID* ppv, DWORD dw);
  31. SC ScFormatIndirectSnapInName (
  32. HINSTANCE hInst, /* I:module containing the resource */
  33. int idNameString, /* I:ID of name's string resource */
  34. CStr& strName); /* O:formatted indirect name string */
  35. /*+-------------------------------------------------------------------------*
  36. * Class: CSnapinDescriptor
  37. *
  38. * PURPOSE: A class that contains information to be filled in by
  39. * derived snap-ins.
  40. *
  41. *+-------------------------------------------------------------------------*/
  42. class CSnapinDescriptor
  43. {
  44. private:
  45. UINT m_idsName;
  46. UINT m_idsDescription;
  47. UINT m_idbSmallImage;
  48. UINT m_idbSmallImageOpen;
  49. UINT m_idbLargeImage;
  50. long m_viewOptions; // for GetResultViewType
  51. UINT m_idiSnapinImage; // the icon used by ISnapinAbout
  52. public:
  53. const CLSID & m_clsidSnapin; // the snapin class ID
  54. const LPCTSTR m_szClsidSnapin;
  55. const GUID & m_guidNodetype; // root node type
  56. const LPCTSTR m_szGuidNodetype;
  57. const LPCTSTR m_szClassName;
  58. const LPCTSTR m_szProgID;
  59. const LPCTSTR m_szVersionIndependentProgID;
  60. public:
  61. CSnapinDescriptor();
  62. CSnapinDescriptor(UINT idsName, UINT idsDescription, UINT idiSnapinImage, UINT idbSmallImage,
  63. UINT idbSmallImageOpen, UINT idbLargeImage,
  64. const CLSID &clsidSnapin, LPCTSTR szClsidSnapin,
  65. const GUID &guidNodetype, LPCTSTR szGuidNodetype,
  66. LPCTSTR szClassName, LPCTSTR szProgID, LPCTSTR szVersionIndependentProgID,
  67. long viewOptions);
  68. void GetName(CStr &str);
  69. void GetRegisteredDefaultName(CStr &str);
  70. void GetRegisteredIndirectName(CStr &str);
  71. UINT GetDescription() {return m_idsDescription;}
  72. HBITMAP GetSmallImage();
  73. HBITMAP GetSmallImageOpen();
  74. HBITMAP GetLargeImage();
  75. long GetViewOptions();
  76. HICON GetSnapinImage();
  77. };
  78. /*+-------------------------------------------------------------------------*
  79. * class CSnapinComponentDataImpl
  80. *
  81. *
  82. * PURPOSE: Implements IComponentData for the built-in snapins.
  83. *
  84. *+-------------------------------------------------------------------------*/
  85. class CSnapinComponentDataImpl :
  86. public IComponentData,
  87. public CComObjectRoot,
  88. public ISnapinAbout,
  89. public ISnapinHelp,
  90. public IPersistStream,
  91. public IExtendPropertySheet2,
  92. public CSerialObjectRW
  93. {
  94. friend class CSnapinComponentImpl;
  95. public:
  96. CSnapinComponentDataImpl();
  97. virtual CSnapinDescriptor& GetDescriptor() = 0;
  98. // IComponentData
  99. STDMETHODIMP Initialize(LPUNKNOWN pUnknown);
  100. STDMETHODIMP Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event,
  101. LPARAM arg, LPARAM param);
  102. STDMETHODIMP Destroy();
  103. STDMETHODIMP QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  104. LPDATAOBJECT* ppDataObject);
  105. STDMETHODIMP GetDisplayInfo( SCOPEDATAITEM* pScopeDataItem);
  106. STDMETHODIMP CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  107. // IPersistStream
  108. STDMETHODIMP GetClassID(CLSID *pClassID);
  109. STDMETHODIMP IsDirty(void);
  110. STDMETHODIMP Load(LPSTREAM pStm);
  111. STDMETHODIMP Save(LPSTREAM pStm , BOOL fClearDirty);
  112. STDMETHODIMP GetSizeMax(ULARGE_INTEGER* pcbSize );
  113. // ISnapinHelp
  114. STDMETHODIMP GetHelpTopic (LPOLESTR* ppszCompiledHelpFile);
  115. // IExtendPropertySheet2
  116. STDMETHODIMP CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider, LONG_PTR handle, LPDATAOBJECT lpIDataObject) = 0;
  117. STDMETHODIMP GetWatermarks(LPDATAOBJECT lpIDataObject, HBITMAP * lphWatermark, HBITMAP * lphHeader, HPALETTE * lphPalette, BOOL* bStretch);
  118. STDMETHODIMP QueryPagesFor(LPDATAOBJECT lpDataObject);
  119. // override
  120. virtual UINT GetHeaderBitmap() {return 0;}
  121. virtual UINT GetWatermark() {return 0;}
  122. // CSerialObject methods
  123. virtual UINT GetVersion() {return 1;}
  124. virtual HRESULT ReadSerialObject (IStream &stm, UINT nVersion);
  125. virtual HRESULT WriteSerialObject(IStream &stm);
  126. protected:
  127. HRESULT OnPreload(HSCOPEITEM scopeItem);
  128. private: // attributes - not persisted
  129. IConsole2Ptr m_spConsole2;
  130. IConsoleNameSpace2Ptr m_spConsoleNameSpace2;
  131. bool m_bDirty;
  132. protected:
  133. UINT m_iImage;
  134. UINT m_iOpenImage;
  135. void SetDirty(BOOL bState = TRUE) { m_bDirty = bState; }
  136. private: // attributes - persisted
  137. CStringTableString m_strName; // the name of the root node, which is the only node created by the snapin
  138. CStringTableString m_strView; // the view displayed by the node.
  139. public:
  140. void SetName(LPCTSTR sz);
  141. LPCTSTR GetName() {return m_strName.data();}
  142. void SetView(LPCTSTR sz);
  143. LPCTSTR GetView() {return m_strView.data();}
  144. };
  145. /*+-------------------------------------------------------------------------*
  146. * class CSnapinComponentImpl
  147. *
  148. *
  149. * PURPOSE: Implements IComponent for the built-in snapins.
  150. *
  151. *+-------------------------------------------------------------------------*/
  152. class CSnapinComponentImpl : public CComObjectRoot, public IComponent
  153. {
  154. public:
  155. BEGIN_COM_MAP(CSnapinComponentImpl)
  156. COM_INTERFACE_ENTRY(IComponent)
  157. END_COM_MAP()
  158. void Init(IComponentData *pComponentData);
  159. // IComponent
  160. STDMETHODIMP Initialize(LPCONSOLE lpConsole);
  161. STDMETHODIMP Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event,
  162. LPARAM arg, LPARAM param);
  163. STDMETHODIMP Destroy(MMC_COOKIE cookie);
  164. STDMETHODIMP QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  165. LPDATAOBJECT* ppDataObject);
  166. STDMETHODIMP GetResultViewType(MMC_COOKIE cookie, LPOLESTR* ppViewType,
  167. long* pViewOptions);
  168. STDMETHODIMP GetDisplayInfo( RESULTDATAITEM* pResultDataItem);
  169. STDMETHODIMP CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  170. protected:
  171. CSnapinComponentDataImpl * GetComponentData();
  172. protected:
  173. virtual SC ScOnSelect(BOOL bScope, BOOL bSelect);
  174. protected: // attributes - not persisted
  175. IConsole2Ptr m_spConsole2;
  176. IComponentDataPtr m_spComponentData;
  177. };
  178. /*+-------------------------------------------------------------------------*
  179. * class CSnapinDataObject
  180. *
  181. *
  182. * PURPOSE: Implements IDataObject for the built-in snapins.
  183. *
  184. *+-------------------------------------------------------------------------*/
  185. class CSnapinDataObject : public CComObjectRoot, public IDataObject
  186. {
  187. public:
  188. BEGIN_COM_MAP(CSnapinDataObject)
  189. COM_INTERFACE_ENTRY(IDataObject)
  190. END_COM_MAP()
  191. CSnapinDataObject();
  192. // IDataObject
  193. STDMETHODIMP GetDataHere(FORMATETC *pformatetc, STGMEDIUM *pmedium);
  194. private:
  195. STDMETHODIMP GetData(LPFORMATETC lpFormatetcIn, LPSTGMEDIUM lpMedium){ return E_NOTIMPL; };
  196. STDMETHODIMP EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC* ppEnumFormatEtc){ return E_NOTIMPL; };
  197. STDMETHODIMP QueryGetData(LPFORMATETC lpFormatetc) { return E_NOTIMPL; };
  198. STDMETHODIMP GetCanonicalFormatEtc(LPFORMATETC lpFormatetcIn, LPFORMATETC lpFormatetcOut){ return E_NOTIMPL; };
  199. STDMETHODIMP SetData(LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium, BOOL bRelease){ return E_NOTIMPL; };
  200. STDMETHODIMP DAdvise(LPFORMATETC lpFormatetc, DWORD advf, LPADVISESINK pAdvSink, LPDWORD pdwConnection){ return E_NOTIMPL; };
  201. STDMETHODIMP DUnadvise(DWORD dwConnection){ return E_NOTIMPL; };
  202. STDMETHODIMP EnumDAdvise(LPENUMSTATDATA* ppEnumAdvise){ return E_NOTIMPL; };
  203. HRESULT WriteString(IStream *pStream, LPCOLESTR sz);
  204. public:
  205. void Initialize(IComponentData *pComponentData, DATA_OBJECT_TYPES type);
  206. DATA_OBJECT_TYPES GetType() const {return m_type;}
  207. private:
  208. bool m_bInitialized;
  209. IComponentDataPtr m_spComponentData; // back pointer to the parent.
  210. DATA_OBJECT_TYPES m_type;
  211. // Clipboard formats that are required by the console
  212. static void RegisterClipboardFormats();
  213. static UINT s_cfNodeType;
  214. static UINT s_cfNodeTypeString;
  215. static UINT s_cfDisplayName;
  216. static UINT s_cfCoClass;
  217. static UINT s_cfSnapinPreloads;
  218. };
  219. SC ScLoadAndAllocateString(UINT ids, LPOLESTR *lpstrOut);
  220. /*+-------------------------------------------------------------------------*
  221. * class CSnapinWrapper
  222. *
  223. *
  224. * PURPOSE: A template class, used to instantiate the snapin.
  225. *
  226. *+-------------------------------------------------------------------------*/
  227. template <class CSnapin, const CLSID *pCLSID_Snapin>
  228. class CSnapinWrapper : public CSnapin, public CComCoClass<CSnapin, pCLSID_Snapin>
  229. {
  230. typedef CSnapinWrapper<CSnapin, pCLSID_Snapin> ThisClass;
  231. BEGIN_COM_MAP(ThisClass)
  232. COM_INTERFACE_ENTRY(IComponentData)
  233. COM_INTERFACE_ENTRY(ISnapinAbout)
  234. COM_INTERFACE_ENTRY(ISnapinHelp)
  235. COM_INTERFACE_ENTRY(IPersistStream)
  236. COM_INTERFACE_ENTRY(IExtendPropertySheet2)
  237. END_COM_MAP()
  238. DECLARE_NOT_AGGREGATABLE(ThisClass)
  239. // registry
  240. static HRESULT WINAPI UpdateRegistry(BOOL bRegister)
  241. {
  242. USES_CONVERSION;
  243. CStr strName;
  244. GetSnapinDescriptor().GetRegisteredDefaultName (strName);
  245. CStr strIndirectName;
  246. GetSnapinDescriptor().GetRegisteredIndirectName (strIndirectName);
  247. _ATL_REGMAP_ENTRY rgEntries[] =
  248. {
  249. { L"VSnapinClsid", T2COLE( GetSnapinDescriptor().m_szClsidSnapin)},
  250. { L"VNodetype", T2COLE( GetSnapinDescriptor().m_szGuidNodetype)},
  251. { L"VSnapinName", T2COLE((LPCTSTR) strName)},
  252. { L"VSnapinNameIndirect", T2COLE((LPCTSTR) strIndirectName)},
  253. { L"VClassName", T2COLE( GetSnapinDescriptor().m_szClassName)},
  254. { L"VProgID", T2COLE( GetSnapinDescriptor().m_szProgID)},
  255. { L"VVersionIndependentProgID", T2COLE( GetSnapinDescriptor().m_szVersionIndependentProgID)},
  256. { L"VFileName", T2COLE( g_szMmcndmgrDll)},
  257. {NULL, NULL}
  258. };
  259. return _Module.UpdateRegistryFromResource(IDR_FOLDERSNAPIN, bRegister, rgEntries);
  260. }
  261. STDMETHODIMP GetSnapinDescription(LPOLESTR* lpDescription)
  262. {
  263. DECLARE_SC(sc, TEXT("CSnapinWrapper::GetSnapinDescription"));
  264. sc = ScLoadAndAllocateString(GetSnapinDescriptor().GetDescription(), lpDescription);
  265. return sc.ToHr();
  266. }
  267. STDMETHODIMP GetProvider(LPOLESTR* lpDescription)
  268. {
  269. DECLARE_SC(sc, TEXT("CSnapinWrapper::GetProvider"));
  270. sc = ScLoadAndAllocateString(IDS_BUILTIN_SNAPIN_PROVIDER, lpDescription);
  271. return sc.ToHr();
  272. }
  273. STDMETHODIMP GetSnapinVersion(LPOLESTR* lpDescription)
  274. {
  275. return E_NOTIMPL;
  276. }
  277. STDMETHODIMP GetSnapinImage(HICON* hAppIcon)
  278. {
  279. DECLARE_SC (sc, TEXT("CSnapinWrapper::GetSnapinImage"));
  280. sc = ScCheckPointers(hAppIcon);
  281. if(sc)
  282. return sc.ToHr();
  283. *hAppIcon = GetDescriptor().GetSnapinImage();
  284. return sc.ToHr();
  285. }
  286. STDMETHODIMP GetStaticFolderImage(HBITMAP* hSmallImage, HBITMAP* hSmallImageOpen,
  287. HBITMAP* hLargeImage, COLORREF* cMask)
  288. {
  289. DECLARE_SC (sc, TEXT("CSnapinWrapper::GetStaticFolderImage"));
  290. sc = ScCheckPointers(hSmallImage, hSmallImageOpen, hLargeImage, cMask);
  291. if(sc)
  292. return sc.ToHr();
  293. *hSmallImage = GetDescriptor().GetSmallImage();
  294. *hSmallImageOpen = GetDescriptor().GetSmallImageOpen();
  295. *hLargeImage = GetDescriptor().GetLargeImage();
  296. *cMask = RGB(255, 0, 255);
  297. return sc.ToHr();
  298. }
  299. virtual CSnapinDescriptor& GetDescriptor()
  300. {
  301. return GetSnapinDescriptor();
  302. }
  303. CSnapinWrapper()
  304. {
  305. CStr strName;
  306. GetDescriptor().GetName(strName);
  307. SetName(strName);
  308. }
  309. };
  310. //____________________________________________________________________________
  311. //
  312. // Class: CFolderSnapinData
  313. //
  314. // PURPOSE:
  315. //____________________________________________________________________________
  316. //
  317. class CFolderSnapinData : public CSnapinComponentDataImpl
  318. {
  319. typedef CSnapinComponentDataImpl BC;
  320. public:
  321. CFolderSnapinData();
  322. // IComponentData
  323. STDMETHODIMP CreateComponent(LPCOMPONENT* ppComponent);
  324. // IExtendPropertySheet2
  325. STDMETHODIMP CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider, LONG_PTR handle, LPDATAOBJECT lpIDataObject);
  326. void SetDirty(BOOL bState = TRUE) { BC::SetDirty(bState); }
  327. static CSnapinDescriptor& GetSnapinDescriptor();
  328. };
  329. typedef CSnapinWrapper<CFolderSnapinData, &CLSID_FolderSnapin> CFolderSnapin;
  330. //____________________________________________________________________________
  331. //
  332. // Class: CFolderSnapinComponent
  333. //
  334. // PURPOSE:
  335. //____________________________________________________________________________
  336. //
  337. class CFolderSnapinComponent : public CSnapinComponentImpl
  338. {
  339. };
  340. //____________________________________________________________________________
  341. //
  342. // Class: CHTMLSnapinData
  343. //
  344. // PURPOSE:
  345. //____________________________________________________________________________
  346. //
  347. class CHTMLSnapinData : public CSnapinComponentDataImpl
  348. {
  349. typedef CSnapinComponentDataImpl BC;
  350. public:
  351. CHTMLSnapinData();
  352. ~CHTMLSnapinData();
  353. // IComponentData
  354. STDMETHODIMP CreateComponent(LPCOMPONENT* ppComponent);
  355. STDMETHODIMP Destroy();
  356. // IExtendPropertySheet2
  357. STDMETHODIMP CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider, LONG_PTR handle, LPDATAOBJECT lpIDataObject);
  358. virtual UINT GetWatermark() {return IDB_SETUPWIZARD1;}
  359. static CSnapinDescriptor& GetSnapinDescriptor();
  360. private:
  361. CHTMLPage1 *m_pHtmlPage1;
  362. CHTMLPage2 *m_pHtmlPage2;
  363. };
  364. typedef CSnapinWrapper<CHTMLSnapinData, &CLSID_HTMLSnapin> CHTMLSnapin;
  365. //____________________________________________________________________________
  366. //
  367. // Class: CHTMLSnapinComponent
  368. //
  369. // PURPOSE:
  370. //____________________________________________________________________________
  371. //
  372. class CHTMLSnapinComponent : public CSnapinComponentImpl
  373. {
  374. typedef CSnapinComponentImpl BC;
  375. public:
  376. virtual SC ScOnSelect(BOOL bScope, BOOL bSelect);
  377. STDMETHODIMP GetResultViewType(MMC_COOKIE cookie, LPOLESTR* ppViewType,
  378. long* pViewOptions);
  379. };
  380. //____________________________________________________________________________
  381. //
  382. // Class: COCXSnapinData
  383. //
  384. // PURPOSE:
  385. //____________________________________________________________________________
  386. //
  387. class COCXSnapinData : public CSnapinComponentDataImpl
  388. {
  389. typedef CSnapinComponentDataImpl BC;
  390. public:
  391. COCXSnapinData();
  392. ~COCXSnapinData();
  393. // IComponentData
  394. STDMETHODIMP CreateComponent(LPCOMPONENT* ppComponent);
  395. STDMETHODIMP Destroy();
  396. // IExtendPropertySheet2
  397. STDMETHODIMP CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider, LONG_PTR handle, LPDATAOBJECT lpIDataObject);
  398. virtual UINT GetHeaderBitmap() {return IDB_OCX_WIZARD_HEADER;}
  399. virtual UINT GetWatermark() {return IDB_SETUPWIZARD;}
  400. static CSnapinDescriptor& GetSnapinDescriptor();
  401. private:
  402. CActiveXPage0* m_pActiveXPage0;
  403. CActiveXPage1* m_pActiveXPage1;
  404. CActiveXPage2* m_pActiveXPage2;
  405. };
  406. typedef CSnapinWrapper<COCXSnapinData, &CLSID_OCXSnapin> COCXSnapin;
  407. //____________________________________________________________________________
  408. //
  409. // Class: COCXSnapinComponent
  410. //
  411. // PURPOSE:
  412. //____________________________________________________________________________
  413. //
  414. class COCXSnapinComponent : public CSnapinComponentImpl, IPersistStorage
  415. {
  416. public:
  417. COCXSnapinComponent() : m_bLoaded(FALSE), m_bInitialized(FALSE) {}
  418. BEGIN_COM_MAP(COCXSnapinComponent)
  419. COM_INTERFACE_ENTRY(IPersistStorage)
  420. COM_INTERFACE_ENTRY_CHAIN(CSnapinComponentImpl)
  421. END_COM_MAP()
  422. // IPersistStorage
  423. STDMETHODIMP HandsOffStorage();
  424. STDMETHODIMP InitNew(IStorage* pStg);
  425. STDMETHODIMP IsDirty();
  426. STDMETHODIMP Load(IStorage* pStg);
  427. STDMETHODIMP Save(IStorage* pStg, BOOL fSameAsLoad);
  428. STDMETHODIMP SaveCompleted(IStorage* pStgNew);
  429. STDMETHODIMP GetClassID(CLSID *pClassID);
  430. // IComponenent override
  431. STDMETHODIMP Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event,
  432. LPARAM arg, LPARAM param);
  433. protected:
  434. STDMETHODIMP OnInitOCX(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param);
  435. private:
  436. IStoragePtr m_spStg; // Storage provided by MMC
  437. IStoragePtr m_spStgInner; // Nested storage given to OCX
  438. IPersistStreamPtr m_spIPStm; // Persist interfaces from OCX
  439. IPersistStoragePtr m_spIPStg; // only one will be used
  440. BOOL m_bLoaded; // MMC called Load
  441. BOOL m_bInitialized; // MMC called InitNew
  442. };
  443. #endif