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.

399 lines
15 KiB

  1. /*
  2. * basesnap.hxx
  3. *
  4. *
  5. * Copyright (c) 1998-1999 Microsoft Corporation
  6. *
  7. * PURPOSE: Defines the snapin base class.
  8. *
  9. *
  10. * OWNER: ptousig
  11. */
  12. // ---- Pragmas ----
  13. #pragma once
  14. // ---- Declarations / references ----
  15. class CBitmap;
  16. class CComponent;
  17. class CColumnInfoEx;
  18. class CComponentData;
  19. class CBaseSnapinItem;
  20. class CSnapinContextMenuItem;
  21. class CBaseMultiSelectSnapinItem;
  22. struct SnapinMenuItem;
  23. // ---- STL based classes ----
  24. // A less operator for GUIDs (avoid comparing pointers, compare real values)
  25. class GUIDLess
  26. {
  27. public:
  28. bool operator()(const GUID &a, const GUID &b) const
  29. {
  30. return ::memcmp(&a, &b, sizeof(GUID)) < 0;
  31. }
  32. };
  33. // A set of guids
  34. typedef set<GUID, GUIDLess> GUIDSet;
  35. // A list of cookies
  36. typedef set<LONG_PTR> CCookieList;
  37. // A list of CBaseSnapinItems
  38. typedef list<CBaseSnapinItem *> ItemList;
  39. // A vector of CBaseSnapinItems
  40. typedef vector<CBaseSnapinItem *> CItemVector;
  41. // A vector of pointers to wrapper of menu items
  42. typedef vector<CSnapinContextMenuItem *> CSnapinContextMenuItemVector;
  43. // ---- Wrapper classes for menu items and menu item collections ----
  44. // A wrapper class for CONTEXTMENUITEM - so that we can keep the strings around (MMC asks for szpointers in CONTEXTMENUITEM!!!)
  45. // Write as a struct
  46. class CSnapinContextMenuItem
  47. {
  48. public:
  49. // Member variables
  50. CONTEXTMENUITEM cm; // cm sz members will point to the associated strings
  51. tstring strName;
  52. tstring strStatusBarText;
  53. // Constructor
  54. CSnapinContextMenuItem(void);
  55. };
  56. // A wrapper class for a CSnapinContextMenuItemVector - so that we can delete all the referenced items
  57. // Write as a struct
  58. // $REVIEW (dominicp) May want to write accessors in the future - many level of indirections to get to an element of a referenced CONTEXTMENUITEM
  59. class CSnapinContextMenuItemVectorWrapper
  60. {
  61. public:
  62. // Member variables
  63. CSnapinContextMenuItemVector cmiv;
  64. // Constructor
  65. CSnapinContextMenuItemVectorWrapper(void) { ;}
  66. virtual ~CSnapinContextMenuItemVectorWrapper(void);
  67. };
  68. // $REVIEW (ptousig) Move this to basestr.hxx
  69. #define CSZ(_x) (sizeof(_x)/sizeof(SZ))
  70. // MMC verbs bit masks, we want each verb to be given
  71. // a unique bit.
  72. enum VerbMask
  73. {
  74. vmNone = 0x00000000,
  75. vmOpen = 0x00000001,
  76. vmCopy = 0x00000002,
  77. vmPaste = 0x00000004,
  78. vmDelete = 0x00000008,
  79. vmProperties= 0x00000010,
  80. vmRename = 0x00000020,
  81. vmRefresh = 0x00000040,
  82. vmPrint = 0x00000080,
  83. vmCut = 0x00000100
  84. };
  85. // A mapping between VerbMasks and MMC_CONSOLE_VERBs
  86. struct VerbMap
  87. {
  88. VerbMask verbmask;
  89. MMC_CONSOLE_VERB mmcverb;
  90. };
  91. // The next three constants are the default values to use for menu items definitions. If used, they cause
  92. // the menu item to always show up, ungrayed, and unchecked.
  93. #define dwMenuAlwaysEnable 0
  94. #define dwMenuNeverGray 0
  95. #define dwMenuNeverChecked 0
  96. // The maximum stream size needed to store persistent information into a .msc file.
  97. #define cMaxStreamSizeLow 200
  98. #define cMaxStreamSizeHigh 0
  99. // Similar to CONTEXTMENUITEM but uses IDS's instead of SZ's. Also implements
  100. // an enabling/disabling mechanism
  101. struct SnapinMenuItem
  102. {
  103. LONG idsName;
  104. LONG idsStatusBarText;
  105. LONG lCommandID;
  106. LONG lInsertionPointID;
  107. LONG fSpecialFlags;
  108. // overrides for fFlags
  109. DWORD dwFlagsDisable; // if the disable parameter has any of these flags set, item is disabled.
  110. DWORD dwFlagsGray; // if the gray parameter has any of these flags set, item is grayed.
  111. DWORD dwFlagsChecked; // if the checked parameter has any of these flags set, item is checked.
  112. };
  113. #define CMENUITEM(_a) (sizeof(_a)/sizeof(SnapinMenuItem));
  114. // These are the "hints" passed to MMCN_VIEW_CHANGE.
  115. enum
  116. {
  117. ONVIEWCHANGE_DELETEITEMS = 1,
  118. ONVIEWCHANGE_DELETESINGLEITEM,
  119. ONVIEWCHANGE_INSERTNEWITEM,
  120. ONVIEWCHANGE_UPDATERESULTITEM,
  121. ONVIEWCHANGE_REFRESHCHILDREN,
  122. ONVIEWCHANGE_DELETERESULTITEMS,
  123. ONVIEWCHANGE_INSERTRESULTITEMS,
  124. ONVIEWCHANGE_UPDATEDESCRIPTIONBAR,
  125. ONVIEWCHANGE_LAST_HINT, // last predefined hint -- snapin specific hints must be greater than this
  126. };
  127. inline LPWSTR CoTaskDupString (LPCWSTR pszSrc)
  128. {
  129. if (pszSrc == NULL)
  130. return (NULL);
  131. int cbAlloc = (wcslen(pszSrc) + 1) * sizeof(WCHAR);
  132. LPWSTR pszDup = (LPWSTR) CoTaskMemAlloc (cbAlloc);
  133. if (pszDup != NULL)
  134. CopyMemory (pszDup, pszSrc, cbAlloc);
  135. return (pszDup);
  136. }
  137. //
  138. // Allocates & copies string.
  139. // $REVIEW (ptousig) This should be moved to basestr.hxx
  140. //
  141. inline SC ScIds2OleStr(LONG ids, LPOLESTR *lp)
  142. {
  143. DECLARE_SC(sc, _T("ScIds2OleStr"));
  144. sc = ScCheckPointers(lp);
  145. if (sc)
  146. return sc;
  147. *lp = NULL;
  148. tstring str;
  149. bool b = str.LoadString(_Module.GetModuleInstance(), ids);
  150. if (!b)
  151. return (sc = E_FAIL);
  152. *lp = CoTaskDupString (T2COLE(str.data()));
  153. if (! (*lp) )
  154. return (sc = E_OUTOFMEMORY);
  155. return sc;
  156. }
  157. // -----------------------------------------------------------------------------
  158. // -----------------------------------------------------------------------------
  159. // -----------------------------------------------------------------------------
  160. // CBaseSnapin
  161. //
  162. // This is the base class of all snapins.
  163. //
  164. // BaseMMC will use some of virtual methods to find out information about
  165. // the snapin. Other virtuals allow snapins to modify the default behavior
  166. // of BaseMMC.
  167. //
  168. // $REVIEW (ptousig) In the long term, it would be nice to have the individual
  169. // snapins implement two classes, directly derived from CComponent and
  170. // CComponentData. But that would be too big a change at the moment.
  171. //
  172. class CBaseSnapin
  173. {
  174. public:
  175. CBaseSnapin(void);
  176. virtual ~CBaseSnapin(void);
  177. //
  178. // Item-related stuff
  179. //
  180. inline CCookieList * Pcookielist(void) { return &m_cookielist;}
  181. virtual SC ScCreateRootItem(LPDATAOBJECT lpDataObject, HSCOPEITEM item, CBaseSnapinItem **ppitem) = 0;
  182. virtual SC ScReleaseIfRootItem(CBaseSnapinItem *pitem);
  183. // This method allows a CComponentData to tell us it is being
  184. // destroyed. Any item referring to this CD as its owner will
  185. // have their owner pointer nulled.
  186. SC ScOwnerDying(CComponentData *pComponentData);
  187. // This is the 'full' version of Pitem(). Given certain parameters, it will
  188. // do its best to find the approriate CBaseSnapinItem (creating a new one
  189. // if necessary).
  190. virtual CBaseSnapinItem * Pitem( CComponentData *pComponentData,
  191. CComponent *pComponent,
  192. LPDATAOBJECT lpDataObject,
  193. HSCOPEITEM hscopeitem,
  194. long cookie);
  195. // This is a simpler version of Pitem(). This version cannot be used if a
  196. // new item needs to be created.
  197. virtual CBaseSnapinItem * Pitem( LPDATAOBJECT lpDataObject = NULL,
  198. HSCOPEITEM hscopeitem = 0,
  199. long cookie = 0);
  200. //
  201. // Information about this snapin
  202. //
  203. virtual const CSnapinInfo * Psnapininfo(void) = 0;
  204. virtual BOOL FIsExtension(void) { return FALSE;}
  205. // Does it have a standalone mode?
  206. virtual BOOL FStandalone(void) { return FALSE;}
  207. virtual SNR * Psnr(INT i=0) = 0;
  208. virtual INT Csnr(void) = 0;
  209. virtual LONG IdsDescription(void) = 0;
  210. virtual LONG IdsName(void) = 0;
  211. virtual LONG Idi(void) { return 0;}
  212. // Does it support IComponent2?
  213. virtual BOOL FSupportsIComponent2() { return FALSE;}
  214. //
  215. // Persistence
  216. //
  217. virtual SC ScLoad(IStream *pstream) { return S_OK;}
  218. virtual SC ScSave(IStream *pstream, BOOL fClearDirty) { return S_OK;}
  219. //
  220. // Columns
  221. //
  222. // $REVIEW (ptousig) It doesn't really makes sense to have the column
  223. // information in the snapin class. But since all the
  224. // snapins are already built this way, I'm leaving it
  225. // in.
  226. //
  227. virtual CColumnInfoEx * Pcolinfoex(INT icolinfo=0) { ASSERT("Should not happen" && FALSE); return NULL;}
  228. virtual INT Ccolinfoex(void) { ASSERT("Should not happen" && FALSE); return 0;}
  229. //
  230. // Bitmaps and icons
  231. //
  232. virtual SC ScInitBitmaps(void);
  233. virtual WTL::CBitmap & BmpImage16(void) { return s_bmpImage16;}
  234. virtual WTL::CBitmap & BmpImage32(void) { return s_bmpImage32;}
  235. virtual WTL::CBitmap * PbitmapImageListSmall(void) { return &BitmapSmall();}
  236. virtual WTL::CBitmap * PbitmapImageListLarge(void) { return &BitmapLarge();}
  237. virtual LONG * Piconid(void) = 0;
  238. virtual INT CIcons(void) = 0;
  239. virtual LONG * PiconidStatic(void) = 0;
  240. virtual WTL::CBitmap & BitmapSmall(void) = 0;
  241. virtual WTL::CBitmap & BitmapLarge(void) = 0;
  242. virtual WTL::CBitmap & BitmapStaticSmall(void) = 0;
  243. virtual WTL::CBitmap & BitmapStaticSmallOpen(void) = 0;
  244. virtual WTL::CBitmap & BitmapStaticLarge(void) = 0;
  245. //
  246. // Verbs
  247. //
  248. static VerbMap * Pverbmap(INT i=0);
  249. static INT Cverbmap(void);
  250. virtual MMC_CONSOLE_VERB MmcverbDefault(LPDATAOBJECT lpDataObject);
  251. virtual SC ScGetVerbs(LPDATAOBJECT lpDataObject, DWORD * pdwVerbs);
  252. //
  253. // Shortcuts. These methods only forward the calls to the CSnapinInfo.
  254. //
  255. virtual const tstring& StrClassName(void) { return Psnapininfo()->StrClassName();}
  256. virtual const CLSID * PclsidSnapin(void) { return Psnapininfo()->PclsidSnapin();}
  257. virtual const tstring& StrClsidSnapin(void) { return Psnapininfo()->StrClsidSnapin();}
  258. virtual const tstring& StrClsidAbout(void) { return Psnapininfo()->StrClsidAbout();}
  259. //
  260. // Snapin registration
  261. //
  262. virtual SC ScRegister(BOOL fRegister = TRUE);
  263. inline IRegistrar & Registrar(void) { return s_registrar;}
  264. //
  265. // ISnapinAbout interface
  266. //
  267. virtual SC ScGetSnapinDescription(LPOLESTR *lpDescription) { return ScIds2OleStr(IdsDescription(), lpDescription);}
  268. virtual SC ScGetSnapinVersion(LPOLESTR *lpVersion);
  269. virtual SC ScGetSnapinImage(HICON *phAppIcon);
  270. virtual SC ScGetStaticFolderImage(HBITMAP *phSmallImage, HBITMAP *phSmallImageOpen, HBITMAP *phLargeImage, COLORREF *pcMask);
  271. virtual SC ScGetProvider(LPOLESTR *lpName);
  272. //
  273. // Other stuff
  274. // These functions are here because:
  275. // - The functionality is the same for both CComponentData and CComponent
  276. // - The functionality can be overriden by a derived class.
  277. //
  278. // $REVIEW (ptousig) Figure out which is which.
  279. //
  280. virtual SC ScAddMenuItems(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK ipContextMenuCallback, long *pInsertionAllowed);
  281. virtual SC ScAddMenuItems(CBaseSnapinItem *pitem, long lInsertionAllowed, LPCONTEXTMENUCALLBACK ipContextMenuCallback, SnapinMenuItem *rgmenuitem, INT cmenuitem);
  282. virtual SC ScGetMenuItem(CSnapinContextMenuItem * pMenuItemReturned, CBaseSnapinItem * pitem, SnapinMenuItem * pMenuItemSource, BOOL * pfAllowed, long lInsertionAllowed);
  283. virtual SC ScIsPastableDataObject(CBaseSnapinItem * pitemTarget, LPDATAOBJECT lpDataObject, BOOL * pfPastable);
  284. virtual SC ScIsOwnedDataObject(LPDATAOBJECT pdataobject, BOOL *pfIsOwned, CNodeType **ppnodetype);
  285. virtual SC ScGetHelpTopic(tstring& strCompiledHelpFile);
  286. virtual SC ScCompare(MMC_COOKIE cookieA, MMC_COOKIE cookieB, INT nColumn, INT * pnResult);
  287. virtual SC ScCompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  288. virtual SC ScOnPropertyChange(BOOL fScope, LPARAM lParam, IConsoleNameSpace *ipConsoleNameSpace, IConsole *ipConsole);
  289. virtual SC ScOnRename(LPDATAOBJECT lpDataObject, const tstring& szNewName, IConsole *ipConsole);
  290. virtual SC ScOnPaste(LPDATAOBJECT lpDataObject, LPDATAOBJECT lpDataObjectList, LPDATAOBJECT *ppDataObjectPasted, IConsole *ipConsole);
  291. virtual SC ScOnQueryPaste(LPDATAOBJECT lpDataObject, LPDATAOBJECT lpDataObjectList, LPDWORD pdwFlags);
  292. virtual SC ScOnCanPasteOutOfProcDataObject(LPBOOL pbCanHandle);
  293. virtual SC ScOnCutOrMove(LPDATAOBJECT lpDataObjectList, IConsoleNameSpace *ipConsoleNameSpace, IConsole *ipConsole);
  294. inline const tstring& StrDisplayName(void) { return *m_pstrDisplayName;}
  295. // Multiselect support (by default, snapin items are not enabled to allow multi support selection)
  296. virtual SC ScCreateMultiSelectionDataObject(LPDATAOBJECT * ppDataObject, CComponent * pComponent);
  297. virtual SC ScAllocateMultiSelectionDataObject(CBaseMultiSelectSnapinItem ** ppBaseMultiSelectSnapinItem);
  298. #ifdef _DEBUG
  299. //
  300. // Debug menu options
  301. //
  302. SnapinMenuItem * PmenuitemBase(void);
  303. INT CMenuItemBase(void);
  304. //
  305. // Debug methods called from debug menu options
  306. //
  307. #if 0
  308. virtual SC ScOnMenuTraces(void);
  309. virtual SC ScOnMenuSCDescription(void);
  310. virtual SC ScOnMenuMemoryDiff(void);
  311. virtual SC ScOnMenuValidateMemory(void);
  312. virtual SC ScOnMenuTotalMemory(void);
  313. #endif
  314. #endif
  315. protected:
  316. //
  317. // The display name for this snapin, this gets populated by
  318. // derived classes, so it needs to be 'protected'.
  319. //
  320. // $REVIEW (ptousig) Snapins should use an accessor.
  321. //
  322. tstring* m_pstrDisplayName;
  323. private:
  324. // The list of root items
  325. ItemList m_ilRootItems;
  326. // The list of valid cookies
  327. CCookieList m_cookielist;
  328. private:
  329. static BOOL s_fBaseSnapinInitialized; // Has the bitmaps been initialized ?
  330. static VerbMap s_rgverbmap[];
  331. static CRegistrar s_registrar;
  332. static WTL::CBitmap s_bmpImage16; // Pointer to 16x16 image strip
  333. static WTL::CBitmap s_bmpImage32; // Pointer to 32x32 image strip
  334. #ifdef _DEBUG
  335. //
  336. // The debug menu options ("Traces", etc...)
  337. //
  338. static SnapinMenuItem s_rgmenuitemBase[];
  339. static INT s_cMenuItemBase;
  340. #endif // _DEBUG
  341. };