1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Stefan Csomor 
   5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText) 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  13 #pragma implementation "textctrl.h" 
  16 #include "wx/wxprec.h" 
  22   #include <sys/types.h> 
  28 #include "wx/msgdlg.h" 
  30 #if wxUSE_STD_IOSTREAM 
  40 #include "wx/button.h" 
  41 #include "wx/toplevel.h" 
  42 #include "wx/textctrl.h" 
  43 #include "wx/notebook.h" 
  44 #include "wx/tabctrl.h" 
  45 #include "wx/settings.h" 
  46 #include "wx/filefn.h" 
  49 #if defined(__BORLANDC__) && !defined(__WIN32__) 
  51 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__) 
  59 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used 
  60 // if set to 0 then the unicode textctrl will be used 
  61 #ifndef wxMAC_AWAYS_USE_MLTE 
  62 #define wxMAC_AWAYS_USE_MLTE 1 
  68     kTXNVisibilityTag             
= 'visb' /*set the visibility state of the object  */ 
  72 #include <MacTextEditor.h> 
  73 #include <ATSUnicode.h> 
  74 #include <TextCommon.h> 
  75 #include <TextEncodingConverter.h> 
  76 #include "wx/mac/uma.h" 
  82     virtual ~wxMacFunctor() {} 
  83     virtual void* operator()() = 0 ; 
  84     static void* CallBackProc(void *param
) 
  86         wxMacFunctor
* f 
= (wxMacFunctor
*) param 
; 
  87         void *result 
= (*f
)() ; 
  92 template<typename classtype
,typename param1type
> 
  93 class wxMacObjectFunctor1 
: public wxMacFunctor
 
  95     typedef void (classtype::*function
)( param1type p1 
) ; 
  96     typedef void (classtype::*ref_function
)( const param1type
& p1 
) ; 
  98     wxMacObjectFunctor1( classtype 
*obj 
, function f 
, param1type p1 
) : 
 106     wxMacObjectFunctor1( classtype 
*obj 
, ref_function f 
, param1type p1 
) : 
 114     ~wxMacObjectFunctor1() {} 
 116     virtual void* operator()() 
 118         (m_object
->*m_function
)(m_param1
) ; 
 122     classtype
* m_object 
; 
 123     param1type m_param1 
; 
 126     function m_function 
; 
 127     ref_function m_refFunction 
; 
 131 template<typename classtype
, typename param1type
> 
 132 void* wxMacMPRemoteCall( classtype 
*object 
, void (classtype::*function
)( param1type p1 
) , param1type p1 
) 
 134     wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ; 
 136         MPRemoteCall( wxMacFunctor::CallBackProc 
, ¶ms  
, kMPOwningProcessRemoteContext 
) ; 
 140 template<typename classtype
, typename param1type
> 
 141 void* wxMacMPRemoteCall( classtype 
*object 
, void (classtype::*function
)( const param1type
& p1 
) , param1type p1 
) 
 143     wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ; 
 145         MPRemoteCall( wxMacFunctor::CallBackProc 
, ¶ms  
, kMPOwningProcessRemoteContext 
) ; 
 149 template<typename classtype
, typename param1type
> 
 150 void* wxMacMPRemoteGUICall( classtype 
*object 
, void (classtype::*function
)( param1type p1 
) , param1type p1 
) 
 153     void *result 
= wxMacMPRemoteCall( object 
, function 
, p1 
) ; 
 158 template<typename classtype
, typename param1type
> 
 159 void* wxMacMPRemoteGUICall( classtype 
*object 
, void (classtype::*function
)( const param1type
& p1 
) , param1type p1 
) 
 162     void *result 
= wxMacMPRemoteCall( object 
, function 
, p1 
) ; 
 166 // common interface for all implementations 
 167 class wxMacTextControl 
: public wxMacControl
 
 170     wxMacTextControl( wxTextCtrl 
*peer 
) ; 
 171     ~wxMacTextControl() ; 
 173     virtual wxString 
GetStringValue() const = 0 ; 
 174     virtual void SetStringValue( const wxString 
&val 
) = 0 ; 
 175     virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ; 
 176     virtual void Copy() ; 
 178     virtual void Paste() ; 
 179     virtual bool CanPaste() const ; 
 180     virtual void SetEditable(bool editable
) ; 
 181     virtual wxTextPos 
GetLastPosition() const ; 
 182     virtual void Replace( long from 
, long to 
, const wxString str 
) ; 
 183     virtual void Remove( long from 
, long to 
) = 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 Clear() ; 
 189     virtual bool CanUndo() const; 
 190     virtual void Undo() ; 
 191     virtual bool CanRedo() const; 
 192     virtual void Redo() ; 
 193     virtual int GetNumberOfLines() const ; 
 194     virtual long XYToPosition(long x
, long y
) const; 
 195     virtual bool PositionToXY(long pos
, long *x
, long *y
) const ; 
 196     virtual void ShowPosition( long WXUNUSED(pos
) ) ; 
 197     virtual int GetLineLength(long lineNo
) const ; 
 198     virtual wxString 
GetLineText(long lineNo
) const ; 
 200 #ifndef __WXMAC_OSX__ 
 201     virtual void            MacControlUserPaneDrawProc(wxInt16 part
) = 0 ; 
 202     virtual wxInt16         
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ; 
 203     virtual wxInt16         
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ; 
 204     virtual void            MacControlUserPaneIdleProc() = 0 ; 
 205     virtual wxInt16         
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ; 
 206     virtual void            MacControlUserPaneActivateProc(bool activating
) = 0 ; 
 207     virtual wxInt16         
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ; 
 208     virtual void            MacControlUserPaneBackgroundProc(void* info
) = 0 ; 
 212 // common parts for implementations based on MLTE 
 214 class wxMacMLTEControl 
: public wxMacTextControl
 
 217     wxMacMLTEControl( wxTextCtrl 
*peer 
) : wxMacTextControl( peer 
) {} 
 218     virtual wxString 
GetStringValue() const ; 
 219     virtual void SetStringValue( const wxString 
&str
) ; 
 221     static TXNFrameOptions 
FrameOptionsFromWXStyle( long wxStyle 
) ; 
 222     void    AdjustCreationAttributes( const wxColour
& background 
, bool visible 
) ; 
 224     virtual void SetFont( const wxFont 
& font 
, const wxColour
& foreground 
, long windowStyle 
) ; 
 225     virtual void SetBackground( const wxBrush 
&brush
) ; 
 226     virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ; 
 227     virtual void Copy() ; 
 229     virtual void Paste() ; 
 230     virtual bool CanPaste() const ; 
 231     virtual void SetEditable(bool editable
) ; 
 232     virtual wxTextPos 
GetLastPosition() const ; 
 233     virtual void Replace( long from 
, long to 
, const wxString str 
) ; 
 234     virtual void Remove( long from 
, long to 
)  ; 
 235     virtual void GetSelection( long* from
, long* to
) const ; 
 236     virtual void SetSelection( long from 
, long to 
) ; 
 238     virtual void WriteText(const wxString
& str
) ; 
 239     virtual void Clear() ; 
 241     virtual bool CanUndo() const ; 
 242     virtual void Undo() ; 
 243     virtual bool CanRedo()  const; 
 244     virtual void Redo() ; 
 245     virtual int GetNumberOfLines() const ; 
 246     virtual long XYToPosition(long x
, long y
) const ; 
 247     virtual bool PositionToXY(long pos
, long *x
, long *y
) const ; 
 248     virtual void ShowPosition( long pos 
) ; 
 249     virtual int GetLineLength(long lineNo
) const ; 
 250     virtual wxString 
GetLineText(long lineNo
) const ; 
 252     void SetTXNData( const wxString
& st 
, TXNOffset start 
, TXNOffset end 
) ; 
 255     void TXNSetAttribute( const wxTextAttr
& style 
, long from 
, long to 
) ; 
 259 #if TARGET_API_MAC_OSX 
 261 // implementation available under OSX 
 263 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 
 265 class wxMacMLTEHIViewControl 
: public wxMacMLTEControl
 
 268     wxMacMLTEHIViewControl( wxTextCtrl 
*wxPeer
, 
 271                              const wxSize
& size
, long style 
) ; 
 272     virtual OSStatus 
SetFocus( ControlFocusPart focusPart 
) ; 
 273     virtual bool HasFocus() const ; 
 274     virtual bool NeedsFocusRect() const; 
 276     HIViewRef m_scrollView 
; 
 277     HIViewRef m_textView 
; 
 282 class wxMacUnicodeTextControl 
: public wxMacTextControl
 
 285     wxMacUnicodeTextControl( wxTextCtrl 
*wxPeer
, 
 288                              const wxSize
& size
, long style 
) ; 
 289     ~wxMacUnicodeTextControl(); 
 290     virtual void VisibilityChanged(bool shown
); 
 291     virtual wxString 
GetStringValue() const ; 
 292     virtual void SetStringValue( const wxString 
&str
) ; 
 295     virtual void Paste(); 
 296     virtual bool CanPaste() const; 
 297     virtual void SetEditable(bool editable
) ; 
 298     virtual void Remove( long from 
, long to 
) ; 
 299     virtual void GetSelection( long* from
, long* to
) const ; 
 300     virtual void SetSelection( long from 
, long to 
) ; 
 301     virtual void WriteText(const wxString
& str
) ; 
 303     // contains the tag for the content (is different for password and non-password controls) 
 309 // 'classic' MLTE implementation 
 311 class wxMacMLTEClassicControl 
: public wxMacMLTEControl
 
 314     wxMacMLTEClassicControl( wxTextCtrl 
*wxPeer
, 
 317                              const wxSize
& size
, long style 
) ; 
 318     ~wxMacMLTEClassicControl() ; 
 319     virtual void VisibilityChanged(bool shown
) ; 
 320     virtual void SuperChangedPosition() ; 
 321     virtual bool NeedsFocusRect() const; 
 323     virtual void            MacControlUserPaneDrawProc(wxInt16 part
) ; 
 324     virtual wxInt16         
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ; 
 325     virtual wxInt16         
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ; 
 326     virtual void            MacControlUserPaneIdleProc() ; 
 327     virtual wxInt16         
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ; 
 328     virtual void            MacControlUserPaneActivateProc(bool activating
) ; 
 329     virtual wxInt16         
MacControlUserPaneFocusProc(wxInt16 action
) ; 
 330     virtual void            MacControlUserPaneBackgroundProc(void* info
) ; 
 332     virtual void            SetRect( Rect 
*r 
) ; 
 337     void                    MacUpdatePosition() ; 
 338     void                    MacActivatePaneText(Boolean setActive
) ; 
 339     void                    MacFocusPaneText(Boolean setFocus
) ; 
 341     void                    MacSetObjectVisibility(Boolean vis
) ; 
 343     TXNFrameID              m_txnFrameID 
; 
 345     // bounds of the control as we last did set the txn frames 
 346     Rect                    m_txnControlBounds 
; 
 348     bool                    m_txnIsFocused 
; 
 350     bool                    m_txnIsVisible 
; 
 351     bool                    m_controlIsActive 
; 
 354     ControlRef              m_sbHorizontal 
; 
 355     ControlRef              m_sbVertical 
; 
 359 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL 
 361 #if !USE_SHARED_LIBRARY 
 362 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
) 
 364 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
) 
 365     EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground 
) 
 366     EVT_DROP_FILES(wxTextCtrl::OnDropFiles
) 
 367     EVT_CHAR(wxTextCtrl::OnChar
) 
 368     EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
) 
 369     EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
) 
 370     EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
) 
 371     EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
) 
 372     EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
) 
 374     EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
) 
 375     EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
) 
 376     EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
) 
 377     EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
) 
 378     EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
) 
 383 void wxTextCtrl::Init() 
 388   m_maxLength 
= TE_UNLIMITED_LENGTH 
; 
 391 wxTextCtrl::~wxTextCtrl() 
 396 bool wxTextCtrl::Create(wxWindow 
*parent
, wxWindowID id
, 
 399            const wxSize
& size
, long style
, 
 400            const wxValidator
& validator
, 
 401            const wxString
& name
) 
 403     m_macIsUserPane 
= false ; 
 406     if ( ! ( style 
& wxNO_BORDER
) ) 
 407         style 
= ( style 
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER 
; 
 409     if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style 
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) ) 
 412     Rect bounds 
= wxMacGetBoundsForControl( this , pos 
, size 
) ; 
 414     if ( m_windowStyle 
& wxTE_MULTILINE 
) 
 416         wxASSERT_MSG( !(m_windowStyle 
& wxTE_PROCESS_ENTER
), 
 417                       wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") ); 
 419         m_windowStyle 
|= wxTE_PROCESS_ENTER
; 
 420         style 
|= wxTE_PROCESS_ENTER 
; 
 424 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 
 425     if ( UMAGetSystemVersion() >= 0x1030 ) 
 427         m_peer 
= new wxMacMLTEHIViewControl( this , str 
, pos 
, size 
, style 
) ; 
 430 #if !wxMAC_AWAYS_USE_MLTE 
 433         m_peer 
= new wxMacUnicodeTextControl( this , str 
, pos 
, size 
, style 
) ; 
 439         m_peer 
= new wxMacMLTEClassicControl( this , str 
, pos 
, size 
, style 
) ; 
 442     MacPostControlCreate(pos
,size
) ; 
 444     if ( m_windowStyle 
& wxTE_READONLY
) 
 446         SetEditable( false ) ; 
 452 void wxTextCtrl::MacSuperChangedPosition()  
 454     wxWindow::MacSuperChangedPosition() ; 
 455     GetPeer()->SuperChangedPosition() ; 
 458 void wxTextCtrl::MacVisibilityChanged() 
 460     GetPeer()->VisibilityChanged( MacIsReallyShown() ) ; 
 463 void wxTextCtrl::MacEnabledStateChanged() 
 467 wxString 
wxTextCtrl::GetValue() const 
 469     return GetPeer()->GetStringValue() ; 
 472 void wxTextCtrl::GetSelection(long* from
, long* to
) const 
 474     GetPeer()->GetSelection( from 
, to 
) ; 
 477 void wxTextCtrl::SetValue(const wxString
& str
) 
 480     if ( GetValue() == str 
) 
 483     GetPeer()->SetStringValue(str
) ; 
 485     wxCommandEvent 
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
); 
 486     event
.SetString( GetValue() ) ; 
 487     event
.SetEventObject( this ); 
 488     GetEventHandler()->ProcessEvent(event
); 
 491 void wxTextCtrl::SetMaxLength(unsigned long len
) 
 496 bool wxTextCtrl::SetFont( const wxFont
& font 
) 
 498     if ( !wxTextCtrlBase::SetFont( font 
) ) 
 501     GetPeer()->SetFont( font 
, GetForegroundColour() , GetWindowStyle() ) ; 
 505 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
) 
 507     GetPeer()->SetStyle( start 
, end 
, style 
) ; 
 511 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
) 
 513     wxTextCtrlBase::SetDefaultStyle( style 
) ; 
 514     SetStyle( kTXNUseCurrentSelection 
, kTXNUseCurrentSelection 
, GetDefaultStyle() ) ; 
 518 // Clipboard operations 
 519 void wxTextCtrl::Copy() 
 527 void wxTextCtrl::Cut() 
 533         wxCommandEvent 
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
); 
 534         event
.SetEventObject( this ); 
 535         GetEventHandler()->ProcessEvent(event
); 
 539 void wxTextCtrl::Paste() 
 544         // eventually we should add setting the default style again 
 546         wxCommandEvent 
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
); 
 547         event
.SetEventObject( this ); 
 548         GetEventHandler()->ProcessEvent(event
); 
 552 bool wxTextCtrl::CanCopy() const 
 554     // Can copy if there's a selection 
 556     GetSelection(& from
, & to
); 
 560 bool wxTextCtrl::CanCut() const 
 566     // Can cut if there's a selection 
 568     GetSelection(& from
, & to
); 
 572 bool wxTextCtrl::CanPaste() const 
 577     return GetPeer()->CanPaste() ; 
 580 void wxTextCtrl::SetEditable(bool editable
) 
 582     if ( editable 
!= m_editable 
) 
 584         m_editable 
= editable 
; 
 585         GetPeer()->SetEditable( editable 
) ; 
 589 void wxTextCtrl::SetInsertionPoint(long pos
) 
 591     SetSelection( pos 
, pos 
) ; 
 594 void wxTextCtrl::SetInsertionPointEnd() 
 596     wxTextPos pos 
= GetLastPosition(); 
 597     SetInsertionPoint(pos
); 
 600 long wxTextCtrl::GetInsertionPoint() const 
 603     GetSelection( &begin 
, &end 
) ; 
 607 wxTextPos 
wxTextCtrl::GetLastPosition() const 
 609     return GetPeer()->GetLastPosition( ) ; 
 612 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
) 
 614     GetPeer()->Replace( from 
, to 
, str
) ; 
 617 void wxTextCtrl::Remove(long from
, long to
) 
 619     GetPeer()->Remove( from 
, to 
) ; 
 622 void wxTextCtrl::SetSelection(long from
, long to
) 
 624     GetPeer()->SetSelection( from 
, to 
) ; 
 627 bool wxTextCtrl::LoadFile(const wxString
& file
) 
 629     if ( wxTextCtrlBase::LoadFile(file
) ) 
 637 void wxTextCtrl::WriteText(const wxString
& str
) 
 639     // TODO this MPRemoting will be moved into a remoting peer proxy for any command 
 640     if ( !wxIsMainThread() ) 
 642         // unfortunately CW 8 is not able to correctly deduce the template types, so we have 
 643         // to instantiate explicitely 
 644         wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText 
, str 
) ; 
 649         GetPeer()->WriteText( str 
) ; 
 653 void wxTextCtrl::AppendText(const wxString
& text
) 
 655     SetInsertionPointEnd(); 
 659 void wxTextCtrl::Clear() 
 664 bool wxTextCtrl::IsModified() const 
 669 bool wxTextCtrl::IsEditable() const 
 671     return IsEnabled() && m_editable 
; 
 674 bool wxTextCtrl::AcceptsFocus() const 
 676     // we don't want focus if we can't be edited 
 677     return /*IsEditable() && */ wxControl::AcceptsFocus(); 
 680 wxSize 
wxTextCtrl::DoGetBestSize() const 
 686     // these are the numbers from the HIG, we reduce them by the borders 
 689     switch( m_windowVariant 
) 
 691         case wxWINDOW_VARIANT_NORMAL 
: 
 694         case wxWINDOW_VARIANT_SMALL 
: 
 697         case wxWINDOW_VARIANT_MINI 
: 
 705     // as the above numbers have some free space around the text 
 706     // we get 5 lines like this anyway 
 707     if ( m_windowStyle 
& wxTE_MULTILINE 
) 
 712     if ( !HasFlag(wxNO_BORDER
) ) 
 715     return wxSize(wText
, hText
); 
 718 // ---------------------------------------------------------------------------- 
 720 // ---------------------------------------------------------------------------- 
 722 void wxTextCtrl::Undo() 
 730 void wxTextCtrl::Redo() 
 738 bool wxTextCtrl::CanUndo() const 
 744     return GetPeer()->CanUndo() ; 
 747 bool wxTextCtrl::CanRedo() const 
 753     return GetPeer()->CanRedo() ; 
 756 void wxTextCtrl::MarkDirty() 
 761 void wxTextCtrl::DiscardEdits() 
 766 int wxTextCtrl::GetNumberOfLines() const 
 768     return GetPeer()->GetNumberOfLines() ; 
 771 long wxTextCtrl::XYToPosition(long x
, long y
) const 
 773     return GetPeer()->XYToPosition( x 
, y 
) ; 
 776 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const 
 778     return GetPeer()->PositionToXY(pos 
, x 
, y 
) ; 
 781 void wxTextCtrl::ShowPosition(long pos
) 
 783     return GetPeer()->ShowPosition(pos
) ; 
 786 int wxTextCtrl::GetLineLength(long lineNo
) const 
 788     return GetPeer()->GetLineLength(lineNo
) ; 
 791 wxString 
wxTextCtrl::GetLineText(long lineNo
) const 
 793     return GetPeer()->GetLineText(lineNo
) ; 
 800 void wxTextCtrl::Command(wxCommandEvent 
& event
) 
 802     SetValue (event
.GetString()); 
 803     ProcessCommand (event
); 
 806 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
) 
 808     // By default, load the first file into the text window. 
 809     if (event
.GetNumberOfFiles() > 0) 
 811         LoadFile(event
.GetFiles()[0]); 
 815 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
) 
 817     // all erasing should be done by the real mac control implementation 
 818     // while this is true for MLTE under classic, the HITextView is somehow 
 819     // transparent but background erase is not working correctly, so intercept 
 820     // things while we can... 
 824 void wxTextCtrl::OnChar(wxKeyEvent
& event
) 
 826     int key 
= event
.GetKeyCode() ; 
 827     bool eat_key 
= false ; 
 829     if ( key 
== 'c' && event
.MetaDown() ) 
 836     if ( !IsEditable() && key 
!= WXK_LEFT 
&& key 
!= WXK_RIGHT 
&& key 
!= WXK_DOWN 
&& key 
!= WXK_UP 
&& key 
!= WXK_TAB 
&& 
 837         !( key 
== WXK_RETURN 
&& ( (m_windowStyle 
& wxPROCESS_ENTER
) || (m_windowStyle 
& wxTE_MULTILINE
) ) ) 
 838 /*        && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */ 
 845     // Check if we have reached the max # of chars, but still allow navigation and deletion 
 846     if ( !IsMultiLine() && GetValue().Length() >= m_maxLength 
&& 
 847         key 
!= WXK_LEFT 
&& key 
!= WXK_RIGHT 
&& key 
!= WXK_TAB 
&& 
 848         key 
!= WXK_BACK 
&& !( key 
== WXK_RETURN 
&& (m_windowStyle 
& wxPROCESS_ENTER
) ) 
 851         // eat it, we don't want to add more than allowed # of characters 
 855     // assume that any key not processed yet is going to modify the control 
 858     if ( key 
== 'v' && event
.MetaDown() ) 
 864     if ( key 
== 'x' && event
.MetaDown() ) 
 873             if (m_windowStyle 
& wxPROCESS_ENTER
) 
 875                 wxCommandEvent 
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
); 
 876                 event
.SetEventObject( this ); 
 877                 event
.SetString( GetValue() ); 
 878                 if ( GetEventHandler()->ProcessEvent(event
) ) 
 881             if ( !(m_windowStyle 
& wxTE_MULTILINE
) ) 
 883                 wxWindow 
*parent 
= GetParent(); 
 884                 while( parent 
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL 
) { 
 885                   parent 
= parent
->GetParent() ; 
 887                 if ( parent 
&& parent
->GetDefaultItem() ) 
 889                     wxButton 
*def 
= wxDynamicCast(parent
->GetDefaultItem(), 
 891                     if ( def 
&& def
->IsEnabled() ) 
 893                         wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() ); 
 894                         event
.SetEventObject(def
); 
 900                 // this will make wxWidgets eat the ENTER key so that 
 901                 // we actually prevent line wrapping in a single line 
 909             if ( !(m_windowStyle 
& wxTE_PROCESS_TAB
)) 
 912                 if (!event
.ShiftDown()) 
 913                     flags 
|= wxNavigationKeyEvent::IsForward 
; 
 914                 if (event
.ControlDown()) 
 915                     flags 
|= wxNavigationKeyEvent::WinChange 
; 
 921                 // This is necessary (don't know why) or the tab will not 
 923                 WriteText(wxT("\t")); 
 931         // perform keystroke handling 
 932         if ( wxTheApp
->MacGetCurrentEvent() != NULL 
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL 
) 
 933             CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ; 
 937             if ( wxMacConvertEventToRecord(  (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec 
) ) 
 939                 EventRecord 
*ev 
= &rec 
; 
 942                 keychar 
= short(ev
->message 
& charCodeMask
); 
 943                 keycode 
= short(ev
->message 
& keyCodeMask
) >> 8 ; 
 945                 m_peer
->HandleKey( keycode 
, keychar 
, ev
->modifiers 
) ; 
 949     if ( ( key 
>= 0x20 && key 
< WXK_START 
) || 
 954         wxCommandEvent 
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
); 
 955         event1
.SetEventObject( this ); 
 956         wxPostEvent(GetEventHandler(),event1
); 
 960 // ---------------------------------------------------------------------------- 
 961 // standard handlers for standard edit menu events 
 962 // ---------------------------------------------------------------------------- 
 964 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
)) 
 969 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
)) 
 974 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
)) 
 979 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
)) 
 984 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
)) 
 989 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
) 
 991     event
.Enable( CanCut() ); 
 994 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
) 
 996     event
.Enable( CanCopy() ); 
 999 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
) 
1001     event
.Enable( CanPaste() ); 
1004 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
) 
1006     event
.Enable( CanUndo() ); 
1009 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
) 
1011     event
.Enable( CanRedo() ); 
1014 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt 
) 
1018 #if !TARGET_API_MAC_OSX 
1020 // user pane implementation 
1022 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
) 
1024     GetPeer()->MacControlUserPaneDrawProc( part 
) ; 
1027 wxInt16 
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) 
1029     return GetPeer()->MacControlUserPaneHitTestProc( x 
, y 
) ; 
1032 wxInt16 
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) 
1034     return GetPeer()->MacControlUserPaneTrackingProc( x 
, y 
, actionProc 
) ; 
1037 void wxTextCtrl::MacControlUserPaneIdleProc() 
1039     GetPeer()->MacControlUserPaneIdleProc( ) ; 
1042 wxInt16 
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) 
1044     return GetPeer()->MacControlUserPaneKeyDownProc( keyCode 
, charCode 
, modifiers 
) ; 
1047 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
) 
1049     GetPeer()->MacControlUserPaneActivateProc( activating 
) ; 
1052 wxInt16 
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
) 
1054     return GetPeer()->MacControlUserPaneFocusProc( action 
) ; 
1057 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
) 
1059     GetPeer()->MacControlUserPaneBackgroundProc( info 
) ; 
1063 // ---------------------------------------------------------------------------- 
1064 // implementation base class 
1065 // ---------------------------------------------------------------------------- 
1067 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) : 
1068     wxMacControl( peer 
) 
1072 wxMacTextControl::~wxMacTextControl() 
1076 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
) 
1080 void wxMacTextControl::Copy() 
1084 void wxMacTextControl::Cut() 
1088 void wxMacTextControl::Paste() 
1092 bool wxMacTextControl::CanPaste() const 
1097 void wxMacTextControl::SetEditable(bool editable
) 
1101 wxTextPos 
wxMacTextControl::GetLastPosition() const 
1103     return GetStringValue().Length() ; 
1106 void wxMacTextControl::Replace( long from 
, long to 
, const wxString str 
) 
1110 void wxMacTextControl::Clear() 
1112     SetStringValue( wxEmptyString 
) ; 
1115 bool wxMacTextControl::CanUndo() const 
1120 void wxMacTextControl::Undo() { } 
1122 bool wxMacTextControl::CanRedo()  const 
1127 void wxMacTextControl::Redo() 
1131 long wxMacTextControl::XYToPosition(long x
, long y
) const 
1136 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const 
1141 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) ) 
1145 int wxMacTextControl::GetNumberOfLines() const 
1147     ItemCount lines 
= 0 ; 
1148     wxString content 
= GetStringValue() ; 
1150     for (size_t i 
= 0; i 
< content
.Length() ; i
++) 
1152         if (content
[i
] == '\r') lines
++; 
1157 wxString 
wxMacTextControl::GetLineText(long lineNo
) const 
1159     // TODO change this if possible to reflect real lines 
1160     wxString content 
= GetStringValue() ; 
1164     for (size_t i 
= 0; i 
< content
.Length() ; i
++) 
1166         if (count 
== lineNo
) 
1168             // Add chars in line then 
1171             for (size_t j 
= i
; j 
< content
.Length(); j
++) 
1173                 if (content
[j
] == '\n') 
1181         if (content
[i
] == '\n') count
++; 
1183     return wxEmptyString 
; 
1186 int  wxMacTextControl::GetLineLength(long lineNo
) const 
1188     // TODO change this if possible to reflect real lines 
1189     wxString content 
= GetStringValue() ; 
1193     for (size_t i 
= 0; i 
< content
.Length() ; i
++) 
1195         if (count 
== lineNo
) 
1197             // Count chars in line then 
1199             for (size_t j 
= i
; j 
< content
.Length(); j
++) 
1202                 if (content
[j
] == '\n') return count
; 
1207         if (content
[i
] == '\n') count
++; 
1212 // ---------------------------------------------------------------------------- 
1213 // standard unicode control implementation 
1214 // ---------------------------------------------------------------------------- 
1216 #if TARGET_API_MAC_OSX 
1218 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl 
*wxPeer
, 
1219                          const wxString
& str
, 
1221                          const wxSize
& size
, long style 
) : wxMacTextControl( wxPeer 
) 
1223     m_font 
= wxPeer
->GetFont() ; 
1224     m_windowStyle 
= style 
; 
1225     Rect bounds 
= wxMacGetBoundsForControl( wxPeer 
, pos 
, size 
) ; 
1227     wxMacConvertNewlines10To13( &st 
) ; 
1228     wxMacCFStringHolder 
cf(st 
, m_font
.GetEncoding()) ; 
1229     CFStringRef cfr 
= cf 
; 
1230     Boolean isPassword 
= ( m_windowStyle 
& wxTE_PASSWORD 
) != 0 ; 
1231     m_valueTag 
= isPassword 
? kControlEditTextPasswordCFStringTag 
: kControlEditTextCFStringTag 
; 
1232     CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds 
, cfr 
, isPassword 
, NULL 
, &m_controlRef 
) ; 
1234     if ( !(m_windowStyle 
& wxTE_MULTILINE
) ) 
1236         SetData
<Boolean
>( kControlEditTextPart 
, kControlEditTextSingleLineTag 
, true ) ; 
1240 wxMacUnicodeTextControl::~wxMacUnicodeTextControl() 
1244 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
) 
1246     if ( !(m_windowStyle 
& wxTE_MULTILINE
) && shown 
) 
1248         // work around a refresh issue insofar as not always the entire content is shown even if this would be possible 
1249         ControlEditTextSelectionRec sel 
; 
1250         CFStringRef value 
= NULL 
; 
1252         verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel 
) ); 
1253         verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag 
, &value 
) ); 
1254         verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value 
) ); 
1255         verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel 
) ); 
1257         CFRelease( value 
) ; 
1260 wxString 
wxMacUnicodeTextControl::GetStringValue() const 
1263     CFStringRef value 
= GetData
<CFStringRef
>(0,m_valueTag
) ; 
1266         wxMacCFStringHolder 
cf(value
) ; 
1267         result 
= cf
.AsString() ; 
1270     wxMacConvertNewlines13To10( &result 
) ; 
1272     wxMacConvertNewlines10To13( &result 
) ; 
1276 void wxMacUnicodeTextControl::SetStringValue( const wxString 
&str
) 
1279     wxMacConvertNewlines10To13( &st 
) ; 
1280     wxMacCFStringHolder 
cf(st 
, m_font
.GetEncoding() ) ; 
1281     verify_noerr( SetData
<CFStringRef
>(  0, m_valueTag 
, cf 
) ) ; 
1283 void wxMacUnicodeTextControl::Copy() 
1285     SendHICommand( kHICommandCopy 
) ; 
1287 void wxMacUnicodeTextControl::Cut() 
1289     SendHICommand( kHICommandCut 
) ; 
1291 void wxMacUnicodeTextControl::Paste() 
1293     SendHICommand( kHICommandPaste 
) ; 
1295 bool wxMacUnicodeTextControl::CanPaste() const 
1299 void wxMacUnicodeTextControl::SetEditable(bool editable
) 
1301     SetData
<Boolean
>( 0 , kControlEditTextLockedTag 
, (Boolean
) !editable 
) ; 
1303 void wxMacUnicodeTextControl::Remove( long from 
, long to 
) 
1307 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const 
1309     ControlEditTextSelectionRec sel 
; 
1310     verify_noerr(GetData
<ControlEditTextSelectionRec
>(  0, kControlEditTextSelectionTag
, &sel 
) ) ; 
1311     if ( from 
) *from 
= sel
.selStart 
; 
1312     if ( to 
) *to 
= sel
.selEnd 
; 
1315 void wxMacUnicodeTextControl::SetSelection( long from 
, long to 
) 
1317     ControlEditTextSelectionRec sel 
; 
1318     sel
.selStart 
= from 
; 
1320     SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel 
) ; 
1323 void wxMacUnicodeTextControl::WriteText(const wxString
& str
) 
1326     wxMacConvertNewlines10To13( &st 
) ; 
1327     #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 
1328         wxMacCFStringHolder 
cf(st 
, m_font
.GetEncoding() ) ; 
1329         CFStringRef value 
= cf 
; 
1330         SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value 
); 
1332         wxString val 
= GetStringValue() ; 
1334         GetSelection( &start 
, &end 
) ; 
1335         val
.Remove( start 
, end 
- start 
) ; 
1336         val
.insert( start 
, str 
) ; 
1337         SetStringValue( val 
) ; 
1338         SetSelection( start 
+ str
.Length() , start 
+ str
.Length() ) ; 
1344 // ---------------------------------------------------------------------------- 
1345 // MLTE control implementation (common part) 
1346 // ---------------------------------------------------------------------------- 
1348 // if mlte is on read only , no changes at all are allowed, not even from 
1349 // procedural API, in order to allow changes via API all the same we must undo 
1350 // the readonly status while we are executing, this class helps to do so 
1355     EditHelper( TXNObject txn 
) 
1357         TXNControlTag tag
[] = { kTXNIOPrivilegesTag 
} ; 
1359         TXNGetTXNObjectControls( m_txn 
, 1 , tag 
, m_data 
) ; 
1360         if ( m_data
[0].uValue 
== kTXNReadOnly 
) 
1362             TXNControlData data
[] = { { kTXNReadWrite 
} } ; 
1363             TXNSetTXNObjectControls( m_txn 
, false , 1 , tag 
, data 
) ; 
1368         TXNControlTag tag
[] = { kTXNIOPrivilegesTag 
} ; 
1369         if ( m_data
[0].uValue 
== kTXNReadOnly 
) 
1371             TXNSetTXNObjectControls( m_txn 
, false , 1 , tag 
, m_data 
) ; 
1376         TXNControlData m_data
[1] ; 
1379 wxString 
wxMacMLTEControl::GetStringValue() const 
1383     Size actualSize 
= 0; 
1387         err 
= TXNGetDataEncoded( m_txn 
, kTXNStartOffset
, kTXNEndOffset
, &theText 
, kTXNUnicodeTextData 
); 
1395             actualSize 
= GetHandleSize( theText 
) / sizeof( UniChar
) ; 
1396             if ( actualSize 
> 0 ) 
1398                 wxChar 
*ptr 
= NULL 
; 
1399 #if SIZEOF_WCHAR_T == 2 
1400                 ptr 
= new wxChar
[actualSize 
+ 1 ] ; 
1401                 wxStrncpy( ptr 
, (wxChar
*) *theText 
, actualSize 
) ; 
1403                 SetHandleSize( theText 
, ( actualSize 
+ 1 ) * sizeof( UniChar 
) ) ; 
1405                 (((UniChar
*)*theText
)[actualSize
]) = 0 ; 
1406                 wxMBConvUTF16BE converter 
; 
1407                 size_t noChars 
= converter
.MB2WC( NULL 
, (const char*)*theText 
, 0 ) ; 
1408                 ptr 
= new wxChar
[noChars 
+ 1] ; 
1410                 noChars 
= converter
.MB2WC( ptr 
, (const char*)*theText 
, noChars 
) ; 
1412                 HUnlock( theText 
) ; 
1414                 ptr
[actualSize
] = 0 ; 
1415                 result 
= wxString( ptr 
) ; 
1418             DisposeHandle( theText 
) ; 
1422         err 
= TXNGetDataEncoded( m_txn 
, kTXNStartOffset
, kTXNEndOffset
, &theText 
, kTXNTextData 
); 
1430             actualSize 
= GetHandleSize( theText 
) ; 
1431             if ( actualSize 
> 0 ) 
1434                 result 
= wxString( *theText 
, wxConvLocal 
, actualSize 
) ; 
1435                 HUnlock( theText 
) ; 
1437             DisposeHandle( theText 
) ; 
1442     wxMacConvertNewlines13To10( &result 
) ; 
1444     wxMacConvertNewlines10To13( &result 
) ; 
1449 void wxMacMLTEControl::SetStringValue( const wxString 
&str
) 
1453     wxMacConvertNewlines10To13( &st 
) ; 
1454     EditHelper 
help(m_txn
) ; 
1456 #if !TARGET_API_MAC_OSX 
1457     // otherwise scrolling might have problems ? 
1458 //    MacUpdatePosition( m_controlRef ) ; 
1460     wxMacWindowClipper 
c( m_peer 
) ; 
1461     SetTXNData( st 
, kTXNStartOffset
, kTXNEndOffset 
) ; 
1462     TXNSetSelection( m_txn
, 0, 0); 
1463     TXNShowSelection( m_txn
, kTXNShowStart
); 
1466 TXNFrameOptions 
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle 
) 
1468     TXNFrameOptions frameOptions 
= 
1469         kTXNDontDrawCaretWhenInactiveMask 
; 
1470     if ( ! ( wxStyle 
& wxTE_NOHIDESEL 
) ) 
1471         frameOptions 
|= kTXNDontDrawSelectionWhenInactiveMask 
; 
1473     if ( wxStyle 
& wxTE_MULTILINE 
) 
1475         if ( ! ( wxStyle 
& wxTE_DONTWRAP 
) ) 
1476             frameOptions 
|= kTXNAlwaysWrapAtViewEdgeMask 
; 
1479             frameOptions 
|= kTXNAlwaysWrapAtViewEdgeMask 
; 
1480             frameOptions 
|= kTXNWantHScrollBarMask 
; 
1483         if ( !(wxStyle 
& wxTE_NO_VSCROLL 
) ) 
1484             frameOptions 
|= kTXNWantVScrollBarMask 
; 
1487         frameOptions 
|= kTXNSingleLineOnlyMask 
; 
1489     if ( wxStyle 
& wxHSCROLL 
) 
1490         frameOptions 
|= kTXNWantHScrollBarMask 
; 
1492     return frameOptions 
; 
1495 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour 
&background
, bool visible 
) 
1497     TXNControlTag iControlTags
[3] = { kTXNDoFontSubstitution
, kTXNWordWrapStateTag 
}; 
1498     TXNControlData iControlData
[3] = { {false}, {kTXNNoAutoWrap
} }; 
1500 #if TARGET_API_MAC_OSX 
1501     iControlTags
[2] = kTXNVisibilityTag 
; 
1502     iControlData
[2].uValue 
= visible 
; 
1506     if ( m_windowStyle 
& wxTE_MULTILINE 
) 
1508         if (m_windowStyle 
& wxTE_DONTWRAP
) 
1509             iControlData
[1].uValue 
= kTXNNoAutoWrap 
; 
1511             iControlData
[1].uValue 
= kTXNAutoWrap 
; 
1513     verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, 
1514                                         iControlTags
, iControlData 
)) ; 
1516     // setting the default font 
1522     GetThemeFont(kThemeSystemFont 
, GetApplicationScript() , fontName 
, &fontSize 
, &fontStyle 
) ; 
1524     TXNTypeAttributes typeAttr
[] = 
1526         {   kTXNQDFontNameAttribute 
, kTXNQDFontNameAttributeSize 
, { (void*) fontName 
} } , 
1527         {   kTXNQDFontSizeAttribute 
, kTXNFontSizeAttributeSize 
, { (void*) (fontSize 
<< 16) } } , 
1528         {   kTXNQDFontStyleAttribute 
, kTXNQDFontStyleAttributeSize 
, {  (void*) normal 
} } , 
1531     verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr 
) / sizeof(TXNTypeAttributes
) , typeAttr
, 
1535     if ( m_windowStyle 
& wxTE_PASSWORD 
) 
1538         verify_noerr(TXNEchoMode( m_txn 
, c 
, 0 , true )) ; 
1541     TXNBackground tback
; 
1542     tback
.bgType 
= kTXNBackgroundTypeRGB
; 
1543     tback
.bg
.color 
= MAC_WXCOLORREF( background
.GetPixel() ); 
1544     TXNSetBackground( m_txn 
, &tback
); 
1547 void wxMacMLTEControl::SetBackground( const wxBrush 
&brush 
) 
1549     // currently only solid background are supported 
1550     TXNBackground tback
; 
1551     tback
.bgType 
= kTXNBackgroundTypeRGB
; 
1552     tback
.bg
.color 
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() ); 
1553     TXNSetBackground( m_txn 
, &tback
); 
1556 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style 
, long from 
, long to
) 
1558     TXNTypeAttributes typeAttr
[4] ; 
1559     Str255 fontName 
= "\pMonaco" ; 
1560     SInt16 fontSize 
= 12 ; 
1561     Style fontStyle 
= normal 
; 
1563     int attrCounter 
= 0 ; 
1564     if ( style
.HasFont() ) 
1566         const wxFont 
&font 
= style
.GetFont() ; 
1567         wxMacStringToPascal( font
.GetFaceName() , fontName 
) ; 
1568         fontSize 
= font
.GetPointSize() ; 
1569         if ( font
.GetUnderlined() ) 
1570             fontStyle 
|= underline 
; 
1571         if ( font
.GetWeight() == wxBOLD 
) 
1573         if ( font
.GetStyle() == wxITALIC 
) 
1574             fontStyle 
|= italic 
; 
1576         typeAttr
[attrCounter
].tag 
= kTXNQDFontNameAttribute 
; 
1577         typeAttr
[attrCounter
].size 
= kTXNQDFontNameAttributeSize 
; 
1578         typeAttr
[attrCounter
].data
.dataPtr 
= (void*) fontName 
; 
1579         typeAttr
[attrCounter
+1].tag 
= kTXNQDFontSizeAttribute 
; 
1580         typeAttr
[attrCounter
+1].size 
= kTXNFontSizeAttributeSize 
; 
1581         typeAttr
[attrCounter
+1].data
.dataValue 
=  (fontSize 
<< 16) ; 
1582         typeAttr
[attrCounter
+2].tag 
= kTXNQDFontStyleAttribute 
; 
1583         typeAttr
[attrCounter
+2].size 
= kTXNQDFontStyleAttributeSize 
; 
1584         typeAttr
[attrCounter
+2].data
.dataValue 
= fontStyle 
; 
1587     if ( style
.HasTextColour() ) 
1589         typeAttr
[attrCounter
].tag 
= kTXNQDFontColorAttribute 
; 
1590         typeAttr
[attrCounter
].size 
= kTXNQDFontColorAttributeSize 
; 
1591         typeAttr
[attrCounter
].data
.dataPtr 
= (void*) &color 
; 
1592         color 
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ; 
1595     if ( attrCounter 
> 0 ) 
1597         verify_noerr( TXNSetTypeAttributes ( m_txn 
, attrCounter 
, typeAttr
, from 
, to
) ); 
1601 void wxMacMLTEControl::SetFont( const wxFont 
& font 
, const wxColour
& foreground 
, long windowStyle 
) 
1603     EditHelper 
help(m_txn
) ; 
1604     TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset 
) ; 
1606 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
) 
1608     EditHelper 
help(m_txn
) ; 
1609     TXNSetAttribute( style 
, start
,end 
) ; 
1612 void wxMacMLTEControl::Copy() 
1614     ClearCurrentScrap(); 
1616     TXNConvertToPublicScrap(); 
1619 void wxMacMLTEControl::Cut() 
1621     ClearCurrentScrap(); 
1623     TXNConvertToPublicScrap(); 
1626 void wxMacMLTEControl::Paste() 
1628     TXNConvertFromPublicScrap(); 
1632 bool wxMacMLTEControl::CanPaste() const 
1634     return TXNIsScrapPastable() ; 
1637 void wxMacMLTEControl::SetEditable(bool editable
) 
1639     TXNControlTag tag
[] = { kTXNIOPrivilegesTag 
} ; 
1640     TXNControlData data
[] = { { editable 
? kTXNReadWrite 
: kTXNReadOnly 
} } ; 
1641     TXNSetTXNObjectControls( m_txn 
, false , sizeof(tag
) / sizeof (TXNControlTag
) , tag 
, data 
) ; 
1644 wxTextPos 
wxMacMLTEControl::GetLastPosition() const 
1646     wxTextPos actualsize 
= 0 ; 
1649     OSErr err 
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText 
, kTXNTextData 
); 
1657         actualsize 
= GetHandleSize( theText 
) ; 
1658         DisposeHandle( theText 
) ; 
1664 void wxMacMLTEControl::Replace( long from 
, long to 
, const wxString str 
) 
1666     wxString value 
= str 
; 
1667     wxMacConvertNewlines10To13( &value 
) ; 
1669     EditHelper 
help( m_txn 
) ; 
1670     wxMacWindowClipper 
c( m_peer 
) ; 
1672     TXNSetSelection(m_txn 
, from 
, to 
) ; 
1674     SetTXNData( value 
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection 
) ; 
1677 void wxMacMLTEControl::Remove( long from 
, long to 
) 
1679     wxMacWindowClipper 
c( m_peer 
) ; 
1680     EditHelper 
help( m_txn 
) ; 
1681     TXNSetSelection(m_txn 
, from 
, to 
) ; 
1685 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const 
1687     TXNGetSelection( m_txn 
, (TXNOffset
*) from 
, (TXNOffset
*) to 
) ; 
1690 void wxMacMLTEControl::SetSelection( long from 
, long to 
) 
1692     wxMacWindowClipper 
c( m_peer 
) ; 
1693     /* change the selection */ 
1694     if ((from 
== -1) && (to 
== -1)) 
1695         TXNSelectAll(m_txn
); 
1697         TXNSetSelection( m_txn
, from
, to
); 
1698     TXNShowSelection( m_txn
, kTXNShowStart
); 
1701 void wxMacMLTEControl::WriteText(const wxString
& str
) 
1703     EditHelper 
helper( m_txn 
) ; 
1705     wxMacConvertNewlines10To13( &st 
) ; 
1707     wxMacWindowClipper 
c( m_peer 
) ; 
1708     long start 
, end 
, dummy 
; 
1709     GetSelection( &start 
, &dummy 
) ; 
1710     SetTXNData( st 
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection 
) ; 
1711     GetSelection( &dummy 
, &end 
) ; 
1712     // TODO SetStyle( start , end , GetDefaultStyle() ) ; 
1715 void wxMacMLTEControl::Clear() 
1717     EditHelper 
st(m_txn
) ; 
1718     wxMacWindowClipper 
c( m_peer 
) ; 
1719     TXNSetSelection( m_txn 
, kTXNStartOffset 
, kTXNEndOffset 
) ; 
1723 bool wxMacMLTEControl::CanUndo() const 
1725     return TXNCanUndo( m_txn 
, NULL 
) ; 
1728 void wxMacMLTEControl::Undo() 
1733 bool wxMacMLTEControl::CanRedo()  const 
1735     return TXNCanRedo( m_txn 
, NULL 
) ; 
1738 void wxMacMLTEControl::Redo() 
1743 int wxMacMLTEControl::GetNumberOfLines() const 
1745     ItemCount lines 
= 0 ; 
1746     TXNGetLineCount(m_txn
, &lines 
) ; 
1750 long wxMacMLTEControl::XYToPosition(long x
, long y
) const 
1754     wxTextPos lastpos 
= GetLastPosition() ; 
1756     // TODO find a better implementation : while we can get the 
1757     // line metrics of a certain line, we don't get its starting 
1758     // position, so it would probably be rather a binary search 
1759     // for the start position 
1762     int lastHeight 
= 0 ; 
1765     for ( n 
= 0 ; n 
<= (ItemCount
) lastpos 
; ++n 
) 
1767         if ( y 
== ypos 
&& x 
== xpos 
) 
1770         TXNOffsetToPoint( m_txn 
,  n 
, &curpt
); 
1772         if ( curpt
.v 
> lastHeight 
) 
1777             lastHeight 
= curpt
.v 
; 
1785 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const 
1789     wxTextPos lastpos 
= GetLastPosition() ; 
1794     if ( pos 
<= lastpos 
) 
1796         // TODO find a better implementation : while we can get the 
1797         // line metrics of a certain line, we don't get its starting 
1798         // position, so it would probably be rather a binary search 
1799         // for the start position 
1802         int lastHeight 
= 0 ; 
1805         for ( n 
= 0 ; n 
<= (ItemCount
) pos 
; ++n 
) 
1807             TXNOffsetToPoint(m_txn 
,  n 
, &curpt
); 
1809             if ( curpt
.v 
> lastHeight 
) 
1814                 lastHeight 
= curpt
.v 
; 
1819         if ( y 
) *y 
= ypos 
; 
1820         if ( x 
) *x 
= xpos 
; 
1826 void wxMacMLTEControl::ShowPosition( long pos 
) 
1828 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER) 
1832         TXNOffset selstart 
, selend 
; 
1833         TXNGetSelection(  m_txn 
, &selstart 
, &selend
) ; 
1834         TXNOffsetToPoint( m_txn
,  selstart 
, ¤t
); 
1835         TXNOffsetToPoint( m_txn
,  pos 
, &desired
); 
1836         //TODO use HIPoints for 10.3 and above 
1837         if ( (UInt32
) TXNScroll 
!= (UInt32
) kUnresolvedCFragSymbolAddress 
) 
1839             OSErr theErr 
= noErr
; 
1840             SInt32 dv 
= desired
.v 
- current
.v 
; 
1841             SInt32 dh 
= desired
.h 
- current
.h 
; 
1842             TXNShowSelection( m_txn 
, true ) ; 
1843             theErr 
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels 
, kTXNScrollUnitsInPixels 
, &dv 
, &dh 
); 
1844             wxASSERT_MSG( theErr 
== noErr
, _T("TXNScroll returned an error!") ); 
1850 void wxMacMLTEControl::SetTXNData( const wxString
& st 
, TXNOffset start 
, TXNOffset end 
) 
1853 #if SIZEOF_WCHAR_T == 2 
1854     size_t len 
= st
.Len() ; 
1855     TXNSetData( m_txn 
, kTXNUnicodeTextData
,  (void*)st
.wc_str(), len 
* 2, 
1858     wxMBConvUTF16BE converter 
; 
1859     ByteCount byteBufferLen 
= converter
.WC2MB( NULL 
, st
.wc_str() , 0 ) ; 
1860     UniChar 
*unibuf 
= (UniChar
*) malloc(byteBufferLen
) ; 
1861     converter
.WC2MB( (char*) unibuf 
, st
.wc_str() , byteBufferLen 
) ; 
1862     TXNSetData( m_txn 
, kTXNUnicodeTextData
,  (void*)unibuf
, byteBufferLen 
, 
1867     wxCharBuffer text 
=  st
.mb_str(wxConvLocal
)  ; 
1868     TXNSetData( m_txn 
, kTXNTextData
,  (void*)text
.data(), strlen( text 
) , 
1874 wxString 
wxMacMLTEControl::GetLineText(long lineNo
) const 
1878     if ( lineNo 
< GetNumberOfLines() ) 
1886         // get the first possible position in the control 
1888         TXNOffsetToPoint(m_txn
, 0, &firstPoint
); 
1890         // Iterate through the lines until we reach the one we want, 
1891         // adding to our current y pixel point position 
1892         while (ypos 
< lineNo
) 
1894             TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
); 
1895             currentHeight 
+= lineHeight
; 
1898         Point thePoint 
= { firstPoint
.v 
+ (currentHeight 
>> 16), firstPoint
.h 
+ (0) }; 
1899         TXNOffset theOffset
; 
1900         TXNPointToOffset(m_txn
, thePoint
, &theOffset
); 
1902         wxString content 
= GetStringValue() ; 
1903         Point currentPoint 
= thePoint
; 
1904         while(thePoint
.v 
== currentPoint
.v 
&& theOffset 
< content
.length()) 
1906             line 
+= content
[theOffset
]; 
1907             TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
); 
1913 int  wxMacMLTEControl::GetLineLength(long lineNo
) const 
1917     if ( lineNo 
< GetNumberOfLines() ) 
1925         // get the first possible position in the control 
1927         TXNOffsetToPoint(m_txn
, 0, &firstPoint
); 
1929         // Iterate through the lines until we reach the one we want, 
1930         // adding to our current y pixel point position 
1931         while (ypos 
< lineNo
) 
1933             TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
); 
1934             currentHeight 
+= lineHeight
; 
1937         Point thePoint 
= { firstPoint
.v 
+ (currentHeight 
>> 16), firstPoint
.h 
+ (0) }; 
1938         TXNOffset theOffset
; 
1939         TXNPointToOffset(m_txn
, thePoint
, &theOffset
); 
1941         wxString content 
= GetStringValue() ; 
1942         Point currentPoint 
= thePoint
; 
1943         while(thePoint
.v 
== currentPoint
.v 
&& theOffset 
< content
.length()) 
1946             TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
); 
1953 // ---------------------------------------------------------------------------- 
1954 // MLTE control implementation (classic part) 
1955 // ---------------------------------------------------------------------------- 
1957 // CS:TODO we still have a problem getting properly at the text events of a control because under Carbon 
1958 // the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the 
1959 // moment is to avoid setting the true focus on the control, the proper solution at the end would be to have 
1960 // an alternate path for carbon key events that routes automatically into the same wx flow of events 
1964 /* kmUPTextPart is the part code we return to indicate the user has clicked 
1965 in the text area of our control */ 
1966 #define kmUPTextPart 1 
1969 /* routines for using existing user pane controls. 
1970 These routines are useful for cases where you would like to use an 
1971 existing user pane control in, say, a dialog window as a scrolling 
1974 /* Utility Routines */ 
1976 /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus 
1977 routine.  In our focus switching routine this part code is understood 
1978 as meaning 'the user has clicked in the control and we need to switch 
1979 the current focus to ourselves before we can continue'. */ 
1980 #define kUserClickedToFocusPart 100 
1982 /* STPTextPaneVars is a structure used for storing the the mUP Control's 
1983 internal variables and state information.  A handle to this record is 
1984 stored in the pane control's reference value field using the 
1985 SetControlReference routine. */ 
1987 /* Univerals Procedure Pointer variables used by the 
1988 mUP Control.  These variables are set up 
1989 the first time that mUPOpenControl is called. */ 
1990 ControlUserPaneDrawUPP gTPDrawProc 
= NULL
; 
1991 ControlUserPaneHitTestUPP gTPHitProc 
= NULL
; 
1992 ControlUserPaneTrackingUPP gTPTrackProc 
= NULL
; 
1993 ControlUserPaneIdleUPP gTPIdleProc 
= NULL
; 
1994 ControlUserPaneKeyDownUPP gTPKeyProc 
= NULL
; 
1995 ControlUserPaneActivateUPP gTPActivateProc 
= NULL
; 
1996 ControlUserPaneFocusUPP gTPFocusProc 
= NULL
; 
1999 class wxMacMLTENoDraw
 
2002     wxMacMLTENoDraw( TXNObject txn 
) ; 
2003     ~wxMacMLTENoDraw() ; 
2010 wxMacMLTENoDraw::wxMacMLTENoDraw( TXNObject txn 
)  
2013 #ifdef __WXMAC_OSX__ 
2014     TXNControlTag iControlTags
[1] = { kTXNVisibilityTag 
}; 
2015     TXNControlData iControlData
[1] ; 
2017     TXNGetTXNObjectControls( m_txn 
, 1 , iControlTags 
, iControlData 
) ; 
2018     m_formerDraw 
= iControlData
[0].uValue 
; 
2021         iControlData
[0].uValue 
= 0 ; 
2022         TXNSetTXNObjectControls( m_txn 
, 1 , true , iControlTags 
, iControlData 
) ; 
2027 wxMacMLTENoDraw::~wxMacMLTENoDraw()  
2029 #ifdef __WXMAC_OSX__ 
2032         TXNControlTag iControlTags
[1] = { kTXNVisibilityTag 
}; 
2033         TXNControlData iControlData
[1] ; 
2035         iControlData
[0].uValue 
= m_formerDraw 
; 
2036         TXNSetTXNObjectControls( m_txn 
, 1 , true , iControlTags 
, iControlData 
) ; 
2042 // make correct activations 
2043 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)  
2045     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference(m_controlRef
); 
2046     if (m_txnIsActive 
!= setActive 
&& textctrl
->MacIsReallyShown() ) 
2048         m_txnIsActive 
= setActive
; 
2049         // TXNSetScrollBarState 
2051         TXNActivate(m_txn
, m_txnFrameID
, m_txnIsActive
); 
2053             TXNFocus( m_txn
, m_txnIsActive
); 
2057 // update TXN focus state 
2058 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
) { 
2059 /*    wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); */ 
2061     if (m_txnIsFocused 
!= setFocus 
/*&& textctrl->MacIsReallyShown() */ ) { 
2062         m_txnIsFocused 
= setFocus
; 
2063         TXNFocus( m_txn
, m_txnIsFocused
); 
2067 // makes sure that the TXNObject is either offscreen or on screen  
2069 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
) 
2072     OSStatus err 
= noErr 
; 
2074     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference(m_controlRef
); 
2077         TXNControlTag iControlTags
[1] = { kTXNVisibilityTag 
}; 
2078         TXNControlData iControlData
[1] = { { vis 
} }; 
2080         TXNSetTXNObjectControls( m_txn 
, 1 , false , iControlTags 
, iControlData 
) ; 
2085 // make sure that the TXNObject is at the right position 
2086 void wxMacMLTEClassicControl::MacUpdatePosition()  
2088     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference(m_controlRef
); 
2089     if ( textctrl 
== NULL 
) 
2093     UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
); 
2095     if ( !EqualRect( &bounds 
, &m_txnControlBounds 
) ) 
2098         Rect oldBounds 
= m_txnControlBounds 
; 
2099         m_txnControlBounds 
= bounds 
; 
2100         wxMacWindowClipper 
cl(textctrl
) ; 
2101         TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
, 
2102             m_txnControlBounds
.bottom
, m_txnControlBounds
.right
, m_txnFrameID
); 
2103 #ifdef __WXMAC_OSX__ 
2104         if ( m_sbHorizontal 
|| m_sbVertical 
) 
2106             Rect boundsInWindow 
; 
2107             UMAGetControlBoundsInWindowCoords( m_controlRef 
, &boundsInWindow 
) ; 
2109             TXNLongRect destinationRect 
; 
2110             TXNGetRectBounds( m_txn 
, &viewRect 
, &destinationRect 
, NULL 
) ; 
2112             if ( m_sbHorizontal 
) 
2115                 GetControlBounds( m_sbHorizontal 
, &sbBounds 
) ; 
2116                 sbBounds
.right 
-= sbBounds
.left 
; 
2117                 sbBounds
.bottom 
-= sbBounds
.top 
; 
2118                 sbBounds
.left 
= -1 ; 
2119                 sbBounds
.top 
= bounds
.bottom 
- bounds
.top 
- 15 ; 
2120                 sbBounds
.right 
+= sbBounds
.left 
; 
2121                 sbBounds
.bottom 
+= sbBounds
.top 
; 
2122                 SetControlBounds( m_sbHorizontal 
, &sbBounds 
) ; 
2127                 GetControlBounds( m_sbVertical 
, &sbBounds 
) ; 
2128                 sbBounds
.right 
-= sbBounds
.left 
; 
2129                 sbBounds
.bottom 
-= sbBounds
.top 
; 
2130                 sbBounds
.left 
= bounds
.right 
- bounds
.left 
- 15 ; 
2132                 sbBounds
.right 
+= sbBounds
.left 
; 
2133                 sbBounds
.bottom 
+= sbBounds
.top 
; 
2135                 SetControlBounds( m_sbVertical 
, &sbBounds 
) ; 
2142 void wxMacMLTEClassicControl::SetRect( Rect 
*r 
)  
2144     wxMacControl::SetRect( r 
) ; 
2145     MacUpdatePosition() ; 
2149 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)  
2151     /* set up our globals */ 
2153     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference(m_controlRef
); 
2154     if ( textctrl 
== NULL 
) 
2157     if ( textctrl
->MacIsReallyShown() ) 
2159         wxMacWindowClipper 
clipper( textctrl 
) ; 
2160         TXNDraw( m_txn 
, NULL 
) ; 
2165 /* TPPaneHitTestProc is called when the control manager would 
2166 like to determine what part of the control the mouse resides over. 
2167 We also call this routine from our tracking proc to determine how 
2168 to handle mouse clicks. */ 
2169 wxInt16 
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)  
2171     Point where 
= { y 
, x 
} ; 
2172     ControlPartCode result
; 
2173     /* set up our locals and lock down our globals*/ 
2175     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference(m_controlRef
); 
2176     if ( textctrl 
== NULL 
) 
2179     if (textctrl
->MacIsReallyShown() ) 
2181         if (PtInRect(where
, &m_txnControlBounds
)) 
2182             result 
= kmUPTextPart
; 
2185             // sometimes we get the coords also in control local coordinates, therefore test again 
2186             if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ) 
2189                 textctrl
->MacClientToRootWindow( &x 
, &y 
) ; 
2193             if (PtInRect(where
, &m_txnControlBounds
)) 
2194                 result 
= kmUPTextPart
; 
2202 /* TPPaneTrackingProc is called when the mouse is being held down 
2203 over our control.  This routine handles clicks in the text area 
2204 and in the scroll bar. */ 
2206 wxInt16 
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc 
)  
2208     Point startPt 
= { y 
,x 
} ; 
2209     ControlPartCode partCodeResult
; 
2210     /* make sure we have some variables... */ 
2212     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference(m_controlRef
); 
2213     if ( textctrl 
== NULL 
) 
2216     if (textctrl
->MacIsReallyShown() ) 
2218         /* we don't do any of these functions unless we're in focus */ 
2219         if ( ! m_txnIsFocused
) { 
2221             owner 
= GetControlOwner(m_controlRef
); 
2222             ClearKeyboardFocus(owner
); 
2223             SetKeyboardFocus(owner
, m_controlRef
, kUserClickedToFocusPart
); 
2225         /* find the location for the click */ 
2226         // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them 
2227         if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ) 
2230             textctrl
->MacClientToRootWindow( &x 
, &y 
) ; 
2235         switch (MacControlUserPaneHitTestProc( startPt
.h 
, startPt
.v 
)) 
2237             /* handle clicks in the text part */ 
2240                 wxMacWindowClipper 
clipper( textctrl 
) ; 
2243                 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec 
) ; 
2244                 TXNClick( m_txn
, &rec 
); 
2251     return partCodeResult
; 
2255 /* TPPaneIdleProc is our user pane idle routine.  When our text field 
2256 is active and in focus, we use this routine to set the cursor. */ 
2257 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()  
2260     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference(m_controlRef
); 
2261     if ( textctrl 
== NULL 
) 
2264     if (textctrl
->MacIsReallyShown())  
2266         /* if we're not active, then we have nothing to say about the cursor */ 
2267         if (m_controlIsActive
)  
2272             wxMacWindowClipper 
clipper( textctrl 
) ; 
2274             /* there's a 'focus thing' and an 'unfocused thing' */ 
2277                 /* flash the cursor */ 
2280                 /* set the cursor */ 
2281                 if (PtInRect(mousep
, &m_txnControlBounds
))  
2284                     RectRgn((theRgn 
= NewRgn()), &m_txnControlBounds
); 
2285                     TXNAdjustCursor(m_txn
, theRgn
); 
2290                     // SetThemeCursor(kThemeArrowCursor); 
2295                 /* if it's in our bounds, set the cursor */ 
2296                 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
); 
2297                 if (PtInRect(mousep
, &bounds
)) 
2299                     //    SetThemeCursor(kThemeArrowCursor); 
2307 /* TPPaneKeyDownProc is called whenever a keydown event is directed 
2308 at our control.  Here, we direct the keydown event to the text 
2309 edit record and redraw the scroll bar and text field as appropriate. */ 
2310 wxInt16 
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)  
2312     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference(m_controlRef
); 
2313     if ( textctrl 
== NULL 
) 
2315     // MacUpdatePosition() ; 
2319         /* turn autoscrolling on and send the key event to text edit */ 
2320         wxMacWindowClipper 
clipper( textctrl 
) ; 
2322         memset( &ev 
, 0 , sizeof( ev 
) ) ; 
2324         ev
.modifiers 
= modifiers 
; 
2325         ev
.message 
= (( keyCode 
<< 8 ) & keyCodeMask 
) + ( charCode 
& charCodeMask 
) ; 
2326         TXNKeyDown( m_txn 
, &ev
); 
2328     return kControlEntireControl
; 
2332 /* TPPaneActivateProc is called when the window containing 
2333 the user pane control receives activate events. Here, we redraw 
2334 the control and it's text as necessary for the activation state. */ 
2336 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)  
2339     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference(m_controlRef
); 
2341     if ( textctrl 
== NULL 
) 
2344     if ( m_controlIsActive 
!= activating 
) 
2346         wxLogDebug(wxString::Format( wxT("id %xd activating with %d") , (long) this , activating 
) ) ; 
2347         // MacUpdatePosition() ; 
2348         m_controlIsActive 
= activating
; 
2349         wxMacWindowClipper 
clipper( textctrl 
) ; 
2350         MacActivatePaneText( activating 
); 
2357 /* TPPaneFocusProc is called when every the focus changes to or 
2358 from our control.  Herein, switch the focus appropriately 
2359 according to the parameters and redraw the control as 
2361 wxInt16 
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)  
2363     wxLogDebug(wxString::Format( wxT("id %xd Focus Proc with action %d") , (long) this , action 
) ) ; 
2364     ControlPartCode focusResult
; 
2366     focusResult 
= kControlFocusNoPart
; 
2367     wxTextCtrl
* textctrl 
= (wxTextCtrl
*) GetControlReference(m_controlRef
); 
2368     if ( textctrl 
== NULL 
) 
2371     wxMacWindowClipper 
clipper( textctrl 
) ; 
2373     // MacUpdatePosition() ; 
2375     /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is 
2376         tabbing forwards (or shift tabbing backwards) through the items in the dialog, 
2377         and kControlFocusNextPart will be received.  When the user clicks in our field 
2378         and it is not the current focus, then the constant kUserClickedToFocusPart will 
2379         be received.  The constant kControlFocusNoPart will be received when our control 
2380         is the current focus and the user clicks in another control.  In your focus routine, 
2381         you should respond to these codes as follows: 
2383         kControlFocusNoPart - turn off focus and return kControlFocusNoPart.  redraw 
2384         the control and the focus rectangle as necessary. 
2386         kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off 
2387         depending on its current state.  redraw the control and the focus rectangle 
2388         as appropriate for the new focus state.  If the focus state is 'off', return the constant 
2389         kControlFocusNoPart, otherwise return a non-zero part code. 
2390         kUserClickedToFocusPart - is a constant defined for this example.  You should 
2391         define your own value for handling click-to-focus type events. */ 
2392     /* calculate the next highlight state */ 
2396         case kControlFocusNoPart
: 
2397             MacFocusPaneText( false); 
2398             focusResult 
= kControlFocusNoPart
; 
2400         case kUserClickedToFocusPart
: 
2401             MacFocusPaneText(true); 
2404         case kControlFocusPrevPart
: 
2405         case kControlFocusNextPart
: 
2406             MacFocusPaneText( ( ! m_txnIsFocused
)); 
2407             focusResult 
= m_txnIsFocused 
? 1 : kControlFocusNoPart
; 
2414 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info 
) 
2418 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl 
*wxPeer
, 
2419                          const wxString
& str
, 
2421                          const wxSize
& size
, long style 
) : wxMacMLTEControl( wxPeer 
) 
2423     m_font 
= wxPeer
->GetFont() ; 
2424     m_windowStyle 
= style 
; 
2425     Rect bounds 
= wxMacGetBoundsForControl( wxPeer 
, pos 
, size 
) ; 
2427     wxMacConvertNewlines10To13( &st 
) ; 
2431     featurSet 
= kControlSupportsEmbedding 
| kControlSupportsFocus  
| kControlWantsIdle
 
2432             | kControlWantsActivate  
| kControlHandlesTracking 
| kControlHasSpecialBackground
 
2433             | kControlGetsFocusOnClick 
| kControlSupportsLiveFeedback
; 
2434         /* create the control */ 
2436     verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef 
) ); 
2441     if ( wxPeer->MacIsReallyShown() ) 
2442         MacSetObjectVisibility( true ) ; 
2444     AdjustCreationAttributes( *wxWHITE 
, true) ; 
2447         wxMacWindowClipper 
clipper( m_peer 
) ; 
2448         SetTXNData( st 
, kTXNStartOffset
, kTXNEndOffset 
) ; 
2449         TXNSetSelection( m_txn
, 0, 0); 
2450         TXNShowSelection( m_txn
, kTXNShowStart
); 
2454 wxMacMLTEClassicControl::~wxMacMLTEClassicControl() 
2456 //    SetControlReference(m_controlRef , 0) ; 
2457     TXNDeleteObject(m_txn
); 
2460 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
) 
2462     MacSetObjectVisibility( shown 
) ; 
2463     wxMacControl::VisibilityChanged( shown 
) ; 
2466 void wxMacMLTEClassicControl::SuperChangedPosition() 
2468     MacUpdatePosition() ; 
2469     wxMacControl::SuperChangedPosition() ; 
2472 bool wxMacMLTEClassicControl::NeedsFocusRect() const 
2477 #ifdef __WXMAC_OSX__ 
2479 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
) 
2481     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2482     wxMacMLTEClassicControl 
* win 
= textCtrl 
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL 
; 
2484         win
->MacControlUserPaneDrawProc(part
) ; 
2487 static pascal ControlPartCode 
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
) 
2489     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2490     wxMacMLTEClassicControl 
* win 
= textCtrl 
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL 
; 
2492         return win
->MacControlUserPaneHitTestProc(where
.h 
, where
.v
) ; 
2494         return kControlNoPart 
; 
2497 static pascal ControlPartCode 
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
) 
2499     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2500     wxMacMLTEClassicControl 
* win 
= textCtrl 
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL 
; 
2502         return win
->MacControlUserPaneTrackingProc( startPt
.h 
, startPt
.v 
, (void*) actionProc
) ; 
2504         return kControlNoPart 
; 
2507 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
) 
2509     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2510     wxMacMLTEClassicControl 
* win 
= textCtrl 
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL 
; 
2512         win
->MacControlUserPaneIdleProc() ; 
2515 static pascal ControlPartCode 
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) 
2517     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2518     wxMacMLTEClassicControl 
* win 
= textCtrl 
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL 
; 
2520         return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ; 
2522         return kControlNoPart 
; 
2525 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
) 
2527     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2528     wxMacMLTEClassicControl 
* win 
= textCtrl 
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL 
; 
2530         win
->MacControlUserPaneActivateProc(activating
) ; 
2533 static pascal ControlPartCode 
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
) 
2535     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2536     wxMacMLTEClassicControl 
* win 
= textCtrl 
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL 
; 
2538         return win
->MacControlUserPaneFocusProc(action
) ; 
2540         return kControlNoPart 
; 
2543 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
) 
2545     wxTextCtrl 
*textCtrl 
=  wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl 
) ; 
2546     wxMacMLTEClassicControl 
* win 
= textCtrl 
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL 
; 
2548         win
->MacControlUserPaneBackgroundProc(info
) ; 
2552 OSStatus 
wxMacMLTEClassicControl::DoCreate() 
2556     OSStatus err 
= noErr 
; 
2558     /* set up our globals */ 
2559 #ifdef __WXMAC_OSX__ 
2560     if (gTPDrawProc 
== NULL
) gTPDrawProc 
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
); 
2561     if (gTPHitProc 
== NULL
) gTPHitProc 
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
); 
2562     if (gTPTrackProc 
== NULL
) gTPTrackProc 
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
); 
2563     if (gTPIdleProc 
== NULL
) gTPIdleProc 
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
); 
2564     if (gTPKeyProc 
== NULL
) gTPKeyProc 
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
); 
2565     if (gTPActivateProc 
== NULL
) gTPActivateProc 
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
); 
2566     if (gTPFocusProc 
== NULL
) gTPFocusProc 
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
); 
2569     /* set the initial settings for our private data */ 
2571     m_txnIsFocused 
= false; 
2572     m_controlIsActive 
= true; 
2573     m_txnIsActive 
= false; 
2574     m_txnIsVisible 
= true ; 
2576     WindowRef owningWindow 
= GetControlOwner(m_controlRef
); 
2577     m_txnPort 
= (GrafPtr
) GetWindowPort(owningWindow
); 
2579 #ifdef __WXMAC_OSX__ 
2580     /* set up the user pane procedures */ 
2581     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
); 
2582     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
); 
2583     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
); 
2584     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
); 
2585     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
); 
2586     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
); 
2587     SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
); 
2589     /* calculate the rectangles used by the control */ 
2590     UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
); 
2592     m_txnControlBounds 
= bounds 
; 
2594     CGrafPtr        origPort 
= NULL 
; 
2595     GDHandle        origDev 
= NULL 
; 
2596     GetGWorld( &origPort 
, &origDev 
) ; 
2599     /* create the new edit field */ 
2601     TXNFrameOptions frameOptions 
= FrameOptionsFromWXStyle( m_windowStyle 
) ; 
2603 #ifdef __WXMAC_OSX__ 
2605     // the scrollbars are not correctly embedded but are inserted at the root 
2606     // this gives us problems as we have erratic redraws even over the structure 
2609     ControlRef rootControl 
= 0 ; 
2610     GetRootControl( owningWindow 
, &rootControl 
) ; 
2611     UInt16 countBefore 
; 
2612     CountSubControls( rootControl 
, &countBefore 
) ; 
2614     // so that we can determine where which scrollbar is 
2616     ::SetRect( &bounds 
, 0 , 0 , 100 , 100 ) ; 
2620     verify_noerr(TXNNewObject(NULL
, owningWindow 
, &bounds
, 
2622                               kTXNTextEditStyleFrameType
, 
2624                               kTXNSystemDefaultEncoding
, 
2625                               &m_txn
, &m_txnFrameID
, NULL 
) ); 
2627 #ifdef __WXMAC_OSX__ 
2629     m_sbHorizontal 
= 0 ; 
2633     CountSubControls( rootControl 
, &countAfter 
) ; 
2635     // as we are removing controls this loop must count downwards 
2636     for ( int i 
= countAfter 
; i 
> countBefore 
; --i 
) 
2638         ControlRef scrollbar 
; 
2639         Rect scrollbarBounds 
; 
2640         GetIndexedSubControl( rootControl 
, i 
, &scrollbar 
) ; 
2641         HIViewRemoveFromSuperview( scrollbar 
) ; 
2642         HIViewAddSubview( m_controlRef 
, scrollbar 
) ; 
2643         GetControlBounds( scrollbar 
, &scrollbarBounds 
) ; 
2644         if ( scrollbarBounds
.left 
<= 0 ) 
2646             m_sbHorizontal 
= scrollbar 
; 
2648         if ( scrollbarBounds
.top 
<= 0 ) 
2650             m_sbVertical 
= scrollbar 
; 
2656     /* perform final activations and setup for our text field.  Here, 
2657     we assume that the window is going to be the 'active' window. */ 
2658     // MacActivatePaneText(m_controlIsActive && m_txnIsFocused); 
2660     SetGWorld( origPort 
, origDev 
) ; 
2664 // ---------------------------------------------------------------------------- 
2665 // MLTE control implementation (OSX part) 
2666 // ---------------------------------------------------------------------------- 
2668 #if TARGET_API_MAC_OSX 
2670 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 
2672 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl 
*wxPeer
, 
2673                          const wxString
& str
, 
2675                          const wxSize
& size
, long style 
) : wxMacMLTEControl( wxPeer 
) 
2677     m_font 
= wxPeer
->GetFont() ; 
2678     m_windowStyle 
= style 
; 
2679     Rect bounds 
= wxMacGetBoundsForControl( wxPeer 
, pos 
, size 
) ; 
2681     wxMacConvertNewlines10To13( &st 
) ; 
2683     HIRect hr 
= { bounds
.left 
, bounds
.top 
, bounds
.right 
- bounds
.left 
, bounds
.bottom
- bounds
.top 
} ; 
2685     m_scrollView 
= NULL 
; 
2686     TXNFrameOptions frameOptions 
= FrameOptionsFromWXStyle( style 
) ; 
2687     if ( frameOptions 
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) ) 
2689         HIScrollViewCreate(( frameOptions 
& kTXNWantHScrollBarMask 
? kHIScrollViewOptionsHorizScroll 
: 0) | 
2690             ( frameOptions 
& kTXNWantVScrollBarMask 
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView 
) ; 
2692         HIViewSetFrame( m_scrollView
, &hr 
); 
2693         HIViewSetVisible( m_scrollView
, true ); 
2697     HITextViewCreate( NULL 
, 0, frameOptions 
, &m_textView 
) ; 
2698     m_txn 
= HITextViewGetTXNObject( m_textView
) ; 
2699     HIViewSetVisible( m_textView 
, true ) ; 
2702         HIViewAddSubview( m_scrollView 
, m_textView 
) ; 
2703         m_controlRef 
= m_scrollView 
; 
2704         wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView  
) ; 
2708         HIViewSetFrame( m_textView
, &hr 
); 
2709         m_controlRef 
= m_textView 
; 
2712     AdjustCreationAttributes( *wxWHITE 
, true ) ; 
2714     wxMacWindowClipper 
c( m_peer 
) ; 
2715     SetTXNData( st 
, kTXNStartOffset
, kTXNEndOffset 
) ; 
2717     TXNSetSelection( m_txn
, 0, 0); 
2718     TXNShowSelection( m_txn
, kTXNShowStart
); 
2722 OSStatus 
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart 
) 
2724     return SetKeyboardFocus(  GetControlOwner( m_textView 
)  , 
2725         m_textView 
, focusPart 
) ; 
2728 bool wxMacMLTEHIViewControl::HasFocus() const 
2730     ControlRef control 
; 
2731     GetKeyboardFocus( GetUserFocusWindow() , &control 
) ; 
2732     return control 
== m_textView 
; 
2735 bool wxMacMLTEHIViewControl::NeedsFocusRect() const 
2737     return m_windowStyle 
& wxNO_BORDER 
? false : true; 
2740 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 
2745 #endif // wxUSE_TEXTCTRL