+#include "wx/mac/carbon/private/mactext.h"
+
+#ifndef __WXMAC_OSX__
+enum
+{
+ kTXNVisibilityTag = 'visb' // set the visibility state of the object
+};
+#endif
+
+
+class wxMacFunctor
+{
+public :
+ wxMacFunctor() {}
+ virtual ~wxMacFunctor() {}
+
+ virtual void* operator()() = 0 ;
+
+ static void* CallBackProc( void *param )
+ {
+ wxMacFunctor* f = (wxMacFunctor*) param ;
+ void *result = (*f)() ;
+ return result ;
+ }
+} ;
+
+template<typename classtype, typename param1type>
+
+class wxMacObjectFunctor1 : public wxMacFunctor
+{
+ typedef void (classtype::*function)( param1type p1 ) ;
+ typedef void (classtype::*ref_function)( const param1type& p1 ) ;
+public :
+ wxMacObjectFunctor1( classtype *obj , function f , param1type p1 ) :
+ wxMacFunctor()
+ {
+ m_object = obj ;
+ m_function = f ;
+ m_param1 = p1 ;
+ }
+
+ wxMacObjectFunctor1( classtype *obj , ref_function f , param1type p1 ) :
+ wxMacFunctor()
+ {
+ m_object = obj ;
+ m_refFunction = f ;
+ m_param1 = p1 ;
+ }
+
+ virtual ~wxMacObjectFunctor1() {}
+
+ virtual void* operator()()
+ {
+ (m_object->*m_function)( m_param1 ) ;
+ return NULL ;
+ }
+
+private :
+ classtype* m_object ;
+ param1type m_param1 ;
+ union
+ {
+ function m_function ;
+ ref_function m_refFunction ;
+ } ;
+} ;
+
+template<typename classtype, typename param1type>
+void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 )
+{
+ wxMacObjectFunctor1<classtype, param1type> params(object, function, p1) ;
+ void *result =
+ MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ;
+ return result ;
+}
+
+template<typename classtype, typename param1type>
+void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 )
+{
+ wxMacObjectFunctor1<classtype,param1type> params(object, function, p1) ;
+ void *result =
+ MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ;
+ return result ;
+}
+
+template<typename classtype, typename param1type>
+void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 )
+{
+ wxMutexGuiLeave() ;
+ void *result = wxMacMPRemoteCall( object , function , p1 ) ;
+ wxMutexGuiEnter() ;
+ return result ;
+}
+
+template<typename classtype, typename param1type>
+void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 )
+{
+ wxMutexGuiLeave() ;
+ void *result = wxMacMPRemoteCall( object , function , p1 ) ;
+ wxMutexGuiEnter() ;
+ return result ;
+}
+
+
+// common parts for implementations based on MLTE
+
+class wxMacMLTEControl : public wxMacTextControl
+{
+public :
+ wxMacMLTEControl( wxTextCtrl *peer ) ;
+
+ virtual wxString GetStringValue() const ;
+ virtual void SetStringValue( const wxString &str ) ;
+
+ static TXNFrameOptions FrameOptionsFromWXStyle( long wxStyle ) ;
+
+ void AdjustCreationAttributes( const wxColour& background, bool visible ) ;
+
+ virtual void SetFont( const wxFont & font, const wxColour& foreground, long windowStyle ) ;
+ virtual void SetBackground( const wxBrush &brush ) ;
+ virtual void SetStyle( long start, long end, const wxTextAttr& style ) ;
+ virtual void Copy() ;
+ virtual void Cut() ;
+ virtual void Paste() ;
+ virtual bool CanPaste() const ;
+ virtual void SetEditable( bool editable ) ;
+ virtual wxTextPos GetLastPosition() const ;
+ virtual void Replace( long from, long to, const wxString &str ) ;
+ virtual void Remove( long from, long to ) ;
+ virtual void GetSelection( long* from, long* to ) const ;
+ virtual void SetSelection( long from, long to ) ;
+
+ virtual void WriteText( const wxString& str ) ;
+
+ virtual bool HasOwnContextMenu() const
+ {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+ if ( UMAGetSystemVersion() >= 0x1040 )
+ {
+ TXNCommandEventSupportOptions options ;
+ TXNGetCommandEventSupport( m_txn , & options ) ;
+ return options & kTXNSupportEditCommandProcessing ;
+ }
+#endif
+
+ return false ;
+ }
+
+ virtual void CheckSpelling(bool check)
+ {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+ TXNSetSpellCheckAsYouType( m_txn, (Boolean) check );
+#endif
+ }
+ virtual void Clear() ;
+
+ virtual bool CanUndo() const ;
+ virtual void Undo() ;
+ virtual bool CanRedo() const;
+ virtual void Redo() ;
+ virtual int GetNumberOfLines() const ;
+ virtual long XYToPosition(long x, long y) const ;
+ virtual bool PositionToXY(long pos, long *x, long *y) const ;
+ virtual void ShowPosition( long pos ) ;
+ virtual int GetLineLength(long lineNo) const ;
+ virtual wxString GetLineText(long lineNo) const ;
+
+ void SetTXNData( const wxString& st , TXNOffset start , TXNOffset end ) ;
+ TXNObject GetTXNObject() { return m_txn ; }
+
+protected :
+ void TXNSetAttribute( const wxTextAttr& style , long from , long to ) ;
+
+ TXNObject m_txn ;
+} ;
+
+#if TARGET_API_MAC_OSX
+
+// implementation available under OSX
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
+
+class wxMacMLTEHIViewControl : public wxMacMLTEControl
+{
+public :
+ wxMacMLTEHIViewControl( wxTextCtrl *wxPeer,
+ const wxString& str,
+ const wxPoint& pos,
+ const wxSize& size, long style ) ;
+ virtual ~wxMacMLTEHIViewControl() ;
+
+ virtual OSStatus SetFocus( ControlFocusPart focusPart ) ;
+ virtual bool HasFocus() const ;
+ virtual void SetBackground( const wxBrush &brush) ;
+
+protected :
+ HIViewRef m_scrollView ;
+ HIViewRef m_textView ;
+ EventHandlerRef m_textEventHandlerRef ;
+};
+
+#endif
+
+#endif
+
+// 'classic' MLTE implementation
+
+class wxMacMLTEClassicControl : public wxMacMLTEControl
+{
+public :
+ wxMacMLTEClassicControl( wxTextCtrl *wxPeer,
+ const wxString& str,
+ const wxPoint& pos,
+ const wxSize& size, long style ) ;
+ virtual ~wxMacMLTEClassicControl() ;
+
+ virtual void VisibilityChanged(bool shown) ;
+ virtual void SuperChangedPosition() ;
+
+ virtual void MacControlUserPaneDrawProc(wxInt16 part) ;
+ virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) ;
+ virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) ;
+ virtual void MacControlUserPaneIdleProc() ;
+ virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) ;
+ virtual void MacControlUserPaneActivateProc(bool activating) ;
+ virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ;
+ virtual void MacControlUserPaneBackgroundProc(void* info) ;
+
+ virtual bool SetupCursor( const wxPoint& WXUNUSED(pt) )
+ {
+ MacControlUserPaneIdleProc();
+ return true;
+ }