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