39 #include <wx/stc/stc.h> 41 #include <wx/listctrl.h> 43 using namespace std::placeholders;
48 m_titleDisplayed( false ),
49 m_isContextMenu( isContextMenu ),
62 menu->SetParent(
nullptr );
64 ACTION_MENU* parent = dynamic_cast<ACTION_MENU*>( GetParent() );
105 wxMenuItem* item = FindItemByPosition( 0 );
106 wxASSERT( item->GetItemLabelText() == GetTitle() );
109 item = FindItemByPosition( 0 );
110 wxASSERT( item->IsSeparator() );
115 else if( aDisplay && !
m_title.IsEmpty() )
120 FindItemByPosition( 0 )->SetItemLabel(
m_title );
125 InsertSeparator( 0 );
126 Insert( 0,
new wxMenuItem(
this, wxID_NONE,
m_title, wxEmptyString, wxITEM_NORMAL ) );
139 wxASSERT_MSG( FindItem( aId ) ==
nullptr,
"Duplicate menu IDs!" );
141 wxMenuItem* item =
new wxMenuItem(
this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
146 return Append( item );
153 wxASSERT_MSG( FindItem( aId ) ==
nullptr,
"Duplicate menu IDs!" );
155 wxMenuItem* item =
new wxMenuItem(
this, aId, aLabel, aTooltip,
156 aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
161 return Append( item );
172 aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
178 return Append( item );
187 wxASSERT_MSG( !menuCopy->
m_title.IsEmpty(),
"Set a title for ACTION_MENU using SetTitle()" );
191 wxMenuItem* newItem =
new wxMenuItem(
this, -1, menuCopy->
m_title );
193 newItem->SetSubMenu( menuCopy );
194 return Append( newItem );
198 return AppendSubMenu( menuCopy, menuCopy->
m_title );
205 Add(
_(
"Close" ) +
"\tCtrl+W",
214 if( !aKiface || aKiface->
IsSingle() )
234 for(
int i = GetMenuItemCount() - 1; i >= 0; --i )
235 Destroy( FindItemByPosition( i ) );
240 wxASSERT( GetMenuItemCount() == 0 );
246 bool hasEnabled =
false;
248 auto& items = GetMenuItems();
250 for(
auto item : items )
252 if( item->IsEnabled() && !item->IsSeparator() )
269 catch( std::exception& )
314 wxASSERT_MSG(
typeid( *
this ) ==
typeid( *menu ),
315 wxString::Format(
"You need to override create() method for class %s",
typeid(*this).name() ) );
342 wxMenuItem* item = FindChildItem(
id );
346 flags |= ( mod &
MD_ALT ) ? wxACCEL_ALT : 0;
347 flags |= ( mod &
MD_CTRL ) ? wxACCEL_CTRL : 0;
348 flags |= ( mod &
MD_SHIFT ) ? wxACCEL_SHIFT : 0;
351 flags = wxACCEL_NORMAL;
353 wxAcceleratorEntry accel( flags, key,
id, item );
354 item->SetAccel( &accel );
388 wxEventType type = aEvent.GetEventType();
389 wxWindow* focus = wxWindow::FindFocus();
391 if( type == wxEVT_MENU_OPEN )
396 wxMenu* parent = dynamic_cast<wxMenu*>( GetParent() );
404 else if( type == wxEVT_MENU_HIGHLIGHT )
406 if( aEvent.GetId() > 0 )
411 else if( type == wxEVT_COMMAND_MENU_SELECTED )
417 if( dynamic_cast<wxTextEntry*>( focus )
418 || dynamic_cast<wxStyledTextCtrl*>( focus )
419 || dynamic_cast<wxListView*>( focus ) )
423 wxMenuItem* menuItem = FindItem( aEvent.GetId() );
424 wxAcceleratorEntry* acceleratorKey = menuItem ? menuItem->GetAccel() :
nullptr;
428 wxKeyEvent keyEvent( wxEVT_CHAR_HOOK );
429 keyEvent.m_keyCode = acceleratorKey->GetKeyCode();
430 keyEvent.m_controlDown = ( acceleratorKey->GetFlags() & wxMOD_CONTROL ) > 0;
431 keyEvent.m_shiftDown = ( acceleratorKey->GetFlags() & wxMOD_SHIFT ) > 0;
432 keyEvent.m_altDown = ( acceleratorKey->GetFlags() & wxMOD_ALT ) > 0;
434 if(
auto ctrl = dynamic_cast<wxTextEntry*>( focus ) )
437 focus->HandleWindowEvent( keyEvent );
439 if( keyEvent.GetSkipped() )
441 keyEvent.SetEventType( wxEVT_CHAR );
442 focus->HandleWindowEvent( keyEvent );
449 if( !keyEvent.GetSkipped() )
457 ACTION_MENU* parent = dynamic_cast<ACTION_MENU*>( GetParent() );
462 parent = dynamic_cast<ACTION_MENU*>( parent->GetParent() );
475 wxMenu* menu =
nullptr;
484 #if wxCHECK_VERSION(3, 1, 2) 487 if( menu && menu !=
this )
490 ACTION_MENU* cxmenu = static_cast<ACTION_MENU*>( menu );
503 #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST 509 ACTION_MENU* actionMenu = dynamic_cast<ACTION_MENU*>( GetParent() );
512 menuText = GetHelpString( aEvent.GetId() );
514 menuText = GetLabelText( aEvent.GetId() );
542 evt->SetHasPosition(
false );
576 m->runOnSubmenus( aFunction );
579 catch( std::exception& )
593 const auto it = m->m_toolActions.find( aId );
595 if( it != m->m_toolActions.end() )
596 evt = it->second->MakeEvent();
618 for(
int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
620 wxMenuItem* item = aMenu.FindItemByPosition( i );
628 wxMenuItem* newItem =
new wxMenuItem(
this, aSource->GetId(), aSource->GetItemLabel(),
629 aSource->GetHelp(), aSource->GetKind() );
639 bool use_checked_bm = ( aSource->GetKind() == wxITEM_CHECK || aSource->GetKind() == wxITEM_RADIO ) ?
false :
true;
640 const wxBitmap& src_bitmap = aSource->GetBitmap( use_checked_bm );
642 const wxBitmap& src_bitmap = aSource->GetBitmap();
645 if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 )
648 if( aSource->IsSubMenu() )
650 ACTION_MENU* menu = dynamic_cast<ACTION_MENU*>( aSource->GetSubMenu() );
651 wxASSERT_MSG( menu,
"Submenus are expected to be a ACTION_MENU" );
656 newItem->SetSubMenu( menuCopy );
664 if( aSource->IsCheckable() )
665 newItem->Check( aSource->IsChecked() );
667 newItem->Enable( aSource->IsEnabled() );
A KIFACE (I)mplementation.
PNG memory record (file in memory).
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
bool IsSingle() const
Is this KIFACE_I running under single_top?
const BITMAP_OPAQUE exit_xpm[1]
Base window classes and related definitions.
wxLogTrace helper definitions.
static TOOL_ACTION updateMenu
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
static void OnCharHook(wxTextEntry *aTextEntry, wxKeyEvent &aEvent)
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.