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