fixed problem with calling SetFont() when (multiline) text control didn't have any value yet
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8598 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -28,7 +28,7 @@ class wxTextCtrl;
|
||||
class wxTextCtrl: public wxTextCtrlBase
|
||||
{
|
||||
public:
|
||||
wxTextCtrl();
|
||||
wxTextCtrl() { Init(); }
|
||||
wxTextCtrl(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxString &value = wxEmptyString,
|
||||
@@ -139,17 +139,25 @@ public:
|
||||
void ApplyWidgetStyle();
|
||||
void CalculateScrollbar();
|
||||
void OnInternalIdle();
|
||||
void UpdateFontIfNeeded();
|
||||
|
||||
void SetModified() { m_modified = TRUE; }
|
||||
|
||||
protected:
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
|
||||
// common part of all ctors
|
||||
void Init();
|
||||
|
||||
private:
|
||||
// change the font for everything in this control
|
||||
void ChangeFontGlobally();
|
||||
|
||||
bool m_modified;
|
||||
GtkWidget *m_text;
|
||||
GtkWidget *m_vScrollbar;
|
||||
bool m_vScrollbarVisible;
|
||||
bool m_updateFont;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
DECLARE_DYNAMIC_CLASS(wxTextCtrl);
|
||||
|
@@ -28,7 +28,7 @@ class wxTextCtrl;
|
||||
class wxTextCtrl: public wxTextCtrlBase
|
||||
{
|
||||
public:
|
||||
wxTextCtrl();
|
||||
wxTextCtrl() { Init(); }
|
||||
wxTextCtrl(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxString &value = wxEmptyString,
|
||||
@@ -139,17 +139,25 @@ public:
|
||||
void ApplyWidgetStyle();
|
||||
void CalculateScrollbar();
|
||||
void OnInternalIdle();
|
||||
void UpdateFontIfNeeded();
|
||||
|
||||
void SetModified() { m_modified = TRUE; }
|
||||
|
||||
protected:
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
|
||||
// common part of all ctors
|
||||
void Init();
|
||||
|
||||
private:
|
||||
// change the font for everything in this control
|
||||
void ChangeFontGlobally();
|
||||
|
||||
bool m_modified;
|
||||
GtkWidget *m_text;
|
||||
GtkWidget *m_vScrollbar;
|
||||
bool m_vScrollbarVisible;
|
||||
bool m_updateFont;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
DECLARE_DYNAMIC_CLASS(wxTextCtrl);
|
||||
|
@@ -51,6 +51,7 @@ gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
|
||||
wxapp_install_idle_handler();
|
||||
|
||||
win->SetModified();
|
||||
win->UpdateFontIfNeeded();
|
||||
|
||||
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
|
||||
event.SetString( win->GetValue() );
|
||||
@@ -95,9 +96,10 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
|
||||
EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
wxTextCtrl::wxTextCtrl()
|
||||
void wxTextCtrl::Init()
|
||||
{
|
||||
m_modified = FALSE;
|
||||
m_updateFont = FALSE;
|
||||
m_text =
|
||||
m_vScrollbar = (GtkWidget *)NULL;
|
||||
}
|
||||
@@ -111,7 +113,8 @@ wxTextCtrl::wxTextCtrl( wxWindow *parent,
|
||||
const wxValidator& validator,
|
||||
const wxString &name )
|
||||
{
|
||||
m_modified = FALSE;
|
||||
Init();
|
||||
|
||||
Create( parent, id, value, pos, size, style, validator, name );
|
||||
}
|
||||
|
||||
@@ -321,23 +324,21 @@ void wxTextCtrl::SetValue( const wxString &value )
|
||||
{
|
||||
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
|
||||
|
||||
wxString tmp = wxT("");
|
||||
if (!value.IsNull()) tmp = value;
|
||||
if (m_windowStyle & wxTE_MULTILINE)
|
||||
{
|
||||
gint len = gtk_text_get_length( GTK_TEXT(m_text) );
|
||||
gtk_editable_delete_text( GTK_EDITABLE(m_text), 0, len );
|
||||
len = 0;
|
||||
#if wxUSE_UNICODE
|
||||
wxWX2MBbuf tmpbuf = tmp.mbc_str();
|
||||
wxWX2MBbuf tmpbuf = value.mbc_str();
|
||||
gtk_editable_insert_text( GTK_EDITABLE(m_text), tmpbuf, strlen(tmpbuf), &len );
|
||||
#else
|
||||
gtk_editable_insert_text( GTK_EDITABLE(m_text), tmp.mbc_str(), tmp.Length(), &len );
|
||||
gtk_editable_insert_text( GTK_EDITABLE(m_text), value.mbc_str(), value.Length(), &len );
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_entry_set_text( GTK_ENTRY(m_text), tmp.mbc_str() );
|
||||
gtk_entry_set_text( GTK_ENTRY(m_text), value.mbc_str() );
|
||||
}
|
||||
|
||||
// GRG, Jun/2000: Changed this after a lot of discussion in
|
||||
@@ -869,20 +870,37 @@ bool wxTextCtrl::SetFont( const wxFont &font )
|
||||
|
||||
if ( m_windowStyle & wxTE_MULTILINE )
|
||||
{
|
||||
// for compatibility with other ports: the font is a global controls
|
||||
// characteristic, so change the font globally
|
||||
wxString value = GetValue();
|
||||
if ( !value.IsEmpty() )
|
||||
{
|
||||
Clear();
|
||||
m_updateFont = TRUE;
|
||||
|
||||
AppendText(value);
|
||||
}
|
||||
ChangeFontGlobally();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxTextCtrl::ChangeFontGlobally()
|
||||
{
|
||||
// this method is very inefficient and hence should be called as rarely as
|
||||
// possible!
|
||||
wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE) && m_updateFont,
|
||||
_T("shouldn't be called for single line controls") );
|
||||
|
||||
wxString value = GetValue();
|
||||
if ( !value.IsEmpty() )
|
||||
{
|
||||
Clear();
|
||||
AppendText(value);
|
||||
|
||||
m_updateFont = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void wxTextCtrl::UpdateFontIfNeeded()
|
||||
{
|
||||
if ( m_updateFont )
|
||||
ChangeFontGlobally();
|
||||
}
|
||||
|
||||
bool wxTextCtrl::SetForegroundColour( const wxColour &WXUNUSED(colour) )
|
||||
{
|
||||
wxCHECK_MSG( m_text != NULL, FALSE, wxT("invalid text ctrl") );
|
||||
|
@@ -51,6 +51,7 @@ gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
|
||||
wxapp_install_idle_handler();
|
||||
|
||||
win->SetModified();
|
||||
win->UpdateFontIfNeeded();
|
||||
|
||||
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
|
||||
event.SetString( win->GetValue() );
|
||||
@@ -95,9 +96,10 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
|
||||
EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
wxTextCtrl::wxTextCtrl()
|
||||
void wxTextCtrl::Init()
|
||||
{
|
||||
m_modified = FALSE;
|
||||
m_updateFont = FALSE;
|
||||
m_text =
|
||||
m_vScrollbar = (GtkWidget *)NULL;
|
||||
}
|
||||
@@ -111,7 +113,8 @@ wxTextCtrl::wxTextCtrl( wxWindow *parent,
|
||||
const wxValidator& validator,
|
||||
const wxString &name )
|
||||
{
|
||||
m_modified = FALSE;
|
||||
Init();
|
||||
|
||||
Create( parent, id, value, pos, size, style, validator, name );
|
||||
}
|
||||
|
||||
@@ -321,23 +324,21 @@ void wxTextCtrl::SetValue( const wxString &value )
|
||||
{
|
||||
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
|
||||
|
||||
wxString tmp = wxT("");
|
||||
if (!value.IsNull()) tmp = value;
|
||||
if (m_windowStyle & wxTE_MULTILINE)
|
||||
{
|
||||
gint len = gtk_text_get_length( GTK_TEXT(m_text) );
|
||||
gtk_editable_delete_text( GTK_EDITABLE(m_text), 0, len );
|
||||
len = 0;
|
||||
#if wxUSE_UNICODE
|
||||
wxWX2MBbuf tmpbuf = tmp.mbc_str();
|
||||
wxWX2MBbuf tmpbuf = value.mbc_str();
|
||||
gtk_editable_insert_text( GTK_EDITABLE(m_text), tmpbuf, strlen(tmpbuf), &len );
|
||||
#else
|
||||
gtk_editable_insert_text( GTK_EDITABLE(m_text), tmp.mbc_str(), tmp.Length(), &len );
|
||||
gtk_editable_insert_text( GTK_EDITABLE(m_text), value.mbc_str(), value.Length(), &len );
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_entry_set_text( GTK_ENTRY(m_text), tmp.mbc_str() );
|
||||
gtk_entry_set_text( GTK_ENTRY(m_text), value.mbc_str() );
|
||||
}
|
||||
|
||||
// GRG, Jun/2000: Changed this after a lot of discussion in
|
||||
@@ -869,20 +870,37 @@ bool wxTextCtrl::SetFont( const wxFont &font )
|
||||
|
||||
if ( m_windowStyle & wxTE_MULTILINE )
|
||||
{
|
||||
// for compatibility with other ports: the font is a global controls
|
||||
// characteristic, so change the font globally
|
||||
wxString value = GetValue();
|
||||
if ( !value.IsEmpty() )
|
||||
{
|
||||
Clear();
|
||||
m_updateFont = TRUE;
|
||||
|
||||
AppendText(value);
|
||||
}
|
||||
ChangeFontGlobally();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxTextCtrl::ChangeFontGlobally()
|
||||
{
|
||||
// this method is very inefficient and hence should be called as rarely as
|
||||
// possible!
|
||||
wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE) && m_updateFont,
|
||||
_T("shouldn't be called for single line controls") );
|
||||
|
||||
wxString value = GetValue();
|
||||
if ( !value.IsEmpty() )
|
||||
{
|
||||
Clear();
|
||||
AppendText(value);
|
||||
|
||||
m_updateFont = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void wxTextCtrl::UpdateFontIfNeeded()
|
||||
{
|
||||
if ( m_updateFont )
|
||||
ChangeFontGlobally();
|
||||
}
|
||||
|
||||
bool wxTextCtrl::SetForegroundColour( const wxColour &WXUNUSED(colour) )
|
||||
{
|
||||
wxCHECK_MSG( m_text != NULL, FALSE, wxT("invalid text ctrl") );
|
||||
|
Reference in New Issue
Block a user