]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/window.mm
Use correct delete[] for a buffer allocated with new[].
[wxWidgets.git] / src / osx / cocoa / window.mm
index a297d9c1fb044dc2380deddfdcac92edbfbff5b1..4e0e77f95bdbbcfd9a4915c9c7bdf581c7727335 100644 (file)
@@ -387,8 +387,8 @@ bool g_lastButtonWasFakeRight = false ;
 // see http://lists.apple.com/archives/cocoa-dev/2007/Feb/msg00050.html
 
 @interface NSEvent (DeviceDelta)
-- (float)deviceDeltaX;
-- (float)deviceDeltaY;
+- (CGFloat)deviceDeltaX;
+- (CGFloat)deviceDeltaY;
 @end
 
 void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
@@ -784,12 +784,34 @@ BOOL wxOSX_isFlipped(NSView* self, SEL _cmd)
     return impl->isFlipped(self, _cmd) ? YES:NO;
 }
 
+typedef void (*wxOSX_DrawRectHandlerPtr)(NSView* self, SEL _cmd, NSRect rect);
+
 void wxOSX_drawRect(NSView* self, SEL _cmd, NSRect rect)
 {
     wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
     if (impl == NULL)
         return;
 
+#ifdef wxUSE_THREADS
+    // OS X starts a NSUIHeartBeatThread for animating the default button in a
+    // dialog. This causes a drawRect of the active dialog from outside the
+    // main UI thread. This causes an occasional crash since the wx drawing
+    // objects (like wxPen) are not thread safe.
+    //
+    // Notice that NSUIHeartBeatThread seems to be undocumented and doing
+    // [NSWindow setAllowsConcurrentViewDrawing:NO] does not affect it.
+    if ( !wxThread::IsMain() )
+    {
+      // just call the superclass handler, we don't need any custom wx drawing
+      // here and it seems to work fine:
+      wxOSX_DrawRectHandlerPtr
+          superimpl = (wxOSX_DrawRectHandlerPtr)
+                        [[self superclass] instanceMethodForSelector:_cmd];
+      superimpl(self, _cmd, rect);
+      return;
+    }
+#endif // wxUSE_THREADS
+
     return impl->drawRect(&rect, self, _cmd);
 }
 
@@ -960,7 +982,6 @@ typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
 typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
 typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd);
 typedef BOOL (*wxOSX_ResetCursorRectsHandlerPtr)(NSView* self, SEL _cmd);
-typedef void (*wxOSX_DrawRectHandlerPtr)(NSView* self, SEL _cmd, NSRect rect);
 
 void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
 {
@@ -1039,6 +1060,15 @@ bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd)
     // is resigning
     NSView* otherView = FindFocus();
     wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
+
+    // It doesn't make sense to notify about the loss of focus if we're not
+    // really losing it and the window which has just gained focus is the same
+    // one as this window itself. Of course, this should never happen in the
+    // first place but somehow it does in wxGrid code and without this check we
+    // enter into an infinite recursion, see #12267.
+    if ( otherWindow == this )
+        return r;
+
     // NSTextViews have an editor as true responder, therefore the might get the
     // resign notification if their editor takes over, don't trigger any event then
     if ( r && !m_hasEditor)
@@ -1116,7 +1146,7 @@ void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd))
 #if OSX_DEBUG_DRAWING
     CGContextBeginPath( context );
     CGContextMoveToPoint(context, 0, 0);
-    NSRect bounds = [self bounds];
+    NSRect bounds = [slf bounds];
     CGContextAddLineToPoint(context, 10, 0);
     CGContextMoveToPoint(context, 0, 0);
     CGContextAddLineToPoint(context, 0, 10);