KiCad PCB EDA Suite
gtk/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 (C) 2020-2021 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 along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <kiplatform/ui.h>
22 
23 #include <wx/choice.h>
24 #include <wx/nonownedwnd.h>
25 #include <wx/settings.h>
26 #include <wx/window.h>
27 
28 #include <gtk/gtk.h>
29 
30 
32 {
33  wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
34 
35  // Weighted W3C formula
36  double brightness = ( bg.Red() / 255.0 ) * 0.299 +
37  ( bg.Green() / 255.0 ) * 0.587 +
38  ( bg.Blue() / 255.0 ) * 0.117;
39 
40  return brightness < 0.5;
41 }
42 
43 
44 void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow )
45 {
46  aWindow->SetFocus();
47 }
48 
49 
50 bool KIPLATFORM::UI::IsWindowActive( wxWindow* aWindow )
51 {
52  if( !aWindow )
53  return false;
54 
55  GtkWindow* window = GTK_WINDOW( aWindow->GetHandle() );
56 
57  if( window )
58  return gtk_window_is_active( window );
59 
60  // We shouldn't really ever reach this point
61  return false;
62 }
63 
64 
65 void KIPLATFORM::UI::ReparentQuasiModal( wxNonOwnedWindow* aWindow )
66 {
67  // Not needed on this platform
68 }
69 
70 
72 {
73  // Not needed on this platform
74 }
75 
76 
77 bool KIPLATFORM::UI::IsStockCursorOk( wxStockCursor aCursor )
78 {
79  switch( aCursor )
80  {
81  case wxCURSOR_BULLSEYE:
82  case wxCURSOR_HAND:
83  case wxCURSOR_ARROW:
84  return true;
85  default:
86  return false;
87  }
88 }
89 
90 
91 void KIPLATFORM::UI::EllipsizeChoiceBox( wxChoice* aChoice )
92 {
93  // This function is based on the code inside the function post_process_ui in
94  // gtkfilechooserwidget.c
95  GList* cells = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( aChoice->m_widget ) );
96 
97  if( !cells )
98  return;
99 
100  GtkCellRenderer* cell = (GtkCellRenderer*) cells->data;
101 
102  if( !cell )
103  return;
104 
105  g_object_set( G_OBJECT( cell ), "ellipsize", PANGO_ELLIPSIZE_END, nullptr );
106 
107  // Only the list of cells must be freed, the renderer isn't ours to free
108  g_list_free( cells );
109 }
110 
111 
112 double KIPLATFORM::UI::GetSystemScaleFactor( const wxWindow* aWindow )
113 {
114  double val = 1.0;
115 
116  GtkWidget* widget = static_cast<GtkWidget*>( aWindow->GetHandle() );
117 
118  if( widget && gtk_check_version( 3, 10, 0 ) == nullptr )
119  val = gtk_widget_get_scale_factor( widget );
120 
121  return val;
122 }
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: gtk/ui.cpp:31
double GetSystemScaleFactor(const wxWindow *aWindow)
Tries to determine the system scaling factor currently in use for the window.
Definition: gtk/ui.cpp:112
bool IsWindowActive(wxWindow *aWindow)
Check to see if the given window is the currently active window (e.g.
Definition: gtk/ui.cpp:50
void EllipsizeChoiceBox(wxChoice *aChoice)
Configure a wxChoice control to ellipsize the shown text in the button with the ellipses placed at th...
Definition: gtk/ui.cpp:91
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: gtk/ui.cpp:77
void ForceFocus(wxWindow *aWindow)
Pass the current focus to the window.
Definition: gtk/ui.cpp:44
void FixupCancelButtonCmdKeyCollision(wxWindow *aWindow)
Definition: gtk/ui.cpp:71
void ReparentQuasiModal(wxNonOwnedWindow *aWindow)
Move a window's parent to be the top-level window and force the window to be on top.
Definition: gtk/ui.cpp:65