X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5de694f065b551d24ecf723e7fd1a276019a26b6..b94fa9f5ab1819eb00774232ebc0d3d9ec325b8f:/src/mac/carbon/textctrl.cpp diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index 0cf2f1696d..baa26ddc54 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 @@ -196,6 +197,7 @@ public : virtual void ShowPosition( long WXUNUSED(pos) ) ; virtual int GetLineLength(long lineNo) const ; virtual wxString GetLineText(long lineNo) const ; + virtual bool SetupCursor( const wxPoint& pt ) { return false ; } #ifndef __WXMAC_OSX__ virtual void MacControlUserPaneDrawProc(wxInt16 part) = 0 ; @@ -214,7 +216,7 @@ public : class wxMacMLTEControl : public wxMacTextControl { public : - wxMacMLTEControl( wxTextCtrl *peer ) : wxMacTextControl( peer ) {} + wxMacMLTEControl( wxTextCtrl *peer ) ; virtual wxString GetStringValue() const ; virtual void SetStringValue( const wxString &str) ; @@ -271,7 +273,6 @@ public : const wxSize& size, long style ) ; virtual OSStatus SetFocus( ControlFocusPart focusPart ) ; virtual bool HasFocus() const ; - virtual bool NeedsFocusRect() const; protected : HIViewRef m_scrollView ; HIViewRef m_textView ; @@ -318,7 +319,6 @@ public : ~wxMacMLTEClassicControl() ; virtual void VisibilityChanged(bool shown) ; virtual void SuperChangedPosition() ; - virtual bool NeedsFocusRect() const; virtual void MacControlUserPaneDrawProc(wxInt16 part) ; virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) ; @@ -329,6 +329,8 @@ public : virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ; virtual void MacControlUserPaneBackgroundProc(void* info) ; + virtual bool SetupCursor( const wxPoint& WXUNUSED(pt) ) { MacControlUserPaneIdleProc() ; return true ;} + virtual void SetRect( Rect *r ) ; protected : @@ -345,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) ; @@ -410,8 +412,6 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, if ( !wxTextCtrlBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) ) return false; - Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - if ( m_windowStyle & wxTE_MULTILINE ) { wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER), @@ -421,19 +421,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 ) { @@ -442,10 +450,16 @@ 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 ) ; } + + SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ; return true; } @@ -1014,7 +1028,10 @@ void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) { - return true ; + if ( !GetPeer()->SetupCursor(pt) ) + return wxWindow::MacSetupCursor( pt ) ; + else + return true ; } #if !TARGET_API_MAC_OSX @@ -1377,6 +1394,11 @@ public : TXNControlData m_data[1] ; } ; +wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) : wxMacTextControl( peer ) +{ + SetNeedsFocusRect( true ) ; +} + wxString wxMacMLTEControl::GetStringValue() const { wxString result ; @@ -1466,8 +1488,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 ; @@ -1506,7 +1532,7 @@ void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, boo }; TXNControlData iControlData[] = { - {false}, + {true}, {kTXNNoAutoWrap}, }; @@ -1523,24 +1549,28 @@ void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, boo iControlTags, iControlData )) ; // setting the default font + // under 10.2 this causes a visible caret, therefore we avoid it - Str255 fontName ; - SInt16 fontSize ; - Style fontStyle ; - - GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; - - TXNTypeAttributes typeAttr[] = + if ( UMAGetSystemVersion() >= 0x1030 ) { - { kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } , - { kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } , - { kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , { (void*) normal } } , - } ; + Str255 fontName ; + SInt16 fontSize ; + Style fontStyle ; - verify_noerr( TXNSetTypeAttributes (m_txn, sizeof( typeAttr ) / sizeof(TXNTypeAttributes) , typeAttr, - kTXNStartOffset, - kTXNEndOffset) ); + GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; + TXNTypeAttributes typeAttr[] = + { + { kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } , + { kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } , + { kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , { (void*) normal } } , + } ; + + verify_noerr( TXNSetTypeAttributes (m_txn, sizeof( typeAttr ) / sizeof(TXNTypeAttributes) , typeAttr, + kTXNStartOffset, + kTXNEndOffset) ); + } + if ( m_windowStyle & wxTE_PASSWORD ) { UniChar c = 0xA5 ; @@ -1852,7 +1882,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 @@ -2092,7 +2124,26 @@ void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus) void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis) { + ControlRef controlFocus = 0 ; + GetKeyboardFocus( m_txnWindow , &controlFocus ) ; + + if ( controlFocus == m_controlRef && vis == false ) + { + SetKeyboardFocus( m_txnWindow , m_controlRef , kControlFocusNoPart ) ; + } + + TXNControlTag iControlTags[1] = { kTXNVisibilityTag }; + TXNControlData iControlData[1] = { {(UInt32) false } }; + verify_noerr( TXNGetTXNObjectControls( m_txn , 1, + iControlTags, iControlData ) ) ; + + if ( iControlData[0].uValue != vis ) + { + iControlData[0].uValue = vis ; + verify_noerr( TXNSetTXNObjectControls( m_txn, false , 1, + iControlTags, iControlData )) ; + } // we right now are always clipping as partial visibility (overlapped) visibility // is also a problem, if we run into further problems we might set the FrameBounds to an empty // rect here @@ -2109,14 +2160,21 @@ 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__ + bool isCompositing = textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ; if ( m_sbHorizontal || m_sbVertical ) { int w = bounds.right - bounds.left ; @@ -2130,6 +2188,10 @@ void wxMacMLTEClassicControl::MacUpdatePosition() sbBounds.top = h - 14 ; sbBounds.right = w + 1 ; sbBounds.bottom = h + 1 ; + + if ( !isCompositing ) + OffsetRect( &sbBounds , m_txnControlBounds.left , m_txnControlBounds.top ) ; + SetControlBounds( m_sbHorizontal , &sbBounds ) ; SetControlViewSize( m_sbHorizontal , w ) ; } @@ -2142,12 +2204,35 @@ void wxMacMLTEClassicControl::MacUpdatePosition() sbBounds.right = w + 1 ; sbBounds.bottom = m_sbHorizontal ? h - 14 : h + 1 ; + if ( !isCompositing ) + OffsetRect( &sbBounds , m_txnControlBounds.left , m_txnControlBounds.top ) ; + SetControlBounds( m_sbVertical , &sbBounds ) ; 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, @@ -2298,7 +2383,7 @@ wxInt16 wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode, ev.modifiers = modifiers ; ev.message = (( keyCode << 8 ) & keyCodeMask ) + ( charCode & charCodeMask ) ; TXNKeyDown( m_txn , &ev); - + return kControlEntireControl; } @@ -2327,7 +2412,7 @@ wxInt16 wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action) case kControlFocusPrevPart: case kControlFocusNextPart: MacFocusPaneText( ( !wasFocused)); - focusResult = (!wasFocused) ? kControlEditTextPart : kControlFocusNoPart; + focusResult = (!wasFocused) ? (ControlPartCode) kControlEditTextPart : (ControlPartCode) kControlFocusNoPart; break; case kControlFocusNoPart: @@ -2358,17 +2443,17 @@ wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer, short featurSet; featurSet = kControlSupportsEmbedding | kControlSupportsFocus | kControlWantsIdle - | kControlWantsActivate | kControlHandlesTracking | kControlHasSpecialBackground + | kControlWantsActivate | kControlHandlesTracking // | kControlHasSpecialBackground | kControlGetsFocusOnClick | kControlSupportsLiveFeedback; verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), &bounds, featurSet, &m_controlRef ) ); DoCreate(); - MacSetObjectVisibility( wxPeer->MacIsReallyShown() ) ; - AdjustCreationAttributes( *wxWHITE , true) ; + MacSetObjectVisibility( wxPeer->MacIsReallyShown() ) ; + wxMacWindowClipper clipper( m_peer ) ; SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; TXNSetSelection( m_txn, 0, 0); @@ -2392,11 +2477,6 @@ void wxMacMLTEClassicControl::SuperChangedPosition() wxMacControl::SuperChangedPosition() ; } -bool wxMacMLTEClassicControl::NeedsFocusRect() const -{ - return true; -} - #ifdef __WXMAC_OSX__ ControlUserPaneDrawUPP gTPDrawProc = NULL; @@ -2410,7 +2490,7 @@ ControlUserPaneFocusUPP gTPFocusProc = NULL; static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) { wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; - wxMacMLTEClassicControl * win = textCtrl ? dynamic_cast(textCtrl->GetPeer()) : NULL ; + wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) win->MacControlUserPaneDrawProc(part) ; } @@ -2418,7 +2498,7 @@ static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where) { wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; - wxMacMLTEClassicControl * win = textCtrl ? dynamic_cast(textCtrl->GetPeer()) : NULL ; + wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) return win->MacControlUserPaneHitTestProc(where.h , where.v) ; else @@ -2428,7 +2508,7 @@ static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc) { wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; - wxMacMLTEClassicControl * win = textCtrl ? dynamic_cast(textCtrl->GetPeer()) : NULL ; + wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ; else @@ -2438,7 +2518,7 @@ static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef contro static pascal void wxMacControlUserPaneIdleProc(ControlRef control) { wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; - wxMacMLTEClassicControl * win = textCtrl ? dynamic_cast(textCtrl->GetPeer()) : NULL ; + wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) win->MacControlUserPaneIdleProc() ; } @@ -2446,7 +2526,7 @@ static pascal void wxMacControlUserPaneIdleProc(ControlRef control) static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) { wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; - wxMacMLTEClassicControl * win = textCtrl ? dynamic_cast(textCtrl->GetPeer()) : NULL ; + wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ; else @@ -2456,7 +2536,7 @@ static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating) { wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; - wxMacMLTEClassicControl * win = textCtrl ? dynamic_cast(textCtrl->GetPeer()) : NULL ; + wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) win->MacControlUserPaneActivateProc(activating) ; } @@ -2464,20 +2544,22 @@ static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action) { wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; - wxMacMLTEClassicControl * win = textCtrl ? dynamic_cast(textCtrl->GetPeer()) : NULL ; + wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) return win->MacControlUserPaneFocusProc(action) ; else return kControlNoPart ; } +/* static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info) { wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; - wxMacMLTEClassicControl * win = textCtrl ? dynamic_cast(textCtrl->GetPeer()) : NULL ; + wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) win->MacControlUserPaneBackgroundProc(info) ; } +*/ #endif // TXNRegisterScrollInfoProc @@ -2521,6 +2603,7 @@ OSStatus wxMacMLTEClassicControl::DoCreate() UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds); m_txnControlBounds = bounds ; + m_txnVisBounds = bounds ; CGrafPtr origPort = NULL ; GDHandle origDev = NULL ; @@ -2570,7 +2653,29 @@ OSStatus wxMacMLTEClassicControl::DoCreate() kTXNTextensionFile, kTXNSystemDefaultEncoding, &m_txn, &m_txnFrameID, NULL ) ); +/* + TXNCarbonEventInfo cInfo ; + + cInfo.useCarbonEvents = false ; + cInfo.filler = 0 ; + cInfo.flags = 0 ; + cInfo.fDictionary = NULL ; + + TXNControlTag iControlTags[] = + { + kTXNUseCarbonEvents , + }; + TXNControlData iControlData[] = + { + {(UInt32) &cInfo }, + }; + + int toptag = WXSIZEOF( iControlTags ) ; + verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag, + iControlTags, iControlData )) ; + +*/ #ifdef __WXMAC_OSX__ TXNRegisterScrollInfoProc( m_txn, gTXNScrollInfoProc, (SInt32) this); #endif @@ -2650,11 +2755,6 @@ bool wxMacMLTEHIViewControl::HasFocus() const return control == m_textView ; } -bool wxMacMLTEHIViewControl::NeedsFocusRect() const -{ - return m_windowStyle & wxNO_BORDER ? false : true; -} - #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2