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 (C) 2012-2019 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 <wx/dialog.h>
30#include <kiway_player.h>
31class wxGridEvent;
32
33
34
36{
37 WINDOW_THAWER( wxWindow* aWindow )
38 {
39 m_window = aWindow;
40 m_freezeCount = 0;
41
42 while( m_window->IsFrozen() )
43 {
44 m_window->Thaw();
46 }
47 }
48
50 {
51 while( m_freezeCount > 0 )
52 {
53 m_window->Freeze();
55 }
56 }
57
58protected:
59 wxWindow* m_window;
61};
62
63
65class WX_EVENT_LOOP;
66
67// These macros are for DIALOG_SHIM only, NOT for KIWAY_PLAYER. KIWAY_PLAYER
68// has its own support for quasi modal and its platform specific issues are different
69// than for a wxDialog.
70 #define SHOWQUASIMODAL ShowQuasiModal
71 #define ENDQUASIMODAL EndQuasiModal
72
83class KICOMMON_API DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER
84{
85public:
86 DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
87 const wxPoint& pos = wxDefaultPosition,
88 const wxSize& size = wxDefaultSize,
89 long style = wxDEFAULT_FRAME_STYLE | wxRESIZE_BORDER,
90 const wxString& name = wxDialogNameStr );
91
93
98 void SetInitialFocus( wxWindow* aWindow )
99 {
100 m_initialFocusTarget = aWindow;
101 }
102
103 int ShowQuasiModal(); // disable only the parent window, otherwise modal.
104
105 void EndQuasiModal( int retCode ); // End quasi-modal mode
106
107 bool IsQuasiModal() const { return m_qmodal_showing; }
108
109 bool Show( bool show ) override;
110
111 bool Enable( bool enable ) override;
112
113 void OnPaint( wxPaintEvent &event );
114
115 void OnModify();
116
121 void SetPosition( const wxPoint& aNewPosition );
122
124 {
125 return m_units;
126 }
127
128 void SelectAllInTextCtrls( wxWindowList& children );
129
130 void SetupStandardButtons( std::map<int, wxString> aLabels = {} );
131
132 static bool IsCtrl( int aChar, const wxKeyEvent& e )
133 {
134 return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
135 !e.ShiftDown() && !e.MetaDown();
136 }
137
138 static bool IsShiftCtrl( int aChar, const wxKeyEvent& e )
139 {
140 return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
141 e.ShiftDown() && !e.MetaDown();
142 }
143
144protected:
155 void finishDialogSettings();
156
162 void setSizeInDU( int x, int y );
163
168 int horizPixelsFromDU( int x ) const;
169
174 int vertPixelsFromDU( int y ) const;
175
183 void resetSize();
184
185 virtual void OnCharHook( wxKeyEvent& aEvt );
186
187private:
192 void OnCloseWindow( wxCloseEvent& aEvent );
193
198 void OnButton( wxCommandEvent& aEvent );
199
200 void onChildSetFocus( wxFocusEvent& aEvent );
201
203
204protected:
205 EDA_UNITS m_units; // userUnits for display and parsing
206 std::string m_hash_key; // alternate for class_map when classname re-used
207
208 // The following disables the storing of a user size. It is used primarily for dialogs
209 // with conditional content which don't need user sizing.
211
212 // On MacOS (at least) SetFocus() calls made in the constructor will fail because a
213 // window that isn't yet visible will return false to AcceptsFocus(). So we must delay
214 // the initial-focus SetFocus() call to the first paint event.
218
219 WX_EVENT_LOOP* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal
220 // and dismissed
223
225
226 std::vector<wxWindow*> m_tabOrder;
227
228 // The size asked by the caller, used the first time the dialog is created
230
231 // Used to support first-esc-cancels-edit logic
232 std::map<wxWindow*, wxString> m_beforeEditValues;
233};
234
235#endif // DIALOG_SHIM_
const char * name
Definition: DXF_plotter.cpp:57
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:84
static bool IsShiftCtrl(int aChar, const wxKeyEvent &e)
Definition: dialog_shim.h:138
bool m_isClosing
Definition: dialog_shim.h:217
std::vector< wxWindow * > m_tabOrder
Definition: dialog_shim.h:226
bool m_qmodal_showing
Definition: dialog_shim.h:221
static bool IsCtrl(int aChar, const wxKeyEvent &e)
Definition: dialog_shim.h:132
EDA_UNITS m_units
Definition: dialog_shim.h:205
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:98
std::string m_hash_key
Definition: dialog_shim.h:206
bool m_firstPaintEvent
Definition: dialog_shim.h:215
std::map< wxWindow *, wxString > m_beforeEditValues
Definition: dialog_shim.h:232
bool IsQuasiModal() const
Definition: dialog_shim.h:107
WDO_ENABLE_DISABLE * m_qmodal_parent_disabler
Definition: dialog_shim.h:222
bool m_useCalculatedSize
Definition: dialog_shim.h:210
wxWindow * m_initialFocusTarget
Definition: dialog_shim.h:216
wxSize m_initialSize
Definition: dialog_shim.h:229
EDA_BASE_FRAME * m_parentFrame
Definition: dialog_shim.h:224
EDA_UNITS GetUserUnits() const
Definition: dialog_shim.h:123
WX_EVENT_LOOP * m_qmodal_loop
Definition: dialog_shim.h:219
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
Toggle a window's "enable" status to disabled, then enabled on destruction.
Definition: dialog_shim.cpp:47
EDA_UNITS
Definition: eda_units.h:46
#define KICOMMON_API
Definition: kicommon.h:28
#define WX_EVENT_LOOP
Definition: kiway_player.h:42
WINDOW_THAWER(wxWindow *aWindow)
Definition: dialog_shim.h:37
wxWindow * m_window
Definition: dialog_shim.h:59