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