git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59265
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
13 files changed:
// accessors
// ---------
// 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;
virtual wxString GetRange(long from, long to) const;
virtual int GetLineLength(long lineNo) const;
protected:
virtual void DoSetValue(const wxString& value, int flags);
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);
virtual bool DoLoadFile(const wxString& file, int fileType);
virtual bool DoSaveFile(const wxString& file, int fileType);
// implement wxTextEntryBase pure virtual methods
virtual void WriteText(const wxString& text);
// 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();
virtual void Remove(long from, long to);
virtual void Copy();
// implementation only from now on
void SendMaxLenEvent();
// 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
private:
// implement this to return the associated GtkEntry or another widget
// implementing GtkEditable
// implement wxTextEntryBase pure virtual methods
virtual void WriteText(const wxString& text);
// 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);
virtual void Replace(long from, long to, const wxString& value);
virtual void Remove(long from, long to);
virtual void SetEditable(bool editable);
protected:
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;
// translate wx text position (which may be -1 meaning "last one") to a
// valid Motif text position
long GetMotifPos(long pos) const;
#endif // wxUSE_UXTHEME
protected:
#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
// 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
// implement wxTextEntryBase pure virtual methods
virtual void WriteText(const wxString& text);
// 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();
virtual void Remove(long from, long to);
virtual void Copy();
virtual void SetMaxLength(unsigned long len);
protected:
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
// 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
virtual void WriteText(const wxString& text) = 0;
virtual void AppendText(const wxString& text);
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; }
virtual wxString GetRange(long from, long to) const;
bool IsEmpty() const { return GetLastPosition() <= 0; }
};
virtual void DoSetValue(const wxString& value, int flags);
};
virtual void DoSetValue(const wxString& value, int flags);
+ virtual wxString DoGetValue() const = 0;
// class which should be used to temporarily disable text change events
//
// class which should be used to temporarily disable text change events
//
wxTextEntryHintData::OnSetFocus, this);
wxBIND_OR_CONNECT_HACK(win, wxEVT_KILL_FOCUS, wxFocusEventHandler,
wxTextEntryHintData::OnKillFocus, this);
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;
+ // are we showing the hint right now?
+ bool ShowsHint() const { return m_showsHint; }
+
void SetHintString(const wxString& hint)
{
m_hint = hint;
void SetHintString(const wxString& hint)
{
m_hint = hint;
{
// update it immediately
m_entry->ChangeValue(hint);
{
// update it immediately
m_entry->ChangeValue(hint);
const wxString& GetHintString() const { return m_hint; }
private:
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
void OnSetFocus(wxFocusEvent& event)
{
// hide the hint if we were showing it
{
// Clear() would send an event which we don't want, so do it like
// this
m_entry->ChangeValue(wxString());
m_win->SetForegroundColour(m_colFg);
{
// 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_colFg = m_win->GetForegroundColour();
m_win->SetForegroundColour(*wxLIGHT_GREY);
m_colFg = m_win->GetForegroundColour();
m_win->SetForegroundColour(*wxLIGHT_GREY);
+ // the text control we're associated with (as its interface and its window)
wxTextEntryBase * const m_entry;
wxWindow * const m_win;
wxTextEntryBase * const m_entry;
wxWindow * const m_win;
+ // the original foreground colour of m_win before we changed it
+ // the hint passed to wxTextEntry::SetHint()
+ // 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);
};
wxDECLARE_NO_COPY_CLASS(wxTextEntryHintData);
};
}
// ----------------------------------------------------------------------------
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
+wxString wxTextEntryBase::GetValue() const
+{
+ return m_hintData && m_hintData->ShowsHint() ? wxString() : DoGetValue();
+}
+
wxString wxTextEntryBase::GetRange(long from, long to) const
{
wxString sel;
wxString wxTextEntryBase::GetRange(long from, long to) const
{
wxString sel;
+// ----------------------------------------------------------------------------
+// text operations
+// ----------------------------------------------------------------------------
+
void wxTextEntryBase::AppendText(const wxString& text)
{
SetInsertionPointEnd();
void wxTextEntryBase::AppendText(const wxString& text)
{
SetInsertionPointEnd();
// accessors
// ---------
// accessors
// ---------
-wxString wxSearchCtrl::GetValue() const
+wxString wxSearchCtrl::DoGetValue() const
{
wxString value = m_text->GetValue();
if (value == m_text->GetDescriptiveText())
{
wxString value = m_text->GetValue();
if (value == m_text->GetDescriptiveText())
-void wxSearchCtrl::SetValue(const wxString& value)
-{
- m_text->SetValue(value);
-}
-
wxString wxSearchCtrl::GetRange(long from, long to) const
{
return m_text->GetRange(from, to);
wxString wxSearchCtrl::GetRange(long from, long to) const
{
return m_text->GetRange(from, to);
gtk_editable_set_position(edit, len);
}
gtk_editable_set_position(edit, len);
}
-wxString wxTextEntry::GetValue() const
+wxString wxTextEntry::DoGetValue() const
{
const wxGtkString value(gtk_editable_get_chars(GetEditable(), 0, -1));
{
const wxGtkString value(gtk_editable_get_chars(GetEditable(), 0, -1));
// operations on control text
// ----------------------------------------------------------------------------
// operations on control text
// ----------------------------------------------------------------------------
-wxString wxTextEntry::GetValue() const
+wxString wxTextEntry::DoGetValue() const
else
#endif // wxUSE_RICHEDIT
{
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 )
// need only a range?
if ( from < to )
// 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)
// 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 */);
{
DoWriteText(value, flags /* doesn't include SelectionOnly here */);
::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str());
}
::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str());
}
-wxString wxTextEntry::GetValue() const
+wxString wxTextEntry::DoGetValue() const
{
return wxGetWindowText(GetEditHWND());
}
{
return wxGetWindowText(GetEditHWND());
}
::WinSetWindowText(GetEditHwnd(), text.c_str());
}
::WinSetWindowText(GetEditHwnd(), text.c_str());
}
-wxString wxTextEntry::GetValue() const
+wxString wxTextEntry::DoGetValue() const
{
return wxGetWindowText(GetEditHWND());
}
{
return wxGetWindowText(GetEditHWND());
}