]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/textctrl.cpp
The code in wxMac's listbox was too ambitious in filtering
[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
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)
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
ed8c2780
RR
127 m_macControl = ::NewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1,
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) ) ;
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 {
198 ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
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 ) ;
213 ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
214 }
215 }
e9576ca5
SC
216}
217
e9576ca5
SC
218// Clipboard operations
219void wxTextCtrl::Copy()
220{
2f1ae414
SC
221 if (CanCopy())
222 {
ed8c2780
RR
223 TEHandle teH ;
224 long size ;
519cb848 225
ed8c2780
RR
226 ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
227 TECopy( teH ) ;
2f1ae414 228#if TARGET_CARBON
ed8c2780
RR
229 OSStatus err ;
230 err = ClearCurrentScrap( );
2f1ae414 231#else
ed8c2780
RR
232 OSErr err ;
233 err = ZeroScrap( );
2f1ae414 234#endif
ed8c2780
RR
235 TEToScrap() ;
236 }
e9576ca5
SC
237}
238
239void wxTextCtrl::Cut()
240{
2f1ae414
SC
241 if (CanCut())
242 {
ed8c2780
RR
243 TEHandle teH ;
244 long size ;
519cb848 245
ed8c2780
RR
246 ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
247 TECut( teH ) ;
2f1ae414 248#if TARGET_CARBON
ed8c2780
RR
249 OSStatus err ;
250 err = ClearCurrentScrap( );
2f1ae414 251#else
ed8c2780
RR
252 OSErr err ;
253 err = ZeroScrap( );
2f1ae414 254#endif
ed8c2780
RR
255 TEToScrap() ;
256 // MacInvalidateControl() ;
257 }
e9576ca5
SC
258}
259
260void wxTextCtrl::Paste()
261{
2f1ae414
SC
262 if (CanPaste())
263 {
ed8c2780
RR
264 TEHandle teH ;
265 long size ;
519cb848 266
ed8c2780
RR
267 ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
268 TEFromScrap() ;
269 TEPaste( teH ) ;
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 {
286 ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
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 ) ;
301 ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
302 }
303 }
304 }
2f1ae414
SC
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
ed8c2780 328 long offset ;
2f1ae414 329#if TARGET_CARBON
ed8c2780
RR
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
2f1ae414 349#else
ed8c2780
RR
350 if ( GetScrap( NULL , 'TEXT' , &offset ) > 0 )
351 {
352 return TRUE ;
353 }
2f1ae414 354#endif
ed8c2780 355 return FALSE ;
e9576ca5
SC
356}
357
358void wxTextCtrl::SetEditable(bool editable)
359{
519cb848 360 if ( editable )
ed8c2780 361 UMAActivateControl( m_macControl ) ;
519cb848 362 else
ed8c2780 363 UMADeactivateControl( m_macControl ) ;
e9576ca5
SC
364}
365
366void wxTextCtrl::SetInsertionPoint(long pos)
367{
ed8c2780 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{
ed8c2780
RR
402 TEHandle teH ;
403 long size ;
519cb848 404
ed8c2780 405 ControlEditTextSelectionRec selection ;
519cb848 406
ed8c2780
RR
407 selection.selStart = from ;
408 selection.selEnd = to ;
409 ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
410 ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
411 TESetSelect( from , to , teH ) ;
412 TEDelete( teH ) ;
413 TEInsert( value , value.Length() , teH ) ;
414 Refresh() ;
e9576ca5
SC
415}
416
417void wxTextCtrl::Remove(long from, long to)
418{
ed8c2780
RR
419 TEHandle teH ;
420 long size ;
519cb848 421
ed8c2780 422 ControlEditTextSelectionRec selection ;
519cb848 423
ed8c2780
RR
424 selection.selStart = from ;
425 selection.selEnd = to ;
426 ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
427 ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
428 TEDelete( teH ) ;
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
ed8c2780
RR
462 memcpy( wxBuffer, text , text.Length() ) ;
463 wxBuffer[text.Length() ] = 0 ;
519cb848
SC
464// wxMacConvertNewlines( wxBuffer , wxBuffer ) ;
465
72055702 466 ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
519cb848 467
ed8c2780
RR
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{
ed8c2780
RR
480 ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
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 ;
ed8c2780 503
2f1ae414 504 int hText ;
ed8c2780
RR
505 if ( UMAHasAppearance() )
506 hText = 13 ;
507 else
508 hText = 24 ;
509 hText += 2 * m_macHorizontalBorder ;
2f1ae414
SC
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{
ed8c2780
RR
564 Size actualsize;
565 ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
566
567 int count = 1;
568 for (int i = 0; i < actualsize; i++)
569 {
570 if (wxBuffer[i] == '\r') count++;
571 }
572
c4c1fab9 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{
ed8c2780
RR
594 Size actualsize;
595 ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
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
c4c1fab9 616 return 0;
e9576ca5
SC
617}
618
619wxString wxTextCtrl::GetLineText(long lineNo) const
620{
ed8c2780
RR
621 Size actualsize;
622 ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
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 {
635 if (wxBuffer[j] == '\r')
636 return tmp;
637
638 tmp += wxBuffer[j];
639 }
640
641 return tmp;
642 }
643 if (wxBuffer[i] == '\r') count++;
644 }
645
c4c1fab9 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
ed8c2780 668void wxTextCtrl::OnChar(wxKeyEvent& key_event)
519cb848 669{
ed8c2780
RR
670 bool eat_key = FALSE;
671
672 switch ( key_event.KeyCode() )
519cb848
SC
673 {
674 case WXK_RETURN:
ed8c2780
RR
675 if (m_windowStyle & wxPROCESS_ENTER)
676 {
e7549107
SC
677 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
678 event.SetEventObject( this );
ed8c2780 679 event.SetString( GetValue() );
e7549107
SC
680 if ( GetEventHandler()->ProcessEvent(event) )
681 return;
ed8c2780 682 }
2f1ae414
SC
683 if ( !(m_windowStyle & wxTE_MULTILINE) )
684 {
ed8c2780
RR
685 wxWindow *parent = GetParent();
686 wxPanel *panel = wxDynamicCast(parent, wxPanel);
687 while ( parent != NULL && panel == NULL )
688 {
689 parent = parent->GetParent() ;
690 panel = wxDynamicCast(parent, wxPanel);
691 }
692 if ( panel && panel->GetDefaultItem() )
693 {
c1fb8167
SC
694 wxButton *def = wxDynamicCast(panel->GetDefaultItem(),
695 wxButton);
ed8c2780
RR
696 if ( def && def->IsEnabled() )
697 {
698 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
699 event.SetEventObject(def);
700 def->Command(event);
701 return ;
702 }
703 }
704
705 // this will make wxWindows eat the ENTER key so that
706 // we actually prevent line wrapping in a single line
707 // text control
708 eat_key = TRUE;
519cb848 709 }
e7549107 710
519cb848 711 break;
2f1ae414 712
519cb848 713 case WXK_TAB:
e7549107
SC
714 // always produce navigation event - even if we process TAB
715 // ourselves the fact that we got here means that the user code
716 // decided to skip processing of this TAB - probably to let it
717 // do its default job.
519cb848
SC
718 {
719 wxNavigationKeyEvent eventNav;
ed8c2780
RR
720 eventNav.SetDirection(!key_event.ShiftDown());
721 eventNav.SetWindowChange(key_event.ControlDown());
519cb848 722 eventNav.SetEventObject(this);
e7549107 723
2f1ae414 724 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) )
519cb848 725 return;
ed8c2780
RR
726
727 key_event.Skip() ;
728 return;
519cb848
SC
729 }
730 break;
731 }
ed8c2780
RR
732
733 EventRecord *ev = wxTheApp->MacGetCurrentEvent();
734 short keychar = short(ev->message & charCodeMask);
735 if (!eat_key)
736 {
737 short keycode = short(ev->message & keyCodeMask) >> 8 ;
738 ::HandleControlKey( m_macControl , keycode , keychar , ev->modifiers );
739 }
740 if ( keychar >= 0x20 ||
741 key_event.KeyCode() == WXK_RETURN ||
742 key_event.KeyCode() == WXK_DELETE ||
743 key_event.KeyCode() == WXK_BACK)
744 {
2f1ae414
SC
745 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
746 event.SetString( GetValue() ) ;
747 event.SetEventObject( this );
748 GetEventHandler()->ProcessEvent(event);
ed8c2780 749 }
e9576ca5
SC
750}
751
2f1ae414
SC
752// ----------------------------------------------------------------------------
753// standard handlers for standard edit menu events
754// ----------------------------------------------------------------------------
755
756void wxTextCtrl::OnCut(wxCommandEvent& event)
757{
758 Cut();
e9576ca5
SC
759}
760
2f1ae414 761void wxTextCtrl::OnCopy(wxCommandEvent& event)
e9576ca5 762{
2f1ae414 763 Copy();
e9576ca5 764}
e9576ca5 765
2f1ae414 766void wxTextCtrl::OnPaste(wxCommandEvent& event)
e9576ca5 767{
2f1ae414 768 Paste();
e9576ca5
SC
769}
770
2f1ae414 771void wxTextCtrl::OnUndo(wxCommandEvent& event)
e9576ca5 772{
2f1ae414 773 Undo();
e9576ca5
SC
774}
775
2f1ae414 776void wxTextCtrl::OnRedo(wxCommandEvent& event)
e9576ca5 777{
2f1ae414 778 Redo();
e9576ca5
SC
779}
780
2f1ae414 781void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
e9576ca5 782{
2f1ae414 783 event.Enable( CanCut() );
e9576ca5
SC
784}
785
2f1ae414 786void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
e9576ca5 787{
2f1ae414 788 event.Enable( CanCopy() );
e9576ca5
SC
789}
790
2f1ae414 791void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
e9576ca5 792{
2f1ae414
SC
793 event.Enable( CanPaste() );
794}
e9576ca5 795
2f1ae414
SC
796void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
797{
798 event.Enable( CanUndo() );
799}
800
801void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
802{
803 event.Enable( CanRedo() );
e9576ca5
SC
804}
805
72055702
SC
806#else
807
808#if !TARGET_CARBON
ed8c2780 809#define GetControlOwner( control ) (**control).contrlOwner
72055702
SC
810#endif
811
812//todo add access to global event record
813
814EventRecord event ;
815
816static EventRecord *GetCurrentEventRecord()
817{
818 return &event ;
819}
820
821// CS:We will replace the TextEdit by using the MultiLanguageTextEngine based on the following code written by apple
822
823/*
824 File: mUPControl.c
825
826 Description:
827 mUPControl implementation.
828
829 Copyright:
830