+static void SetTXNData( TXNObject txn , const wxString& st , TXNOffset start , TXNOffset end )
+{
+#if wxUSE_UNICODE
+ size_t len = st.Len() ;
+#if SIZEOF_WCHAR_T == 2
+ TXNSetData( txn , kTXNUnicodeTextData, (void*)st.wc_str(), len * 2,
+ start, end);
+#else
+ ByteCount byteBufferLen = len * sizeof( UniChar ) ;
+ UniChar *unibuf = (UniChar*) malloc(byteBufferLen) ;
+ wxMBConvUTF16BE converter ;
+ converter.WC2MB( (char*) unibuf , st.wc_str() , byteBufferLen ) ;
+ TXNSetData( txn , kTXNUnicodeTextData, (void*)unibuf, len * 2,
+ start, end);
+ free( unibuf ) ;
+#endif
+#else
+ wxCharBuffer text = st.mb_str(wxConvLocal) ;
+ TXNSetData( txn , kTXNTextData, (void*)text.data(), strlen( text ) ,
+ start, end);
+#endif
+}
+