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 wxMacTextControl
224 wxMacMLTEControl( wxTextCtrl
*peer
) ;
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 wxTextPos
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 wxMacTextControl
* 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
) : wxMacTextControl( wxPeer
)
473 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
476 const wxSize
& size
, long style
)
477 : wxMacTextControl( wxPeer
)
479 Create( wxPeer
, str
, pos
, size
, style
);
482 bool wxMacUnicodeTextControl::Create( wxTextCtrl
*wxPeer
,
485 const wxSize
& size
, long style
)
487 m_font
= wxPeer
->GetFont() ;
488 m_windowStyle
= style
;
489 m_selection
.selStart
= m_selection
.selEnd
= 0;
490 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
492 wxMacConvertNewlines10To13( &st
) ;
493 wxCFStringRef
cf(st
, m_font
.GetEncoding()) ;
494 CFStringRef cfr
= cf
;
496 m_valueTag
= kControlEditTextCFStringTag
;
497 CreateControl( wxPeer
, &bounds
, cfr
);
499 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
500 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
502 ::InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
503 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
509 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
513 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
515 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
517 // work around a refresh issue insofar as not always the entire content is shown,
518 // even if this would be possible
519 ControlEditTextSelectionRec sel
;
520 CFStringRef value
= NULL
;
522 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
523 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
524 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
525 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
531 wxString
wxMacUnicodeTextControl::GetStringValue() const
534 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
537 wxCFStringRef
cf(value
) ;
538 result
= cf
.AsString() ;
542 wxMacConvertNewlines13To10( &result
) ;
544 wxMacConvertNewlines10To13( &result
) ;
550 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
553 wxMacConvertNewlines10To13( &st
) ;
554 wxCFStringRef
cf( st
, m_font
.GetEncoding() ) ;
555 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
558 void wxMacUnicodeTextControl::CreateControl( wxTextCtrl
* peer
, const Rect
* bounds
, CFStringRef cfr
)
560 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
563 m_valueTag
= kControlEditTextPasswordCFStringTag
;
565 OSStatus err
= CreateEditUnicodeTextControl(
566 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()), bounds
, cfr
,
567 isPassword
, NULL
, &m_controlRef
) ;
571 void wxMacUnicodeTextControl::Copy()
573 SendHICommand( kHICommandCopy
) ;
576 void wxMacUnicodeTextControl::Cut()
578 SendHICommand( kHICommandCut
) ;
581 void wxMacUnicodeTextControl::Paste()
583 SendHICommand( kHICommandPaste
) ;
586 bool wxMacUnicodeTextControl::CanPaste() const
591 void wxMacUnicodeTextControl::SetEditable(bool WXUNUSED(editable
))
593 #if 0 // leads to problem because text cannot be selected anymore
594 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
598 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
600 ControlEditTextSelectionRec sel
;
602 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
607 *from
= sel
.selStart
;
612 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
614 ControlEditTextSelectionRec sel
;
617 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
620 wxCFStringRef
cf(value
) ;
621 textLength
= cf
.AsString().length() ;
624 if ((from
== -1) && (to
== -1))
631 from
= wxMin(textLength
,wxMax(from
,0)) ;
635 to
= wxMax(0,wxMin(textLength
,to
)) ;
638 sel
.selStart
= from
;
641 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
646 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
648 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
649 if ( !wxIsMainThread() )
652 // unfortunately CW 8 is not able to correctly deduce the template types,
653 // so we have to instantiate explicitly
654 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( (wxTextCtrl
*) GetWXPeer() , &wxTextCtrl::WriteText
, str
) ;
660 wxMacConvertNewlines10To13( &st
) ;
664 wxCFStringRef
cf(st
, m_font
.GetEncoding() ) ;
665 CFStringRef value
= cf
;
666 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
670 wxString val
= GetStringValue() ;
672 GetSelection( &start
, &end
) ;
673 val
.Remove( start
, end
- start
) ;
674 val
.insert( start
, str
) ;
675 SetStringValue( val
) ;
676 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
680 // ----------------------------------------------------------------------------
681 // MLTE control implementation (common part)
682 // ----------------------------------------------------------------------------
684 // if MTLE is read only, no changes at all are allowed, not even from
685 // procedural API, in order to allow changes via API all the same we must undo
686 // the readonly status while we are executing, this class helps to do so
688 class wxMacEditHelper
691 wxMacEditHelper( TXNObject txn
)
693 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
695 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
696 if ( m_data
[0].uValue
== kTXNReadOnly
)
698 TXNControlData data
[] = { { kTXNReadWrite
} } ;
699 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
705 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
706 if ( m_data
[0].uValue
== kTXNReadOnly
)
707 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
712 TXNControlData m_data
[1] ;
715 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
716 : wxMacTextControl( peer
)
718 SetNeedsFocusRect( true ) ;
721 wxString
wxMacMLTEControl::GetStringValue() const
730 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
739 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
740 if ( actualSize
> 0 )
744 #if SIZEOF_WCHAR_T == 2
745 ptr
= new wxChar
[actualSize
+ 1] ;
746 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
748 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
750 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
751 wxMBConvUTF16 converter
;
752 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
753 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
754 ptr
= new wxChar
[noChars
+ 1] ;
756 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
757 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
762 ptr
[actualSize
] = 0 ;
763 result
= wxString( ptr
) ;
767 DisposeHandle( theText
) ;
771 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
780 actualSize
= GetHandleSize( theText
) ;
781 if ( actualSize
> 0 )
784 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
788 DisposeHandle( theText
) ;
794 wxMacConvertNewlines13To10( &result
) ;
796 wxMacConvertNewlines10To13( &result
) ;
802 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
805 wxMacConvertNewlines10To13( &st
);
809 wxMacWindowClipper
c( GetWXPeer() ) ;
813 wxMacEditHelper
help( m_txn
);
814 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
817 TXNSetSelection( m_txn
, 0, 0 );
818 TXNShowSelection( m_txn
, kTXNShowStart
);
822 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
824 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
826 frameOptions
|= kTXNDoFontSubstitutionMask
;
828 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
829 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
831 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
832 frameOptions
|= kTXNWantHScrollBarMask
;
834 if ( wxStyle
& wxTE_MULTILINE
)
836 if ( ! (wxStyle
& wxTE_DONTWRAP
) )
837 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
839 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
841 frameOptions
|= kTXNWantVScrollBarMask
;
843 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
844 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
845 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
846 // if ( frameOptions & kTXNWantHScrollBarMask )
847 // frameOptions |= kTXNDrawGrowIconMask ;
852 frameOptions
|= kTXNSingleLineOnlyMask
;
855 return frameOptions
;
858 void wxMacMLTEControl::AdjustCreationAttributes(const wxColour
&background
,
859 bool WXUNUSED(visible
))
861 TXNControlTag iControlTags
[] =
863 kTXNDoFontSubstitution
,
864 kTXNWordWrapStateTag
,
866 TXNControlData iControlData
[] =
872 int toptag
= WXSIZEOF( iControlTags
) ;
874 if ( m_windowStyle
& wxTE_MULTILINE
)
876 iControlData
[1].uValue
=
877 (m_windowStyle
& wxTE_DONTWRAP
)
882 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
885 // setting the default font:
886 // under 10.2 this causes a visible caret, therefore we avoid it
892 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
894 TXNTypeAttributes typeAttr
[] =
896 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
897 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
898 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
901 err
= TXNSetTypeAttributes(
902 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
903 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
906 if ( m_windowStyle
& wxTE_PASSWORD
)
909 err
= TXNEchoMode( m_txn
, c
, 0 , true );
914 tback
.bgType
= kTXNBackgroundTypeRGB
;
915 background
.GetRGBColor( &tback
.bg
.color
);
916 TXNSetBackground( m_txn
, &tback
);
919 TXNCommandEventSupportOptions options
;
920 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
923 kTXNSupportEditCommandProcessing
924 | kTXNSupportEditCommandUpdating
925 | kTXNSupportFontCommandProcessing
926 | kTXNSupportFontCommandUpdating
;
928 // only spell check when not read-only
929 // use system options for the default
930 bool checkSpelling
= false ;
931 if ( !(m_windowStyle
& wxTE_READONLY
) )
933 #if wxUSE_SYSTEM_OPTIONS
934 if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) == 1) )
936 checkSpelling
= true ;
943 kTXNSupportSpellCheckCommandProcessing
944 | kTXNSupportSpellCheckCommandUpdating
;
946 TXNSetCommandEventSupport( m_txn
, options
) ;
950 void wxMacMLTEControl::SetBackgroundColour(const wxColour
& col
)
953 tback
.bgType
= kTXNBackgroundTypeRGB
;
954 col
.GetRGBColor(&tback
.bg
.color
);
955 TXNSetBackground( m_txn
, &tback
);
958 static inline int wxConvertToTXN(int x
)
960 return wx_static_cast(int, x
/ 254.0 * 72 + 0.5);
963 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
965 TXNTypeAttributes typeAttr
[4] ;
967 size_t typeAttrCount
= 0 ;
970 TXNControlTag controlTags
[4];
971 TXNControlData controlData
[4];
972 size_t controlAttrCount
= 0;
976 bool relayout
= false;
979 if ( style
.HasFont() )
981 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
982 font
= style
.GetFont() ;
983 typeAttr
[typeAttrCount
].tag
= kTXNATSUIStyle
;
984 typeAttr
[typeAttrCount
].size
= kTXNATSUIStyleSize
;
985 typeAttr
[typeAttrCount
].data
.dataPtr
= font
.MacGetATSUStyle() ;
989 if ( style
.HasTextColour() )
991 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
992 style
.GetTextColour().GetRGBColor( &color
);
993 typeAttr
[typeAttrCount
].tag
= kTXNQDFontColorAttribute
;
994 typeAttr
[typeAttrCount
].size
= kTXNQDFontColorAttributeSize
;
995 typeAttr
[typeAttrCount
].data
.dataPtr
= (void*) &color
;
999 if ( style
.HasAlignment() )
1001 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1004 switch ( style
.GetAlignment() )
1006 case wxTEXT_ALIGNMENT_LEFT
:
1007 align
= kTXNFlushLeft
;
1009 case wxTEXT_ALIGNMENT_CENTRE
:
1012 case wxTEXT_ALIGNMENT_RIGHT
:
1013 align
= kTXNFlushRight
;
1015 case wxTEXT_ALIGNMENT_JUSTIFIED
:
1016 align
= kTXNFullJust
;
1019 case wxTEXT_ALIGNMENT_DEFAULT
:
1020 align
= kTXNFlushDefault
;
1024 controlTags
[controlAttrCount
] = kTXNJustificationTag
;
1025 controlData
[controlAttrCount
].sValue
= align
;
1026 controlAttrCount
++ ;
1029 if ( style
.HasLeftIndent() || style
.HasRightIndent() )
1031 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1032 controlTags
[controlAttrCount
] = kTXNMarginsTag
;
1033 controlData
[controlAttrCount
].marginsPtr
= &margins
;
1034 verify_noerr( TXNGetTXNObjectControls (m_txn
, 1 ,
1035 &controlTags
[controlAttrCount
], &controlData
[controlAttrCount
]) );
1036 if ( style
.HasLeftIndent() )
1038 margins
.leftMargin
= wxConvertToTXN(style
.GetLeftIndent());
1040 if ( style
.HasRightIndent() )
1042 margins
.rightMargin
= wxConvertToTXN(style
.GetRightIndent());
1044 controlAttrCount
++ ;
1047 if ( style
.HasTabs() )
1049 const wxArrayInt
& tabarray
= style
.GetTabs();
1050 // unfortunately Mac only applies a tab distance, not individually different tabs
1051 controlTags
[controlAttrCount
] = kTXNTabSettingsTag
;
1052 if ( tabarray
.size() > 0 )
1053 controlData
[controlAttrCount
].tabValue
.value
= wxConvertToTXN(tabarray
[0]);
1055 controlData
[controlAttrCount
].tabValue
.value
= 72 ;
1057 controlData
[controlAttrCount
].tabValue
.tabType
= kTXNLeftTab
;
1058 controlAttrCount
++ ;
1061 // unfortunately the relayout is not automatic
1062 if ( controlAttrCount
> 0 )
1064 verify_noerr( TXNSetTXNObjectControls (m_txn
, false /* don't clear all */, controlAttrCount
,
1065 controlTags
, controlData
) );
1069 if ( typeAttrCount
> 0 )
1071 verify_noerr( TXNSetTypeAttributes( m_txn
, typeAttrCount
, typeAttr
, from
, to
) );
1082 TXNRecalcTextLayout( m_txn
);
1086 void wxMacMLTEControl::SetFont(const wxFont
& font
,
1087 const wxColour
& foreground
,
1088 long WXUNUSED(windowStyle
))
1090 wxMacEditHelper
help( m_txn
) ;
1091 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1094 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1096 wxMacEditHelper
help( m_txn
) ;
1097 TXNSetAttribute( style
, start
, end
) ;
1100 void wxMacMLTEControl::Copy()
1105 void wxMacMLTEControl::Cut()
1110 void wxMacMLTEControl::Paste()
1115 bool wxMacMLTEControl::CanPaste() const
1117 return TXNIsScrapPastable() ;
1120 void wxMacMLTEControl::SetEditable(bool editable
)
1122 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1123 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1124 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1127 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1129 wxTextPos actualsize
= 0 ;
1132 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1137 actualsize
= GetHandleSize( theText
) ;
1138 DisposeHandle( theText
) ;
1148 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1150 wxString value
= str
;
1151 wxMacConvertNewlines10To13( &value
) ;
1153 wxMacEditHelper
help( m_txn
) ;
1155 wxMacWindowClipper
c( GetWXPeer() ) ;
1158 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
) ;
1160 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1163 void wxMacMLTEControl::Remove( long from
, long to
)
1166 wxMacWindowClipper
c( GetWXPeer() ) ;
1168 wxMacEditHelper
help( m_txn
) ;
1169 TXNSetSelection( m_txn
, from
, to
) ;
1173 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1176 TXNGetSelection( m_txn
, &f
, &t
) ;
1181 void wxMacMLTEControl::SetSelection( long from
, long to
)
1184 wxMacWindowClipper
c( GetWXPeer() ) ;
1187 // change the selection
1188 if ((from
== -1) && (to
== -1))
1189 TXNSelectAll( m_txn
);
1191 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
);
1193 TXNShowSelection( m_txn
, kTXNShowStart
);
1196 void wxMacMLTEControl::WriteText( const wxString
& str
)
1198 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
1199 if ( !wxIsMainThread() )
1201 #if wxOSX_USE_CARBON
1202 // unfortunately CW 8 is not able to correctly deduce the template types,
1203 // so we have to instantiate explicitly
1204 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( (wxTextCtrl
*) GetWXPeer() , &wxTextCtrl::WriteText
, str
) ;
1210 wxMacConvertNewlines10To13( &st
) ;
1212 long start
, end
, dummy
;
1214 GetSelection( &start
, &dummy
) ;
1216 wxMacWindowClipper
c( GetWXPeer() ) ;
1220 wxMacEditHelper
helper( m_txn
) ;
1221 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1224 GetSelection( &dummy
, &end
) ;
1226 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1229 void wxMacMLTEControl::Clear()
1232 wxMacWindowClipper
c( GetWXPeer() ) ;
1234 wxMacEditHelper
st( m_txn
) ;
1235 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1239 bool wxMacMLTEControl::CanUndo() const
1241 return TXNCanUndo( m_txn
, NULL
) ;
1244 void wxMacMLTEControl::Undo()
1249 bool wxMacMLTEControl::CanRedo() const
1251 return TXNCanRedo( m_txn
, NULL
) ;
1254 void wxMacMLTEControl::Redo()
1259 int wxMacMLTEControl::GetNumberOfLines() const
1261 ItemCount lines
= 0 ;
1262 TXNGetLineCount( m_txn
, &lines
) ;
1267 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1272 // TODO: find a better implementation : while we can get the
1273 // line metrics of a certain line, we don't get its starting
1274 // position, so it would probably be rather a binary search
1275 // for the start position
1276 long xpos
= 0, ypos
= 0 ;
1277 int lastHeight
= 0 ;
1280 lastpos
= GetLastPosition() ;
1281 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1283 if ( y
== ypos
&& x
== xpos
)
1286 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
1288 if ( curpt
.v
> lastHeight
)
1294 lastHeight
= curpt
.v
;
1303 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
1313 lastpos
= GetLastPosition() ;
1314 if ( pos
<= lastpos
)
1316 // TODO: find a better implementation - while we can get the
1317 // line metrics of a certain line, we don't get its starting
1318 // position, so it would probably be rather a binary search
1319 // for the start position
1320 long xpos
= 0, ypos
= 0 ;
1321 int lastHeight
= 0 ;
1324 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1326 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
1328 if ( curpt
.v
> lastHeight
)
1334 lastHeight
= curpt
.v
;
1349 void wxMacMLTEControl::ShowPosition( long pos
)
1351 Point current
, desired
;
1352 TXNOffset selstart
, selend
;
1354 TXNGetSelection( m_txn
, &selstart
, &selend
);
1355 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1356 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1358 // TODO: use HIPoints for 10.3 and above
1360 OSErr theErr
= noErr
;
1361 long dv
= desired
.v
- current
.v
;
1362 long dh
= desired
.h
- current
.h
;
1363 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
1364 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1366 // there will be an error returned for classic MLTE implementation when the control is
1367 // invisible, but HITextView works correctly, so we don't assert that one
1368 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
1371 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1374 #if SIZEOF_WCHAR_T == 2
1375 size_t len
= st
.length() ;
1376 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
1378 wxMBConvUTF16 converter
;
1379 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
1380 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
1381 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
1382 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
1386 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
1387 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
1391 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1395 if ( lineNo
< GetNumberOfLines() )
1398 Fixed lineWidth
, lineHeight
, currentHeight
;
1401 // get the first possible position in the control
1402 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1404 // Iterate through the lines until we reach the one we want,
1405 // adding to our current y pixel point position
1408 while (ypos
< lineNo
)
1410 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1411 currentHeight
+= lineHeight
;
1414 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1415 TXNOffset theOffset
;
1416 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1418 wxString content
= GetStringValue() ;
1419 Point currentPoint
= thePoint
;
1420 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1422 line
+= content
[theOffset
];
1423 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1430 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1434 if ( lineNo
< GetNumberOfLines() )
1437 Fixed lineWidth
, lineHeight
, currentHeight
;
1440 // get the first possible position in the control
1441 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1443 // Iterate through the lines until we reach the one we want,
1444 // adding to our current y pixel point position
1447 while (ypos
< lineNo
)
1449 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1450 currentHeight
+= lineHeight
;
1453 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1454 TXNOffset theOffset
;
1455 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1457 wxString content
= GetStringValue() ;
1458 Point currentPoint
= thePoint
;
1459 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1462 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1469 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
1471 // ----------------------------------------------------------------------------
1472 // MLTE control implementation (classic part)
1473 // ----------------------------------------------------------------------------
1475 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
1476 // has to live on. We have different problems coming from outdated implementations on the
1477 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
1478 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
1479 // no way out, therefore we are using our own implementation and our own scrollbars ....
1481 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
1482 ControlActionUPP gTXNScrollActionProc
= NULL
;
1484 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
1485 SInt32 iValue
, SInt32 iMaximumValue
,
1486 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
1488 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
1489 SInt32 value
= wxMax( iValue
, 0 ) ;
1490 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
1492 if ( iScrollBarOrientation
== kTXNHorizontal
)
1494 if ( mlte
->m_sbHorizontal
)
1496 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
1497 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
1498 mlte
->m_lastHorizontalValue
= value
;
1501 else if ( iScrollBarOrientation
== kTXNVertical
)
1503 if ( mlte
->m_sbVertical
)
1505 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
1506 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
1507 mlte
->m_lastVerticalValue
= value
;
1512 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
1514 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
1518 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
1522 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
1524 SInt32 minimum
= 0 ;
1525 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
1526 SInt32 value
= GetControl32BitValue( controlRef
) ;
1531 case kControlDownButtonPart
:
1535 case kControlUpButtonPart
:
1539 case kControlPageDownPart
:
1540 delta
= GetControlViewSize( controlRef
) ;
1543 case kControlPageUpPart
:
1544 delta
= -GetControlViewSize( controlRef
) ;
1547 case kControlIndicatorPart
:
1548 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
1557 SInt32 newValue
= value
;
1559 if ( partCode
!= kControlIndicatorPart
)
1561 if ( value
+ delta
< minimum
)
1562 delta
= minimum
- value
;
1563 if ( value
+ delta
> maximum
)
1564 delta
= maximum
- value
;
1566 SetControl32BitValue( controlRef
, value
+ delta
) ;
1567 newValue
= value
+ delta
;
1570 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
1571 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
1574 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
1575 &verticalDelta
, &horizontalDelta
);
1576 verify_noerr( err
);
1579 mlte
->m_lastHorizontalValue
= newValue
;
1581 mlte
->m_lastVerticalValue
= newValue
;
1585 // make correct activations
1586 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
1588 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
1590 wxMacWindowClipper
clipper( textctrl
) ;
1591 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
1593 ControlRef controlFocus
= 0 ;
1594 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
1595 if ( controlFocus
== m_controlRef
)
1596 TXNFocus( m_txn
, setActive
);
1599 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
1601 TXNFocus( m_txn
, setFocus
);
1604 // guards against inappropriate redraw (hidden objects drawing onto window)
1606 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
1608 ControlRef controlFocus
= 0 ;
1609 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
1611 if ( !vis
&& (controlFocus
== m_controlRef
) )
1612 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
1614 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
1615 TXNControlData iControlData
[1] = { { (UInt32
)false } };
1617 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
1619 if ( iControlData
[0].uValue
!= vis
)
1621 iControlData
[0].uValue
= vis
;
1622 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
1625 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
1626 // if we run into further problems we might set the FrameBounds to an empty rect here
1629 // make sure that the TXNObject is at the right position
1631 void wxMacMLTEClassicControl::MacUpdatePosition()
1633 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1634 if ( textctrl
== NULL
)
1638 GetRectInWindowCoords( &bounds
);
1640 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
1641 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
1644 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
1645 OffsetRect( &visBounds
, x
, y
) ;
1647 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
1649 m_txnControlBounds
= bounds
;
1650 m_txnVisBounds
= visBounds
;
1651 wxMacWindowClipper
cl( textctrl
) ;
1653 if ( m_sbHorizontal
|| m_sbVertical
)
1655 int w
= bounds
.right
- bounds
.left
;
1656 int h
= bounds
.bottom
- bounds
.top
;
1658 if ( m_sbHorizontal
)
1662 sbBounds
.left
= -1 ;
1663 sbBounds
.top
= h
- 14 ;
1664 sbBounds
.right
= w
+ 1 ;
1665 sbBounds
.bottom
= h
+ 1 ;
1667 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
1668 SetControlViewSize( m_sbHorizontal
, w
) ;
1675 sbBounds
.left
= w
- 14 ;
1677 sbBounds
.right
= w
+ 1 ;
1678 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
1680 SetControlBounds( m_sbVertical
, &sbBounds
) ;
1681 SetControlViewSize( m_sbVertical
, h
) ;
1686 TXNLongRect olddestRect
;
1687 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
1689 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
1690 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
1691 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
1692 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
1693 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
1694 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
1696 if ( olddestRect
.right
>= 10000 )
1697 destRect
.right
= destRect
.left
+ 32000 ;
1699 if ( olddestRect
.bottom
>= 0x20000000 )
1700 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
1702 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
1703 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
1708 m_txnControlBounds
.top
,
1709 m_txnControlBounds
.left
,
1710 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
1711 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
1715 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
1716 // movement, therefore we have to force it
1718 // this problem has been reported in OSX as well, so we use this here once again
1720 TXNLongRect textRect
;
1721 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
1722 if ( textRect
.left
< m_txnControlBounds
.left
)
1723 TXNShowSelection( m_txn
, kTXNShowStart
) ;
1727 void wxMacMLTEClassicControl::Move(int x
, int y
, int width
, int height
)
1729 wxMacControl::Move(x
,y
,width
,height
) ;
1730 MacUpdatePosition() ;
1733 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16
WXUNUSED(thePart
))
1735 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1736 if ( textctrl
== NULL
)
1739 if ( textctrl
->IsShownOnScreen() )
1741 wxMacWindowClipper
clipper( textctrl
) ;
1742 TXNDraw( m_txn
, NULL
) ;
1746 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1748 Point where
= { y
, x
} ;
1749 ControlPartCode result
= kControlNoPart
;
1751 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
1752 if ( (textctrl
!= NULL
) && textctrl
->IsShownOnScreen() )
1754 if (PtInRect( where
, &m_txnControlBounds
))
1756 result
= kControlEditTextPart
;
1760 // sometimes we get the coords also in control local coordinates, therefore test again
1762 textctrl
->MacClientToRootWindow( &x
, &y
) ;
1766 if (PtInRect( where
, &m_txnControlBounds
))
1767 result
= kControlEditTextPart
;
1774 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* WXUNUSED(actionProc
) )
1776 ControlPartCode result
= kControlNoPart
;
1778 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
1779 if ( (textctrl
!= NULL
) && textctrl
->IsShownOnScreen() )
1781 Point startPt
= { y
, x
} ;
1783 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
1785 textctrl
->MacClientToRootWindow( &x
, &y
) ;
1789 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
1791 case kControlEditTextPart
:
1793 wxMacWindowClipper
clipper( textctrl
) ;
1796 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
1797 TXNClick( m_txn
, &rec
);
1809 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
1811 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1812 if ( textctrl
== NULL
)
1815 if (textctrl
->IsShownOnScreen())
1817 if (IsControlActive(m_controlRef
))
1821 wxMacWindowClipper
clipper( textctrl
) ;
1826 if (PtInRect(mousep
, &m_txnControlBounds
))
1828 RgnHandle theRgn
= NewRgn();
1829 RectRgn(theRgn
, &m_txnControlBounds
);
1830 TXNAdjustCursor(m_txn
, theRgn
);
1837 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1839 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1840 if ( textctrl
== NULL
)
1841 return kControlNoPart
;
1843 wxMacWindowClipper
clipper( textctrl
) ;
1846 memset( &ev
, 0 , sizeof( ev
) ) ;
1848 ev
.modifiers
= modifiers
;
1849 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
1850 TXNKeyDown( m_txn
, &ev
);
1852 return kControlEntireControl
;
1855 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
1857 MacActivatePaneText( activating
);
1860 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
1862 ControlPartCode focusResult
= kControlFocusNoPart
;
1864 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1865 if ( textctrl
== NULL
)
1868 wxMacWindowClipper
clipper( textctrl
) ;
1870 ControlRef controlFocus
= NULL
;
1871 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
1872 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
1876 case kControlFocusPrevPart
:
1877 case kControlFocusNextPart
:
1878 MacFocusPaneText( !wasFocused
);
1879 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
1882 case kControlFocusNoPart
:
1884 MacFocusPaneText( false );
1885 focusResult
= kControlFocusNoPart
;
1892 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *WXUNUSED(info
) )
1896 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
1897 const wxString
& str
,
1899 const wxSize
& size
, long style
)
1900 : wxMacMLTEControl( wxPeer
)
1902 m_font
= wxPeer
->GetFont() ;
1903 m_windowStyle
= style
;
1904 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1907 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
1908 | kControlWantsActivate
| kControlHandlesTracking
1909 // | kControlHasSpecialBackground
1910 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
1912 OSStatus err
= ::CreateUserPaneControl(
1913 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
1914 &bounds
, featureSet
, &m_controlRef
);
1915 verify_noerr( err
);
1919 AdjustCreationAttributes( *wxWHITE
, true ) ;
1921 MacSetObjectVisibility( wxPeer
->IsShownOnScreen() ) ;
1925 wxMacConvertNewlines10To13( &st
) ;
1926 wxMacWindowClipper
clipper( GetWXPeer() ) ;
1927 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1928 TXNSetSelection( m_txn
, 0, 0 ) ;
1932 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
1934 TXNDeleteObject( m_txn
);
1938 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
1940 MacSetObjectVisibility( shown
) ;
1941 wxMacControl::VisibilityChanged( shown
) ;
1944 void wxMacMLTEClassicControl::SuperChangedPosition()
1946 MacUpdatePosition() ;
1947 wxMacControl::SuperChangedPosition() ;
1950 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
1951 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
1952 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
1953 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
1954 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
1955 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
1956 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
1958 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
1960 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
1961 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1963 win
->MacControlUserPaneDrawProc( part
) ;
1966 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
1968 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
1969 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1971 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
1973 return kControlNoPart
;
1976 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
1978 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
1979 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1981 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
1983 return kControlNoPart
;
1986 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
1988 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
1989 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1991 win
->MacControlUserPaneIdleProc() ;
1994 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
1996 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
1997 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1999 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2001 return kControlNoPart
;
2004 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2006 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
)control
) , wxTextCtrl
) ;
2007 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2009 win
->MacControlUserPaneActivateProc( activating
) ;
2012 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2014 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
2015 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2017 return win
->MacControlUserPaneFocusProc( action
) ;
2019 return kControlNoPart
;
2023 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2025 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget(control
) , wxTextCtrl
) ;
2026 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2028 win
->MacControlUserPaneBackgroundProc(info
) ;
2032 // TXNRegisterScrollInfoProc
2034 OSStatus
wxMacMLTEClassicControl::DoCreate()
2037 OSStatus err
= noErr
;
2039 // set up our globals
2040 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2041 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2042 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2043 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2044 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2045 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2046 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2048 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2049 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2051 // set the initial settings for our private data
2053 m_txnWindow
= GetControlOwner(m_controlRef
);
2054 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2056 // set up the user pane procedures
2057 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2058 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2059 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2060 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2061 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2062 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2063 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2065 // calculate the rectangles used by the control
2066 GetRectInWindowCoords( &bounds
);
2068 m_txnControlBounds
= bounds
;
2069 m_txnVisBounds
= bounds
;
2074 GetGWorld( &origPort
, &origDev
) ;
2075 SetPort( m_txnPort
);
2077 // create the new edit field
2078 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2080 // the scrollbars are not correctly embedded but are inserted at the root:
2081 // this gives us problems as we have erratic redraws even over the structure area
2083 m_sbHorizontal
= 0 ;
2085 m_lastHorizontalValue
= 0 ;
2086 m_lastVerticalValue
= 0 ;
2088 Rect sb
= { 0 , 0 , 0 , 0 } ;
2089 if ( frameOptions
& kTXNWantVScrollBarMask
)
2091 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2092 SetControlReference( m_sbVertical
, (SInt32
)this );
2093 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2094 ShowControl( m_sbVertical
);
2095 EmbedControl( m_sbVertical
, m_controlRef
);
2096 frameOptions
&= ~kTXNWantVScrollBarMask
;
2099 if ( frameOptions
& kTXNWantHScrollBarMask
)
2101 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2102 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2103 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2104 ShowControl( m_sbHorizontal
);
2105 EmbedControl( m_sbHorizontal
, m_controlRef
);
2106 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2110 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2111 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2112 &m_txn
, &m_txnFrameID
, NULL
);
2113 verify_noerr( err
);
2116 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2117 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2118 int toptag
= WXSIZEOF( iControlTags
) ;
2119 TXNCarbonEventInfo cInfo
;
2120 cInfo
.useCarbonEvents
= false ;
2123 cInfo
.fDictionary
= NULL
;
2125 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2128 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2130 SetGWorld( origPort
, origDev
) ;
2136 // ----------------------------------------------------------------------------
2137 // MLTE control implementation (OSX part)
2138 // ----------------------------------------------------------------------------
2140 // tiger multi-line textcontrols with no CR in the entire content
2141 // don't scroll automatically, so we need a hack.
2142 // This attempt only works 'before' the key (ie before CallNextEventHandler)
2143 // is processed, thus the scrolling always occurs one character too late, but
2144 // better than nothing ...
2146 static const EventTypeSpec eventList
[] =
2148 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
2151 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2153 OSStatus result
= eventNotHandledErr
;
2154 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
2156 switch ( GetEventKind( event
) )
2158 case kEventTextInputUnicodeForKeyEvent
:
2160 TXNOffset from
, to
;
2161 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
2163 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
2164 result
= CallNextEventHandler(handler
,event
);
2174 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2176 OSStatus result
= eventNotHandledErr
;
2178 switch ( GetEventClass( event
) )
2180 case kEventClassTextInput
:
2181 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
2190 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
2192 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2193 const wxString
& str
,
2195 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2197 m_font
= wxPeer
->GetFont() ;
2198 m_windowStyle
= style
;
2199 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2201 wxMacConvertNewlines10To13( &st
) ;
2204 { bounds
.left
, bounds
.top
},
2205 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2207 m_scrollView
= NULL
;
2208 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2209 if (( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
)) || (frameOptions
&kTXNSingleLineOnlyMask
))
2211 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2214 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2215 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2220 HIScrollViewCreate(kHIScrollViewOptionsVertScroll
,&m_scrollView
);
2221 HIScrollViewSetScrollBarAutoHide(m_scrollView
,true);
2224 HIViewSetFrame( m_scrollView
, &hr
);
2225 HIViewSetVisible( m_scrollView
, true );
2229 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2230 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2231 HIViewSetVisible( m_textView
, true ) ;
2234 HIViewAddSubview( m_scrollView
, m_textView
) ;
2235 m_controlRef
= m_scrollView
;
2236 wxMacControl::MacInstallEventHandler( m_textView
, wxPeer
) ;
2240 HIViewSetFrame( m_textView
, &hr
);
2241 m_controlRef
= m_textView
;
2244 AdjustCreationAttributes( *wxWHITE
, true ) ;
2246 wxMacWindowClipper
c( GetWXPeer() ) ;
2248 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2250 TXNSetSelection( m_txn
, 0, 0 );
2251 TXNShowSelection( m_txn
, kTXNShowStart
);
2253 ::InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
2254 GetEventTypeCount(eventList
), eventList
, this,
2258 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
2262 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2264 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
2267 bool wxMacMLTEHIViewControl::HasFocus() const
2269 ControlRef control
;
2270 if ( GetUserFocusWindow() == NULL
)
2273 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2274 return control
== m_textView
;
2277 void wxMacMLTEHIViewControl::SetBackgroundColour(const wxColour
& col
)
2279 HITextViewSetBackgroundColor( m_textView
, col
.GetPixel() );
2282 #endif // wxUSE_TEXTCTRL