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 wxDECLARE_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 wxDECLARE_NO_COPY_CLASS(wxMacWindowClipper
);
166 wxMacWindowClipper( const wxWindow
* win
);
167 ~wxMacWindowClipper();
170 RgnHandle m_formerClip
;
174 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
176 ::GetPort( &m_port
);
180 wxMacPortSaver::~wxMacPortSaver()
185 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
186 wxMacPortSaver( (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) )
188 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
189 m_formerClip
= NewRgn() ;
190 m_newClip
= NewRgn() ;
191 GetClip( m_formerClip
) ;
195 // guard against half constructed objects, this just leads to a empty clip
196 if ( win
->GetPeer() )
199 win
->MacWindowToRootWindow( &x
, &y
) ;
201 // get area including focus rect
202 HIShapeGetAsQDRgn( ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
);
203 if ( !EmptyRgn( m_newClip
) )
204 OffsetRgn( m_newClip
, x
, y
) ;
207 SetClip( m_newClip
) ;
211 wxMacWindowClipper::~wxMacWindowClipper()
213 SetPort( m_newPort
) ;
214 SetClip( m_formerClip
) ;
215 DisposeRgn( m_newClip
) ;
216 DisposeRgn( m_formerClip
) ;
219 // common parts for implementations based on MLTE
221 class wxMacMLTEControl
: public wxMacControl
, public wxTextWidgetImpl
224 wxMacMLTEControl( wxTextCtrl
*peer
) ;
225 ~wxMacMLTEControl() {}
227 virtual bool CanFocus() const
230 virtual wxString
GetStringValue() const ;
231 virtual void SetStringValue( const wxString
&str
) ;
233 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
235 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
237 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
) ;
238 virtual void SetBackgroundColour(const wxColour
& col
);
239 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
240 virtual void Copy() ;
242 virtual void Paste() ;
243 virtual bool CanPaste() const ;
244 virtual void SetEditable( bool editable
) ;
245 virtual long GetLastPosition() const ;
246 virtual void Replace( long from
, long to
, const wxString
&str
) ;
247 virtual void Remove( long from
, long to
) ;
248 virtual void GetSelection( long* from
, long* to
) const ;
249 virtual void SetSelection( long from
, long to
) ;
251 virtual void WriteText( const wxString
& str
) ;
253 virtual bool HasOwnContextMenu() const
255 TXNCommandEventSupportOptions options
;
256 TXNGetCommandEventSupport( m_txn
, & options
) ;
257 return options
& kTXNSupportEditCommandProcessing
;
260 virtual void CheckSpelling(bool check
)
262 TXNSetSpellCheckAsYouType( m_txn
, (Boolean
) check
);
264 virtual void Clear() ;
266 virtual bool CanUndo() const ;
267 virtual void Undo() ;
268 virtual bool CanRedo() const;
269 virtual void Redo() ;
270 virtual int GetNumberOfLines() const ;
271 virtual long XYToPosition(long x
, long y
) const ;
272 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
273 virtual void ShowPosition( long pos
) ;
274 virtual int GetLineLength(long lineNo
) const ;
275 virtual wxString
GetLineText(long lineNo
) const ;
277 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
278 TXNObject
GetTXNObject() { return m_txn
; }
281 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
286 // implementation available under OSX
288 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
291 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
294 const wxSize
& size
, long style
) ;
295 virtual ~wxMacMLTEHIViewControl() ;
297 virtual bool SetFocus() ;
298 virtual bool HasFocus() const ;
299 virtual void SetBackgroundColour(const wxColour
& col
) ;
302 HIViewRef m_scrollView
;
303 HIViewRef m_textView
;
306 // 'classic' MLTE implementation
308 class wxMacMLTEClassicControl
: public wxMacMLTEControl
311 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
314 const wxSize
& size
, long style
) ;
315 virtual ~wxMacMLTEClassicControl() ;
317 virtual void VisibilityChanged(bool shown
) ;
318 virtual void SuperChangedPosition() ;
320 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
321 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
322 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
323 virtual void MacControlUserPaneIdleProc() ;
324 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
325 virtual void MacControlUserPaneActivateProc(bool activating
) ;
326 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
327 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
329 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
331 MacControlUserPaneIdleProc();
335 virtual void Move(int x
, int y
, int width
, int height
);
340 void MacUpdatePosition() ;
341 void MacActivatePaneText(bool setActive
) ;
342 void MacFocusPaneText(bool setFocus
) ;
343 void MacSetObjectVisibility(bool vis
) ;
346 TXNFrameID m_txnFrameID
;
348 WindowRef m_txnWindow
;
349 // bounds of the control as we last did set the txn frames
350 Rect m_txnControlBounds
;
351 Rect m_txnVisBounds
;
353 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
354 static pascal void TXNScrollInfoProc(
355 SInt32 iValue
, SInt32 iMaximumValue
,
356 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
358 ControlRef m_sbHorizontal
;
359 SInt32 m_lastHorizontalValue
;
360 ControlRef m_sbVertical
;
361 SInt32 m_lastVerticalValue
;
364 wxWidgetImplType
* wxWidgetImpl::CreateTextControl( wxTextCtrl
* wxpeer
,
365 wxWindowMac
* WXUNUSED(parent
),
366 wxWindowID
WXUNUSED(id
),
371 long WXUNUSED(extraStyle
))
373 bool forceMLTE
= false ;
375 #if wxUSE_SYSTEM_OPTIONS
376 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
382 if ( UMAGetSystemVersion() >= 0x1050 )
385 wxMacControl
* peer
= NULL
;
389 if ( style
& wxTE_MULTILINE
|| ( UMAGetSystemVersion() >= 0x1050 ) )
390 peer
= new wxMacMLTEHIViewControl( wxpeer
, str
, pos
, size
, style
) ;
395 if ( !(style
& wxTE_MULTILINE
) && !forceMLTE
)
397 peer
= new wxMacUnicodeTextControl( wxpeer
, str
, pos
, size
, style
) ;
401 // the horizontal single line scrolling bug that made us keep the classic implementation
403 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
405 peer
= new wxMacMLTEClassicControl( wxpeer
, str
, pos
, size
, style
) ;
410 // ----------------------------------------------------------------------------
411 // standard unicode control implementation
412 // ----------------------------------------------------------------------------
414 // the current unicode textcontrol implementation has a bug : only if the control
415 // is currently having the focus, the selection can be retrieved by the corresponding
416 // data tag. So we have a mirroring using a member variable
417 // TODO : build event table using virtual member functions for wxMacControl
419 static const EventTypeSpec unicodeTextControlEventList
[] =
421 { kEventClassControl
, kEventControlSetFocusPart
} ,
424 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
426 OSStatus result
= eventNotHandledErr
;
427 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
428 wxMacCarbonEvent
cEvent( event
) ;
430 switch ( GetEventKind( event
) )
432 case kEventControlSetFocusPart
:
434 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
435 if ( controlPart
== kControlFocusNoPart
)
437 // about to loose focus -> store selection to field
438 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
440 result
= CallNextEventHandler(handler
,event
) ;
441 if ( controlPart
!= kControlFocusNoPart
)
443 // about to gain focus -> set selection from field
444 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
455 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
457 OSStatus result
= eventNotHandledErr
;
459 switch ( GetEventClass( event
) )
461 case kEventClassControl
:
462 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
471 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
473 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
) : wxMacControl( wxPeer
)
477 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
480 const wxSize
& size
, long style
)
481 : wxMacControl( wxPeer
)
483 m_font
= wxPeer
->GetFont() ;
484 m_windowStyle
= style
;
485 m_selection
.selStart
= m_selection
.selEnd
= 0;
486 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
488 wxMacConvertNewlines10To13( &st
) ;
489 wxCFStringRef
cf(st
, m_font
.GetEncoding()) ;
491 m_valueTag
= kControlEditTextCFStringTag
;
492 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
495 m_valueTag
= kControlEditTextPasswordCFStringTag
;
497 OSStatus err
= CreateEditUnicodeTextControl(
498 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cf
,
499 isPassword
, NULL
, &m_controlRef
) ;
502 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
503 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
505 InstallEventHandlers();
508 void wxMacUnicodeTextControl::InstallEventHandlers()
510 ::InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
511 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
512 (EventHandlerRef
*) &m_macTextCtrlEventHandler
);
515 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
517 ::RemoveEventHandler((EventHandlerRef
) m_macTextCtrlEventHandler
);
520 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
522 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
524 // work around a refresh issue insofar as not always the entire content is shown,
525 // even if this would be possible
526 ControlEditTextSelectionRec sel
;
527 CFStringRef value
= NULL
;
529 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
530 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
531 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
532 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
538 wxString
wxMacUnicodeTextControl::GetStringValue() const
541 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
544 wxCFStringRef
cf(value
) ;
545 result
= cf
.AsString() ;
549 wxMacConvertNewlines13To10( &result
) ;
551 wxMacConvertNewlines10To13( &result
) ;
557 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
560 wxMacConvertNewlines10To13( &st
) ;
561 wxCFStringRef
cf( st
, m_font
.GetEncoding() ) ;
562 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
565 void wxMacUnicodeTextControl::Copy()
567 SendHICommand( kHICommandCopy
) ;
570 void wxMacUnicodeTextControl::Cut()
572 SendHICommand( kHICommandCut
) ;
575 void wxMacUnicodeTextControl::Paste()
577 SendHICommand( kHICommandPaste
) ;
580 bool wxMacUnicodeTextControl::CanPaste() const
585 void wxMacUnicodeTextControl::SetEditable(bool WXUNUSED(editable
))
587 #if 0 // leads to problem because text cannot be selected anymore
588 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
592 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
594 ControlEditTextSelectionRec sel
;
596 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
601 *from
= sel
.selStart
;
606 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
608 ControlEditTextSelectionRec sel
;
611 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
614 wxCFStringRef
cf(value
) ;
615 textLength
= cf
.AsString().length() ;
618 if ((from
== -1) && (to
== -1))
625 from
= wxMin(textLength
,wxMax(from
,0)) ;
629 to
= wxMax(0,wxMin(textLength
,to
)) ;
632 sel
.selStart
= from
;
635 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
640 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
642 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
643 if ( !wxIsMainThread() )
646 // unfortunately CW 8 is not able to correctly deduce the template types,
647 // so we have to instantiate explicitly
648 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( (wxTextCtrl
*) GetWXPeer() , &wxTextCtrl::WriteText
, str
) ;
654 wxMacConvertNewlines10To13( &st
) ;
658 wxCFStringRef
cf(st
, m_font
.GetEncoding() ) ;
659 CFStringRef value
= cf
;
660 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
664 wxString val
= GetStringValue() ;
666 GetSelection( &start
, &end
) ;
667 val
.Remove( start
, end
- start
) ;
668 val
.insert( start
, str
) ;
669 SetStringValue( val
) ;
670 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
674 // ----------------------------------------------------------------------------
675 // MLTE control implementation (common part)
676 // ----------------------------------------------------------------------------
678 // if MTLE is read only, no changes at all are allowed, not even from
679 // procedural API, in order to allow changes via API all the same we must undo
680 // the readonly status while we are executing, this class helps to do so
682 class wxMacEditHelper
685 wxMacEditHelper( TXNObject txn
)
687 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
689 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
690 if ( m_data
[0].uValue
== kTXNReadOnly
)
692 TXNControlData data
[] = { { kTXNReadWrite
} } ;
693 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
699 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
700 if ( m_data
[0].uValue
== kTXNReadOnly
)
701 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
706 TXNControlData m_data
[1] ;
709 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
710 : wxMacControl( peer
)
712 SetNeedsFocusRect( true ) ;
715 wxString
wxMacMLTEControl::GetStringValue() const
724 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
733 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
734 if ( actualSize
> 0 )
738 #if SIZEOF_WCHAR_T == 2
739 ptr
= new wxChar
[actualSize
+ 1] ;
740 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
742 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
744 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
745 wxMBConvUTF16 converter
;
746 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
747 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, wxT("Unable to count the number of characters in this string!") );
748 ptr
= new wxChar
[noChars
+ 1] ;
750 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
751 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, wxT("Conversion of string failed!") );
756 ptr
[actualSize
] = 0 ;
757 result
= wxString( ptr
) ;
761 DisposeHandle( theText
) ;
765 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
774 actualSize
= GetHandleSize( theText
) ;
775 if ( actualSize
> 0 )
778 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
782 DisposeHandle( theText
) ;
788 wxMacConvertNewlines13To10( &result
) ;
790 wxMacConvertNewlines10To13( &result
) ;
796 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
799 wxMacConvertNewlines10To13( &st
);
803 wxMacWindowClipper
c( GetWXPeer() ) ;
807 wxMacEditHelper
help( m_txn
);
808 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
811 TXNSetSelection( m_txn
, 0, 0 );
812 TXNShowSelection( m_txn
, kTXNShowStart
);
816 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
818 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
820 frameOptions
|= kTXNDoFontSubstitutionMask
;
822 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
823 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
825 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
826 frameOptions
|= kTXNWantHScrollBarMask
;
828 if ( wxStyle
& wxTE_MULTILINE
)
830 if ( ! (wxStyle
& wxTE_DONTWRAP
) )
831 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
833 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
835 frameOptions
|= kTXNWantVScrollBarMask
;
837 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
838 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
839 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
840 // if ( frameOptions & kTXNWantHScrollBarMask )
841 // frameOptions |= kTXNDrawGrowIconMask ;
846 frameOptions
|= kTXNSingleLineOnlyMask
;
849 return frameOptions
;
852 void wxMacMLTEControl::AdjustCreationAttributes(const wxColour
&background
,
853 bool WXUNUSED(visible
))
855 TXNControlTag iControlTags
[] =
857 kTXNDoFontSubstitution
,
858 kTXNWordWrapStateTag
,
860 TXNControlData iControlData
[] =
866 int toptag
= WXSIZEOF( iControlTags
) ;
868 if ( m_windowStyle
& wxTE_MULTILINE
)
870 iControlData
[1].uValue
=
871 (m_windowStyle
& wxTE_DONTWRAP
)
876 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
879 // setting the default font:
880 // under 10.2 this causes a visible caret, therefore we avoid it
886 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
888 TXNTypeAttributes typeAttr
[] =
890 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
891 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
892 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
895 err
= TXNSetTypeAttributes(
896 m_txn
, WXSIZEOF(typeAttr
),
897 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
900 if ( m_windowStyle
& wxTE_PASSWORD
)
903 err
= TXNEchoMode( m_txn
, c
, 0 , true );
908 tback
.bgType
= kTXNBackgroundTypeRGB
;
909 background
.GetRGBColor( &tback
.bg
.color
);
910 TXNSetBackground( m_txn
, &tback
);
913 TXNCommandEventSupportOptions options
;
914 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
917 kTXNSupportEditCommandProcessing
918 | kTXNSupportEditCommandUpdating
919 | kTXNSupportFontCommandProcessing
920 | kTXNSupportFontCommandUpdating
;
922 // only spell check when not read-only
923 // use system options for the default
924 bool checkSpelling
= false ;
925 if ( !(m_windowStyle
& wxTE_READONLY
) )
927 #if wxUSE_SYSTEM_OPTIONS
928 if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) == 1) )
930 checkSpelling
= true ;
937 kTXNSupportSpellCheckCommandProcessing
938 | kTXNSupportSpellCheckCommandUpdating
;
940 TXNSetCommandEventSupport( m_txn
, options
) ;
944 void wxMacMLTEControl::SetBackgroundColour(const wxColour
& col
)
947 tback
.bgType
= kTXNBackgroundTypeRGB
;
948 col
.GetRGBColor(&tback
.bg
.color
);
949 TXNSetBackground( m_txn
, &tback
);
952 static inline int wxConvertToTXN(int x
)
954 return static_cast<int>(x
/ 254.0 * 72 + 0.5);
957 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
959 TXNTypeAttributes typeAttr
[4] ;
961 size_t typeAttrCount
= 0 ;
964 TXNControlTag controlTags
[4];
965 TXNControlData controlData
[4];
966 size_t controlAttrCount
= 0;
970 bool relayout
= false;
973 if ( style
.HasFont() )
975 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
976 font
= style
.GetFont() ;
977 typeAttr
[typeAttrCount
].tag
= kTXNATSUIStyle
;
978 typeAttr
[typeAttrCount
].size
= kTXNATSUIStyleSize
;
979 typeAttr
[typeAttrCount
].data
.dataPtr
= font
.MacGetATSUStyle() ;
983 if ( style
.HasTextColour() )
985 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
986 style
.GetTextColour().GetRGBColor( &color
);
987 typeAttr
[typeAttrCount
].tag
= kTXNQDFontColorAttribute
;
988 typeAttr
[typeAttrCount
].size
= kTXNQDFontColorAttributeSize
;
989 typeAttr
[typeAttrCount
].data
.dataPtr
= (void*) &color
;
993 if ( style
.HasAlignment() )
995 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
998 switch ( style
.GetAlignment() )
1000 case wxTEXT_ALIGNMENT_LEFT
:
1001 align
= kTXNFlushLeft
;
1003 case wxTEXT_ALIGNMENT_CENTRE
:
1006 case wxTEXT_ALIGNMENT_RIGHT
:
1007 align
= kTXNFlushRight
;
1009 case wxTEXT_ALIGNMENT_JUSTIFIED
:
1010 align
= kTXNFullJust
;
1013 case wxTEXT_ALIGNMENT_DEFAULT
:
1014 align
= kTXNFlushDefault
;
1018 controlTags
[controlAttrCount
] = kTXNJustificationTag
;
1019 controlData
[controlAttrCount
].sValue
= align
;
1020 controlAttrCount
++ ;
1023 if ( style
.HasLeftIndent() || style
.HasRightIndent() )
1025 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1026 controlTags
[controlAttrCount
] = kTXNMarginsTag
;
1027 controlData
[controlAttrCount
].marginsPtr
= &margins
;
1028 verify_noerr( TXNGetTXNObjectControls (m_txn
, 1 ,
1029 &controlTags
[controlAttrCount
], &controlData
[controlAttrCount
]) );
1030 if ( style
.HasLeftIndent() )
1032 margins
.leftMargin
= wxConvertToTXN(style
.GetLeftIndent());
1034 if ( style
.HasRightIndent() )
1036 margins
.rightMargin
= wxConvertToTXN(style
.GetRightIndent());
1038 controlAttrCount
++ ;
1041 if ( style
.HasTabs() )
1043 const wxArrayInt
& tabarray
= style
.GetTabs();
1044 // unfortunately Mac only applies a tab distance, not individually different tabs
1045 controlTags
[controlAttrCount
] = kTXNTabSettingsTag
;
1046 if ( tabarray
.size() > 0 )
1047 controlData
[controlAttrCount
].tabValue
.value
= wxConvertToTXN(tabarray
[0]);
1049 controlData
[controlAttrCount
].tabValue
.value
= 72 ;
1051 controlData
[controlAttrCount
].tabValue
.tabType
= kTXNLeftTab
;
1052 controlAttrCount
++ ;
1055 // unfortunately the relayout is not automatic
1056 if ( controlAttrCount
> 0 )
1058 verify_noerr( TXNSetTXNObjectControls (m_txn
, false /* don't clear all */, controlAttrCount
,
1059 controlTags
, controlData
) );
1063 if ( typeAttrCount
> 0 )
1065 verify_noerr( TXNSetTypeAttributes( m_txn
, typeAttrCount
, typeAttr
, from
, to
) );
1077 TXNRecalcTextLayout( m_txn
);
1081 void wxMacMLTEControl::SetFont(const wxFont
& font
,
1082 const wxColour
& foreground
,
1083 long WXUNUSED(windowStyle
),
1084 bool WXUNUSED(ignoreBlack
))
1086 wxMacEditHelper
help( m_txn
) ;
1087 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1090 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1092 wxMacEditHelper
help( m_txn
) ;
1093 TXNSetAttribute( style
, start
, end
) ;
1096 void wxMacMLTEControl::Copy()
1101 void wxMacMLTEControl::Cut()
1106 void wxMacMLTEControl::Paste()
1111 bool wxMacMLTEControl::CanPaste() const
1113 return TXNIsScrapPastable() ;
1116 void wxMacMLTEControl::SetEditable(bool editable
)
1118 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1119 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1120 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1123 long wxMacMLTEControl::GetLastPosition() const
1125 wxTextPos actualsize
= 0 ;
1129 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1133 actualsize
= GetHandleSize( theText
)/sizeof(UniChar
);
1134 DisposeHandle( theText
) ;
1137 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1142 actualsize
= GetHandleSize( theText
) ;
1143 DisposeHandle( theText
) ;
1154 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1156 wxString value
= str
;
1157 wxMacConvertNewlines10To13( &value
) ;
1159 wxMacEditHelper
help( m_txn
) ;
1161 wxMacWindowClipper
c( GetWXPeer() ) ;
1164 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
) ;
1166 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1169 void wxMacMLTEControl::Remove( long from
, long to
)
1172 wxMacWindowClipper
c( GetWXPeer() ) ;
1174 wxMacEditHelper
help( m_txn
) ;
1175 TXNSetSelection( m_txn
, from
, to
) ;
1179 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1182 TXNGetSelection( m_txn
, &f
, &t
) ;
1187 void wxMacMLTEControl::SetSelection( long from
, long to
)
1190 wxMacWindowClipper
c( GetWXPeer() ) ;
1193 // change the selection
1194 if ((from
== -1) && (to
== -1))
1195 TXNSelectAll( m_txn
);
1197 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
);
1199 TXNShowSelection( m_txn
, kTXNShowStart
);
1202 void wxMacMLTEControl::WriteText( const wxString
& str
)
1204 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
1205 if ( !wxIsMainThread() )
1207 #if wxOSX_USE_CARBON
1208 // unfortunately CW 8 is not able to correctly deduce the template types,
1209 // so we have to instantiate explicitly
1210 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( (wxTextCtrl
*) GetWXPeer() , &wxTextCtrl::WriteText
, str
) ;
1216 wxMacConvertNewlines10To13( &st
) ;
1218 long start
, end
, dummy
;
1220 GetSelection( &start
, &dummy
) ;
1222 wxMacWindowClipper
c( GetWXPeer() ) ;
1226 wxMacEditHelper
helper( m_txn
) ;
1227 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1230 GetSelection( &dummy
, &end
) ;
1232 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1235 void wxMacMLTEControl::Clear()
1238 wxMacWindowClipper
c( GetWXPeer() ) ;
1240 wxMacEditHelper
st( m_txn
) ;
1241 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1245 bool wxMacMLTEControl::CanUndo() const
1247 return TXNCanUndo( m_txn
, NULL
) ;
1250 void wxMacMLTEControl::Undo()
1255 bool wxMacMLTEControl::CanRedo() const
1257 return TXNCanRedo( m_txn
, NULL
) ;
1260 void wxMacMLTEControl::Redo()
1265 int wxMacMLTEControl::GetNumberOfLines() const
1267 ItemCount lines
= 0 ;
1268 TXNGetLineCount( m_txn
, &lines
) ;
1273 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1278 // TODO: find a better implementation : while we can get the
1279 // line metrics of a certain line, we don't get its starting
1280 // position, so it would probably be rather a binary search
1281 // for the start position
1282 long xpos
= 0, ypos
= 0 ;
1283 int lastHeight
= 0 ;
1286 lastpos
= GetLastPosition() ;
1287 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1289 if ( y
== ypos
&& x
== xpos
)
1292 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
1294 if ( curpt
.v
> lastHeight
)
1300 lastHeight
= curpt
.v
;
1309 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
1319 lastpos
= GetLastPosition() ;
1320 if ( pos
<= lastpos
)
1322 // TODO: find a better implementation - while we can get the
1323 // line metrics of a certain line, we don't get its starting
1324 // position, so it would probably be rather a binary search
1325 // for the start position
1326 long xpos
= 0, ypos
= 0 ;
1327 int lastHeight
= 0 ;
1330 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1332 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
1334 if ( curpt
.v
> lastHeight
)
1340 lastHeight
= curpt
.v
;
1355 void wxMacMLTEControl::ShowPosition( long pos
)
1357 Point current
, desired
;
1358 TXNOffset selstart
, selend
;
1360 TXNGetSelection( m_txn
, &selstart
, &selend
);
1361 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1362 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1364 // TODO: use HIPoints for 10.3 and above
1366 OSErr theErr
= noErr
;
1367 long dv
= desired
.v
- current
.v
;
1368 long dh
= desired
.h
- current
.h
;
1369 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
1370 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1372 // there will be an error returned for classic MLTE implementation when the control is
1373 // invisible, but HITextView works correctly, so we don't assert that one
1374 // wxASSERT_MSG( theErr == noErr, wxT("TXNScroll returned an error!") );
1377 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1380 #if SIZEOF_WCHAR_T == 2
1381 size_t len
= st
.length() ;
1382 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
1384 wxMBConvUTF16 converter
;
1385 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
1386 wxASSERT_MSG( byteBufferLen
!= wxCONV_FAILED
,
1387 wxT("Conversion to UTF-16 unexpectedly failed") );
1388 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
+ 2 ) ; // 2 for NUL in UTF-16
1389 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
+ 2 ) ;
1390 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
1394 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
1395 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
1399 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1403 if ( lineNo
< GetNumberOfLines() )
1406 Fixed lineWidth
, lineHeight
, currentHeight
;
1409 // get the first possible position in the control
1410 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1412 // Iterate through the lines until we reach the one we want,
1413 // adding to our current y pixel point position
1416 while (ypos
< lineNo
)
1418 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1419 currentHeight
+= lineHeight
;
1422 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1423 TXNOffset theOffset
;
1424 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1426 wxString content
= GetStringValue() ;
1427 Point currentPoint
= thePoint
;
1428 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1430 line
+= content
[theOffset
];
1431 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1438 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1442 if ( lineNo
< GetNumberOfLines() )
1445 Fixed lineWidth
, lineHeight
, currentHeight
;
1448 // get the first possible position in the control
1449 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1451 // Iterate through the lines until we reach the one we want,
1452 // adding to our current y pixel point position
1455 while (ypos
< lineNo
)
1457 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1458 currentHeight
+= lineHeight
;
1461 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1462 TXNOffset theOffset
;
1463 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1465 wxString content
= GetStringValue() ;
1466 Point currentPoint
= thePoint
;
1467 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1470 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1477 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
1479 // ----------------------------------------------------------------------------
1480 // MLTE control implementation (classic part)
1481 // ----------------------------------------------------------------------------
1483 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
1484 // has to live on. We have different problems coming from outdated implementations on the
1485 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
1486 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
1487 // no way out, therefore we are using our own implementation and our own scrollbars ....
1489 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
1490 ControlActionUPP gTXNScrollActionProc
= NULL
;
1492 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
1493 SInt32 iValue
, SInt32 iMaximumValue
,
1494 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
1496 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
1497 SInt32 value
= wxMax( iValue
, 0 ) ;
1498 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
1500 if ( iScrollBarOrientation
== kTXNHorizontal
)
1502 if ( mlte
->m_sbHorizontal
)
1504 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
1505 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
1506 mlte
->m_lastHorizontalValue
= value
;
1509 else if ( iScrollBarOrientation
== kTXNVertical
)
1511 if ( mlte
->m_sbVertical
)
1513 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
1514 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
1515 mlte
->m_lastVerticalValue
= value
;
1520 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
1522 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
1526 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
1530 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
1532 SInt32 minimum
= 0 ;
1533 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
1534 SInt32 value
= GetControl32BitValue( controlRef
) ;
1539 case kControlDownButtonPart
:
1543 case kControlUpButtonPart
:
1547 case kControlPageDownPart
:
1548 delta
= GetControlViewSize( controlRef
) ;
1551 case kControlPageUpPart
:
1552 delta
= -GetControlViewSize( controlRef
) ;
1555 case kControlIndicatorPart
:
1556 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
1565 SInt32 newValue
= value
;
1567 if ( partCode
!= kControlIndicatorPart
)
1569 if ( value
+ delta
< minimum
)
1570 delta
= minimum
- value
;
1571 if ( value
+ delta
> maximum
)
1572 delta
= maximum
- value
;
1574 SetControl32BitValue( controlRef
, value
+ delta
) ;
1575 newValue
= value
+ delta
;
1578 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
1579 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
1582 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
1583 &verticalDelta
, &horizontalDelta
);
1584 verify_noerr( err
);
1587 mlte
->m_lastHorizontalValue
= newValue
;
1589 mlte
->m_lastVerticalValue
= newValue
;
1593 // make correct activations
1594 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
1596 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
1598 wxMacWindowClipper
clipper( textctrl
) ;
1599 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
1601 ControlRef controlFocus
= 0 ;
1602 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
1603 if ( controlFocus
== m_controlRef
)
1604 TXNFocus( m_txn
, setActive
);
1607 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
1609 TXNFocus( m_txn
, setFocus
);
1612 // guards against inappropriate redraw (hidden objects drawing onto window)
1614 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
1616 ControlRef controlFocus
= 0 ;
1617 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
1619 if ( !vis
&& (controlFocus
== m_controlRef
) )
1620 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
1622 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
1623 TXNControlData iControlData
[1] = { { (UInt32
)false } };
1625 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
1627 if ( iControlData
[0].uValue
!= vis
)
1629 iControlData
[0].uValue
= vis
;
1630 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
1633 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
1634 // if we run into further problems we might set the FrameBounds to an empty rect here
1637 // make sure that the TXNObject is at the right position
1639 void wxMacMLTEClassicControl::MacUpdatePosition()
1641 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1642 if ( textctrl
== NULL
)
1646 GetRectInWindowCoords( &bounds
);
1648 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
1649 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
1652 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
1653 OffsetRect( &visBounds
, x
, y
) ;
1655 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
1657 m_txnControlBounds
= bounds
;
1658 m_txnVisBounds
= visBounds
;
1659 wxMacWindowClipper
cl( textctrl
) ;
1661 if ( m_sbHorizontal
|| m_sbVertical
)
1663 int w
= bounds
.right
- bounds
.left
;
1664 int h
= bounds
.bottom
- bounds
.top
;
1666 if ( m_sbHorizontal
)
1670 sbBounds
.left
= -1 ;
1671 sbBounds
.top
= h
- 14 ;
1672 sbBounds
.right
= w
+ 1 ;
1673 sbBounds
.bottom
= h
+ 1 ;
1675 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
1676 SetControlViewSize( m_sbHorizontal
, w
) ;
1683 sbBounds
.left
= w
- 14 ;
1685 sbBounds
.right
= w
+ 1 ;
1686 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
1688 SetControlBounds( m_sbVertical
, &sbBounds
) ;
1689 SetControlViewSize( m_sbVertical
, h
) ;
1694 TXNLongRect olddestRect
;
1695 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
1697 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
1698 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
1699 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
1700 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
1701 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
1702 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
1704 if ( olddestRect
.right
>= 10000 )
1705 destRect
.right
= destRect
.left
+ 32000 ;
1707 if ( olddestRect
.bottom
>= 0x20000000 )
1708 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
1710 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
1711 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
1716 m_txnControlBounds
.top
,
1717 m_txnControlBounds
.left
,
1718 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
1719 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
1723 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
1724 // movement, therefore we have to force it
1726 // this problem has been reported in OSX as well, so we use this here once again
1728 TXNLongRect textRect
;
1729 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
1730 if ( textRect
.left
< m_txnControlBounds
.left
)
1731 TXNShowSelection( m_txn
, kTXNShowStart
) ;
1735 void wxMacMLTEClassicControl::Move(int x
, int y
, int width
, int height
)
1737 wxMacControl::Move(x
,y
,width
,height
) ;
1738 MacUpdatePosition() ;
1741 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16
WXUNUSED(thePart
))
1743 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1744 if ( textctrl
== NULL
)
1747 if ( textctrl
->IsShownOnScreen() )
1749 wxMacWindowClipper
clipper( textctrl
) ;
1750 TXNDraw( m_txn
, NULL
) ;
1754 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1756 Point where
= { y
, x
} ;
1757 ControlPartCode result
= kControlNoPart
;
1759 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
1760 if ( (textctrl
!= NULL
) && textctrl
->IsShownOnScreen() )
1762 if (PtInRect( where
, &m_txnControlBounds
))
1764 result
= kControlEditTextPart
;
1768 // sometimes we get the coords also in control local coordinates, therefore test again
1770 textctrl
->MacClientToRootWindow( &x
, &y
) ;
1774 if (PtInRect( where
, &m_txnControlBounds
))
1775 result
= kControlEditTextPart
;
1782 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* WXUNUSED(actionProc
) )
1784 ControlPartCode result
= kControlNoPart
;
1786 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
1787 if ( (textctrl
!= NULL
) && textctrl
->IsShownOnScreen() )
1789 Point startPt
= { y
, x
} ;
1791 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
1793 textctrl
->MacClientToRootWindow( &x
, &y
) ;
1797 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
1799 case kControlEditTextPart
:
1801 wxMacWindowClipper
clipper( textctrl
) ;
1804 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
1805 TXNClick( m_txn
, &rec
);
1817 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
1819 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1820 if ( textctrl
== NULL
)
1823 if (textctrl
->IsShownOnScreen())
1825 if (IsControlActive(m_controlRef
))
1829 wxMacWindowClipper
clipper( textctrl
) ;
1834 if (PtInRect(mousep
, &m_txnControlBounds
))
1836 RgnHandle theRgn
= NewRgn();
1837 RectRgn(theRgn
, &m_txnControlBounds
);
1838 TXNAdjustCursor(m_txn
, theRgn
);
1845 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1847 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1848 if ( textctrl
== NULL
)
1849 return kControlNoPart
;
1851 wxMacWindowClipper
clipper( textctrl
) ;
1854 memset( &ev
, 0 , sizeof( ev
) ) ;
1856 ev
.modifiers
= modifiers
;
1857 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
1858 TXNKeyDown( m_txn
, &ev
);
1860 return kControlEntireControl
;
1863 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
1865 MacActivatePaneText( activating
);
1868 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
1870 ControlPartCode focusResult
= kControlFocusNoPart
;
1872 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
1873 if ( textctrl
== NULL
)
1876 wxMacWindowClipper
clipper( textctrl
) ;
1878 ControlRef controlFocus
= NULL
;
1879 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
1880 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
1884 case kControlFocusPrevPart
:
1885 case kControlFocusNextPart
:
1886 MacFocusPaneText( !wasFocused
);
1887 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
1890 case kControlFocusNoPart
:
1892 MacFocusPaneText( false );
1893 focusResult
= kControlFocusNoPart
;
1900 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *WXUNUSED(info
) )
1904 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
1905 const wxString
& str
,
1907 const wxSize
& size
, long style
)
1908 : wxMacMLTEControl( wxPeer
)
1910 m_font
= wxPeer
->GetFont() ;
1911 m_windowStyle
= style
;
1912 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1915 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
1916 | kControlWantsActivate
| kControlHandlesTracking
1917 // | kControlHasSpecialBackground
1918 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
1920 OSStatus err
= ::CreateUserPaneControl(
1921 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
1922 &bounds
, featureSet
, &m_controlRef
);
1923 verify_noerr( err
);
1924 SetControlReference( m_controlRef
, (URefCon
) wxPeer
);
1928 AdjustCreationAttributes( *wxWHITE
, true ) ;
1930 MacSetObjectVisibility( wxPeer
->IsShownOnScreen() ) ;
1934 wxMacConvertNewlines10To13( &st
) ;
1935 wxMacWindowClipper
clipper( GetWXPeer() ) ;
1936 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1937 TXNSetSelection( m_txn
, 0, 0 ) ;
1941 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
1943 TXNDeleteObject( m_txn
);
1947 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
1949 MacSetObjectVisibility( shown
) ;
1950 wxMacControl::VisibilityChanged( shown
) ;
1953 void wxMacMLTEClassicControl::SuperChangedPosition()
1955 MacUpdatePosition() ;
1956 wxMacControl::SuperChangedPosition() ;
1959 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
1960 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
1961 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
1962 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
1963 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
1964 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
1965 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
1967 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
1969 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
1970 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1972 win
->MacControlUserPaneDrawProc( part
) ;
1975 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
1977 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
1978 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1980 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
1982 return kControlNoPart
;
1985 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
1987 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
1988 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
1990 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
1992 return kControlNoPart
;
1995 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
1997 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
1998 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2000 win
->MacControlUserPaneIdleProc() ;
2003 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2005 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
2006 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2008 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2010 return kControlNoPart
;
2013 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2015 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
)control
) , wxTextCtrl
) ;
2016 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2018 win
->MacControlUserPaneActivateProc( activating
) ;
2021 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2023 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
2024 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2026 return win
->MacControlUserPaneFocusProc( action
) ;
2028 return kControlNoPart
;
2032 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2034 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget(control
) , wxTextCtrl
) ;
2035 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2037 win
->MacControlUserPaneBackgroundProc(info
) ;
2041 // TXNRegisterScrollInfoProc
2043 OSStatus
wxMacMLTEClassicControl::DoCreate()
2046 OSStatus err
= noErr
;
2048 // set up our globals
2049 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2050 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2051 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2052 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2053 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2054 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2055 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2057 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2058 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2060 // set the initial settings for our private data
2062 m_txnWindow
= GetControlOwner(m_controlRef
);
2063 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2065 // set up the user pane procedures
2066 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2067 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2068 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2069 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2070 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2071 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2072 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2074 // calculate the rectangles used by the control
2075 GetRectInWindowCoords( &bounds
);
2077 m_txnControlBounds
= bounds
;
2078 m_txnVisBounds
= bounds
;
2083 GetGWorld( &origPort
, &origDev
) ;
2084 SetPort( m_txnPort
);
2086 // create the new edit field
2087 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2089 // the scrollbars are not correctly embedded but are inserted at the root:
2090 // this gives us problems as we have erratic redraws even over the structure area
2092 m_sbHorizontal
= 0 ;
2094 m_lastHorizontalValue
= 0 ;
2095 m_lastVerticalValue
= 0 ;
2097 Rect sb
= { 0 , 0 , 0 , 0 } ;
2098 if ( frameOptions
& kTXNWantVScrollBarMask
)
2100 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2101 SetControlReference( m_sbVertical
, (SInt32
)this );
2102 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2103 ShowControl( m_sbVertical
);
2104 EmbedControl( m_sbVertical
, m_controlRef
);
2105 frameOptions
&= ~kTXNWantVScrollBarMask
;
2108 if ( frameOptions
& kTXNWantHScrollBarMask
)
2110 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2111 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2112 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2113 ShowControl( m_sbHorizontal
);
2114 EmbedControl( m_sbHorizontal
, m_controlRef
);
2115 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2119 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2120 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2121 &m_txn
, &m_txnFrameID
, NULL
);
2122 verify_noerr( err
);
2125 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2126 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2127 int toptag
= WXSIZEOF( iControlTags
) ;
2128 TXNCarbonEventInfo cInfo
;
2129 cInfo
.useCarbonEvents
= false ;
2132 cInfo
.fDictionary
= NULL
;
2134 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2137 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2139 SetGWorld( origPort
, origDev
) ;
2145 // ----------------------------------------------------------------------------
2146 // MLTE control implementation (OSX part)
2147 // ----------------------------------------------------------------------------
2149 // tiger multi-line textcontrols with no CR in the entire content
2150 // don't scroll automatically, so we need a hack.
2151 // This attempt only works 'before' the key (ie before CallNextEventHandler)
2152 // is processed, thus the scrolling always occurs one character too late, but
2153 // better than nothing ...
2155 static const EventTypeSpec eventList
[] =
2157 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
2160 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2162 OSStatus result
= eventNotHandledErr
;
2163 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
2165 switch ( GetEventKind( event
) )
2167 case kEventTextInputUnicodeForKeyEvent
:
2169 TXNOffset from
, to
;
2170 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
2172 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
2173 result
= CallNextEventHandler(handler
,event
);
2183 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2185 OSStatus result
= eventNotHandledErr
;
2187 switch ( GetEventClass( event
) )
2189 case kEventClassTextInput
:
2190 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
2199 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
2201 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2202 const wxString
& str
,
2204 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2206 m_font
= wxPeer
->GetFont() ;
2207 m_windowStyle
= style
;
2208 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2210 wxMacConvertNewlines10To13( &st
) ;
2213 { bounds
.left
, bounds
.top
},
2214 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2216 m_scrollView
= NULL
;
2217 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2218 if (( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
)) || (frameOptions
&kTXNSingleLineOnlyMask
))
2220 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2223 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2224 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2229 HIScrollViewCreate(kHIScrollViewOptionsVertScroll
,&m_scrollView
);
2230 HIScrollViewSetScrollBarAutoHide(m_scrollView
,true);
2233 HIViewSetFrame( m_scrollView
, &hr
);
2234 HIViewSetVisible( m_scrollView
, true );
2238 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2239 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2240 HIViewSetVisible( m_textView
, true ) ;
2243 HIViewAddSubview( m_scrollView
, m_textView
) ;
2244 m_controlRef
= m_scrollView
;
2245 InstallEventHandler( (WXWidget
) m_textView
) ;
2249 HIViewSetFrame( m_textView
, &hr
);
2250 m_controlRef
= m_textView
;
2253 AdjustCreationAttributes( *wxWHITE
, true ) ;
2255 wxMacWindowClipper
c( GetWXPeer() ) ;
2257 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2259 TXNSetSelection( m_txn
, 0, 0 );
2260 TXNShowSelection( m_txn
, kTXNShowStart
);
2262 ::InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
2263 GetEventTypeCount(eventList
), eventList
, this,
2267 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
2271 bool wxMacMLTEHIViewControl::SetFocus()
2273 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, kControlFocusNextPart
) == noErr
;
2276 bool wxMacMLTEHIViewControl::HasFocus() const
2278 ControlRef control
;
2279 if ( GetUserFocusWindow() == NULL
)
2282 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2283 return control
== m_textView
;
2286 void wxMacMLTEHIViewControl::SetBackgroundColour(const wxColour
& col
)
2288 HITextViewSetBackgroundColor( m_textView
, col
.GetPixel() );
2291 #endif // wxUSE_TEXTCTRL