X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f1ff3d4a3e58c6c583d75c478eb87b2b1cae2c2e..b9b8a2b5d79c50af78720589dc96cd7e16cde26e:/src/mac/textctrl.cpp diff --git a/src/mac/textctrl.cpp b/src/mac/textctrl.cpp index ad911c3987..4ba38713d4 100644 --- a/src/mac/textctrl.cpp +++ b/src/mac/textctrl.cpp @@ -24,6 +24,8 @@ #include #endif +#include "wx/msgdlg.h" + #if wxUSE_STD_IOSTREAM #if wxUSE_IOSTREAMH #include @@ -657,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() { @@ -783,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); @@ -838,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 ) ; } @@ -878,7 +903,7 @@ void wxTextCtrl::GetSelection(long* from, long* to) const } else { - TXNGetSelection( ((TXNObject) m_macTXN) , (TXNOffset*) from , (TXNOffset*) to ) ; + TXNGetSelection( (TXNObject) m_macTXN , (TXNOffset*) from , (TXNOffset*) to ) ; } } @@ -896,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 ) @@ -1193,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 ) ; } @@ -1292,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 ) @@ -1442,16 +1447,23 @@ void wxTextCtrl::DiscardEdits() int wxTextCtrl::GetNumberOfLines() const { - // TODO change this if possible to reflect real lines - wxString content = GetValue() ; - - int count = 1; - for (size_t i = 0; i < content.Length() ; i++) + if ( m_macUsesTXN ) { - if (content[i] == '\r') count++; + ItemCount lines ; + TXNGetLineCount((TXNObject)m_macTXN, &lines ) ; + return lines ; } + else + { + wxString content = GetValue() ; - return count; + int count = 1; + for (size_t i = 0; i < content.Length() ; i++) + { + if (content[i] == '\r') count++; + } + return count; + } } long wxTextCtrl::XYToPosition(long x, long y) const @@ -1467,7 +1479,27 @@ bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const void wxTextCtrl::ShowPosition(long pos) { - // TODO +#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 ; + 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 ) ; + theErr = TXNScroll( (TXNObject) m_macTXN, kTXNScrollUnitsInPixels , kTXNScrollUnitsInPixels , &dv , &dh ); + wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); + } + } +#endif } int wxTextCtrl::GetLineLength(long lineNo) const