]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/carbon/window.cpp
A call to wxPopupWindow::Show shouldn't automatically cause the popup window to steal...
[wxWidgets.git] / src / osx / carbon / window.cpp
index 392c061792913a3998e1db093112b643d710d20b..1e54d5a279a86d0d32bd462fed7c6a88dcbf2484 100644 (file)
@@ -65,7 +65,7 @@
 #include "wx/osx/uma.h"
 #else
 #include "wx/osx/private.h"
 #include "wx/osx/uma.h"
 #else
 #include "wx/osx/private.h"
-// bring in themeing
+// bring in theming
 #include <Carbon/Carbon.h>
 #endif
 
 #include <Carbon/Carbon.h>
 #endif
 
 #define wxMAC_DEBUG_REDRAW 0
 #endif
 
 #define wxMAC_DEBUG_REDRAW 0
 #endif
 
+// Get the window with the focus
+WXWidget wxWidgetImpl::FindFocus()
+{
+    ControlRef control = NULL ;
+    GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
+    return control;
+}
+
 // ---------------------------------------------------------------------------
 // Carbon Events
 // ---------------------------------------------------------------------------
 // ---------------------------------------------------------------------------
 // Carbon Events
 // ---------------------------------------------------------------------------
@@ -131,24 +139,23 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
     {
         case kEventControlDraw :
             {
     {
         case kEventControlDraw :
             {
-                RgnHandle updateRgn = NULL ;
-                RgnHandle allocatedRgn = NULL ;
+                HIShapeRef updateRgn = NULL ;
+                HIMutableShapeRef allocatedRgn = NULL ;
                 wxRegion visRegion = thisWindow->MacGetVisibleRegion() ;
 
                 wxRegion visRegion = thisWindow->MacGetVisibleRegion() ;
 
-                if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr )
+                // according to the docs: redraw entire control if param not present
+                if ( cEvent.GetParameter<HIShapeRef>(kEventParamShape, &updateRgn) != noErr )
                 {
                 {
-                    HIShapeGetAsQDRgn( visRegion.GetWXHRGN(), updateRgn );
+                    updateRgn = visRegion.GetWXHRGN();
                 }
                 else
                 {
                     if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 )
                     {
                         // as this update region is in native window locals we must adapt it to wx window local
                 }
                 else
                 {
                     if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 )
                     {
                         // as this update region is in native window locals we must adapt it to wx window local
-                        allocatedRgn = NewRgn() ;
-                        CopyRgn( updateRgn , allocatedRgn ) ;
-
+                        allocatedRgn = HIShapeCreateMutableCopy(updateRgn);
+                        HIShapeOffset(allocatedRgn, thisWindow->MacGetLeftBorderSize() , thisWindow->MacGetTopBorderSize());
                         // hide the given region by the new region that must be shifted
                         // hide the given region by the new region that must be shifted
-                        OffsetRgn( allocatedRgn , thisWindow->MacGetLeftBorderSize() , thisWindow->MacGetTopBorderSize() ) ;
                         updateRgn = allocatedRgn ;
                     }
                 }
                         updateRgn = allocatedRgn ;
                     }
                 }
@@ -177,7 +184,6 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
 #endif
 
                 {
 #endif
 
                 {
-                    bool created = false ;
                     CGContextRef cgContext = NULL ;
                     OSStatus err = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) ;
                     if ( err != noErr )
                     CGContextRef cgContext = NULL ;
                     OSStatus err = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) ;
                     if ( err != noErr )
@@ -201,7 +207,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                                     iter = iter->GetParent() ;
                             }
                         }
                                     iter = iter->GetParent() ;
                             }
                         }
-                        CGContextSetAlpha( cgContext , alpha ) ;
+                        CGContextSetAlpha( cgContext, alpha ) ;
 
                         if ( thisWindow->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
                         {
 
                         if ( thisWindow->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
                         {
@@ -210,20 +216,36 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                             CGContextClearRect( cgContext, bounds );
                         }
 
                             CGContextClearRect( cgContext, bounds );
                         }
 
-
-
-                        if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
-                            result = noErr ;
-
+                        if ( !HIShapeIsEmpty(updateRgn) )
+                        {
+                            // refcount increase because wxRegion constructor takes ownership of the native region
+                            CFRetain(updateRgn);
+                            thisWindow->GetUpdateRegion() = wxRegion(updateRgn);
+                            if ( !thisWindow->MacDoRedraw( cEvent.GetTicks() ) )
+                            {
+                               // for native controls: call their native paint method
+                                if ( !thisWindow->MacIsUserPane() ||
+                                    ( thisWindow->IsTopLevel() && thisWindow->GetBackgroundStyle() == wxBG_STYLE_SYSTEM ) )
+                                {
+                                    if ( thisWindow->GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT )
+                                    {
+                                        CallNextEventHandler( handler,event ) ;
+                                        result = noErr ;
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                result = noErr ;
+                            }
+                            thisWindow->MacPaintChildrenBorders();
+                        }
                         thisWindow->MacSetCGContextRef( NULL ) ;
                     }
                         thisWindow->MacSetCGContextRef( NULL ) ;
                     }
-
-                    if ( created )
-                        CGContextRelease( cgContext ) ;
                 }
 
                 if ( allocatedRgn )
                 }
 
                 if ( allocatedRgn )
-                    DisposeRgn( allocatedRgn ) ;
+                    CFRelease( allocatedRgn ) ;
             }
             break ;
 
             }
             break ;
 
@@ -287,8 +309,8 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                         thisWindow->GetCaret()->OnKillFocus();
 #endif
 
                         thisWindow->GetCaret()->OnKillFocus();
 #endif
 
-                    wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
-                    
+                    wxLogTrace(wxT("Focus"), wxT("focus lost(%p)"), static_cast<void*>(thisWindow));
+
                     // remove this as soon as posting the synthesized event works properly
                     static bool inKillFocusEvent = false ;
 
                     // remove this as soon as posting the synthesized event works properly
                     static bool inKillFocusEvent = false ;
 
@@ -307,7 +329,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                 {
                     // set focus
                     // panel wants to track the window which was the last to have focus in it
                 {
                     // set focus
                     // panel wants to track the window which was the last to have focus in it
-                    wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
+                    wxLogTrace(wxT("Focus"), wxT("focus set(%p)"), static_cast<void*>(thisWindow));
                     wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
                     thisWindow->HandleWindowEvent(eventFocus);
 
                     wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
                     thisWindow->HandleWindowEvent(eventFocus);
 
@@ -335,14 +357,14 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                 if ( controlPart != kControlFocusNoPart )
                 {
                     targetFocusWindow = thisWindow;
                 if ( controlPart != kControlFocusNoPart )
                 {
                     targetFocusWindow = thisWindow;
-                    wxLogTrace(_T("Focus"), _T("focus to be set(%p)"), static_cast<void*>(thisWindow));
+                    wxLogTrace(wxT("Focus"), wxT("focus to be set(%p)"), static_cast<void*>(thisWindow));
                 }
                 else
                 {
                     formerFocusWindow = thisWindow;
                 }
                 else
                 {
                     formerFocusWindow = thisWindow;
-                    wxLogTrace(_T("Focus"), _T("focus to be lost(%p)"), static_cast<void*>(thisWindow));
+                    wxLogTrace(wxT("Focus"), wxT("focus to be lost(%p)"), static_cast<void*>(thisWindow));
                 }
                 }
-                
+
                 ControlPartCode previousControlPart = 0;
                 verify_noerr( HIViewGetFocusPart(controlRef, &previousControlPart));
 
                 ControlPartCode previousControlPart = 0;
                 verify_noerr( HIViewGetFocusPart(controlRef, &previousControlPart));
 
@@ -375,7 +397,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                         iEvent.SetParameter<EventTargetRef>( kEventParamPostTarget, typeEventTargetRef, GetControlEventTarget( controlRef ) );
                         iEvent.SetParameter<ControlPartCode>( kEventParamControlPreviousPart, typeControlPartCode, previousControlPart );
                         iEvent.SetParameter<ControlPartCode>( kEventParamControlCurrentPart, typeControlPartCode, currentControlPart );
                         iEvent.SetParameter<EventTargetRef>( kEventParamPostTarget, typeEventTargetRef, GetControlEventTarget( controlRef ) );
                         iEvent.SetParameter<ControlPartCode>( kEventParamControlPreviousPart, typeControlPartCode, previousControlPart );
                         iEvent.SetParameter<ControlPartCode>( kEventParamControlCurrentPart, typeControlPartCode, currentControlPart );
-        
+
 #if 1
                         // TODO test this first, avoid double posts etc...
                         PostEventToQueue( GetMainEventQueue(), evRef , kEventPriorityHigh );
 #if 1
                         // TODO test this first, avoid double posts etc...
                         PostEventToQueue( GetMainEventQueue(), evRef , kEventPriorityHigh );
@@ -393,7 +415,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                             thisWindow->GetCaret()->OnKillFocus();
 #endif
 
                             thisWindow->GetCaret()->OnKillFocus();
 #endif
 
-                        wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
+                        wxLogTrace(wxT("Focus"), wxT("focus lost(%p)"), static_cast<void*>(thisWindow));
 
                         static bool inKillFocusEvent = false ;
 
 
                         static bool inKillFocusEvent = false ;
 
@@ -409,7 +431,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                     else
                     {
                         // panel wants to track the window which was the last to have focus in it
                     else
                     {
                         // panel wants to track the window which was the last to have focus in it
-                        wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
+                        wxLogTrace(wxT("Focus"), wxT("focus set(%p)"), static_cast<void*>(thisWindow));
                         wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
                         thisWindow->HandleWindowEvent(eventFocus);
 
                         wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
                         thisWindow->HandleWindowEvent(eventFocus);
 
@@ -770,13 +792,46 @@ pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode p
     {
         wxWindow*  wx = wxFindWindowFromWXWidget(  (WXWidget) control ) ;
         if ( wx )
     {
         wxWindow*  wx = wxFindWindowFromWXWidget(  (WXWidget) control ) ;
         if ( wx )
-            wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ;
+        {
+            wxEventType scrollEvent = wxEVT_NULL;
+            switch ( partCode )
+            {
+            case kControlUpButtonPart:
+                scrollEvent = wxEVT_SCROLL_LINEUP;
+                break;
+
+            case kControlDownButtonPart:
+                scrollEvent = wxEVT_SCROLL_LINEDOWN;
+                break;
+
+            case kControlPageUpPart:
+                scrollEvent = wxEVT_SCROLL_PAGEUP;
+                break;
+
+            case kControlPageDownPart:
+                scrollEvent = wxEVT_SCROLL_PAGEDOWN;
+                break;
+
+            case kControlIndicatorPart:
+                scrollEvent = wxEVT_SCROLL_THUMBTRACK;
+                // when this is called as a live proc, mouse is always still down
+                // so no need for thumbrelease
+                // scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
+                break;
+            }
+            wx->TriggerScrollEvent(scrollEvent) ;
+        }
     }
 }
 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP , wxMacLiveScrollbarActionProc ) ;
 
     }
 }
 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP , wxMacLiveScrollbarActionProc ) ;
 
-wxWidgetImplType* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
-                            long style, long extraStyle)
+wxWidgetImplType* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer,
+                            wxWindowMac* WXUNUSED(parent),
+                            wxWindowID WXUNUSED(id),
+                            const wxPoint& pos,
+                            const wxSize& size,
+                            long WXUNUSED(style),
+                            long WXUNUSED(extraStyle))
 {
     OSStatus err = noErr;
     Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ;
 {
     OSStatus err = noErr;
     Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ;
@@ -870,7 +925,7 @@ void wxMacControl::Raise()
 {
     verify_noerr( HIViewSetZOrder( m_controlRef, kHIViewZOrderAbove, NULL ) );
 }
 {
     verify_noerr( HIViewSetZOrder( m_controlRef, kHIViewZOrderAbove, NULL ) );
 }
-    
+
 void wxMacControl::Lower()
 {
     verify_noerr( HIViewSetZOrder( m_controlRef, kHIViewZOrderBelow, NULL ) );
 void wxMacControl::Lower()
 {
     verify_noerr( HIViewSetZOrder( m_controlRef, kHIViewZOrderBelow, NULL ) );
@@ -878,19 +933,27 @@ void wxMacControl::Lower()
 
 void wxMacControl::GetContentArea(int &left , int &top , int &width , int &height) const
 {
 
 void wxMacControl::GetContentArea(int &left , int &top , int &width , int &height) const
 {
-    RgnHandle rgn = NewRgn() ;
+    HIShapeRef rgn = NULL;
     Rect content ;
     Rect content ;
-    if ( GetControlRegion( m_controlRef, kControlContentMetaPart , rgn ) == noErr )
-        GetRegionBounds( rgn , &content ) ;
+
+    if ( HIViewCopyShape(m_controlRef, kHIViewContentMetaPart, &rgn) == noErr)
+    {
+        CGRect cgrect;
+        HIShapeGetBounds(rgn, &cgrect);
+        content = (Rect){ (short)cgrect.origin.y,
+                          (short)cgrect.origin.x,
+                          (short)(cgrect.origin.y+cgrect.size.height),
+                          (short)(cgrect.origin.x+cgrect.size.width) };
+        CFRelease(rgn);
+    }
     else
     {
     else
     {
-        GetControlBounds( m_controlRef , &content );
+        GetControlBounds(m_controlRef, &content);
         content.right -= content.left;
         content.left = 0;
         content.bottom -= content.top;
         content.top = 0;
     }
         content.right -= content.left;
         content.left = 0;
         content.bottom -= content.top;
         content.top = 0;
     }
-    DisposeRgn( rgn ) ;
 
     left = content.left;
     top = content.top;
 
     left = content.left;
     top = content.top;
@@ -921,7 +984,7 @@ void wxMacControl::GetSize( int &width, int &height ) const
     height = r.bottom - r.top;
 }
 
     height = r.bottom - r.top;
 }
 
-void wxMacControl::SetControlSize( wxWindowVariant variant ) 
+void wxMacControl::SetControlSize( wxWindowVariant variant )
 {
     ControlSize size ;
     switch ( variant )
 {
     ControlSize size ;
     switch ( variant )
@@ -944,7 +1007,7 @@ void wxMacControl::SetControlSize( wxWindowVariant variant )
             break ;
 
         default:
             break ;
 
         default:
-            wxFAIL_MSG(_T("unexpected window variant"));
+            wxFAIL_MSG(wxT("unexpected window variant"));
             break ;
     }
 
             break ;
     }
 
@@ -1027,7 +1090,7 @@ bool wxMacControl::SetFocus()
     if ( err == errCouldntSetFocus )
         return false ;
     SetUserFocusWindow(GetControlOwner( m_controlRef ) );
     if ( err == errCouldntSetFocus )
         return false ;
     SetUserFocusWindow(GetControlOwner( m_controlRef ) );
-    
+
     return true;
 }
 
     return true;
 }
 
@@ -1132,17 +1195,15 @@ wxInt32 wxMacControl::GetValue() const
     return ::GetControl32BitValue( m_controlRef );
 }
 
     return ::GetControl32BitValue( m_controlRef );
 }
 
-SInt32 wxMacControl::GetMaximum() const
+wxInt32 wxMacControl::GetMaximum() const
 {
     return ::GetControl32BitMaximum( m_controlRef );
 }
 
 {
     return ::GetControl32BitMaximum( m_controlRef );
 }
 
-/*
 wxInt32 wxMacControl::GetMinimum() const
 {
     return ::GetControl32BitMinimum( m_controlRef );
 }
 wxInt32 wxMacControl::GetMinimum() const
 {
     return ::GetControl32BitMinimum( m_controlRef );
 }
-*/
 
 void wxMacControl::SetValue( wxInt32 v )
 {
 
 void wxMacControl::SetValue( wxInt32 v )
 {
@@ -1186,7 +1247,7 @@ void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , l
             flush = kHIThemeTextHorizontalFlushCenter;
         else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT )
             flush = kHIThemeTextHorizontalFlushRight;
             flush = kHIThemeTextHorizontalFlushCenter;
         else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT )
             flush = kHIThemeTextHorizontalFlushRight;
-        HIViewSetTextFont( m_controlRef , part , (CTFontRef) font.MacGetCTFont() );
+        HIViewSetTextFont( m_controlRef , part , (CTFontRef) font.OSXGetCTFont() );
         HIViewSetTextHorizontalFlush( m_controlRef, part, flush );
 
         if ( foreground != *wxBLACK || ignoreBlack == false )
         HIViewSetTextHorizontalFlush( m_controlRef, part, flush );
 
         if ( foreground != *wxBLACK || ignoreBlack == false )
@@ -1227,7 +1288,7 @@ void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , l
     {
         fontStyle.font = font.MacGetFontNum();
         fontStyle.style = font.MacGetFontStyle();
     {
         fontStyle.font = font.MacGetFontNum();
         fontStyle.style = font.MacGetFontStyle();
-        fontStyle.size = font.MacGetFontSize();
+        fontStyle.size = font.GetPointSize();
         fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask;
     }
 
         fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask;
     }
 
@@ -1352,12 +1413,6 @@ void wxMacControl::GetFeatures( UInt32 * features )
     GetControlFeatures( m_controlRef , features );
 }
 
     GetControlFeatures( m_controlRef , features );
 }
 
-OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region )
-{
-    OSStatus err = GetControlRegion( m_controlRef , partCode , region );
-    return err;
-}
-
 void wxMacControl::PulseGauge()
 {
 }
 void wxMacControl::PulseGauge()
 {
 }
@@ -1412,11 +1467,21 @@ wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control)
     return NULL;
 }
 
     return NULL;
 }
 
+wxBitmap wxMacControl::GetBitmap() const
+{
+    return wxNullBitmap;
+}
+
 void wxMacControl::SetBitmap( const wxBitmap& WXUNUSED(bmp) )
 {
     // implemented in the respective subclasses
 }
 
 void wxMacControl::SetBitmap( const wxBitmap& WXUNUSED(bmp) )
 {
     // implemented in the respective subclasses
 }
 
+void wxMacControl::SetBitmapPosition( wxDirection WXUNUSED(dir) )
+{
+    // implemented in the same subclasses that implement SetBitmap()
+}
+
 void wxMacControl::SetScrollThumb( wxInt32 WXUNUSED(pos), wxInt32 WXUNUSED(viewsize) )
 {
     // implemented in respective subclass
 void wxMacControl::SetScrollThumb( wxInt32 WXUNUSED(pos), wxInt32 WXUNUSED(viewsize) )
 {
     // implemented in respective subclass
@@ -1435,11 +1500,11 @@ OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable )
 
 // Control Factory
 
 
 // Control Factory
 
-wxWidgetImplType* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now ) 
+wxWidgetImplType* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
 {
     // 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 explicitly
 {
     // 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 explicitly
-    
+
     wxMacControl* contentview = new wxMacControl(now , true /*isRootControl*/);
     HIViewFindByID( HIViewGetRoot( (WindowRef) now->GetWXWindow() ) , kHIViewWindowContentID ,
         contentview->GetControlRefAddr() ) ;
     wxMacControl* contentview = new wxMacControl(now , true /*isRootControl*/);
     HIViewFindByID( HIViewGetRoot( (WindowRef) now->GetWXWindow() ) , kHIViewWindowContentID ,
         contentview->GetControlRefAddr() ) ;