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 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...
 
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 ()
 

Function Documentation

◆ 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 153 of file ui_common.cpp.

154 {
155  wxWindow* window = aCtrl->GetParent();
156 
157  if( !window )
158  window = aCtrl;
159 
160  wxString ctrlText;
161 
162  if( !aString )
163  {
164  ctrlText = aCtrl->GetValue();
165  aString = &ctrlText;
166  }
167 
168  wxSize textz = GetTextSize( *aString, window );
169  wxSize ctrlz = aCtrl->GetSize();
170 
171  if( ctrlz.GetWidth() < textz.GetWidth() + 10 )
172  {
173  ctrlz.SetWidth( textz.GetWidth() + 10 );
174  aCtrl->SetSizeHints( ctrlz );
175  return true;
176  }
177 
178  return false;
179 }
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:67

References GetTextSize().

Referenced by GERBVIEW_FRAME::UpdateTitleAndInfo().

◆ GetControlFont()

wxFont KIUI::GetControlFont ( wxWindow *  aWindow)

Definition at line 147 of file ui_common.cpp.

148 {
149  return getGUIFont( aWindow, 0 );
150 }
wxFont getGUIFont(wxWindow *aWindow, int aRelativeSize)
Definition: ui_common.cpp:98

References getGUIFont().

Referenced by EDA_MSG_PANEL::GetRequiredHeight(), EDA_MSG_PANEL::OnPaint(), PAGED_DIALOG::PAGED_DIALOG(), PROJECT_TREE::PROJECT_TREE(), WX_GRID::SetColLabelSize(), and WX_GRID::WX_GRID().

◆ GetInfoFont()

wxFont KIUI::GetInfoFont ( wxWindow *  aWindow)

Definition at line 141 of file ui_common.cpp.

142 {
143  return getGUIFont( aWindow, -1 );
144 }
wxFont getGUIFont(wxWindow *aWindow, int aRelativeSize)
Definition: ui_common.cpp:98

References getGUIFont().

Referenced by APPEARANCE_CONTROLS::APPEARANCE_CONTROLS(), 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_TEXT_PROPERTIES::DIALOG_LIB_TEXT_PROPERTIES(), DIALOG_LINE_WIRE_BUS_PROPERTIES::DIALOG_LINE_WIRE_BUS_PROPERTIES(), DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES(), DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES(), DIALOG_TEXT_AND_LABEL_PROPERTIES::DIALOG_TEXT_AND_LABEL_PROPERTIES(), DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES(), PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS(), PANEL_EESCHEMA_DISPLAY_OPTIONS::PANEL_EESCHEMA_DISPLAY_OPTIONS(), PANEL_FP_EDITOR_DEFAULTS::PANEL_FP_EDITOR_DEFAULTS(), PANEL_SELECTION_FILTER::PANEL_SELECTION_FILTER(), PANEL_SETUP_CONSTRAINTS::PANEL_SETUP_CONSTRAINTS(), PANEL_SETUP_MASK_AND_PASTE::PANEL_SETUP_MASK_AND_PASTE(), PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES(), PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME(), PROPERTIES_FRAME::PROPERTIES_FRAME(), and WX_HTML_REPORT_PANEL::WX_HTML_REPORT_PANEL().

◆ GetMonospacedUIFont()

wxFont KIUI::GetMonospacedUIFont ( )

Definition at line 82 of file ui_common.cpp.

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

Referenced by CVPCB_MAINFRAME::BuildFootprintsListBox(), CVPCB_MAINFRAME::BuildLibrariesListBox(), CVPCB_MAINFRAME::BuildSymbolsListBox(), SIM_PLOT_FRAME::onShowNetlist(), and SCINTILLA_TRICKS::setupStyles().

◆ GetStatusFont()

wxFont KIUI::GetStatusFont ( wxWindow *  aWindow)

Definition at line 129 of file ui_common.cpp.

130 {
131 #ifdef __WXMAC__
132  int scale = -2;
133 #else
134  int scale = 0;
135 #endif
136 
137  return getGUIFont( aWindow, scale );
138 }
const int scale
wxFont getGUIFont(wxWindow *aWindow, int aRelativeSize)
Definition: ui_common.cpp:98

References getGUIFont(), and scale.

Referenced by CVPCB_MAINFRAME::CVPCB_MAINFRAME(), DIALOG_BOARD_STATISTICS::DIALOG_BOARD_STATISTICS(), EDA_DRAW_FRAME::EDA_DRAW_FRAME(), EDA_MSG_PANEL::EDA_MSG_PANEL(), and EVT_MENU_RANGE().

◆ GetStdMargin()

int KIUI::GetStdMargin ( )

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

Returns
margin in pixels

Definition at line 38 of file ui_common.cpp.

39 {
40  // This is the value used in (most) wxFB dialogs
41  return 5;
42 }

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

◆ 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 67 of file ui_common.cpp.

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

Referenced by DIALOG_EDIT_SYMBOLS_LIBID::AdjustGridColumns(), LIB_TREE_MODEL_ADAPTER::AttachTo(), DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE(), WX_ELLIPSIZED_STATIC_TEXT::DoGetBestSize(), EDA_DRAW_FRAME::EDA_DRAW_FRAME(), EnsureTextCtrlWidth(), FIELDS_EDITOR_GRID_DATA_MODEL::GetDataWidth(), 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 250 of file ui_common.cpp.

251 {
252  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( aFocus );
253  wxStyledTextCtrl* styledText = dynamic_cast<wxStyledTextCtrl*>( aFocus );
254  wxSearchCtrl* searchCtrl = dynamic_cast<wxSearchCtrl*>( aFocus );
255 
256  if( textEntry )
257  return textEntry->IsEditable();
258  else if( styledText )
259  return styledText->IsEditable();
260  else if( searchCtrl )
261  return searchCtrl->IsEditable();
262 
263  return true; // Must return true if we can't determine the state, intentionally true for non inputs as well
264 }

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 217 of file ui_common.cpp.

218 {
219  if( aFocus == nullptr )
220  aFocus = wxWindow::FindFocus();
221 
222  if( !aFocus )
223  return false;
224 
225  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( aFocus );
226  wxStyledTextCtrl* styledText = dynamic_cast<wxStyledTextCtrl*>( aFocus );
227  wxListBox* listBox = dynamic_cast<wxListBox*>( aFocus );
228  wxSearchCtrl* searchCtrl = dynamic_cast<wxSearchCtrl*>( aFocus );
229  wxCheckBox* checkboxCtrl = dynamic_cast<wxCheckBox*>( aFocus );
230  wxChoice* choiceCtrl = dynamic_cast<wxChoice*>( aFocus );
231  wxRadioButton* radioBtn = dynamic_cast<wxRadioButton*>( aFocus );
232  wxSpinCtrl* spinCtrl = dynamic_cast<wxSpinCtrl*>( aFocus );
233  wxSpinCtrlDouble* spinDblCtrl = dynamic_cast<wxSpinCtrlDouble*>( aFocus );
234  wxSlider* sliderCtl = dynamic_cast<wxSlider*>( aFocus );
235 
236  // Data view control is annoying, the focus is on a "wxDataViewCtrlMainWindow" class that
237  // is not formerly exported via the header.
238  wxDataViewCtrl* dataViewCtrl = nullptr;
239 
240  wxWindow* parent = aFocus->GetParent();
241 
242  if( parent )
243  dataViewCtrl = dynamic_cast<wxDataViewCtrl*>( parent );
244 
245  return ( textEntry || styledText || listBox || searchCtrl || checkboxCtrl || choiceCtrl
246  || radioBtn || spinCtrl || spinDblCtrl || sliderCtl || dataViewCtrl );
247 }

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

◆ IsModalDialogFocused()

bool KIUI::IsModalDialogFocused ( )

Definition at line 267 of file ui_common.cpp.

268 {
269  return Pgm().m_ModalDialogCount > 0;
270 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106

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 182 of file ui_common.cpp.

183 {
184  wxString ref = aTextEntry->GetValue();
185 
186  if( ref.find_first_of( '?' ) != ref.npos )
187  {
188  aTextEntry->SetSelection( ref.find_first_of( '?' ), ref.find_last_of( '?' ) + 1 );
189  }
190  else if( ref.find_first_of( '*' ) != ref.npos )
191  {
192  aTextEntry->SetSelection( ref.find_first_of( '*' ), ref.find_last_of( '*' ) + 1 );
193  }
194  else
195  {
196  wxString num = ref;
197 
198  while( !num.IsEmpty() && ( !isdigit( num.Last() ) || !isdigit( num.GetChar( 0 ) ) ) )
199  {
200  // Trim non-digit from end
201  if( !isdigit( num.Last() ) )
202  num.RemoveLast();
203 
204  // Trim non-digit from the start
205  if( !num.IsEmpty() && !isdigit( num.GetChar( 0 ) ) )
206  num = num.Right( num.Length() - 1 );
207  }
208 
209  aTextEntry->SetSelection( ref.Find( num ), ref.Find( num ) + num.Length() );
210 
211  if( num.IsEmpty() )
212  aTextEntry->SetSelection( -1, -1 );
213  }
214 }

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

◆ 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, "Transferring validator data without a control" );
381 
382  wxEventBlocker orient_update_blocker( ctrl, wxEVT_ANY );
383  aValidator.TransferToWindow();
384 }

Referenced by DIALOG_FOOTPRINT_PROPERTIES::updateOrientationControl().