1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/srchctrl_osx.cpp
3 // Purpose: implements mac carbon wxSearchCtrl
4 // Author: Vince Harron
7 // Copyright: Vince Harron
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/srchctrl.h"
26 #if wxUSE_NATIVE_SEARCH_CONTROL
28 #include "wx/osx/private.h"
30 BEGIN_EVENT_TABLE(wxSearchCtrl
, wxSearchCtrlBase
)
33 IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl
, wxSearchCtrlBase
)
36 #endif // wxUSE_NATIVE_SEARCH_CONTROL
39 // ----------------------------------------------------------------------------
40 // wxSearchCtrl creation
41 // ----------------------------------------------------------------------------
46 wxSearchCtrl::wxSearchCtrl()
51 wxSearchCtrl::wxSearchCtrl(wxWindow
*parent
, wxWindowID id
,
52 const wxString
& value
,
56 const wxValidator
& validator
,
61 Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
64 void wxSearchCtrl::Init()
69 wxSearchWidgetImpl
* wxSearchCtrl::GetSearchPeer() const
71 return dynamic_cast<wxSearchWidgetImpl
*> (GetPeer());
74 wxSearchCtrl::~wxSearchCtrl()
79 wxSize
wxSearchCtrl::DoGetBestSize() const
81 wxSize size
= wxWindow::DoGetBestSize();
82 // it seems to return a default width of about 16, which is way too small here.
83 if (size
.GetWidth() < 100)
90 // search control specific interfaces
91 // wxSearchCtrl owns menu after this call
92 void wxSearchCtrl::SetMenu( wxMenu
* menu
)
102 m_menu
->SetInvokingWindow( 0 );
110 m_menu
->SetInvokingWindow( this );
113 GetSearchPeer()->SetSearchMenu( m_menu
);
116 wxMenu
* wxSearchCtrl::GetMenu()
121 void wxSearchCtrl::ShowSearchButton( bool show
)
123 if ( IsSearchButtonVisible() == show
)
128 GetSearchPeer()->ShowSearchButton( show
);
131 bool wxSearchCtrl::IsSearchButtonVisible() const
133 return GetSearchPeer()->IsSearchButtonVisible();
137 void wxSearchCtrl::ShowCancelButton( bool show
)
139 if ( IsCancelButtonVisible() == show
)
144 GetSearchPeer()->ShowCancelButton( show
);
147 bool wxSearchCtrl::IsCancelButtonVisible() const
149 return GetSearchPeer()->IsCancelButtonVisible();
152 void wxSearchCtrl::SetDescriptiveText(const wxString
& text
)
154 m_descriptiveText
= text
;
155 GetSearchPeer()->SetDescriptiveText(text
);
158 wxString
wxSearchCtrl::GetDescriptiveText() const
160 return m_descriptiveText
;
163 bool wxSearchCtrl::Create(wxWindow
*parent
, wxWindowID id
,
164 const wxString
& value
,
168 const wxValidator
& validator
,
169 const wxString
& name
)
174 if ( ! (style
& wxNO_BORDER
) )
175 style
= (style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
177 if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
180 if ( m_windowStyle
& wxTE_MULTILINE
)
182 // always turn on this style for multi-line controls
183 m_windowStyle
|= wxTE_PROCESS_ENTER
;
184 style
|= wxTE_PROCESS_ENTER
;
188 SetPeer(wxWidgetImpl::CreateSearchControl( this, GetParent(), GetId(), value
, pos
, size
, style
, GetExtraStyle() ));
190 MacPostControlCreate(pos
, size
) ;
192 // only now the embedding is correct and we can do a positioning update
194 MacSuperChangedPosition() ;
196 if ( m_windowStyle
& wxTE_READONLY
)
197 SetEditable( false ) ;
199 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
204 bool wxSearchCtrl::HandleSearchFieldSearchHit()
206 wxCommandEvent
event(wxEVT_SEARCHCTRL_SEARCH_BTN
, m_windowId
);
207 event
.SetEventObject(this);
209 // provide the string to search for directly in the event, this is more
210 // convenient than retrieving it from the control in event handler code
211 event
.SetString(GetValue());
213 return ProcessCommand(event
);
216 bool wxSearchCtrl::HandleSearchFieldCancelHit()
218 wxCommandEvent
event(wxEVT_SEARCHCTRL_CANCEL_BTN
, m_windowId
);
219 event
.SetEventObject(this);
220 return ProcessCommand(event
);
224 #endif // wxUSE_SEARCHCTRL