KiCad PCB EDA Suite
menus_helpers.h File Reference

Usefull macros and inline functions to create menus items in menubars or popup menus. More...

#include <wx/menu.h>
#include <wx/menuitem.h>
#include <bitmaps.h>

Go to the source code of this file.

Functions

void AddBitmapToMenuItem (wxMenuItem *aMenu, const wxBitmap &aImage)
 Add a bitmap to a menuitem. More...
 
wxMenuItem * AddMenuItem (wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
 Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into aMenu. More...
 
wxMenuItem * AddMenuItem (wxMenu *aMenu, int aId, const wxString &aText, const wxString &aHelpText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
 Function AddMenuItem is an inline helper function to create and insert a menu item with an icon and a help message string into aMenu. More...
 
wxMenuItem * AddMenuItem (wxMenu *aMenu, wxMenu *aSubMenu, int aId, const wxString &aText, const wxBitmap &aImage)
 Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into aSubMenu in aMenu. More...
 
wxMenuItem * AddMenuItem (wxMenu *aMenu, wxMenu *aSubMenu, int aId, const wxString &aText, const wxString &aHelpText, const wxBitmap &aImage)
 Function AddMenuItem is an inline helper function to create and insert a menu item with an icon and a help message string into aSubMenu in aMenu. More...
 

Detailed Description

Usefull macros and inline functions to create menus items in menubars or popup menus.

Definition in file menus_helpers.h.

Function Documentation

◆ AddBitmapToMenuItem()

void AddBitmapToMenuItem ( wxMenuItem *  aMenu,
const wxBitmap &  aImage 
)

Add a bitmap to a menuitem.

Parameters
aMenuis the menuitem.
aImageis the icon to add to aMenu. It is added only if use images in menus config option allows it. For wxITEM_CHECK or wxITEM_RADIO menuitems, the bitmap is added only on Windows, other platforms do not support it

Definition at line 223 of file bitmap.cpp.

224 {
225  // Retrieve the global applicaton show icon option:
226  bool useImagesInMenus;
227  Pgm().CommonSettings()->Read( USE_ICONS_IN_MENUS_KEY, &useImagesInMenus );
228 
229  wxItemKind menu_type = aMenu->GetKind();
230 
231  if( useImagesInMenus )
232  {
233  if( menu_type == wxITEM_CHECK || menu_type == wxITEM_RADIO )
234  {
235  #if defined( __WINDOWS__ )
236  aMenu->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
237  // A workaround to a strange bug on Windows, wx Widgets 3.0:
238  // size of bitmaps is not taken in account for wxITEM_{CHECK,RADIO} menu
239  // unless we call SetFont
240  aMenu->SetFont( *wxNORMAL_FONT );
241  #endif
242  }
243  else if( menu_type != wxITEM_RADIO )
244  {
245  aMenu->SetBitmap( aImage );
246  }
247  }
248 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:190
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:45

References PGM_BASE::CommonSettings(), KiBitmap(), Pgm(), and USE_ICONS_IN_MENUS_KEY.

Referenced by AddMenuItem(), and SIM_PLOT_FRAME::setIconsForMenuItems().

◆ AddMenuItem() [1/4]

wxMenuItem* AddMenuItem ( wxMenu *  aMenu,
int  aId,
const wxString &  aText,
const wxBitmap &  aImage,
wxItemKind  aType = wxITEM_NORMAL 
)

Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into aMenu.

Parameters
aMenuis the menu to add the new item.
aIdis the command ID for the new menu item.
aTextis the string for the new menu item.
aImageis the icon to add to the new menu item.
aTypeis the type of menu :wxITEM_NORMAL (default), wxITEM_CHECK ...
Returns
a pointer to the new created wxMenuItem

Definition at line 251 of file bitmap.cpp.

253 {
254  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
255  AddBitmapToMenuItem( item, aImage );
256 
257  aMenu->Append( item );
258 
259  return item;
260 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223

References AddBitmapToMenuItem().

Referenced by PGM_BASE::AddMenuLanguageList(), AddNewItemsCommand(), PCB_LAYER_WIDGET::AddRightClickMenuItems(), GERBER_LAYER_WIDGET::AddRightClickMenuItems(), EDA_3D_VIEWER::CreateMenuBar(), PCB_EDIT_FRAME::createPopUpBlockMenu(), PCB_EDIT_FRAME::createPopUpMenuForFootprints(), PCB_EDIT_FRAME::createPopUpMenuForFpPads(), PCB_EDIT_FRAME::createPopUpMenuForFpTexts(), PCB_EDIT_FRAME::createPopUpMenuForMarkers(), PCB_EDIT_FRAME::createPopUpMenuForTexts(), PCB_EDIT_FRAME::createPopupMenuForTracks(), PCB_EDIT_FRAME::createPopUpMenuForZones(), FOOTPRINT_TREE_PANE::FOOTPRINT_TREE_PANE(), FOOTPRINT_EDIT_FRAME::ModeditLocateAndDisplay(), DIALOG_CONFIGURE_PATHS::OnGridCellRightClick(), TREE_PROJECT_FRAME::OnRight(), FOOTPRINT_EDIT_FRAME::OnRightClick(), EDA_3D_CANVAS::OnRightClick(), PL_EDITOR_FRAME::OnRightClick(), GERBVIEW_FRAME::OnRightClick(), PCB_EDIT_FRAME::OnRightClick(), LAYER_WIDGET::OnRightDownLayer(), LAYER_WIDGET::OnRightDownRender(), PL_EDITOR_FRAME::OnTreeRightClick(), PCB_BASE_FRAME::PcbGeneralLocateAndDisplay(), prepareEditMenu(), prepareExportMenu(), prepareFilesMenu(), prepareHelpMenu(), prepareInspectMenu(), prepareLibraryMenu(), preparePlaceMenu(), preparePreferencesMenu(), prepareRouteMenu(), prepareToolsMenu(), LIB_VIEW_FRAME::ReCreateMenuBar(), CVPCB_MAINFRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU(), and SYMBOL_TREE_PANE::SYMBOL_TREE_PANE().

◆ AddMenuItem() [2/4]

wxMenuItem* AddMenuItem ( wxMenu *  aMenu,
int  aId,
const wxString &  aText,
const wxString &  aHelpText,
const wxBitmap &  aImage,
wxItemKind  aType = wxITEM_NORMAL 
)

Function AddMenuItem is an inline helper function to create and insert a menu item with an icon and a help message string into aMenu.

Parameters
aMenuis the menu to add the new item.
aIdis the command ID for the new menu item.
aTextis the string for the new menu item.
aHelpTextis the help message string for the new menu item.
aImageis the icon to add to the new menu item.
aTypeis the type of menu :wxITEM_NORMAL (default), wxITEM_CHECK ...
Returns
a pointer to the new created wxMenuItem

Definition at line 263 of file bitmap.cpp.

266 {
267  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
268  AddBitmapToMenuItem( item, aImage );
269 
270  aMenu->Append( item );
271 
272  return item;
273 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223

References AddBitmapToMenuItem().

◆ AddMenuItem() [3/4]

wxMenuItem* AddMenuItem ( wxMenu *  aMenu,
wxMenu *  aSubMenu,
int  aId,
const wxString &  aText,
const wxBitmap &  aImage 
)

Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into aSubMenu in aMenu.

Parameters
aMenuis the menu to add the new submenu item.
aSubMenuis the submenu to add the new menu.
aIdis the command ID for the new menu item.
aTextis the string for the new menu item.
aImageis the icon to add to the new menu item.
Returns
a pointer to the new created wxMenuItem

Definition at line 276 of file bitmap.cpp.

278 {
279  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText );
280  item->SetSubMenu( aSubMenu );
281  AddBitmapToMenuItem( item, aImage );
282 
283  aMenu->Append( item );
284 
285  return item;
286 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223

References AddBitmapToMenuItem().

◆ AddMenuItem() [4/4]

wxMenuItem* AddMenuItem ( wxMenu *  aMenu,
wxMenu *  aSubMenu,
int  aId,
const wxString &  aText,
const wxString &  aHelpText,
const wxBitmap &  aImage 
)

Function AddMenuItem is an inline helper function to create and insert a menu item with an icon and a help message string into aSubMenu in aMenu.

Parameters
aMenuis the menu to add the new submenu item.
aSubMenuis the submenu to add the new menu.
aIdis the command ID for the new menu item.
aTextis the string for the new menu item.
aHelpTextis the help message string for the new menu item.
aImageis the icon to add to the new menu item.
Returns
a pointer to the new created wxMenuItem

Definition at line 289 of file bitmap.cpp.

292 {
293  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, aHelpText );
294  item->SetSubMenu( aSubMenu );
295  AddBitmapToMenuItem( item, aImage );
296 
297  aMenu->Append( item );
298 
299  return item;
300 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223

References AddBitmapToMenuItem().