fixed inserting styled text into an empty control under GTK+ 2.0
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28435 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -88,6 +88,10 @@ public:
|
|||||||
|
|
||||||
virtual void ShowPosition(long pos);
|
virtual void ShowPosition(long pos);
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
|
||||||
|
#endif // __WXGTK20__
|
||||||
|
|
||||||
// Clipboard operations
|
// Clipboard operations
|
||||||
virtual void Copy();
|
virtual void Copy();
|
||||||
virtual void Cut();
|
virtual void Cut();
|
||||||
@@ -136,7 +140,13 @@ public:
|
|||||||
void DoApplyWidgetStyle(GtkRcStyle *style);
|
void DoApplyWidgetStyle(GtkRcStyle *style);
|
||||||
void CalculateScrollbar();
|
void CalculateScrollbar();
|
||||||
void OnInternalIdle();
|
void OnInternalIdle();
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
void SetUpdateFont(bool WXUNUSED(update)) { }
|
||||||
|
#else // !__WXGTK20__
|
||||||
|
void SetUpdateFont(bool update) { m_updateFont = update; }
|
||||||
void UpdateFontIfNeeded();
|
void UpdateFontIfNeeded();
|
||||||
|
#endif // __WXGTK20__/!__WXGTK20__
|
||||||
|
|
||||||
void SetModified() { m_modified = TRUE; }
|
void SetModified() { m_modified = TRUE; }
|
||||||
|
|
||||||
@@ -191,7 +201,9 @@ private:
|
|||||||
|
|
||||||
bool m_modified:1;
|
bool m_modified:1;
|
||||||
bool m_vScrollbarVisible:1;
|
bool m_vScrollbarVisible:1;
|
||||||
|
#ifndef __WXGTK20__
|
||||||
bool m_updateFont:1;
|
bool m_updateFont:1;
|
||||||
|
#endif // !__WXGTK20__
|
||||||
bool m_ignoreNextUpdate:1;
|
bool m_ignoreNextUpdate:1;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
@@ -88,6 +88,10 @@ public:
|
|||||||
|
|
||||||
virtual void ShowPosition(long pos);
|
virtual void ShowPosition(long pos);
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
|
||||||
|
#endif // __WXGTK20__
|
||||||
|
|
||||||
// Clipboard operations
|
// Clipboard operations
|
||||||
virtual void Copy();
|
virtual void Copy();
|
||||||
virtual void Cut();
|
virtual void Cut();
|
||||||
@@ -136,7 +140,13 @@ public:
|
|||||||
void DoApplyWidgetStyle(GtkRcStyle *style);
|
void DoApplyWidgetStyle(GtkRcStyle *style);
|
||||||
void CalculateScrollbar();
|
void CalculateScrollbar();
|
||||||
void OnInternalIdle();
|
void OnInternalIdle();
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
void SetUpdateFont(bool WXUNUSED(update)) { }
|
||||||
|
#else // !__WXGTK20__
|
||||||
|
void SetUpdateFont(bool update) { m_updateFont = update; }
|
||||||
void UpdateFontIfNeeded();
|
void UpdateFontIfNeeded();
|
||||||
|
#endif // __WXGTK20__/!__WXGTK20__
|
||||||
|
|
||||||
void SetModified() { m_modified = TRUE; }
|
void SetModified() { m_modified = TRUE; }
|
||||||
|
|
||||||
@@ -191,7 +201,9 @@ private:
|
|||||||
|
|
||||||
bool m_modified:1;
|
bool m_modified:1;
|
||||||
bool m_vScrollbarVisible:1;
|
bool m_vScrollbarVisible:1;
|
||||||
|
#ifndef __WXGTK20__
|
||||||
bool m_updateFont:1;
|
bool m_updateFont:1;
|
||||||
|
#endif // !__WXGTK20__
|
||||||
bool m_ignoreNextUpdate:1;
|
bool m_ignoreNextUpdate:1;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
@@ -155,7 +155,9 @@ gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win )
|
|||||||
wxapp_install_idle_handler();
|
wxapp_install_idle_handler();
|
||||||
|
|
||||||
win->SetModified();
|
win->SetModified();
|
||||||
|
#ifndef __WXGTK20__
|
||||||
win->UpdateFontIfNeeded();
|
win->UpdateFontIfNeeded();
|
||||||
|
#endif // !__WXGTK20__
|
||||||
|
|
||||||
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
|
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
|
||||||
event.SetEventObject( win );
|
event.SetEventObject( win );
|
||||||
@@ -239,7 +241,7 @@ void wxTextCtrl::Init()
|
|||||||
{
|
{
|
||||||
m_ignoreNextUpdate =
|
m_ignoreNextUpdate =
|
||||||
m_modified = FALSE;
|
m_modified = FALSE;
|
||||||
m_updateFont = FALSE;
|
SetUpdateFont(FALSE);
|
||||||
m_text =
|
m_text =
|
||||||
m_vScrollbar = (GtkWidget *)NULL;
|
m_vScrollbar = (GtkWidget *)NULL;
|
||||||
}
|
}
|
||||||
@@ -577,6 +579,11 @@ void wxTextCtrl::WriteText( const wxString &text )
|
|||||||
if ( text.empty() )
|
if ( text.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// gtk_text_changed_callback() will set m_modified to true but m_modified
|
||||||
|
// shouldn't be changed by the program writing to the text control itself,
|
||||||
|
// so save the old value and restore when we're done
|
||||||
|
bool oldModified = m_modified;
|
||||||
|
|
||||||
if ( m_windowStyle & wxTE_MULTILINE )
|
if ( m_windowStyle & wxTE_MULTILINE )
|
||||||
{
|
{
|
||||||
#ifdef __WXGTK20__
|
#ifdef __WXGTK20__
|
||||||
@@ -612,7 +619,7 @@ void wxTextCtrl::WriteText( const wxString &text )
|
|||||||
// in UpdateFontIfNeeded() any longer
|
// in UpdateFontIfNeeded() any longer
|
||||||
if ( !text.empty() )
|
if ( !text.empty() )
|
||||||
{
|
{
|
||||||
m_updateFont = FALSE;
|
SetUpdateFont(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bring editable's cursor back uptodate.
|
// Bring editable's cursor back uptodate.
|
||||||
@@ -644,7 +651,7 @@ void wxTextCtrl::WriteText( const wxString &text )
|
|||||||
gtk_entry_set_position( GTK_ENTRY(m_text), len );
|
gtk_entry_set_position( GTK_ENTRY(m_text), len );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_modified = TRUE;
|
m_modified = oldModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::AppendText( const wxString &text )
|
void wxTextCtrl::AppendText( const wxString &text )
|
||||||
@@ -1401,7 +1408,7 @@ bool wxTextCtrl::SetFont( const wxFont &font )
|
|||||||
|
|
||||||
if ( m_windowStyle & wxTE_MULTILINE )
|
if ( m_windowStyle & wxTE_MULTILINE )
|
||||||
{
|
{
|
||||||
m_updateFont = TRUE;
|
SetUpdateFont(TRUE);
|
||||||
|
|
||||||
m_defaultStyle.SetFont(font);
|
m_defaultStyle.SetFont(font);
|
||||||
|
|
||||||
@@ -1415,25 +1422,35 @@ void wxTextCtrl::ChangeFontGlobally()
|
|||||||
{
|
{
|
||||||
// this method is very inefficient and hence should be called as rarely as
|
// this method is very inefficient and hence should be called as rarely as
|
||||||
// possible!
|
// possible!
|
||||||
wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE) && m_updateFont,
|
//
|
||||||
|
// TODO: it can be implemented much more efficiently for GTK2
|
||||||
|
wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE)
|
||||||
|
#ifndef __WXGTK20__
|
||||||
|
&& m_updateFont
|
||||||
|
#endif // GTK+ 1.x
|
||||||
|
,
|
||||||
_T("shouldn't be called for single line controls") );
|
_T("shouldn't be called for single line controls") );
|
||||||
|
|
||||||
wxString value = GetValue();
|
wxString value = GetValue();
|
||||||
if ( !value.IsEmpty() )
|
if ( !value.IsEmpty() )
|
||||||
{
|
{
|
||||||
m_updateFont = FALSE;
|
SetUpdateFont(FALSE);
|
||||||
|
|
||||||
Clear();
|
Clear();
|
||||||
AppendText(value);
|
AppendText(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __WXGTK20__
|
||||||
|
|
||||||
void wxTextCtrl::UpdateFontIfNeeded()
|
void wxTextCtrl::UpdateFontIfNeeded()
|
||||||
{
|
{
|
||||||
if ( m_updateFont )
|
if ( m_updateFont )
|
||||||
ChangeFontGlobally();
|
ChangeFontGlobally();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // GTK+ 1.x
|
||||||
|
|
||||||
bool wxTextCtrl::SetForegroundColour(const wxColour& colour)
|
bool wxTextCtrl::SetForegroundColour(const wxColour& colour)
|
||||||
{
|
{
|
||||||
if ( !wxControl::SetForegroundColour(colour) )
|
if ( !wxControl::SetForegroundColour(colour) )
|
||||||
|
@@ -155,7 +155,9 @@ gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win )
|
|||||||
wxapp_install_idle_handler();
|
wxapp_install_idle_handler();
|
||||||
|
|
||||||
win->SetModified();
|
win->SetModified();
|
||||||
|
#ifndef __WXGTK20__
|
||||||
win->UpdateFontIfNeeded();
|
win->UpdateFontIfNeeded();
|
||||||
|
#endif // !__WXGTK20__
|
||||||
|
|
||||||
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
|
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
|
||||||
event.SetEventObject( win );
|
event.SetEventObject( win );
|
||||||
@@ -239,7 +241,7 @@ void wxTextCtrl::Init()
|
|||||||
{
|
{
|
||||||
m_ignoreNextUpdate =
|
m_ignoreNextUpdate =
|
||||||
m_modified = FALSE;
|
m_modified = FALSE;
|
||||||
m_updateFont = FALSE;
|
SetUpdateFont(FALSE);
|
||||||
m_text =
|
m_text =
|
||||||
m_vScrollbar = (GtkWidget *)NULL;
|
m_vScrollbar = (GtkWidget *)NULL;
|
||||||
}
|
}
|
||||||
@@ -577,6 +579,11 @@ void wxTextCtrl::WriteText( const wxString &text )
|
|||||||
if ( text.empty() )
|
if ( text.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// gtk_text_changed_callback() will set m_modified to true but m_modified
|
||||||
|
// shouldn't be changed by the program writing to the text control itself,
|
||||||
|
// so save the old value and restore when we're done
|
||||||
|
bool oldModified = m_modified;
|
||||||
|
|
||||||
if ( m_windowStyle & wxTE_MULTILINE )
|
if ( m_windowStyle & wxTE_MULTILINE )
|
||||||
{
|
{
|
||||||
#ifdef __WXGTK20__
|
#ifdef __WXGTK20__
|
||||||
@@ -612,7 +619,7 @@ void wxTextCtrl::WriteText( const wxString &text )
|
|||||||
// in UpdateFontIfNeeded() any longer
|
// in UpdateFontIfNeeded() any longer
|
||||||
if ( !text.empty() )
|
if ( !text.empty() )
|
||||||
{
|
{
|
||||||
m_updateFont = FALSE;
|
SetUpdateFont(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bring editable's cursor back uptodate.
|
// Bring editable's cursor back uptodate.
|
||||||
@@ -644,7 +651,7 @@ void wxTextCtrl::WriteText( const wxString &text )
|
|||||||
gtk_entry_set_position( GTK_ENTRY(m_text), len );
|
gtk_entry_set_position( GTK_ENTRY(m_text), len );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_modified = TRUE;
|
m_modified = oldModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::AppendText( const wxString &text )
|
void wxTextCtrl::AppendText( const wxString &text )
|
||||||
@@ -1401,7 +1408,7 @@ bool wxTextCtrl::SetFont( const wxFont &font )
|
|||||||
|
|
||||||
if ( m_windowStyle & wxTE_MULTILINE )
|
if ( m_windowStyle & wxTE_MULTILINE )
|
||||||
{
|
{
|
||||||
m_updateFont = TRUE;
|
SetUpdateFont(TRUE);
|
||||||
|
|
||||||
m_defaultStyle.SetFont(font);
|
m_defaultStyle.SetFont(font);
|
||||||
|
|
||||||
@@ -1415,25 +1422,35 @@ void wxTextCtrl::ChangeFontGlobally()
|
|||||||
{
|
{
|
||||||
// this method is very inefficient and hence should be called as rarely as
|
// this method is very inefficient and hence should be called as rarely as
|
||||||
// possible!
|
// possible!
|
||||||
wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE) && m_updateFont,
|
//
|
||||||
|
// TODO: it can be implemented much more efficiently for GTK2
|
||||||
|
wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE)
|
||||||
|
#ifndef __WXGTK20__
|
||||||
|
&& m_updateFont
|
||||||
|
#endif // GTK+ 1.x
|
||||||
|
,
|
||||||
_T("shouldn't be called for single line controls") );
|
_T("shouldn't be called for single line controls") );
|
||||||
|
|
||||||
wxString value = GetValue();
|
wxString value = GetValue();
|
||||||
if ( !value.IsEmpty() )
|
if ( !value.IsEmpty() )
|
||||||
{
|
{
|
||||||
m_updateFont = FALSE;
|
SetUpdateFont(FALSE);
|
||||||
|
|
||||||
Clear();
|
Clear();
|
||||||
AppendText(value);
|
AppendText(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __WXGTK20__
|
||||||
|
|
||||||
void wxTextCtrl::UpdateFontIfNeeded()
|
void wxTextCtrl::UpdateFontIfNeeded()
|
||||||
{
|
{
|
||||||
if ( m_updateFont )
|
if ( m_updateFont )
|
||||||
ChangeFontGlobally();
|
ChangeFontGlobally();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // GTK+ 1.x
|
||||||
|
|
||||||
bool wxTextCtrl::SetForegroundColour(const wxColour& colour)
|
bool wxTextCtrl::SetForegroundColour(const wxColour& colour)
|
||||||
{
|
{
|
||||||
if ( !wxControl::SetForegroundColour(colour) )
|
if ( !wxControl::SetForegroundColour(colour) )
|
||||||
|
Reference in New Issue
Block a user