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.

214 lines
8.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: menuitem.h
  8. //
  9. //--------------------------------------------------------------------------
  10. // MenuItem.h : Declaration of the CMenuItem class.
  11. /////////////////////////////////////////////////////////////////////////////
  12. // MenuItem.h : See MenuItem.cpp for implementation.
  13. #ifndef _MENUITEM_H
  14. #define _MENUITEM_H
  15. #ifndef DECLSPEC_UUID
  16. #if _MSC_VER >= 1100
  17. #define DECLSPEC_UUID(x) __declspec(uuid(x))
  18. #else
  19. #define DECLSPEC_UUID(x)
  20. #endif
  21. #endif
  22. #include "ndmgr.h"
  23. #include "cmenuinfo.h"
  24. // menu owner IDs
  25. #define OWNERID_NATIVE 0
  26. #define OWNERID_PRIMARY_MIN 1
  27. #define OWNERID_PRIMARY_MAX 0x7FFFFFFF
  28. #define OWNERID_THIRD_PARTY_MIN 0x80000000
  29. #define OWNERID_THIRD_PARTY_MAX 0xFFFFFFFE
  30. #define OWNERID_INVALID 0xFFFFFFFF
  31. inline BOOL IsSystemOwnerID( MENU_OWNER_ID ownerid )
  32. { return (OWNERID_NATIVE == ownerid); }
  33. inline BOOL IsPrimaryOwnerID( MENU_OWNER_ID ownerid )
  34. { return (OWNERID_PRIMARY_MIN <= ownerid && OWNERID_PRIMARY_MAX >= ownerid ); }
  35. inline BOOL IsThirdPartyOwnerID( MENU_OWNER_ID ownerid )
  36. { return (OWNERID_THIRD_PARTY_MIN <= ownerid && OWNERID_THIRD_PARTY_MAX >= ownerid ); }
  37. inline BOOL IsSpecialInsertionPointID( long lInsertionPointID )
  38. { return (lInsertionPointID & CCM_INSERTIONPOINTID_MASK_SPECIAL); }
  39. inline BOOL IsSharedInsertionPointID( long lInsertionPointID )
  40. { return (lInsertionPointID & CCM_INSERTIONPOINTID_MASK_SHARED); }
  41. inline BOOL IsCreatePrimaryInsertionPointID( long lInsertionPointID )
  42. { return (lInsertionPointID & CCM_INSERTIONPOINTID_MASK_CREATE_PRIMARY); }
  43. inline BOOL IsAddPrimaryInsertionPointID( long lInsertionPointID )
  44. { return (lInsertionPointID & CCM_INSERTIONPOINTID_MASK_ADD_PRIMARY); }
  45. inline BOOL IsAdd3rdPartyInsertionPointID( long lInsertionPointID )
  46. { return (lInsertionPointID & CCM_INSERTIONPOINTID_MASK_ADD_3RDPARTY); }
  47. inline BOOL IsReservedInsertionPointID( long lInsertionPointID )
  48. { return (lInsertionPointID & CCM_INSERTIONPOINTID_MASK_RESERVED); }
  49. inline BOOL IsReservedCommandID( long lCommandID )
  50. { return (lCommandID & CCM_COMMANDID_MASK_RESERVED); }
  51. #define MENUITEM_BASE_ID 1000
  52. /*+-------------------------------------------------------------------------*
  53. * class CMenuItem
  54. *
  55. *
  56. * PURPOSE: Encapsulates all information, including how to execute,
  57. * for a menu item.
  58. *
  59. *+-------------------------------------------------------------------------*/
  60. class CMenuItem :
  61. public CTiedObject
  62. {
  63. DECLARE_NOT_COPIABLE(CMenuItem)
  64. DECLARE_NOT_ASSIGNABLE(CMenuItem)
  65. public:
  66. CMenuItem( LPCTSTR lpszName,
  67. LPCTSTR lpszStatusBarText,
  68. LPCTSTR lpszLanguageIndependentName,
  69. LPCTSTR lpszPath,
  70. LPCTSTR lpszLanguageIndependentPath,
  71. long nCommandID,
  72. long nMenuItemID,
  73. long nFlags,
  74. MENU_OWNER_ID ownerID,
  75. IExtendContextMenu * pExtendContextMenu,
  76. IDataObject * pDataObject,
  77. DWORD fSpecialFlags,
  78. bool bPassCommandBackToSnapin = false );
  79. virtual ~CMenuItem();
  80. // Interfaces
  81. public:
  82. // use MFC's standard object validity technique
  83. virtual void AssertValid();
  84. public:
  85. void GetMenuItemName(LPTSTR pBuffer, int* pLen);
  86. LPCTSTR GetMenuItemName() const { return m_strName; }
  87. LPCTSTR GetMenuItemStatusBarText() const { return m_strStatusBarText; }
  88. LPCTSTR GetLanguageIndependentName() const { return m_strLanguageIndependentName;}
  89. LPCTSTR GetPath() const { return m_strPath;}
  90. LPCTSTR GetLanguageIndependentPath() const { return m_strLanguageIndependentPath;}
  91. long GetCommandID() const { return m_nCommandID; }
  92. long GetMenuItemID() const { return m_nMenuItemID; }
  93. long GetMenuItemFlags() const { return m_nFlags; }
  94. void SetMenuItemFlags( long nFlags ) { m_nFlags = nFlags; }
  95. MENU_OWNER_ID GetMenuItemOwner() const { return m_OwnerID; }
  96. MenuItemList& GetMenuItemSubmenu() { return m_SubMenu; }
  97. DWORD GetSpecialFlags() const { return m_fSpecialFlags;}
  98. HMENU GetPopupMenuHandle() { return m_PopupMenuHandle; }
  99. void SetPopupMenuHandle( HMENU hmenu ) { m_PopupMenuHandle = hmenu; }
  100. BOOL IsPopupMenu() { return (MF_POPUP & m_nFlags); }
  101. BOOL IsSpecialItemDefault() { return (m_fSpecialFlags & CCM_SPECIAL_DEFAULT_ITEM); }
  102. BOOL IsSpecialSeparator() { return (m_fSpecialFlags & CCM_SPECIAL_SEPARATOR); }
  103. BOOL IsSpecialSubmenu() { return (m_fSpecialFlags & CCM_SPECIAL_SUBMENU); }
  104. BOOL IsSpecialInsertionPoint() { return (m_fSpecialFlags & CCM_SPECIAL_INSERTION_POINT); }
  105. BOOL HasChildList() { return ((m_nFlags & MF_POPUP) || IsSpecialInsertionPoint()); }
  106. CMenuItem* FindItemByPath( LPCTSTR lpstrPath );
  107. // creates and returns a ContextMenu interface.
  108. SC ScGetMenuItem(PPMENUITEM ppMenuItem);
  109. // MenuItem methods.
  110. virtual SC ScExecute(); // executes the menu item.
  111. virtual SC Scget_DisplayName(PBSTR pbstrName);
  112. virtual SC Scget_LanguageIndependentName(PBSTR LanguageIndependentName);
  113. virtual SC Scget_Path(PBSTR pbstrPath);
  114. virtual SC Scget_LanguageIndependentPath(PBSTR LanguageIndependentPath);
  115. virtual SC Scget_Enabled(PBOOL pBool);
  116. bool NeedsToPassCommandBackToSnapin() { return m_bPassCommandBackToSnapin; }
  117. private:
  118. CStr m_strName;
  119. CStr m_strStatusBarText;
  120. CStr m_strPath;
  121. CStr m_strLanguageIndependentName;
  122. CStr m_strLanguageIndependentPath;
  123. long m_nCommandID;
  124. long m_nMenuItemID;
  125. long m_nFlags;
  126. MENU_OWNER_ID m_OwnerID;
  127. long m_fSpecialFlags;
  128. HMENU m_PopupMenuHandle;
  129. MenuItemList m_SubMenu;
  130. IExtendContextMenuPtr m_spExtendContextMenu; // the callback called when the item is executed.
  131. IDataObject* m_pDataObject;
  132. BOOL m_bEnabled;
  133. MenuItemPtr m_spMenuItem;
  134. bool m_bPassCommandBackToSnapin;
  135. };
  136. /*+-------------------------------------------------------------------------*
  137. *
  138. * CRootMenuItem
  139. *
  140. * PURPOSE: The root menu item.
  141. *
  142. * RETURNS:
  143. * class
  144. *
  145. *+-------------------------------------------------------------------------*/
  146. class
  147. CRootMenuItem : public CMenuItem
  148. {
  149. public:
  150. CRootMenuItem() : CMenuItem(NULL/*lpszName*/, NULL/*lpszStatusBarText*/, NULL/*lpszLanguageIndependentName*/,
  151. NULL/*lpszPath*/, NULL/*lpszLanguageIndependentPath*/, 0/*nCommandID*/,
  152. 0/*nMenuItemID*/,MF_POPUP/*nFlags*/,0/*ownerID*/, NULL/*pExtendContextMenu*/,
  153. NULL/*pDataObject*/, 0/*fSpecialFlags*/)
  154. {
  155. }
  156. virtual SC ScExecute() const {SC sc; return sc;} // does nothing.
  157. };
  158. /////////////////////////////////////////////////////////////////////////////
  159. // SnapinStruct
  160. class SnapinStruct
  161. {
  162. // cannot assign - will unbalance m_pIDataObject refs
  163. DECLARE_NOT_COPIABLE(SnapinStruct)
  164. DECLARE_NOT_ASSIGNABLE(SnapinStruct)
  165. public:
  166. IExtendContextMenuPtr pIExtendContextMenu;
  167. MENU_OWNER_ID m_OwnerID;
  168. IDataObject* m_pIDataObject;
  169. SnapinStruct( IExtendContextMenu* pintf,
  170. IDataObject* pIDataObject,
  171. MENU_OWNER_ID ownerID)
  172. : pIExtendContextMenu( pintf ),
  173. m_OwnerID( ownerID )
  174. {
  175. ASSERT( NULL != pintf && NULL != pIDataObject );
  176. m_pIDataObject = pIDataObject;
  177. if (! IS_SPECIAL_DATAOBJECT(m_pIDataObject))
  178. m_pIDataObject->AddRef();
  179. }
  180. ~SnapinStruct()
  181. {
  182. if (! IS_SPECIAL_DATAOBJECT(m_pIDataObject))
  183. m_pIDataObject->Release();
  184. }
  185. };
  186. #endif