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
This commit is contained in:
Paul Cornett 2006-12-09 06:21:15 +00:00
parent 6d3e4e02c7
commit 5a3ef19432
2 changed files with 40 additions and 26 deletions

View File

@ -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_

View File

@ -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;
}
}
}
}