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.

322 lines
8.5 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 1999
  5. *
  6. * File: tasknode.cpp
  7. *
  8. * Contents: Implementation file for console taskpad CMTNode- and
  9. * CNode-derived classes.
  10. *
  11. * History: 29-Oct-98 jeffro Created
  12. *
  13. *--------------------------------------------------------------------------*/
  14. #include "stdafx.h"
  15. #include "tasks.h"
  16. #include "util.h"
  17. #include "conview.h"
  18. #include "rsltitem.h"
  19. //############################################################################
  20. //############################################################################
  21. //
  22. // Implementation of class CConsoleTaskCallbackImpl
  23. //
  24. //############################################################################
  25. //############################################################################
  26. /*+-------------------------------------------------------------------------*
  27. * CConsoleTaskCallbackImpl::CConsoleTaskCallbackImpl
  28. *
  29. * PURPOSE:
  30. *
  31. * PARAMETERS:
  32. *
  33. * RETURNS:
  34. *
  35. /*+-------------------------------------------------------------------------*/
  36. CConsoleTaskCallbackImpl::CConsoleTaskCallbackImpl() :
  37. m_clsid (GUID_NULL),
  38. m_fTaskpad (false),
  39. m_fInitialized (false),
  40. m_pViewData (NULL)
  41. {
  42. }
  43. /*+-------------------------------------------------------------------------*
  44. *
  45. * CConsoleTaskCallbackImpl::ScInitialize
  46. *
  47. * PURPOSE: This is the initialization function called for taskpad
  48. * view extensions.
  49. *
  50. * PARAMETERS:
  51. * CConsoleTaskpad * pConsoleTaskpad :
  52. * CScopeTree * pScopeTree :
  53. * CNode * pNodeTarget :
  54. *
  55. * RETURNS:
  56. * void
  57. *
  58. *+-------------------------------------------------------------------------*/
  59. SC
  60. CConsoleTaskCallbackImpl::ScInitialize(
  61. CConsoleTaskpad* pConsoleTaskpad,
  62. CScopeTree* pScopeTree,
  63. CNode* pNodeTarget)
  64. {
  65. DECLARE_SC (sc, _T("CConsoleTaskCallbackImpl::ScInitialize"));
  66. /*
  67. * validate input
  68. */
  69. sc = ScCheckPointers (pConsoleTaskpad, pScopeTree, pNodeTarget);
  70. if (sc)
  71. return (sc);
  72. sc = ScCheckPointers (pNodeTarget->GetViewData(), E_UNEXPECTED);
  73. if (sc)
  74. return (sc);
  75. m_pConsoleTaskpad = pConsoleTaskpad;
  76. m_pScopeTree = pScopeTree;
  77. m_pNodeTarget = pNodeTarget;
  78. m_pViewData = pNodeTarget->GetViewData();
  79. m_fInitialized = true;
  80. m_fTaskpad = true;
  81. return (sc);
  82. }
  83. /*+-------------------------------------------------------------------------*
  84. * CConsoleTaskCallbackImpl::ScInitialize
  85. *
  86. * This is the initialization function called for ordinary view extensions.
  87. *--------------------------------------------------------------------------*/
  88. SC CConsoleTaskCallbackImpl::ScInitialize (const CLSID& clsid)
  89. {
  90. DECLARE_SC (sc, _T("CConsoleTaskCallbackImpl::ScInitialize"));
  91. m_clsid = clsid;
  92. return (sc);
  93. }
  94. /*+-------------------------------------------------------------------------*
  95. * CConsoleTaskCallbackImpl::IsEditable
  96. *
  97. * Returns S_OK if "Edit" and "Delete" menu items should be displayed
  98. * on the context menu for the node while this view extension is active.
  99. *
  100. * Returns S_FALSE if "Edit" and "Delete" should not be displayed.
  101. *--------------------------------------------------------------------------*/
  102. STDMETHODIMP CConsoleTaskCallbackImpl::IsEditable()
  103. {
  104. if (IsTaskpad())
  105. return (S_OK);
  106. return (S_FALSE);
  107. }
  108. /*+-------------------------------------------------------------------------*
  109. * CConsoleTaskCallbackImpl::OnModifyTaskpad
  110. *
  111. * PURPOSE:
  112. *
  113. * PARAMETERS: +-
  114. *
  115. * RETURNS:
  116. * HRESULT
  117. /*+-------------------------------------------------------------------------*/
  118. STDMETHODIMP
  119. CConsoleTaskCallbackImpl::OnModifyTaskpad()
  120. {
  121. DECLARE_SC (sc, _T("CConsoleTaskCallbackImpl::OnModifyTaskpad"));
  122. /*
  123. * this should only be called for taskpad view extensions
  124. */
  125. if (!IsTaskpad())
  126. return ((sc = E_UNEXPECTED).ToHr());
  127. CNode *pNodeTarget = GetConsoleTaskpad()->HasTarget() ? GetTargetNode() : NULL;
  128. bool fCookieValid = false;
  129. // determine whether the taskpad node is selected. If not, fCookieValid = false.
  130. LPARAM lResultItemCookie = -1;
  131. bool bScope;
  132. CNode* pNode = NULL;
  133. CConsoleView* pConsoleView = GetViewData()->GetConsoleView();
  134. if (pConsoleView != NULL)
  135. {
  136. HNODE hNode;
  137. sc = pConsoleView->ScGetFocusedItem (hNode, lResultItemCookie, bScope);
  138. if (sc)
  139. return (sc.ToHr());
  140. pNode = CNode::FromHandle (hNode);
  141. }
  142. if (pNode == NULL)
  143. fCookieValid = false;
  144. int iResp = CTaskpadPropertySheet(pNodeTarget, *GetConsoleTaskpad(), FALSE, NULL, fCookieValid,
  145. GetViewData(), CTaskpadPropertySheet::eReason_PROPERTIES).DoModal();
  146. if(iResp == IDOK)
  147. {
  148. GetViewData()->m_spTaskCallback = NULL;
  149. GetScopeTree()->UpdateAllViews(VIEW_RESELECT, 0);
  150. }
  151. return (sc.ToHr());
  152. }
  153. /*+-------------------------------------------------------------------------*
  154. *
  155. * CConsoleTaskCallbackImpl::GetTaskpadID
  156. *
  157. * PURPOSE: Returns the GUID ID of the underlying taskpad.
  158. *
  159. * PARAMETERS:
  160. * GUID * pGuid :
  161. *
  162. * RETURNS:
  163. * STDMETHODIMP
  164. *
  165. *+-------------------------------------------------------------------------*/
  166. STDMETHODIMP
  167. CConsoleTaskCallbackImpl::GetTaskpadID(GUID *pGuid)
  168. {
  169. DECLARE_SC (sc, _T("CConsoleTaskCallbackImpl::GetTaskpadID"));
  170. sc = ScCheckPointers (pGuid);
  171. if (sc)
  172. return (sc.ToHr());
  173. if (IsTaskpad())
  174. {
  175. /*
  176. * TODO: initialize m_clsid in ScInitialize for taskpads
  177. */
  178. CConsoleTaskpad* pTaskpad = GetConsoleTaskpad();
  179. sc = ScCheckPointers (pTaskpad, E_UNEXPECTED);
  180. if (sc)
  181. return (sc.ToHr());
  182. *pGuid = pTaskpad->GetID();
  183. }
  184. else
  185. {
  186. *pGuid = m_clsid;
  187. }
  188. return (sc.ToHr());
  189. }
  190. /*+-------------------------------------------------------------------------*
  191. *
  192. * CConsoleTaskCallbackImpl::OnDeleteTaskpad
  193. *
  194. * PURPOSE: Deletes a taskpad.
  195. *
  196. * RETURNS:
  197. * STDMETHODIMP
  198. *
  199. *+-------------------------------------------------------------------------*/
  200. STDMETHODIMP
  201. CConsoleTaskCallbackImpl::OnDeleteTaskpad()
  202. {
  203. DECLARE_SC (sc, _T("CConsoleTaskCallbackImpl::OnDeleteTaskpad"));
  204. /*
  205. * this should only be called for taskpad view extensions
  206. */
  207. if (!IsTaskpad())
  208. return ((sc = E_UNEXPECTED).ToHr());
  209. CScopeTree* pScopeTree = GetScopeTree();
  210. sc = ScCheckPointers (pScopeTree, E_UNEXPECTED);
  211. if (sc)
  212. return (sc.ToHr());
  213. CConsoleTaskpadList* pTaskpadList = pScopeTree->GetConsoleTaskpadList();
  214. sc = ScCheckPointers (pTaskpadList, E_UNEXPECTED);
  215. if (sc)
  216. return (sc.ToHr());
  217. CConsoleTaskpad* pTaskpad = GetConsoleTaskpad();
  218. sc = ScCheckPointers (pTaskpad, E_UNEXPECTED);
  219. if (sc)
  220. return (sc.ToHr());
  221. CConsoleTaskpadList::iterator iter;
  222. for(iter = pTaskpadList->begin(); iter != pTaskpadList->end(); iter++)
  223. {
  224. if(iter->MatchesID(pTaskpad->GetID()))
  225. {
  226. pTaskpadList->erase(iter);
  227. pScopeTree->UpdateAllViews(VIEW_RESELECT, 0);
  228. return (sc.ToHr());
  229. }
  230. }
  231. return ((sc = E_UNEXPECTED).ToHr()); // not found.
  232. }
  233. /*+-------------------------------------------------------------------------*
  234. *
  235. * CConsoleTaskCallbackImpl::OnNewTask
  236. *
  237. * PURPOSE:
  238. *
  239. * RETURNS:
  240. * HRESULT : S_OK if tasks were added, S_FALSE if no tasks were added.
  241. *
  242. *+-------------------------------------------------------------------------*/
  243. HRESULT
  244. CConsoleTaskCallbackImpl::OnNewTask()
  245. {
  246. HRESULT hr = S_OK;
  247. CNode *pNodeTarget = GetConsoleTaskpad()->HasTarget() ? GetTargetNode() : NULL;
  248. // fake up a taskpad frame.
  249. CTaskpadFrame taskpadFrame(pNodeTarget, GetConsoleTaskpad(), GetViewData(), false, 0);
  250. CTaskWizard taskWizard;
  251. bool fRestartTaskpad = true;
  252. bool bAddedTasks = false;
  253. while(fRestartTaskpad)
  254. {
  255. if (taskWizard.Show(GetViewData()->GetMainFrame(), &taskpadFrame,
  256. true, &fRestartTaskpad)==S_OK)
  257. {
  258. bAddedTasks = true;
  259. CConsoleTaskpad::TaskIter itTask;
  260. CConsoleTaskpad * pTaskpad = GetConsoleTaskpad();
  261. itTask = pTaskpad->BeginTask();
  262. pTaskpad->InsertTask (itTask, taskWizard.ConsoleTask());
  263. }
  264. else
  265. break;
  266. }
  267. return bAddedTasks? S_OK : S_FALSE;
  268. }