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...
 
bool EnsureTextCtrlWidth (wxTextCtrl *aCtrl, const wxString *aString=NULL)
 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 ()
 Checks if a input control has focus. More...
 
bool IsModalDialogFocused ()
 

Function Documentation

◆ EnsureTextCtrlWidth()

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

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
bool - true if the aCtrl had its size changed, else false.

Definition at line 73 of file ui_common.cpp.

74 {
75  wxWindow* window = aCtrl->GetParent();
76 
77  if( !window )
78  window = aCtrl;
79 
80  wxString ctrlText;
81 
82  if( !aString )
83  {
84  ctrlText = aCtrl->GetValue();
85  aString = &ctrlText;
86  }
87 
88  wxSize textz = GetTextSize( *aString, window );
89  wxSize ctrlz = aCtrl->GetSize();
90 
91  if( ctrlz.GetWidth() < textz.GetWidth() + 10 )
92  {
93  ctrlz.SetWidth( textz.GetWidth() + 10 );
94  aCtrl->SetSizeHints( ctrlz );
95  return true;
96  }
97 
98  return false;
99 }
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:58

References GetTextSize().

Referenced by GERBVIEW_FRAME::UpdateTitleAndInfo().

◆ GetStdMargin()

int KIUI::GetStdMargin ( )

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

Returns
margin in pixels

Definition at line 29 of file ui_common.cpp.

30 {
31  // This is the value used in (most) wxFB dialogs
32  return 5;
33 }

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

59 {
60  wxCoord width;
61  wxCoord height;
62 
63  {
64  wxClientDC dc( aWindow );
65  dc.SetFont( aWindow->GetFont() );
66  dc.GetTextExtent( aSingleLine, &width, &height );
67  }
68 
69  return wxSize( width, height );
70 }

Referenced by DIALOG_EDIT_COMPONENTS_LIBID::AdjustGridColumns(), LIB_TREE_MODEL_ADAPTER::AttachTo(), DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL(), 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().

◆ IsInputControlFocused()

bool KIUI::IsInputControlFocused ( )

Checks if a input control has focus.

Definition at line 137 of file ui_common.cpp.

138 {
139  wxWindow* focus = wxWindow::FindFocus();
140  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( focus );
141  wxStyledTextCtrl* styledText = dynamic_cast<wxStyledTextCtrl*>( focus );
142  wxListBox* listBox = dynamic_cast<wxListBox*>( focus );
143  wxDataViewCtrl* dataViewCtrl = dynamic_cast<wxDataViewCtrl*>( focus );
144 
145  return ( textEntry || styledText || listBox || dataViewCtrl );
146 }

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

◆ IsModalDialogFocused()

bool KIUI::IsModalDialogFocused ( )

Definition at line 149 of file ui_common.cpp.

150 {
151  return Pgm().m_ModalDialogCount > 0;
152 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102

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

103 {
104  wxString ref = aTextEntry->GetValue();
105 
106  if( ref.find_first_of( '?' ) != ref.npos )
107  {
108  aTextEntry->SetSelection( ref.find_first_of( '?' ), ref.find_last_of( '?' ) + 1 );
109  }
110  else if( ref.find_first_of( '*' ) != ref.npos )
111  {
112  aTextEntry->SetSelection( ref.find_first_of( '*' ), ref.find_last_of( '*' ) + 1 );
113  }
114  else
115  {
116  wxString num = ref;
117 
118  while( !num.IsEmpty() && ( !isdigit( num.Last() ) || !isdigit( num.GetChar( 0 ) ) ) )
119  {
120  // Trim non-digit from end
121  if( !isdigit( num.Last() ) )
122  num.RemoveLast();
123 
124  // Trim non-digit from the start
125  if( !num.IsEmpty() && !isdigit( num.GetChar( 0 ) ) )
126  num = num.Right( num.Length() - 1 );
127  }
128 
129  aTextEntry->SetSelection( ref.Find( num ), ref.Find( num ) + num.Length() );
130 
131  if( num.IsEmpty() )
132  aTextEntry->SetSelection( -1, -1 );
133  }
134 }

Referenced by DIALOG_TEXT_PROPERTIES::OnSetFocusText(), DIALOG_EDIT_ONE_FIELD::OnSetFocusText(), DIALOG_SYMBOL_PROPERTIES::OnUpdateUI(), DIALOG_FOOTPRINT_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().