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 <core/raii.h>
34
35class EDA_BASE_FRAME;
36class UNIT_BINDER;
37
38class wxGridEvent;
39class wxGUIEventLoop;
40class wxInitDialogEvent;
41
42
60class KICOMMON_API DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER
61{
62public:
63 DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
64 const wxPoint& pos = wxDefaultPosition,
65 const wxSize& size = wxDefaultSize,
66 long style = wxDEFAULT_FRAME_STYLE | wxRESIZE_BORDER,
67 const wxString& name = wxDialogNameStr );
68
70
75 void SetInitialFocus( wxWindow* aWindow )
76 {
77 m_initialFocusTarget = aWindow;
78 }
79
80 int ShowModal() override;
81
82 int ShowQuasiModal(); // disable only the parent window, otherwise modal.
83
84 void EndQuasiModal( int retCode ); // End quasi-modal mode
85
86 bool IsQuasiModal() const { return m_qmodal_showing; }
87
88 // A quasi-modal dialog disables its parent window. Sadly this disabling is more extreme
89 // than wxWidgets' normal modal dialog disabling, and prevents things like hotkey Cut/Copy/
90 // Paste from working in search controls in standard file dialogs. So when we put up a modal
91 // dialog in front of a quasi-modal, we suspend the quasi-modal dialog parent window
92 // disabling, causing us to fall back to the normal modal dialog parent window disabling.
93 void PrepareForModalSubDialog();
94 void CleanupAfterModalSubDialog();
95
96 bool Show( bool show ) override;
97
98 bool Enable( bool enable ) override;
99
100 void OnPaint( wxPaintEvent &event );
101
102 void OnModify();
103 void ClearModify();
104
109 void SetPosition( const wxPoint& aNewPosition );
110
112 {
113 return m_units;
114 }
115
116 void SelectAllInTextCtrls( wxWindowList& children );
117
118 void SetupStandardButtons( std::map<int, wxString> aLabels = {} );
119
120 static bool IsCtrl( int aChar, const wxKeyEvent& e )
121 {
122 return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
123 !e.ShiftDown() && !e.MetaDown();
124 }
125
126 static bool IsShiftCtrl( int aChar, const wxKeyEvent& e )
127 {
128 return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
129 e.ShiftDown() && !e.MetaDown();
130 }
131
137 void LoadControlState();
138
142 void SaveControlState();
143
148 void OptOut( wxWindow* aWindow );
149
156 void RegisterUnitBinder( UNIT_BINDER* aUnitBinder, wxWindow* aWindow );
157
158protected:
169 void finishDialogSettings();
170
176 void setSizeInDU( int x, int y );
177
182 int horizPixelsFromDU( int x ) const;
183
188 int vertPixelsFromDU( int y ) const;
189
197 void resetSize();
198
199 virtual void OnCharHook( wxKeyEvent& aEvt );
200
208 virtual void TearDownQuasiModal() {}
209
210private:
215 void OnCloseWindow( wxCloseEvent& aEvent );
216
217 void OnSize( wxSizeEvent& aEvent );
218 void OnMove( wxMoveEvent& aEvent );
219
224 void OnButton( wxCommandEvent& aEvent );
225
226 void onChildSetFocus( wxFocusEvent& aEvent );
227
228 void onInitDialog( wxInitDialogEvent& aEvent );
229
230 std::string generateKey( const wxWindow* aWin ) const;
231
233
234protected:
235 EDA_UNITS m_units; // userUnits for display and parsing
236 std::string m_hash_key; // optional custom key for persistence
237
238 // The following disables the storing of a user size. It is used primarily for dialogs
239 // with conditional content which don't need user sizing.
241
242 // On MacOS (at least) SetFocus() calls made in the constructor will fail because a
243 // window that isn't yet visible will return false to AcceptsFocus(). So we must delay
244 // the initial-focus SetFocus() call to the first paint event.
248
249 wxGUIEventLoop* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal
250 // and dismissed
253
255
256 std::vector<wxWindow*> m_tabOrder;
257
258 // The size asked by the caller, used the first time the dialog is created
262
263 // Used to support first-esc-cancels-edit logic
264 std::map<wxWindow*, wxString> m_beforeEditValues;
265 std::map<wxWindow*, UNIT_BINDER*> m_unitBinders;
266};
267
268#endif // DIALOG_SHIM_
const char * name
Definition: DXF_plotter.cpp:62
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:61
static bool IsShiftCtrl(int aChar, const wxKeyEvent &e)
Definition: dialog_shim.h:126
bool m_isClosing
Definition: dialog_shim.h:247
std::vector< wxWindow * > m_tabOrder
Definition: dialog_shim.h:256
bool m_qmodal_showing
Definition: dialog_shim.h:251
virtual void TearDownQuasiModal()
Override this method to perform dialog tear down actions not suitable for object dtor.
Definition: dialog_shim.h:208
static bool IsCtrl(int aChar, const wxKeyEvent &e)
Definition: dialog_shim.h:120
wxGUIEventLoop * m_qmodal_loop
Definition: dialog_shim.h:249
EDA_UNITS m_units
Definition: dialog_shim.h:235
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:75
WINDOW_DISABLER * m_qmodal_parent_disabler
Definition: dialog_shim.h:252
std::string m_hash_key
Definition: dialog_shim.h:236
bool m_firstPaintEvent
Definition: dialog_shim.h:245
bool m_userResized
Definition: dialog_shim.h:261
std::map< wxWindow *, wxString > m_beforeEditValues
Definition: dialog_shim.h:264
bool IsQuasiModal() const
Definition: dialog_shim.h:86
bool m_useCalculatedSize
Definition: dialog_shim.h:240
std::map< wxWindow *, UNIT_BINDER * > m_unitBinders
Definition: dialog_shim.h:265
wxWindow * m_initialFocusTarget
Definition: dialog_shim.h:246
bool m_userPositioned
Definition: dialog_shim.h:260
wxSize m_initialSize
Definition: dialog_shim.h:259
EDA_BASE_FRAME * m_parentFrame
Definition: dialog_shim.h:254
EDA_UNITS GetUserUnits() const
Definition: dialog_shim.h:111
The base frame for deriving all KiCad main window classes.
A mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_holder.h:39
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:28