1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/textctrl.cpp
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/textctrl.h"
23 #include "wx/button.h"
25 #include "wx/settings.h"
26 #include "wx/msgdlg.h"
27 #include "wx/toplevel.h"
31 #include <sys/types.h>
37 #if wxUSE_STD_IOSTREAM
45 #include "wx/filefn.h"
46 #include "wx/sysopt.h"
47 #include "wx/thread.h"
49 #include "wx/osx/private.h"
50 #include "wx/osx/carbon/private/mactext.h"
56 virtual ~wxMacFunctor() {}
58 virtual void* operator()() = 0 ;
60 static void* CallBackProc( void *param
)
62 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
63 void *result
= (*f
)() ;
68 template<typename classtype
, typename param1type
>
70 class wxMacObjectFunctor1
: public wxMacFunctor
72 typedef void (classtype::*function
)( param1type p1
) ;
73 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
75 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
83 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
91 virtual ~wxMacObjectFunctor1() {}
93 virtual void* operator()()
95 (m_object
->*m_function
)( m_param1
) ;
100 classtype
* m_object
;
101 param1type m_param1
;
104 function m_function
;
105 ref_function m_refFunction
;
109 template<typename classtype
, typename param1type
>
110 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
112 wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ;
114 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
118 template<typename classtype
, typename param1type
>
119 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
121 wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ;
123 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
127 template<typename classtype
, typename param1type
>
128 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
131 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
136 template<typename classtype
, typename param1type
>
137 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
140 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
145 class WXDLLEXPORT wxMacPortSaver
147 DECLARE_NO_COPY_CLASS(wxMacPortSaver
)
150 wxMacPortSaver( GrafPtr port
);
158 Clips to the visible region of a control within the current port
161 class WXDLLEXPORT wxMacWindowClipper
: public wxMacPortSaver
163 DECLARE_NO_COPY_CLASS(wxMacWindowClipper
)
166 wxMacWindowClipper( const wxWindow
* win
);
167 ~wxMacWindowClipper();
170 RgnHandle m_formerClip
;
174 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
176 ::GetPort( &m_port
);
180 wxMacPortSaver::~wxMacPortSaver()
185 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
186 wxMacPortSaver( (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) )
188 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
189 m_formerClip
= NewRgn() ;
190 m_newClip
= NewRgn() ;
191 GetClip( m_formerClip
) ;
195 // guard against half constructed objects, this just leads to a empty clip
196 if ( win
->GetPeer() )
199 win
->MacWindowToRootWindow( &x
, &y
) ;
201 // get area including focus rect
202 HIShapeGetAsQDRgn( ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
);
203 if ( !EmptyRgn( m_newClip
) )
204 OffsetRgn( m_newClip
, x
, y
) ;
207 SetClip( m_newClip
) ;
211 wxMacWindowClipper::~wxMacWindowClipper()
213 SetPort( m_newPort
) ;
214 SetClip( m_formerClip
) ;
215 DisposeRgn( m_newClip
) ;
216 DisposeRgn( m_formerClip
) ;
219 // common parts for implementations based on MLTE
221 class wxMacMLTEControl
: public wxMacControl
, public wxTextWidgetImpl
224 wxMacMLTEControl( wxTextCtrl
*peer
) ;
225 ~wxMacMLTEControl() {}
226 virtual wxString
GetStringValue() const ;
227 virtual void SetStringValue( const wxString
&str
) ;
229 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
231 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
233 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
234 virtual void SetBackgroundColour(const wxColour
& col
);
235 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
236 virtual void Copy() ;
238 virtual void Paste() ;
239 virtual bool CanPaste() const ;
240 virtual void SetEditable( bool editable
) ;
241 virtual long GetLastPosition() const ;
242 virtual void Replace( long from
, long to
, const wxString
&str
) ;
243 virtual void Remove( long from
, long to
) ;
244 virtual void GetSelection( long* from
, long* to
) const ;
245 virtual void SetSelection( long from
, long to
) ;
247 virtual void WriteText( const wxString
& str
) ;
249 virtual bool HasOwnContextMenu() const
251 TXNCommandEventSupportOptions options
;
252 TXNGetCommandEventSupport( m_txn
, & options
) ;
253 return options
& kTXNSupportEditCommandProcessing
;
256 virtual void CheckSpelling(bool check
)
258 TXNSetSpellCheckAsYouType( m_txn
, (Boolean
) check
);
260 virtual void Clear() ;
262 virtual bool CanUndo() const ;
263 virtual void Undo() ;
264 virtual bool CanRedo() const;
265 virtual void Redo() ;
266 virtual int GetNumberOfLines() const ;
267 virtual long XYToPosition(long x
, long y
) const ;
268 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
269 virtual void ShowPosition( long pos
) ;
270 virtual int GetLineLength(long lineNo
) const ;
271 virtual wxString
GetLineText(long lineNo
) const ;
273 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
274 TXNObject
GetTXNObject() { return m_txn
; }
277 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
282 // implementation available under OSX
284 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
287 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
290 const wxSize
& size
, long style
) ;
291 virtual ~wxMacMLTEHIViewControl() ;
293 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
294 virtual bool HasFocus() const ;
295 virtual void SetBackgroundColour(const wxColour
& col
) ;
298 HIViewRef m_scrollView
;
299 HIViewRef m_textView
;
302 // 'classic' MLTE implementation
304 class wxMacMLTEClassicControl
: public wxMacMLTEControl
307 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
310 const wxSize
& size
, long style
) ;
311 virtual ~wxMacMLTEClassicControl() ;
313 virtual void VisibilityChanged(bool shown
) ;
314 virtual void SuperChangedPosition() ;
316 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
317 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
318 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
319 virtual void MacControlUserPaneIdleProc() ;
320 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
321 virtual void MacControlUserPaneActivateProc(bool activating
) ;
322 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
323 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
325 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
327 MacControlUserPaneIdleProc();
331 virtual void Move(int x
, int y
, int width
, int height
);
336 void MacUpdatePosition() ;
337 void MacActivatePaneText(bool setActive
) ;
338 void MacFocusPaneText(bool setFocus
) ;
339 void MacSetObjectVisibility(bool vis
) ;
342 TXNFrameID m_txnFrameID
;
344 WindowRef m_txnWindow
;
345 // bounds of the control as we last did set the txn frames
346 Rect m_txnControlBounds
;
347 Rect m_txnVisBounds
;
349 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
350 static pascal void TXNScrollInfoProc(
351 SInt32 iValue
, SInt32 iMaximumValue
,
352 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
354 ControlRef m_sbHorizontal
;
355 SInt32 m_lastHorizontalValue
;
356 ControlRef m_sbVertical
;
357 SInt32 m_lastVerticalValue
;
360 wxWidgetImplType
* wxWidgetImpl::CreateTextControl( wxTextCtrl
* wxpeer
,
369 bool forceMLTE
= false ;
371 #if wxUSE_SYSTEM_OPTIONS
372 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
378 if ( UMAGetSystemVersion() >= 0x1050 )
381 wxMacControl
* peer
= NULL
;
385 if ( style
& wxTE_MULTILINE
|| ( UMAGetSystemVersion() >= 0x1050 ) )
386 peer
= new wxMacMLTEHIViewControl( wxpeer
, str
, pos
, size
, style
) ;
391 if ( !(style
& wxTE_MULTILINE
) && !forceMLTE
)
393 peer
= new wxMacUnicodeTextControl( wxpeer
, str
, pos
, size
, style
) ;
397 // the horizontal single line scrolling bug that made us keep the classic implementation
399 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
401 peer
= new wxMacMLTEClassicControl( wxpeer
, str
, pos
, size
, style
) ;
406 // ----------------------------------------------------------------------------
407 // standard unicode control implementation
408 // ----------------------------------------------------------------------------
410 // the current unicode textcontrol implementation has a bug : only if the control
411 // is currently having the focus, the selection can be retrieved by the corresponding
412 // data tag. So we have a mirroring using a member variable
413 // TODO : build event table using virtual member functions for wxMacControl
415 static const EventTypeSpec unicodeTextControlEventList
[] =
417 { kEventClassControl
, kEventControlSetFocusPart
} ,
420 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
422 OSStatus result
= eventNotHandledErr
;
423 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
424 wxMacCarbonEvent
cEvent( event
) ;
426 switch ( GetEventKind( event
) )
428 case kEventControlSetFocusPart
:
430 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
431 if ( controlPart
== kControlFocusNoPart
)
433 // about to loose focus -> store selection to field
434 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
436 result
= CallNextEventHandler(handler
,event
) ;
437 if ( controlPart
!= kControlFocusNoPart
)
439 // about to gain focus -> set selection from field
440 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
451 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
453 OSStatus result
= eventNotHandledErr
;
455 switch ( GetEventClass( event
) )
457 case kEventClassControl
:
458 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
467 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
469 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
) : wxMacControl( wxPeer
)
473 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
476 const wxSize
& size
, long style
)
477 : wxMacControl( wxPeer
)
479 m_font
= wxPeer
->GetFont() ;
480 m_windowStyle
= style
;
481 m_selection
.selStart
= m_selection
.selEnd
= 0;
482 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
484 wxMacConvertNewlines10To13( &st
) ;
485 wxCFStringRef
cf(st
, m_font
.GetEncoding()) ;
487 m_valueTag
= kControlEditTextCFStringTag
;
488 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
491 m_valueTag
= kControlEditTextPasswordCFStringTag
;
493 OSStatus err
= CreateEditUnicodeTextControl(
494 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cf
,
495 isPassword
, NULL
, &m_controlRef
) ;
498 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
499 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
501 InstallEventHandlers();
504 void wxMacUnicodeTextControl::InstallEventHandlers()
506 ::InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
507 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
511 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
515 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
517 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
519 // work around a refresh issue insofar as not always the entire content is shown,
520 // even if this would be possible
521 ControlEditTextSelectionRec sel
;
522 CFStringRef value
= NULL
;
524 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
525 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
526 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
527 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
533 wxString
wxMacUnicodeTextControl::GetStringValue() const
536 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
539 wxCFStringRef
cf(value
) ;
540 result
= cf
.AsString() ;
544 wxMacConvertNewlines13To10( &result
) ;
546 wxMacConvertNewlines10To13( &result
) ;
552 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
555 wxMacConvertNewlines10To13( &st
) ;
556 wxCFStringRef
cf( st
, m_font
.GetEncoding() ) ;
557 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
560 void wxMacUnicodeTextControl::Copy()
562 SendHICommand( kHICommandCopy
) ;
565 void wxMacUnicodeTextControl::Cut()
567 SendHICommand( kHICommandCut
) ;
570 void wxMacUnicodeTextControl::Paste()
572 SendHICommand( kHICommandPaste
) ;
575 bool wxMacUnicodeTextControl::CanPaste() const
580 void wxMacUnicodeTextControl::SetEditable(bool WXUNUSED(editable
))
582 #if 0 // leads to problem because text cannot be selected anymore
583 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
587 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
589 ControlEditTextSelectionRec sel
;
591 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
596 *from
= sel
.selStart
;
601 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
603 ControlEditTextSelectionRec sel
;
606 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
609 wxCFStringRef
cf(value
) ;
610 textLength
= cf
.AsString().length() ;
613 if ((from
== -1) && (to
== -1))
620 from
= wxMin(textLength
,wxMax(from
,0)) ;
624 to
= wxMax(0,wxMin(textLength
,to
)) ;
627 sel
.selStart
= from
;
630 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
635 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
637 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
638 if ( !wxIsMainThread() )
641 // unfortunately CW 8 is not able to correctly deduce the template types,
642 // so we have to instantiate explicitly
643 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( (wxTextCtrl
*) GetWXPeer() , &wxTextCtrl::WriteText
, str
) ;
649 wxMacConvertNewlines10To13( &st
) ;
653 wxCFStringRef
cf(st
, m_font
.GetEncoding() ) ;
654 CFStringRef value
= cf
;
655 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
659 wxString val
= GetStringValue() ;
661 GetSelection( &start
, &end
) ;
662 val
.Remove( start
, end
- start
) ;
663 val
.insert( start
, str
) ;
664 SetStringValue( val
) ;
665 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
669 // ----------------------------------------------------------------------------
670 // MLTE control implementation (common part)
671 // ----------------------------------------------------------------------------
673 // if MTLE is read only, no changes at all are allowed, not even from
674 // procedural API, in order to allow changes via API all the same we must undo
675 // the readonly status while we are executing, this class helps to do so
677 class wxMacEditHelper
680 wxMacEditHelper( TXNObject txn
)
682 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
684 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
685 if ( m_data
[0].uValue
== kTXNReadOnly
)
687 TXNControlData data
[] = { { kTXNReadWrite
} } ;
688 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
694 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
695 if ( m_data
[0].uValue
== kTXNReadOnly
)
696 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
701 TXNControlData m_data
[1] ;
704 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
705 : wxMacControl( peer
)
707 SetNeedsFocusRect( true ) ;
710 wxString
wxMacMLTEControl::GetStringValue() const
719 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
728 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
729 if ( actualSize
> 0 )
733 #if SIZEOF_WCHAR_T == 2
734 ptr
= new wxChar
[actualSize
+ 1] ;
735 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
737 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
739 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
740 wxMBConvUTF16 converter
;
741 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
742 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
743 ptr
= new wxChar
[noChars
+ 1] ;
745 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
746 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
751 ptr
[actualSize
] = 0 ;
752 result
= wxString( ptr
) ;
756 DisposeHandle( theText
) ;
760 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
769 actualSize
= GetHandleSize( theText
) ;
770 if ( actualSize
> 0 )
773 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
777 DisposeHandle( theText
) ;
783 wxMacConvertNewlines13To10( &result
) ;
785 wxMacConvertNewlines10To13( &result
) ;
791 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
794 wxMacConvertNewlines10To13( &st
);
798 wxMacWindowClipper
c( GetWXPeer() ) ;
802 wxMacEditHelper
help( m_txn
);
803 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
806 TXNSetSelection( m_txn
, 0, 0 );
807 TXNShowSelection( m_txn
, kTXNShowStart
);
811 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
813 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
815 frameOptions
|= kTXNDoFontSubstitutionMask
;
817 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
818 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
820 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
821 frameOptions
|= kTXNWantHScrollBarMask
;
823 if ( wxStyle
& wxTE_MULTILINE
)
825 if ( ! (wxStyle
& wxTE_DONTWRAP
) )
826 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
828 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
830 frameOptions
|= kTXNWantVScrollBarMask
;
832 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
833 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
834 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
835 // if ( frameOptions & kTXNWantHScrollBarMask )
836 // frameOptions |= kTXNDrawGrowIconMask ;
841 frameOptions
|= kTXNSingleLineOnlyMask
;
844 return frameOptions
;
847 void wxMacMLTEControl::AdjustCreationAttributes(const wxColour
&background
,
848 bool WXUNUSED(visible
))
850 TXNControlTag iControlTags
[] =
852 kTXNDoFontSubstitution
,
853 kTXNWordWrapStateTag
,
855 TXNControlData iControlData
[] =
861 int toptag
= WXSIZEOF( iControlTags
) ;
863 if ( m_windowStyle
& wxTE_MULTILINE
)
865 iControlData
[1].uValue
=
866 (m_windowStyle
& wxTE_DONTWRAP
)
871 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
874 // setting the default font:
875 // under 10.2 this causes a visible caret, therefore we avoid it
881 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
883 TXNTypeAttributes typeAttr
[] =
885 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
886 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
887 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
890 err
= TXNSetTypeAttributes(
891 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
892 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
895 if ( m_windowStyle
& wxTE_PASSWORD
)
898 err
= TXNEchoMode( m_txn
, c
, 0 , true );
903 tback
.bgType
= kTXNBackgroundTypeRGB
;
904 background
.GetRGBColor( &tback
.bg
.color
);
905 TXNSetBackground( m_txn
, &tback
);
908 TXNCommandEventSupportOptions options
;
909 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
912 kTXNSupportEditCommandProcessing
913 | kTXNSupportEditCommandUpdating
914 | kTXNSupportFontCommandProcessing
915 | kTXNSupportFontCommandUpdating
;
917 // only spell check when not read-only
918 // use system options for the default
919 bool checkSpelling
= false ;
920 if ( !(m_windowStyle
& wxTE_READONLY
) )
922 #if wxUSE_SYSTEM_OPTIONS
923 if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) == 1) )
925 checkSpelling
= true ;
932 kTXNSupportSpellCheckCommandProcessing
933 | kTXNSupportSpellCheckCommandUpdating
;
935 TXNSetCommandEventSupport( m_txn
, options
) ;
939 void wxMacMLTEControl::SetBackgroundColour(const wxColour
& col
)
942 tback
.bgType
= kTXNBackgroundTypeRGB
;
943 col
.GetRGBColor(&tback
.bg
.color
);
944 TXNSetBackground( m_txn
, &tback
);
947 static inline int wxConvertToTXN(int x
)
949 return wx_static_cast(int, x
/ 254.0 * 72 + 0.5);
952 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
954 TXNTypeAttributes typeAttr
[4] ;
956 size_t typeAttrCount
= 0 ;
959 TXNControlTag controlTags
[4];
960 TXNControlData controlData
[4];
961 size_t controlAttrCount
= 0;
965 bool relayout
= false;
968 if ( style
.HasFont() )
970 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
971 font
= style
.GetFont() ;
972 typeAttr
[typeAttrCount
].tag
= kTXNATSUIStyle
;
973 typeAttr
[typeAttrCount
].size
= kTXNATSUIStyleSize
;
974 typeAttr
[typeAttrCount
].data
.dataPtr
= font
.MacGetATSUStyle() ;
978 if ( style
.HasTextColour() )
980 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
981 style
.GetTextColour().GetRGBColor( &color
);
982 typeAttr
[typeAttrCount
].tag
= kTXNQDFontColorAttribute
;
983 typeAttr
[typeAttrCount
].size
= kTXNQDFontColorAttributeSize
;
984 typeAttr
[typeAttrCount
].data
.dataPtr
= (void*) &color
;
988 if ( style
.HasAlignment() )
990 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
993 switch ( style
.GetAlignment() )
995 case wxTEXT_ALIGNMENT_LEFT
:
996 align
= kTXNFlushLeft
;
998 case wxTEXT_ALIGNMENT_CENTRE
:
1001 case wxTEXT_ALIGNMENT_RIGHT
:
1002 align
= kTXNFlushRight
;
1004 case wxTEXT_ALIGNMENT_JUSTIFIED
:
1005 align
= kTXNFullJust
;
1008 case wxTEXT_ALIGNMENT_DEFAULT
:
1009 align
= kTXNFlushDefault
;
1013 controlTags
[controlAttrCount
] = kTXNJustificationTag
;
1014 controlData
[controlAttrCount
].sValue
= align
;
1015 controlAttrCount
++ ;
1018 if ( style
.HasLeftIndent() || style
.HasRightIndent() )
1020 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1021 controlTags
[controlAttrCount
] = kTXNMarginsTag
;
1022 controlData
[controlAttrCount
].marginsPtr
= &margins
;
1023 verify_noerr( TXNGetTXNObjectControls (m_txn
, 1 ,
1024 &controlTags
[controlAttrCount
], &controlData
[controlAttrCount
]) );
1025 if ( style
.HasLeftIndent() )
1027 margins
.leftMargin
= wxConvertToTXN(style
.GetLeftIndent());
1029 if ( style
.HasRightIndent() )
1031 margins
.rightMargin
= wxConvertToTXN(style
.GetRightIndent());
1033 controlAttrCount
++ ;
1036 if ( style
.HasTabs() )
1038 const wxArrayInt
& tabarray
= style
.GetTabs();
1039 // unfortunately Mac only applies a tab distance, not individually different tabs
1040 controlTags
[controlAttrCount
] = kTXNTabSettingsTag
;
1041 if ( tabarray
.size() > 0 )
1042 controlData
[controlAttrCount
].tabValue
.value
= wxConvertToTXN(tabarray
[0]);
1044 controlData
[controlAttrCount
].tabValue
.value
= 72 ;
1046 controlData
[controlAttrCount
].tabValue
.tabType
= kTXNLeftTab
;
1047 controlAttrCount
++ ;
1050 // unfortunately the relayout is not automatic
1051 if ( controlAttrCount
> 0 )
1053 verify_noerr( TXNSetTXNObjectControls (m_txn
, false /* don't clear all */, controlAttrCount
,
1054 controlTags
, controlData
) );
1058 if ( typeAttrCount
> 0 )
1060 verify_noerr( TXNSetTypeAttributes( m_txn
, typeAttrCount
, typeAttr
, from
, to
) );
1071 TXNRecalcTextLayout( m_txn
);
1075 void wxMacMLTEControl::SetFont(const wxFont
& font
,
1076 const wxColour
& foreground
,
1077 long WXUNUSED(windowStyle
))
1079 wxMacEditHelper
help( m_txn
) ;
1080 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1083 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1085 wxMacEditHelper
help( m_txn
) ;
1086 TXNSetAttribute( style
, start
, end
) ;
1089 void wxMacMLTEControl::Copy()
1094 void wxMacMLTEControl::Cut()
1099 void wxMacMLTEControl::Paste()
1104 bool wxMacMLTEControl::CanPaste() const
1106 return TXNIsScrapPastable() ;
1109 void wxMacMLTEControl::SetEditable(bool editable
)
1111 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1112 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1113 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1116 long wxMacMLTEControl::GetLastPosition() const
1118 wxTextPos actualsize
= 0 ;
1121 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1126 actualsize
= GetHandleSize( theText
) ;
1127 DisposeHandle( theText
) ;
1137 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1139 wxString value
= str
;
1140 wxMacConvertNewlines10To13( &value
) ;
1142 wxMacEditHelper
help( m_txn
) ;
1144 wxMacWindowClipper
c( GetWXPeer() ) ;
1147 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
) ;
1149 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1152 void wxMacMLTEControl::Remove( long from
, long to
)
1155 wxMacWindowClipper
c( GetWXPeer() ) ;
1157 wxMacEditHelper
help( m_txn
) ;
1158 TXNSetSelection( m_txn
, from
, to
) ;
1162 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1165 TXNGetSelection( m_txn
, &f
, &t
) ;
1170 void wxMacMLTEControl::SetSelection( long from
, long to
)
1173 wxMacWindowClipper
c( GetWXPeer() ) ;
1176 // change the selection
1177 if ((from
== -1) && (to
== -1))
1178 TXNSelectAll( m_txn
);
1180 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
);
1182 TXNShowSelection( m_txn
, kTXNShowStart
);
1185 void wxMacMLTEControl::WriteText( const wxString
& str
)
1187 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
1188 if ( !wxIsMainThread() )
1190 #if wxOSX_USE_CARBON
1191 // unfortunately CW 8 is not able to correctly deduce the template types,
1192 // so we have to instantiate explicitly
1193 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( (wxTextCtrl
*) GetWXPeer() , &wxTextCtrl::WriteText
, str
) ;
1199 wxMacConvertNewlines10To13( &st
) ;
1201 long start
, end
, dummy
;
1203 GetSelection( &start
, &dummy
) ;
1205 wxMacWindowClipper
c( GetWXPeer() ) ;
1209 wxMacEditHelper
helper( m_txn
) ;
1210 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1213 GetSelection( &dummy
, &end
) ;
1215 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1218 void wxMacMLTEControl::Clear()
1221 wxMacWindowClipper
c( GetWXPeer() ) ;
1223 wxMacEditHelper
st( m_txn
) ;
1224 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1228 bool wxMacMLTEControl::CanUndo() const
1230 return TXNCanUndo( m_txn
, NULL
) ;
1233 void wxMacMLTEControl::Undo()
1238 bool wxMacMLTEControl::CanRedo() const
1240 return TXNCanRedo( m_txn
, NULL
) ;
1243 void wxMacMLTEControl::Redo()
1248 int wxMacMLTEControl::GetNumberOfLines() const
1250 ItemCount lines
= 0 ;
1251 TXNGetLineCount( m_txn
, &lines
) ;
1256 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1261 // TODO: find a better implementation : while we can get the
1262 // line metrics of a certain line, we don't get its starting
1263 // position, so it would probably be rather a binary search
1264 // for the start position
1265 long xpos
= 0, ypos
= 0 ;
1266 int lastHeight
= 0 ;
1269 lastpos
= GetLastPosition() ;
1270 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1272 if ( y
== ypos
&& x
== xpos
)
1275 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
1277 if ( curpt
.v
> lastHeight
)
1283 lastHeight
= curpt
.v
;
1292 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
1302 lastpos
= GetLastPosition() ;
1303 if ( pos
<= lastpos
)
1305 // TODO: find a better implementation - while we can get the
1306 // line metrics of a certain line, we don't get its starting
1307 // position, so it would probably be rather a binary search
1308 // for the start position
1309 long xpos
= 0, ypos
= 0 ;
1310 int lastHeight
= 0 ;
1313 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1315 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
1317 if ( curpt
.v
> lastHeight
)
1323 lastHeight
= curpt
.v
;
1338 void wxMacMLTEControl::ShowPosition( long pos
)
1340 Point current
, desired
;
1341 TXNOffset selstart
, selend
;
1343 TXNGetSelection( m_txn
, &selstart
, &selend
);
1344 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1345 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1347 // TODO: use HIPoints for 10.3 and above
1349 OSErr theErr
= noErr
;
1350 long dv
= desired
.v
- current
.v
;
1351 long dh
= desired
.h
- current
.h
;
1352 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
1353 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1355 // there will be an error returned for classic MLTE implementation when the control is
1356 // invisible, but HITextView works correctly, so we don't assert that one
1357 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
1360 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1363 #if SIZEOF_WCHAR_T == 2
1364 size_t len
= st
.length() ;
1365 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
1367 wxMBConvUTF16 converter
;
1368 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
1369 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
1370 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
1371 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
1375 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
1376 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
1380 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1384 if ( lineNo
< GetNumberOfLines() )
1387 Fixed lineWidth
, lineHeight
, currentHeight
;
1390 // get the first possible position in the control
1391 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1393 // Iterate through the lines until we reach the one we want,
1394 // adding to our current y pixel point position
1397 while (ypos
< lineNo
)
1399 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1400 currentHeight
+= lineHeight
;
1403 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1404 TXNOffset theOffset
;
1405 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1407 wxString content
= GetStringValue() ;
1408 Point currentPoint
= thePoint
;
1409 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1411 line
+= content
[theOffset
];
1412 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1419 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1423 if ( lineNo
< GetNumberOfLines() )
1426 Fixed lineWidth
, lineHeight
, currentHeight
;
1429 // get the first possible position in the control
1430 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1432 // Iterate through the lines until we reach the one we want,
1433 // adding to our current y pixel point position
1436 while (ypos
< lineNo
)
1438 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1439 currentHeight
+= lineHeight
;
1442 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1443 TXNOffset theOffset
;
1444 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1446 wxString content
= GetStringValue() ;
1447 Point currentPoint
= thePoint
;
1448 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1451 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1458 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
1460 // ----------------------------------------------------------------------------
1461 // MLTE control implementation (classic part)
1462 // ----------------------------------------------------------------------------
1464 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
1465 // has to live on. We have different problems coming from outdated implementations on the
1466 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
1467 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
1468 // no way out, therefore we are using our own implementation and our own scrollbars ....
1470 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
1471 ControlActionUPP gTXNScrollActionProc
= NULL
;
1473 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
1474 SInt32 iValue
, SInt32 iMaximumValue
,
1475 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
1477 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
1478 SInt32 value
= wxMax( iValue
, 0 ) ;
1479 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
1481 if ( iScrollBarOrientation
== kTXNHorizontal
)
1483 if ( mlte
->m_sbHorizontal
)
1485 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
1486 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
1487 mlte
->m_lastHorizontalValue
= value
;
1490 else if ( iScrollBarOrientation
== kTXNVertical
)
1492 if ( mlte
->m_sbVertical
)
1494 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
1495 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
1496 mlte
->m_lastVerticalValue
= value
;
1501 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
1503 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
1507 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
1511 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
1513 SInt32 minimum
= 0 ;
1514 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
1515 SInt32 value
= GetControl32BitValue( controlRef
) ;
1520 case kControlDownButtonPart
:
1524 case kControlUpButtonPart
:
1528 case kControlPageDownPart
:
1529 delta
= GetControlViewSize( controlRef
) ;
1532 case kControlPageUpPart
:
1533 delta
= -GetControlViewSize( controlRef
) ;
1536 case kControlIndicatorPart
:
1537 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
1546 SInt32 newValue
= value
;
1548 if ( partCode
!= kControlIndicatorPart
)
1550 if ( value
+ delta
< minimum
)
1551 delta
= minimum
- value
;
1552 if ( value
+ delta
> maximum
)
1553 delta
= maximum
- value
;
1555 SetControl32BitValue( controlRef
, value
+ delta
) ;
1556 newValue
= value
+ delta
;
1559 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
1560 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
1563 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
1564 &verticalDelta
, &horizontalDelta
);
1565 verify_noerr( err
);
1568 mlte
->m_lastHorizontalValue
= newValue
;
1570 mlte
->m_lastVerticalValue
= newValue
;
1574 // make correct activations
1575 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
1577 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
1579 wxMacWindowClipper
clipper( textctrl
) ;
1580 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
1582 ControlRef controlFocus
= 0 ;
1583 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
1584 if ( controlFocus
== m_controlRef
)
1585 TXNFocus( m_txn
, setActive
);
1588 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
1590 TXNFocus( m_txn
, setFocus
);
1593 // guards against inappropriate redraw (hidden objects drawing onto window)
1595 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
1597 ControlRef controlFocus
= 0 ;
1598 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
1600 if ( !vis
&& (controlFocus
== m_controlRef
) )
1601 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
1603 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
1604 TXNControlData iControlData
[1] = { { (UInt32
)false } };
1606 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
1608 if ( iControlData
[0].uValue
!= vis
)
1610 iControlData
[0].uValue
= vis
;
1611 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
1614 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
1615 // if we run into further problems we might set the FrameBounds to an empty rect here
1618 // make sure that the TXNObject is at the right position
1620 void wxMacMLTEClassicControl::MacUpdatePosition()
1622 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1623 if ( textctrl
== NULL
)
1627 GetRectInWindowCoords( &bounds
);
1629 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
1630 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
1633 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
1634 OffsetRect( &visBounds
, x
, y
) ;
1636 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
1638 m_txnControlBounds
= bounds
;
1639 m_txnVisBounds
= visBounds
;
1640 wxMacWindowClipper
cl( textctrl
) ;
1642 if ( m_sbHorizontal
|| m_sbVertical
)
1644 int w
= bounds
.right
- bounds
.left
;
1645 int h
= bounds
.bottom
- bounds
.top
;
1647 if ( m_sbHorizontal
)
1651 sbBounds
.left
= -1 ;
1652 sbBounds
.top
= h
- 14 ;
1653 sbBounds
.right
= w
+ 1 ;
1654 sbBounds
.bottom
= h
+ 1 ;
1656 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
1657 SetControlViewSize( m_sbHorizontal
, w
) ;
1664 sbBounds
.left
= w
- 14 ;
1666 sbBounds
.right
= w
+ 1 ;
1667 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
1669 SetControlBounds( m_sbVertical
, &sbBounds
) ;
1670 SetControlViewSize( m_sbVertical
, h
) ;
1675 TXNLongRect olddestRect
;
1676 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
1678 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
1679 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
1680 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
1681 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
1682 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
1683 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
1685 if ( olddestRect
.right
>= 10000 )
1686 destRect
.right
= destRect
.left
+ 32000 ;
1688 if ( olddestRect
.bottom
>= 0x20000000 )
1689 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
1691 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
1692 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
1697 m_txnControlBounds
.top
,
1698 m_txnControlBounds
.left
,
1699 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
1700 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
1704 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
1705 // movement, therefore we have to force it
1707 // this problem has been reported in OSX as well, so we use this here once again
1709 TXNLongRect textRect
;
1710 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
1711 if ( textRect
.left
< m_txnControlBounds
.left
)
1712 TXNShowSelection( m_txn
, kTXNShowStart
) ;
1716 void wxMacMLTEClassicControl::Move(int x
, int y
, int width
, int height
)
1718 wxMacControl::Move(x
,y
,width
,height
) ;
1719 MacUpdatePosition() ;
1722 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16
WXUNUSED(thePart
))
1724 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1725 if ( textctrl
== NULL
)
1728 if ( textctrl
->IsShownOnScreen() )
1730 wxMacWindowClipper
clipper( textctrl
) ;
1731 TXNDraw( m_txn
, NULL
) ;
1735 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1737 Point where
= { y
, x
} ;
1738 ControlPartCode result
= kControlNoPart
;
1740 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
1741 if ( (textctrl
!= NULL
) && textctrl
->IsShownOnScreen() )
1743 if (PtInRect( where
, &m_txnControlBounds
))
1745 result
= kControlEditTextPart
;
1749 // sometimes we get the coords also in control local coordinates, therefore test again
1751 textctrl
->MacClientToRootWindow( &x
, &y
) ;
1755 if (PtInRect( where
, &m_txnControlBounds
))
1756 result
= kControlEditTextPart
;
1763 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* WXUNUSED(actionProc
) )
1765 ControlPartCode result
= kControlNoPart
;
1767 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
1768 if ( (textctrl
!= NULL
) && textctrl
->IsShownOnScreen() )
1770 Point startPt
= { y
, x
} ;
1772 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
1774 textctrl
->MacClientToRootWindow( &x
, &y
) ;
1778 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
1780 case kControlEditTextPart
:
1782 wxMacWindowClipper
clipper( textctrl
) ;
1785 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
1786 TXNClick( m_txn
, &rec
);
1798 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
1800 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1801 if ( textctrl
== NULL
)
1804 if (textctrl
->IsShownOnScreen())
1806 if (IsControlActive(m_controlRef
))
1810 wxMacWindowClipper
clipper( textctrl
) ;
1815 if (PtInRect(mousep
, &m_txnControlBounds
))
1817 RgnHandle theRgn
= NewRgn();
1818 RectRgn(theRgn
, &m_txnControlBounds
);
1819 TXNAdjustCursor(m_txn
, theRgn
);
1826 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1828 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1829 if ( textctrl
== NULL
)
1830 return kControlNoPart
;
1832 wxMacWindowClipper
clipper( textctrl
) ;
1835 memset( &ev
, 0 , sizeof( ev
) ) ;
1837 ev
.modifiers
= modifiers
;
1838 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
1839 TXNKeyDown( m_txn
, &ev
);
1841 return kControlEntireControl
;
1844 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
1846 MacActivatePaneText( activating
);
1849 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
1851 ControlPartCode focusResult
= kControlFocusNoPart
;
1853 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1854 if ( textctrl
== NULL
)
1857 wxMacWindowClipper
clipper( textctrl
) ;
1859 ControlRef controlFocus
= NULL
;
1860 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
1861 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
1865 case kControlFocusPrevPart
:
1866 case kControlFocusNextPart
:
1867 MacFocusPaneText( !wasFocused
);
1868 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
1871 case kControlFocusNoPart
:
1873 MacFocusPaneText( false );
1874 focusResult
= kControlFocusNoPart
;
1881 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *WXUNUSED(info
) )
1885 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
1886 const wxString
& str
,
1888 const wxSize
& size
, long style
)
1889 : wxMacMLTEControl( wxPeer
)
1891 m_font
= wxPeer
->GetFont() ;
1892 m_windowStyle
= style
;
1893 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1896 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
1897 | kControlWantsActivate
| kControlHandlesTracking
1898 // | kControlHasSpecialBackground
1899 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
1901 OSStatus err
= ::CreateUserPaneControl(
1902 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
1903 &bounds
, featureSet
, &m_controlRef
);
1904 verify_noerr( err
);
1908 AdjustCreationAttributes( *wxWHITE
, true ) ;
1910 MacSetObjectVisibility( wxPeer
->IsShownOnScreen() ) ;
1914 wxMacConvertNewlines10To13( &st
) ;
1915 wxMacWindowClipper
clipper( GetWXPeer() ) ;
1916 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1917 TXNSetSelection( m_txn
, 0, 0 ) ;
1921 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
1923 TXNDeleteObject( m_txn
);
1927 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
1929 MacSetObjectVisibility( shown
) ;
1930 wxMacControl::VisibilityChanged( shown
) ;
1933 void wxMacMLTEClassicControl::SuperChangedPosition()
1935 MacUpdatePosition() ;
1936 wxMacControl::SuperChangedPosition() ;
1939 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
1940 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
1941 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
1942 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
1943 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
1944 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
1945 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
1947 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
1949 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
1950 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1952 win
->MacControlUserPaneDrawProc( part
) ;
1955 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
1957 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
1958 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1960 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
1962 return kControlNoPart
;
1965 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
1967 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
1968 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1970 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
1972 return kControlNoPart
;
1975 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
1977 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
1978 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1980 win
->MacControlUserPaneIdleProc() ;
1983 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
1985 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
1986 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1988 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1990 return kControlNoPart
;
1993 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
1995 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
)control
) , wxTextCtrl
) ;
1996 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1998 win
->MacControlUserPaneActivateProc( activating
) ;
2001 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2003 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
2004 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2006 return win
->MacControlUserPaneFocusProc( action
) ;
2008 return kControlNoPart
;
2012 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2014 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget(control
) , wxTextCtrl
) ;
2015 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2017 win
->MacControlUserPaneBackgroundProc(info
) ;
2021 // TXNRegisterScrollInfoProc
2023 OSStatus
wxMacMLTEClassicControl::DoCreate()
2026 OSStatus err
= noErr
;
2028 // set up our globals
2029 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2030 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2031 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2032 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2033 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2034 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2035 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2037 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2038 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2040 // set the initial settings for our private data
2042 m_txnWindow
= GetControlOwner(m_controlRef
);
2043 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2045 // set up the user pane procedures
2046 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2047 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2048 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2049 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2050 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2051 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2052 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2054 // calculate the rectangles used by the control
2055 GetRectInWindowCoords( &bounds
);
2057 m_txnControlBounds
= bounds
;
2058 m_txnVisBounds
= bounds
;
2063 GetGWorld( &origPort
, &origDev
) ;
2064 SetPort( m_txnPort
);
2066 // create the new edit field
2067 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2069 // the scrollbars are not correctly embedded but are inserted at the root:
2070 // this gives us problems as we have erratic redraws even over the structure area
2072 m_sbHorizontal
= 0 ;
2074 m_lastHorizontalValue
= 0 ;
2075 m_lastVerticalValue
= 0 ;
2077 Rect sb
= { 0 , 0 , 0 , 0 } ;
2078 if ( frameOptions
& kTXNWantVScrollBarMask
)
2080 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2081 SetControlReference( m_sbVertical
, (SInt32
)this );
2082 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2083 ShowControl( m_sbVertical
);
2084 EmbedControl( m_sbVertical
, m_controlRef
);
2085 frameOptions
&= ~kTXNWantVScrollBarMask
;
2088 if ( frameOptions
& kTXNWantHScrollBarMask
)
2090 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2091 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2092 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2093 ShowControl( m_sbHorizontal
);
2094 EmbedControl( m_sbHorizontal
, m_controlRef
);
2095 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2099 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2100 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2101 &m_txn
, &m_txnFrameID
, NULL
);
2102 verify_noerr( err
);
2105 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2106 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2107 int toptag
= WXSIZEOF( iControlTags
) ;
2108 TXNCarbonEventInfo cInfo
;
2109 cInfo
.useCarbonEvents
= false ;
2112 cInfo
.fDictionary
= NULL
;
2114 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2117 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2119 SetGWorld( origPort
, origDev
) ;
2125 // ----------------------------------------------------------------------------
2126 // MLTE control implementation (OSX part)
2127 // ----------------------------------------------------------------------------
2129 // tiger multi-line textcontrols with no CR in the entire content
2130 // don't scroll automatically, so we need a hack.
2131 // This attempt only works 'before' the key (ie before CallNextEventHandler)
2132 // is processed, thus the scrolling always occurs one character too late, but
2133 // better than nothing ...
2135 static const EventTypeSpec eventList
[] =
2137 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
2140 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2142 OSStatus result
= eventNotHandledErr
;
2143 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
2145 switch ( GetEventKind( event
) )
2147 case kEventTextInputUnicodeForKeyEvent
:
2149 TXNOffset from
, to
;
2150 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
2152 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
2153 result
= CallNextEventHandler(handler
,event
);
2163 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2165 OSStatus result
= eventNotHandledErr
;
2167 switch ( GetEventClass( event
) )
2169 case kEventClassTextInput
:
2170 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
2179 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
2181 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2182 const wxString
& str
,
2184 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2186 m_font
= wxPeer
->GetFont() ;
2187 m_windowStyle
= style
;
2188 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2190 wxMacConvertNewlines10To13( &st
) ;
2193 { bounds
.left
, bounds
.top
},
2194 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2196 m_scrollView
= NULL
;
2197 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2198 if (( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
)) || (frameOptions
&kTXNSingleLineOnlyMask
))
2200 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2203 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2204 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2209 HIScrollViewCreate(kHIScrollViewOptionsVertScroll
,&m_scrollView
);
2210 HIScrollViewSetScrollBarAutoHide(m_scrollView
,true);
2213 HIViewSetFrame( m_scrollView
, &hr
);
2214 HIViewSetVisible( m_scrollView
, true );
2218 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2219 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2220 HIViewSetVisible( m_textView
, true ) ;
2223 HIViewAddSubview( m_scrollView
, m_textView
) ;
2224 m_controlRef
= m_scrollView
;
2225 wxMacControl::MacInstallEventHandler( m_textView
, wxPeer
) ;
2229 HIViewSetFrame( m_textView
, &hr
);
2230 m_controlRef
= m_textView
;
2233 AdjustCreationAttributes( *wxWHITE
, true ) ;
2235 wxMacWindowClipper
c( GetWXPeer() ) ;
2237 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2239 TXNSetSelection( m_txn
, 0, 0 );
2240 TXNShowSelection( m_txn
, kTXNShowStart
);
2242 ::InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
2243 GetEventTypeCount(eventList
), eventList
, this,
2247 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
2251 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2253 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
2256 bool wxMacMLTEHIViewControl::HasFocus() const
2258 ControlRef control
;
2259 if ( GetUserFocusWindow() == NULL
)
2262 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2263 return control
== m_textView
;
2266 void wxMacMLTEHIViewControl::SetBackgroundColour(const wxColour
& col
)
2268 HITextViewSetBackgroundColor( m_textView
, col
.GetPixel() );
2271 #endif // wxUSE_TEXTCTRL