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.

391 lines
13 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1999
  5. //
  6. // File: samplesnap.hxx
  7. //
  8. // Contents: Classes that implement sample snapin using the framework.
  9. //
  10. //--------------------------------------------------------------------
  11. #ifndef _SAMPLESNAP_HXX_
  12. #define _SAMPLESNAP_HXX_
  13. // Forward declarations.
  14. class CSampleSnapinLVContainer;
  15. class CSampleSnapinLVLeafItem;
  16. //+-------------------------------------------------------------------
  17. //
  18. // Class: CSnapinRootItem
  19. //
  20. // Purpose: Implements the root item for a standalone snapin.
  21. //
  22. //--------------------------------------------------------------------
  23. class CSnapinRootItem : public CBaseSnapinItem
  24. {
  25. typedef CBaseSnapinItem super;
  26. // Used by CBaseSnapinItem::ScCreateItem, connect this item with its children.
  27. typedef CComObject<CSnapinItem<CSnapinRootItem> > t_item;
  28. typedef CComObject<CSnapinItem<CSampleSnapinLVContainer> > t_itemChild; // Who is my child?
  29. public:
  30. CSnapinRootItem( void ) {} // Raw constructor - use only for static item.
  31. virtual ~CSnapinRootItem( void ) {}
  32. BEGIN_COM_MAP(CSnapinRootItem)
  33. COM_INTERFACE_ENTRY(IDataObject) // Cant have empty map so add IDataObject
  34. END_COM_MAP()
  35. protected:
  36. // Item tree related information
  37. // node type related information
  38. virtual const CNodeType* Pnodetype( void ) { return &nodetypeSampleRoot;}
  39. // the display name of the item
  40. virtual const tstring* PstrDisplayName( void ) { return &m_strDisplayName;}
  41. // Get ListView data (GetDisplayInfo calls this).
  42. virtual SC ScGetField(DAT dat, tstring& strField);
  43. // Image list information
  44. virtual LONG Iconid() { return m_uIconIndex; }
  45. virtual LONG OpenIconid() { return m_uIconIndex; }
  46. virtual BOOL FIsContainer( void ) { return TRUE; }
  47. public:
  48. virtual SC ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex = NULL, INT ccolinfoex = 0, BOOL fIsRoot = FALSE);
  49. public:
  50. // Creates children for the node
  51. virtual SC ScCreateChildren( void );
  52. protected:
  53. tstring m_strDisplayName;
  54. UINT m_uIconIndex;
  55. };
  56. //+-------------------------------------------------------------------
  57. //
  58. // Class: CSampleSnapinLVContainer
  59. //
  60. // Purpose: Implements a scope pane item.
  61. //
  62. //--------------------------------------------------------------------
  63. class CSampleSnapinLVContainer : public CBaseSnapinItem
  64. {
  65. typedef CBaseSnapinItem super;
  66. // Used by CBaseSnapinItem::ScCreateItem, connect this item with its children.
  67. typedef CComObject<CSnapinItem<CSampleSnapinLVContainer> > t_item;
  68. typedef CComObject<CSnapinItem<CSampleSnapinLVLeafItem> > t_itemChild;
  69. public:
  70. CSampleSnapinLVContainer( void ) {}
  71. virtual ~CSampleSnapinLVContainer( void ) {}
  72. BEGIN_COM_MAP(CSampleSnapinLVContainer)
  73. COM_INTERFACE_ENTRY(IDataObject) // Cant have empty map so add IDataObject
  74. END_COM_MAP()
  75. protected:
  76. // Item tree related information
  77. // node type related information
  78. const CNodeType *Pnodetype( void ) { return &nodetypeSampleLVContainer;}
  79. // the display name of the item
  80. virtual const tstring* PstrDisplayName( void ) { return &m_strDisplayName;}
  81. // Get ListView data (GetDisplayInfo calls this).
  82. virtual SC ScGetField(DAT dat, tstring& strField);
  83. // Image list information
  84. virtual LONG Iconid() { return m_uIconIndex; }
  85. virtual LONG OpenIconid() { return m_uIconIndex; }
  86. // This item attributes.
  87. virtual BOOL FIsContainer( void ) { return TRUE; }
  88. virtual BOOL FAllowMultiSelectionForChildren() { return FALSE;}
  89. public:
  90. virtual SC ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex = NULL, INT ccolinfoex = 0, BOOL fIsRoot = FALSE);
  91. public:
  92. // Creates children for the node
  93. virtual SC ScCreateChildren( void );
  94. static SC ScCreateLVContainer(CSnapinRootItem *pitemParent, t_item ** ppitem, BOOL fNew);
  95. protected:
  96. // virtual SC ScGetVerbs(DWORD * pdwVerbs);
  97. protected:
  98. tstring m_strDisplayName;
  99. UINT m_uIconIndex;
  100. };
  101. //+-------------------------------------------------------------------
  102. //
  103. // Class: CSampleSnapinLVLeafItem
  104. //
  105. // Purpose: Implements a result pane item.
  106. //
  107. //--------------------------------------------------------------------
  108. class CSampleSnapinLVLeafItem : public CBaseSnapinItem
  109. {
  110. typedef CBaseSnapinItem super;
  111. // Used by CBaseSnapinItem::ScCreateItem, connect this item with its children.
  112. // This is a leaf item so this item acts as its child.
  113. typedef CComObject<CSnapinItem<CSampleSnapinLVLeafItem> > t_item;
  114. typedef CComObject<CSnapinItem<CSampleSnapinLVLeafItem> > t_itemChild;
  115. public:
  116. CSampleSnapinLVLeafItem( void ) {}
  117. virtual ~CSampleSnapinLVLeafItem( void ) {}
  118. BEGIN_COM_MAP(CSampleSnapinLVLeafItem)
  119. COM_INTERFACE_ENTRY(IDataObject) // Cant have empty map so add IDataObject
  120. END_COM_MAP()
  121. protected:
  122. // Item tree related information
  123. // node type related information
  124. virtual const CNodeType *Pnodetype( void ) {return &nodetypeSampleLVLeafItem;}
  125. // the display name of the item
  126. virtual const tstring* PstrDisplayName( void ) { return &m_strDisplayName; }
  127. // Get ListView data (GetDisplayInfo calls this).
  128. virtual SC ScGetField(DAT dat, tstring& strField);
  129. // Image list information
  130. virtual LONG Iconid() { return m_uIconIndex; }
  131. virtual BOOL FIsContainer( void ) { return FALSE; }
  132. // Context menu support
  133. virtual SnapinMenuItem *Pmenuitem(void);
  134. virtual INT CMenuItem(void);
  135. virtual SC ScCommand(long nCommandID, CComponent *pComponent = NULL);
  136. public:
  137. virtual SC ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex = NULL, INT ccolinfoex = 0, BOOL fIsRoot = FALSE);
  138. public:
  139. static SC ScCreateLVLeafItem(CSampleSnapinLVContainer *pitemParent, t_itemChild * pitemPrevious, t_itemChild ** ppitem, BOOL fNew);
  140. protected:
  141. // virtual SC ScGetVerbs(DWORD * pdwVerbs);
  142. private:
  143. tstring m_strDisplayName;
  144. UINT m_uIconIndex;
  145. // For context menus
  146. static SnapinMenuItem s_rgmenuitemLVLeafItem[];
  147. static INT s_cmenuitemLVLeafItem;
  148. };
  149. //+-------------------------------------------------------------------
  150. //
  151. // Class: CSampleSnapin
  152. //
  153. // Purpose: Implements a snapin.
  154. //
  155. //--------------------------------------------------------------------
  156. class CSampleSnapin : public CBaseSnapin
  157. {
  158. // Specify the root node of the snapin.
  159. typedef CComObject<CSnapinItem<CSnapinRootItem> > t_itemRoot;
  160. SNAPIN_DECLARE(CSampleSnapin);
  161. public:
  162. CSampleSnapin();
  163. virtual ~CSampleSnapin();
  164. // information about the snapin and root (ie initial) node
  165. virtual BOOL FStandalone() { return TRUE; }
  166. virtual BOOL FIsExtension() { return FALSE; }
  167. virtual LONG IdsDescription(void) {return IDS_SAMPLESNAPIN;}
  168. virtual LONG IdsName(void) {return IDS_SAMPLESNAPIN;}
  169. const CSnapinInfo* Psnapininfo() { return &snapininfoSample; }
  170. protected:
  171. // The column header info structures.
  172. static CColumnInfoEx s_colinfo[];
  173. static INT s_colwidths[];
  174. static INT s_ccolinfo;
  175. protected:
  176. virtual CColumnInfoEx* Pcolinfoex(INT icolinfo=0) { return s_colinfo + icolinfo; }
  177. virtual INT &ColumnWidth(INT icolwidth=0) { return s_colwidths[icolwidth]; }
  178. virtual INT Ccolinfoex() { return s_ccolinfo; }
  179. };
  180. //----------------------Name Space Extension ----------------------
  181. class CBaseProtSnapinItem;
  182. /* CSampleGhostRootSnapinItem
  183. *
  184. * PURPOSE: Implements the item class for the ghost root of container
  185. *
  186. */
  187. class CSampleGhostRootSnapinItem : public CBaseSnapinItem
  188. {
  189. typedef CBaseSnapinItem super;
  190. typedef CComObject<CSnapinItem<CSampleGhostRootSnapinItem> > t_item;
  191. typedef CComObject<CSnapinItem<CBaseProtSnapinItem> > t_itemChild;
  192. friend CBaseProtSnapinItem;
  193. public:
  194. CSampleGhostRootSnapinItem( void ) {}
  195. virtual ~CSampleGhostRootSnapinItem( void ) {}
  196. BEGIN_COM_MAP(CSampleGhostRootSnapinItem)
  197. COM_INTERFACE_ENTRY(IDataObject) // Cant have empty map so add IDataObject
  198. END_COM_MAP()
  199. protected:
  200. // the name of the server (used to build up the DN of the object.)
  201. // Item tree related information
  202. virtual BOOL FIsContainer( void ) { return TRUE;}
  203. // Overiding pure virtual functions. Should never be called here!!!
  204. const CNodeType *Pnodetype(void) { ASSERT(FALSE); return NULL;}
  205. virtual const tstring *PstrDisplayName( void ) { ASSERT(FALSE); return &m_strDisplayName;}
  206. virtual SC ScGetField(DAT dat, tstring& strField) { ASSERT(FALSE); return E_FAIL;}
  207. // column header and image list information
  208. virtual LONG Iconid() { return m_uIconIndex;}
  209. public:
  210. virtual SC ScInitializeNamespaceExtension(LPDATAOBJECT lpDataObject, HSCOPEITEM item, CNodeType *pNodeType);
  211. virtual SC ScCreateChildren( void );
  212. private:
  213. UINT m_uIconIndex;
  214. tstring m_strDisplayName;
  215. };
  216. /* CBaseProtSnapinItem
  217. *
  218. * PURPOSE: Implements the sample namespace extension snapin items.
  219. * This class is instantiated from the CSampleGhostRootSnapinItem
  220. * by first creating a container and than filling it with the sample
  221. * item instances.
  222. *
  223. */
  224. class CBaseProtSnapinItem : public CBaseSnapinItem
  225. {
  226. typedef CBaseSnapinItem super;
  227. typedef CComObject<CSnapinItem<CBaseProtSnapinItem> > t_item;
  228. typedef CComObject<CSnapinItem<CBaseProtSnapinItem> > t_itemChild;
  229. friend CSampleGhostRootSnapinItem;
  230. public:
  231. CBaseProtSnapinItem( void ); // Raw constructor - use only for static item.
  232. virtual ~CBaseProtSnapinItem( void ) {}
  233. BEGIN_COM_MAP(CBaseProtSnapinItem)
  234. COM_INTERFACE_ENTRY(IDataObject) // Cant have empty map so add IDataObject
  235. END_COM_MAP()
  236. protected:
  237. // Item tree related information
  238. // node type related information
  239. const CNodeType *Pnodetype( void ) { return &nodetypeSampleExtnNode;}
  240. // the display name of the item
  241. virtual const tstring* PstrDisplayName( void ) { return &m_strDisplayName;}
  242. virtual SC ScGetField(DAT dat, tstring& strField);
  243. // column header and image list information
  244. virtual LONG Iconid() { return PitemRoot()->Iconid(); }
  245. virtual BOOL FIsContainer( void ) { return m_fIsContainer;}
  246. void InitContainer(void) { m_fIsContainer = TRUE;}
  247. virtual CSampleGhostRootSnapinItem *PitemRoot(void)
  248. {
  249. return (dynamic_cast<CSampleGhostRootSnapinItem *>(CBaseSnapinItem::PitemRoot()));
  250. }
  251. public:
  252. // Creates children for the node
  253. virtual SC ScCreateChildren( void );
  254. static SC ScCreateItem(CBaseSnapinItem *pitemParent, t_itemChild * pitemPrevious, t_itemChild ** ppitem, BOOL fNew);
  255. private:
  256. UINT m_uIconIndex;
  257. BOOL m_fInitialized : 1;
  258. BOOL m_fIsContainer : 1;
  259. tstring m_strDisplayName;
  260. };
  261. /* CSampleSnapExtensionItem
  262. *
  263. * PURPOSE: Implements the NameSpace sample snapin item - must be a separate class to distinguish between different node types
  264. */
  265. class CSampleSnapExtensionItem : public CSampleGhostRootSnapinItem
  266. {
  267. typedef CSampleGhostRootSnapinItem super;
  268. virtual SC ScInitializeNamespaceExtension(LPDATAOBJECT lpDataObject, HSCOPEITEM item, CNodeType *pnodetype)
  269. {
  270. return super::ScInitializeNamespaceExtension(lpDataObject, item, pnodetype);
  271. }
  272. };
  273. /* CSampleExtnSnapin
  274. *
  275. * PURPOSE: Implements the Sample extension snapin
  276. */
  277. class CSampleExtnSnapin : public CBaseSnapin
  278. {
  279. typedef CComObject<CSnapinItem<CSampleGhostRootSnapinItem> > t_itemRoot;
  280. SNAPIN_DECLARE(CSampleExtnSnapin);
  281. public:
  282. CSampleExtnSnapin();
  283. virtual ~CSampleExtnSnapin();
  284. // information about the snapin and root (ie initial) node
  285. virtual BOOL FStandalone() { return FALSE;} // only an extension snapin.
  286. virtual BOOL FIsExtension() { return TRUE;}
  287. const CSnapinInfo *Psnapininfo() { return &snapininfoSampleExtn;}
  288. virtual LONG IdsDescription() { return IDS_SampleExtnSnapinDescription;}
  289. virtual LONG IdsName() { return IDS_SampleExtnSnapinName;}
  290. protected:
  291. // The column header info structures.
  292. static CColumnInfoEx s_colinfo[];
  293. static INT s_colwidths[];
  294. static INT s_ccolinfo;
  295. protected:
  296. virtual CColumnInfoEx *Pcolinfoex(INT icolinfo=0) { return s_colinfo + icolinfo;}
  297. virtual INT &ColumnWidth(INT icolwidth=0) { return s_colwidths[icolwidth];}
  298. virtual INT Ccolinfoex() { return s_ccolinfo;}
  299. };
  300. #endif //_BASEPROTSNAP_HXX