40#include <wx/stc/stc.h>
42#include <wx/listctrl.h>
44using namespace std::placeholders;
48 m_isForcedPosition( false ),
50 m_titleDisplayed( false ),
51 m_isContextMenu( isContextMenu ),
64 menu->SetParent(
nullptr );
103 wxMenuItem* item = FindItemByPosition( 0 );
104 wxASSERT( item->GetItemLabelText() == GetTitle() );
107 item = FindItemByPosition( 0 );
108 wxASSERT( item->IsSeparator() );
113 else if( aDisplay && !
m_title.IsEmpty() )
118 FindItemByPosition( 0 )->SetItemLabel(
m_title );
123 InsertSeparator( 0 );
124 Insert( 0,
new wxMenuItem(
this, wxID_NONE,
m_title, wxEmptyString, wxITEM_NORMAL ) );
137 wxASSERT_MSG( FindItem( aId ) ==
nullptr, wxS(
"Duplicate menu IDs!" ) );
139 wxMenuItem* item =
new wxMenuItem(
this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
144 return Append( item );
149 BITMAPS aIcon,
bool aIsCheckmarkEntry )
151 wxASSERT_MSG( FindItem( aId ) ==
nullptr, wxS(
"Duplicate menu IDs!" ) );
153 wxMenuItem* item =
new wxMenuItem(
this, aId, aLabel, aTooltip,
154 aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
159 return Append( item );
164 const wxString& aOverrideLabel )
170 wxString menuLabel = aOverrideLabel.IsEmpty() ? aAction.
GetMenuItem() : aOverrideLabel;
172 wxMenuItem* item =
new wxMenuItem(
this, aAction.
GetUIId(), menuLabel,
174 aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
180 return Append( item );
188 wxASSERT_MSG( !aMenu->
m_title.IsEmpty(), wxS(
"Set a title for ACTION_MENU using SetTitle()" ) );
192 wxMenuItem* newItem =
new wxMenuItem(
this, -1, aMenu->
m_title );
194 newItem->SetSubMenu( aMenu );
195 return Append( newItem );
199 return AppendSubMenu( aMenu, aMenu->
m_title );
208 wxString::Format(
_(
"Close %s" ), aAppname ),
212 Add(
_(
"Close" ) + wxS(
"\tCtrl+W" ),
213 wxString::Format(
_(
"Close %s" ), aAppname ),
222 if( !aKiface || aKiface->
IsSingle() )
226 Add(
_(
"Quit" ) + wxS(
"\tCtrl+Q" ),
227 wxString::Format(
_(
"Quit %s" ), aAppname ),
242 Add(
_(
"Quit" ) + wxS(
"\tCtrl+Q" ),
243 wxString::Format(
_(
"Quit %s" ), aAppname ),
253 for(
int i = GetMenuItemCount() - 1; i >= 0; --i )
254 Destroy( FindItemByPosition( i ) );
259 wxASSERT( GetMenuItemCount() == 0 );
265 for( wxMenuItem* item : GetMenuItems() )
267 if( item->IsEnabled() && !item->IsSeparator() )
281 catch( std::exception& )
326 wxASSERT_MSG(
typeid( *
this ) ==
typeid( *menu ),
327 wxString::Format(
"You need to override create() method for class %s",
328 typeid( *this ).name() ) );
346 for( std::pair<const int, const TOOL_ACTION*>& ii :
m_toolActions )
350 int key = toolMgr->
GetHotKey( action ) & ~MD_MODIFIER_MASK;
356 wxMenuItem* item = FindChildItem(
id );
360 flags |= ( mod &
MD_ALT ) ? wxACCEL_ALT : 0;
361 flags |= ( mod &
MD_CTRL ) ? wxACCEL_CTRL : 0;
362 flags |= ( mod &
MD_SHIFT ) ? wxACCEL_SHIFT : 0;
365 flags = wxACCEL_NORMAL;
367 wxAcceleratorEntry accel( flags, key,
id, item );
368 item->SetAccel( &accel );
403 wxEventType type = aEvent.GetEventType();
404 wxWindow* focus = wxWindow::FindFocus();
407 if( type == wxEVT_MENU_OPEN )
412 wxMenu* parent =
dynamic_cast<wxMenu*
>( GetParent() );
415 if( !parent && toolMgr )
420 else if( type == wxEVT_MENU_HIGHLIGHT )
422 if( aEvent.GetId() > 0 )
427 else if( type == wxEVT_COMMAND_MENU_SELECTED )
433 if(
dynamic_cast<wxTextEntry*
>( focus )
434 ||
dynamic_cast<wxStyledTextCtrl*
>( focus )
435 ||
dynamic_cast<wxListView*
>( focus ) )
439 wxMenuItem* menuItem = FindItem( aEvent.GetId() );
440 wxAcceleratorEntry* acceleratorKey = menuItem ? menuItem->GetAccel() :
nullptr;
444 wxKeyEvent keyEvent( wxEVT_CHAR_HOOK );
445 keyEvent.m_keyCode = acceleratorKey->GetKeyCode();
446 keyEvent.m_controlDown = ( acceleratorKey->GetFlags() & wxMOD_CONTROL ) > 0;
447 keyEvent.m_shiftDown = ( acceleratorKey->GetFlags() & wxMOD_SHIFT ) > 0;
448 keyEvent.m_altDown = ( acceleratorKey->GetFlags() & wxMOD_ALT ) > 0;
450 if(
auto ctrl =
dynamic_cast<wxTextEntry*
>( focus ) )
453 focus->HandleWindowEvent( keyEvent );
455 if( keyEvent.GetSkipped() )
457 keyEvent.SetEventType( wxEVT_CHAR );
458 focus->HandleWindowEvent( keyEvent );
465 if( !keyEvent.GetSkipped() )
478 parent =
dynamic_cast<ACTION_MENU*
>( parent->GetParent() );
491 wxMenu* menu =
nullptr;
510 #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST
519 menuText = GetHelpString( aEvent.GetId() );
521 menuText = GetLabelText( aEvent.GetId() );
524 evt->SetParameter( &menuText );
549 evt->SetHasPosition(
false );
584 m->runOnSubmenus( aFunction );
587 catch( std::exception& )
603 const auto it = m->m_toolActions.find( aId );
605 if( it != m->m_toolActions.end() )
606 evt = it->second->MakeEvent();
628 for(
int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
630 wxMenuItem* item = aMenu.FindItemByPosition( i );
638 wxMenuItem* newItem =
new wxMenuItem(
this, aSource->GetId(), aSource->GetItemLabel(),
639 aSource->GetHelp(), aSource->GetKind() );
649 bool use_checked_bm = ( aSource->GetKind() == wxITEM_CHECK ||
650 aSource->GetKind() == wxITEM_RADIO ) ?
false :
true;
651 const wxBitmap& src_bitmap = aSource->GetBitmap( use_checked_bm );
653 const wxBitmap& src_bitmap = aSource->GetBitmap();
656 if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 )
659 if( aSource->IsSubMenu() )
662 wxASSERT_MSG( menu, wxS(
"Submenus are expected to be a ACTION_MENU" ) );
667 newItem->SetSubMenu( menuCopy );
675 if( aSource->IsCheckable() )
676 newItem->Check( aSource->IsChecked() );
678 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...
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
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.
static void OnCharHook(wxTextEntry *aTextEntry, wxKeyEvent &aEvent)
wxLogTrace helper definitions.