KiCad PCB EDA Suite
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 <wx/dialog.h>
29#include <kiway_player.h>
30class wxGridEvent;
31
32
33
35{
36 WINDOW_THAWER( wxWindow* aWindow )
37 {
38 m_window = aWindow;
39 m_freezeCount = 0;
40
41 while( m_window->IsFrozen() )
42 {
43 m_window->Thaw();
45 }
46 }
47
49 {
50 while( m_freezeCount > 0 )
51 {
52 m_window->Freeze();
54 }
55 }
56
57protected:
58 wxWindow* m_window;
60};
61
62
64class WX_EVENT_LOOP;
65
66// These macros are for DIALOG_SHIM only, NOT for KIWAY_PLAYER. KIWAY_PLAYER
67// has its own support for quasi modal and its platform specific issues are different
68// than for a wxDialog.
69 #define SHOWQUASIMODAL ShowQuasiModal
70 #define ENDQUASIMODAL EndQuasiModal
71
82class DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER
83{
84public:
85 DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
86 const wxPoint& pos = wxDefaultPosition,
87 const wxSize& size = wxDefaultSize,
88 long style = wxDEFAULT_FRAME_STYLE | wxRESIZE_BORDER,
89 const wxString& name = wxDialogNameStr );
90
92
97 void SetInitialFocus( wxWindow* aWindow )
98 {
99 m_initialFocusTarget = aWindow;
100 }
101
102 int ShowQuasiModal(); // disable only the parent window, otherwise modal.
103
104 void EndQuasiModal( int retCode ); // End quasi-modal mode
105
106 bool IsQuasiModal() const { return m_qmodal_showing; }
107
108 bool Show( bool show ) override;
109
110 bool Enable( bool enable ) override;
111
112 void OnPaint( wxPaintEvent &event );
113
114 void OnModify();
115
119 void SetPosition( const wxPoint& aNewPosition );
120
122 {
123 return m_units;
124 }
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
140protected:
152
158 void setSizeInDU( int x, int y );
159
164 int horizPixelsFromDU( int x ) const;
165
170 int vertPixelsFromDU( int y ) const;
171
179 void resetSize();
180
181 virtual void OnCharHook( wxKeyEvent& aEvt );
182
183private:
188 void OnCloseWindow( wxCloseEvent& aEvent );
189
194 void OnButton( wxCommandEvent& aEvent );
195
196 void OnGridEditorShown( wxGridEvent& event );
197 void OnGridEditorHidden( wxGridEvent& event );
198
200
201protected:
202 EDA_UNITS m_units; // userUnits for display and parsing
203 std::string m_hash_key; // alternate for class_map when classname re-used
204
205 // The following disables the storing of a user size. It is used primarily for dialogs
206 // with conditional content which don't need user sizing.
208
209 // On MacOS (at least) SetFocus() calls made in the constructor will fail because a
210 // window that isn't yet visible will return false to AcceptsFocus(). So we must delay
211 // the initial-focus SetFocus() call to the first paint event.
214
215 WX_EVENT_LOOP* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal
216 // and dismissed
219
221
222 std::vector<wxWindow*> m_tabOrder;
223
224 // The size asked by the caller, used the first time the dialog is created
226};
227
228#endif // DIALOG_SHIM_
const char * name
Definition: DXF_plotter.cpp:56
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:83
static bool IsShiftCtrl(int aChar, const wxKeyEvent &e)
Definition: dialog_shim.h:134
std::vector< wxWindow * > m_tabOrder
Definition: dialog_shim.h:222
void OnPaint(wxPaintEvent &event)
bool m_qmodal_showing
Definition: dialog_shim.h:217
static bool IsCtrl(int aChar, const wxKeyEvent &e)
Definition: dialog_shim.h:128
int vertPixelsFromDU(int y) const
Convert an integer number of dialog units to pixels, vertically.
bool Show(bool show) override
EDA_UNITS m_units
Definition: dialog_shim.h:202
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
void SetupStandardButtons(std::map< int, wxString > aLabels={})
int ShowQuasiModal()
std::string m_hash_key
Definition: dialog_shim.h:203
bool m_firstPaintEvent
Definition: dialog_shim.h:212
int horizPixelsFromDU(int x) const
Convert an integer number of dialog units to pixels, horizontally.
void resetSize()
Clear the existing dialog size and position.
void setSizeInDU(int x, int y)
Set the dialog to the given dimensions in "dialog units".
bool IsQuasiModal() const
Definition: dialog_shim.h:106
void OnGridEditorShown(wxGridEvent &event)
WDO_ENABLE_DISABLE * m_qmodal_parent_disabler
Definition: dialog_shim.h:218
bool m_useCalculatedSize
Definition: dialog_shim.h:207
void EndQuasiModal(int retCode)
void OnModify()
void OnButton(wxCommandEvent &aEvent)
Properly handle the default button events when in the quasimodal mode when not calling EndQuasiModal ...
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
wxWindow * m_initialFocusTarget
Definition: dialog_shim.h:213
bool Enable(bool enable) override
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)
Definition: dialog_shim.cpp:78
void SetPosition(const wxPoint &aNewPosition)
Force the position of the dialog to a new position.
void OnCloseWindow(wxCloseEvent &aEvent)
Properly handle the wxCloseEvent when in the quasimodal mode when not calling EndQuasiModal which is ...
wxSize m_initialSize
Definition: dialog_shim.h:225
EDA_BASE_FRAME * m_parentFrame
Definition: dialog_shim.h:220
virtual void OnCharHook(wxKeyEvent &aEvt)
void OnGridEditorHidden(wxGridEvent &event)
EDA_UNITS GetUserUnits() const
Definition: dialog_shim.h:121
WX_EVENT_LOOP * m_qmodal_loop
Definition: dialog_shim.h:215
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:37
Toggle a window's "enable" status to disabled, then enabled on destruction.
Definition: dialog_shim.cpp:46
EDA_UNITS
Definition: eda_units.h:43
#define WX_EVENT_LOOP
Definition: kiway_player.h:41
WINDOW_THAWER(wxWindow *aWindow)
Definition: dialog_shim.h:36
wxWindow * m_window
Definition: dialog_shim.h:58