added wxTextEntry::DoGetValue() to allow returning empty string if the control currently contains hint text
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59265 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -69,9 +69,6 @@ public:
|
||||
// accessors
|
||||
// ---------
|
||||
|
||||
virtual wxString GetValue() const;
|
||||
virtual void SetValue(const wxString& value);
|
||||
|
||||
virtual wxString GetRange(long from, long to) const;
|
||||
|
||||
virtual int GetLineLength(long lineNo) const;
|
||||
@@ -204,6 +201,9 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void DoSetValue(const wxString& value, int flags);
|
||||
virtual wxString DoGetValue() const;
|
||||
virtual void SetValue(const wxString& value);
|
||||
|
||||
virtual bool DoLoadFile(const wxString& file, int fileType);
|
||||
virtual bool DoSaveFile(const wxString& file, int fileType);
|
||||
|
||||
|
@@ -24,7 +24,6 @@ public:
|
||||
|
||||
// implement wxTextEntryBase pure virtual methods
|
||||
virtual void WriteText(const wxString& text);
|
||||
virtual wxString GetValue() const;
|
||||
virtual void Remove(long from, long to);
|
||||
|
||||
virtual void Copy();
|
||||
@@ -53,6 +52,9 @@ public:
|
||||
// implementation only from now on
|
||||
void SendMaxLenEvent();
|
||||
|
||||
protected:
|
||||
virtual wxString DoGetValue() const;
|
||||
|
||||
private:
|
||||
// implement this to return the associated GtkEntry or another widget
|
||||
// implementing GtkEditable
|
||||
|
@@ -22,7 +22,6 @@ public:
|
||||
|
||||
// implement wxTextEntryBase pure virtual methods
|
||||
virtual void WriteText(const wxString& text);
|
||||
virtual wxString GetValue() const;
|
||||
virtual void Replace(long from, long to, const wxString& value);
|
||||
virtual void Remove(long from, long to);
|
||||
|
||||
@@ -46,6 +45,8 @@ public:
|
||||
virtual void SetEditable(bool editable);
|
||||
|
||||
protected:
|
||||
virtual wxString DoGetValue() const;
|
||||
|
||||
// translate wx text position (which may be -1 meaning "last one") to a
|
||||
// valid Motif text position
|
||||
long GetMotifPos(long pos) const;
|
||||
|
@@ -59,6 +59,8 @@ public:
|
||||
#endif // wxUSE_UXTHEME
|
||||
|
||||
protected:
|
||||
virtual wxString DoGetValue() const;
|
||||
|
||||
// this is really a hook for multiline text controls as the single line
|
||||
// ones don't need to ever scroll to show the selection but having it here
|
||||
// allows us to put Remove() in the base class
|
||||
|
@@ -22,7 +22,6 @@ public:
|
||||
|
||||
// implement wxTextEntryBase pure virtual methods
|
||||
virtual void WriteText(const wxString& text);
|
||||
virtual wxString GetValue() const;
|
||||
virtual void Remove(long from, long to);
|
||||
|
||||
virtual void Copy();
|
||||
@@ -48,6 +47,8 @@ public:
|
||||
virtual void SetMaxLength(unsigned long len);
|
||||
|
||||
protected:
|
||||
virtual wxString DoGetValue() const;
|
||||
|
||||
// this is really a hook for multiline text controls as the single line
|
||||
// ones don't need to ever scroll to show the selection but having it here
|
||||
// allows us to put Remove() in the base class
|
||||
|
@@ -44,7 +44,7 @@ public:
|
||||
virtual void WriteText(const wxString& text) = 0;
|
||||
virtual void AppendText(const wxString& text);
|
||||
|
||||
virtual wxString GetValue() const = 0;
|
||||
virtual wxString GetValue() const;
|
||||
virtual wxString GetRange(long from, long to) const;
|
||||
bool IsEmpty() const { return GetLastPosition() <= 0; }
|
||||
|
||||
@@ -152,6 +152,7 @@ protected:
|
||||
};
|
||||
|
||||
virtual void DoSetValue(const wxString& value, int flags);
|
||||
virtual wxString DoGetValue() const = 0;
|
||||
|
||||
// class which should be used to temporarily disable text change events
|
||||
//
|
||||
|
@@ -48,15 +48,21 @@ public:
|
||||
wxTextEntryHintData::OnSetFocus, this);
|
||||
wxBIND_OR_CONNECT_HACK(win, wxEVT_KILL_FOCUS, wxFocusEventHandler,
|
||||
wxTextEntryHintData::OnKillFocus, this);
|
||||
|
||||
// we don't have any hint yet
|
||||
m_showsHint = false;
|
||||
}
|
||||
|
||||
// default dtor is ok
|
||||
|
||||
// are we showing the hint right now?
|
||||
bool ShowsHint() const { return m_showsHint; }
|
||||
|
||||
void SetHintString(const wxString& hint)
|
||||
{
|
||||
m_hint = hint;
|
||||
|
||||
if ( ShowsHint() )
|
||||
if ( m_showsHint )
|
||||
{
|
||||
// update it immediately
|
||||
m_entry->ChangeValue(hint);
|
||||
@@ -67,21 +73,17 @@ public:
|
||||
const wxString& GetHintString() const { return m_hint; }
|
||||
|
||||
private:
|
||||
// are we showing the hint right now?
|
||||
bool ShowsHint() const
|
||||
{
|
||||
return m_entry->GetValue() == m_hint;
|
||||
}
|
||||
|
||||
void OnSetFocus(wxFocusEvent& event)
|
||||
{
|
||||
// hide the hint if we were showing it
|
||||
if ( ShowsHint() )
|
||||
if ( m_showsHint )
|
||||
{
|
||||
// Clear() would send an event which we don't want, so do it like
|
||||
// this
|
||||
m_entry->ChangeValue(wxString());
|
||||
m_win->SetForegroundColour(m_colFg);
|
||||
|
||||
m_showsHint = false;
|
||||
}
|
||||
|
||||
event.Skip();
|
||||
@@ -96,19 +98,27 @@ private:
|
||||
|
||||
m_colFg = m_win->GetForegroundColour();
|
||||
m_win->SetForegroundColour(*wxLIGHT_GREY);
|
||||
|
||||
m_showsHint = true;
|
||||
}
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
|
||||
// the text control we're associated with (as its interface and its window)
|
||||
wxTextEntryBase * const m_entry;
|
||||
wxWindow * const m_win;
|
||||
|
||||
// the original foreground colour of m_win before we changed it
|
||||
wxColour m_colFg;
|
||||
|
||||
// the hint passed to wxTextEntry::SetHint()
|
||||
wxString m_hint;
|
||||
|
||||
// true if we're currently showing it, for this we must be empty and not
|
||||
// have focus
|
||||
bool m_showsHint;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxTextEntryHintData);
|
||||
};
|
||||
|
||||
@@ -122,9 +132,14 @@ wxTextEntryBase::~wxTextEntryBase()
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// text operations
|
||||
// text accessors
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxString wxTextEntryBase::GetValue() const
|
||||
{
|
||||
return m_hintData && m_hintData->ShowsHint() ? wxString() : DoGetValue();
|
||||
}
|
||||
|
||||
wxString wxTextEntryBase::GetRange(long from, long to) const
|
||||
{
|
||||
wxString sel;
|
||||
@@ -138,6 +153,10 @@ wxString wxTextEntryBase::GetRange(long from, long to) const
|
||||
return sel;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// text operations
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxTextEntryBase::AppendText(const wxString& text)
|
||||
{
|
||||
SetInsertionPointEnd();
|
||||
|
@@ -577,7 +577,7 @@ void wxSearchCtrl::LayoutControls(int x, int y, int width, int height)
|
||||
// accessors
|
||||
// ---------
|
||||
|
||||
wxString wxSearchCtrl::GetValue() const
|
||||
wxString wxSearchCtrl::DoGetValue() const
|
||||
{
|
||||
wxString value = m_text->GetValue();
|
||||
if (value == m_text->GetDescriptiveText())
|
||||
@@ -585,11 +585,6 @@ wxString wxSearchCtrl::GetValue() const
|
||||
else
|
||||
return value;
|
||||
}
|
||||
void wxSearchCtrl::SetValue(const wxString& value)
|
||||
{
|
||||
m_text->SetValue(value);
|
||||
}
|
||||
|
||||
wxString wxSearchCtrl::GetRange(long from, long to) const
|
||||
{
|
||||
return m_text->GetRange(from, to);
|
||||
|
@@ -103,7 +103,7 @@ void wxTextEntry::WriteText(const wxString& value)
|
||||
gtk_editable_set_position(edit, len);
|
||||
}
|
||||
|
||||
wxString wxTextEntry::GetValue() const
|
||||
wxString wxTextEntry::DoGetValue() const
|
||||
{
|
||||
const wxGtkString value(gtk_editable_get_chars(GetEditable(), 0, -1));
|
||||
|
||||
|
@@ -59,7 +59,7 @@ long wxTextEntry::GetMotifPos(long pos) const
|
||||
// operations on control text
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxString wxTextEntry::GetValue() const
|
||||
wxString wxTextEntry::DoGetValue() const
|
||||
{
|
||||
wxString str;
|
||||
|
||||
|
@@ -858,8 +858,9 @@ wxString wxTextCtrl::GetRange(long from, long to) const
|
||||
else
|
||||
#endif // wxUSE_RICHEDIT
|
||||
{
|
||||
// retrieve all text
|
||||
str = wxGetWindowText(GetHWND());
|
||||
// retrieve all text: wxTextEntry method works even for multiline
|
||||
// controls and must be used for single line ones to account for hints
|
||||
str = wxTextEntry::GetValue();
|
||||
|
||||
// need only a range?
|
||||
if ( from < to )
|
||||
@@ -882,7 +883,7 @@ void wxTextCtrl::DoSetValue(const wxString& value, int flags)
|
||||
// comparing it with the old one (chances are that it will be different
|
||||
// anyhow, this comparison is there to avoid flicker for small single-line
|
||||
// edit controls mostly)
|
||||
if ( (value.length() > 0x400) || (value != GetValue()) )
|
||||
if ( (value.length() > 0x400) || (value != DoGetValue()) )
|
||||
{
|
||||
DoWriteText(value, flags /* doesn't include SelectionOnly here */);
|
||||
|
||||
|
@@ -184,7 +184,7 @@ void wxTextEntry::WriteText(const wxString& text)
|
||||
::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str());
|
||||
}
|
||||
|
||||
wxString wxTextEntry::GetValue() const
|
||||
wxString wxTextEntry::DoGetValue() const
|
||||
{
|
||||
return wxGetWindowText(GetEditHWND());
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ void wxTextEntry::WriteText(const wxString& text)
|
||||
::WinSetWindowText(GetEditHwnd(), text.c_str());
|
||||
}
|
||||
|
||||
wxString wxTextEntry::GetValue() const
|
||||
wxString wxTextEntry::DoGetValue() const
|
||||
{
|
||||
return wxGetWindowText(GetEditHWND());
|
||||
}
|
||||
|
Reference in New Issue
Block a user