X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7dbefc568525cecea8c67986775a945283afd365..3570a1c6e596c358848c77c5b37d724097340ce8:/src/mac/carbon/textctrl.cpp diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index 9f8e83ee04..a8bcfbdef9 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -44,6 +44,7 @@ #include "wx/filefn.h" #include "wx/sysopt.h" +#include "wx/thread.h" #include "wx/mac/uma.h" #include "wx/mac/carbon/private/mactext.h" @@ -141,6 +142,79 @@ void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( con return result ; } +class WXDLLEXPORT wxMacPortSaver +{ + DECLARE_NO_COPY_CLASS(wxMacPortSaver) + +public: + wxMacPortSaver( GrafPtr port ); + ~wxMacPortSaver(); +private : + GrafPtr m_port; +}; + + +/* + Clips to the visible region of a control within the current port + */ + +class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver +{ + DECLARE_NO_COPY_CLASS(wxMacWindowClipper) + +public: + wxMacWindowClipper( const wxWindow* win ); + ~wxMacWindowClipper(); +private: + GrafPtr m_newPort; + RgnHandle m_formerClip; + RgnHandle m_newClip; +}; + +wxMacPortSaver::wxMacPortSaver( GrafPtr port ) +{ + ::GetPort( &m_port ); + ::SetPort( port ); +} + +wxMacPortSaver::~wxMacPortSaver() +{ + ::SetPort( m_port ); +} + +wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) : +wxMacPortSaver( (GrafPtr) GetWindowPort( (WindowRef) win->MacGetTopLevelWindowRef() ) ) +{ + m_newPort = (GrafPtr) GetWindowPort( (WindowRef) win->MacGetTopLevelWindowRef() ) ; + m_formerClip = NewRgn() ; + m_newClip = NewRgn() ; + GetClip( m_formerClip ) ; + + if ( win ) + { + // guard against half constructed objects, this just leads to a empty clip + if ( win->GetPeer() ) + { + int x = 0 , y = 0; + win->MacWindowToRootWindow( &x, &y ) ; + + // get area including focus rect + HIShapeGetAsQDRgn( ((wxWindow*)win)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip ); + if ( !EmptyRgn( m_newClip ) ) + OffsetRgn( m_newClip , x , y ) ; + } + + SetClip( m_newClip ) ; + } +} + +wxMacWindowClipper::~wxMacWindowClipper() +{ + SetPort( m_newPort ) ; + SetClip( m_formerClip ) ; + DisposeRgn( m_newClip ) ; + DisposeRgn( m_formerClip ) ; +} // common parts for implementations based on MLTE @@ -157,7 +231,7 @@ public : void AdjustCreationAttributes( const wxColour& background, bool visible ) ; virtual void SetFont( const wxFont & font, const wxColour& foreground, long windowStyle ) ; - virtual void SetBackground( const wxBrush &brush ) ; + virtual void SetBackgroundColour(const wxColour& col ); virtual void SetStyle( long start, long end, const wxTextAttr& style ) ; virtual void Copy() ; virtual void Cut() ; @@ -218,7 +292,7 @@ public : virtual OSStatus SetFocus( ControlFocusPart focusPart ) ; virtual bool HasFocus() const ; - virtual void SetBackground( const wxBrush &brush) ; + virtual void SetBackgroundColour(const wxColour& col ) ; protected : HIViewRef m_scrollView ; @@ -287,7 +361,6 @@ private : IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) - EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground ) EVT_DROP_FILES(wxTextCtrl::OnDropFiles) EVT_CHAR(wxTextCtrl::OnChar) EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) @@ -385,7 +458,7 @@ void wxTextCtrl::CreatePeer( if ( !forceMLTE ) { - if ( m_windowStyle & wxTE_MULTILINE ) + if ( m_windowStyle & wxTE_MULTILINE || ( UMAGetSystemVersion() >= 0x1050 ) ) m_peer = new wxMacMLTEHIViewControl( this , str , pos , size , style ) ; } @@ -416,10 +489,6 @@ void wxTextCtrl::MacVisibilityChanged() GetPeer()->VisibilityChanged( MacIsReallyShown() ) ; } -void wxTextCtrl::MacEnabledStateChanged() -{ -} - void wxTextCtrl::MacCheckSpelling(bool check) { GetPeer()->CheckSpelling(check); @@ -495,7 +564,7 @@ void wxTextCtrl::Cut() wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); event.SetEventObject( this ); - GetEventHandler()->ProcessEvent( event ); + HandleWindowEvent( event ); } } @@ -509,7 +578,7 @@ void wxTextCtrl::Paste() wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); event.SetEventObject( this ); - GetEventHandler()->ProcessEvent( event ); + HandleWindowEvent( event ); } } @@ -755,15 +824,6 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) LoadFile( event.GetFiles()[0] ); } -void wxTextCtrl::OnEraseBackground(wxEraseEvent& event) -{ - // all erasing should be done by the real mac control implementation - // while this is true for MLTE under classic, the HITextView is somehow - // transparent but background erase is not working correctly, so intercept - // things while we can... - event.Skip() ; -} - void wxTextCtrl::OnChar(wxKeyEvent& event) { int key = event.GetKeyCode() ; @@ -833,7 +893,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); event.SetEventObject( this ); event.SetString( GetValue() ); - if ( GetEventHandler()->ProcessEvent(event) ) + if ( HandleWindowEvent(event) ) return; } @@ -1279,7 +1339,7 @@ bool wxMacUnicodeTextControl::Create( wxTextCtrl *wxPeer, Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; wxString st = str ; wxMacConvertNewlines10To13( &st ) ; - wxMacCFStringHolder cf(st , m_font.GetEncoding()) ; + wxCFStringRef cf(st , m_font.GetEncoding()) ; CFStringRef cfr = cf ; m_valueTag = kControlEditTextCFStringTag ; @@ -1323,7 +1383,7 @@ wxString wxMacUnicodeTextControl::GetStringValue() const CFStringRef value = GetData(0, m_valueTag) ; if ( value ) { - wxMacCFStringHolder cf(value) ; + wxCFStringRef cf(value) ; result = cf.AsString() ; } @@ -1340,7 +1400,7 @@ void wxMacUnicodeTextControl::SetStringValue( const wxString &str ) { wxString st = str ; wxMacConvertNewlines10To13( &st ) ; - wxMacCFStringHolder cf( st , m_font.GetEncoding() ) ; + wxCFStringRef cf( st , m_font.GetEncoding() ) ; verify_noerr( SetData( 0, m_valueTag , cf ) ) ; } @@ -1406,7 +1466,7 @@ void wxMacUnicodeTextControl::SetSelection( long from , long to ) CFStringRef value = GetData(0, m_valueTag) ; if ( value ) { - wxMacCFStringHolder cf(value) ; + wxCFStringRef cf(value) ; textLength = cf.AsString().length() ; } @@ -1439,7 +1499,7 @@ void wxMacUnicodeTextControl::WriteText( const wxString& str ) if ( HasFocus() ) { - wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ; + wxCFStringRef cf(st , m_font.GetEncoding() ) ; CFStringRef value = cf ; SetData( 0, kControlEditTextInsertCFStringRefTag, &value ); } @@ -1611,7 +1671,8 @@ TXNFrameOptions wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle ) if ( wxStyle & wxTE_MULTILINE ) { - frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ; + if ( ! (wxStyle & wxTE_DONTWRAP ) ) + frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ; if ( !(wxStyle & wxTE_NO_VSCROLL) ) { @@ -1689,7 +1750,7 @@ void wxMacMLTEControl::AdjustCreationAttributes(const wxColour &background, TXNBackground tback; tback.bgType = kTXNBackgroundTypeRGB; - tback.bg.color = MAC_WXCOLORREF( background.GetPixel() ); + background.GetRGBColor( &tback.bg.color ); TXNSetBackground( m_txn , &tback ); @@ -1724,13 +1785,11 @@ void wxMacMLTEControl::AdjustCreationAttributes(const wxColour &background, } } -void wxMacMLTEControl::SetBackground( const wxBrush &brush ) +void wxMacMLTEControl::SetBackgroundColour(const wxColour& col ) { - // currently only solid background are supported TXNBackground tback; - tback.bgType = kTXNBackgroundTypeRGB; - tback.bg.color = MAC_WXCOLORREF( brush.GetColour().GetPixel() ); + col.GetRGBColor(&tback.bg.color); TXNSetBackground( m_txn , &tback ); } @@ -1767,8 +1826,7 @@ void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , lo if ( style.HasTextColour() ) { wxASSERT( typeAttrCount < WXSIZEOF(typeAttr) ); - color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ; - + style.GetTextColour().GetRGBColor( &color ); typeAttr[typeAttrCount].tag = kTXNQDFontColorAttribute ; typeAttr[typeAttrCount].size = kTXNQDFontColorAttributeSize ; typeAttr[typeAttrCount].data.dataPtr = (void*) &color ; @@ -2403,7 +2461,7 @@ void wxMacMLTEClassicControl::MacUpdatePosition() return ; Rect bounds ; - UMAGetControlBoundsInWindowCoords( m_controlRef, &bounds ); + GetRectInWindowCoords( &bounds ); wxRect visRect = textctrl->MacGetClippedClientRect() ; Rect visBounds = { visRect.y , visRect.x , visRect.y + visRect.height , visRect.x + visRect.width } ; @@ -2831,7 +2889,7 @@ OSStatus wxMacMLTEClassicControl::DoCreate() SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneFocusProcTag, sizeof(gTPFocusProc), &gTPFocusProc); // calculate the rectangles used by the control - UMAGetControlBoundsInWindowCoords( m_controlRef, &bounds ); + GetRectInWindowCoords( &bounds ); m_txnControlBounds = bounds ; m_txnVisBounds = bounds ; @@ -2974,7 +3032,7 @@ wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, m_scrollView = NULL ; TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( style ) ; - if (( frameOptions & (kTXNWantVScrollBarMask | kTXNWantHScrollBarMask)) || !(frameOptions &kTXNSingleLineOnlyMask)) + if (( frameOptions & (kTXNWantVScrollBarMask | kTXNWantHScrollBarMask)) || (frameOptions &kTXNSingleLineOnlyMask)) { if ( frameOptions & (kTXNWantVScrollBarMask | kTXNWantHScrollBarMask) ) { @@ -3042,24 +3100,9 @@ bool wxMacMLTEHIViewControl::HasFocus() const return control == m_textView ; } -void wxMacMLTEHIViewControl::SetBackground( const wxBrush &brush ) +void wxMacMLTEHIViewControl::SetBackgroundColour(const wxColour& col ) { - wxMacMLTEControl::SetBackground( brush ) ; - -#if 0 - CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB(); - RGBColor col = MAC_WXCOLORREF(brush.GetColour().GetPixel()) ; - - float component[4] ; - component[0] = col.red / 65536.0 ; - component[1] = col.green / 65536.0 ; - component[2] = col.blue / 65536.0 ; - component[3] = 1.0 ; // alpha - - CGColorRef color = CGColorCreate( rgbSpace , component ); - HITextViewSetBackgroundColor( m_textView , color ); - CGColorSpaceRelease( rgbSpace ); -#endif + HITextViewSetBackgroundColor( m_textView, col.GetPixel() ); } #endif // wxUSE_TEXTCTRL