X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3a05d58d94a25dee362c5e1025c612ec6e84678c..b9b8a2b5d79c50af78720589dc96cd7e16cde26e:/src/mac/textctrl.cpp diff --git a/src/mac/textctrl.cpp b/src/mac/textctrl.cpp index 69a1ddfacc..4ba38713d4 100644 --- a/src/mac/textctrl.cpp +++ b/src/mac/textctrl.cpp @@ -659,6 +659,29 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) END_EVENT_TABLE() #endif +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 +} + // Text item void wxTextCtrl::Init() { @@ -785,14 +808,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, tpvars = (STPTextPaneVars **) GetControlReference((ControlHandle) m_macControl); /* set the text in the record */ m_macTXN = (**tpvars).fTXNRec ; -#if wxUSE_UNICODE - TXNSetData( ((TXNObject) m_macTXN) , kTXNUnicodeTextData, (void*)st.wc_str(), st.Length() * 2, - kTXNStartOffset, kTXNEndOffset); -#else - wxCharBuffer text = st.mb_str(wxConvLocal) ; - TXNSetData( ((TXNObject) m_macTXN) , kTXNTextData, (void*)text.data(), strlen( text ) , - kTXNStartOffset, kTXNEndOffset); -#endif + SetTXNData( (TXNObject) m_macTXN , st , kTXNStartOffset, kTXNEndOffset ) ; m_macTXNvars = tpvars ; m_macUsesTXN = true ; TXNSetSelection( (TXNObject) m_macTXN, 0, 0); @@ -840,7 +856,14 @@ wxString wxTextCtrl::GetValue() const if ( actualSize > 0 ) { wxChar *ptr = result.GetWriteBuf(actualSize*sizeof(wxChar)) ; +#if SIZEOF_WCHAR_T == 2 wxStrncpy( ptr , (wxChar*) *theText , actualSize ) ; +#else + wxMBConvUTF16BE converter ; + HLock( theText ) ; + converter.MB2WC( ptr , (const char*)*theText , actualSize*sizeof(wxChar) ) ; + HUnlock( theText ) ; +#endif ptr[actualSize] = 0 ; result.UngetWriteBuf( actualSize ) ; } @@ -898,14 +921,7 @@ void wxTextCtrl::SetValue(const wxString& str) bool formerEditable = m_editable ; if ( !formerEditable ) SetEditable(true) ; -#if wxUSE_UNICODE - TXNSetData( ((TXNObject) m_macTXN), kTXNUnicodeTextData, (void*)st.wc_str(), st.Length() * 2 , - kTXNStartOffset, kTXNEndOffset); -#else - wxCharBuffer text = st.mb_str(wxConvLocal) ; - TXNSetData( ((TXNObject) m_macTXN), kTXNTextData, (void*)text.data(), strlen( text ) , - kTXNStartOffset, kTXNEndOffset); -#endif + SetTXNData( (TXNObject) m_macTXN , st , kTXNStartOffset, kTXNEndOffset ) ; TXNSetSelection( (TXNObject) m_macTXN, 0, 0); TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart); if ( !formerEditable ) @@ -1195,13 +1211,7 @@ void wxTextCtrl::Replace(long from, long to, const wxString& str) SetEditable(true) ; TXNSetSelection( ((TXNObject) m_macTXN) , from , to ) ; TXNClear( ((TXNObject) m_macTXN) ) ; -#if wxUSE_UNICODE - TXNSetData( ((TXNObject) m_macTXN), kTXNUnicodeTextData, (void*)value.wc_str(), value.Length() * 2 , - kTXNUseCurrentSelection, kTXNUseCurrentSelection); -#else - TXNSetData( ((TXNObject) m_macTXN), kTXNTextData, (void*)value.c_str(), value.Length(), - kTXNUseCurrentSelection, kTXNUseCurrentSelection); -#endif + SetTXNData( (TXNObject) m_macTXN , str , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; if ( !formerEditable ) SetEditable( formerEditable ) ; } @@ -1294,14 +1304,7 @@ void wxTextCtrl::WriteText(const wxString& str) SetEditable(true) ; long start , end , dummy ; GetSelection( &start , &dummy ) ; -#if wxUSE_UNICODE - TXNSetData( ((TXNObject) m_macTXN), kTXNUnicodeTextData, (void*)st.wc_str(), st.Length() * 2 , - kTXNUseCurrentSelection, kTXNUseCurrentSelection); -#else - wxCharBuffer text = st.mb_str(wxConvLocal) ; - TXNSetData( ((TXNObject) m_macTXN), kTXNTextData, (void*)text.data(), strlen( text ) , - kTXNUseCurrentSelection, kTXNUseCurrentSelection); -#endif + SetTXNData( (TXNObject) m_macTXN , st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; GetSelection( &dummy , &end ) ; SetStyle( start , end , GetDefaultStyle() ) ; if ( !formerEditable ) @@ -1446,20 +1449,20 @@ int wxTextCtrl::GetNumberOfLines() const { if ( m_macUsesTXN ) { - ItemCount lines ; - TXNGetLineCount((TXNObject)m_macTXN, &lines ) ; - return lines ; + ItemCount lines ; + TXNGetLineCount((TXNObject)m_macTXN, &lines ) ; + return lines ; } else { - wxString content = GetValue() ; + wxString content = GetValue() ; - int count = 1; - for (size_t i = 0; i < content.Length() ; i++) - { - if (content[i] == '\r') count++; - } - return count; + int count = 1; + for (size_t i = 0; i < content.Length() ; i++) + { + if (content[i] == '\r') count++; + } + return count; } } @@ -1479,22 +1482,22 @@ void wxTextCtrl::ShowPosition(long pos) #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER) if ( m_macUsesTXN ) { - Point current ; - Point desired ; - TXNOffset selstart , selend ; + Point current ; + Point desired ; + TXNOffset selstart , selend ; TXNGetSelection( (TXNObject) m_macTXN , &selstart , &selend) ; - TXNOffsetToPoint( (TXNObject) m_macTXN, selstart , ¤t); - TXNOffsetToPoint( (TXNObject) m_macTXN, pos , &desired); - //TODO use HIPoints for 10.3 and above - if ( (UInt32) TXNScroll != (UInt32) kUnresolvedCFragSymbolAddress ) - { - OSErr theErr = noErr; - SInt32 dv = desired.v - current.v ; - SInt32 dh = desired.h - current.h ; - TXNShowSelection( (TXNObject) m_macTXN , true ) ; + TXNOffsetToPoint( (TXNObject) m_macTXN, selstart , ¤t); + TXNOffsetToPoint( (TXNObject) m_macTXN, pos , &desired); + //TODO use HIPoints for 10.3 and above + if ( (UInt32) TXNScroll != (UInt32) kUnresolvedCFragSymbolAddress ) + { + OSErr theErr = noErr; + SInt32 dv = desired.v - current.v ; + SInt32 dh = desired.h - current.h ; + TXNShowSelection( (TXNObject) m_macTXN , true ) ; theErr = TXNScroll( (TXNObject) m_macTXN, kTXNScrollUnitsInPixels , kTXNScrollUnitsInPixels , &dv , &dh ); - wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); - } + wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); + } } #endif }