KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wxmsw/ui.cpp
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) 2020 Ian McInerney <Ian.S.McInerney at ieee.org>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <windows.h>
22
23#include <kiplatform/ui.h>
24
25#include <wx/cursor.h>
26#include <wx/dataview.h>
27#include <wx/dialog.h>
28#include <wx/display.h>
29#include <wx/nonownedwnd.h>
30#include <wx/window.h>
31#include <wx/msw/registry.h>
32
33
35{
36#if wxCHECK_VERSION( 3, 3, 0 )
37 wxSystemAppearance appearance = wxSystemSettings::GetAppearance();
38 return appearance.IsDark();
39#else
40 wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
41
42 // Weighted W3C formula
43 double brightness = ( bg.Red() / 255.0 ) * 0.299 +
44 ( bg.Green() / 255.0 ) * 0.587 +
45 ( bg.Blue() / 255.0 ) * 0.117;
46
47 return brightness < 0.5;
48#endif
49}
50
51
53{
54 return wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
55}
56
57
58void KIPLATFORM::UI::GetInfoBarColours( wxColour& aFGColour, wxColour& aBGColour )
59{
60 aBGColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOBK );
61 aFGColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOTEXT );
62}
63
64
65wxWindow* KIPLATFORM::UI::CreateCanvasOverlay( wxWindow* aCanvas )
66{
67 return nullptr;
68}
69
70
71void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow )
72{
73 aWindow->SetFocus();
74}
75
76
77bool KIPLATFORM::UI::IsWindowActive( wxWindow* aWindow )
78{
79 if(! aWindow )
80 {
81 return false;
82 }
83
84 return ( aWindow->GetHWND() == GetForegroundWindow() );
85}
86
87
88void KIPLATFORM::UI::StabilizeWindowPosition( wxWindow* aWindow )
89{
90 // Not needed on this platform
91}
92
93
94wxPoint KIPLATFORM::UI::GetRestorablePosition( wxWindow* aWindow )
95{
96 return aWindow->GetPosition();
97}
98
99
100void KIPLATFORM::UI::ReparentModal( wxNonOwnedWindow* aWindow )
101{
102 // Not needed on this platform
103}
104
105
106void KIPLATFORM::UI::ReparentWindow( wxNonOwnedWindow* aWindow, wxTopLevelWindow* aParent )
107{
108 // Not needed on this platform (used only on macOS for child window ordering)
109}
110
111
113{
114 // Not needed on this platform
115}
116
117
118bool KIPLATFORM::UI::IsStockCursorOk( wxStockCursor aCursor )
119{
120 switch( aCursor )
121 {
122 case wxCURSOR_BULLSEYE:
123 case wxCURSOR_HAND:
124 case wxCURSOR_ARROW:
125 return true;
126 default:
127 return false;
128 }
129}
130
131
132void KIPLATFORM::UI::LargeChoiceBoxHack( wxChoice* aChoice )
133{
134 // Not implemented
135}
136
137
138void KIPLATFORM::UI::EllipsizeChoiceBox( wxChoice* aChoice )
139{
140 // Not implemented
141}
142
143
144double KIPLATFORM::UI::GetPixelScaleFactor( const wxWindow* aWindow )
145{
146 return aWindow->GetContentScaleFactor();
147}
148
149
150double KIPLATFORM::UI::GetContentScaleFactor( const wxWindow* aWindow )
151{
152 return aWindow->GetDPIScaleFactor();
153}
154
155
156double KIPLATFORM::UI::GetDisplayRefreshRate( const wxWindow* aWindow )
157{
158 // wx reports the hardware's default rate as 0
159 return wxDisplay( aWindow ).GetCurrentMode().refresh;
160}
161
162
163wxSize KIPLATFORM::UI::GetUnobscuredSize( const wxWindow* aWindow )
164{
165 return aWindow->GetClientSize();
166}
167
168
169void KIPLATFORM::UI::SetOverlayScrolling( const wxWindow* aWindow, bool overlay )
170{
171 // Not implemented
172}
173
174
176{
177 return true;
178}
179
180
182{
183 return true;
184}
185
186
188{
189 return wxKeyEvent();
190}
191
192
194{
195 return true;
196}
197
198
200{
201 return wxGetMousePosition();
202}
203
204
205bool KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY )
206{
207 aWindow->WarpPointer( aX, aY );
208 return true;
209}
210
211
212void KIPLATFORM::UI::ImmControl( wxWindow* aWindow, bool aEnable )
213{
214 if ( !aEnable )
215 {
216 ImmAssociateContext( aWindow->GetHWND(), NULL );
217 }
218 else
219 {
220 ImmAssociateContextEx( aWindow->GetHWND(), 0, IACE_DEFAULT );
221 }
222}
223
224
225void KIPLATFORM::UI::ImeNotifyCancelComposition( wxWindow* aWindow )
226{
227 const HIMC himc = ImmGetContext( aWindow->GetHWND() );
228 ImmNotifyIME( himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0 );
229 ImmReleaseContext( aWindow->GetHWND(), himc );
230}
231
232
233bool KIPLATFORM::UI::InfiniteDragPrepareWindow( wxWindow* aWindow )
234{
235 return true;
236}
237
238
240{
241 // Not needed on this platform
242}
243
244
245void KIPLATFORM::UI::SetFloatLevel( wxWindow* aWindow )
246{
247}
248
249void KIPLATFORM::UI::ReleaseChildWindow( wxNonOwnedWindow* aWindow )
250{
251 // Not needed on this platform
252}
253
254
255void KIPLATFORM::UI::AllowNetworkFileSystems( wxDialog* aDialog )
256{
257 // Not needed on Windows - file dialogs show network filesystems by default
258}
259
260
261int KIPLATFORM::UI::GetColumnWidth( const wxDataViewColumn* aColumn )
262{
263 return aColumn->WXGetSpecifiedWidth();
264}
265
266
267void KIPLATFORM::UI::CancelPendingScroll( wxDataViewCtrl* aCtrl )
268{
269 // Not needed on this platform; the native control does not race on model resets.
270}
271
272
273void KIPLATFORM::UI::SetWMClass( wxWindow* aWindow, const wxString& aClass )
274{
275 // WM_CLASS is an X11/Wayland concept; taskbar identity on Windows is driven by the
276 // AppUserModelID (see KIPLATFORM::ENV::SetAppDetailsForWindow).
277}
278
279
280void KIPLATFORM::UI::GetNativeWindowHandles( wxWindow* aWindow, void** aHandle, void** aDisplay,
281 int* aDisplayType )
282{
283 *aHandle = nullptr;
284 *aDisplay = nullptr;
285
286 if( aDisplayType )
287 *aDisplayType = NATIVE_DISPLAY_TYPE::DISPLAY_WIN32;
288
289 if( aWindow )
290 *aHandle = static_cast<void*>( aWindow->GetHWND() );
291}
292
293
294void KIPLATFORM::UI::PrepareForExternalRendering( wxWindow* aWindow )
295{
296 // The GPU API owns Win32 surfaces natively
297}
298
299
300void KIPLATFORM::UI::KeepAboveExternalRendering( wxWindow* aChild )
301{
302 // Child windows are native and clip their parent's surface
303}
wxPoint GetRestorablePosition(wxWindow *aWindow)
Return the point that wxWindow::Move() needs to put a stabilized window back where it is.
Definition wxgtk/ui.cpp:260
double GetDisplayRefreshRate(const wxWindow *aWindow)
Return the refresh rate in Hz of the display showing most of the window, or 0 if unknown.
Definition wxgtk/ui.cpp:477
wxWindow * CreateCanvasOverlay(wxWindow *aCanvas)
Create a window for widgets that are shown over a canvas without taking space from it.
Definition wxgtk/ui.cpp:200
bool AllowIconsInMenus()
If the user has disabled icons system-wide, we check that here.
Definition wxgtk/ui.cpp:510
void GetNativeWindowHandles(wxWindow *aWindow, void **aHandle, void **aDisplay, int *aDisplayType=nullptr)
Get the native handles needed to create a GPU surface for aWindow.
void SetFloatLevel(wxWindow *aWindow)
Intended to set the floating window level in macOS on a window.
Definition wxgtk/ui.cpp:730
void GetInfoBarColours(wxColour &aFGColour, wxColour &aBGColour)
Return the background and foreground colors for info bars in the current scheme.
Definition wxgtk/ui.cpp:76
void ReparentWindow(wxNonOwnedWindow *aWindow, wxTopLevelWindow *aParent)
Definition wxgtk/ui.cpp:370
void ReleaseChildWindow(wxNonOwnedWindow *aWindow)
Release a modal window's parent-child relationship with its parent window.
Definition wxgtk/ui.cpp:735
void EllipsizeChoiceBox(wxChoice *aChoice)
Configure a wxChoice control to ellipsize the shown text in the button with the ellipses placed at th...
Definition wxgtk/ui.cpp:436
void PrepareForExternalRendering(wxWindow *aWindow)
Prepare a realized widget for Vulkan or Metal rendering, before its first present.
void FixupCancelButtonCmdKeyCollision(wxWindow *aWindow)
Definition wxgtk/ui.cpp:376
void SetOverlayScrolling(const wxWindow *aWindow, bool overlay)
Used to set overlay/non-overlay scrolling mode in a window.
Definition wxgtk/ui.cpp:503
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
void ImmControl(wxWindow *aWindow, bool aEnable)
Configures the IME mode of a given control handle.
Definition wxgtk/ui.cpp:711
void StabilizeWindowPosition(wxWindow *aWindow)
Prepare a top-level window for reliable position round-tripping.
Definition wxgtk/ui.cpp:248
double GetPixelScaleFactor(const wxWindow *aWindow)
Tries to determine the pixel scaling factor currently in use for the window.
Definition wxgtk/ui.cpp:457
bool PrepareChoicePopup(wxWindow *aControl)
Definition wxgtk/ui.cpp:558
void InfiniteDragReleaseWindow()
On Wayland, allows the cursor to freely move again after a drag (see InfiniteDragPrepareWindow).
int GetColumnWidth(const wxDataViewColumn *aColumn)
The width last asked of aColumn, by SetWidth or by the user dragging its border.
Definition wxgtk/ui.cpp:750
bool IsStockCursorOk(wxStockCursor aCursor)
Checks if we designated a stock cursor for this OS as "OK" or else we may need to load a custom one.
Definition wxgtk/ui.cpp:382
bool SupportsKeyState()
Return whether wxGetKeyState() can query ordinary keys, beyond modifiers and lock keys.
Definition wxgtk/ui.cpp:520
wxKeyEvent GetNativePopupDismissalEvent()
Definition wxgtk/ui.cpp:573
void KeepAboveExternalRendering(wxWindow *aChild)
Keep a child visible on top of a parent prepared with PrepareForExternalRendering().
double GetContentScaleFactor(const wxWindow *aWindow)
Tries to determine the content scaling factor currently in use for the window.
Definition wxgtk/ui.cpp:470
void ImeNotifyCancelComposition(wxWindow *aWindow)
Asks the IME to cancel.
Definition wxgtk/ui.cpp:716
void LargeChoiceBoxHack(wxChoice *aChoice)
Configure a wxChoice control to support a lot of entries by disabling functionality that makes adding...
Definition wxgtk/ui.cpp:418
bool WarpPointer(wxWindow *aWindow, int aX, int aY)
Move the mouse cursor to a specific position relative to the window.
Definition wxgtk/ui.cpp:638
wxColour GetDialogBGColour()
Definition wxgtk/ui.cpp:70
bool IsWindowActive(wxWindow *aWindow)
Check to see if the given window is the currently active window (e.g.
Definition wxgtk/ui.cpp:233
wxSize GetUnobscuredSize(const wxWindow *aWindow)
Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl,...
Definition wxgtk/ui.cpp:496
void ForceFocus(wxWindow *aWindow)
Pass the current focus to the window.
Definition wxgtk/ui.cpp:211
bool InfiniteDragPrepareWindow(wxWindow *aWindow)
On Wayland, restricts the pointer movement to a rectangle slightly bigger than the given wxWindow.
void SetWMClass(wxWindow *aWindow, const wxString &aClass)
Tag a top-level window with the freedesktop application id of its installed launcher,...
Definition wxgtk/ui.cpp:336
void ReparentModal(wxNonOwnedWindow *aWindow)
Move a window's parent to be the top-level window and force the window to be on top.
Definition wxgtk/ui.cpp:364
void CancelPendingScroll(wxDataViewCtrl *aCtrl)
Cancel any pending scroll-to-item request on aCtrl.
Definition wxgtk/ui.cpp:759
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition wxgtk/ui.cpp:57
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:741
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > overlay