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.

174 lines
5.4 KiB

  1. /**
  2. * @file menus_helpers.h
  3. * @brief Usefull macros and inline functions to create menus items
  4. * in menubars or popup menus
  5. */
  6. #include <bitmaps.h>
  7. /**
  8. * Definition SETBITMAPS
  9. * is a macro use to add a bitmaps to check menu item.
  10. * @note Do not use with normal menu items or any platform other than Windows.
  11. * @param aImage is the image to add the menu item.
  12. */
  13. #if defined( USE_IMAGES_IN_MENUS ) && defined( __WINDOWS__ )
  14. # define SETBITMAPS( aImage ) item->SetBitmaps( KiBitmap( apply_xpm ), KiBitmap( aImage ) )
  15. #else
  16. # define SETBITMAPS( aImage )
  17. #endif
  18. /**
  19. * Definition SETBITMAP
  20. * is a macro use to add a bitmap to a menu items.
  21. * @note Do not use with checked menu items.
  22. * @param aImage is the image to add the menu item.
  23. */
  24. #if !defined( USE_IMAGES_IN_MENUS )
  25. # define SET_BITMAP( aImage )
  26. #else
  27. # define SET_BITMAP( aImage ) item->SetBitmap( aImage )
  28. #endif
  29. /**
  30. * Function AddMenuItem
  31. * is an inline helper function to create and insert a menu item with an icon
  32. * into \a aMenu
  33. *
  34. * @param aMenu is the menu to add the new item.
  35. * @param aId is the command ID for the new menu item.
  36. * @param aText is the string for the new menu item.
  37. * @param aImage is the icon to add to the new menu item.
  38. * @param aType is the type of menu :wxITEM_NORMAL (default), wxITEM_CHECK ...
  39. * @return a pointer to the new created wxMenuItem
  40. */
  41. static inline wxMenuItem* AddMenuItem( wxMenu* aMenu,
  42. int aId,
  43. const wxString& aText,
  44. const wxBitmap& aImage,
  45. wxItemKind aType = wxITEM_NORMAL )
  46. {
  47. wxMenuItem* item;
  48. item = new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
  49. if( aType == wxITEM_CHECK )
  50. {
  51. #if defined( USE_IMAGES_IN_MENUS ) && defined( __WINDOWS__ )
  52. item->SetBitmaps( KiBitmap( apply_xpm ), aImage );
  53. #endif
  54. }
  55. else
  56. {
  57. SET_BITMAP( aImage );
  58. }
  59. aMenu->Append( item );
  60. return item;
  61. }
  62. /**
  63. * Function AddMenuItem
  64. * is an inline helper function to create and insert a menu item with an icon
  65. * and a help message string into \a aMenu
  66. *
  67. * @param aMenu is the menu to add the new item.
  68. * @param aId is the command ID for the new menu item.
  69. * @param aText is the string for the new menu item.
  70. * @param aHelpText is the help message string for the new menu item.
  71. * @param aImage is the icon to add to the new menu item.
  72. * @param aType is the type of menu :wxITEM_NORMAL (default), wxITEM_CHECK ...
  73. * @return a pointer to the new created wxMenuItem
  74. */
  75. static inline wxMenuItem* AddMenuItem( wxMenu* aMenu,
  76. int aId,
  77. const wxString& aText,
  78. const wxString& aHelpText,
  79. const wxBitmap& aImage,
  80. wxItemKind aType = wxITEM_NORMAL )
  81. {
  82. wxMenuItem* item;
  83. item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
  84. if( aType == wxITEM_CHECK )
  85. {
  86. #if defined( USE_IMAGES_IN_MENUS ) && defined( __WINDOWS__ )
  87. item->SetBitmaps( KiBitmap( apply_xpm ), aImage );
  88. #endif
  89. }
  90. else
  91. {
  92. SET_BITMAP( aImage );
  93. }
  94. aMenu->Append( item );
  95. return item;
  96. }
  97. /**
  98. * Function AddMenuItem
  99. * is an inline helper function to create and insert a menu item with an icon
  100. * into \a aSubMenu in \a aMenu
  101. *
  102. * @param aMenu is the menu to add the new submenu item.
  103. * @param aSubMenu is the submenu to add the new menu.
  104. * @param aId is the command ID for the new menu item.
  105. * @param aText is the string for the new menu item.
  106. * @param aImage is the icon to add to the new menu item.
  107. * @return a pointer to the new created wxMenuItem
  108. */
  109. static inline wxMenuItem* AddMenuItem( wxMenu* aMenu,
  110. wxMenu* aSubMenu,
  111. int aId,
  112. const wxString& aText,
  113. const wxBitmap& aImage )
  114. {
  115. wxMenuItem* item;
  116. item = new wxMenuItem( aMenu, aId, aText );
  117. item->SetSubMenu( aSubMenu );
  118. SET_BITMAP( aImage );
  119. aMenu->Append( item );
  120. return item;
  121. };
  122. /**
  123. * Function AddMenuItem
  124. * is an inline helper function to create and insert a menu item with an icon
  125. * and a help message string into \a aSubMenu in \a aMenu
  126. *
  127. * @param aMenu is the menu to add the new submenu item.
  128. * @param aSubMenu is the submenu to add the new menu.
  129. * @param aId is the command ID for the new menu item.
  130. * @param aText is the string for the new menu item.
  131. * @param aHelpText is the help message string for the new menu item.
  132. * @param aImage is the icon to add to the new menu item.
  133. * @return a pointer to the new created wxMenuItem
  134. */
  135. static inline wxMenuItem* AddMenuItem( wxMenu* aMenu,
  136. wxMenu* aSubMenu,
  137. int aId,
  138. const wxString& aText,
  139. const wxString& aHelpText,
  140. const wxBitmap& aImage )
  141. {
  142. wxMenuItem* item;
  143. item = new wxMenuItem( aMenu, aId, aText, aHelpText );
  144. item->SetSubMenu( aSubMenu );
  145. SET_BITMAP( aImage );
  146. aMenu->Append( item );
  147. return item;
  148. };