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.

572 lines
19 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. UINT GetSmallImage() {return m_idbSmallImage;}
  73. UINT GetSmallImageOpen() {return m_idbSmallImageOpen;}
  74. UINT GetLargeImage() {return m_idbLargeImage;}
  75. long GetViewOptions();
  76. UINT GetSnapinImage() {return m_idiSnapinImage;}
  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. if(!m_hIconSnapinImage)
  284. LoadIcon( _Module.GetModuleInstance(), MAKEINTRESOURCE(GetDescriptor().GetSnapinImage()));
  285. *hAppIcon = m_hIconSnapinImage;
  286. return sc.ToHr();
  287. }
  288. STDMETHODIMP GetStaticFolderImage(HBITMAP* hSmallImage, HBITMAP* hSmallImageOpen,
  289. HBITMAP* hLargeImage, COLORREF* cMask)
  290. {
  291. DECLARE_SC (sc, TEXT("CSnapinWrapper::GetStaticFolderImage"));
  292. sc = ScCheckPointers(hSmallImage, hSmallImageOpen, hLargeImage, cMask);
  293. if(sc)
  294. return sc.ToHr();
  295. if(!m_bmpSmallImage)
  296. m_bmpSmallImage.LoadBitmap(MAKEINTRESOURCE(GetDescriptor().GetSmallImage()));
  297. if(!m_bmpSmallImageOpen)
  298. m_bmpSmallImageOpen.LoadBitmap(MAKEINTRESOURCE(GetDescriptor().GetSmallImageOpen()));
  299. if(!m_bmpLargeImage)
  300. m_bmpLargeImage.LoadBitmap(MAKEINTRESOURCE(GetDescriptor().GetLargeImage()));
  301. *hSmallImage = m_bmpSmallImage;
  302. *hSmallImageOpen = m_bmpSmallImageOpen;
  303. *hLargeImage = m_bmpLargeImage;
  304. *cMask = RGB(255, 0, 255);
  305. return sc.ToHr();
  306. }
  307. virtual CSnapinDescriptor& GetDescriptor()
  308. {
  309. return GetSnapinDescriptor();
  310. }
  311. CSnapinWrapper() : m_hIconSnapinImage(NULL)
  312. {
  313. CStr strName;
  314. GetDescriptor().GetName(strName);
  315. SetName(strName);
  316. }
  317. private:
  318. HICON m_hIconSnapinImage;
  319. WTL::CBitmap m_bmpSmallImage; // these are smart handles.
  320. WTL::CBitmap m_bmpSmallImageOpen;
  321. WTL::CBitmap m_bmpLargeImage;
  322. };
  323. //____________________________________________________________________________
  324. //
  325. // Class: CFolderSnapinData
  326. //
  327. // PURPOSE:
  328. //____________________________________________________________________________
  329. //
  330. class CFolderSnapinData : public CSnapinComponentDataImpl
  331. {
  332. typedef CSnapinComponentDataImpl BC;
  333. public:
  334. CFolderSnapinData();
  335. // IComponentData
  336. STDMETHODIMP CreateComponent(LPCOMPONENT* ppComponent);
  337. // IExtendPropertySheet2
  338. STDMETHODIMP CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider, LONG_PTR handle, LPDATAOBJECT lpIDataObject);
  339. void SetDirty(BOOL bState = TRUE) { BC::SetDirty(bState); }
  340. static CSnapinDescriptor& GetSnapinDescriptor();
  341. };
  342. typedef CSnapinWrapper<CFolderSnapinData, &CLSID_FolderSnapin> CFolderSnapin;
  343. //____________________________________________________________________________
  344. //
  345. // Class: CFolderSnapinComponent
  346. //
  347. // PURPOSE:
  348. //____________________________________________________________________________
  349. //
  350. class CFolderSnapinComponent : public CSnapinComponentImpl
  351. {
  352. };
  353. //____________________________________________________________________________
  354. //
  355. // Class: CHTMLSnapinData
  356. //
  357. // PURPOSE:
  358. //____________________________________________________________________________
  359. //
  360. class CHTMLSnapinData : public CSnapinComponentDataImpl
  361. {
  362. typedef CSnapinComponentDataImpl BC;
  363. public:
  364. CHTMLSnapinData();
  365. ~CHTMLSnapinData();
  366. // IComponentData
  367. STDMETHODIMP CreateComponent(LPCOMPONENT* ppComponent);
  368. STDMETHODIMP Destroy();
  369. // IExtendPropertySheet2
  370. STDMETHODIMP CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider, LONG_PTR handle, LPDATAOBJECT lpIDataObject);
  371. virtual UINT GetWatermark() {return IDB_SETUPWIZARD1;}
  372. static CSnapinDescriptor& GetSnapinDescriptor();
  373. private:
  374. CHTMLPage1 *m_pHtmlPage1;
  375. CHTMLPage2 *m_pHtmlPage2;
  376. };
  377. typedef CSnapinWrapper<CHTMLSnapinData, &CLSID_HTMLSnapin> CHTMLSnapin;
  378. //____________________________________________________________________________
  379. //
  380. // Class: CHTMLSnapinComponent
  381. //
  382. // PURPOSE:
  383. //____________________________________________________________________________
  384. //
  385. class CHTMLSnapinComponent : public CSnapinComponentImpl
  386. {
  387. typedef CSnapinComponentImpl BC;
  388. public:
  389. virtual SC ScOnSelect(BOOL bScope, BOOL bSelect);
  390. STDMETHODIMP GetResultViewType(MMC_COOKIE cookie, LPOLESTR* ppViewType,
  391. long* pViewOptions);
  392. };
  393. //____________________________________________________________________________
  394. //
  395. // Class: COCXSnapinData
  396. //
  397. // PURPOSE:
  398. //____________________________________________________________________________
  399. //
  400. class COCXSnapinData : public CSnapinComponentDataImpl
  401. {
  402. typedef CSnapinComponentDataImpl BC;
  403. public:
  404. COCXSnapinData();
  405. ~COCXSnapinData();
  406. // IComponentData
  407. STDMETHODIMP CreateComponent(LPCOMPONENT* ppComponent);
  408. STDMETHODIMP Destroy();
  409. // IExtendPropertySheet2
  410. STDMETHODIMP CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider, LONG_PTR handle, LPDATAOBJECT lpIDataObject);
  411. virtual UINT GetHeaderBitmap() {return IDB_OCX_WIZARD_HEADER;}
  412. virtual UINT GetWatermark() {return IDB_SETUPWIZARD;}
  413. static CSnapinDescriptor& GetSnapinDescriptor();
  414. private:
  415. CActiveXPage0* m_pActiveXPage0;
  416. CActiveXPage1* m_pActiveXPage1;
  417. CActiveXPage2* m_pActiveXPage2;
  418. };
  419. typedef CSnapinWrapper<COCXSnapinData, &CLSID_OCXSnapin> COCXSnapin;
  420. //____________________________________________________________________________
  421. //
  422. // Class: COCXSnapinComponent
  423. //
  424. // PURPOSE:
  425. //____________________________________________________________________________
  426. //
  427. class COCXSnapinComponent : public CSnapinComponentImpl, IPersistStorage
  428. {
  429. public:
  430. COCXSnapinComponent() : m_bLoaded(FALSE), m_bInitialized(FALSE) {}
  431. BEGIN_COM_MAP(COCXSnapinComponent)
  432. COM_INTERFACE_ENTRY(IPersistStorage)
  433. COM_INTERFACE_ENTRY_CHAIN(CSnapinComponentImpl)
  434. END_COM_MAP()
  435. // IPersistStorage
  436. STDMETHODIMP HandsOffStorage();
  437. STDMETHODIMP InitNew(IStorage* pStg);
  438. STDMETHODIMP IsDirty();
  439. STDMETHODIMP Load(IStorage* pStg);
  440. STDMETHODIMP Save(IStorage* pStg, BOOL fSameAsLoad);
  441. STDMETHODIMP SaveCompleted(IStorage* pStgNew);
  442. STDMETHODIMP GetClassID(CLSID *pClassID);
  443. // IComponenent override
  444. STDMETHODIMP Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event,
  445. LPARAM arg, LPARAM param);
  446. protected:
  447. STDMETHODIMP OnInitOCX(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param);
  448. private:
  449. IStoragePtr m_spStg; // Storage provided by MMC
  450. IStoragePtr m_spStgInner; // Nested storage given to OCX
  451. IPersistStreamPtr m_spIPStm; // Persist interfaces from OCX
  452. IPersistStoragePtr m_spIPStg; // only one will be used
  453. BOOL m_bLoaded; // MMC called Load
  454. BOOL m_bInitialized; // MMC called InitNew
  455. };
  456. #endif