X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/55d0b180270fcaa3e3be77110f2857bbab008fdd..5f7348ce627157e21bec507623ebd31c1e9dc762:/src/mac/carbon/textctrl.cpp diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index c80ba8ff6f..6980cdc9f3 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -45,6 +45,7 @@ #include "wx/settings.h" #include "wx/filefn.h" #include "wx/utils.h" +#include "wx/sysopt.h" #if defined(__BORLANDC__) && !defined(__WIN32__) #include @@ -346,7 +347,7 @@ private : WindowRef m_txnWindow ; // bounds of the control as we last did set the txn frames Rect m_txnControlBounds ; - + Rect m_txnVisBounds ; #ifdef __WXMAC_OSX__ static pascal void TXNScrollInfoProc (SInt32 iValue, SInt32 iMaximumValue, TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon) ; @@ -360,7 +361,6 @@ private : #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) @@ -379,7 +379,6 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) END_EVENT_TABLE() -#endif // Text item void wxTextCtrl::Init() @@ -420,19 +419,27 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, style |= wxTE_PROCESS_ENTER ; } + bool forceMLTE = false ; +#if wxUSE_SYSTEM_OPTIONS + if ( (wxSystemOptions::HasOption(wxMAC_TEXTCONTROL_USE_MLTE) ) && ( wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE ) == 1) ) + { + forceMLTE = true ; + } +#endif + #ifdef __WXMAC_OSX__ #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 - if ( UMAGetSystemVersion() >= 0x1050 ) + if ( UMAGetSystemVersion() >= 0x1030 && forceMLTE == false ) { - m_peer = new wxMacMLTEHIViewControl( this , str , pos , size , style ) ; + if ( m_windowStyle & wxTE_MULTILINE ) + m_peer = new wxMacMLTEHIViewControl( this , str , pos , size , style ) ; } #endif -#if !wxMAC_AWAYS_USE_MLTE if ( !m_peer ) { - m_peer = new wxMacUnicodeTextControl( this , str , pos , size , style ) ; + if ( !(m_windowStyle & wxTE_MULTILINE) && forceMLTE == false ) + m_peer = new wxMacUnicodeTextControl( this , str , pos , size , style ) ; } -#endif #endif if ( !m_peer ) { @@ -441,6 +448,10 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, MacPostControlCreate(pos,size) ; + // only now the embedding is correct and we can do a positioning update + + MacSuperChangedPosition() ; + if ( m_windowStyle & wxTE_READONLY) { SetEditable( false ) ; @@ -642,7 +653,7 @@ void wxTextCtrl::WriteText(const wxString& str) if ( !wxIsMainThread() ) { // unfortunately CW 8 is not able to correctly deduce the template types, so we have - // to instantiate explicitely + // to instantiate explicitly wxMacMPRemoteGUICall( this , &wxTextCtrl::WriteText , str ) ; return ; } @@ -1413,7 +1424,7 @@ wxString wxMacMLTEControl::GetStringValue() const SetHandleSize( theText , ( actualSize + 1 ) * sizeof( UniChar ) ) ; HLock( theText ) ; (((UniChar*)*theText)[actualSize]) = 0 ; - wxMBConvUTF16BE converter ; + wxMBConvUTF16 converter ; size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ; ptr = new wxChar[noChars + 1] ; @@ -1475,8 +1486,12 @@ void wxMacMLTEControl::SetStringValue( const wxString &str) TXNFrameOptions wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle ) { TXNFrameOptions frameOptions = - kTXNDontDrawCaretWhenInactiveMask ; - + kTXNDontDrawCaretWhenInactiveMask +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 + | kTXNDoFontSubstitutionMask +#endif + ; + if ( ! ( wxStyle & wxTE_NOHIDESEL ) ) frameOptions |= kTXNDontDrawSelectionWhenInactiveMask ; @@ -1515,7 +1530,7 @@ void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, boo }; TXNControlData iControlData[] = { - {false}, + {true}, {kTXNNoAutoWrap}, }; @@ -1865,7 +1880,9 @@ void wxMacMLTEControl::ShowPosition( long pos ) SInt32 dh = desired.h - current.h ; TXNShowSelection( m_txn , true ) ; theErr = TXNScroll( m_txn, kTXNScrollUnitsInPixels , kTXNScrollUnitsInPixels , &dv , &dh ); - wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); + // there will be an error returned for classic mlte implementation when the control is + // invisible, but HITextView works correctly, so we don't assert that one + // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); } } #endif @@ -1879,7 +1896,7 @@ void wxMacMLTEControl::SetTXNData( const wxString& st , TXNOffset start , TXNOff TXNSetData( m_txn , kTXNUnicodeTextData, (void*)st.wc_str(), len * 2, start, end); #else - wxMBConvUTF16BE converter ; + wxMBConvUTF16 converter ; ByteCount byteBufferLen = converter.WC2MB( NULL , st.wc_str() , 0 ) ; UniChar *unibuf = (UniChar*) malloc(byteBufferLen) ; converter.WC2MB( (char*) unibuf , st.wc_str() , byteBufferLen ) ; @@ -2113,24 +2130,16 @@ void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis) SetKeyboardFocus( m_txnWindow , m_controlRef , kControlFocusNoPart ) ; } - TXNControlTag iControlTags[] = - { - kTXNVisibilityTag , - }; - TXNControlData iControlData[] = - { - {(UInt32) false }, - }; - - int toptag = WXSIZEOF( iControlTags ) ; + TXNControlTag iControlTags[1] = { kTXNVisibilityTag }; + TXNControlData iControlData[1] = { {(UInt32) false } }; - verify_noerr( TXNGetTXNObjectControls( m_txn , toptag, + verify_noerr( TXNGetTXNObjectControls( m_txn , 1, iControlTags, iControlData ) ) ; if ( iControlData[0].uValue != vis ) { iControlData[0].uValue = vis ; - verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag, + verify_noerr( TXNSetTXNObjectControls( m_txn, false , 1, iControlTags, iControlData )) ; } // we right now are always clipping as partial visibility (overlapped) visibility @@ -2149,11 +2158,17 @@ void wxMacMLTEClassicControl::MacUpdatePosition() Rect bounds ; UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds); - if ( !EqualRect( &bounds , &m_txnControlBounds ) ) + wxRect visRect = textctrl->MacGetClippedClientRect() ; + Rect visBounds = { visRect.y , visRect.x , visRect.y + visRect.height , visRect.x + visRect.width } ; + int x , y ; + x = y = 0 ; + textctrl->MacWindowToRootWindow( &x , &y ) ; + OffsetRect( &visBounds , x , y ) ; + + if ( !EqualRect( &bounds , &m_txnControlBounds ) || !EqualRect( &visBounds , &m_txnVisBounds) ) { - // old position - Rect oldBounds = m_txnControlBounds ; m_txnControlBounds = bounds ; + m_txnVisBounds = visBounds ; wxMacWindowClipper cl(textctrl) ; #ifdef __WXMAC_OSX__ @@ -2194,8 +2209,28 @@ void wxMacMLTEClassicControl::MacUpdatePosition() SetControlViewSize( m_sbVertical , h ) ; } } + + Rect oldviewRect ; + TXNLongRect olddestRect ; + TXNGetRectBounds( m_txn , &oldviewRect , &olddestRect , NULL ) ; + + Rect viewRect = { m_txnControlBounds.top, m_txnControlBounds.left, + m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ; + TXNLongRect destRect = { m_txnControlBounds.top, m_txnControlBounds.left, + m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ; + + if ( olddestRect.right >= 10000 ) + destRect.right = destRect.left + 32000 ; + + if ( olddestRect.bottom >= 0x20000000 ) + destRect.bottom = destRect.top + 0x40000000 ; + + SectRect( &viewRect , &visBounds , &viewRect ) ; + TXNSetRectBounds( m_txn , &viewRect , &destRect , true ) ; +/* TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left, m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID); +*/ #else TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left, @@ -2566,6 +2601,7 @@ OSStatus wxMacMLTEClassicControl::DoCreate() UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds); m_txnControlBounds = bounds ; + m_txnVisBounds = bounds ; CGrafPtr origPort = NULL ; GDHandle origDev = NULL ; @@ -2615,7 +2651,7 @@ OSStatus wxMacMLTEClassicControl::DoCreate() kTXNTextensionFile, kTXNSystemDefaultEncoding, &m_txn, &m_txnFrameID, NULL ) ); - +/* TXNCarbonEventInfo cInfo ; cInfo.useCarbonEvents = false ; @@ -2637,7 +2673,7 @@ OSStatus wxMacMLTEClassicControl::DoCreate() verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag, iControlTags, iControlData )) ; - +*/ #ifdef __WXMAC_OSX__ TXNRegisterScrollInfoProc( m_txn, gTXNScrollInfoProc, (SInt32) this); #endif