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.

436 lines
13 KiB

  1. #ifndef __CFOLDER_H__
  2. #define __CFOLDER_H__
  3. /*++
  4. Copyright (C) Microsoft Corporation
  5. Module Name:
  6. cfolder.h
  7. Abstract:
  8. header file for cfolder.cpp.
  9. Author:
  10. William Hsieh (williamh) created
  11. Revision History:
  12. --*/
  13. class CFolder;
  14. class CResultView;
  15. class CViewTreeByType;
  16. class CViewTreeByConnection;
  17. class CViewResourceTree;
  18. class CComponent;
  19. const int IMAGE_INDEX_START = 20;
  20. const int IMAGE_INDEX_DEVMGR = IMAGE_INDEX_START;
  21. const int OPEN_IMAGE_INDEX_DEVMGR = IMAGE_INDEX_DEVMGR;
  22. typedef enum tagViewType {
  23. VIEW_DEVICESBYTYPE = 0,
  24. VIEW_DEVICESBYCONNECTION,
  25. VIEW_RESOURCESBYTYPE,
  26. VIEW_RESOURCESBYCONNECTION,
  27. VIEW_NONE
  28. }VIEWTYPE, *PVIEWTYPE;
  29. typedef struct tagMMCMenuItem {
  30. int idName;
  31. int idStatusBar;
  32. long lCommandId;
  33. VIEWTYPE Type;
  34. }MMCMENUITEM, *PMMCMENUITEM;
  35. const VIEWTYPE VIEW_FIRST = VIEW_DEVICESBYTYPE;
  36. const VIEWTYPE VIEW_LAST = VIEW_RESOURCESBYCONNECTION;
  37. const int TOTAL_VIEWS = VIEW_LAST - VIEW_FIRST + 1;
  38. const int TOTAL_RESOURCE_TYPES = 4;
  39. extern const MMCMENUITEM ViewDevicesMenuItems[];
  40. typedef struct tagDevMgrFolderStates {
  41. COOKIE_TYPE Type;
  42. VIEWTYPE CurViewType;
  43. BOOL ShowHiddenDevices;
  44. }DEVMGRFOLDER_STATES, *PDEVMGRFOLDER_STATES;
  45. typedef DWORD FOLDER_SIGNATURE;
  46. const FOLDER_SIGNATURE_DEVMGR = 0x00FF00FF;
  47. //
  48. // This is the class created and maintained by IComponentData
  49. //
  50. class CScopeItem {
  51. public:
  52. CScopeItem(COOKIE_TYPE ct, int iImage, int iOpenImage, int iNameStringId, int iDescStringId, int iDisplayNameFormatId)
  53. {
  54. UNREFERENCED_PARAMETER(iDisplayNameFormatId);
  55. m_iImage = iImage;
  56. m_iOpenImage = iOpenImage;
  57. m_iNameStringId = iNameStringId;
  58. m_iDescStringId = iDescStringId;
  59. m_Enumerated = FALSE;
  60. m_hScopeItem = NULL;
  61. m_Type = ct;
  62. }
  63. virtual CFolder* CreateFolder(CComponent* pComponent);
  64. virtual HRESULT AddMenuItems(LPCONTEXTMENUCALLBACK pCallback, long* pInsertionAllowed);
  65. virtual HRESULT MenuCommand(long lCommandId);
  66. virtual HRESULT QueryPagesFor();
  67. virtual HRESULT CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  68. LONG_PTR handle);
  69. virtual ~CScopeItem();
  70. virtual BOOL Create();
  71. HRESULT GetDisplayInfo(LPSCOPEDATAITEM pScopeDataItem);
  72. void SetScopeItemID(HSCOPEITEM hScopeItem)
  73. {
  74. m_hScopeItem = hScopeItem;
  75. }
  76. const int GetImageIndex() const
  77. {
  78. return m_iImage;
  79. }
  80. const int GetOpenImageIndex() const
  81. {
  82. return m_iOpenImage;
  83. }
  84. const TCHAR* GetNameString() const
  85. {
  86. return(LPCTSTR)m_strName;
  87. }
  88. const TCHAR* GetDescString() const
  89. {
  90. return(LPCTSTR)m_strDesc;
  91. }
  92. operator HSCOPEITEM()
  93. {
  94. return m_hScopeItem;
  95. }
  96. BOOL EnumerateChildren(int Index, CScopeItem** ppChild);
  97. int GetChildCount()
  98. {
  99. return m_listChildren.GetCount();
  100. }
  101. COOKIE_TYPE GetType()
  102. {
  103. return m_Type;
  104. }
  105. void SetHandle(HSCOPEITEM hScopeItem)
  106. {
  107. m_hScopeItem = hScopeItem;
  108. }
  109. BOOL IsEnumerated()
  110. {
  111. return m_Enumerated;
  112. }
  113. void Enumerated()
  114. {
  115. m_Enumerated = TRUE;
  116. }
  117. HRESULT Reset();
  118. protected:
  119. CCookie* FindSelectedCookieData(CResultView** ppResultView);
  120. int m_iNameStringId;
  121. int m_iDescStringId;
  122. int m_iImage;
  123. int m_iOpenImage;
  124. String m_strName;
  125. String m_strDesc;
  126. BOOL m_Enumerated;
  127. HSCOPEITEM m_hScopeItem;
  128. COOKIE_TYPE m_Type;
  129. CList<CFolder*, CFolder*> m_listFolder;
  130. CList<CScopeItem*, CScopeItem*> m_listChildren;
  131. };
  132. // While ScopeItem objects are created and managed by CComponentData,
  133. // CFolder objects are created and managed by CComponent class.
  134. // CComponent objects are created and managed by CComponentData.
  135. // A CComponent object is created when a new window is created.
  136. // For each CScopeItem, CComponent creates a CFolder object to
  137. // represent that CScopeItem in the CComponent's window.
  138. // CFolder is responsible for painting the result pane that represents
  139. // the visual states of its associated CScopeItem.
  140. //
  141. class CFolder {
  142. public:
  143. CFolder(CScopeItem* pScopeItem, CComponent* pComponent);
  144. virtual ~CFolder();
  145. virtual HRESULT Compare(MMC_COOKIE cookieA, MMC_COOKIE cookieB, int nCol, int* pnResult);
  146. virtual HRESULT GetDisplayInfo(LPRESULTDATAITEM pResultDataItem);
  147. virtual HRESULT AddMenuItems(CCookie* pCookie, LPCONTEXTMENUCALLBACK pCallback, long* pInsertionAllowed);
  148. virtual HRESULT MenuCommand(CCookie* pCookie, long lCommandId);
  149. virtual HRESULT QueryPagesFor(CCookie* pCookie);
  150. virtual HRESULT CreatePropertyPages(CCookie* pCookie, LPPROPERTYSHEETCALLBACK lpProvider,
  151. LONG_PTR handle);
  152. virtual HRESULT OnShow(BOOL fShow);
  153. virtual HRESULT GetResultViewType(LPOLESTR* ppViewType, long* pViewOptions);
  154. virtual CResultView* GetCurResultView()
  155. {
  156. return m_pCurView;
  157. }
  158. virtual int GetPersistDataSize()
  159. {
  160. return sizeof(DEVMGRFOLDER_STATES);
  161. }
  162. virtual HRESULT GetPersistData(PBYTE pBuffer, int BufferSize);
  163. virtual HRESULT SetPersistData(PBYTE pData, int Size);
  164. LPCTSTR GetNameString()
  165. {
  166. return m_pScopeItem->GetNameString();
  167. }
  168. LPCTSTR GetDescString()
  169. {
  170. return m_pScopeItem->GetDescString();
  171. }
  172. FOLDER_SIGNATURE GetSignature()
  173. {
  174. return m_Signature;
  175. }
  176. virtual HRESULT tvNotify(HWND hwndTV, CCookie* pCookie, TV_NOTIFY_CODE Code, LPARAM arg, LPARAM param);
  177. virtual HRESULT MachinePropertyChanged(CMachine* pMachine);
  178. virtual HRESULT OnOcxNotify(MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  179. virtual HRESULT OnRestoreView(BOOL* pfHandled);
  180. virtual HRESULT OnSelect()
  181. {
  182. // If the folder is selected, reset the console verbs.
  183. if (m_bSelect)
  184. return S_FALSE;
  185. else
  186. return S_OK;
  187. }
  188. ULONG AddRef()
  189. {
  190. return ++m_Ref;
  191. }
  192. ULONG Release()
  193. {
  194. ASSERT(m_Ref);
  195. --m_Ref;
  196. if (!m_Ref) {
  197. delete this;
  198. return 0;
  199. }
  200. return m_Ref;
  201. }
  202. virtual HRESULT Reset();
  203. BOOL ShowHiddenDevices()
  204. {
  205. return m_ShowHiddenDevices;
  206. }
  207. BOOL SelectView(VIEWTYPE ViewType, BOOL fShowHiddenDevices);
  208. HRESULT DoProperties(HWND hwndParent, CCookie* pCookie);
  209. CComponent* m_pComponent;
  210. CScopeItem* m_pScopeItem;
  211. CMachine* m_pMachine;
  212. BOOL m_bSelect; // Saved by MMCN_SELECT for MenuCommand
  213. protected:
  214. FOLDER_SIGNATURE m_Signature;
  215. BOOL m_Show;
  216. String m_strScratch;
  217. LPOLESTR m_pOleTaskString;
  218. ULONG m_Ref;
  219. private:
  220. CViewTreeByType* m_pViewTreeByType;
  221. CViewTreeByConnection* m_pViewTreeByConnection;
  222. CViewResourceTree* m_pViewResourcesByType;
  223. CViewResourceTree* m_pViewResourcesByConnection;
  224. CResultView* m_pCurView;
  225. VIEWTYPE m_CurViewType;
  226. BOOL m_ShowHiddenDevices;
  227. BOOL m_FirstTimeOnShow;
  228. };
  229. class CResultView {
  230. public:
  231. CResultView(int DescStringId) :
  232. m_DescStringId(DescStringId),
  233. m_pFolder(NULL),
  234. m_pMachine(NULL),
  235. m_pCookieComputer(NULL),
  236. m_pIDMTVOCX(NULL),
  237. m_hwndTV(NULL),
  238. m_pSelectedCookie(NULL),
  239. m_SelectOk(FALSE),
  240. m_pSelectedItem(NULL)
  241. {
  242. String stringWorking, stringProblem, stringDisabled, stringForced;
  243. stringWorking.LoadString(g_hInstance, IDS_ANNOTATION_WORKING);
  244. stringProblem.LoadString(g_hInstance, IDS_ANNOTATION_PROBLEM);
  245. stringDisabled.LoadString(g_hInstance, IDS_ANNOTATION_DISABLED);
  246. stringForced.LoadString(g_hInstance, IDS_ANNOTATION_FORCED);
  247. m_stringAnnotationMap.Format(TEXT("A:2:%d:%s:%d:%s:%d:%s:%d:%s:"),
  248. 0,
  249. (LPTSTR)stringWorking,
  250. (IDI_PROBLEM_OVL - IDI_CLASSICON_OVERLAYFIRST + 1),
  251. (LPTSTR)stringProblem,
  252. (IDI_DISABLED_OVL - IDI_CLASSICON_OVERLAYFIRST + 1),
  253. (LPTSTR)stringDisabled,
  254. (IDI_FORCED_OVL - IDI_CLASSICON_OVERLAYFIRST + 1),
  255. (LPTSTR)stringForced);
  256. }
  257. virtual ~CResultView();
  258. virtual HRESULT GetDisplayInfo(LPRESULTDATAITEM pResultDataItem)
  259. {
  260. UNREFERENCED_PARAMETER(pResultDataItem);
  261. return S_OK;
  262. }
  263. virtual HRESULT OnShow(BOOL fShow);
  264. LPCTSTR GetStartupDeviceId();
  265. LPCTSTR GetStartupCommand();
  266. void SetFolder(CFolder* pFolder)
  267. {
  268. m_pFolder = pFolder;
  269. }
  270. int GetDescriptionStringID()
  271. {
  272. return m_DescStringId;
  273. }
  274. virtual CCookie* GetSelectedCookie()
  275. {
  276. return m_pSelectedCookie;
  277. }
  278. void SetSelectOk(BOOL fSelect)
  279. {
  280. m_SelectOk = fSelect;
  281. }
  282. HRESULT MachinePropertyChanged(CMachine* pMachine);
  283. void SaveTreeStates(CCookie* pCookieStart);
  284. void DestroySavedTreeStates();
  285. void RestoreSavedTreeState(CCookie* pCookie);
  286. BOOL DisplayTree();
  287. HRESULT GetResultViewType(LPOLESTR* ppViewType, long* pViewOptions);
  288. HRESULT AddMenuItems(CCookie* pCookie, LPCONTEXTMENUCALLBACK pCallback,
  289. long* pInsertionAllowed, BOOL fContextMenu);
  290. HRESULT MenuCommand(CCookie* pCookie, long lCommandId);
  291. HRESULT QueryPagesFor(CCookie* pCookie);
  292. HRESULT CreatePropertyPages(CCookie* pCookie, LPPROPERTYSHEETCALLBACK pProvider, LONG_PTR handle);
  293. HRESULT tvNotify(HWND hwndTV, CCookie* pCookie, TV_NOTIFY_CODE Code, LPARAM arg, LPARAM param);
  294. HRESULT OnOcxNotify(MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  295. HRESULT DoProperties(HWND hwndParent, CCookie* pCookie);
  296. HRESULT DoContextMenu(HWND hwndParent, CCookie* pCookie, POINT* pPoint);
  297. HRESULT DoPrint();
  298. protected:
  299. BOOL DisplaySubtree(HTREEITEM htiParent, CCookie* pCookieStart, BOOL* pReportProblem = NULL);
  300. HRESULT UpdateConsoleVerbs(CCookie* pCookie);
  301. CFolder* m_pFolder;
  302. int m_DescStringId;
  303. CMachine* m_pMachine;
  304. CCookie* m_pCookieComputer;
  305. IDMTVOCX* m_pIDMTVOCX;
  306. CCookie* m_pSelectedCookie;
  307. BOOL m_SelectOk;
  308. HWND m_hwndTV;
  309. CList<CItemIdentifier*, CItemIdentifier*> m_listExpandedItems;
  310. CItemIdentifier* m_pSelectedItem;
  311. String m_stringAnnotationMap;
  312. private:
  313. HRESULT RemoveDevice(CDevice* pDevice);
  314. };
  315. class CViewDeviceTree : public CResultView {
  316. public:
  317. CViewDeviceTree(int DescStringId)
  318. : CResultView(DescStringId)
  319. {}
  320. virtual ~CViewDeviceTree() {}
  321. virtual HRESULT OnShow(BOOL fShow);
  322. virtual BOOL CreateDeviceTree();
  323. protected:
  324. private:
  325. };
  326. class CViewTreeByType : public CViewDeviceTree {
  327. public:
  328. CViewTreeByType()
  329. : CViewDeviceTree(IDS_STATUS_DEVICES_BYTYPE)
  330. {}
  331. virtual BOOL CreateDeviceTree();
  332. };
  333. class CViewTreeByConnection : public CViewDeviceTree {
  334. public:
  335. CViewTreeByConnection()
  336. : CViewDeviceTree(IDS_STATUS_DEVICES_BYCONN)
  337. {}
  338. virtual BOOL CreateDeviceTree();
  339. private:
  340. BOOL CreateSubtree(CCookie* pCookieParent, CCookie* pCookieSibling, CDevice* pDeviceStart);
  341. };
  342. class CViewResourceTree : public CResultView {
  343. public:
  344. CViewResourceTree(int DescStringId)
  345. : CResultView(DescStringId)
  346. {
  347. int i;
  348. for (i = 0; i < TOTAL_RESOURCE_TYPES; i++) {
  349. m_pResourceList[i] = NULL;
  350. m_pResourceType[i] = NULL;
  351. }
  352. }
  353. ~CViewResourceTree();
  354. virtual HRESULT OnShow(BOOL fShow);
  355. protected:
  356. private:
  357. void CreateResourceTree();
  358. void CreateResourceSubtree(CCookie* pCookieParent,
  359. CCookie* pCookieSibling,
  360. CDevice* pDevice, CCookie** ppLastCookie = NULL);
  361. BOOL InsertCookieToTree(CCookie* pCookie, CCookie* pCookieStart,
  362. BOOL ForcedInsert);
  363. void DestroyResourceTree();
  364. CResourceList* m_pResourceList[TOTAL_RESOURCE_TYPES];
  365. CResourceType* m_pResourceType[TOTAL_RESOURCE_TYPES];
  366. };
  367. typedef BOOL (CALLBACK* PROPSHEET_PROVIDER_PROC)(
  368. PSP_PROPSHEETPAGE_REQUEST PropPageRequest,
  369. LPFNADDPROPSHEETPAGE lpfnAddPropPageProc,
  370. LPARAM lParam
  371. );
  372. class CPropPageProvider {
  373. public:
  374. CPropPageProvider() : m_hDll(NULL)
  375. {}
  376. virtual ~CPropPageProvider()
  377. {
  378. if (m_hDll)
  379. FreeLibrary(m_hDll);
  380. }
  381. virtual BOOL EnumPages(CDevice* pDevice, CPropSheetData* ppsd) = 0;
  382. protected:
  383. HMODULE m_hDll;
  384. };
  385. class CBusPropPageProvider : public CPropPageProvider {
  386. public:
  387. virtual BOOL EnumPages(CDevice* pDevice, CPropSheetData* ppsd);
  388. };
  389. #endif // __CFOLDER_H__