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