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" 
  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" 
  48 #include "wx/mac/uma.h" 
  49 #include "wx/mac/carbon/private/mactext.h" 
  55     virtual ~wxMacFunctor() {} 
  57     virtual void* operator()() = 0 ; 
  59     static void* CallBackProc( void *param 
) 
  61         wxMacFunctor
* f 
= (wxMacFunctor
*) param 
; 
  62         void *result 
= (*f
)() ; 
  67 template<typename classtype
, typename param1type
> 
  69 class wxMacObjectFunctor1 
: public wxMacFunctor
 
  71     typedef void (classtype::*function
)( param1type p1 
) ; 
  72     typedef void (classtype::*ref_function
)( const param1type
& p1 
) ; 
  74     wxMacObjectFunctor1( classtype 
*obj 
, function f 
, param1type p1 
) : 
  82     wxMacObjectFunctor1( classtype 
*obj 
, ref_function f 
, param1type p1 
) : 
  90     virtual ~wxMacObjectFunctor1() {} 
  92     virtual void* operator()() 
  94         (m_object
->*m_function
)( m_param1 
) ; 
 100     param1type m_param1 
; 
 103         function m_function 
; 
 104         ref_function m_refFunction 
; 
 108 template<typename classtype
, typename param1type
> 
 109 void* wxMacMPRemoteCall( classtype 
*object 
, void (classtype::*function
)( param1type p1 
) , param1type p1 
) 
 111     wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ; 
 113         MPRemoteCall( wxMacFunctor::CallBackProc 
, ¶ms 
, kMPOwningProcessRemoteContext 
) ; 
 117 template<typename classtype
, typename param1type
> 
 118 void* wxMacMPRemoteCall( classtype 
*object 
, void (classtype::*function
)( const param1type
& p1 
) , param1type p1 
) 
 120     wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ; 
 122         MPRemoteCall( wxMacFunctor::CallBackProc 
, ¶ms 
, kMPOwningProcessRemoteContext 
) ; 
 126 template<typename classtype
, typename param1type
> 
 127 void* wxMacMPRemoteGUICall( classtype 
*object 
, void (classtype::*function
)( param1type p1 
) , param1type p1 
) 
 130     void *result 
= wxMacMPRemoteCall( object 
, function 
, p1 
) ; 
 135 template<typename classtype
, typename param1type
> 
 136 void* wxMacMPRemoteGUICall( classtype 
*object 
, void (classtype::*function
)( const param1type
& p1 
) , param1type p1 
) 
 139     void *result 
= wxMacMPRemoteCall( object 
, function 
, p1 
) ; 
 145 // common parts for implementations based on MLTE 
 147 class wxMacMLTEControl 
: public wxMacTextControl
 
 150     wxMacMLTEControl( wxTextCtrl 
*peer 
) ; 
 152     virtual wxString 
GetStringValue() const ; 
 153     virtual void SetStringValue( const wxString 
&str 
) ; 
 155     static TXNFrameOptions 
FrameOptionsFromWXStyle( long wxStyle 
) ; 
 157     void AdjustCreationAttributes( const wxColour
& background
, bool visible 
) ; 
 159     virtual void SetFont( const wxFont 
& font
, const wxColour
& foreground
, long windowStyle 
) ; 
 160     virtual void SetBackground( const wxBrush 
&brush 
) ; 
 161     virtual void SetStyle( long start
, long end
, const wxTextAttr
& style 
) ; 
 162     virtual void Copy() ; 
 164     virtual void Paste() ; 
 165     virtual bool CanPaste() const ; 
 166     virtual void SetEditable( bool editable 
) ; 
 167     virtual wxTextPos 
GetLastPosition() const ; 
 168     virtual void Replace( long from
, long to
, const wxString 
&str 
) ; 
 169     virtual void Remove( long from
, long to 
) ; 
 170     virtual void GetSelection( long* from
, long* to 
) const ; 
 171     virtual void SetSelection( long from
, long to 
) ; 
 173     virtual void WriteText( const wxString
& str 
) ; 
 175     virtual bool HasOwnContextMenu() const 
 177 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 
 178         if ( UMAGetSystemVersion() >= 0x1040 ) 
 180             TXNCommandEventSupportOptions options 
; 
 181             TXNGetCommandEventSupport( m_txn 
, & options 
) ; 
 182             return options 
& kTXNSupportEditCommandProcessing 
; 
 189     virtual void CheckSpelling(bool check
) 
 191 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 
 192     TXNSetSpellCheckAsYouType( m_txn
, (Boolean
) check 
); 
 195     virtual void Clear() ; 
 197     virtual bool CanUndo() const ; 
 198     virtual void Undo() ; 
 199     virtual bool CanRedo()  const; 
 200     virtual void Redo() ; 
 201     virtual int GetNumberOfLines() const ; 
 202     virtual long XYToPosition(long x
, long y
) const ; 
 203     virtual bool PositionToXY(long pos
, long *x
, long *y
) const ; 
 204     virtual void ShowPosition( long pos 
) ; 
 205     virtual int GetLineLength(long lineNo
) const ; 
 206     virtual wxString 
GetLineText(long lineNo
) const ; 
 208     void SetTXNData( const wxString
& st 
, TXNOffset start 
, TXNOffset end 
) ; 
 209     TXNObject 
GetTXNObject() { return m_txn 
; } 
 212     void TXNSetAttribute( const wxTextAttr
& style 
, long from 
, long to 
) ; 
 217 // implementation available under OSX 
 219 class wxMacMLTEHIViewControl 
: public wxMacMLTEControl
 
 222     wxMacMLTEHIViewControl( wxTextCtrl 
*wxPeer
, 
 225                              const wxSize
& size
, long style 
) ; 
 226     virtual ~wxMacMLTEHIViewControl() ; 
 228     virtual OSStatus 
SetFocus( ControlFocusPart focusPart 
) ; 
 229     virtual bool HasFocus() const ; 
 230     virtual void SetBackground( const wxBrush 
&brush
) ; 
 233     HIViewRef m_scrollView 
; 
 234     HIViewRef m_textView 
; 
 237 // 'classic' MLTE implementation 
 239 class wxMacMLTEClassicControl 
: public wxMacMLTEControl
 
 242     wxMacMLTEClassicControl( wxTextCtrl 
*wxPeer
, 
 245                              const wxSize
& size
, long style 
) ; 
 246     virtual ~wxMacMLTEClassicControl() ; 
 248     virtual void VisibilityChanged(bool shown
) ; 
 249     virtual void SuperChangedPosition() ; 
 251     virtual void            MacControlUserPaneDrawProc(wxInt16 part
) ; 
 252     virtual wxInt16         
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ; 
 253     virtual wxInt16         
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ; 
 254     virtual void            MacControlUserPaneIdleProc() ; 
 255     virtual wxInt16         
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ; 
 256     virtual void            MacControlUserPaneActivateProc(bool activating
) ; 
 257     virtual wxInt16         
MacControlUserPaneFocusProc(wxInt16 action
) ; 
 258     virtual void            MacControlUserPaneBackgroundProc(void* info
) ; 
 260     virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) ) 
 262         MacControlUserPaneIdleProc(); 
 266     virtual void            SetRect( Rect 
*r 
) ; 
 271     void                    MacUpdatePosition() ; 
 272     void                    MacActivatePaneText(bool setActive
) ; 
 273     void                    MacFocusPaneText(bool setFocus
) ; 
 274     void                    MacSetObjectVisibility(bool vis
) ; 
 277     TXNFrameID              m_txnFrameID 
; 
 279     WindowRef               m_txnWindow 
; 
 280     // bounds of the control as we last did set the txn frames 
 281     Rect                    m_txnControlBounds 
; 
 282     Rect                    m_txnVisBounds 
; 
 284     static pascal void TXNScrollActionProc( ControlRef controlRef 
, ControlPartCode partCode 
) ; 
 285     static pascal void TXNScrollInfoProc( 
 286         SInt32 iValue
, SInt32 iMaximumValue
, 
 287         TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon 
) ; 
 289     ControlRef              m_sbHorizontal 
; 
 290     SInt32                  m_lastHorizontalValue 
; 
 291     ControlRef              m_sbVertical 
; 
 292     SInt32                  m_lastVerticalValue 
; 
 296 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxTextCtrlBase
) 
 298 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
) 
 299     EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground 
) 
 300     EVT_DROP_FILES(wxTextCtrl::OnDropFiles
) 
 301     EVT_CHAR(wxTextCtrl::OnChar
) 
 302     EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
) 
 303     EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
) 
 304     EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
) 
 305     EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
) 
 306     EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
) 
 307     EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
) 
 308     EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
) 
 310     EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
) 
 312     EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
) 
 313     EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
) 
 314     EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
) 
 315     EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
) 
 316     EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
) 
 317     EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
) 
 318     EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
) 
 322 void wxTextCtrl::Init() 
 328     m_privateContextMenu 
= NULL
; 
 329     m_triggerOnSetValue 
= true ; 
 332 wxTextCtrl::~wxTextCtrl() 
 334     delete m_privateContextMenu
; 
 337 bool wxTextCtrl::Create( wxWindow 
*parent
, 
 343     const wxValidator
& validator
, 
 344     const wxString
& name 
) 
 346     m_macIsUserPane 
= false ; 
 349     if ( ! (style 
& wxNO_BORDER
) ) 
 350         style 
= (style 
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER 
; 
 352     if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style 
& ~(wxHSCROLL 
| wxVSCROLL
), validator
, name 
) ) 
 355     if ( m_windowStyle 
& wxTE_MULTILINE 
) 
 357         // always turn on this style for multi-line controls 
 358         m_windowStyle 
|= wxTE_PROCESS_ENTER
; 
 359         style 
|= wxTE_PROCESS_ENTER 
; 
 362     CreatePeer( str
, pos
, size
, style 
); 
 364     MacPostControlCreate(pos
, size
) ; 
 366     // only now the embedding is correct and we can do a positioning update 
 368     MacSuperChangedPosition() ; 
 370     if ( m_windowStyle 
& wxTE_READONLY
) 
 371         SetEditable( false ) ; 
 373     SetCursor( wxCursor( wxCURSOR_IBEAM 
) ) ; 
 378 void wxTextCtrl::CreatePeer( 
 381            const wxSize
& size
, long style 
) 
 383     bool forceMLTE 
= false ; 
 385 #if wxUSE_SYSTEM_OPTIONS 
 386     if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE 
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE 
) == 1)) 
 392     if ( UMAGetSystemVersion() >= 0x1050 ) 
 397         if ( m_windowStyle 
& wxTE_MULTILINE 
) 
 398             m_peer 
= new wxMacMLTEHIViewControl( this , str 
, pos 
, size 
, style 
) ; 
 403         if ( !(m_windowStyle 
& wxTE_MULTILINE
) && !forceMLTE 
) 
 405             m_peer 
= new wxMacUnicodeTextControl( this , str 
, pos 
, size 
, style 
) ; 
 409     // the horizontal single line scrolling bug that made us keep the classic implementation 
 411 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 
 413         m_peer 
= new wxMacMLTEClassicControl( this , str 
, pos 
, size 
, style 
) ; 
 417 void wxTextCtrl::MacSuperChangedPosition() 
 419     wxWindow::MacSuperChangedPosition() ; 
 420     GetPeer()->SuperChangedPosition() ; 
 423 void wxTextCtrl::MacVisibilityChanged() 
 425     GetPeer()->VisibilityChanged( MacIsReallyShown() ) ; 
 428 void wxTextCtrl::MacEnabledStateChanged() 
 432 void wxTextCtrl::MacCheckSpelling(bool check
) 
 434     GetPeer()->CheckSpelling(check
); 
 437 wxString 
wxTextCtrl::GetValue() const 
 439     return GetPeer()->GetStringValue() ; 
 442 void wxTextCtrl::GetSelection(long* from
, long* to
) const 
 444     GetPeer()->GetSelection( from 
, to 
) ; 
 447 void wxTextCtrl::DoSetValue(const wxString
& str
, int flags
) 
 450     if ( GetValue() == str 
) 
 453     GetPeer()->SetStringValue( str 
) ; 
 455     if ( (flags 
& SetValue_SendEvent
) && m_triggerOnSetValue 
) 
 457         SendTextUpdatedEvent(); 
 461 void wxTextCtrl::SetMaxLength(unsigned long len
) 
 466 bool wxTextCtrl::SetFont( const wxFont
& font 
) 
 468     if ( !wxTextCtrlBase::SetFont( font 
) ) 
 471     GetPeer()->SetFont( font 
, GetForegroundColour() , GetWindowStyle() ) ; 
 476 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
) 
 478     GetPeer()->SetStyle( start 
, end 
, style 
) ; 
 483 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
) 
 485     wxTextCtrlBase::SetDefaultStyle( style 
) ; 
 486     SetStyle( kTXNUseCurrentSelection 
, kTXNUseCurrentSelection 
, GetDefaultStyle() ) ; 
 491 // Clipboard operations 
 493 void wxTextCtrl::Copy() 
 499 void wxTextCtrl::Cut() 
 505         wxCommandEvent 
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId 
); 
 506         event
.SetEventObject( this ); 
 507         GetEventHandler()->ProcessEvent( event 
); 
 511 void wxTextCtrl::Paste() 
 517         // TODO: eventually we should add setting the default style again 
 519         wxCommandEvent 
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId 
); 
 520         event
.SetEventObject( this ); 
 521         GetEventHandler()->ProcessEvent( event 
); 
 525 bool wxTextCtrl::CanCopy() const 
 527     // Can copy if there's a selection 
 529     GetSelection( &from
, &to 
); 
 534 bool wxTextCtrl::CanCut() const 
 539     // Can cut if there's a selection 
 541     GetSelection( &from
, &to 
); 
 546 bool wxTextCtrl::CanPaste() const 
 551     return GetPeer()->CanPaste() ; 
 554 void wxTextCtrl::SetEditable(bool editable
) 
 556     if ( editable 
!= m_editable 
) 
 558         m_editable 
= editable 
; 
 559         GetPeer()->SetEditable( editable 
) ; 
 563 void wxTextCtrl::SetInsertionPoint(long pos
) 
 565     SetSelection( pos 
, pos 
) ; 
 568 void wxTextCtrl::SetInsertionPointEnd() 
 570     wxTextPos pos 
= GetLastPosition(); 
 571     SetInsertionPoint( pos 
); 
 574 long wxTextCtrl::GetInsertionPoint() const 
 577     GetSelection( &begin 
, &end 
) ; 
 582 wxTextPos 
wxTextCtrl::GetLastPosition() const 
 584     return GetPeer()->GetLastPosition() ; 
 587 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
) 
 589     GetPeer()->Replace( from 
, to 
, str 
) ; 
 592 void wxTextCtrl::Remove(long from
, long to
) 
 594     GetPeer()->Remove( from 
, to 
) ; 
 597 void wxTextCtrl::SetSelection(long from
, long to
) 
 599     GetPeer()->SetSelection( from 
, to 
) ; 
 602 void wxTextCtrl::WriteText(const wxString
& str
) 
 604     // TODO: this MPRemoting will be moved into a remoting peer proxy for any command 
 605     if ( !wxIsMainThread() ) 
 607         // unfortunately CW 8 is not able to correctly deduce the template types, 
 608         // so we have to instantiate explicitly 
 609         wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText 
, str 
) ; 
 614     GetPeer()->WriteText( str 
) ; 
 617 void wxTextCtrl::AppendText(const wxString
& text
) 
 619     SetInsertionPointEnd(); 
 623 void wxTextCtrl::Clear() 
 628 bool wxTextCtrl::IsModified() const 
 633 bool wxTextCtrl::IsEditable() const 
 635     return IsEnabled() && m_editable 
; 
 638 bool wxTextCtrl::AcceptsFocus() const 
 640     // we don't want focus if we can't be edited 
 641     return /*IsEditable() && */ wxControl::AcceptsFocus(); 
 644 wxSize 
wxTextCtrl::DoGetBestSize() const 
 648     // these are the numbers from the HIG: 
 649     // we reduce them by the borders first 
 652     switch ( m_windowVariant 
) 
 654         case wxWINDOW_VARIANT_NORMAL 
: 
 658         case wxWINDOW_VARIANT_SMALL 
: 
 662         case wxWINDOW_VARIANT_MINI 
: 
 671     // as the above numbers have some free space around the text 
 672     // we get 5 lines like this anyway 
 673     if ( m_windowStyle 
& wxTE_MULTILINE 
) 
 676     if ( !HasFlag(wxNO_BORDER
) ) 
 679     return wxSize(wText
, hText
); 
 682 // ---------------------------------------------------------------------------- 
 684 // ---------------------------------------------------------------------------- 
 686 void wxTextCtrl::Undo() 
 692 void wxTextCtrl::Redo() 
 698 bool wxTextCtrl::CanUndo() const 
 703     return GetPeer()->CanUndo() ; 
 706 bool wxTextCtrl::CanRedo() const 
 711     return GetPeer()->CanRedo() ; 
 714 void wxTextCtrl::MarkDirty() 
 719 void wxTextCtrl::DiscardEdits() 
 724 int wxTextCtrl::GetNumberOfLines() const 
 726     return GetPeer()->GetNumberOfLines() ; 
 729 long wxTextCtrl::XYToPosition(long x
, long y
) const 
 731     return GetPeer()->XYToPosition( x 
, y 
) ; 
 734 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const 
 736     return GetPeer()->PositionToXY( pos 
, x 
, y 
) ; 
 739 void wxTextCtrl::ShowPosition(long pos
) 
 741     return GetPeer()->ShowPosition(pos
) ; 
 744 int wxTextCtrl::GetLineLength(long lineNo
) const 
 746     return GetPeer()->GetLineLength(lineNo
) ; 
 749 wxString 
wxTextCtrl::GetLineText(long lineNo
) const 
 751     return GetPeer()->GetLineText(lineNo
) ; 
 754 void wxTextCtrl::Command(wxCommandEvent 
& event
) 
 756     SetValue(event
.GetString()); 
 757     ProcessCommand(event
); 
 760 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
) 
 762     // By default, load the first file into the text window. 
 763     if (event
.GetNumberOfFiles() > 0) 
 764         LoadFile( event
.GetFiles()[0] ); 
 767 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
) 
 769     // all erasing should be done by the real mac control implementation 
 770     // while this is true for MLTE under classic, the HITextView is somehow 
 771     // transparent but background erase is not working correctly, so intercept 
 772     // things while we can... 
 776 void wxTextCtrl::OnChar(wxKeyEvent
& event
) 
 778     int key 
= event
.GetKeyCode() ; 
 779     bool eat_key 
= false ; 
 781     if ( key 
== 'a' && event
.MetaDown() ) 
 788     if ( key 
== 'c' && event
.MetaDown() ) 
 796     if ( !IsEditable() && key 
!= WXK_LEFT 
&& key 
!= WXK_RIGHT 
&& key 
!= WXK_DOWN 
&& key 
!= WXK_UP 
&& key 
!= WXK_TAB 
&& 
 797         !( key 
== WXK_RETURN 
&& ( (m_windowStyle 
& wxTE_PROCESS_ENTER
) || (m_windowStyle 
& wxTE_MULTILINE
) ) ) 
 798 //        && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END 
 805     // Check if we have reached the max # of chars (if it is set), but still 
 806     // allow navigation and deletion 
 807     if ( !IsMultiLine() && m_maxLength 
&& GetValue().length() >= m_maxLength 
&& 
 808         key 
!= WXK_LEFT 
&& key 
!= WXK_RIGHT 
&& key 
!= WXK_TAB 
&& 
 809         key 
!= WXK_BACK 
&& !( key 
== WXK_RETURN 
&& (m_windowStyle 
& wxTE_PROCESS_ENTER
) ) 
 812         // eat it, we don't want to add more than allowed # of characters 
 814         // TODO: generate EVT_TEXT_MAXLEN() 
 818     // assume that any key not processed yet is going to modify the control 
 821     if ( key 
== 'v' && event
.MetaDown() ) 
 829     if ( key 
== 'x' && event
.MetaDown() ) 
 840             if (m_windowStyle 
& wxTE_PROCESS_ENTER
) 
 842                 wxCommandEvent 
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
); 
 843                 event
.SetEventObject( this ); 
 844                 event
.SetString( GetValue() ); 
 845                 if ( GetEventHandler()->ProcessEvent(event
) ) 
 849             if ( !(m_windowStyle 
& wxTE_MULTILINE
) ) 
 851                 wxTopLevelWindow 
*tlw 
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
); 
 852                 if ( tlw 
&& tlw
->GetDefaultItem() ) 
 854                     wxButton 
*def 
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
); 
 855                     if ( def 
&& def
->IsEnabled() ) 
 857                         wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() ); 
 858                         event
.SetEventObject(def
); 
 865                 // this will make wxWidgets eat the ENTER key so that 
 866                 // we actually prevent line wrapping in a single line text control 
 872             if ( !(m_windowStyle 
& wxTE_PROCESS_TAB
)) 
 875                 if (!event
.ShiftDown()) 
 876                     flags 
|= wxNavigationKeyEvent::IsForward 
; 
 877                 if (event
.ControlDown()) 
 878                     flags 
|= wxNavigationKeyEvent::WinChange 
; 
 885                 // This is necessary (don't know why); 
 886                 // otherwise the tab will not be inserted. 
 887                 WriteText(wxT("\t")); 
 898         // perform keystroke handling 
 902     if ( ( key 
>= 0x20 && key 
< WXK_START 
) || 
 903          ( key 
>= WXK_NUMPAD0 
&& key 
<= WXK_DIVIDE 
) || 
 908         wxCommandEvent 
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
); 
 909         event1
.SetEventObject( this ); 
 910         wxPostEvent( GetEventHandler(), event1 
); 
 914 // ---------------------------------------------------------------------------- 
 915 // standard handlers for standard edit menu events 
 916 // ---------------------------------------------------------------------------- 
 918 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
)) 
 923 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
)) 
 928 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
)) 
 933 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
)) 
 938 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
)) 
 943 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
)) 
 947     GetSelection( &from
, &to 
); 
 948     if (from 
!= -1 && to 
!= -1) 
 952 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
)) 
 954     SetSelection(-1, -1); 
 957 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
) 
 959     event
.Enable( CanCut() ); 
 962 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
) 
 964     event
.Enable( CanCopy() ); 
 967 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
) 
 969     event
.Enable( CanPaste() ); 
 972 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
) 
 974     event
.Enable( CanUndo() ); 
 977 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
) 
 979     event
.Enable( CanRedo() ); 
 982 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
) 
 986     GetSelection( &from
, &to 
); 
 987     event
.Enable( from 
!= -1 && to 
!= -1 && from 
!= to 
&& IsEditable() ) ; 
 990 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
) 
 992     event
.Enable(GetLastPosition() > 0); 
 995 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment 
 997 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
) 
 999     if ( GetPeer()->HasOwnContextMenu() ) 
1005     if (m_privateContextMenu 
== NULL
) 
1007         m_privateContextMenu 
= new wxMenu
; 
1008         m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo")); 
1009         m_privateContextMenu
->Append(wxID_REDO
, _("&Redo")); 
1010         m_privateContextMenu
->AppendSeparator(); 
1011         m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t")); 
1012         m_privateContextMenu
->Append(wxID_COPY
, _("&Copy")); 
1013         m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste")); 
1014         m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete")); 
1015         m_privateContextMenu
->AppendSeparator(); 
1016         m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All")); 
1019     if (m_privateContextMenu 
!= NULL
) 
1020         PopupMenu(m_privateContextMenu
); 
1023 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt 
) 
1025     if ( !GetPeer()->SetupCursor( pt 
) ) 
1026         return wxWindow::MacSetupCursor( pt 
) ; 
1031 #if !TARGET_API_MAC_OSX 
1033 // user pane implementation 
1035 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
) 
1037     GetPeer()->MacControlUserPaneDrawProc( part 
) ; 
1040 wxInt16 
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) 
1042     return GetPeer()->MacControlUserPaneHitTestProc( x 
, y 
) ; 
1045 wxInt16 
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) 
1047     return GetPeer()->MacControlUserPaneTrackingProc( x 
, y 
, actionProc 
) ; 
1050 void wxTextCtrl::MacControlUserPaneIdleProc() 
1052     GetPeer()->MacControlUserPaneIdleProc( ) ; 
1055 wxInt16 
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) 
1057     return GetPeer()->MacControlUserPaneKeyDownProc( keyCode 
, charCode 
, modifiers 
) ; 
1060 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
) 
1062     GetPeer()->MacControlUserPaneActivateProc( activating 
) ; 
1065 wxInt16 
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
) 
1067     return GetPeer()->MacControlUserPaneFocusProc( action 
) ; 
1070 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
) 
1072     GetPeer()->MacControlUserPaneBackgroundProc( info 
) ; 
1077 // ---------------------------------------------------------------------------- 
1078 // implementation base class 
1079 // ---------------------------------------------------------------------------- 
1081 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) : 
1082     wxMacControl( peer 
) 
1086 wxMacTextControl::~wxMacTextControl() 
1090 void wxMacTextControl::SetStyle(long WXUNUSED(start
), 
1092                                 const wxTextAttr
& WXUNUSED(style
)) 
1096 void wxMacTextControl::Copy() 
1100 void wxMacTextControl::Cut() 
1104 void wxMacTextControl::Paste() 
1108 bool wxMacTextControl::CanPaste() const 
1113 void wxMacTextControl::SetEditable(bool WXUNUSED(editable
)) 
1117 wxTextPos 
wxMacTextControl::GetLastPosition() const 
1119     return GetStringValue().length() ; 
1122 void wxMacTextControl::Replace( long from 
, long to 
, const wxString 
&val 
) 
1124     SetSelection( from 
, to 
) ; 
1128 void wxMacTextControl::Remove( long from 
, long to 
) 
1130     SetSelection( from 
, to 
) ; 
1131     WriteText( wxEmptyString
) ; 
1134 void wxMacTextControl::Clear() 
1136     SetStringValue( wxEmptyString 
) ; 
1139 bool wxMacTextControl::CanUndo() const 
1144 void wxMacTextControl::Undo() 
1148 bool wxMacTextControl::CanRedo()  const 
1153 void wxMacTextControl::Redo() 
1157 long wxMacTextControl::XYToPosition(long WXUNUSED(x
), long WXUNUSED(y
)) const 
1162 bool wxMacTextControl::PositionToXY(long WXUNUSED(pos
), 
1164                                     long *WXUNUSED(y
)) const 
1169 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) ) 
1173 int wxMacTextControl::GetNumberOfLines() const 
1175     ItemCount lines 
= 0 ; 
1176     wxString content 
= GetStringValue() ; 
1179     for (size_t i 
= 0; i 
< content
.length() ; i
++) 
1181         if (content
[i
] == '\r') 
1188 wxString 
wxMacTextControl::GetLineText(long lineNo
) const 
1190     // TODO: change this if possible to reflect real lines 
1191     wxString content 
= GetStringValue() ; 
1195     for (size_t i 
= 0; i 
< content
.length() ; i
++) 
1197         if (count 
== lineNo
) 
1199             // Add chars in line then 
1202             for (size_t j 
= i
; j 
< content
.length(); j
++) 
1204                 if (content
[j
] == '\n') 
1213         if (content
[i
] == '\n') 
1217     return wxEmptyString 
; 
1220 int wxMacTextControl::GetLineLength(long lineNo
) const 
1222     // TODO: change this if possible to reflect real lines 
1223     wxString content 
= GetStringValue() ; 
1227     for (size_t i 
= 0; i 
< content
.length() ; i
++) 
1229         if (count 
== lineNo
) 
1231             // Count chars in line then 
1233             for (size_t j 
= i
; j 
< content
.length(); j
++) 
1236                 if (content
[j
] == '\n') 
1243         if (content
[i
] == '\n') 
1250 // ---------------------------------------------------------------------------- 
1251 // standard unicode control implementation 
1252 // ---------------------------------------------------------------------------- 
1254 #if TARGET_API_MAC_OSX 
1256 // the current unicode textcontrol implementation has a bug : only if the control 
1257 // is currently having the focus, the selection can be retrieved by the corresponding 
1258 // data tag. So we have a mirroring using a member variable 
1259 // TODO : build event table using virtual member functions for wxMacControl 
1261 static const EventTypeSpec unicodeTextControlEventList
[] = 
1263     { kEventClassControl 
, kEventControlSetFocusPart 
} , 
1266 static pascal OSStatus 
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
1268     OSStatus result 
= eventNotHandledErr 
; 
1269     wxMacUnicodeTextControl
* focus 
= (wxMacUnicodeTextControl
*) data 
; 
1270     wxMacCarbonEvent 
cEvent( event 
) ; 
1272     switch ( GetEventKind( event 
) ) 
1274         case kEventControlSetFocusPart 
: 
1276             ControlPartCode controlPart 
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart 
, typeControlPartCode 
); 
1277             if ( controlPart 
== kControlFocusNoPart 
) 
1279                 // about to loose focus -> store selection to field 
1280                 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection 
); 
1282             result 
= CallNextEventHandler(handler
,event
) ; 
1283             if ( controlPart 
!= kControlFocusNoPart 
) 
1285                 // about to gain focus -> set selection from field 
1286                 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection 
); 
1297 static pascal OSStatus 
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
1299     OSStatus result 
= eventNotHandledErr 
; 
1301     switch ( GetEventClass( event 
) ) 
1303         case kEventClassControl 
: 
1304             result 
= wxMacUnicodeTextControlControlEventHandler( handler 
, event 
, data 
) ; 
1313 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler 
) 
1315 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl 
*wxPeer 
) : wxMacTextControl( wxPeer 
) 
1319 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl 
*wxPeer
, 
1320     const wxString
& str
, 
1322     const wxSize
& size
, long style 
) 
1323     : wxMacTextControl( wxPeer 
) 
1325     Create( wxPeer
, str
, pos
, size
, style 
); 
1328 bool wxMacUnicodeTextControl::Create( wxTextCtrl 
*wxPeer
, 
1329     const wxString
& str
, 
1331     const wxSize
& size
, long style 
) 
1333     m_font 
= wxPeer
->GetFont() ; 
1334     m_windowStyle 
= style 
; 
1335     m_selection
.selStart 
= m_selection
.selEnd 
= 0; 
1336     Rect bounds 
= wxMacGetBoundsForControl( wxPeer 
, pos 
, size 
) ; 
1338     wxMacConvertNewlines10To13( &st 
) ; 
1339     wxMacCFStringHolder 
cf(st 
, m_font
.GetEncoding()) ; 
1340     CFStringRef cfr 
= cf 
; 
1342     m_valueTag 
= kControlEditTextCFStringTag 
; 
1343     CreateControl( wxPeer
, &bounds
, cfr 
); 
1345     if ( !(m_windowStyle 
& wxTE_MULTILINE
) ) 
1346         SetData
<Boolean
>( kControlEditTextPart 
, kControlEditTextSingleLineTag 
, true ) ; 
1348     InstallControlEventHandler( m_controlRef 
, GetwxMacUnicodeTextControlEventHandlerUPP(), 
1349                                 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this, 
1355 wxMacUnicodeTextControl::~wxMacUnicodeTextControl() 
1359 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
) 
1361     if ( !(m_windowStyle 
& wxTE_MULTILINE
) && shown 
) 
1363         // work around a refresh issue insofar as not always the entire content is shown, 
1364         // even if this would be possible 
1365         ControlEditTextSelectionRec sel 
; 
1366         CFStringRef value 
= NULL 
; 
1368         verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel 
) ); 
1369         verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value 
) ); 
1370         verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value 
) ); 
1371         verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel 
) ); 
1373         CFRelease( value 
) ; 
1377 wxString 
wxMacUnicodeTextControl::GetStringValue() const 
1380     CFStringRef value 
= GetData
<CFStringRef
>(0, m_valueTag
) ; 
1383         wxMacCFStringHolder 
cf(value
) ; 
1384         result 
= cf
.AsString() ; 
1388     wxMacConvertNewlines13To10( &result 
) ; 
1390     wxMacConvertNewlines10To13( &result 
) ; 
1396 void wxMacUnicodeTextControl::SetStringValue( const wxString 
&str 
) 
1399     wxMacConvertNewlines10To13( &st 
) ; 
1400     wxMacCFStringHolder 
cf( st 
, m_font
.GetEncoding() ) ; 
1401     verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag 
, cf 
) ) ; 
1404 void wxMacUnicodeTextControl::CreateControl( wxTextCtrl
* peer
, const Rect
* bounds
, CFStringRef cfr 
) 
1406     Boolean isPassword 
= ( m_windowStyle 
& wxTE_PASSWORD 
) != 0 ; 
1409         m_valueTag 
= kControlEditTextPasswordCFStringTag 
; 
1411     OSStatus err 
= CreateEditUnicodeTextControl( 
1412         MAC_WXHWND(peer
->MacGetTopLevelWindowRef()), bounds 
, cfr 
, 
1413         isPassword 
, NULL 
, &m_controlRef 
) ; 
1414     verify_noerr( err 
); 
1417 void wxMacUnicodeTextControl::Copy() 
1419     SendHICommand( kHICommandCopy 
) ; 
1422 void wxMacUnicodeTextControl::Cut() 
1424     SendHICommand( kHICommandCut 
) ; 
1427 void wxMacUnicodeTextControl::Paste() 
1429     SendHICommand( kHICommandPaste 
) ; 
1432 bool wxMacUnicodeTextControl::CanPaste() const 
1437 void wxMacUnicodeTextControl::SetEditable(bool WXUNUSED(editable
)) 
1439 #if 0 // leads to problem because text cannot be selected anymore 
1440     SetData
<Boolean
>( kControlEditTextPart 
, kControlEditTextLockedTag 
, (Boolean
) !editable 
) ; 
1444 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to 
) const 
1446     ControlEditTextSelectionRec sel 
; 
1448         verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel 
) ) ; 
1453         *from 
= sel
.selStart 
; 
1458 void wxMacUnicodeTextControl::SetSelection( long from 
, long to 
) 
1460     ControlEditTextSelectionRec sel 
; 
1462     int textLength 
= 0 ; 
1463     CFStringRef value 
= GetData
<CFStringRef
>(0, m_valueTag
) ; 
1466         wxMacCFStringHolder 
cf(value
) ; 
1467         textLength 
= cf
.AsString().length() ; 
1470     if ((from 
== -1) && (to 
== -1)) 
1477         from 
= wxMin(textLength
,wxMax(from
,0)) ; 
1478         to 
= wxMax(0,wxMin(textLength
,to
)) ; 
1481     sel
.selStart 
= from 
; 
1484         SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel 
) ; 
1489 void wxMacUnicodeTextControl::WriteText( const wxString
& str 
) 
1492     wxMacConvertNewlines10To13( &st 
) ; 
1496         wxMacCFStringHolder 
cf(st 
, m_font
.GetEncoding() ) ; 
1497         CFStringRef value 
= cf 
; 
1498         SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value 
); 
1502         wxString val 
= GetStringValue() ; 
1504         GetSelection( &start 
, &end 
) ; 
1505         val
.Remove( start 
, end 
- start 
) ; 
1506         val
.insert( start 
, str 
) ; 
1507         SetStringValue( val 
) ; 
1508         SetSelection( start 
+ str
.length() , start 
+ str
.length() ) ; 
1514 // ---------------------------------------------------------------------------- 
1515 // MLTE control implementation (common part) 
1516 // ---------------------------------------------------------------------------- 
1518 // if MTLE is read only, no changes at all are allowed, not even from 
1519 // procedural API, in order to allow changes via API all the same we must undo 
1520 // the readonly status while we are executing, this class helps to do so 
1522 class wxMacEditHelper
 
1525     wxMacEditHelper( TXNObject txn 
) 
1527         TXNControlTag tag
[] = { kTXNIOPrivilegesTag 
} ; 
1529         TXNGetTXNObjectControls( m_txn 
, 1 , tag 
, m_data 
) ; 
1530         if ( m_data
[0].uValue 
== kTXNReadOnly 
) 
1532             TXNControlData data
[] = { { kTXNReadWrite 
} } ; 
1533             TXNSetTXNObjectControls( m_txn 
, false , 1 , tag 
, data 
) ; 
1539         TXNControlTag tag
[] = { kTXNIOPrivilegesTag 
} ; 
1540         if ( m_data
[0].uValue 
== kTXNReadOnly 
) 
1541             TXNSetTXNObjectControls( m_txn 
, false , 1 , tag 
, m_data 
) ; 
1546     TXNControlData m_data
[1] ; 
1549 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl 
*peer 
) 
1550     : wxMacTextControl( peer 
) 
1552     SetNeedsFocusRect( true ) ; 
1555 wxString 
wxMacMLTEControl::GetStringValue() const 
1559     Size actualSize 
= 0; 
1564         err 
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData 
); 
1573             actualSize 
= GetHandleSize( theText 
) / sizeof(UniChar
) ; 
1574             if ( actualSize 
> 0 ) 
1576                 wxChar 
*ptr 
= NULL 
; 
1578 #if SIZEOF_WCHAR_T == 2 
1579                 ptr 
= new wxChar
[actualSize 
+ 1] ; 
1580                 wxStrncpy( ptr 
, (wxChar
*)(*theText
) , actualSize 
) ; 
1582                 SetHandleSize( theText
, (actualSize 
+ 1) * sizeof(UniChar
) ) ; 
1584                 (((UniChar
*)*theText
)[actualSize
]) = 0 ; 
1585                 wxMBConvUTF16 converter 
; 
1586                 size_t noChars 
= converter
.MB2WC( NULL 
, (const char*)*theText 
, 0 ) ; 
1587                 wxASSERT_MSG( noChars 
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") ); 
1588                 ptr 
= new wxChar
[noChars 
+ 1] ; 
1590                 noChars 
= converter
.MB2WC( ptr 
, (const char*)*theText 
, noChars 
+ 1 ) ; 
1591                 wxASSERT_MSG( noChars 
!= wxCONV_FAILED
, _T("Conversion of string failed!") ); 
1593                 HUnlock( theText 
) ; 
1596                 ptr
[actualSize
] = 0 ; 
1597                 result 
= wxString( ptr 
) ; 
1601             DisposeHandle( theText 
) ; 
1605         err 
= TXNGetDataEncoded( m_txn 
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData 
); 
1614             actualSize 
= GetHandleSize( theText 
) ; 
1615             if ( actualSize 
> 0 ) 
1618                 result 
= wxString( *theText 
, wxConvLocal 
, actualSize 
) ; 
1619                 HUnlock( theText 
) ; 
1622             DisposeHandle( theText 
) ; 
1628     wxMacConvertNewlines13To10( &result 
) ; 
1630     wxMacConvertNewlines10To13( &result 
) ; 
1636 void wxMacMLTEControl::SetStringValue( const wxString 
&str 
) 
1639     wxMacConvertNewlines10To13( &st 
); 
1643         wxMacWindowClipper 
c( m_peer 
) ; 
1647             wxMacEditHelper 
help( m_txn 
); 
1648             SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset 
); 
1651         TXNSetSelection( m_txn
, 0, 0 ); 
1652         TXNShowSelection( m_txn
, kTXNShowStart 
); 
1656 TXNFrameOptions 
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle 
) 
1658     TXNFrameOptions frameOptions 
= kTXNDontDrawCaretWhenInactiveMask
; 
1660     frameOptions 
|= kTXNDoFontSubstitutionMask
; 
1662     if ( ! (wxStyle 
& wxTE_NOHIDESEL
) ) 
1663         frameOptions 
|= kTXNDontDrawSelectionWhenInactiveMask 
; 
1665     if ( wxStyle 
& (wxHSCROLL 
| wxTE_DONTWRAP
) ) 
1666         frameOptions 
|= kTXNWantHScrollBarMask 
; 
1668     if ( wxStyle 
& wxTE_MULTILINE 
) 
1670         frameOptions 
|= kTXNAlwaysWrapAtViewEdgeMask 
; 
1672         if ( !(wxStyle 
& wxTE_NO_VSCROLL
) ) 
1674             frameOptions 
|= kTXNWantVScrollBarMask 
; 
1676             // The following code causes drawing problems on 10.4. Perhaps it can be restored for 
1677             // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here 
1678             // anyways, as AFAIK users can't actually use it to resize the text ctrl. 
1679 //            if ( frameOptions & kTXNWantHScrollBarMask ) 
1680 //                frameOptions |= kTXNDrawGrowIconMask ; 
1685         frameOptions 
|= kTXNSingleLineOnlyMask 
; 
1688     return frameOptions 
; 
1691 void wxMacMLTEControl::AdjustCreationAttributes(const wxColour 
&background
, 
1692                                                 bool WXUNUSED(visible
)) 
1694     TXNControlTag iControlTags
[] = 
1696             kTXNDoFontSubstitution
, 
1697             kTXNWordWrapStateTag 
, 
1699     TXNControlData iControlData
[] = 
1705     int toptag 
= WXSIZEOF( iControlTags 
) ; 
1707     if ( m_windowStyle 
& wxTE_MULTILINE 
) 
1709         iControlData
[1].uValue 
= 
1710             (m_windowStyle 
& wxTE_DONTWRAP
) 
1715     OSStatus err 
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData 
) ; 
1716     verify_noerr( err 
); 
1718     // setting the default font: 
1719     // under 10.2 this causes a visible caret, therefore we avoid it 
1725     GetThemeFont( kThemeSystemFont 
, GetApplicationScript() , fontName 
, &fontSize 
, &fontStyle 
) ; 
1727     TXNTypeAttributes typeAttr
[] = 
1729         { kTXNQDFontNameAttribute 
, kTXNQDFontNameAttributeSize 
, { (void*) fontName 
} } , 
1730         { kTXNQDFontSizeAttribute 
, kTXNFontSizeAttributeSize 
, { (void*) (fontSize 
<< 16) } } , 
1731         { kTXNQDFontStyleAttribute 
, kTXNQDFontStyleAttributeSize 
, { (void*) normal 
} } , 
1734     err 
= TXNSetTypeAttributes( 
1735         m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
), 
1736         typeAttr
, kTXNStartOffset
, kTXNEndOffset 
); 
1737     verify_noerr( err 
); 
1739     if ( m_windowStyle 
& wxTE_PASSWORD 
) 
1741         UniChar c 
= 0x00A5 ; 
1742         err 
= TXNEchoMode( m_txn 
, c 
, 0 , true ); 
1743         verify_noerr( err 
); 
1746     TXNBackground tback
; 
1747     tback
.bgType 
= kTXNBackgroundTypeRGB
; 
1748     tback
.bg
.color 
= MAC_WXCOLORREF( background
.GetPixel() ); 
1749     TXNSetBackground( m_txn 
, &tback 
); 
1751 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 
1752     if ( UMAGetSystemVersion() >= 0x1040 ) 
1754         TXNCommandEventSupportOptions options 
; 
1755         if ( TXNGetCommandEventSupport( m_txn
, &options 
) == noErr 
) 
1758                 kTXNSupportEditCommandProcessing
 
1759                 | kTXNSupportEditCommandUpdating
 
1760                 | kTXNSupportFontCommandProcessing
 
1761                 | kTXNSupportFontCommandUpdating
; 
1763             // only spell check when not read-only  
1764             // use system options for the default 
1765             bool checkSpelling 
= false ;  
1766             if ( !(m_windowStyle 
& wxTE_READONLY
) ) 
1768 #if wxUSE_SYSTEM_OPTIONS 
1769                 if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER 
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER 
) == 1) ) 
1771                     checkSpelling 
= true ; 
1776             if ( checkSpelling 
) 
1778                     kTXNSupportSpellCheckCommandProcessing
 
1779                     | kTXNSupportSpellCheckCommandUpdating
;               
1781             TXNSetCommandEventSupport( m_txn 
, options 
) ; 
1787 void wxMacMLTEControl::SetBackground( const wxBrush 
&brush 
) 
1789     // currently only solid background are supported 
1790     TXNBackground tback
; 
1792     tback
.bgType 
= kTXNBackgroundTypeRGB
; 
1793     tback
.bg
.color 
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() ); 
1794     TXNSetBackground( m_txn 
, &tback 
); 
1797 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style 
, long from 
, long to 
) 
1799     TXNTypeAttributes typeAttr
[4] ; 
1801     size_t typeAttrCount 
= 0 ; 
1804     TXNControlTag    controlTags
[4]; 
1805     TXNControlData   controlData
[4]; 
1806     size_t controlAttrCount 
= 0; 
1808     TXNTab
* tabs 
= NULL
; 
1810     bool relayout 
= false; 
1812     if ( style
.HasFont() ) 
1814         wxASSERT( typeAttrCount 
< WXSIZEOF(typeAttr
) ); 
1815         const wxFont 
&font 
= style
.GetFont() ; 
1816         typeAttr
[typeAttrCount
].tag 
= kTXNATSUIStyle 
; 
1817         typeAttr
[typeAttrCount
].size 
= kTXNATSUIStyleSize 
; 
1818         typeAttr
[typeAttrCount
].data
.dataPtr 
= font
.MacGetATSUStyle() ; 
1822     if ( style
.HasTextColour() ) 
1824         wxASSERT( typeAttrCount 
< WXSIZEOF(typeAttr
) ); 
1825         color 
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ; 
1827         typeAttr
[typeAttrCount
].tag 
= kTXNQDFontColorAttribute 
; 
1828         typeAttr
[typeAttrCount
].size 
= kTXNQDFontColorAttributeSize 
; 
1829         typeAttr
[typeAttrCount
].data
.dataPtr 
= (void*) &color 
; 
1833     if ( style
.HasAlignment() ) 
1835         wxASSERT( controlAttrCount 
< WXSIZEOF(controlTags
) ); 
1838         switch ( style
.GetAlignment() ) 
1840             case wxTEXT_ALIGNMENT_LEFT
: 
1841                 align 
= kTXNFlushLeft
; 
1843             case wxTEXT_ALIGNMENT_CENTRE
: 
1846             case wxTEXT_ALIGNMENT_RIGHT
: 
1847                 align 
= kTXNFlushRight
; 
1849             case wxTEXT_ALIGNMENT_JUSTIFIED
: 
1850                 align 
= kTXNFullJust
; 
1853             case wxTEXT_ALIGNMENT_DEFAULT
: 
1854                 align 
= kTXNFlushDefault
; 
1858         controlTags
[controlAttrCount
] = kTXNJustificationTag 
; 
1859         controlData
[controlAttrCount
].sValue 
= align 
; 
1860         controlAttrCount
++ ; 
1863     if ( style
.HasLeftIndent() || style
.HasRightIndent() ) 
1865         wxASSERT( controlAttrCount 
< WXSIZEOF(controlTags
) ); 
1866         controlTags
[controlAttrCount
] = kTXNMarginsTag
; 
1867         controlData
[controlAttrCount
].marginsPtr 
= &margins
; 
1868         verify_noerr( TXNGetTXNObjectControls (m_txn
, 1 , 
1869                                 &controlTags
[controlAttrCount
], &controlData
[controlAttrCount
]) ); 
1870         if ( style
.HasLeftIndent() ) 
1872             margins
.leftMargin 
= style
.GetLeftIndent() / 254.0 * 72 + 0.5; 
1874         if ( style
.HasRightIndent() ) 
1876             margins
.rightMargin 
= style
.GetRightIndent() / 254.0 * 72 + 0.5; 
1878         controlAttrCount
++ ; 
1881     if ( style
.HasTabs() ) 
1883         const wxArrayInt
& tabarray 
= style
.GetTabs(); 
1884         // unfortunately Mac only applies a tab distance, not individually different tabs 
1885         controlTags
[controlAttrCount
] = kTXNTabSettingsTag
; 
1886         if ( tabarray
.size() > 0 ) 
1887             controlData
[controlAttrCount
].tabValue
.value 
= tabarray
[0] / 254.0 * 72 + 0.5; 
1889             controlData
[controlAttrCount
].tabValue
.value 
= 72 ;  
1891         controlData
[controlAttrCount
].tabValue
.tabType 
= kTXNLeftTab
; 
1892         controlAttrCount
++ ; 
1895     // unfortunately the relayout is not automatic 
1896     if ( controlAttrCount 
> 0 ) 
1898         verify_noerr( TXNSetTXNObjectControls (m_txn
, false /* don't clear all */, controlAttrCount
, 
1899                                 controlTags
, controlData
) ); 
1903     if ( typeAttrCount 
> 0 ) 
1905         verify_noerr( TXNSetTypeAttributes( m_txn 
, typeAttrCount
, typeAttr
, from 
, to 
) ); 
1916         TXNRecalcTextLayout( m_txn 
); 
1920 void wxMacMLTEControl::SetFont(const wxFont 
& font
, 
1921                                const wxColour
& foreground
, 
1922                                long WXUNUSED(windowStyle
)) 
1924     wxMacEditHelper 
help( m_txn 
) ; 
1925     TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font 
), kTXNStartOffset
, kTXNEndOffset 
) ; 
1928 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style 
) 
1930     wxMacEditHelper 
help( m_txn 
) ; 
1931     TXNSetAttribute( style
, start
, end 
) ; 
1934 void wxMacMLTEControl::Copy() 
1939 void wxMacMLTEControl::Cut() 
1944 void wxMacMLTEControl::Paste() 
1949 bool wxMacMLTEControl::CanPaste() const 
1951     return TXNIsScrapPastable() ; 
1954 void wxMacMLTEControl::SetEditable(bool editable
) 
1956     TXNControlTag tag
[] = { kTXNIOPrivilegesTag 
} ; 
1957     TXNControlData data
[] = { { editable 
? kTXNReadWrite 
: kTXNReadOnly 
} } ; 
1958     TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data 
) ; 
1961 wxTextPos 
wxMacMLTEControl::GetLastPosition() const 
1963     wxTextPos actualsize 
= 0 ; 
1966     OSErr err 
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData 
); 
1971         actualsize 
= GetHandleSize( theText 
) ; 
1972         DisposeHandle( theText 
) ; 
1982 void wxMacMLTEControl::Replace( long from 
, long to 
, const wxString 
&str 
) 
1984     wxString value 
= str 
; 
1985     wxMacConvertNewlines10To13( &value 
) ; 
1987     wxMacEditHelper 
help( m_txn 
) ; 
1989     wxMacWindowClipper 
c( m_peer 
) ; 
1992     TXNSetSelection( m_txn
, from
, to 
) ; 
1994     SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection 
) ; 
1997 void wxMacMLTEControl::Remove( long from 
, long to 
) 
2000     wxMacWindowClipper 
c( m_peer 
) ; 
2002     wxMacEditHelper 
help( m_txn 
) ; 
2003     TXNSetSelection( m_txn 
, from 
, to 
) ; 
2007 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const 
2010     TXNGetSelection( m_txn 
, &f 
, &t 
) ; 
2015 void wxMacMLTEControl::SetSelection( long from 
, long to 
) 
2018     wxMacWindowClipper 
c( m_peer 
) ; 
2021     // change the selection 
2022     if ((from 
== -1) && (to 
== -1)) 
2023         TXNSelectAll( m_txn 
); 
2025         TXNSetSelection( m_txn
, from
, to 
); 
2027     TXNShowSelection( m_txn
, kTXNShowStart 
); 
2030 void wxMacMLTEControl::WriteText( const wxString
& str 
) 
2033     wxMacConvertNewlines10To13( &st 
) ; 
2035     long start 
, end 
, dummy 
; 
2037     GetSelection( &start 
, &dummy 
) ; 
2039     wxMacWindowClipper 
c( m_peer 
) ; 
2043         wxMacEditHelper 
helper( m_txn 
) ; 
2044         SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection 
) ; 
2047     GetSelection( &dummy
, &end 
) ; 
2049     // TODO: SetStyle( start , end , GetDefaultStyle() ) ; 
2052 void wxMacMLTEControl::Clear() 
2055     wxMacWindowClipper 
c( m_peer 
) ; 
2057     wxMacEditHelper 
st( m_txn 
) ; 
2058     TXNSetSelection( m_txn 
, kTXNStartOffset 
, kTXNEndOffset 
) ; 
2062 bool wxMacMLTEControl::CanUndo() const 
2064     return TXNCanUndo( m_txn 
, NULL 
) ; 
2067 void wxMacMLTEControl::Undo() 
2072 bool wxMacMLTEControl::CanRedo() const 
2074     return TXNCanRedo( m_txn 
, NULL 
) ; 
2077 void wxMacMLTEControl::Redo() 
2082 int wxMacMLTEControl::GetNumberOfLines() const 
2084     ItemCount lines 
= 0 ; 
2085     TXNGetLineCount( m_txn
, &lines 
) ; 
2090 long wxMacMLTEControl::XYToPosition(long x
, long y
) const 
2095     // TODO: find a better implementation : while we can get the 
2096     // line metrics of a certain line, we don't get its starting 
2097     // position, so it would probably be rather a binary search 
2098     // for the start position 
2099     long xpos 
= 0, ypos 
= 0 ; 
2100     int lastHeight 
= 0 ; 
2103     lastpos 
= GetLastPosition() ; 
2104     for ( n 
= 0 ; n 
<= (ItemCount
) lastpos 
; ++n 
) 
2106         if ( y 
== ypos 
&& x 
== xpos 
) 
2109         TXNOffsetToPoint( m_txn
, n
, &curpt 
) ; 
2111         if ( curpt
.v 
> lastHeight 
) 
2117             lastHeight 
= curpt
.v 
; 
2126 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y 
) const 
2136     lastpos 
= GetLastPosition() ; 
2137     if ( pos 
<= lastpos 
) 
2139         // TODO: find a better implementation - while we can get the 
2140         // line metrics of a certain line, we don't get its starting 
2141         // position, so it would probably be rather a binary search 
2142         // for the start position 
2143         long xpos 
= 0, ypos 
= 0 ; 
2144         int lastHeight 
= 0 ; 
2147         for ( n 
= 0 ; n 
<= (ItemCount
) pos 
; ++n 
) 
2149             TXNOffsetToPoint( m_txn
, n
, &curpt 
) ; 
2151             if ( curpt
.v 
> lastHeight 
) 
2157                 lastHeight 
= curpt
.v 
; 
2172 void wxMacMLTEControl::ShowPosition( long pos 
) 
2174     Point current
, desired 
; 
2175     TXNOffset selstart
, selend
; 
2177     TXNGetSelection( m_txn
, &selstart
, &selend 
); 
2178     TXNOffsetToPoint( m_txn
, selstart
, ¤t 
); 
2179     TXNOffsetToPoint( m_txn
, pos
, &desired 
); 
2181     // TODO: use HIPoints for 10.3 and above 
2183     OSErr theErr 
= noErr
; 
2184     long dv 
= desired
.v 
- current
.v
; 
2185     long dh 
= desired
.h 
- current
.h
; 
2186     TXNShowSelection( m_txn
, kTXNShowStart 
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ?? 
2187     theErr 
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh 
); 
2189     // there will be an error returned for classic MLTE implementation when the control is 
2190     // invisible, but HITextView works correctly, so we don't assert that one 
2191     // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); 
2194 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end 
) 
2197 #if SIZEOF_WCHAR_T == 2 
2198     size_t len 
= st
.length() ; 
2199     TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len 
* 2, start
, end 
); 
2201     wxMBConvUTF16 converter 
; 
2202     ByteCount byteBufferLen 
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ; 
2203     UniChar 
*unibuf 
= (UniChar
*)malloc( byteBufferLen 
) ; 
2204     converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen 
) ; 
2205     TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end 
) ; 
2209     wxCharBuffer text 
= st
.mb_str( wxConvLocal 
) ; 
2210     TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text 
), start
, end 
) ; 
2214 wxString 
wxMacMLTEControl::GetLineText(long lineNo
) const 
2218     if ( lineNo 
< GetNumberOfLines() ) 
2221         Fixed lineWidth
, lineHeight
, currentHeight
; 
2224         // get the first possible position in the control 
2225         TXNOffsetToPoint(m_txn
, 0, &firstPoint
); 
2227         // Iterate through the lines until we reach the one we want, 
2228         // adding to our current y pixel point position 
2231         while (ypos 
< lineNo
) 
2233             TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
); 
2234             currentHeight 
+= lineHeight
; 
2237         Point thePoint 
= { firstPoint
.v 
+ (currentHeight 
>> 16), firstPoint
.h 
+ (0) }; 
2238         TXNOffset theOffset
; 
2239         TXNPointToOffset(m_txn
, thePoint
, &theOffset
); 
2241         wxString content 
= GetStringValue() ; 
2242         Point currentPoint 
= thePoint
; 
2243         while (thePoint
.v 
== currentPoint
.v 
&& theOffset 
< content
.length()) 
2245             line 
+= content
[theOffset
]; 
2246             TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
); 
2253 int wxMacMLTEControl::GetLineLength(long lineNo
) const 
2257     if ( lineNo 
< GetNumberOfLines() ) 
2260         Fixed lineWidth
, lineHeight
, currentHeight
; 
2263         // get the first possible position in the control 
2264         TXNOffsetToPoint(m_txn
, 0, &firstPoint
); 
2266         // Iterate through the lines until we reach the one we want, 
2267         // adding to our current y pixel point position 
2270         while (ypos 
< lineNo
) 
2272             TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
); 
2273             currentHeight 
+= lineHeight
; 
2276         Point thePoint 
= { firstPoint
.v 
+ (currentHeight 
>> 16), firstPoint
.h 
+ (0) }; 
2277         TXNOffset theOffset
; 
2278         TXNPointToOffset(m_txn
, thePoint
, &theOffset
); 
2280         wxString content 
= GetStringValue() ; 
2281         Point currentPoint 
= thePoint
; 
2282         while (thePoint
.v 
== currentPoint
.v 
&& theOffset 
< content
.length()) 
2285             TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
); 
2292 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 
2294 // ---------------------------------------------------------------------------- 
2295 // MLTE control implementation (classic part) 
2296 // ---------------------------------------------------------------------------- 
2298 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation 
2299 // has to live on. We have different problems coming from outdated implementations on the 
2300 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded 
2301 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is 
2302 // no way out, therefore we are using our own implementation and our own scrollbars .... 
2304 TXNScrollInfoUPP gTXNScrollInfoProc 
= NULL 
; 
2305 ControlActionUPP gTXNScrollActionProc 
= NULL 
; 
2307 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc( 
2308     SInt32 iValue
, SInt32 iMaximumValue
, 
2309     TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon 
) 
2311     wxMacMLTEClassicControl
* mlte 
= (wxMacMLTEClassicControl
*) iRefCon 
; 
2312     SInt32 value 
=  wxMax( iValue 
, 0 ) ; 
2313     SInt32 maximum 
= wxMax( iMaximumValue 
, 0 ) ; 
2315     if ( iScrollBarOrientation 
== kTXNHorizontal 
) 
2317         if ( mlte
->m_sbHorizontal 
) 
2319             SetControl32BitValue( mlte
->m_sbHorizontal 
, value 
) ; 
2320             SetControl32BitMaximum( mlte
->m_sbHorizontal 
, maximum 
) ; 
2321             mlte
->m_lastHorizontalValue 
= value 
; 
2324     else if ( iScrollBarOrientation 
== kTXNVertical 
) 
2326         if ( mlte
->m_sbVertical 
) 
2328             SetControl32BitValue( mlte
->m_sbVertical 
, value 
) ; 
2329             SetControl32BitMaximum( mlte
->m_sbVertical 
, maximum 
) ; 
2330             mlte
->m_lastVerticalValue 
= value 
; 
2335 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef 
, ControlPartCode partCode 
) 
2337     wxMacMLTEClassicControl
* mlte 
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef 
) ; 
2341     if ( controlRef 
!= mlte
->m_sbVertical 
&& controlRef 
!= mlte
->m_sbHorizontal 
) 
2345     bool isHorizontal 
= ( controlRef 
== mlte
->m_sbHorizontal 
) ; 
2347     SInt32 minimum 
= 0 ; 
2348     SInt32 maximum 
= GetControl32BitMaximum( controlRef 
) ; 
2349     SInt32 value 
= GetControl32BitValue( controlRef 
) ; 
2354         case kControlDownButtonPart 
: 
2358         case kControlUpButtonPart 
: 
2362         case kControlPageDownPart 
: 
2363             delta 
= GetControlViewSize( controlRef 
) ; 
2366         case kControlPageUpPart 
: 
2367             delta 
= -GetControlViewSize( controlRef 
) ; 
2370         case kControlIndicatorPart 
: 
2371             delta 
= value 
- (isHorizontal 
? mlte
->m_lastHorizontalValue 
: mlte
->m_lastVerticalValue
) ; 
2380         SInt32 newValue 
= value 
; 
2382         if ( partCode 
!= kControlIndicatorPart 
) 
2384             if ( value 
+ delta 
< minimum 
) 
2385                 delta 
= minimum 
- value 
; 
2386             if ( value 
+ delta 
> maximum 
) 
2387                 delta 
= maximum 
- value 
; 
2389             SetControl32BitValue( controlRef 
, value 
+ delta 
) ; 
2390             newValue 
= value 
+ delta 
; 
2393         SInt32 verticalDelta 
= isHorizontal 
? 0 : delta 
; 
2394         SInt32 horizontalDelta 
= isHorizontal 
? delta 
: 0 ; 
2397             mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, 
2398             &verticalDelta
, &horizontalDelta 
); 
2399         verify_noerr( err 
); 
2402             mlte
->m_lastHorizontalValue 
= newValue 
; 
2404             mlte
->m_lastVerticalValue 
= newValue 
; 
2408 // make correct activations 
2409 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
) 
2411     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference(m_controlRef
); 
2413     wxMacWindowClipper 
clipper( textctrl 
) ; 
2414     TXNActivate( m_txn
, m_txnFrameID
, setActive 
); 
2416     ControlRef controlFocus 
= 0 ; 
2417     GetKeyboardFocus( m_txnWindow 
, &controlFocus 
) ; 
2418     if ( controlFocus 
== m_controlRef 
) 
2419         TXNFocus( m_txn
, setActive 
); 
2422 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
) 
2424     TXNFocus( m_txn
, setFocus 
); 
2427 // guards against inappropriate redraw (hidden objects drawing onto window) 
2429 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
) 
2431     ControlRef controlFocus 
= 0 ; 
2432     GetKeyboardFocus( m_txnWindow 
, &controlFocus 
) ; 
2434     if ( !vis 
&& (controlFocus 
== m_controlRef 
) ) 
2435         SetKeyboardFocus( m_txnWindow 
, m_controlRef 
, kControlFocusNoPart 
) ; 
2437     TXNControlTag iControlTags
[1] = { kTXNVisibilityTag 
}; 
2438     TXNControlData iControlData
[1] = { { (UInt32
)false } }; 
2440     verify_noerr( TXNGetTXNObjectControls( m_txn 
, 1, iControlTags
, iControlData 
) ) ; 
2442     if ( iControlData
[0].uValue 
!= vis 
) 
2444         iControlData
[0].uValue 
= vis 
; 
2445         verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData 
) ) ; 
2448     // currently, we always clip as partial visibility (overlapped) visibility is also a problem, 
2449     // if we run into further problems we might set the FrameBounds to an empty rect here 
2452 // make sure that the TXNObject is at the right position 
2454 void wxMacMLTEClassicControl::MacUpdatePosition() 
2456     wxTextCtrl
* textctrl 
= (wxTextCtrl
*)GetControlReference( m_controlRef 
); 
2457     if ( textctrl 
== NULL 
) 
2461     UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds 
); 
2463     wxRect visRect 
= textctrl
->MacGetClippedClientRect() ; 
2464     Rect visBounds 
= { visRect
.y 
, visRect
.x 
, visRect
.y 
+ visRect
.height 
, visRect
.x 
+ visRect
.width 
} ; 
2467     textctrl
->MacWindowToRootWindow( &x 
, &y 
) ; 
2468     OffsetRect( &visBounds 
, x 
, y 
) ; 
2470     if ( !EqualRect( &bounds
, &m_txnControlBounds 
) || !EqualRect( &visBounds
, &m_txnVisBounds 
) ) 
2472         m_txnControlBounds 
= bounds 
; 
2473         m_txnVisBounds 
= visBounds 
; 
2474         wxMacWindowClipper 
cl( textctrl 
) ; 
2476         if ( m_sbHorizontal 
|| m_sbVertical 
) 
2478             int w 
= bounds
.right 
- bounds
.left 
; 
2479             int h 
= bounds
.bottom 
- bounds
.top 
; 
2481             if ( m_sbHorizontal 
) 
2485                 sbBounds
.left 
= -1 ; 
2486                 sbBounds
.top 
= h 
- 14 ; 
2487                 sbBounds
.right 
= w 
+ 1 ; 
2488                 sbBounds
.bottom 
= h 
+ 1 ; 
2490                 SetControlBounds( m_sbHorizontal 
, &sbBounds 
) ; 
2491                 SetControlViewSize( m_sbHorizontal 
, w 
) ; 
2498                 sbBounds
.left 
= w 
- 14 ; 
2500                 sbBounds
.right 
= w 
+ 1 ; 
2501                 sbBounds
.bottom 
= m_sbHorizontal 
? h 
- 14 : h 
+ 1 ; 
2503                 SetControlBounds( m_sbVertical 
, &sbBounds 
) ; 
2504                 SetControlViewSize( m_sbVertical 
, h 
) ; 
2509         TXNLongRect olddestRect 
; 
2510         TXNGetRectBounds( m_txn 
, &oldviewRect 
, &olddestRect 
, NULL 
) ; 
2512         Rect viewRect 
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
, 
2513             m_txnControlBounds
.bottom 
- ( m_sbHorizontal 
? 14 : 0 ) , 
2514             m_txnControlBounds
.right 
- ( m_sbVertical 
? 14 : 0 ) } ; 
2515         TXNLongRect destRect 
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
, 
2516             m_txnControlBounds
.bottom 
- ( m_sbHorizontal 
? 14 : 0 ) , 
2517             m_txnControlBounds
.right 
- ( m_sbVertical 
? 14 : 0 ) } ; 
2519         if ( olddestRect
.right 
>= 10000 ) 
2520             destRect
.right 
= destRect
.left 
+ 32000 ; 
2522         if ( olddestRect
.bottom 
>= 0x20000000 ) 
2523             destRect
.bottom 
= destRect
.top 
+ 0x40000000 ; 
2525         SectRect( &viewRect 
, &visBounds 
, &viewRect 
) ; 
2526         TXNSetRectBounds( m_txn 
, &viewRect 
, &destRect 
, true ) ; 
2531             m_txnControlBounds
.top
, 
2532             m_txnControlBounds
.left
, 
2533             m_txnControlBounds
.bottom 
- (m_sbHorizontal 
? 14 : 0), 
2534             m_txnControlBounds
.right 
- (m_sbVertical 
? 14 : 0), 
2538         // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a 
2539         // movement, therefore we have to force it 
2541         // this problem has been reported in OSX as well, so we use this here once again 
2543         TXNLongRect textRect 
; 
2544         TXNGetRectBounds( m_txn 
, NULL 
, NULL 
, &textRect 
) ; 
2545         if ( textRect
.left 
< m_txnControlBounds
.left 
) 
2546             TXNShowSelection( m_txn 
, kTXNShowStart 
) ; 
2550 void wxMacMLTEClassicControl::SetRect( Rect 
*r 
) 
2552     wxMacControl::SetRect( r 
) ; 
2553     MacUpdatePosition() ; 
2556 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 
WXUNUSED(thePart
)) 
2558     wxTextCtrl
* textctrl 
= (wxTextCtrl
*)GetControlReference( m_controlRef 
); 
2559     if ( textctrl 
== NULL 
) 
2562     if ( textctrl
->MacIsReallyShown() ) 
2564         wxMacWindowClipper 
clipper( textctrl 
) ; 
2565         TXNDraw( m_txn 
, NULL 
) ; 
2569 wxInt16 
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) 
2571     Point where 
= { y 
, x 
} ; 
2572     ControlPartCode result 
= kControlNoPart
; 
2574     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference( m_controlRef 
); 
2575     if ( (textctrl 
!= NULL
) && textctrl
->MacIsReallyShown() ) 
2577         if (PtInRect( where
, &m_txnControlBounds 
)) 
2579             result 
= kControlEditTextPart 
; 
2583             // sometimes we get the coords also in control local coordinates, therefore test again 
2585             textctrl
->MacClientToRootWindow( &x 
, &y 
) ; 
2589             if (PtInRect( where
, &m_txnControlBounds 
)) 
2590                 result 
= kControlEditTextPart 
; 
2597 wxInt16 
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* WXUNUSED(actionProc
) ) 
2599     ControlPartCode result 
= kControlNoPart
; 
2601     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference( m_controlRef 
); 
2602     if ( (textctrl 
!= NULL
) && textctrl
->MacIsReallyShown() ) 
2604         Point startPt 
= { y 
, x 
} ; 
2606         // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them 
2608         textctrl
->MacClientToRootWindow( &x 
, &y 
) ; 
2612         switch (MacControlUserPaneHitTestProc( startPt
.h 
, startPt
.v 
)) 
2614             case kControlEditTextPart 
: 
2616                 wxMacWindowClipper 
clipper( textctrl 
) ; 
2619                 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec 
) ; 
2620                 TXNClick( m_txn
, &rec 
); 
2632 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc() 
2634     wxTextCtrl
* textctrl 
= (wxTextCtrl
*)GetControlReference( m_controlRef 
); 
2635     if ( textctrl 
== NULL 
) 
2638     if (textctrl
->MacIsReallyShown()) 
2640         if (IsControlActive(m_controlRef
)) 
2644             wxMacWindowClipper 
clipper( textctrl 
) ; 
2649             if (PtInRect(mousep
, &m_txnControlBounds
)) 
2651                 RgnHandle theRgn 
= NewRgn(); 
2652                 RectRgn(theRgn
, &m_txnControlBounds
); 
2653                 TXNAdjustCursor(m_txn
, theRgn
); 
2660 wxInt16 
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) 
2662     wxTextCtrl
* textctrl 
= (wxTextCtrl
*)GetControlReference( m_controlRef 
); 
2663     if ( textctrl 
== NULL 
) 
2664         return kControlNoPart
; 
2666     wxMacWindowClipper 
clipper( textctrl 
) ; 
2669     memset( &ev 
, 0 , sizeof( ev 
) ) ; 
2671     ev
.modifiers 
= modifiers 
; 
2672     ev
.message 
= ((keyCode 
<< 8) & keyCodeMask
) | (charCode 
& charCodeMask
); 
2673     TXNKeyDown( m_txn 
, &ev 
); 
2675     return kControlEntireControl
; 
2678 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
) 
2680     MacActivatePaneText( activating 
); 
2683 wxInt16 
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
) 
2685     ControlPartCode focusResult 
= kControlFocusNoPart
; 
2687     wxTextCtrl
* textctrl 
= (wxTextCtrl
*)GetControlReference( m_controlRef 
); 
2688     if ( textctrl 
== NULL 
) 
2691     wxMacWindowClipper 
clipper( textctrl 
) ; 
2693     ControlRef controlFocus 
= NULL 
; 
2694     GetKeyboardFocus( m_txnWindow 
, &controlFocus 
) ; 
2695     bool wasFocused 
= ( controlFocus 
== m_controlRef 
) ; 
2699         case kControlFocusPrevPart
: 
2700         case kControlFocusNextPart
: 
2701             MacFocusPaneText( !wasFocused 
); 
2702             focusResult 
= (!wasFocused 
? (ControlPartCode
) kControlEditTextPart 
: (ControlPartCode
) kControlFocusNoPart
); 
2705         case kControlFocusNoPart
: 
2707             MacFocusPaneText( false ); 
2708             focusResult 
= kControlFocusNoPart
; 
2715 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *WXUNUSED(info
) ) 
2719 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl 
*wxPeer
, 
2720     const wxString
& str
, 
2722     const wxSize
& size
, long style 
) 
2723     : wxMacMLTEControl( wxPeer 
) 
2725     m_font 
= wxPeer
->GetFont() ; 
2726     m_windowStyle 
= style 
; 
2727     Rect bounds 
= wxMacGetBoundsForControl( wxPeer 
, pos 
, size 
) ; 
2730         kControlSupportsEmbedding 
| kControlSupportsFocus 
| kControlWantsIdle
 
2731         | kControlWantsActivate  
| kControlHandlesTracking
 
2732 //    | kControlHasSpecialBackground 
2733         | kControlGetsFocusOnClick 
| kControlSupportsLiveFeedback
; 
2735    OSStatus err 
= ::CreateUserPaneControl( 
2736         MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), 
2737         &bounds
, featureSet
, &m_controlRef 
); 
2738     verify_noerr( err 
); 
2742     AdjustCreationAttributes( *wxWHITE 
, true ) ; 
2744     MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ; 
2748         wxMacConvertNewlines10To13( &st 
) ; 
2749         wxMacWindowClipper 
clipper( m_peer 
) ; 
2750         SetTXNData( st 
, kTXNStartOffset
, kTXNEndOffset 
) ; 
2751         TXNSetSelection( m_txn
, 0, 0 ) ; 
2755 wxMacMLTEClassicControl::~wxMacMLTEClassicControl() 
2757     TXNDeleteObject( m_txn 
); 
2761 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
) 
2763     MacSetObjectVisibility( shown 
) ; 
2764     wxMacControl::VisibilityChanged( shown 
) ; 
2767 void wxMacMLTEClassicControl::SuperChangedPosition() 
2769     MacUpdatePosition() ; 
2770     wxMacControl::SuperChangedPosition() ; 
2773 ControlUserPaneDrawUPP gTPDrawProc 
= NULL
; 
2774 ControlUserPaneHitTestUPP gTPHitProc 
= NULL
; 
2775 ControlUserPaneTrackingUPP gTPTrackProc 
= NULL
; 
2776 ControlUserPaneIdleUPP gTPIdleProc 
= NULL
; 
2777 ControlUserPaneKeyDownUPP gTPKeyProc 
= NULL
; 
2778 ControlUserPaneActivateUPP gTPActivateProc 
= NULL
; 
2779 ControlUserPaneFocusUPP gTPFocusProc 
= NULL
; 
2781 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
) 
2783     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2784     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2786         win
->MacControlUserPaneDrawProc( part 
) ; 
2789 static pascal ControlPartCode 
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
) 
2791     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2792     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2794         return win
->MacControlUserPaneHitTestProc( where
.h 
, where
.v 
) ; 
2796         return kControlNoPart 
; 
2799 static pascal ControlPartCode 
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
) 
2801     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2802     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2804         return win
->MacControlUserPaneTrackingProc( startPt
.h 
, startPt
.v 
, (void*) actionProc 
) ; 
2806         return kControlNoPart 
; 
2809 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
) 
2811     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2812     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2814         win
->MacControlUserPaneIdleProc() ; 
2817 static pascal ControlPartCode 
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) 
2819     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2820     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2822         return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers 
) ; 
2824         return kControlNoPart 
; 
2827 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
) 
2829     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2830     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2832         win
->MacControlUserPaneActivateProc( activating 
) ; 
2835 static pascal ControlPartCode 
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
) 
2837     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2838     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2840         return win
->MacControlUserPaneFocusProc( action 
) ; 
2842         return kControlNoPart 
; 
2846 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
) 
2848     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2849     wxMacMLTEClassicControl 
* win 
= textCtrl 
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL 
; 
2851         win
->MacControlUserPaneBackgroundProc(info
) ; 
2855 // TXNRegisterScrollInfoProc 
2857 OSStatus 
wxMacMLTEClassicControl::DoCreate() 
2860     OSStatus err 
= noErr 
; 
2862     // set up our globals 
2863     if (gTPDrawProc 
== NULL
) gTPDrawProc 
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
); 
2864     if (gTPHitProc 
== NULL
) gTPHitProc 
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
); 
2865     if (gTPTrackProc 
== NULL
) gTPTrackProc 
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
); 
2866     if (gTPIdleProc 
== NULL
) gTPIdleProc 
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
); 
2867     if (gTPKeyProc 
== NULL
) gTPKeyProc 
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
); 
2868     if (gTPActivateProc 
== NULL
) gTPActivateProc 
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
); 
2869     if (gTPFocusProc 
== NULL
) gTPFocusProc 
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
); 
2871     if (gTXNScrollInfoProc 
== NULL 
) gTXNScrollInfoProc 
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ; 
2872     if (gTXNScrollActionProc 
== NULL 
) gTXNScrollActionProc 
= NewControlActionUPP(TXNScrollActionProc
) ; 
2874     // set the initial settings for our private data 
2876     m_txnWindow 
= GetControlOwner(m_controlRef
); 
2877     m_txnPort 
= (GrafPtr
) GetWindowPort(m_txnWindow
); 
2879     // set up the user pane procedures 
2880     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
); 
2881     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
); 
2882     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
); 
2883     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
); 
2884     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
); 
2885     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
); 
2886     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
); 
2888     // calculate the rectangles used by the control 
2889     UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds 
); 
2891     m_txnControlBounds 
= bounds 
; 
2892     m_txnVisBounds 
= bounds 
; 
2897     GetGWorld( &origPort
, &origDev 
) ; 
2898     SetPort( m_txnPort 
); 
2900     // create the new edit field 
2901     TXNFrameOptions frameOptions 
= FrameOptionsFromWXStyle( m_windowStyle 
); 
2903     // the scrollbars are not correctly embedded but are inserted at the root: 
2904     // this gives us problems as we have erratic redraws even over the structure area 
2906     m_sbHorizontal 
= 0 ; 
2908     m_lastHorizontalValue 
= 0 ; 
2909     m_lastVerticalValue 
= 0 ; 
2911     Rect sb 
= { 0 , 0 , 0 , 0 } ; 
2912     if ( frameOptions 
& kTXNWantVScrollBarMask 
) 
2914         CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical 
); 
2915         SetControlReference( m_sbVertical
, (SInt32
)this ); 
2916         SetControlAction( m_sbVertical
, gTXNScrollActionProc 
); 
2917         ShowControl( m_sbVertical 
); 
2918         EmbedControl( m_sbVertical 
, m_controlRef 
); 
2919         frameOptions 
&= ~kTXNWantVScrollBarMask
; 
2922     if ( frameOptions 
& kTXNWantHScrollBarMask 
) 
2924         CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal 
); 
2925         SetControlReference( m_sbHorizontal
, (SInt32
)this ); 
2926         SetControlAction( m_sbHorizontal
, gTXNScrollActionProc 
); 
2927         ShowControl( m_sbHorizontal 
); 
2928         EmbedControl( m_sbHorizontal
, m_controlRef 
); 
2929         frameOptions 
&= ~(kTXNWantHScrollBarMask 
| kTXNDrawGrowIconMask
); 
2933         NULL
, m_txnWindow
, &bounds
, frameOptions
, 
2934         kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
, 
2935         &m_txn
, &m_txnFrameID
, NULL 
); 
2936     verify_noerr( err 
); 
2939     TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents 
}; 
2940     TXNControlData iControlData
[] = { { (UInt32
)&cInfo 
} }; 
2941     int toptag 
= WXSIZEOF( iControlTags 
) ; 
2942     TXNCarbonEventInfo cInfo 
; 
2943     cInfo
.useCarbonEvents 
= false ; 
2946     cInfo
.fDictionary 
= NULL 
; 
2948     verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData 
) ); 
2951     TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this ); 
2953     SetGWorld( origPort 
, origDev 
) ; 
2959 // ---------------------------------------------------------------------------- 
2960 // MLTE control implementation (OSX part) 
2961 // ---------------------------------------------------------------------------- 
2963 // tiger multi-line textcontrols with no CR in the entire content 
2964 // don't scroll automatically, so we need a hack. 
2965 // This attempt only works 'before' the key (ie before CallNextEventHandler) 
2966 // is processed, thus the scrolling always occurs one character too late, but 
2967 // better than nothing ... 
2969 static const EventTypeSpec eventList
[] = 
2971     { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent 
} , 
2974 static pascal OSStatus 
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
2976     OSStatus result 
= eventNotHandledErr 
; 
2977     wxMacMLTEHIViewControl
* focus 
= (wxMacMLTEHIViewControl
*) data 
; 
2979     switch ( GetEventKind( event 
) ) 
2981         case kEventTextInputUnicodeForKeyEvent 
: 
2983             if ( UMAGetSystemVersion() >= 0x1040 ) 
2985                 TXNOffset from 
, to 
; 
2986                 TXNGetSelection( focus
->GetTXNObject() , &from 
, &to 
) ; 
2988                     TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart 
); 
2990             result 
= CallNextEventHandler(handler
,event
); 
3000 static pascal OSStatus 
wxMacTextControlEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
3002     OSStatus result 
= eventNotHandledErr 
; 
3004     switch ( GetEventClass( event 
) ) 
3006         case kEventClassTextInput 
: 
3007             result 
= wxMacUnicodeTextEventHandler( handler 
, event 
, data 
) ; 
3016 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler 
) 
3018 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl 
*wxPeer
, 
3019     const wxString
& str
, 
3021     const wxSize
& size
, long style 
) : wxMacMLTEControl( wxPeer 
) 
3023     m_font 
= wxPeer
->GetFont() ; 
3024     m_windowStyle 
= style 
; 
3025     Rect bounds 
= wxMacGetBoundsForControl( wxPeer 
, pos 
, size 
) ; 
3027     wxMacConvertNewlines10To13( &st 
) ; 
3030         { bounds
.left 
, bounds
.top 
}, 
3031         { bounds
.right 
- bounds
.left
, bounds
.bottom 
- bounds
.top 
} } ; 
3033     m_scrollView 
= NULL 
; 
3034     TXNFrameOptions frameOptions 
= FrameOptionsFromWXStyle( style 
) ; 
3035     if (( frameOptions 
& (kTXNWantVScrollBarMask 
| kTXNWantHScrollBarMask
)) || !(frameOptions 
&kTXNSingleLineOnlyMask
)) 
3037         if ( frameOptions 
& (kTXNWantVScrollBarMask 
| kTXNWantHScrollBarMask
) ) 
3040                 (frameOptions 
& kTXNWantHScrollBarMask 
? kHIScrollViewOptionsHorizScroll 
: 0) 
3041                 | (frameOptions 
& kTXNWantVScrollBarMask 
? kHIScrollViewOptionsVertScroll 
: 0) , 
3046             HIScrollViewCreate(kHIScrollViewOptionsVertScroll
,&m_scrollView
); 
3047             HIScrollViewSetScrollBarAutoHide(m_scrollView
,true); 
3050         HIViewSetFrame( m_scrollView
, &hr 
); 
3051         HIViewSetVisible( m_scrollView
, true ); 
3055     HITextViewCreate( NULL 
, 0, frameOptions 
, &m_textView 
) ; 
3056     m_txn 
= HITextViewGetTXNObject( m_textView 
) ; 
3057     HIViewSetVisible( m_textView 
, true ) ; 
3060         HIViewAddSubview( m_scrollView 
, m_textView 
) ; 
3061         m_controlRef 
= m_scrollView 
; 
3062         wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView 
) ; 
3066         HIViewSetFrame( m_textView
, &hr 
); 
3067         m_controlRef 
= m_textView 
; 
3070     AdjustCreationAttributes( *wxWHITE 
, true ) ; 
3072     wxMacWindowClipper 
c( m_peer 
) ; 
3074     SetTXNData( st 
, kTXNStartOffset
, kTXNEndOffset 
) ; 
3076     TXNSetSelection( m_txn
, 0, 0 ); 
3077     TXNShowSelection( m_txn
, kTXNShowStart 
); 
3079     InstallControlEventHandler( m_textView 
, GetwxMacTextControlEventHandlerUPP(), 
3080                                 GetEventTypeCount(eventList
), eventList
, this, 
3084 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl() 
3088 OSStatus 
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart 
) 
3090     return SetKeyboardFocus( GetControlOwner( m_textView 
), m_textView
, focusPart 
) ; 
3093 bool wxMacMLTEHIViewControl::HasFocus() const 
3095     ControlRef control 
; 
3096     if ( GetUserFocusWindow() == NULL 
) 
3099     GetKeyboardFocus( GetUserFocusWindow() , &control 
) ; 
3100     return control 
== m_textView 
; 
3103 void wxMacMLTEHIViewControl::SetBackground( const wxBrush 
&brush 
) 
3105     wxMacMLTEControl::SetBackground( brush 
) ; 
3108     CGColorSpaceRef rgbSpace 
= CGColorSpaceCreateDeviceRGB(); 
3109     RGBColor col 
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ; 
3111     float component
[4] ; 
3112     component
[0] = col
.red 
/ 65536.0 ; 
3113     component
[1] = col
.green 
/ 65536.0 ; 
3114     component
[2] = col
.blue 
/ 65536.0 ; 
3115     component
[3] = 1.0 ; // alpha 
3117     CGColorRef color 
= CGColorCreate( rgbSpace 
, component 
); 
3118     HITextViewSetBackgroundColor( m_textView 
, color 
); 
3119     CGColorSpaceRelease( rgbSpace 
); 
3123 #endif // wxUSE_TEXTCTRL