1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/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" 
  30     #include <sys/types.h> 
  36 #if wxUSE_STD_IOSTREAM 
  44 #include "wx/toplevel.h" 
  45 #include "wx/filefn.h" 
  46 #include "wx/sysopt.h" 
  48 #if defined(__BORLANDC__) && !defined(__WIN32__) 
  50 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__) 
  59 #include <MacTextEditor.h> 
  60 #include <ATSUnicode.h> 
  61 #include <TextCommon.h> 
  62 #include <TextEncodingConverter.h> 
  65 #include "wx/mac/uma.h" 
  68 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used 
  69 // if set to 0 then the unicode textctrl will be used 
  70 #ifndef wxMAC_AWAYS_USE_MLTE 
  71 #define wxMAC_AWAYS_USE_MLTE 1 
  77     kTXNVisibilityTag 
= 'visb' // set the visibility state of the object 
  86     virtual ~wxMacFunctor() {} 
  88     virtual void* operator()() = 0 ; 
  90     static void* CallBackProc( void *param 
) 
  92         wxMacFunctor
* f 
= (wxMacFunctor
*) param 
; 
  93         void *result 
= (*f
)() ; 
  98 template<typename classtype
, typename param1type
> 
 100 class wxMacObjectFunctor1 
: public wxMacFunctor
 
 102     typedef void (classtype::*function
)( param1type p1 
) ; 
 103     typedef void (classtype::*ref_function
)( const param1type
& p1 
) ; 
 105     wxMacObjectFunctor1( classtype 
*obj 
, function f 
, param1type p1 
) : 
 113     wxMacObjectFunctor1( classtype 
*obj 
, ref_function f 
, param1type p1 
) : 
 121     ~wxMacObjectFunctor1() {} 
 123     virtual void* operator()() 
 125         (m_object
->*m_function
)( m_param1 
) ; 
 130     classtype
* m_object 
; 
 131     param1type m_param1 
; 
 134         function m_function 
; 
 135         ref_function m_refFunction 
; 
 139 template<typename classtype
, typename param1type
> 
 140 void* wxMacMPRemoteCall( classtype 
*object 
, void (classtype::*function
)( param1type p1 
) , param1type p1 
) 
 142     wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ; 
 144         MPRemoteCall( wxMacFunctor::CallBackProc 
, ¶ms 
, kMPOwningProcessRemoteContext 
) ; 
 148 template<typename classtype
, typename param1type
> 
 149 void* wxMacMPRemoteCall( classtype 
*object 
, void (classtype::*function
)( const param1type
& p1 
) , param1type p1 
) 
 151     wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ; 
 153         MPRemoteCall( wxMacFunctor::CallBackProc 
, ¶ms 
, kMPOwningProcessRemoteContext 
) ; 
 157 template<typename classtype
, typename param1type
> 
 158 void* wxMacMPRemoteGUICall( classtype 
*object 
, void (classtype::*function
)( param1type p1 
) , param1type p1 
) 
 161     void *result 
= wxMacMPRemoteCall( object 
, function 
, p1 
) ; 
 166 template<typename classtype
, typename param1type
> 
 167 void* wxMacMPRemoteGUICall( classtype 
*object 
, void (classtype::*function
)( const param1type
& p1 
) , param1type p1 
) 
 170     void *result 
= wxMacMPRemoteCall( object 
, function 
, p1 
) ; 
 175 // common interface for all implementations 
 176 class wxMacTextControl 
: public wxMacControl
 
 179     wxMacTextControl( wxTextCtrl 
*peer 
) ; 
 180     ~wxMacTextControl() ; 
 182     virtual wxString 
GetStringValue() const = 0 ; 
 183     virtual void SetStringValue( const wxString 
&val 
) = 0 ; 
 184     virtual void SetSelection( long from
, long to 
) = 0 ; 
 185     virtual void GetSelection( long* from
, long* to 
) const = 0 ; 
 186     virtual void WriteText( const wxString
& str 
) = 0 ; 
 188     virtual void SetStyle( long start
, long end
, const wxTextAttr
& style 
) ; 
 189     virtual void Copy() ; 
 191     virtual void Paste() ; 
 192     virtual bool CanPaste() const ; 
 193     virtual void SetEditable( bool editable 
) ; 
 194     virtual wxTextPos 
GetLastPosition() const ; 
 195     virtual void Replace( long from
, long to
, const wxString 
&str 
) ; 
 196     virtual void Remove( long from
, long to 
) ; 
 199     virtual bool HasOwnContextMenu() const 
 202     virtual bool SetupCursor( const wxPoint
& pt 
) 
 205     virtual void Clear() ; 
 206     virtual bool CanUndo() const; 
 207     virtual void Undo() ; 
 208     virtual bool CanRedo() const; 
 209     virtual void Redo() ; 
 210     virtual int GetNumberOfLines() const ; 
 211     virtual long XYToPosition(long x
, long y
) const; 
 212     virtual bool PositionToXY(long pos
, long *x
, long *y
) const ; 
 213     virtual void ShowPosition(long WXUNUSED(pos
)) ; 
 214     virtual int GetLineLength(long lineNo
) const ; 
 215     virtual wxString 
GetLineText(long lineNo
) const ; 
 217 #ifndef __WXMAC_OSX__ 
 218     virtual void            MacControlUserPaneDrawProc(wxInt16 part
) = 0 ; 
 219     virtual wxInt16         
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ; 
 220     virtual wxInt16         
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ; 
 221     virtual void            MacControlUserPaneIdleProc() = 0 ; 
 222     virtual wxInt16         
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ; 
 223     virtual void            MacControlUserPaneActivateProc(bool activating
) = 0 ; 
 224     virtual wxInt16         
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ; 
 225     virtual void            MacControlUserPaneBackgroundProc(void* info
) = 0 ; 
 229 // common parts for implementations based on MLTE 
 231 class wxMacMLTEControl 
: public wxMacTextControl
 
 234     wxMacMLTEControl( wxTextCtrl 
*peer 
) ; 
 236     virtual wxString 
GetStringValue() const ; 
 237     virtual void SetStringValue( const wxString 
&str 
) ; 
 239     static TXNFrameOptions 
FrameOptionsFromWXStyle( long wxStyle 
) ; 
 241     void AdjustCreationAttributes( const wxColour
& background
, bool visible 
) ; 
 243     virtual void SetFont( const wxFont 
& font
, const wxColour
& foreground
, long windowStyle 
) ; 
 244     virtual void SetBackground( const wxBrush 
&brush 
) ; 
 245     virtual void SetStyle( long start
, long end
, const wxTextAttr
& style 
) ; 
 246     virtual void Copy() ; 
 248     virtual void Paste() ; 
 249     virtual bool CanPaste() const ; 
 250     virtual void SetEditable( bool editable 
) ; 
 251     virtual wxTextPos 
GetLastPosition() const ; 
 252     virtual void Replace( long from
, long to
, const wxString 
&str 
) ; 
 253     virtual void Remove( long from
, long to 
) ; 
 254     virtual void GetSelection( long* from
, long* to 
) const ; 
 255     virtual void SetSelection( long from
, long to 
) ; 
 257     virtual void WriteText( const wxString
& str 
) ; 
 259     virtual bool HasOwnContextMenu() const 
 261 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 
 262         if ( UMAGetSystemVersion() >= 0x1040 ) 
 264             TXNCommandEventSupportOptions options 
; 
 265             TXNGetCommandEventSupport( m_txn 
, & options 
) ; 
 266             return options 
& kTXNSupportEditCommandProcessing 
; 
 273     virtual void Clear() ; 
 275     virtual bool CanUndo() const ; 
 276     virtual void Undo() ; 
 277     virtual bool CanRedo()  const; 
 278     virtual void Redo() ; 
 279     virtual int GetNumberOfLines() const ; 
 280     virtual long XYToPosition(long x
, long y
) const ; 
 281     virtual bool PositionToXY(long pos
, long *x
, long *y
) const ; 
 282     virtual void ShowPosition( long pos 
) ; 
 283     virtual int GetLineLength(long lineNo
) const ; 
 284     virtual wxString 
GetLineText(long lineNo
) const ; 
 286     void SetTXNData( const wxString
& st 
, TXNOffset start 
, TXNOffset end 
) ; 
 287     TXNObject 
GetTXNObject() { return m_txn 
; } 
 290     void TXNSetAttribute( const wxTextAttr
& style 
, long from 
, long to 
) ; 
 295 #if TARGET_API_MAC_OSX 
 297 // implementation available under OSX 
 299 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 
 301 class wxMacMLTEHIViewControl 
: public wxMacMLTEControl
 
 304     wxMacMLTEHIViewControl( wxTextCtrl 
*wxPeer
, 
 307                              const wxSize
& size
, long style 
) ; 
 308     ~wxMacMLTEHIViewControl() ; 
 310     virtual OSStatus 
SetFocus( ControlFocusPart focusPart 
) ; 
 311     virtual bool HasFocus() const ; 
 312     virtual void SetBackground( const wxBrush 
&brush
) ; 
 315     HIViewRef m_scrollView 
; 
 316     HIViewRef m_textView 
; 
 317     EventHandlerRef m_textEventHandlerRef 
; 
 322 class wxMacUnicodeTextControl 
: public wxMacTextControl
 
 325     wxMacUnicodeTextControl( wxTextCtrl 
*wxPeer
, 
 328                              const wxSize
& size
, long style 
) ; 
 329     ~wxMacUnicodeTextControl(); 
 331     virtual void VisibilityChanged(bool shown
); 
 332     virtual wxString 
GetStringValue() const ; 
 333     virtual void SetStringValue( const wxString 
&str
) ; 
 336     virtual void Paste(); 
 337     virtual bool CanPaste() const; 
 338     virtual void SetEditable(bool editable
) ; 
 339     virtual void GetSelection( long* from
, long* to
) const ; 
 340     virtual void SetSelection( long from 
, long to 
) ; 
 341     virtual void WriteText(const wxString
& str
) ; 
 344     // contains the tag for the content (is different for password and non-password controls) 
 347     // as the selection tag only works correctly when the control has the focus we have to mirror the 
 349     EventHandlerRef m_focusHandlerRef 
; 
 351     ControlEditTextSelectionRec m_selection 
; 
 356 // 'classic' MLTE implementation 
 358 class wxMacMLTEClassicControl 
: public wxMacMLTEControl
 
 361     wxMacMLTEClassicControl( wxTextCtrl 
*wxPeer
, 
 364                              const wxSize
& size
, long style 
) ; 
 365     ~wxMacMLTEClassicControl() ; 
 367     virtual void VisibilityChanged(bool shown
) ; 
 368     virtual void SuperChangedPosition() ; 
 370     virtual void            MacControlUserPaneDrawProc(wxInt16 part
) ; 
 371     virtual wxInt16         
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ; 
 372     virtual wxInt16         
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ; 
 373     virtual void            MacControlUserPaneIdleProc() ; 
 374     virtual wxInt16         
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ; 
 375     virtual void            MacControlUserPaneActivateProc(bool activating
) ; 
 376     virtual wxInt16         
MacControlUserPaneFocusProc(wxInt16 action
) ; 
 377     virtual void            MacControlUserPaneBackgroundProc(void* info
) ; 
 379     virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) ) 
 381         MacControlUserPaneIdleProc(); 
 385     virtual void            SetRect( Rect 
*r 
) ; 
 390     void                    MacUpdatePosition() ; 
 391     void                    MacActivatePaneText(bool setActive
) ; 
 392     void                    MacFocusPaneText(bool setFocus
) ; 
 393     void                    MacSetObjectVisibility(bool vis
) ; 
 396     TXNFrameID              m_txnFrameID 
; 
 398     WindowRef               m_txnWindow 
; 
 399     // bounds of the control as we last did set the txn frames 
 400     Rect                    m_txnControlBounds 
; 
 401     Rect                    m_txnVisBounds 
; 
 404     static pascal void TXNScrollActionProc( ControlRef controlRef 
, ControlPartCode partCode 
) ; 
 405     static pascal void TXNScrollInfoProc( 
 406         SInt32 iValue
, SInt32 iMaximumValue
, 
 407         TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon 
) ; 
 409     ControlRef              m_sbHorizontal 
; 
 410     SInt32                  m_lastHorizontalValue 
; 
 411     ControlRef              m_sbVertical 
; 
 412     SInt32                  m_lastVerticalValue 
; 
 417 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
) 
 419 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
) 
 420     EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground 
) 
 421     EVT_DROP_FILES(wxTextCtrl::OnDropFiles
) 
 422     EVT_CHAR(wxTextCtrl::OnChar
) 
 423     EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
) 
 424     EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
) 
 425     EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
) 
 426     EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
) 
 427     EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
) 
 428     EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
) 
 429     EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
) 
 431     EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
) 
 433     EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
) 
 434     EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
) 
 435     EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
) 
 436     EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
) 
 437     EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
) 
 438     EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
) 
 439     EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
) 
 443 void wxTextCtrl::Init() 
 449     m_privateContextMenu 
= NULL
; 
 450     m_triggerOnSetValue 
= true ; 
 453 wxTextCtrl::~wxTextCtrl() 
 455     delete m_privateContextMenu
; 
 458 bool wxTextCtrl::Create( wxWindow 
*parent
, 
 464     const wxValidator
& validator
, 
 465     const wxString
& name 
) 
 467     m_macIsUserPane 
= false ; 
 470     if ( ! (style 
& wxNO_BORDER
) ) 
 471         style 
= (style 
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER 
; 
 473     if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style 
& ~(wxHSCROLL 
| wxVSCROLL
), validator
, name 
) ) 
 476     if ( m_windowStyle 
& wxTE_MULTILINE 
) 
 479             !(m_windowStyle 
& wxTE_PROCESS_ENTER
), 
 480             wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") ); 
 482         m_windowStyle 
|= wxTE_PROCESS_ENTER
; 
 483         style 
|= wxTE_PROCESS_ENTER 
; 
 486     bool forceMLTE 
= false ; 
 488 #if wxUSE_SYSTEM_OPTIONS 
 489     if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE 
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE 
) == 1)) 
 496 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 
 497     if ( UMAGetSystemVersion() >= 0x1030 && !forceMLTE 
) 
 499         if ( m_windowStyle 
& wxTE_MULTILINE 
) 
 500             m_peer 
= new wxMacMLTEHIViewControl( this , str 
, pos 
, size 
, style 
) ; 
 506         if ( !(m_windowStyle 
& wxTE_MULTILINE
) && !forceMLTE 
) 
 507             m_peer 
= new wxMacUnicodeTextControl( this , str 
, pos 
, size 
, style 
) ; 
 512         m_peer 
= new wxMacMLTEClassicControl( this , str 
, pos 
, size 
, style 
) ; 
 514     MacPostControlCreate(pos
, size
) ; 
 516     // only now the embedding is correct and we can do a positioning update 
 518     MacSuperChangedPosition() ; 
 520     if ( m_windowStyle 
& wxTE_READONLY
) 
 521         SetEditable( false ) ; 
 523     SetCursor( wxCursor( wxCURSOR_IBEAM 
) ) ; 
 528 void wxTextCtrl::MacSuperChangedPosition() 
 530     wxWindow::MacSuperChangedPosition() ; 
 531     GetPeer()->SuperChangedPosition() ; 
 534 void wxTextCtrl::MacVisibilityChanged() 
 536     GetPeer()->VisibilityChanged( MacIsReallyShown() ) ; 
 539 void wxTextCtrl::MacEnabledStateChanged() 
 543 wxString 
wxTextCtrl::GetValue() const 
 545     return GetPeer()->GetStringValue() ; 
 548 void wxTextCtrl::GetSelection(long* from
, long* to
) const 
 550     GetPeer()->GetSelection( from 
, to 
) ; 
 553 void wxTextCtrl::SetValue(const wxString
& str
) 
 556     if ( GetValue() == str 
) 
 559     GetPeer()->SetStringValue( str 
) ; 
 561     if ( m_triggerOnSetValue 
) 
 563         wxCommandEvent 
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId 
); 
 564         event
.SetString( GetValue() ); 
 565         event
.SetEventObject( this ); 
 566         GetEventHandler()->ProcessEvent( event 
); 
 570 void wxTextCtrl::SetMaxLength(unsigned long len
) 
 575 bool wxTextCtrl::SetFont( const wxFont
& font 
) 
 577     if ( !wxTextCtrlBase::SetFont( font 
) ) 
 580     GetPeer()->SetFont( font 
, GetForegroundColour() , GetWindowStyle() ) ; 
 585 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
) 
 587     GetPeer()->SetStyle( start 
, end 
, style 
) ; 
 592 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
) 
 594     wxTextCtrlBase::SetDefaultStyle( style 
) ; 
 595     SetStyle( kTXNUseCurrentSelection 
, kTXNUseCurrentSelection 
, GetDefaultStyle() ) ; 
 600 // Clipboard operations 
 602 void wxTextCtrl::Copy() 
 608 void wxTextCtrl::Cut() 
 614         wxCommandEvent 
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId 
); 
 615         event
.SetEventObject( this ); 
 616         GetEventHandler()->ProcessEvent( event 
); 
 620 void wxTextCtrl::Paste() 
 626         // TODO: eventually we should add setting the default style again 
 628         wxCommandEvent 
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId 
); 
 629         event
.SetEventObject( this ); 
 630         GetEventHandler()->ProcessEvent( event 
); 
 634 bool wxTextCtrl::CanCopy() const 
 636     // Can copy if there's a selection 
 638     GetSelection( &from
, &to 
); 
 643 bool wxTextCtrl::CanCut() const 
 648     // Can cut if there's a selection 
 650     GetSelection( &from
, &to 
); 
 655 bool wxTextCtrl::CanPaste() const 
 660     return GetPeer()->CanPaste() ; 
 663 void wxTextCtrl::SetEditable(bool editable
) 
 665     if ( editable 
!= m_editable 
) 
 667         m_editable 
= editable 
; 
 668         GetPeer()->SetEditable( editable 
) ; 
 672 void wxTextCtrl::SetInsertionPoint(long pos
) 
 674     SetSelection( pos 
, pos 
) ; 
 677 void wxTextCtrl::SetInsertionPointEnd() 
 679     wxTextPos pos 
= GetLastPosition(); 
 680     SetInsertionPoint( pos 
); 
 683 long wxTextCtrl::GetInsertionPoint() const 
 686     GetSelection( &begin 
, &end 
) ; 
 691 wxTextPos 
wxTextCtrl::GetLastPosition() const 
 693     return GetPeer()->GetLastPosition() ; 
 696 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
) 
 698     GetPeer()->Replace( from 
, to 
, str 
) ; 
 701 void wxTextCtrl::Remove(long from
, long to
) 
 703     GetPeer()->Remove( from 
, to 
) ; 
 706 void wxTextCtrl::SetSelection(long from
, long to
) 
 708     GetPeer()->SetSelection( from 
, to 
) ; 
 711 bool wxTextCtrl::LoadFile(const wxString
& file
) 
 713     return wxTextCtrlBase::LoadFile( file 
); 
 716 void wxTextCtrl::WriteText(const wxString
& str
) 
 718     // TODO: this MPRemoting will be moved into a remoting peer proxy for any command 
 719     if ( !wxIsMainThread() ) 
 721         // unfortunately CW 8 is not able to correctly deduce the template types, 
 722         // so we have to instantiate explicitly 
 723         wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText 
, str 
) ; 
 728     GetPeer()->WriteText( str 
) ; 
 731 void wxTextCtrl::AppendText(const wxString
& text
) 
 733     SetInsertionPointEnd(); 
 737 void wxTextCtrl::Clear() 
 742 bool wxTextCtrl::IsModified() const 
 747 bool wxTextCtrl::IsEditable() const 
 749     return IsEnabled() && m_editable 
; 
 752 bool wxTextCtrl::AcceptsFocus() const 
 754     // we don't want focus if we can't be edited 
 755     return /*IsEditable() && */ wxControl::AcceptsFocus(); 
 758 wxSize 
wxTextCtrl::DoGetBestSize() const 
 762     // these are the numbers from the HIG: 
 763     // we reduce them by the borders first 
 766     switch ( m_windowVariant 
) 
 768         case wxWINDOW_VARIANT_NORMAL 
: 
 772         case wxWINDOW_VARIANT_SMALL 
: 
 776         case wxWINDOW_VARIANT_MINI 
: 
 785     // as the above numbers have some free space around the text 
 786     // we get 5 lines like this anyway 
 787     if ( m_windowStyle 
& wxTE_MULTILINE 
) 
 790     if ( !HasFlag(wxNO_BORDER
) ) 
 793     return wxSize(wText
, hText
); 
 796 // ---------------------------------------------------------------------------- 
 798 // ---------------------------------------------------------------------------- 
 800 void wxTextCtrl::Undo() 
 806 void wxTextCtrl::Redo() 
 812 bool wxTextCtrl::CanUndo() const 
 817     return GetPeer()->CanUndo() ; 
 820 bool wxTextCtrl::CanRedo() const 
 825     return GetPeer()->CanRedo() ; 
 828 void wxTextCtrl::MarkDirty() 
 833 void wxTextCtrl::DiscardEdits() 
 838 int wxTextCtrl::GetNumberOfLines() const 
 840     return GetPeer()->GetNumberOfLines() ; 
 843 long wxTextCtrl::XYToPosition(long x
, long y
) const 
 845     return GetPeer()->XYToPosition( x 
, y 
) ; 
 848 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const 
 850     return GetPeer()->PositionToXY( pos 
, x 
, y 
) ; 
 853 void wxTextCtrl::ShowPosition(long pos
) 
 855     return GetPeer()->ShowPosition(pos
) ; 
 858 int wxTextCtrl::GetLineLength(long lineNo
) const 
 860     return GetPeer()->GetLineLength(lineNo
) ; 
 863 wxString 
wxTextCtrl::GetLineText(long lineNo
) const 
 865     return GetPeer()->GetLineText(lineNo
) ; 
 868 void wxTextCtrl::Command(wxCommandEvent 
& event
) 
 870     SetValue(event
.GetString()); 
 871     ProcessCommand(event
); 
 874 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
) 
 876     // By default, load the first file into the text window. 
 877     if (event
.GetNumberOfFiles() > 0) 
 878         LoadFile( event
.GetFiles()[0] ); 
 881 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
) 
 883     // all erasing should be done by the real mac control implementation 
 884     // while this is true for MLTE under classic, the HITextView is somehow 
 885     // transparent but background erase is not working correctly, so intercept 
 886     // things while we can... 
 890 void wxTextCtrl::OnChar(wxKeyEvent
& event
) 
 892     int key 
= event
.GetKeyCode() ; 
 893     bool eat_key 
= false ; 
 895     if ( key 
== 'a' && event
.MetaDown() ) 
 902     if ( key 
== 'c' && event
.MetaDown() ) 
 910     if ( !IsEditable() && key 
!= WXK_LEFT 
&& key 
!= WXK_RIGHT 
&& key 
!= WXK_DOWN 
&& key 
!= WXK_UP 
&& key 
!= WXK_TAB 
&& 
 911         !( key 
== WXK_RETURN 
&& ( (m_windowStyle 
& wxTE_PROCESS_ENTER
) || (m_windowStyle 
& wxTE_MULTILINE
) ) ) 
 912 //        && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END 
 919     // Check if we have reached the max # of chars (if it is set), but still 
 920     // allow navigation and deletion 
 921     if ( !IsMultiLine() && m_maxLength 
&& GetValue().length() >= m_maxLength 
&& 
 922         key 
!= WXK_LEFT 
&& key 
!= WXK_RIGHT 
&& key 
!= WXK_TAB 
&& 
 923         key 
!= WXK_BACK 
&& !( key 
== WXK_RETURN 
&& (m_windowStyle 
& wxTE_PROCESS_ENTER
) ) 
 926         // eat it, we don't want to add more than allowed # of characters 
 928         // TODO: generate EVT_TEXT_MAXLEN() 
 932     // assume that any key not processed yet is going to modify the control 
 935     if ( key 
== 'v' && event
.MetaDown() ) 
 943     if ( key 
== 'x' && event
.MetaDown() ) 
 954             if (m_windowStyle 
& wxTE_PROCESS_ENTER
) 
 956                 wxCommandEvent 
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
); 
 957                 event
.SetEventObject( this ); 
 958                 event
.SetString( GetValue() ); 
 959                 if ( GetEventHandler()->ProcessEvent(event
) ) 
 963             if ( !(m_windowStyle 
& wxTE_MULTILINE
) ) 
 965                 wxWindow 
*parent 
= GetParent(); 
 966                 while ( parent 
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL 
) 
 968                     parent 
= parent
->GetParent() ; 
 971                 if ( parent 
&& parent
->GetDefaultItem() ) 
 973                     wxButton 
*def 
= wxDynamicCast(parent
->GetDefaultItem(), wxButton
); 
 974                     if ( def 
&& def
->IsEnabled() ) 
 976                         wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() ); 
 977                         event
.SetEventObject(def
); 
 984                 // this will make wxWidgets eat the ENTER key so that 
 985                 // we actually prevent line wrapping in a single line text control 
 991             if ( !(m_windowStyle 
& wxTE_PROCESS_TAB
)) 
 994                 if (!event
.ShiftDown()) 
 995                     flags 
|= wxNavigationKeyEvent::IsForward 
; 
 996                 if (event
.ControlDown()) 
 997                     flags 
|= wxNavigationKeyEvent::WinChange 
; 
1004                 // This is necessary (don't know why); 
1005                 // otherwise the tab will not be inserted. 
1006                 WriteText(wxT("\t")); 
1016         // perform keystroke handling 
1020     if ( ( key 
>= 0x20 && key 
< WXK_START 
) || 
1021          key 
== WXK_RETURN 
|| 
1022          key 
== WXK_DELETE 
|| 
1025         wxCommandEvent 
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
); 
1026         event1
.SetEventObject( this ); 
1027         wxPostEvent( GetEventHandler(), event1 
); 
1031 // ---------------------------------------------------------------------------- 
1032 // standard handlers for standard edit menu events 
1033 // ---------------------------------------------------------------------------- 
1035 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
)) 
1040 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
)) 
1045 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
)) 
1050 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
)) 
1055 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
)) 
1060 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
)) 
1064     GetSelection( &from
, &to 
); 
1065     if (from 
!= -1 && to 
!= -1) 
1069 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
)) 
1071     SetSelection(-1, -1); 
1074 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
) 
1076     event
.Enable( CanCut() ); 
1079 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
) 
1081     event
.Enable( CanCopy() ); 
1084 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
) 
1086     event
.Enable( CanPaste() ); 
1089 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
) 
1091     event
.Enable( CanUndo() ); 
1094 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
) 
1096     event
.Enable( CanRedo() ); 
1099 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
) 
1103     GetSelection( &from
, &to 
); 
1104     event
.Enable( from 
!= -1 && to 
!= -1 && from 
!= to 
&& IsEditable() ) ; 
1107 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
) 
1109     event
.Enable(GetLastPosition() > 0); 
1112 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment 
1114 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
) 
1116     if ( GetPeer()->HasOwnContextMenu() ) 
1122     if (m_privateContextMenu 
== NULL
) 
1124         m_privateContextMenu 
= new wxMenu
; 
1125         m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo")); 
1126         m_privateContextMenu
->Append(wxID_REDO
, _("&Redo")); 
1127         m_privateContextMenu
->AppendSeparator(); 
1128         m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t")); 
1129         m_privateContextMenu
->Append(wxID_COPY
, _("&Copy")); 
1130         m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste")); 
1131         m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete")); 
1132         m_privateContextMenu
->AppendSeparator(); 
1133         m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All")); 
1136     if (m_privateContextMenu 
!= NULL
) 
1137         PopupMenu(m_privateContextMenu
); 
1140 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt 
) 
1142     if ( !GetPeer()->SetupCursor( pt 
) ) 
1143         return wxWindow::MacSetupCursor( pt 
) ; 
1148 #if !TARGET_API_MAC_OSX 
1150 // user pane implementation 
1152 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
) 
1154     GetPeer()->MacControlUserPaneDrawProc( part 
) ; 
1157 wxInt16 
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) 
1159     return GetPeer()->MacControlUserPaneHitTestProc( x 
, y 
) ; 
1162 wxInt16 
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) 
1164     return GetPeer()->MacControlUserPaneTrackingProc( x 
, y 
, actionProc 
) ; 
1167 void wxTextCtrl::MacControlUserPaneIdleProc() 
1169     GetPeer()->MacControlUserPaneIdleProc( ) ; 
1172 wxInt16 
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) 
1174     return GetPeer()->MacControlUserPaneKeyDownProc( keyCode 
, charCode 
, modifiers 
) ; 
1177 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
) 
1179     GetPeer()->MacControlUserPaneActivateProc( activating 
) ; 
1182 wxInt16 
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
) 
1184     return GetPeer()->MacControlUserPaneFocusProc( action 
) ; 
1187 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
) 
1189     GetPeer()->MacControlUserPaneBackgroundProc( info 
) ; 
1194 // ---------------------------------------------------------------------------- 
1195 // implementation base class 
1196 // ---------------------------------------------------------------------------- 
1198 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) : 
1199     wxMacControl( peer 
) 
1203 wxMacTextControl::~wxMacTextControl() 
1207 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
) 
1211 void wxMacTextControl::Copy() 
1215 void wxMacTextControl::Cut() 
1219 void wxMacTextControl::Paste() 
1223 bool wxMacTextControl::CanPaste() const 
1228 void wxMacTextControl::SetEditable(bool editable
) 
1232 wxTextPos 
wxMacTextControl::GetLastPosition() const 
1234     return GetStringValue().length() ; 
1237 void wxMacTextControl::Replace( long from 
, long to 
, const wxString 
&val 
) 
1239     SetSelection( from 
, to 
) ; 
1243 void wxMacTextControl::Remove( long from 
, long to 
) 
1245     SetSelection( from 
, to 
) ; 
1246     WriteText( wxEmptyString
) ; 
1249 void wxMacTextControl::Clear() 
1251     SetStringValue( wxEmptyString 
) ; 
1254 bool wxMacTextControl::CanUndo() const 
1259 void wxMacTextControl::Undo() 
1263 bool wxMacTextControl::CanRedo()  const 
1268 void wxMacTextControl::Redo() 
1272 long wxMacTextControl::XYToPosition(long x
, long y
) const 
1277 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const 
1282 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) ) 
1286 int wxMacTextControl::GetNumberOfLines() const 
1288     ItemCount lines 
= 0 ; 
1289     wxString content 
= GetStringValue() ; 
1292     for (size_t i 
= 0; i 
< content
.length() ; i
++) 
1294         if (content
[i
] == '\r') 
1301 wxString 
wxMacTextControl::GetLineText(long lineNo
) const 
1303     // TODO: change this if possible to reflect real lines 
1304     wxString content 
= GetStringValue() ; 
1308     for (size_t i 
= 0; i 
< content
.length() ; i
++) 
1310         if (count 
== lineNo
) 
1312             // Add chars in line then 
1315             for (size_t j 
= i
; j 
< content
.length(); j
++) 
1317                 if (content
[j
] == '\n') 
1326         if (content
[i
] == '\n') 
1330     return wxEmptyString 
; 
1333 int wxMacTextControl::GetLineLength(long lineNo
) const 
1335     // TODO: change this if possible to reflect real lines 
1336     wxString content 
= GetStringValue() ; 
1340     for (size_t i 
= 0; i 
< content
.length() ; i
++) 
1342         if (count 
== lineNo
) 
1344             // Count chars in line then 
1346             for (size_t j 
= i
; j 
< content
.length(); j
++) 
1349                 if (content
[j
] == '\n') 
1356         if (content
[i
] == '\n') 
1363 // ---------------------------------------------------------------------------- 
1364 // standard unicode control implementation 
1365 // ---------------------------------------------------------------------------- 
1367 #if TARGET_API_MAC_OSX 
1369 // the current unicode textcontrol implementation has a bug : only if the control 
1370 // is currently having the focus, the selection can be retrieved by the corresponding 
1371 // data tag. So we have a mirroring using a member variable 
1372 // TODO : build event table using virtual member functions for wxMacControl 
1374 static const EventTypeSpec unicodeTextControlEventList
[] = 
1376     { kEventClassControl 
, kEventControlSetFocusPart 
} , 
1379 static pascal OSStatus 
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
1381     OSStatus result 
= eventNotHandledErr 
; 
1382     wxMacUnicodeTextControl
* focus 
= (wxMacUnicodeTextControl
*) data 
; 
1383     wxMacCarbonEvent 
cEvent( event 
) ; 
1385     switch ( GetEventKind( event 
) ) 
1387         case kEventControlSetFocusPart 
: 
1389             ControlPartCode controlPart 
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart 
, typeControlPartCode 
); 
1390             if ( controlPart 
== kControlFocusNoPart 
) 
1392                 // about to loose focus -> store selection to field 
1393                 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection 
); 
1395             result 
= CallNextEventHandler(handler
,event
) ; 
1396             if ( controlPart 
!= kControlFocusNoPart 
) 
1398                 // about to gain focus -> set selection from field 
1399                 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection 
); 
1410 static pascal OSStatus 
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
1412     OSStatus result 
= eventNotHandledErr 
; 
1414     switch ( GetEventClass( event 
) ) 
1416         case kEventClassControl 
: 
1417             result 
= wxMacUnicodeTextControlControlEventHandler( handler 
, event 
, data 
) ; 
1426 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler 
) 
1428 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl 
*wxPeer
, 
1429     const wxString
& str
, 
1431     const wxSize
& size
, long style 
) 
1432     : wxMacTextControl( wxPeer 
) 
1434     m_font 
= wxPeer
->GetFont() ; 
1435     m_windowStyle 
= style 
; 
1436     Rect bounds 
= wxMacGetBoundsForControl( wxPeer 
, pos 
, size 
) ; 
1438     wxMacConvertNewlines10To13( &st 
) ; 
1439     wxMacCFStringHolder 
cf(st 
, m_font
.GetEncoding()) ; 
1440     CFStringRef cfr 
= cf 
; 
1441     Boolean isPassword 
= ( m_windowStyle 
& wxTE_PASSWORD 
) != 0 ; 
1442     m_valueTag 
= isPassword 
? kControlEditTextPasswordCFStringTag 
: kControlEditTextCFStringTag 
; 
1444     OSStatus err 
= CreateEditUnicodeTextControl( 
1445         MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds 
, cfr 
, 
1446         isPassword 
, NULL 
, &m_controlRef 
) ; 
1447     verify_noerr( err 
); 
1449     if ( !(m_windowStyle 
& wxTE_MULTILINE
) ) 
1450         SetData
<Boolean
>( kControlEditTextPart 
, kControlEditTextSingleLineTag 
, true ) ; 
1452     InstallControlEventHandler( m_controlRef 
, GetwxMacUnicodeTextControlEventHandlerUPP(), 
1453                                 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this, 
1454                                 &m_focusHandlerRef
); 
1457 wxMacUnicodeTextControl::~wxMacUnicodeTextControl() 
1459     ::RemoveEventHandler( m_focusHandlerRef 
); 
1462 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
) 
1464     if ( !(m_windowStyle 
& wxTE_MULTILINE
) && shown 
) 
1466         // work around a refresh issue insofar as not always the entire content is shown, 
1467         // even if this would be possible 
1468         ControlEditTextSelectionRec sel 
; 
1469         CFStringRef value 
= NULL 
; 
1471         verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel 
) ); 
1472         verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value 
) ); 
1473         verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value 
) ); 
1474         verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel 
) ); 
1476         CFRelease( value 
) ; 
1480 wxString 
wxMacUnicodeTextControl::GetStringValue() const 
1483     CFStringRef value 
= GetData
<CFStringRef
>(0, m_valueTag
) ; 
1486         wxMacCFStringHolder 
cf(value
) ; 
1487         result 
= cf
.AsString() ; 
1491     wxMacConvertNewlines13To10( &result 
) ; 
1493     wxMacConvertNewlines10To13( &result 
) ; 
1499 void wxMacUnicodeTextControl::SetStringValue( const wxString 
&str 
) 
1502     wxMacConvertNewlines10To13( &st 
) ; 
1503     wxMacCFStringHolder 
cf( st 
, m_font
.GetEncoding() ) ; 
1504     verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag 
, cf 
) ) ; 
1507 void wxMacUnicodeTextControl::Copy() 
1509     SendHICommand( kHICommandCopy 
) ; 
1512 void wxMacUnicodeTextControl::Cut() 
1514     SendHICommand( kHICommandCut 
) ; 
1517 void wxMacUnicodeTextControl::Paste() 
1519     SendHICommand( kHICommandPaste 
) ; 
1522 bool wxMacUnicodeTextControl::CanPaste() const 
1527 void wxMacUnicodeTextControl::SetEditable(bool editable
) 
1529 #if 0 // leads to problem because text cannot be selected anymore 
1530     SetData
<Boolean
>( kControlEditTextPart 
, kControlEditTextLockedTag 
, (Boolean
) !editable 
) ; 
1534 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to 
) const 
1536     ControlEditTextSelectionRec sel 
; 
1538         verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel 
) ) ; 
1543         *from 
= sel
.selStart 
; 
1548 void wxMacUnicodeTextControl::SetSelection( long from 
, long to 
) 
1550     ControlEditTextSelectionRec sel 
; 
1552     int textLength 
= 0 ; 
1553     CFStringRef value 
= GetData
<CFStringRef
>(0, m_valueTag
) ; 
1556         wxMacCFStringHolder 
cf(value
) ; 
1557         textLength 
= cf
.AsString().Length() ; 
1560     if ((from 
== -1) && (to 
== -1)) 
1567         from 
= wxMin(textLength
,wxMax(from
,0)) ; 
1568         to 
= wxMax(0,wxMin(textLength
,to
)) ; 
1571     sel
.selStart 
= from 
; 
1574         SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel 
) ; 
1579 void wxMacUnicodeTextControl::WriteText( const wxString
& str 
) 
1582     wxMacConvertNewlines10To13( &st 
) ; 
1584 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 
1587         wxMacCFStringHolder 
cf(st 
, m_font
.GetEncoding() ) ; 
1588         CFStringRef value 
= cf 
; 
1589         SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value 
); 
1593         wxString val 
= GetStringValue() ; 
1595         GetSelection( &start 
, &end 
) ; 
1596         val
.Remove( start 
, end 
- start 
) ; 
1597         val
.insert( start 
, str 
) ; 
1598         SetStringValue( val 
) ; 
1599         SetSelection( start 
+ str
.length() , start 
+ str
.length() ) ; 
1605 // ---------------------------------------------------------------------------- 
1606 // MLTE control implementation (common part) 
1607 // ---------------------------------------------------------------------------- 
1609 // if MTLE is read only, no changes at all are allowed, not even from 
1610 // procedural API, in order to allow changes via API all the same we must undo 
1611 // the readonly status while we are executing, this class helps to do so 
1613 class wxMacEditHelper
 
1616     wxMacEditHelper( TXNObject txn 
) 
1618         TXNControlTag tag
[] = { kTXNIOPrivilegesTag 
} ; 
1620         TXNGetTXNObjectControls( m_txn 
, 1 , tag 
, m_data 
) ; 
1621         if ( m_data
[0].uValue 
== kTXNReadOnly 
) 
1623             TXNControlData data
[] = { { kTXNReadWrite 
} } ; 
1624             TXNSetTXNObjectControls( m_txn 
, false , 1 , tag 
, data 
) ; 
1630         TXNControlTag tag
[] = { kTXNIOPrivilegesTag 
} ; 
1631         if ( m_data
[0].uValue 
== kTXNReadOnly 
) 
1632             TXNSetTXNObjectControls( m_txn 
, false , 1 , tag 
, m_data 
) ; 
1637     TXNControlData m_data
[1] ; 
1640 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl 
*peer 
) 
1641     : wxMacTextControl( peer 
) 
1643     SetNeedsFocusRect( true ) ; 
1646 wxString 
wxMacMLTEControl::GetStringValue() const 
1650     Size actualSize 
= 0; 
1655         err 
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData 
); 
1664             actualSize 
= GetHandleSize( theText 
) / sizeof(UniChar
) ; 
1665             if ( actualSize 
> 0 ) 
1667                 wxChar 
*ptr 
= NULL 
; 
1669 #if SIZEOF_WCHAR_T == 2 
1670                 ptr 
= new wxChar
[actualSize 
+ 1] ; 
1671                 wxStrncpy( ptr 
, (wxChar
*)(*theText
) , actualSize 
) ; 
1673                 SetHandleSize( theText
, (actualSize 
+ 1) * sizeof(UniChar
) ) ; 
1675                 (((UniChar
*)*theText
)[actualSize
]) = 0 ; 
1676                 wxMBConvUTF16 converter 
; 
1677                 size_t noChars 
= converter
.MB2WC( NULL 
, (const char*)*theText 
, 0 ) ; 
1678                 wxASSERT_MSG( noChars 
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") ); 
1679                 ptr 
= new wxChar
[noChars 
+ 1] ; 
1681                 noChars 
= converter
.MB2WC( ptr 
, (const char*)*theText 
, noChars 
+ 1 ) ; 
1682                 wxASSERT_MSG( noChars 
!= wxCONV_FAILED
, _T("Conversion of string failed!") ); 
1684                 HUnlock( theText 
) ; 
1687                 ptr
[actualSize
] = 0 ; 
1688                 result 
= wxString( ptr 
) ; 
1692             DisposeHandle( theText 
) ; 
1696         err 
= TXNGetDataEncoded( m_txn 
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData 
); 
1705             actualSize 
= GetHandleSize( theText 
) ; 
1706             if ( actualSize 
> 0 ) 
1709                 result 
= wxString( *theText 
, wxConvLocal 
, actualSize 
) ; 
1710                 HUnlock( theText 
) ; 
1713             DisposeHandle( theText 
) ; 
1719     wxMacConvertNewlines13To10( &result 
) ; 
1721     wxMacConvertNewlines10To13( &result 
) ; 
1727 void wxMacMLTEControl::SetStringValue( const wxString 
&str 
) 
1730     wxMacConvertNewlines10To13( &st 
); 
1733         wxMacWindowClipper 
c( m_peer 
); 
1736             wxMacEditHelper 
help( m_txn 
); 
1737             SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset 
); 
1740         TXNSetSelection( m_txn
, 0, 0 ); 
1741         TXNShowSelection( m_txn
, kTXNShowStart 
); 
1745 TXNFrameOptions 
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle 
) 
1747     TXNFrameOptions frameOptions 
= kTXNDontDrawCaretWhenInactiveMask
; 
1749 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 
1750     frameOptions 
|= kTXNDoFontSubstitutionMask
; 
1753     if ( ! (wxStyle 
& wxTE_NOHIDESEL
) ) 
1754         frameOptions 
|= kTXNDontDrawSelectionWhenInactiveMask 
; 
1756     if ( wxStyle 
& (wxHSCROLL 
| wxTE_DONTWRAP
) ) 
1757         frameOptions 
|= kTXNWantHScrollBarMask 
; 
1759     if ( wxStyle 
& wxTE_MULTILINE 
) 
1761         frameOptions 
|= kTXNAlwaysWrapAtViewEdgeMask 
; 
1763         if ( !(wxStyle 
& wxTE_NO_VSCROLL
) ) 
1765             frameOptions 
|= kTXNWantVScrollBarMask 
; 
1767             // The following code causes drawing problems on 10.4. Perhaps it can be restored for 
1768             // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here 
1769             // anyways, as AFAIK users can't actually use it to resize the text ctrl. 
1770 //            if ( frameOptions & kTXNWantHScrollBarMask ) 
1771 //                frameOptions |= kTXNDrawGrowIconMask ; 
1776         frameOptions 
|= kTXNSingleLineOnlyMask 
; 
1779     return frameOptions 
; 
1782 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour 
&background
, bool visible 
) 
1784     TXNControlTag iControlTags
[] = 
1786             kTXNDoFontSubstitution
, 
1787             kTXNWordWrapStateTag 
, 
1789     TXNControlData iControlData
[] = 
1795     int toptag 
= WXSIZEOF( iControlTags 
) ; 
1797     if ( m_windowStyle 
& wxTE_MULTILINE 
) 
1799         iControlData
[1].uValue 
= 
1800             (m_windowStyle 
& wxTE_DONTWRAP
) 
1805     OSStatus err 
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData 
) ; 
1806     verify_noerr( err 
); 
1808     // setting the default font: 
1809     // under 10.2 this causes a visible caret, therefore we avoid it 
1811     if ( UMAGetSystemVersion() >= 0x1030 ) 
1817         GetThemeFont( kThemeSystemFont 
, GetApplicationScript() , fontName 
, &fontSize 
, &fontStyle 
) ; 
1819         TXNTypeAttributes typeAttr
[] = 
1821             { kTXNQDFontNameAttribute 
, kTXNQDFontNameAttributeSize 
, { (void*) fontName 
} } , 
1822             { kTXNQDFontSizeAttribute 
, kTXNFontSizeAttributeSize 
, { (void*) (fontSize 
<< 16) } } , 
1823             { kTXNQDFontStyleAttribute 
, kTXNQDFontStyleAttributeSize 
, { (void*) normal 
} } , 
1826         err 
= TXNSetTypeAttributes( 
1827             m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
), 
1828             typeAttr
, kTXNStartOffset
, kTXNEndOffset 
); 
1829         verify_noerr( err 
); 
1832     if ( m_windowStyle 
& wxTE_PASSWORD 
) 
1834         UniChar c 
= 0x00A5 ; 
1835         err 
= TXNEchoMode( m_txn 
, c 
, 0 , true ); 
1836         verify_noerr( err 
); 
1839     TXNBackground tback
; 
1840     tback
.bgType 
= kTXNBackgroundTypeRGB
; 
1841     tback
.bg
.color 
= MAC_WXCOLORREF( background
.GetPixel() ); 
1842     TXNSetBackground( m_txn 
, &tback 
); 
1844 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 
1845     if ( UMAGetSystemVersion() >= 0x1040 ) 
1847         TXNCommandEventSupportOptions options 
; 
1848         if ( TXNGetCommandEventSupport( m_txn
, &options 
) == noErr 
) 
1851                 kTXNSupportEditCommandProcessing
 
1852                 | kTXNSupportEditCommandUpdating
 
1853                 | kTXNSupportSpellCheckCommandProcessing
 
1854                 | kTXNSupportSpellCheckCommandUpdating
 
1855                 | kTXNSupportFontCommandProcessing
 
1856                 | kTXNSupportFontCommandUpdating
; 
1858             TXNSetCommandEventSupport( m_txn 
, options 
) ; 
1864 void wxMacMLTEControl::SetBackground( const wxBrush 
&brush 
) 
1866     // currently only solid background are supported 
1867     TXNBackground tback
; 
1869     tback
.bgType 
= kTXNBackgroundTypeRGB
; 
1870     tback
.bg
.color 
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() ); 
1871     TXNSetBackground( m_txn 
, &tback 
); 
1874 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style 
, long from 
, long to 
) 
1876     TXNTypeAttributes typeAttr
[4] ; 
1880     if ( style
.HasFont() ) 
1882         const wxFont 
&font 
= style
.GetFont() ; 
1884 #if 0 // old version 
1885         Str255 fontName 
= "\pMonaco" ; 
1886         SInt16 fontSize 
= 12 ; 
1887         Style fontStyle 
= normal 
; 
1888         wxMacStringToPascal( font
.GetFaceName() , fontName 
) ; 
1889         fontSize 
= font
.GetPointSize() ; 
1890         if ( font
.GetUnderlined() ) 
1891             fontStyle 
|= underline 
; 
1892         if ( font
.GetWeight() == wxBOLD 
) 
1894         if ( font
.GetStyle() == wxITALIC 
) 
1895             fontStyle 
|= italic 
; 
1897         typeAttr
[attrCount
].tag 
= kTXNQDFontNameAttribute 
; 
1898         typeAttr
[attrCount
].size 
= kTXNQDFontNameAttributeSize 
; 
1899         typeAttr
[attrCount
].data
.dataPtr 
= (void*)fontName 
; 
1902         typeAttr
[attrCount
].tag 
= kTXNQDFontSizeAttribute 
; 
1903         typeAttr
[attrCount
].size 
= kTXNFontSizeAttributeSize 
; 
1904         typeAttr
[attrCount
].data
.dataValue 
= (fontSize 
<< 16) ; 
1907         typeAttr
[attrCount
].tag 
= kTXNQDFontStyleAttribute 
; 
1908         typeAttr
[attrCount
].size 
= kTXNQDFontStyleAttributeSize 
; 
1909         typeAttr
[attrCount
].data
.dataValue 
= fontStyle 
; 
1912         typeAttr
[attrCount
].tag 
= kTXNATSUIStyle 
; 
1913         typeAttr
[attrCount
].size 
= kTXNATSUIStyleSize 
; 
1914         typeAttr
[attrCount
].data
.dataValue 
= (UInt32
)font
.MacGetATSUStyle() ; 
1919     if ( style
.HasTextColour() ) 
1921         color 
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ; 
1923         typeAttr
[attrCount
].tag 
= kTXNQDFontColorAttribute 
; 
1924         typeAttr
[attrCount
].size 
= kTXNQDFontColorAttributeSize 
; 
1925         typeAttr
[attrCount
].data
.dataPtr 
= (void*) &color 
; 
1929     if ( attrCount 
> 0 ) 
1931         verify_noerr( TXNSetTypeAttributes( m_txn 
, attrCount 
, typeAttr
, from 
, to 
) ); 
1932         // unfortunately the relayout is not automatic 
1933         TXNRecalcTextLayout( m_txn 
); 
1937 void wxMacMLTEControl::SetFont( const wxFont 
& font 
, const wxColour
& foreground 
, long windowStyle 
) 
1939     wxMacEditHelper 
help( m_txn 
) ; 
1940     TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font 
), kTXNStartOffset
, kTXNEndOffset 
) ; 
1943 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style 
) 
1945     wxMacEditHelper 
help( m_txn 
) ; 
1946     TXNSetAttribute( style
, start
, end 
) ; 
1949 void wxMacMLTEControl::Copy() 
1951     ClearCurrentScrap(); 
1953     TXNConvertToPublicScrap(); 
1956 void wxMacMLTEControl::Cut() 
1958     ClearCurrentScrap(); 
1960     TXNConvertToPublicScrap(); 
1963 void wxMacMLTEControl::Paste() 
1965     TXNConvertFromPublicScrap(); 
1969 bool wxMacMLTEControl::CanPaste() const 
1971     return TXNIsScrapPastable() ; 
1974 void wxMacMLTEControl::SetEditable(bool editable
) 
1976     TXNControlTag tag
[] = { kTXNIOPrivilegesTag 
} ; 
1977     TXNControlData data
[] = { { editable 
? kTXNReadWrite 
: kTXNReadOnly 
} } ; 
1978     TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data 
) ; 
1981 wxTextPos 
wxMacMLTEControl::GetLastPosition() const 
1983     wxTextPos actualsize 
= 0 ; 
1986     OSErr err 
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData 
); 
1991         actualsize 
= GetHandleSize( theText 
) ; 
1992         DisposeHandle( theText 
) ; 
2002 void wxMacMLTEControl::Replace( long from 
, long to 
, const wxString 
&str 
) 
2004     wxString value 
= str 
; 
2005     wxMacConvertNewlines10To13( &value 
) ; 
2007     wxMacEditHelper 
help( m_txn 
) ; 
2008     wxMacWindowClipper 
c( m_peer 
) ; 
2010     TXNSetSelection( m_txn
, from
, to 
) ; 
2012     SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection 
) ; 
2015 void wxMacMLTEControl::Remove( long from 
, long to 
) 
2017     wxMacWindowClipper 
c( m_peer 
) ; 
2018     wxMacEditHelper 
help( m_txn 
) ; 
2019     TXNSetSelection( m_txn 
, from 
, to 
) ; 
2023 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const 
2025     TXNGetSelection( m_txn 
, (TXNOffset
*) from 
, (TXNOffset
*) to 
) ; 
2028 void wxMacMLTEControl::SetSelection( long from 
, long to 
) 
2030     wxMacWindowClipper 
c( m_peer 
) ; 
2032     // change the selection 
2033     if ((from 
== -1) && (to 
== -1)) 
2034         TXNSelectAll( m_txn 
); 
2036         TXNSetSelection( m_txn
, from
, to 
); 
2038     TXNShowSelection( m_txn
, kTXNShowStart 
); 
2041 void wxMacMLTEControl::WriteText( const wxString
& str 
) 
2044     wxMacConvertNewlines10To13( &st 
) ; 
2046     long start 
, end 
, dummy 
; 
2048     GetSelection( &start 
, &dummy 
) ; 
2049     wxMacWindowClipper 
c( m_peer 
) ; 
2052         wxMacEditHelper 
helper( m_txn 
) ; 
2053         SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection 
) ; 
2056     GetSelection( &dummy
, &end 
) ; 
2058     // TODO: SetStyle( start , end , GetDefaultStyle() ) ; 
2061 void wxMacMLTEControl::Clear() 
2063     wxMacWindowClipper 
c( m_peer 
) ; 
2064     wxMacEditHelper 
st( m_txn 
) ; 
2065     TXNSetSelection( m_txn 
, kTXNStartOffset 
, kTXNEndOffset 
) ; 
2069 bool wxMacMLTEControl::CanUndo() const 
2071     return TXNCanUndo( m_txn 
, NULL 
) ; 
2074 void wxMacMLTEControl::Undo() 
2079 bool wxMacMLTEControl::CanRedo() const 
2081     return TXNCanRedo( m_txn 
, NULL 
) ; 
2084 void wxMacMLTEControl::Redo() 
2089 int wxMacMLTEControl::GetNumberOfLines() const 
2091     ItemCount lines 
= 0 ; 
2092     TXNGetLineCount( m_txn
, &lines 
) ; 
2097 long wxMacMLTEControl::XYToPosition(long x
, long y
) const 
2102     // TODO: find a better implementation : while we can get the 
2103     // line metrics of a certain line, we don't get its starting 
2104     // position, so it would probably be rather a binary search 
2105     // for the start position 
2106     long xpos 
= 0, ypos 
= 0 ; 
2107     int lastHeight 
= 0 ; 
2110     lastpos 
= GetLastPosition() ; 
2111     for ( n 
= 0 ; n 
<= (ItemCount
) lastpos 
; ++n 
) 
2113         if ( y 
== ypos 
&& x 
== xpos 
) 
2116         TXNOffsetToPoint( m_txn
, n
, &curpt 
) ; 
2118         if ( curpt
.v 
> lastHeight 
) 
2124             lastHeight 
= curpt
.v 
; 
2133 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y 
) const 
2143     lastpos 
= GetLastPosition() ; 
2144     if ( pos 
<= lastpos 
) 
2146         // TODO: find a better implementation - while we can get the 
2147         // line metrics of a certain line, we don't get its starting 
2148         // position, so it would probably be rather a binary search 
2149         // for the start position 
2150         long xpos 
= 0, ypos 
= 0 ; 
2151         int lastHeight 
= 0 ; 
2154         for ( n 
= 0 ; n 
<= (ItemCount
) pos 
; ++n 
) 
2156             TXNOffsetToPoint( m_txn
, n
, &curpt 
) ; 
2158             if ( curpt
.v 
> lastHeight 
) 
2164                 lastHeight 
= curpt
.v 
; 
2179 void wxMacMLTEControl::ShowPosition( long pos 
) 
2181 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER) 
2183         Point current
, desired 
; 
2184         TXNOffset selstart
, selend
; 
2186         TXNGetSelection( m_txn
, &selstart
, &selend 
); 
2187         TXNOffsetToPoint( m_txn
, selstart
, ¤t 
); 
2188         TXNOffsetToPoint( m_txn
, pos
, &desired 
); 
2190         // TODO: use HIPoints for 10.3 and above 
2191         if ( (UInt32
)TXNScroll 
!= (UInt32
)kUnresolvedCFragSymbolAddress 
) 
2193             OSErr theErr 
= noErr
; 
2194             SInt32 dv 
= desired
.v 
- current
.v
; 
2195             SInt32 dh 
= desired
.h 
- current
.h
; 
2196             TXNShowSelection( m_txn
, kTXNShowStart 
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ?? 
2197             theErr 
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh 
); 
2199             // there will be an error returned for classic MLTE implementation when the control is 
2200             // invisible, but HITextView works correctly, so we don't assert that one 
2201             // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); 
2207 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end 
) 
2210 #if SIZEOF_WCHAR_T == 2 
2211     size_t len 
= st
.Len() ; 
2212     TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len 
* 2, start
, end 
); 
2214     wxMBConvUTF16 converter 
; 
2215     ByteCount byteBufferLen 
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ; 
2216     UniChar 
*unibuf 
= (UniChar
*)malloc( byteBufferLen 
) ; 
2217     converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen 
) ; 
2218     TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end 
) ; 
2222     wxCharBuffer text 
= st
.mb_str( wxConvLocal 
) ; 
2223     TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text 
), start
, end 
) ; 
2227 wxString 
wxMacMLTEControl::GetLineText(long lineNo
) const 
2231     if ( lineNo 
< GetNumberOfLines() ) 
2234         Fixed lineWidth
, lineHeight
, currentHeight
; 
2237         // get the first possible position in the control 
2238         TXNOffsetToPoint(m_txn
, 0, &firstPoint
); 
2240         // Iterate through the lines until we reach the one we want, 
2241         // adding to our current y pixel point position 
2244         while (ypos 
< lineNo
) 
2246             TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
); 
2247             currentHeight 
+= lineHeight
; 
2250         Point thePoint 
= { firstPoint
.v 
+ (currentHeight 
>> 16), firstPoint
.h 
+ (0) }; 
2251         TXNOffset theOffset
; 
2252         TXNPointToOffset(m_txn
, thePoint
, &theOffset
); 
2254         wxString content 
= GetStringValue() ; 
2255         Point currentPoint 
= thePoint
; 
2256         while (thePoint
.v 
== currentPoint
.v 
&& theOffset 
< content
.length()) 
2258             line 
+= content
[theOffset
]; 
2259             TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
); 
2266 int wxMacMLTEControl::GetLineLength(long lineNo
) const 
2270     if ( lineNo 
< GetNumberOfLines() ) 
2273         Fixed lineWidth
, lineHeight
, currentHeight
; 
2276         // get the first possible position in the control 
2277         TXNOffsetToPoint(m_txn
, 0, &firstPoint
); 
2279         // Iterate through the lines until we reach the one we want, 
2280         // adding to our current y pixel point position 
2283         while (ypos 
< lineNo
) 
2285             TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
); 
2286             currentHeight 
+= lineHeight
; 
2289         Point thePoint 
= { firstPoint
.v 
+ (currentHeight 
>> 16), firstPoint
.h 
+ (0) }; 
2290         TXNOffset theOffset
; 
2291         TXNPointToOffset(m_txn
, thePoint
, &theOffset
); 
2293         wxString content 
= GetStringValue() ; 
2294         Point currentPoint 
= thePoint
; 
2295         while (thePoint
.v 
== currentPoint
.v 
&& theOffset 
< content
.length()) 
2298             TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
); 
2305 // ---------------------------------------------------------------------------- 
2306 // MLTE control implementation (classic part) 
2307 // ---------------------------------------------------------------------------- 
2309 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation 
2310 // has to live on. We have different problems coming from outdated implementations on the 
2311 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded 
2312 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is 
2313 // no way out, therefore we are using our own implementation and our own scrollbars .... 
2315 #ifdef __WXMAC_OSX__ 
2317 TXNScrollInfoUPP gTXNScrollInfoProc 
= NULL 
; 
2318 ControlActionUPP gTXNScrollActionProc 
= NULL 
; 
2320 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc( 
2321     SInt32 iValue
, SInt32 iMaximumValue
, 
2322     TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon 
) 
2324     wxMacMLTEClassicControl
* mlte 
= (wxMacMLTEClassicControl
*) iRefCon 
; 
2325     SInt32 value 
=  wxMax( iValue 
, 0 ) ; 
2326     SInt32 maximum 
= wxMax( iMaximumValue 
, 0 ) ; 
2328     if ( iScrollBarOrientation 
== kTXNHorizontal 
) 
2330         if ( mlte
->m_sbHorizontal 
) 
2332             SetControl32BitValue( mlte
->m_sbHorizontal 
, value 
) ; 
2333             SetControl32BitMaximum( mlte
->m_sbHorizontal 
, maximum 
) ; 
2334             mlte
->m_lastHorizontalValue 
= value 
; 
2337     else if ( iScrollBarOrientation 
== kTXNVertical 
) 
2339         if ( mlte
->m_sbVertical 
) 
2341             SetControl32BitValue( mlte
->m_sbVertical 
, value 
) ; 
2342             SetControl32BitMaximum( mlte
->m_sbVertical 
, maximum 
) ; 
2343             mlte
->m_lastVerticalValue 
= value 
; 
2348 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef 
, ControlPartCode partCode 
) 
2350     wxMacMLTEClassicControl
* mlte 
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef 
) ; 
2354     if ( controlRef 
!= mlte
->m_sbVertical 
&& controlRef 
!= mlte
->m_sbHorizontal 
) 
2358     bool isHorizontal 
= ( controlRef 
== mlte
->m_sbHorizontal 
) ; 
2360     SInt32 minimum 
= 0 ; 
2361     SInt32 maximum 
= GetControl32BitMaximum( controlRef 
) ; 
2362     SInt32 value 
= GetControl32BitValue( controlRef 
) ; 
2367         case kControlDownButtonPart 
: 
2371         case kControlUpButtonPart 
: 
2375         case kControlPageDownPart 
: 
2376             delta 
= GetControlViewSize( controlRef 
) ; 
2379         case kControlPageUpPart 
: 
2380             delta 
= -GetControlViewSize( controlRef 
) ; 
2383         case kControlIndicatorPart 
: 
2384             delta 
= value 
- (isHorizontal 
? mlte
->m_lastHorizontalValue 
: mlte
->m_lastVerticalValue
) ; 
2393         SInt32 newValue 
= value 
; 
2395         if ( partCode 
!= kControlIndicatorPart 
) 
2397             if ( value 
+ delta 
< minimum 
) 
2398                 delta 
= minimum 
- value 
; 
2399             if ( value 
+ delta 
> maximum 
) 
2400                 delta 
= maximum 
- value 
; 
2402             SetControl32BitValue( controlRef 
, value 
+ delta 
) ; 
2403             newValue 
= value 
+ delta 
; 
2406         SInt32 verticalDelta 
= isHorizontal 
? 0 : delta 
; 
2407         SInt32 horizontalDelta 
= isHorizontal 
? delta 
: 0 ; 
2410             mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, 
2411             &verticalDelta
, &horizontalDelta 
); 
2412         verify_noerr( err 
); 
2415             mlte
->m_lastHorizontalValue 
= newValue 
; 
2417             mlte
->m_lastVerticalValue 
= newValue 
; 
2422 // make correct activations 
2423 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
) 
2425     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference(m_controlRef
); 
2427     wxMacWindowClipper 
clipper( textctrl 
) ; 
2428     TXNActivate( m_txn
, m_txnFrameID
, setActive 
); 
2430     ControlRef controlFocus 
= 0 ; 
2431     GetKeyboardFocus( m_txnWindow 
, &controlFocus 
) ; 
2432     if ( controlFocus 
== m_controlRef 
) 
2433         TXNFocus( m_txn
, setActive 
); 
2436 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
) 
2438     TXNFocus( m_txn
, setFocus 
); 
2441 // guards against inappropriate redraw (hidden objects drawing onto window) 
2443 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
) 
2445     ControlRef controlFocus 
= 0 ; 
2446     GetKeyboardFocus( m_txnWindow 
, &controlFocus 
) ; 
2448     if ( !vis 
&& (controlFocus 
== m_controlRef 
) ) 
2449         SetKeyboardFocus( m_txnWindow 
, m_controlRef 
, kControlFocusNoPart 
) ; 
2451     TXNControlTag iControlTags
[1] = { kTXNVisibilityTag 
}; 
2452     TXNControlData iControlData
[1] = { { (UInt32
)false } }; 
2454     verify_noerr( TXNGetTXNObjectControls( m_txn 
, 1, iControlTags
, iControlData 
) ) ; 
2456     if ( iControlData
[0].uValue 
!= vis 
) 
2458         iControlData
[0].uValue 
= vis 
; 
2459         verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData 
) ) ; 
2462     // currently, we always clip as partial visibility (overlapped) visibility is also a problem, 
2463     // if we run into further problems we might set the FrameBounds to an empty rect here 
2466 // make sure that the TXNObject is at the right position 
2468 void wxMacMLTEClassicControl::MacUpdatePosition() 
2470     wxTextCtrl
* textctrl 
= (wxTextCtrl
*)GetControlReference( m_controlRef 
); 
2471     if ( textctrl 
== NULL 
) 
2475     UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds 
); 
2477     wxRect visRect 
= textctrl
->MacGetClippedClientRect() ; 
2478     Rect visBounds 
= { visRect
.y 
, visRect
.x 
, visRect
.y 
+ visRect
.height 
, visRect
.x 
+ visRect
.width 
} ; 
2481     textctrl
->MacWindowToRootWindow( &x 
, &y 
) ; 
2482     OffsetRect( &visBounds 
, x 
, y 
) ; 
2484     if ( !EqualRect( &bounds
, &m_txnControlBounds 
) || !EqualRect( &visBounds
, &m_txnVisBounds 
) ) 
2486         m_txnControlBounds 
= bounds 
; 
2487         m_txnVisBounds 
= visBounds 
; 
2488         wxMacWindowClipper 
cl( textctrl 
) ; 
2490 #ifdef __WXMAC_OSX__ 
2491         bool isCompositing 
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ; 
2492         if ( m_sbHorizontal 
|| m_sbVertical 
) 
2494             int w 
= bounds
.right 
- bounds
.left 
; 
2495             int h 
= bounds
.bottom 
- bounds
.top 
; 
2497             if ( m_sbHorizontal 
) 
2501                 sbBounds
.left 
= -1 ; 
2502                 sbBounds
.top 
= h 
- 14 ; 
2503                 sbBounds
.right 
= w 
+ 1 ; 
2504                 sbBounds
.bottom 
= h 
+ 1 ; 
2506                 if ( !isCompositing 
) 
2507                     OffsetRect( &sbBounds 
, m_txnControlBounds
.left 
, m_txnControlBounds
.top 
) ; 
2509                 SetControlBounds( m_sbHorizontal 
, &sbBounds 
) ; 
2510                 SetControlViewSize( m_sbHorizontal 
, w 
) ; 
2517                 sbBounds
.left 
= w 
- 14 ; 
2519                 sbBounds
.right 
= w 
+ 1 ; 
2520                 sbBounds
.bottom 
= m_sbHorizontal 
? h 
- 14 : h 
+ 1 ; 
2522                 if ( !isCompositing 
) 
2523                     OffsetRect( &sbBounds 
, m_txnControlBounds
.left 
, m_txnControlBounds
.top 
) ; 
2525                 SetControlBounds( m_sbVertical 
, &sbBounds 
) ; 
2526                 SetControlViewSize( m_sbVertical 
, h 
) ; 
2531         TXNLongRect olddestRect 
; 
2532         TXNGetRectBounds( m_txn 
, &oldviewRect 
, &olddestRect 
, NULL 
) ; 
2534         Rect viewRect 
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
, 
2535             m_txnControlBounds
.bottom 
- ( m_sbHorizontal 
? 14 : 0 ) , 
2536             m_txnControlBounds
.right 
- ( m_sbVertical 
? 14 : 0 ) } ; 
2537         TXNLongRect destRect 
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
, 
2538             m_txnControlBounds
.bottom 
- ( m_sbHorizontal 
? 14 : 0 ) , 
2539             m_txnControlBounds
.right 
- ( m_sbVertical 
? 14 : 0 ) } ; 
2541         if ( olddestRect
.right 
>= 10000 ) 
2542             destRect
.right 
= destRect
.left 
+ 32000 ; 
2544         if ( olddestRect
.bottom 
>= 0x20000000 ) 
2545             destRect
.bottom 
= destRect
.top 
+ 0x40000000 ; 
2547         SectRect( &viewRect 
, &visBounds 
, &viewRect 
) ; 
2548         TXNSetRectBounds( m_txn 
, &viewRect 
, &destRect 
, true ) ; 
2553             m_txnControlBounds
.top
, 
2554             m_txnControlBounds
.left
, 
2555             m_txnControlBounds
.bottom 
- (m_sbHorizontal 
? 14 : 0), 
2556             m_txnControlBounds
.right 
- (m_sbVertical 
? 14 : 0), 
2562             m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
, 
2563             wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top 
), 
2564             wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left 
), m_txnFrameID 
); 
2567         // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a 
2568         // movement, therefore we have to force it 
2570         // this problem has been reported in OSX as well, so we use this here once again 
2572         TXNLongRect textRect 
; 
2573         TXNGetRectBounds( m_txn 
, NULL 
, NULL 
, &textRect 
) ; 
2574         if ( textRect
.left 
< m_txnControlBounds
.left 
) 
2575             TXNShowSelection( m_txn 
, kTXNShowStart 
) ; 
2579 void wxMacMLTEClassicControl::SetRect( Rect 
*r 
) 
2581     wxMacControl::SetRect( r 
) ; 
2582     MacUpdatePosition() ; 
2585 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
) 
2587     wxTextCtrl
* textctrl 
= (wxTextCtrl
*)GetControlReference( m_controlRef 
); 
2588     if ( textctrl 
== NULL 
) 
2591     if ( textctrl
->MacIsReallyShown() ) 
2593         wxMacWindowClipper 
clipper( textctrl 
) ; 
2594         TXNDraw( m_txn 
, NULL 
) ; 
2598 wxInt16 
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) 
2600     Point where 
= { y 
, x 
} ; 
2601     ControlPartCode result 
= kControlNoPart
; 
2603     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference( m_controlRef 
); 
2604     if ( (textctrl 
!= NULL
) && textctrl
->MacIsReallyShown() ) 
2606         if (PtInRect( where
, &m_txnControlBounds 
)) 
2608             result 
= kControlEditTextPart 
; 
2612             // sometimes we get the coords also in control local coordinates, therefore test again 
2613             if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ) 
2616                 textctrl
->MacClientToRootWindow( &x 
, &y 
) ; 
2621             if (PtInRect( where
, &m_txnControlBounds 
)) 
2622                 result 
= kControlEditTextPart 
; 
2629 wxInt16 
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc 
) 
2631     ControlPartCode result 
= kControlNoPart
; 
2633     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference( m_controlRef 
); 
2634     if ( (textctrl 
!= NULL
) && textctrl
->MacIsReallyShown() ) 
2636         Point startPt 
= { y 
, x 
} ; 
2637         // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them 
2638         if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ) 
2641             textctrl
->MacClientToRootWindow( &x 
, &y 
) ; 
2646         switch (MacControlUserPaneHitTestProc( startPt
.h 
, startPt
.v 
)) 
2648             case kControlEditTextPart 
: 
2650                 wxMacWindowClipper 
clipper( textctrl 
) ; 
2653                 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec 
) ; 
2654                 TXNClick( m_txn
, &rec 
); 
2666 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc() 
2668     wxTextCtrl
* textctrl 
= (wxTextCtrl
*)GetControlReference( m_controlRef 
); 
2669     if ( textctrl 
== NULL 
) 
2672     if (textctrl
->MacIsReallyShown()) 
2674         if (IsControlActive(m_controlRef
)) 
2678             wxMacWindowClipper 
clipper( textctrl 
) ; 
2683             if (PtInRect(mousep
, &m_txnControlBounds
)) 
2685                 RgnHandle theRgn 
= NewRgn(); 
2686                 RectRgn(theRgn
, &m_txnControlBounds
); 
2687                 TXNAdjustCursor(m_txn
, theRgn
); 
2694 wxInt16 
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) 
2696     wxTextCtrl
* textctrl 
= (wxTextCtrl
*)GetControlReference( m_controlRef 
); 
2697     if ( textctrl 
== NULL 
) 
2698         return kControlNoPart
; 
2700     wxMacWindowClipper 
clipper( textctrl 
) ; 
2703     memset( &ev 
, 0 , sizeof( ev 
) ) ; 
2705     ev
.modifiers 
= modifiers 
; 
2706     ev
.message 
= ((keyCode 
<< 8) & keyCodeMask
) | (charCode 
& charCodeMask
); 
2707     TXNKeyDown( m_txn 
, &ev 
); 
2709     return kControlEntireControl
; 
2712 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
) 
2714     MacActivatePaneText( activating 
); 
2717 wxInt16 
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
) 
2719     ControlPartCode focusResult 
= kControlFocusNoPart
; 
2721     wxTextCtrl
* textctrl 
= (wxTextCtrl
*)GetControlReference( m_controlRef 
); 
2722     if ( textctrl 
== NULL 
) 
2725     wxMacWindowClipper 
clipper( textctrl 
) ; 
2727     ControlRef controlFocus 
= NULL 
; 
2728     GetKeyboardFocus( m_txnWindow 
, &controlFocus 
) ; 
2729     bool wasFocused 
= ( controlFocus 
== m_controlRef 
) ; 
2733         case kControlFocusPrevPart
: 
2734         case kControlFocusNextPart
: 
2735             MacFocusPaneText( !wasFocused 
); 
2736             focusResult 
= (!wasFocused 
? (ControlPartCode
) kControlEditTextPart 
: (ControlPartCode
) kControlFocusNoPart
); 
2739         case kControlFocusNoPart
: 
2741             MacFocusPaneText( false ); 
2742             focusResult 
= kControlFocusNoPart
; 
2749 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info 
) 
2753 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl 
*wxPeer
, 
2754     const wxString
& str
, 
2756     const wxSize
& size
, long style 
) 
2757     : wxMacMLTEControl( wxPeer 
) 
2759     m_font 
= wxPeer
->GetFont() ; 
2760     m_windowStyle 
= style 
; 
2761     Rect bounds 
= wxMacGetBoundsForControl( wxPeer 
, pos 
, size 
) ; 
2764         kControlSupportsEmbedding 
| kControlSupportsFocus 
| kControlWantsIdle
 
2765         | kControlWantsActivate  
| kControlHandlesTracking
 
2766 //    | kControlHasSpecialBackground 
2767         | kControlGetsFocusOnClick 
| kControlSupportsLiveFeedback
; 
2769    OSStatus err 
= ::CreateUserPaneControl( 
2770         MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), 
2771         &bounds
, featureSet
, &m_controlRef 
); 
2772     verify_noerr( err 
); 
2776     AdjustCreationAttributes( *wxWHITE 
, true ) ; 
2778     MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ; 
2782         wxMacConvertNewlines10To13( &st 
) ; 
2783         wxMacWindowClipper 
clipper( m_peer 
) ; 
2784         SetTXNData( st 
, kTXNStartOffset
, kTXNEndOffset 
) ; 
2785         TXNSetSelection( m_txn
, 0, 0 ) ; 
2789 wxMacMLTEClassicControl::~wxMacMLTEClassicControl() 
2791     TXNDeleteObject( m_txn 
); 
2795 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
) 
2797     MacSetObjectVisibility( shown 
) ; 
2798     wxMacControl::VisibilityChanged( shown 
) ; 
2801 void wxMacMLTEClassicControl::SuperChangedPosition() 
2803     MacUpdatePosition() ; 
2804     wxMacControl::SuperChangedPosition() ; 
2807 #ifdef __WXMAC_OSX__ 
2809 ControlUserPaneDrawUPP gTPDrawProc 
= NULL
; 
2810 ControlUserPaneHitTestUPP gTPHitProc 
= NULL
; 
2811 ControlUserPaneTrackingUPP gTPTrackProc 
= NULL
; 
2812 ControlUserPaneIdleUPP gTPIdleProc 
= NULL
; 
2813 ControlUserPaneKeyDownUPP gTPKeyProc 
= NULL
; 
2814 ControlUserPaneActivateUPP gTPActivateProc 
= NULL
; 
2815 ControlUserPaneFocusUPP gTPFocusProc 
= NULL
; 
2817 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
) 
2819     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2820     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2822         win
->MacControlUserPaneDrawProc( part 
) ; 
2825 static pascal ControlPartCode 
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
) 
2827     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2828     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2830         return win
->MacControlUserPaneHitTestProc( where
.h 
, where
.v 
) ; 
2832         return kControlNoPart 
; 
2835 static pascal ControlPartCode 
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
) 
2837     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2838     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2840         return win
->MacControlUserPaneTrackingProc( startPt
.h 
, startPt
.v 
, (void*) actionProc 
) ; 
2842         return kControlNoPart 
; 
2845 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
) 
2847     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2848     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2850         win
->MacControlUserPaneIdleProc() ; 
2853 static pascal ControlPartCode 
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) 
2855     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2856     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2858         return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers 
) ; 
2860         return kControlNoPart 
; 
2863 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
) 
2865     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2866     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2868         win
->MacControlUserPaneActivateProc( activating 
) ; 
2871 static pascal ControlPartCode 
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
) 
2873     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2874     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2876         return win
->MacControlUserPaneFocusProc( action 
) ; 
2878         return kControlNoPart 
; 
2882 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
) 
2884     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2885     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2887         win
->MacControlUserPaneBackgroundProc(info
) ; 
2891 #endif // __WXMAC_OSX__ 
2893 // TXNRegisterScrollInfoProc 
2895 OSStatus 
wxMacMLTEClassicControl::DoCreate() 
2898     OSStatus err 
= noErr 
; 
2900     // set up our globals 
2901 #ifdef __WXMAC_OSX__ 
2902     if (gTPDrawProc 
== NULL
) gTPDrawProc 
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
); 
2903     if (gTPHitProc 
== NULL
) gTPHitProc 
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
); 
2904     if (gTPTrackProc 
== NULL
) gTPTrackProc 
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
); 
2905     if (gTPIdleProc 
== NULL
) gTPIdleProc 
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
); 
2906     if (gTPKeyProc 
== NULL
) gTPKeyProc 
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
); 
2907     if (gTPActivateProc 
== NULL
) gTPActivateProc 
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
); 
2908     if (gTPFocusProc 
== NULL
) gTPFocusProc 
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
); 
2910     if (gTXNScrollInfoProc 
== NULL 
) gTXNScrollInfoProc 
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ; 
2911     if (gTXNScrollActionProc 
== NULL 
) gTXNScrollActionProc 
= NewControlActionUPP(TXNScrollActionProc
) ; 
2914     // set the initial settings for our private data 
2916     m_txnWindow 
= GetControlOwner(m_controlRef
); 
2917     m_txnPort 
= (GrafPtr
) GetWindowPort(m_txnWindow
); 
2919 #ifdef __WXMAC_OSX__ 
2920     // set up the user pane procedures 
2921     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
); 
2922     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
); 
2923     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
); 
2924     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
); 
2925     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
); 
2926     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
); 
2927     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
); 
2930     // calculate the rectangles used by the control 
2931     UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds 
); 
2933     m_txnControlBounds 
= bounds 
; 
2934     m_txnVisBounds 
= bounds 
; 
2939     GetGWorld( &origPort
, &origDev 
) ; 
2940     SetPort( m_txnPort 
); 
2942     // create the new edit field 
2943     TXNFrameOptions frameOptions 
= FrameOptionsFromWXStyle( m_windowStyle 
); 
2945 #ifdef __WXMAC_OSX__ 
2946     // the scrollbars are not correctly embedded but are inserted at the root: 
2947     // this gives us problems as we have erratic redraws even over the structure area 
2949     m_sbHorizontal 
= 0 ; 
2951     m_lastHorizontalValue 
= 0 ; 
2952     m_lastVerticalValue 
= 0 ; 
2954     Rect sb 
= { 0 , 0 , 0 , 0 } ; 
2955     if ( frameOptions 
& kTXNWantVScrollBarMask 
) 
2957         CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical 
); 
2958         SetControlReference( m_sbVertical
, (SInt32
)this ); 
2959         SetControlAction( m_sbVertical
, gTXNScrollActionProc 
); 
2960         ShowControl( m_sbVertical 
); 
2961         EmbedControl( m_sbVertical 
, m_controlRef 
); 
2962         frameOptions 
&= ~kTXNWantVScrollBarMask
; 
2965     if ( frameOptions 
& kTXNWantHScrollBarMask 
) 
2967         CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal 
); 
2968         SetControlReference( m_sbHorizontal
, (SInt32
)this ); 
2969         SetControlAction( m_sbHorizontal
, gTXNScrollActionProc 
); 
2970         ShowControl( m_sbHorizontal 
); 
2971         EmbedControl( m_sbHorizontal
, m_controlRef 
); 
2972         frameOptions 
&= ~(kTXNWantHScrollBarMask 
| kTXNDrawGrowIconMask
); 
2978         NULL
, m_txnWindow
, &bounds
, frameOptions
, 
2979         kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
, 
2980         &m_txn
, &m_txnFrameID
, NULL 
); 
2981     verify_noerr( err 
); 
2984     TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents 
}; 
2985     TXNControlData iControlData
[] = { { (UInt32
)&cInfo 
} }; 
2986     int toptag 
= WXSIZEOF( iControlTags 
) ; 
2987     TXNCarbonEventInfo cInfo 
; 
2988     cInfo
.useCarbonEvents 
= false ; 
2991     cInfo
.fDictionary 
= NULL 
; 
2993     verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData 
) ); 
2996 #ifdef __WXMAC_OSX__ 
2997     TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this ); 
3000     SetGWorld( origPort 
, origDev 
) ; 
3005 // ---------------------------------------------------------------------------- 
3006 // MLTE control implementation (OSX part) 
3007 // ---------------------------------------------------------------------------- 
3009 #if TARGET_API_MAC_OSX 
3011 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 
3013 // tiger multi-line textcontrols with no CR in the entire content 
3014 // don't scroll automatically, so we need a hack. 
3015 // This attempt only works 'before' the key (ie before CallNextEventHandler) 
3016 // is processed, thus the scrolling always occurs one character too late, but 
3017 // better than nothing ... 
3019 static const EventTypeSpec eventList
[] = 
3021     { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent 
} , 
3024 static pascal OSStatus 
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
3026     OSStatus result 
= eventNotHandledErr 
; 
3027     wxMacMLTEHIViewControl
* focus 
= (wxMacMLTEHIViewControl
*) data 
; 
3029     switch ( GetEventKind( event 
) ) 
3031         case kEventTextInputUnicodeForKeyEvent 
: 
3033             if ( UMAGetSystemVersion() >= 0x1040 ) 
3035                 TXNOffset from 
, to 
; 
3036                 TXNGetSelection( focus
->GetTXNObject() , &from 
, &to 
) ; 
3038                     TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart 
); 
3040             result 
= CallNextEventHandler(handler
,event
); 
3050 static pascal OSStatus 
wxMacTextControlEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
3052     OSStatus result 
= eventNotHandledErr 
; 
3054     switch ( GetEventClass( event 
) ) 
3056         case kEventClassTextInput 
: 
3057             result 
= wxMacUnicodeTextEventHandler( handler 
, event 
, data 
) ; 
3066 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler 
) 
3068 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl 
*wxPeer
, 
3069     const wxString
& str
, 
3071     const wxSize
& size
, long style 
) : wxMacMLTEControl( wxPeer 
) 
3073     m_font 
= wxPeer
->GetFont() ; 
3074     m_windowStyle 
= style 
; 
3075     Rect bounds 
= wxMacGetBoundsForControl( wxPeer 
, pos 
, size 
) ; 
3077     wxMacConvertNewlines10To13( &st 
) ; 
3080         { bounds
.left 
, bounds
.top 
}, 
3081         { bounds
.right 
- bounds
.left
, bounds
.bottom 
- bounds
.top 
} } ; 
3083     m_scrollView 
= NULL 
; 
3084     TXNFrameOptions frameOptions 
= FrameOptionsFromWXStyle( style 
) ; 
3085     if ( frameOptions 
& (kTXNWantVScrollBarMask 
| kTXNWantHScrollBarMask
) ) 
3088             (frameOptions 
& kTXNWantHScrollBarMask 
? kHIScrollViewOptionsHorizScroll 
: 0) 
3089             | (frameOptions 
& kTXNWantVScrollBarMask 
? kHIScrollViewOptionsVertScroll 
: 0) , 
3092         HIViewSetFrame( m_scrollView
, &hr 
); 
3093         HIViewSetVisible( m_scrollView
, true ); 
3097     HITextViewCreate( NULL 
, 0, frameOptions 
, &m_textView 
) ; 
3098     m_txn 
= HITextViewGetTXNObject( m_textView 
) ; 
3099     HIViewSetVisible( m_textView 
, true ) ; 
3102         HIViewAddSubview( m_scrollView 
, m_textView 
) ; 
3103         m_controlRef 
= m_scrollView 
; 
3104         wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView 
) ; 
3108         HIViewSetFrame( m_textView
, &hr 
); 
3109         m_controlRef 
= m_textView 
; 
3112     AdjustCreationAttributes( *wxWHITE 
, true ) ; 
3114     wxMacWindowClipper 
c( m_peer 
) ; 
3115     SetTXNData( st 
, kTXNStartOffset
, kTXNEndOffset 
) ; 
3117     TXNSetSelection( m_txn
, 0, 0 ); 
3118     TXNShowSelection( m_txn
, kTXNShowStart 
); 
3120     InstallControlEventHandler( m_textView 
, GetwxMacTextControlEventHandlerUPP(), 
3121                                 GetEventTypeCount(eventList
), eventList
, this, 
3122                                 &m_textEventHandlerRef
); 
3125 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl() 
3127     ::RemoveEventHandler( m_textEventHandlerRef 
) ; 
3130 OSStatus 
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart 
) 
3132     return SetKeyboardFocus( GetControlOwner( m_textView 
), m_textView
, focusPart 
) ; 
3135 bool wxMacMLTEHIViewControl::HasFocus() const 
3137     ControlRef control 
; 
3138     GetKeyboardFocus( GetUserFocusWindow() , &control 
) ; 
3139     return control 
== m_textView 
; 
3142 void wxMacMLTEHIViewControl::SetBackground( const wxBrush 
&brush 
) 
3144     wxMacMLTEControl::SetBackground( brush 
) ; 
3147     CGColorSpaceRef rgbSpace 
= CGColorSpaceCreateDeviceRGB(); 
3148     RGBColor col 
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ; 
3150     float component
[4] ; 
3151     component
[0] = col
.red 
/ 65536.0 ; 
3152     component
[1] = col
.green 
/ 65536.0 ; 
3153     component
[2] = col
.blue 
/ 65536.0 ; 
3154     component
[3] = 1.0 ; // alpha 
3156     CGColorRef color 
= CGColorCreate( rgbSpace 
, component 
); 
3157     HITextViewSetBackgroundColor( m_textView 
, color 
); 
3158     CGColorSpaceRelease( rgbSpace 
); 
3162 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 
3167 #endif // wxUSE_TEXTCTRL