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