From 5a3ef19432acb30174a8b7eb5c8c56e568fb8a3a Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Sat, 9 Dec 2006 06:21:15 +0000 Subject: [PATCH] fix for SetPosition/SetInsertionPoint when called during Freeze git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43870 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/textctrl.h | 16 +++++++------ src/gtk/textctrl.cpp | 50 ++++++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 1cb6cf64bd..510cdbd91e 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -8,8 +8,10 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef __GTKTEXTCTRLH__ -#define __GTKTEXTCTRLH__ +#ifndef _WX_GTK_TEXTCTRL_H_ +#define _WX_GTK_TEXTCTRL_H_ + +typedef struct _GtkTextMark GtkTextMark; //----------------------------------------------------------------------------- // wxTextCtrl @@ -176,7 +178,7 @@ public: GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); // has the control been frozen by Freeze()? - bool IsFrozen() const { return m_frozenness > 0; } + bool IsFrozen() const { return m_freezeCount > 0; } protected: virtual wxSize DoGetBestSize() const; @@ -219,11 +221,12 @@ private: int m_countUpdatesToIgnore; // Our text buffer. Convenient, and holds the buffer while using - // a dummy one when m_frozenness > 0 + // a dummy one when frozen GtkTextBuffer *m_buffer; // number of calls to Freeze() minus number of calls to Thaw() - unsigned int m_frozenness; + unsigned m_freezeCount; + GtkTextMark* m_showPositionOnThaw; // For wxTE_AUTO_URL void OnUrlMouseEvent(wxMouseEvent&); @@ -234,5 +237,4 @@ private: DECLARE_DYNAMIC_CLASS(wxTextCtrl) }; -#endif // __GTKTEXTCTRLH__ - +#endif // _WX_GTK_TEXTCTRL_H_ diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 40c89ee562..05256cb4f8 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -647,7 +647,8 @@ void wxTextCtrl::Init() SetUpdateFont(false); m_text = NULL; - m_frozenness = 0; + m_freezeCount = 0; + m_showPositionOnThaw = NULL; m_gdkHandCursor = NULL; m_gdkXTermCursor = NULL; } @@ -702,6 +703,11 @@ bool wxTextCtrl::Create( wxWindow *parent, m_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) ); + // create "ShowPosition" marker + GtkTextIter iter; + gtk_text_buffer_get_start_iter(m_buffer, &iter); + gtk_text_buffer_create_mark(m_buffer, "ShowPosition", &iter, true); + // create scrolled window m_widget = gtk_scrolled_window_new( NULL, NULL ); gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( m_widget ), @@ -1225,15 +1231,12 @@ void wxTextCtrl::SetInsertionPoint( long pos ) GtkTextIter iter; gtk_text_buffer_get_iter_at_offset( m_buffer, &iter, pos ); gtk_text_buffer_place_cursor( m_buffer, &iter ); - if (!IsFrozen()) - { - // won't work when frozen, text view is not using m_buffer then - gtk_text_view_scroll_mark_onscreen - ( - GTK_TEXT_VIEW(m_text), - gtk_text_buffer_get_insert( m_buffer ) - ); - } + GtkTextMark* mark = gtk_text_buffer_get_insert(m_buffer); + if (IsFrozen()) + // defer until Thaw, text view is not using m_buffer now + m_showPositionOnThaw = mark; + else + gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(m_text), mark); } else { @@ -1405,14 +1408,17 @@ void wxTextCtrl::SetSelection( long from, long to ) void wxTextCtrl::ShowPosition( long pos ) { - // won't work when frozen, text view is not using m_buffer then - if (IsMultiLine() && !IsFrozen()) + if (IsMultiLine()) { GtkTextIter iter; - gtk_text_buffer_get_start_iter( m_buffer, &iter ); - gtk_text_iter_set_offset( &iter, pos ); - GtkTextMark *mark = gtk_text_buffer_create_mark( m_buffer, NULL, &iter, TRUE ); - gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text), mark, 0.0, FALSE, 0.0, 0.0 ); + gtk_text_buffer_get_iter_at_offset(m_buffer, &iter, int(pos)); + GtkTextMark* mark = gtk_text_buffer_get_mark(m_buffer, "ShowPosition"); + gtk_text_buffer_move_mark(m_buffer, mark, &iter); + if (IsFrozen()) + // defer until Thaw, text view is not using m_buffer now + m_showPositionOnThaw = mark; + else + gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(m_text), mark); } } @@ -1879,7 +1885,7 @@ void wxTextCtrl::Freeze() if ( HasFlag(wxTE_MULTILINE) ) { - if (m_frozenness++ == 0) + if (m_freezeCount++ == 0) { // freeze textview updates and remove buffer g_signal_connect (m_text, "expose_event", @@ -1907,9 +1913,9 @@ void wxTextCtrl::Thaw() { if ( HasFlag(wxTE_MULTILINE) ) { - wxCHECK_RET(m_frozenness != 0, _T("Thaw() without matching Freeze()")); + wxCHECK_RET(m_freezeCount != 0, _T("Thaw() without matching Freeze()")); - if (--m_frozenness == 0) + if (--m_freezeCount == 0) { // Reattach buffer and thaw textview updates gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), m_buffer); @@ -1919,6 +1925,12 @@ void wxTextCtrl::Thaw() (gpointer) gtk_text_exposed_callback, this); g_signal_handlers_disconnect_by_func (m_text, (gpointer) gtk_text_exposed_callback, this); + if (m_showPositionOnThaw != NULL) + { + gtk_text_view_scroll_mark_onscreen( + GTK_TEXT_VIEW(m_text), m_showPositionOnThaw); + m_showPositionOnThaw = NULL; + } } } } -- 2.45.2