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.

420 lines
11 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. int menuItemStatusBarId
  195. ) throw ()
  196. : SnapInPreNamedItem(nameId),
  197. cxn(connection),
  198. loaded(false),
  199. errorTitle(errorTitleId),
  200. topMenuItem(topMenuItemId),
  201. newMenuItem(newMenuItemId),
  202. menuItemStatusBar(menuItemStatusBarId),
  203. scopeId(0)
  204. {
  205. cxn.advise(*this);
  206. }
  207. SdoScopeItem::~SdoScopeItem() throw ()
  208. {
  209. cxn.unadvise(*this);
  210. }
  211. void SdoScopeItem::addResultItem(SnapInView& view, SdoResultItem& item)
  212. {
  213. items.push_back(&item);
  214. if (active)
  215. {
  216. // We can't add it directly, since this may be called from a scope item.
  217. view.updateAllViews(item);
  218. }
  219. }
  220. void SdoScopeItem::deleteResultItem(SnapInView& view, SdoResultItem& item)
  221. {
  222. // Remove from the SDO collection,
  223. getSelf().remove(item.getSelf());
  224. // the result pane, and
  225. view.deleteResultItem(item);
  226. // our cached copy.
  227. items.erase(&item);
  228. }
  229. HRESULT SdoScopeItem::addMenuItems(
  230. SnapInView& view,
  231. LPCONTEXTMENUCALLBACK callback,
  232. long insertionAllowed
  233. )
  234. {
  235. CONTEXTMENUITEM cmi;
  236. memset(&cmi, 0, sizeof(cmi));
  237. if (insertionAllowed & CCM_INSERTIONALLOWED_NEW)
  238. {
  239. cmi.strName = newMenuItem;
  240. cmi.strStatusBarText = menuItemStatusBar;
  241. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  242. callback->AddItem(&cmi);
  243. }
  244. if (insertionAllowed & CCM_INSERTIONALLOWED_TOP)
  245. {
  246. cmi.strName = topMenuItem;
  247. cmi.strStatusBarText = menuItemStatusBar;
  248. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  249. callback->AddItem(&cmi);
  250. }
  251. return S_OK;
  252. }
  253. HRESULT SdoScopeItem::onRefresh(
  254. SnapInView& view
  255. )
  256. {
  257. // Refresh the connection.
  258. cxn.refresh(view);
  259. return S_OK;
  260. }
  261. HRESULT SdoScopeItem::onSelect(
  262. SnapInView& view,
  263. BOOL scopeItem,
  264. BOOL selected
  265. )
  266. {
  267. if (!selected) { return S_FALSE; }
  268. // Get IConsoleVerb ...
  269. CComPtr<IConsoleVerb> consoleVerb;
  270. CheckError(view.getConsole()->QueryConsoleVerb(&consoleVerb));
  271. // ... and turn on refresh.
  272. consoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, TRUE);
  273. return S_OK;
  274. }
  275. HRESULT SdoScopeItem::onShow(
  276. SnapInView& view,
  277. HSCOPEITEM itemId,
  278. BOOL selected
  279. )
  280. {
  281. if (selected)
  282. {
  283. // Set the icon strip.
  284. view.setImageStrip(IDB_PROXY_SMALL_ICONS, IDB_PROXY_LARGE_ICONS, FALSE);
  285. // Let the derived class update the column headers.
  286. insertColumns(view.getHeaderCtrl());
  287. // Populate the result pane.
  288. insertResultItems(view);
  289. // Our node is active.
  290. active = true;
  291. }
  292. else
  293. {
  294. active = false;
  295. }
  296. return S_OK;
  297. }
  298. HRESULT SdoScopeItem::onViewChange(
  299. SnapInView& view,
  300. LPARAM data,
  301. LPARAM hint
  302. )
  303. {
  304. loaded = false;
  305. if (active)
  306. {
  307. CheckError(view.getConsole()->SelectScopeItem(getScopeId()));
  308. }
  309. return S_OK;
  310. }
  311. bool SdoScopeItem::queryRefresh(SnapInView& view)
  312. {
  313. // Make sure no properties are open.
  314. for (ResultIterator i = items.begin(); i != items.end(); ++i)
  315. {
  316. if (view.isPropertySheetOpen(**i))
  317. {
  318. int retval;
  319. view.formatMessageBox(
  320. errorTitle,
  321. IDS_PROXY_E_CLOSE_ALL_SHEETS,
  322. TRUE,
  323. MB_OK | MB_ICONWARNING,
  324. &retval
  325. );
  326. return false;
  327. }
  328. }
  329. return true;
  330. }
  331. void SdoScopeItem::refreshComplete(SnapInView& view)
  332. {
  333. view.updateAllViews(*this);
  334. }
  335. void SdoScopeItem::insertResultItems(SnapInView& view)
  336. {
  337. // Delete any existing items.
  338. view.getResultData()->DeleteAllRsltItems();
  339. // Have we loaded everything from the SDO's yet?
  340. if (!loaded)
  341. {
  342. // Get ourself.
  343. SdoCollection self = getSelf();
  344. // Get the source iterator ...
  345. SdoEnum src(self.getNewEnum());
  346. // ... and the destination vector.
  347. ObjectVector<SdoResultItem> dst;
  348. dst.reserve(self.count());
  349. // Ask the derived class to get the result items.
  350. getResultItems(src, dst);
  351. // Swap them in.
  352. items.swap(dst);
  353. loaded = true;
  354. }
  355. RESULTDATAITEM rdi;
  356. memset(&rdi, 0, sizeof(rdi));
  357. rdi.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  358. rdi.str = MMC_CALLBACK;
  359. for (ResultIterator i = items.begin(); i != items.end(); ++i)
  360. {
  361. rdi.nImage = (*i)->getImageIndex();
  362. rdi.lParam = (LPARAM)*i;
  363. CheckError(view.getResultData()->InsertItem(&rdi));
  364. }
  365. }