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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef DIALOG_SHIM_
26#define DIALOG_SHIM_
27
28#include <kicommon.h>
29#include <eda_units.h>
30#include <kiway_holder.h>
31#include <wx/dialog.h>
32#include <map>
33#include <set>
34#include <vector>
35#include <wx/variant.h>
36#include <core/raii.h>
37
38class EDA_BASE_FRAME;
39class UNIT_BINDER;
40
41class wxGridEvent;
42class wxGUIEventLoop;
43class wxInitDialogEvent;
44class wxSpinEvent;
45class wxSpinDoubleEvent;
46class wxStyledTextEvent;
47class wxPropertyGridEvent;
48class wxDataViewEvent;
49
50
68class KICOMMON_API DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER
69{
70public:
71 DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
72 const wxPoint& pos = wxDefaultPosition,
73 const wxSize& size = wxDefaultSize,
74 long style = wxDEFAULT_FRAME_STYLE | wxRESIZE_BORDER,
75 const wxString& name = wxDialogNameStr );
76
78
83 void SetInitialFocus( wxWindow* aWindow )
84 {
85 m_initialFocusTarget = aWindow;
86 }
87
88 int ShowModal() override;
89
90 int ShowQuasiModal(); // disable only the parent window, otherwise modal.
91
92 void EndQuasiModal( int retCode ); // End quasi-modal mode
93
94 bool IsQuasiModal() const { return m_qmodal_showing; }
95
96 // A quasi-modal dialog disables its parent window. Sadly this disabling is more extreme
97 // than wxWidgets' normal modal dialog disabling, and prevents things like hotkey Cut/Copy/
98 // Paste from working in search controls in standard file dialogs. So when we put up a modal
99 // dialog in front of a quasi-modal, we suspend the quasi-modal dialog parent window
100 // disabling, causing us to fall back to the normal modal dialog parent window disabling.
101 void PrepareForModalSubDialog();
102 void CleanupAfterModalSubDialog();
103
104 bool Show( bool show ) override;
105
106 bool Enable( bool enable ) override;
107
108 void OnPaint( wxPaintEvent &event );
109
110 void OnModify();
111 void ClearModify();
112
117 void SetPosition( const wxPoint& aNewPosition );
118
120 {
121 return m_units;
122 }
123
124 void SelectAllInTextCtrls( wxWindowList& children );
125
126 void SetupStandardButtons( std::map<int, wxString> aLabels = {} );
127
128 static bool IsCtrl( int aChar, const wxKeyEvent& e )
129 {
130 return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
131 !e.ShiftDown() && !e.MetaDown();
132 }
133
134 static bool IsShiftCtrl( int aChar, const wxKeyEvent& e )
135 {
136 return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
137 e.ShiftDown() && !e.MetaDown();
138 }
139
145 void LoadControlState();
146
150 void SaveControlState();
151
156 void OptOut( wxWindow* aWindow );
157
165 void ExcludeFromControlUndoRedo( wxWindow* aWindow );
166
173 void RegisterUnitBinder( UNIT_BINDER* aUnitBinder, wxWindow* aWindow );
174
175protected:
186 void finishDialogSettings();
187
193 void setSizeInDU( int x, int y );
194
199 int horizPixelsFromDU( int x ) const;
200
205 int vertPixelsFromDU( int y ) const;
206
214 void resetSize();
215
216 virtual void OnCharHook( wxKeyEvent& aEvt );
217
225 virtual void TearDownQuasiModal() {}
226
235 void resetUndoRedoForNewContent( wxWindowList& aChildren );
236
244 void unregisterUnitBinders( wxWindow* aWindow );
245
246private:
251 void OnCloseWindow( wxCloseEvent& aEvent );
252
253 void OnSize( wxSizeEvent& aEvent );
254 void OnMove( wxMoveEvent& aEvent );
255
260 void OnButton( wxCommandEvent& aEvent );
261
262 void onChildSetFocus( wxFocusEvent& aEvent );
263
264 void onInitDialog( wxInitDialogEvent& aEvent );
265
271 void focusParentCanvas();
272
273 std::string generateKey( const wxWindow* aWin ) const;
274
275 void registerUndoRedoHandlers( wxWindowList& aChildren );
276 void recordControlChange( wxWindow* aCtrl );
277 void onCommandEvent( wxCommandEvent& aEvent );
278 void onSpinEvent( wxSpinEvent& aEvent );
279 void onSpinDoubleEvent( wxSpinDoubleEvent& aEvent );
280 void onStyledTextChanged( wxStyledTextEvent& aEvent );
281 void onGridCellChanged( wxGridEvent& aEvent );
282 void onPropertyGridChanged( wxPropertyGridEvent& aEvent );
283 void onDataViewListChanged( wxDataViewEvent& aEvent );
284 void doUndo();
285 void doRedo();
286 wxVariant getControlValue( wxWindow* aCtrl );
287 void setControlValue( wxWindow* aCtrl, const wxVariant& aValue );
288
290
291protected:
292 EDA_UNITS m_units; // userUnits for display and parsing
293 std::string m_hash_key; // optional custom key for persistence
294
295 // The following disables the storing of a user size. It is used primarily for dialogs
296 // with conditional content which don't need user sizing.
298
299 // On MacOS (at least) SetFocus() calls made in the constructor will fail because a
300 // window that isn't yet visible will return false to AcceptsFocus(). So we must delay
301 // the initial-focus SetFocus() call to the first paint event.
305
306 wxGUIEventLoop* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal
307 // and dismissed
310
312
313 std::vector<wxWindow*> m_tabOrder;
314
315 // The size asked by the caller, used the first time the dialog is created
319
320 // Used to support first-esc-cancels-edit logic
321 std::map<wxWindow*, wxString> m_beforeEditValues;
322 std::map<wxWindow*, UNIT_BINDER*> m_unitBinders;
323
325 {
326 wxWindow* ctrl;
327 wxVariant before;
328 wxVariant after;
329 };
330
331 std::vector<UNDO_STEP> m_undoStack;
332 std::vector<UNDO_STEP> m_redoStack;
333 std::map<wxWindow*, wxVariant> m_currentValues;
334 std::set<wxWindow*> m_noControlUndoRedo;
337};
338
339#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.
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:83
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
Definition dialog_shim.h:94
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:87
EDA_UNITS
Definition eda_units.h:48
#define KICOMMON_API
Definition kicommon.h:27