]> git.saurik.com Git - wxWidgets.git/blame - src/osx/srchctrl_osx.cpp
Try to better revert to the original string value in wxBitmapComboBox::RecreateControl()
[wxWidgets.git] / src / osx / srchctrl_osx.cpp
CommitLineData
524c47aa
SC
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/srchctrl_osx.cpp
3// Purpose: implements mac carbon wxSearchCtrl
4// Author: Vince Harron
5// Created: 2006-02-19
b5b208a1 6// RCS-ID: $Id$
524c47aa 7// Copyright: Vince Harron
526954c5 8// Licence: wxWindows licence
524c47aa
SC
9///////////////////////////////////////////////////////////////////////////////
10
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18#if wxUSE_SEARCHCTRL
19
20#include "wx/srchctrl.h"
21
22#ifndef WX_PRECOMP
23 #include "wx/menu.h"
24#endif //WX_PRECOMP
25
26#if wxUSE_NATIVE_SEARCH_CONTROL
27
1e181c7a
SC
28#include "wx/osx/private.h"
29
30BEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase)
31END_EVENT_TABLE()
32
33IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase)
34
524c47aa
SC
35
36#endif // wxUSE_NATIVE_SEARCH_CONTROL
37
1e181c7a
SC
38
39// ----------------------------------------------------------------------------
40// wxSearchCtrl creation
41// ----------------------------------------------------------------------------
42
43// creation
44// --------
45
46wxSearchCtrl::wxSearchCtrl()
47{
48 Init();
49}
50
51wxSearchCtrl::wxSearchCtrl(wxWindow *parent, wxWindowID id,
52 const wxString& value,
53 const wxPoint& pos,
54 const wxSize& size,
55 long style,
56 const wxValidator& validator,
57 const wxString& name)
58{
59 Init();
60
61 Create(parent, id, value, pos, size, style, validator, name);
62}
63
64void wxSearchCtrl::Init()
65{
66 m_menu = 0;
67}
68
69wxSearchWidgetImpl* wxSearchCtrl::GetSearchPeer() const
70{
71 return dynamic_cast<wxSearchWidgetImpl*> (m_peer);
72}
03647350 73
1e181c7a
SC
74wxSearchCtrl::~wxSearchCtrl()
75{
76 delete m_menu;
77}
78
79wxSize wxSearchCtrl::DoGetBestSize() const
80{
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)
84 size.SetWidth(100);
85
86 return size;
87}
88
89
90// search control specific interfaces
91// wxSearchCtrl owns menu after this call
92void wxSearchCtrl::SetMenu( wxMenu* menu )
93{
94 if ( menu == m_menu )
95 {
96 // no change
97 return;
98 }
99
100 if ( m_menu )
101 {
102 m_menu->SetInvokingWindow( 0 );
103 }
104
105 delete m_menu;
106 m_menu = menu;
107
108 if ( m_menu )
109 {
110 m_menu->SetInvokingWindow( this );
111 }
112
113 GetSearchPeer()->SetSearchMenu( m_menu );
114}
115
116wxMenu* wxSearchCtrl::GetMenu()
117{
118 return m_menu;
119}
120
121void wxSearchCtrl::ShowSearchButton( bool show )
122{
123 if ( IsSearchButtonVisible() == show )
124 {
125 // no change
126 return;
127 }
128 GetSearchPeer()->ShowSearchButton( show );
129}
130
131bool wxSearchCtrl::IsSearchButtonVisible() const
132{
133 return GetSearchPeer()->IsSearchButtonVisible();
134}
135
136
137void wxSearchCtrl::ShowCancelButton( bool show )
138{
139 if ( IsCancelButtonVisible() == show )
140 {
141 // no change
142 return;
143 }
144 GetSearchPeer()->ShowCancelButton( show );
145}
146
147bool wxSearchCtrl::IsCancelButtonVisible() const
148{
149 return GetSearchPeer()->IsCancelButtonVisible();
150}
151
152void wxSearchCtrl::SetDescriptiveText(const wxString& text)
153{
154 m_descriptiveText = text;
155 GetSearchPeer()->SetDescriptiveText(text);
156}
157
158wxString wxSearchCtrl::GetDescriptiveText() const
159{
160 return m_descriptiveText;
161}
162
163bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id,
164 const wxString& value,
165 const wxPoint& pos,
166 const wxSize& size,
167 long style,
168 const wxValidator& validator,
169 const wxString& name)
170{
171 m_macIsUserPane = false ;
172 m_editable = true ;
173
174 if ( ! (style & wxNO_BORDER) )
175 style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ;
176
177 if ( !wxTextCtrlBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
178 return false;
179
180 if ( m_windowStyle & wxTE_MULTILINE )
181 {
182 // always turn on this style for multi-line controls
183 m_windowStyle |= wxTE_PROCESS_ENTER;
184 style |= wxTE_PROCESS_ENTER ;
185 }
186
187
188 m_peer = wxWidgetImpl::CreateSearchControl( this, GetParent(), GetId(), value, pos, size, style, GetExtraStyle() );
189
190 MacPostControlCreate(pos, size) ;
191
192 // only now the embedding is correct and we can do a positioning update
193
194 MacSuperChangedPosition() ;
195
196 if ( m_windowStyle & wxTE_READONLY)
197 SetEditable( false ) ;
198
199 SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ;
200
201 return true;
202}
203
204bool wxSearchCtrl::HandleSearchFieldSearchHit()
205{
206 wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, m_windowId );
207 event.SetEventObject(this);
ac63bc40
VZ
208
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());
212
1e181c7a
SC
213 return ProcessCommand(event);
214}
215
216bool wxSearchCtrl::HandleSearchFieldCancelHit()
217{
218 wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, m_windowId );
219 event.SetEventObject(this);
220 return ProcessCommand(event);
221}
222
223
524c47aa 224#endif // wxUSE_SEARCHCTRL