]> git.saurik.com Git - wxWidgets.git/blob - src/osx/srchctrl_osx.cpp
changing to allow for 2x ramping up NSApp run
[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 // Copyright: Vince Harron
7 // Licence: wxWindows licence
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
27 #include "wx/osx/private.h"
28
29 BEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase)
30 END_EVENT_TABLE()
31
32 IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase)
33
34
35 #endif // wxUSE_NATIVE_SEARCH_CONTROL
36
37
38 // ----------------------------------------------------------------------------
39 // wxSearchCtrl creation
40 // ----------------------------------------------------------------------------
41
42 // creation
43 // --------
44
45 wxSearchCtrl::wxSearchCtrl()
46 {
47 Init();
48 }
49
50 wxSearchCtrl::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
63 void wxSearchCtrl::Init()
64 {
65 m_menu = 0;
66 }
67
68 wxSearchWidgetImpl* wxSearchCtrl::GetSearchPeer() const
69 {
70 return dynamic_cast<wxSearchWidgetImpl*> (GetPeer());
71 }
72
73 wxSearchCtrl::~wxSearchCtrl()
74 {
75 delete m_menu;
76 }
77
78 wxSize 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
91 void 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
115 wxMenu* wxSearchCtrl::GetMenu()
116 {
117 return m_menu;
118 }
119
120 void wxSearchCtrl::ShowSearchButton( bool show )
121 {
122 if ( IsSearchButtonVisible() == show )
123 {
124 // no change
125 return;
126 }
127 GetSearchPeer()->ShowSearchButton( show );
128 }
129
130 bool wxSearchCtrl::IsSearchButtonVisible() const
131 {
132 return GetSearchPeer()->IsSearchButtonVisible();
133 }
134
135
136 void wxSearchCtrl::ShowCancelButton( bool show )
137 {
138 if ( IsCancelButtonVisible() == show )
139 {
140 // no change
141 return;
142 }
143 GetSearchPeer()->ShowCancelButton( show );
144 }
145
146 bool wxSearchCtrl::IsCancelButtonVisible() const
147 {
148 return GetSearchPeer()->IsCancelButtonVisible();
149 }
150
151 void wxSearchCtrl::SetDescriptiveText(const wxString& text)
152 {
153 m_descriptiveText = text;
154 GetSearchPeer()->SetDescriptiveText(text);
155 }
156
157 wxString wxSearchCtrl::GetDescriptiveText() const
158 {
159 return m_descriptiveText;
160 }
161
162 bool 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 {
170 DontCreatePeer();
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
187 SetPeer(wxWidgetImpl::CreateSearchControl( this, GetParent(), GetId(), value, pos, size, style, GetExtraStyle() ));
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
203 bool wxSearchCtrl::HandleSearchFieldSearchHit()
204 {
205 wxCommandEvent event(wxEVT_SEARCHCTRL_SEARCH_BTN, m_windowId );
206 event.SetEventObject(this);
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
212 return ProcessCommand(event);
213 }
214
215 bool wxSearchCtrl::HandleSearchFieldCancelHit()
216 {
217 wxCommandEvent event(wxEVT_SEARCHCTRL_CANCEL_BTN, m_windowId );
218 event.SetEventObject(this);
219 return ProcessCommand(event);
220 }
221
222
223 #endif // wxUSE_SEARCHCTRL