KiCad PCB EDA Suite
KIUI Namespace Reference

Functions

void ValidatorTransferToWindowWithoutEvents (wxValidator &aValidator)
 Call a text validator's TransferDataToWindow method without firing a text change event. More...
 
void SetControlsTabOrder (const std::vector< wxWindow * > &aControlsInTabOrder)
 Set a list of controls to have a defined sequential tab order. More...
 
int GetStdMargin ()
 Get the standard margin around a widget in the KiCad UI. More...
 
wxSize GetTextSize (const wxString &aSingleLine, wxWindow *aWindow)
 Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currently set in that window. More...
 
wxFont GetMonospacedUIFont ()
 
wxFont GetControlFont (wxWindow *aWindow)
 
wxFont GetInfoFont (wxWindow *aWindow)
 
wxFont GetDockedPaneFont (wxWindow *aWindow)
 
wxFont GetStatusFont (wxWindow *aWindow)
 
bool EnsureTextCtrlWidth (wxTextCtrl *aCtrl, const wxString *aString=nullptr)
 Set the minimum pixel width on a text control in order to make a text string be fully visible within it. More...
 
void SelectReferenceNumber (wxTextEntry *aTextEntry)
 Select the number (or "?") in a reference for ease of editing. More...
 
wxString EllipsizeStatusText (wxWindow *aWindow, const wxString &aString)
 Ellipsize text (at the end) to be no more than 1/3 of the window width. More...
 
wxString EllipsizeMenuText (const wxString &aString)
 Ellipsize text (at the end) to be no more than 36 characters. More...
 
bool IsInputControlFocused (wxWindow *aFocus=nullptr)
 Check if a input control has focus. More...
 
bool IsInputControlEditable (wxWindow *aControl)
 Check if a input control has focus. More...
 
bool IsModalDialogFocused ()
 
void Disable (wxWindow *aWindow)
 Makes a window read-only. More...
 

Function Documentation

◆ Disable()

void KIUI::Disable ( wxWindow *  aWindow)

Makes a window read-only.

Does some extra work over wxWindow::Disable() to make sure you can still scroll around in sub-windows.

Definition at line 321 of file ui_common.cpp.

322{
323 wxScrollBar* scrollBar = dynamic_cast<wxScrollBar*>( aWindow );
324 wxGrid* grid = dynamic_cast<wxGrid*>( aWindow );
325 wxStyledTextCtrl* scintilla = dynamic_cast<wxStyledTextCtrl*>( aWindow );
326 wxControl* control = dynamic_cast<wxControl*>( aWindow );
327
328 if( scrollBar )
329 {
330 // Leave a scroll bar active
331 }
332 else if( grid )
333 {
334 for( int row = 0; row < grid->GetNumberRows(); ++row )
335 {
336 for( int col = 0; col < grid->GetNumberCols(); ++col )
337 grid->SetReadOnly( row, col );
338 }
339 }
340 else if( scintilla )
341 {
342 scintilla->SetReadOnly( true );
343 }
344 else if( control )
345 {
346 control->Disable();
347 }
348 else
349 {
350 for( wxWindow* child : aWindow->GetChildren() )
351 Disable( child );
352 }
353}
void Disable(wxWindow *aWindow)
Makes a window read-only.
Definition: ui_common.cpp:321
must_if< error >::control< Rule > control

References Disable(), and grid.

Referenced by Disable(), DIALOG_SCHEMATIC_SETUP::onPageChanged(), DIALOG_BOARD_SETUP::onPageChanged(), and PANEL_DATA_COLLECTION::TransferDataToWindow().

◆ EllipsizeMenuText()

wxString KIUI::EllipsizeMenuText ( const wxString &  aString)

Ellipsize text (at the end) to be no more than 36 characters.

Returns
shortened text ending with an ellipsis.

Definition at line 215 of file ui_common.cpp.

216{
217 wxString msg = UnescapeString( aString );
218
219 msg.Replace( wxT( "\n" ), wxT( " " ) );
220 msg.Replace( wxT( "\r" ), wxT( " " ) );
221 msg.Replace( wxT( "\t" ), wxT( " " ) );
222
223 if( msg.Length() > 36 )
224 msg = msg.Left( 34 ) + wxT( "..." );
225
226 return msg;
227}
wxString UnescapeString(const wxString &aSource)

References UnescapeString().

Referenced by LIB_FIELD::GetItemDescription(), LIB_TEXT::GetItemDescription(), SCH_FIELD::GetItemDescription(), SCH_LABEL::GetItemDescription(), SCH_GLOBALLABEL::GetItemDescription(), SCH_HIERLABEL::GetItemDescription(), SCH_SHEET_PIN::GetItemDescription(), SCH_TEXT::GetItemDescription(), FP_TEXT::GetItemDescription(), and PCB_TEXT::GetItemDescription().

◆ EllipsizeStatusText()

wxString KIUI::EllipsizeStatusText ( wxWindow *  aWindow,
const wxString &  aString 
)

Ellipsize text (at the end) to be no more than 1/3 of the window width.

Returns
shortened text ending with an ellipsis.

Definition at line 197 of file ui_common.cpp.

198{
199 wxString msg = UnescapeString( aString );
200
201 msg.Replace( wxT( "\n" ), wxT( " " ) );
202 msg.Replace( wxT( "\r" ), wxT( " " ) );
203 msg.Replace( wxT( "\t" ), wxT( " " ) );
204
205 wxClientDC dc( aWindow );
206 int statusWidth = aWindow->GetSize().GetWidth();
207
208 // 30% of the first 800 pixels plus 60% of the remaining width
209 int textWidth = std::min( statusWidth, 800 ) * 0.3 + std::max( statusWidth - 800, 0 ) * 0.6;
210
211 return wxControl::Ellipsize( msg, dc, wxELLIPSIZE_END, textWidth );
212}

References UnescapeString().

Referenced by LIB_TEXTBOX::GetMsgPanelInfo(), SCH_TEXT::GetMsgPanelInfo(), SCH_TEXTBOX::GetMsgPanelInfo(), PCB_TEXT::GetMsgPanelInfo(), and PCB_TEXTBOX::GetMsgPanelInfo().

◆ EnsureTextCtrlWidth()

bool KIUI::EnsureTextCtrlWidth ( wxTextCtrl *  aCtrl,
const wxString *  aString = nullptr 
)

Set the minimum pixel width on a text control in order to make a text string be fully visible within it.

The current font within the text control is considered. The text can come either from the control or be given as an argument. If the text control is larger than needed, then nothing is done.

Parameters
aCtrlthe text control to potentially make wider.
aStringthe text that is used in sizing the control's pixel width. If NULL, then the text already within the control is used.
Returns
true if the aCtrl had its size changed, else false.

Definition at line 168 of file ui_common.cpp.

169{
170 wxWindow* window = aCtrl->GetParent();
171
172 if( !window )
173 window = aCtrl;
174
175 wxString ctrlText;
176
177 if( !aString )
178 {
179 ctrlText = aCtrl->GetValue();
180 aString = &ctrlText;
181 }
182
183 wxSize textz = GetTextSize( *aString, window );
184 wxSize ctrlz = aCtrl->GetSize();
185
186 if( ctrlz.GetWidth() < textz.GetWidth() + 10 )
187 {
188 ctrlz.SetWidth( textz.GetWidth() + 10 );
189 aCtrl->SetSizeHints( ctrlz );
190 return true;
191 }
192
193 return false;
194}
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: ui_common.cpp:70

References GetTextSize().

Referenced by GERBVIEW_FRAME::UpdateTitleAndInfo().

◆ GetControlFont()

wxFont KIUI::GetControlFont ( wxWindow *  aWindow)

◆ GetDockedPaneFont()

wxFont KIUI::GetDockedPaneFont ( wxWindow *  aWindow)

Definition at line 144 of file ui_common.cpp.

145{
146#ifdef __WXMAC__
147 int scale = -1;
148#else
149 int scale = 0;
150#endif
151
152 return getGUIFont( aWindow, scale );
153}
const int scale

References getGUIFont(), and scale.

Referenced by PCB_SEARCH_PANE::PCB_SEARCH_PANE(), and PROPERTIES_PANEL::PROPERTIES_PANEL().

◆ GetInfoFont()

wxFont KIUI::GetInfoFont ( wxWindow *  aWindow)

Definition at line 156 of file ui_common.cpp.

157{
158 return getGUIFont( aWindow, -1 );
159}

References getGUIFont().

Referenced by APPEARANCE_CONTROLS::APPEARANCE_CONTROLS(), APPEARANCE_CONTROLS::createControls(), DIALOG_ASSIGN_NETCLASS::DIALOG_ASSIGN_NETCLASS(), DIALOG_CLEANUP_GRAPHICS::DIALOG_CLEANUP_GRAPHICS(), DIALOG_FIELD_PROPERTIES::DIALOG_FIELD_PROPERTIES(), DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(), DIALOG_GET_FOOTPRINT_BY_NAME::DIALOG_GET_FOOTPRINT_BY_NAME(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS(), DIALOG_JUNCTION_PROPS::DIALOG_JUNCTION_PROPS(), DIALOG_LIB_SHAPE_PROPERTIES::DIALOG_LIB_SHAPE_PROPERTIES(), DIALOG_LINE_PROPERTIES::DIALOG_LINE_PROPERTIES(), DIALOG_NON_COPPER_ZONES_EDITOR::DIALOG_NON_COPPER_ZONES_EDITOR(), DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES(), DIALOG_PRINT_PCBNEW::DIALOG_PRINT_PCBNEW(), DIALOG_SHAPE_PROPERTIES::DIALOG_SHAPE_PROPERTIES(), DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES(), DIALOG_SIM_MODEL< T_symbol, T_field >::DIALOG_SIM_MODEL(), DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES(), DIALOG_WIRE_BUS_PROPERTIES::DIALOG_WIRE_BUS_PROPERTIES(), PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS(), PANEL_EESCHEMA_DISPLAY_OPTIONS::PANEL_EESCHEMA_DISPLAY_OPTIONS(), PANEL_EESCHEMA_EDITING_OPTIONS::PANEL_EESCHEMA_EDITING_OPTIONS(), PANEL_FP_EDITOR_DEFAULTS::PANEL_FP_EDITOR_DEFAULTS(), PANEL_GERBVIEW_EXCELLON_SETTINGS::PANEL_GERBVIEW_EXCELLON_SETTINGS(), PANEL_RF_ATTENUATORS::PANEL_RF_ATTENUATORS(), PANEL_SELECTION_FILTER::PANEL_SELECTION_FILTER(), PANEL_SETUP_BUSES::PANEL_SETUP_BUSES(), PANEL_SETUP_CONSTRAINTS::PANEL_SETUP_CONSTRAINTS(), PANEL_SETUP_FORMATTING::PANEL_SETUP_FORMATTING(), PANEL_SETUP_MASK_AND_PASTE::PANEL_SETUP_MASK_AND_PASTE(), PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES(), PANEL_SYM_EDITING_OPTIONS::PANEL_SYM_EDITING_OPTIONS(), PROPERTIES_FRAME::PROPERTIES_FRAME(), TEMPLATE_WIDGET::SetTemplate(), PANEL_RF_ATTENUATORS::ThemeChanged(), and WX_HTML_REPORT_PANEL::WX_HTML_REPORT_PANEL().

◆ GetMonospacedUIFont()

wxFont KIUI::GetMonospacedUIFont ( )

Definition at line 85 of file ui_common.cpp.

86{
87 static int guiFontSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize();
88
89 wxFont font( guiFontSize, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL );
90
91#ifdef __WXMAC__
92 // https://trac.wxwidgets.org/ticket/19210
93 if( font.GetFaceName().IsEmpty() )
94 font.SetFaceName( wxS( "Menlo" ) );
95#endif
96
97 return font;
98}

Referenced by CVPCB_MAINFRAME::BuildFootprintsListBox(), CVPCB_MAINFRAME::BuildSymbolsListBox(), CVPCB_MAINFRAME::CVPCB_MAINFRAME(), NETLIST_VIEW_DIALOG::NETLIST_VIEW_DIALOG(), and SCINTILLA_TRICKS::setupStyles().

◆ GetStatusFont()

wxFont KIUI::GetStatusFont ( wxWindow *  aWindow)

◆ GetStdMargin()

int KIUI::GetStdMargin ( )

Get the standard margin around a widget in the KiCad UI.

Returns
margin in pixels

Definition at line 41 of file ui_common.cpp.

42{
43 // This is the value used in (most) wxFB dialogs
44 return 5;
45}

Referenced by BUTTON_ROW_PANEL::addButtons(), BUTTON_ROW_PANEL::BUTTON_ROW_PANEL(), DIALOG_LIST_HOTKEYS::DIALOG_LIST_HOTKEYS(), and PANEL_HOTKEYS_EDITOR::installButtons().

◆ GetTextSize()

wxSize KIUI::GetTextSize ( const wxString &  aSingleLine,
wxWindow *  aWindow 
)

Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currently set in that window.

Definition at line 70 of file ui_common.cpp.

71{
72 wxCoord width;
73 wxCoord height;
74
75 {
76 wxClientDC dc( aWindow );
77 dc.SetFont( aWindow->GetFont() );
78 dc.GetTextExtent( aSingleLine, &width, &height );
79 }
80
81 return wxSize( width, height );
82}

Referenced by DIALOG_EDIT_SYMBOLS_LIBID::AdjustGridColumns(), DIALOG_PLOT::DIALOG_PLOT(), DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE(), LIB_TREE_MODEL_ADAPTER::doAddColumn(), WX_ELLIPSIZED_STATIC_TEXT::DoGetBestSize(), EDA_DRAW_FRAME::EDA_DRAW_FRAME(), EnsureTextCtrlWidth(), FIELDS_EDITOR_GRID_DATA_MODEL::GetDataWidth(), PANEL_SETUP_CONSTRAINTS::PANEL_SETUP_CONSTRAINTS(), PL_EDITOR_FRAME::PL_EDITOR_FRAME(), PANEL_SETUP_PINMAP::reBuildMatrixPanel(), DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::recalculateColumns(), PL_EDITOR_FRAME::ReCreateHToolbar(), ZONE_SETTINGS::SetupLayersList(), and NET_SELECTOR_COMBOPOPUP::updateSize().

◆ IsInputControlEditable()

bool KIUI::IsInputControlEditable ( wxWindow *  aControl)

Check if a input control has focus.

Parameters
aFocusControl that test if editable
Returns
True if control is input and editable OR control is not a input. False if control is input and not editable.

Definition at line 298 of file ui_common.cpp.

299{
300 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( aFocus );
301 wxStyledTextCtrl* styledText = dynamic_cast<wxStyledTextCtrl*>( aFocus );
302 wxSearchCtrl* searchCtrl = dynamic_cast<wxSearchCtrl*>( aFocus );
303
304 if( textEntry )
305 return textEntry->IsEditable();
306 else if( styledText )
307 return styledText->IsEditable();
308 else if( searchCtrl )
309 return searchCtrl->IsEditable();
310
311 return true; // Must return true if we can't determine the state, intentionally true for non inputs as well
312}

Referenced by TOOL_DISPATCHER::DispatchWxEvent().

◆ IsInputControlFocused()

bool KIUI::IsInputControlFocused ( wxWindow *  aFocus = nullptr)

Check if a input control has focus.

Parameters
aFocusControl that has focus, if null, wxWidgets will be queried

Definition at line 265 of file ui_common.cpp.

266{
267 if( aFocus == nullptr )
268 aFocus = wxWindow::FindFocus();
269
270 if( !aFocus )
271 return false;
272
273 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( aFocus );
274 wxStyledTextCtrl* styledText = dynamic_cast<wxStyledTextCtrl*>( aFocus );
275 wxListBox* listBox = dynamic_cast<wxListBox*>( aFocus );
276 wxSearchCtrl* searchCtrl = dynamic_cast<wxSearchCtrl*>( aFocus );
277 wxCheckBox* checkboxCtrl = dynamic_cast<wxCheckBox*>( aFocus );
278 wxChoice* choiceCtrl = dynamic_cast<wxChoice*>( aFocus );
279 wxRadioButton* radioBtn = dynamic_cast<wxRadioButton*>( aFocus );
280 wxSpinCtrl* spinCtrl = dynamic_cast<wxSpinCtrl*>( aFocus );
281 wxSpinCtrlDouble* spinDblCtrl = dynamic_cast<wxSpinCtrlDouble*>( aFocus );
282 wxSlider* sliderCtl = dynamic_cast<wxSlider*>( aFocus );
283
284 // Data view control is annoying, the focus is on a "wxDataViewCtrlMainWindow" class that
285 // is not formally exported via the header.
286 wxDataViewCtrl* dataViewCtrl = nullptr;
287
288 wxWindow* parent = aFocus->GetParent();
289
290 if( parent )
291 dataViewCtrl = dynamic_cast<wxDataViewCtrl*>( parent );
292
293 return ( textEntry || styledText || listBox || searchCtrl || checkboxCtrl || choiceCtrl
294 || radioBtn || spinCtrl || spinDblCtrl || sliderCtl || dataViewCtrl );
295}

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

◆ IsModalDialogFocused()

bool KIUI::IsModalDialogFocused ( )

Definition at line 315 of file ui_common.cpp.

316{
317 return !Pgm().m_ModalDialogs.empty();
318}
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

References Pgm().

Referenced by EDA_DRAW_PANEL_GAL::onEnter(), and EDA_DRAW_PANEL_GAL::OnEvent().

◆ SelectReferenceNumber()

void KIUI::SelectReferenceNumber ( wxTextEntry *  aTextEntry)

Select the number (or "?") in a reference for ease of editing.

Definition at line 230 of file ui_common.cpp.

231{
232 wxString ref = aTextEntry->GetValue();
233
234 if( ref.find_first_of( '?' ) != ref.npos )
235 {
236 aTextEntry->SetSelection( ref.find_first_of( '?' ), ref.find_last_of( '?' ) + 1 );
237 }
238 else if( ref.find_first_of( '*' ) != ref.npos )
239 {
240 aTextEntry->SetSelection( ref.find_first_of( '*' ), ref.find_last_of( '*' ) + 1 );
241 }
242 else
243 {
244 wxString num = ref;
245
246 while( !num.IsEmpty() && ( !isdigit( num.Last() ) || !isdigit( num.GetChar( 0 ) ) ) )
247 {
248 // Trim non-digit from end
249 if( !isdigit( num.Last() ) )
250 num.RemoveLast();
251
252 // Trim non-digit from the start
253 if( !num.IsEmpty() && !isdigit( num.GetChar( 0 ) ) )
254 num = num.Right( num.Length() - 1 );
255 }
256
257 aTextEntry->SetSelection( ref.Find( num ), ref.Find( num ) + num.Length() );
258
259 if( num.IsEmpty() )
260 aTextEntry->SetSelection( -1, -1 );
261 }
262}

Referenced by DIALOG_SYMBOL_PROPERTIES::HandleDelayedSelection(), DIALOG_FIELD_PROPERTIES::OnSetFocusText(), DIALOG_TEXT_PROPERTIES::OnSetFocusText(), and DIALOG_FOOTPRINT_PROPERTIES::OnUpdateUI().

◆ SetControlsTabOrder()

void KIUI::SetControlsTabOrder ( const std::vector< wxWindow * > &  aControlsInTabOrder)

Set a list of controls to have a defined sequential tab order.

Each control in the list will come after the previous one. The first control will keep its current position. The end result will be that the given control will be sequential when tabbed though.

This can be slightly clearer than manually calling MoveAfterInTabOrder on each control in turn.

Parameters
aControlsInTabOrderlist of controls (wxWindows) in desired tab order

◆ ValidatorTransferToWindowWithoutEvents()

void KIUI::ValidatorTransferToWindowWithoutEvents ( wxValidator &  aValidator)

Call a text validator's TransferDataToWindow method without firing a text change event.

This is useful when you want to keep a validator in sync with other data, but the act of changing it should not trigger other updates. It is the validator equivalent of ChangeValue() compared to SetValue().

This function blocks all events, but the same technique can be used to selectively block events.

Parameters
aValidatorthe validator to update the control of

Definition at line 376 of file validators.cpp.

377{
378 wxWindow* ctrl = aValidator.GetWindow();
379
380 wxCHECK_RET( ctrl != nullptr, wxS( "Transferring validator data without a control" ) );
381
382 wxEventBlocker orient_update_blocker( ctrl, wxEVT_ANY );
383 aValidator.TransferToWindow();
384}