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.

393 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: propsht.h
  8. //
  9. //--------------------------------------------------------------------------
  10. // Declaration for callback functions
  11. LRESULT CALLBACK MessageProc(int nCode, WPARAM wParam, LPARAM lParam);
  12. // Declaration for data window wnd Proc
  13. LRESULT CALLBACK DataWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
  14. // Forward declarations
  15. class CNodeInitObject;
  16. class CPropertySheetProvider;
  17. // Type definitions
  18. typedef CList<HANDLE, HANDLE> PAGE_LIST;
  19. #include "tstring.h"
  20. enum EPropertySheetType
  21. {
  22. epstScopeItem = 0,
  23. epstResultItem = 1,
  24. epstMultipleItems = 2,
  25. };
  26. ///////////////////////////////////////////////////////////////////////////////
  27. // CThreadData - Base class for thread based objects
  28. //
  29. namespace AMC
  30. {
  31. class CThreadData
  32. {
  33. public:
  34. CThreadData() {m_dwTid = 0;};
  35. public:
  36. UINT m_dwTid;
  37. };
  38. }
  39. class CNoPropsPropertyPage : public WTL::CPropertyPageImpl<CNoPropsPropertyPage>
  40. {
  41. typedef WTL::CPropertyPageImpl<CNoPropsPropertyPage> BaseClass;
  42. public:
  43. CNoPropsPropertyPage() {}
  44. ~CNoPropsPropertyPage() {}
  45. public:
  46. enum { IDD = IDD_NOPROPS_PROPPAGE };
  47. BEGIN_MSG_MAP(CSnapinAboutPage)
  48. CHAIN_MSG_MAP(BaseClass)
  49. END_MSG_MAP()
  50. };
  51. //+-------------------------------------------------------------------
  52. //
  53. // Class: CPropertySheetToolTips
  54. //
  55. // Purpose: This class has stores tooltip data for
  56. // the property sheets. This includes fullpath
  57. // from the console root to property sheet owner
  58. // node, owner name and an array of snapin name
  59. // indexed by property page tab number.
  60. //
  61. // History: 06-18-1999 AnandhaG Created
  62. //
  63. //--------------------------------------------------------------------
  64. class CPropertySheetToolTips : public WTL::CToolTipCtrl
  65. {
  66. // This is the id used for the tool tip control for property sheet
  67. // title. So when we get TTN_NEEDTEXT we can identify if the text
  68. // is for title or a tab.
  69. #define PROPSHEET_TITLE_TOOLTIP_ID 1234
  70. private:
  71. tstring m_strThisSnapinName; // This is a temp member variable that has
  72. // snapin that is currently adding pages
  73. // This is used while constructing below
  74. // array of pages.
  75. std::vector<tstring> m_strSnapins; // Property page (tab) owner snapins array
  76. tstring m_strFullPath;
  77. tstring m_strItemName;
  78. EPropertySheetType m_PropSheetType;
  79. public:
  80. CPropertySheetToolTips()
  81. {
  82. }
  83. CPropertySheetToolTips(const CPropertySheetToolTips& sp)
  84. {
  85. m_strThisSnapinName = sp.m_strThisSnapinName;
  86. m_strSnapins = sp.m_strSnapins;
  87. m_strFullPath = sp.m_strFullPath;
  88. }
  89. CPropertySheetToolTips& operator=(const CPropertySheetToolTips& sp)
  90. {
  91. if (this != &sp)
  92. {
  93. m_strThisSnapinName = sp.m_strThisSnapinName;
  94. m_strSnapins = sp.m_strSnapins;
  95. m_strFullPath = sp.m_strFullPath;
  96. }
  97. return (*this);
  98. }
  99. void SetThisSnapin(LPCTSTR szName)
  100. {
  101. m_strThisSnapinName = szName;
  102. }
  103. LPCTSTR GetThisSnapin()
  104. {
  105. return m_strThisSnapinName.data();
  106. }
  107. void AddSnapinPage()
  108. {
  109. m_strSnapins.push_back(m_strThisSnapinName);
  110. }
  111. LPCTSTR GetSnapinPage(int nIndex)
  112. {
  113. return m_strSnapins[nIndex].data();
  114. }
  115. INT GetNumPages()
  116. {
  117. return m_strSnapins.size();
  118. }
  119. LPCTSTR GetFullPath()
  120. {
  121. return m_strFullPath.data();
  122. }
  123. void SetFullPath(LPTSTR szName, BOOL bAddEllipses = FALSE)
  124. {
  125. m_strFullPath = szName;
  126. if (bAddEllipses)
  127. m_strFullPath += _T("...");
  128. }
  129. void SetItemName(LPTSTR szName)
  130. {
  131. m_strItemName = szName;
  132. }
  133. LPCTSTR GetItemName()
  134. {
  135. return m_strItemName.data();
  136. }
  137. void SetPropSheetType(EPropertySheetType propSheetType)
  138. {
  139. m_PropSheetType = propSheetType;
  140. }
  141. EPropertySheetType GetPropSheetType()
  142. {
  143. return m_PropSheetType;
  144. }
  145. };
  146. ///////////////////////////////////////////////////////////////////////////////
  147. // CPropertySheet - Basic property sheet class
  148. //
  149. namespace AMC
  150. {
  151. class CPropertySheet : public AMC::CThreadData
  152. {
  153. friend class CPropertySheetProvider;
  154. // Constructor/Destructor
  155. public:
  156. CPropertySheet();
  157. virtual ~CPropertySheet();
  158. private:
  159. /*
  160. * copy construction and assignment aren't supported;
  161. * insure the compiler doesn't generate defaults
  162. */
  163. CPropertySheet (const CPropertySheet& other);
  164. CPropertySheet& operator= (const CPropertySheet& other);
  165. // Interface
  166. public:
  167. void CommonConstruct();
  168. BOOL Create(LPCTSTR lpszCaption, bool fPropSheet, MMC_COOKIE cookie, LPDATAOBJECT pDataObject,
  169. LONG_PTR lpMasterTreeNode, DWORD dwOptions);
  170. HRESULT DoSheet(HWND hParent, int nPage); // create property sheet/pages and go modeless
  171. BOOL AddExtensionPages();
  172. void AddNoPropsPage();
  173. BOOL CreateDataWindow(HWND hParent); // create the hidden data window
  174. bool IsWizard() const { return (m_pstHeader.dwFlags & (PSH_WIZARD97 | PSH_WIZARD)); }
  175. bool IsWizard97() const { return (m_pstHeader.dwFlags & PSH_WIZARD97); }
  176. void GetWatermarks (IExtendPropertySheet2* pExtend2);
  177. DWORD GetOriginatingThreadID () const
  178. {
  179. return (m_dwThreadID);
  180. }
  181. void ForceOldStyleWizard ();
  182. // Attributes
  183. public:
  184. PROPSHEETHEADER m_pstHeader; //
  185. PAGE_LIST m_PageList; // page list for property sheet
  186. MMC_COOKIE m_cookie;
  187. LONG_PTR m_lpMasterNode; // master tree pointer
  188. LPSTREAM m_pStream; // Stream for marshalled pointer
  189. LPDATAOBJECT m_pThreadLocalDataObject; // Marshalled data object pointer
  190. CMTNode* m_pMTNode; // MTNode of property sheet owner
  191. const DWORD m_dwThreadID; // ID of thread that created property sheet
  192. /*
  193. * Bug 187702: Use CXxxHandle instead of CXxx so the resources
  194. * will *not* be cleaned up on destruction. Yes, this may leak if
  195. * the if the snap-in doesn't manage the object lifetime (which it
  196. * shouldn't have to do because these are OUT parameters for
  197. * IExtendPropertySheet2::GetWatermarks), but it's required for app
  198. * compat.
  199. */
  200. WTL::CBitmapHandle m_bmpWatermark;
  201. WTL::CBitmapHandle m_bmpHeader;
  202. WTL::CPaletteHandle m_Palette;
  203. public:
  204. void SetDataObject( IDataObject *pDataObject) {m_spDataObject = pDataObject;}
  205. void SetComponent( IComponent *pComponent) {m_spComponent = pComponent;}
  206. void SetComponentData(IComponentData *pComponentData){m_spComponentData = pComponentData;}
  207. IDataObject* GetDataObject() { return m_spDataObject.GetInterfacePtr();}
  208. IComponent * GetComponent() { return m_spComponent.GetInterfacePtr();}
  209. IComponentData * GetComponentData() { return m_spComponentData.GetInterfacePtr();}
  210. private:
  211. IDataObjectPtr m_spDataObject;
  212. IComponentDataPtr m_spComponentData;
  213. IComponentPtr m_spComponent;
  214. // components that extend this prop sheet
  215. std::vector<IUnknownPtr> m_Extenders;
  216. // streams containing exterders' marshalled interfaces (if required)
  217. std::vector<IStream*> m_ExtendersMarshallStreams;
  218. // Message handlers
  219. public:
  220. LRESULT OnCreate(CWPRETSTRUCT* pMsg);
  221. LRESULT OnInitDialog(CWPRETSTRUCT* pMsg);
  222. LRESULT OnNcDestroy(CWPRETSTRUCT* pMsg);
  223. LRESULT OnWMNotify(CWPRETSTRUCT* pMsg);
  224. public:
  225. HWND m_hDlg; // property sheet hwnd
  226. HHOOK m_msgHook; // hook handle for page, only valid through WM_INITDIALOG
  227. HWND m_hDataWindow; // hidden data window
  228. BOOL m_bModalProp; // TRUE if the property sheet should be modal
  229. BOOL m_bAddExtension;// TRUE if we need to add extension pages
  230. private:
  231. HPROPSHEETPAGE m_pages[MAXPROPPAGES];
  232. CStr m_title;
  233. CNoPropsPropertyPage m_NoPropsPage;
  234. public:
  235. // Tooltip data
  236. CPropertySheetToolTips m_PropToolTips;
  237. };
  238. }
  239. ///////////////////////////////////////////////////////////////////////////////
  240. // CThreadToSheetMap - Maps thread IDs to CPropertySheetObjects.
  241. //
  242. class CThreadToSheetMap
  243. {
  244. public:
  245. typedef DWORD KEY;
  246. typedef AMC::CPropertySheet * VALUE;
  247. typedef std::map<KEY, VALUE> CMap;
  248. CThreadToSheetMap(){};
  249. ~CThreadToSheetMap(){};
  250. public:
  251. void Add(KEY id, VALUE pObject)
  252. {
  253. CSingleLock lock(&m_critSection, TRUE);
  254. m_map[id] = pObject;
  255. }
  256. void Remove(KEY id)
  257. {
  258. CSingleLock lock(&m_critSection, TRUE);
  259. m_map.erase(id);
  260. }
  261. BOOL Find(KEY id, VALUE& pObject)
  262. {
  263. CSingleLock lock(&m_critSection, TRUE);
  264. std::map<KEY, VALUE>::iterator it = m_map.find(id);
  265. if(it == m_map.end())
  266. return false;
  267. pObject = it->second;
  268. return true;
  269. }
  270. public:
  271. CCriticalSection m_critSection;
  272. private:
  273. CMap m_map;
  274. };
  275. ///////////////////////////////////////////////////////////////////////////////
  276. // CPropertySheetProvider - The implementation for the IPropertySheetProvider
  277. // interface.
  278. class CPropertySheetProvider :
  279. public IPropertySheetProviderPrivate,
  280. public IPropertySheetCallback,
  281. public IPropertySheetNotify
  282. {
  283. friend class AMCPropertySheet;
  284. public:
  285. CPropertySheetProvider();
  286. ~CPropertySheetProvider();
  287. // IPropertySheetProviderPrivate
  288. public:
  289. STDMETHOD(CreatePropertySheet)(LPCWSTR title, unsigned char bType, MMC_COOKIE cookie,
  290. LPDATAOBJECT pDataObject, DWORD dwOptions);
  291. STDMETHOD(CreatePropertySheetEx)(LPCWSTR title, unsigned char bType, MMC_COOKIE cookie,
  292. LPDATAOBJECT pDataObject, LONG_PTR lpMasterTreeNode, DWORD dwOptions);
  293. STDMETHOD(Show)(LONG_PTR window, int page);
  294. STDMETHOD(ShowEx)(HWND hwnd, int page, BOOL bModalPage);
  295. STDMETHOD(FindPropertySheet)(MMC_COOKIE cookie, LPCOMPONENT lpComponent, LPDATAOBJECT lpDataObject);
  296. STDMETHOD(AddPrimaryPages)(LPUNKNOWN lpUnknown, BOOL bCreateHandle, HWND hNotifyWindow, BOOL bScopePane);
  297. STDMETHOD(AddExtensionPages)();
  298. STDMETHOD(AddMultiSelectionExtensionPages)(LONG_PTR lMultiSelection);
  299. STDMETHOD(FindPropertySheetEx)(MMC_COOKIE cookie, LPCOMPONENT lpComponent,
  300. LPCOMPONENTDATA lpComponentData, LPDATAOBJECT lpDataObject);
  301. STDMETHOD(SetPropertySheetData)(INT nPropSheetType, HMTNODE hMTNode);
  302. // IPropertySheetCallback
  303. public:
  304. STDMETHOD(AddPage)(HPROPSHEETPAGE page);
  305. STDMETHOD(RemovePage)(HPROPSHEETPAGE page);
  306. // IPropertySheetNotify
  307. public:
  308. STDMETHOD(Notify)(LPPROPERTYNOTIFYINFO pNotify, LPARAM lParam);
  309. // Objects in common with all instances of IPropertySheetProvider(s)
  310. static CThreadToSheetMap TID_LIST;
  311. public:
  312. AMC::CPropertySheet* m_pSheet;
  313. };