KiCad PCB EDA Suite
menus_helpers.h File Reference

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

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

Go to the source code of this file.

Functions

void AddMenuLanguageList (ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
 Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to MasterMenu. More...
 
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)
 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)
 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)
 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)
 Create and insert a menu item with an icon and a help message string into aSubMenu in aMenu. More...
 

Detailed Description

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.

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

Parameters
aMenuis the menuitem.
aImageis the icon to add to aMenu.

Definition at line 252 of file bitmap.cpp.

253{
254 // Retrieve the global application show icon option:
255 bool useImagesInMenus = Pgm().GetCommonSettings()->m_Appearance.use_icons_in_menus;
256
257 wxItemKind menu_type = aMenu->GetKind();
258
259 if( useImagesInMenus && menu_type != wxITEM_CHECK && menu_type != wxITEM_RADIO )
260 {
261 aMenu->SetBitmap( aImage );
262 }
263}
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

References Pgm().

Referenced by ACTION_MENU::Add(), CONDITIONAL_MENU::AddCheckItem(), CONDITIONAL_MENU::AddItem(), AddMenuItem(), ACTION_MENU::appendCopy(), ACTION_MENU::DisplayTitle(), and CONDITIONAL_MENU::Evaluate().

◆ AddMenuItem() [1/4]

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

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 266 of file bitmap.cpp.

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

References AddBitmapToMenuItem().

Referenced by GERBER_LAYER_WIDGET::AddRightClickMenuItems(), PCB_EDIT_FRAME::buildActionPluginMenus(), PROJECT_TREE_PANE::onRight(), LAYER_WIDGET::OnRightDownLayer(), LAYER_WIDGET::OnRightDownRender(), APPEARANCE_CONTROLS::rebuildLayerContextMenu(), and PANEL_COLOR_SETTINGS::ShowColorContextMenu().

◆ AddMenuItem() [2/4]

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

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 278 of file bitmap.cpp.

281{
282 wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
283 AddBitmapToMenuItem( item, aImage );
284
285 aMenu->Append( item );
286
287 return item;
288}

References AddBitmapToMenuItem().

◆ AddMenuItem() [3/4]

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

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 291 of file bitmap.cpp.

293{
294 wxMenuItem* item = new wxMenuItem( aMenu, aId, aText );
295 item->SetSubMenu( aSubMenu );
296 AddBitmapToMenuItem( item, aImage );
297
298 aMenu->Append( item );
299
300 return item;
301}

References AddBitmapToMenuItem().

◆ AddMenuItem() [4/4]

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

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 304 of file bitmap.cpp.

307{
308 wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, aHelpText );
309 item->SetSubMenu( aSubMenu );
310 AddBitmapToMenuItem( item, aImage );
311
312 aMenu->Append( item );
313
314 return item;
315}

References AddBitmapToMenuItem().

◆ AddMenuLanguageList()

void AddMenuLanguageList ( ACTION_MENU aMasterMenu,
TOOL_INTERACTIVE aControlTool 
)

Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to MasterMenu.

Parameters
aMasterMenuis the main menu.
aControlToolis the tool to associate with the menu

Definition at line 45 of file languages_menu.cpp.

46{
47 ACTION_MENU* langsMenu = new ACTION_MENU( false, aControlTool );
48 langsMenu->SetTitle( _( "Set Language" ) );
49 langsMenu->SetIcon( BITMAPS::language );
50
51 wxString tooltip;
52
53 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
54 {
55 wxString label;
56
57 if( LanguagesList[ii].m_DoNotTranslate )
58 label = LanguagesList[ii].m_Lang_Label;
59 else
60 label = wxGetTranslation( LanguagesList[ii].m_Lang_Label );
61
62 wxMenuItem* item = new wxMenuItem( langsMenu,
63 LanguagesList[ii].m_KI_Lang_Identifier, // wxMenuItem wxID
64 label,
65 tooltip,
66 wxITEM_CHECK );
67
68 langsMenu->Append( item );
69 }
70
71 // This must be done after the items are added
72 aMasterMenu->Add( langsMenu );
73}
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:87
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:73
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
#define _(s)
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:85
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:66
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:69

References _, ACTION_MENU::Add(), language, LanguagesList, LANGUAGE_DESCR::m_KI_Lang_Identifier, LANGUAGE_DESCR::m_Lang_Label, ACTION_MENU::SetIcon(), and ACTION_MENU::SetTitle().

Referenced by CVPCB_MAINFRAME::doReCreateMenuBar(), SCH_EDIT_FRAME::doReCreateMenuBar(), SIMULATOR_FRAME::doReCreateMenuBar(), SYMBOL_EDIT_FRAME::doReCreateMenuBar(), GERBVIEW_FRAME::doReCreateMenuBar(), KICAD_MANAGER_FRAME::doReCreateMenuBar(), PL_EDITOR_FRAME::doReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::doReCreateMenuBar(), and PCB_EDIT_FRAME::doReCreateMenuBar().