From c04ec4965704643f498999fb5123e63330a3ee50 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 23 Jul 2004 19:59:00 +0000 Subject: [PATCH] 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 --- include/wx/gtk/textctrl.h | 12 ++++++++++++ include/wx/gtk1/textctrl.h | 12 ++++++++++++ src/gtk/textctrl.cpp | 29 +++++++++++++++++++++++------ src/gtk1/textctrl.cpp | 29 +++++++++++++++++++++++------ 4 files changed, 70 insertions(+), 12 deletions(-) diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 3832c956dc..e27cb9f9a4 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -88,6 +88,10 @@ public: virtual void ShowPosition(long pos); +#ifdef __WXGTK20__ + virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const; +#endif // __WXGTK20__ + // Clipboard operations virtual void Copy(); virtual void Cut(); @@ -136,7 +140,13 @@ public: void DoApplyWidgetStyle(GtkRcStyle *style); void CalculateScrollbar(); void OnInternalIdle(); + +#ifdef __WXGTK20__ + void SetUpdateFont(bool WXUNUSED(update)) { } +#else // !__WXGTK20__ + void SetUpdateFont(bool update) { m_updateFont = update; } void UpdateFontIfNeeded(); +#endif // __WXGTK20__/!__WXGTK20__ void SetModified() { m_modified = TRUE; } @@ -191,7 +201,9 @@ private: bool m_modified:1; bool m_vScrollbarVisible:1; +#ifndef __WXGTK20__ bool m_updateFont:1; +#endif // !__WXGTK20__ bool m_ignoreNextUpdate:1; DECLARE_EVENT_TABLE() diff --git a/include/wx/gtk1/textctrl.h b/include/wx/gtk1/textctrl.h index 3832c956dc..e27cb9f9a4 100644 --- a/include/wx/gtk1/textctrl.h +++ b/include/wx/gtk1/textctrl.h @@ -88,6 +88,10 @@ public: virtual void ShowPosition(long pos); +#ifdef __WXGTK20__ + virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const; +#endif // __WXGTK20__ + // Clipboard operations virtual void Copy(); virtual void Cut(); @@ -136,7 +140,13 @@ public: void DoApplyWidgetStyle(GtkRcStyle *style); void CalculateScrollbar(); void OnInternalIdle(); + +#ifdef __WXGTK20__ + void SetUpdateFont(bool WXUNUSED(update)) { } +#else // !__WXGTK20__ + void SetUpdateFont(bool update) { m_updateFont = update; } void UpdateFontIfNeeded(); +#endif // __WXGTK20__/!__WXGTK20__ void SetModified() { m_modified = TRUE; } @@ -191,7 +201,9 @@ private: bool m_modified:1; bool m_vScrollbarVisible:1; +#ifndef __WXGTK20__ bool m_updateFont:1; +#endif // !__WXGTK20__ bool m_ignoreNextUpdate:1; DECLARE_EVENT_TABLE() diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 9def3e02e4..4f48c8f5cd 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -155,7 +155,9 @@ gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win ) wxapp_install_idle_handler(); win->SetModified(); +#ifndef __WXGTK20__ win->UpdateFontIfNeeded(); +#endif // !__WXGTK20__ wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() ); event.SetEventObject( win ); @@ -239,7 +241,7 @@ void wxTextCtrl::Init() { m_ignoreNextUpdate = m_modified = FALSE; - m_updateFont = FALSE; + SetUpdateFont(FALSE); m_text = m_vScrollbar = (GtkWidget *)NULL; } @@ -577,6 +579,11 @@ void wxTextCtrl::WriteText( const wxString &text ) if ( text.empty() ) 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 ) { #ifdef __WXGTK20__ @@ -612,7 +619,7 @@ void wxTextCtrl::WriteText( const wxString &text ) // in UpdateFontIfNeeded() any longer if ( !text.empty() ) { - m_updateFont = FALSE; + SetUpdateFont(FALSE); } // 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 ); } - m_modified = TRUE; + m_modified = oldModified; } void wxTextCtrl::AppendText( const wxString &text ) @@ -1401,7 +1408,7 @@ bool wxTextCtrl::SetFont( const wxFont &font ) if ( m_windowStyle & wxTE_MULTILINE ) { - m_updateFont = TRUE; + SetUpdateFont(TRUE); m_defaultStyle.SetFont(font); @@ -1415,25 +1422,35 @@ 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, + // + // 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") ); wxString value = GetValue(); if ( !value.IsEmpty() ) { - m_updateFont = FALSE; + SetUpdateFont(FALSE); Clear(); AppendText(value); } } +#ifndef __WXGTK20__ + void wxTextCtrl::UpdateFontIfNeeded() { if ( m_updateFont ) ChangeFontGlobally(); } +#endif // GTK+ 1.x + bool wxTextCtrl::SetForegroundColour(const wxColour& colour) { if ( !wxControl::SetForegroundColour(colour) ) diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 9def3e02e4..4f48c8f5cd 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -155,7 +155,9 @@ gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win ) wxapp_install_idle_handler(); win->SetModified(); +#ifndef __WXGTK20__ win->UpdateFontIfNeeded(); +#endif // !__WXGTK20__ wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() ); event.SetEventObject( win ); @@ -239,7 +241,7 @@ void wxTextCtrl::Init() { m_ignoreNextUpdate = m_modified = FALSE; - m_updateFont = FALSE; + SetUpdateFont(FALSE); m_text = m_vScrollbar = (GtkWidget *)NULL; } @@ -577,6 +579,11 @@ void wxTextCtrl::WriteText( const wxString &text ) if ( text.empty() ) 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 ) { #ifdef __WXGTK20__ @@ -612,7 +619,7 @@ void wxTextCtrl::WriteText( const wxString &text ) // in UpdateFontIfNeeded() any longer if ( !text.empty() ) { - m_updateFont = FALSE; + SetUpdateFont(FALSE); } // 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 ); } - m_modified = TRUE; + m_modified = oldModified; } void wxTextCtrl::AppendText( const wxString &text ) @@ -1401,7 +1408,7 @@ bool wxTextCtrl::SetFont( const wxFont &font ) if ( m_windowStyle & wxTE_MULTILINE ) { - m_updateFont = TRUE; + SetUpdateFont(TRUE); m_defaultStyle.SetFont(font); @@ -1415,25 +1422,35 @@ 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, + // + // 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") ); wxString value = GetValue(); if ( !value.IsEmpty() ) { - m_updateFont = FALSE; + SetUpdateFont(FALSE); Clear(); AppendText(value); } } +#ifndef __WXGTK20__ + void wxTextCtrl::UpdateFontIfNeeded() { if ( m_updateFont ) ChangeFontGlobally(); } +#endif // GTK+ 1.x + bool wxTextCtrl::SetForegroundColour(const wxColour& colour) { if ( !wxControl::SetForegroundColour(colour) ) -- 2.45.2