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.

484 lines
13 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1999
  5. //
  6. // File: Component2Testsnap.cxx
  7. //
  8. // Contents: Classes that implement Component2Test snapin using the framework.
  9. //
  10. //--------------------------------------------------------------------
  11. #include "stdafx.hxx"
  12. //+-------------------------------------------------------------------
  13. //
  14. // Member: CComponent2TestRootItem::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 CComponent2TestRootItem::ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex, INT ccolinfoex, BOOL fIsRoot)
  27. {
  28. DECLARE_SC(sc, _T("CComponent2TestRootItem::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_Component2TestROOT);
  37. return sc;
  38. }
  39. //+-------------------------------------------------------------------
  40. //
  41. // Member: CComponent2TestRootItem::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 CComponent2TestRootItem::ScGetField (DAT dat, tstring& strField)
  53. {
  54. DECLARE_SC(sc, _T("CComponent2TestRootItem::ScGetField"));
  55. switch(dat)
  56. {
  57. case datString1:
  58. strField = _T("Root String1");
  59. break;
  60. case datString2:
  61. strField = _T("Root String2");
  62. break;
  63. case datString3:
  64. strField = _T("Root String3");
  65. break;
  66. default:
  67. E_INVALIDARG;
  68. break;
  69. }
  70. return (sc);
  71. }
  72. //+-------------------------------------------------------------------
  73. //
  74. // Member: CComponent2TestRootItem::ScCreateChildren
  75. //
  76. // Synopsis: Create any children (nodes & leaf items) for this item.
  77. //
  78. // Arguments: None
  79. //
  80. // Returns: SC
  81. //
  82. //--------------------------------------------------------------------
  83. SC CComponent2TestRootItem::ScCreateChildren ()
  84. {
  85. DECLARE_SC(sc, _T("CComponent2TestRootItem::ScCreateChildren"));
  86. t_itemChild * pitemChild = NULL;
  87. t_itemChild * pitemPrevious = NULL;
  88. // Let us create 10 items for this container.
  89. for (int i = 0; i < 10; ++i)
  90. {
  91. // Create the child nodes and init them.
  92. sc = CComponent2TestSnapinLVLeafItem::ScCreateLVLeafItem(this, pitemPrevious, &pitemChild, FALSE); // Why FALSE???
  93. if (sc)
  94. return sc;
  95. pitemPrevious = pitemChild;
  96. }
  97. return (sc);
  98. }
  99. //+-------------------------------------------------------------------
  100. //
  101. // Member: CComponent2TestRootItem::ScQueryDispatch
  102. //
  103. // Synopsis: We support IDispatch for scripting, just return a pointer
  104. // to the IDispatch of ourselves.
  105. //
  106. // Arguments:
  107. //
  108. // Returns: SC
  109. //
  110. //--------------------------------------------------------------------
  111. SC CComponent2TestRootItem::ScQueryDispatch(long cookie, DATA_OBJECT_TYPES type, LPDISPATCH *ppDispatch)
  112. {
  113. DECLARE_SC(sc, _T("CComponent2TestRootItem::ScQueryDispatch"));
  114. *ppDispatch = dynamic_cast<IDispatch*>(this);
  115. if (! *ppDispatch)
  116. return (sc = E_NOINTERFACE);
  117. (*ppDispatch)->AddRef();
  118. return sc;
  119. }
  120. HRESULT CComponent2TestRootItem::StringFromScriptToSnapin(BSTR bstrMessage)
  121. {
  122. DECLARE_SC(sc , _T("CComponent2TestRootItem::StringFromScriptToSnapin"));
  123. // The script is supposed to give us this function name in the string.
  124. if (0 == _wcsicmp(bstrMessage, L"StringFromScriptToSnapin"))
  125. return sc.ToHr();
  126. sc = E_FAIL;
  127. return sc.ToHr();
  128. }
  129. HRESULT CComponent2TestRootItem::StringFromSnapinToScript(BSTR *pbstrMessage)
  130. {
  131. DECLARE_SC(sc , _T("CComponent2TestRootItem::StringFromSnapinToScript"));
  132. sc = ScCheckPointers(pbstrMessage);
  133. if (sc)
  134. return sc.ToHr();
  135. // The script is supposed to expect this function name in the string.
  136. *pbstrMessage = ::SysAllocString(OLESTR("StringFromSnapinToScript"));
  137. return sc.ToHr();
  138. }
  139. HRESULT CComponent2TestRootItem::get_Name(BSTR *pbstrMessage)
  140. {
  141. DECLARE_SC(sc , _T("CComponent2TestRootItem::get_Name"));
  142. sc = ScCheckPointers(pbstrMessage);
  143. if (sc)
  144. return sc.ToHr();
  145. // The script is supposed to expect this function name in the string.
  146. *pbstrMessage = ::SysAllocString(OLESTR("Name"));
  147. return sc.ToHr();
  148. }
  149. HRESULT CComponent2TestRootItem::put_Name(BSTR bstrMessage)
  150. {
  151. DECLARE_SC(sc , _T("CComponent2TestRootItem::put_Name"));
  152. // The script is supposed to give us this function name in the string.
  153. if (0 == _wcsicmp(bstrMessage, L"Name"))
  154. return sc.ToHr();
  155. sc = E_FAIL;
  156. return sc.ToHr();
  157. }
  158. //+-------------------------------------------------------------------
  159. //
  160. // Member: CComponent2TestSnapinLVLeafItem::ScInit
  161. //
  162. // Synopsis: Called immeadiately after the item is created to init
  163. // displayname, icon index etc...
  164. //
  165. // Arguments: [CBaseSnapin] -
  166. // [CColumnInfoEx] - Any columns to be displayed for this item.
  167. // [INT] - # of columns
  168. //
  169. // Returns: SC
  170. //
  171. //--------------------------------------------------------------------
  172. SC CComponent2TestSnapinLVLeafItem::ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex, INT ccolinfoex, BOOL fIsRoot)
  173. {
  174. DECLARE_SC(sc, _T("CComponent2TestSnapinLVLeafItem::ScInit"));
  175. sc = CBaseSnapinItem::ScInit(pSnapin, pcolinfoex, ccolinfoex, fIsRoot);
  176. if (sc)
  177. return sc;
  178. // Init following
  179. // a. Icon index.
  180. // b. Load display name.
  181. m_uIconIndex = 7; // use an enum instead of 7
  182. m_strDisplayName.LoadString(_Module.GetResourceInstance(), IDS_LVLeafItem);
  183. return sc;
  184. }
  185. //+-------------------------------------------------------------------
  186. //
  187. // Member: CComponent2TestSnapinLVLeafItem::ScGetField
  188. //
  189. // Synopsis: Get the string representation for given field to display
  190. // it in result pane.
  191. //
  192. // Arguments: [DAT] - The column requested (this is an enumeration).
  193. // [tstring] - Out string.
  194. //
  195. // Returns: SC
  196. //
  197. //--------------------------------------------------------------------
  198. SC CComponent2TestSnapinLVLeafItem::ScGetField (DAT dat, tstring& strField)
  199. {
  200. DECLARE_SC(sc, _T("CComponent2TestSnapinLVLeafItem::ScGetField"));
  201. switch(dat)
  202. {
  203. case datString1:
  204. strField = _T("LVLeaf String1");
  205. break;
  206. case datString2:
  207. strField = _T("LVLeaf String2");
  208. break;
  209. case datString3:
  210. strField = _T("LVLeaf String3");
  211. break;
  212. default:
  213. E_INVALIDARG;
  214. break;
  215. }
  216. return (sc);
  217. }
  218. //+-------------------------------------------------------------------
  219. //
  220. // Member: CComponent2TestSnapinLVLeafItem::ScCreateLVLeafItem
  221. //
  222. // Synopsis: Do we really need this method?
  223. //
  224. // Arguments:
  225. //
  226. // Returns: SC
  227. //
  228. //--------------------------------------------------------------------
  229. SC CComponent2TestSnapinLVLeafItem::ScCreateLVLeafItem(CComponent2TestRootItem *pitemParent, t_itemChild * pitemPrevious, t_itemChild ** ppitem, BOOL fNew)
  230. {
  231. DECLARE_SC(sc, _T("CComponent2TestSnapinLVLeafItem::ScCreateLVLeafItem"));
  232. t_itemChild * pitem = NULL;
  233. *ppitem = NULL;
  234. // What to do here?
  235. sc = ::ScCreateItem(pitemParent, pitemPrevious, &pitem, fNew);
  236. if (sc)
  237. return sc;
  238. *ppitem = pitem;
  239. return (sc);
  240. }
  241. // Initialize context menu structures. Let us have one item for demonstration.
  242. SnapinMenuItem CComponent2TestSnapinLVLeafItem::s_rgmenuitemLVLeafItem[] =
  243. {
  244. {IDS_NewLVItem, IDS_NewLVItem, IDS_NewLVItem, CCM_INSERTIONPOINTID_PRIMARY_TOP, NULL, dwMenuAlwaysEnable, dwMenuNeverGray, dwMenuNeverChecked},
  245. };
  246. INT CComponent2TestSnapinLVLeafItem::s_cmenuitemLVLeafItem = CMENUITEM(s_rgmenuitemLVLeafItem);
  247. // -----------------------------------------------------------------------------
  248. SnapinMenuItem *CComponent2TestSnapinLVLeafItem::Pmenuitem(void)
  249. {
  250. return s_rgmenuitemLVLeafItem;
  251. }
  252. // -----------------------------------------------------------------------------
  253. INT CComponent2TestSnapinLVLeafItem::CMenuItem(void)
  254. {
  255. return s_cmenuitemLVLeafItem;
  256. }
  257. //+-------------------------------------------------------------------
  258. //
  259. // Member: CComponent2TestSnapinLVLeafItem::ScCommand
  260. //
  261. // Synopsis:
  262. //
  263. // Arguments:
  264. //
  265. // Returns: SC
  266. //
  267. //--------------------------------------------------------------------
  268. SC CComponent2TestSnapinLVLeafItem::ScCommand (long nCommandID, CComponent *pComponent)
  269. {
  270. DECLARE_SC(sc, _T("CComponent2TestSnapinLVLeafItem::ScCommand"));
  271. switch(nCommandID)
  272. {
  273. case IDS_NewLVItem:
  274. sc = ScInsertResultItem(pComponent);
  275. break;
  276. default:
  277. sc = E_INVALIDARG;
  278. break;
  279. }
  280. return (sc);
  281. }
  282. //+-------------------------------------------------------------------
  283. //
  284. // Member: CComponent2TestSnapinLVLeafItem::ScQueryDispatch
  285. //
  286. // Synopsis: We support IDispatch for scripting, just return a pointer
  287. // to the IDispatch of ourselves.
  288. //
  289. // Arguments:
  290. //
  291. // Returns: SC
  292. //
  293. //--------------------------------------------------------------------
  294. SC CComponent2TestSnapinLVLeafItem::ScQueryDispatch(long cookie, DATA_OBJECT_TYPES type, LPDISPATCH *ppDispatch)
  295. {
  296. DECLARE_SC(sc, _T("CComponent2TestSnapinLVLeafItem::ScQueryDispatch"));
  297. *ppDispatch = dynamic_cast<IDispatch *>(this);
  298. if (! *ppDispatch)
  299. return (sc = E_NOINTERFACE);
  300. (*ppDispatch)->AddRef();
  301. return sc;
  302. }
  303. HRESULT CComponent2TestSnapinLVLeafItem::StringFromScriptToSnapin(BSTR bstrMessage)
  304. {
  305. DECLARE_SC(sc , _T("CComponent2TestSnapinLVLeafItem::StringFromScriptToSnapin"));
  306. // The script is supposed to give us this function name in the string.
  307. if (0 == _wcsicmp(bstrMessage, L"StringFromScriptToSnapin"))
  308. return sc.ToHr();
  309. sc = E_FAIL;
  310. return sc.ToHr();
  311. }
  312. HRESULT CComponent2TestSnapinLVLeafItem::StringFromSnapinToScript(BSTR *pbstrMessage)
  313. {
  314. DECLARE_SC(sc , _T("CComponent2TestSnapinLVLeafItem::StringFromSnapinToScript"));
  315. sc = ScCheckPointers(pbstrMessage);
  316. if (sc)
  317. return sc.ToHr();
  318. // The script is supposed to expect this function name in the string.
  319. *pbstrMessage = ::SysAllocString(OLESTR("StringFromSnapinToScript"));
  320. return sc.ToHr();
  321. }
  322. HRESULT CComponent2TestSnapinLVLeafItem::get_Name(BSTR *pbstrMessage)
  323. {
  324. DECLARE_SC(sc , _T("CComponent2TestSnapinLVLeafItem::get_Name"));
  325. sc = ScCheckPointers(pbstrMessage);
  326. if (sc)
  327. return sc.ToHr();
  328. // The script is supposed to expect this function name in the string.
  329. *pbstrMessage = ::SysAllocString(OLESTR("Name"));
  330. return sc.ToHr();
  331. }
  332. HRESULT CComponent2TestSnapinLVLeafItem::put_Name(BSTR bstrMessage)
  333. {
  334. DECLARE_SC(sc , _T("CComponent2TestSnapinLVLeafItem::put_Name"));
  335. // The script is supposed to give us this function name in the string.
  336. if (0 == _wcsicmp(bstrMessage, L"Name"))
  337. return sc.ToHr();
  338. sc = E_FAIL;
  339. return sc.ToHr();
  340. }
  341. //-------------------------------------------------------------------------------------
  342. // class CComponent2TestSnapin
  343. #pragma BEGIN_CODESPACE_DATA
  344. SNR CComponent2TestSnapin::s_rgsnr[] =
  345. {
  346. SNR(&nodetypeComponent2TestRoot, snrEnumSP ), // Standalone snapin.
  347. SNR(&nodetypeComponent2TestLVLeafItem, snrEnumSP | snrEnumRP ), // enumerates this node in the scope pane and result pane.
  348. };
  349. LONG CComponent2TestSnapin::s_rgiconid[] = {3};
  350. LONG CComponent2TestSnapin::s_iconidStatic = 2;
  351. CColumnInfoEx CComponent2TestSnapin::s_colinfo[] =
  352. {
  353. CColumnInfoEx(_T("Column Name0"), LVCFMT_LEFT, 180, datString1),
  354. CColumnInfoEx(_T("Column Name1"), LVCFMT_LEFT, 180, datString2),
  355. CColumnInfoEx(_T("Column Name2"), LVCFMT_LEFT, 180, datString3),
  356. };
  357. INT CComponent2TestSnapin::s_ccolinfo = sizeof(s_colinfo) / sizeof(CColumnInfoEx);
  358. INT CComponent2TestSnapin::s_colwidths[1];
  359. #pragma END_CODESPACE_DATA
  360. // include members needed for every snapin.
  361. SNAPIN_DEFINE(CComponent2TestSnapin);
  362. /* CComponent2TestSnapin::CComponent2TestSnapin
  363. *
  364. * PURPOSE: Constructor
  365. *
  366. * PARAMETERS: None
  367. *
  368. */
  369. CComponent2TestSnapin::CComponent2TestSnapin()
  370. {
  371. m_pstrDisplayName = new tstring();
  372. *m_pstrDisplayName = _T("Component2Test Snapin Root");
  373. }
  374. /* CComponent2TestSnapin::~CComponent2TestSnapin
  375. *
  376. * PURPOSE: Destructor
  377. *
  378. * PARAMETERS: None
  379. *
  380. */
  381. CComponent2TestSnapin::~CComponent2TestSnapin()
  382. {
  383. delete m_pstrDisplayName;
  384. }