1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/textctrl.cpp
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
15 #include "wx/textctrl.h"
22 #include "wx/button.h"
24 #include "wx/settings.h"
25 #include "wx/msgdlg.h"
26 #include "wx/toplevel.h"
30 #include <sys/types.h>
36 #if wxUSE_STD_IOSTREAM
44 #include "wx/filefn.h"
45 #include "wx/sysopt.h"
46 #include "wx/thread.h"
48 #include "wx/osx/private.h"
49 #include "wx/osx/carbon/private/mactext.h"
55 virtual ~wxMacFunctor() {}
57 virtual void* operator()() = 0 ;
59 static void* CallBackProc( void *param
)
61 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
62 void *result
= (*f
)() ;
67 template<typename classtype
, typename param1type
>
69 class wxMacObjectFunctor1
: public wxMacFunctor
71 typedef void (classtype::*function
)( param1type p1
) ;
72 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
74 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
82 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
90 virtual ~wxMacObjectFunctor1() {}
92 virtual void* operator()()
94 (m_object
->*m_function
)( m_param1
) ;
100 param1type m_param1
;
103 function m_function
;
104 ref_function m_refFunction
;
108 template<typename classtype
, typename param1type
>
109 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
111 wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ;
113 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
117 template<typename classtype
, typename param1type
>
118 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
120 wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ;
122 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
126 template<typename classtype
, typename param1type
>
127 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
130 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
135 template<typename classtype
, typename param1type
>
136 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
139 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
144 class WXDLLEXPORT wxMacPortSaver
146 wxDECLARE_NO_COPY_CLASS(wxMacPortSaver
);
149 wxMacPortSaver( GrafPtr port
);
157 Clips to the visible region of a control within the current port
160 class WXDLLEXPORT wxMacWindowClipper
: public wxMacPortSaver
162 wxDECLARE_NO_COPY_CLASS(wxMacWindowClipper
);
165 wxMacWindowClipper( const wxWindow
* win
);
166 ~wxMacWindowClipper();
169 RgnHandle m_formerClip
;
173 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
175 ::GetPort( &m_port
);
179 wxMacPortSaver::~wxMacPortSaver()
184 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
185 wxMacPortSaver( (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) )
187 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
188 m_formerClip
= NewRgn() ;
189 m_newClip
= NewRgn() ;
190 GetClip( m_formerClip
) ;
194 // guard against half constructed objects, this just leads to a empty clip
195 if ( win
->GetPeer() )
198 win
->MacWindowToRootWindow( &x
, &y
) ;
200 // get area including focus rect
201 HIShapeGetAsQDRgn( ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
);
202 if ( !EmptyRgn( m_newClip
) )
203 OffsetRgn( m_newClip
, x
, y
) ;
206 SetClip( m_newClip
) ;
210 wxMacWindowClipper::~wxMacWindowClipper()
212 SetPort( m_newPort
) ;
213 SetClip( m_formerClip
) ;
214 DisposeRgn( m_newClip
) ;
215 DisposeRgn( m_formerClip
) ;
218 // common parts for implementations based on MLTE
220 class wxMacMLTEControl
: public wxMacControl
, public wxTextWidgetImpl
223 wxMacMLTEControl( wxTextCtrl
*peer
) ;
224 ~wxMacMLTEControl() {}
226 virtual bool CanFocus() const
229 virtual wxString
GetStringValue() const ;
230 virtual void SetStringValue( const wxString
&str
) ;
232 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
234 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
236 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
) ;
237 virtual void SetBackgroundColour(const wxColour
& col
);
238 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
239 virtual void Copy() ;
241 virtual void Paste() ;
242 virtual bool CanPaste() const ;
243 virtual void SetEditable( bool editable
) ;
244 virtual long GetLastPosition() const ;
245 virtual void Replace( long from
, long to
, const wxString
&str
) ;
246 virtual void Remove( long from
, long to
) ;
247 virtual void GetSelection( long* from
, long* to
) const ;
248 virtual void SetSelection( long from
, long to
) ;
250 virtual void WriteText( const wxString
& str
) ;
252 virtual bool HasOwnContextMenu() const
254 TXNCommandEventSupportOptions options
;
255 TXNGetCommandEventSupport( m_txn
, & options
) ;
256 return options
& kTXNSupportEditCommandProcessing
;
259 virtual void CheckSpelling(bool check
)
261 TXNSetSpellCheckAsYouType( m_txn
, (Boolean
) check
);
263 virtual void Clear() ;
265 virtual bool CanUndo() const ;
266 virtual void Undo() ;
267 virtual bool CanRedo() const;
268 virtual void Redo() ;
269 virtual int GetNumberOfLines() const ;
270 virtual long XYToPosition(long x
, long y
) const ;
271 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
272 virtual void ShowPosition( long pos
) ;
273 virtual int GetLineLength(long lineNo
) const ;
274 virtual wxString
GetLineText(long lineNo
) const ;
276 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
277 TXNObject
GetTXNObject() { return m_txn
; }
280 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
285 // implementation available under OSX
287 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
290 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
293 const wxSize
& size
, long style
) ;
294 virtual ~wxMacMLTEHIViewControl() ;
296 virtual bool SetFocus() ;
297 virtual bool HasFocus() const ;
298 virtual void SetBackgroundColour(const wxColour
& col
) ;
301 HIViewRef m_scrollView
;
302 HIViewRef m_textView
;
305 // 'classic' MLTE implementation
307 class wxMacMLTEClassicControl
: public wxMacMLTEControl
310 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
313 const wxSize
& size
, long style
) ;
314 virtual ~wxMacMLTEClassicControl() ;
316 virtual void VisibilityChanged(bool shown
) ;
317 virtual void SuperChangedPosition() ;
319 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
320 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
321 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
322 virtual void MacControlUserPaneIdleProc() ;
323 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
324 virtual void MacControlUserPaneActivateProc(bool activating
) ;
325 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
326 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
328 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
330 MacControlUserPaneIdleProc();
334 virtual void Move(int x
, int y
, int width
, int height
);
339 void MacUpdatePosition() ;
340 void MacActivatePaneText(bool setActive
) ;
341 void MacFocusPaneText(bool setFocus
) ;
342 void MacSetObjectVisibility(bool vis
) ;
345 TXNFrameID m_txnFrameID
;
347 WindowRef m_txnWindow
;
348 // bounds of the control as we last did set the txn frames
349 Rect m_txnControlBounds
;
350 Rect m_txnVisBounds
;
352 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
353 static pascal void TXNScrollInfoProc(
354 SInt32 iValue
, SInt32 iMaximumValue
,
355 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
357 ControlRef m_sbHorizontal
;
358 SInt32 m_lastHorizontalValue
;
359 ControlRef m_sbVertical
;
360 SInt32 m_lastVerticalValue
;
363 wxWidgetImplType
* wxWidgetImpl::CreateTextControl( wxTextCtrl
* wxpeer
,
364 wxWindowMac
* WXUNUSED(parent
),
365 wxWindowID
WXUNUSED(id
),
370 long WXUNUSED(extraStyle
))
372 bool forceMLTE
= false ;
374 #if wxUSE_SYSTEM_OPTIONS
375 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
381 if ( UMAGetSystemVersion() >= 0x1050 )
384 wxMacControl
* peer
= NULL
;
388 if ( style
& wxTE_MULTILINE
|| ( UMAGetSystemVersion() >= 0x1050 ) )
389 peer
= new wxMacMLTEHIViewControl( wxpeer
, str
, pos
, size
, style
) ;
394 if ( !(style
& wxTE_MULTILINE
) && !forceMLTE
)
396 peer
= new wxMacUnicodeTextControl( wxpeer
, str
, pos
, size
, style
) ;
400 // the horizontal single line scrolling bug that made us keep the classic implementation
402 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
404 peer
= new wxMacMLTEClassicControl( wxpeer
, str
, pos
, size
, style
) ;
409 // ----------------------------------------------------------------------------
410 // standard unicode control implementation
411 // ----------------------------------------------------------------------------
413 // the current unicode textcontrol implementation has a bug : only if the control
414 // is currently having the focus, the selection can be retrieved by the corresponding
415 // data tag. So we have a mirroring using a member variable
416 // TODO : build event table using virtual member functions for wxMacControl
418 static const EventTypeSpec unicodeTextControlEventList
[] =
420 { kEventClassControl
, kEventControlSetFocusPart
} ,
423 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
425 OSStatus result
= eventNotHandledErr
;
426 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
427 wxMacCarbonEvent
cEvent( event
) ;
429 switch ( GetEventKind( event
) )
431 case kEventControlSetFocusPart
:
433 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
434 if ( controlPart
== kControlFocusNoPart
)
436 // about to lose focus -> store selection to field
437 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
439 result
= CallNextEventHandler(handler
,event
) ;
440 if ( controlPart
!= kControlFocusNoPart
)
442 // about to gain focus -> set selection from field
443 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
454 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
456 OSStatus result
= eventNotHandledErr
;
458 switch ( GetEventClass( event
) )
460 case kEventClassControl
:
461 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
470 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
472 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
)
473 : wxMacControl( wxPeer
),
474 wxTextWidgetImpl( wxPeer
)
478 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
481 const wxSize
& size
, long style
)
482 : wxMacControl( wxPeer
),
483 wxTextWidgetImpl( wxPeer
)
485 m_font
= wxPeer
->GetFont() ;
486 m_windowStyle
= style
;
487 m_selection
.selStart
= m_selection
.selEnd
= 0;
488 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
490 wxMacConvertNewlines10To13( &st
) ;
491 wxCFStringRef
cf(st
, m_font
.GetEncoding()) ;
493 m_valueTag
= kControlEditTextCFStringTag
;
494 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
497 m_valueTag
= kControlEditTextPasswordCFStringTag
;
499 OSStatus err
= CreateEditUnicodeTextControl(
500 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cf
,
501 isPassword
, NULL
, &m_controlRef
) ;
504 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
505 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
507 InstallEventHandlers();
510 void wxMacUnicodeTextControl::InstallEventHandlers()
512 ::InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
513 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
514 (EventHandlerRef
*) &m_macTextCtrlEventHandler
);
517 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
519 ::RemoveEventHandler((EventHandlerRef
) m_macTextCtrlEventHandler
);
522 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
524 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
526 // work around a refresh issue insofar as not always the entire content is shown,
527 // even if this would be possible
528 ControlEditTextSelectionRec sel
;
529 CFStringRef value
= NULL
;
531 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
532 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
533 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
534 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
540 wxString
wxMacUnicodeTextControl::GetStringValue() const
543 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
546 wxCFStringRef
cf(value
) ;
547 result
= cf
.AsString() ;
551 wxMacConvertNewlines13To10( &result
) ;
553 wxMacConvertNewlines10To13( &result
) ;
559 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
562 wxMacConvertNewlines10To13( &st
) ;
563 wxCFStringRef
cf( st
, m_font
.GetEncoding() ) ;
564 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
567 void wxMacUnicodeTextControl::Copy()
569 SendHICommand( kHICommandCopy
) ;
572 void wxMacUnicodeTextControl::Cut()
574 SendHICommand( kHICommandCut
) ;
577 void wxMacUnicodeTextControl::Paste()
579 SendHICommand( kHICommandPaste
) ;
582 bool wxMacUnicodeTextControl::CanPaste() const
587 void wxMacUnicodeTextControl::SetEditable(bool WXUNUSED(editable
))
589 #if 0 // leads to problem because text cannot be selected anymore
590 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
594 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
596 ControlEditTextSelectionRec sel
;
598 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
603 *from
= sel
.selStart
;
608 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
610 ControlEditTextSelectionRec sel
;
613 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
616 wxCFStringRef
cf(value
) ;
617 textLength
= cf
.AsString().length() ;
620 if ((from
== -1) && (to
== -1))
627 from
= wxMin(textLength
,wxMax(from
,0)) ;
631 to
= wxMax(0,wxMin(textLength
,to
)) ;
634 sel
.selStart
= from
;
637 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
642 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
644 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
645 if ( !wxIsMainThread() )
648 // unfortunately CW 8 is not able to correctly deduce the template types,
649 // so we have to instantiate explicitly
650 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( (wxTextCtrl
*) GetWXPeer() , &wxTextCtrl::WriteText
, str
) ;
656 wxMacConvertNewlines10To13( &st
) ;
660 wxCFStringRef
cf(st
, m_font
.GetEncoding() ) ;
661 CFStringRef value
= cf
;
662 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
666 wxString val
= GetStringValue() ;
668 GetSelection( &start
, &end
) ;
669 val
.Remove( start
, end
- start
) ;
670 val
.insert( start
, str
) ;
671 SetStringValue( val
) ;
672 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
676 // ----------------------------------------------------------------------------
677 // MLTE control implementation (common part)
678 // ----------------------------------------------------------------------------
680 // if MTLE is read only, no changes at all are allowed, not even from
681 // procedural API, in order to allow changes via API all the same we must undo
682 // the readonly status while we are executing, this class helps to do so
684 class wxMacEditHelper
687 wxMacEditHelper( TXNObject txn
)
689 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
691 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
692 if ( m_data
[0].uValue
== kTXNReadOnly
)
694 TXNControlData data
[] = { { kTXNReadWrite
} } ;
695 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
701 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
702 if ( m_data
[0].uValue
== kTXNReadOnly
)
703 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
708 TXNControlData m_data
[1] ;
711 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
712 : wxMacControl( peer
),
713 wxTextWidgetImpl( peer
)
715 SetNeedsFocusRect( true ) ;
718 wxString
wxMacMLTEControl::GetStringValue() const
727 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
736 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
737 if ( actualSize
> 0 )
741 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
743 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
744 wxMBConvUTF16 converter
;
745 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
746 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, wxT("Unable to count the number of characters in this string!") );
747 ptr
= new wxChar
[noChars
+ 1] ;
749 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
750 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, wxT("Conversion of string failed!") );
754 ptr
[actualSize
] = 0 ;
755 result
= wxString( ptr
) ;
759 DisposeHandle( theText
) ;
761 #else // !wxUSE_UNICODE
763 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
772 actualSize
= GetHandleSize( theText
) ;
773 if ( actualSize
> 0 )
776 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
780 DisposeHandle( theText
) ;
782 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
786 wxMacConvertNewlines13To10( &result
) ;
788 wxMacConvertNewlines10To13( &result
) ;
794 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
797 wxMacConvertNewlines10To13( &st
);
801 wxMacWindowClipper
c( GetWXPeer() ) ;
805 wxMacEditHelper
help( m_txn
);
806 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
809 TXNSetSelection( m_txn
, 0, 0 );
810 TXNShowSelection( m_txn
, kTXNShowStart
);
814 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
816 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
818 frameOptions
|= kTXNDoFontSubstitutionMask
;
820 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
821 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
823 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
824 frameOptions
|= kTXNWantHScrollBarMask
;
826 if ( wxStyle
& wxTE_MULTILINE
)
828 if ( ! (wxStyle
& wxTE_DONTWRAP
) )
829 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
831 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
833 frameOptions
|= kTXNWantVScrollBarMask
;
835 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
836 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
837 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
838 // if ( frameOptions & kTXNWantHScrollBarMask )
839 // frameOptions |= kTXNDrawGrowIconMask ;
844 frameOptions
|= kTXNSingleLineOnlyMask
;
847 return frameOptions
;
850 void wxMacMLTEControl::AdjustCreationAttributes(const wxColour
&background
,
851 bool WXUNUSED(visible
))
853 TXNControlTag iControlTags
[] =
855 kTXNDoFontSubstitution
,
856 kTXNWordWrapStateTag
,
858 TXNControlData iControlData
[] =
864 int toptag
= WXSIZEOF( iControlTags
) ;
866 if ( m_windowStyle
& wxTE_MULTILINE
)
868 iControlData
[1].uValue
=
869 (m_windowStyle
& wxTE_DONTWRAP
)
874 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
877 // setting the default font:
878 // under 10.2 this causes a visible caret, therefore we avoid it
884 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
886 TXNTypeAttributes typeAttr
[] =
888 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
889 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
890 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
893 err
= TXNSetTypeAttributes(
894 m_txn
, WXSIZEOF(typeAttr
),
895 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
898 if ( m_windowStyle
& wxTE_PASSWORD
)
901 err
= TXNEchoMode( m_txn
, c
, 0 , true );
906 tback
.bgType
= kTXNBackgroundTypeRGB
;
907 background
.GetRGBColor( &tback
.bg
.color
);
908 TXNSetBackground( m_txn
, &tback
);
911 TXNCommandEventSupportOptions options
;
912 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
915 kTXNSupportEditCommandProcessing
916 | kTXNSupportEditCommandUpdating
917 | kTXNSupportFontCommandProcessing
918 | kTXNSupportFontCommandUpdating
;
920 // only spell check when not read-only
921 // use system options for the default
922 bool checkSpelling
= false ;
923 if ( !(m_windowStyle
& wxTE_READONLY
) )
925 #if wxUSE_SYSTEM_OPTIONS
926 if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) == 1) )
928 checkSpelling
= true ;
935 kTXNSupportSpellCheckCommandProcessing
936 | kTXNSupportSpellCheckCommandUpdating
;
938 TXNSetCommandEventSupport( m_txn
, options
) ;
942 void wxMacMLTEControl::SetBackgroundColour(const wxColour
& col
)
945 tback
.bgType
= kTXNBackgroundTypeRGB
;
946 col
.GetRGBColor(&tback
.bg
.color
);
947 TXNSetBackground( m_txn
, &tback
);
950 static inline int wxConvertToTXN(int x
)
952 return static_cast<int>(x
/ 254.0 * 72 + 0.5);
955 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
957 TXNTypeAttributes typeAttr
[4] ;
959 size_t typeAttrCount
= 0 ;
962 TXNControlTag controlTags
[4];
963 TXNControlData controlData
[4];
964 size_t controlAttrCount
= 0;
968 bool relayout
= false;
971 if ( style
.HasFont() )
973 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
974 font
= style
.GetFont() ;
975 typeAttr
[typeAttrCount
].tag
= kTXNATSUIStyle
;
976 typeAttr
[typeAttrCount
].size
= kTXNATSUIStyleSize
;
977 typeAttr
[typeAttrCount
].data
.dataPtr
= font
.MacGetATSUStyle() ;
981 if ( style
.HasTextColour() )
983 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
984 style
.GetTextColour().GetRGBColor( &color
);
985 typeAttr
[typeAttrCount
].tag
= kTXNQDFontColorAttribute
;
986 typeAttr
[typeAttrCount
].size
= kTXNQDFontColorAttributeSize
;
987 typeAttr
[typeAttrCount
].data
.dataPtr
= (void*) &color
;
991 if ( style
.HasAlignment() )
993 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
996 switch ( style
.GetAlignment() )
998 case wxTEXT_ALIGNMENT_LEFT
:
999 align
= kTXNFlushLeft
;
1001 case wxTEXT_ALIGNMENT_CENTRE
:
1004 case wxTEXT_ALIGNMENT_RIGHT
:
1005 align
= kTXNFlushRight
;
1007 case wxTEXT_ALIGNMENT_JUSTIFIED
:
1008 align
= kTXNFullJust
;
1011 case wxTEXT_ALIGNMENT_DEFAULT
:
1012 align
= kTXNFlushDefault
;
1016 controlTags
[controlAttrCount
] = kTXNJustificationTag
;
1017 controlData
[controlAttrCount
].sValue
= align
;
1018 controlAttrCount
++ ;
1021 if ( style
.HasLeftIndent() || style
.HasRightIndent() )
1023 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1024 controlTags
[controlAttrCount
] = kTXNMarginsTag
;
1025 controlData
[controlAttrCount
].marginsPtr
= &margins
;
1026 verify_noerr( TXNGetTXNObjectControls (m_txn
, 1 ,
1027 &controlTags
[controlAttrCount
], &controlData
[controlAttrCount
]) );
1028 if ( style
.HasLeftIndent() )
1030 margins
.leftMargin
= wxConvertToTXN(style
.GetLeftIndent());
1032 if ( style
.HasRightIndent() )
1034 margins
.rightMargin
= wxConvertToTXN(style
.GetRightIndent());
1036 controlAttrCount
++ ;
1039 if ( style
.HasTabs() )
1041 const wxArrayInt
& tabarray
= style
.GetTabs();
1042 // unfortunately Mac only applies a tab distance, not individually different tabs
1043 controlTags
[controlAttrCount
] = kTXNTabSettingsTag
;
1044 if ( tabarray
.size() > 0 )
1045 controlData
[controlAttrCount
].tabValue
.value
= wxConvertToTXN(tabarray
[0]);
1047 controlData
[controlAttrCount
].tabValue
.value
= 72 ;
1049 controlData
[controlAttrCount
].tabValue
.tabType
= kTXNLeftTab
;
1050 controlAttrCount
++ ;
1053 // unfortunately the relayout is not automatic
1054 if ( controlAttrCount
> 0 )
1056 verify_noerr( TXNSetTXNObjectControls (m_txn
, false /* don't clear all */, controlAttrCount
,
1057 controlTags
, controlData
) );
1061 if ( typeAttrCount
> 0 )
1063 verify_noerr( TXNSetTypeAttributes( m_txn
, typeAttrCount
, typeAttr
, from
, to
) );
1075 TXNRecalcTextLayout( m_txn
);
1079 void wxMacMLTEControl::SetFont(const wxFont
& font
,
1080 const wxColour
& foreground
,
1081 long WXUNUSED(windowStyle
),
1082 bool WXUNUSED(ignoreBlack
))
1084 wxMacEditHelper
help( m_txn
) ;
1085 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1088 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1090 wxMacEditHelper
help( m_txn
) ;
1091 TXNSetAttribute( style
, start
, end
) ;
1094 void wxMacMLTEControl::Copy()
1099 void wxMacMLTEControl::Cut()
1104 void wxMacMLTEControl::Paste()
1109 bool wxMacMLTEControl::CanPaste() const
1111 return TXNIsScrapPastable() ;
1114 void wxMacMLTEControl::SetEditable(bool editable
)
1116 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1117 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1118 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1121 long wxMacMLTEControl::GetLastPosition() const
1123 wxTextPos actualsize
= 0 ;
1127 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1131 actualsize
= GetHandleSize( theText
)/sizeof(UniChar
);
1132 DisposeHandle( theText
) ;
1135 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1140 actualsize
= GetHandleSize( theText
) ;
1141 DisposeHandle( theText
) ;
1152 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1154 wxString value
= str
;
1155 wxMacConvertNewlines10To13( &value
) ;
1157 wxMacEditHelper
help( m_txn
) ;
1159 wxMacWindowClipper
c( GetWXPeer() ) ;
1162 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
) ;
1164 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1167 void wxMacMLTEControl::Remove( long from
, long to
)
1170 wxMacWindowClipper
c( GetWXPeer() ) ;
1172 wxMacEditHelper
help( m_txn
) ;
1173 TXNSetSelection( m_txn
, from
, to
) ;
1177 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1180 TXNGetSelection( m_txn
, &f
, &t
) ;
1185 void wxMacMLTEControl::SetSelection( long from
, long to
)
1188 wxMacWindowClipper
c( GetWXPeer() ) ;
1191 // change the selection
1192 if ((from
== -1) && (to
== -1))
1193 TXNSelectAll( m_txn
);
1195 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
);
1197 TXNShowSelection( m_txn
, kTXNShowStart
);
1200 void wxMacMLTEControl::WriteText( const wxString
& str
)
1202 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
1203 if ( !wxIsMainThread() )
1205 #if wxOSX_USE_CARBON
1206 // unfortunately CW 8 is not able to correctly deduce the template types,
1207 // so we have to instantiate explicitly
1208 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( (wxTextCtrl
*) GetWXPeer() , &wxTextCtrl::WriteText
, str
) ;
1214 wxMacConvertNewlines10To13( &st
) ;
1216 long start
, end
, dummy
;
1218 GetSelection( &start
, &dummy
) ;
1220 wxMacWindowClipper
c( GetWXPeer() ) ;
1224 wxMacEditHelper
helper( m_txn
) ;
1225 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1228 GetSelection( &dummy
, &end
) ;
1230 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1233 void wxMacMLTEControl::Clear()
1236 wxMacWindowClipper
c( GetWXPeer() ) ;
1238 wxMacEditHelper
st( m_txn
) ;
1239 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1243 bool wxMacMLTEControl::CanUndo() const
1245 return TXNCanUndo( m_txn
, NULL
) ;
1248 void wxMacMLTEControl::Undo()
1253 bool wxMacMLTEControl::CanRedo() const
1255 return TXNCanRedo( m_txn
, NULL
) ;
1258 void wxMacMLTEControl::Redo()
1263 int wxMacMLTEControl::GetNumberOfLines() const
1265 ItemCount lines
= 0 ;
1266 TXNGetLineCount( m_txn
, &lines
) ;
1271 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1276 // TODO: find a better implementation : while we can get the
1277 // line metrics of a certain line, we don't get its starting
1278 // position, so it would probably be rather a binary search
1279 // for the start position
1280 long xpos
= 0, ypos
= 0 ;
1281 int lastHeight
= 0 ;
1284 lastpos
= GetLastPosition() ;
1285 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1287 if ( y
== ypos
&& x
== xpos
)
1290 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
1292 if ( curpt
.v
> lastHeight
)
1298 lastHeight
= curpt
.v
;
1307 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
1317 lastpos
= GetLastPosition() ;
1318 if ( pos
<= lastpos
)
1320 // TODO: find a better implementation - while we can get the
1321 // line metrics of a certain line, we don't get its starting
1322 // position, so it would probably be rather a binary search
1323 // for the start position
1324 long xpos
= 0, ypos
= 0 ;
1325 int lastHeight
= 0 ;
1328 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1330 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
1332 if ( curpt
.v
> lastHeight
)
1338 lastHeight
= curpt
.v
;
1353 void wxMacMLTEControl::ShowPosition( long pos
)
1355 Point current
, desired
;
1356 TXNOffset selstart
, selend
;
1358 TXNGetSelection( m_txn
, &selstart
, &selend
);
1359 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1360 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1362 // TODO: use HIPoints for 10.3 and above
1364 OSErr theErr
= noErr
;
1365 long dv
= desired
.v
- current
.v
;
1366 long dh
= desired
.h
- current
.h
;
1367 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
1368 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1370 // there will be an error returned for classic MLTE implementation when the control is
1371 // invisible, but HITextView works correctly, so we don't assert that one
1372 // wxASSERT_MSG( theErr == noErr, wxT("TXNScroll returned an error!") );
1375 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1378 wxMBConvUTF16 converter
;
1379 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
1380 wxASSERT_MSG( byteBufferLen
!= wxCONV_FAILED
,
1381 wxT("Conversion to UTF-16 unexpectedly failed") );
1382 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
+ 2 ) ; // 2 for NUL in UTF-16
1383 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
+ 2 ) ;
1384 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
1386 #else // !wxUSE_UNICODE
1387 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
1388 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
1389 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
1392 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1396 if ( lineNo
< GetNumberOfLines() )
1399 Fixed lineWidth
, lineHeight
, currentHeight
;
1402 // get the first possible position in the control
1403 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1405 // Iterate through the lines until we reach the one we want,
1406 // adding to our current y pixel point position
1409 while (ypos
< lineNo
)
1411 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1412 currentHeight
+= lineHeight
;
1415 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1416 TXNOffset theOffset
;
1417 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1419 wxString content
= GetStringValue() ;
1420 Point currentPoint
= thePoint
;
1421 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1423 line
+= content
[theOffset
];
1424 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1431 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1435 if ( lineNo
< GetNumberOfLines() )
1438 Fixed lineWidth
, lineHeight
, currentHeight
;
1441 // get the first possible position in the control
1442 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1444 // Iterate through the lines until we reach the one we want,
1445 // adding to our current y pixel point position
1448 while (ypos
< lineNo
)
1450 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1451 currentHeight
+= lineHeight
;
1454 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1455 TXNOffset theOffset
;
1456 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1458 wxString content
= GetStringValue() ;
1459 Point currentPoint
= thePoint
;
1460 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1463 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1470 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
1472 // ----------------------------------------------------------------------------
1473 // MLTE control implementation (classic part)
1474 // ----------------------------------------------------------------------------
1476 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
1477 // has to live on. We have different problems coming from outdated implementations on the
1478 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
1479 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
1480 // no way out, therefore we are using our own implementation and our own scrollbars ....
1482 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
1483 ControlActionUPP gTXNScrollActionProc
= NULL
;
1485 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
1486 SInt32 iValue
, SInt32 iMaximumValue
,
1487 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
1489 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
1490 SInt32 value
= wxMax( iValue
, 0 ) ;
1491 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
1493 if ( iScrollBarOrientation
== kTXNHorizontal
)
1495 if ( mlte
->m_sbHorizontal
)
1497 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
1498 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
1499 mlte
->m_lastHorizontalValue
= value
;
1502 else if ( iScrollBarOrientation
== kTXNVertical
)
1504 if ( mlte
->m_sbVertical
)
1506 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
1507 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
1508 mlte
->m_lastVerticalValue
= value
;
1513 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
1515 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
1519 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
1523 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
1525 SInt32 minimum
= 0 ;
1526 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
1527 SInt32 value
= GetControl32BitValue( controlRef
) ;
1532 case kControlDownButtonPart
:
1536 case kControlUpButtonPart
:
1540 case kControlPageDownPart
:
1541 delta
= GetControlViewSize( controlRef
) ;
1544 case kControlPageUpPart
:
1545 delta
= -GetControlViewSize( controlRef
) ;
1548 case kControlIndicatorPart
:
1549 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
1558 SInt32 newValue
= value
;
1560 if ( partCode
!= kControlIndicatorPart
)
1562 if ( value
+ delta
< minimum
)
1563 delta
= minimum
- value
;
1564 if ( value
+ delta
> maximum
)
1565 delta
= maximum
- value
;
1567 SetControl32BitValue( controlRef
, value
+ delta
) ;
1568 newValue
= value
+ delta
;
1571 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
1572 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
1575 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
1576 &verticalDelta
, &horizontalDelta
);
1577 verify_noerr( err
);
1580 mlte
->m_lastHorizontalValue
= newValue
;
1582 mlte
->m_lastVerticalValue
= newValue
;
1586 // make correct activations
1587 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
1589 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
1591 wxMacWindowClipper
clipper( textctrl
) ;
1592 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
1594 ControlRef controlFocus
= 0 ;
1595 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
1596 if ( controlFocus
== m_controlRef
)
1597 TXNFocus( m_txn
, setActive
);
1600 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
1602 TXNFocus( m_txn
, setFocus
);
1605 // guards against inappropriate redraw (hidden objects drawing onto window)
1607 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
1609 ControlRef controlFocus
= 0 ;
1610 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
1612 if ( !vis
&& (controlFocus
== m_controlRef
) )
1613 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
1615 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
1616 TXNControlData iControlData
[1] = { { (UInt32
)false } };
1618 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
1620 if ( iControlData
[0].uValue
!= vis
)
1622 iControlData
[0].uValue
= vis
;
1623 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
1626 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
1627 // if we run into further problems we might set the FrameBounds to an empty rect here
1630 // make sure that the TXNObject is at the right position
1632 void wxMacMLTEClassicControl::MacUpdatePosition()
1634 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1635 if ( textctrl
== NULL
)
1639 GetRectInWindowCoords( &bounds
);
1641 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
1642 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
1645 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
1646 OffsetRect( &visBounds
, x
, y
) ;
1648 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
1650 m_txnControlBounds
= bounds
;
1651 m_txnVisBounds
= visBounds
;
1652 wxMacWindowClipper
cl( textctrl
) ;
1654 if ( m_sbHorizontal
|| m_sbVertical
)
1656 int w
= bounds
.right
- bounds
.left
;
1657 int h
= bounds
.bottom
- bounds
.top
;
1659 if ( m_sbHorizontal
)
1663 sbBounds
.left
= -1 ;
1664 sbBounds
.top
= h
- 14 ;
1665 sbBounds
.right
= w
+ 1 ;
1666 sbBounds
.bottom
= h
+ 1 ;
1668 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
1669 SetControlViewSize( m_sbHorizontal
, w
) ;
1676 sbBounds
.left
= w
- 14 ;
1678 sbBounds
.right
= w
+ 1 ;
1679 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
1681 SetControlBounds( m_sbVertical
, &sbBounds
) ;
1682 SetControlViewSize( m_sbVertical
, h
) ;
1687 TXNLongRect olddestRect
;
1688 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
1690 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
1691 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
1692 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
1693 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
1694 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
1695 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
1697 if ( olddestRect
.right
>= 10000 )
1698 destRect
.right
= destRect
.left
+ 32000 ;
1700 if ( olddestRect
.bottom
>= 0x20000000 )
1701 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
1703 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
1704 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
1709 m_txnControlBounds
.top
,
1710 m_txnControlBounds
.left
,
1711 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
1712 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
1716 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
1717 // movement, therefore we have to force it
1719 // this problem has been reported in OSX as well, so we use this here once again
1721 TXNLongRect textRect
;
1722 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
1723 if ( textRect
.left
< m_txnControlBounds
.left
)
1724 TXNShowSelection( m_txn
, kTXNShowStart
) ;
1728 void wxMacMLTEClassicControl::Move(int x
, int y
, int width
, int height
)
1730 wxMacControl::Move(x
,y
,width
,height
) ;
1731 MacUpdatePosition() ;
1734 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16
WXUNUSED(thePart
))
1736 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1737 if ( textctrl
== NULL
)
1740 if ( textctrl
->IsShownOnScreen() )
1742 wxMacWindowClipper
clipper( textctrl
) ;
1743 TXNDraw( m_txn
, NULL
) ;
1747 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1749 Point where
= { y
, x
} ;
1750 ControlPartCode result
= kControlNoPart
;
1752 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
1753 if ( (textctrl
!= NULL
) && textctrl
->IsShownOnScreen() )
1755 if (PtInRect( where
, &m_txnControlBounds
))
1757 result
= kControlEditTextPart
;
1761 // sometimes we get the coords also in control local coordinates, therefore test again
1763 textctrl
->MacClientToRootWindow( &x
, &y
) ;
1767 if (PtInRect( where
, &m_txnControlBounds
))
1768 result
= kControlEditTextPart
;
1775 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* WXUNUSED(actionProc
) )
1777 ControlPartCode result
= kControlNoPart
;
1779 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
1780 if ( (textctrl
!= NULL
) && textctrl
->IsShownOnScreen() )
1782 Point startPt
= { y
, x
} ;
1784 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
1786 textctrl
->MacClientToRootWindow( &x
, &y
) ;
1790 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
1792 case kControlEditTextPart
:
1794 wxMacWindowClipper
clipper( textctrl
) ;
1797 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
1798 TXNClick( m_txn
, &rec
);
1810 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
1812 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1813 if ( textctrl
== NULL
)
1816 if (textctrl
->IsShownOnScreen())
1818 if (IsControlActive(m_controlRef
))
1822 wxMacWindowClipper
clipper( textctrl
) ;
1827 if (PtInRect(mousep
, &m_txnControlBounds
))
1829 RgnHandle theRgn
= NewRgn();
1830 RectRgn(theRgn
, &m_txnControlBounds
);
1831 TXNAdjustCursor(m_txn
, theRgn
);
1838 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1840 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1841 if ( textctrl
== NULL
)
1842 return kControlNoPart
;
1844 wxMacWindowClipper
clipper( textctrl
) ;
1847 memset( &ev
, 0 , sizeof( ev
) ) ;
1849 ev
.modifiers
= modifiers
;
1850 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
1851 TXNKeyDown( m_txn
, &ev
);
1853 return kControlEntireControl
;
1856 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
1858 MacActivatePaneText( activating
);
1861 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
1863 ControlPartCode focusResult
= kControlFocusNoPart
;
1865 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1866 if ( textctrl
== NULL
)
1869 wxMacWindowClipper
clipper( textctrl
) ;
1871 ControlRef controlFocus
= NULL
;
1872 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
1873 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
1877 case kControlFocusPrevPart
:
1878 case kControlFocusNextPart
:
1879 MacFocusPaneText( !wasFocused
);
1880 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
1883 case kControlFocusNoPart
:
1885 MacFocusPaneText( false );
1886 focusResult
= kControlFocusNoPart
;
1893 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *WXUNUSED(info
) )
1897 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
1898 const wxString
& str
,
1900 const wxSize
& size
, long style
)
1901 : wxMacMLTEControl( wxPeer
)
1903 m_font
= wxPeer
->GetFont() ;
1904 m_windowStyle
= style
;
1905 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1908 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
1909 | kControlWantsActivate
| kControlHandlesTracking
1910 // | kControlHasSpecialBackground
1911 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
1913 OSStatus err
= ::CreateUserPaneControl(
1914 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
1915 &bounds
, featureSet
, &m_controlRef
);
1916 verify_noerr( err
);
1917 SetControlReference( m_controlRef
, (URefCon
) wxPeer
);
1921 AdjustCreationAttributes( *wxWHITE
, true ) ;
1923 MacSetObjectVisibility( wxPeer
->IsShownOnScreen() ) ;
1927 wxMacConvertNewlines10To13( &st
) ;
1928 wxMacWindowClipper
clipper( GetWXPeer() ) ;
1929 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1930 TXNSetSelection( m_txn
, 0, 0 ) ;
1934 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
1936 TXNDeleteObject( m_txn
);
1940 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
1942 MacSetObjectVisibility( shown
) ;
1943 wxMacControl::VisibilityChanged( shown
) ;
1946 void wxMacMLTEClassicControl::SuperChangedPosition()
1948 MacUpdatePosition() ;
1949 wxMacControl::SuperChangedPosition() ;
1952 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
1953 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
1954 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
1955 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
1956 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
1957 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
1958 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
1960 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
1962 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
1963 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1965 win
->MacControlUserPaneDrawProc( part
) ;
1968 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
1970 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
1971 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1973 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
1975 return kControlNoPart
;
1978 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
1980 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
1981 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1983 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
1985 return kControlNoPart
;
1988 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
1990 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
1991 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1993 win
->MacControlUserPaneIdleProc() ;
1996 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
1998 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
1999 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2001 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2003 return kControlNoPart
;
2006 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2008 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
)control
) , wxTextCtrl
) ;
2009 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2011 win
->MacControlUserPaneActivateProc( activating
) ;
2014 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2016 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
2017 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2019 return win
->MacControlUserPaneFocusProc( action
) ;
2021 return kControlNoPart
;
2025 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2027 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget(control
) , wxTextCtrl
) ;
2028 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2030 win
->MacControlUserPaneBackgroundProc(info
) ;
2034 // TXNRegisterScrollInfoProc
2036 OSStatus
wxMacMLTEClassicControl::DoCreate()
2039 OSStatus err
= noErr
;
2041 // set up our globals
2042 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2043 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2044 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2045 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2046 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2047 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2048 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2050 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2051 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2053 // set the initial settings for our private data
2055 m_txnWindow
= GetControlOwner(m_controlRef
);
2056 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2058 // set up the user pane procedures
2059 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2060 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2061 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2062 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2063 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2064 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2065 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2067 // calculate the rectangles used by the control
2068 GetRectInWindowCoords( &bounds
);
2070 m_txnControlBounds
= bounds
;
2071 m_txnVisBounds
= bounds
;
2076 GetGWorld( &origPort
, &origDev
) ;
2077 SetPort( m_txnPort
);
2079 // create the new edit field
2080 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2082 // the scrollbars are not correctly embedded but are inserted at the root:
2083 // this gives us problems as we have erratic redraws even over the structure area
2085 m_sbHorizontal
= 0 ;
2087 m_lastHorizontalValue
= 0 ;
2088 m_lastVerticalValue
= 0 ;
2090 Rect sb
= { 0 , 0 , 0 , 0 } ;
2091 if ( frameOptions
& kTXNWantVScrollBarMask
)
2093 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2094 SetControlReference( m_sbVertical
, (SInt32
)this );
2095 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2096 ShowControl( m_sbVertical
);
2097 EmbedControl( m_sbVertical
, m_controlRef
);
2098 frameOptions
&= ~kTXNWantVScrollBarMask
;
2101 if ( frameOptions
& kTXNWantHScrollBarMask
)
2103 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2104 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2105 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2106 ShowControl( m_sbHorizontal
);
2107 EmbedControl( m_sbHorizontal
, m_controlRef
);
2108 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2112 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2113 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2114 &m_txn
, &m_txnFrameID
, NULL
);
2115 verify_noerr( err
);
2118 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2119 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2120 int toptag
= WXSIZEOF( iControlTags
) ;
2121 TXNCarbonEventInfo cInfo
;
2122 cInfo
.useCarbonEvents
= false ;
2125 cInfo
.fDictionary
= NULL
;
2127 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2130 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2132 SetGWorld( origPort
, origDev
) ;
2138 // ----------------------------------------------------------------------------
2139 // MLTE control implementation (OSX part)
2140 // ----------------------------------------------------------------------------
2142 // tiger multi-line textcontrols with no CR in the entire content
2143 // don't scroll automatically, so we need a hack.
2144 // This attempt only works 'before' the key (ie before CallNextEventHandler)
2145 // is processed, thus the scrolling always occurs one character too late, but
2146 // better than nothing ...
2148 static const EventTypeSpec eventList
[] =
2150 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
2153 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2155 OSStatus result
= eventNotHandledErr
;
2156 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
2158 switch ( GetEventKind( event
) )
2160 case kEventTextInputUnicodeForKeyEvent
:
2162 TXNOffset from
, to
;
2163 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
2165 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
2166 result
= CallNextEventHandler(handler
,event
);
2176 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2178 OSStatus result
= eventNotHandledErr
;
2180 switch ( GetEventClass( event
) )
2182 case kEventClassTextInput
:
2183 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
2192 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
2194 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2195 const wxString
& str
,
2197 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2199 m_font
= wxPeer
->GetFont() ;
2200 m_windowStyle
= style
;
2201 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2203 wxMacConvertNewlines10To13( &st
) ;
2206 { bounds
.left
, bounds
.top
},
2207 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2209 m_scrollView
= NULL
;
2210 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2211 if (( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
)) || (frameOptions
&kTXNSingleLineOnlyMask
))
2213 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2216 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2217 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2222 HIScrollViewCreate(kHIScrollViewOptionsVertScroll
,&m_scrollView
);
2223 HIScrollViewSetScrollBarAutoHide(m_scrollView
,true);
2226 HIViewSetFrame( m_scrollView
, &hr
);
2227 HIViewSetVisible( m_scrollView
, true );
2231 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2232 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2233 HIViewSetVisible( m_textView
, true ) ;
2236 HIViewAddSubview( m_scrollView
, m_textView
) ;
2237 m_controlRef
= m_scrollView
;
2238 InstallEventHandler( (WXWidget
) m_textView
) ;
2242 HIViewSetFrame( m_textView
, &hr
);
2243 m_controlRef
= m_textView
;
2246 AdjustCreationAttributes( *wxWHITE
, true ) ;
2248 wxMacWindowClipper
c( GetWXPeer() ) ;
2250 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2252 TXNSetSelection( m_txn
, 0, 0 );
2253 TXNShowSelection( m_txn
, kTXNShowStart
);
2255 ::InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
2256 GetEventTypeCount(eventList
), eventList
, this,
2260 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
2264 bool wxMacMLTEHIViewControl::SetFocus()
2266 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, kControlFocusNextPart
) == noErr
;
2269 bool wxMacMLTEHIViewControl::HasFocus() const
2271 ControlRef control
;
2272 if ( GetUserFocusWindow() == NULL
)
2275 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2276 return control
== m_textView
;
2279 void wxMacMLTEHIViewControl::SetBackgroundColour(const wxColour
& col
)
2281 HITextViewSetBackgroundColor( m_textView
, col
.GetPixel() );
2284 #endif // wxUSE_TEXTCTRL