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.

391 lines
10 KiB

  1. //==============================================================;
  2. //
  3. // This source code is only intended as a supplement to
  4. // existing Microsoft documentation.
  5. //
  6. //
  7. //
  8. //
  9. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  10. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  11. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  12. // PURPOSE.
  13. //
  14. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  15. //
  16. //
  17. //
  18. //==============================================================;
  19. #include <stdio.h>
  20. #include "DataObj.h"
  21. #include "Space.h"
  22. #include "Comp.h"
  23. const GUID CSpaceFolder::thisGuid = { 0x29743810, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  24. const GUID CSpaceStation::thisGuid = { 0x62273a12, 0x1914, 0x11d3, { 0x9a, 0x38, 0x0, 0x80, 0xc7, 0x25, 0x80, 0x72 } };
  25. const GUID CRocket::thisGuid = { 0x29743811, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  26. //==============================================================
  27. //
  28. // CSpaceFolder implementation
  29. //
  30. //
  31. CSpaceFolder::CSpaceFolder()
  32. {
  33. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  34. children[n] = new CSpaceStation();
  35. }
  36. }
  37. CSpaceFolder::~CSpaceFolder()
  38. {
  39. for (int n = 0; n < NUMBER_OF_CHILDREN; n++)
  40. if (children[n]) {
  41. delete children[n];
  42. }
  43. }
  44. HRESULT CSpaceFolder::OnExpand(IConsoleNameSpace *pConsoleNameSpace, IConsole *pConsole, HSCOPEITEM parent)
  45. {
  46. SCOPEDATAITEM sdi;
  47. if (!bExpanded) {
  48. // create the child nodes, then expand them
  49. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  50. ZeroMemory(&sdi, sizeof(SCOPEDATAITEM) );
  51. sdi.mask = SDI_STR | // Displayname is valid
  52. SDI_PARAM | // lParam is valid
  53. SDI_IMAGE | // nImage is valid
  54. SDI_OPENIMAGE | // nOpenImage is valid
  55. SDI_PARENT |
  56. SDI_CHILDREN;
  57. sdi.relativeID = (HSCOPEITEM)parent;
  58. sdi.nImage = children[n]->GetBitmapIndex();
  59. sdi.nOpenImage = INDEX_OPENFOLDER;
  60. sdi.displayname = MMC_CALLBACK;
  61. sdi.lParam = (LPARAM)children[n]; // The cookie
  62. sdi.cChildren = 0;
  63. HRESULT hr = pConsoleNameSpace->InsertItem( &sdi );
  64. _ASSERT( SUCCEEDED(hr) );
  65. children[n]->SetHandle((HANDLE)sdi.ID);
  66. }
  67. }
  68. return S_OK;
  69. }
  70. //==============================================================
  71. //
  72. // CSpaceStation implementation
  73. //
  74. //
  75. CSpaceStation::CSpaceStation()
  76. {
  77. for (int n = 0; n < MAX_CHILDREN; n++) {
  78. children[n] = NULL;
  79. }
  80. for (n = 0; n < NUMBER_OF_CHILDREN; n++) {
  81. children[n] = new CRocket(this, _T("Rocket"), n, 350115, 320, 52300);
  82. }
  83. }
  84. CSpaceStation::~CSpaceStation()
  85. {
  86. for (int n = 0; n < NUMBER_OF_CHILDREN; n++)
  87. if (children[n]) {
  88. delete children[n];
  89. }
  90. }
  91. HRESULT CSpaceStation::GetResultViewType(LPOLESTR *ppViewType, long *pViewOptions)
  92. {
  93. *pViewOptions = MMC_VIEW_OPTIONS_MULTISELECT;
  94. return S_FALSE;
  95. }
  96. HRESULT CSpaceStation::OnShow(IConsole *pConsole, BOOL bShow, HSCOPEITEM scopeitem)
  97. {
  98. HRESULT hr = S_OK;
  99. IHeaderCtrl *pHeaderCtrl = NULL;
  100. IResultData *pResultData = NULL;
  101. if (bShow) {
  102. hr = pConsole->QueryInterface(IID_IHeaderCtrl, (void **)&pHeaderCtrl);
  103. _ASSERT( SUCCEEDED(hr) );
  104. hr = pConsole->QueryInterface(IID_IResultData, (void **)&pResultData);
  105. _ASSERT( SUCCEEDED(hr) );
  106. // Set the column headers in the results pane
  107. hr = pHeaderCtrl->InsertColumn( 0, L"Rocket Class", 0, MMCLV_AUTO );
  108. _ASSERT( S_OK == hr );
  109. hr = pHeaderCtrl->InsertColumn( 1, L"Rocket Weight", 0, MMCLV_AUTO );
  110. _ASSERT( S_OK == hr );
  111. hr = pHeaderCtrl->InsertColumn( 2, L"Rocket Height", 0, MMCLV_AUTO );
  112. _ASSERT( S_OK == hr );
  113. hr = pHeaderCtrl->InsertColumn( 3, L"Rocket Payload", 0, MMCLV_AUTO );
  114. _ASSERT( S_OK == hr );
  115. hr = pHeaderCtrl->InsertColumn( 4, L"Status", 0, MMCLV_AUTO );
  116. _ASSERT( S_OK == hr );
  117. // insert items here
  118. RESULTDATAITEM rdi;
  119. hr = pResultData->DeleteAllRsltItems();
  120. _ASSERT( SUCCEEDED(hr) );
  121. if (!bExpanded) {
  122. // create the child nodes, then expand them
  123. for (int n = 0; NULL != children[n]; n++) {
  124. BOOL childDeleteStatus = children[n]->getDeletedStatus();
  125. if ( !childDeleteStatus) {
  126. ZeroMemory(&rdi, sizeof(RESULTDATAITEM) );
  127. rdi.mask = RDI_STR | // Displayname is valid
  128. RDI_IMAGE |
  129. RDI_PARAM; // nImage is valid
  130. rdi.nImage = children[n]->GetBitmapIndex();
  131. rdi.str = MMC_CALLBACK;
  132. rdi.nCol = 0;
  133. rdi.lParam = (LPARAM)children[n];
  134. hr = pResultData->InsertItem( &rdi );
  135. _ASSERT( SUCCEEDED(hr) );
  136. children[n]->SetHandle((HANDLE)rdi.itemID);
  137. }
  138. }
  139. }
  140. pHeaderCtrl->Release();
  141. pResultData->Release();
  142. }
  143. return hr;
  144. }
  145. HRESULT CSpaceStation::OnSelect(IConsole *pConsole, BOOL bScope, BOOL bSelect)
  146. {
  147. IConsoleVerb *pConsoleVerb;
  148. HRESULT hr = pConsole->QueryConsoleVerb(&pConsoleVerb);
  149. _ASSERT(SUCCEEDED(hr));
  150. hr = pConsoleVerb->SetVerbState(MMC_VERB_PASTE, ENABLED, TRUE);
  151. pConsoleVerb->Release();
  152. return S_OK;
  153. }
  154. HRESULT CSpaceStation::OnUpdateItem(IConsole *pConsole, long item, ITEM_TYPE itemtype)
  155. {
  156. HRESULT hr = S_OK;
  157. _ASSERT(item);
  158. _ASSERT(SCOPE == itemtype);
  159. //refresh all result pane views
  160. hr = pConsole->SelectScopeItem( (HSCOPEITEM)item );
  161. _ASSERT( S_OK == hr);
  162. return hr;
  163. }
  164. //==============================================================
  165. //
  166. // CRocket implementation
  167. //
  168. //
  169. CRocket::CRocket(CSpaceStation *pSpaceStation, _TCHAR *szName, int id, LONG lWeight, LONG lHeight, LONG lPayload)
  170. : m_pSpaceStation(pSpaceStation), szName(NULL), lWeight(0), lHeight(0), lPayload(0), iStatus(STOPPED)
  171. {
  172. if (szName) {
  173. this->szName = new _TCHAR[(_tcslen(szName) + 1) * sizeof(_TCHAR)];
  174. _tcscpy(this->szName, szName);
  175. }
  176. this->nId = id;
  177. this->lWeight = lWeight;
  178. this->lHeight = lHeight;
  179. this->lPayload = lPayload;
  180. isDeleted = FALSE;
  181. }
  182. CRocket::~CRocket()
  183. {
  184. if (szName)
  185. delete [] szName;
  186. }
  187. const _TCHAR *CRocket::GetDisplayName(int nCol)
  188. {
  189. static _TCHAR buf[128];
  190. switch (nCol) {
  191. case 0:
  192. _stprintf(buf, _T("%s (#%d)"), szName ? szName : _T(""), nId);
  193. break;
  194. case 1:
  195. _stprintf(buf, _T("%ld metric tons"), lWeight);
  196. break;
  197. case 2:
  198. _stprintf(buf, _T("%ld meters"), lHeight);
  199. break;
  200. case 3:
  201. _stprintf(buf, _T("%ld kilos"), lPayload);
  202. break;
  203. case 4:
  204. _stprintf(buf, _T("%s"),
  205. iStatus == RUNNING ? _T("running") :
  206. iStatus == PAUSED ? _T("paused") :
  207. iStatus == STOPPED ? _T("stopped") : _T("unknown"));
  208. break;
  209. }
  210. return buf;
  211. }
  212. HRESULT CRocket::OnSelect(IConsole *pConsole, BOOL bScope, BOOL bSelect)
  213. {
  214. IConsoleVerb *pConsoleVerb;
  215. HRESULT hr = pConsole->QueryConsoleVerb(&pConsoleVerb);
  216. _ASSERT(SUCCEEDED(hr));
  217. //MMC automatically disables rename verb during a multiselection
  218. hr = pConsoleVerb->SetVerbState(MMC_VERB_RENAME, ENABLED, TRUE);
  219. hr = pConsoleVerb->SetVerbState(MMC_VERB_DELETE, ENABLED, TRUE);
  220. pConsoleVerb->Release();
  221. return S_OK;
  222. }
  223. HRESULT CRocket::OnRefresh(IConsole *pConsole)
  224. {
  225. //Call IConsole::UpdateAllViews to redraw all views
  226. //owned by the parent scope item
  227. IDataObject *pDummy = NULL;
  228. HANDLE handle = m_pSpaceStation->GetHandle();
  229. HRESULT hr;
  230. hr = pConsole->UpdateAllViews(pDummy, (long)handle, UPDATE_SCOPEITEM);
  231. _ASSERT( S_OK == hr);
  232. return hr;
  233. }
  234. HRESULT CRocket::OnDelete(IConsole *pConsole)
  235. {
  236. _ASSERT( NULL != this );
  237. HRESULT hr = S_OK;
  238. //Delete the item. The IConsole that is passed into DeleteChild
  239. //is from the child result item, so we can use it to QI for IResultData
  240. IResultData *pResultData = NULL;
  241. hr = pConsole->QueryInterface(IID_IResultData, (void **)&pResultData);
  242. _ASSERT( SUCCEEDED(hr) );
  243. HRESULTITEM childresultitem;
  244. _ASSERT( NULL != &childresultitem );
  245. //lparam == this. See CSpaceVehicle::OnShow
  246. hr = pResultData->FindItemByLParam( (LPARAM)this, &childresultitem );
  247. if ( FAILED(hr) )
  248. {
  249. // Failed : Reason may be that current view does not have this item.
  250. // So exit gracefully.
  251. hr = S_FALSE;
  252. } else
  253. {
  254. hr = pResultData->DeleteItem( childresultitem, 0 );
  255. _ASSERT( SUCCEEDED(hr) );
  256. }
  257. pResultData->Release();
  258. //Now set child's isDeleted member to true so that the parent doesn't try to
  259. //to insert it again in CSpaceVehicle::OnShow. Admittedly, a hack...
  260. isDeleted = TRUE;
  261. return hr;
  262. }
  263. HRESULT CRocket::OnRename(LPOLESTR pszNewName)
  264. {
  265. HRESULT hr = S_FALSE;
  266. if (szName) {
  267. delete [] szName;
  268. szName = NULL;
  269. }
  270. MAKE_TSTRPTR_FROMWIDE(ptrname, pszNewName);
  271. szName = new _TCHAR[(_tcslen(ptrname) + 1) * sizeof(_TCHAR)];
  272. _tcscpy(szName, ptrname);
  273. return hr;
  274. }
  275. HRESULT CRocket::OnUpdateItem(IConsole *pConsole, long item, ITEM_TYPE itemtype)
  276. {
  277. HRESULT hr = S_FALSE;
  278. _ASSERT(NULL != this || isDeleted || RESULT == itemtype);
  279. //redraw the item
  280. IResultData *pResultData = NULL;
  281. hr = pConsole->QueryInterface(IID_IResultData, (void **)&pResultData);
  282. _ASSERT( SUCCEEDED(hr) );
  283. HRESULTITEM myhresultitem;
  284. _ASSERT(NULL != &myhresultitem);
  285. //lparam == this. See CSpaceStation::OnShow
  286. hr = pResultData->FindItemByLParam( (LPARAM)this, &myhresultitem );
  287. if ( FAILED(hr) ) {
  288. //there is no HRESULTITEM for the item, because
  289. //the item is not inserted in the current view. Exit gracefully
  290. hr = S_FALSE;
  291. } else
  292. {
  293. hr = pResultData->UpdateItem( myhresultitem );
  294. _ASSERT( SUCCEEDED(hr) );
  295. }
  296. pResultData->Release();
  297. return hr;
  298. }