26#include <wx/listctrl.h>
28#include <wx/textentry.h>
29#include <wx/stc/stc.h>
44using namespace std::placeholders;
66 for(
auto subitem : GetMenuItems() )
67 subitem->SetBitmap( wxNullBitmap );
72 for(
auto menuItem : GetMenuItems() )
73 menuItem->SetBitmap( wxNullBitmap );
75 menu->SetParent(
nullptr );
114 wxMenuItem* item = FindItemByPosition( 0 );
115 wxASSERT( item->GetItemLabelText() ==
GetTitle() );
116 item->SetBitmap( wxNullBitmap );
120 item = FindItemByPosition( 0 );
121 wxASSERT( item->IsSeparator() );
126 else if( aDisplay && !
m_title.IsEmpty() )
131 FindItemByPosition( 0 )->SetItemLabel(
m_title );
136 InsertSeparator( 0 );
137 Insert( 0,
new wxMenuItem(
this, wxID_NONE,
m_title, wxEmptyString, wxITEM_NORMAL ) );
150 wxASSERT_MSG( FindItem( aId ) ==
nullptr, wxS(
"Duplicate menu IDs!" ) );
152 wxMenuItem* item =
new wxMenuItem(
this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
157 return Append( item );
162 BITMAPS aIcon,
bool aIsCheckmarkEntry )
164 wxASSERT_MSG( FindItem( aId ) ==
nullptr, wxS(
"Duplicate menu IDs!" ) );
166 wxMenuItem* item =
new wxMenuItem(
this, aId, aLabel, aTooltip, aIsCheckmarkEntry ? wxITEM_CHECK
172 return Append( item );
177 const wxString& aOverrideLabel )
183 wxString menuLabel = aOverrideLabel.IsEmpty() ? aAction.
GetMenuItem() : aOverrideLabel;
185 wxMenuItem* item =
new wxMenuItem(
this, aAction.
GetUIId(), menuLabel, aAction.
GetTooltip(),
186 aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
192 return Append( item );
200 wxASSERT_MSG( !aMenu->
m_title.IsEmpty(), wxS(
"Set a title for ACTION_MENU using SetTitle()" ) );
204 wxMenuItem* newItem =
new wxMenuItem(
this, -1, aMenu->
m_title );
206 newItem->SetSubMenu( aMenu );
207 return Append( newItem );
211 return AppendSubMenu( aMenu, aMenu->
m_title );
220 wxString::Format(
_(
"Close %s" ), aAppname ),
224 Add(
_(
"Close" ) + wxS(
"\tCtrl+W" ),
225 wxString::Format(
_(
"Close %s" ), aAppname ),
234 if( !aKiface || aKiface->
IsSingle() )
238 Add(
_(
"Quit" ) + wxS(
"\tCtrl+Q" ),
239 wxString::Format(
_(
"Quit %s" ), aAppname ),
254 Add(
_(
"Quit" ) + wxS(
"\tCtrl+Q" ),
255 wxString::Format(
_(
"Quit %s" ), aAppname ),
265 for(
int i = GetMenuItemCount() - 1; i >= 0; --i )
266 Destroy( FindItemByPosition( i ) );
271 wxASSERT( GetMenuItemCount() == 0 );
277 for( wxMenuItem* item : GetMenuItems() )
279 if( item->IsEnabled() && !item->IsSeparator() )
293 catch( std::exception& )
338 wxASSERT_MSG(
typeid( *
this ) ==
typeid( *menu ),
339 wxString::Format(
"You need to override create() method for class %s",
typeid( *this ).name() ) );
357 for( std::pair<const int, const TOOL_ACTION*>& ii :
m_toolActions )
367 wxMenuItem* item = FindChildItem(
id );
371 flags |= ( mod &
MD_ALT ) ? wxACCEL_ALT : 0;
372 flags |= ( mod &
MD_CTRL ) ? wxACCEL_CTRL : 0;
373 flags |= ( mod &
MD_SHIFT ) ? wxACCEL_SHIFT : 0;
376 flags = wxACCEL_NORMAL;
378 wxAcceleratorEntry accel( flags, key,
id, item );
379 item->SetAccel( &accel );
414 wxEventType type = aEvent.GetEventType();
415 wxWindow* focus = wxWindow::FindFocus();
418 if( type == wxEVT_MENU_OPEN )
423 wxMenu* parent =
dynamic_cast<wxMenu*
>( GetParent() );
426 if( !parent && !IsAttached() && toolMgr )
431 else if( type == wxEVT_MENU_HIGHLIGHT )
433 if( aEvent.GetId() > 0 )
438 else if( type == wxEVT_COMMAND_MENU_SELECTED )
444 if(
dynamic_cast<wxTextEntry*
>( focus )
445 ||
dynamic_cast<wxStyledTextCtrl*
>( focus )
446 ||
dynamic_cast<wxListView*
>( focus )
447 ||
dynamic_cast<wxGrid*
>( focus ) )
451 wxMenuItem* menuItem = FindItem( aEvent.GetId() );
452 wxAcceleratorEntry* acceleratorKey = menuItem ? menuItem->GetAccel() :
nullptr;
456 wxKeyEvent keyEvent( wxEVT_CHAR_HOOK );
457 keyEvent.m_keyCode = acceleratorKey->GetKeyCode();
458 keyEvent.m_controlDown = ( acceleratorKey->GetFlags() & wxMOD_CONTROL ) > 0;
459 keyEvent.m_shiftDown = ( acceleratorKey->GetFlags() & wxMOD_SHIFT ) > 0;
460 keyEvent.m_altDown = ( acceleratorKey->GetFlags() & wxMOD_ALT ) > 0;
462 if( wxTextEntry* ctrl =
dynamic_cast<wxTextEntry*
>( focus ) )
465 focus->HandleWindowEvent( keyEvent );
467 if( keyEvent.GetSkipped() )
469 keyEvent.SetEventType( wxEVT_CHAR );
475 int keyCode = keyEvent.GetKeyCode();
477 if( keyCode >=
'A' && keyCode <=
'Z' )
479 bool shiftActive = wxGetKeyState( WXK_SHIFT );
480 bool capsActive = wxGetKeyState( WXK_CAPITAL );
482 if( !( shiftActive ^ capsActive ) )
483 keyEvent.m_keyCode = keyCode + 32;
487 keyEvent.m_uniChar = keyEvent.m_keyCode;
490 focus->HandleWindowEvent( keyEvent );
495 if( keyEvent.GetKeyCode() == WXK_BACK || keyEvent.GetKeyCode() == WXK_DELETE )
501 if( !keyEvent.GetSkipped() )
514 parent =
dynamic_cast<ACTION_MENU*
>( parent->GetParent() );
527 wxMenu* menu =
nullptr;
546 #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST
554 menuText = GetHelpString( aEvent.GetId() );
556 menuText = GetLabelText( aEvent.GetId() );
559 evt->SetParameter( &menuText );
585 evt->SetHasPosition(
false );
620 m->runOnSubmenus( aFunction );
623 catch( std::exception& )
639 const auto it = m->m_toolActions.find( aId );
641 if( it != m->m_toolActions.end() )
642 evt = it->second->MakeEvent();
664 for(
int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
666 wxMenuItem* item = aMenu.FindItemByPosition( i );
674 wxMenuItem* newItem =
new wxMenuItem(
this, aSource->GetId(), aSource->GetItemLabel(),
675 aSource->GetHelp(), aSource->GetKind() );
682#if defined( __WXMSW__ )
686 bool use_checked_bm = ( aSource->GetKind() == wxITEM_CHECK ||
687 aSource->GetKind() == wxITEM_RADIO ) ? false :
true;
688 const wxBitmap& src_bitmap = aSource->GetBitmap( use_checked_bm );
690 const wxBitmap& src_bitmap = aSource->GetBitmap();
693 if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 )
696 if( aSource->IsSubMenu() )
699 wxASSERT_MSG( menu, wxS(
"Submenus are expected to be a ACTION_MENU" ) );
704 newItem->SetSubMenu( menuCopy );
712 if( aSource->IsCheckable() )
713 newItem->Check( aSource->IsChecked() );
715 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