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.

210 lines
5.0 KiB

  1. // menucmd.h - context menu commands header file
  2. #ifndef _MENUCMD_H_
  3. #define _MENUCMD_H_
  4. #include <atlgdi.h>
  5. #include "util.h"
  6. class CQueryNode;
  7. class CQueryItem;
  8. class CRowItem;
  9. // These parameter IDs must not change because they are persisted
  10. // in the shell command line strings
  11. enum MENU_PARAM_ID
  12. {
  13. MENU_PARAM_SCOPE = 1,
  14. MENU_PARAM_FILTER,
  15. MENU_PARAM_NAME,
  16. MENU_PARAM_TYPE,
  17. MENU_PARAM_LAST = MENU_PARAM_TYPE
  18. };
  19. struct MENU_PARAM_ENTRY
  20. {
  21. MENU_PARAM_ID ID; // Param identifier
  22. UINT rsrcID; // resource string ID
  23. };
  24. #define MENU_PARAM_TABLE_LEN 5
  25. extern const MENU_PARAM_ENTRY MenuParamTable[MENU_PARAM_TABLE_LEN];
  26. //------------------------------------------------------------------
  27. // class CMenuCmd
  28. //------------------------------------------------------------------
  29. enum MENUTYPE
  30. {
  31. MENUTYPE_SHELL = 0,
  32. MENUTYPE_ACTDIR
  33. };
  34. enum MENU_FLAGS
  35. {
  36. MENUFLG_REFRESH = 0x00001
  37. };
  38. typedef MMC_STRING_ID MenuID;
  39. class CMenuCmd
  40. {
  41. friend class CAddMenuDlg;
  42. friend class CAddQNMenuDlg;
  43. friend class CMenuCmdPtr;
  44. public:
  45. CMenuCmd(LPCWSTR pszMenuName = NULL)
  46. {
  47. m_menuID = 0;
  48. m_dwFlags = 0;
  49. HRESULT hr = CoCreateGuid( &m_guidNoLocMenu );
  50. ASSERT(SUCCEEDED(hr));
  51. if (pszMenuName != NULL)
  52. m_strName = pszMenuName;
  53. }
  54. virtual ~CMenuCmd() {};
  55. virtual CMenuCmd* Clone() = 0;
  56. virtual MENUTYPE MenuType() const = 0;
  57. virtual HRESULT Save(IStream& stm) = 0;
  58. virtual HRESULT Load(IStream& stm) = 0;
  59. LPCWSTR Name() { return m_strName.c_str(); }
  60. MenuID ID() { return m_menuID; }
  61. GUID NoLocID() { return m_guidNoLocMenu; }
  62. HRESULT LoadName(IStringTable* pStringTable)
  63. {
  64. if (!m_strName.empty())
  65. return S_OK;
  66. return StringTableRead(pStringTable, m_menuID, m_strName);
  67. }
  68. HRESULT SetName(IStringTable* pStringTable, LPCWSTR pszName)
  69. {
  70. ASSERT(pszName && pszName[0]);
  71. HRESULT hr = StringTableWrite(pStringTable, pszName, &m_menuID);
  72. if (SUCCEEDED(hr))
  73. m_strName = pszName;
  74. return hr;
  75. }
  76. BOOL IsAutoRefresh() { return (m_dwFlags & MENUFLG_REFRESH); }
  77. void SetAutoRefresh(BOOL bState)
  78. { m_dwFlags = bState ? (m_dwFlags | MENUFLG_REFRESH) : (m_dwFlags & ~MENUFLG_REFRESH); }
  79. BOOL operator==(MenuID ID) { return (m_menuID == ID); }
  80. protected:
  81. tstring m_strName;
  82. MenuID m_menuID;
  83. GUID m_guidNoLocMenu;
  84. DWORD m_dwFlags;
  85. };
  86. class CShellMenuCmd : public CMenuCmd
  87. {
  88. friend class CAddMenuDlg;
  89. friend class CAddQNMenuDlg;
  90. public:
  91. // CMenuCmd
  92. CMenuCmd* Clone() { return new CShellMenuCmd(*this); }
  93. MENUTYPE MenuType() const { return MENUTYPE_SHELL; }
  94. LPCWSTR ProgramName() { return m_strProgPath.c_str(); }
  95. HRESULT Save(IStream& stm);
  96. HRESULT Load(IStream& stm);
  97. HRESULT Execute(CParamLookup* pLookup, PHANDLE phProcess);
  98. private:
  99. tstring m_strProgPath;
  100. tstring m_strCmdLine;
  101. tstring m_strStartDir;
  102. };
  103. class CActDirMenuCmd : public CMenuCmd
  104. {
  105. friend class CAddMenuDlg;
  106. public:
  107. CMenuCmd* Clone() { return new CActDirMenuCmd(*this); }
  108. MENUTYPE MenuType() const { return MENUTYPE_ACTDIR; }
  109. HRESULT Save(IStream& stm);
  110. HRESULT Load(IStream& stm);
  111. LPCWSTR ADName() { return m_strADName.c_str(); }
  112. LPCWSTR ADNoLocName() { return m_strADNoLocName.c_str(); }
  113. private:
  114. tstring m_strADName;
  115. tstring m_strADNoLocName;
  116. };
  117. class CMenuCmdPtr
  118. {
  119. public:
  120. CMenuCmdPtr(CMenuCmd* pMenuCmd = NULL) : m_pMenuCmd(pMenuCmd) {}
  121. ~CMenuCmdPtr() { delete m_pMenuCmd; }
  122. // Copy constructor
  123. CMenuCmdPtr (const CMenuCmdPtr& src) { m_pMenuCmd = src.m_pMenuCmd ? src.m_pMenuCmd->Clone() : NULL; }
  124. // cast to normal pointer
  125. operator CMenuCmd* () { return m_pMenuCmd; }
  126. // "->" operator casts to pointer too
  127. const CMenuCmd* operator->() const { return m_pMenuCmd; }
  128. CMenuCmd* operator->() { return m_pMenuCmd; }
  129. // Comparison for search by ID
  130. BOOL operator==(MenuID ID) { return m_pMenuCmd ? (m_pMenuCmd->ID() == ID) : FALSE; }
  131. // Assignment from plain pointer does not deep copy
  132. CMenuCmdPtr& operator= (CMenuCmd* pMenuCmd)
  133. {
  134. delete m_pMenuCmd;
  135. m_pMenuCmd = pMenuCmd;
  136. return *this;
  137. }
  138. // Assignment from another CMenuCmdPtr does deep copy
  139. CMenuCmdPtr& operator= (const CMenuCmdPtr& src)
  140. {
  141. if (this == &src)
  142. return *this;
  143. delete m_pMenuCmd;
  144. m_pMenuCmd = src.m_pMenuCmd ? src.m_pMenuCmd->Clone() : NULL;
  145. return *this;
  146. }
  147. private:
  148. CMenuCmd* m_pMenuCmd;
  149. };
  150. typedef std::vector<CMenuCmdPtr> menucmd_vector;
  151. IStream& operator>> (IStream& stm, menucmd_vector& vMenus);
  152. IStream& operator<< (IStream& stm, menucmd_vector& vMenus);
  153. #endif _MENUCMD_H_