]>
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 | WindowRef window = MacGetRootWindow() ; | |
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 | ||
191 | bool hasTabBehind = false ; | |
192 | wxWindow* parent = GetParent() ; | |
193 | while ( parent ) | |
194 | { | |
195 | if( parent->IsTopLevel() ) | |
196 | { | |
197 | // ::SetThemeWindowBackground( win->MacGetRootWindow() , kThemeBrushDialogBackgroundActive , false ) ; | |
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 ) ; | |
212 | // ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; | |
213 | } | |
214 | } | |
215 | } | |
216 | ||
217 | // Clipboard operations | |
218 | void wxTextCtrl::Copy() | |
219 | { | |
220 | if (CanCopy()) | |
221 | { | |
222 | TEHandle teH ; | |
223 | long size ; | |
224 | ||
225 | ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
226 | TECopy( teH ) ; | |
227 | ClearCurrentScrap(); | |
228 | TEToScrap() ; | |
229 | } | |
230 | } | |
231 | ||
232 | void wxTextCtrl::Cut() | |
233 | { | |
234 | if (CanCut()) | |
235 | { | |
236 | TEHandle teH ; | |
237 | long size ; | |
238 | ||
239 | ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
240 | TECut( teH ) ; | |
241 | ClearCurrentScrap(); | |
242 | TEToScrap() ; | |
243 | // MacInvalidateControl() ; | |
244 | } | |
245 | } | |
246 | ||
247 | void wxTextCtrl::Paste() | |
248 | { | |
249 | if (CanPaste()) | |
250 | { | |
251 | TEHandle teH ; | |
252 | long size ; | |
253 | ||
254 | ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
255 | TEFromScrap() ; | |
256 | TEPaste( teH ) ; | |
257 | WindowRef window = MacGetRootWindow() ; | |
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 | |
265 | ||
266 | bool hasTabBehind = false ; | |
267 | wxWindow* parent = GetParent() ; | |
268 | while ( parent ) | |
269 | { | |
270 | if( parent->IsTopLevel() ) | |
271 | { | |
272 | // ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; | |
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 ) ; | |
287 | // ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; | |
288 | } | |
289 | } | |
290 | } | |
291 | } | |
292 | ||
293 | bool 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 | ||
301 | bool 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 | ||
309 | bool wxTextCtrl::CanPaste() const | |
310 | { | |
311 | if (!IsEditable()) | |
312 | return FALSE; | |
313 | ||
314 | long offset ; | |
315 | #if TARGET_CARBON | |
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 | ||
335 | #else | |
336 | if ( GetScrap( NULL , 'TEXT' , &offset ) > 0 ) | |
337 | { | |
338 | return TRUE ; | |
339 | } | |
340 | #endif | |
341 | return FALSE ; | |
342 | } | |
343 | ||
344 | void wxTextCtrl::SetEditable(bool editable) | |
345 | { | |
346 | if ( editable ) | |
347 | UMAActivateControl( m_macControl ) ; | |
348 | else | |
349 | UMADeactivateControl( m_macControl ) ; | |
350 | } | |
351 | ||
352 | void wxTextCtrl::SetInsertionPoint(long pos) | |
353 | { | |
354 | SetSelection( pos , pos ) ; | |
355 | } | |
356 | ||
357 | void wxTextCtrl::SetInsertionPointEnd() | |
358 | { | |
359 | long pos = GetLastPosition(); | |
360 | SetInsertionPoint(pos); | |
361 | } | |
362 | ||
363 | long wxTextCtrl::GetInsertionPoint() const | |
364 | { | |
365 | ControlEditTextSelectionRec selection ; | |
366 | TEHandle teH ; | |
367 | long size ; | |
368 | ||
369 | ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
370 | // ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ; | |
371 | return (**teH).selStart ; | |
372 | } | |
373 | ||
374 | long wxTextCtrl::GetLastPosition() const | |
375 | { | |
376 | ControlEditTextSelectionRec selection ; | |
377 | TEHandle teH ; | |
378 | long size ; | |
379 | ||
380 | ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
381 | ||
382 | // ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ; | |
383 | return (**teH).teLength ; | |
384 | } | |
385 | ||
386 | void wxTextCtrl::Replace(long from, long to, const wxString& value) | |
387 | { | |
388 | TEHandle teH ; | |
389 | long size ; | |
390 | ||
391 | ControlEditTextSelectionRec selection ; | |
392 | ||
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() ; | |
401 | } | |
402 | ||
403 | void wxTextCtrl::Remove(long from, long to) | |
404 | { | |
405 | TEHandle teH ; | |
406 | long size ; | |
407 | ||
408 | ControlEditTextSelectionRec selection ; | |
409 | ||
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() ; | |
416 | } | |
417 | ||
418 | void wxTextCtrl::SetSelection(long from, long to) | |
419 | { | |
420 | ControlEditTextSelectionRec selection ; | |
421 | TEHandle teH ; | |
422 | long size ; | |
423 | ||
424 | ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
425 | ||
426 | selection.selStart = from ; | |
427 | selection.selEnd = to ; | |
428 | ||
429 | ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ; | |
430 | TESetSelect( selection.selStart , selection.selEnd , teH ) ; | |
431 | } | |
432 | ||
433 | bool wxTextCtrl::LoadFile(const wxString& file) | |
434 | { | |
435 | if ( wxTextCtrlBase::LoadFile(file) ) | |
436 | { | |
437 | return TRUE; | |
438 | } | |
439 | ||
440 | return FALSE; | |
441 | } | |
442 | ||
443 | void wxTextCtrl::WriteText(const wxString& text) | |
444 | { | |
445 | TEHandle teH ; | |
446 | long size ; | |
447 | ||
448 | memcpy( wxBuffer, text , text.Length() ) ; | |
449 | wxBuffer[text.Length() ] = 0 ; | |
450 | // wxMacConvertNewlines( wxBuffer , wxBuffer ) ; | |
451 | ||
452 | ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; | |
453 | ||
454 | TEInsert( wxBuffer , strlen( wxBuffer) , teH ) ; | |
455 | Refresh() ; | |
456 | } | |
457 | ||
458 | void wxTextCtrl::AppendText(const wxString& text) | |
459 | { | |
460 | SetInsertionPointEnd(); | |
461 | WriteText(text); | |
462 | } | |
463 | ||
464 | void wxTextCtrl::Clear() | |
465 | { | |
466 | ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ; | |
467 | Refresh() ; | |
468 | } | |
469 | ||
470 | bool wxTextCtrl::IsModified() const | |
471 | { | |
472 | return TRUE; | |
473 | } | |
474 | ||
475 | bool wxTextCtrl::IsEditable() const | |
476 | { | |
477 | return IsEnabled(); | |
478 | } | |
479 | ||
480 | bool wxTextCtrl::AcceptsFocus() const | |
481 | { | |
482 | // we don't want focus if we can't be edited | |
483 | return IsEditable() && wxControl::AcceptsFocus(); | |
484 | } | |
485 | ||
486 | wxSize wxTextCtrl::DoGetBestSize() const | |
487 | { | |
488 | int wText = 100 ; | |
489 | ||
490 | int hText ; | |
491 | if ( UMAHasAppearance() ) | |
492 | hText = 13 ; | |
493 | else | |
494 | hText = 24 ; | |
495 | hText += 2 * m_macHorizontalBorder ; | |
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 | ||
518 | void wxTextCtrl::Undo() | |
519 | { | |
520 | if (CanUndo()) | |
521 | { | |
522 | } | |
523 | } | |
524 | ||
525 | void wxTextCtrl::Redo() | |
526 | { | |
527 | if (CanRedo()) | |
528 | { | |
529 | } | |
530 | } | |
531 | ||
532 | bool wxTextCtrl::CanUndo() const | |
533 | { | |
534 | return FALSE ; | |
535 | } | |
536 | ||
537 | bool wxTextCtrl::CanRedo() const | |
538 | { | |
539 | return FALSE ; | |
540 | } | |
541 | ||
542 | // Makes 'unmodified' | |
543 | void wxTextCtrl::DiscardEdits() | |
544 | { | |
545 | // TODO | |
546 | } | |
547 | ||
548 | int wxTextCtrl::GetNumberOfLines() const | |
549 | { | |
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 | ||
559 | return count; | |
560 | } | |
561 | ||
562 | long wxTextCtrl::XYToPosition(long x, long y) const | |
563 | { | |
564 | // TODO | |
565 | return 0; | |
566 | } | |
567 | ||
568 | bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const | |
569 | { | |
570 | return FALSE ; | |
571 | } | |
572 | ||
573 | void wxTextCtrl::ShowPosition(long pos) | |
574 | { | |
575 | // TODO | |
576 | } | |
577 | ||
578 | int wxTextCtrl::GetLineLength(long lineNo) const | |
579 | { | |
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 | ||
602 | return 0; | |
603 | } | |
604 | ||
605 | wxString wxTextCtrl::GetLineText(long lineNo) const | |
606 | { | |
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 | ||
632 | return wxString(""); | |
633 | } | |
634 | ||
635 | /* | |
636 | * Text item | |
637 | */ | |
638 | ||
639 | void wxTextCtrl::Command(wxCommandEvent & event) | |
640 | { | |
641 | SetValue (event.GetString()); | |
642 | ProcessCommand (event); | |
643 | } | |
644 | ||
645 | void 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 | ||
654 | void wxTextCtrl::OnChar(wxKeyEvent& key_event) | |
655 | { | |
656 | bool eat_key = FALSE; | |
657 | ||
658 | switch ( key_event.KeyCode() ) | |
659 | { | |
660 | case WXK_RETURN: | |
661 | if (m_windowStyle & wxPROCESS_ENTER) | |
662 | { | |
663 | wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); | |
664 | event.SetEventObject( this ); | |
665 | event.SetString( GetValue() ); | |
666 | if ( GetEventHandler()->ProcessEvent(event) ) | |
667 | return; | |
668 | } | |
669 | if ( !(m_windowStyle & wxTE_MULTILINE) ) | |
670 | { | |
671 | wxWindow *parent = GetParent(); | |
672 | while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) { | |
673 | parent = parent->GetParent() ; | |
674 | } | |
675 | if ( parent && parent->GetDefaultItem() ) | |
676 | { | |
677 | wxButton *def = wxDynamicCast(parent->GetDefaultItem(), | |
678 | wxButton); | |
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 ; | |
685 | } | |
686 | } | |
687 | ||
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; | |
692 | } | |
693 | ||
694 | break; | |
695 | ||
696 | case WXK_TAB: | |
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. | |
701 | { | |
702 | wxNavigationKeyEvent eventNav; | |
703 | eventNav.SetDirection(!key_event.ShiftDown()); | |
704 | eventNav.SetWindowChange(key_event.ControlDown()); | |
705 | eventNav.SetEventObject(this); | |
706 | ||
707 | if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) | |
708 | return; | |
709 | ||
710 | key_event.Skip() ; | |
711 | return; | |
712 | } | |
713 | break; | |
714 | } | |
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 | { | |
728 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); | |
729 | event.SetString( GetValue() ) ; | |
730 | event.SetEventObject( this ); | |
731 | GetEventHandler()->ProcessEvent(event); | |
732 | } | |
733 | } | |
734 | ||
735 | // ---------------------------------------------------------------------------- | |
736 | // standard handlers for standard edit menu events | |
737 | // ---------------------------------------------------------------------------- | |
738 | ||
739 | void wxTextCtrl::OnCut(wxCommandEvent& event) | |
740 | { | |
741 | Cut(); | |
742 | } | |
743 | ||
744 | void wxTextCtrl::OnCopy(wxCommandEvent& event) | |
745 | { | |
746 | Copy(); | |
747 | } | |
748 | ||
749 | void wxTextCtrl::OnPaste(wxCommandEvent& event) | |
750 | { | |
751 | Paste(); | |
752 | } | |
753 | ||
754 | void wxTextCtrl::OnUndo(wxCommandEvent& event) | |
755 | { | |
756 | Undo(); | |
757 | } | |
758 | ||
759 | void wxTextCtrl::OnRedo(wxCommandEvent& event) | |
760 | { | |
761 | Redo(); | |
762 | } | |
763 | ||
764 | void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) | |
765 | { | |
766 | event.Enable( CanCut() ); | |
767 | } | |
768 | ||
769 | void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) | |
770 | { | |
771 | event.Enable( CanCopy() ); | |
772 | } | |
773 | ||
774 | void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) | |
775 | { | |
776 | event.Enable( CanPaste() ); | |
777 | } | |
778 | ||
779 | void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) | |
780 | { | |
781 | event.Enable( CanUndo() ); | |
782 | } | |
783 | ||
784 | void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) | |
785 | { | |
786 | event.Enable( CanRedo() ); | |
787 | } | |
788 | ||
789 | #else | |
790 | ||
791 | extern wxApp *wxTheApp ; | |
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 |