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.

400 lines
11 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1999
  5. //
  6. // File: ocxcaching.cpp
  7. //
  8. // Contents: Classes that implement OCX caching snapin using the framework.
  9. //
  10. //--------------------------------------------------------------------
  11. #include "stdafx.hxx"
  12. //+-------------------------------------------------------------------
  13. //
  14. // Member: COCXCachingSnapinRootItem::ScInit
  15. //
  16. // Synopsis: Called immeadiately after the item is created to init
  17. // displayname, icon index etc...
  18. //
  19. // Arguments: [CBaseSnapin] -
  20. // [CColumnInfoEx] - Any columns to be displayed for this item.
  21. // [INT] - # of columns
  22. //
  23. // Returns: SC
  24. //
  25. //--------------------------------------------------------------------
  26. SC COCXCachingSnapinRootItem::ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex, INT ccolinfoex, BOOL fIsRoot)
  27. {
  28. DECLARE_SC(sc, _T("COCXCachingSnapinRootItem::ScInit"));
  29. sc = CBaseSnapinItem::ScInit(pSnapin, pcolinfoex, ccolinfoex, fIsRoot);
  30. if (sc)
  31. return sc;
  32. // Init following
  33. // a. Icon index.
  34. // b. Load display name.
  35. m_uIconIndex = 3; // use an enum instead of 3
  36. m_strDisplayName.LoadString(_Module.GetResourceInstance(), IDS_OCXCachingRoot);
  37. return sc;
  38. }
  39. //+-------------------------------------------------------------------
  40. //
  41. // Member: COCXCachingSnapinRootItem::ScGetField
  42. //
  43. // Synopsis: Get the string representation for given field to display
  44. // it in result pane.
  45. //
  46. // Arguments: [DAT] - The column requested (this is an enumeration).
  47. // [tstring] - Out string.
  48. //
  49. // Returns: SC
  50. //
  51. //--------------------------------------------------------------------
  52. SC COCXCachingSnapinRootItem::ScGetField (DAT dat, tstring& strField)
  53. {
  54. DECLARE_SC(sc, _T("COCXCachingSnapinRootItem::ScGetField"));
  55. switch(dat)
  56. {
  57. case datString1:
  58. strField = _T("OCX Caching Snapin Root Node");
  59. break;
  60. default:
  61. E_INVALIDARG;
  62. break;
  63. }
  64. return (sc);
  65. }
  66. //+-------------------------------------------------------------------
  67. //
  68. // Member: COCXCachingSnapinRootItem::ScCreateChildren
  69. //
  70. // Synopsis: Create any children (nodes & leaf items) for this item.
  71. //
  72. // Arguments: None
  73. //
  74. // Returns: SC
  75. //
  76. //--------------------------------------------------------------------
  77. SC COCXCachingSnapinRootItem::ScCreateChildren ()
  78. {
  79. DECLARE_SC(sc, _T("COCXCachingSnapinRootItem::ScCreateChildren"));
  80. COCXContainer * pitemChild = NULL;
  81. COCXContainer * pitemPrevious = NULL;
  82. // Create the 1st child node for calendar OCX.
  83. sc = COCXContainer::ScCreateLVContainer(this, pitemPrevious, &pitemChild, FALSE); // Why FALSE???
  84. if (sc)
  85. return sc;
  86. pitemChild->SetOCXGUID(TEXT("{8E27C92B-1264-101C-8A2F-040224009C02}"));
  87. pitemPrevious = pitemChild;
  88. // Create the 2nd child node for calendar OCX.
  89. sc = COCXContainer::ScCreateLVContainer(this, pitemPrevious, &pitemChild, FALSE); // Why FALSE???
  90. if (sc)
  91. return sc;
  92. pitemChild->SetOCXGUID(TEXT("{2179C5D3-EBFF-11CF-B6FD-00AA00B4E220}"));
  93. pitemPrevious = pitemChild;
  94. return (sc);
  95. }
  96. // Initialize context menu structures. Let us have one item for demonstration.
  97. SnapinMenuItem COCXCachingSnapinRootItem::s_rgmenuitem[] =
  98. {
  99. {IDS_EnableOCXCaching, IDS_EnableOCXCaching, IDS_EnableOCXCaching, CCM_INSERTIONPOINTID_PRIMARY_TOP, NULL, dwMenuAlwaysEnable, dwMenuNeverGray, 0},
  100. };
  101. INT COCXCachingSnapinRootItem::s_cmenuitem = CMENUITEM(s_rgmenuitem);
  102. // -----------------------------------------------------------------------------
  103. SnapinMenuItem *COCXCachingSnapinRootItem::Pmenuitem(void)
  104. {
  105. return s_rgmenuitem;
  106. }
  107. // -----------------------------------------------------------------------------
  108. INT COCXCachingSnapinRootItem::CMenuItem(void)
  109. {
  110. return s_cmenuitem;
  111. }
  112. //+-------------------------------------------------------------------
  113. //
  114. // Member: COCXCachingSnapinRootItem::ScCommand
  115. //
  116. // Synopsis:
  117. //
  118. // Arguments:
  119. //
  120. // Returns: SC
  121. //
  122. //--------------------------------------------------------------------
  123. SC COCXCachingSnapinRootItem::ScCommand (long nCommandID, CComponent *pComponent)
  124. {
  125. DECLARE_SC(sc, _T("COCXCachingSnapinRootItem::ScCommand"));
  126. COCXCachingSnapin *pSnapin = dynamic_cast<COCXCachingSnapin*>(Psnapin());
  127. if (!pSnapin)
  128. return sc;
  129. switch(nCommandID)
  130. {
  131. case IDS_EnableOCXCaching:
  132. {
  133. bool bCachingEnabled = pSnapin->FCacheOCX();
  134. pSnapin->SetCacheOCX(! bCachingEnabled);
  135. for (int i = 0; i < CMenuItem(); ++i)
  136. {
  137. if (s_rgmenuitem[i].lCommandID == IDS_EnableOCXCaching)
  138. s_rgmenuitem[i].dwFlagsChecked = (!bCachingEnabled);
  139. }
  140. }
  141. break;
  142. default:
  143. sc = E_INVALIDARG;
  144. break;
  145. }
  146. return (sc);
  147. }
  148. //+-------------------------------------------------------------------
  149. //
  150. // Member: COCXContainer::ScInit
  151. //
  152. // Synopsis: Called immeadiately after the item is created to init
  153. // displayname, icon index etc...
  154. //
  155. // Arguments: [CBaseSnapin] -
  156. // [CColumnInfoEx] - Any columns to be displayed for this item.
  157. // [INT] - # of columns
  158. //
  159. // Returns: SC
  160. //
  161. //--------------------------------------------------------------------
  162. SC COCXContainer::ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex, INT ccolinfoex, BOOL fIsRoot)
  163. {
  164. DECLARE_SC(sc, _T("COCXContainer::ScInit"));
  165. sc = CBaseSnapinItem::ScInit(pSnapin, pcolinfoex, ccolinfoex, fIsRoot);
  166. if (sc)
  167. return sc;
  168. // Init following
  169. // a. Icon index.
  170. // b. Load display name.
  171. m_uIconIndex = 4; // use an enum instead of 4
  172. m_strDisplayName.LoadString(_Module.GetResourceInstance(), IDS_OCXContainer);
  173. return sc;
  174. }
  175. BOOL COCXContainer::FCacheOCX()
  176. {
  177. COCXCachingSnapin *pSnapin = dynamic_cast<COCXCachingSnapin*>(Psnapin());
  178. if (!pSnapin)
  179. return FALSE;
  180. return pSnapin->FCacheOCX();
  181. }
  182. //+-------------------------------------------------------------------
  183. //
  184. // Member: COCXContainer::ScGetField
  185. //
  186. // Synopsis: Get the string representation for given field to display
  187. // it in result pane.
  188. //
  189. // Arguments: [DAT] - The column requested (this is an enumeration).
  190. // [tstring] - Out string.
  191. //
  192. // Returns: SC
  193. //
  194. //--------------------------------------------------------------------
  195. SC COCXContainer::ScGetField (DAT dat, tstring& strField)
  196. {
  197. DECLARE_SC(sc, _T("COCXContainer::ScGetField"));
  198. switch(dat)
  199. {
  200. case datString1:
  201. strField = _T("OCX Container");
  202. break;
  203. default:
  204. E_INVALIDARG;
  205. break;
  206. }
  207. return (sc);
  208. }
  209. //+-------------------------------------------------------------------
  210. //
  211. // Member: COCXContainer::ScInitOCX
  212. //
  213. // Synopsis: OCX is created & attached to host. Now MMC has asked
  214. // us to initialize the OCX.
  215. //
  216. // Arguments: [pUnkOCX] - IUnknown of the OCX.
  217. //
  218. // Returns: SC
  219. //
  220. //--------------------------------------------------------------------
  221. SC COCXContainer::ScInitOCX (LPUNKNOWN pUnkOCX, IConsole* pConsole)
  222. {
  223. DECLARE_SC(sc, _T("COCXContainer::ScInitOCX"));
  224. sc = ScCheckPointers(pUnkOCX, pConsole);
  225. if (sc)
  226. return sc;
  227. // Store the cached OCX ptr to provide it later in GetResultViewType2.
  228. if (FCacheOCX())
  229. m_mapOCXs.insert(CachedOCXs::value_type(pConsole, pUnkOCX));
  230. CComQIPtr <IPersistStreamInit> spPerStm(pUnkOCX);
  231. if (spPerStm)
  232. spPerStm->InitNew();
  233. return (sc);
  234. }
  235. IUnknown* COCXContainer::GetCachedOCX(IConsole* pConsole)
  236. {
  237. CachedOCXs::iterator it = m_mapOCXs.find(pConsole);
  238. if (it != m_mapOCXs.end())
  239. return it->second;
  240. return NULL;
  241. }
  242. //+-------------------------------------------------------------------
  243. //
  244. // Member: COCXContainer::ScCreateChildren
  245. //
  246. // Synopsis: Create any children (nodes & leaf items) for this item.
  247. //
  248. // Arguments: None
  249. //
  250. // Returns: SC
  251. //
  252. //--------------------------------------------------------------------
  253. SC COCXContainer::ScCreateChildren ()
  254. {
  255. DECLARE_SC(sc, _T("COCXContainer::ScCreateChildren"));
  256. return (sc);
  257. }
  258. //+-------------------------------------------------------------------
  259. //
  260. // Member: COCXContainer::ScCreateLVContainer
  261. //
  262. // Synopsis: Do we really need this method?
  263. //
  264. // Arguments:
  265. //
  266. // Returns: SC
  267. //
  268. //--------------------------------------------------------------------
  269. SC COCXContainer::ScCreateLVContainer(CBaseSnapinItem *pitemParent, CBaseSnapinItem *pitemPrevious, COCXContainer ** ppitem, BOOL fNew)
  270. {
  271. DECLARE_SC(sc, _T("COCXCachingSnapinRootItem::ScCreateLVContainer"));
  272. t_item * pitem = NULL;
  273. *ppitem = NULL;
  274. // What to do here?
  275. sc = ::ScCreateItem(pitemParent, pitemPrevious, &pitem, fNew);
  276. if (sc)
  277. return sc;
  278. *ppitem = pitem;
  279. return (sc);
  280. }
  281. //-------------------------------------------------------------------------------------
  282. // class COCXCachingSnapin
  283. #pragma BEGIN_CODESPACE_DATA
  284. SNR COCXCachingSnapin::s_rgsnr[] =
  285. {
  286. SNR(&nodetypeOCXCachingRoot, snrEnumSP ), // Standalone snapin.
  287. SNR(&nodetypeOCXCachingContainer1, snrEnumSP ), // enumerates this node in the scope pane
  288. SNR(&nodetypeOCXCachingContainer2, snrEnumSP ), // enumerates this node in the scope pane
  289. };
  290. LONG COCXCachingSnapin::s_rgiconid[] = {3};
  291. LONG COCXCachingSnapin::s_iconidStatic = 2;
  292. CColumnInfoEx COCXCachingSnapin::s_colinfo[] =
  293. {
  294. CColumnInfoEx(_T("Column Name0"), LVCFMT_LEFT, 180, datString1),
  295. CColumnInfoEx(_T("Column Name1"), LVCFMT_LEFT, 180, datString2),
  296. CColumnInfoEx(_T("Column Name2"), LVCFMT_LEFT, 180, datString3),
  297. };
  298. INT COCXCachingSnapin::s_ccolinfo = sizeof(s_colinfo) / sizeof(CColumnInfoEx);
  299. INT COCXCachingSnapin::s_colwidths[1];
  300. #pragma END_CODESPACE_DATA
  301. // include members needed for every snapin.
  302. SNAPIN_DEFINE( COCXCachingSnapin);
  303. /* COCXCachingSnapin::COCXCachingSnapin
  304. *
  305. * PURPOSE: Constructor
  306. *
  307. * PARAMETERS: None
  308. *
  309. */
  310. COCXCachingSnapin::COCXCachingSnapin()
  311. {
  312. m_pstrDisplayName = new tstring();
  313. m_bCacheOCX = false;
  314. *m_pstrDisplayName = _T("OCX Caching Snapin Root");
  315. }
  316. /* COCXCachingSnapin::~COCXCachingSnapin
  317. *
  318. * PURPOSE: Destructor
  319. *
  320. * PARAMETERS: None
  321. *
  322. */
  323. COCXCachingSnapin::~COCXCachingSnapin()
  324. {
  325. delete m_pstrDisplayName;
  326. }