]> git.saurik.com Git - wxWidgets.git/blob - src/osx/srchctrl_osx.cpp
Test whether GTK+ is 2.18 or newer in configure.
[wxWidgets.git] / src / osx / srchctrl_osx.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/srchctrl_osx.cpp
3 // Purpose: implements mac carbon wxSearchCtrl
4 // Author: Vince Harron
5 // Created: 2006-02-19
6 // RCS-ID: $Id: srchctrl.cpp 54820 2008-07-29 20:04:11Z SC $
7 // Copyright: Vince Harron
8 // License: wxWindows licence
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
28 #include "wx/osx/private.h"
29
30 BEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase)
31 END_EVENT_TABLE()
32
33 IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase)
34
35
36 #endif // wxUSE_NATIVE_SEARCH_CONTROL
37
38
39 // ----------------------------------------------------------------------------
40 // wxSearchCtrl creation
41 // ----------------------------------------------------------------------------
42
43 // creation
44 // --------
45
46 wxSearchCtrl::wxSearchCtrl()
47 {
48 Init();
49 }
50
51 wxSearchCtrl::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
64 void wxSearchCtrl::Init()
65 {
66 m_menu = 0;
67 }
68
69 wxSearchWidgetImpl* wxSearchCtrl::GetSearchPeer() const
70 {
71 return dynamic_cast<wxSearchWidgetImpl*> (m_peer);
72 }
73
74 wxSearchCtrl::~wxSearchCtrl()
75 {
76 delete m_menu;
77 }
78
79 wxSize 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
92 void 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
116 wxMenu* wxSearchCtrl::GetMenu()
117 {
118 return m_menu;
119 }
120
121 void wxSearchCtrl::ShowSearchButton( bool show )
122 {
123 if ( IsSearchButtonVisible() == show )
124 {
125 // no change
126 return;
127 }
128 GetSearchPeer()->ShowSearchButton( show );
129 }
130
131 bool wxSearchCtrl::IsSearchButtonVisible() const
132 {
133 return GetSearchPeer()->IsSearchButtonVisible();
134 }
135
136
137 void wxSearchCtrl::ShowCancelButton( bool show )
138 {
139 if ( IsCancelButtonVisible() == show )
140 {
141 // no change
142 return;
143 }
144 GetSearchPeer()->ShowCancelButton( show );
145 }
146
147 bool wxSearchCtrl::IsCancelButtonVisible() const
148 {
149 return GetSearchPeer()->IsCancelButtonVisible();
150 }
151
152 void wxSearchCtrl::SetDescriptiveText(const wxString& text)
153 {
154 m_descriptiveText = text;
155 GetSearchPeer()->SetDescriptiveText(text);
156 }
157
158 wxString wxSearchCtrl::GetDescriptiveText() const
159 {
160 return m_descriptiveText;
161 }
162
163 bool 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
204 bool wxSearchCtrl::HandleSearchFieldSearchHit()
205 {
206 wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, m_windowId );
207 event.SetEventObject(this);
208 return ProcessCommand(event);
209 }
210
211 bool wxSearchCtrl::HandleSearchFieldCancelHit()
212 {
213 wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, m_windowId );
214 event.SetEventObject(this);
215 return ProcessCommand(event);
216 }
217
218
219 #endif // wxUSE_SEARCHCTRL