]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: textctrl.cpp | |
3 | // Purpose: wxTextCtrl | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "textctrl.h" | |
14 | #endif | |
15 | ||
03e11df5 GD |
16 | #ifdef __UNIX__ |
17 | #include <sys/types.h> | |
18 | #include <sys/stat.h> | |
e9576ca5 | 19 | #else |
03e11df5 | 20 | #include <stat.h> |
e9576ca5 SC |
21 | #endif |
22 | #include <fstream.h> | |
23 | ||
03e11df5 GD |
24 | #include "wx/app.h" |
25 | #include "wx/button.h" | |
26 | #include "wx/panel.h" | |
e9576ca5 | 27 | #include "wx/textctrl.h" |
90b22aca SC |
28 | #include "wx/notebook.h" |
29 | #include "wx/tabctrl.h" | |
e9576ca5 SC |
30 | #include "wx/settings.h" |
31 | #include "wx/filefn.h" | |
32 | #include "wx/utils.h" | |
33 | ||
34 | #if defined(__BORLANDC__) && !defined(__WIN32__) | |
03e11df5 GD |
35 | #include <alloc.h> |
36 | #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__WXMAC_X__) | |
37 | #include <malloc.h> | |
e9576ca5 SC |
38 | #endif |
39 | ||
519cb848 SC |
40 | #include "wx/mac/uma.h" |
41 | ||
2f1ae414 | 42 | #if !USE_SHARED_LIBRARY |
e9576ca5 SC |
43 | IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) |
44 | ||
45 | BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) | |
46 | EVT_DROP_FILES(wxTextCtrl::OnDropFiles) | |
519cb848 | 47 | EVT_CHAR(wxTextCtrl::OnChar) |
2f1ae414 SC |
48 | EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) |
49 | EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) | |
50 | EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) | |
51 | EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) | |
52 | EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) | |
53 | ||
54 | EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) | |
55 | EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) | |
56 | EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) | |
57 | EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) | |
58 | EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) | |
e9576ca5 | 59 | END_EVENT_TABLE() |
2f1ae414 | 60 | #endif |
e9576ca5 SC |
61 | |
62 | // Text item | |
63 | wxTextCtrl::wxTextCtrl() | |
e9576ca5 | 64 | { |
e9576ca5 SC |
65 | } |
66 | ||
2f1ae414 SC |
67 | const short kVerticalMargin = 2 ; |
68 | const short kHorizontalMargin = 2 ; | |
69 | ||
e9576ca5 | 70 | bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, |
519cb848 | 71 | const wxString& st, |
e9576ca5 SC |
72 | const wxPoint& pos, |
73 | const wxSize& size, long style, | |
74 | const wxValidator& validator, | |
75 | const wxString& name) | |
76 | { | |
2f1ae414 SC |
77 | // base initialization |
78 | if ( !CreateBase(parent, id, pos, size, style, validator, name) ) | |
79 | return FALSE; | |
519cb848 SC |
80 | |
81 | wxSize mySize = size ; | |
2f1ae414 SC |
82 | if ( UMAHasAppearance() ) |
83 | { | |
84 | m_macHorizontalBorder = 5 ; // additional pixels around the real control | |
85 | m_macVerticalBorder = 5 ; | |
86 | } | |
87 | else | |
88 | { | |
89 | m_macHorizontalBorder = 0 ; // additional pixels around the real control | |
90 | m_macVerticalBorder = 0 ; | |
91 | } | |
92 | ||
519cb848 SC |
93 | |
94 | Rect bounds ; | |
95 | Str255 title ; | |
2f1ae414 | 96 | |
519cb848 SC |
97 | if ( mySize.y == -1 ) |
98 | { | |
99 | if ( UMAHasAppearance() ) | |
2f1ae414 | 100 | mySize.y = 13 ; |
519cb848 SC |
101 | else |
102 | mySize.y = 24 ; | |
2f1ae414 SC |
103 | |
104 | mySize.y += 2 * m_macVerticalBorder ; | |
519cb848 | 105 | } |
2f1ae414 | 106 | |
519cb848 SC |
107 | MacPreControlCreate( parent , id , "" , pos , mySize ,style, validator , name , &bounds , title ) ; |
108 | ||
109 | m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, | |
2f1ae414 | 110 | ( style & wxTE_PASSWORD ) ? kControlEditTextPasswordProc : kControlEditTextProc , (long) this ) ; |
519cb848 SC |
111 | MacPostControlCreate() ; |
112 | ||
113 | wxString value ; | |
114 | ||
5b781a67 SC |
115 | { |
116 | TEHandle teH ; | |
117 | long size ; | |
118 | ||
119 | UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
120 | (*teH)->lineHeight = -1 ; | |
121 | } | |
122 | ||
519cb848 SC |
123 | if( wxApp::s_macDefaultEncodingIsPC ) |
124 | value = wxMacMakeMacStringFromPC( st ) ; | |
125 | else | |
126 | value = st ; | |
2f1ae414 | 127 | UMASetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ; |
519cb848 SC |
128 | |
129 | return TRUE; | |
e9576ca5 SC |
130 | } |
131 | ||
132 | wxString wxTextCtrl::GetValue() const | |
133 | { | |
519cb848 | 134 | Size actualsize; |
2f1ae414 | 135 | UMAGetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ; |
519cb848 SC |
136 | wxBuffer[actualsize] = 0 ; |
137 | if( wxApp::s_macDefaultEncodingIsPC ) | |
138 | return wxMacMakePCStringFromMac( wxBuffer ) ; | |
139 | else | |
140 | return wxString(wxBuffer); | |
e9576ca5 SC |
141 | } |
142 | ||
2f1ae414 SC |
143 | void wxTextCtrl::GetSelection(long* from, long* to) const |
144 | { | |
145 | ControlEditTextSelectionRec selection ; | |
146 | TEHandle teH ; | |
147 | long size ; | |
148 | ||
149 | UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
150 | ||
151 | *from = (**teH).selStart; | |
152 | *to = (**teH).selEnd; | |
153 | } | |
154 | ||
519cb848 SC |
155 | void wxTextCtrl::SetValue(const wxString& st) |
156 | { | |
157 | wxString value ; | |
158 | ||
159 | if( wxApp::s_macDefaultEncodingIsPC ) | |
160 | value = wxMacMakeMacStringFromPC( st ) ; | |
161 | else | |
162 | value = st ; | |
2f1ae414 | 163 | UMASetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ; |
90b22aca SC |
164 | WindowRef window = GetMacRootWindow() ; |
165 | if ( window ) | |
166 | { | |
167 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
168 | if ( win ) | |
169 | { | |
170 | wxMacDrawingHelper help( win ) ; | |
171 | // the mac control manager always assumes to have the origin at 0,0 | |
172 | SetOrigin( 0 , 0 ) ; | |
173 | ||
174 | bool hasTabBehind = false ; | |
175 | wxWindow* parent = GetParent() ; | |
176 | while ( parent ) | |
177 | { | |
178 | if( parent->MacGetWindowData() ) | |
179 | { | |
180 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; | |
181 | break ; | |
182 | } | |
183 | ||
184 | if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
185 | { | |
186 | if ( ((wxControl*)parent)->GetMacControl() ) | |
187 | SetUpControlBackground( ((wxControl*)parent)->GetMacControl() , -1 , true ) ; | |
188 | break ; | |
189 | } | |
190 | ||
191 | parent = parent->GetParent() ; | |
192 | } | |
193 | ||
194 | UMADrawControl( m_macControl ) ; | |
195 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; | |
196 | wxDC::MacInvalidateSetup() ; | |
197 | } | |
198 | } | |
e9576ca5 SC |
199 | } |
200 | ||
e9576ca5 SC |
201 | // Clipboard operations |
202 | void wxTextCtrl::Copy() | |
203 | { | |
2f1ae414 SC |
204 | if (CanCopy()) |
205 | { | |
206 | TEHandle teH ; | |
207 | long size ; | |
519cb848 | 208 | |
2f1ae414 SC |
209 | UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; |
210 | TECopy( teH ) ; | |
211 | #if TARGET_CARBON | |
212 | OSStatus err ; | |
213 | err = ClearCurrentScrap( ); | |
214 | #else | |
215 | OSErr err ; | |
216 | err = ZeroScrap( ); | |
217 | #endif | |
218 | TEToScrap() ; | |
219 | } | |
e9576ca5 SC |
220 | } |
221 | ||
222 | void wxTextCtrl::Cut() | |
223 | { | |
2f1ae414 SC |
224 | if (CanCut()) |
225 | { | |
226 | TEHandle teH ; | |
227 | long size ; | |
519cb848 | 228 | |
2f1ae414 SC |
229 | UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; |
230 | TECut( teH ) ; | |
231 | #if TARGET_CARBON | |
232 | OSStatus err ; | |
233 | err = ClearCurrentScrap( ); | |
234 | #else | |
235 | OSErr err ; | |
236 | err = ZeroScrap( ); | |
237 | #endif | |
238 | TEToScrap() ; | |
239 | // MacInvalidateControl() ; | |
240 | } | |
e9576ca5 SC |
241 | } |
242 | ||
243 | void wxTextCtrl::Paste() | |
244 | { | |
2f1ae414 SC |
245 | if (CanPaste()) |
246 | { | |
247 | TEHandle teH ; | |
248 | long size ; | |
519cb848 | 249 | |
2f1ae414 SC |
250 | UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; |
251 | TEFromScrap() ; | |
252 | TEPaste( teH ) ; | |
90b22aca SC |
253 | WindowRef window = GetMacRootWindow() ; |
254 | if ( window ) | |
255 | { | |
256 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
257 | if ( win ) | |
258 | { | |
259 | wxMacDrawingHelper help( win ) ; | |
260 | // the mac control manager always assumes to have the origin at 0,0 | |
261 | SetOrigin( 0 , 0 ) ; | |
262 | ||
263 | bool hasTabBehind = false ; | |
264 | wxWindow* parent = GetParent() ; | |
265 | while ( parent ) | |
266 | { | |
267 | if( parent->MacGetWindowData() ) | |
268 | { | |
269 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; | |
270 | break ; | |
271 | } | |
272 | ||
273 | if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
274 | { | |
275 | if ( ((wxControl*)parent)->GetMacControl() ) | |
276 | SetUpControlBackground( ((wxControl*)parent)->GetMacControl() , -1 , true ) ; | |
277 | break ; | |
278 | } | |
279 | ||
280 | parent = parent->GetParent() ; | |
281 | } | |
282 | ||
283 | UMADrawControl( m_macControl ) ; | |
284 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; | |
285 | wxDC::MacInvalidateSetup() ; | |
286 | } | |
287 | } | |
2f1ae414 SC |
288 | } |
289 | } | |
290 | ||
291 | bool wxTextCtrl::CanCopy() const | |
292 | { | |
293 | // Can copy if there's a selection | |
294 | long from, to; | |
295 | GetSelection(& from, & to); | |
296 | return (from != to); | |
297 | } | |
298 | ||
299 | bool wxTextCtrl::CanCut() const | |
300 | { | |
301 | // Can cut if there's a selection | |
302 | long from, to; | |
303 | GetSelection(& from, & to); | |
304 | return (from != to); | |
305 | } | |
306 | ||
307 | bool wxTextCtrl::CanPaste() const | |
308 | { | |
309 | if (!IsEditable()) | |
310 | return FALSE; | |
311 | ||
312 | long offset ; | |
313 | #if TARGET_CARBON | |
314 | OSStatus err = noErr; | |
315 | ScrapRef scrapRef; | |
316 | ||
317 | err = GetCurrentScrap( &scrapRef ); | |
318 | if ( err != noTypeErr && err != memFullErr ) | |
319 | { | |
320 | ScrapFlavorFlags flavorFlags; | |
321 | Size byteCount; | |
322 | ||
323 | if (( err = GetScrapFlavorFlags( scrapRef, 'TEXT', &flavorFlags )) == noErr) | |
324 | { | |
325 | if (( err = GetScrapFlavorSize( scrapRef, 'TEXT', &byteCount )) == noErr) | |
326 | { | |
327 | return TRUE ; | |
328 | } | |
329 | } | |
330 | } | |
331 | return FALSE; | |
332 | ||
333 | #else | |
334 | if ( GetScrap( NULL , 'TEXT' , &offset ) > 0 ) | |
335 | { | |
336 | return TRUE ; | |
337 | } | |
338 | #endif | |
339 | return FALSE ; | |
e9576ca5 SC |
340 | } |
341 | ||
342 | void wxTextCtrl::SetEditable(bool editable) | |
343 | { | |
519cb848 SC |
344 | if ( editable ) |
345 | UMAActivateControl( m_macControl ) ; | |
346 | else | |
347 | UMADeactivateControl( m_macControl ) ; | |
e9576ca5 SC |
348 | } |
349 | ||
350 | void wxTextCtrl::SetInsertionPoint(long pos) | |
351 | { | |
519cb848 | 352 | SetSelection( pos , pos ) ; |
e9576ca5 SC |
353 | } |
354 | ||
355 | void wxTextCtrl::SetInsertionPointEnd() | |
356 | { | |
357 | long pos = GetLastPosition(); | |
358 | SetInsertionPoint(pos); | |
359 | } | |
360 | ||
361 | long wxTextCtrl::GetInsertionPoint() const | |
362 | { | |
519cb848 SC |
363 | ControlEditTextSelectionRec selection ; |
364 | TEHandle teH ; | |
365 | long size ; | |
366 | ||
367 | UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
368 | // UMAGetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ; | |
369 | return (**teH).selStart ; | |
e9576ca5 SC |
370 | } |
371 | ||
372 | long wxTextCtrl::GetLastPosition() const | |
373 | { | |
519cb848 SC |
374 | ControlEditTextSelectionRec selection ; |
375 | TEHandle teH ; | |
376 | long size ; | |
377 | ||
378 | UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
379 | ||
380 | // UMAGetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ; | |
381 | return (**teH).teLength ; | |
e9576ca5 SC |
382 | } |
383 | ||
384 | void wxTextCtrl::Replace(long from, long to, const wxString& value) | |
385 | { | |
519cb848 SC |
386 | TEHandle teH ; |
387 | long size ; | |
388 | ||
389 | ControlEditTextSelectionRec selection ; | |
390 | ||
391 | selection.selStart = from ; | |
392 | selection.selEnd = to ; | |
393 | UMASetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ; | |
394 | UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
395 | TESetSelect( from , to , teH ) ; | |
396 | TEDelete( teH ) ; | |
397 | TEInsert( value , value.Length() , teH ) ; | |
398 | // MacInvalidateControl() ; | |
e9576ca5 SC |
399 | } |
400 | ||
401 | void wxTextCtrl::Remove(long from, long to) | |
402 | { | |
519cb848 SC |
403 | TEHandle teH ; |
404 | long size ; | |
405 | ||
406 | ControlEditTextSelectionRec selection ; | |
407 | ||
408 | selection.selStart = from ; | |
409 | selection.selEnd = to ; | |
410 | UMASetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ; | |
411 | UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
412 | TEDelete( teH ) ; | |
413 | // MacInvalidateControl() ; | |
e9576ca5 SC |
414 | } |
415 | ||
416 | void wxTextCtrl::SetSelection(long from, long to) | |
417 | { | |
519cb848 SC |
418 | ControlEditTextSelectionRec selection ; |
419 | TEHandle teH ; | |
420 | long size ; | |
421 | ||
422 | UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
423 | ||
424 | selection.selStart = from ; | |
425 | selection.selEnd = to ; | |
426 | ||
427 | UMASetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ; | |
428 | TESetSelect( selection.selStart , selection.selEnd , teH ) ; | |
e9576ca5 SC |
429 | } |
430 | ||
431 | bool wxTextCtrl::LoadFile(const wxString& file) | |
432 | { | |
2f1ae414 | 433 | if ( wxTextCtrlBase::LoadFile(file) ) |
e9576ca5 | 434 | { |
2f1ae414 | 435 | return TRUE; |
e9576ca5 | 436 | } |
e9576ca5 SC |
437 | |
438 | return FALSE; | |
439 | } | |
440 | ||
441 | void wxTextCtrl::WriteText(const wxString& text) | |
442 | { | |
519cb848 SC |
443 | TEHandle teH ; |
444 | long size ; | |
445 | ||
446 | memcpy( wxBuffer, text , text.Length() ) ; | |
447 | wxBuffer[text.Length() ] = 0 ; | |
448 | // wxMacConvertNewlines( wxBuffer , wxBuffer ) ; | |
449 | ||
450 | UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
451 | ||
452 | TEInsert( wxBuffer , strlen( wxBuffer) , teH ) ; | |
453 | Refresh() ; | |
e9576ca5 SC |
454 | } |
455 | ||
13c21be5 HH |
456 | void wxTextCtrl::AppendText(const wxString& text) |
457 | { | |
519cb848 SC |
458 | SetInsertionPointEnd(); |
459 | WriteText(text); | |
13c21be5 HH |
460 | } |
461 | ||
e9576ca5 SC |
462 | void wxTextCtrl::Clear() |
463 | { | |
2f1ae414 SC |
464 | UMASetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ; |
465 | Refresh() ; | |
e9576ca5 SC |
466 | } |
467 | ||
468 | bool wxTextCtrl::IsModified() const | |
469 | { | |
519cb848 | 470 | return TRUE; |
e9576ca5 SC |
471 | } |
472 | ||
2f1ae414 SC |
473 | bool wxTextCtrl::IsEditable() const |
474 | { | |
475 | return IsEnabled(); | |
476 | } | |
477 | ||
478 | bool wxTextCtrl::AcceptsFocus() const | |
479 | { | |
480 | // we don't want focus if we can't be edited | |
481 | return IsEditable() && wxControl::AcceptsFocus(); | |
482 | } | |
483 | ||
484 | wxSize wxTextCtrl::DoGetBestSize() const | |
485 | { | |
486 | int wText = 100 ; | |
487 | ||
488 | int hText ; | |
489 | if ( UMAHasAppearance() ) | |
490 | hText = 13 ; | |
491 | else | |
492 | hText = 24 ; | |
493 | hText += 2 * m_macHorizontalBorder ; | |
494 | /* | |
495 | int cx, cy; | |
496 | wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); | |
497 | ||
498 | int wText = DEFAULT_ITEM_WIDTH; | |
499 | ||
500 | int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); | |
501 | ||
502 | return wxSize(wText, hText); | |
503 | */ | |
504 | if ( m_windowStyle & wxTE_MULTILINE ) | |
505 | { | |
506 | hText *= wxMin(GetNumberOfLines(), 5); | |
507 | } | |
508 | //else: for single line control everything is ok | |
509 | return wxSize(wText, hText); | |
510 | } | |
511 | ||
512 | // ---------------------------------------------------------------------------- | |
513 | // Undo/redo | |
514 | // ---------------------------------------------------------------------------- | |
515 | ||
516 | void wxTextCtrl::Undo() | |
517 | { | |
518 | if (CanUndo()) | |
519 | { | |
520 | } | |
521 | } | |
522 | ||
523 | void wxTextCtrl::Redo() | |
524 | { | |
525 | if (CanRedo()) | |
526 | { | |
527 | } | |
528 | } | |
529 | ||
530 | bool wxTextCtrl::CanUndo() const | |
531 | { | |
532 | return FALSE ; | |
533 | } | |
534 | ||
535 | bool wxTextCtrl::CanRedo() const | |
536 | { | |
537 | return FALSE ; | |
538 | } | |
539 | ||
e9576ca5 SC |
540 | // Makes 'unmodified' |
541 | void wxTextCtrl::DiscardEdits() | |
542 | { | |
543 | // TODO | |
544 | } | |
545 | ||
546 | int wxTextCtrl::GetNumberOfLines() const | |
547 | { | |
548 | // TODO | |
549 | return 0; | |
550 | } | |
551 | ||
552 | long wxTextCtrl::XYToPosition(long x, long y) const | |
553 | { | |
554 | // TODO | |
555 | return 0; | |
556 | } | |
557 | ||
2f1ae414 | 558 | bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const |
e9576ca5 | 559 | { |
2f1ae414 | 560 | return FALSE ; |
e9576ca5 SC |
561 | } |
562 | ||
563 | void wxTextCtrl::ShowPosition(long pos) | |
564 | { | |
565 | // TODO | |
566 | } | |
567 | ||
568 | int wxTextCtrl::GetLineLength(long lineNo) const | |
569 | { | |
519cb848 | 570 | return GetValue().Length(); |
e9576ca5 SC |
571 | } |
572 | ||
573 | wxString wxTextCtrl::GetLineText(long lineNo) const | |
574 | { | |
519cb848 | 575 | return GetValue(); |
e9576ca5 SC |
576 | } |
577 | ||
578 | /* | |
579 | * Text item | |
580 | */ | |
581 | ||
582 | void wxTextCtrl::Command(wxCommandEvent & event) | |
583 | { | |
584 | SetValue (event.GetString()); | |
585 | ProcessCommand (event); | |
586 | } | |
587 | ||
588 | void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) | |
589 | { | |
590 | // By default, load the first file into the text window. | |
591 | if (event.GetNumberOfFiles() > 0) | |
592 | { | |
593 | LoadFile(event.GetFiles()[0]); | |
594 | } | |
595 | } | |
596 | ||
519cb848 SC |
597 | void wxTextCtrl::OnChar(wxKeyEvent& event) |
598 | { | |
2f1ae414 | 599 | switch ( event.KeyCode() ) |
519cb848 SC |
600 | { |
601 | case WXK_RETURN: | |
2f1ae414 SC |
602 | if (m_windowStyle & wxPROCESS_ENTER) |
603 | { | |
e7549107 SC |
604 | wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); |
605 | event.SetEventObject( this ); | |
606 | if ( GetEventHandler()->ProcessEvent(event) ) | |
607 | return; | |
2f1ae414 SC |
608 | } |
609 | if ( !(m_windowStyle & wxTE_MULTILINE) ) | |
610 | { | |
611 | wxWindow *parent = GetParent(); | |
612 | wxPanel *panel = wxDynamicCast(parent, wxPanel); | |
613 | while ( parent != NULL && panel == NULL ) | |
614 | { | |
615 | parent = parent->GetParent() ; | |
616 | panel = wxDynamicCast(parent, wxPanel); | |
617 | } | |
618 | if ( panel && panel->GetDefaultItem() ) | |
619 | { | |
620 | wxButton *def = panel->GetDefaultItem() ; | |
621 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); | |
622 | event.SetEventObject(def); | |
623 | def->Command(event); | |
624 | event.Skip() ; | |
625 | return ; | |
626 | } | |
519cb848 | 627 | } |
e7549107 SC |
628 | //else: multiline controls need Enter for themselves |
629 | ||
519cb848 | 630 | break; |
2f1ae414 | 631 | |
519cb848 | 632 | case WXK_TAB: |
e7549107 SC |
633 | // always produce navigation event - even if we process TAB |
634 | // ourselves the fact that we got here means that the user code | |
635 | // decided to skip processing of this TAB - probably to let it | |
636 | // do its default job. | |
519cb848 SC |
637 | { |
638 | wxNavigationKeyEvent eventNav; | |
639 | eventNav.SetDirection(!event.ShiftDown()); | |
2f1ae414 | 640 | eventNav.SetWindowChange(event.ControlDown()); |
519cb848 | 641 | eventNav.SetEventObject(this); |
e7549107 | 642 | |
2f1ae414 | 643 | if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) |
519cb848 | 644 | return; |
2f1ae414 SC |
645 | event.Skip() ; |
646 | return ; | |
519cb848 SC |
647 | } |
648 | break; | |
649 | } | |
e7549107 | 650 | |
2f1ae414 SC |
651 | EventRecord *ev = wxTheApp->MacGetCurrentEvent() ; |
652 | short keycode ; | |
653 | short keychar ; | |
654 | keychar = short(ev->message & charCodeMask); | |
655 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
656 | UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ; | |
657 | if ( keychar >= 0x20 || event.KeyCode() == WXK_RETURN) | |
658 | { | |
659 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); | |
660 | event.SetString( GetValue() ) ; | |
661 | event.SetEventObject( this ); | |
662 | GetEventHandler()->ProcessEvent(event); | |
663 | } | |
664 | ||
e9576ca5 SC |
665 | } |
666 | ||
2f1ae414 SC |
667 | // ---------------------------------------------------------------------------- |
668 | // standard handlers for standard edit menu events | |
669 | // ---------------------------------------------------------------------------- | |
670 | ||
671 | void wxTextCtrl::OnCut(wxCommandEvent& event) | |
672 | { | |
673 | Cut(); | |
e9576ca5 SC |
674 | } |
675 | ||
2f1ae414 | 676 | void wxTextCtrl::OnCopy(wxCommandEvent& event) |
e9576ca5 | 677 | { |
2f1ae414 | 678 | Copy(); |
e9576ca5 | 679 | } |
e9576ca5 | 680 | |
2f1ae414 | 681 | void wxTextCtrl::OnPaste(wxCommandEvent& event) |
e9576ca5 | 682 | { |
2f1ae414 | 683 | Paste(); |
e9576ca5 SC |
684 | } |
685 | ||
2f1ae414 | 686 | void wxTextCtrl::OnUndo(wxCommandEvent& event) |
e9576ca5 | 687 | { |
2f1ae414 | 688 | Undo(); |
e9576ca5 SC |
689 | } |
690 | ||
2f1ae414 | 691 | void wxTextCtrl::OnRedo(wxCommandEvent& event) |
e9576ca5 | 692 | { |
2f1ae414 | 693 | Redo(); |
e9576ca5 SC |
694 | } |
695 | ||
2f1ae414 | 696 | void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) |
e9576ca5 | 697 | { |
2f1ae414 | 698 | event.Enable( CanCut() ); |
e9576ca5 SC |
699 | } |
700 | ||
2f1ae414 | 701 | void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) |
e9576ca5 | 702 | { |
2f1ae414 | 703 | event.Enable( CanCopy() ); |
e9576ca5 SC |
704 | } |
705 | ||
2f1ae414 | 706 | void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) |
e9576ca5 | 707 | { |
2f1ae414 SC |
708 | event.Enable( CanPaste() ); |
709 | } | |
e9576ca5 | 710 | |
2f1ae414 SC |
711 | void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) |
712 | { | |
713 | event.Enable( CanUndo() ); | |
714 | } | |
715 | ||
716 | void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) | |
717 | { | |
718 | event.Enable( CanRedo() ); | |
e9576ca5 SC |
719 | } |
720 |