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() );
112 item = FindItemByPosition( 0 );
113 wxASSERT( item->IsSeparator() );
118 else if( aDisplay && !
m_title.IsEmpty() )
123 FindItemByPosition( 0 )->SetItemLabel(
m_title );
128 InsertSeparator( 0 );
129 Insert( 0,
new wxMenuItem(
this, wxID_NONE,
m_title, wxEmptyString, wxITEM_NORMAL ) );
142 wxASSERT_MSG( FindItem( aId ) ==
nullptr, wxS(
"Duplicate menu IDs!" ) );
144 wxMenuItem* item =
new wxMenuItem(
this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
149 return Append( item );
154 BITMAPS aIcon,
bool aIsCheckmarkEntry )
156 wxASSERT_MSG( FindItem( aId ) ==
nullptr, wxS(
"Duplicate menu IDs!" ) );
158 wxMenuItem* item =
new wxMenuItem(
this, aId, aLabel, aTooltip,
159 aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
164 return Append( item );
169 const wxString& aOverrideLabel )
175 wxString menuLabel = aOverrideLabel.IsEmpty() ? aAction.
GetMenuItem() : aOverrideLabel;
177 wxMenuItem* item =
new wxMenuItem(
this, aAction.
GetUIId(), menuLabel,
179 aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
185 return Append( item );
193 wxASSERT_MSG( !aMenu->
m_title.IsEmpty(), wxS(
"Set a title for ACTION_MENU using SetTitle()" ) );
197 wxMenuItem* newItem =
new wxMenuItem(
this, -1, aMenu->
m_title );
199 newItem->SetSubMenu( aMenu );
200 return Append( newItem );
204 return AppendSubMenu( aMenu, aMenu->
m_title );
213 wxString::Format(
_(
"Close %s" ), aAppname ),
217 Add(
_(
"Close" ) + wxS(
"\tCtrl+W" ),
218 wxString::Format(
_(
"Close %s" ), aAppname ),
227 if( !aKiface || aKiface->
IsSingle() )
231 Add(
_(
"Quit" ) + wxS(
"\tCtrl+Q" ),
232 wxString::Format(
_(
"Quit %s" ), aAppname ),
247 Add(
_(
"Quit" ) + wxS(
"\tCtrl+Q" ),
248 wxString::Format(
_(
"Quit %s" ), aAppname ),
258 for(
int i = GetMenuItemCount() - 1; i >= 0; --i )
259 Destroy( FindItemByPosition( i ) );
264 wxASSERT( GetMenuItemCount() == 0 );
270 for( wxMenuItem* item : GetMenuItems() )
272 if( item->IsEnabled() && !item->IsSeparator() )
286 catch( std::exception& )
331 wxASSERT_MSG(
typeid( *
this ) ==
typeid( *menu ),
332 wxString::Format(
"You need to override create() method for class %s",
333 typeid( *this ).name() ) );
351 for( std::pair<const int, const TOOL_ACTION*>& ii :
m_toolActions )
355 int key = toolMgr->
GetHotKey( action ) & ~MD_MODIFIER_MASK;
361 wxMenuItem* item = FindChildItem(
id );
365 flags |= ( mod &
MD_ALT ) ? wxACCEL_ALT : 0;
366 flags |= ( mod &
MD_CTRL ) ? wxACCEL_CTRL : 0;
367 flags |= ( mod &
MD_SHIFT ) ? wxACCEL_SHIFT : 0;
370 flags = wxACCEL_NORMAL;
372 wxAcceleratorEntry accel( flags, key,
id, item );
373 item->SetAccel( &accel );
408 wxEventType type = aEvent.GetEventType();
409 wxWindow* focus = wxWindow::FindFocus();
412 if( type == wxEVT_MENU_OPEN )
417 wxMenu* parent =
dynamic_cast<wxMenu*
>( GetParent() );
420 if( !parent && !IsAttached() && toolMgr )
425 else if( type == wxEVT_MENU_HIGHLIGHT )
427 if( aEvent.GetId() > 0 )
432 else if( type == wxEVT_COMMAND_MENU_SELECTED )
438 if(
dynamic_cast<wxTextEntry*
>( focus )
439 ||
dynamic_cast<wxStyledTextCtrl*
>( focus )
440 ||
dynamic_cast<wxListView*
>( focus )
441 ||
dynamic_cast<wxGrid*
>( focus ) )
445 wxMenuItem* menuItem = FindItem( aEvent.GetId() );
446 wxAcceleratorEntry* acceleratorKey = menuItem ? menuItem->GetAccel() :
nullptr;
450 wxKeyEvent keyEvent( wxEVT_CHAR_HOOK );
451 keyEvent.m_keyCode = acceleratorKey->GetKeyCode();
452 keyEvent.m_controlDown = ( acceleratorKey->GetFlags() & wxMOD_CONTROL ) > 0;
453 keyEvent.m_shiftDown = ( acceleratorKey->GetFlags() & wxMOD_SHIFT ) > 0;
454 keyEvent.m_altDown = ( acceleratorKey->GetFlags() & wxMOD_ALT ) > 0;
456 if( wxTextEntry* ctrl =
dynamic_cast<wxTextEntry*
>( focus ) )
459 focus->HandleWindowEvent( keyEvent );
461 if( keyEvent.GetSkipped() )
463 keyEvent.SetEventType( wxEVT_CHAR );
464 focus->HandleWindowEvent( keyEvent );
469 if( keyEvent.GetKeyCode() == WXK_BACK || keyEvent.GetKeyCode() == WXK_DELETE )
475 if( !keyEvent.GetSkipped() )
488 parent =
dynamic_cast<ACTION_MENU*
>( parent->GetParent() );
501 wxMenu* menu =
nullptr;
520 #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST
529 menuText = GetHelpString( aEvent.GetId() );
531 menuText = GetLabelText( aEvent.GetId() );
534 evt->SetParameter( &menuText );
560 evt->SetHasPosition(
false );
595 m->runOnSubmenus( aFunction );
598 catch( std::exception& )
614 const auto it = m->m_toolActions.find( aId );
616 if( it != m->m_toolActions.end() )
617 evt = it->second->MakeEvent();
639 for(
int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
641 wxMenuItem* item = aMenu.FindItemByPosition( i );
649 wxMenuItem* newItem =
new wxMenuItem(
this, aSource->GetId(), aSource->GetItemLabel(),
650 aSource->GetHelp(), aSource->GetKind() );
656#if defined( __WXMSW__ )
660 bool use_checked_bm = ( aSource->GetKind() == wxITEM_CHECK ||
661 aSource->GetKind() == wxITEM_RADIO ) ?
false :
true;
662 const wxBitmap& src_bitmap = aSource->GetBitmap( use_checked_bm );
664 const wxBitmap& src_bitmap = aSource->GetBitmap();
667 if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 )
670 if( aSource->IsSubMenu() )
673 wxASSERT_MSG( menu, wxS(
"Submenus are expected to be a ACTION_MENU" ) );
678 newItem->SetSubMenu( menuCopy );
686 if( aSource->IsCheckable() )
687 newItem->Check( aSource->IsChecked() );
689 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.
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.