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;
36
37class wxGridEvent;
38class wxGUIEventLoop;
39
40
51class KICOMMON_API DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER
52{
53public:
54 DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
55 const wxPoint& pos = wxDefaultPosition,
56 const wxSize& size = wxDefaultSize,
57 long style = wxDEFAULT_FRAME_STYLE | wxRESIZE_BORDER,
58 const wxString& name = wxDialogNameStr );
59
61
66 void SetInitialFocus( wxWindow* aWindow )
67 {
68 m_initialFocusTarget = aWindow;
69 }
70
71 int ShowModal() override;
72
73 int ShowQuasiModal(); // disable only the parent window, otherwise modal.
74
75 void EndQuasiModal( int retCode ); // End quasi-modal mode
76
77 bool IsQuasiModal() const { return m_qmodal_showing; }
78
79 // A quasi-modal dialog disables its parent window. Sadly this disabling is more extreme
80 // than wxWidgets' normal modal dialog disabling, and prevents things like hotkey Cut/Copy/
81 // Paste from working in search controls in standard file dialogs. So when we put up a modal
82 // dialog in front of a quasi-modal, we suspend the quasi-modal dialog parent window
83 // disabling, causing us to fall back to the normal modal dialog parent window disabling.
84 void PrepareForModalSubDialog();
85 void CleanupAfterModalSubDialog();
86
87 bool Show( bool show ) override;
88
89 bool Enable( bool enable ) override;
90
91 void OnPaint( wxPaintEvent &event );
92
93 void OnModify();
94 void ClearModify();
95
100 void SetPosition( const wxPoint& aNewPosition );
101
103 {
104 return m_units;
105 }
106
107 void SelectAllInTextCtrls( wxWindowList& children );
108
109 void SetupStandardButtons( std::map<int, wxString> aLabels = {} );
110
111 static bool IsCtrl( int aChar, const wxKeyEvent& e )
112 {
113 return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
114 !e.ShiftDown() && !e.MetaDown();
115 }
116
117 static bool IsShiftCtrl( int aChar, const wxKeyEvent& e )
118 {
119 return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
120 e.ShiftDown() && !e.MetaDown();
121 }
122
123protected:
134 void finishDialogSettings();
135
141 void setSizeInDU( int x, int y );
142
147 int horizPixelsFromDU( int x ) const;
148
153 int vertPixelsFromDU( int y ) const;
154
162 void resetSize();
163
164 virtual void OnCharHook( wxKeyEvent& aEvt );
165
173 virtual void TearDownQuasiModal() {}
174
175private:
180 void OnCloseWindow( wxCloseEvent& aEvent );
181
186 void OnButton( wxCommandEvent& aEvent );
187
188 void onChildSetFocus( wxFocusEvent& aEvent );
189
191
192protected:
193 EDA_UNITS m_units; // userUnits for display and parsing
194 std::string m_hash_key; // alternate for class_map when classname re-used
195
196 // The following disables the storing of a user size. It is used primarily for dialogs
197 // with conditional content which don't need user sizing.
199
200 // On MacOS (at least) SetFocus() calls made in the constructor will fail because a
201 // window that isn't yet visible will return false to AcceptsFocus(). So we must delay
202 // the initial-focus SetFocus() call to the first paint event.
206
207 wxGUIEventLoop* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal
208 // and dismissed
211
213
214 std::vector<wxWindow*> m_tabOrder;
215
216 // The size asked by the caller, used the first time the dialog is created
218
219 // Used to support first-esc-cancels-edit logic
220 std::map<wxWindow*, wxString> m_beforeEditValues;
221};
222
223#endif // DIALOG_SHIM_
const char * name
Definition: DXF_plotter.cpp:59
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:52
static bool IsShiftCtrl(int aChar, const wxKeyEvent &e)
Definition: dialog_shim.h:117
bool m_isClosing
Definition: dialog_shim.h:205
std::vector< wxWindow * > m_tabOrder
Definition: dialog_shim.h:214
bool m_qmodal_showing
Definition: dialog_shim.h:209
virtual void TearDownQuasiModal()
Override this method to perform dialog tear down actions not suitable for object dtor.
Definition: dialog_shim.h:173
static bool IsCtrl(int aChar, const wxKeyEvent &e)
Definition: dialog_shim.h:111
wxGUIEventLoop * m_qmodal_loop
Definition: dialog_shim.h:207
EDA_UNITS m_units
Definition: dialog_shim.h:193
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:66
WINDOW_DISABLER * m_qmodal_parent_disabler
Definition: dialog_shim.h:210
std::string m_hash_key
Definition: dialog_shim.h:194
bool m_firstPaintEvent
Definition: dialog_shim.h:203
std::map< wxWindow *, wxString > m_beforeEditValues
Definition: dialog_shim.h:220
bool IsQuasiModal() const
Definition: dialog_shim.h:77
bool m_useCalculatedSize
Definition: dialog_shim.h:198
wxWindow * m_initialFocusTarget
Definition: dialog_shim.h:204
wxSize m_initialSize
Definition: dialog_shim.h:217
EDA_BASE_FRAME * m_parentFrame
Definition: dialog_shim.h:212
EDA_UNITS GetUserUnits() const
Definition: dialog_shim.h:102
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:46
#define KICOMMON_API
Definition: kicommon.h:28