33#include <wx/display.h>
34#include <wx/evtloop.h>
38#include <wx/bmpbuttn.h>
39#include <wx/textctrl.h>
40#include <wx/stc/stc.h>
79 const wxPoint& pos, const wxSize& size,
long style,
80 const wxString&
name ) :
81 wxDialog( aParent,
id, title, pos, size, style,
name ),
84 m_useCalculatedSize( false ),
85 m_firstPaintEvent( true ),
86 m_initialFocusTarget(
nullptr ),
87 m_qmodal_loop(
nullptr ),
88 m_qmodal_showing( false ),
89 m_qmodal_parent_disabler(
nullptr ),
90 m_parentFrame(
nullptr )
99 while( !kiwayHolder && aParent->GetParent() )
101 aParent = aParent->GetParent();
116 TOOL_MANAGER* toolMgr = m_parentFrame->GetToolManager();
124 SetKiway(
this, &kiwayHolder->
Kiway() );
164 GetSizer()->SetSizeHints(
this );
171 SetSize( ConvertDialogToPixels( sz ) );
178 return ConvertDialogToPixels( sz ).x;
185 return ConvertDialogToPixels( sz ).y;
193static std::unordered_map<std::string, wxRect>
class_map;
201 const char* hash_key;
210 hash_key =
typeid(*this).name();
213 std::unordered_map<std::string, wxRect>::iterator it =
class_map.find( hash_key );
218 wxRect rect = it->second;
219 rect.SetPosition( aNewPosition );
228 const char* hash_key;
237 hash_key =
typeid(*this).name();
247 ret = wxDialog::Show( show );
250 wxRect savedDialogRect =
class_map[ hash_key ];
252 if( savedDialogRect.GetSize().x != 0 && savedDialogRect.GetSize().y != 0 )
256 SetSize( savedDialogRect.GetPosition().x, savedDialogRect.GetPosition().y,
257 wxDialog::GetSize().x, wxDialog::GetSize().y, 0 );
261 SetSize( savedDialogRect.GetPosition().x, savedDialogRect.GetPosition().y,
262 std::max( wxDialog::GetSize().x, savedDialogRect.GetSize().x ),
263 std::max( wxDialog::GetSize().y, savedDialogRect.GetSize().y ),
273 if( wxDisplay::GetFromWindow(
this ) == wxNOT_FOUND )
279 class_map[ hash_key ] = wxRect( wxDialog::GetPosition(), wxDialog::GetSize() );
283 m_eventLoop->Exit( GetReturnCode() );
286 ret = wxDialog::Show( show );
295 const char* hash_key;
304 hash_key =
typeid(*this).name();
307 std::unordered_map<std::string, wxRect>::iterator it =
class_map.find( hash_key );
312 wxRect rect = it->second;
313 rect.SetSize( wxSize( 0, 0 ) );
321 return wxDialog::Enable( enable );
330 for( wxWindow* child : children )
332 if( wxTextCtrl* childTextCtrl =
dynamic_cast<wxTextCtrl*
>( child ) )
337#if defined( __WXMAC__ ) || defined( __WXMSW__ )
338 if( !childTextCtrl->GetStringSelection().IsEmpty() )
344 childTextCtrl->SelectAll();
350 else if( wxStyledTextCtrl* scintilla =
dynamic_cast<wxStyledTextCtrl*
>( child ) )
352 if( !scintilla->GetSelectedText().IsEmpty() )
356 else if( !scintilla->GetText().Contains( wxT(
"\n") ) )
358 scintilla->SelectAll();
364 else if(
dynamic_cast<wxBitmapButton*
>( child ) !=
nullptr )
367 wxRect rect = child->GetRect();
369 child->ConvertDialogToPixels(
minSize );
371 rect.Inflate( std::max( 0,
minSize.x - rect.GetWidth() ),
372 std::max( 0,
minSize.y - rect.GetHeight() ) );
374 child->SetMinSize( rect.GetSize() );
375 child->SetSize( rect );
408 if( !GetTitle().StartsWith( wxS(
"*" ) ) )
409 SetTitle( wxS(
"*" ) + GetTitle() );
444 NULLER(
void*& aPtr ) : m_what( aPtr ) {}
445 ~NULLER() { m_what =
nullptr; }
451 wxWindow* win = wxWindow::GetCapture();
456 wxWindow* parent = GetParentForModalDialog( GetParent(), GetWindowStyle() );
482 return GetReturnCode();
490 if( ( retCode == wxID_OK ) && ( !Validate() || !TransferDataFromWindow() ) )
493 SetReturnCode( retCode );
497 wxFAIL_MSG( wxT(
"Either DIALOG_SHIM::EndQuasiModal was called twice, or ShowQuasiModal"
534 const int id = aEvent.GetId();
538 if(
id == wxID_CANCEL )
539 SetEscapeId( wxID_ANY );
543 if(
id == GetAffirmativeId() )
547 else if(
id == wxID_APPLY )
558 else if(
id == GetEscapeId() || (
id == wxID_CANCEL && GetEscapeId() == wxID_ANY) )
577 if( aEvt.GetKeyCode() ==
'U' && aEvt.GetModifiers() == wxMOD_CONTROL )
586 else if( aEvt.GetKeyCode() == WXK_RETURN && ( aEvt.ShiftDown() || aEvt.ControlDown() ) )
588 wxPostEvent(
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
591 else if( aEvt.GetKeyCode() == WXK_TAB && !aEvt.ControlDown() )
593 wxWindow* currentWindow = wxWindow::FindFocus();
595 int delta = aEvt.ShiftDown() ? -1 : 1;
602 idx = ( ( idx +
delta ) % size + size ) % size;
605 for(
size_t i = 0; i <
m_tabOrder.size(); ++i )
609 currentIdx = (int) i;
614 if( currentIdx >= 0 )
616 advance( currentIdx );
621 while(
dynamic_cast<wxTextEntry*
>(
m_tabOrder[ currentIdx ] ) ==
nullptr )
622 advance( currentIdx );
636 SetEscapeId( wxID_NONE );
643 SetEscapeId( wxID_ANY );
650 wxStdDialogButtonSizer* sdbSizer =
dynamic_cast<wxStdDialogButtonSizer*
>( aSizer );
653 [&]( wxButton* aButton )
655 if( aLabels.count( aButton->GetId() ) > 0 )
657 aButton->SetLabel( aLabels[ aButton->GetId() ] );
663 switch( aButton->GetId() )
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;
679 if( sdbSizer->GetAffirmativeButton() )
680 setupButton( sdbSizer->GetAffirmativeButton() );
682 if( sdbSizer->GetApplyButton() )
683 setupButton( sdbSizer->GetApplyButton() );
685 if( sdbSizer->GetNegativeButton() )
686 setupButton( sdbSizer->GetNegativeButton() );
688 if( sdbSizer->GetCancelButton() )
689 setupButton( sdbSizer->GetCancelButton() );
691 if( sdbSizer->GetHelpButton() )
692 setupButton( sdbSizer->GetHelpButton() );
696 if( sdbSizer->GetAffirmativeButton() )
697 sdbSizer->GetAffirmativeButton()->SetDefault();
700 for( wxSizerItem* item : aSizer->GetChildren() )
702 if( item->GetSizer() )
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
std::vector< wxWindow * > m_tabOrder
void OnPaint(wxPaintEvent &event)
int vertPixelsFromDU(int y) const
Convert an integer number of dialog units to pixels, vertically.
bool Show(bool show) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
int horizPixelsFromDU(int x) const
Convert an integer number of dialog units to pixels, horizontally.
void resetSize()
Clear the existing dialog size and position.
void setSizeInDU(int x, int y)
Set the dialog to the given dimensions in "dialog units".
bool IsQuasiModal() const
void OnGridEditorShown(wxGridEvent &event)
WDO_ENABLE_DISABLE * m_qmodal_parent_disabler
void EndQuasiModal(int retCode)
void OnButton(wxCommandEvent &aEvent)
Properly handle the default button events when in the quasimodal mode when not calling EndQuasiModal ...
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
wxWindow * m_initialFocusTarget
bool Enable(bool enable) override
void SetPosition(const wxPoint &aNewPosition)
Force the position of the dialog to a new position.
void OnCloseWindow(wxCloseEvent &aEvent)
Properly handle the wxCloseEvent when in the quasimodal mode when not calling EndQuasiModal which is ...
EDA_BASE_FRAME * m_parentFrame
virtual void OnCharHook(wxKeyEvent &aEvt)
void OnGridEditorHidden(wxGridEvent &event)
EDA_UNITS GetUserUnits() const
WX_EVENT_LOOP * m_qmodal_loop
The base frame for deriving all KiCad main window classes.
virtual void ToggleUserUnits()
A mix in class which holds the location of a wxWindow's KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
bool HasKiway() const
Safety check before asking for the Kiway reference.
HOLDER_TYPE GetType() const
void SetBlockingDialog(wxWindow *aWin)
EDA_UNITS GetUserUnits() const
Toggle a window's "enable" status to disabled, then enabled on destruction.
WDO_ENABLE_DISABLE(wxWindow *aWindow)
static void recursiveDescent(wxSizer *aSizer, std::map< int, wxString > &aLabels)
static std::unordered_map< std::string, wxRect > class_map
static void selectAllInTextCtrls(wxWindowList &children)
const int minSize
Push and Shove router track width and via size dialog.
void ignore_unused(const T &)
void SetPosition(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.