Add new kiplatform library for platform-specific code
* Implement ReparentQuasiModal for OSX natively * Implement ForceFocus of OSX natively This change means we no longer rely on the kicad-specific functions in our osx wx fork.
This commit is contained in:
parent
77a59fb5d3
commit
a843c74529
|
@ -418,6 +418,7 @@ add_dependencies( common version_header )
|
|||
|
||||
target_link_libraries( common
|
||||
kimath
|
||||
kiplatform
|
||||
bitmaps
|
||||
gal
|
||||
${Boost_LIBRARIES}
|
||||
|
@ -515,6 +516,7 @@ target_include_directories( pcbcommon PUBLIC
|
|||
target_link_libraries( pcbcommon PUBLIC
|
||||
common
|
||||
kimath
|
||||
kiplatform
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -23,12 +23,15 @@
|
|||
*/
|
||||
|
||||
#include <dialog_shim.h>
|
||||
#include <eda_rect.h>
|
||||
#include <kiway_player.h>
|
||||
#include <wx/evtloop.h>
|
||||
#include <pgm_base.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <eda_rect.h>
|
||||
|
||||
#include <kiplatform/ui.h>
|
||||
|
||||
#include <wx/display.h>
|
||||
#include <wx/evtloop.h>
|
||||
#include <wx/grid.h>
|
||||
|
||||
/// Toggle a window's "enable" status to disabled, then enabled on destruction.
|
||||
|
@ -395,13 +398,13 @@ int DIALOG_SHIM::ShowQuasiModal()
|
|||
// quasi-modal: disable only my "optimal" parent
|
||||
m_qmodal_parent_disabler = new WDO_ENABLE_DISABLE( parent );
|
||||
|
||||
#ifdef __WXMAC__
|
||||
|
||||
// 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.
|
||||
ReparentQuasiModal();
|
||||
#endif
|
||||
KIPLATFORM::UI::ReparentQuasiModal( this );
|
||||
|
||||
Show( true );
|
||||
|
||||
m_qmodal_showing = true;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <kiplatform/ui.h>
|
||||
|
||||
#include <widgets/net_selector.h>
|
||||
|
||||
|
@ -501,11 +502,7 @@ protected:
|
|||
|
||||
void doSetFocus( wxWindow* aWindow )
|
||||
{
|
||||
#ifdef __WXOSX_MAC__
|
||||
aWindow->OSXForceFocus();
|
||||
#else
|
||||
aWindow->SetFocus();
|
||||
#endif
|
||||
KIPLATFORM::UI::ForceFocus( aWindow );
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
@ -23,4 +23,5 @@
|
|||
|
||||
# Build file for generic re-useable libraries
|
||||
add_subdirectory( kimath )
|
||||
add_subdirectory( kiplatform )
|
||||
add_subdirectory( sexpr )
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
# Add the appropriate source files
|
||||
if( APPLE )
|
||||
set( PLATFORM_SRCS
|
||||
osx/ui.mm
|
||||
)
|
||||
|
||||
set( PLATFORM_LIBS
|
||||
"-framework Cocoa"
|
||||
"-framework AppKit"
|
||||
"-framework CoreData"
|
||||
"-framework Foundation"
|
||||
)
|
||||
elseif( WIN32 )
|
||||
set( PLATFORM_SRCS
|
||||
msw/ui.cpp
|
||||
)
|
||||
elseif( UNIX )
|
||||
set( PLATFORM_SRCS
|
||||
gtk/ui.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
add_library( kiplatform STATIC
|
||||
${PLATFORM_SRCS}
|
||||
)
|
||||
|
||||
target_include_directories( kiplatform PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_link_libraries( kiplatform
|
||||
${wxWidgets_LIBRARIES}
|
||||
${PLATFORM_LIBS}
|
||||
)
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2020 Ian McInerney <Ian.S.McInerney at ieee.org>
|
||||
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <kiplatform/ui.h>
|
||||
|
||||
#include <wx/nonownedwnd.h>
|
||||
#include <wx/window.h>
|
||||
|
||||
void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow )
|
||||
{
|
||||
aWindow->SetFocus();
|
||||
}
|
||||
|
||||
|
||||
void KIPLATFORM::UI::ReparentQuasiModal( wxNonOwnedWindow* aWindow )
|
||||
{
|
||||
// Not needed on this platform
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2020 Ian McInerney <Ian.S.McInerney at ieee.org>
|
||||
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KIPLATFORM_UI_H_
|
||||
#define KIPLATFORM_UI_H_
|
||||
|
||||
class wxNonOwnedWindow;
|
||||
class wxWindow;
|
||||
|
||||
namespace KIPLATFORM
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
/**
|
||||
* Pass the current focus to the window. On OSX this will forcefully give the focus to
|
||||
* the desired window, while on MSW and GTK it will simply call the wxWidgets SetFocus()
|
||||
* function.
|
||||
*
|
||||
* @param aWindow is the window to pass focus to
|
||||
*/
|
||||
void ForceFocus( wxWindow* aWindow );
|
||||
|
||||
/**
|
||||
* Move a window's parent to be the top-level window and force the window to be on top.
|
||||
*
|
||||
* This only has an affect for OSX, it is a NOP for GTK and MSW.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @param aWindow is the window to reparent
|
||||
*/
|
||||
void ReparentQuasiModal( wxNonOwnedWindow* aWindow );
|
||||
}
|
||||
}
|
||||
|
||||
#endif // KIPLATFORM_UI_H_
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2020 Ian McInerney <Ian.S.McInerney at ieee.org>
|
||||
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <kiplatform/ui.h>
|
||||
|
||||
#include <wx/nonownedwnd.h>
|
||||
#include <wx/window.h>
|
||||
|
||||
void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow )
|
||||
{
|
||||
aWindow->SetFocus();
|
||||
}
|
||||
|
||||
|
||||
void KIPLATFORM::UI::ReparentQuasiModal( wxNonOwnedWindow* aWindow )
|
||||
{
|
||||
// Not needed on this platform
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2020 Ian McInerney <Ian.S.McInerney at ieee.org>
|
||||
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <kiplatform/ui.h>
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include <wx/nonownedwnd.h>
|
||||
#include <wx/toplevel.h>
|
||||
#include <wx/window.h>
|
||||
|
||||
void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow )
|
||||
{
|
||||
// On OSX we need to forcefully give the focus to the window
|
||||
[[aWindow->GetHandle() window] makeFirstResponder: aWindow->GetHandle()];
|
||||
}
|
||||
|
||||
|
||||
void KIPLATFORM::UI::ReparentQuasiModal( wxNonOwnedWindow* aWindow )
|
||||
{
|
||||
wxTopLevelWindow* parent =
|
||||
static_cast<wxTopLevelWindow*>( wxGetTopLevelParent( aWindow->GetParent() ) );
|
||||
|
||||
wxASSERT_MSG(parent, "QuasiModal windows require a parent.");
|
||||
|
||||
NSWindow* parentWindow = parent->GetWXWindow();
|
||||
NSWindow* theWindow = aWindow->GetWXWindow();
|
||||
|
||||
[parentWindow addChildWindow:theWindow ordered:NSWindowAbove];
|
||||
}
|
|
@ -665,6 +665,7 @@ set( PCBNEW_KIFACE_LIBRARIES
|
|||
pnsrouter
|
||||
pcad2kicadpcb
|
||||
altium2kicadpcb
|
||||
kiplatform
|
||||
common
|
||||
gal
|
||||
dxflib_qcad
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
#include <3d_viewer/eda_3d_viewer.h>
|
||||
#include <kiplatform/ui.h>
|
||||
#include <pcb_base_frame.h>
|
||||
#include <pcbnew_settings.h>
|
||||
#include <preview_items/ruler_item.h>
|
||||
|
@ -63,19 +64,14 @@ int PCB_VIEWER_TOOLS::Show3DViewer( const TOOL_EVENT& aEvent )
|
|||
{
|
||||
EDA_3D_VIEWER* draw3DFrame = frame()->CreateAndShow3D_Frame();
|
||||
|
||||
// Suppress warnings on non-Mac systems
|
||||
[&draw3DFrame] {}();
|
||||
|
||||
if( frame()->IsType( FRAME_FOOTPRINT_VIEWER )
|
||||
|| frame()->IsType( FRAME_FOOTPRINT_VIEWER_MODAL )
|
||||
|| frame()->IsType( FRAME_FOOTPRINT_WIZARD ) )
|
||||
{
|
||||
frame()->Update3DView( true );
|
||||
|
||||
#ifdef __WXMAC__
|
||||
// A stronger version of Raise() which promotes the window to its parent's level.
|
||||
draw3DFrame->ReparentQuasiModal();
|
||||
#endif
|
||||
KIPLATFORM::UI::ReparentQuasiModal( draw3DFrame );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue