KiCad PCB EDA Suite
KIPLATFORM::UI Namespace Reference

Functions

bool IsDarkTheme ()
 Determine if the desktop interface is currently using a dark theme or a light theme. More...
 
void ForceFocus (wxWindow *aWindow)
 Pass the current focus to the window. More...
 
bool IsWindowActive (wxWindow *aWindow)
 Check to see if the given window is the currently active window (e.g. More...
 
void ReparentQuasiModal (wxNonOwnedWindow *aWindow)
 Move a window's parent to be the top-level window and force the window to be on top. More...
 
void FixupCancelButtonCmdKeyCollision (wxWindow *aWindow)
 
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. More...
 
void EllipsizeChoiceBox (wxChoice *aChoice)
 Configure a wxChoice control to ellipsize the shown text in the button with the ellipses placed at the end of the string. More...
 
double GetSystemScaleFactor (const wxWindow *aWindow)
 Tries to determine the system scaling factor currently in use for the window. More...
 
wxSize GetUnobscuredSize (const wxWindow *aWindow)
 Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl, wxGrid) that won't be obscured by scrollbars. More...
 
void SetOverlayScrolling (const wxWindow *aWindow, bool overlay)
 Used to set overlay/non-overlay scrolling mode in a window. More...
 
bool AllowIconsInMenus ()
 If the user has disabled icons system-wide, we check that here. More...
 
void WarpPointer (wxWindow *aWindow, int aX, int aY)
 Move the mouse cursor to a specific position relative to the window. More...
 

Function Documentation

◆ AllowIconsInMenus()

bool KIPLATFORM::UI::AllowIconsInMenus ( )

If the user has disabled icons system-wide, we check that here.

Definition at line 140 of file gtk/ui.cpp.

141{
142 gboolean allowed = 1;
143
144 g_object_get( gtk_settings_get_default(), "gtk-menu-images", &allowed, NULL );
145
146 return !!allowed;
147}

Referenced by PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS().

◆ EllipsizeChoiceBox()

void KIPLATFORM::UI::EllipsizeChoiceBox ( wxChoice *  aChoice)

Configure a wxChoice control to ellipsize the shown text in the button with the ellipses placed at the end of the string.

Parameters
aChoiceis the choice box to ellipsize

Definition at line 92 of file gtk/ui.cpp.

93{
94 // This function is based on the code inside the function post_process_ui in
95 // gtkfilechooserwidget.c
96 GList* cells = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( aChoice->m_widget ) );
97
98 if( !cells )
99 return;
100
101 GtkCellRenderer* cell = (GtkCellRenderer*) cells->data;
102
103 if( !cell )
104 return;
105
106 g_object_set( G_OBJECT( cell ), "ellipsize", PANGO_ELLIPSIZE_END, nullptr );
107
108 // Only the list of cells must be freed, the renderer isn't ours to free
109 g_list_free( cells );
110}

Referenced by DIALOG_SELECT_3DMODEL::DIALOG_SELECT_3DMODEL().

◆ FixupCancelButtonCmdKeyCollision()

void KIPLATFORM::UI::FixupCancelButtonCmdKeyCollision ( wxWindow *  aWindow)

Definition at line 71 of file gtk/ui.cpp.

72{
73 // Not needed on this platform
74}

Referenced by CVPCB_MAINFRAME::CVPCB_MAINFRAME(), and DIALOG_SHIM::OnPaint().

◆ ForceFocus()

void KIPLATFORM::UI::ForceFocus ( wxWindow *  aWindow)

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.

Parameters
aWindowis the window to pass focus to

Definition at line 44 of file gtk/ui.cpp.

45{
46 aWindow->SetFocus();
47}

Referenced by NET_SELECTOR_COMBOPOPUP::doSetFocus(), DIALOG_SHIM::OnPaint(), DIALOG_DRC::OnRunDRCClick(), and DIALOG_ERC::OnRunERCClick().

◆ GetSystemScaleFactor()

double KIPLATFORM::UI::GetSystemScaleFactor ( const wxWindow *  aWindow)

Tries to determine the system scaling factor currently in use for the window.

Under wx3.0, GTK fails to properly detect the scale factor.

Parameters
aWindowpointer to the window to check
Returns
System scale factor in use, defaulting to the wxWidgets method

Definition at line 113 of file gtk/ui.cpp.

114{
115 double val = 1.0;
116
117 GtkWidget* widget = static_cast<GtkWidget*>( aWindow->GetHandle() );
118
119 if( widget && gtk_check_version( 3, 10, 0 ) == nullptr )
120 val = gtk_widget_get_scale_factor( widget );
121
122 return val;
123}

Referenced by DPI_SCALING::GetScaleFactor().

◆ GetUnobscuredSize()

wxSize KIPLATFORM::UI::GetUnobscuredSize ( const wxWindow *  aWindow)

Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl, wxGrid) that won't be obscured by scrollbars.

Parameters
aWindowpointer to the scrollable widget to check
Returns
Viewport size that won't be obscured by scrollbars

Definition at line 126 of file gtk/ui.cpp.

127{
128 return wxSize( aWindow->GetSize().GetX() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ),
129 aWindow->GetSize().GetY() - wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y ) );
130}

Referenced by DIALOG_BOARD_STATISTICS::adjustDrillGridColumns(), DIALOG_SYMBOL_PROPERTIES::AdjustFieldsGridColumns(), DIALOG_EDIT_SYMBOLS_LIBID::AdjustGridColumns(), DIALOG_LIB_EDIT_PIN_TABLE::adjustGridColumns(), DIALOG_LIB_SYMBOL_PROPERTIES::adjustGridColumns(), DIALOG_PIN_PROPERTIES::adjustGridColumns(), DIALOG_SHEET_PROPERTIES::AdjustGridColumns(), DIALOG_FOOTPRINT_PROPERTIES::adjustGridColumns(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::adjustGridColumns(), DIALOG_SWAP_LAYERS::adjustGridColumns(), PANEL_FP_PROPERTIES_3D_MODEL::AdjustGridColumnWidths(), DIALOG_SYMBOL_PROPERTIES::AdjustPinsGridColumns(), DIALOG_SIM_MODEL< T >::onPinAssignmentsGridSize(), and DIALOG_SYMBOL_FIELDS_TABLE::OnSizeFieldList().

◆ IsDarkTheme()

bool KIPLATFORM::UI::IsDarkTheme ( )

Determine if the desktop interface is currently using a dark theme or a light theme.

Returns
true if a dark theme is being used.

Definition at line 31 of file gtk/ui.cpp.

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}

Referenced by WX_AUI_TOOLBAR_ART::DrawButton(), WX_HTML_REPORT_PANEL::generateHtml(), MakeDisabledBitmap(), BITMAP_BUTTON::OnPaint(), ACTION_PLUGINS::register_action(), BITMAP_STORE::ThemeChanged(), NUMBER_BADGE::UpdateNumber(), and WX_INFOBAR::WX_INFOBAR().

◆ IsStockCursorOk()

bool KIPLATFORM::UI::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.

Parameters
aCursoris wxStockCursor we want to see if its acceptable

Definition at line 77 of file gtk/ui.cpp.

78{
79 switch( aCursor )
80 {
81 case wxCURSOR_BULLSEYE:
82 case wxCURSOR_HAND:
83 case wxCURSOR_ARROW:
84 case wxCURSOR_BLANK:
85 return true;
86 default:
87 return false;
88 }
89}

Referenced by CURSOR_STORE::GetStockCursor().

◆ IsWindowActive()

bool KIPLATFORM::UI::IsWindowActive ( wxWindow *  aWindow)

Check to see if the given window is the currently active window (e.g.

the window in the foreground the user is interacting with).

Parameters
aWindowis the window to check

Definition at line 50 of file gtk/ui.cpp.

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}

Referenced by TOOL_DISPATCHER::DispatchWxEvent(), EDA_DRAW_PANEL_GAL::onEnter(), KIGFX::WX_VIEW_CONTROLS::onEnter(), EDA_DRAW_PANEL_GAL::OnEvent(), and KIGFX::WX_VIEW_CONTROLS::onMotion().

◆ ReparentQuasiModal()

void KIPLATFORM::UI::ReparentQuasiModal ( wxNonOwnedWindow *  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.

Parameters
aWindowis the window to reparent

Definition at line 65 of file gtk/ui.cpp.

66{
67 // Not needed on this platform
68}

Referenced by PCB_VIEWER_TOOLS::Show3DViewer(), and DIALOG_SHIM::ShowQuasiModal().

◆ SetOverlayScrolling()

void KIPLATFORM::UI::SetOverlayScrolling ( const wxWindow *  aWindow,
bool  overlay 
)

Used to set overlay/non-overlay scrolling mode in a window.

Implemented only on GTK.

Definition at line 133 of file gtk/ui.cpp.

134{
135 gtk_scrolled_window_set_overlay_scrolling( GTK_SCROLLED_WINDOW( aWindow->GetHandle() ),
136 overlay );
137}
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > overlay
Definition: playground.cpp:36

References overlay.

Referenced by EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL().

◆ WarpPointer()

void KIPLATFORM::UI::WarpPointer ( wxWindow *  aWindow,
int  aX,
int  aY 
)

Move the mouse cursor to a specific position relative to the window.

Parameters
aWindowWindow in which to position to mouse cursor
aXdestination x position
aYdestination y position

Definition at line 150 of file gtk/ui.cpp.

151{
152 if( !wxGetEnv( wxT( "WAYLAND_DISPLAY" ), nullptr ) )
153 {
154 aWindow->WarpPointer( aX, aY );
155 }
156 else
157 {
158 GdkDisplay* disp = gtk_widget_get_display( static_cast<GtkWidget*>( aWindow->GetHandle() ) );
159 GdkSeat* seat = gdk_display_get_default_seat( disp );
160 GdkDevice* dev = gdk_seat_get_pointer( seat );
161 GdkWindow* win = gdk_device_get_window_at_position( dev, nullptr, nullptr );
162 GdkCursor* blank_cursor = gdk_cursor_new_for_display( disp, GDK_BLANK_CURSOR );
163 GdkCursor* cur_cursor = gdk_window_get_cursor( win );
164
165 if( cur_cursor )
166 g_object_ref( cur_cursor );
167
168 gdk_window_set_cursor( win, blank_cursor );
169 aWindow->WarpPointer( aX, aY );
170 gdk_window_set_cursor( win, cur_cursor );
171 }
172}

Referenced by KIGFX::WX_VIEW_CONTROLS::CenterOnCursor(), KIGFX::WX_VIEW_CONTROLS::handleCursorCapture(), KIGFX::WX_VIEW_CONTROLS::onMotion(), and KIGFX::WX_VIEW_CONTROLS::WarpMouseCursor().