32 #include <wx/display.h> 33 #include <wx/evtloop.h> 37 #include <wx/bmpbuttn.h> 38 #include <wx/textctrl.h> 39 #include <wx/stc/stc.h> 78 const wxPoint& pos, const wxSize& size,
long style,
79 const wxString&
name ) :
80 wxDialog( aParent,
id, title, pos, size, style,
name ),
83 m_useCalculatedSize( false ),
84 m_firstPaintEvent( true ),
85 m_initialFocusTarget(
nullptr ),
86 m_qmodal_loop(
nullptr ),
87 m_qmodal_showing( false ),
88 m_qmodal_parent_disabler(
nullptr ),
89 m_parentFrame(
nullptr )
96 kiwayHolder = dynamic_cast<KIWAY_HOLDER*>( aParent );
98 while( !kiwayHolder && aParent->GetParent() )
100 aParent = aParent->GetParent();
101 kiwayHolder = dynamic_cast<KIWAY_HOLDER*>( aParent );
107 m_units = static_cast<EDA_BASE_FRAME*>( kiwayHolder )->GetUserUnits();
109 m_units = static_cast<DIALOG_SHIM*>( kiwayHolder )->GetUserUnits();
114 m_parentFrame = static_cast<EDA_BASE_FRAME*>( kiwayHolder );
115 TOOL_MANAGER* toolMgr = m_parentFrame->GetToolManager();
123 SetKiway(
this, &kiwayHolder->
Kiway() );
158 GetSizer()->SetSizeHints(
this );
165 SetSize( ConvertDialogToPixels( sz ) );
172 return ConvertDialogToPixels( sz ).x;
179 return ConvertDialogToPixels( sz ).y;
187 static std::unordered_map<std::string, wxRect>
class_map;
195 const char* hash_key;
204 hash_key =
typeid(*this).name();
207 std::unordered_map<std::string, wxRect>::iterator it =
class_map.find( hash_key );
212 wxRect rect = it->second;
213 rect.SetPosition( aNewPosition );
222 const char* hash_key;
231 hash_key =
typeid(*this).name();
241 ret = wxDialog::Show( show );
244 wxRect savedDialogRect =
class_map[ hash_key ];
246 if( savedDialogRect.GetSize().x != 0 && savedDialogRect.GetSize().y != 0 )
250 SetSize( savedDialogRect.GetPosition().x, savedDialogRect.GetPosition().y,
251 wxDialog::GetSize().x, wxDialog::GetSize().y, 0 );
255 SetSize( savedDialogRect.GetPosition().x, savedDialogRect.GetPosition().y,
256 std::max( wxDialog::GetSize().x, savedDialogRect.GetSize().x ),
257 std::max( wxDialog::GetSize().y, savedDialogRect.GetSize().y ),
267 if( wxDisplay::GetFromWindow(
this ) == wxNOT_FOUND )
273 class_map[ hash_key ] = wxRect( wxDialog::GetPosition(), wxDialog::GetSize() );
277 m_eventLoop->Exit( GetReturnCode() );
280 ret = wxDialog::Show( show );
289 const char* hash_key;
298 hash_key =
typeid(*this).name();
301 std::unordered_map<std::string, wxRect>::iterator it =
class_map.find( hash_key );
306 wxRect rect = it->second;
307 rect.SetSize( wxSize( 0, 0 ) );
315 return wxDialog::Enable( enable );
324 for( wxWindow* child : children )
326 if( wxTextCtrl* childTextCtrl = dynamic_cast<wxTextCtrl*>( child ) )
331 #if defined( __WXMAC__ ) || defined( __WXMSW__ ) 332 if( !childTextCtrl->GetStringSelection().IsEmpty() )
338 childTextCtrl->SelectAll();
344 else if( wxStyledTextCtrl* scintilla = dynamic_cast<wxStyledTextCtrl*>( child ) )
346 if( !scintilla->GetSelectedText().IsEmpty() )
352 scintilla->SelectAll();
358 else if( dynamic_cast<wxBitmapButton*>( child ) !=
nullptr )
361 wxRect rect = child->GetRect();
363 child->ConvertDialogToPixels(
minSize );
365 rect.Inflate( std::max( 0,
minSize.x - rect.GetWidth() ),
366 std::max( 0,
minSize.y - rect.GetHeight() ) );
368 child->SetMinSize( rect.GetSize() );
369 child->SetSize( rect );
402 if( !GetTitle().StartsWith( wxT(
"*" ) ) )
403 SetTitle( wxT(
"*" ) + GetTitle() );
438 NULLER(
void*& aPtr ) : m_what( aPtr ) {}
439 ~NULLER() { m_what =
nullptr; }
445 wxWindow* win = wxWindow::GetCapture();
450 wxWindow* parent = GetParentForModalDialog( GetParent(), GetWindowStyle() );
453 wxT(
"Caller using ShowQuasiModal() twice on same window?" ) );
476 return GetReturnCode();
484 if( ( retCode == wxID_OK ) && ( !Validate() || !TransferDataFromWindow() ) )
487 SetReturnCode( retCode );
491 wxFAIL_MSG( wxT(
"either DIALOG_SHIM::EndQuasiModal called twice or ShowQuasiModal" )
492 wxT(
"wasn't called" ) );
528 const int id = aEvent.GetId();
532 if(
id == wxID_CANCEL )
533 SetEscapeId( wxID_ANY );
537 if(
id == GetAffirmativeId() )
541 else if(
id == wxID_APPLY )
552 else if(
id == GetEscapeId() ||
553 (
id == wxID_CANCEL && GetEscapeId() == wxID_ANY) )
572 if( aEvt.GetKeyCode() ==
'U' && aEvt.GetModifiers() == wxMOD_CONTROL )
581 else if( aEvt.GetKeyCode() == WXK_RETURN && ( aEvt.ShiftDown() || aEvt.ControlDown() ) )
583 wxPostEvent(
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
586 else if( aEvt.GetKeyCode() == WXK_TAB && !aEvt.ControlDown() )
588 wxWindow* currentWindow = wxWindow::FindFocus();
590 int delta = aEvt.ShiftDown() ? -1 : 1;
592 auto advance = [&](
int& idx )
596 idx = ( ( idx +
delta ) % size + size ) % size;
599 for(
size_t i = 0; i <
m_tabOrder.size(); ++i )
603 currentIdx = (int) i;
608 if( currentIdx >= 0 )
610 advance( currentIdx );
615 while( dynamic_cast<wxTextEntry*>(
m_tabOrder[ currentIdx ] ) ==
nullptr )
616 advance( currentIdx );
630 SetEscapeId( wxID_NONE );
637 SetEscapeId( wxID_ANY );
A mix in class which holds the location of a wxWindow's KIWAY.
void setSizeInDU(int x, int y)
Set the dialog to the given dimensions in "dialog units".
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
void OnButton(wxCommandEvent &aEvent)
Properly handle the default button events when in the quasimodal mode when not calling EndQuasiModal ...
std::vector< wxWindow * > m_tabOrder
HOLDER_TYPE GetType() const
bool IsQuasiModal() const
static std::unordered_map< std::string, wxRect > class_map
wxWindow * m_initialFocusTarget
int horizPixelsFromDU(int x) const
Convert an integer number of dialog units to pixels, horizontally.
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
void OnGridEditorShown(wxGridEvent &event)
const int minSize
Push and Shove router track width and via size dialog.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
void OnGridEditorHidden(wxGridEvent &event)
WX_EVENT_LOOP * m_qmodal_loop
void OnCloseWindow(wxCloseEvent &aEvent)
Properly handle the wxCloseEvent when in the quasimodal mode when not calling EndQuasiModal which is ...
void SetPosition(const wxPoint &aNewPosition)
Force the position of the dialog to a new position.
EDA_BASE_FRAME * m_parentFrame
void OnPaint(wxPaintEvent &event)
bool Show(bool show) override
WDO_ENABLE_DISABLE * m_qmodal_parent_disabler
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual void OnCharHook(wxKeyEvent &aEvt)
void EndQuasiModal(int retCode)
virtual void ToggleUserUnits()
The base frame for deriving all KiCad main window classes.
Toggle a window's "enable" status to disabled, then enabled on destruction.
void resetSize()
Clear the existing dialog size and position.
void ignore_unused(const T &)
int vertPixelsFromDU(int y) const
Convert an integer number of dialog units to pixels, vertically.
bool Enable(bool enable) override
WDO_ENABLE_DISABLE(wxWindow *aWindow)
void SetPosition(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
static void selectAllInTextCtrls(wxWindowList &children)