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 648 of file dialog_shim.cpp.

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

References _, and recursiveDescent().

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

◆ selectAllInTextCtrls()

static void selectAllInTextCtrls ( wxWindowList &  children)
static

Definition at line 328 of file dialog_shim.cpp.

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