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.

347 lines
11 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) 1995-1996 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. // CSnapin.h : Declaration of the CSnapin
  9. #include "resource.h" // main symbols
  10. #ifndef __mmc_h__
  11. #include <mmc.h>
  12. #endif
  13. #include "objidl.h"
  14. #include "data.h"
  15. #include "amsp.h"
  16. #include "gptedit.h"
  17. // Note - This is the offset in my image list that represents the folder
  18. const FOLDER_IMAGE_IDX = 0;
  19. const OPEN_FOLDER_IMAGE_IDX = 5;
  20. extern HINSTANCE ghInstance;
  21. extern const CLSID CLSID_Snapin;
  22. extern const wchar_t * szCLSID_Snapin;
  23. extern const GUID cNodeType;
  24. extern const wchar_t* cszNodeType;
  25. /////////////////////////////////////////////////////////////////////////////
  26. // Snapin
  27. INTERNAL* ExtractInternalFormat(LPDATAOBJECT lpDataObject);
  28. class CComponentDataImpl:
  29. public IComponentData,
  30. public IExtendContextMenu,
  31. public IPersistStreamInit,
  32. public CComObjectRoot,
  33. public IAppManagerActions,
  34. public CComCoClass<CComponentDataImpl, &CLSID_Snapin>
  35. {
  36. BEGIN_COM_MAP(CComponentDataImpl)
  37. COM_INTERFACE_ENTRY(IComponentData)
  38. COM_INTERFACE_ENTRY(IExtendContextMenu)
  39. COM_INTERFACE_ENTRY(IPersistStreamInit)
  40. COM_INTERFACE_ENTRY(IAppManagerActions)
  41. END_COM_MAP()
  42. DECLARE_REGISTRY(CSnapin, _T("AppManager.1"), _T("AppManager"), IDS_SNAPIN_DESC, THREADFLAGS_BOTH)
  43. friend class CSnapin;
  44. friend class CDataObject;
  45. CComponentDataImpl();
  46. ~CComponentDataImpl();
  47. protected:
  48. LPGPTINFORMATION m_pIGPTInformation; // Interface pointer to the GPT
  49. public:
  50. // IComponentData interface members
  51. STDMETHOD(Initialize)(LPUNKNOWN pUnknown);
  52. STDMETHOD(CreateComponent)(LPCOMPONENT* ppComponent);
  53. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param);
  54. STDMETHOD(Destroy)();
  55. STDMETHOD(QueryDataObject)(long cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject);
  56. STDMETHOD(GetDisplayInfo)(SCOPEDATAITEM* pScopeDataItem);
  57. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  58. // IExtendContextMenu
  59. public:
  60. STDMETHOD(AddMenuItems)(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK pCallbackUnknown, LONG * pInsertionAllowed);
  61. STDMETHOD(Command)(long nCommandID, LPDATAOBJECT pDataObject);
  62. public:
  63. // IPersistStreamInit interface members
  64. STDMETHOD(GetClassID)(CLSID *pClassID);
  65. STDMETHOD(IsDirty)();
  66. STDMETHOD(Load)(IStream *pStm);
  67. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  68. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize);
  69. STDMETHOD(InitNew)(VOID);
  70. public:
  71. // IAppManagerActions,
  72. STDMETHOD(CanPackageBeAssigned)(ULONG cookie);
  73. STDMETHOD(MovePackageToAssigned)(ULONG cookie);
  74. STDMETHOD(MovePackageToPublished)(ULONG cookie);
  75. STDMETHOD(ReloadPackageData)(ULONG cookie);
  76. STDMETHOD(NotifyClients)(BOOL f);
  77. // Notify handler declarations
  78. private:
  79. HRESULT OnAdd(long cookie, long arg, long param);
  80. HRESULT OnDelete(long cookie, long arg, long param);
  81. HRESULT OnRename(long cookie, long arg, long param);
  82. HRESULT OnExpand(long cookie, long arg, long param);
  83. HRESULT OnSelect(long cookie, long arg, long param);
  84. HRESULT OnContextMenu(long cookie, long arg, long param);
  85. HRESULT OnProperties(long param);
  86. #if DBG==1
  87. public:
  88. ULONG InternalAddRef()
  89. {
  90. return CComObjectRoot::InternalAddRef();
  91. }
  92. ULONG InternalRelease()
  93. {
  94. return CComObjectRoot::InternalRelease();
  95. }
  96. #endif // DBG==1
  97. // Scope item creation helpers
  98. private:
  99. void DeleteList();
  100. void EnumerateScopePane(long cookie, HSCOPEITEM pParent);
  101. BOOL IsScopePaneNode(LPDATAOBJECT lpDataObject);
  102. HRESULT InitializeClassAdmin();
  103. HRESULT AddMSIPackage(LPDATAOBJECT pDataObject, LPSTR szPackagePath, LPSTR szFilePath,
  104. LPOLESTR lpFileTitle, BOOL *bAssigned);
  105. HRESULT RemovePackage(LPDATAOBJECT pDataObject, BOOL *bAssigned);
  106. private:
  107. LPCONSOLENAMESPACE m_pScope; // My interface pointer to the scope pane
  108. LPCONSOLE m_pConsole;
  109. BOOL m_bIsDirty;
  110. IClassAdmin * m_pIClassAdmin;
  111. BOOL m_fExtension;
  112. BOOL m_fLoaded;
  113. void SetDirty(BOOL b = TRUE) { m_bIsDirty = b; }
  114. void ClearDirty() { m_bIsDirty = FALSE; }
  115. BOOL ThisIsDirty() { return m_bIsDirty; }
  116. void AddScopeItemToResultPane(long cookie);
  117. HRESULT CreateApplicationDirectories(VOID);
  118. UINT CreateNestedDirectory (LPTSTR lpPath, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
  119. CSnapin * m_pSnapin;
  120. public:
  121. CString m_szGPT_Path;
  122. CString m_szLDAP_Path;
  123. CString m_szFolderTitle;
  124. std::map <long, APP_DATA> m_AppData;
  125. long m_lLastAllocated;
  126. };
  127. class CSnapin :
  128. public IComponent,
  129. public IExtendContextMenu, // Step 3
  130. // public IExtendControlbar,
  131. public IExtendPropertySheet,
  132. public IResultDataCompare,
  133. public CComObjectRoot
  134. {
  135. public:
  136. CSnapin();
  137. ~CSnapin();
  138. BEGIN_COM_MAP(CSnapin)
  139. COM_INTERFACE_ENTRY(IComponent)
  140. COM_INTERFACE_ENTRY(IExtendContextMenu) // Step 3
  141. // COM_INTERFACE_ENTRY(IExtendControlbar)
  142. COM_INTERFACE_ENTRY(IResultDataCompare)
  143. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  144. END_COM_MAP()
  145. // DECLARE_REGISTRY(CSnapin, _T("Snapin.Snapin.1"), _T("Snapin.Snapin"), IDS_SNAPIN_DESC, THREADFLAGS_BOTH)
  146. friend class CDataObject;
  147. static long lDataObjectRefCount;
  148. // IComponent interface members
  149. public:
  150. STDMETHOD(Initialize)(LPCONSOLE lpConsole);
  151. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param);
  152. STDMETHOD(Destroy)(long cookie);
  153. STDMETHOD(GetResultViewType)(long cookie, BSTR* ppViewType, LONG * pViewOptions);
  154. STDMETHOD(QueryDataObject)(long cookie, DATA_OBJECT_TYPES type,
  155. LPDATAOBJECT* ppDataObject);
  156. STDMETHOD(GetDisplayInfo)(RESULTDATAITEM* pResultDataItem);
  157. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  158. // IResultDataCompare
  159. STDMETHOD(Compare)(long lUserParam, long cookieA, long cookieB, int* pnResult);
  160. // IExtendControlbar
  161. // STDMETHOD(SetControlbar)(LPCONTROLBAR pControlbar);
  162. // STDMETHOD(ControlbarNotify)(MMC_NOTIFY_TYPE event, long arg, long param);
  163. // IExtendPropertySheet interface
  164. public:
  165. STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,
  166. long handle,
  167. LPDATAOBJECT lpIDataObject);
  168. STDMETHOD(QueryPagesFor)(LPDATAOBJECT lpDataObject);
  169. // Helpers for CSnapin
  170. public:
  171. void SetIComponentData(CComponentDataImpl* pData);
  172. #if DBG==1
  173. public:
  174. int dbg_cRef;
  175. ULONG InternalAddRef()
  176. {
  177. ++dbg_cRef;
  178. return CComObjectRoot::InternalAddRef();
  179. }
  180. ULONG InternalRelease()
  181. {
  182. --dbg_cRef;
  183. return CComObjectRoot::InternalRelease();
  184. }
  185. #endif // DBG==1
  186. // Notify event handlers
  187. protected:
  188. HRESULT OnFolder(long cookie, long arg, long param);
  189. HRESULT OnShow(long cookie, long arg, long param);
  190. HRESULT OnActivate(long cookie, long arg, long param);
  191. HRESULT OnMinimize(long cookie, long arg, long param);
  192. HRESULT OnSelect(DATA_OBJECT_TYPES type, long cookie, long arg, long param);
  193. HRESULT OnPropertyChange(long param); // Step 3
  194. HRESULT OnUpdateView(LPDATAOBJECT lpDataObject);
  195. HRESULT OnResultItemClkOrDblClk(long cookie, BOOL fDblClick);
  196. HRESULT OnAddImages(long cookie, long arg, long param);
  197. // IExtendContextMenu
  198. public:
  199. STDMETHOD(AddMenuItems)(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK pCallbackUnknown, LONG * pInsertionAllowed);
  200. STDMETHOD(Command)(long nCommandID, LPDATAOBJECT pDataObject);
  201. // End step 3
  202. // Helper functions
  203. protected:
  204. BOOL IsEnumerating(LPDATAOBJECT lpDataObject);
  205. void Construct();
  206. void LoadResources();
  207. HRESULT InitializeHeaders(long cookie);
  208. void Enumerate(long cookie, HSCOPEITEM pParent);
  209. HRESULT InitializeBitmaps(long cookie);
  210. public:
  211. void EnumerateResultPane(long cookie);
  212. // Interface pointers
  213. protected:
  214. LPCONSOLE m_pConsole; // Console's IFrame interface
  215. LPHEADERCTRL m_pHeader; // Result pane's header control interface
  216. CComponentDataImpl * m_pComponentData;
  217. IPropertySheetProvider * m_pIPropertySheetProvider;
  218. LPCONSOLEVERB m_pConsoleVerb; // pointer the console verb
  219. LONG m_lViewMode; // View mode
  220. public:
  221. LPRESULTDATA m_pResult; // My interface pointer to the result pane
  222. LPIMAGELIST m_pImageResult; // My interface pointer to the result pane image list
  223. protected:
  224. // LPTOOLBAR m_pToolbar1; // Toolbar for view
  225. // LPTOOLBAR m_pToolbar2; // Toolbar for view
  226. // LPCONTROLBAR m_pControlbar; // control bar to hold my tool bars
  227. // CBitmap* m_pbmpToolbar1; // Imagelist for the first toolbar
  228. // CBitmap* m_pbmpToolbar2; // Imagelist for the first toolbar
  229. IClassAdmin * m_pIClassAdmin;
  230. IAppManagerActions * m_pIAppManagerActions;
  231. // Header titles for each nodetype(s)
  232. protected:
  233. CString m_column1;
  234. CString m_column2;
  235. CString m_column3;
  236. CString m_column4;
  237. CString m_column5;
  238. CString m_column6;
  239. CString m_column7;
  240. CString m_szAddApp;
  241. CString m_szDelApp;
  242. CString m_szUpdateApp;
  243. CString m_szAddFromIe;
  244. CString m_szShowData;
  245. CString m_szAddAppDesc;
  246. CString m_szDelAppDesc;
  247. CString m_szUpdateAppDesc;
  248. CString m_szAddFromIeDesc;
  249. CString m_szShowDataDesc;
  250. CString m_szFolderTitle;
  251. CString m_szRefresh;
  252. CString m_szRefreshDesc;
  253. };
  254. inline void CSnapin::SetIComponentData(CComponentDataImpl* pData)
  255. {
  256. ASSERT(pData);
  257. ASSERT(m_pComponentData == NULL);
  258. LPUNKNOWN pUnk = pData->GetUnknown();
  259. HRESULT hr;
  260. LPCOMPONENTDATA lpcd;
  261. hr = pUnk->QueryInterface(IID_IComponentData, reinterpret_cast<void**>(&lpcd));
  262. ASSERT(hr == S_OK);
  263. m_pComponentData = dynamic_cast<CComponentDataImpl*>(lpcd);
  264. hr = pUnk->QueryInterface(IID_IAppManagerActions, reinterpret_cast<void**>(&m_pIAppManagerActions));
  265. ASSERT(hr == S_OK);
  266. }
  267. #define FREE_INTERNAL(pInternal) \
  268. ASSERT(pInternal != NULL); \
  269. do { if (pInternal != NULL) \
  270. GlobalFree(pInternal); } \
  271. while(0);
  272. class CHourglass
  273. {
  274. private:
  275. HCURSOR m_hcurSaved;
  276. public:
  277. CHourglass()
  278. {
  279. m_hcurSaved = ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT)));
  280. };
  281. ~CHourglass()
  282. {
  283. ::SetCursor(m_hcurSaved);
  284. };
  285. };
  286. #define ATOW(wsz, sz, cch) MultiByteToWideChar(CP_ACP, 0, sz, -1, wsz, cch)
  287. #define WTOA(sz, wsz, cch) WideCharToMultiByte(CP_ACP, 0, wsz, -1, sz, cch, NULL, NULL)
  288. #define ATOWLEN(sz) MultiByteToWideChar(CP_ACP, 0, sz, -1, NULL, 0)
  289. #define WTOALEN(wsz) WideCharToMultiByte(CP_ACP, 0, wsz, -1, NULL, 0, NULL, NULL)