X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/939fba6c17da245488a77a3f58e983180fc5de91..b93f3832441e0f0317be37eda0059f1d67a9b89a:/src/mac/carbon/textctrl.cpp diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index e86d3299a3..b3c1fbe234 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -24,6 +24,8 @@ #include #endif +#include "wx/msgdlg.h" + #if wxUSE_STD_IOSTREAM #if wxUSE_IOSTREAMH #include @@ -460,10 +462,7 @@ static pascal ControlPartCode TPPaneFocusProc(ControlHandle theControl, ControlF kControlFocusNoPart, otherwise return a non-zero part code. kUserClickedToFocusPart - is a constant defined for this example. You should define your own value for handling click-to-focus type events. */ - /* save the drawing state */ - SetPort((**tpvars).fDrawingEnvironment); - wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ; - /* calculate the next highlight state */ + /* calculate the next highlight state */ switch (action) { default: case kControlFocusNoPart: @@ -485,6 +484,9 @@ static pascal ControlPartCode TPPaneFocusProc(ControlHandle theControl, ControlF new focus state */ if ( IsControlVisible( theControl ) ) { + /* save the drawing state */ + SetPort((**tpvars).fDrawingEnvironment); + wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ; DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fIsActive && varsp->fInFocus); } @@ -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 +#if SIZEOF_WCHAR_T == 2 + size_t len = st.Len() ; + TXNSetData( txn , kTXNUnicodeTextData, (void*)st.wc_str(), len * 2, + start, end); +#else + wxMBConvUTF16BE converter ; + ByteCount byteBufferLen = converter.WC2MB( NULL , st.wc_str() , 0 ) ; + UniChar *unibuf = (UniChar*) malloc(byteBufferLen) ; + converter.WC2MB( (char*) unibuf , st.wc_str() , byteBufferLen ) ; + TXNSetData( txn , kTXNUnicodeTextData, (void*)unibuf, byteBufferLen , + 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() { @@ -748,7 +773,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, } wxString st = str ; - st.Replace(wxT("\n"), wxT("\r")); + wxMacConvertNewlines13To10( &st ) ; if ( !m_macUsesTXN ) { m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , false , 0 , 0 , 1, @@ -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 ) ; + HUnlock( theText ) ; +#endif ptr[actualSize] = 0 ; result.UngetWriteBuf( actualSize ) ; } @@ -865,7 +890,7 @@ wxString wxTextCtrl::GetValue() const } #endif } - result.Replace(wxT("\r"),wxT("\n")) ; + wxMacConvertNewlines10To13( &result ) ; return result ; } @@ -878,14 +903,14 @@ 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 ) ; } } void wxTextCtrl::SetValue(const wxString& str) { wxString st = str ; - st.Replace(wxT("\n"), wxT("\r")); + wxMacConvertNewlines13To10( &st ) ; if ( !m_macUsesTXN ) { wxCharBuffer text = st.mb_str(wxConvLocal) ; @@ -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 ) @@ -1174,7 +1192,7 @@ long wxTextCtrl::GetLastPosition() const void wxTextCtrl::Replace(long from, long to, const wxString& str) { wxString value = str ; - value.Replace(wxT("\n"), wxT("\r")); + wxMacConvertNewlines13To10( &value ) ; if ( !m_macUsesTXN ) { ControlEditTextSelectionRec selection ; @@ -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 ) ; } @@ -1279,7 +1291,7 @@ bool wxTextCtrl::LoadFile(const wxString& file) void wxTextCtrl::WriteText(const wxString& str) { wxString st = str ; - st.Replace(wxT("\n"), wxT("\r")); + wxMacConvertNewlines13To10( &st ) ; if ( !m_macUsesTXN ) { wxCharBuffer text = st.mb_str(wxConvLocal) ; @@ -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 ) @@ -1316,10 +1321,6 @@ void wxTextCtrl::AppendText(const wxString& text) void wxTextCtrl::Clear() { - if ( !IsEditable() ) - { - return ; - } if ( !m_macUsesTXN ) { ::SetControlData((ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ; @@ -1433,7 +1434,12 @@ bool wxTextCtrl::CanRedo() const return FALSE ; } -// Makes 'unmodified' +// Makes modifie or unmodified +void wxTextCtrl::MarkDirty() +{ + m_dirty = true; +} + void wxTextCtrl::DiscardEdits() { m_dirty = false; @@ -1441,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 @@ -1466,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