Instead of using broken emulation of the support for hints available in the
text control, use the real wxTextCtrl::SetHint() for SetDescriptiveText()
implementation in the search control.
This looks better and, more importantly, fixes the bug when searching for the
string equal to the current descriptive text searched for an empty string
instead.
Closes #13324.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68237
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
public:
wxSearchTextCtrl(wxSearchCtrl *search, const wxString& value, int style)
: wxTextCtrl(search, wxID_ANY, value, wxDefaultPosition, wxDefaultSize,
public:
wxSearchTextCtrl(wxSearchCtrl *search, const wxString& value, int style)
: wxTextCtrl(search, wxID_ANY, value, wxDefaultPosition, wxDefaultSize,
+ (style & ~wxBORDER_MASK) | wxNO_BORDER)
- m_defaultFG = GetForegroundColour();
+
+ SetHint(_("Search"));
// remove the default minsize, the searchctrl will have one instead
SetSizeHints(wxDefaultCoord,wxDefaultCoord);
}
// remove the default minsize, the searchctrl will have one instead
SetSizeHints(wxDefaultCoord,wxDefaultCoord);
}
- void SetDescriptiveText(const wxString& text)
- {
- if ( GetValue() == m_descriptiveText )
- {
- ChangeValue(wxEmptyString);
- }
-
- m_descriptiveText = text;
- }
-
- wxString GetDescriptiveText() const
- {
- return m_descriptiveText;
- }
-
// provide access to the base class protected methods to wxSearchCtrl which
// needs to forward to them
// provide access to the base class protected methods to wxSearchCtrl which
// needs to forward to them
m_search->GetEventHandler()->ProcessEvent(event);
}
m_search->GetEventHandler()->ProcessEvent(event);
}
- void OnIdle(wxIdleEvent& WXUNUSED(event))
- {
- if ( IsEmpty() && !(wxWindow::FindFocus() == this) )
- {
- ChangeValue(m_descriptiveText);
- SetInsertionPoint(0);
- SetForegroundColour(m_defaultFG.ChangeLightness (LIGHT_STEP));
- }
- }
-
- void OnFocus(wxFocusEvent& event)
- {
- event.Skip();
- if ( GetValue() == m_descriptiveText )
- {
- ChangeValue(wxEmptyString);
- SetForegroundColour(m_defaultFG);
- }
- }
-
private:
wxSearchCtrl* m_search;
private:
wxSearchCtrl* m_search;
- wxString m_descriptiveText;
- wxColour m_defaultFG;
EVT_TEXT_ENTER(wxID_ANY, wxSearchTextCtrl::OnText)
EVT_TEXT_URL(wxID_ANY, wxSearchTextCtrl::OnTextUrl)
EVT_TEXT_MAXLEN(wxID_ANY, wxSearchTextCtrl::OnText)
EVT_TEXT_ENTER(wxID_ANY, wxSearchTextCtrl::OnText)
EVT_TEXT_URL(wxID_ANY, wxSearchTextCtrl::OnTextUrl)
EVT_TEXT_MAXLEN(wxID_ANY, wxSearchTextCtrl::OnText)
- EVT_IDLE(wxSearchTextCtrl::OnIdle)
- EVT_SET_FOCUS(wxSearchTextCtrl::OnFocus)
END_EVENT_TABLE()
// ----------------------------------------------------------------------------
END_EVENT_TABLE()
// ----------------------------------------------------------------------------
- m_text = new wxSearchTextCtrl(this, value, style & ~wxBORDER_MASK);
- m_text->SetDescriptiveText(_("Search"));
+ m_text = new wxSearchTextCtrl(this, value, style);
m_searchButton = new wxSearchButton(this,
wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN,
m_searchButton = new wxSearchButton(this,
wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN,
void wxSearchCtrl::SetDescriptiveText(const wxString& text)
{
void wxSearchCtrl::SetDescriptiveText(const wxString& text)
{
- m_text->SetDescriptiveText(text);
}
wxString wxSearchCtrl::GetDescriptiveText() const
{
}
wxString wxSearchCtrl::GetDescriptiveText() const
{
- return m_text->GetDescriptiveText();
+ return m_text->GetHint();
}
// ----------------------------------------------------------------------------
}
// ----------------------------------------------------------------------------
wxString wxSearchCtrl::DoGetValue() const
{
wxString wxSearchCtrl::DoGetValue() const
{
- wxString value = m_text->GetValue();
- if (value == m_text->GetDescriptiveText())
- return wxEmptyString;
- else
- return value;
+ return m_text->GetValue();
}
wxString wxSearchCtrl::GetRange(long from, long to) const
{
}
wxString wxSearchCtrl::GetRange(long from, long to) const
{