moved DoSetValue() to wxTextCtrlBase instead of having it in almost, but not quite all, derived classes; linking fixes for wxCocoa/wxX11/wxMotif

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41754 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2006-10-08 22:40:14 +00:00
parent 5dcf8dd06c
commit ee2ec18e88
19 changed files with 80 additions and 142 deletions

View File

@ -55,9 +55,6 @@ protected:
// ------------------------------------------------------------------------
public:
virtual wxString GetValue() const;
virtual void SetValue(const wxString& value);
virtual void ChangeValue(const wxString &value);
virtual int GetLineLength(long lineNo) const;
virtual wxString GetLineText(long lineNo) const;
@ -118,6 +115,8 @@ public:
protected:
virtual wxSize DoGetBestSize() const;
virtual void DoSetValue(const wxString& value, int flags = 0);
};
#endif // __WX_COCOA_TEXTCTRL_H__

View File

@ -44,8 +44,6 @@ public:
virtual wxString GetValue() const;
virtual bool IsEmpty() const;
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 wxString GetLineText(long lineNo) const;
@ -191,7 +189,7 @@ protected:
// has the control been frozen by Freeze()?
bool IsFrozen() const { return m_frozenness > 0; }
void DoSetValue(const wxString &value, int flags = 0);
virtual void DoSetValue(const wxString &value, int flags = 0);
private:
// change the font for everything in this control

View File

@ -43,9 +43,6 @@ public:
// ----------------------------------
virtual wxString GetValue() const;
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 wxString GetLineText(long lineNo) const;
@ -184,7 +181,7 @@ protected:
// override this and return true.
virtual bool UseGTKStyleBase() const { return true; }
void DoSetValue(const wxString &value, int flags = 0);
virtual void DoSetValue(const wxString &value, int flags = 0);
private:
// change the font for everything in this control

View File

@ -61,9 +61,6 @@ public:
// accessors
// ---------
virtual wxString GetValue() const;
virtual void SetValue(const wxString& value);
virtual void ChangeValue(const wxString &value);
virtual int GetLineLength(long lineNo) const;
virtual wxString GetLineText(long lineNo) const;
@ -187,13 +184,15 @@ public:
wxMacTextControl * GetPeer() const
{ return (wxMacTextControl*) m_peer; }
protected:
// common part of all ctors
void Init();
virtual wxSize DoGetBestSize() const;
virtual void DoSetValue(const wxString& value, int flags = 0);
bool m_editable;
// flag is set to true when the user edits the controls contents
@ -201,17 +200,17 @@ protected:
// need to make this public because of the current implementation via callbacks
unsigned long m_maxLength;
bool GetTriggerOnSetValue() const
{
return m_triggerOnSetValue;
bool GetTriggerOnSetValue() const
{
return m_triggerOnSetValue;
}
void SetTriggerOnSetValue(bool trigger)
{
m_triggerOnSetValue = trigger;
void SetTriggerOnSetValue(bool trigger)
{
m_triggerOnSetValue = trigger;
}
bool m_triggerOnSetValue ;
private :

View File

@ -43,10 +43,6 @@ public:
// accessors
// ---------
virtual wxString GetValue() const;
virtual void SetValue(const wxString& value)
{ ChangeValue(value); SendTextUpdatedEvent(); }
virtual void ChangeValue(const wxString &value);
virtual int GetLineLength(long lineNo) const;
virtual wxString GetLineText(long lineNo) const;
@ -130,6 +126,9 @@ protected:
wxString m_fileName;
virtual wxSize DoGetBestSize() const;
virtual void DoSetValue(const wxString& value, int flags = 0);
public:
// Motif-specific
void* m_tempCallbackStruct;

View File

@ -46,8 +46,6 @@ public:
virtual wxString GetValue() const;
virtual bool IsEmpty() const;
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;
@ -209,7 +207,7 @@ protected:
// common part of all ctors
void Init();
void DoSetValue(const wxString &value, int flags = 0);
virtual void DoSetValue(const wxString &value, int flags = 0);
// 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)

View File

@ -47,9 +47,6 @@ public:
// ----------------------------------
//
virtual wxString GetValue(void) const;
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 wxString GetLineText(long nLineNo) const;
@ -183,7 +180,7 @@ protected:
,WXDWORD* dwExstyle
) const;
void DoSetValue(const wxString &value, int flags = 0);
virtual void DoSetValue(const wxString &value, int flags = 0);
bool m_bSkipUpdate;

View File

@ -45,9 +45,6 @@ public:
// ----------------------------------
virtual wxString GetValue() const;
virtual void SetValue(const wxString& value);
virtual void ChangeValue(const wxString &value);
virtual int GetLineLength(long lineNo) const;
virtual wxString GetLineText(long lineNo) const;
@ -181,6 +178,9 @@ protected:
// common part of all ctors
void Init();
virtual void DoSetValue(const wxString& value, int flags = 0);
// intercept WM_GETDLGCODE
virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);

View File

@ -298,11 +298,12 @@ public:
// ---------
virtual wxString GetValue() const = 0;
virtual void SetValue(const wxString& value) = 0;
virtual bool IsEmpty() const { return GetValue().empty(); }
virtual void ChangeValue(const wxString &value) = 0;
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;
@ -422,6 +423,9 @@ public:
wxTextCtrl& operator<<(double d);
wxTextCtrl& operator<<(const wxChar c);
// generate the wxEVT_COMMAND_TEXT_UPDATED event, like SetValue() does
void SendTextUpdatedEvent();
// do the window-specific processing after processing the update event
virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
@ -433,17 +437,16 @@ protected:
int overflow(int i);
#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()
// flags for DoSetValue(): common part of SetValue() and ChangeValue() and
// also used to implement WriteText() in wxMSW
enum
{
SetValue_SendEvent = 1,
SetValue_SelectionOnly = 2
};
// generate the wxEVT_COMMAND_TEXT_UPDATED event
void SendTextUpdatedEvent();
virtual void DoSetValue(const wxString& value, int flags = 0) = 0;
// the name of the last file loaded with LoadFile() which will be used by
// SaveFile() by default

View File

@ -105,9 +105,6 @@ public:
// ----------------------------------
virtual wxString GetValue() const;
virtual void SetValue(const wxString& value);
virtual void ChangeValue(const wxString &value);
virtual int GetLineLength(wxTextCoord lineNo) const;
virtual wxString GetLineText(wxTextCoord lineNo) const;
@ -262,6 +259,9 @@ protected:
// calc the size from the text extent
virtual wxSize DoGetBestClientSize() const;
// implements Set/ChangeValue()
virtual void DoSetValue(const wxString& value, int flags = 0);
// common part of all ctors
void Init();

View File

@ -116,10 +116,6 @@ public:
// implement base class pure virtuals
// ----------------------------------
virtual wxString GetValue() const;
virtual void SetValue(const wxString& value)
{ ChangeValue(value); SendTextUpdatedEvent(); }
virtual void ChangeValue(const wxString &value);
virtual int GetLineLength(long lineNo) const;
@ -132,10 +128,6 @@ public:
// more readable flag testing methods
// ----------------------------------
#if 0
// it seems now in wxTextCtrlBase
bool IsSingleLine() const { return !(GetWindowStyle() & wxTE_MULTILINE); }
#endif
bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD) != 0; }
bool WrapLines() const { return false; }
@ -274,6 +266,8 @@ protected:
virtual wxSize DoGetBestSize() const;
virtual void DoSetValue(const wxString& value, int flags = 0);
friend class wxSourceUndoStep;
wxSourceLineArray m_lines;

View File

@ -135,10 +135,13 @@ void wxTextCtrl::Replace(long, long, wxString const&)
{
}
void wxTextCtrl::SetValue(wxString const& value)
void wxTextCtrl::DoSetValue(wxString const& value, int flags)
{
wxAutoNSAutoreleasePool pool;
[GetNSTextField() setStringValue: wxNSStringWithWxString(value)];
if ( flags & SetValue_SendEvent )
SendTextUpdatedEvent();
}
void wxTextCtrl::WriteText(wxString const&)

View File

@ -243,7 +243,7 @@ bool wxTextCtrlBase::DoSaveFile(const wxString& filename, int WXUNUSED(fileType)
{
// if it worked, save for future calls
m_filename = filename;
// it's not modified any longer
DiscardEdits();
@ -525,6 +525,24 @@ wxTextCtrlBase::HitTest(const wxPoint& WXUNUSED(pt),
return wxTE_HT_UNKNOWN;
}
// ----------------------------------------------------------------------------
// events
// ----------------------------------------------------------------------------
void wxTextCtrlBase::SendTextUpdatedEvent()
{
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
// do not do this as it could be very inefficient if the text control
// contains a lot of text and we're not using ref-counted wxString
// implementation -- instead, event.GetString() will query the control for
// its current text if needed
//event.SetString(GetValue());
event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event);
}
#else // !wxUSE_TEXTCTRL
// define this one even if !wxUSE_TEXTCTRL because it is also used by other

View File

@ -448,9 +448,7 @@ gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win )
if ( win->MarkDirtyOnChange() )
win->MarkDirty();
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
event.SetEventObject( win );
win->GetEventHandler()->ProcessEvent( event );
win->SendTextUpdatedEvent();
}
}

View File

@ -547,32 +547,20 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
GetPeer()->GetSelection( from , to ) ;
}
void wxTextCtrl::SetValue(const wxString& str)
void wxTextCtrl::DoSetValue(const wxString& str, int flags)
{
// optimize redraws
if ( GetValue() == str )
return ;
return;
GetPeer()->SetStringValue( str ) ;
if ( m_triggerOnSetValue )
if ( (flags & SetValue_SendEvent) && m_triggerOnSetValue )
{
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId );
event.SetString( GetValue() );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event );
SendTextUpdatedEvent();
}
}
void wxTextCtrl::ChangeValue(const wxString& str)
{
// optimize redraws
if ( GetValue() == str )
return ;
GetPeer()->SetStringValue( str ) ;
}
void wxTextCtrl::SetMaxLength(unsigned long len)
{
m_maxLength = len ;

View File

@ -240,7 +240,7 @@ wxString wxTextCtrl::GetValue() const
return str;
}
void wxTextCtrl::ChangeValue(const wxString& text)
void wxTextCtrl::DoSetValue(const wxString& text, int flags)
{
m_inSetValue = true;
@ -254,6 +254,9 @@ void wxTextCtrl::ChangeValue(const wxString& text)
m_modified = true;
m_inSetValue = false;
if ( flags & SetValue_SendEvent )
SendTextUpdatedEvent();
}
// Clipboard operations

View File

@ -229,66 +229,10 @@ wxString wxTextCtrl::GetValue() const
return res;
}
void wxTextCtrl::SetValue(const wxString& value)
void wxTextCtrl::DoSetValue(const wxString& value, int flags)
{
}
void wxTextCtrl::ChangeValue(const wxString& value)
{
}
#if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
// TODO: using memcpy() would improve performance a lot for big amounts of text
DWORD CALLBACK
wxRichEditStreamIn(DWORD dwCookie, BYTE *buf, LONG cb, LONG *pcb)
{
return 0;
}
// helper struct used to pass parameters from wxTextCtrl to wxRichEditStreamOut
struct wxStreamOutData
{
wchar_t *wpc;
size_t len;
};
DWORD CALLBACK
wxRichEditStreamOut(DWORD_PTR dwCookie, BYTE *buf, LONG cb, LONG *pcb)
{
return 0;
}
#if wxUSE_UNICODE_MSLU
#define UNUSED_IF_MSLU(param)
#else
#define UNUSED_IF_MSLU(param) param
#endif
bool
wxTextCtrl::StreamIn(const wxString& value,
wxFontEncoding UNUSED_IF_MSLU(encoding),
bool selectionOnly)
{
return false;
}
#if !wxUSE_UNICODE_MSLU
wxString
wxTextCtrl::StreamOut(wxFontEncoding encoding, bool selectionOnly) const
{
wxString out;
return out;
}
#endif // !wxUSE_UNICODE_MSLU
#endif // wxUSE_RICHEDIT
void wxTextCtrl::WriteText(const wxString& value)
{
}

View File

@ -778,7 +778,7 @@ wxTextCtrl::~wxTextCtrl()
// set/get the value
// ----------------------------------------------------------------------------
void wxTextCtrl::ChangeValue(const wxString& value)
void wxTextCtrl::DoSetValue(const wxString& value, int flags)
{
if ( IsSingleLine() && (value == GetValue()) )
{
@ -792,12 +792,9 @@ void wxTextCtrl::ChangeValue(const wxString& value)
{
SetInsertionPoint(0);
}
}
void wxTextCtrl::SetValue(const wxString& value)
{
ChangeValue(value);
SendTextUpdatedEvent();
if ( flags & SetValue_SendEvent )
SendTextUpdatedEvent();
}
const wxArrayString& wxTextCtrl::GetLines() const

View File

@ -277,7 +277,7 @@ wxString wxTextCtrl::GetValue() const
return ret;
}
void wxTextCtrl::ChangeValue(const wxString& value)
void wxTextCtrl::DoSetValue(const wxString& value, int flags)
{
m_modified = false;
@ -343,6 +343,9 @@ void wxTextCtrl::ChangeValue(const wxString& value)
MyAdjustScrollbars();
Refresh();
if ( flags & SetValue_SendEvent )
SendTextUpdatedEvent();
}
int wxTextCtrl::GetLineLength(long lineNo) const