+ verify_noerr( TXNSetTypeAttributes ( m_txn , attrCounter , typeAttr, kTXNStartOffset,kTXNEndOffset) );
+ }
+}
+void wxMacMLTEControl::SetStyle(long start, long end, const wxTextAttr& style)
+{
+ EditHelper help(m_txn) ;
+ TXNTypeAttributes typeAttr[4] ;
+ int attrCounter = ConvertAttribute( style , typeAttr ) ;
+ if ( attrCounter > 0 )
+ {
+ verify_noerr( TXNSetTypeAttributes ( m_txn , attrCounter , typeAttr, start,end) );
+ }
+}
+
+void wxMacMLTEControl::Copy()
+{
+ ClearCurrentScrap();
+ TXNCopy(m_txn);
+ TXNConvertToPublicScrap();
+}
+
+void wxMacMLTEControl::Cut()
+{
+ ClearCurrentScrap();
+ TXNCut(m_txn);
+ TXNConvertToPublicScrap();
+}
+
+void wxMacMLTEControl::Paste()
+{
+ TXNConvertFromPublicScrap();
+ TXNPaste(m_txn);
+}
+
+bool wxMacMLTEControl::CanPaste() const
+{
+ return TXNIsScrapPastable() ;
+}
+
+void wxMacMLTEControl::SetEditable(bool editable)
+{
+ TXNControlTag tag[] = { kTXNIOPrivilegesTag } ;
+ TXNControlData data[] = { { editable ? kTXNReadWrite : kTXNReadOnly } } ;
+ TXNSetTXNObjectControls( m_txn , false , sizeof(tag) / sizeof (TXNControlTag) , tag , data ) ;
+}
+
+long wxMacMLTEControl::GetLastPosition() const
+{
+ long actualsize = 0 ;
+
+ Handle theText ;
+ OSErr err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
+ /* all done */
+ if ( err )
+ {
+ actualsize = 0 ;
+ }
+ else
+ {
+ actualsize = GetHandleSize( theText ) ;
+ DisposeHandle( theText ) ;
+ }
+
+ return actualsize ;
+}
+
+void wxMacMLTEControl::Replace( long from , long to , const wxString str )
+{
+ wxString value = str ;
+ wxMacConvertNewlines13To10( &value ) ;
+
+ EditHelper help( m_txn ) ;
+
+ TXNSetSelection(m_txn , from , to ) ;
+ TXNClear( m_txn ) ;
+ SetTXNData( str , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ;
+}
+
+void wxMacMLTEControl::Remove( long from , long to )
+{
+ EditHelper help( m_txn ) ;
+
+ TXNSetSelection(m_txn , from , to ) ;
+ TXNClear( m_txn ) ;
+}
+
+void wxMacMLTEControl::GetSelection( long* from, long* to) const
+{
+ TXNGetSelection( m_txn , (TXNOffset*) from , (TXNOffset*) to ) ;
+}
+
+void wxMacMLTEControl::SetSelection( long from , long to )
+{
+ /* change the selection */
+ if ((from == -1) && (to == -1))
+ TXNSelectAll(m_txn);
+ else
+ TXNSetSelection( m_txn, from, to);
+ TXNShowSelection( m_txn, kTXNShowStart);
+}
+
+void wxMacMLTEControl::WriteText(const wxString& str)
+{
+ EditHelper helper( m_txn ) ;
+ wxString st = str ;
+ wxMacConvertNewlines13To10( &st ) ;
+
+ long start , end , dummy ;
+ GetSelection( &start , &dummy ) ;
+ SetTXNData( st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ;
+ GetSelection( &dummy , &end ) ;
+ // TODO SetStyle( start , end , GetDefaultStyle() ) ;
+}
+
+void wxMacMLTEControl::Clear()
+{
+ EditHelper st(m_txn) ;
+ TXNSetSelection( m_txn , kTXNStartOffset , kTXNEndOffset ) ;
+ TXNClear(m_txn);
+}
+
+bool wxMacMLTEControl::CanUndo() const
+{
+ return TXNCanUndo( m_txn , NULL ) ;
+}
+
+void wxMacMLTEControl::Undo()
+{
+ TXNUndo( m_txn ) ;
+}
+
+bool wxMacMLTEControl::CanRedo() const
+{
+ return TXNCanRedo( m_txn , NULL ) ;
+}
+
+void wxMacMLTEControl::Redo()
+{
+ TXNRedo( m_txn ) ;
+}
+
+int wxMacMLTEControl::GetNumberOfLines() const
+{
+ ItemCount lines = 0 ;
+ TXNGetLineCount(m_txn, &lines ) ;
+ return lines ;
+}
+
+long wxMacMLTEControl::XYToPosition(long x, long y) const
+{
+ Point curpt ;
+
+ long lastpos = GetLastPosition() ;
+
+ // TODO find a better implementation : while we can get the
+ // line metrics of a certain line, we don't get its starting
+ // position, so it would probably be rather a binary search
+ // for the start position
+ long xpos = 0 ;
+ long ypos = 0 ;
+ int lastHeight = 0 ;
+
+ ItemCount n ;
+ for ( n = 0 ; n <= (ItemCount) lastpos ; ++n )
+ {
+ if ( y == ypos && x == xpos )
+ return n ;
+
+ TXNOffsetToPoint( m_txn , n , &curpt);
+
+ if ( curpt.v > lastHeight )
+ {
+ xpos = 0 ;
+ if ( n > 0 )
+ ++ypos ;
+ lastHeight = curpt.v ;
+ }
+ else
+ ++xpos ;
+ }
+ return 0 ;
+}
+
+bool wxMacMLTEControl::PositionToXY(long pos, long *x, long *y) const
+{
+ Point curpt ;
+
+ long lastpos = GetLastPosition() ;
+
+ if ( y ) *y = 0 ;
+ if ( x ) *x = 0 ;
+
+ if ( pos <= lastpos )
+ {
+ // TODO find a better implementation : while we can get the
+ // line metrics of a certain line, we don't get its starting
+ // position, so it would probably be rather a binary search
+ // for the start position
+ long xpos = 0 ;