added the superbly convenient EnsureTextCtrlWidth()

This commit is contained in:
dickelbeck 2009-01-29 17:30:38 +00:00
parent fcedda3ff7
commit 75ea28917c
5 changed files with 76 additions and 32 deletions

View File

@ -16,10 +16,13 @@ email address.
2009-Jan-29 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++all
common.c added EnsureTextCtrlWidth()
++eeschema
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
dialog edit component in library.
* dialog edit component in schematic: make sure chipname text control is wide
enough to handle unusually long chip names.
* 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>

View File

@ -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 )
/*********************************************************************************************/

View File

@ -19,21 +19,7 @@
int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_SelectedRow;
/**
* 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 );
}
wxSize DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize = wxDefaultSize;
/**********************************************************************/
@ -57,24 +43,25 @@ void InstallCmpeditFrame( WinEDA_SchematicFrame* parent, wxPoint& pos,
dialog->InitBuffers( aComponent );
// make sure the chipnameTextCtrl is wide enough to hold any unusually long chip names:
wxSize sizeNow = dialog->GetSize();
// this relies on wxDefaultSize being -1,-1, be careful here.
if( sizeNow.GetWidth() < DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize.GetWidth()
|| sizeNow.GetHeight() < DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize.GetHeight() )
{
wxCoord width;
wxCoord height;
GetTextSize( dialog->chipnameTextCtrl->GetValue(), dialog, dialog->chipnameTextCtrl, &width, &height );
wxSize size = dialog->chipnameTextCtrl->GetSize();
if( size.GetWidth() < width + 10 )
{
size.SetWidth( width + 10 );
dialog->chipnameTextCtrl->SetSizeHints( size );
dialog->Layout();
}
dialog->SetSize( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize );
}
// make sure the chipnameTextCtrl is wide enough to hold any unusually long chip names:
EnsureTextCtrlWidth( dialog->chipnameTextCtrl );
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();
}

View File

@ -22,6 +22,9 @@ class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC : public DIALOG_EDIT_COMPONENT_IN_SCHEM
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
SCH_CMP_FIELDS m_FieldsBuf;

View File

@ -389,6 +389,21 @@ but could make more easier an optional use of locale in kicad
*/
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
* outputs a point to the argument string in a format resembling