always forcing a relayout when position changes, making mlte a system option
[wxWidgets.git] / src / mac / carbon / textctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: textctrl.cpp
3 // Purpose: wxTextCtrl
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "textctrl.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #if wxUSE_TEXTCTRL
19
20
21 #ifdef __DARWIN__
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #else
25 #include <stat.h>
26 #endif
27
28 #include "wx/msgdlg.h"
29
30 #if wxUSE_STD_IOSTREAM
31 #if wxUSE_IOSTREAMH
32 #include <fstream.h>
33 #else
34 #include <fstream>
35 #endif
36 #endif
37
38 #include "wx/app.h"
39 #include "wx/dc.h"
40 #include "wx/button.h"
41 #include "wx/toplevel.h"
42 #include "wx/textctrl.h"
43 #include "wx/notebook.h"
44 #include "wx/tabctrl.h"
45 #include "wx/settings.h"
46 #include "wx/filefn.h"
47 #include "wx/utils.h"
48 #include "wx/sysopt.h"
49
50 #if defined(__BORLANDC__) && !defined(__WIN32__)
51 #include <alloc.h>
52 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
53 #include <malloc.h>
54 #endif
55
56 #ifndef __DARWIN__
57 #include <Scrap.h>
58 #endif
59
60 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
61 // if set to 0 then the unicode textctrl will be used
62 #ifndef wxMAC_AWAYS_USE_MLTE
63 #define wxMAC_AWAYS_USE_MLTE 1
64 #endif
65
66 #ifndef __WXMAC_OSX__
67 enum
68 {
69 kTXNVisibilityTag = 'visb' /*set the visibility state of the object */
70 };
71 #endif
72
73 #include <MacTextEditor.h>
74 #include <ATSUnicode.h>
75 #include <TextCommon.h>
76 #include <TextEncodingConverter.h>
77 #include "wx/mac/uma.h"
78
79 class wxMacFunctor
80 {
81 public :
82 wxMacFunctor(){}
83 virtual ~wxMacFunctor() {}
84 virtual void* operator()() = 0 ;
85 static void* CallBackProc(void *param)
86 {
87 wxMacFunctor* f = (wxMacFunctor*) param ;
88 void *result = (*f)() ;
89 return result ;
90 }
91 } ;
92
93 template<typename classtype,typename param1type>
94 class wxMacObjectFunctor1 : public wxMacFunctor
95 {
96 typedef void (classtype::*function)( param1type p1 ) ;
97 typedef void (classtype::*ref_function)( const param1type& p1 ) ;
98 public :
99 wxMacObjectFunctor1( classtype *obj , function f , param1type p1 ) :
100 wxMacFunctor( )
101 {
102 m_object = obj ;
103 m_function = f ;
104 m_param1 = p1 ;
105 }
106
107 wxMacObjectFunctor1( classtype *obj , ref_function f , param1type p1 ) :
108 wxMacFunctor( )
109 {
110 m_object = obj ;
111 m_refFunction = f ;
112 m_param1 = p1 ;
113 }
114
115 ~wxMacObjectFunctor1() {}
116
117 virtual void* operator()()
118 {
119 (m_object->*m_function)(m_param1) ;
120 return NULL ;
121 }
122 private :
123 classtype* m_object ;
124 param1type m_param1 ;
125 union
126 {
127 function m_function ;
128 ref_function m_refFunction ;
129 } ;
130 } ;
131
132 template<typename classtype, typename param1type>
133 void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 )
134 {
135 wxMacObjectFunctor1<classtype,param1type> params(object,function,p1) ;
136 void *result =
137 MPRemoteCall( wxMacFunctor::CallBackProc , &params , kMPOwningProcessRemoteContext ) ;
138 return result ;
139 }
140
141 template<typename classtype, typename param1type>
142 void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 )
143 {
144 wxMacObjectFunctor1<classtype,param1type> params(object,function,p1) ;
145 void *result =
146 MPRemoteCall( wxMacFunctor::CallBackProc , &params , kMPOwningProcessRemoteContext ) ;
147 return result ;
148 }
149
150 template<typename classtype, typename param1type>
151 void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 )
152 {
153 wxMutexGuiLeave() ;
154 void *result = wxMacMPRemoteCall( object , function , p1 ) ;
155 wxMutexGuiEnter() ;
156 return result ;
157 }
158
159 template<typename classtype, typename param1type>
160 void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 )
161 {
162 wxMutexGuiLeave() ;
163 void *result = wxMacMPRemoteCall( object , function , p1 ) ;
164 wxMutexGuiEnter() ;
165 return result ;
166 }
167 // common interface for all implementations
168 class wxMacTextControl : public wxMacControl
169 {
170 public :
171 wxMacTextControl( wxTextCtrl *peer ) ;
172 ~wxMacTextControl() ;
173
174 virtual wxString GetStringValue() const = 0 ;
175 virtual void SetStringValue( const wxString &val ) = 0 ;
176 virtual void SetStyle(long start, long end, const wxTextAttr& style) ;
177 virtual void Copy() ;
178 virtual void Cut() ;
179 virtual void Paste() ;
180 virtual bool CanPaste() const ;
181 virtual void SetEditable(bool editable) ;
182 virtual wxTextPos GetLastPosition() const ;
183 virtual void Replace( long from , long to , const wxString str ) ;
184 virtual void Remove( long from , long to ) = 0 ;
185 virtual void SetSelection( long from , long to ) = 0 ;
186 virtual void GetSelection( long* from, long* to) const = 0 ;
187 virtual void WriteText(const wxString& str) = 0 ;
188
189 virtual void Clear() ;
190 virtual bool CanUndo() const;
191 virtual void Undo() ;
192 virtual bool CanRedo() const;
193 virtual void Redo() ;
194 virtual int GetNumberOfLines() const ;
195 virtual long XYToPosition(long x, long y) const;
196 virtual bool PositionToXY(long pos, long *x, long *y) const ;
197 virtual void ShowPosition( long WXUNUSED(pos) ) ;
198 virtual int GetLineLength(long lineNo) const ;
199 virtual wxString GetLineText(long lineNo) const ;
200 virtual bool SetupCursor( const wxPoint& pt ) { return false ; }
201
202 #ifndef __WXMAC_OSX__
203 virtual void MacControlUserPaneDrawProc(wxInt16 part) = 0 ;
204 virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) = 0 ;
205 virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) = 0 ;
206 virtual void MacControlUserPaneIdleProc() = 0 ;
207 virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) = 0 ;
208 virtual void MacControlUserPaneActivateProc(bool activating) = 0 ;
209 virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) = 0 ;
210 virtual void MacControlUserPaneBackgroundProc(void* info) = 0 ;
211 #endif
212 } ;
213
214 // common parts for implementations based on MLTE
215
216 class wxMacMLTEControl : public wxMacTextControl
217 {
218 public :
219 wxMacMLTEControl( wxTextCtrl *peer ) ;
220 virtual wxString GetStringValue() const ;
221 virtual void SetStringValue( const wxString &str) ;
222
223 static TXNFrameOptions FrameOptionsFromWXStyle( long wxStyle ) ;
224 void AdjustCreationAttributes( const wxColour& background , bool visible ) ;
225
226 virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) ;
227 virtual void SetBackground( const wxBrush &brush) ;
228 virtual void SetStyle(long start, long end, const wxTextAttr& style) ;
229 virtual void Copy() ;
230 virtual void Cut() ;
231 virtual void Paste() ;
232 virtual bool CanPaste() const ;
233 virtual void SetEditable(bool editable) ;
234 virtual wxTextPos GetLastPosition() const ;
235 virtual void Replace( long from , long to , const wxString str ) ;
236 virtual void Remove( long from , long to ) ;
237 virtual void GetSelection( long* from, long* to) const ;
238 virtual void SetSelection( long from , long to ) ;
239
240 virtual void WriteText(const wxString& str) ;
241 virtual void Clear() ;
242
243 virtual bool CanUndo() const ;
244 virtual void Undo() ;
245 virtual bool CanRedo() const;
246 virtual void Redo() ;
247 virtual int GetNumberOfLines() const ;
248 virtual long XYToPosition(long x, long y) const ;
249 virtual bool PositionToXY(long pos, long *x, long *y) const ;
250 virtual void ShowPosition( long pos ) ;
251 virtual int GetLineLength(long lineNo) const ;
252 virtual wxString GetLineText(long lineNo) const ;
253
254 void SetTXNData( const wxString& st , TXNOffset start , TXNOffset end ) ;
255
256 protected :
257 void TXNSetAttribute( const wxTextAttr& style , long from , long to ) ;
258 TXNObject m_txn ;
259 } ;
260
261 #if TARGET_API_MAC_OSX
262
263 // implementation available under OSX
264
265 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
266
267 class wxMacMLTEHIViewControl : public wxMacMLTEControl
268 {
269 public :
270 wxMacMLTEHIViewControl( wxTextCtrl *wxPeer,
271 const wxString& str,
272 const wxPoint& pos,
273 const wxSize& size, long style ) ;
274 virtual OSStatus SetFocus( ControlFocusPart focusPart ) ;
275 virtual bool HasFocus() const ;
276 protected :
277 HIViewRef m_scrollView ;
278 HIViewRef m_textView ;
279 } ;
280
281 #endif
282
283 class wxMacUnicodeTextControl : public wxMacTextControl
284 {
285 public :
286 wxMacUnicodeTextControl( wxTextCtrl *wxPeer,
287 const wxString& str,
288 const wxPoint& pos,
289 const wxSize& size, long style ) ;
290 ~wxMacUnicodeTextControl();
291 virtual void VisibilityChanged(bool shown);
292 virtual wxString GetStringValue() const ;
293 virtual void SetStringValue( const wxString &str) ;
294 virtual void Copy();
295 virtual void Cut();
296 virtual void Paste();
297 virtual bool CanPaste() const;
298 virtual void SetEditable(bool editable) ;
299 virtual void Remove( long from , long to ) ;
300 virtual void GetSelection( long* from, long* to) const ;
301 virtual void SetSelection( long from , long to ) ;
302 virtual void WriteText(const wxString& str) ;
303 protected :
304 // contains the tag for the content (is different for password and non-password controls)
305 OSType m_valueTag ;
306 } ;
307
308 #endif
309
310 // 'classic' MLTE implementation
311
312 class wxMacMLTEClassicControl : public wxMacMLTEControl
313 {
314 public :
315 wxMacMLTEClassicControl( wxTextCtrl *wxPeer,
316 const wxString& str,
317 const wxPoint& pos,
318 const wxSize& size, long style ) ;
319 ~wxMacMLTEClassicControl() ;
320 virtual void VisibilityChanged(bool shown) ;
321 virtual void SuperChangedPosition() ;
322
323 virtual void MacControlUserPaneDrawProc(wxInt16 part) ;
324 virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) ;
325 virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) ;
326 virtual void MacControlUserPaneIdleProc() ;
327 virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) ;
328 virtual void MacControlUserPaneActivateProc(bool activating) ;
329 virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ;
330 virtual void MacControlUserPaneBackgroundProc(void* info) ;
331
332 virtual bool SetupCursor( const wxPoint& WXUNUSED(pt) ) { MacControlUserPaneIdleProc() ; return true ;}
333
334 virtual void SetRect( Rect *r ) ;
335
336 protected :
337 OSStatus DoCreate();
338
339 void MacUpdatePosition() ;
340 void MacActivatePaneText(Boolean setActive) ;
341 void MacFocusPaneText(Boolean setFocus) ;
342
343 void MacSetObjectVisibility(Boolean vis) ;
344 private :
345 TXNFrameID m_txnFrameID ;
346 GrafPtr m_txnPort ;
347 WindowRef m_txnWindow ;
348 // bounds of the control as we last did set the txn frames
349 Rect m_txnControlBounds ;
350 Rect m_txnVisBounds ;
351 #ifdef __WXMAC_OSX__
352 static pascal void TXNScrollInfoProc (SInt32 iValue, SInt32 iMaximumValue,
353 TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon) ;
354 static pascal void TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode ) ;
355 ControlRef m_sbHorizontal ;
356 SInt32 m_lastHorizontalValue ;
357 ControlRef m_sbVertical ;
358 SInt32 m_lastVerticalValue ;
359 #endif
360 } ;
361
362 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
363
364 #if !USE_SHARED_LIBRARY
365 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
366
367 BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
368 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground )
369 EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
370 EVT_CHAR(wxTextCtrl::OnChar)
371 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
372 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
373 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
374 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
375 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
376
377 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
378 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
379 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
380 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
381 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
382 END_EVENT_TABLE()
383 #endif
384
385 // Text item
386 void wxTextCtrl::Init()
387 {
388 m_editable = true ;
389 m_dirty = false;
390
391 m_maxLength = TE_UNLIMITED_LENGTH ;
392 }
393
394 wxTextCtrl::~wxTextCtrl()
395 {
396 }
397
398
399 bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
400 const wxString& str,
401 const wxPoint& pos,
402 const wxSize& size, long style,
403 const wxValidator& validator,
404 const wxString& name)
405 {
406 m_macIsUserPane = false ;
407 m_editable = true ;
408
409 if ( ! ( style & wxNO_BORDER) )
410 style = ( style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ;
411
412 if ( !wxTextCtrlBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) )
413 return false;
414
415 if ( m_windowStyle & wxTE_MULTILINE )
416 {
417 wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER),
418 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
419
420 m_windowStyle |= wxTE_PROCESS_ENTER;
421 style |= wxTE_PROCESS_ENTER ;
422 }
423
424 #ifdef __WXMAC_OSX__
425 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
426
427 bool tryHIView = UMAGetSystemVersion() >= 0x1030 ;
428 #if wxUSE_SYSTEM_OPTIONS
429 if ( (wxSystemOptions::HasOption(wxMAC_TEXTCONTROL_USE_MLTE) ) && ( wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE ) == 1) )
430 {
431 tryHIView = false ;
432 }
433 #endif
434 if ( tryHIView )
435 {
436 m_peer = new wxMacMLTEHIViewControl( this , str , pos , size , style ) ;
437 }
438 #endif
439 #if !wxMAC_AWAYS_USE_MLTE
440 if ( !m_peer )
441 {
442 m_peer = new wxMacUnicodeTextControl( this , str , pos , size , style ) ;
443 }
444 #endif
445 #endif
446 if ( !m_peer )
447 {
448 m_peer = new wxMacMLTEClassicControl( this , str , pos , size , style ) ;
449 }
450
451 MacPostControlCreate(pos,size) ;
452
453 // only now the embedding is correct and we can do a positioning update
454
455 MacSuperChangedPosition() ;
456
457 if ( m_windowStyle & wxTE_READONLY)
458 {
459 SetEditable( false ) ;
460 }
461
462 SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ;
463
464 return true;
465 }
466
467 void wxTextCtrl::MacSuperChangedPosition()
468 {
469 wxWindow::MacSuperChangedPosition() ;
470 GetPeer()->SuperChangedPosition() ;
471 }
472
473 void wxTextCtrl::MacVisibilityChanged()
474 {
475 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
476 }
477
478 void wxTextCtrl::MacEnabledStateChanged()
479 {
480 }
481
482 wxString wxTextCtrl::GetValue() const
483 {
484 return GetPeer()->GetStringValue() ;
485 }
486
487 void wxTextCtrl::GetSelection(long* from, long* to) const
488 {
489 GetPeer()->GetSelection( from , to ) ;
490 }
491
492 void wxTextCtrl::SetValue(const wxString& str)
493 {
494 // optimize redraws
495 if ( GetValue() == str )
496 return ;
497
498 GetPeer()->SetStringValue(str) ;
499
500 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
501 event.SetString( GetValue() ) ;
502 event.SetEventObject( this );
503 GetEventHandler()->ProcessEvent(event);
504 }
505
506 void wxTextCtrl::SetMaxLength(unsigned long len)
507 {
508 m_maxLength = len ;
509 }
510
511 bool wxTextCtrl::SetFont( const wxFont& font )
512 {
513 if ( !wxTextCtrlBase::SetFont( font ) )
514 return false ;
515
516 GetPeer()->SetFont( font , GetForegroundColour() , GetWindowStyle() ) ;
517 return true ;
518 }
519
520 bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
521 {
522 GetPeer()->SetStyle( start , end , style ) ;
523 return true ;
524 }
525
526 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style)
527 {
528 wxTextCtrlBase::SetDefaultStyle( style ) ;
529 SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ;
530 return true ;
531 }
532
533 // Clipboard operations
534 void wxTextCtrl::Copy()
535 {
536 if (CanCopy())
537 {
538 GetPeer()->Copy() ;
539 }
540 }
541
542 void wxTextCtrl::Cut()
543 {
544 if (CanCut())
545 {
546 GetPeer()->Cut() ;
547
548 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
549 event.SetEventObject( this );
550 GetEventHandler()->ProcessEvent(event);
551 }
552 }
553
554 void wxTextCtrl::Paste()
555 {
556 if (CanPaste())
557 {
558 GetPeer()->Paste() ;
559 // eventually we should add setting the default style again
560
561 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
562 event.SetEventObject( this );
563 GetEventHandler()->ProcessEvent(event);
564 }
565 }
566
567 bool wxTextCtrl::CanCopy() const
568 {
569 // Can copy if there's a selection
570 long from, to;
571 GetSelection(& from, & to);
572 return (from != to);
573 }
574
575 bool wxTextCtrl::CanCut() const
576 {
577 if ( !IsEditable() )
578 {
579 return false ;
580 }
581 // Can cut if there's a selection
582 long from, to;
583 GetSelection(& from, & to);
584 return (from != to);
585 }
586
587 bool wxTextCtrl::CanPaste() const
588 {
589 if (!IsEditable())
590 return false;
591
592 return GetPeer()->CanPaste() ;
593 }
594
595 void wxTextCtrl::SetEditable(bool editable)
596 {
597 if ( editable != m_editable )
598 {
599 m_editable = editable ;
600 GetPeer()->SetEditable( editable ) ;
601 }
602 }
603
604 void wxTextCtrl::SetInsertionPoint(long pos)
605 {
606 SetSelection( pos , pos ) ;
607 }
608
609 void wxTextCtrl::SetInsertionPointEnd()
610 {
611 wxTextPos pos = GetLastPosition();
612 SetInsertionPoint(pos);
613 }
614
615 long wxTextCtrl::GetInsertionPoint() const
616 {
617 long begin,end ;
618 GetSelection( &begin , &end ) ;
619 return begin ;
620 }
621
622 wxTextPos wxTextCtrl::GetLastPosition() const
623 {
624 return GetPeer()->GetLastPosition( ) ;
625 }
626
627 void wxTextCtrl::Replace(long from, long to, const wxString& str)
628 {
629 GetPeer()->Replace( from , to , str) ;
630 }
631
632 void wxTextCtrl::Remove(long from, long to)
633 {
634 GetPeer()->Remove( from , to ) ;
635 }
636
637 void wxTextCtrl::SetSelection(long from, long to)
638 {
639 GetPeer()->SetSelection( from , to ) ;
640 }
641
642 bool wxTextCtrl::LoadFile(const wxString& file)
643 {
644 if ( wxTextCtrlBase::LoadFile(file) )
645 {
646 return true;
647 }
648
649 return false;
650 }
651
652 void wxTextCtrl::WriteText(const wxString& str)
653 {
654 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
655 if ( !wxIsMainThread() )
656 {
657 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
658 // to instantiate explicitely
659 wxMacMPRemoteGUICall<wxTextCtrl,wxString>( this , &wxTextCtrl::WriteText , str ) ;
660 return ;
661 }
662 else
663 {
664 GetPeer()->WriteText( str ) ;
665 }
666 }
667
668 void wxTextCtrl::AppendText(const wxString& text)
669 {
670 SetInsertionPointEnd();
671 WriteText(text);
672 }
673
674 void wxTextCtrl::Clear()
675 {
676 GetPeer()->Clear() ;
677 }
678
679 bool wxTextCtrl::IsModified() const
680 {
681 return m_dirty;
682 }
683
684 bool wxTextCtrl::IsEditable() const
685 {
686 return IsEnabled() && m_editable ;
687 }
688
689 bool wxTextCtrl::AcceptsFocus() const
690 {
691 // we don't want focus if we can't be edited
692 return /*IsEditable() && */ wxControl::AcceptsFocus();
693 }
694
695 wxSize wxTextCtrl::DoGetBestSize() const
696 {
697 int wText = 100 ;
698
699 int hText;
700
701 // these are the numbers from the HIG, we reduce them by the borders
702 // first
703
704 switch( m_windowVariant )
705 {
706 case wxWINDOW_VARIANT_NORMAL :
707 hText = 22 - 6 ;
708 break ;
709 case wxWINDOW_VARIANT_SMALL :
710 hText = 19 - 6 ;
711 break ;
712 case wxWINDOW_VARIANT_MINI :
713 hText= 15 - 6 ;
714 break ;
715 default :
716 hText = 22 - 6;
717 break ;
718 }
719
720 // as the above numbers have some free space around the text
721 // we get 5 lines like this anyway
722 if ( m_windowStyle & wxTE_MULTILINE )
723 {
724 hText *= 5 ;
725 }
726
727 if ( !HasFlag(wxNO_BORDER) )
728 hText += 6 ;
729
730 return wxSize(wText, hText);
731 }
732
733 // ----------------------------------------------------------------------------
734 // Undo/redo
735 // ----------------------------------------------------------------------------
736
737 void wxTextCtrl::Undo()
738 {
739 if (CanUndo())
740 {
741 GetPeer()->Undo() ;
742 }
743 }
744
745 void wxTextCtrl::Redo()
746 {
747 if (CanRedo())
748 {
749 GetPeer()->Redo() ;
750 }
751 }
752
753 bool wxTextCtrl::CanUndo() const
754 {
755 if ( !IsEditable() )
756 {
757 return false ;
758 }
759 return GetPeer()->CanUndo() ;
760 }
761
762 bool wxTextCtrl::CanRedo() const
763 {
764 if ( !IsEditable() )
765 {
766 return false ;
767 }
768 return GetPeer()->CanRedo() ;
769 }
770
771 void wxTextCtrl::MarkDirty()
772 {
773 m_dirty = true;
774 }
775
776 void wxTextCtrl::DiscardEdits()
777 {
778 m_dirty = false;
779 }
780
781 int wxTextCtrl::GetNumberOfLines() const
782 {
783 return GetPeer()->GetNumberOfLines() ;
784 }
785
786 long wxTextCtrl::XYToPosition(long x, long y) const
787 {
788 return GetPeer()->XYToPosition( x , y ) ;
789 }
790
791 bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
792 {
793 return GetPeer()->PositionToXY(pos , x , y ) ;
794 }
795
796 void wxTextCtrl::ShowPosition(long pos)
797 {
798 return GetPeer()->ShowPosition(pos) ;
799 }
800
801 int wxTextCtrl::GetLineLength(long lineNo) const
802 {
803 return GetPeer()->GetLineLength(lineNo) ;
804 }
805
806 wxString wxTextCtrl::GetLineText(long lineNo) const
807 {
808 return GetPeer()->GetLineText(lineNo) ;
809 }
810
811 /*
812 * Text item
813 */
814
815 void wxTextCtrl::Command(wxCommandEvent & event)
816 {
817 SetValue (event.GetString());
818 ProcessCommand (event);
819 }
820
821 void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
822 {
823 // By default, load the first file into the text window.
824 if (event.GetNumberOfFiles() > 0)
825 {
826 LoadFile(event.GetFiles()[0]);
827 }
828 }
829
830 void wxTextCtrl::OnEraseBackground(wxEraseEvent& event)
831 {
832 // all erasing should be done by the real mac control implementation
833 // while this is true for MLTE under classic, the HITextView is somehow
834 // transparent but background erase is not working correctly, so intercept
835 // things while we can...
836 event.Skip() ;
837 }
838
839 void wxTextCtrl::OnChar(wxKeyEvent& event)
840 {
841 int key = event.GetKeyCode() ;
842 bool eat_key = false ;
843
844 if ( key == 'c' && event.MetaDown() )
845 {
846 if ( CanCopy() )
847 Copy() ;
848 return ;
849 }
850
851 if ( !IsEditable() && key != WXK_LEFT && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_UP && key != WXK_TAB &&
852 !( key == WXK_RETURN && ( (m_windowStyle & wxPROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) )
853 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
854 )
855 {
856 // eat it
857 return ;
858 }
859
860 // Check if we have reached the max # of chars, but still allow navigation and deletion
861 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength &&
862 key != WXK_LEFT && key != WXK_RIGHT && key != WXK_TAB &&
863 key != WXK_BACK && !( key == WXK_RETURN && (m_windowStyle & wxPROCESS_ENTER) )
864 )
865 {
866 // eat it, we don't want to add more than allowed # of characters
867 return;
868 }
869
870 // assume that any key not processed yet is going to modify the control
871 m_dirty = true;
872
873 if ( key == 'v' && event.MetaDown() )
874 {
875 if ( CanPaste() )
876 Paste() ;
877 return ;
878 }
879 if ( key == 'x' && event.MetaDown() )
880 {
881 if ( CanCut() )
882 Cut() ;
883 return ;
884 }
885 switch ( key )
886 {
887 case WXK_RETURN:
888 if (m_windowStyle & wxPROCESS_ENTER)
889 {
890 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
891 event.SetEventObject( this );
892 event.SetString( GetValue() );
893 if ( GetEventHandler()->ProcessEvent(event) )
894 return;
895 }
896 if ( !(m_windowStyle & wxTE_MULTILINE) )
897 {
898 wxWindow *parent = GetParent();
899 while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) {
900 parent = parent->GetParent() ;
901 }
902 if ( parent && parent->GetDefaultItem() )
903 {
904 wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
905 wxButton);
906 if ( def && def->IsEnabled() )
907 {
908 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
909 event.SetEventObject(def);
910 def->Command(event);
911 return ;
912 }
913 }
914
915 // this will make wxWidgets eat the ENTER key so that
916 // we actually prevent line wrapping in a single line
917 // text control
918 eat_key = true;
919 }
920
921 break;
922
923 case WXK_TAB:
924 if ( !(m_windowStyle & wxTE_PROCESS_TAB))
925 {
926 int flags = 0;
927 if (!event.ShiftDown())
928 flags |= wxNavigationKeyEvent::IsForward ;
929 if (event.ControlDown())
930 flags |= wxNavigationKeyEvent::WinChange ;
931 Navigate(flags);
932 return;
933 }
934 else
935 {
936 // This is necessary (don't know why) or the tab will not
937 // be inserted.
938 WriteText(wxT("\t"));
939 }
940
941 break;
942 }
943
944 if (!eat_key)
945 {
946 // perform keystroke handling
947 if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL )
948 CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ;
949 else
950 {
951 EventRecord rec ;
952 if ( wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) )
953 {
954 EventRecord *ev = &rec ;
955 short keycode ;
956 short keychar ;
957 keychar = short(ev->message & charCodeMask);
958 keycode = short(ev->message & keyCodeMask) >> 8 ;
959
960 m_peer->HandleKey( keycode , keychar , ev->modifiers ) ;
961 }
962 }
963 }
964 if ( ( key >= 0x20 && key < WXK_START ) ||
965 key == WXK_RETURN ||
966 key == WXK_DELETE ||
967 key == WXK_BACK)
968 {
969 wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
970 event1.SetEventObject( this );
971 wxPostEvent(GetEventHandler(),event1);
972 }
973 }
974
975 // ----------------------------------------------------------------------------
976 // standard handlers for standard edit menu events
977 // ----------------------------------------------------------------------------
978
979 void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
980 {
981 Cut();
982 }
983
984 void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event))
985 {
986 Copy();
987 }
988
989 void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event))
990 {
991 Paste();
992 }
993
994 void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event))
995 {
996 Undo();
997 }
998
999 void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event))
1000 {
1001 Redo();
1002 }
1003
1004 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
1005 {
1006 event.Enable( CanCut() );
1007 }
1008
1009 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
1010 {
1011 event.Enable( CanCopy() );
1012 }
1013
1014 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
1015 {
1016 event.Enable( CanPaste() );
1017 }
1018
1019 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
1020 {
1021 event.Enable( CanUndo() );
1022 }
1023
1024 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
1025 {
1026 event.Enable( CanRedo() );
1027 }
1028
1029 bool wxTextCtrl::MacSetupCursor( const wxPoint& pt )
1030 {
1031 if ( !GetPeer()->SetupCursor(pt) )
1032 return wxWindow::MacSetupCursor( pt ) ;
1033 else
1034 return true ;
1035 }
1036 #if !TARGET_API_MAC_OSX
1037
1038 // user pane implementation
1039
1040 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part)
1041 {
1042 GetPeer()->MacControlUserPaneDrawProc( part ) ;
1043 }
1044
1045 wxInt16 wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
1046 {
1047 return GetPeer()->MacControlUserPaneHitTestProc( x , y ) ;
1048 }
1049
1050 wxInt16 wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc)
1051 {
1052 return GetPeer()->MacControlUserPaneTrackingProc( x , y , actionProc ) ;
1053 }
1054
1055 void wxTextCtrl::MacControlUserPaneIdleProc()
1056 {
1057 GetPeer()->MacControlUserPaneIdleProc( ) ;
1058 }
1059
1060 wxInt16 wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
1061 {
1062 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode , charCode , modifiers ) ;
1063 }
1064
1065 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating)
1066 {
1067 GetPeer()->MacControlUserPaneActivateProc( activating ) ;
1068 }
1069
1070 wxInt16 wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action)
1071 {
1072 return GetPeer()->MacControlUserPaneFocusProc( action ) ;
1073 }
1074
1075 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info)
1076 {
1077 GetPeer()->MacControlUserPaneBackgroundProc( info ) ;
1078 }
1079
1080 #endif
1081 // ----------------------------------------------------------------------------
1082 // implementation base class
1083 // ----------------------------------------------------------------------------
1084
1085 wxMacTextControl::wxMacTextControl(wxTextCtrl* peer) :
1086 wxMacControl( peer )
1087 {
1088 }
1089
1090 wxMacTextControl::~wxMacTextControl()
1091 {
1092 }
1093
1094 void wxMacTextControl::SetStyle(long start, long end, const wxTextAttr& style)
1095 {
1096 }
1097
1098 void wxMacTextControl::Copy()
1099 {
1100 }
1101
1102 void wxMacTextControl::Cut()
1103 {
1104 }
1105
1106 void wxMacTextControl::Paste()
1107 {
1108 }
1109
1110 bool wxMacTextControl::CanPaste() const
1111 {
1112 return false ;
1113 }
1114
1115 void wxMacTextControl::SetEditable(bool editable)
1116 {
1117 }
1118
1119 wxTextPos wxMacTextControl::GetLastPosition() const
1120 {
1121 return GetStringValue().Length() ;
1122 }
1123
1124 void wxMacTextControl::Replace( long from , long to , const wxString str )
1125 {
1126 }
1127
1128 void wxMacTextControl::Clear()
1129 {
1130 SetStringValue( wxEmptyString ) ;
1131 }
1132
1133 bool wxMacTextControl::CanUndo() const
1134 {
1135 return false ;
1136 }
1137
1138 void wxMacTextControl::Undo() { }
1139
1140 bool wxMacTextControl::CanRedo() const
1141 {
1142 return false ;
1143 }
1144
1145 void wxMacTextControl::Redo()
1146 {
1147 }
1148
1149 long wxMacTextControl::XYToPosition(long x, long y) const
1150 {
1151 return 0 ;
1152 }
1153
1154 bool wxMacTextControl::PositionToXY(long pos, long *x, long *y) const
1155 {
1156 return false ;
1157 }
1158
1159 void wxMacTextControl::ShowPosition( long WXUNUSED(pos) )
1160 {
1161 }
1162
1163 int wxMacTextControl::GetNumberOfLines() const
1164 {
1165 ItemCount lines = 0 ;
1166 wxString content = GetStringValue() ;
1167 lines = 1;
1168 for (size_t i = 0; i < content.Length() ; i++)
1169 {
1170 if (content[i] == '\r') lines++;
1171 }
1172 return lines ;
1173 }
1174
1175 wxString wxMacTextControl::GetLineText(long lineNo) const
1176 {
1177 // TODO change this if possible to reflect real lines
1178 wxString content = GetStringValue() ;
1179
1180 // Find line first
1181 int count = 0;
1182 for (size_t i = 0; i < content.Length() ; i++)
1183 {
1184 if (count == lineNo)
1185 {
1186 // Add chars in line then
1187 wxString tmp;
1188
1189 for (size_t j = i; j < content.Length(); j++)
1190 {
1191 if (content[j] == '\n')
1192 return tmp;
1193
1194 tmp += content[j];
1195 }
1196
1197 return tmp;
1198 }
1199 if (content[i] == '\n') count++;
1200 }
1201 return wxEmptyString ;
1202 }
1203
1204 int wxMacTextControl::GetLineLength(long lineNo) const
1205 {
1206 // TODO change this if possible to reflect real lines
1207 wxString content = GetStringValue() ;
1208
1209 // Find line first
1210 int count = 0;
1211 for (size_t i = 0; i < content.Length() ; i++)
1212 {
1213 if (count == lineNo)
1214 {
1215 // Count chars in line then
1216 count = 0;
1217 for (size_t j = i; j < content.Length(); j++)
1218 {
1219 count++;
1220 if (content[j] == '\n') return count;
1221 }
1222
1223 return count;
1224 }
1225 if (content[i] == '\n') count++;
1226 }
1227 return 0 ;
1228 }
1229
1230 // ----------------------------------------------------------------------------
1231 // standard unicode control implementation
1232 // ----------------------------------------------------------------------------
1233
1234 #if TARGET_API_MAC_OSX
1235
1236 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer,
1237 const wxString& str,
1238 const wxPoint& pos,
1239 const wxSize& size, long style ) : wxMacTextControl( wxPeer )
1240 {
1241 m_font = wxPeer->GetFont() ;
1242 m_windowStyle = style ;
1243 Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ;
1244 wxString st = str ;
1245 wxMacConvertNewlines10To13( &st ) ;
1246 wxMacCFStringHolder cf(st , m_font.GetEncoding()) ;
1247 CFStringRef cfr = cf ;
1248 Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ;
1249 m_valueTag = isPassword ? kControlEditTextPasswordCFStringTag : kControlEditTextCFStringTag ;
1250 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer->MacGetTopLevelWindowRef()), &bounds , cfr , isPassword , NULL , &m_controlRef ) ;
1251
1252 if ( !(m_windowStyle & wxTE_MULTILINE) )
1253 {
1254 SetData<Boolean>( kControlEditTextPart , kControlEditTextSingleLineTag , true ) ;
1255 }
1256 }
1257
1258 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1259 {
1260 }
1261
1262 void wxMacUnicodeTextControl::VisibilityChanged(bool shown)
1263 {
1264 if ( !(m_windowStyle & wxTE_MULTILINE) && shown )
1265 {
1266 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1267 ControlEditTextSelectionRec sel ;
1268 CFStringRef value = NULL ;
1269
1270 verify_noerr( GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) );
1271 verify_noerr( GetData<CFStringRef>( 0, m_valueTag , &value ) );
1272 verify_noerr( SetData<CFStringRef>( 0, m_valueTag, &value ) );
1273 verify_noerr( SetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) );
1274
1275 CFRelease( value ) ;
1276 }
1277 }
1278 wxString wxMacUnicodeTextControl::GetStringValue() const
1279 {
1280 wxString result ;
1281 CFStringRef value = GetData<CFStringRef>(0,m_valueTag) ;
1282 if ( value )
1283 {
1284 wxMacCFStringHolder cf(value) ;
1285 result = cf.AsString() ;
1286 }
1287 #if '\n' == 10
1288 wxMacConvertNewlines13To10( &result ) ;
1289 #else
1290 wxMacConvertNewlines10To13( &result ) ;
1291 #endif
1292 return result ;
1293 }
1294 void wxMacUnicodeTextControl::SetStringValue( const wxString &str)
1295 {
1296 wxString st = str ;
1297 wxMacConvertNewlines10To13( &st ) ;
1298 wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ;
1299 verify_noerr( SetData<CFStringRef>( 0, m_valueTag , cf ) ) ;
1300 }
1301 void wxMacUnicodeTextControl::Copy()
1302 {
1303 SendHICommand( kHICommandCopy ) ;
1304 }
1305 void wxMacUnicodeTextControl::Cut()
1306 {
1307 SendHICommand( kHICommandCut ) ;
1308 }
1309 void wxMacUnicodeTextControl::Paste()
1310 {
1311 SendHICommand( kHICommandPaste ) ;
1312 }
1313 bool wxMacUnicodeTextControl::CanPaste() const
1314 {
1315 return true ;
1316 }
1317 void wxMacUnicodeTextControl::SetEditable(bool editable)
1318 {
1319 SetData<Boolean>( 0 , kControlEditTextLockedTag , (Boolean) !editable ) ;
1320 }
1321 void wxMacUnicodeTextControl::Remove( long from , long to )
1322 {
1323 }
1324
1325 void wxMacUnicodeTextControl::GetSelection( long* from, long* to) const
1326 {
1327 ControlEditTextSelectionRec sel ;
1328 verify_noerr(GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ) ;
1329 if ( from ) *from = sel.selStart ;
1330 if ( to ) *to = sel.selEnd ;
1331 }
1332
1333 void wxMacUnicodeTextControl::SetSelection( long from , long to )
1334 {
1335 ControlEditTextSelectionRec sel ;
1336 sel.selStart = from ;
1337 sel.selEnd = to ;
1338 SetData<ControlEditTextSelectionRec>( 0 , kControlEditTextSelectionTag, &sel ) ;
1339 }
1340
1341 void wxMacUnicodeTextControl::WriteText(const wxString& str)
1342 {
1343 wxString st = str ;
1344 wxMacConvertNewlines10To13( &st ) ;
1345 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1346 wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ;
1347 CFStringRef value = cf ;
1348 SetData<CFStringRef>( 0, kControlEditTextInsertCFStringRefTag, &value );
1349 #else
1350 wxString val = GetStringValue() ;
1351 long start , end ;
1352 GetSelection( &start , &end ) ;
1353 val.Remove( start , end - start ) ;
1354 val.insert( start , str ) ;
1355 SetStringValue( val ) ;
1356 SetSelection( start + str.Length() , start + str.Length() ) ;
1357 #endif
1358 }
1359
1360 #endif
1361
1362 // ----------------------------------------------------------------------------
1363 // MLTE control implementation (common part)
1364 // ----------------------------------------------------------------------------
1365
1366 // if mlte is on read only , no changes at all are allowed, not even from
1367 // procedural API, in order to allow changes via API all the same we must undo
1368 // the readonly status while we are executing, this class helps to do so
1369
1370 class wxMacEditHelper
1371 {
1372 public :
1373 wxMacEditHelper( TXNObject txn )
1374 {
1375 TXNControlTag tag[] = { kTXNIOPrivilegesTag } ;
1376 m_txn = txn ;
1377 TXNGetTXNObjectControls( m_txn , 1 , tag , m_data ) ;
1378 if ( m_data[0].uValue == kTXNReadOnly )
1379 {
1380 TXNControlData data[] = { { kTXNReadWrite } } ;
1381 TXNSetTXNObjectControls( m_txn , false , 1 , tag , data ) ;
1382 }
1383 }
1384 ~wxMacEditHelper()
1385 {
1386 TXNControlTag tag[] = { kTXNIOPrivilegesTag } ;
1387 if ( m_data[0].uValue == kTXNReadOnly )
1388 {
1389 TXNSetTXNObjectControls( m_txn , false , 1 , tag , m_data ) ;
1390 }
1391 }
1392 protected :
1393 TXNObject m_txn ;
1394 TXNControlData m_data[1] ;
1395 } ;
1396
1397 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) : wxMacTextControl( peer )
1398 {
1399 SetNeedsFocusRect( true ) ;
1400 }
1401
1402 wxString wxMacMLTEControl::GetStringValue() const
1403 {
1404 wxString result ;
1405 OSStatus err ;
1406 Size actualSize = 0;
1407 {
1408 #if wxUSE_UNICODE
1409 Handle theText ;
1410 err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText , kTXNUnicodeTextData );
1411 // all done
1412 if ( err )
1413 {
1414 actualSize = 0 ;
1415 }
1416 else
1417 {
1418 actualSize = GetHandleSize( theText ) / sizeof( UniChar) ;
1419 if ( actualSize > 0 )
1420 {
1421 wxChar *ptr = NULL ;
1422 #if SIZEOF_WCHAR_T == 2
1423 ptr = new wxChar[actualSize + 1 ] ;
1424 wxStrncpy( ptr , (wxChar*) *theText , actualSize ) ;
1425 #else
1426 SetHandleSize( theText , ( actualSize + 1 ) * sizeof( UniChar ) ) ;
1427 HLock( theText ) ;
1428 (((UniChar*)*theText)[actualSize]) = 0 ;
1429 wxMBConvUTF16BE converter ;
1430 size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ;
1431 ptr = new wxChar[noChars + 1] ;
1432
1433 noChars = converter.MB2WC( ptr , (const char*)*theText , noChars ) ;
1434 ptr[noChars] = 0 ;
1435 HUnlock( theText ) ;
1436 #endif
1437 ptr[actualSize] = 0 ;
1438 result = wxString( ptr ) ;
1439 delete[] ptr ;
1440 }
1441 DisposeHandle( theText ) ;
1442 }
1443 #else
1444 Handle theText ;
1445 err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
1446 // all done
1447 if ( err )
1448 {
1449 actualSize = 0 ;
1450 }
1451 else
1452 {
1453 actualSize = GetHandleSize( theText ) ;
1454 if ( actualSize > 0 )
1455 {
1456 HLock( theText ) ;
1457 result = wxString( *theText , wxConvLocal , actualSize ) ;
1458 HUnlock( theText ) ;
1459 }
1460 DisposeHandle( theText ) ;
1461 }
1462 #endif
1463 }
1464 #if '\n' == 10
1465 wxMacConvertNewlines13To10( &result ) ;
1466 #else
1467 wxMacConvertNewlines10To13( &result ) ;
1468 #endif
1469 return result ;
1470 }
1471
1472 void wxMacMLTEControl::SetStringValue( const wxString &str)
1473 {
1474 wxString st = str ;
1475
1476 wxMacConvertNewlines10To13( &st ) ;
1477 {
1478 wxMacWindowClipper c( m_peer ) ;
1479 {
1480 wxMacEditHelper help(m_txn) ;
1481 SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ;
1482 }
1483 TXNSetSelection( m_txn, 0, 0);
1484 TXNShowSelection( m_txn, kTXNShowStart);
1485 }
1486 }
1487
1488 TXNFrameOptions wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle )
1489 {
1490 TXNFrameOptions frameOptions =
1491 kTXNDontDrawCaretWhenInactiveMask ;
1492
1493 if ( ! ( wxStyle & wxTE_NOHIDESEL ) )
1494 frameOptions |= kTXNDontDrawSelectionWhenInactiveMask ;
1495
1496 if ( wxStyle & wxTE_MULTILINE )
1497 {
1498 if ( ! ( wxStyle & wxTE_DONTWRAP ) )
1499 frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ;
1500 else
1501 {
1502 frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ;
1503 frameOptions |= kTXNWantHScrollBarMask ;
1504 }
1505
1506 if ( !(wxStyle & wxTE_NO_VSCROLL ) )
1507 {
1508 frameOptions |= kTXNWantVScrollBarMask ;
1509 if ( frameOptions & kTXNWantHScrollBarMask )
1510 frameOptions |= kTXNDrawGrowIconMask ;
1511 }
1512 }
1513 else
1514 frameOptions |= kTXNSingleLineOnlyMask ;
1515
1516 if ( wxStyle & wxHSCROLL )
1517 frameOptions |= kTXNWantHScrollBarMask ;
1518
1519 return frameOptions ;
1520 }
1521
1522 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, bool visible )
1523 {
1524 TXNControlTag iControlTags[] =
1525 {
1526 kTXNDoFontSubstitution,
1527 kTXNWordWrapStateTag ,
1528 };
1529 TXNControlData iControlData[] =
1530 {
1531 {false},
1532 {kTXNNoAutoWrap},
1533 };
1534
1535 int toptag = WXSIZEOF( iControlTags ) ;
1536
1537 if ( m_windowStyle & wxTE_MULTILINE )
1538 {
1539 if (m_windowStyle & wxTE_DONTWRAP)
1540 iControlData[1].uValue = kTXNNoAutoWrap ;
1541 else
1542 iControlData[1].uValue = kTXNAutoWrap ;
1543 }
1544 verify_noerr( TXNSetTXNObjectControls( m_txn, false, toptag,
1545 iControlTags, iControlData )) ;
1546
1547 // setting the default font
1548 // under 10.2 this causes a visible caret, therefore we avoid it
1549
1550 if ( UMAGetSystemVersion() >= 0x1030 )
1551 {
1552 Str255 fontName ;
1553 SInt16 fontSize ;
1554 Style fontStyle ;
1555
1556 GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
1557
1558 TXNTypeAttributes typeAttr[] =
1559 {
1560 { kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } ,
1561 { kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } ,
1562 { kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , { (void*) normal } } ,
1563 } ;
1564
1565 verify_noerr( TXNSetTypeAttributes (m_txn, sizeof( typeAttr ) / sizeof(TXNTypeAttributes) , typeAttr,
1566 kTXNStartOffset,
1567 kTXNEndOffset) );
1568 }
1569
1570 if ( m_windowStyle & wxTE_PASSWORD )
1571 {
1572 UniChar c = 0xA5 ;
1573 verify_noerr(TXNEchoMode( m_txn , c , 0 , true )) ;
1574 }
1575
1576 TXNBackground tback;
1577 tback.bgType = kTXNBackgroundTypeRGB;
1578 tback.bg.color = MAC_WXCOLORREF( background.GetPixel() );
1579 TXNSetBackground( m_txn , &tback);
1580 }
1581
1582 void wxMacMLTEControl::SetBackground( const wxBrush &brush )
1583 {
1584 // currently only solid background are supported
1585 TXNBackground tback;
1586 tback.bgType = kTXNBackgroundTypeRGB;
1587 tback.bg.color = MAC_WXCOLORREF( brush.GetColour().GetPixel() );
1588 TXNSetBackground( m_txn , &tback);
1589 }
1590
1591 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , long to)
1592 {
1593 TXNTypeAttributes typeAttr[4] ;
1594 Str255 fontName = "\pMonaco" ;
1595 SInt16 fontSize = 12 ;
1596 Style fontStyle = normal ;
1597 RGBColor color ;
1598 int attrCounter = 0 ;
1599 if ( style.HasFont() )
1600 {
1601 const wxFont &font = style.GetFont() ;
1602 wxMacStringToPascal( font.GetFaceName() , fontName ) ;
1603 fontSize = font.GetPointSize() ;
1604 if ( font.GetUnderlined() )
1605 fontStyle |= underline ;
1606 if ( font.GetWeight() == wxBOLD )
1607 fontStyle |= bold ;
1608 if ( font.GetStyle() == wxITALIC )
1609 fontStyle |= italic ;
1610
1611 typeAttr[attrCounter].tag = kTXNQDFontNameAttribute ;
1612 typeAttr[attrCounter].size = kTXNQDFontNameAttributeSize ;
1613 typeAttr[attrCounter].data.dataPtr = (void*) fontName ;
1614 typeAttr[attrCounter+1].tag = kTXNQDFontSizeAttribute ;
1615 typeAttr[attrCounter+1].size = kTXNFontSizeAttributeSize ;
1616 typeAttr[attrCounter+1].data.dataValue = (fontSize << 16) ;
1617 typeAttr[attrCounter+2].tag = kTXNQDFontStyleAttribute ;
1618 typeAttr[attrCounter+2].size = kTXNQDFontStyleAttributeSize ;
1619 typeAttr[attrCounter+2].data.dataValue = fontStyle ;
1620 attrCounter += 3 ;
1621 }
1622 if ( style.HasTextColour() )
1623 {
1624 typeAttr[attrCounter].tag = kTXNQDFontColorAttribute ;
1625 typeAttr[attrCounter].size = kTXNQDFontColorAttributeSize ;
1626 typeAttr[attrCounter].data.dataPtr = (void*) &color ;
1627 color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ;
1628 attrCounter += 1 ;
1629 }
1630 if ( attrCounter > 0 )
1631 {
1632 verify_noerr( TXNSetTypeAttributes ( m_txn , attrCounter , typeAttr, from , to) );
1633 }
1634 }
1635
1636 void wxMacMLTEControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle )
1637 {
1638 wxMacEditHelper help(m_txn) ;
1639 TXNSetAttribute( wxTextAttr(foreground,wxNullColour,font) , kTXNStartOffset,kTXNEndOffset ) ;
1640 }
1641 void wxMacMLTEControl::SetStyle(long start, long end, const wxTextAttr& style)
1642 {
1643 wxMacEditHelper help(m_txn) ;
1644 TXNSetAttribute( style , start,end ) ;
1645 }
1646
1647 void wxMacMLTEControl::Copy()
1648 {
1649 ClearCurrentScrap();
1650 TXNCopy(m_txn);
1651 TXNConvertToPublicScrap();
1652 }
1653
1654 void wxMacMLTEControl::Cut()
1655 {
1656 ClearCurrentScrap();
1657 TXNCut(m_txn);
1658 TXNConvertToPublicScrap();
1659 }
1660
1661 void wxMacMLTEControl::Paste()
1662 {
1663 TXNConvertFromPublicScrap();
1664 TXNPaste(m_txn);
1665 }
1666
1667 bool wxMacMLTEControl::CanPaste() const
1668 {
1669 return TXNIsScrapPastable() ;
1670 }
1671
1672 void wxMacMLTEControl::SetEditable(bool editable)
1673 {
1674 TXNControlTag tag[] = { kTXNIOPrivilegesTag } ;
1675 TXNControlData data[] = { { editable ? kTXNReadWrite : kTXNReadOnly } } ;
1676 TXNSetTXNObjectControls( m_txn , false , WXSIZEOF(tag) , tag , data ) ;
1677 }
1678
1679 wxTextPos wxMacMLTEControl::GetLastPosition() const
1680 {
1681 wxTextPos actualsize = 0 ;
1682
1683 Handle theText ;
1684 OSErr err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
1685 /* all done */
1686 if ( err )
1687 {
1688 actualsize = 0 ;
1689 }
1690 else
1691 {
1692 actualsize = GetHandleSize( theText ) ;
1693 DisposeHandle( theText ) ;
1694 }
1695
1696 return actualsize ;
1697 }
1698
1699 void wxMacMLTEControl::Replace( long from , long to , const wxString str )
1700 {
1701 wxString value = str ;
1702 wxMacConvertNewlines10To13( &value ) ;
1703
1704 wxMacEditHelper help( m_txn ) ;
1705 wxMacWindowClipper c( m_peer ) ;
1706
1707 TXNSetSelection(m_txn , from , to ) ;
1708 TXNClear( m_txn ) ;
1709 SetTXNData( value , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ;
1710 }
1711
1712 void wxMacMLTEControl::Remove( long from , long to )
1713 {
1714 wxMacWindowClipper c( m_peer ) ;
1715 wxMacEditHelper help( m_txn ) ;
1716 TXNSetSelection(m_txn , from , to ) ;
1717 TXNClear( m_txn ) ;
1718 }
1719
1720 void wxMacMLTEControl::GetSelection( long* from, long* to) const
1721 {
1722 TXNGetSelection( m_txn , (TXNOffset*) from , (TXNOffset*) to ) ;
1723 }
1724
1725 void wxMacMLTEControl::SetSelection( long from , long to )
1726 {
1727 wxMacWindowClipper c( m_peer ) ;
1728 /* change the selection */
1729 if ((from == -1) && (to == -1))
1730 TXNSelectAll(m_txn);
1731 else
1732 TXNSetSelection( m_txn, from, to);
1733 TXNShowSelection( m_txn, kTXNShowStart);
1734 }
1735
1736 void wxMacMLTEControl::WriteText(const wxString& str)
1737 {
1738 wxString st = str ;
1739 wxMacConvertNewlines10To13( &st ) ;
1740
1741 long start , end , dummy ;
1742 GetSelection( &start , &dummy ) ;
1743 wxMacWindowClipper c( m_peer ) ;
1744 {
1745 wxMacEditHelper helper( m_txn ) ;
1746 SetTXNData( st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ;
1747 }
1748 GetSelection( &dummy , &end ) ;
1749 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1750 }
1751
1752 void wxMacMLTEControl::Clear()
1753 {
1754 wxMacWindowClipper c( m_peer ) ;
1755 wxMacEditHelper st(m_txn) ;
1756 TXNSetSelection( m_txn , kTXNStartOffset , kTXNEndOffset ) ;
1757 TXNClear(m_txn);
1758 }
1759
1760 bool wxMacMLTEControl::CanUndo() const
1761 {
1762 return TXNCanUndo( m_txn , NULL ) ;
1763 }
1764
1765 void wxMacMLTEControl::Undo()
1766 {
1767 TXNUndo( m_txn ) ;
1768 }
1769
1770 bool wxMacMLTEControl::CanRedo() const
1771 {
1772 return TXNCanRedo( m_txn , NULL ) ;
1773 }
1774
1775 void wxMacMLTEControl::Redo()
1776 {
1777 TXNRedo( m_txn ) ;
1778 }
1779
1780 int wxMacMLTEControl::GetNumberOfLines() const
1781 {
1782 ItemCount lines = 0 ;
1783 TXNGetLineCount(m_txn, &lines ) ;
1784 return lines ;
1785 }
1786
1787 long wxMacMLTEControl::XYToPosition(long x, long y) const
1788 {
1789 Point curpt ;
1790
1791 wxTextPos lastpos = GetLastPosition() ;
1792
1793 // TODO find a better implementation : while we can get the
1794 // line metrics of a certain line, we don't get its starting
1795 // position, so it would probably be rather a binary search
1796 // for the start position
1797 long xpos = 0 ;
1798 long ypos = 0 ;
1799 int lastHeight = 0 ;
1800
1801 ItemCount n ;
1802 for ( n = 0 ; n <= (ItemCount) lastpos ; ++n )
1803 {
1804 if ( y == ypos && x == xpos )
1805 return n ;
1806
1807 TXNOffsetToPoint( m_txn , n , &curpt);
1808
1809 if ( curpt.v > lastHeight )
1810 {
1811 xpos = 0 ;
1812 if ( n > 0 )
1813 ++ypos ;
1814 lastHeight = curpt.v ;
1815 }
1816 else
1817 ++xpos ;
1818 }
1819 return 0 ;
1820 }
1821
1822 bool wxMacMLTEControl::PositionToXY(long pos, long *x, long *y) const
1823 {
1824 Point curpt ;
1825
1826 wxTextPos lastpos = GetLastPosition() ;
1827
1828 if ( y ) *y = 0 ;
1829 if ( x ) *x = 0 ;
1830
1831 if ( pos <= lastpos )
1832 {
1833 // TODO find a better implementation : while we can get the
1834 // line metrics of a certain line, we don't get its starting
1835 // position, so it would probably be rather a binary search
1836 // for the start position
1837 long xpos = 0 ;
1838 long ypos = 0 ;
1839 int lastHeight = 0 ;
1840
1841 ItemCount n ;
1842 for ( n = 0 ; n <= (ItemCount) pos ; ++n )
1843 {
1844 TXNOffsetToPoint(m_txn , n , &curpt);
1845
1846 if ( curpt.v > lastHeight )
1847 {
1848 xpos = 0 ;
1849 if ( n > 0 )
1850 ++ypos ;
1851 lastHeight = curpt.v ;
1852 }
1853 else
1854 ++xpos ;
1855 }
1856 if ( y ) *y = ypos ;
1857 if ( x ) *x = xpos ;
1858 }
1859
1860 return false ;
1861 }
1862
1863 void wxMacMLTEControl::ShowPosition( long pos )
1864 {
1865 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1866 {
1867 Point current ;
1868 Point desired ;
1869 TXNOffset selstart , selend ;
1870 TXNGetSelection( m_txn , &selstart , &selend) ;
1871 TXNOffsetToPoint( m_txn, selstart , &current);
1872 TXNOffsetToPoint( m_txn, pos , &desired);
1873 //TODO use HIPoints for 10.3 and above
1874 if ( (UInt32) TXNScroll != (UInt32) kUnresolvedCFragSymbolAddress )
1875 {
1876 OSErr theErr = noErr;
1877 SInt32 dv = desired.v - current.v ;
1878 SInt32 dh = desired.h - current.h ;
1879 TXNShowSelection( m_txn , true ) ;
1880 theErr = TXNScroll( m_txn, kTXNScrollUnitsInPixels , kTXNScrollUnitsInPixels , &dv , &dh );
1881 wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
1882 }
1883 }
1884 #endif
1885 }
1886
1887 void wxMacMLTEControl::SetTXNData( const wxString& st , TXNOffset start , TXNOffset end )
1888 {
1889 #if wxUSE_UNICODE
1890 #if SIZEOF_WCHAR_T == 2
1891 size_t len = st.Len() ;
1892 TXNSetData( m_txn , kTXNUnicodeTextData, (void*)st.wc_str(), len * 2,
1893 start, end);
1894 #else
1895 wxMBConvUTF16BE converter ;
1896 ByteCount byteBufferLen = converter.WC2MB( NULL , st.wc_str() , 0 ) ;
1897 UniChar *unibuf = (UniChar*) malloc(byteBufferLen) ;
1898 converter.WC2MB( (char*) unibuf , st.wc_str() , byteBufferLen ) ;
1899 TXNSetData( m_txn , kTXNUnicodeTextData, (void*)unibuf, byteBufferLen ,
1900 start, end);
1901 free( unibuf ) ;
1902 #endif
1903 #else
1904 wxCharBuffer text = st.mb_str(wxConvLocal) ;
1905 TXNSetData( m_txn , kTXNTextData, (void*)text.data(), strlen( text ) ,
1906 start, end);
1907 #endif
1908 }
1909
1910
1911 wxString wxMacMLTEControl::GetLineText(long lineNo) const
1912 {
1913 wxString line ;
1914
1915 if ( lineNo < GetNumberOfLines() )
1916 {
1917 long ypos = 0 ;
1918
1919 Fixed lineWidth,
1920 lineHeight,
1921 currentHeight = 0;
1922
1923 // get the first possible position in the control
1924 Point firstPoint;
1925 TXNOffsetToPoint(m_txn, 0, &firstPoint);
1926
1927 // Iterate through the lines until we reach the one we want,
1928 // adding to our current y pixel point position
1929 while (ypos < lineNo)
1930 {
1931 TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight);
1932 currentHeight += lineHeight;
1933 }
1934
1935 Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) };
1936 TXNOffset theOffset;
1937 TXNPointToOffset(m_txn, thePoint, &theOffset);
1938
1939 wxString content = GetStringValue() ;
1940 Point currentPoint = thePoint;
1941 while(thePoint.v == currentPoint.v && theOffset < content.length())
1942 {
1943 line += content[theOffset];
1944 TXNOffsetToPoint(m_txn, ++theOffset, &currentPoint);
1945 }
1946 }
1947 return line ;
1948 }
1949
1950 int wxMacMLTEControl::GetLineLength(long lineNo) const
1951 {
1952 int theLength = 0;
1953
1954 if ( lineNo < GetNumberOfLines() )
1955 {
1956 long ypos = 0 ;
1957
1958 Fixed lineWidth,
1959 lineHeight,
1960 currentHeight = 0;
1961
1962 // get the first possible position in the control
1963 Point firstPoint;
1964 TXNOffsetToPoint(m_txn, 0, &firstPoint);
1965
1966 // Iterate through the lines until we reach the one we want,
1967 // adding to our current y pixel point position
1968 while (ypos < lineNo)
1969 {
1970 TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight);
1971 currentHeight += lineHeight;
1972 }
1973
1974 Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) };
1975 TXNOffset theOffset;
1976 TXNPointToOffset(m_txn, thePoint, &theOffset);
1977
1978 wxString content = GetStringValue() ;
1979 Point currentPoint = thePoint;
1980 while(thePoint.v == currentPoint.v && theOffset < content.length())
1981 {
1982 ++theLength;
1983 TXNOffsetToPoint(m_txn, ++theOffset, &currentPoint);
1984 }
1985 }
1986 return theLength ;
1987 }
1988
1989
1990 // ----------------------------------------------------------------------------
1991 // MLTE control implementation (classic part)
1992 // ----------------------------------------------------------------------------
1993
1994 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
1995 // has to live on. We have different problems coming from outdated implementations on the
1996 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
1997 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
1998 // no way out, therefore we are using our own implementation and our own scrollbars ....
1999
2000 #ifdef __WXMAC_OSX__
2001
2002 TXNScrollInfoUPP gTXNScrollInfoProc = NULL ;
2003 ControlActionUPP gTXNScrollActionProc = NULL ;
2004
2005 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue, SInt32 iMaximumValue, TXNScrollBarOrientation
2006 iScrollBarOrientation, SInt32 iRefCon)
2007 {
2008 wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) iRefCon ;
2009 SInt32 value = wxMax( iValue , 0 ) ;
2010 SInt32 maximum = wxMax( iMaximumValue , 0 ) ;
2011
2012 if ( iScrollBarOrientation == kTXNHorizontal )
2013 {
2014 if ( mlte->m_sbHorizontal )
2015 {
2016 SetControl32BitValue( mlte->m_sbHorizontal , value ) ;
2017 SetControl32BitMaximum( mlte->m_sbHorizontal , maximum ) ;
2018 mlte->m_lastHorizontalValue = value ;
2019 }
2020 }
2021 else if ( iScrollBarOrientation == kTXNVertical )
2022 {
2023 if ( mlte->m_sbVertical )
2024 {
2025 SetControl32BitValue( mlte->m_sbVertical , value ) ;
2026 SetControl32BitMaximum( mlte->m_sbVertical , maximum ) ;
2027 mlte->m_lastVerticalValue = value ;
2028 }
2029 }
2030 }
2031
2032 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode )
2033 {
2034 OSStatus err ;
2035 wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) GetControlReference( controlRef ) ;
2036 if ( mlte == NULL )
2037 return ;
2038
2039 if ( controlRef != mlte->m_sbVertical && controlRef != mlte->m_sbHorizontal )
2040 return ;
2041
2042 bool isHorizontal = ( controlRef == mlte->m_sbHorizontal ) ;
2043
2044 SInt32 minimum = 0 ;
2045 SInt32 maximum = GetControl32BitMaximum( controlRef ) ;
2046 SInt32 value = GetControl32BitValue( controlRef ) ;
2047 SInt32 delta = 0;
2048 switch ( partCode )
2049 {
2050 case kControlDownButtonPart :
2051 delta = 10 ;
2052 break ;
2053 case kControlUpButtonPart :
2054 delta = -10 ;
2055 break ;
2056 case kControlPageDownPart :
2057 delta = GetControlViewSize( controlRef ) ;
2058 break ;
2059 case kControlPageUpPart :
2060 delta = -GetControlViewSize( controlRef ) ;
2061 break ;
2062 case kControlIndicatorPart :
2063 delta = value -
2064 ( isHorizontal ? mlte->m_lastHorizontalValue : mlte->m_lastVerticalValue ) ;
2065 break ;
2066 default :
2067 break ;
2068 }
2069 if ( delta != 0 )
2070 {
2071 SInt32 newValue = value ;
2072
2073 if ( partCode != kControlIndicatorPart )
2074 {
2075 if( value + delta < minimum )
2076 delta = minimum - value ;
2077 if ( value + delta > maximum )
2078 delta = maximum - value ;
2079
2080 SetControl32BitValue( controlRef , value + delta ) ;
2081 newValue = value + delta ;
2082 }
2083
2084 SInt32 verticalDelta = isHorizontal ? 0 : delta ;
2085 SInt32 horizontalDelta = isHorizontal ? delta : 0 ;
2086
2087 err = TXNScroll( mlte->m_txn , kTXNScrollUnitsInPixels, kTXNScrollUnitsInPixels,
2088 &verticalDelta , &horizontalDelta );
2089
2090 if ( isHorizontal )
2091 mlte->m_lastHorizontalValue = newValue ;
2092 else
2093 mlte->m_lastVerticalValue = newValue ;
2094 }
2095 }
2096 #endif
2097
2098 // make correct activations
2099 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive)
2100 {
2101 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2102
2103 wxMacWindowClipper clipper( textctrl ) ;
2104 TXNActivate(m_txn, m_txnFrameID, setActive);
2105
2106 ControlRef controlFocus = 0 ;
2107 GetKeyboardFocus( m_txnWindow , &controlFocus ) ;
2108 if ( controlFocus == m_controlRef )
2109 TXNFocus( m_txn, setActive);
2110 }
2111
2112 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus)
2113 {
2114 TXNFocus( m_txn, setFocus);
2115 }
2116
2117 // guards against inappropriate redraw (hidden objects drawing onto window)
2118
2119 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis)
2120 {
2121 ControlRef controlFocus = 0 ;
2122 GetKeyboardFocus( m_txnWindow , &controlFocus ) ;
2123
2124 if ( controlFocus == m_controlRef && vis == false )
2125 {
2126 SetKeyboardFocus( m_txnWindow , m_controlRef , kControlFocusNoPart ) ;
2127 }
2128
2129 TXNControlTag iControlTags[1] = { kTXNVisibilityTag };
2130 TXNControlData iControlData[1] = { {(UInt32) false } };
2131
2132 verify_noerr( TXNGetTXNObjectControls( m_txn , 1,
2133 iControlTags, iControlData ) ) ;
2134
2135 if ( iControlData[0].uValue != vis )
2136 {
2137 iControlData[0].uValue = vis ;
2138 verify_noerr( TXNSetTXNObjectControls( m_txn, false , 1,
2139 iControlTags, iControlData )) ;
2140 }
2141 // we right now are always clipping as partial visibility (overlapped) visibility
2142 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2143 // rect here
2144 }
2145
2146 // make sure that the TXNObject is at the right position
2147
2148 void wxMacMLTEClassicControl::MacUpdatePosition()
2149 {
2150 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2151 if ( textctrl == NULL )
2152 return ;
2153
2154 Rect bounds ;
2155 UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds);
2156
2157 wxRect visRect = textctrl->MacGetClippedClientRect() ;
2158 Rect visBounds = { visRect.y , visRect.x , visRect.y + visRect.height , visRect.x + visRect.width } ;
2159 int x , y ;
2160 x = y = 0 ;
2161 textctrl->MacWindowToRootWindow( &x , &y ) ;
2162 OffsetRect( &visBounds , x , y ) ;
2163
2164 if ( !EqualRect( &bounds , &m_txnControlBounds ) || !EqualRect( &visBounds , &m_txnVisBounds) )
2165 {
2166 m_txnControlBounds = bounds ;
2167 m_txnVisBounds = visBounds ;
2168 wxMacWindowClipper cl(textctrl) ;
2169
2170 #ifdef __WXMAC_OSX__
2171 bool isCompositing = textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ;
2172 if ( m_sbHorizontal || m_sbVertical )
2173 {
2174 int w = bounds.right - bounds.left ;
2175 int h = bounds.bottom - bounds.top ;
2176
2177 if ( m_sbHorizontal )
2178 {
2179 Rect sbBounds ;
2180
2181 sbBounds.left = -1 ;
2182 sbBounds.top = h - 14 ;
2183 sbBounds.right = w + 1 ;
2184 sbBounds.bottom = h + 1 ;
2185
2186 if ( !isCompositing )
2187 OffsetRect( &sbBounds , m_txnControlBounds.left , m_txnControlBounds.top ) ;
2188
2189 SetControlBounds( m_sbHorizontal , &sbBounds ) ;
2190 SetControlViewSize( m_sbHorizontal , w ) ;
2191 }
2192 if ( m_sbVertical )
2193 {
2194 Rect sbBounds ;
2195
2196 sbBounds.left = w - 14 ;
2197 sbBounds.top = -1 ;
2198 sbBounds.right = w + 1 ;
2199 sbBounds.bottom = m_sbHorizontal ? h - 14 : h + 1 ;
2200
2201 if ( !isCompositing )
2202 OffsetRect( &sbBounds , m_txnControlBounds.left , m_txnControlBounds.top ) ;
2203
2204 SetControlBounds( m_sbVertical , &sbBounds ) ;
2205 SetControlViewSize( m_sbVertical , h ) ;
2206 }
2207 }
2208
2209 Rect oldviewRect ;
2210 TXNLongRect olddestRect ;
2211 TXNGetRectBounds( m_txn , &oldviewRect , &olddestRect , NULL ) ;
2212
2213 Rect viewRect = { m_txnControlBounds.top, m_txnControlBounds.left,
2214 m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ;
2215 TXNLongRect destRect = { m_txnControlBounds.top, m_txnControlBounds.left,
2216 m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ;
2217
2218 if ( olddestRect.right >= 10000 )
2219 destRect.right = destRect.left + 32000 ;
2220
2221 if ( olddestRect.bottom >= 0x20000000 )
2222 destRect.bottom = destRect.top + 0x40000000 ;
2223
2224 SectRect( &viewRect , &visBounds , &viewRect ) ;
2225 TXNSetRectBounds( m_txn , &viewRect , &destRect , true ) ;
2226 /*
2227 TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
2228 m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID);
2229 */
2230 #else
2231
2232 TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
2233 wxMax( m_txnControlBounds.bottom , m_txnControlBounds.top ) ,
2234 wxMax( m_txnControlBounds.right , m_txnControlBounds.left ) , m_txnFrameID);
2235
2236 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2237 // movement, therefore we have to force it
2238
2239 TXNLongRect textRect ;
2240 TXNGetRectBounds( m_txn , NULL , NULL , &textRect ) ;
2241 if ( textRect.left < m_txnControlBounds.left )
2242 {
2243 TXNShowSelection( m_txn , false ) ;
2244 }
2245 #endif
2246 }
2247 }
2248
2249 void wxMacMLTEClassicControl::SetRect( Rect *r )
2250 {
2251 wxMacControl::SetRect( r ) ;
2252 MacUpdatePosition() ;
2253 }
2254
2255 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart)
2256 {
2257 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2258 if ( textctrl == NULL )
2259 return ;
2260
2261 if ( textctrl->MacIsReallyShown() )
2262 {
2263 wxMacWindowClipper clipper( textctrl ) ;
2264 TXNDraw( m_txn , NULL ) ;
2265 }
2266 }
2267
2268 wxInt16 wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
2269 {
2270 Point where = { y , x } ;
2271 ControlPartCode result;
2272
2273 result = 0;
2274 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2275 if ( textctrl == NULL )
2276 return 0 ;
2277
2278 if (textctrl->MacIsReallyShown() )
2279 {
2280 if (PtInRect(where, &m_txnControlBounds))
2281 result = kControlEditTextPart ;
2282 else
2283 {
2284 // sometimes we get the coords also in control local coordinates, therefore test again
2285 if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() )
2286 {
2287 int x = 0 , y = 0 ;
2288 textctrl->MacClientToRootWindow( &x , &y ) ;
2289 where.h += x ;
2290 where.v += y ;
2291 }
2292 if (PtInRect(where, &m_txnControlBounds))
2293 result = kControlEditTextPart ;
2294 else
2295 result = 0;
2296 }
2297 }
2298 return result;
2299 }
2300
2301 wxInt16 wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x, wxInt16 y, void* actionProc )
2302 {
2303 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2304 if ( textctrl == NULL )
2305 return 0;
2306
2307 ControlPartCode partCodeResult = 0;
2308
2309 if (textctrl->MacIsReallyShown() )
2310 {
2311 Point startPt = { y ,x } ;
2312 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2313 if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() )
2314 {
2315 int x = 0 , y = 0 ;
2316 textctrl->MacClientToRootWindow( &x , &y ) ;
2317 startPt.h += x ;
2318 startPt.v += y ;
2319 }
2320
2321 switch (MacControlUserPaneHitTestProc( startPt.h , startPt.v ))
2322 {
2323 case kControlEditTextPart :
2324 {
2325 wxMacWindowClipper clipper( textctrl ) ;
2326
2327 EventRecord rec ;
2328 ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ;
2329 TXNClick( m_txn, &rec );
2330
2331 }
2332 break;
2333 }
2334 }
2335 return partCodeResult;
2336 }
2337
2338 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2339 {
2340 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2341 if ( textctrl == NULL )
2342 return ;
2343
2344 if (textctrl->MacIsReallyShown())
2345 {
2346 if (IsControlActive(m_controlRef))
2347 {
2348 Point mousep;
2349
2350 wxMacWindowClipper clipper( textctrl ) ;
2351 GetMouse(&mousep);
2352
2353 TXNIdle(m_txn);
2354
2355 if (PtInRect(mousep, &m_txnControlBounds))
2356 {
2357 RgnHandle theRgn;
2358 RectRgn((theRgn = NewRgn()), &m_txnControlBounds);
2359 TXNAdjustCursor(m_txn, theRgn);
2360 DisposeRgn(theRgn);
2361 }
2362 }
2363 }
2364 }
2365
2366 wxInt16 wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
2367 {
2368 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2369 if ( textctrl == NULL )
2370 return 0;
2371
2372 wxMacWindowClipper clipper( textctrl ) ;
2373
2374 EventRecord ev ;
2375 memset( &ev , 0 , sizeof( ev ) ) ;
2376 ev.what = keyDown ;
2377 ev.modifiers = modifiers ;
2378 ev.message = (( keyCode << 8 ) & keyCodeMask ) + ( charCode & charCodeMask ) ;
2379 TXNKeyDown( m_txn , &ev);
2380
2381 return kControlEntireControl;
2382 }
2383
2384 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating)
2385 {
2386 MacActivatePaneText( activating );
2387 }
2388
2389 wxInt16 wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action)
2390 {
2391 ControlPartCode focusResult;
2392
2393 focusResult = kControlFocusNoPart;
2394 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2395 if ( textctrl == NULL )
2396 return 0;
2397
2398 wxMacWindowClipper clipper( textctrl ) ;
2399
2400 ControlRef controlFocus = 0 ;
2401 GetKeyboardFocus( m_txnWindow , &controlFocus ) ;
2402 bool wasFocused = ( controlFocus == m_controlRef ) ;
2403
2404 switch (action)
2405 {
2406 case kControlFocusPrevPart:
2407 case kControlFocusNextPart:
2408 MacFocusPaneText( ( !wasFocused));
2409 focusResult = (!wasFocused) ? (ControlPartCode) kControlEditTextPart : (ControlPartCode) kControlFocusNoPart;
2410 break;
2411
2412 case kControlFocusNoPart:
2413 default:
2414 MacFocusPaneText( false);
2415 focusResult = kControlFocusNoPart;
2416 break;
2417 }
2418
2419 return focusResult;
2420 }
2421
2422 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info )
2423 {
2424 }
2425
2426 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer,
2427 const wxString& str,
2428 const wxPoint& pos,
2429 const wxSize& size, long style ) : wxMacMLTEControl( wxPeer )
2430 {
2431 m_font = wxPeer->GetFont() ;
2432 m_windowStyle = style ;
2433 Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ;
2434 wxString st = str ;
2435 wxMacConvertNewlines10To13( &st ) ;
2436
2437 short featurSet;
2438
2439 featurSet = kControlSupportsEmbedding | kControlSupportsFocus | kControlWantsIdle
2440 | kControlWantsActivate | kControlHandlesTracking // | kControlHasSpecialBackground
2441 | kControlGetsFocusOnClick | kControlSupportsLiveFeedback;
2442
2443 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), &bounds, featurSet, &m_controlRef ) );
2444
2445 DoCreate();
2446
2447 AdjustCreationAttributes( *wxWHITE , true) ;
2448
2449 MacSetObjectVisibility( wxPeer->MacIsReallyShown() ) ;
2450
2451 wxMacWindowClipper clipper( m_peer ) ;
2452 SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ;
2453 TXNSetSelection( m_txn, 0, 0);
2454 }
2455
2456 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2457 {
2458 TXNDeleteObject(m_txn);
2459 m_txn = NULL ;
2460 }
2461
2462 void wxMacMLTEClassicControl::VisibilityChanged(bool shown)
2463 {
2464 MacSetObjectVisibility( shown ) ;
2465 wxMacControl::VisibilityChanged( shown ) ;
2466 }
2467
2468 void wxMacMLTEClassicControl::SuperChangedPosition()
2469 {
2470 MacUpdatePosition() ;
2471 wxMacControl::SuperChangedPosition() ;
2472 }
2473
2474 #ifdef __WXMAC_OSX__
2475
2476 ControlUserPaneDrawUPP gTPDrawProc = NULL;
2477 ControlUserPaneHitTestUPP gTPHitProc = NULL;
2478 ControlUserPaneTrackingUPP gTPTrackProc = NULL;
2479 ControlUserPaneIdleUPP gTPIdleProc = NULL;
2480 ControlUserPaneKeyDownUPP gTPKeyProc = NULL;
2481 ControlUserPaneActivateUPP gTPActivateProc = NULL;
2482 ControlUserPaneFocusUPP gTPFocusProc = NULL;
2483
2484 static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part)
2485 {
2486 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2487 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2488 if ( win )
2489 win->MacControlUserPaneDrawProc(part) ;
2490 }
2491
2492 static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where)
2493 {
2494 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2495 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2496 if ( win )
2497 return win->MacControlUserPaneHitTestProc(where.h , where.v) ;
2498 else
2499 return kControlNoPart ;
2500 }
2501
2502 static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc)
2503 {
2504 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2505 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2506 if ( win )
2507 return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ;
2508 else
2509 return kControlNoPart ;
2510 }
2511
2512 static pascal void wxMacControlUserPaneIdleProc(ControlRef control)
2513 {
2514 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2515 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2516 if ( win )
2517 win->MacControlUserPaneIdleProc() ;
2518 }
2519
2520 static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers)
2521 {
2522 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2523 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2524 if ( win )
2525 return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ;
2526 else
2527 return kControlNoPart ;
2528 }
2529
2530 static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating)
2531 {
2532 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2533 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2534 if ( win )
2535 win->MacControlUserPaneActivateProc(activating) ;
2536 }
2537
2538 static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action)
2539 {
2540 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2541 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2542 if ( win )
2543 return win->MacControlUserPaneFocusProc(action) ;
2544 else
2545 return kControlNoPart ;
2546 }
2547
2548 /*
2549 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
2550 {
2551 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2552 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2553 if ( win )
2554 win->MacControlUserPaneBackgroundProc(info) ;
2555 }
2556 */
2557 #endif
2558
2559 // TXNRegisterScrollInfoProc
2560
2561 OSStatus wxMacMLTEClassicControl::DoCreate()
2562 {
2563 Rect bounds;
2564
2565 OSStatus err = noErr ;
2566
2567 /* set up our globals */
2568 #ifdef __WXMAC_OSX__
2569 if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc);
2570 if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc);
2571 if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc);
2572 if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc);
2573 if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc);
2574 if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc);
2575 if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc);
2576
2577 if (gTXNScrollInfoProc == NULL ) gTXNScrollInfoProc = NewTXNScrollInfoUPP(TXNScrollInfoProc) ;
2578 if (gTXNScrollActionProc == NULL ) gTXNScrollActionProc = NewControlActionUPP(TXNScrollActionProc) ;
2579 #endif
2580
2581 /* set the initial settings for our private data */
2582
2583 m_txnWindow =GetControlOwner(m_controlRef);
2584 m_txnPort = (GrafPtr) GetWindowPort(m_txnWindow);
2585
2586 #ifdef __WXMAC_OSX__
2587 /* set up the user pane procedures */
2588 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneDrawProcTag, sizeof(gTPDrawProc), &gTPDrawProc);
2589 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneHitTestProcTag, sizeof(gTPHitProc), &gTPHitProc);
2590 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneTrackingProcTag, sizeof(gTPTrackProc), &gTPTrackProc);
2591 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneIdleProcTag, sizeof(gTPIdleProc), &gTPIdleProc);
2592 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneKeyDownProcTag, sizeof(gTPKeyProc), &gTPKeyProc);
2593 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneActivateProcTag, sizeof(gTPActivateProc), &gTPActivateProc);
2594 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneFocusProcTag, sizeof(gTPFocusProc), &gTPFocusProc);
2595 #endif
2596 /* calculate the rectangles used by the control */
2597 UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds);
2598
2599 m_txnControlBounds = bounds ;
2600 m_txnVisBounds = bounds ;
2601
2602 CGrafPtr origPort = NULL ;
2603 GDHandle origDev = NULL ;
2604 GetGWorld( &origPort , &origDev ) ;
2605 SetPort(m_txnPort);
2606
2607 /* create the new edit field */
2608
2609 TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( m_windowStyle ) ;
2610
2611 #ifdef __WXMAC_OSX__
2612
2613 // the scrollbars are not correctly embedded but are inserted at the root
2614 // this gives us problems as we have erratic redraws even over the structure
2615 // area
2616
2617 m_sbHorizontal = 0 ;
2618 m_sbVertical = 0 ;
2619 m_lastHorizontalValue = 0 ;
2620 m_lastVerticalValue = 0 ;
2621
2622 Rect sb = { 0 , 0 , 0 , 0 } ;
2623 if ( frameOptions & kTXNWantVScrollBarMask )
2624 {
2625 CreateScrollBarControl( m_txnWindow , &sb , 0 , 0 , 100 , 1 , true , gTXNScrollActionProc , &m_sbVertical ) ;
2626 SetControlReference( m_sbVertical , (SInt32) this ) ;
2627 SetControlAction( m_sbVertical, gTXNScrollActionProc );
2628 ShowControl( m_sbVertical ) ;
2629 EmbedControl( m_sbVertical , m_controlRef ) ;
2630 frameOptions &= ~kTXNWantVScrollBarMask ;
2631 }
2632 if ( frameOptions & kTXNWantHScrollBarMask )
2633 {
2634 CreateScrollBarControl( m_txnWindow , &sb , 0 , 0 , 100 , 1 , true , gTXNScrollActionProc , &m_sbHorizontal ) ;
2635 SetControlReference( m_sbHorizontal , (SInt32) this ) ;
2636 SetControlAction( m_sbHorizontal, gTXNScrollActionProc );
2637 ShowControl( m_sbHorizontal ) ;
2638 EmbedControl( m_sbHorizontal , m_controlRef ) ;
2639 frameOptions &= ~(kTXNWantHScrollBarMask | kTXNDrawGrowIconMask);
2640 }
2641
2642 #endif
2643
2644 verify_noerr(TXNNewObject(NULL, m_txnWindow , &bounds,
2645 frameOptions ,
2646 kTXNTextEditStyleFrameType,
2647 kTXNTextensionFile,
2648 kTXNSystemDefaultEncoding,
2649 &m_txn, &m_txnFrameID, NULL ) );
2650 /*
2651 TXNCarbonEventInfo cInfo ;
2652
2653 cInfo.useCarbonEvents = false ;
2654 cInfo.filler = 0 ;
2655 cInfo.flags = 0 ;
2656 cInfo.fDictionary = NULL ;
2657
2658 TXNControlTag iControlTags[] =
2659 {
2660 kTXNUseCarbonEvents ,
2661 };
2662 TXNControlData iControlData[] =
2663 {
2664 {(UInt32) &cInfo },
2665 };
2666
2667 int toptag = WXSIZEOF( iControlTags ) ;
2668
2669 verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag,
2670 iControlTags, iControlData )) ;
2671
2672 */
2673 #ifdef __WXMAC_OSX__
2674 TXNRegisterScrollInfoProc( m_txn, gTXNScrollInfoProc, (SInt32) this);
2675 #endif
2676
2677 SetGWorld( origPort , origDev ) ;
2678 return err;
2679 }
2680
2681 // ----------------------------------------------------------------------------
2682 // MLTE control implementation (OSX part)
2683 // ----------------------------------------------------------------------------
2684
2685 #if TARGET_API_MAC_OSX
2686
2687 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2688
2689 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer,
2690 const wxString& str,
2691 const wxPoint& pos,
2692 const wxSize& size, long style ) : wxMacMLTEControl( wxPeer )
2693 {
2694 m_font = wxPeer->GetFont() ;
2695 m_windowStyle = style ;
2696 Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ;
2697 wxString st = str ;
2698 wxMacConvertNewlines10To13( &st ) ;
2699
2700 HIRect hr = { bounds.left , bounds.top , bounds.right - bounds.left , bounds.bottom- bounds.top } ;
2701
2702 m_scrollView = NULL ;
2703 TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( style ) ;
2704 if ( frameOptions & (kTXNWantVScrollBarMask|kTXNWantHScrollBarMask) )
2705 {
2706 HIScrollViewCreate(( frameOptions & kTXNWantHScrollBarMask ? kHIScrollViewOptionsHorizScroll : 0) |
2707 ( frameOptions & kTXNWantVScrollBarMask ? kHIScrollViewOptionsVertScroll: 0 ) , &m_scrollView ) ;
2708
2709 HIViewSetFrame( m_scrollView, &hr );
2710 HIViewSetVisible( m_scrollView, true );
2711 }
2712
2713 m_textView = NULL ;
2714 HITextViewCreate( NULL , 0, frameOptions , &m_textView ) ;
2715 m_txn = HITextViewGetTXNObject( m_textView) ;
2716 HIViewSetVisible( m_textView , true ) ;
2717 if ( m_scrollView )
2718 {
2719 HIViewAddSubview( m_scrollView , m_textView ) ;
2720 m_controlRef = m_scrollView ;
2721 wxPeer->MacInstallEventHandler( (WXWidget) m_textView ) ;
2722 }
2723 else
2724 {
2725 HIViewSetFrame( m_textView, &hr );
2726 m_controlRef = m_textView ;
2727 }
2728
2729 AdjustCreationAttributes( *wxWHITE , true ) ;
2730
2731 wxMacWindowClipper c( m_peer ) ;
2732 SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ;
2733
2734 TXNSetSelection( m_txn, 0, 0);
2735 TXNShowSelection( m_txn, kTXNShowStart);
2736
2737 }
2738
2739 OSStatus wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart )
2740 {
2741 return SetKeyboardFocus( GetControlOwner( m_textView ) ,
2742 m_textView , focusPart ) ;
2743 }
2744
2745 bool wxMacMLTEHIViewControl::HasFocus() const
2746 {
2747 ControlRef control ;
2748 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
2749 return control == m_textView ;
2750 }
2751
2752 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2753
2754
2755 #endif
2756
2757 #endif // wxUSE_TEXTCTRL