X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/524c47aa3adf2af11a3069fd5da035a604f08f66..f7ae43f080576ef142d3884073df298294860328:/src/osx/srchctrl_osx.cpp diff --git a/src/osx/srchctrl_osx.cpp b/src/osx/srchctrl_osx.cpp index c5de244400..d264955f00 100644 --- a/src/osx/srchctrl_osx.cpp +++ b/src/osx/srchctrl_osx.cpp @@ -25,8 +25,195 @@ #if wxUSE_NATIVE_SEARCH_CONTROL -// no common code yet, only here as placeholder +#include "wx/osx/private.h" + +BEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase) +END_EVENT_TABLE() + +IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase) + #endif // wxUSE_NATIVE_SEARCH_CONTROL + +// ---------------------------------------------------------------------------- +// wxSearchCtrl creation +// ---------------------------------------------------------------------------- + +// creation +// -------- + +wxSearchCtrl::wxSearchCtrl() +{ + Init(); +} + +wxSearchCtrl::wxSearchCtrl(wxWindow *parent, wxWindowID id, + const wxString& value, + const wxPoint& pos, + const wxSize& size, + long style, + const wxValidator& validator, + const wxString& name) +{ + Init(); + + Create(parent, id, value, pos, size, style, validator, name); +} + +void wxSearchCtrl::Init() +{ + m_menu = 0; +} + +wxSearchWidgetImpl* wxSearchCtrl::GetSearchPeer() const +{ + return dynamic_cast (m_peer); +} + +wxSearchCtrl::~wxSearchCtrl() +{ + delete m_menu; +} + +wxSize wxSearchCtrl::DoGetBestSize() const +{ + wxSize size = wxWindow::DoGetBestSize(); + // it seems to return a default width of about 16, which is way too small here. + if (size.GetWidth() < 100) + size.SetWidth(100); + + return size; +} + + +// search control specific interfaces +// wxSearchCtrl owns menu after this call +void wxSearchCtrl::SetMenu( wxMenu* menu ) +{ + if ( menu == m_menu ) + { + // no change + return; + } + + if ( m_menu ) + { + m_menu->SetInvokingWindow( 0 ); + } + + delete m_menu; + m_menu = menu; + + if ( m_menu ) + { + m_menu->SetInvokingWindow( this ); + } + + GetSearchPeer()->SetSearchMenu( m_menu ); +} + +wxMenu* wxSearchCtrl::GetMenu() +{ + return m_menu; +} + +void wxSearchCtrl::ShowSearchButton( bool show ) +{ + if ( IsSearchButtonVisible() == show ) + { + // no change + return; + } + GetSearchPeer()->ShowSearchButton( show ); +} + +bool wxSearchCtrl::IsSearchButtonVisible() const +{ + return GetSearchPeer()->IsSearchButtonVisible(); +} + + +void wxSearchCtrl::ShowCancelButton( bool show ) +{ + if ( IsCancelButtonVisible() == show ) + { + // no change + return; + } + GetSearchPeer()->ShowCancelButton( show ); +} + +bool wxSearchCtrl::IsCancelButtonVisible() const +{ + return GetSearchPeer()->IsCancelButtonVisible(); +} + +void wxSearchCtrl::SetDescriptiveText(const wxString& text) +{ + m_descriptiveText = text; + GetSearchPeer()->SetDescriptiveText(text); +} + +wxString wxSearchCtrl::GetDescriptiveText() const +{ + return m_descriptiveText; +} + +bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id, + const wxString& value, + const wxPoint& pos, + const wxSize& size, + long style, + const wxValidator& validator, + const wxString& name) +{ + m_macIsUserPane = false ; + m_editable = true ; + + if ( ! (style & wxNO_BORDER) ) + style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ; + + if ( !wxTextCtrlBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) + return false; + + if ( m_windowStyle & wxTE_MULTILINE ) + { + // always turn on this style for multi-line controls + m_windowStyle |= wxTE_PROCESS_ENTER; + style |= wxTE_PROCESS_ENTER ; + } + + + m_peer = wxWidgetImpl::CreateSearchControl( this, GetParent(), GetId(), value, pos, size, style, GetExtraStyle() ); + + MacPostControlCreate(pos, size) ; + + // only now the embedding is correct and we can do a positioning update + + MacSuperChangedPosition() ; + + if ( m_windowStyle & wxTE_READONLY) + SetEditable( false ) ; + + SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ; + + return true; +} + +bool wxSearchCtrl::HandleSearchFieldSearchHit() +{ + wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, m_windowId ); + event.SetEventObject(this); + return ProcessCommand(event); +} + +bool wxSearchCtrl::HandleSearchFieldCancelHit() +{ + wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, m_windowId ); + event.SetEventObject(this); + return ProcessCommand(event); +} + + #endif // wxUSE_SEARCHCTRL