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>
|
2020-08-18 14:17:16 +00:00
|
|
|
* Copyright (C) 2012-2020 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dialog_shim.h>
|
2021-10-05 16:57:25 +00:00
|
|
|
#include <ignore.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>
|
2022-07-12 21:44:53 +00:00
|
|
|
#include <kiway.h>
|
2015-08-28 14:15:45 +00:00
|
|
|
#include <pgm_base.h>
|
2019-04-08 18:59:23 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2020-06-03 14:58:54 +00:00
|
|
|
#include <kiplatform/ui.h>
|
|
|
|
|
2018-03-19 23:02:22 +00:00
|
|
|
#include <wx/display.h>
|
2020-06-03 14:58:54 +00:00
|
|
|
#include <wx/evtloop.h>
|
2020-10-18 11:31:07 +00:00
|
|
|
#include <wx/app.h>
|
|
|
|
#include <wx/event.h>
|
2019-01-17 12:19:43 +00:00
|
|
|
#include <wx/grid.h>
|
2020-11-13 17:52:08 +00:00
|
|
|
#include <wx/bmpbuttn.h>
|
2021-06-03 11:49:49 +00:00
|
|
|
#include <wx/textctrl.h>
|
2021-07-27 23:15:55 +00:00
|
|
|
#include <wx/stc/stc.h>
|
2014-05-04 18:22:27 +00:00
|
|
|
|
2020-07-11 09:37:22 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2014-08-17 23:00:49 +00:00
|
|
|
/// Toggle a window's "enable" status to disabled, then enabled on destruction.
|
|
|
|
class WDO_ENABLE_DISABLE
|
|
|
|
{
|
|
|
|
wxWindow* m_win;
|
2014-05-04 18:22:27 +00:00
|
|
|
|
2014-08-17 23:00:49 +00:00
|
|
|
public:
|
2014-05-04 18:22:27 +00:00
|
|
|
|
2014-08-17 23:00:49 +00:00
|
|
|
WDO_ENABLE_DISABLE( wxWindow* aWindow ) :
|
|
|
|
m_win( aWindow )
|
|
|
|
{
|
|
|
|
if( m_win )
|
|
|
|
m_win->Disable();
|
|
|
|
}
|
2014-05-04 18:22:27 +00:00
|
|
|
|
2014-08-17 23:00:49 +00:00
|
|
|
~WDO_ENABLE_DISABLE()
|
|
|
|
{
|
|
|
|
if( m_win )
|
|
|
|
{
|
|
|
|
m_win->Enable();
|
|
|
|
m_win->SetFocus(); // let's focus back on the parent window
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-05-04 18:22:27 +00:00
|
|
|
|
2012-03-22 07:02:49 +00:00
|
|
|
|
2019-01-17 12:19:43 +00:00
|
|
|
BEGIN_EVENT_TABLE( DIALOG_SHIM, wxDialog )
|
|
|
|
// If dialog has a grid and the grid has an active cell editor
|
|
|
|
// Esc key closes cell editor, otherwise Esc key closes the dialog.
|
|
|
|
EVT_GRID_EDITOR_SHOWN( DIALOG_SHIM::OnGridEditorShown )
|
|
|
|
EVT_GRID_EDITOR_HIDDEN( DIALOG_SHIM::OnGridEditorHidden )
|
2019-08-13 15:52:34 +00:00
|
|
|
EVT_CHAR_HOOK( DIALOG_SHIM::OnCharHook )
|
2019-01-17 12:19:43 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2012-03-22 07:02:49 +00:00
|
|
|
DIALOG_SHIM::DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
|
2020-11-26 11:57:40 +00:00
|
|
|
const wxPoint& pos, const wxSize& size, long style,
|
|
|
|
const wxString& name ) :
|
|
|
|
wxDialog( aParent, id, title, pos, size, style, name ),
|
|
|
|
KIWAY_HOLDER( nullptr, KIWAY_HOLDER::DIALOG ),
|
|
|
|
m_units( EDA_UNITS::MILLIMETRES ),
|
2021-01-07 19:53:52 +00:00
|
|
|
m_useCalculatedSize( false ),
|
2020-11-26 11:57:40 +00:00
|
|
|
m_firstPaintEvent( true ),
|
|
|
|
m_initialFocusTarget( nullptr ),
|
|
|
|
m_qmodal_loop( nullptr ),
|
|
|
|
m_qmodal_showing( false ),
|
|
|
|
m_qmodal_parent_disabler( nullptr ),
|
|
|
|
m_parentFrame( nullptr )
|
2012-03-22 07:02:49 +00:00
|
|
|
{
|
2018-07-19 23:06:53 +00:00
|
|
|
KIWAY_HOLDER* kiwayHolder = nullptr;
|
2021-07-24 16:59:28 +00:00
|
|
|
m_initialSize = size;
|
2018-07-19 23:06:53 +00:00
|
|
|
|
|
|
|
if( aParent )
|
2018-02-03 09:09:53 +00:00
|
|
|
{
|
2018-07-19 23:06:53 +00:00
|
|
|
kiwayHolder = dynamic_cast<KIWAY_HOLDER*>( aParent );
|
|
|
|
|
|
|
|
while( !kiwayHolder && aParent->GetParent() )
|
|
|
|
{
|
|
|
|
aParent = aParent->GetParent();
|
|
|
|
kiwayHolder = dynamic_cast<KIWAY_HOLDER*>( aParent );
|
|
|
|
}
|
|
|
|
}
|
2018-02-03 09:09:53 +00:00
|
|
|
|
2019-06-08 22:14:57 +00:00
|
|
|
// Inherit units from parent
|
|
|
|
if( kiwayHolder && kiwayHolder->GetType() == KIWAY_HOLDER::FRAME )
|
|
|
|
m_units = static_cast<EDA_BASE_FRAME*>( kiwayHolder )->GetUserUnits();
|
|
|
|
else if( kiwayHolder && kiwayHolder->GetType() == KIWAY_HOLDER::DIALOG )
|
|
|
|
m_units = static_cast<DIALOG_SHIM*>( kiwayHolder )->GetUserUnits();
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2019-06-08 22:14:57 +00:00
|
|
|
// Don't mouse-warp after a dialog run from the context menu
|
|
|
|
if( kiwayHolder && kiwayHolder->GetType() == KIWAY_HOLDER::FRAME )
|
|
|
|
{
|
2020-05-02 13:36:29 +00:00
|
|
|
m_parentFrame = static_cast<EDA_BASE_FRAME*>( kiwayHolder );
|
|
|
|
TOOL_MANAGER* toolMgr = m_parentFrame->GetToolManager();
|
2019-04-08 18:59:23 +00:00
|
|
|
|
2019-06-19 20:04:34 +00:00
|
|
|
if( toolMgr && toolMgr->IsContextMenuActive() )
|
2019-04-08 18:59:23 +00:00
|
|
|
toolMgr->VetoContextMenuMouseWarp();
|
2019-06-08 22:14:57 +00:00
|
|
|
}
|
2019-04-08 18:59:23 +00:00
|
|
|
|
2019-06-08 22:14:57 +00:00
|
|
|
// Set up the message bus
|
|
|
|
if( kiwayHolder )
|
2018-07-19 23:06:53 +00:00
|
|
|
SetKiway( this, &kiwayHolder->Kiway() );
|
* 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
|
|
|
|
2022-07-14 18:36:07 +00:00
|
|
|
if( HasKiway() )
|
|
|
|
Kiway().SetBlockingDialog( this );
|
2022-07-12 21:44:53 +00:00
|
|
|
|
2016-04-11 23:39:43 +00:00
|
|
|
Bind( wxEVT_CLOSE_WINDOW, &DIALOG_SHIM::OnCloseWindow, this );
|
|
|
|
Bind( wxEVT_BUTTON, &DIALOG_SHIM::OnButton, this );
|
|
|
|
|
2015-08-28 14:15:45 +00:00
|
|
|
#ifdef __WINDOWS__
|
2019-11-06 19:15:42 +00:00
|
|
|
// On Windows, the app top windows can be brought to the foreground (at least temporarily)
|
2019-06-08 22:14:57 +00:00
|
|
|
// in certain circumstances such as when calling an external tool in Eeschema BOM generation.
|
|
|
|
// So set the parent frame (if exists) to top window to avoid this annoying behavior.
|
|
|
|
if( kiwayHolder && kiwayHolder->GetType() == KIWAY_HOLDER::FRAME )
|
|
|
|
Pgm().App().SetTopWindow( (EDA_BASE_FRAME*) kiwayHolder );
|
2015-08-28 14:15:45 +00:00
|
|
|
#endif
|
|
|
|
|
2017-12-26 22:35:04 +00:00
|
|
|
Connect( wxEVT_PAINT, wxPaintEventHandler( DIALOG_SHIM::OnPaint ) );
|
2012-03-22 07:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-04 18:22:27 +00:00
|
|
|
DIALOG_SHIM::~DIALOG_SHIM()
|
|
|
|
{
|
|
|
|
// if the dialog is quasi-modal, this will end its event loop
|
|
|
|
if( IsQuasiModal() )
|
|
|
|
EndQuasiModal( wxID_CANCEL );
|
2014-08-17 23:00:49 +00:00
|
|
|
|
2022-07-14 18:36:07 +00:00
|
|
|
if( HasKiway() )
|
|
|
|
Kiway().SetBlockingDialog( nullptr );
|
2022-07-12 21:44:53 +00:00
|
|
|
|
2017-04-02 12:09:01 +00:00
|
|
|
if( m_qmodal_parent_disabler )
|
|
|
|
delete m_qmodal_parent_disabler; // usually NULL by now
|
2014-05-04 18:22:27 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 02:33:41 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
void DIALOG_SHIM::finishDialogSettings()
|
2016-07-02 09:35:52 +00:00
|
|
|
{
|
|
|
|
// must be called from the constructor of derived classes,
|
|
|
|
// when all widgets are initialized, and therefore their size fixed
|
|
|
|
|
|
|
|
// SetSizeHints fixes the minimal size of sizers in the dialog
|
|
|
|
// (SetSizeHints calls Fit(), so no need to call it)
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
}
|
2014-05-04 18:22:27 +00:00
|
|
|
|
2016-07-14 14:25:35 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
void DIALOG_SHIM::setSizeInDU( int x, int y )
|
2018-01-06 02:33:41 +00:00
|
|
|
{
|
2018-01-06 21:51:07 +00:00
|
|
|
wxSize sz( x, y );
|
|
|
|
SetSize( ConvertDialogToPixels( sz ) );
|
2018-01-06 18:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
int DIALOG_SHIM::horizPixelsFromDU( int x ) const
|
2018-01-06 18:18:28 +00:00
|
|
|
{
|
2018-01-06 21:51:07 +00:00
|
|
|
wxSize sz( x, 0 );
|
2018-01-06 18:18:28 +00:00
|
|
|
return ConvertDialogToPixels( sz ).x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
int DIALOG_SHIM::vertPixelsFromDU( int y ) const
|
2018-01-06 18:18:28 +00:00
|
|
|
{
|
2018-01-06 21:51:07 +00:00
|
|
|
wxSize sz( 0, y );
|
2018-01-06 18:18:28 +00:00
|
|
|
return ConvertDialogToPixels( sz ).y;
|
2018-01-06 02:33:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-22 07:02:49 +00:00
|
|
|
// our hashtable is an implementation secret, don't need or want it in a header file
|
|
|
|
#include <hashtables.h>
|
|
|
|
#include <typeinfo>
|
|
|
|
|
2021-06-04 01:11:08 +00:00
|
|
|
static std::unordered_map<std::string, wxRect> class_map;
|
2012-03-22 07:02:49 +00:00
|
|
|
|
2021-02-17 19:47:28 +00:00
|
|
|
|
|
|
|
void DIALOG_SHIM::SetPosition( const wxPoint& aNewPosition )
|
|
|
|
{
|
|
|
|
wxDialog::SetPosition( aNewPosition );
|
|
|
|
|
|
|
|
// Now update the stored position:
|
|
|
|
const char* hash_key;
|
|
|
|
|
|
|
|
if( m_hash_key.size() )
|
|
|
|
{
|
|
|
|
// a special case like EDA_LIST_DIALOG, which has multiple uses.
|
|
|
|
hash_key = m_hash_key.c_str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hash_key = typeid(*this).name();
|
|
|
|
}
|
|
|
|
|
2021-06-04 01:11:08 +00:00
|
|
|
std::unordered_map<std::string, wxRect>::iterator it = class_map.find( hash_key );
|
2021-02-17 19:47:28 +00:00
|
|
|
|
|
|
|
if( it == class_map.end() )
|
|
|
|
return;
|
|
|
|
|
2021-06-04 01:11:08 +00:00
|
|
|
wxRect rect = it->second;
|
|
|
|
rect.SetPosition( aNewPosition );
|
2021-02-17 19:47:28 +00:00
|
|
|
|
|
|
|
class_map[ hash_key ] = rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-22 07:02:49 +00:00
|
|
|
bool DIALOG_SHIM::Show( bool show )
|
|
|
|
{
|
|
|
|
bool ret;
|
2013-11-17 06:04:20 +00:00
|
|
|
const char* hash_key;
|
|
|
|
|
|
|
|
if( m_hash_key.size() )
|
|
|
|
{
|
|
|
|
// a special case like EDA_LIST_DIALOG, which has multiple uses.
|
|
|
|
hash_key = m_hash_key.c_str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hash_key = typeid(*this).name();
|
|
|
|
}
|
2012-03-22 07:02:49 +00:00
|
|
|
|
|
|
|
// Show or hide the window. If hiding, save current position and size.
|
|
|
|
// If showing, use previous position and size.
|
|
|
|
if( show )
|
|
|
|
{
|
2017-11-19 01:39:52 +00:00
|
|
|
#ifndef __WINDOWS__
|
2015-07-15 08:18:48 +00:00
|
|
|
wxDialog::Raise(); // Needed on OS X and some other window managers (i.e. Unity)
|
2017-11-19 01:39:52 +00:00
|
|
|
#endif
|
2012-03-22 07:02:49 +00:00
|
|
|
ret = wxDialog::Show( show );
|
|
|
|
|
|
|
|
// classname is key, returns a zeroed out default EDA_RECT if none existed before.
|
2021-06-04 01:11:08 +00:00
|
|
|
wxRect savedDialogRect = class_map[ hash_key ];
|
2012-03-22 07:02:49 +00:00
|
|
|
|
2018-02-19 01:15:30 +00:00
|
|
|
if( savedDialogRect.GetSize().x != 0 && savedDialogRect.GetSize().y != 0 )
|
|
|
|
{
|
2021-01-07 00:45:32 +00:00
|
|
|
if( m_useCalculatedSize )
|
|
|
|
{
|
|
|
|
SetSize( savedDialogRect.GetPosition().x, savedDialogRect.GetPosition().y,
|
|
|
|
wxDialog::GetSize().x, wxDialog::GetSize().y, 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetSize( savedDialogRect.GetPosition().x, savedDialogRect.GetPosition().y,
|
|
|
|
std::max( wxDialog::GetSize().x, savedDialogRect.GetSize().x ),
|
|
|
|
std::max( wxDialog::GetSize().y, savedDialogRect.GetSize().y ),
|
|
|
|
0 );
|
|
|
|
}
|
2018-02-19 01:15:30 +00:00
|
|
|
}
|
2021-07-24 16:59:28 +00:00
|
|
|
else if( m_initialSize != wxDefaultSize )
|
|
|
|
SetSize( m_initialSize );
|
2018-03-19 23:02:22 +00:00
|
|
|
|
|
|
|
// Be sure that the dialog appears in a visible area
|
|
|
|
// (the dialog position might have been stored at the time when it was
|
|
|
|
// shown on another display)
|
|
|
|
if( wxDisplay::GetFromWindow( this ) == wxNOT_FOUND )
|
|
|
|
Centre();
|
2012-03-22 07:02:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Save the dialog's position & size before hiding, using classname as key
|
2021-06-04 01:11:08 +00:00
|
|
|
class_map[ hash_key ] = wxRect( wxDialog::GetPosition(), wxDialog::GetSize() );
|
2012-03-22 07:02:49 +00:00
|
|
|
|
2018-01-26 16:44:17 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
if ( m_eventLoop )
|
|
|
|
m_eventLoop->Exit( GetReturnCode() ); // Needed for APP-MODAL dlgs on OSX
|
|
|
|
#endif
|
|
|
|
|
2012-03-22 07:02:49 +00:00
|
|
|
ret = wxDialog::Show( show );
|
|
|
|
}
|
2017-01-27 20:31:35 +00:00
|
|
|
|
2012-03-22 07:02:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-18 06:04:25 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
void DIALOG_SHIM::resetSize()
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
|
|
|
const char* hash_key;
|
|
|
|
|
|
|
|
if( m_hash_key.size() )
|
|
|
|
{
|
|
|
|
// a special case like EDA_LIST_DIALOG, which has multiple uses.
|
|
|
|
hash_key = m_hash_key.c_str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hash_key = typeid(*this).name();
|
|
|
|
}
|
|
|
|
|
2021-06-04 01:11:08 +00:00
|
|
|
std::unordered_map<std::string, wxRect>::iterator it = class_map.find( hash_key );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
if( it == class_map.end() )
|
|
|
|
return;
|
|
|
|
|
2021-06-04 01:11:08 +00:00
|
|
|
wxRect rect = it->second;
|
|
|
|
rect.SetSize( wxSize( 0, 0 ) );
|
2019-11-06 19:15:42 +00:00
|
|
|
class_map[ hash_key ] = rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-04 18:22:27 +00:00
|
|
|
bool DIALOG_SHIM::Enable( bool enable )
|
|
|
|
{
|
2014-05-04 19:57:44 +00:00
|
|
|
// so we can do logging of this state change:
|
2014-05-04 18:22:27 +00:00
|
|
|
return wxDialog::Enable( enable );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-06 05:33:04 +00:00
|
|
|
// Recursive descent doing a SelectAll() in wxTextCtrls.
|
|
|
|
// MacOS User Interface Guidelines state that when tabbing to a text control all its
|
|
|
|
// text should be selected. Since wxWidgets fails to implement this, we do it here.
|
|
|
|
static void selectAllInTextCtrls( wxWindowList& children )
|
2014-08-17 23:00:49 +00:00
|
|
|
{
|
2018-03-06 05:33:04 +00:00
|
|
|
for( wxWindow* child : children )
|
2014-08-17 23:00:49 +00:00
|
|
|
{
|
2020-11-13 17:52:08 +00:00
|
|
|
if( wxTextCtrl* childTextCtrl = dynamic_cast<wxTextCtrl*>( child ) )
|
2014-08-17 23:00:49 +00:00
|
|
|
{
|
2021-07-27 23:15:55 +00:00
|
|
|
// We don't currently run this on GTK because some window managers don't hide the
|
|
|
|
// selection in non-active controls, and other window managers do the selection
|
|
|
|
// automatically anyway.
|
2021-06-20 12:36:36 +00:00
|
|
|
#if defined( __WXMAC__ ) || defined( __WXMSW__ )
|
2021-07-27 23:15:55 +00:00
|
|
|
if( !childTextCtrl->GetStringSelection().IsEmpty() )
|
|
|
|
{
|
|
|
|
// Respect an existing selection
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-13 14:00:45 +00:00
|
|
|
childTextCtrl->SelectAll();
|
2021-07-27 23:15:55 +00:00
|
|
|
}
|
2021-10-05 16:57:25 +00:00
|
|
|
#else
|
|
|
|
ignore_unused( childTextCtrl );
|
2021-06-20 12:36:36 +00:00
|
|
|
#endif
|
2018-03-06 05:33:04 +00:00
|
|
|
}
|
2021-07-27 23:15:55 +00:00
|
|
|
else if( wxStyledTextCtrl* scintilla = dynamic_cast<wxStyledTextCtrl*>( child ) )
|
|
|
|
{
|
|
|
|
if( !scintilla->GetSelectedText().IsEmpty() )
|
|
|
|
{
|
|
|
|
// Respect an existing selection
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scintilla->SelectAll();
|
|
|
|
}
|
|
|
|
}
|
2020-11-13 17:52:08 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
// Temp hack for square (looking) buttons on OSX. Will likely be made redundant
|
|
|
|
// by the image store....
|
|
|
|
else if( dynamic_cast<wxBitmapButton*>( child ) != nullptr )
|
|
|
|
{
|
|
|
|
wxSize minSize( 29, 27 );
|
|
|
|
wxRect rect = child->GetRect();
|
|
|
|
|
|
|
|
child->ConvertDialogToPixels( minSize );
|
|
|
|
|
|
|
|
rect.Inflate( std::max( 0, minSize.x - rect.GetWidth() ),
|
|
|
|
std::max( 0, minSize.y - rect.GetHeight() ) );
|
|
|
|
|
2020-12-06 14:57:26 +00:00
|
|
|
child->SetMinSize( rect.GetSize() );
|
2020-11-13 17:52:08 +00:00
|
|
|
child->SetSize( rect );
|
|
|
|
}
|
|
|
|
#endif
|
2018-03-06 05:33:04 +00:00
|
|
|
else
|
2020-11-13 17:52:08 +00:00
|
|
|
{
|
2018-03-06 05:33:04 +00:00
|
|
|
selectAllInTextCtrls( child->GetChildren() );
|
2020-11-13 17:52:08 +00:00
|
|
|
}
|
2017-12-26 22:35:04 +00:00
|
|
|
}
|
2014-08-17 23:00:49 +00:00
|
|
|
}
|
2018-03-06 05:33:04 +00:00
|
|
|
|
2014-08-17 23:00:49 +00:00
|
|
|
|
2017-12-26 22:35:04 +00:00
|
|
|
void DIALOG_SHIM::OnPaint( wxPaintEvent &event )
|
2014-08-17 23:00:49 +00:00
|
|
|
{
|
2018-03-06 05:33:04 +00:00
|
|
|
if( m_firstPaintEvent )
|
2017-12-26 22:35:04 +00:00
|
|
|
{
|
2020-06-04 21:26:15 +00:00
|
|
|
KIPLATFORM::UI::FixupCancelButtonCmdKeyCollision( this );
|
2017-12-26 22:35:04 +00:00
|
|
|
|
2019-04-03 18:53:13 +00:00
|
|
|
selectAllInTextCtrls( GetChildren() );
|
|
|
|
|
2018-03-06 05:33:04 +00:00
|
|
|
if( m_initialFocusTarget )
|
2020-11-26 15:43:48 +00:00
|
|
|
KIPLATFORM::UI::ForceFocus( m_initialFocusTarget );
|
2018-03-06 05:33:04 +00:00
|
|
|
else
|
2020-11-26 15:43:48 +00:00
|
|
|
KIPLATFORM::UI::ForceFocus( this ); // Focus the dialog itself
|
2018-03-06 05:33:04 +00:00
|
|
|
|
|
|
|
m_firstPaintEvent = false;
|
2014-08-17 23:00:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-26 22:35:04 +00:00
|
|
|
event.Skip();
|
2014-08-17 23:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-25 11:34:30 +00:00
|
|
|
void DIALOG_SHIM::OnModify()
|
|
|
|
{
|
2022-02-05 00:24:26 +00:00
|
|
|
if( !GetTitle().StartsWith( wxT( "*" ) ) )
|
|
|
|
SetTitle( wxT( "*" ) + GetTitle() );
|
2021-10-25 11:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-17 23:00:49 +00:00
|
|
|
/*
|
|
|
|
Quasi-Modal Mode Explained:
|
|
|
|
|
|
|
|
The gtk calls in wxDialog::ShowModal() cause event routing problems if that
|
|
|
|
modal dialog then tries to use KIWAY_PLAYER::ShowModal(). The latter shows up
|
|
|
|
and mostly works but does not respond to the window decoration close button.
|
|
|
|
There is no way to get around this without reversing the gtk calls temporarily.
|
|
|
|
|
|
|
|
Quasi-Modal mode is our own almost modal mode which disables only the parent
|
|
|
|
of the DIALOG_SHIM, leaving other frames operable and while staying captured in the
|
|
|
|
nested event loop. This avoids the gtk calls and leaves event routing pure
|
|
|
|
and sufficient to operate the KIWAY_PLAYER::ShowModal() properly. When using
|
|
|
|
ShowQuasiModal() you have to use EndQuasiModal() in your dialogs and not
|
|
|
|
EndModal(). There is also IsQuasiModal() but its value can only be true
|
|
|
|
when the nested event loop is active. Do not mix the modal and quasi-modal
|
|
|
|
functions. Use one set or the other.
|
|
|
|
|
|
|
|
You might find this behavior preferable over a pure modal mode, and it was said
|
|
|
|
that only the Mac has this natively, but now other platforms have something
|
|
|
|
similar. You CAN use it anywhere for any dialog. But you MUST use it when
|
|
|
|
you want to use KIWAY_PLAYER::ShowModal() from a dialog event.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int DIALOG_SHIM::ShowQuasiModal()
|
|
|
|
{
|
2014-05-04 18:22:27 +00:00
|
|
|
// This is an exception safe way to zero a pointer before returning.
|
|
|
|
// Yes, even though DismissModal() clears this first normally, this is
|
|
|
|
// here in case there's an exception before the dialog is dismissed.
|
|
|
|
struct NULLER
|
|
|
|
{
|
|
|
|
void*& m_what;
|
|
|
|
NULLER( void*& aPtr ) : m_what( aPtr ) {}
|
2021-04-22 21:20:34 +00:00
|
|
|
~NULLER() { m_what = nullptr; } // indeed, set it to NULL on destruction
|
2014-05-04 18:22:27 +00:00
|
|
|
} clear_this( (void*&) m_qmodal_loop );
|
|
|
|
|
|
|
|
// release the mouse if it's currently captured as the window having it
|
|
|
|
// will be disabled when this dialog is shown -- but will still keep the
|
|
|
|
// capture making it impossible to do anything in the modal dialog itself
|
|
|
|
wxWindow* win = wxWindow::GetCapture();
|
|
|
|
if( win )
|
|
|
|
win->ReleaseMouse();
|
|
|
|
|
2014-05-05 17:28:40 +00:00
|
|
|
// Get the optimal parent
|
2014-05-04 19:57:44 +00:00
|
|
|
wxWindow* parent = GetParentForModalDialog( GetParent(), GetWindowStyle() );
|
2014-05-04 18:22:27 +00:00
|
|
|
|
2014-08-17 23:00:49 +00:00
|
|
|
wxASSERT_MSG( !m_qmodal_parent_disabler,
|
|
|
|
wxT( "Caller using ShowQuasiModal() twice on same window?" ) );
|
|
|
|
|
|
|
|
// quasi-modal: disable only my "optimal" parent
|
|
|
|
m_qmodal_parent_disabler = new WDO_ENABLE_DISABLE( parent );
|
2014-05-04 18:22:27 +00:00
|
|
|
|
2018-01-09 20:00:28 +00:00
|
|
|
// Apple in its infinite wisdom will raise a disabled window before even passing
|
|
|
|
// us the event, so we have no way to stop it. Instead, we must set an order on
|
|
|
|
// the windows so that the quasi-modal will be pushed in front of the disabled
|
|
|
|
// window when it is raised.
|
2020-06-03 14:58:54 +00:00
|
|
|
KIPLATFORM::UI::ReparentQuasiModal( this );
|
|
|
|
|
2014-05-04 18:22:27 +00:00
|
|
|
Show( true );
|
|
|
|
|
|
|
|
m_qmodal_showing = true;
|
|
|
|
|
2018-03-06 06:30:46 +00:00
|
|
|
WX_EVENT_LOOP event_loop;
|
2014-05-04 18:22:27 +00:00
|
|
|
|
|
|
|
m_qmodal_loop = &event_loop;
|
|
|
|
|
|
|
|
event_loop.Run();
|
|
|
|
|
2018-06-08 23:50:06 +00:00
|
|
|
m_qmodal_showing = false;
|
|
|
|
|
2014-05-04 18:22:27 +00:00
|
|
|
return GetReturnCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SHIM::EndQuasiModal( int retCode )
|
|
|
|
{
|
2016-04-02 12:25:44 +00:00
|
|
|
// Hook up validator and transfer data from controls handling so quasi-modal dialogs
|
|
|
|
// handle validation in the same way as other dialogs.
|
|
|
|
if( ( retCode == wxID_OK ) && ( !Validate() || !TransferDataFromWindow() ) )
|
|
|
|
return;
|
|
|
|
|
2014-05-04 18:22:27 +00:00
|
|
|
SetReturnCode( retCode );
|
|
|
|
|
|
|
|
if( !IsQuasiModal() )
|
|
|
|
{
|
2022-02-05 00:24:26 +00:00
|
|
|
wxFAIL_MSG( wxT( "either DIALOG_SHIM::EndQuasiModal called twice or ShowQuasiModal" )
|
|
|
|
wxT( "wasn't called" ) );
|
2014-05-04 18:22:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_qmodal_loop )
|
|
|
|
{
|
2014-08-17 23:00:49 +00:00
|
|
|
if( m_qmodal_loop->IsRunning() )
|
|
|
|
m_qmodal_loop->Exit( 0 );
|
2013-01-18 06:04:25 +00:00
|
|
|
else
|
2014-08-17 23:00:49 +00:00
|
|
|
m_qmodal_loop->ScheduleExit( 0 );
|
2015-11-09 12:14:28 +00:00
|
|
|
|
2021-04-22 21:20:34 +00:00
|
|
|
m_qmodal_loop = nullptr;
|
2013-01-18 06:04:25 +00:00
|
|
|
}
|
|
|
|
|
2014-08-17 23:00:49 +00:00
|
|
|
delete m_qmodal_parent_disabler;
|
2021-04-22 21:20:34 +00:00
|
|
|
m_qmodal_parent_disabler = nullptr;
|
2012-03-22 07:02:49 +00:00
|
|
|
|
2014-08-17 23:00:49 +00:00
|
|
|
Show( false );
|
2012-03-22 07:02:49 +00:00
|
|
|
}
|
2016-04-11 23:39:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SHIM::OnCloseWindow( wxCloseEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( IsQuasiModal() )
|
|
|
|
{
|
|
|
|
EndQuasiModal( wxID_CANCEL );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is mandatory to allow wxDialogBase::OnCloseWindow() to be called.
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SHIM::OnButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
2019-02-28 07:55:24 +00:00
|
|
|
const int id = aEvent.GetId();
|
|
|
|
|
|
|
|
// If we are pressing a button to exit, we need to enable the escapeID
|
|
|
|
// otherwise the dialog does not process cancel
|
|
|
|
if( id == wxID_CANCEL )
|
|
|
|
SetEscapeId( wxID_ANY );
|
|
|
|
|
2016-04-11 23:39:43 +00:00
|
|
|
if( IsQuasiModal() )
|
|
|
|
{
|
|
|
|
if( id == GetAffirmativeId() )
|
|
|
|
{
|
|
|
|
EndQuasiModal( id );
|
|
|
|
}
|
|
|
|
else if( id == wxID_APPLY )
|
|
|
|
{
|
2016-05-12 03:27:57 +00:00
|
|
|
// Dialogs that provide Apply buttons should make sure data is valid before
|
|
|
|
// allowing a transfer, as there is no other way to indicate failure
|
|
|
|
// (i.e. the dialog can't refuse to close as it might with OK, because it
|
|
|
|
// isn't closing anyway)
|
2016-04-11 23:39:43 +00:00
|
|
|
if( Validate() )
|
2016-07-14 17:30:25 +00:00
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( TransferDataFromWindow() );
|
2016-07-14 17:30:25 +00:00
|
|
|
}
|
2016-04-11 23:39:43 +00:00
|
|
|
}
|
|
|
|
else if( id == GetEscapeId() ||
|
|
|
|
(id == wxID_CANCEL && GetEscapeId() == wxID_ANY) )
|
|
|
|
{
|
|
|
|
EndQuasiModal( wxID_CANCEL );
|
|
|
|
}
|
|
|
|
else // not a standard button
|
|
|
|
{
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is mandatory to allow wxDialogBase::OnButton() to be called.
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
2019-01-17 12:19:43 +00:00
|
|
|
|
|
|
|
|
2019-08-13 15:52:34 +00:00
|
|
|
void DIALOG_SHIM::OnCharHook( wxKeyEvent& aEvt )
|
|
|
|
{
|
2020-06-23 10:21:16 +00:00
|
|
|
if( aEvt.GetKeyCode() == 'U' && aEvt.GetModifiers() == wxMOD_CONTROL )
|
|
|
|
{
|
|
|
|
if( m_parentFrame )
|
|
|
|
{
|
|
|
|
m_parentFrame->ToggleUserUnits();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-08-13 15:52:34 +00:00
|
|
|
// shift-return (Mac default) or Ctrl-Return (GTK) for OK
|
2020-06-23 10:21:16 +00:00
|
|
|
else if( aEvt.GetKeyCode() == WXK_RETURN && ( aEvt.ShiftDown() || aEvt.ControlDown() ) )
|
2019-08-22 20:16:40 +00:00
|
|
|
{
|
2019-08-13 15:52:34 +00:00
|
|
|
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
|
2019-08-22 20:16:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( aEvt.GetKeyCode() == WXK_TAB && !aEvt.ControlDown() )
|
|
|
|
{
|
|
|
|
wxWindow* currentWindow = wxWindow::FindFocus();
|
|
|
|
int currentIdx = -1;
|
|
|
|
int delta = aEvt.ShiftDown() ? -1 : 1;
|
|
|
|
|
2019-08-23 21:14:12 +00:00
|
|
|
auto advance = [&]( int& idx )
|
|
|
|
{
|
2019-09-04 18:05:33 +00:00
|
|
|
// Wrap-around modulus
|
|
|
|
int size = m_tabOrder.size();
|
|
|
|
idx = ( ( idx + delta ) % size + size ) % size;
|
2019-08-23 21:14:12 +00:00
|
|
|
};
|
|
|
|
|
2019-08-22 20:16:40 +00:00
|
|
|
for( size_t i = 0; i < m_tabOrder.size(); ++i )
|
|
|
|
{
|
|
|
|
if( m_tabOrder[i] == currentWindow )
|
|
|
|
{
|
2019-08-23 21:14:12 +00:00
|
|
|
currentIdx = (int) i;
|
2019-08-22 20:16:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( currentIdx >= 0 )
|
|
|
|
{
|
2019-08-23 21:14:12 +00:00
|
|
|
advance( currentIdx );
|
|
|
|
|
2019-09-04 18:05:33 +00:00
|
|
|
//todo: We don't currently have non-textentry dialog boxes but this will break if
|
|
|
|
// we add them.
|
2019-08-23 21:14:12 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
while( dynamic_cast<wxTextEntry*>( m_tabOrder[ currentIdx ] ) == nullptr )
|
|
|
|
advance( currentIdx );
|
|
|
|
#endif
|
|
|
|
|
2019-08-22 20:16:40 +00:00
|
|
|
m_tabOrder[ currentIdx ]->SetFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aEvt.Skip();
|
2019-08-13 15:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-17 12:19:43 +00:00
|
|
|
void DIALOG_SHIM::OnGridEditorShown( wxGridEvent& event )
|
|
|
|
{
|
|
|
|
SetEscapeId( wxID_NONE );
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SHIM::OnGridEditorHidden( wxGridEvent& event )
|
|
|
|
{
|
|
|
|
SetEscapeId( wxID_ANY );
|
|
|
|
event.Skip();
|
|
|
|
}
|