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