+#include "wx/mac/carbon/private/mactext.h"
+
+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 ;
+}
+
+class WXDLLEXPORT wxMacPortSaver
+{
+ DECLARE_NO_COPY_CLASS(wxMacPortSaver)
+
+public:
+ wxMacPortSaver( GrafPtr port );
+ ~wxMacPortSaver();
+private :
+ GrafPtr m_port;
+};
+
+
+/*
+ Clips to the visible region of a control within the current port
+ */
+
+class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver
+{
+ DECLARE_NO_COPY_CLASS(wxMacWindowClipper)
+
+public:
+ wxMacWindowClipper( const wxWindow* win );
+ ~wxMacWindowClipper();
+private:
+ GrafPtr m_newPort;
+ RgnHandle m_formerClip;
+ RgnHandle m_newClip;
+};
+
+wxMacPortSaver::wxMacPortSaver( GrafPtr port )
+{
+ ::GetPort( &m_port );
+ ::SetPort( port );
+}
+
+wxMacPortSaver::~wxMacPortSaver()
+{
+ ::SetPort( m_port );
+}
+
+wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) :
+wxMacPortSaver( (GrafPtr) GetWindowPort( (WindowRef) win->MacGetTopLevelWindowRef() ) )
+{
+ m_newPort = (GrafPtr) GetWindowPort( (WindowRef) win->MacGetTopLevelWindowRef() ) ;
+ m_formerClip = NewRgn() ;
+ m_newClip = NewRgn() ;
+ GetClip( m_formerClip ) ;
+
+ if ( win )
+ {
+ // guard against half constructed objects, this just leads to a empty clip
+ if ( win->GetPeer() )
+ {
+ int x = 0 , y = 0;
+ win->MacWindowToRootWindow( &x, &y ) ;
+
+ // get area including focus rect
+ HIShapeGetAsQDRgn( ((wxWindow*)win)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip );
+ if ( !EmptyRgn( m_newClip ) )
+ OffsetRgn( m_newClip , x , y ) ;
+ }
+
+ SetClip( m_newClip ) ;
+ }
+}
+
+wxMacWindowClipper::~wxMacWindowClipper()
+{
+ SetPort( m_newPort ) ;
+ SetClip( m_formerClip ) ;
+ DisposeRgn( m_newClip ) ;
+ DisposeRgn( m_formerClip ) ;
+}
+
+// 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 SetBackgroundColour(const wxColour& col );
+ 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
+ {
+ TXNCommandEventSupportOptions options ;
+ TXNGetCommandEventSupport( m_txn , & options ) ;
+ return options & kTXNSupportEditCommandProcessing ;
+ }
+
+ virtual void CheckSpelling(bool check)
+ {
+ TXNSetSpellCheckAsYouType( m_txn, (Boolean) check );
+ }
+ 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 ;
+} ;
+
+// implementation available under OSX
+
+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 SetBackgroundColour(const wxColour& col ) ;
+
+protected :
+ HIViewRef m_scrollView ;
+ HIViewRef m_textView ;
+};
+
+// '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;
+ }