Commit 75ea2891 authored by dickelbeck's avatar dickelbeck

added the superbly convenient EnsureTextCtrlWidth()

parent fcedda3f
...@@ -16,10 +16,13 @@ email address. ...@@ -16,10 +16,13 @@ email address.
2009-Jan-29 UPDATE Dick Hollenbeck <dick@softplc.com> 2009-Jan-29 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================ ================================================================================
++all
common.c added EnsureTextCtrlWidth()
++eeschema ++eeschema
dialog edit component in schematic: make sure chipname text control is wide * dialog edit component in schematic: make sure chipname text control is wide
enough to handle unusually long chip names. Did not have time to look at enough to handle unusually long chip names.
dialog edit component in library. * Retain and re-use user's desired dialog edit component window size.
Did not have time to look at dialog edit component in library.
2009-Jan-27 UPDATE Vesa Solonen <vesa.solonen@hut.fi> 2009-Jan-27 UPDATE Vesa Solonen <vesa.solonen@hut.fi>
......
...@@ -72,6 +72,42 @@ void SetLocaleTo_Default( void ) ...@@ -72,6 +72,42 @@ void SetLocaleTo_Default( void )
} }
/********************************************************************/
bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString )
/********************************************************************/
{
wxWindow* window = aCtrl->GetParent();
if( !window )
window = aCtrl;
wxString ctrlText;
if( !aString )
{
ctrlText = aCtrl->GetValue();
aString = &ctrlText;
}
wxCoord width;
wxCoord height;
{
wxClientDC dc( window );
dc.SetFont( aCtrl->GetFont() );
dc.GetTextExtent( *aString, &width, &height );
}
wxSize size = aCtrl->GetSize();
if( size.GetWidth() < width + 10 )
{
size.SetWidth( width + 10 );
aCtrl->SetSizeHints( size );
return true;
}
return false;
}
/*********************************************************************************************/ /*********************************************************************************************/
Ki_PageDescr::Ki_PageDescr( const wxSize& size, const wxPoint& offset, const wxString& name ) Ki_PageDescr::Ki_PageDescr( const wxSize& size, const wxPoint& offset, const wxString& name )
/*********************************************************************************************/ /*********************************************************************************************/
......
...@@ -19,21 +19,7 @@ ...@@ -19,21 +19,7 @@
int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_SelectedRow; int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_SelectedRow;
/** wxSize DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize = wxDefaultSize;
* Function GetTextSize
* computes the size of a text string in pixels from the wxFont used within a wxTextCtrl.
* @param aString is the text string to measure, must be a single line, no newlines.
* @param aWindow is the wxWindow which is the parent of the wxTextCtrl \a aCtrl.
* @param aWidth is where to put the width of the string in pixels.
* @param aHeight is where to put the heigth of the string in pixels.
*/
static void GetTextSize( const wxString& aString, wxWindow* aWindow, wxTextCtrl* aCtrl, wxCoord* aWidth, wxCoord* aHeight )
{
wxClientDC dc( aWindow );
dc.SetFont( aCtrl->GetFont() );
dc.GetTextExtent( aString, aWidth, aHeight );
}
/**********************************************************************/ /**********************************************************************/
...@@ -57,24 +43,25 @@ void InstallCmpeditFrame( WinEDA_SchematicFrame* parent, wxPoint& pos, ...@@ -57,24 +43,25 @@ void InstallCmpeditFrame( WinEDA_SchematicFrame* parent, wxPoint& pos,
dialog->InitBuffers( aComponent ); dialog->InitBuffers( aComponent );
// make sure the chipnameTextCtrl is wide enough to hold any unusually long chip names: wxSize sizeNow = dialog->GetSize();
{
wxCoord width;
wxCoord height;
GetTextSize( dialog->chipnameTextCtrl->GetValue(), dialog, dialog->chipnameTextCtrl, &width, &height );
wxSize size = dialog->chipnameTextCtrl->GetSize(); // this relies on wxDefaultSize being -1,-1, be careful here.
if( sizeNow.GetWidth() < DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize.GetWidth()
if( size.GetWidth() < width + 10 ) || sizeNow.GetHeight() < DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize.GetHeight() )
{ {
size.SetWidth( width + 10 ); dialog->SetSize( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize );
dialog->chipnameTextCtrl->SetSizeHints( size );
dialog->Layout();
}
} }
// make sure the chipnameTextCtrl is wide enough to hold any unusually long chip names:
EnsureTextCtrlWidth( dialog->chipnameTextCtrl );
dialog->ShowModal(); dialog->ShowModal();
// Some of the field values are long and are not always fully visible
// because the window comes up too narrow.
// Remember user's manual window resizing efforts here so it comes up wide enough next time.
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize = dialog->GetSize();
dialog->Destroy(); dialog->Destroy();
} }
......
...@@ -22,6 +22,9 @@ class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC : public DIALOG_EDIT_COMPONENT_IN_SCHEM ...@@ -22,6 +22,9 @@ class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC : public DIALOG_EDIT_COMPONENT_IN_SCHEM
static int s_SelectedRow; static int s_SelectedRow;
/// The size of the dialog window last time it was displayed;
static wxSize s_LastSize;
/// a copy of the edited component's SCH_CMP_FIELDs /// a copy of the edited component's SCH_CMP_FIELDs
SCH_CMP_FIELDS m_FieldsBuf; SCH_CMP_FIELDS m_FieldsBuf;
......
...@@ -389,6 +389,21 @@ but could make more easier an optional use of locale in kicad ...@@ -389,6 +389,21 @@ but could make more easier an optional use of locale in kicad
*/ */
void SetLocaleTo_Default(void); void SetLocaleTo_Default(void);
/**
* Function EnsureTextCtrlWidth
* sets 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.
* @param aCtrl the text control to potentially make wider.
* @param aString the text that is used in sizing the control's pixel width. If NULL, then
* the text already within the control is used.
* @return bool - true if the \a aCtrl had its size changed, else false.
*/
bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = NULL );
/** /**
* Operator << overload * Operator << overload
* outputs a point to the argument string in a format resembling * outputs a point to the argument string in a format resembling
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment