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.

456 lines
12 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1999
  5. //
  6. // File: Renamesnap.cxx
  7. //
  8. // Contents: Classes that implement Rename snapin using the framework.
  9. //
  10. //--------------------------------------------------------------------
  11. #include "stdafx.hxx"
  12. //+-------------------------------------------------------------------
  13. //
  14. // Member: CRenameRootItem::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 CRenameRootItem::ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex, INT ccolinfoex, BOOL fIsRoot)
  27. {
  28. DECLARE_SC(sc, _T("CRenameRootItem::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_RenameROOT);
  37. return sc;
  38. }
  39. //+-------------------------------------------------------------------
  40. //
  41. // Member: CRenameRootItem::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 CRenameRootItem::ScGetField (DAT dat, tstring& strField)
  53. {
  54. DECLARE_SC(sc, _T("CRenameRootItem::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: CRenameRootItem::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 CRenameRootItem::ScCreateChildren ()
  84. {
  85. DECLARE_SC(sc, _T("CRenameRootItem::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 = CRenameSnapinLVLeafItem::ScCreateLVLeafItem(this, pitemPrevious, &pitemChild, FALSE); // Why FALSE???
  93. if (sc)
  94. return sc;
  95. pitemPrevious = pitemChild;
  96. }
  97. return (sc);
  98. }
  99. /*+-------------------------------------------------------------------------*
  100. *
  101. * CRenameRootItem::ScOnRename
  102. *
  103. * PURPOSE: Renames the item
  104. *
  105. * PARAMETERS:
  106. * const tstring :
  107. *
  108. * RETURNS:
  109. * SC
  110. *
  111. *+-------------------------------------------------------------------------*/
  112. SC
  113. CRenameRootItem::ScOnRename(const tstring& strNewName)
  114. {
  115. DECLARE_SC(sc, TEXT("CRenameRootItem::ScOnRename"));
  116. m_strDisplayName = strNewName;
  117. return sc;
  118. }
  119. //+-------------------------------------------------------------------
  120. //
  121. // Member: CRenameSnapinLVLeafItem::ScInit
  122. //
  123. // Synopsis: Called immeadiately after the item is created to init
  124. // displayname, icon index etc...
  125. //
  126. // Arguments: [CBaseSnapin] -
  127. // [CColumnInfoEx] - Any columns to be displayed for this item.
  128. // [INT] - # of columns
  129. //
  130. // Returns: SC
  131. //
  132. //--------------------------------------------------------------------
  133. SC CRenameSnapinLVLeafItem::ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex, INT ccolinfoex, BOOL fIsRoot)
  134. {
  135. DECLARE_SC(sc, _T("CRenameSnapinLVLeafItem::ScInit"));
  136. sc = CBaseSnapinItem::ScInit(pSnapin, pcolinfoex, ccolinfoex, fIsRoot);
  137. if (sc)
  138. return sc;
  139. // Init following
  140. // a. Icon index.
  141. // b. Load display name.
  142. m_uIconIndex = 7; // use an enum instead of 7
  143. m_strDisplayName.LoadString(_Module.GetResourceInstance(), IDS_LVLeafItem);
  144. return sc;
  145. }
  146. //+-------------------------------------------------------------------
  147. //
  148. // Member: CRenameSnapinLVLeafItem::ScGetField
  149. //
  150. // Synopsis: Get the string representation for given field to display
  151. // it in result pane.
  152. //
  153. // Arguments: [DAT] - The column requested (this is an enumeration).
  154. // [tstring] - Out string.
  155. //
  156. // Returns: SC
  157. //
  158. //--------------------------------------------------------------------
  159. SC CRenameSnapinLVLeafItem::ScGetField (DAT dat, tstring& strField)
  160. {
  161. DECLARE_SC(sc, _T("CRenameSnapinLVLeafItem::ScGetField"));
  162. switch(dat)
  163. {
  164. case datString1:
  165. strField = _T("LVLeaf String1");
  166. break;
  167. case datString2:
  168. strField = _T("LVLeaf String2");
  169. break;
  170. case datString3:
  171. strField = _T("LVLeaf String3");
  172. break;
  173. default:
  174. E_INVALIDARG;
  175. break;
  176. }
  177. return (sc);
  178. }
  179. //+-------------------------------------------------------------------
  180. //
  181. // Member: CRenameSnapinLVLeafItem::ScCreateLVLeafItem
  182. //
  183. // Synopsis: Do we really need this method?
  184. //
  185. // Arguments:
  186. //
  187. // Returns: SC
  188. //
  189. //--------------------------------------------------------------------
  190. SC CRenameSnapinLVLeafItem::ScCreateLVLeafItem(CRenameRootItem *pitemParent, t_itemChild * pitemPrevious, t_itemChild ** ppitem, BOOL fNew)
  191. {
  192. DECLARE_SC(sc, _T("CRenameSnapinLVLeafItem::ScCreateLVLeafItem"));
  193. t_itemChild * pitem = NULL;
  194. *ppitem = NULL;
  195. // What to do here?
  196. sc = ::ScCreateItem(pitemParent, pitemPrevious, &pitem, fNew);
  197. if (sc)
  198. return sc;
  199. *ppitem = pitem;
  200. return (sc);
  201. }
  202. // Initialize context menu structures. Let us have one item for demonstration.
  203. SnapinMenuItem CRenameSnapinLVLeafItem::s_rgmenuitemLVLeafItem[] =
  204. {
  205. {IDS_NewLVItem, IDS_NewLVItem, IDS_NewLVItem, CCM_INSERTIONPOINTID_PRIMARY_TOP, NULL, dwMenuAlwaysEnable, dwMenuNeverGray, dwMenuNeverChecked},
  206. {IDS_RenameScopeItem, IDS_RenameScopeItem, IDS_RenameScopeItem, CCM_INSERTIONPOINTID_PRIMARY_TOP, NULL, dwMenuAlwaysEnable, dwMenuNeverGray, dwMenuNeverChecked},
  207. {IDS_RenameResultItem, IDS_RenameResultItem, IDS_RenameResultItem, CCM_INSERTIONPOINTID_PRIMARY_TOP, NULL, dwMenuAlwaysEnable, dwMenuNeverGray, dwMenuNeverChecked},
  208. };
  209. INT CRenameSnapinLVLeafItem::s_cmenuitemLVLeafItem = CMENUITEM(s_rgmenuitemLVLeafItem);
  210. // -----------------------------------------------------------------------------
  211. SnapinMenuItem *CRenameSnapinLVLeafItem::Pmenuitem(void)
  212. {
  213. return s_rgmenuitemLVLeafItem;
  214. }
  215. // -----------------------------------------------------------------------------
  216. INT CRenameSnapinLVLeafItem::CMenuItem(void)
  217. {
  218. return s_cmenuitemLVLeafItem;
  219. }
  220. //+-------------------------------------------------------------------
  221. //
  222. // Member: CRenameSnapinLVLeafItem::ScCommand
  223. //
  224. // Synopsis:
  225. //
  226. // Arguments:
  227. //
  228. // Returns: SC
  229. //
  230. //--------------------------------------------------------------------
  231. SC CRenameSnapinLVLeafItem::ScCommand (long nCommandID, CComponent *pComponent)
  232. {
  233. DECLARE_SC(sc, _T("CRenameSnapinLVLeafItem::ScCommand"));
  234. switch(nCommandID)
  235. {
  236. case IDS_NewLVItem:
  237. sc = ScInsertResultItem(pComponent);
  238. break;
  239. case IDS_RenameScopeItem:
  240. sc = ScRenameScopeItem();
  241. break;
  242. case IDS_RenameResultItem:
  243. sc = ScRenameResultItem();
  244. break;
  245. default:
  246. sc = E_INVALIDARG;
  247. break;
  248. }
  249. return (sc);
  250. }
  251. /*+-------------------------------------------------------------------------*
  252. *
  253. * CRenameSnapinLVLeafItem::ScRenameScopeItem
  254. *
  255. * PURPOSE: Puts the parent scope item into rename mode.
  256. *
  257. * RETURNS:
  258. * SC
  259. *
  260. *+-------------------------------------------------------------------------*/
  261. SC
  262. CRenameSnapinLVLeafItem::ScRenameScopeItem()
  263. {
  264. DECLARE_SC(sc, _T("CRenameSnapinLVLeafItem::ScRenameScopeItem"));
  265. IConsole3Ptr spConsole3 = IpConsole(); // get a pointer to the IConsole3 interface
  266. sc = ScCheckPointers(spConsole3, PitemParent(), E_FAIL);
  267. if(sc)
  268. return sc;
  269. sc = spConsole3->RenameScopeItem(PitemParent()->Hscopeitem());
  270. return sc;
  271. }
  272. /*+-------------------------------------------------------------------------*
  273. *
  274. * CRenameSnapinLVLeafItem::ScInsertResultItem
  275. *
  276. * PURPOSE: Overrides the base class method because we need to cache the
  277. * IResultData2 and HRESULTITEM
  278. *
  279. * PARAMETERS:
  280. * CComponent * pComponent :
  281. *
  282. * RETURNS:
  283. * SC
  284. *
  285. *+-------------------------------------------------------------------------*/
  286. SC
  287. CRenameSnapinLVLeafItem::ScInsertResultItem(CComponent *pComponent)
  288. {
  289. DECLARE_SC(sc, _T("CRenameSnapinLVLeafItem::ScInsertResultItem"));
  290. RESULTDATAITEM resultdataitem;
  291. ASSERT(pComponent && pComponent->IpResultData());
  292. // Add this item
  293. ZeroMemory(&resultdataitem, sizeof(resultdataitem));
  294. resultdataitem.lParam = Cookie();
  295. resultdataitem.mask = RDI_STR | RDI_PARAM | RDI_IMAGE;
  296. // Callback for the display name.
  297. resultdataitem.str = MMC_CALLBACK;
  298. // Custom icon
  299. resultdataitem.nImage = (int) MMC_CALLBACK;
  300. sc = pComponent->IpResultData()->InsertItem(&resultdataitem);
  301. if (sc)
  302. return sc;
  303. // cache this item - NOTE: breaks for multiple views
  304. m_hresultItem = resultdataitem.itemID;
  305. m_spResultData2 = pComponent->IpResultData();
  306. return sc;
  307. }
  308. /*+-------------------------------------------------------------------------*
  309. *
  310. * CRenameSnapinLVLeafItem::ScRenameResultItem
  311. *
  312. * PURPOSE: Renames the list item
  313. *
  314. * RETURNS:
  315. * SC
  316. *
  317. *+-------------------------------------------------------------------------*/
  318. SC
  319. CRenameSnapinLVLeafItem::ScRenameResultItem()
  320. {
  321. DECLARE_SC(sc, _T("CRenameSnapinLVLeafItem::ScRenameResultItem"));
  322. sc = ScCheckPointers(m_spResultData2, PitemParent(), E_FAIL);
  323. if(sc)
  324. return sc;
  325. if(m_hresultItem==NULL)
  326. return (sc = E_FAIL);
  327. sc = m_spResultData2->RenameResultItem(m_hresultItem);
  328. return sc;
  329. }
  330. //-------------------------------------------------------------------------------------
  331. // class CRenameSnapin
  332. #pragma BEGIN_CODESPACE_DATA
  333. SNR CRenameSnapin::s_rgsnr[] =
  334. {
  335. SNR(&nodetypeRenameRoot, snrEnumSP ), // Standalone snapin.
  336. SNR(&nodetypeRenameLVLeafItem, snrEnumSP | snrEnumRP ), // enumerates this node in the scope pane and result pane.
  337. };
  338. LONG CRenameSnapin::s_rgiconid[] = {3};
  339. LONG CRenameSnapin::s_iconidStatic = 2;
  340. CColumnInfoEx CRenameSnapin::s_colinfo[] =
  341. {
  342. CColumnInfoEx(_T("Column Name0"), LVCFMT_LEFT, 180, datString1),
  343. CColumnInfoEx(_T("Column Name1"), LVCFMT_LEFT, 180, datString2),
  344. CColumnInfoEx(_T("Column Name2"), LVCFMT_LEFT, 180, datString3),
  345. };
  346. INT CRenameSnapin::s_ccolinfo = sizeof(s_colinfo) / sizeof(CColumnInfoEx);
  347. INT CRenameSnapin::s_colwidths[1];
  348. #pragma END_CODESPACE_DATA
  349. // include members needed for every snapin.
  350. SNAPIN_DEFINE(CRenameSnapin);
  351. /* CRenameSnapin::CRenameSnapin
  352. *
  353. * PURPOSE: Constructor
  354. *
  355. * PARAMETERS: None
  356. *
  357. */
  358. CRenameSnapin::CRenameSnapin()
  359. {
  360. m_pstrDisplayName = new tstring();
  361. *m_pstrDisplayName = _T("Rename Snapin Root");
  362. }
  363. /* CRenameSnapin::~CRenameSnapin
  364. *
  365. * PURPOSE: Destructor
  366. *
  367. * PARAMETERS: None
  368. *
  369. */
  370. CRenameSnapin::~CRenameSnapin()
  371. {
  372. delete m_pstrDisplayName;
  373. }