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.

480 lines
19 KiB

  1. #ifndef INCLUDE_SNPDATA_H
  2. #define INCLUDE_SNPDATA_H
  3. #include "snapdata.h" // interface definition for IWirelessSnapInDataObject
  4. // forward declaration for spolitem stuff
  5. class CSecPolItem;
  6. typedef CComObject<CSecPolItem>* LPCSECPOLITEM;
  7. ///////////////////////////////////////////////////////////////////////////////
  8. // Macros to be used for adding toolbars to CSnapObject derived objects.
  9. // See CSnapObject class definition for example.
  10. #define BEGIN_SNAPINTOOLBARID_MAP(theClass) \
  11. public: \
  12. STDMETHOD_(CSnapInToolbarInfo*, GetToolbarInfo)(void) \
  13. { \
  14. if (NULL == m_aToolbarInfo) \
  15. { \
  16. CSnapInToolbarInfo m_tbInfo_##theClass[] = \
  17. {
  18. #define SNAPINTOOLBARID_ENTRY(id) \
  19. { NULL, NULL, NULL, id, 0, NULL },
  20. #define END_SNAPINTOOLBARID_MAP(theClass) \
  21. { NULL, NULL, NULL, 0, 0, NULL } \
  22. }; \
  23. int nElemCount = sizeof(m_tbInfo_##theClass)/sizeof(CSnapInToolbarInfo); \
  24. if (nElemCount > 1) \
  25. { \
  26. m_aToolbarInfo = new CSnapInToolbarInfo[nElemCount]; \
  27. if (NULL != m_aToolbarInfo) \
  28. { \
  29. CopyMemory( m_aToolbarInfo, m_tbInfo_##theClass, sizeof( CSnapInToolbarInfo ) * nElemCount ); \
  30. } \
  31. } \
  32. else { \
  33. ASSERT( 1 == nElemCount ); /* the NULL entry marking end-of-array */ \
  34. ASSERT( 0 == m_tbInfo_##theClass[0].m_idToolbar ); \
  35. } \
  36. } \
  37. return m_aToolbarInfo; \
  38. }
  39. ///////////////////////////////////////////////////////////////////////////////
  40. // struct CSnapInToolbarInfo - Used to add a toolbar to MMC for a result/scope item.
  41. struct CSnapInToolbarInfo
  42. {
  43. public:
  44. TCHAR** m_pStrToolTip; // array of tooltip strings
  45. TCHAR** m_pStrButtonText; // NOT USED (array of button text strings)
  46. UINT* m_pnButtonID; // array of button IDs
  47. UINT m_idToolbar; // id of toolbar
  48. UINT m_nButtonCount; // # of buttons on toolbar
  49. IToolbar* m_pToolbar; // Interface ptr
  50. ~CSnapInToolbarInfo()
  51. {
  52. if (m_pStrToolTip)
  53. {
  54. for (UINT i = 0; i < m_nButtonCount; i++)
  55. {
  56. delete m_pStrToolTip[i];
  57. m_pStrToolTip[i] = NULL;
  58. }
  59. delete [] m_pStrToolTip;
  60. m_pStrToolTip = NULL;
  61. }
  62. if (m_pStrButtonText)
  63. {
  64. for (UINT i = 0; i < m_nButtonCount; i++)
  65. {
  66. delete m_pStrButtonText[i];
  67. m_pStrButtonText[i] = NULL;
  68. }
  69. delete [] m_pStrButtonText;
  70. m_pStrButtonText = NULL;
  71. }
  72. if (m_pnButtonID)
  73. {
  74. delete m_pnButtonID;
  75. m_pnButtonID = NULL;
  76. }
  77. m_nButtonCount = 0;
  78. if (m_pToolbar)
  79. m_pToolbar->Release();
  80. m_pToolbar = NULL;
  81. }
  82. };
  83. ///////////////////////////////////////////////////////////////////////////////
  84. struct CSnapInToolBarData
  85. {
  86. WORD wVersion;
  87. WORD wWidth;
  88. WORD wHeight;
  89. WORD wItemCount;
  90. //WORD aItems[wItemCount]
  91. WORD* items()
  92. { return (WORD*)(this+1); }
  93. };
  94. #define RT_TOOLBAR MAKEINTRESOURCE(241)
  95. ///////////////////////////////////////////////////////////////////////////////
  96. // class CWirelessSnapInDataObjectImpl - Implementation of private COM interface
  97. template <class T>
  98. class CWirelessSnapInDataObjectImpl :
  99. public IWirelessSnapInDataObject
  100. {
  101. public:
  102. CWirelessSnapInDataObjectImpl() :
  103. m_DataObjType( CCT_UNINITIALIZED ),
  104. m_aToolbarInfo( NULL ),
  105. m_bEnablePropertyChangeHook( FALSE )
  106. {
  107. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::CWirelessSnapInDataObjectImpl this-%p\n"), this);
  108. }
  109. virtual ~CWirelessSnapInDataObjectImpl()
  110. {
  111. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::~CWirelessSnapInDataObjectImpl this-%p\n"), this);
  112. // Clean up array of toolbar info
  113. if (NULL != m_aToolbarInfo)
  114. {
  115. delete [] m_aToolbarInfo;
  116. m_aToolbarInfo = NULL;
  117. }
  118. }
  119. ///////////////////////////////////////////////////////////////////////////
  120. // Interface to handle IExtendContextMenu
  121. STDMETHOD(AddMenuItems)( LPCONTEXTMENUCALLBACK piCallback,
  122. long *pInsertionAllowed )
  123. {
  124. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::AddMenuItems NOT implemented, this-%p\n"), this);
  125. return E_NOTIMPL;
  126. }
  127. STDMETHOD(Command)( long lCommandID,
  128. IConsoleNameSpace *pNameSpace )
  129. {
  130. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::Command NOT implemented, this-%p\n"), this);
  131. return E_NOTIMPL;
  132. }
  133. ///////////////////////////////////////////////////////////////////////////
  134. // IExtendContextMenu helpers
  135. // Non-interface members intended to be overridden by instantiated class.
  136. STDMETHOD(AdjustVerbState)(LPCONSOLEVERB pConsoleVerb)
  137. {
  138. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::AdjustVerbState this-%p\n"), this);
  139. HRESULT hr = pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, FALSE);
  140. ASSERT (hr == S_OK);
  141. hr = pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, HIDDEN, TRUE);
  142. ASSERT (hr == S_OK);
  143. return hr;
  144. }
  145. ///////////////////////////////////////////////////////////////////////////
  146. // Interface to handle IExtendPropertySheet
  147. STDMETHOD(CreatePropertyPages)( LPPROPERTYSHEETCALLBACK lpProvider,
  148. LONG_PTR handle )
  149. {
  150. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::CreatePropertyPages this-%p\n"), this);
  151. return S_OK; // no prop pages added by default
  152. }
  153. STDMETHOD(QueryPagesFor)( void )
  154. {
  155. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::QueryPagesFor NOT implemented this-%p\n"), this);
  156. return E_NOTIMPL;
  157. }
  158. ///////////////////////////////////////////////////////////////////////////
  159. // Interface to handle IExtendControlbar
  160. STDMETHOD(ControlbarNotify)( IControlbar *pControlbar,
  161. IExtendControlbar *pExtendControlbar,
  162. MMC_NOTIFY_TYPE event,
  163. LPARAM arg,
  164. LPARAM param )
  165. {
  166. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::ControlbarNotify this-%p\n"), this);
  167. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  168. T* pThis = (T*)this;
  169. HRESULT hr;
  170. // Load object's toolbar (if any) and associated baggage.
  171. pThis->SetControlbar(pControlbar, pExtendControlbar);
  172. if(MMCN_SELECT == event)
  173. {
  174. BOOL bScope = (BOOL) LOWORD(arg);
  175. BOOL bSelect = (BOOL) HIWORD (arg);
  176. // A scope item has been selected
  177. CSnapInToolbarInfo* pInfo = pThis->GetToolbarInfo();
  178. if (pInfo == NULL)
  179. return S_OK;
  180. // Attach toolbar to console, and set button states with UpdateToolbarButton()
  181. for(; pInfo->m_idToolbar; pInfo++)
  182. {
  183. // When a result item has been deselected, remove its toolbar.
  184. // Otherwise add the object's toolbar. Note: the scope item's
  185. // toolbar is always displayed as long as we're in its "scope",
  186. // thats why we Detach() for a result item only.
  187. if (!bScope && !bSelect)
  188. {
  189. hr = pControlbar->Detach(pInfo->m_pToolbar);
  190. ASSERT (hr == S_OK);
  191. }
  192. else
  193. {
  194. hr = pControlbar->Attach(TOOLBAR, pInfo->m_pToolbar);
  195. ASSERT (hr == S_OK);
  196. }
  197. for (UINT i = 0; i < pInfo->m_nButtonCount; i++)
  198. {
  199. if (pInfo->m_pnButtonID[i])
  200. {
  201. // set the button state properly for each valid state
  202. pInfo->m_pToolbar->SetButtonState( pInfo->m_pnButtonID[i], ENABLED, UpdateToolbarButton( pInfo->m_pnButtonID[i], bSelect, ENABLED ));
  203. pInfo->m_pToolbar->SetButtonState( pInfo->m_pnButtonID[i], CHECKED, UpdateToolbarButton( pInfo->m_pnButtonID[i], bSelect, CHECKED ));
  204. pInfo->m_pToolbar->SetButtonState( pInfo->m_pnButtonID[i], HIDDEN, UpdateToolbarButton( pInfo->m_pnButtonID[i], bSelect, HIDDEN ));
  205. pInfo->m_pToolbar->SetButtonState( pInfo->m_pnButtonID[i], INDETERMINATE, UpdateToolbarButton( pInfo->m_pnButtonID[i], bSelect, INDETERMINATE ));
  206. pInfo->m_pToolbar->SetButtonState( pInfo->m_pnButtonID[i], BUTTONPRESSED, UpdateToolbarButton( pInfo->m_pnButtonID[i], bSelect, BUTTONPRESSED ));
  207. }
  208. }
  209. }
  210. return S_OK;
  211. }
  212. // This is supposed to be the only other event IExtendControlbar receives.
  213. ASSERT( MMCN_BTN_CLICK == event );
  214. return pThis->Command( (UINT)param, NULL );
  215. }
  216. STDMETHOD(SetControlbar)( IControlbar *pControlbar,
  217. IExtendControlbar *pExtendControlbar )
  218. {
  219. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::SetControlbar this-%p\n"), this);
  220. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  221. T* pThis = (T*)this;
  222. CSnapInToolbarInfo* pInfo = pThis->GetToolbarInfo();
  223. if (pInfo == NULL)
  224. return S_OK;
  225. for( ; pInfo->m_idToolbar; pInfo++)
  226. {
  227. if (pInfo->m_pToolbar)
  228. continue;
  229. HBITMAP hBitmap = LoadBitmap( AfxGetInstanceHandle(), MAKEINTRESOURCE(pInfo->m_idToolbar) );
  230. if (hBitmap == NULL)
  231. return S_OK;
  232. HRSRC hRsrc = ::FindResource( AfxGetInstanceHandle(), MAKEINTRESOURCE(pInfo->m_idToolbar), RT_TOOLBAR );
  233. if (hRsrc == NULL)
  234. return S_OK;
  235. HGLOBAL hGlobal = LoadResource( AfxGetInstanceHandle(), hRsrc );
  236. if (hGlobal == NULL)
  237. return S_OK;
  238. CSnapInToolBarData* pData = (CSnapInToolBarData*)LockResource( hGlobal );
  239. if (pData == NULL)
  240. return S_OK;
  241. ASSERT( pData->wVersion == 1 );
  242. pInfo->m_nButtonCount = pData->wItemCount;
  243. pInfo->m_pnButtonID = new UINT[pInfo->m_nButtonCount];
  244. MMCBUTTON *pButtons = new MMCBUTTON[pData->wItemCount];
  245. pInfo->m_pStrToolTip = new TCHAR* [pData->wItemCount];
  246. if (pInfo->m_pStrToolTip == NULL)
  247. continue;
  248. for (int i = 0, j = 0; i < pData->wItemCount; i++)
  249. {
  250. pInfo->m_pStrToolTip[i] = NULL;
  251. memset(&pButtons[i], 0, sizeof(MMCBUTTON));
  252. pInfo->m_pnButtonID[i] = pButtons[i].idCommand = pData->items()[i];
  253. if (pButtons[i].idCommand)
  254. {
  255. pButtons[i].nBitmap = j++;
  256. // get the statusbar string and allow modification of the button state
  257. TCHAR strStatusBar[512];
  258. LoadString( AfxGetInstanceHandle(), pButtons[i].idCommand, strStatusBar, 512 );
  259. pInfo->m_pStrToolTip[i] = new TCHAR[lstrlen(strStatusBar) + 1];
  260. if (pInfo->m_pStrToolTip[i] == NULL)
  261. continue;
  262. lstrcpy( pInfo->m_pStrToolTip[i], strStatusBar );
  263. pButtons[i].lpTooltipText = pInfo->m_pStrToolTip[i];
  264. pButtons[i].lpButtonText = _T("");
  265. pThis->SetToolbarButtonInfo( pButtons[i].idCommand, &pButtons[i].fsState, &pButtons[i].fsType );
  266. }
  267. else
  268. {
  269. pButtons[i].lpTooltipText = _T("");
  270. pButtons[i].lpButtonText = _T("");
  271. pButtons[i].fsType = TBSTYLE_SEP;
  272. }
  273. }
  274. HRESULT hr = pControlbar->Create( TOOLBAR, pExtendControlbar, reinterpret_cast<LPUNKNOWN*>(&pInfo->m_pToolbar) );
  275. if (hr != S_OK)
  276. continue;
  277. // pData->wHeight is 15, but AddBitmap insists on 16, hard code it.
  278. hr = pInfo->m_pToolbar->AddBitmap( pData->wItemCount, hBitmap, pData->wWidth, 16, RGB(192, 192, 192) );
  279. if (hr != S_OK)
  280. {
  281. pInfo->m_pToolbar->Release();
  282. pInfo->m_pToolbar = NULL;
  283. continue;
  284. }
  285. hr = pInfo->m_pToolbar->AddButtons( pData->wItemCount, pButtons );
  286. if (hr != S_OK)
  287. {
  288. pInfo->m_pToolbar->Release();
  289. pInfo->m_pToolbar = NULL;
  290. }
  291. delete [] pButtons;
  292. }
  293. return S_OK;
  294. }
  295. ///////////////////////////////////////////////////////////////////////////
  296. // IExtendControlbar helpers
  297. // Non-interface members intended to be overridden by instantiated class.
  298. STDMETHOD_(void, SetToolbarButtonInfo)( UINT id, // button ID
  299. BYTE *fsState, // return button state here
  300. BYTE *fsType ) // return button type here
  301. {
  302. *fsState = TBSTATE_ENABLED;
  303. *fsType = TBSTYLE_BUTTON;
  304. }
  305. STDMETHOD_(BOOL, UpdateToolbarButton)( UINT id, // button ID
  306. BOOL bSnapObjSelected, // ==TRUE when result/scope item is selected
  307. BYTE fsState ) // enable/disable this button state by returning TRUE/FALSE
  308. {
  309. return FALSE;
  310. }
  311. BEGIN_SNAPINTOOLBARID_MAP(CWirelessSnapInDataObjectImpl)
  312. // Add a line like the following one for each toolbar to be displayed
  313. // for the derived class. Since there is no toolbar by default we'll
  314. // leave the macro out completely.
  315. //SNAPINTOOLBARID_ENTRY(your_toolbar_resource_id_goes_here, NULL)
  316. END_SNAPINTOOLBARID_MAP(CWirelessSnapInDataObjectImpl)
  317. ///////////////////////////////////////////////////////////////////////////
  318. // Interface to handle IComponent and IComponentData
  319. STDMETHOD(Notify)( MMC_NOTIFY_TYPE event,
  320. LPARAM arg,
  321. LPARAM param,
  322. BOOL bComponentData,
  323. IConsole *pConsole,
  324. IHeaderCtrl *pHeader )
  325. {
  326. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::Notify NOT implemented this-%p\n"), this);
  327. return E_NOTIMPL;
  328. }
  329. ///////////////////////////////////////////////////////////////////////////
  330. // IComponent and IComponentData Notify() helpers
  331. // Non-interface members intended to be overridden by instantiated class.
  332. STDMETHOD(OnDelete)( LPARAM arg, LPARAM param )
  333. {
  334. return S_OK;
  335. }
  336. STDMETHOD(OnRename)( LPARAM arg, LPARAM param )
  337. {
  338. return S_OK;
  339. }
  340. STDMETHOD(OnPropertyChange)( LPARAM lParam, LPCONSOLE pConsole )
  341. {
  342. T* pThis = (T*)this;
  343. // we changed, so update the views
  344. // NOTE: after we do this we are essentially invalid, so make sure we don't
  345. // touch any members etc on the way back out
  346. return pConsole->UpdateAllViews( pThis, 0, 0 );
  347. // we don't have a failure case
  348. }
  349. STDMETHOD(EnumerateResults)(LPRESULTDATA pResult, int nSortColumn, DWORD dwSortOrder )
  350. {
  351. ASSERT (0);
  352. // set the sort parameters
  353. pResult->Sort( nSortColumn, dwSortOrder, 0 );
  354. return S_OK; //hr;
  355. }
  356. ///////////////////////////////////////////////////////////////////////////
  357. // Interface to handle IComponent
  358. STDMETHOD(GetResultDisplayInfo)( RESULTDATAITEM *pResultDataItem )
  359. {
  360. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::GetResultDisplayInfo NOT implmented, this-%p\n"), this);
  361. return E_NOTIMPL;
  362. }
  363. ///////////////////////////////////////////////////////////////////////////
  364. // Interface to handle IComponentData
  365. STDMETHOD(GetScopeDisplayInfo)( SCOPEDATAITEM *pScopeDataItem )
  366. {
  367. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::GetScopeDisplayInfo NOT implemented, this-%p\n"), this);
  368. return E_NOTIMPL;
  369. }
  370. ///////////////////////////////////////////////////////////////////////////
  371. // Non-interface functions intended to be overridden by instantiated class
  372. STDMETHOD(DoPropertyChangeHook)( void )
  373. {
  374. return S_OK;
  375. }
  376. ///////////////////////////////////////////////////////////////////////////
  377. // Other IIWirelessSnapInData interface functions
  378. STDMETHOD(GetScopeData)( SCOPEDATAITEM **ppScopeDataItem )
  379. {
  380. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::GetScopeData NOT implemented, this-%p\n"), this);
  381. return E_NOTIMPL;
  382. }
  383. STDMETHOD(GetResultData)( RESULTDATAITEM **ppResultDataItem )
  384. {
  385. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::GetResultData NOT implemented, this-%p\n"), this);
  386. return E_NOTIMPL;
  387. }
  388. STDMETHOD(GetGuidForCompare)( GUID *pGuid )
  389. {
  390. OPT_TRACE(_T("CWirelessSnapInDataObjectImpl::GetGuidForCompare NOT implemented, this-%p\n"), this);
  391. return E_NOTIMPL;
  392. }
  393. STDMETHOD(GetDataObjectType)( DATA_OBJECT_TYPES *ptype )
  394. {
  395. ASSERT( NULL != ptype );
  396. if (NULL == ptype)
  397. return E_INVALIDARG;
  398. *ptype = m_DataObjType;
  399. return S_OK;
  400. }
  401. STDMETHOD(SetDataObjectType)( DATA_OBJECT_TYPES type )
  402. {
  403. m_DataObjType = type;
  404. return S_OK;
  405. }
  406. STDMETHOD(EnablePropertyChangeHook)( BOOL bEnable )
  407. {
  408. m_bEnablePropertyChangeHook = bEnable;
  409. return S_OK;
  410. }
  411. BOOL IsPropertyChangeHookEnabled()
  412. {
  413. return m_bEnablePropertyChangeHook;
  414. }
  415. protected:
  416. DATA_OBJECT_TYPES m_DataObjType;
  417. CSnapInToolbarInfo *m_aToolbarInfo; // IExtendControlbar impl
  418. CString m_strName; // Policy's name, stored on rename, used in GetResultDisplayInfo?
  419. BOOL m_bEnablePropertyChangeHook; // if TRUE, call DoPropertyChangeHook on MMCN_PROPERTY_CHANGE
  420. };
  421. #endif //#ifndef INCLUDE_SNPDATA_H