X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/524c47aa3adf2af11a3069fd5da035a604f08f66..4d8209b9070ea7120078e83a648f3627e57bc15a:/src/osx/srchctrl_osx.cpp diff --git a/src/osx/srchctrl_osx.cpp b/src/osx/srchctrl_osx.cpp index c5de244400..9a300ff33e 100644 --- a/src/osx/srchctrl_osx.cpp +++ b/src/osx/srchctrl_osx.cpp @@ -3,9 +3,9 @@ // Purpose: implements mac carbon wxSearchCtrl // Author: Vince Harron // Created: 2006-02-19 -// RCS-ID: $Id: srchctrl.cpp 54820 2008-07-29 20:04:11Z SC $ +// RCS-ID: $Id$ // Copyright: Vince Harron -// License: wxWindows licence +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx.h". @@ -25,8 +25,200 @@ #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 (GetPeer()); +} + +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) +{ + DontCreatePeer(); + 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 ; + } + + + SetPeer(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); + + // provide the string to search for directly in the event, this is more + // convenient than retrieving it from the control in event handler code + event.SetString(GetValue()); + + return ProcessCommand(event); +} + +bool wxSearchCtrl::HandleSearchFieldCancelHit() +{ + wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, m_windowId ); + event.SetEventObject(this); + return ProcessCommand(event); +} + + #endif // wxUSE_SEARCHCTRL