added wxTextCtrl::ChangeValue() which is the same as SetValue() but doesn't send the text changed event (first part of patch 1553551)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41739 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -218,9 +218,10 @@ functions that take a \helpref{wxCommandEvent}{wxcommandevent} argument.
|
|||||||
\twocolwidtha{7cm}%
|
\twocolwidtha{7cm}%
|
||||||
\begin{twocollist}\itemsep=0pt
|
\begin{twocollist}\itemsep=0pt
|
||||||
\twocolitem{{\bf EVT\_TEXT(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_UPDATED event,
|
\twocolitem{{\bf EVT\_TEXT(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_UPDATED event,
|
||||||
generated when the text changes. Notice that this event will always be sent
|
generated when the text changes. Notice that this event will be sent
|
||||||
when the text controls contents changes - whether this is due to user input or
|
when the text controls contents changes - whether this is due to user input or
|
||||||
comes from the program itself (for example, if SetValue() is called)}
|
comes from the program itself (for example, if SetValue() is called); see ChangeValue() for
|
||||||
|
a function which does not send this event.}
|
||||||
\twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
|
\twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
|
||||||
generated when enter is pressed in a text control (which must have
|
generated when enter is pressed in a text control (which must have
|
||||||
wxTE\_PROCESS\_ENTER style for this event to be generated).}
|
wxTE\_PROCESS\_ENTER style for this event to be generated).}
|
||||||
@@ -973,6 +974,27 @@ after the call to SetValue).
|
|||||||
Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
|
Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
|
||||||
event.
|
event.
|
||||||
|
|
||||||
|
This function is deprecated and should not be used in new code. Please use the
|
||||||
|
\helpref{ChangeValue}{wxtextctrlchangevalue} function instead.
|
||||||
|
|
||||||
|
\wxheading{Parameters}
|
||||||
|
|
||||||
|
\docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
|
||||||
|
|
||||||
|
|
||||||
|
\membersection{wxTextCtrl::ChangeValue}\label{wxtextctrlchangevalue}
|
||||||
|
|
||||||
|
\func{virtual void}{ChangeValue}{\param{const wxString\& }{ value}}
|
||||||
|
|
||||||
|
Sets the text value and marks the control as not-modified (which means that
|
||||||
|
\helpref{IsModified}{wxtextctrlismodified} would return {\tt false} immediately
|
||||||
|
after the call to SetValue).
|
||||||
|
|
||||||
|
Note that this function will \emph{not} generate the {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}
|
||||||
|
event.
|
||||||
|
This is the only difference with \helpref{SetValue}{wxtextctrlsetvalue}.
|
||||||
|
See \helpref{this topic}{progevent} for more info.
|
||||||
|
|
||||||
\wxheading{Parameters}
|
\wxheading{Parameters}
|
||||||
|
|
||||||
\docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
|
\docparam{value}{The new value to set. It may contain newline characters if the text control is multi-line.}
|
||||||
|
@@ -57,6 +57,8 @@ public:
|
|||||||
virtual wxString GetValue() const;
|
virtual wxString GetValue() const;
|
||||||
virtual void SetValue(const wxString& value);
|
virtual void SetValue(const wxString& value);
|
||||||
|
|
||||||
|
virtual void ChangeValue(const wxString &value);
|
||||||
|
|
||||||
virtual int GetLineLength(long lineNo) const;
|
virtual int GetLineLength(long lineNo) const;
|
||||||
virtual wxString GetLineText(long lineNo) const;
|
virtual wxString GetLineText(long lineNo) const;
|
||||||
virtual int GetNumberOfLines() const;
|
virtual int GetNumberOfLines() const;
|
||||||
|
@@ -43,7 +43,9 @@ public:
|
|||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
virtual wxString GetValue() const;
|
virtual wxString GetValue() const;
|
||||||
virtual void SetValue(const wxString& value);
|
virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); }
|
||||||
|
|
||||||
|
virtual void ChangeValue(const wxString &value) { DoSetValue(value); }
|
||||||
|
|
||||||
virtual int GetLineLength(long lineNo) const;
|
virtual int GetLineLength(long lineNo) const;
|
||||||
virtual wxString GetLineText(long lineNo) const;
|
virtual wxString GetLineText(long lineNo) const;
|
||||||
@@ -155,7 +157,7 @@ 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() { m_ignoreNextUpdate = true; }
|
void IgnoreNextTextUpdate(int n = 1) { m_countUpdatesToIgnore = n; }
|
||||||
|
|
||||||
// should we ignore the changed signal? always resets the flag
|
// should we ignore the changed signal? always resets the flag
|
||||||
bool IgnoreTextUpdate();
|
bool IgnoreTextUpdate();
|
||||||
@@ -189,6 +191,8 @@ protected:
|
|||||||
// has the control been frozen by Freeze()?
|
// has the control been frozen by Freeze()?
|
||||||
bool IsFrozen() const { return m_frozenness > 0; }
|
bool IsFrozen() const { return m_frozenness > 0; }
|
||||||
|
|
||||||
|
void DoSetValue(const wxString &value, int flags = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// change the font for everything in this control
|
// change the font for everything in this control
|
||||||
void ChangeFontGlobally();
|
void ChangeFontGlobally();
|
||||||
@@ -203,9 +207,10 @@ private:
|
|||||||
GtkWidget *m_text;
|
GtkWidget *m_text;
|
||||||
|
|
||||||
bool m_modified:1;
|
bool m_modified:1;
|
||||||
bool m_ignoreNextUpdate:1;
|
|
||||||
bool m_dontMarkDirty:1;
|
bool m_dontMarkDirty:1;
|
||||||
|
|
||||||
|
int m_countUpdatesToIgnore;
|
||||||
|
|
||||||
// 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
|
||||||
GtkTextBuffer *m_buffer;
|
GtkTextBuffer *m_buffer;
|
||||||
|
@@ -43,7 +43,9 @@ public:
|
|||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
virtual wxString GetValue() const;
|
virtual wxString GetValue() const;
|
||||||
virtual void SetValue(const wxString& value);
|
virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); }
|
||||||
|
|
||||||
|
virtual void ChangeValue(const wxString &value) { DoSetValue(value); }
|
||||||
|
|
||||||
virtual int GetLineLength(long lineNo) const;
|
virtual int GetLineLength(long lineNo) const;
|
||||||
virtual wxString GetLineText(long lineNo) const;
|
virtual wxString GetLineText(long lineNo) const;
|
||||||
@@ -182,6 +184,8 @@ protected:
|
|||||||
// override this and return true.
|
// override this and return true.
|
||||||
virtual bool UseGTKStyleBase() const { return true; }
|
virtual bool UseGTKStyleBase() const { return true; }
|
||||||
|
|
||||||
|
void DoSetValue(const wxString &value, int flags = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// change the font for everything in this control
|
// change the font for everything in this control
|
||||||
void ChangeFontGlobally();
|
void ChangeFontGlobally();
|
||||||
|
@@ -63,6 +63,8 @@ public:
|
|||||||
virtual wxString GetValue() const;
|
virtual wxString GetValue() const;
|
||||||
virtual void SetValue(const wxString& value);
|
virtual void SetValue(const wxString& value);
|
||||||
|
|
||||||
|
virtual void ChangeValue(const wxString &value);
|
||||||
|
|
||||||
virtual int GetLineLength(long lineNo) const;
|
virtual int GetLineLength(long lineNo) const;
|
||||||
virtual wxString GetLineText(long lineNo) const;
|
virtual wxString GetLineText(long lineNo) const;
|
||||||
virtual int GetNumberOfLines() const;
|
virtual int GetNumberOfLines() const;
|
||||||
|
@@ -43,7 +43,10 @@ public:
|
|||||||
// accessors
|
// accessors
|
||||||
// ---------
|
// ---------
|
||||||
virtual wxString GetValue() const;
|
virtual wxString GetValue() const;
|
||||||
virtual void SetValue(const wxString& value);
|
virtual void SetValue(const wxString& value)
|
||||||
|
{ ChangeValue(value); SendTextUpdatedEvent(); }
|
||||||
|
|
||||||
|
virtual void ChangeValue(const wxString &value);
|
||||||
|
|
||||||
virtual int GetLineLength(long lineNo) const;
|
virtual int GetLineLength(long lineNo) const;
|
||||||
virtual wxString GetLineText(long lineNo) const;
|
virtual wxString GetLineText(long lineNo) const;
|
||||||
|
@@ -45,7 +45,8 @@ public:
|
|||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
virtual wxString GetValue() const;
|
virtual wxString GetValue() const;
|
||||||
virtual void SetValue(const wxString& value);
|
virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); }
|
||||||
|
virtual void ChangeValue(const wxString &value) { DoSetValue(value); }
|
||||||
|
|
||||||
virtual wxString GetRange(long from, long to) const;
|
virtual wxString GetRange(long from, long to) const;
|
||||||
|
|
||||||
@@ -207,6 +208,8 @@ protected:
|
|||||||
// common part of all ctors
|
// common part of all ctors
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
|
void DoSetValue(const wxString &value, int flags = 0);
|
||||||
|
|
||||||
// return true if this control has a user-set limit on amount of text (i.e.
|
// return true if this control has a user-set limit on amount of text (i.e.
|
||||||
// the limit is due to a previous call to SetMaxLength() and not built in)
|
// the limit is due to a previous call to SetMaxLength() and not built in)
|
||||||
bool HasSpaceLimit(unsigned int *len) const;
|
bool HasSpaceLimit(unsigned int *len) const;
|
||||||
@@ -229,7 +232,7 @@ protected:
|
|||||||
|
|
||||||
// replace the contents of the selection or of the entire control with the
|
// replace the contents of the selection or of the entire control with the
|
||||||
// given text
|
// given text
|
||||||
void DoWriteText(const wxString& text, bool selectionOnly = true);
|
void DoWriteText(const wxString& text, int flags = SetValue_SelectionOnly);
|
||||||
|
|
||||||
// set the selection possibly without scrolling the caret into view
|
// set the selection possibly without scrolling the caret into view
|
||||||
void DoSetSelection(long from, long to, bool scrollCaret = true);
|
void DoSetSelection(long from, long to, bool scrollCaret = true);
|
||||||
|
@@ -50,7 +50,9 @@ public:
|
|||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
virtual wxString GetValue() const;
|
virtual wxString GetValue() const;
|
||||||
virtual void SetValue(const wxString& value);
|
virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); }
|
||||||
|
|
||||||
|
virtual void ChangeValue(const wxString &value) { DoSetValue(value); }
|
||||||
|
|
||||||
virtual wxString GetRange(long from, long to) const;
|
virtual wxString GetRange(long from, long to) const;
|
||||||
|
|
||||||
@@ -185,9 +187,11 @@ protected:
|
|||||||
// false if we hit the limit set by SetMaxLength() and so didn't change it
|
// false if we hit the limit set by SetMaxLength() and so didn't change it
|
||||||
bool AdjustSpaceLimit();
|
bool AdjustSpaceLimit();
|
||||||
|
|
||||||
|
void DoSetValue(const wxString &value, int flags = 0);
|
||||||
|
|
||||||
// replace the contents of the selection or of the entire control with the
|
// replace the contents of the selection or of the entire control with the
|
||||||
// given text
|
// given text
|
||||||
void DoWriteText(const wxString& text, bool selectionOnly = true);
|
void DoWriteText(const wxString& text, int flags = SetValue_SelectionOnly);
|
||||||
|
|
||||||
// set the selection possibly without scrolling the caret into view
|
// set the selection possibly without scrolling the caret into view
|
||||||
void DoSetSelection(long from, long to, bool scrollCaret = true);
|
void DoSetSelection(long from, long to, bool scrollCaret = true);
|
||||||
|
@@ -47,7 +47,9 @@ public:
|
|||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
//
|
//
|
||||||
virtual wxString GetValue(void) const;
|
virtual wxString GetValue(void) const;
|
||||||
virtual void SetValue(const wxString& rsValue);
|
virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); }
|
||||||
|
|
||||||
|
virtual void ChangeValue(const wxString &value) { DoSetValue(value); }
|
||||||
|
|
||||||
virtual int GetLineLength(long nLineNo) const;
|
virtual int GetLineLength(long nLineNo) const;
|
||||||
virtual wxString GetLineText(long nLineNo) const;
|
virtual wxString GetLineText(long nLineNo) const;
|
||||||
@@ -180,6 +182,11 @@ protected:
|
|||||||
virtual WXDWORD OS2GetStyle( long lStyle
|
virtual WXDWORD OS2GetStyle( long lStyle
|
||||||
,WXDWORD* dwExstyle
|
,WXDWORD* dwExstyle
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
void DoSetValue(const wxString &value, int flags = 0);
|
||||||
|
|
||||||
|
bool m_bSkipUpdate;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_bIsMLE;
|
bool m_bIsMLE;
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
@@ -47,6 +47,8 @@ public:
|
|||||||
virtual wxString GetValue() const;
|
virtual wxString GetValue() const;
|
||||||
virtual void SetValue(const wxString& value);
|
virtual void SetValue(const wxString& value);
|
||||||
|
|
||||||
|
virtual void ChangeValue(const wxString &value);
|
||||||
|
|
||||||
virtual int GetLineLength(long lineNo) const;
|
virtual int GetLineLength(long lineNo) const;
|
||||||
virtual wxString GetLineText(long lineNo) const;
|
virtual wxString GetLineText(long lineNo) const;
|
||||||
virtual int GetNumberOfLines() const;
|
virtual int GetNumberOfLines() const;
|
||||||
|
@@ -300,6 +300,8 @@ public:
|
|||||||
virtual wxString GetValue() const = 0;
|
virtual wxString GetValue() const = 0;
|
||||||
virtual void SetValue(const wxString& value) = 0;
|
virtual void SetValue(const wxString& value) = 0;
|
||||||
|
|
||||||
|
virtual void ChangeValue(const wxString &value) = 0;
|
||||||
|
|
||||||
virtual wxString GetRange(long from, long to) const;
|
virtual wxString GetRange(long from, long to) const;
|
||||||
|
|
||||||
virtual int GetLineLength(long lineNo) const = 0;
|
virtual int GetLineLength(long lineNo) const = 0;
|
||||||
@@ -429,6 +431,18 @@ protected:
|
|||||||
int overflow(int i);
|
int overflow(int i);
|
||||||
#endif // wxHAS_TEXT_WINDOW_STREAM
|
#endif // wxHAS_TEXT_WINDOW_STREAM
|
||||||
|
|
||||||
|
// typically, wxTextCtrl classes will use a DoSetValue() function to
|
||||||
|
// implement both SetValue() and ChangeValue() functions and these
|
||||||
|
// flags are meant to be passed to such DoSetValue()
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
SetValue_SendEvent = 1,
|
||||||
|
SetValue_SelectionOnly = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
// generate the wxEVT_COMMAND_TEXT_UPDATED event
|
||||||
|
void SendTextUpdatedEvent();
|
||||||
|
|
||||||
// the name of the last file loaded with LoadFile() which will be used by
|
// the name of the last file loaded with LoadFile() which will be used by
|
||||||
// SaveFile() by default
|
// SaveFile() by default
|
||||||
wxString m_filename;
|
wxString m_filename;
|
||||||
|
@@ -107,6 +107,8 @@ public:
|
|||||||
virtual wxString GetValue() const;
|
virtual wxString GetValue() const;
|
||||||
virtual void SetValue(const wxString& value);
|
virtual void SetValue(const wxString& value);
|
||||||
|
|
||||||
|
virtual void ChangeValue(const wxString &value);
|
||||||
|
|
||||||
virtual int GetLineLength(wxTextCoord lineNo) const;
|
virtual int GetLineLength(wxTextCoord lineNo) const;
|
||||||
virtual wxString GetLineText(wxTextCoord lineNo) const;
|
virtual wxString GetLineText(wxTextCoord lineNo) const;
|
||||||
virtual int GetNumberOfLines() const;
|
virtual int GetNumberOfLines() const;
|
||||||
|
@@ -117,7 +117,10 @@ public:
|
|||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
virtual wxString GetValue() const;
|
virtual wxString GetValue() const;
|
||||||
virtual void SetValue(const wxString& value);
|
virtual void SetValue(const wxString& value)
|
||||||
|
{ ChangeValue(value); SendTextUpdatedEvent(); }
|
||||||
|
|
||||||
|
virtual void ChangeValue(const wxString &value);
|
||||||
|
|
||||||
virtual int GetLineLength(long lineNo) const;
|
virtual int GetLineLength(long lineNo) const;
|
||||||
virtual wxString GetLineText(long lineNo) const;
|
virtual wxString GetLineText(long lineNo) const;
|
||||||
|
@@ -947,7 +947,7 @@ void MyTextCtrl::OnKeyDown(wxKeyEvent& event)
|
|||||||
case WXK_F6:
|
case WXK_F6:
|
||||||
wxLogMessage(_T("IsModified() before SetValue(): %d"),
|
wxLogMessage(_T("IsModified() before SetValue(): %d"),
|
||||||
IsModified());
|
IsModified());
|
||||||
SetValue(_T("SetValue() has been called"));
|
ChangeValue(_T("ChangeValue() has been called"));
|
||||||
wxLogMessage(_T("IsModified() after SetValue(): %d"),
|
wxLogMessage(_T("IsModified() after SetValue(): %d"),
|
||||||
IsModified());
|
IsModified());
|
||||||
break;
|
break;
|
||||||
|
@@ -544,9 +544,10 @@ END_EVENT_TABLE()
|
|||||||
void wxTextCtrl::Init()
|
void wxTextCtrl::Init()
|
||||||
{
|
{
|
||||||
m_dontMarkDirty =
|
m_dontMarkDirty =
|
||||||
m_ignoreNextUpdate =
|
|
||||||
m_modified = false;
|
m_modified = false;
|
||||||
|
|
||||||
|
m_countUpdatesToIgnore = 0;
|
||||||
|
|
||||||
SetUpdateFont(false);
|
SetUpdateFont(false);
|
||||||
|
|
||||||
m_text = NULL;
|
m_text = NULL;
|
||||||
@@ -820,7 +821,7 @@ wxFontEncoding wxTextCtrl::GetTextEncoding() const
|
|||||||
return enc;
|
return enc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::SetValue( const wxString &value )
|
void wxTextCtrl::DoSetValue( const wxString &value, int flags )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
|
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
|
||||||
|
|
||||||
@@ -842,8 +843,20 @@ void wxTextCtrl::SetValue( const wxString &value )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if the control is not empty, two "changed" signals are emitted
|
||||||
|
if ( flags & SetValue_SendEvent )
|
||||||
|
{
|
||||||
if ( gtk_text_buffer_get_char_count(m_buffer) != 0 )
|
if ( gtk_text_buffer_get_char_count(m_buffer) != 0 )
|
||||||
IgnoreNextTextUpdate();
|
IgnoreNextTextUpdate();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( gtk_text_buffer_get_char_count(m_buffer) != 0 )
|
||||||
|
IgnoreNextTextUpdate(2);
|
||||||
|
else
|
||||||
|
IgnoreNextTextUpdate(1); // skip only one
|
||||||
|
}
|
||||||
|
|
||||||
gtk_text_buffer_set_text( m_buffer, buffer, strlen(buffer) );
|
gtk_text_buffer_set_text( m_buffer, buffer, strlen(buffer) );
|
||||||
}
|
}
|
||||||
@@ -851,9 +864,19 @@ void wxTextCtrl::SetValue( const wxString &value )
|
|||||||
{
|
{
|
||||||
// gtk_entry_set_text() emits two "changed" signals if the control is
|
// gtk_entry_set_text() emits two "changed" signals if the control is
|
||||||
// not empty because internally it calls gtk_editable_delete_text() and
|
// not empty because internally it calls gtk_editable_delete_text() and
|
||||||
// gtk_editable_insert_text() but we want to have only one event
|
// gtk_editable_insert_text()
|
||||||
|
if ( flags & SetValue_SendEvent )
|
||||||
|
{
|
||||||
if ( !GetValue().empty() )
|
if ( !GetValue().empty() )
|
||||||
IgnoreNextTextUpdate();
|
IgnoreNextTextUpdate();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( !GetValue().empty() )
|
||||||
|
IgnoreNextTextUpdate(2);
|
||||||
|
else
|
||||||
|
IgnoreNextTextUpdate(1); // if we are empty, skip only one event
|
||||||
|
}
|
||||||
|
|
||||||
gtk_entry_set_text( GTK_ENTRY(m_text), wxGTK_CONV(value) );
|
gtk_entry_set_text( GTK_ENTRY(m_text), wxGTK_CONV(value) );
|
||||||
}
|
}
|
||||||
@@ -1178,9 +1201,9 @@ void wxTextCtrl::DiscardEdits()
|
|||||||
|
|
||||||
bool wxTextCtrl::IgnoreTextUpdate()
|
bool wxTextCtrl::IgnoreTextUpdate()
|
||||||
{
|
{
|
||||||
if ( m_ignoreNextUpdate )
|
if ( m_countUpdatesToIgnore > 0 )
|
||||||
{
|
{
|
||||||
m_ignoreNextUpdate = false;
|
m_countUpdatesToIgnore--;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -412,10 +412,16 @@ wxString wxTextCtrl::GetValue() const
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::SetValue( const wxString &value )
|
void wxTextCtrl::DoSetValue( const wxString &value, int flags )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
|
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
|
||||||
|
|
||||||
|
if ( !(flags & SetValue_SendEvent) )
|
||||||
|
{
|
||||||
|
// do not generate events
|
||||||
|
IgnoreNextTextUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
if (m_windowStyle & wxTE_MULTILINE)
|
if (m_windowStyle & wxTE_MULTILINE)
|
||||||
{
|
{
|
||||||
gint len = gtk_text_get_length( GTK_TEXT(m_text) );
|
gint len = gtk_text_get_length( GTK_TEXT(m_text) );
|
||||||
|
@@ -564,6 +564,15 @@ void wxTextCtrl::SetValue(const wxString& str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxTextCtrl::ChangeValue(const wxString& str)
|
||||||
|
{
|
||||||
|
// optimize redraws
|
||||||
|
if ( GetValue() == str )
|
||||||
|
return ;
|
||||||
|
|
||||||
|
GetPeer()->SetStringValue( str ) ;
|
||||||
|
}
|
||||||
|
|
||||||
void wxTextCtrl::SetMaxLength(unsigned long len)
|
void wxTextCtrl::SetMaxLength(unsigned long len)
|
||||||
{
|
{
|
||||||
m_maxLength = len ;
|
m_maxLength = len ;
|
||||||
|
@@ -240,7 +240,7 @@ wxString wxTextCtrl::GetValue() const
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::SetValue(const wxString& text)
|
void wxTextCtrl::ChangeValue(const wxString& text)
|
||||||
{
|
{
|
||||||
m_inSetValue = true;
|
m_inSetValue = true;
|
||||||
|
|
||||||
|
@@ -134,9 +134,13 @@ public:
|
|||||||
UpdatesCountFilter(int& count)
|
UpdatesCountFilter(int& count)
|
||||||
: m_count(count)
|
: m_count(count)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( m_count == -1, _T("wrong initial m_updatesCount value") );
|
wxASSERT_MSG( m_count == -1 || m_count == -2,
|
||||||
|
_T("wrong initial m_updatesCount value") );
|
||||||
|
|
||||||
|
if (m_count != -2)
|
||||||
m_count = 0;
|
m_count = 0;
|
||||||
|
//else: we don't want to count how many update events we get as we're going
|
||||||
|
// to ignore all of them
|
||||||
}
|
}
|
||||||
|
|
||||||
~UpdatesCountFilter()
|
~UpdatesCountFilter()
|
||||||
@@ -781,7 +785,7 @@ wxString wxTextCtrl::GetRange(long from, long to) const
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::SetValue(const wxString& value)
|
void wxTextCtrl::DoSetValue(const wxString& value, int flags)
|
||||||
{
|
{
|
||||||
// if the text is long enough, it's faster to just set it instead of first
|
// if the text is long enough, it's faster to just set it instead of first
|
||||||
// comparing it with the old one (chances are that it will be different
|
// comparing it with the old one (chances are that it will be different
|
||||||
@@ -789,7 +793,7 @@ void wxTextCtrl::SetValue(const wxString& value)
|
|||||||
// edit controls mostly)
|
// edit controls mostly)
|
||||||
if ( (value.length() > 0x400) || (value != GetValue()) )
|
if ( (value.length() > 0x400) || (value != GetValue()) )
|
||||||
{
|
{
|
||||||
DoWriteText(value, false /* not selection only */);
|
DoWriteText(value, flags);
|
||||||
|
|
||||||
// mark the control as being not dirty - we changed its text, not the
|
// mark the control as being not dirty - we changed its text, not the
|
||||||
// user
|
// user
|
||||||
@@ -807,6 +811,7 @@ void wxTextCtrl::SetValue(const wxString& value)
|
|||||||
DiscardEdits();
|
DiscardEdits();
|
||||||
|
|
||||||
// still send an event for consistency
|
// still send an event for consistency
|
||||||
|
if (flags & SetValue_SendEvent)
|
||||||
SendUpdateEvent();
|
SendUpdateEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1005,8 +1010,9 @@ void wxTextCtrl::WriteText(const wxString& value)
|
|||||||
DoWriteText(value);
|
DoWriteText(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::DoWriteText(const wxString& value, bool selectionOnly)
|
void wxTextCtrl::DoWriteText(const wxString& value, int flags)
|
||||||
{
|
{
|
||||||
|
bool selectionOnly = (flags & SetValue_SelectionOnly) != 0;
|
||||||
wxString valueDos;
|
wxString valueDos;
|
||||||
if ( m_windowStyle & wxTE_MULTILINE )
|
if ( m_windowStyle & wxTE_MULTILINE )
|
||||||
valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
|
valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
|
||||||
@@ -1070,13 +1076,16 @@ void wxTextCtrl::DoWriteText(const wxString& value, bool selectionOnly)
|
|||||||
// we generate exactly one of them by ignoring all but the first one in
|
// we generate exactly one of them by ignoring all but the first one in
|
||||||
// SendUpdateEvent() and generating one ourselves if we hadn't got any
|
// SendUpdateEvent() and generating one ourselves if we hadn't got any
|
||||||
// notifications from Windows
|
// notifications from Windows
|
||||||
|
if ( !(flags & SetValue_SendEvent) )
|
||||||
|
m_updatesCount = -2; // suppress any update event
|
||||||
|
|
||||||
UpdatesCountFilter ucf(m_updatesCount);
|
UpdatesCountFilter ucf(m_updatesCount);
|
||||||
|
|
||||||
::SendMessage(GetHwnd(), selectionOnly ? EM_REPLACESEL : WM_SETTEXT,
|
::SendMessage(GetHwnd(), selectionOnly ? EM_REPLACESEL : WM_SETTEXT,
|
||||||
// EM_REPLACESEL takes 1 to indicate the operation should be redoable
|
// EM_REPLACESEL takes 1 to indicate the operation should be redoable
|
||||||
selectionOnly ? 1 : 0, (LPARAM)valueDos.c_str());
|
selectionOnly ? 1 : 0, (LPARAM)valueDos.c_str());
|
||||||
|
|
||||||
if ( !ucf.GotUpdate() )
|
if ( !ucf.GotUpdate() && (flags & SetValue_SendEvent) )
|
||||||
{
|
{
|
||||||
SendUpdateEvent();
|
SendUpdateEvent();
|
||||||
}
|
}
|
||||||
@@ -1427,7 +1436,7 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
|
|||||||
// Set selection and remove it
|
// Set selection and remove it
|
||||||
DoSetSelection(from, to, false /* don't scroll caret into view */);
|
DoSetSelection(from, to, false /* don't scroll caret into view */);
|
||||||
|
|
||||||
DoWriteText(value, true /* selection only */);
|
DoWriteText(value, SetValue_SelectionOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::Remove(long from, long to)
|
void wxTextCtrl::Remove(long from, long to)
|
||||||
@@ -1971,6 +1980,11 @@ bool wxTextCtrl::SendUpdateEvent()
|
|||||||
// we hadn't updated the control ourselves, this event comes from
|
// we hadn't updated the control ourselves, this event comes from
|
||||||
// the user, don't need to ignore it nor update the count
|
// the user, don't need to ignore it nor update the count
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case -2:
|
||||||
|
// the control was updated programmatically and we do NOT want to
|
||||||
|
// send events
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
|
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
|
||||||
|
@@ -393,7 +393,7 @@ wxString wxTextCtrl::GetRange(long from, long to) const
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::SetValue(const wxString& value)
|
void wxTextCtrl::DoSetValue(const wxString& value, int flags)
|
||||||
{
|
{
|
||||||
// if the text is long enough, it's faster to just set it instead of first
|
// if the text is long enough, it's faster to just set it instead of first
|
||||||
// comparing it with the old one (chances are that it will be different
|
// comparing it with the old one (chances are that it will be different
|
||||||
@@ -401,7 +401,7 @@ void wxTextCtrl::SetValue(const wxString& value)
|
|||||||
// edit controls mostly)
|
// edit controls mostly)
|
||||||
if ( (value.length() > 0x400) || (value != GetValue()) )
|
if ( (value.length() > 0x400) || (value != GetValue()) )
|
||||||
{
|
{
|
||||||
DoWriteText(value, false);
|
DoWriteText(value, flags);
|
||||||
|
|
||||||
// for compatibility, don't move the cursor when doing SetValue()
|
// for compatibility, don't move the cursor when doing SetValue()
|
||||||
SetInsertionPoint(0);
|
SetInsertionPoint(0);
|
||||||
@@ -409,6 +409,7 @@ void wxTextCtrl::SetValue(const wxString& value)
|
|||||||
else // same text
|
else // same text
|
||||||
{
|
{
|
||||||
// still send an event for consistency
|
// still send an event for consistency
|
||||||
|
if ( flags & SetValue_SendEvent )
|
||||||
SendUpdateEvent();
|
SendUpdateEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,8 +425,9 @@ void wxTextCtrl::WriteText(const wxString& value)
|
|||||||
DoWriteText(value);
|
DoWriteText(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::DoWriteText(const wxString& value, bool selectionOnly)
|
void wxTextCtrl::DoWriteText(const wxString& value, int flags)
|
||||||
{
|
{
|
||||||
|
bool selectionOnly = (flags & SetValue_SelectionOnly) != 0;
|
||||||
wxString valueDos;
|
wxString valueDos;
|
||||||
if ( m_windowStyle & wxTE_MULTILINE )
|
if ( m_windowStyle & wxTE_MULTILINE )
|
||||||
valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
|
valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
|
||||||
@@ -436,7 +438,7 @@ void wxTextCtrl::DoWriteText(const wxString& value, bool selectionOnly)
|
|||||||
// call below which is confusing for the client code and so should be
|
// call below which is confusing for the client code and so should be
|
||||||
// avoided
|
// avoided
|
||||||
//
|
//
|
||||||
if ( ( selectionOnly && HasSelection() ) )
|
if ( selectionOnly && HasSelection() )
|
||||||
{
|
{
|
||||||
m_suppressNextUpdate = true;
|
m_suppressNextUpdate = true;
|
||||||
}
|
}
|
||||||
@@ -444,7 +446,7 @@ void wxTextCtrl::DoWriteText(const wxString& value, bool selectionOnly)
|
|||||||
::SendMessage(GetBuddyHwnd(), selectionOnly ? EM_REPLACESEL : WM_SETTEXT,
|
::SendMessage(GetBuddyHwnd(), selectionOnly ? EM_REPLACESEL : WM_SETTEXT,
|
||||||
0, (LPARAM)valueDos.c_str());
|
0, (LPARAM)valueDos.c_str());
|
||||||
|
|
||||||
if ( !selectionOnly )
|
if ( !selectionOnly && !( flags & SetValue_SendEvent ) )
|
||||||
{
|
{
|
||||||
// Windows already sends an update event for single-line
|
// Windows already sends an update event for single-line
|
||||||
// controls.
|
// controls.
|
||||||
@@ -641,7 +643,7 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
|
|||||||
// Set selection and remove it
|
// Set selection and remove it
|
||||||
DoSetSelection(from, to, false);
|
DoSetSelection(from, to, false);
|
||||||
|
|
||||||
DoWriteText(value, true);
|
DoWriteText(value, SetValue_SelectionOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::Remove(long from, long to)
|
void wxTextCtrl::Remove(long from, long to)
|
||||||
|
@@ -125,6 +125,7 @@ bool wxTextCtrl::Create(
|
|||||||
|
|
||||||
m_windowStyle = lStyle;
|
m_windowStyle = lStyle;
|
||||||
m_bIsMLE = false;
|
m_bIsMLE = false;
|
||||||
|
m_bSkipUpdate = false;
|
||||||
|
|
||||||
long lSstyle = WS_VISIBLE | WS_TABSTOP;
|
long lSstyle = WS_VISIBLE | WS_TABSTOP;
|
||||||
|
|
||||||
@@ -343,8 +344,9 @@ wxString wxTextCtrl::GetValue() const
|
|||||||
return sStr;
|
return sStr;
|
||||||
} // end of wxTextCtrl::GetValue
|
} // end of wxTextCtrl::GetValue
|
||||||
|
|
||||||
void wxTextCtrl::SetValue(
|
void wxTextCtrl::DoSetValue(
|
||||||
const wxString& rsValue
|
const wxString& rsValue,
|
||||||
|
int flags
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -355,6 +357,9 @@ void wxTextCtrl::SetValue(
|
|||||||
//
|
//
|
||||||
if ((rsValue.length() > 0x400) || (rsValue != GetValue()))
|
if ((rsValue.length() > 0x400) || (rsValue != GetValue()))
|
||||||
{
|
{
|
||||||
|
if ( flags & SetValue_SendEvent )
|
||||||
|
m_bSkipUpdate = true;
|
||||||
|
|
||||||
::WinSetWindowText(GetHwnd(), (PSZ)rsValue.c_str());
|
::WinSetWindowText(GetHwnd(), (PSZ)rsValue.c_str());
|
||||||
AdjustSpaceLimit();
|
AdjustSpaceLimit();
|
||||||
}
|
}
|
||||||
@@ -1095,6 +1100,12 @@ bool wxTextCtrl::OS2Command(
|
|||||||
|
|
||||||
case EN_CHANGE:
|
case EN_CHANGE:
|
||||||
{
|
{
|
||||||
|
if (m_bSkipUpdate)
|
||||||
|
{
|
||||||
|
m_bSkipUpdate = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
wxCommandEvent vEvent( wxEVT_COMMAND_TEXT_UPDATED
|
wxCommandEvent vEvent( wxEVT_COMMAND_TEXT_UPDATED
|
||||||
,m_windowId
|
,m_windowId
|
||||||
);
|
);
|
||||||
|
@@ -233,6 +233,10 @@ void wxTextCtrl::SetValue(const wxString& value)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxTextCtrl::ChangeValue(const wxString& value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
#if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
|
#if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
|
||||||
|
|
||||||
// TODO: using memcpy() would improve performance a lot for big amounts of text
|
// TODO: using memcpy() would improve performance a lot for big amounts of text
|
||||||
|
@@ -778,7 +778,7 @@ wxTextCtrl::~wxTextCtrl()
|
|||||||
// set/get the value
|
// set/get the value
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxTextCtrl::SetValue(const wxString& value)
|
void wxTextCtrl::ChangeValue(const wxString& value)
|
||||||
{
|
{
|
||||||
if ( IsSingleLine() && (value == GetValue()) )
|
if ( IsSingleLine() && (value == GetValue()) )
|
||||||
{
|
{
|
||||||
@@ -792,8 +792,12 @@ void wxTextCtrl::SetValue(const wxString& value)
|
|||||||
{
|
{
|
||||||
SetInsertionPoint(0);
|
SetInsertionPoint(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: should we generate the event or not, finally?
|
void wxTextCtrl::SetValue(const wxString& value)
|
||||||
|
{
|
||||||
|
ChangeValue(value);
|
||||||
|
SendTextUpdatedEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
const wxArrayString& wxTextCtrl::GetLines() const
|
const wxArrayString& wxTextCtrl::GetLines() const
|
||||||
|
@@ -277,7 +277,7 @@ wxString wxTextCtrl::GetValue() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::SetValue(const wxString& value)
|
void wxTextCtrl::ChangeValue(const wxString& value)
|
||||||
{
|
{
|
||||||
m_modified = false;
|
m_modified = false;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user