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 AddMenuLanguageList (CONDITIONAL_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)
 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 205 of file bitmap.cpp.

206 {
207  // Retrieve the global applicaton show icon option:
208  bool useImagesInMenus = Pgm().GetCommonSettings()->m_Appearance.use_icons_in_menus;
209 
210  wxItemKind menu_type = aMenu->GetKind();
211 
212  if( useImagesInMenus )
213  {
214  if( menu_type == wxITEM_CHECK || menu_type == wxITEM_RADIO )
215  {
216  #if defined( __WINDOWS__ )
217  aMenu->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
218  // A workaround to a strange bug on Windows, wx Widgets 3.0:
219  // size of bitmaps is not taken in account for wxITEM_{CHECK,RADIO} menu
220  // unless we call SetFont
221  aMenu->SetFont( *wxNORMAL_FONT );
222  #endif
223  }
224  else if( menu_type != wxITEM_RADIO )
225  {
226  aMenu->SetBitmap( aImage );
227  }
228  }
229 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
const BITMAP_OPAQUE checked_ok_xpm[1]
Definition: checked_ok.cpp:51

References checked_ok_xpm, KiBitmap(), and Pgm().

Referenced by ACTION_MENU::Add(), CONDITIONAL_MENU::AddCheckItem(), CONDITIONAL_MENU::AddItem(), AddMenuItem(), ACTION_MENU::appendCopy(), ACTION_MENU::DisplayTitle(), CONDITIONAL_MENU::Evaluate(), 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 232 of file bitmap.cpp.

234 {
235  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
236  AddBitmapToMenuItem( item, aImage );
237 
238  aMenu->Append( item );
239 
240  return item;
241 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:205

References AddBitmapToMenuItem().

Referenced by PCB_LAYER_WIDGET::AddRightClickMenuItems(), GERBER_LAYER_WIDGET::AddRightClickMenuItems(), DIALOG_CONFIGURE_PATHS::OnGridCellRightClick(), TREE_PROJECT_FRAME::OnRight(), LAYER_WIDGET::OnRightDownLayer(), LAYER_WIDGET::OnRightDownRender(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PANEL_COLOR_SETTINGS::ShowColorContextMenu(), and SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU().

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

247 {
248  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
249  AddBitmapToMenuItem( item, aImage );
250 
251  aMenu->Append( item );
252 
253  return item;
254 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:205

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

259 {
260  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText );
261  item->SetSubMenu( aSubMenu );
262  AddBitmapToMenuItem( item, aImage );
263 
264  aMenu->Append( item );
265 
266  return item;
267 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:205

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

273 {
274  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, aHelpText );
275  item->SetSubMenu( aSubMenu );
276  AddBitmapToMenuItem( item, aImage );
277 
278  aMenu->Append( item );
279 
280  return item;
281 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:205

References AddBitmapToMenuItem().

◆ AddMenuLanguageList()

void AddMenuLanguageList ( CONDITIONAL_MENU aMasterMenu,
TOOL_INTERACTIVE aControlTool 
)

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

Parameters
aMasterMenuThe main menu.

Definition at line 50 of file languages_menu.cpp.

51 {
52  CONDITIONAL_MENU* langsMenu = new CONDITIONAL_MENU( false, aControlTool );
53  langsMenu->SetTitle( _( "Set Language" ) );
54  langsMenu->SetIcon( language_xpm );
55  aMasterMenu->AddMenu( langsMenu );
56  wxString tooltip;
57 
58  auto isCurrentLang = [] ( int aLangIdentifier ) {
59  return Pgm().GetSelectedLanguageIdentifier() == aLangIdentifier;
60  };
61 
62  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
63  {
64  wxString label;
65 
66  if( LanguagesList[ii].m_DoNotTranslate )
67  label = LanguagesList[ii].m_Lang_Label;
68  else
69  label = wxGetTranslation( LanguagesList[ii].m_Lang_Label );
70 
71  langsMenu->AddCheckItem( LanguagesList[ii].m_KI_Lang_Identifier, // wxMenuItem wxID
72  label, tooltip, LanguagesList[ii].m_Lang_Icon,
73  std::bind( isCurrentLang, LanguagesList[ii].m_WX_Lang_Identifier ) );
74  }
75 }
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:64
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
LANGUAGE_DESCR LanguagesList[]
Definition: pgm_base.cpp:74
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:70
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:70
const BITMAP_OPAQUE language_xpm[1]
Definition: language.cpp:104
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:88
#define _(s)
Definition: 3d_actions.cpp:33

References _, CONDITIONAL_MENU::AddCheckItem(), CONDITIONAL_MENU::AddMenu(), language_xpm, LanguagesList, LANGUAGE_DESCR::m_KI_Lang_Identifier, LANGUAGE_DESCR::m_Lang_Label, Pgm(), ACTION_MENU::SetIcon(), and ACTION_MENU::SetTitle().

Referenced by KICAD_MANAGER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), CVPCB_MAINFRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), and PCB_EDIT_FRAME::ReCreateMenuBar().