Make wxSearchCtrl inherit from wxTextEntry in all ports

Previously it only inherited from wxTextEntryBase in the generic
implementation (used e.g. in wxMSW).

Update the code, documentation and add new unit tests checking that
wxSearchCtrl member functions inherited from wxTextEntry behave
correctly.

Closes #23686.

Closes #23697.
This commit is contained in:
Martin Corino 2023-07-09 16:21:09 +02:00 committed by Vadim Zeitlin
parent 52a11a3a9d
commit 4d76a87015
3 changed files with 76 additions and 4 deletions

View file

@ -25,8 +25,14 @@
class WXDLLIMPEXP_CORE wxSearchCtrlBaseBaseClass
: public wxCompositeWindow< wxNavigationEnabled<wxControl> >,
public wxTextEntryBase
public wxTextEntry
{
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
private:
// implement this to return the HWND of the EDIT control
// can return nullptr here as this TextEntry is just a proxy
virtual WXHWND GetEditHWND() const override { wxFAIL_MSG("unreachable"); return nullptr; }
#endif
};
#elif defined(__WXMAC__)
// search control was introduced in Mac OS X 10.3 Panther

View file

@ -15,9 +15,9 @@
generically for all the other platforms.
Please note that this class provides many wxTextCtrl-like methods, but does
_not_ necessarily derive from wxTextCtrl in all ports (although it does in
the generic version). Only the methods defined in wxTextEntry interface
class are guaranteed to be available under all platforms.
_not_ necessarily derive from wxTextCtrl in all ports (it actually only does
so in the MacOSX version currently). Only the methods defined in the wxTextEntry
interface class are guaranteed to be available under all platforms.
@beginStyleTable
@style{wxTE_PROCESS_TAB}

View file

@ -32,6 +32,29 @@ public:
delete m_search;
}
void CheckStringSelection(const char *sel)
{
wxTextEntry * const entry = m_search;
CHECK( sel == entry->GetStringSelection() );
}
void AssertSelection(int from, int to, const char *sel)
{
wxTextEntry * const entry = m_search;
CHECK( entry->HasSelection() );
long fromReal,
toReal;
entry->GetSelection(&fromReal, &toReal);
CHECK( from == fromReal );
CHECK( to == toReal );
CHECK( from == entry->GetInsertionPoint() );
CheckStringSelection(sel);
}
protected:
wxSearchCtrl* const m_search;
};
@ -54,6 +77,49 @@ SEARCH_CTRL_TEST_CASE("wxSearchCtrl::ChangeValue", "[wxSearchCtrl][text]")
m_search->ChangeValue("foo");
CHECK( m_search->GetValue() == "foo" );
m_search->Clear();
CHECK( m_search->GetValue() == "" );
}
SEARCH_CTRL_TEST_CASE("wxSearchCtrl::SetValue", "[wxSearchCtrl][set_value]")
{
// Work around bug with hint implementation in wxGTK2.
#if defined(__WXGTK__) && !defined(__WXGTK3__)
m_search->Clear();
#endif
CHECK( m_search->IsEmpty() );
m_search->SetValue("foo");
CHECK( m_search->GetValue() == "foo" );
m_search->SetValue("");
CHECK( m_search->IsEmpty() );
m_search->SetValue("hi");
CHECK( "hi" == m_search->GetValue() );
m_search->SetValue("bye");
CHECK( "bye" == m_search->GetValue() );
}
SEARCH_CTRL_TEST_CASE("wxSearchCtrl::Selection", "[wxSearchCtrl][selection]")
{
wxTextEntry * const entry = m_search;
entry->SetValue("0123456789");
entry->SetSelection(2, 4);
AssertSelection(2, 4, "23"); // not "234"!
entry->SetSelection(3, -1);
AssertSelection(3, 10, "3456789");
entry->SelectAll();
AssertSelection(0, 10, "0123456789");
entry->SetSelection(0, 0);
CHECK( !entry->HasSelection() );
}
#endif // wxUSE_SEARCHCTRL