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-2016 KiCad Developers, see CHANGELOG.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 #ifdef __WXMAC__
33 
36 #define DLGSHIM_USE_SETFOCUS 1
37 #else
38 #define DLGSHIM_USE_SETFOCUS 0
39 #endif
40 
41 class WDO_ENABLE_DISABLE;
42 class EVENT_LOOP;
43 
44 // These macros are for DIALOG_SHIM only, NOT for KIWAY_PLAYER. KIWAY_PLAYER
45 // has its own support for quasi modal and its platform specific issues are different
46 // than for a wxDialog.
47  #define SHOWQUASIMODAL ShowQuasiModal
48  #define ENDQUASIMODAL EndQuasiModal
49 
50 
60 class DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER
61 {
68  void OnCloseWindow( wxCloseEvent& aEvent );
69 
76  void OnButton( wxCommandEvent& aEvent );
77 
78 public:
79 
80  DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
81  const wxPoint& pos = wxDefaultPosition,
82  const wxSize& size = wxDefaultSize,
83  long style = wxDEFAULT_DIALOG_STYLE,
84  const wxString& name = wxDialogNameStr
85  );
86 
87  ~DIALOG_SHIM();
88 
89  int ShowQuasiModal(); // disable only the parent window, otherwise modal.
90 
91  void EndQuasiModal( int retCode ); // End quasi-modal mode
92 
93  bool IsQuasiModal() { return m_qmodal_showing; }
94 
95  bool Show( bool show ) override;
96 
97  bool Enable( bool enable ) override;
98 
99 protected:
100 
116  void FinishDialogSettings();
117 
127 
128  std::string m_hash_key; // alternate for class_map when classname re-used.
129 
130  // variables for quasi-modal behavior support, only used by a few derivatives.
131  EVENT_LOOP* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal and dismissed
134 
135 #if DLGSHIM_USE_SETFOCUS
136 private:
137  void onInit( wxInitDialogEvent& aEvent );
138 #endif
139 };
140 
141 #endif // DIALOG_SHIM_
bool m_qmodal_showing
Definition: dialog_shim.h:132
Class KIWAY_HOLDER is a mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_player.h:48
void OnButton(wxCommandEvent &aEvent)
Function OnCloseWindow.
std::string m_hash_key
Definition: dialog_shim.h:128
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_SHIM may sit in the inheritance tree between wxDialog and any class written by wxFormBui...
Definition: dialog_shim.h:60
EVENT_LOOP * m_qmodal_loop
Definition: dialog_shim.h:131
void FixOSXCancelButtonIssue()
A ugly hack to fix an issue on OSX: when typing ctrl+c in a wxTextCtrl inside a dialog, it is closed instead of copying a text if a button with wxID_CANCEL is used in a wxStdDialogButtonSizer, when the dlg is created by wxFormBuilder: the label is &Cancel, and this accelerator key has priority to copy text standard accelerator, and the dlg is closed when trying to copy text this function do nothing on other platforms.
void OnCloseWindow(wxCloseEvent &aEvent)
Function OnCloseWindow.
int ShowQuasiModal()
bool IsQuasiModal()
Definition: dialog_shim.h:93
bool Show(bool show) override
WDO_ENABLE_DISABLE * m_qmodal_parent_disabler
Definition: dialog_shim.h:133
void EndQuasiModal(int retCode)
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const wxString &name=wxDialogNameStr)
Definition: dialog_shim.cpp:57
Toggle a window's "enable" status to disabled, then enabled on destruction.
Definition: dialog_shim.cpp:33
bool Enable(bool enable) override