make sure that IsModified() returns false when it's called from EVT_TEXT handler invoked because of SetValue() call

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39172 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-05-17 00:20:20 +00:00
parent 781acf8347
commit 6964cbbac9
2 changed files with 36 additions and 15 deletions

View File

@@ -157,11 +157,19 @@ public:
virtual void OnParentEnable( bool enable ) ; virtual void OnParentEnable( bool enable ) ;
// tell the control to ignore next text changed signal // tell the control to ignore next text changed signal
void IgnoreNextTextUpdate(); void IgnoreNextTextUpdate() { m_ignoreNextUpdate = true; }
// should we ignore the changed signal? always resets the flag // should we ignore the changed signal? always resets the flag
bool IgnoreTextUpdate(); bool IgnoreTextUpdate();
// call this to indicate that the control is about to be changed
// programmatically and so m_modified flag shouldn't be set
void DontMarkDirtyOnNextChange() { m_dontMarkDirty = true; }
// should we mark the control as dirty? always resets the flag
bool MarkDirtyOnChange();
static wxVisualAttributes static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
@@ -187,6 +195,7 @@ private:
bool m_modified:1; bool m_modified:1;
bool m_ignoreNextUpdate:1; bool m_ignoreNextUpdate:1;
bool m_dontMarkDirty:1;
// Our text buffer. Convenient, and holds the buffer while using // Our text buffer. Convenient, and holds the buffer while using
// a dummy one when m_frozenness > 0 // a dummy one when m_frozenness > 0

View File

@@ -454,6 +454,7 @@ gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win )
if (g_isIdle) if (g_isIdle)
wxapp_install_idle_handler(); wxapp_install_idle_handler();
if ( win->MarkDirtyOnChange() )
win->MarkDirty(); win->MarkDirty();
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() ); wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
@@ -551,9 +552,12 @@ END_EVENT_TABLE()
void wxTextCtrl::Init() void wxTextCtrl::Init()
{ {
m_dontMarkDirty =
m_ignoreNextUpdate = m_ignoreNextUpdate =
m_modified = false; m_modified = false;
SetUpdateFont(false); SetUpdateFont(false);
m_text = NULL; m_text = NULL;
m_frozenness = 0; m_frozenness = 0;
m_gdkHandCursor = NULL; m_gdkHandCursor = NULL;
@@ -812,6 +816,13 @@ void wxTextCtrl::SetValue( const wxString &value )
{ {
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
// the control won't be modified any more as we programmatically replace
// all the existing text, so reset the flag and don't set it again (and do
// it now, before the text event handler is ran so that IsModified() called
// from there returns the expected value)
m_modified = false;
DontMarkDirtyOnNextChange();
if (m_windowStyle & wxTE_MULTILINE) if (m_windowStyle & wxTE_MULTILINE)
{ {
const wxCharBuffer buffer(wxGTK_CONV(value)); const wxCharBuffer buffer(wxGTK_CONV(value));
@@ -840,8 +851,6 @@ void wxTextCtrl::SetValue( const wxString &value )
// the lists. wxWidgets 2.2 will have a set of flags to // the lists. wxWidgets 2.2 will have a set of flags to
// customize this behaviour. // customize this behaviour.
SetInsertionPoint(0); SetInsertionPoint(0);
m_modified = false;
} }
void wxTextCtrl::WriteText( const wxString &text ) void wxTextCtrl::WriteText( const wxString &text )
@@ -858,10 +867,8 @@ void wxTextCtrl::WriteText( const wxString &text )
return; return;
} }
// gtk_text_changed_callback() will set m_modified to true but m_modified // we're changing the text programmatically
// shouldn't be changed by the program writing to the text control itself, DontMarkDirtyOnNextChange();
// 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 )
{ {
@@ -896,8 +903,6 @@ void wxTextCtrl::WriteText( const wxString &text )
// Bring entry's cursor uptodate. // Bring entry's cursor uptodate.
gtk_editable_set_position( GTK_EDITABLE(m_text), len ); gtk_editable_set_position( GTK_EDITABLE(m_text), len );
} }
m_modified = oldModified;
} }
void wxTextCtrl::AppendText( const wxString &text ) void wxTextCtrl::AppendText( const wxString &text )
@@ -1139,11 +1144,6 @@ void wxTextCtrl::DiscardEdits()
// max text length support // max text length support
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxTextCtrl::IgnoreNextTextUpdate()
{
m_ignoreNextUpdate = true;
}
bool wxTextCtrl::IgnoreTextUpdate() bool wxTextCtrl::IgnoreTextUpdate()
{ {
if ( m_ignoreNextUpdate ) if ( m_ignoreNextUpdate )
@@ -1156,6 +1156,18 @@ bool wxTextCtrl::IgnoreTextUpdate()
return false; return false;
} }
bool wxTextCtrl::MarkDirtyOnChange()
{
if ( m_dontMarkDirty )
{
m_dontMarkDirty = false;
return false;
}
return true;
}
void wxTextCtrl::SetMaxLength(unsigned long len) void wxTextCtrl::SetMaxLength(unsigned long len)
{ {
if ( !HasFlag(wxTE_MULTILINE) ) if ( !HasFlag(wxTE_MULTILINE) )