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 <dick@softplc.com>
5  * Copyright (C) 2012-2018 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 <hashtables.h>
30 #include <kiway_player.h>
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();
44  m_freezeCount++;
45  }
46  }
47 
49  {
50  while( m_freezeCount > 0 )
51  {
52  m_window->Freeze();
53  m_freezeCount--;
54  }
55  }
56 
57 protected:
58  wxWindow* m_window;
60 };
61 
62 
63 class WDO_ENABLE_DISABLE;
64 class 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 
72 
82 class DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER
83 {
90  void OnCloseWindow( wxCloseEvent& aEvent );
91 
98  void OnButton( wxCommandEvent& aEvent );
99 
100 public:
101 
102  DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
103  const wxPoint& pos = wxDefaultPosition,
104  const wxSize& size = wxDefaultSize,
105  long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER,
106  const wxString& name = wxDialogNameStr
107  );
108 
109  ~DIALOG_SHIM();
110 
115  void SetInitialFocus( wxWindow* aWindow )
116  {
117  m_initialFocusTarget = aWindow;
118  }
119 
120  int ShowQuasiModal(); // disable only the parent window, otherwise modal.
121 
122  void EndQuasiModal( int retCode ); // End quasi-modal mode
123 
124  bool IsQuasiModal() { return m_qmodal_showing; }
125 
126  bool Show( bool show ) override;
127 
128  bool Enable( bool enable ) override;
129 
130  void OnPaint( wxPaintEvent &event );
131 
132  EDA_UNITS_T GetUserUnits() const override { return m_units; }
133 
134 protected:
135 
151  void FinishDialogSettings();
152 
158  void SetSizeInDU( int x, int y );
159 
164  int HorizPixelsFromDU( int x );
165 
170  int VertPixelsFromDU( int y );
171 
172  EDA_UNITS_T m_units; // userUnits for display and parsing
173  std::string m_hash_key; // alternate for class_map when classname re-used
174 
175  // On MacOS (at least) SetFocus() calls made in the constructor will fail because a
176  // window that isn't yet visible will return false to AcceptsFocus(). So we must delay
177  // the initial-focus SetFocus() call to the first paint event.
180 
181  // variables for quasi-modal behavior support, only used by a few derivatives.
182  WX_EVENT_LOOP* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal and dismissed
185 };
186 
187 #endif // DIALOG_SHIM_
bool m_qmodal_showing
Definition: dialog_shim.h:183
Class KIWAY_HOLDER is a mix in class which holds the location of a wxWindow&#39;s KIWAY.
Definition: kiway_player.h:48
#define WX_EVENT_LOOP
Definition: kiway_player.h:100
std::string m_hash_key
Definition: dialog_shim.h:173
wxWindow * m_initialFocusTarget
Definition: dialog_shim.h:179
Class DIALOG_SHIM may sit in the inheritance tree between wxDialog and any class written by wxFormBui...
Definition: dialog_shim.h:82
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:115
bool m_firstPaintEvent
Definition: dialog_shim.h:178
WX_EVENT_LOOP * m_qmodal_loop
Definition: dialog_shim.h:182
WINDOW_THAWER(wxWindow *aWindow)
Definition: dialog_shim.h:36
bool IsQuasiModal()
Definition: dialog_shim.h:124
wxWindow * m_window
Definition: dialog_shim.h:58
WDO_ENABLE_DISABLE * m_qmodal_parent_disabler
Definition: dialog_shim.h:184
const char * name
Definition: DXF_plotter.cpp:61
Toggle a window&#39;s "enable" status to disabled, then enabled on destruction.
Definition: dialog_shim.cpp:33
EDA_UNITS_T m_units
Definition: dialog_shim.h:172
EDA_UNITS_T
Definition: common.h:159
EDA_UNITS_T GetUserUnits() const override
Definition: dialog_shim.h:132