]> git.saurik.com Git - wxWidgets.git/blob - src/osx/textentry_osx.cpp
avoid setting pango matrix when not needed
[wxWidgets.git] / src / osx / textentry_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/textentry_osx.cpp
3 // Purpose: wxTextEntry
4 // Author: Stefan Csomor
5 // Modified by: Kevin Ollivier
6 // Created: 1998-01-01
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #if wxUSE_TEXTCTRL
14
15 #include "wx/textctrl.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/intl.h"
19 #include "wx/app.h"
20 #include "wx/utils.h"
21 #include "wx/dc.h"
22 #include "wx/button.h"
23 #include "wx/menu.h"
24 #include "wx/settings.h"
25 #include "wx/msgdlg.h"
26 #include "wx/toplevel.h"
27 #endif
28
29 #ifdef __DARWIN__
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #else
33 #include <stat.h>
34 #endif
35
36 #if wxUSE_STD_IOSTREAM
37 #if wxUSE_IOSTREAMH
38 #include <fstream.h>
39 #else
40 #include <fstream>
41 #endif
42 #endif
43
44 #include "wx/filefn.h"
45 #include "wx/sysopt.h"
46 #include "wx/thread.h"
47 #include "wx/textcompleter.h"
48
49 #include "wx/osx/private.h"
50
51 wxTextEntry::wxTextEntry()
52 {
53 m_completer = NULL;
54 m_editable = true;
55 m_maxLength = 0;
56 }
57
58 wxTextEntry::~wxTextEntry()
59 {
60 delete m_completer;
61 }
62
63 wxString wxTextEntry::DoGetValue() const
64 {
65 wxCHECK_MSG( GetTextPeer(), wxString(), "Must create the control first" );
66
67 return GetTextPeer()->GetStringValue() ;
68 }
69
70 void wxTextEntry::GetSelection(long* from, long* to) const
71 {
72 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
73
74 GetTextPeer()->GetSelection( from , to ) ;
75 }
76
77 void wxTextEntry::SetMaxLength(unsigned long len)
78 {
79 if ( GetTextPeer()->CanClipMaxLength() )
80 GetTextPeer()->SetMaxLength(len);
81 m_maxLength = len ;
82 }
83
84 // Clipboard operations
85
86 void wxTextEntry::Copy()
87 {
88 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
89
90 if (CanCopy())
91 GetTextPeer()->Copy() ;
92 }
93
94 void wxTextEntry::Cut()
95 {
96 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
97
98 if (CanCut())
99 GetTextPeer()->Cut() ;
100 }
101
102 void wxTextEntry::Paste()
103 {
104 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
105
106 if (CanPaste())
107 GetTextPeer()->Paste() ;
108 }
109
110 bool wxTextEntry::CanCopy() const
111 {
112 // Can copy if there's a selection
113 long from, to;
114 GetSelection( &from, &to );
115
116 return (from != to);
117 }
118
119 bool wxTextEntry::CanCut() const
120 {
121 if ( !IsEditable() )
122 return false;
123
124 // Can cut if there's a selection
125 long from, to;
126 GetSelection( &from, &to );
127
128 return (from != to);
129 }
130
131 bool wxTextEntry::CanPaste() const
132 {
133 if (!IsEditable())
134 return false;
135
136 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
137
138 return GetTextPeer()->CanPaste() ;
139 }
140
141 void wxTextEntry::SetEditable(bool editable)
142 {
143 if ( editable == m_editable )
144 return;
145
146 m_editable = editable ;
147
148 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
149 GetTextPeer()->SetEditable( editable ) ;
150 }
151
152 void wxTextEntry::SetInsertionPoint(long pos)
153 {
154 SetSelection( pos , pos ) ;
155 }
156
157 void wxTextEntry::SetInsertionPointEnd()
158 {
159 long pos = GetLastPosition();
160 SetInsertionPoint( pos );
161 }
162
163 long wxTextEntry::GetInsertionPoint() const
164 {
165 long begin, end ;
166 GetSelection( &begin , &end ) ;
167
168 return begin ;
169 }
170
171 wxTextPos wxTextEntry::GetLastPosition() const
172 {
173 wxCHECK_MSG( GetTextPeer(), -1, "Must create the control first" );
174
175 return GetTextPeer()->GetLastPosition() ;
176 }
177
178 void wxTextEntry::Remove(long from, long to)
179 {
180 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
181
182 {
183 EventsSuppressor noevents(this);
184 GetTextPeer()->Remove( from , to );
185 }
186
187 SendTextUpdatedEventIfAllowed();
188 }
189
190 void wxTextEntry::SetSelection(long from, long to)
191 {
192 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
193
194 GetTextPeer()->SetSelection( from , to ) ;
195 }
196
197 void wxTextEntry::WriteText(const wxString& str)
198 {
199 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
200
201 {
202 EventsSuppressor noevents(this);
203 GetTextPeer()->WriteText( str );
204 }
205
206 SendTextUpdatedEventIfAllowed();
207 }
208
209 void wxTextEntry::Clear()
210 {
211 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
212
213 {
214 EventsSuppressor noevents(this);
215 GetTextPeer()->Clear();
216 }
217
218 SendTextUpdatedEventIfAllowed();
219 }
220
221 bool wxTextEntry::IsEditable() const
222 {
223 return m_editable ;
224 }
225
226 bool wxTextEntry::SendMaxLenEvent()
227 {
228 wxWindow *win = GetEditableWindow();
229 wxCHECK_MSG( win, false, "can't send an event without a window" );
230
231 wxCommandEvent event(wxEVT_TEXT_MAXLEN, win->GetId());
232
233 // do not do this as it could be very inefficient if the text control
234 // contains a lot of text and we're not using ref-counted wxString
235 // implementation -- instead, event.GetString() will query the control for
236 // its current text if needed
237 //event.SetString(win->GetValue());
238
239 event.SetEventObject(win);
240 return win->HandleWindowEvent(event);
241 }
242
243 // ----------------------------------------------------------------------------
244 // Undo/redo
245 // ----------------------------------------------------------------------------
246
247 void wxTextEntry::Undo()
248 {
249 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
250
251 if (CanUndo())
252 GetTextPeer()->Undo() ;
253 }
254
255 void wxTextEntry::Redo()
256 {
257 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
258
259 if (CanRedo())
260 GetTextPeer()->Redo() ;
261 }
262
263 bool wxTextEntry::CanUndo() const
264 {
265 if ( !IsEditable() )
266 return false ;
267
268 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
269
270 return GetTextPeer()->CanUndo() ;
271 }
272
273 bool wxTextEntry::CanRedo() const
274 {
275 if ( !IsEditable() )
276 return false ;
277
278 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
279
280 return GetTextPeer()->CanRedo() ;
281 }
282
283 wxTextWidgetImpl * wxTextEntry::GetTextPeer() const
284 {
285 wxWindow * const win = const_cast<wxTextEntry *>(this)->GetEditableWindow();
286
287 return win ? dynamic_cast<wxTextWidgetImpl *>(win->GetPeer()) : NULL;
288 }
289
290 // ----------------------------------------------------------------------------
291 // Auto-completion
292 // ----------------------------------------------------------------------------
293
294 bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString& choices)
295 {
296 wxTextCompleterFixed * const completer = new wxTextCompleterFixed;
297 completer->SetCompletions(choices);
298
299 return DoAutoCompleteCustom(completer);
300 }
301
302 bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter *completer)
303 {
304 m_completer = completer;
305
306 return true;
307 }
308
309 #endif // wxUSE_TEXTCTRL