2018-10-03 10:02:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
#include <wx/wx.h>
|
2020-11-05 02:06:36 +00:00
|
|
|
#include <wx/dataview.h>
|
|
|
|
#include <wx/stc/stc.h>
|
2018-10-03 10:02:43 +00:00
|
|
|
#include <widgets/ui_common.h>
|
|
|
|
|
2020-05-08 14:34:28 +00:00
|
|
|
#include <algorithm>
|
2020-09-21 20:09:30 +00:00
|
|
|
#include <gal/color4d.h>
|
2018-10-03 10:02:43 +00:00
|
|
|
|
|
|
|
int KIUI::GetStdMargin()
|
|
|
|
{
|
|
|
|
// This is the value used in (most) wxFB dialogs
|
|
|
|
return 5;
|
2020-02-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
SEVERITY SeverityFromString( const wxString& aSeverity )
|
|
|
|
{
|
|
|
|
if( aSeverity == wxT( "warning" ) )
|
|
|
|
return RPT_SEVERITY_WARNING;
|
|
|
|
else if( aSeverity == wxT( "ignore" ) )
|
|
|
|
return RPT_SEVERITY_IGNORE;
|
|
|
|
else
|
|
|
|
return RPT_SEVERITY_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString SeverityToString( const SEVERITY& aSeverity )
|
|
|
|
{
|
|
|
|
if( aSeverity == RPT_SEVERITY_IGNORE )
|
|
|
|
return wxT( "ignore" );
|
|
|
|
else if( aSeverity == RPT_SEVERITY_WARNING )
|
|
|
|
return wxT( "warning" );
|
|
|
|
else
|
|
|
|
return wxT( "error" );
|
|
|
|
}
|
2020-10-25 16:41:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
wxSize KIUI::GetTextSize( const wxString& aSingleLine, wxWindow* aWindow )
|
|
|
|
{
|
|
|
|
wxCoord width;
|
|
|
|
wxCoord height;
|
|
|
|
|
|
|
|
{
|
|
|
|
wxClientDC dc( aWindow );
|
|
|
|
dc.SetFont( aWindow->GetFont() );
|
|
|
|
dc.GetTextExtent( aSingleLine, &width, &height );
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxSize( width, height );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KIUI::EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString )
|
|
|
|
{
|
|
|
|
wxWindow* window = aCtrl->GetParent();
|
|
|
|
|
|
|
|
if( !window )
|
|
|
|
window = aCtrl;
|
|
|
|
|
|
|
|
wxString ctrlText;
|
|
|
|
|
|
|
|
if( !aString )
|
|
|
|
{
|
|
|
|
ctrlText = aCtrl->GetValue();
|
|
|
|
aString = &ctrlText;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSize textz = GetTextSize( *aString, window );
|
|
|
|
wxSize ctrlz = aCtrl->GetSize();
|
|
|
|
|
|
|
|
if( ctrlz.GetWidth() < textz.GetWidth() + 10 )
|
|
|
|
{
|
|
|
|
ctrlz.SetWidth( textz.GetWidth() + 10 );
|
|
|
|
aCtrl->SetSizeHints( ctrlz );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KIUI::SelectReferenceNumber( wxTextEntry* aTextEntry )
|
|
|
|
{
|
|
|
|
wxString ref = aTextEntry->GetValue();
|
|
|
|
|
|
|
|
if( ref.find_first_of( '?' ) != ref.npos )
|
|
|
|
{
|
|
|
|
aTextEntry->SetSelection( ref.find_first_of( '?' ), ref.find_last_of( '?' ) + 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString num = ref;
|
|
|
|
|
|
|
|
while( !num.IsEmpty() && ( !isdigit( num.Last() ) || !isdigit( num.GetChar( 0 ) ) ) )
|
|
|
|
{
|
|
|
|
// Trim non-digit from end
|
|
|
|
if( !isdigit( num.Last() ) )
|
|
|
|
num.RemoveLast();
|
|
|
|
|
|
|
|
// Trim non-digit from the start
|
|
|
|
if( !num.IsEmpty() && !isdigit( num.GetChar( 0 ) ) )
|
|
|
|
num = num.Right( num.Length() - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
aTextEntry->SetSelection( ref.Find( num ), ref.Find( num ) + num.Length() );
|
|
|
|
|
|
|
|
if( num.IsEmpty() )
|
|
|
|
aTextEntry->SetSelection( -1, -1 );
|
|
|
|
}
|
2020-11-05 02:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KIUI::IsInputControlFocused()
|
|
|
|
{
|
|
|
|
wxWindow* focus = wxWindow::FindFocus();
|
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( focus );
|
|
|
|
wxStyledTextCtrl* styledText = dynamic_cast<wxStyledTextCtrl*>( focus );
|
|
|
|
wxListBox* listBox = dynamic_cast<wxListBox*>( focus );
|
|
|
|
wxDataViewCtrl* dataViewCtrl = dynamic_cast<wxDataViewCtrl*>( focus );
|
|
|
|
|
|
|
|
return ( textEntry || styledText || listBox || dataViewCtrl );
|
2020-10-25 16:41:38 +00:00
|
|
|
}
|