30#include <wx/listctrl.h>
32#include <wx/textentry.h>
33#include <wx/stc/stc.h>
48using namespace std::placeholders;
70 for(
auto subitem : GetMenuItems() )
71 subitem->SetBitmap( wxNullBitmap );
76 for(
auto menuItem : GetMenuItems() )
77 menuItem->SetBitmap( wxNullBitmap );
79 menu->SetParent(
nullptr );
118 wxMenuItem* item = FindItemByPosition( 0 );
119 wxASSERT( item->GetItemLabelText() ==
GetTitle() );
120 item->SetBitmap( wxNullBitmap );
124 item = FindItemByPosition( 0 );
125 wxASSERT( item->IsSeparator() );
130 else if( aDisplay && !
m_title.IsEmpty() )
135 FindItemByPosition( 0 )->SetItemLabel(
m_title );
140 InsertSeparator( 0 );
141 Insert( 0,
new wxMenuItem(
this, wxID_NONE,
m_title, wxEmptyString, wxITEM_NORMAL ) );
154 wxASSERT_MSG( FindItem( aId ) ==
nullptr, wxS(
"Duplicate menu IDs!" ) );
156 wxMenuItem* item =
new wxMenuItem(
this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
161 return Append( item );
166 BITMAPS aIcon,
bool aIsCheckmarkEntry )
168 wxASSERT_MSG( FindItem( aId ) ==
nullptr, wxS(
"Duplicate menu IDs!" ) );
170 wxMenuItem* item =
new wxMenuItem(
this, aId, aLabel, aTooltip, aIsCheckmarkEntry ? wxITEM_CHECK
176 return Append( item );
181 const wxString& aOverrideLabel )
187 wxString menuLabel = aOverrideLabel.IsEmpty() ? aAction.
GetMenuItem() : aOverrideLabel;
189 wxMenuItem* item =
new wxMenuItem(
this, aAction.
GetUIId(), menuLabel, aAction.
GetTooltip(),
190 aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
196 return Append( item );
204 wxASSERT_MSG( !aMenu->
m_title.IsEmpty(), wxS(
"Set a title for ACTION_MENU using SetTitle()" ) );
208 wxMenuItem* newItem =
new wxMenuItem(
this, -1, aMenu->
m_title );
210 newItem->SetSubMenu( aMenu );
211 return Append( newItem );
215 return AppendSubMenu( aMenu, aMenu->
m_title );
224 wxString::Format(
_(
"Close %s" ), aAppname ),
228 Add(
_(
"Close" ) + wxS(
"\tCtrl+W" ),
229 wxString::Format(
_(
"Close %s" ), aAppname ),
238 if( !aKiface || aKiface->
IsSingle() )
242 Add(
_(
"Quit" ) + wxS(
"\tCtrl+Q" ),
243 wxString::Format(
_(
"Quit %s" ), aAppname ),
258 Add(
_(
"Quit" ) + wxS(
"\tCtrl+Q" ),
259 wxString::Format(
_(
"Quit %s" ), aAppname ),
269 for(
int i = GetMenuItemCount() - 1; i >= 0; --i )
270 Destroy( FindItemByPosition( i ) );
275 wxASSERT( GetMenuItemCount() == 0 );
281 for( wxMenuItem* item : GetMenuItems() )
283 if( item->IsEnabled() && !item->IsSeparator() )
297 catch( std::exception& )
342 wxASSERT_MSG(
typeid( *
this ) ==
typeid( *menu ),
343 wxString::Format(
"You need to override create() method for class %s",
typeid( *this ).name() ) );
361 for( std::pair<const int, const TOOL_ACTION*>& ii :
m_toolActions )
371 wxMenuItem* item = FindChildItem(
id );
375 flags |= ( mod &
MD_ALT ) ? wxACCEL_ALT : 0;
376 flags |= ( mod &
MD_CTRL ) ? wxACCEL_CTRL : 0;
377 flags |= ( mod &
MD_SHIFT ) ? wxACCEL_SHIFT : 0;
380 flags = wxACCEL_NORMAL;
382 wxAcceleratorEntry accel( flags, key,
id, item );
383 item->SetAccel( &accel );
418 wxEventType type = aEvent.GetEventType();
419 wxWindow* focus = wxWindow::FindFocus();
422 if( type == wxEVT_MENU_OPEN )
427 wxMenu* parent =
dynamic_cast<wxMenu*
>( GetParent() );
430 if( !parent && !IsAttached() && toolMgr )
435 else if( type == wxEVT_MENU_HIGHLIGHT )
437 if( aEvent.GetId() > 0 )
442 else if( type == wxEVT_COMMAND_MENU_SELECTED )
448 if(
dynamic_cast<wxTextEntry*
>( focus )
449 ||
dynamic_cast<wxStyledTextCtrl*
>( focus )
450 ||
dynamic_cast<wxListView*
>( focus )
451 ||
dynamic_cast<wxGrid*
>( focus ) )
455 wxMenuItem* menuItem = FindItem( aEvent.GetId() );
456 wxAcceleratorEntry* acceleratorKey = menuItem ? menuItem->GetAccel() :
nullptr;
460 wxKeyEvent keyEvent( wxEVT_CHAR_HOOK );
461 keyEvent.m_keyCode = acceleratorKey->GetKeyCode();
462 keyEvent.m_controlDown = ( acceleratorKey->GetFlags() & wxMOD_CONTROL ) > 0;
463 keyEvent.m_shiftDown = ( acceleratorKey->GetFlags() & wxMOD_SHIFT ) > 0;
464 keyEvent.m_altDown = ( acceleratorKey->GetFlags() & wxMOD_ALT ) > 0;
466 if( wxTextEntry* ctrl =
dynamic_cast<wxTextEntry*
>( focus ) )
469 focus->HandleWindowEvent( keyEvent );
471 if( keyEvent.GetSkipped() )
473 keyEvent.SetEventType( wxEVT_CHAR );
474 focus->HandleWindowEvent( keyEvent );
479 if( keyEvent.GetKeyCode() == WXK_BACK || keyEvent.GetKeyCode() == WXK_DELETE )
485 if( !keyEvent.GetSkipped() )
498 parent =
dynamic_cast<ACTION_MENU*
>( parent->GetParent() );
511 wxMenu* menu =
nullptr;
530 #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST
538 menuText = GetHelpString( aEvent.GetId() );
540 menuText = GetLabelText( aEvent.GetId() );
543 evt->SetParameter( &menuText );
569 evt->SetHasPosition(
false );
604 m->runOnSubmenus( aFunction );
607 catch( std::exception& )
623 const auto it = m->m_toolActions.find( aId );
625 if( it != m->m_toolActions.end() )
626 evt = it->second->MakeEvent();
648 for(
int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
650 wxMenuItem* item = aMenu.FindItemByPosition( i );
658 wxMenuItem* newItem =
new wxMenuItem(
this, aSource->GetId(), aSource->GetItemLabel(),
659 aSource->GetHelp(), aSource->GetKind() );
666#if defined( __WXMSW__ )
670 bool use_checked_bm = ( aSource->GetKind() == wxITEM_CHECK ||
671 aSource->GetKind() == wxITEM_RADIO ) ? false :
true;
672 const wxBitmap& src_bitmap = aSource->GetBitmap( use_checked_bm );
674 const wxBitmap& src_bitmap = aSource->GetBitmap();
677 if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 )
680 if( aSource->IsSubMenu() )
683 wxASSERT_MSG( menu, wxS(
"Submenus are expected to be a ACTION_MENU" ) );
688 newItem->SetSubMenu( menuCopy );
696 if( aSource->IsCheckable() )
697 newItem->Check( aSource->IsChecked() );
699 newItem->Enable( aSource->IsEnabled() );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
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.
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.
VECTOR2< double > VECTOR2D