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>
75 const wxPoint& pos, const wxSize& size,
long style,
76 const wxString&
name ) :
77 wxDialog( aParent,
id, title, pos, size, style,
name ),
80 m_useCalculatedSize( false ),
81 m_firstPaintEvent( true ),
82 m_initialFocusTarget(
nullptr ),
83 m_qmodal_loop(
nullptr ),
84 m_qmodal_showing( false ),
85 m_qmodal_parent_disabler(
nullptr ),
86 m_parentFrame(
nullptr )
95 while( !kiwayHolder && aParent->GetParent() )
97 aParent = aParent->GetParent();
112 TOOL_MANAGER* toolMgr = m_parentFrame->GetToolManager();
120 SetKiway(
this, &kiwayHolder->
Kiway() );
160 GetSizer()->SetSizeHints(
this );
167 SetSize( ConvertDialogToPixels( sz ) );
174 return ConvertDialogToPixels( sz ).x;
181 return ConvertDialogToPixels( sz ).y;
189static std::unordered_map<std::string, wxRect>
class_map;
194 wxDialog::SetPosition( aNewPosition );
197 const char* hash_key;
206 hash_key =
typeid(*this).name();
209 std::unordered_map<std::string, wxRect>::iterator it =
class_map.find( hash_key );
214 wxRect rect = it->second;
215 rect.SetPosition( aNewPosition );
224 const char* hash_key;
233 hash_key =
typeid(*this).name();
243 ret = wxDialog::Show( show );
246 wxRect savedDialogRect =
class_map[ hash_key ];
248 if( savedDialogRect.GetSize().x != 0 && savedDialogRect.GetSize().y != 0 )
252 SetSize( savedDialogRect.GetPosition().x, savedDialogRect.GetPosition().y,
253 wxDialog::GetSize().x, wxDialog::GetSize().y, 0 );
257 SetSize( savedDialogRect.GetPosition().x, savedDialogRect.GetPosition().y,
258 std::max( wxDialog::GetSize().x, savedDialogRect.GetSize().x ),
259 std::max( wxDialog::GetSize().y, savedDialogRect.GetSize().y ),
269 if( wxDisplay::GetFromWindow(
this ) == wxNOT_FOUND )
275 class_map[ hash_key ] = wxRect( wxDialog::GetPosition(), wxDialog::GetSize() );
279 m_eventLoop->Exit( GetReturnCode() );
282 ret = wxDialog::Show( show );
291 const char* hash_key;
300 hash_key =
typeid(*this).name();
303 std::unordered_map<std::string, wxRect>::iterator it =
class_map.find( hash_key );
308 wxRect rect = it->second;
309 rect.SetSize( wxSize( 0, 0 ) );
317 return wxDialog::Enable( enable );
326 for( wxWindow* child : children )
328 if( wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( child ) )
337#if defined( __WXMAC__ ) || defined( __WXMSW__ )
338 if( !textCtrl->GetStringSelection().IsEmpty() )
342 else if( textCtrl->IsEditable() )
344 textCtrl->SelectAll();
350 else if( wxStyledTextCtrl* scintilla =
dynamic_cast<wxStyledTextCtrl*
>( child ) )
356 if( !scintilla->GetSelectedText().IsEmpty() )
360 else if( scintilla->IsEditable() )
362 scintilla->SelectAll();
368 else if(
dynamic_cast<wxBitmapButton*
>( child ) !=
nullptr )
371 wxRect rect = child->GetRect();
373 child->ConvertDialogToPixels(
minSize );
375 rect.Inflate( std::max( 0,
minSize.x - rect.GetWidth() ),
376 std::max( 0,
minSize.y - rect.GetHeight() ) );
378 child->SetMinSize( rect.GetSize() );
379 child->SetSize( rect );
412 if( !GetTitle().StartsWith( wxS(
"*" ) ) )
413 SetTitle( wxS(
"*" ) + GetTitle() );
448 NULLER(
void*& aPtr ) : m_what( aPtr ) {}
449 ~NULLER() { m_what =
nullptr; }
455 wxWindow* win = wxWindow::GetCapture();
460 wxWindow* parent = GetParentForModalDialog( GetParent(), GetWindowStyle() );
486 return GetReturnCode();
494 if( ( retCode == wxID_OK ) && ( !Validate() || !TransferDataFromWindow() ) )
497 SetReturnCode( retCode );
501 wxFAIL_MSG( wxT(
"Either DIALOG_SHIM::EndQuasiModal was called twice, or ShowQuasiModal"
538 const int id = aEvent.GetId();
542 if(
id == GetAffirmativeId() )
546 else if(
id == wxID_APPLY )
557 else if(
id == wxID_CANCEL )
578 if( wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aEvent.GetEventObject() ) )
580 else if( wxStyledTextCtrl* scintilla =
dynamic_cast<wxStyledTextCtrl*
>( aEvent.GetEventObject() ) )
589 if( aEvt.GetKeyCode() ==
'U' && aEvt.GetModifiers() == wxMOD_CONTROL )
598 else if( ( aEvt.GetKeyCode() == WXK_RETURN || aEvt.GetKeyCode() == WXK_NUMPAD_ENTER )
599 && ( aEvt.ShiftDown() || aEvt.ControlDown() ) )
601 wxPostEvent(
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
604 else if( aEvt.GetKeyCode() == WXK_TAB && !aEvt.ControlDown() )
606 wxWindow* currentWindow = wxWindow::FindFocus();
608 int delta = aEvt.ShiftDown() ? -1 : 1;
615 idx = ( ( idx +
delta ) % size + size ) % size;
618 for(
size_t i = 0; i <
m_tabOrder.size(); ++i )
622 currentIdx = (int) i;
627 if( currentIdx >= 0 )
629 advance( currentIdx );
634 while(
dynamic_cast<wxTextEntry*
>(
m_tabOrder[ currentIdx ] ) ==
nullptr )
635 advance( currentIdx );
642 else if( aEvt.GetKeyCode() == WXK_ESCAPE )
644 wxObject* eventSource = aEvt.GetEventObject();
646 if( wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( eventSource ) )
652 textCtrl->SelectAll();
656 else if( wxStyledTextCtrl* scintilla =
dynamic_cast<wxStyledTextCtrl*
>( eventSource ) )
662 scintilla->SelectAll();
674 wxStdDialogButtonSizer* sdbSizer =
dynamic_cast<wxStdDialogButtonSizer*
>( aSizer );
677 [&]( wxButton* aButton )
679 if( aLabels.count( aButton->GetId() ) > 0 )
681 aButton->SetLabel( aLabels[ aButton->GetId() ] );
687 switch( aButton->GetId() )
689 case wxID_OK: aButton->SetLabel(
_(
"&OK" ) );
break;
690 case wxID_CANCEL: aButton->SetLabel(
_(
"&Cancel" ) );
break;
691 case wxID_YES: aButton->SetLabel(
_(
"&Yes" ) );
break;
692 case wxID_NO: aButton->SetLabel(
_(
"&No" ) );
break;
693 case wxID_APPLY: aButton->SetLabel(
_(
"&Apply" ) );
break;
694 case wxID_SAVE: aButton->SetLabel(
_(
"&Save" ) );
break;
695 case wxID_HELP: aButton->SetLabel(
_(
"&Help" ) );
break;
696 case wxID_CONTEXT_HELP: aButton->SetLabel(
_(
"&Help" ) );
break;
703 if( sdbSizer->GetAffirmativeButton() )
704 setupButton( sdbSizer->GetAffirmativeButton() );
706 if( sdbSizer->GetApplyButton() )
707 setupButton( sdbSizer->GetApplyButton() );
709 if( sdbSizer->GetNegativeButton() )
710 setupButton( sdbSizer->GetNegativeButton() );
712 if( sdbSizer->GetCancelButton() )
713 setupButton( sdbSizer->GetCancelButton() );
715 if( sdbSizer->GetHelpButton() )
716 setupButton( sdbSizer->GetHelpButton() );
720 if( sdbSizer->GetAffirmativeButton() )
721 sdbSizer->GetAffirmativeButton()->SetDefault();
724 for( wxSizerItem* item : aSizer->GetChildren() )
726 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 onChildSetFocus(wxFocusEvent &aEvent)
void selectAllInTextCtrls(wxWindowList &children)
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.
std::map< wxWindow *, wxString > m_beforeEditValues
void setSizeInDU(int x, int y)
Set the dialog to the given dimensions in "dialog units".
bool IsQuasiModal() const
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)
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
const int minSize
Push and Shove router track width and via size dialog.
void ignore_unused(const T &)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.