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.

433 lines
13 KiB

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