public:
wxSearchTextCtrl(wxSearchCtrl *search, const wxString& value, int style)
: wxTextCtrl(search, wxID_ANY, value, wxDefaultPosition, wxDefaultSize,
- style | wxNO_BORDER)
+ (style & ~wxBORDER_MASK) | wxNO_BORDER)
{
m_search = search;
- m_defaultFG = GetForegroundColour();
+
+ SetHint(_("Search"));
// 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
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;
- wxString m_descriptiveText;
- wxColour m_defaultFG;
DECLARE_EVENT_TABLE()
};
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()
// ----------------------------------------------------------------------------
void SetBitmapLabel(const wxBitmap& label) { m_bmp = label; }
+ // The buttons in wxSearchCtrl shouldn't accept focus from keyboard because
+ // this would interfere with the usual TAB processing: the user expects
+ // that pressing TAB in the search control should switch focus to the next
+ // control and not give it to the button inside the same control. Besides,
+ // the search button can be already activated by pressing "Enter" so there
+ // is really no reason for it to be able to get focus from keyboard.
+ virtual bool AcceptsFocusFromKeyboard() const { return false; }
protected:
wxSize DoGetBestSize() const
return false;
}
- 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,
void wxSearchCtrl::SetDescriptiveText(const wxString& text)
{
- m_text->SetDescriptiveText(text);
+ m_text->SetHint(text);
}
wxString wxSearchCtrl::GetDescriptiveText() const
{
- return m_text->GetDescriptiveText();
+ return m_text->GetHint();
}
// ----------------------------------------------------------------------------
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
{