2020-06-03 14:58:54 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2022-02-09 14:01:30 +00:00
|
|
|
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-06-03 14:58:54 +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 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>
|
2020-06-04 21:26:15 +00:00
|
|
|
#include <wx/button.h>
|
2021-09-13 22:30:22 +00:00
|
|
|
#include <wx/settings.h>
|
2020-06-03 14:58:54 +00:00
|
|
|
|
2020-09-19 23:32:23 +00:00
|
|
|
|
|
|
|
bool KIPLATFORM::UI::IsDarkTheme()
|
|
|
|
{
|
2021-09-13 22:30:22 +00:00
|
|
|
// Disabled for now because it appears that the wxWidgets event goes out before the
|
|
|
|
// NSAppearance name has been updated
|
|
|
|
#ifdef NOTYET
|
|
|
|
// It appears the wxWidgets event goes out before the NSAppearance name has been updated
|
2021-02-23 21:34:24 +00:00
|
|
|
NSString *appearanceName = [[NSAppearance currentAppearance] name];
|
|
|
|
return !![appearanceName containsString:@"Dark"];
|
2021-09-13 22:30:22 +00:00
|
|
|
#else
|
|
|
|
wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
|
|
|
|
|
|
|
|
// Weighted W3C formula
|
|
|
|
double brightness = ( bg.Red() / 255.0 ) * 0.299 +
|
|
|
|
( bg.Green() / 255.0 ) * 0.587 +
|
|
|
|
( bg.Blue() / 255.0 ) * 0.117;
|
|
|
|
|
|
|
|
return brightness < 0.5;
|
|
|
|
#endif
|
2020-09-19 23:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 11:19:43 +00:00
|
|
|
wxColour KIPLATFORM::UI::GetDialogBGColour()
|
|
|
|
{
|
|
|
|
wxColor bg = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
|
|
|
|
|
|
|
|
if( KIPLATFORM::UI::IsDarkTheme() )
|
|
|
|
bg = bg.ChangeLightness( 80 );
|
|
|
|
else
|
|
|
|
bg = bg.ChangeLightness( 160 );
|
|
|
|
|
|
|
|
return bg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-03 14:58:54 +00:00
|
|
|
void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow )
|
|
|
|
{
|
|
|
|
// On OSX we need to forcefully give the focus to the window
|
|
|
|
[[aWindow->GetHandle() window] makeFirstResponder: aWindow->GetHandle()];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-02 23:04:33 +00:00
|
|
|
bool KIPLATFORM::UI::IsWindowActive( wxWindow* aWindow )
|
|
|
|
{
|
|
|
|
// Just always return true
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-03 14:58:54 +00:00
|
|
|
void KIPLATFORM::UI::ReparentQuasiModal( wxNonOwnedWindow* aWindow )
|
|
|
|
{
|
|
|
|
wxTopLevelWindow* parent =
|
|
|
|
static_cast<wxTopLevelWindow*>( wxGetTopLevelParent( aWindow->GetParent() ) );
|
|
|
|
|
2022-02-09 14:01:30 +00:00
|
|
|
wxASSERT_MSG(parent, wxT( "QuasiModal windows require a parent.") );
|
2020-06-03 14:58:54 +00:00
|
|
|
|
|
|
|
NSWindow* parentWindow = parent->GetWXWindow();
|
|
|
|
NSWindow* theWindow = aWindow->GetWXWindow();
|
|
|
|
|
|
|
|
[parentWindow addChildWindow:theWindow ordered:NSWindowAbove];
|
|
|
|
}
|
2020-06-04 21:26:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
void KIPLATFORM::UI::FixupCancelButtonCmdKeyCollision( wxWindow *aWindow )
|
|
|
|
{
|
|
|
|
wxButton* button = dynamic_cast<wxButton*>( wxWindow::FindWindowById( wxID_CANCEL, aWindow ) );
|
|
|
|
|
|
|
|
if( button )
|
|
|
|
{
|
|
|
|
static const wxString placeholder = wxT( "{amp}" );
|
|
|
|
|
|
|
|
wxString buttonLabel = button->GetLabel();
|
|
|
|
buttonLabel.Replace( wxT( "&&" ), placeholder );
|
|
|
|
buttonLabel.Replace( wxT( "&" ), wxEmptyString );
|
|
|
|
buttonLabel.Replace( placeholder, wxT( "&" ) );
|
|
|
|
button->SetLabel( buttonLabel );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
|
|
|
|
bool KIPLATFORM::UI::IsStockCursorOk( wxStockCursor aCursor )
|
|
|
|
{
|
|
|
|
switch( aCursor )
|
|
|
|
{
|
|
|
|
case wxCURSOR_SIZING:
|
|
|
|
case wxCURSOR_BULLSEYE:
|
|
|
|
case wxCURSOR_HAND:
|
|
|
|
case wxCURSOR_ARROW:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-17 21:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-12 14:22:04 +00:00
|
|
|
void KIPLATFORM::UI::LargeChoiceBoxHack( wxChoice* aChoice )
|
|
|
|
{
|
|
|
|
// Not implemented
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 21:55:38 +00:00
|
|
|
void KIPLATFORM::UI::EllipsizeChoiceBox( wxChoice* aChoice )
|
|
|
|
{
|
|
|
|
// Not implemented
|
|
|
|
}
|
2021-02-23 01:38:27 +00:00
|
|
|
|
|
|
|
|
2023-02-22 05:15:14 +00:00
|
|
|
double KIPLATFORM::UI::GetPixelScaleFactor( const wxWindow* aWindow )
|
2021-02-23 01:38:27 +00:00
|
|
|
{
|
|
|
|
return aWindow->GetContentScaleFactor();
|
|
|
|
}
|
2021-12-16 04:56:21 +00:00
|
|
|
|
|
|
|
|
2023-02-22 05:15:14 +00:00
|
|
|
double KIPLATFORM::UI::GetContentScaleFactor( const wxWindow* aWindow )
|
|
|
|
{
|
|
|
|
// TODO: Check if this should be different on macOS
|
|
|
|
return GetPixelScaleFactor( aWindow );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-16 04:56:21 +00:00
|
|
|
wxSize KIPLATFORM::UI::GetUnobscuredSize( const wxWindow* aWindow )
|
|
|
|
{
|
|
|
|
return wxSize( aWindow->GetSize().GetX() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ),
|
|
|
|
aWindow->GetSize().GetY() - wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y ) );
|
|
|
|
}
|
2022-01-31 15:45:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
void KIPLATFORM::UI::SetOverlayScrolling( const wxWindow* aWindow, bool overlay )
|
|
|
|
{
|
|
|
|
// Not implemented
|
|
|
|
}
|
2022-02-07 18:26:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool KIPLATFORM::UI::AllowIconsInMenus()
|
|
|
|
{
|
2022-04-24 13:39:00 +00:00
|
|
|
return true;
|
2022-06-24 16:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-18 03:13:09 +00:00
|
|
|
wxPoint KIPLATFORM::UI::GetMousePosition()
|
|
|
|
{
|
|
|
|
return wxGetMousePosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-22 02:10:42 +00:00
|
|
|
bool KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY )
|
2022-06-24 16:54:28 +00:00
|
|
|
{
|
|
|
|
aWindow->WarpPointer( aX, aY );
|
2023-09-22 02:10:42 +00:00
|
|
|
return true;
|
2022-06-24 16:54:28 +00:00
|
|
|
}
|
2023-05-10 00:30:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
void KIPLATFORM::UI::ImmControl( wxWindow* aWindow, bool aEnable )
|
|
|
|
{
|
2023-09-17 17:41:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KIPLATFORM::UI::InfiniteDragPrepareWindow( wxWindow* aWindow )
|
|
|
|
{
|
|
|
|
// Not needed on this platform
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KIPLATFORM::UI::InfiniteDragReleaseWindow()
|
|
|
|
{
|
|
|
|
// Not needed on this platform
|
|
|
|
}
|