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 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 void KIPLATFORM::UI::ReparentQuasiModal( wxNonOwnedWindow* aWindow )
51 {
52  // Not needed on this platform
53 }
54 
55 
57 {
58  // Not needed on this platform
59 }
60 
61 
62 bool KIPLATFORM::UI::IsStockCursorOk( wxStockCursor aCursor )
63 {
64  switch( aCursor )
65  {
66  case wxCURSOR_BULLSEYE:
67  case wxCURSOR_HAND:
68  case wxCURSOR_ARROW:
69  return true;
70  default:
71  return false;
72  }
73 }
74 
75 
76 void KIPLATFORM::UI::EllipsizeChoiceBox( wxChoice* aChoice )
77 {
78  // This function is based on the code inside the function post_process_ui in gtkfilechooserwidget.c
79  GList* cells = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( aChoice->m_widget ) );
80 
81  if( !cells )
82  return;
83 
84  GtkCellRenderer* cell = (GtkCellRenderer*) cells->data;
85 
86  if( !cell )
87  return;
88 
89  g_object_set( G_OBJECT( cell ), "ellipsize", PANGO_ELLIPSIZE_END, NULL );
90 
91  // Only the list of cells must be freed, the renderer isn't ours to free
92  g_list_free( cells );
93 }
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: gtk/ui.cpp:31
#define NULL
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:76
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:62
void ForceFocus(wxWindow *aWindow)
Pass the current focus to the window.
Definition: gtk/ui.cpp:44
void FixupCancelButtonCmdKeyCollision(wxWindow *aWindow)
Definition: gtk/ui.cpp:56
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:50