+ Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) };
+ TXNOffset theOffset;
+ TXNPointToOffset(m_txn, thePoint, &theOffset);
+
+ wxString content = GetStringValue() ;
+ Point currentPoint = thePoint;
+ while(thePoint.v == currentPoint.v && theOffset < content.length())
+ {
+ line += content[theOffset];
+ TXNOffsetToPoint(m_txn, ++theOffset, ¤tPoint);
+ }
+ }
+ return line ;
+}
+
+int wxMacMLTEControl::GetLineLength(long lineNo) const
+{
+ int theLength = 0;
+
+ if ( lineNo < GetNumberOfLines() )
+ {
+ long ypos = 0 ;
+
+ Fixed lineWidth,
+ lineHeight,
+ currentHeight = 0;
+
+ // get the first possible position in the control
+ Point firstPoint;
+ TXNOffsetToPoint(m_txn, 0, &firstPoint);
+
+ // Iterate through the lines until we reach the one we want,
+ // adding to our current y pixel point position
+ while (ypos < lineNo)
+ {
+ TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight);
+ currentHeight += lineHeight;
+ }
+
+ Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) };
+ TXNOffset theOffset;
+ TXNPointToOffset(m_txn, thePoint, &theOffset);
+
+ wxString content = GetStringValue() ;
+ Point currentPoint = thePoint;
+ while(thePoint.v == currentPoint.v && theOffset < content.length())
+ {
+ ++theLength;
+ TXNOffsetToPoint(m_txn, ++theOffset, ¤tPoint);
+ }
+ }
+ return theLength ;
+}
+
+
+// ----------------------------------------------------------------------------
+// MLTE control implementation (classic part)
+// ----------------------------------------------------------------------------
+
+// CS:TODO we still have a problem getting properly at the text events of a control because under Carbon
+// the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the
+// moment is to avoid setting the true focus on the control, the proper solution at the end would be to have
+// an alternate path for carbon key events that routes automatically into the same wx flow of events
+
+/* part codes */
+
+/* kmUPTextPart is the part code we return to indicate the user has clicked
+in the text area of our control */
+#define kmUPTextPart 1
+
+
+/* routines for using existing user pane controls.
+These routines are useful for cases where you would like to use an
+existing user pane control in, say, a dialog window as a scrolling
+text edit field.*/
+
+/* Utility Routines */
+
+/* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus
+routine. In our focus switching routine this part code is understood
+as meaning 'the user has clicked in the control and we need to switch
+the current focus to ourselves before we can continue'. */
+#define kUserClickedToFocusPart 100
+
+/* STPTextPaneVars is a structure used for storing the the mUP Control's
+internal variables and state information. A handle to this record is
+stored in the pane control's reference value field using the
+SetControlReference routine. */
+
+/* Univerals Procedure Pointer variables used by the
+mUP Control. These variables are set up
+the first time that mUPOpenControl is called. */
+ControlUserPaneDrawUPP gTPDrawProc = NULL;
+ControlUserPaneHitTestUPP gTPHitProc = NULL;
+ControlUserPaneTrackingUPP gTPTrackProc = NULL;
+ControlUserPaneIdleUPP gTPIdleProc = NULL;
+ControlUserPaneKeyDownUPP gTPKeyProc = NULL;
+ControlUserPaneActivateUPP gTPActivateProc = NULL;
+ControlUserPaneFocusUPP gTPFocusProc = NULL;
+
+
+class wxMacMLTENoDraw
+{
+public :
+ wxMacMLTENoDraw( TXNObject txn ) ;
+ ~wxMacMLTENoDraw() ;
+
+private :
+ bool m_formerDraw ;
+ TXNObject m_txn ;
+} ;
+
+wxMacMLTENoDraw::wxMacMLTENoDraw( TXNObject txn )
+{
+ m_txn = txn ;
+#ifdef __WXMAC_OSX__
+ TXNControlTag iControlTags[1] = { kTXNVisibilityTag };
+ TXNControlData iControlData[1] ;
+
+ TXNGetTXNObjectControls( m_txn , 1 , iControlTags , iControlData ) ;
+ m_formerDraw = iControlData[0].uValue ;
+ if ( m_formerDraw )
+ {
+ iControlData[0].uValue = 0 ;
+ TXNSetTXNObjectControls( m_txn , 1 , true , iControlTags , iControlData ) ;
+ }
+#endif
+}
+
+wxMacMLTENoDraw::~wxMacMLTENoDraw()
+{
+#ifdef __WXMAC_OSX__
+ if ( m_formerDraw )
+ {
+ TXNControlTag iControlTags[1] = { kTXNVisibilityTag };
+ TXNControlData iControlData[1] ;
+
+ iControlData[0].uValue = m_formerDraw ;
+ TXNSetTXNObjectControls( m_txn , 1 , true , iControlTags , iControlData ) ;
+ }
+#endif
+}
+
+
+// make correct activations
+void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive)
+{
+ wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
+ if (m_txnIsActive != setActive && textctrl->MacIsReallyShown() )
+ {
+ m_txnIsActive = setActive;
+ // TXNSetScrollBarState
+
+ TXNActivate(m_txn, m_txnFrameID, m_txnIsActive);
+ if (m_txnIsFocused)
+ TXNFocus( m_txn, m_txnIsActive);
+ }
+}
+
+// update TXN focus state
+void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus) {
+/* wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); */
+
+ if (m_txnIsFocused != setFocus /*&& textctrl->MacIsReallyShown() */ ) {
+ m_txnIsFocused = setFocus;
+ TXNFocus( m_txn, m_txnIsFocused);
+ }
+}
+
+// makes sure that the TXNObject is either offscreen or on screen
+
+void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis)
+{
+#ifdef __WXMAC_OSX__
+ OSStatus err = noErr ;
+
+ wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
+ if ( textctrl )
+ {
+ UMAGetControlBoundsInWindowCoords( m_controlRef, &m_txnControlBounds);
+ TXNControlTag iControlTags[1] = { kTXNVisibilityTag };
+ TXNControlData iControlData[1] = { { vis } };
+
+ TXNSetTXNObjectControls( m_txn , 1 , true , iControlTags , iControlData ) ;
+ }
+#endif
+}
+
+// make sure that the TXNObject is at the right position
+void wxMacMLTEClassicControl::MacUpdatePosition()
+{
+ wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
+ if ( textctrl == NULL )
+ return ;
+
+ Rect bounds ;
+ UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds);
+
+ if ( !EqualRect( &bounds , &m_txnControlBounds ) )
+ {
+ // old position
+ Rect oldBounds = m_txnControlBounds ;
+ m_txnControlBounds = bounds ;
+ wxMacWindowClipper cl(textctrl) ;
+ TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
+ m_txnControlBounds.bottom, m_txnControlBounds.right, m_txnFrameID);
+ }
+}
+
+void wxMacMLTEClassicControl::SetRect( Rect *r )
+{
+ wxMacControl::SetRect( r ) ;
+ MacUpdatePosition() ;
+}
+
+// draw the control
+void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart)
+{
+ /* set up our globals */
+
+ wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
+ if ( textctrl == NULL )
+ return ;
+
+ if ( textctrl->MacIsReallyShown() )
+ {
+ wxMacWindowClipper clipper( textctrl ) ;
+ TXNDraw( m_txn , NULL ) ;
+ }
+}
+
+
+/* TPPaneHitTestProc is called when the control manager would
+like to determine what part of the control the mouse resides over.
+We also call this routine from our tracking proc to determine how
+to handle mouse clicks. */
+wxInt16 wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
+{
+ Point where = { y , x } ;
+ ControlPartCode result;
+ /* set up our locals and lock down our globals*/
+ result = 0;
+ wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
+ if ( textctrl == NULL )
+ return 0 ;
+
+ if (textctrl->MacIsReallyShown() )
+ {
+ if (PtInRect(where, &m_txnControlBounds))
+ result = kmUPTextPart;
+ else
+ {
+ // sometimes we get the coords also in control local coordinates, therefore test again
+ if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() )