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