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.

457 lines
15 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: common.h
  7. //
  8. // Contents: common definitions used by the main snapin modules
  9. //
  10. // Classes: CResultPane, CScopePane
  11. //
  12. // History: 03-17-1998 stevebl Created
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "resource.h" // main symbols
  16. #ifndef __mmc_h__
  17. #include <mmc.h>
  18. #endif
  19. #include <vector>
  20. #include <malloc.h>
  21. #include <objsel.h>
  22. #include <shlwapi.h>
  23. #include "objidl.h"
  24. #include "gpedit.h"
  25. #include "iads.h"
  26. #include "HelpArr.h"
  27. #include "Path.hxx"
  28. #include "PathSlct.hxx"
  29. #include "redirect.hxx"
  30. #include "FileInfo.hxx"
  31. #include "utils.hxx"
  32. #include "error.hxx"
  33. #include "security.hxx"
  34. #include "secpath.hxx"
  35. #include "prefs.hxx"
  36. #include "rsopinfo.h"
  37. #include "rsopprop.h"
  38. ///////////////////////////////////////////////////////////////////
  39. // workaround macro for MFC bug
  40. // (see NTRAID 342926 and MFC "Monte Carlo" RAID db # 1034)
  41. #define FIX_THREAD_STATE_MFC_BUG() \
  42. AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState(); \
  43. CWinThread _dummyWinThread; \
  44. if (pState->m_pCurrentWinThread == NULL) \
  45. { \
  46. pState->m_pCurrentWinThread = &_dummyWinThread; \
  47. }
  48. //get the index of a cookie in the folder cache of the scope pane
  49. #define GETINDEX(x) (((x) < IDS_DIRS_END && (x) >= IDS_DIRS_START) ? ((x) - IDS_DIRS_START) : -1)
  50. // private notifications
  51. #define WM_USER_REFRESH WM_USER
  52. #define WM_USER_CLOSE (WM_USER + 1)
  53. #define MAX_DS_PATH 1024
  54. // Other private notifications.
  55. #define WM_PATH_TWEAKED (WM_APP + 1)
  56. //the max. possible length of the path that can be entered into the edit control
  57. #define TARGETPATHLIMIT MAX_PATH - 4
  58. // Note - This is the offset in my image list that represents the folder
  59. const FOLDER_IMAGE_IDX = 0;
  60. const OPEN_FOLDER_IMAGE_IDX = 5;
  61. extern HINSTANCE ghInstance;
  62. extern const CLSID CLSID_Snapin;
  63. extern const wchar_t * szCLSID_Snapin;
  64. extern const GUID cNodeType;
  65. extern const wchar_t* cszNodeType;
  66. //the GUID for the client side extension
  67. extern GUID guidExtension;
  68. extern CString szExtension;
  69. extern CString szFilter;
  70. // RSOP GUIDS
  71. extern const CLSID CLSID_RSOP_Snapin;
  72. extern const wchar_t * szCLSID_RSOP_Snapin;
  73. #define IMG_OPENBOX 0
  74. #define IMG_CLOSEDBOX 1
  75. #define IMG_DISABLED 2
  76. #define IMG_PUBLISHED 3
  77. #define IMG_ASSIGNED 4
  78. #define IMG_UPGRADE 5
  79. //
  80. // MACROS for allocating and freeing memory via OLE's common allocator: IMalloc.
  81. //
  82. extern IMalloc * g_pIMalloc;
  83. // UNDONE - throw exception on failure
  84. //#define OLEALLOC(x) new char [x]
  85. #define OLEALLOC(x) g_pIMalloc->Alloc(x)
  86. //#define OLESAFE_DELETE(x) if (x) {delete x; x = NULL;}
  87. #define OLESAFE_DELETE(x) if (x) {g_pIMalloc->Free(x); x = NULL;}
  88. #define OLESAFE_COPYSTRING(szO, szI) {if (szI) {int i_dontcollidewithanything = wcslen(szI); szO=(OLECHAR *)OLEALLOC(sizeof(OLECHAR) * (i_dontcollidewithanything+1)); HRESULT hr = StringCchCopy(szO, i_dontcollidewithanything+1, szI);ASSERT(SUCCEEDED(hr));} else szO=NULL;}
  89. /////////////////////////////////////////////////////////////////////////////
  90. // Snapin
  91. INTERNAL* ExtractInternalFormat(LPDATAOBJECT lpDataObject);
  92. class CScopePane:
  93. public IComponentData,
  94. public IExtendContextMenu,
  95. public IPersistStreamInit,
  96. public CComObjectRoot,
  97. public IExtendPropertySheet,
  98. public ISnapinAbout,
  99. public ISnapinHelp
  100. {
  101. friend class CResultPane;
  102. friend class CDataObject;
  103. friend class CRedirect;
  104. friend HRESULT ConvertOldStyleSection (const CString&, const CScopePane*);
  105. public:
  106. CScopePane();
  107. ~CScopePane();
  108. protected:
  109. LPGPEINFORMATION m_pIGPEInformation; // Interface pointer to the GPT
  110. LPRSOPINFORMATION m_pIRSOPInformation; // Interface pointer to the GPT
  111. CFileInfo m_FolderData[IDS_DIRS_END - IDS_DIRS_START];
  112. public:
  113. virtual IUnknown * GetMyUnknown() = 0;
  114. // IComponentData interface members
  115. STDMETHOD(Initialize)(LPUNKNOWN pUnknown);
  116. STDMETHOD(CreateComponent)(LPCOMPONENT* ppComponent);
  117. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  118. STDMETHOD(Destroy)();
  119. STDMETHOD(QueryDataObject)(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject);
  120. STDMETHOD(GetDisplayInfo)(SCOPEDATAITEM* pScopeDataItem);
  121. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  122. // IExtendContextMenu
  123. public:
  124. STDMETHOD(AddMenuItems)(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK pCallbackUnknown, LONG * pInsertionAllowed);
  125. STDMETHOD(Command)(long nCommandID, LPDATAOBJECT pDataObject);
  126. public:
  127. // IPersistStreamInit interface members
  128. STDMETHOD(GetClassID)(CLSID *pClassID);
  129. STDMETHOD(IsDirty)();
  130. STDMETHOD(Load)(IStream *pStm);
  131. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  132. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize);
  133. STDMETHOD(InitNew)(VOID);
  134. // IExtendPropertySheet interface
  135. public:
  136. STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,
  137. LONG_PTR handle,
  138. LPDATAOBJECT lpIDataObject);
  139. STDMETHOD(QueryPagesFor)(LPDATAOBJECT lpDataObject);
  140. // ISnapinAbout interface
  141. public:
  142. STDMETHOD(GetSnapinDescription)(LPOLESTR * lpDescription);
  143. STDMETHOD(GetProvider)(LPOLESTR * lpName);
  144. STDMETHOD(GetSnapinVersion)(LPOLESTR * lpVersion);
  145. STDMETHOD(GetSnapinImage)(HICON * hAppIcon);
  146. STDMETHOD(GetStaticFolderImage)(HBITMAP * hSmallImage,
  147. HBITMAP * hSmallImageOpen,
  148. HBITMAP * hLargeImage,
  149. COLORREF * cMask);
  150. //
  151. // Implemented ISnapinHelp interface members
  152. //
  153. public:
  154. STDMETHOD(GetHelpTopic)(LPOLESTR *lpCompiledHelpFile);
  155. // Notify handler declarations
  156. private:
  157. HRESULT OnAdd(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  158. HRESULT OnExpand(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  159. HRESULT OnSelect(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  160. HRESULT OnContextMenu(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  161. HRESULT OnProperties(LPARAM param);
  162. #if DBG==1
  163. public:
  164. ULONG InternalAddRef()
  165. {
  166. return CComObjectRoot::InternalAddRef();
  167. }
  168. ULONG InternalRelease()
  169. {
  170. return CComObjectRoot::InternalRelease();
  171. }
  172. #endif // DBG==1
  173. // Scope item creation helpers
  174. private:
  175. void EnumerateScopePane(MMC_COOKIE cookie, HSCOPEITEM pParent);
  176. BOOL IsScopePaneNode(LPDATAOBJECT lpDataObject);
  177. private:
  178. LPCONSOLENAMESPACE m_pScope; // My interface pointer to the scope pane
  179. LPCONSOLE m_pConsole;
  180. LPDISPLAYHELP m_pDisplayHelp;
  181. BOOL m_bIsDirty;
  182. BOOL m_fExtension;
  183. BOOL m_fLoaded;
  184. void SetDirty(BOOL b = TRUE) { m_bIsDirty = b; }
  185. void ClearDirty() { m_bIsDirty = FALSE; }
  186. BOOL ThisIsDirty() { return m_bIsDirty; }
  187. UINT CreateNestedDirectory (LPTSTR lpPath, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
  188. void LoadToolDefaults();
  189. void SaveToolDefaults();
  190. CResultPane * m_pResultPane;
  191. IPropertySheetProvider * m_pIPropertySheetProvider;
  192. public:
  193. CString m_szFileRoot;
  194. CString m_szFolderTitle;
  195. CString m_szRSOPNamespace;
  196. BOOL m_fRSOP;
  197. };
  198. class CResultPane :
  199. public IComponent,
  200. public IExtendContextMenu,
  201. // COM_INTERFACE_ENTRY(IExtendControlbar)
  202. public IExtendPropertySheet,
  203. public IResultDataCompare,
  204. public CComObjectRoot
  205. {
  206. public:
  207. CResultPane();
  208. ~CResultPane();
  209. BEGIN_COM_MAP(CResultPane)
  210. COM_INTERFACE_ENTRY(IComponent)
  211. COM_INTERFACE_ENTRY(IExtendContextMenu)
  212. // COM_INTERFACE_ENTRY(IExtendControlbar)
  213. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  214. COM_INTERFACE_ENTRY(IResultDataCompare)
  215. END_COM_MAP()
  216. friend class CDataObject;
  217. static long lDataObjectRefCount;
  218. // IComponent interface members
  219. public:
  220. STDMETHOD(Initialize)(LPCONSOLE lpConsole);
  221. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  222. STDMETHOD(Destroy)(MMC_COOKIE cookie);
  223. STDMETHOD(GetResultViewType)(MMC_COOKIE cookie, BSTR* ppViewType, LONG * pViewOptions);
  224. STDMETHOD(QueryDataObject)(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  225. LPDATAOBJECT* ppDataObject);
  226. STDMETHOD(GetDisplayInfo)(RESULTDATAITEM* pResultDataItem);
  227. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  228. // IResultDataCompare
  229. STDMETHOD(Compare)(LPARAM lUserParam, MMC_COOKIE cookieA, MMC_COOKIE cookieB, int* pnResult);
  230. // IExtendControlbar
  231. // STDMETHOD(SetControlbar)(LPCONTROLBAR pControlbar);
  232. // STDMETHOD(ControlbarNotify)(MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  233. // IExtendPropertySheet interface
  234. public:
  235. STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,
  236. LONG_PTR handle,
  237. LPDATAOBJECT lpIDataObject);
  238. STDMETHOD(QueryPagesFor)(LPDATAOBJECT lpDataObject);
  239. // Helpers for CResultPane
  240. public:
  241. void SetIComponentData(CScopePane* pData);
  242. #if DBG==1
  243. public:
  244. int dbg_cRef;
  245. ULONG InternalAddRef()
  246. {
  247. ++dbg_cRef;
  248. return CComObjectRoot::InternalAddRef();
  249. }
  250. ULONG InternalRelease()
  251. {
  252. --dbg_cRef;
  253. return CComObjectRoot::InternalRelease();
  254. }
  255. #endif // DBG==1
  256. // Notify event handlers
  257. protected:
  258. HRESULT OnFolder(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  259. HRESULT OnShow(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  260. HRESULT OnActivate(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  261. HRESULT OnMinimize(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  262. HRESULT OnSelect(DATA_OBJECT_TYPES type, MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  263. HRESULT OnPropertyChange(LPARAM param); // Step 3
  264. HRESULT OnUpdateView(LPDATAOBJECT lpDataObject);
  265. HRESULT OnResultItemClkOrDblClk(MMC_COOKIE cookie, BOOL fDblClick);
  266. HRESULT OnContextHelp(void);
  267. public:
  268. HRESULT TestForRSOPData(MMC_COOKIE cookie);
  269. HRESULT OnAddImages(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  270. // IExtendContextMenu
  271. public:
  272. STDMETHOD(AddMenuItems)(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK pCallbackUnknown, LONG * pInsertionAllowed);
  273. STDMETHOD(Command)(long nCommandID, LPDATAOBJECT pDataObject);
  274. // Helper functions
  275. protected:
  276. void Construct();
  277. void LoadResources();
  278. HRESULT InitializeHeaders(MMC_COOKIE cookie);
  279. // Interface pointers
  280. protected:
  281. LPCONSOLE m_pConsole; // Console's IFrame interface
  282. LPHEADERCTRL m_pHeader; // Result pane's header control interface
  283. CScopePane * m_pScopePane;
  284. LPCONSOLEVERB m_pConsoleVerb; // pointer the console verb
  285. LONG m_lViewMode; // View mode
  286. HSCOPEITEM m_hCurrScopeItem; //the scope item whose elements are
  287. //currently being displayed in the
  288. //result pane
  289. public:
  290. LPRESULTDATA m_pResult; // My interface pointer to the result pane
  291. int m_nSortColumn;
  292. DWORD m_dwSortOptions;
  293. protected:
  294. // LPTOOLBAR m_pToolbar1; // Toolbar for view
  295. // LPTOOLBAR m_pToolbar2; // Toolbar for view
  296. // LPCONTROLBAR m_pControlbar; // control bar to hold my tool bars
  297. // CBitmap* m_pbmpToolbar1; // Imagelist for the first toolbar
  298. // CBitmap* m_pbmpToolbar2; // Imagelist for the first toolbar
  299. // Header titles for each nodetype(s)
  300. protected:
  301. CString m_columns[IDS_LAST_COL - IDS_FIRST_COL];
  302. CString m_RSOP_columns[IDS_LAST_RSOP_COL - IDS_FIRST_RSOP_COL];
  303. CString m_szFolderTitle;
  304. map <UINT, CRSOPInfo> m_RSOPData;
  305. UINT m_nIndex ;
  306. };
  307. class CUserComponentDataImpl:
  308. public CScopePane,
  309. public CComCoClass<CUserComponentDataImpl, &CLSID_Snapin>
  310. {
  311. public:
  312. DECLARE_REGISTRY(CResultPane, _T("FDE.1"), _T("FDE"), IDS_SNAPIN_DESC, THREADFLAGS_BOTH)
  313. BEGIN_COM_MAP(CUserComponentDataImpl)
  314. COM_INTERFACE_ENTRY(IComponentData)
  315. COM_INTERFACE_ENTRY(IExtendContextMenu)
  316. COM_INTERFACE_ENTRY(IPersistStreamInit)
  317. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  318. COM_INTERFACE_ENTRY(ISnapinAbout)
  319. COM_INTERFACE_ENTRY(ISnapinHelp)
  320. END_COM_MAP()
  321. CUserComponentDataImpl()
  322. {
  323. m_fRSOP = FALSE;
  324. }
  325. virtual IUnknown * GetMyUnknown() {return GetUnknown();};
  326. };
  327. class CRSOPUserComponentDataImpl:
  328. public CScopePane,
  329. public CComCoClass<CRSOPUserComponentDataImpl, &CLSID_RSOP_Snapin>
  330. {
  331. public:
  332. DECLARE_REGISTRY(CResultPane, _T("FDE.1"), _T("FDE"), IDS_SNAPIN_DESC, THREADFLAGS_BOTH)
  333. BEGIN_COM_MAP(CRSOPUserComponentDataImpl)
  334. COM_INTERFACE_ENTRY(IComponentData)
  335. COM_INTERFACE_ENTRY(IExtendContextMenu)
  336. COM_INTERFACE_ENTRY(IPersistStreamInit)
  337. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  338. COM_INTERFACE_ENTRY(ISnapinAbout)
  339. COM_INTERFACE_ENTRY(ISnapinHelp)
  340. END_COM_MAP()
  341. CRSOPUserComponentDataImpl()
  342. {
  343. m_fRSOP = TRUE;
  344. }
  345. virtual IUnknown * GetMyUnknown() {return GetUnknown();};
  346. };
  347. inline void CResultPane::SetIComponentData(CScopePane* pData)
  348. {
  349. ASSERT(pData);
  350. ASSERT(m_pScopePane == NULL);
  351. LPUNKNOWN pUnk = pData->GetMyUnknown();
  352. HRESULT hr;
  353. LPCOMPONENTDATA lpcd;
  354. hr = pUnk->QueryInterface(IID_IComponentData, reinterpret_cast<void**>(&lpcd));
  355. ASSERT(hr == S_OK);
  356. m_pScopePane = dynamic_cast<CScopePane*>(lpcd);
  357. }
  358. #define FREE_INTERNAL(pInternal) \
  359. ASSERT(pInternal != NULL); \
  360. do { if (pInternal != NULL) \
  361. GlobalFree(pInternal); } \
  362. while(0);
  363. class CHourglass
  364. {
  365. private:
  366. HCURSOR m_hcurSaved;
  367. public:
  368. CHourglass()
  369. {
  370. m_hcurSaved = ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT)));
  371. };
  372. ~CHourglass()
  373. {
  374. ::SetCursor(m_hcurSaved);
  375. };
  376. };
  377. LRESULT SetPropPageToDeleteOnClose(void * vpsp);
  378. #define ATOW(wsz, sz, cch) MultiByteToWideChar(CP_ACP, 0, sz, -1, wsz, cch)
  379. #define WTOA(sz, wsz, cch) WideCharToMultiByte(CP_ACP, 0, wsz, -1, sz, cch, NULL, NULL)
  380. #define ATOWLEN(sz) MultiByteToWideChar(CP_ACP, 0, sz, -1, NULL, 0)
  381. #define WTOALEN(wsz) WideCharToMultiByte(CP_ACP, 0, wsz, -1, NULL, 0, NULL, NULL)