1
///////////////////////////////////////////////////////////////////////////////
2
// Name: src/osx/srchctrl_osx.cpp
3
// Purpose: implements mac carbon wxSearchCtrl
4
// Author: Vince Harron
6
// Copyright: Vince Harron
7
// Licence: wxWindows licence
8
///////////////////////////////////////////////////////////////////////////////
10
// For compilers that support precompilation, includes "wx.h".
11
#include "wx/wxprec.h"
19
#include "wx/srchctrl.h"
25
#if wxUSE_NATIVE_SEARCH_CONTROL
27
#include "wx/osx/private.h"
29
BEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase)
32
IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase)
35
#endif // wxUSE_NATIVE_SEARCH_CONTROL
38
// ----------------------------------------------------------------------------
39
// wxSearchCtrl creation
40
// ----------------------------------------------------------------------------
45
wxSearchCtrl::wxSearchCtrl()
50
wxSearchCtrl::wxSearchCtrl(wxWindow *parent, wxWindowID id,
51
const wxString& value,
55
const wxValidator& validator,
60
Create(parent, id, value, pos, size, style, validator, name);
63
void wxSearchCtrl::Init()
68
wxSearchWidgetImpl* wxSearchCtrl::GetSearchPeer() const
70
return dynamic_cast<wxSearchWidgetImpl*> (GetPeer());
73
wxSearchCtrl::~wxSearchCtrl()
78
wxSize wxSearchCtrl::DoGetBestSize() const
80
wxSize size = wxWindow::DoGetBestSize();
81
// it seems to return a default width of about 16, which is way too small here.
82
if (size.GetWidth() < 100)
89
// search control specific interfaces
90
// wxSearchCtrl owns menu after this call
91
void wxSearchCtrl::SetMenu( wxMenu* menu )
101
m_menu->SetInvokingWindow( 0 );
109
m_menu->SetInvokingWindow( this );
112
GetSearchPeer()->SetSearchMenu( m_menu );
115
wxMenu* wxSearchCtrl::GetMenu()
120
void wxSearchCtrl::ShowSearchButton( bool show )
122
if ( IsSearchButtonVisible() == show )
127
GetSearchPeer()->ShowSearchButton( show );
130
bool wxSearchCtrl::IsSearchButtonVisible() const
132
return GetSearchPeer()->IsSearchButtonVisible();
136
void wxSearchCtrl::ShowCancelButton( bool show )
138
if ( IsCancelButtonVisible() == show )
143
GetSearchPeer()->ShowCancelButton( show );
146
bool wxSearchCtrl::IsCancelButtonVisible() const
148
return GetSearchPeer()->IsCancelButtonVisible();
151
void wxSearchCtrl::SetDescriptiveText(const wxString& text)
153
m_descriptiveText = text;
154
GetSearchPeer()->SetDescriptiveText(text);
157
wxString wxSearchCtrl::GetDescriptiveText() const
159
return m_descriptiveText;
162
bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id,
163
const wxString& value,
167
const wxValidator& validator,
168
const wxString& name)
173
if ( ! (style & wxNO_BORDER) )
174
style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ;
176
if ( !wxTextCtrlBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
179
if ( m_windowStyle & wxTE_MULTILINE )
181
// always turn on this style for multi-line controls
182
m_windowStyle |= wxTE_PROCESS_ENTER;
183
style |= wxTE_PROCESS_ENTER ;
187
SetPeer(wxWidgetImpl::CreateSearchControl( this, GetParent(), GetId(), value, pos, size, style, GetExtraStyle() ));
189
MacPostControlCreate(pos, size) ;
191
// only now the embedding is correct and we can do a positioning update
193
MacSuperChangedPosition() ;
195
if ( m_windowStyle & wxTE_READONLY)
196
SetEditable( false ) ;
198
SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ;
203
bool wxSearchCtrl::HandleSearchFieldSearchHit()
205
wxCommandEvent event(wxEVT_SEARCHCTRL_SEARCH_BTN, m_windowId );
206
event.SetEventObject(this);
208
// provide the string to search for directly in the event, this is more
209
// convenient than retrieving it from the control in event handler code
210
event.SetString(GetValue());
212
return ProcessCommand(event);
215
bool wxSearchCtrl::HandleSearchFieldCancelHit()
217
wxCommandEvent event(wxEVT_SEARCHCTRL_CANCEL_BTN, m_windowId );
218
event.SetEventObject(this);
219
return ProcessCommand(event);
223
#endif // wxUSE_SEARCHCTRL