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