+ Rect bounds;
+ OSStatus err = noErr ;
+
+ // set up our globals
+#ifdef __WXMAC_OSX__
+ if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc);
+ if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc);
+ if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc);
+ if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc);
+ if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc);
+ if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc);
+ if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc);
+
+ if (gTXNScrollInfoProc == NULL ) gTXNScrollInfoProc = NewTXNScrollInfoUPP(TXNScrollInfoProc) ;
+ if (gTXNScrollActionProc == NULL ) gTXNScrollActionProc = NewControlActionUPP(TXNScrollActionProc) ;
+#endif
+
+ // set the initial settings for our private data
+
+ m_txnWindow = GetControlOwner(m_controlRef);
+ m_txnPort = (GrafPtr) GetWindowPort(m_txnWindow);
+
+#ifdef __WXMAC_OSX__
+ // set up the user pane procedures
+ SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneDrawProcTag, sizeof(gTPDrawProc), &gTPDrawProc);
+ SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneHitTestProcTag, sizeof(gTPHitProc), &gTPHitProc);
+ SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneTrackingProcTag, sizeof(gTPTrackProc), &gTPTrackProc);
+ SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneIdleProcTag, sizeof(gTPIdleProc), &gTPIdleProc);
+ SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneKeyDownProcTag, sizeof(gTPKeyProc), &gTPKeyProc);
+ SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneActivateProcTag, sizeof(gTPActivateProc), &gTPActivateProc);
+ SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneFocusProcTag, sizeof(gTPFocusProc), &gTPFocusProc);
+#endif
+
+ // calculate the rectangles used by the control
+ UMAGetControlBoundsInWindowCoords( m_controlRef, &bounds );
+
+ m_txnControlBounds = bounds ;
+ m_txnVisBounds = bounds ;
+
+ CGrafPtr origPort ;
+ GDHandle origDev ;
+
+ GetGWorld( &origPort, &origDev ) ;
+ SetPort( m_txnPort );
+
+ // create the new edit field
+ TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( m_windowStyle );
+
+#ifdef __WXMAC_OSX__
+ // the scrollbars are not correctly embedded but are inserted at the root:
+ // this gives us problems as we have erratic redraws even over the structure area
+
+ m_sbHorizontal = 0 ;
+ m_sbVertical = 0 ;
+ m_lastHorizontalValue = 0 ;
+ m_lastVerticalValue = 0 ;
+
+ Rect sb = { 0 , 0 , 0 , 0 } ;
+ if ( frameOptions & kTXNWantVScrollBarMask )
+ {
+ CreateScrollBarControl( m_txnWindow, &sb, 0, 0, 100, 1, true, gTXNScrollActionProc, &m_sbVertical );
+ SetControlReference( m_sbVertical, (SInt32)this );
+ SetControlAction( m_sbVertical, gTXNScrollActionProc );
+ ShowControl( m_sbVertical );
+ EmbedControl( m_sbVertical , m_controlRef );
+ frameOptions &= ~kTXNWantVScrollBarMask;
+ }
+
+ if ( frameOptions & kTXNWantHScrollBarMask )
+ {
+ CreateScrollBarControl( m_txnWindow, &sb, 0, 0, 100, 1, true, gTXNScrollActionProc, &m_sbHorizontal );
+ SetControlReference( m_sbHorizontal, (SInt32)this );
+ SetControlAction( m_sbHorizontal, gTXNScrollActionProc );
+ ShowControl( m_sbHorizontal );
+ EmbedControl( m_sbHorizontal, m_controlRef );
+ frameOptions &= ~(kTXNWantHScrollBarMask | kTXNDrawGrowIconMask);
+ }
+
+#endif
+
+ err = TXNNewObject(
+ NULL, m_txnWindow, &bounds, frameOptions,
+ kTXNTextEditStyleFrameType, kTXNTextensionFile, kTXNSystemDefaultEncoding,
+ &m_txn, &m_txnFrameID, NULL );
+ verify_noerr( err );
+
+#if 0
+ TXNControlTag iControlTags[] = { kTXNUseCarbonEvents };
+ TXNControlData iControlData[] = { { (UInt32)&cInfo } };
+ int toptag = WXSIZEOF( iControlTags ) ;
+ TXNCarbonEventInfo cInfo ;
+ cInfo.useCarbonEvents = false ;
+ cInfo.filler = 0 ;
+ cInfo.flags = 0 ;
+ cInfo.fDictionary = NULL ;
+
+ verify_noerr( TXNSetTXNObjectControls( m_txn, false, toptag, iControlTags, iControlData ) );
+#endif
+
+#ifdef __WXMAC_OSX__
+ TXNRegisterScrollInfoProc( m_txn, gTXNScrollInfoProc, (SInt32)this );
+#endif
+
+ SetGWorld( origPort , origDev ) ;
+
+ return err;
+}
+#endif
+
+// ----------------------------------------------------------------------------
+// MLTE control implementation (OSX part)
+// ----------------------------------------------------------------------------
+
+#if TARGET_API_MAC_OSX
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
+
+// tiger multi-line textcontrols with no CR in the entire content
+// don't scroll automatically, so we need a hack.
+// This attempt only works 'before' the key (ie before CallNextEventHandler)
+// is processed, thus the scrolling always occurs one character too late, but
+// better than nothing ...
+
+static const EventTypeSpec eventList[] =
+{
+ { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
+} ;
+
+static pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+ wxMacMLTEHIViewControl* focus = (wxMacMLTEHIViewControl*) data ;
+
+ switch ( GetEventKind( event ) )
+ {
+ case kEventTextInputUnicodeForKeyEvent :
+ {
+ if ( UMAGetSystemVersion() >= 0x1040 )
+ {
+ TXNOffset from , to ;
+ TXNGetSelection( focus->GetTXNObject() , &from , &to ) ;
+ if ( from == to )
+ TXNShowSelection( focus->GetTXNObject() , kTXNShowStart );
+ }
+ result = CallNextEventHandler(handler,event);
+ break;
+ }
+ default:
+ break ;
+ }
+
+ return result ;