// 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;
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);
// 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();
// 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
// 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 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;
#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
// 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 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
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 void DoSetValue(const wxString& value, int flags);
+ virtual wxString DoGetValue() const = 0;
// 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);
+
+ // 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);
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();
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);
};
}
// ----------------------------------------------------------------------------
-// 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;
return sel;
}
+// ----------------------------------------------------------------------------
+// text operations
+// ----------------------------------------------------------------------------
+
void wxTextEntryBase::AppendText(const wxString& text)
{
SetInsertionPointEnd();
// accessors
// ---------
-wxString wxSearchCtrl::GetValue() const
+wxString wxSearchCtrl::DoGetValue() const
{
wxString value = m_text->GetValue();
if (value == m_text->GetDescriptiveText())
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);
gtk_editable_set_position(edit, len);
}
-wxString wxTextEntry::GetValue() const
+wxString wxTextEntry::DoGetValue() const
{
const wxGtkString value(gtk_editable_get_chars(GetEditable(), 0, -1));
// operations on control text
// ----------------------------------------------------------------------------
-wxString wxTextEntry::GetValue() const
+wxString wxTextEntry::DoGetValue() const
{
wxString str;
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 )
// 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 */);
::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str());
}
-wxString wxTextEntry::GetValue() const
+wxString wxTextEntry::DoGetValue() const
{
return wxGetWindowText(GetEditHWND());
}
::WinSetWindowText(GetEditHwnd(), text.c_str());
}
-wxString wxTextEntry::GetValue() const
+wxString wxTextEntry::DoGetValue() const
{
return wxGetWindowText(GetEditHWND());
}