Source code of Windows XP (NT5)
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.

203 lines
5.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ExtMenu.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CExtMenuItem class.
  10. //
  11. // Author:
  12. // David Potter (davidp) August 28, 1996
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "ExtMenu.h"
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CExtMenuItem
  23. /////////////////////////////////////////////////////////////////////////////
  24. IMPLEMENT_DYNAMIC( CExtMenuItem, CObject );
  25. /////////////////////////////////////////////////////////////////////////////
  26. //++
  27. //
  28. // CExtMenuItem::CExtMenuItem
  29. //
  30. // Routine Description:
  31. // Default constructor.
  32. //
  33. // Arguments:
  34. // None.
  35. //
  36. // Return Value:
  37. // None.
  38. //
  39. //--
  40. /////////////////////////////////////////////////////////////////////////////
  41. CExtMenuItem::CExtMenuItem( void )
  42. {
  43. CommonConstruct();
  44. } //*** CExtMenuItem::CExtMenuItem()
  45. /////////////////////////////////////////////////////////////////////////////
  46. //++
  47. //
  48. // CExtMenuItem::CExtMenuItem
  49. //
  50. // Routine Description:
  51. // Constructor. Caller must check range on ID and flags.
  52. //
  53. // Arguments:
  54. // lpszName [IN] Name of item.
  55. // lpszStatusBarText [IN] Text to appear on the status bar when the
  56. // item is highlighted.
  57. // nExtCommandID [IN] Extension's ID for the command.
  58. // nCommandID [IN] ID for the command when menu item is invoked.
  59. // nMenuItemID [IN] Index in the menu of the item.
  60. // uFlags [IN] Menu flags.
  61. // bMakeDefault [IN] TRUE = Make this item the default item.
  62. // piCommand [IN OUT] Command interface.
  63. //
  64. // Return Value:
  65. // None.
  66. //
  67. //--
  68. /////////////////////////////////////////////////////////////////////////////
  69. CExtMenuItem::CExtMenuItem(
  70. IN LPCTSTR lpszName,
  71. IN LPCTSTR lpszStatusBarText,
  72. IN ULONG nExtCommandID,
  73. IN ULONG nCommandID,
  74. IN ULONG nMenuItemID,
  75. IN ULONG uFlags,
  76. IN BOOL bMakeDefault,
  77. IN OUT IWEInvokeCommand * piCommand
  78. )
  79. {
  80. CommonConstruct();
  81. ASSERT( piCommand != NULL );
  82. m_strName = lpszName;
  83. m_strStatusBarText = lpszStatusBarText;
  84. m_nExtCommandID = nExtCommandID;
  85. m_nCommandID = nCommandID;
  86. m_nMenuItemID = nMenuItemID;
  87. m_uFlags = uFlags;
  88. m_bDefault = bMakeDefault;
  89. m_piCommand = piCommand;
  90. // will throw its own exception if it fails
  91. if ( uFlags & MF_POPUP )
  92. {
  93. m_plSubMenuItems = new CExtMenuItemList;
  94. if ( m_plSubMenuItems == NULL )
  95. {
  96. AfxThrowMemoryException();
  97. } // if: error allocating memory
  98. } // if: popup menu
  99. ASSERT_VALID( this );
  100. } //*** CExtMenuItem::CExtMenuItem()
  101. /////////////////////////////////////////////////////////////////////////////
  102. //++
  103. //
  104. // CExtMenuItem::~CExtMenuItem
  105. //
  106. // Routine Description:
  107. // Default constructor.
  108. //
  109. // Arguments:
  110. // None.
  111. //
  112. // Return Value:
  113. // None.
  114. //
  115. //--
  116. /////////////////////////////////////////////////////////////////////////////
  117. CExtMenuItem::~CExtMenuItem( void )
  118. {
  119. delete m_plSubMenuItems;
  120. // Nuke data so it can't be used again
  121. CommonConstruct();
  122. } //*** CExtMenuItem::~CExtMenuItem()
  123. /////////////////////////////////////////////////////////////////////////////
  124. //++
  125. //
  126. // CExtMenuItem::CommonConstruct
  127. //
  128. // Routine Description:
  129. // Common object construction.
  130. //
  131. // Arguments:
  132. // None.
  133. //
  134. // Return Value:
  135. // None.
  136. //
  137. //--
  138. /////////////////////////////////////////////////////////////////////////////
  139. void CExtMenuItem::CommonConstruct( void )
  140. {
  141. m_strName.Empty();
  142. m_strStatusBarText.Empty();
  143. m_nExtCommandID = (ULONG) -1;
  144. m_nCommandID = (ULONG) -1;
  145. m_nMenuItemID = (ULONG) -1;
  146. m_uFlags = (ULONG) -1;
  147. m_bDefault = FALSE;
  148. m_piCommand = NULL;
  149. m_plSubMenuItems = NULL;
  150. m_hmenuPopup = NULL;
  151. } //*** CExtMenuItem::CommonConstruct()
  152. #ifdef _DEBUG
  153. /////////////////////////////////////////////////////////////////////////////
  154. //++
  155. //
  156. // CExtMenuItem::AssertValid
  157. //
  158. // Routine Description:
  159. // Assert that the object is valid.
  160. //
  161. // Arguments:
  162. // None.
  163. //
  164. // Return Value:
  165. // None.
  166. //
  167. //--
  168. /////////////////////////////////////////////////////////////////////////////
  169. void CExtMenuItem::AssertValid( void )
  170. {
  171. CObject::AssertValid();
  172. if ( ( m_nExtCommandID == -1 )
  173. || ( m_nCommandID == -1 )
  174. || ( m_nMenuItemID == -1 )
  175. || ( m_uFlags == -1 )
  176. || ( ( ( m_uFlags & MF_POPUP ) == 0 ) && ( m_plSubMenuItems != NULL ) )
  177. || ( ( ( m_uFlags & MF_POPUP ) != 0 ) && ( m_plSubMenuItems == NULL ) )
  178. )
  179. {
  180. ASSERT( FALSE );
  181. }
  182. } //*** CExtMenuItem::AssertValid()
  183. #endif