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.

372 lines
14 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 1999
  5. *
  6. * File: task.h
  7. *
  8. * Contents: Interface file for CConsoleTask
  9. *
  10. * History: 05-Oct-98 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #ifndef TASK_H
  14. #define TASK_H
  15. #pragma once
  16. #include "bookmark.h"
  17. #include "refcount.h"
  18. #include "tstring.h"
  19. #include "menuitem.h"
  20. #include "xmlicon.h" // for CXMLIcon
  21. // forward declarations
  22. class CConsoleTaskpad;
  23. class CBookmarkEx;
  24. class CStr;
  25. typedef CConsoleTaskpad * PCONSOLETASKPAD;
  26. #include <pshpack8.h> // for Win64
  27. /*+-------------------------------------------------------------------------*
  28. * CConsoleTask
  29. *
  30. *
  31. *--------------------------------------------------------------------------*/
  32. enum eConsoleTaskType
  33. {
  34. eTask_None, // invalid task type
  35. eTask_Scope, // task for a scope item
  36. eTask_Result, // task for a result item
  37. eTask_CommandLine, // task for a command line
  38. eTask_Target, // task for menu item on the target node.
  39. eTask_Favorite // task for a favorite
  40. };
  41. enum eWindowState
  42. {
  43. eState_Restored,
  44. eState_Minimized,
  45. eState_Maximized,
  46. };
  47. /*+-------------------------------------------------------------------------*
  48. * CConsoleTask
  49. *
  50. *
  51. *--------------------------------------------------------------------------*/
  52. class CConsoleTask : public CSerialObject, public CXMLObject
  53. {
  54. enum
  55. {
  56. eFlag_Disabled = 0x00000001,
  57. };
  58. bool operator==(const CConsoleTask & consoleTask) const; // private and unimplemented
  59. public:
  60. CConsoleTask ();
  61. CConsoleTask(const CConsoleTask &rhs);
  62. ~CConsoleTask ();
  63. static CConsoleTask * GetConsoleTask(DWORD dwUniqueID); // returns the console task that has the specified unique ID.
  64. SC ScGetHTML(LPCTSTR szFmtHTML, CStr &strTaskHTML, bool bUseLargeIcons, bool bUseTextDescriptions) const; // get the HTML representation of the task.
  65. // need an explicit copy ctor & assignment operator.
  66. CConsoleTask& operator= (const CConsoleTask& rhs);
  67. bool IsEnabled () const {return ((m_dwFlags & eFlag_Disabled) == 0);}
  68. void SetDirty (bool fDirty = true) {m_fDirty = fDirty;}
  69. bool IsDirty () const;
  70. bool HasCustomIcon() const;
  71. tstring GetName () const {return (m_strName.str()); }
  72. tstring GetDescription () const {return (m_strDescription.str()); }
  73. tstring GetCommand () const {return (m_strCommand); }
  74. tstring GetParameters () const {return (m_strParameters); }
  75. tstring GetDirectory () const {return (m_strDirectory); }
  76. CMemento * GetMemento() {return &m_memento;}
  77. void Draw (HDC hdc, RECT *lpRect, bool bSmall = false) const ; // Draw into a DC.
  78. DWORD GetSymbol() const {return m_dwSymbol;}
  79. const CSmartIcon & GetSmallCustomIcon() const {return m_smartIconCustomSmall;}
  80. const CSmartIcon & GetLargeCustomIcon() const {return m_smartIconCustomLarge;}
  81. DWORD GetUniqueID() const {return m_dwUniqueID;}// returns an ID unique to the task for the current process. Is not persistent.
  82. void Enable (bool fEnable);
  83. void SetName (const tstring& strName);
  84. void SetDescription (const tstring& strDescription);
  85. void SetCommand (const tstring& strCommand);
  86. void SetParameters (const tstring& strParameters);
  87. void SetDirectory (const tstring &strDirectory);
  88. void SetMemento (const CMemento &memento);
  89. void SetSymbol (DWORD dwSymbol);
  90. void SetCustomIcon (CSmartIcon& iconSmall, CSmartIcon& iconLarge);
  91. void ResetUI(); // signal to look for the target node again
  92. void SetTaskType(eConsoleTaskType consoleTaskType)
  93. {m_eConsoleTaskType = consoleTaskType;}
  94. void SetWindowState (eWindowState eState);
  95. eConsoleTaskType GetTaskType() const {return m_eConsoleTaskType;}
  96. eWindowState GetWindowState() const {return m_eWindowState;}
  97. CConsoleTaskpad* GetOwner () const { return (m_pctpOwner); }
  98. void SetOwner (CConsoleTaskpad* pctpOwner);
  99. bool operator==(const CMenuItem & menuItem) const;
  100. // target node methods (scope tasks only)
  101. bool RetargetScopeNode(CNode *pNewNode);
  102. CMTNode * GetScopeNode(IScopeTree *pScopeTree) const;
  103. std::auto_ptr<CNode> GetScopeNode(CViewData *pViewData) const;
  104. private:
  105. /*
  106. * these are persisted
  107. */
  108. eConsoleTaskType m_eConsoleTaskType;
  109. CStringTableString m_strName;
  110. CStringTableString m_strDescription;
  111. DWORD m_dwSymbol; // the index of the built-in icon
  112. CXMLIcon m_smartIconCustomLarge; // the large custom icon, if one exists
  113. CXMLIcon m_smartIconCustomSmall; // the small custom icon, if one exists
  114. tstring m_strCommand; // contains: either the menu item, or the command line.
  115. tstring m_strParameters; // the list of arguments for command line tasks.
  116. tstring m_strDirectory; // the default directory for command line tasks.
  117. eWindowState m_eWindowState; // min, max, restored
  118. DWORD m_dwFlags;
  119. mutable CBookmarkEx m_bmScopeNode; // for scope tasks only.
  120. CMemento m_memento; // for favorite tasks only.
  121. /*
  122. * these are not persisted
  123. */
  124. bool m_fDirty;
  125. CConsoleTaskpad* m_pctpOwner;
  126. const DWORD m_dwUniqueID;
  127. // CXMLObject methods
  128. public:
  129. DEFINE_XML_TYPE(XML_TAG_TASK);
  130. virtual void Persist(CPersistor &persistor);
  131. protected:
  132. // CSerialObject methods
  133. virtual UINT GetVersion() {return 1;}
  134. virtual HRESULT ReadSerialObject (IStream &stm, UINT nVersion /*,LARGE_INTEGER nBytes*/);
  135. };
  136. /*+-------------------------------------------------------------------------*
  137. * CTaskCollection
  138. *
  139. *
  140. * PURPOSE: A list of console tasks. Used by CConsoleTaskpad.
  141. *
  142. *+-------------------------------------------------------------------------*/
  143. typedef std::list<CConsoleTask> TaskCollection;
  144. class CTaskCollection : public XMLListCollectionImp<TaskCollection>
  145. {
  146. DEFINE_XML_TYPE(XML_TAG_TASK_LIST);
  147. };
  148. /*+-------------------------------------------------------------------------*
  149. * CConsoleTaskpad
  150. *
  151. *
  152. *--------------------------------------------------------------------------*/
  153. const DWORD TVO_HORIZONTAL = 0x0001;
  154. const DWORD TVO_VERTICAL = 0x0002;
  155. const DWORD TVO_NO_RESULTS = 0x0004;
  156. const DWORD TVO_DESCRIPTIONS_AS_TEXT = 0x0008;
  157. /*
  158. * small list == large task area
  159. */
  160. enum ListSize
  161. {
  162. eSize_None = -1,
  163. eSize_Small = 1,
  164. eSize_Medium,
  165. eSize_Large,
  166. eSize_Default= eSize_Medium
  167. };
  168. class CConsoleTaskpad : public CSerialObject, public CXMLObject
  169. {
  170. public:
  171. CConsoleTaskpad (CNode* pTargetNode = NULL);
  172. /*
  173. * member-wise construction and assignment are sufficient
  174. */
  175. // CConsoleTaskpad (const CConsoleTaskpad& other);
  176. // CConsoleTaskpad& operator= (const CConsoleTaskpad& other);
  177. void SetDirty (bool fDirty = true) { m_fDirty = fDirty; }
  178. bool IsDirty () const;
  179. bool HasTarget() const { return true;}
  180. const GUID& GetNodeType () const { return (m_guidNodeType); }
  181. const GUID& GetID() const { return (m_guidID);}
  182. bool MatchesNodeType(const GUID& guid) const {return (guid == m_guidNodeType);}
  183. bool MatchesID (const GUID& guid) const {return (guid == m_guidID);}
  184. bool Retarget (CNode* pNewNode);
  185. bool Retarget (CMTNode* pMTNewNode, bool fReset=false);
  186. CMTNode* GetTargetMTNode (IScopeTree* pScopeTree);
  187. tstring GetName () const { return (m_strName.str()); }
  188. tstring GetDescription () const { return (m_strDescription.str()); }
  189. tstring GetToolTip () const { return (m_strTooltip.str()); }
  190. ListSize GetListSize() const { return m_listSize;}
  191. bool IsNodeSpecific() const { return m_bNodeSpecific;}
  192. bool FReplacesDefaultView() const { return m_bReplacesDefaultView;}
  193. DWORD GetOrientation() const { return m_dwOrientation;}
  194. bool IsValid(CNode *pNode) const; // is this taskpad appropriate for this node?
  195. CMTNode* GetRetargetRootNode() const;
  196. void SetName (const tstring& strName);
  197. void SetDescription (const tstring& strDescription);
  198. void SetToolTip (const tstring& strTooltip);
  199. void SetListSize (const ListSize listSize);
  200. void SetNodeSpecific (bool bNodeSpecific);
  201. void SetReplacesDefaultView(bool bReplacesDefaultView);
  202. void SetOrientation (DWORD dwOrientation) {m_dwOrientation = dwOrientation;}
  203. void ResetUI();
  204. CConsoleTaskpad * PConsoleTaskpad() {return this;} // an easy way to get to the object pointer thru an iterator.
  205. SC ScGetHTML(CStr &strTaskpadHTML) const; // get the HTML representation of the taskpad.
  206. /*
  207. * task list access
  208. */
  209. typedef CTaskCollection::iterator TaskIter;
  210. typedef CTaskCollection::const_iterator TaskConstIter;
  211. TaskIter BeginTask() const { return (m_Tasks.begin()); }
  212. TaskIter EndTask() const { return (m_Tasks.end()); }
  213. UINT TaskCount() const { return (static_cast<UINT>(m_Tasks.size())); }
  214. TaskIter AddTask (const CConsoleTask& task);
  215. TaskIter InsertTask (TaskIter itTaskBeforeWhichToInsert, const CConsoleTask& task);
  216. TaskIter EraseTask (TaskIter itErase);
  217. TaskIter EraseTasks (TaskIter itFirst, TaskIter itLast);
  218. void ClearTasks ();
  219. // CXMLObject methods
  220. public:
  221. DEFINE_XML_TYPE(XML_TAG_CONSOLE_TASKPAD);
  222. virtual void Persist(CPersistor &persistor);
  223. private:
  224. CBookmarkEx & GetTargetBookmark() {return m_bmTargetNode;}
  225. void ResetTargetNodePointer() {m_pMTNodeTarget = NULL;}
  226. void SetStringMember(CStringTableString& strMember, const tstring& strNewValue);
  227. private:
  228. /*
  229. * these are persisted
  230. */
  231. CStringTableString m_strName;
  232. CStringTableString m_strDescription;
  233. CStringTableString m_strTooltip;
  234. ListSize m_listSize; // the area of the the result pane occupied by the embedded view
  235. bool m_bNodeSpecific; // is this taskpad specific to this node, or can it be used for all nodes of this type?
  236. DWORD m_dwOrientation;
  237. GUID m_guidNodeType;
  238. GUID m_guidID; // the unique identifier of the taskpad.
  239. mutable CBookmarkEx m_bmTargetNode;
  240. CTaskCollection m_Tasks;
  241. bool m_bReplacesDefaultView; // does this taskpad replace the default view?
  242. /*
  243. * these are not persisted
  244. */
  245. bool m_fDirty;
  246. CMTNode * m_pMTNodeTarget;
  247. protected:
  248. // CSerialObject methods
  249. virtual UINT GetVersion() {return 1;}
  250. virtual HRESULT ReadSerialObject (IStream &stm, UINT nVersion);
  251. };
  252. /*+-------------------------------------------------------------------------*
  253. * CConsoleTaskpadFilteredList
  254. *
  255. *
  256. * PURPOSE: Provides a list of taskpads appropriate to a given node.
  257. *
  258. *+-------------------------------------------------------------------------*/
  259. class CConsoleTaskpadFilteredList : public std::list<PCONSOLETASKPAD>
  260. {
  261. iterator m_CurrentSelection; // the currently selected taskpad
  262. };
  263. /*+-------------------------------------------------------------------------*
  264. * CConsoleTaskpadList
  265. *
  266. *
  267. * PURPOSE: There should be only one object of this kind. This object contains
  268. * a flat list of taskpads available. These are not sorted in any
  269. * particular order.
  270. *
  271. *+-------------------------------------------------------------------------*/
  272. typedef std::list<CConsoleTaskpad> CTaskpadList_base;
  273. class CConsoleTaskpadList : public CSerialObject, public XMLListCollectionImp<CTaskpadList_base>
  274. {
  275. typedef std::list<CConsoleTaskpad> BC;
  276. public: // find a taskpad for this node, else return NULL
  277. SC ScGetTaskpadList(CNode *pNode, CConsoleTaskpadFilteredList &filteredList);
  278. // CSerialObject methods
  279. virtual UINT GetVersion() {return 1;}
  280. virtual HRESULT ReadSerialObject (IStream &stm, UINT nVersion);
  281. // CXMLObject methods
  282. public:
  283. DEFINE_XML_TYPE(XML_TAG_CONSOLE_TASKPADS);
  284. };
  285. /*+-------------------------------------------------------------------------*
  286. * CDefaultTaskpadList
  287. *
  288. *
  289. * PURPOSE: stores a map from nodetypes to console taskpad IDs
  290. * This maps a nodetype to the default taskpad for that nodetype.
  291. *
  292. *+-------------------------------------------------------------------------*/
  293. class CDefaultTaskpadList : public std::map<GUID, GUID>, // 1st = nodetype, 2nd = taskpad ID
  294. public CSerialObject
  295. {
  296. public:
  297. // CSerialObject methods
  298. virtual UINT GetVersion() {return 1;}
  299. virtual HRESULT ReadSerialObject (IStream &stm, UINT nVersion);
  300. };
  301. #include <poppack.h>
  302. #endif // TASK_H