39#include <wx/stc/stc.h>
41#include <wx/listctrl.h>
45using namespace std::placeholders;
49 m_isForcedPosition( false ),
51 m_titleDisplayed( false ),
52 m_isContextMenu( isContextMenu ),
69 menu->SetParent(
nullptr );
108 wxMenuItem* item = FindItemByPosition( 0 );
109 wxASSERT( item->GetItemLabelText() ==
GetTitle() );
113 item = FindItemByPosition( 0 );
114 wxASSERT( item->IsSeparator() );
119 else if( aDisplay && !
m_title.IsEmpty() )
124 FindItemByPosition( 0 )->SetItemLabel(
m_title );
129 InsertSeparator( 0 );
130 Insert( 0,
new wxMenuItem(
this, wxID_NONE,
m_title, wxEmptyString, wxITEM_NORMAL ) );
143 wxASSERT_MSG( FindItem( aId ) ==
nullptr, wxS(
"Duplicate menu IDs!" ) );
145 wxMenuItem* item =
new wxMenuItem(
this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
150 return Append( item );
155 BITMAPS aIcon,
bool aIsCheckmarkEntry )
157 wxASSERT_MSG( FindItem( aId ) ==
nullptr, wxS(
"Duplicate menu IDs!" ) );
159 wxMenuItem* item =
new wxMenuItem(
this, aId, aLabel, aTooltip,
160 aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
165 return Append( item );
170 const wxString& aOverrideLabel )
176 wxString menuLabel = aOverrideLabel.IsEmpty() ? aAction.
GetMenuItem() : aOverrideLabel;
178 wxMenuItem* item =
new wxMenuItem(
this, aAction.
GetUIId(), menuLabel,
180 aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
186 return Append( item );
194 wxASSERT_MSG( !aMenu->
m_title.IsEmpty(),
195 wxS(
"Set a title for ACTION_MENU using SetTitle()" ) );
199 wxMenuItem* newItem =
new wxMenuItem(
this, -1, aMenu->
m_title );
201 newItem->SetSubMenu( aMenu );
202 return Append( newItem );
206 return AppendSubMenu( aMenu, aMenu->
m_title );
215 wxString::Format(
_(
"Close %s" ), aAppname ),
219 Add(
_(
"Close" ) + wxS(
"\tCtrl+W" ),
220 wxString::Format(
_(
"Close %s" ), aAppname ),
229 if( !aKiface || aKiface->
IsSingle() )
233 Add(
_(
"Quit" ) + wxS(
"\tCtrl+Q" ),
234 wxString::Format(
_(
"Quit %s" ), aAppname ),
249 Add(
_(
"Quit" ) + wxS(
"\tCtrl+Q" ),
250 wxString::Format(
_(
"Quit %s" ), aAppname ),
260 for(
int i = GetMenuItemCount() - 1; i >= 0; --i )
261 Destroy( FindItemByPosition( i ) );
266 wxASSERT( GetMenuItemCount() == 0 );
272 for( wxMenuItem* item : GetMenuItems() )
274 if( item->IsEnabled() && !item->IsSeparator() )
288 catch( std::exception& )
333 wxASSERT_MSG(
typeid( *
this ) ==
typeid( *menu ),
334 wxString::Format(
"You need to override create() method for class %s",
335 typeid( *this ).name() ) );
353 for( std::pair<const int, const TOOL_ACTION*>& ii :
m_toolActions )
357 int key = toolMgr->
GetHotKey( action ) & ~MD_MODIFIER_MASK;
363 wxMenuItem* item = FindChildItem(
id );
367 flags |= ( mod &
MD_ALT ) ? wxACCEL_ALT : 0;
368 flags |= ( mod &
MD_CTRL ) ? wxACCEL_CTRL : 0;
369 flags |= ( mod &
MD_SHIFT ) ? wxACCEL_SHIFT : 0;
372 flags = wxACCEL_NORMAL;
374 wxAcceleratorEntry accel( flags, key,
id, item );
375 item->SetAccel( &accel );
410 wxEventType type = aEvent.GetEventType();
411 wxWindow* focus = wxWindow::FindFocus();
414 if( type == wxEVT_MENU_OPEN )
419 wxMenu* parent =
dynamic_cast<wxMenu*
>( GetParent() );
422 if( !parent && !IsAttached() && toolMgr )
427 else if( type == wxEVT_MENU_HIGHLIGHT )
429 if( aEvent.GetId() > 0 )
434 else if( type == wxEVT_COMMAND_MENU_SELECTED )
440 if(
dynamic_cast<wxTextEntry*
>( focus )
441 ||
dynamic_cast<wxStyledTextCtrl*
>( focus )
442 ||
dynamic_cast<wxListView*
>( focus )
443 ||
dynamic_cast<wxGrid*
>( focus ) )
447 wxMenuItem* menuItem = FindItem( aEvent.GetId() );
448 wxAcceleratorEntry* acceleratorKey = menuItem ? menuItem->GetAccel() :
nullptr;
452 wxKeyEvent keyEvent( wxEVT_CHAR_HOOK );
453 keyEvent.m_keyCode = acceleratorKey->GetKeyCode();
454 keyEvent.m_controlDown = ( acceleratorKey->GetFlags() & wxMOD_CONTROL ) > 0;
455 keyEvent.m_shiftDown = ( acceleratorKey->GetFlags() & wxMOD_SHIFT ) > 0;
456 keyEvent.m_altDown = ( acceleratorKey->GetFlags() & wxMOD_ALT ) > 0;
458 if( wxTextEntry* ctrl =
dynamic_cast<wxTextEntry*
>( focus ) )
461 focus->HandleWindowEvent( keyEvent );
463 if( keyEvent.GetSkipped() )
465 keyEvent.SetEventType( wxEVT_CHAR );
466 focus->HandleWindowEvent( keyEvent );
471 if( keyEvent.GetKeyCode() == WXK_BACK || keyEvent.GetKeyCode() == WXK_DELETE )
477 if( !keyEvent.GetSkipped() )
490 parent =
dynamic_cast<ACTION_MENU*
>( parent->GetParent() );
503 wxMenu* menu =
nullptr;
522 #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST
531 menuText = GetHelpString( aEvent.GetId() );
533 menuText = GetLabelText( aEvent.GetId() );
536 evt->SetParameter( &menuText );
562 evt->SetHasPosition(
false );
597 m->runOnSubmenus( aFunction );
600 catch( std::exception& )
616 const auto it = m->m_toolActions.find( aId );
618 if( it != m->m_toolActions.end() )
619 evt = it->second->MakeEvent();
641 for(
int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
643 wxMenuItem* item = aMenu.FindItemByPosition( i );
651 wxMenuItem* newItem =
new wxMenuItem(
this, aSource->GetId(), aSource->GetItemLabel(),
652 aSource->GetHelp(), aSource->GetKind() );
659#if defined( __WXMSW__ )
663 bool use_checked_bm = ( aSource->GetKind() == wxITEM_CHECK ||
664 aSource->GetKind() == wxITEM_RADIO ) ?
false :
true;
665 const wxBitmap& src_bitmap = aSource->GetBitmap( use_checked_bm );
667 const wxBitmap& src_bitmap = aSource->GetBitmap();
670 if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 )
673 if( aSource->IsSubMenu() )
676 wxASSERT_MSG( menu, wxS(
"Submenus are expected to be a ACTION_MENU" ) );
681 newItem->SetSubMenu( menuCopy );
689 if( aSource->IsCheckable() )
690 newItem->Check( aSource->IsChecked() );
692 newItem->Enable( aSource->IsEnabled() );
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
BITMAPS
A list of all bitmap identifiers.
static TOOL_ACTION updateMenu
bool IsActionUIId(int aId) const
Test if a UI ID corresponds to an action ID in our system.
bool IsSingle() const
Is this KIFACE running under single_top?
Base window classes and related definitions.
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
Common command IDs shared by more than one of the KiCad applications.
KICOMMON_API void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmapBundle &aImage)
Add a bitmap to a menuitem.
static void OnCharHook(wxTextEntry *aTextEntry, wxKeyEvent &aEvent)
wxLogTrace helper definitions.
Functions to provide common constants and other functions to assist in making a consistent UI.