From 789ae0cfa2cefc10a3065a5e22c70f7180bbe15d Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 27 Feb 2005 09:10:52 +0000 Subject: [PATCH] reintroducing non-composited functionality due to DataBrowser Bugs under 10.2 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32396 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/checklst.cpp | 6 ++ src/mac/carbon/dnd.cpp | 2 +- src/mac/carbon/listbox.cpp | 85 +++++++++++---- src/mac/carbon/textctrl.cpp | 35 +++--- src/mac/carbon/toolbar.cpp | 24 ++--- src/mac/carbon/toplevel.cpp | 100 +++++++++-------- src/mac/carbon/uma.cpp | 16 +-- src/mac/carbon/window.cpp | 210 +++++++++++++++++------------------- 8 files changed, 264 insertions(+), 214 deletions(-) diff --git a/src/mac/carbon/checklst.cpp b/src/mac/carbon/checklst.cpp index d56fb61bc9..466c722e7b 100644 --- a/src/mac/carbon/checklst.cpp +++ b/src/mac/carbon/checklst.cpp @@ -300,6 +300,12 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id, #endif m_peer->SetCallbacks( &callbacks); +#if 0 + // shouldn't be necessary anymore under 10.2 + m_peer->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean) false ) ; + m_peer->SetNeedsFocusRect( true ) ; +#endif + MacPostControlCreate(pos,size) ; for ( int i = 0 ; i < n ; i++ ) diff --git a/src/mac/carbon/dnd.cpp b/src/mac/carbon/dnd.cpp index 61db55a7d6..ad21b7ffc5 100644 --- a/src/mac/carbon/dnd.cpp +++ b/src/mac/carbon/dnd.cpp @@ -482,7 +482,7 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind // wxPoint point(localMouse.h , localMouse.v) ; wxWindow *win = NULL ; ControlPartCode controlPart ; - ControlRef control = wxMacFindControlUnderMouse( localMouse , + ControlRef control = wxMacFindControlUnderMouse( toplevel , localMouse , theWindow , &controlPart ) ; if ( control ) win = wxFindControlFromMacControl( control ) ; diff --git a/src/mac/carbon/listbox.cpp b/src/mac/carbon/listbox.cpp index aba639219e..38bdecfd01 100644 --- a/src/mac/carbon/listbox.cpp +++ b/src/mac/carbon/listbox.cpp @@ -48,6 +48,10 @@ const short kTextColumnId = 1024 ; // we just introduce id s corresponding // to the line number +DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL ; +DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL ; +DataBrowserDrawItemUPP gDataBrowserDrawItemUPP = NULL ; + #if TARGET_API_MAC_OSX static pascal void DataBrowserItemNotificationProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef itemData) @@ -137,6 +141,34 @@ static pascal OSStatus ListBoxGetSetItemData(ControlRef browser, return err; } +static pascal void ListBoxDrawProc( ControlRef browser , DataBrowserItemID item , DataBrowserPropertyID property , + DataBrowserItemState itemState , const Rect *itemRect , SInt16 depth , Boolean isColorDevice ) +{ + + CFStringRef cfString; + long systemVersion; + + cfString = CFStringCreateWithFormat( NULL, NULL, CFSTR("Row %d"), item ); + + ThemeDrawingState themeState ; + GetThemeDrawingState( &themeState ) ; + + if ( itemState == kDataBrowserItemIsSelected ) // In this sample we handle the "selected" state, all others fall through to our "active" state + { + Gestalt( gestaltSystemVersion, &systemVersion ); + if ( (systemVersion >= 0x00001030) && (IsControlActive( browser ) == false) ) // Panther DB starts using kThemeBrushSecondaryHighlightColor for inactive browser hilighting + SetThemePen( kThemeBrushSecondaryHighlightColor, 32, true ); + else + SetThemePen( kThemeBrushPrimaryHighlightColor, 32, true ); + + PaintRect( itemRect ); // First paint the hilite rect, then the text on top + SetThemeDrawingState( themeState , false ) ; + } + DrawThemeTextBox( cfString, kThemeApplicationFont, kThemeStateActive, true, itemRect, teFlushDefault, NULL ); + if ( cfString != NULL ) + CFRelease( cfString ); + SetThemeDrawingState( themeState , true ) ; +} // Listbox item wxListBox::wxListBox() @@ -199,7 +231,33 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, options += kDataBrowserSelectOnlyOne ; } verify_noerr(m_peer->SetSelectionFlags( options ) ); + + if ( gDataBrowserItemDataUPP == NULL ) gDataBrowserItemDataUPP = NewDataBrowserItemDataUPP(ListBoxGetSetItemData) ; + if ( gDataBrowserItemNotificationUPP == NULL ) + { + gDataBrowserItemNotificationUPP = +#if TARGET_API_MAC_OSX + (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc) ; +#else + NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc) ; +#endif + } + if ( gDataBrowserDrawItemUPP == NULL ) gDataBrowserDrawItemUPP = NewDataBrowserDrawItemUPP(ListBoxDrawProc) ; + + DataBrowserCallbacks callbacks ; + InitializeDataBrowserCallbacks( &callbacks , kDataBrowserLatestCallbacks ) ; + + callbacks.u.v1.itemDataCallback = gDataBrowserItemDataUPP; + callbacks.u.v1.itemNotificationCallback = gDataBrowserItemNotificationUPP; + m_peer->SetCallbacks( &callbacks); + DataBrowserCustomCallbacks customCallbacks ; + InitializeDataBrowserCustomCallbacks( &customCallbacks , kDataBrowserLatestCustomCallbacks ) ; + + customCallbacks.u.v1.drawItemCallback = gDataBrowserDrawItemUPP ; + + SetDataBrowserCustomCallbacks( m_peer->GetControlRef() , &customCallbacks ) ; + DataBrowserListViewColumnDesc columnDesc ; columnDesc.headerBtnDesc.titleOffset = 0; columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; @@ -208,7 +266,6 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, kControlUseFontMask | kControlUseJustMask; columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent; - columnDesc.propertyDesc.propertyType = kDataBrowserTextType; columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault; columnDesc.headerBtnDesc.minimumWidth = 0; columnDesc.headerBtnDesc.maximumWidth = 10000; @@ -218,41 +275,25 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, columnDesc.headerBtnDesc.titleString = NULL ; // CFSTR( "" ); columnDesc.propertyDesc.propertyID = kTextColumnId; - columnDesc.propertyDesc.propertyType = kDataBrowserTextType; + columnDesc.propertyDesc.propertyType = kDataBrowserTextType ; // kDataBrowserCustomType; columnDesc.propertyDesc.propertyFlags = #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 kDataBrowserListViewTypeSelectColumn | #endif kDataBrowserTableViewSelectionColumn ; - verify_noerr(m_peer->AddListViewColumn( &columnDesc, kDataBrowserListViewAppendColumn) ) ; verify_noerr(m_peer->AutoSizeListViewColumns() ) ; verify_noerr(m_peer->SetHasScrollBars(false , true ) ) ; verify_noerr(m_peer->SetTableViewHiliteStyle(kDataBrowserTableViewFillHilite ) ) ; verify_noerr(m_peer->SetListViewHeaderBtnHeight( 0 ) ) ; - DataBrowserCallbacks callbacks ; - - callbacks.version = kDataBrowserLatestCallbacks; - - InitDataBrowserCallbacks(&callbacks); - callbacks.u.v1.itemDataCallback = - NewDataBrowserItemDataUPP(ListBoxGetSetItemData); - - callbacks.u.v1.itemNotificationCallback = -#if TARGET_API_MAC_OSX - (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc) ; -#else - NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc) ; +#if 0 + // shouldn't be necessary anymore under 10.2 + m_peer->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean) false ) ; + m_peer->SetNeedsFocusRect( true ) ; #endif - m_peer->SetCallbacks( &callbacks); -#if TARGET_API_MAC_OSX - // there is a redraw bug in 10.2.X - if ( UMAGetSystemVersion() < 0x1030 ) - m_peer->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean) false ) ; -#endif MacPostControlCreate(pos,size) ; for ( int i = 0 ; i < n ; i++ ) diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index 0cf2f1696d..791f18486b 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -214,7 +214,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 +271,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 +317,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) ; @@ -1377,6 +1375,11 @@ public : TXNControlData m_data[1] ; } ; +wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) : wxMacTextControl( peer ) +{ + SetNeedsFocusRect( true ) ; +} + wxString wxMacMLTEControl::GetStringValue() const { wxString result ; @@ -2092,7 +2095,13 @@ 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 ) ; + } // 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 @@ -2117,6 +2126,7 @@ void wxMacMLTEClassicControl::MacUpdatePosition() wxMacWindowClipper cl(textctrl) ; #ifdef __WXMAC_OSX__ + bool isCompositing = textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ; if ( m_sbHorizontal || m_sbVertical ) { int w = bounds.right - bounds.left ; @@ -2130,6 +2140,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,6 +2156,9 @@ 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 ) ; } @@ -2392,11 +2409,6 @@ void wxMacMLTEClassicControl::SuperChangedPosition() wxMacControl::SuperChangedPosition() ; } -bool wxMacMLTEClassicControl::NeedsFocusRect() const -{ - return true; -} - #ifdef __WXMAC_OSX__ ControlUserPaneDrawUPP gTPDrawProc = NULL; @@ -2650,11 +2662,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 diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index 70710393b8..5c6aedcb0e 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -240,20 +240,21 @@ void wxToolBarTool::SetPosition(const wxPoint& position) m_x = position.x; m_y = position.y; - if ( IsButton() ) + int x , y ; + x = y = 0 ; + int mac_x = position.x ; + int mac_y = position.y ; + + if ( ! GetToolBar()->MacGetTopLevelWindow()->MacUsesCompositing() ) { - int x , y ; - x = y = 0 ; - int mac_x = position.x ; - int mac_y = position.y ; -#ifdef __WXMAC_OSX__ - // already correctly set up -#else WindowRef rootwindow = (WindowRef) GetToolBar()->MacGetTopLevelWindowRef() ; GetToolBar()->MacWindowToRootWindow( &x , &y ) ; mac_x += x; mac_y += y; -#endif + } + + if ( IsButton() ) + { Rect contrlRect ; GetControlBounds( m_controlHandle , &contrlRect ) ; int former_mac_x = contrlRect.left ; @@ -273,11 +274,6 @@ void wxToolBarTool::SetPosition(const wxPoint& position) { // separator #ifdef __WXMAC_OSX__ - int x , y ; - x = y = 0 ; - int mac_x = position.x ; - int mac_y = position.y ; - Rect contrlRect ; GetControlBounds( m_controlHandle , &contrlRect ) ; int former_mac_x = contrlRect.left ; diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index 4af012f7d6..9410c614c6 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -359,7 +359,7 @@ static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) } } -ControlRef wxMacFindSubControl( Point location , ControlRef superControl , ControlPartCode *outPart ) +ControlRef wxMacFindSubControl( wxTopLevelWindowMac* toplevelWindow, Point location , ControlRef superControl , ControlPartCode *outPart ) { if ( superControl ) { @@ -383,16 +383,19 @@ ControlRef wxMacFindSubControl( Point location , ControlRef superControl , Contr UMAGetControlBoundsInWindowCoords( sibling , &r ) ; if ( MacPtInRect( location , &r ) ) { - ControlHandle child = wxMacFindSubControl( location , sibling , outPart ) ; + ControlHandle child = wxMacFindSubControl( toplevelWindow , location , sibling , outPart ) ; if ( child ) return child ; else { Point testLocation = location ; -#if TARGET_API_MAC_OSX - testLocation.h -= r.left ; - testLocation.v -= r.top ; -#endif + + if ( toplevelWindow && toplevelWindow->MacUsesCompositing() ) + { + testLocation.h -= r.left ; + testLocation.v -= r.top ; + } + *outPart = TestControl( sibling , testLocation ) ; return sibling ; } @@ -403,19 +406,20 @@ ControlRef wxMacFindSubControl( Point location , ControlRef superControl , Contr return NULL ; } -ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart ) +ControlRef wxMacFindControlUnderMouse( wxTopLevelWindowMac* toplevelWindow , Point location , WindowRef window , ControlPartCode *outPart ) { #if TARGET_API_MAC_OSX - if ( UMAGetSystemVersion() >= 0x1030 ) + if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow == 0 || toplevelWindow->MacUsesCompositing() ) ) return FindControlUnderMouse( location , window , outPart ) ; #endif ControlRef rootControl = NULL ; verify_noerr( GetRootControl( window , &rootControl ) ) ; - return wxMacFindSubControl( location , rootControl , outPart ) ; + return wxMacFindSubControl( toplevelWindow , location , rootControl , outPart ) ; } pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { + wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; OSStatus result = eventNotHandledErr ; @@ -441,7 +445,7 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev else if ( (IsWindowActive(window) && windowPart == inContent) ) { ControlPartCode part ; - control = wxMacFindControlUnderMouse( windowMouseLocation , window , &part ) ; + control = wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &part ) ; // if there is no control below the mouse position, send the event to the toplevel window itself if ( control == 0 ) currentMouseWindow = (wxWindow*) data ; @@ -549,7 +553,7 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev #ifdef __WXMAC_OSX__ && (FindControlUnderMouse(windowMouseLocation , window , &dummyPart) != - wxMacFindControlUnderMouse( windowMouseLocation , window , &dummyPart ) ) + wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &dummyPart ) ) #endif ) { @@ -557,9 +561,10 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev { EventModifiers modifiers = cEvent.GetParameter(kEventParamKeyModifiers, typeUInt32) ; Point clickLocation = windowMouseLocation ; - #if TARGET_API_MAC_OSX - currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ; - #endif + + if ( toplevelWindow->MacUsesCompositing() ) + currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ; + HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation , modifiers , (ControlActionUPP ) -1 ) ; @@ -594,19 +599,21 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev // don't mess with controls we don't know about // for some reason returning eventNotHandledErr does not lead to the correct behaviour // so we try sending them the correct control directly - wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control ) { EventModifiers modifiers = cEvent.GetParameter(kEventParamKeyModifiers, typeUInt32) ; Point clickLocation = windowMouseLocation ; -#if TARGET_API_MAC_OSX - HIPoint hiPoint ; - hiPoint.x = clickLocation.h ; - hiPoint.y = clickLocation.v ; - HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ; - clickLocation.h = (int)hiPoint.x ; - clickLocation.v = (int)hiPoint.y ; + if ( toplevelWindow->MacUsesCompositing() ) + { +#ifdef __WXMAC_OSX__ + HIPoint hiPoint ; + hiPoint.x = clickLocation.h ; + hiPoint.y = clickLocation.v ; + HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ; + clickLocation.h = (int)hiPoint.x ; + clickLocation.v = (int)hiPoint.y ; #endif + } HandleControlClick( control , clickLocation , modifiers , (ControlActionUPP ) -1 ) ; result = noErr ; @@ -720,7 +727,7 @@ static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef hand cEvent.SetParameter( kEventParamCurrentBounds , &adjustedRect ) ; } - result = noErr ; + result = noErr ; break ; } default : @@ -843,10 +850,15 @@ void wxTopLevelWindowMac::Init() m_maximizeOnShow = FALSE; m_macWindow = NULL ; #if TARGET_API_MAC_OSX - m_macUsesCompositing = TRUE; -#else - m_macUsesCompositing = FALSE; + if ( UMAGetSystemVersion() >= 0x1030 ) + { + m_macUsesCompositing = TRUE; + } + else #endif + { + m_macUsesCompositing = FALSE; + } m_macEventHandler = NULL ; m_macFullScreenData = NULL ; } @@ -1052,10 +1064,8 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, else if ( HasFlag( wxFRAME_DRAWER ) ) { wclass = kDrawerWindowClass; - // Should this be left for compositing check below? - // CreateNewWindow will fail without it, should wxDrawerWindow turn - // on compositing before calling MacCreateRealWindow? - attr |= kWindowCompositingAttribute;// | kWindowStandardHandlerAttribute; + // we must force compositing on a drawer + m_macUsesCompositing = TRUE ; } #endif //10.2 and up else @@ -1100,7 +1110,8 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, } #if TARGET_API_MAC_OSX - attr |= kWindowCompositingAttribute; + if ( m_macUsesCompositing ) + attr |= kWindowCompositingAttribute; #endif if ( HasFlag(wxFRAME_SHAPED) ) @@ -1131,18 +1142,23 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ; m_peer = new wxMacControl(this) ; #if TARGET_API_MAC_OSX - // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of - // the content view, so we have to retrieve it explicitely - HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID , - m_peer->GetControlRefAddr() ) ; - if ( !m_peer->Ok() ) + + if ( m_macUsesCompositing ) { - // compatibility mode fallback - GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ; + // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of + // the content view, so we have to retrieve it explicitely + HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID , + m_peer->GetControlRefAddr() ) ; + if ( !m_peer->Ok() ) + { + // compatibility mode fallback + GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ; + } } -#else - ::CreateRootControl( (WindowRef)m_macWindow , m_peer->GetControlRefAddr() ) ; #endif + { + ::CreateRootControl( (WindowRef)m_macWindow , m_peer->GetControlRefAddr() ) ; + } // the root control level handleer MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ; @@ -1361,9 +1377,7 @@ void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const void wxTopLevelWindowMac::MacSetMetalAppearance( bool set ) { #if TARGET_API_MAC_OSX - UInt32 attr = 0 ; - GetWindowAttributes((WindowRef) m_macWindow , &attr ) ; - wxASSERT_MSG( attr & kWindowCompositingAttribute , + wxASSERT_MSG( m_macUsesCompositing , wxT("Cannot set metal appearance on a non-compositing window") ) ; MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , diff --git a/src/mac/carbon/uma.cpp b/src/mac/carbon/uma.cpp index bf940a280d..1de3eacf7f 100644 --- a/src/mac/carbon/uma.cpp +++ b/src/mac/carbon/uma.cpp @@ -790,18 +790,18 @@ OSStatus UMAPutScrap( Size size , OSType type , void *data ) Rect* UMAGetControlBoundsInWindowCoords(ControlRef theControl, Rect *bounds) { -// wxWindow* win = wxFindControlFromMacControl( theControl ) ; - GetControlBounds( theControl , bounds ) ; #if TARGET_API_MAC_OSX WindowRef tlwref = GetControlOwner( theControl ) ; - wxWindow* tlwwx = (wxWindow*) wxFindWinFromMacWindow( tlwref ) ; - ControlRef rootControl = tlwwx->GetPeer()->GetControlRef() ; - HIPoint hiPoint = CGPointMake( 0 , 0 ) ; - - HIViewConvertPoint( &hiPoint , HIViewGetSuperview(theControl) , rootControl ) ; - OffsetRect( bounds , (short) (hiPoint.x) , (short) (hiPoint.y) ) ; + wxTopLevelWindowMac* tlwwx = wxFindWinFromMacWindow( tlwref ) ; + if ( tlwwx->MacUsesCompositing() ) + { + ControlRef rootControl = tlwwx->GetPeer()->GetControlRef() ; + HIPoint hiPoint = CGPointMake( 0 , 0 ) ; + HIViewConvertPoint( &hiPoint , HIViewGetSuperview(theControl) , rootControl ) ; + OffsetRect( bounds , (short) hiPoint.x , (short) hiPoint.y ) ; + } #endif return bounds ; } diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index e4681d15d3..df6c49635b 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -201,7 +201,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl RgnHandle updateRgn = NULL ; RgnHandle allocatedRgn = NULL ; wxRegion visRegion = thisWindow->MacGetVisibleRegion() ; - if ( cEvent.GetParameter(kEventParamRgnHandle, &updateRgn) != noErr ) + if ( thisWindow->MacGetTopLevelWindow()->MacUsesCompositing() == false || cEvent.GetParameter(kEventParamRgnHandle, &updateRgn) != noErr ) { updateRgn = (RgnHandle) visRegion.GetWXHRGN() ; } @@ -1175,6 +1175,8 @@ bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, int& x, int& y, int& w, int& h , bool adjustOrigin ) const { + bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ; + // the desired size, minus the border pixels gives the correct size of the control x = (int)pos.x; @@ -1182,9 +1184,9 @@ bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, // todo the default calls may be used as soon as PostCreateControl Is moved here w = wxMax(size.x,0) ; // WidthDefault( size.x ); h = wxMax(size.y,0) ; // HeightDefault( size.y ) ; -#if !TARGET_API_MAC_OSX - GetParent()->MacWindowToRootWindow( &x , &y ) ; -#endif + + if ( !isCompositing ) + GetParent()->MacWindowToRootWindow( &x , &y ) ; x += MacGetLeftBorderSize() ; y += MacGetTopBorderSize() ; @@ -1193,14 +1195,14 @@ bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, if ( adjustOrigin ) AdjustForParentClientOrigin( x , y ) ; -#if TARGET_API_MAC_OSX + // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border - if ( ! GetParent()->IsTopLevel() ) + if ( !GetParent()->IsTopLevel() ) { x -= GetParent()->MacGetLeftBorderSize() ; y -= GetParent()->MacGetTopBorderSize() ; } -#endif + return true ; } @@ -1222,20 +1224,22 @@ void wxWindowMac::DoGetSize(int *x, int *y) const // get the position of the bounds of this window in client coordinates of its parent void wxWindowMac::DoGetPosition(int *x, int *y) const { + bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ; + int x1 , y1 , w1 ,h1 ; MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ; x1 -= MacGetLeftBorderSize() ; y1 -= MacGetTopBorderSize() ; // to non-client - #if !TARGET_API_MAC_OSX - if ( !GetParent()->IsTopLevel() ) + + if ( !isCompositing && !GetParent()->IsTopLevel() ) { Rect bounds ; GetControlBounds( (ControlRef) GetParent()->GetHandle() , &bounds ) ; x1 -= bounds.left ; y1 -= bounds.top ; } -#endif + if ( !IsTopLevel() ) { wxWindow *parent = GetParent(); @@ -1377,6 +1381,8 @@ void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) { + bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ; + RgnHandle rgn = NewRgn() ; Rect content ; if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) @@ -1390,9 +1396,10 @@ void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , in DisposeRgn( rgn ) ; Rect structure ; m_peer->GetRect( &structure ) ; -#if !TARGET_API_MAC_OSX - OffsetRect( &content , -structure.left , -structure.top ) ; -#endif + + if ( !isCompositing ) + OffsetRect( &content , -structure.left , -structure.top ) ; + left = content.left - structure.left ; top = content.top - structure.top ; right = structure.right - content.right ; @@ -1401,6 +1408,7 @@ void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , in wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const { + bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ; wxSize sizeTotal = size; RgnHandle rgn = NewRgn() ; @@ -1418,9 +1426,9 @@ wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const DisposeRgn( rgn ) ; Rect structure ; m_peer->GetRect( &structure ) ; -#if !TARGET_API_MAC_OSX - OffsetRect( &content , -structure.left , -structure.top ) ; -#endif + + if ( !isCompositing ) + OffsetRect( &content , -structure.left , -structure.top ) ; sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ; sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ; @@ -1435,6 +1443,7 @@ wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const // Get size *available for subwindows* i.e. excluding menu bar etc. void wxWindowMac::DoGetClientSize(int *x, int *y) const { + bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ; int ww, hh; RgnHandle rgn = NewRgn() ; @@ -1448,11 +1457,13 @@ void wxWindowMac::DoGetClientSize(int *x, int *y) const m_peer->GetRect( &content ) ; } DisposeRgn( rgn ) ; -#if !TARGET_API_MAC_OSX - Rect structure ; - m_peer->GetRect( &structure ) ; - OffsetRect( &content , -structure.left , -structure.top ) ; -#endif + + if ( !isCompositing ) + { + Rect structure ; + m_peer->GetRect( &structure ) ; + OffsetRect( &content , -structure.left , -structure.top ) ; + } ww = content.right - content.left ; hh = content.bottom - content.top ; /* @@ -1538,7 +1549,8 @@ bool wxWindowMac::SetCursor(const wxCursor& cursor) wxWindowMac *mouseWin = 0 ; { - WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; + wxTopLevelWindowMac *tlw = MacGetTopLevelWindow() ; + WindowRef window = (WindowRef) ( tlw ? tlw->MacGetWindowRef() : 0 ) ; CGrafPtr savePort ; Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ; @@ -1549,7 +1561,7 @@ bool wxWindowMac::SetCursor(const wxCursor& cursor) GetMouse( &pt ) ; ControlPartCode part ; ControlRef control ; - control = wxMacFindControlUnderMouse( pt , window , &part ) ; + control = wxMacFindControlUnderMouse( tlw , pt , window , &part ) ; if ( control ) mouseWin = wxFindControlFromMacControl( control ) ; @@ -1802,14 +1814,8 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) bool vis = MacIsReallyShown() ; MacInvalidateBorders() ; - - // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not ! - if ( vis ) - m_peer->SetVisibility( false , true ) ; - + m_peer->SetRect( &r ) ; - if ( vis ) - m_peer->SetVisibility( true , true ) ; if ( doMove ) wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified @@ -1948,21 +1954,24 @@ void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxPoint wxWindowMac::GetClientAreaOrigin() const { + bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ; RgnHandle rgn = NewRgn() ; Rect content ; m_peer->GetRegion( kControlContentMetaPart , rgn ) ; GetRegionBounds( rgn , &content ) ; DisposeRgn( rgn ) ; -#if !TARGET_API_MAC_OSX - // if the content rgn is empty / not supported - // don't attempt to correct the coordinates to wxWindow relative ones - if (!::EmptyRect( &content ) ) + + if ( !isCompositing ) { - Rect structure ; - m_peer->GetRect( &structure ) ; - OffsetRect( &content , -structure.left , -structure.top ) ; + // if the content rgn is empty / not supported + // don't attempt to correct the coordinates to wxWindow relative ones + if (!::EmptyRect( &content ) ) + { + Rect structure ; + m_peer->GetRect( &structure ) ; + OffsetRect( &content , -structure.left , -structure.top ) ; + } } -#endif return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) ); } @@ -2187,83 +2196,62 @@ void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) if ( m_peer == NULL ) return ; -#if TARGET_API_MAC_OSX - if ( rect == NULL ) - m_peer->SetNeedsDisplay( true ) ; - else + + bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ; +// if ( isCompositing ) { - RgnHandle update = NewRgn() ; - SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ; - SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ; - wxPoint origin = GetClientAreaOrigin() ; - OffsetRgn( update, origin.x , origin.y ) ; - // right now this is wx' window coordinates, as our native peer does not have borders, this is - // inset - OffsetRgn( update , -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; - m_peer->SetNeedsDisplay( true , update) ; - DisposeRgn( update ) ; - } -#else -/* - RgnHandle updateRgn = NewRgn() ; - if ( rect == NULL ) - { - CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ; - } + if ( rect == NULL && isCompositing ) + m_peer->SetNeedsDisplay( true ) ; else { - SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ; - SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ; + + Rect controlBounds ; + m_peer->GetRect( &controlBounds ) ; + InvalWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &controlBounds ) ; + /* + RgnHandle update = NewRgn() ; + if ( rect == NULL ) + { + CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update ) ; + } + else + { + SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ; + SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ; + } + + wxPoint origin = GetClientAreaOrigin() ; + OffsetRgn( update, origin.x , origin.y ) ; + // right now this is wx' window coordinates, as our native peer does not have borders, this is + // inset + if ( isCompositing ) + { + OffsetRgn( update , -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; + m_peer->SetNeedsDisplay( true , update) ; + } + else + { + int x = 0 ; + int y = 0 ; + MacWindowToRootWindow( &x , &y ) ; + OffsetRgn( update , x , y ) ; + InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , update ) ; + } + DisposeRgn( update ) ; + */ } - InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ; - DisposeRgn(updateRgn) ; -*/ - if ( MacIsReallyShown() ) - { - m_peer->SetVisibility( false , false ) ; - m_peer->SetVisibility( true , true ) ; } - /* - if ( MacGetTopLevelWindow() == NULL ) - return ; - if ( !m_peer->IsVisible()) - return ; - - wxPoint client = GetClientAreaOrigin(); - int x1 = -client.x; - int y1 = -client.y; - int x2 = m_width - client.x; - int y2 = m_height - client.y; - - if (IsKindOf( CLASSINFO(wxButton))) + if ( 0 ) { - // buttons have an "aura" - y1 -= 5; - x1 -= 5; - y2 += 5; - x2 += 5; - } - - Rect clientrect = { y1, x1, y2, x2 }; - - if ( rect ) - { - Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; - SectRect( &clientrect , &r , &clientrect ) ; - } - - if ( !EmptyRect( &clientrect ) ) - { - int top = 0 , left = 0 ; - - MacClientToRootWindow( &left , &top ) ; - OffsetRect( &clientrect , left , top ) ; - - MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ; + if ( MacIsReallyShown() ) + { + /* + m_peer->SetVisibility( false , false ) ; + m_peer->SetVisibility( true , true ) ; + */ + } } - */ -#endif } void wxWindowMac::Freeze() @@ -2309,7 +2297,7 @@ void wxWindowMac::WarpPointer (int x_pos, int y_pos) void wxWindowMac::OnEraseBackground(wxEraseEvent& event) { #if TARGET_API_MAC_OSX - if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) + if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) ) { event.Skip() ; } @@ -2470,10 +2458,9 @@ void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin ) else #endif { -#ifdef __WXMAC_OSX__ // as the non OSX Version is already working in window relative coordinates, it's not needed wxTopLevelWindowMac* top = MacGetTopLevelWindow(); - if (top) + if (top && top->MacUsesCompositing()) { wxPoint pt(0,0) ; wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ; @@ -2482,7 +2469,6 @@ void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin ) rect.top += pt.y ; rect.bottom += pt.y ; } -#endif if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) { @@ -2739,7 +2725,7 @@ void wxWindowMac::OnSetFocus(wxFocusEvent& event) #ifdef __WXMAC_OSX__ // as the non OSX Version is already working in window relative coordinates, it's not needed wxTopLevelWindowMac* top = MacGetTopLevelWindow(); - if (top) + if (top && top->MacUsesCompositing() ) { wxPoint pt(0,0) ; wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ; -- 2.45.2