2012-03-22 07:02:49 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2019-08-30 14:16:34 +00:00
|
|
|
* Copyright (C) 2012-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-03-22 07:02:49 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2016-01-12 16:33:33 +00:00
|
|
|
#ifndef DIALOG_SHIM_
|
|
|
|
#define DIALOG_SHIM_
|
|
|
|
|
2012-03-22 07:02:49 +00:00
|
|
|
#include <wx/dialog.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <kiway_player.h>
|
2019-01-17 12:19:43 +00:00
|
|
|
class wxGridEvent;
|
2012-03-22 07:02:49 +00:00
|
|
|
|
2013-01-18 06:04:25 +00:00
|
|
|
|
2017-12-26 22:35:04 +00:00
|
|
|
|
2018-11-14 23:34:32 +00:00
|
|
|
struct WINDOW_THAWER
|
|
|
|
{
|
|
|
|
WINDOW_THAWER( wxWindow* aWindow )
|
|
|
|
{
|
|
|
|
m_window = aWindow;
|
|
|
|
m_freezeCount = 0;
|
|
|
|
|
|
|
|
while( m_window->IsFrozen() )
|
|
|
|
{
|
|
|
|
m_window->Thaw();
|
|
|
|
m_freezeCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~WINDOW_THAWER()
|
|
|
|
{
|
|
|
|
while( m_freezeCount > 0 )
|
|
|
|
{
|
|
|
|
m_window->Freeze();
|
|
|
|
m_freezeCount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxWindow* m_window;
|
|
|
|
int m_freezeCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-17 23:00:49 +00:00
|
|
|
class WDO_ENABLE_DISABLE;
|
2018-03-06 06:30:46 +00:00
|
|
|
class WX_EVENT_LOOP;
|
2014-08-17 23:00:49 +00:00
|
|
|
|
|
|
|
// These macros are for DIALOG_SHIM only, NOT for KIWAY_PLAYER. KIWAY_PLAYER
|
|
|
|
// has its own support for quasi modal and its platform specific issues are different
|
|
|
|
// than for a wxDialog.
|
|
|
|
#define SHOWQUASIMODAL ShowQuasiModal
|
|
|
|
#define ENDQUASIMODAL EndQuasiModal
|
2014-05-04 19:57:44 +00:00
|
|
|
|
2012-03-22 07:02:49 +00:00
|
|
|
/**
|
2019-11-06 19:15:42 +00:00
|
|
|
* Dialog helper object to sit in the inheritance tree between wxDialog and any class written
|
|
|
|
* by wxFormBuilder.
|
|
|
|
*
|
|
|
|
* To put it there, use wxFormBuilder tool and set:
|
2012-03-22 07:02:49 +00:00
|
|
|
* <br> subclass name = DIALOG_SHIM
|
|
|
|
* <br> subclass header = dialog_shim.h
|
|
|
|
* <br>
|
|
|
|
* in the dialog window's properties.
|
2019-11-06 19:15:42 +00:00
|
|
|
*/
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
class DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER
|
2012-03-22 07:02:49 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
|
2020-11-16 11:16:44 +00:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxDEFAULT_FRAME_STYLE | wxRESIZE_BORDER,
|
|
|
|
const wxString& name = wxDialogNameStr );
|
2012-03-22 07:02:49 +00:00
|
|
|
|
2014-05-04 18:22:27 +00:00
|
|
|
~DIALOG_SHIM();
|
2012-03-22 07:02:49 +00:00
|
|
|
|
2018-07-19 19:15:40 +00:00
|
|
|
/**
|
|
|
|
* Sets the window (usually a wxTextCtrl) that should be focused when the dialog is
|
|
|
|
* shown.
|
|
|
|
*/
|
|
|
|
void SetInitialFocus( wxWindow* aWindow )
|
|
|
|
{
|
|
|
|
m_initialFocusTarget = aWindow;
|
|
|
|
}
|
|
|
|
|
2014-05-04 18:22:27 +00:00
|
|
|
int ShowQuasiModal(); // disable only the parent window, otherwise modal.
|
|
|
|
|
|
|
|
void EndQuasiModal( int retCode ); // End quasi-modal mode
|
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
bool IsQuasiModal() const { return m_qmodal_showing; }
|
2014-05-04 18:22:27 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
bool Show( bool show ) override;
|
2014-05-04 18:22:27 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
bool Enable( bool enable ) override;
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
|
2017-12-26 22:35:04 +00:00
|
|
|
void OnPaint( wxPaintEvent &event );
|
|
|
|
|
2021-10-25 11:34:30 +00:00
|
|
|
void OnModify();
|
|
|
|
|
2021-02-17 19:47:28 +00:00
|
|
|
/** Force the position of the dialog to a new position
|
|
|
|
* @param aNewPosition is the new forced position
|
|
|
|
*/
|
|
|
|
void SetPosition( const wxPoint& aNewPosition );
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
EDA_UNITS GetUserUnits() const
|
|
|
|
{
|
|
|
|
return m_units;
|
|
|
|
}
|
2018-02-03 09:09:53 +00:00
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
void SetupStandardButtons( std::map<int, wxString> aLabels = {} );
|
|
|
|
|
2019-09-05 07:42:01 +00:00
|
|
|
static bool IsCtrl( int aChar, const wxKeyEvent& e )
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
|
|
|
|
!e.ShiftDown() && !e.MetaDown();
|
2019-09-05 07:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsShiftCtrl( int aChar, const wxKeyEvent& e )
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
|
|
|
|
e.ShiftDown() && !e.MetaDown();
|
2019-09-05 07:42:01 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 06:04:20 +00:00
|
|
|
protected:
|
2016-07-02 09:35:52 +00:00
|
|
|
/**
|
2020-11-16 11:16:44 +00:00
|
|
|
* In all dialogs, we must call the same functions to fix minimal dlg size, the default
|
|
|
|
* position and perhaps some others to fix a few issues depending on Windows Managers
|
2016-07-02 09:35:52 +00:00
|
|
|
* this helper function does these calls.
|
|
|
|
*
|
2020-11-16 11:16:44 +00:00
|
|
|
* finishDialogSettings must be called from derived classes after all widgets have been
|
|
|
|
* initialized, and therefore their size fixed. If TransferDataToWindow() is used to
|
|
|
|
* initialize widgets, at the end of TransferDataToWindow, or better yet, at end of a
|
|
|
|
* wxInitDialogEvent handler.
|
2016-07-02 09:35:52 +00:00
|
|
|
*/
|
2020-11-16 11:16:44 +00:00
|
|
|
void finishDialogSettings();
|
2016-07-02 09:35:52 +00:00
|
|
|
|
2018-01-06 02:33:41 +00:00
|
|
|
/**
|
2018-01-06 18:18:28 +00:00
|
|
|
* Set the dialog to the given dimensions in "dialog units". These are units equivalent
|
|
|
|
* to 4* the average character width and 8* the average character height, allowing a dialog
|
|
|
|
* to be sized in a way that scales it with the system font.
|
|
|
|
*/
|
2020-11-16 11:16:44 +00:00
|
|
|
void setSizeInDU( int x, int y );
|
2018-01-06 18:18:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert an integer number of dialog units to pixels, horizontally. See SetSizeInDU or
|
|
|
|
* wxDialog documentation for more information.
|
|
|
|
*/
|
2020-11-18 19:50:36 +00:00
|
|
|
int horizPixelsFromDU( int x ) const;
|
2018-01-06 18:18:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert an integer number of dialog units to pixels, vertically. See SetSizeInDU or
|
|
|
|
* wxDialog documentation for more information.
|
2018-01-06 02:33:41 +00:00
|
|
|
*/
|
2020-11-18 19:50:36 +00:00
|
|
|
int vertPixelsFromDU( int y ) const;
|
2018-01-06 02:33:41 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
/**
|
|
|
|
* Clear the existing dialog size and position.
|
|
|
|
*
|
|
|
|
* This will cause the dialog size to be clear so the next time the dialog is shown
|
|
|
|
* the sizers will layout the dialog accordingly. This useful when there are dialog
|
|
|
|
* windows that size changes due to layout dependency hidden controls.
|
|
|
|
*/
|
2020-11-16 11:16:44 +00:00
|
|
|
void resetSize();
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2020-12-18 14:04:03 +00:00
|
|
|
virtual void OnCharHook( wxKeyEvent& aEvt );
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Properly handle the wxCloseEvent when in the quasimodal mode when not calling
|
|
|
|
* EndQuasiModal which is possible with any dialog derived from #DIALOG_SHIM.
|
|
|
|
*/
|
|
|
|
void OnCloseWindow( wxCloseEvent& aEvent );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Properly handle the default button events when in the quasimodal mode when not
|
|
|
|
* calling EndQuasiModal which is possible with any dialog derived from #DIALOG_SHIM.
|
|
|
|
*/
|
|
|
|
void OnButton( wxCommandEvent& aEvent );
|
|
|
|
|
|
|
|
void OnGridEditorShown( wxGridEvent& event );
|
|
|
|
void OnGridEditorHidden( wxGridEvent& event );
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE();
|
|
|
|
|
|
|
|
protected:
|
2020-11-16 11:16:44 +00:00
|
|
|
EDA_UNITS m_units; // userUnits for display and parsing
|
|
|
|
std::string m_hash_key; // alternate for class_map when classname re-used
|
2013-01-18 06:04:25 +00:00
|
|
|
|
2021-01-07 00:45:32 +00:00
|
|
|
// The following disables the storing of a user size. It is used primarily for dialogs
|
|
|
|
// with conditional content which don't need user sizing.
|
|
|
|
bool m_useCalculatedSize;
|
|
|
|
|
2018-03-06 05:33:04 +00:00
|
|
|
// On MacOS (at least) SetFocus() calls made in the constructor will fail because a
|
|
|
|
// window that isn't yet visible will return false to AcceptsFocus(). So we must delay
|
|
|
|
// the initial-focus SetFocus() call to the first paint event.
|
2019-08-22 20:16:40 +00:00
|
|
|
bool m_firstPaintEvent;
|
|
|
|
wxWindow* m_initialFocusTarget;
|
2018-03-06 05:33:04 +00:00
|
|
|
|
2019-08-22 20:16:40 +00:00
|
|
|
WX_EVENT_LOOP* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal
|
|
|
|
// and dismissed
|
|
|
|
bool m_qmodal_showing;
|
|
|
|
WDO_ENABLE_DISABLE* m_qmodal_parent_disabler;
|
|
|
|
|
2020-05-02 13:36:29 +00:00
|
|
|
EDA_BASE_FRAME* m_parentFrame;
|
|
|
|
|
2019-08-22 20:16:40 +00:00
|
|
|
std::vector<wxWindow*> m_tabOrder;
|
2021-07-24 16:59:28 +00:00
|
|
|
|
|
|
|
// The size asked by the caller, used the first time the dialog is created
|
|
|
|
wxSize m_initialSize;
|
2012-03-22 07:02:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DIALOG_SHIM_
|