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