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.

416 lines
10 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // sdonode.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the classes SdoResultItem and SdoScopeItem.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/10/2000 Original version.
  16. // 04/25/2000 Don't add result item unless pane is active.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <proxypch.h>
  20. #include <sdonode.h>
  21. #include <proxynode.h>
  22. SdoResultItem::SdoResultItem(
  23. SdoScopeItem& owner,
  24. ISdo* sdo
  25. )
  26. : parent(owner), self(sdo)
  27. {
  28. self.getName(name);
  29. }
  30. HRESULT SdoResultItem::queryPagesFor() throw ()
  31. { return S_OK; }
  32. HRESULT SdoResultItem::onDelete(
  33. SnapInView& view
  34. )
  35. {
  36. // Can't delete it with the properties open.
  37. if (view.isPropertySheetOpen(*this))
  38. {
  39. int retval;
  40. view.formatMessageBox(
  41. mapResourceId(ERROR_CAPTION),
  42. IDS_PROXY_E_CLOSE_SHEET,
  43. TRUE,
  44. MB_OK | MB_ICONWARNING,
  45. &retval
  46. );
  47. return S_FALSE;
  48. }
  49. // Confirm the delete operation.
  50. int retval;
  51. bool isLast = (parent.getNumItems() == 1);
  52. if (parent.getCxn().isLocal())
  53. {
  54. view.formatMessageBox(
  55. mapResourceId(DELETE_TITLE),
  56. isLast?mapResourceId(DELETE_LAST_LOCAL)
  57. :mapResourceId(DELETE_LOCAL),
  58. FALSE,
  59. MB_YESNO | MB_ICONQUESTION,
  60. &retval,
  61. name
  62. );
  63. }
  64. else
  65. {
  66. view.formatMessageBox(
  67. mapResourceId(DELETE_TITLE),
  68. isLast?mapResourceId(DELETE_LAST_REMOTE)
  69. :mapResourceId(DELETE_REMOTE),
  70. FALSE,
  71. MB_YESNO | MB_ICONQUESTION,
  72. &retval,
  73. name,
  74. parent.getCxn().getMachineName()
  75. );
  76. }
  77. if (retval != IDYES) { return S_FALSE; }
  78. // It passed the tests, so ask our parent to delete us.
  79. parent.deleteResultItem(view, *this);
  80. // Tell the service to reload
  81. parent.getCxn().resetService();
  82. return S_OK;
  83. }
  84. HRESULT SdoResultItem::onPropertyChange(
  85. SnapInView& view,
  86. BOOL scopeItem
  87. )
  88. {
  89. // Reload our name.
  90. self.getName(name);
  91. // Update the result pane.
  92. view.updateResultItem(*this);
  93. // Tell the service to reload
  94. parent.getCxn().resetService();
  95. return S_OK;
  96. }
  97. HRESULT SdoResultItem::onRename(
  98. SnapInView& view,
  99. LPCOLESTR newName
  100. )
  101. {
  102. // Can't rename with the properties open.
  103. if (view.isPropertySheetOpen(*this))
  104. {
  105. int retval;
  106. view.formatMessageBox(
  107. mapResourceId(ERROR_CAPTION),
  108. IDS_PROXY_E_CLOSE_SHEET,
  109. TRUE,
  110. MB_OK | MB_ICONWARNING,
  111. &retval
  112. );
  113. return S_FALSE;
  114. }
  115. // Turn newName into a BSTR ...
  116. CComBSTR bstrNewName(newName);
  117. if (!bstrNewName) { AfxThrowOleException(E_OUTOFMEMORY); }
  118. // ... and trim off the fat.
  119. SdoTrimBSTR(bstrNewName);
  120. // Names can't be empty.
  121. if (bstrNewName.Length() == 0)
  122. {
  123. int retval;
  124. view.formatMessageBox(
  125. mapResourceId(ERROR_CAPTION),
  126. mapResourceId(ERROR_NAME_EMPTY),
  127. TRUE,
  128. MB_OK | MB_ICONWARNING,
  129. &retval
  130. );
  131. return S_FALSE;
  132. }
  133. // This will fail if the name isn't unique.
  134. if (!self.setName(bstrNewName))
  135. {
  136. int retval;
  137. view.formatMessageBox(
  138. mapResourceId(ERROR_CAPTION),
  139. mapResourceId(ERROR_NOT_UNIQUE),
  140. FALSE,
  141. MB_OK | MB_ICONWARNING,
  142. &retval,
  143. (BSTR)name
  144. );
  145. return S_FALSE;
  146. }
  147. // Write the result to the datastore.
  148. self.apply();
  149. // Update our cached value.
  150. name.Attach(bstrNewName.Detach());
  151. // Tell the service to reload
  152. parent.getCxn().resetService();
  153. return S_OK;
  154. }
  155. HRESULT SdoResultItem::onSelect(
  156. SnapInView& view,
  157. BOOL scopeItem,
  158. BOOL selected
  159. )
  160. {
  161. if (!selected) { return S_FALSE; }
  162. // Get IConsoleVerb ...
  163. CComPtr<IConsoleVerb> consoleVerb;
  164. CheckError(view.getConsole()->QueryConsoleVerb(&consoleVerb));
  165. // ... and turn on our verbs. Don't care if this fails.
  166. consoleVerb->SetVerbState(MMC_VERB_DELETE, ENABLED, TRUE);
  167. consoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  168. consoleVerb->SetVerbState(MMC_VERB_RENAME, ENABLED, TRUE);
  169. consoleVerb->SetDefaultVerb(MMC_VERB_PROPERTIES);
  170. return S_OK;
  171. }
  172. HRESULT SdoResultItem::onViewChange(
  173. SnapInView& view,
  174. LPARAM data,
  175. LPARAM hint
  176. )
  177. {
  178. // Currently, this is only called when a new object is added.
  179. RESULTDATAITEM rdi;
  180. memset(&rdi, 0, sizeof(rdi));
  181. rdi.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  182. rdi.str = MMC_CALLBACK;
  183. rdi.nImage = getImageIndex();
  184. rdi.lParam = (LPARAM)this;
  185. CheckError(view.getResultData()->InsertItem(&rdi));
  186. return S_OK;
  187. }
  188. SdoScopeItem::SdoScopeItem(
  189. SdoConnection& connection,
  190. int nameId,
  191. int errorTitleId,
  192. int topMenuItemId,
  193. int newMenuItemId
  194. ) throw ()
  195. : SnapInPreNamedItem(nameId),
  196. cxn(connection),
  197. loaded(false),
  198. errorTitle(errorTitleId),
  199. topMenuItem(topMenuItemId),
  200. newMenuItem(newMenuItemId),
  201. scopeId(0)
  202. {
  203. cxn.advise(*this);
  204. }
  205. SdoScopeItem::~SdoScopeItem() throw ()
  206. {
  207. cxn.unadvise(*this);
  208. }
  209. void SdoScopeItem::addResultItem(SnapInView& view, SdoResultItem& item)
  210. {
  211. items.push_back(&item);
  212. if (active)
  213. {
  214. // We can't add it directly, since this may be called from a scope item.
  215. CheckError(view.getConsole()->UpdateAllViews(&item, 0, 0));
  216. }
  217. }
  218. void SdoScopeItem::deleteResultItem(SnapInView& view, SdoResultItem& item)
  219. {
  220. // Remove from the SDO collection,
  221. getSelf().remove(item.getSelf());
  222. // the result pane, and
  223. view.deleteResultItem(item);
  224. // our cached copy.
  225. items.erase(&item);
  226. }
  227. HRESULT SdoScopeItem::addMenuItems(
  228. SnapInView& view,
  229. LPCONTEXTMENUCALLBACK callback,
  230. long insertionAllowed
  231. )
  232. {
  233. CONTEXTMENUITEM cmi;
  234. memset(&cmi, 0, sizeof(cmi));
  235. if (insertionAllowed & CCM_INSERTIONALLOWED_NEW)
  236. {
  237. cmi.strName = newMenuItem;
  238. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  239. callback->AddItem(&cmi);
  240. }
  241. if (insertionAllowed & CCM_INSERTIONALLOWED_TOP)
  242. {
  243. cmi.strName = topMenuItem;
  244. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  245. callback->AddItem(&cmi);
  246. }
  247. return S_OK;
  248. }
  249. HRESULT SdoScopeItem::onRefresh(
  250. SnapInView& view
  251. )
  252. {
  253. // Refresh the connection.
  254. cxn.refresh(view);
  255. return S_OK;
  256. }
  257. HRESULT SdoScopeItem::onSelect(
  258. SnapInView& view,
  259. BOOL scopeItem,
  260. BOOL selected
  261. )
  262. {
  263. if (!selected) { return S_FALSE; }
  264. // Get IConsoleVerb ...
  265. CComPtr<IConsoleVerb> consoleVerb;
  266. CheckError(view.getConsole()->QueryConsoleVerb(&consoleVerb));
  267. // ... and turn on refresh.
  268. consoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, TRUE);
  269. return S_OK;
  270. }
  271. HRESULT SdoScopeItem::onShow(
  272. SnapInView& view,
  273. HSCOPEITEM itemId,
  274. BOOL selected
  275. )
  276. {
  277. if (selected)
  278. {
  279. // Set the icon strip.
  280. view.setImageStrip(IDB_PROXY_SMALL_ICONS, IDB_PROXY_LARGE_ICONS, FALSE);
  281. // Let the derived class update the column headers.
  282. insertColumns(view.getHeaderCtrl());
  283. // Populate the result pane.
  284. insertResultItems(view);
  285. // Our node is active.
  286. active = true;
  287. }
  288. else
  289. {
  290. active = false;
  291. }
  292. return S_OK;
  293. }
  294. HRESULT SdoScopeItem::onViewChange(
  295. SnapInView& view,
  296. LPARAM data,
  297. LPARAM hint
  298. )
  299. {
  300. loaded = false;
  301. if (active)
  302. {
  303. CheckError(view.getConsole()->SelectScopeItem(getScopeId()));
  304. }
  305. return S_OK;
  306. }
  307. bool SdoScopeItem::queryRefresh(SnapInView& view)
  308. {
  309. // Make sure no properties are open.
  310. for (ResultIterator i = items.begin(); i != items.end(); ++i)
  311. {
  312. if (view.isPropertySheetOpen(**i))
  313. {
  314. int retval;
  315. view.formatMessageBox(
  316. errorTitle,
  317. IDS_PROXY_E_CLOSE_ALL_SHEETS,
  318. TRUE,
  319. MB_OK | MB_ICONWARNING,
  320. &retval
  321. );
  322. return false;
  323. }
  324. }
  325. return true;
  326. }
  327. void SdoScopeItem::refreshComplete(SnapInView& view)
  328. {
  329. CheckError(view.getConsole()->UpdateAllViews(this, 0, 0));
  330. }
  331. void SdoScopeItem::insertResultItems(SnapInView& view)
  332. {
  333. // Delete any existing items.
  334. view.getResultData()->DeleteAllRsltItems();
  335. // Have we loaded everything from the SDO's yet?
  336. if (!loaded)
  337. {
  338. // Get ourself.
  339. SdoCollection self = getSelf();
  340. // Get the source iterator ...
  341. SdoEnum src(self.getNewEnum());
  342. // ... and the destination vector.
  343. ObjectVector<SdoResultItem> dst;
  344. dst.reserve(self.count());
  345. // Ask the derived class to get the result items.
  346. getResultItems(src, dst);
  347. // Swap them in.
  348. items.swap(dst);
  349. loaded = true;
  350. }
  351. RESULTDATAITEM rdi;
  352. memset(&rdi, 0, sizeof(rdi));
  353. rdi.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  354. rdi.str = MMC_CALLBACK;
  355. for (ResultIterator i = items.begin(); i != items.end(); ++i)
  356. {
  357. rdi.nImage = (*i)->getImageIndex();
  358. rdi.lParam = (LPARAM)*i;
  359. CheckError(view.getResultData()->InsertItem(&rdi));
  360. }
  361. }