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