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();
return m_hintData ? m_hintData->GetHintString() : wxString();
}
+// ----------------------------------------------------------------------------
+// margins support
+// ----------------------------------------------------------------------------
+
+bool wxTextEntryBase::DoSetMargins(const wxPoint& WXUNUSED(pt))
+{
+ return false;
+}
+
+wxPoint wxTextEntryBase::DoGetMargins() const
+{
+ return wxPoint(-1, -1);
+}
+
+// ----------------------------------------------------------------------------
+// events
+// ----------------------------------------------------------------------------
+
+/* static */
+bool wxTextEntryBase::SendTextUpdatedEvent(wxWindow *win)
+{
+ wxCHECK_MSG( win, false, "can't send an event without a window" );
+
+ wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, win->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(win->GetValue());
+
+ event.SetEventObject(win);
+ return win->HandleWindowEvent(event);
+}
+
#endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX