KiCad PCB EDA Suite
dialog_shim.cpp File Reference
#include <dialog_shim.h>
#include <ignore.h>
#include <kiway_player.h>
#include <kiway.h>
#include <pgm_base.h>
#include <tool/tool_manager.h>
#include <kiplatform/ui.h>
#include <wx/display.h>
#include <wx/evtloop.h>
#include <wx/app.h>
#include <wx/event.h>
#include <wx/grid.h>
#include <wx/bmpbuttn.h>
#include <wx/textctrl.h>
#include <wx/stc/stc.h>
#include <algorithm>
#include <hashtables.h>
#include <typeinfo>

Go to the source code of this file.

Classes

class  WDO_ENABLE_DISABLE
 Toggle a window's "enable" status to disabled, then enabled on destruction. More...
 

Functions

static void selectAllInTextCtrls (wxWindowList &children)
 
static void recursiveDescent (wxSizer *aSizer, std::map< int, wxString > &aLabels)
 

Variables

static std::unordered_map< std::string, wxRect > class_map
 

Function Documentation

◆ recursiveDescent()

static void recursiveDescent ( wxSizer *  aSizer,
std::map< int, wxString > &  aLabels 
)
static

Definition at line 649 of file dialog_shim.cpp.

650{
651 wxStdDialogButtonSizer* sdbSizer = dynamic_cast<wxStdDialogButtonSizer*>( aSizer );
652
653 auto setupButton =
654 [&]( wxButton* aButton )
655 {
656 if( aLabels.count( aButton->GetId() ) > 0 )
657 {
658 aButton->SetLabel( aLabels[ aButton->GetId() ] );
659 }
660 else
661 {
662 // wxWidgets has an uneven track record when the language is changed on
663 // the fly so we set them even when they don't appear in the label map
664 switch( aButton->GetId() )
665 {
666 case wxID_OK: aButton->SetLabel( _( "&OK" ) ); break;
667 case wxID_CANCEL: aButton->SetLabel( _( "&Cancel" ) ); break;
668 case wxID_YES: aButton->SetLabel( _( "&Yes" ) ); break;
669 case wxID_NO: aButton->SetLabel( _( "&No" ) ); break;
670 case wxID_APPLY: aButton->SetLabel( _( "&Apply" ) ); break;
671 case wxID_SAVE: aButton->SetLabel( _( "&Save" ) ); break;
672 case wxID_HELP: aButton->SetLabel( _( "&Help" ) ); break;
673 case wxID_CONTEXT_HELP: aButton->SetLabel( _( "&Help" ) ); break;
674 }
675 }
676 };
677
678 if( sdbSizer )
679 {
680 if( sdbSizer->GetAffirmativeButton() )
681 setupButton( sdbSizer->GetAffirmativeButton() );
682
683 if( sdbSizer->GetApplyButton() )
684 setupButton( sdbSizer->GetApplyButton() );
685
686 if( sdbSizer->GetNegativeButton() )
687 setupButton( sdbSizer->GetNegativeButton() );
688
689 if( sdbSizer->GetCancelButton() )
690 setupButton( sdbSizer->GetCancelButton() );
691
692 if( sdbSizer->GetHelpButton() )
693 setupButton( sdbSizer->GetHelpButton() );
694
695 sdbSizer->Layout();
696
697 if( sdbSizer->GetAffirmativeButton() )
698 sdbSizer->GetAffirmativeButton()->SetDefault();
699 }
700
701 for( wxSizerItem* item : aSizer->GetChildren() )
702 {
703 if( item->GetSizer() )
704 recursiveDescent( item->GetSizer(), aLabels );
705 }
706}
static void recursiveDescent(wxSizer *aSizer, std::map< int, wxString > &aLabels)
#define _(s)

References _, and recursiveDescent().

Referenced by recursiveDescent(), DIALOG_SHIM::SetupStandardButtons(), and HIERARCHY_NAVIG_PANEL::UpdateHierarchySelection().

◆ selectAllInTextCtrls()

static void selectAllInTextCtrls ( wxWindowList &  children)
static

Definition at line 329 of file dialog_shim.cpp.

330{
331 for( wxWindow* child : children )
332 {
333 if( wxTextCtrl* childTextCtrl = dynamic_cast<wxTextCtrl*>( child ) )
334 {
335 // We don't currently run this on GTK because some window managers don't hide the
336 // selection in non-active controls, and other window managers do the selection
337 // automatically anyway.
338#if defined( __WXMAC__ ) || defined( __WXMSW__ )
339 if( !childTextCtrl->GetStringSelection().IsEmpty() )
340 {
341 // Respect an existing selection
342 }
343 else
344 {
345 childTextCtrl->SelectAll();
346 }
347#else
348 ignore_unused( childTextCtrl );
349#endif
350 }
351 else if( wxStyledTextCtrl* scintilla = dynamic_cast<wxStyledTextCtrl*>( child ) )
352 {
353 if( !scintilla->GetSelectedText().IsEmpty() )
354 {
355 // Respect an existing selection
356 }
357 else
358 {
359 scintilla->SelectAll();
360 }
361 }
362#ifdef __WXMAC__
363 // Temp hack for square (looking) buttons on OSX. Will likely be made redundant
364 // by the image store....
365 else if( dynamic_cast<wxBitmapButton*>( child ) != nullptr )
366 {
367 wxSize minSize( 29, 27 );
368 wxRect rect = child->GetRect();
369
370 child->ConvertDialogToPixels( minSize );
371
372 rect.Inflate( std::max( 0, minSize.x - rect.GetWidth() ),
373 std::max( 0, minSize.y - rect.GetHeight() ) );
374
375 child->SetMinSize( rect.GetSize() );
376 child->SetSize( rect );
377 }
378#endif
379 else
380 {
381 selectAllInTextCtrls( child->GetChildren() );
382 }
383 }
384}
static void selectAllInTextCtrls(wxWindowList &children)
const int minSize
Push and Shove router track width and via size dialog.
void ignore_unused(const T &)
Definition: ignore.h:24

References ignore_unused(), minSize, and selectAllInTextCtrls().

Referenced by DIALOG_SHIM::OnPaint(), and selectAllInTextCtrls().

Variable Documentation

◆ class_map

std::unordered_map<std::string, wxRect> class_map
static