KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_shim.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef DIALOG_SHIM_
22#define DIALOG_SHIM_
23
24#include <kicommon.h>
25#include <eda_units.h>
26#include <kiway_holder.h>
27#include <wx/dialog.h>
28#include <map>
29#include <set>
30#include <vector>
31#include <wx/variant.h>
32#include <core/raii.h>
33
34class EDA_BASE_FRAME;
35class UNIT_BINDER;
36
37class wxGridEvent;
38class wxGUIEventLoop;
39class wxInitDialogEvent;
40class wxSpinEvent;
41class wxSpinDoubleEvent;
42class wxStyledTextEvent;
43class wxPropertyGridEvent;
44class wxDataViewEvent;
45
46
59KICOMMON_API wxRect ClampRectToDisplay( const wxRect& aRect, const wxRect& aClientArea );
60
61
79class KICOMMON_API DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER
80{
81public:
82 DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
83 const wxPoint& pos = wxDefaultPosition,
84 const wxSize& size = wxDefaultSize,
85 long style = wxDEFAULT_FRAME_STYLE | wxRESIZE_BORDER,
86 const wxString& name = wxDialogNameStr );
87
89
94 void SetInitialFocus( wxWindow* aWindow )
95 {
96 m_initialFocusTarget = aWindow;
97 }
98
99 int ShowModal() override;
100
101 int ShowQuasiModal(); // disable only the parent window, otherwise modal.
102
103 void EndQuasiModal( int retCode ); // End quasi-modal mode
104
105 bool IsQuasiModal() const { return m_qmodal_showing; }
106
107 // A quasi-modal dialog disables its parent window. Sadly this disabling is more extreme
108 // than wxWidgets' normal modal dialog disabling, and prevents things like hotkey Cut/Copy/
109 // Paste from working in search controls in standard file dialogs. So when we put up a modal
110 // dialog in front of a quasi-modal, we suspend the quasi-modal dialog parent window
111 // disabling, causing us to fall back to the normal modal dialog parent window disabling.
112 void PrepareForModalSubDialog();
113 void CleanupAfterModalSubDialog();
114
115 bool Show( bool show ) override;
116
117 bool Enable( bool enable ) override;
118
119 void OnPaint( wxPaintEvent &event );
120
121 void OnModify();
122 void ClearModify();
123
128 void SetPosition( const wxPoint& aNewPosition );
129
131 {
132 return m_units;
133 }
134
135 void SelectAllInTextCtrls( wxWindowList& children );
136
137 void SetupStandardButtons( std::map<int, wxString> aLabels = {} );
138
139 static bool IsCtrl( int aChar, const wxKeyEvent& e )
140 {
141 return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
142 !e.ShiftDown() && !e.MetaDown();
143 }
144
145 static bool IsShiftCtrl( int aChar, const wxKeyEvent& e )
146 {
147 return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
148 e.ShiftDown() && !e.MetaDown();
149 }
150
156 void LoadControlState();
157
162 void ReloadSashPositions();
163
167 void SaveControlState();
168
173 void OptOut( wxWindow* aWindow );
174
182 void ExcludeFromControlUndoRedo( wxWindow* aWindow );
183
190 void RegisterUnitBinder( UNIT_BINDER* aUnitBinder, wxWindow* aWindow );
191
201 void UnregisterUnitBinder( UNIT_BINDER* aUnitBinder );
202
215 void EndDialogShim( int aReturnCode );
216
217protected:
228 void finishDialogSettings();
229
239 void clampToWorkArea();
240
246 void setSizeInDU( int x, int y );
247
252 int horizPixelsFromDU( int x ) const;
253
258 int vertPixelsFromDU( int y ) const;
259
267 void resetSize();
268
269 virtual void OnCharHook( wxKeyEvent& aEvt );
270
278 virtual void TearDownQuasiModal() {}
279
288 void resetUndoRedoForNewContent( wxWindowList& aChildren );
289
297 void unregisterUnitBinders( wxWindow* aWindow );
298
299private:
304 void OnCloseWindow( wxCloseEvent& aEvent );
305 void OnActivate( wxActivateEvent& aEvent );
306
311 void forceInitialFocus();
312
313 void OnSize( wxSizeEvent& aEvent );
314 void OnMove( wxMoveEvent& aEvent );
315
320 void OnButton( wxCommandEvent& aEvent );
321
322 void onChildSetFocus( wxFocusEvent& aEvent );
323
324 void onInitDialog( wxInitDialogEvent& aEvent );
325
335 void focusParentCanvas( bool aDeferUntilFrameActive = false );
336
337 std::string generateKey( const wxWindow* aWin ) const;
338
339 void registerUndoRedoHandlers( wxWindowList& aChildren );
340
348 void recordControlChange( wxWindow* aCtrl );
349
355 void flushPendingControlChanges();
356
357 void onCommandEvent( wxCommandEvent& aEvent );
358 void onSpinEvent( wxSpinEvent& aEvent );
359 void onSpinDoubleEvent( wxSpinDoubleEvent& aEvent );
360 void onStyledTextChanged( wxStyledTextEvent& aEvent );
361 void onGridCellChanged( wxGridEvent& aEvent );
362 void onPropertyGridChanged( wxPropertyGridEvent& aEvent );
363 void onDataViewListChanged( wxDataViewEvent& aEvent );
364 void doUndo();
365 void doRedo();
366 wxVariant getControlValue( wxWindow* aCtrl );
367 void setControlValue( wxWindow* aCtrl, const wxVariant& aValue );
368
370
371protected:
372 EDA_UNITS m_units; // userUnits for display and parsing
373 std::string m_hash_key; // optional custom key for persistence
374
375 // The following disables the storing of a user size. It is used primarily for dialogs
376 // with conditional content which don't need user sizing.
378
379 // On MacOS (at least) SetFocus() calls made in the constructor will fail because a
380 // window that isn't yet visible will return false to AcceptsFocus(). So we must delay
381 // the initial-focus SetFocus() call to the first paint event.
385
386 wxGUIEventLoop* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal
387 // and dismissed
390
392
393 std::vector<wxWindow*> m_tabOrder;
394
395 // The size asked by the caller, used the first time the dialog is created
399
400 // Used to support first-esc-cancels-edit logic
401 std::map<wxWindow*, wxString> m_beforeEditValues;
402 std::map<wxWindow*, UNIT_BINDER*> m_unitBinders;
403
405 {
406 wxWindow* ctrl;
407 wxVariant before;
408 wxVariant after;
409 };
410
411 std::vector<UNDO_STEP> m_undoStack;
412 std::vector<UNDO_STEP> m_redoStack;
413 std::map<wxWindow*, wxVariant> m_currentValues;
414 std::set<wxWindow*> m_controlsWithPendingChanges;
415 std::set<wxWindow*> m_noControlUndoRedo;
418};
419
420#endif // DIALOG_SHIM_
const char * name
static bool IsShiftCtrl(int aChar, const wxKeyEvent &e)
bool m_handlingUndoRedo
std::set< wxWindow * > m_noControlUndoRedo
std::vector< wxWindow * > m_tabOrder
bool m_qmodal_showing
virtual void TearDownQuasiModal()
Override this method to perform dialog tear down actions not suitable for object dtor.
std::set< wxWindow * > m_controlsWithPendingChanges
static bool IsCtrl(int aChar, const wxKeyEvent &e)
std::vector< UNDO_STEP > m_redoStack
wxGUIEventLoop * m_qmodal_loop
EDA_UNITS m_units
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:94
WINDOW_DISABLER * m_qmodal_parent_disabler
std::string m_hash_key
bool m_firstPaintEvent
bool m_userResized
std::map< wxWindow *, wxString > m_beforeEditValues
bool IsQuasiModal() const
bool m_useCalculatedSize
std::map< wxWindow *, UNIT_BINDER * > m_unitBinders
bool m_childReleased
wxWindow * m_initialFocusTarget
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER, const wxString &name=wxDialogNameStr)
bool m_userPositioned
std::map< wxWindow *, wxVariant > m_currentValues
wxSize m_initialSize
EDA_BASE_FRAME * m_parentFrame
std::vector< UNDO_STEP > m_undoStack
EDA_UNITS GetUserUnits() const
The base frame for deriving all KiCad main window classes.
KIWAY_HOLDER(KIWAY *aKiway, HOLDER_TYPE aType)
Temporarily disable a window, and then re-enable on destruction.
Definition raii.h:89
KICOMMON_API wxRect ClampRectToDisplay(const wxRect &aRect, const wxRect &aClientArea)
Constrain a window rectangle so it fits entirely within a display's client area.
EDA_UNITS
Definition eda_units.h:44
#define KICOMMON_API
Definition kicommon.h:27