21#include <wx/dcclient.h>
22#include <wx/checkbox.h>
25#include <wx/menuitem.h>
26#include <wx/listbox.h>
27#include <wx/dataview.h>
28#include <wx/radiobut.h>
30#include <wx/spinctrl.h>
31#include <wx/srchctrl.h>
32#include <wx/stc/stc.h>
33#include <wx/scrolbar.h>
35#include <wx/hyperlink.h>
36#include <wx/notebook.h>
42#include <wx/settings.h>
60 if( aSeverity == wxT(
"warning" ) )
62 else if( aSeverity == wxT(
"ignore" ) )
72 return wxT(
"ignore" );
74 return wxT(
"warning" );
76 return wxT(
"error" );
86 wxClientDC dc( aWindow );
87 dc.SetFont( aWindow->GetFont() );
88 dc.GetTextExtent( aSingleLine, &width, &height );
91 return wxSize( width, height );
97 static const int guiFontSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize();
99 wxFont font( guiFontSize + aRelativeSize, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL );
103 if( font.GetFaceName().IsEmpty() )
104 font.SetFaceName( wxS(
"Menlo" ) );
113 wxFont font = aWindow->GetFont();
115 font.SetPointSize( font.GetPointSize() + aRelativeSize );
117 if(
Pgm().GetCommonSettings() &&
Pgm().GetCommonSettings()->m_Appearance.apply_icon_scale_to_fonts )
122 if( font.GetFaceName().IsEmpty() )
123 font.SetFaceName( wxS(
"San Francisco" ) );
178 wxWindow* window = aCtrl->GetParent();
187 ctrlText = aCtrl->GetValue();
192 wxSize ctrlz = aCtrl->GetSize();
194 if( ctrlz.GetWidth() < textz.GetWidth() + 10 )
196 ctrlz.SetWidth( textz.GetWidth() + 10 );
197 aCtrl->SetSizeHints( ctrlz );
209 msg.Replace( wxT(
"\n" ), wxT(
" " ) );
210 msg.Replace( wxT(
"\r" ), wxT(
" " ) );
211 msg.Replace( wxT(
"\t" ), wxT(
" " ) );
213 wxClientDC dc( aWindow );
214 int statusWidth = aWindow->GetSize().GetWidth();
217 int textWidth = std::min( statusWidth, 800 ) * 0.3 + std::max( statusWidth - 800, 0 ) * 0.6;
219 return wxControl::Ellipsize( msg, dc, wxELLIPSIZE_END, textWidth );
227 msg.Replace( wxT(
"\n" ), wxT(
" " ) );
228 msg.Replace( wxT(
"\r" ), wxT(
" " ) );
229 msg.Replace( wxT(
"\t" ), wxT(
" " ) );
231 if( msg.Length() > 36 )
232 msg = msg.Left( 34 ) + wxT(
"..." );
240 wxClientDC dc( aWindow );
241 dc.SetFont( aWindow->GetFont() );
244 [&](
const wxString& aLine )
246 return dc.GetTextExtent( aLine ).x;
251 for(
const wxString& line : wxSplit( aText,
'\n',
'\0' ) )
255 for( wxString word : wxSplit( line,
' ',
'\0' ) )
257 const bool isPath = word.Contains( wxS(
"/" ) ) || word.Contains( wxS(
"\\" ) );
259 if( isPath && measure( word ) > aWidth )
260 word = wxControl::Ellipsize( word, dc, wxELLIPSIZE_MIDDLE, aWidth, wxELLIPSIZE_FLAGS_NONE );
262 const wxString joined = current.IsEmpty() ? word : current + wxS(
" " ) + word;
264 if( measure( joined ) <= aWidth )
270 if( !current.IsEmpty() )
272 wrapped += current + wxS(
"\n" );
278 if( !current.IsEmpty() && measure( current + cluster ) > aWidth )
280 wrapped += current + wxS(
"\n" );
288 wrapped += current + wxS(
"\n" );
291 wrapped.RemoveLast();
298 wxString ref = aTextEntry->GetValue();
300 if( ref.find_first_of(
'?' ) != ref.npos )
302 aTextEntry->SetSelection( ref.find_first_of(
'?' ), ref.find_last_of(
'?' ) + 1 );
304 else if( ref.find_first_of(
'*' ) != ref.npos )
306 aTextEntry->SetSelection( ref.find_first_of(
'*' ), ref.find_last_of(
'*' ) + 1 );
312 while( !num.IsEmpty() && ( !isdigit( num.Last() ) || !isdigit( num.GetChar( 0 ) ) ) )
315 if( !isdigit( num.Last() ) )
319 if( !num.IsEmpty() && !isdigit( num.GetChar( 0 ) ) )
320 num = num.Right( num.Length() - 1 );
323 aTextEntry->SetSelection( ref.Find( num ), ref.Find( num ) + num.Length() );
326 aTextEntry->SetSelection( -1, -1 );
333 if( aFocus ==
nullptr )
334 aFocus = wxWindow::FindFocus();
343 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>( aFocus );
344 wxStyledTextCtrl* styledText =
dynamic_cast<wxStyledTextCtrl*
>( aFocus );
345 wxListBox* listBox =
dynamic_cast<wxListBox*
>( aFocus );
346 wxSearchCtrl* searchCtrl =
dynamic_cast<wxSearchCtrl*
>( aFocus );
347 wxCheckBox* checkboxCtrl =
dynamic_cast<wxCheckBox*
>( aFocus );
348 wxChoice* choiceCtrl =
dynamic_cast<wxChoice*
>( aFocus );
349 wxRadioButton* radioBtn =
dynamic_cast<wxRadioButton*
>( aFocus );
350 wxSpinCtrl* spinCtrl =
dynamic_cast<wxSpinCtrl*
>( aFocus );
351 wxSpinCtrlDouble* spinDblCtrl =
dynamic_cast<wxSpinCtrlDouble*
>( aFocus );
352 wxSlider* sliderCtl =
dynamic_cast<wxSlider*
>( aFocus );
356 wxDataViewCtrl* dataViewCtrl =
nullptr;
358 wxWindow* parent = aFocus->GetParent();
361 dataViewCtrl =
dynamic_cast<wxDataViewCtrl*
>( parent );
363 return ( textEntry || styledText || listBox || searchCtrl || checkboxCtrl || choiceCtrl
364 || radioBtn || spinCtrl || spinDblCtrl || sliderCtl || dataViewCtrl );
370 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>( aFocus );
371 wxStyledTextCtrl* styledText =
dynamic_cast<wxStyledTextCtrl*
>( aFocus );
372 wxSearchCtrl* searchCtrl =
dynamic_cast<wxSearchCtrl*
>( aFocus );
375 return textEntry->IsEditable();
376 else if( styledText )
377 return styledText->IsEditable();
378 else if( searchCtrl )
379 return searchCtrl->IsEditable();
394 wxScrollBar* scrollBar =
dynamic_cast<wxScrollBar*
>( aWindow );
395 wxHyperlinkCtrl* hyperlink =
dynamic_cast<wxHyperlinkCtrl*
>( aWindow );
396 wxGrid*
grid =
dynamic_cast<wxGrid*
>( aWindow );
397 wxStyledTextCtrl* scintilla =
dynamic_cast<wxStyledTextCtrl*
>( aWindow );
398 wxControl* control =
dynamic_cast<wxControl*
>( aWindow );
400 if( scrollBar || hyperlink )
406 for(
int row = 0; row <
grid->GetNumberRows(); ++row )
408 for(
int col = 0; col <
grid->GetNumberCols(); ++col )
409 grid->SetReadOnly( row, col );
414 scintilla->SetReadOnly(
true );
422 for( wxWindow* child : aWindow->GetChildren() )
433 wxItemKind menu_type = aMenu->GetKind();
435 if( useImagesInMenus && menu_type != wxITEM_CHECK && menu_type != wxITEM_RADIO )
436 aMenu->SetBitmap( aImage );
441 const wxBitmapBundle& aImage, wxItemKind aType )
443 wxMenuItem* item =
new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
446 aMenu->Append( item );
453 const wxString& aHelpText,
const wxBitmapBundle& aImage,
456 wxMenuItem* item =
new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
459 aMenu->Append( item );
466 const wxBitmapBundle& aImage )
468 wxMenuItem* item =
new wxMenuItem( aMenu, aId, aText );
469 item->SetSubMenu( aSubMenu );
472 aMenu->Append( item );
479 const wxString& aHelpText,
const wxBitmapBundle& aImage )
481 wxMenuItem* item =
new wxMenuItem( aMenu, aId, aText, aHelpText );
482 item->SetSubMenu( aSubMenu );
485 aMenu->Append( item );
493 wxWindow* candidate = aChildWindow;
495 while( candidate && candidate->GetParent() != aNotebook )
496 candidate = candidate->GetParent();
499 return aNotebook->FindPage( candidate );
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
virtual COMMON_SETTINGS * GetCommonSettings() const
std::vector< void * > m_ModalDialogs
KICOMMON_API int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
KICOMMON_API wxFont GetDockedPaneFont(wxWindow *aWindow)
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
KICOMMON_API bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
KICOMMON_API bool IsInputControlEditable(wxWindow *aControl)
Check if a input control has focus.
KICOMMON_API wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
KICOMMON_API wxString WrapText(wxWindow *aWindow, const wxString &aText, int aWidth)
Break text into lines no wider than aWidth pixels in aWindow's font.
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
KICOMMON_API bool IsModalDialogFocused()
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
KICOMMON_API wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmapBundle &aImage, wxItemKind aType=wxITEM_NORMAL)
Create and insert a menu item with an icon into aMenu.
KICOMMON_API wxString EllipsizeStatusText(wxWindow *aWindow, const wxString &aString)
Ellipsize text (at the end) to be no more than 1/3 of the window width.
KICOMMON_API const wxString s_FocusStealableInputName
KICOMMON_API void SelectReferenceNumber(wxTextEntry *aTextEntry)
Select the number (or "?") in a reference for ease of editing.
KICOMMON_API 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...
KICOMMON_API void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmapBundle &aImage)
Add a bitmap to a menuitem.
KICOMMON_API wxFont GetMonospacedUIFont(int aRelativeSize=0)
KICOMMON_API 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 ...
KICOMMON_API void Disable(wxWindow *aWindow)
Makes a window read-only.
PGM_BASE & Pgm()
The global program "get" accessor.
wxString UnescapeString(const wxString &aSource)
std::vector< wxString > SplitGraphemeClusters(const wxString &aText)
Split text into the units a reader sees as one character.
int FindNotebookPage(wxNotebook *aNotebook, wxWindow *aChildWindow)
SEVERITY SeverityFromString(const wxString &aSeverity)
wxString SeverityToString(const SEVERITY &aSeverity)
wxFont getGUIFont(wxWindow *aWindow, int aRelativeSize)
Functions to provide common constants and other functions to assist in making a consistent UI.