From 14a72b5a083da74b42bf5a7d54ae16a05d34e325 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 24 Nov 2010 07:12:02 -0700 Subject: [PATCH] cocoa: fix problems with frame-list management --- collects/mred/private/wx/cocoa/frame.rkt | 17 ++++++++++++----- collects/mred/private/wx/cocoa/printer-dc.rkt | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/collects/mred/private/wx/cocoa/frame.rkt b/collects/mred/private/wx/cocoa/frame.rkt index 3956ed8f68..b9570d2508 100644 --- a/collects/mred/private/wx/cocoa/frame.rkt +++ b/collects/mred/private/wx/cocoa/frame.rkt @@ -36,6 +36,9 @@ (define empty-mb (new menu-bar%)) (define root-fake-frame #f) +;; Maps window numbers to weak boxes of frame objects; +;; the weak-box layer is needed to avoid GC-accounting +;; problems. (define all-windows (make-hash)) (define-objc-mixin (MyWindowMethods Superclass) @@ -278,12 +281,12 @@ (register-frame-shown this on?) (let ([num (tell #:type _NSInteger cocoa windowNumber)]) (if on? - (hash-set! all-windows num this) + (hash-set! all-windows num (make-weak-box this)) (hash-remove! all-windows num))) (when on? (let ([b (eventspace-wait-cursor-count (get-eventspace))]) (set-wait-cursor-mode (not (zero? b)))))) - + (define/override (show on?) (let ([es (get-eventspace)]) (when on? @@ -534,9 +537,13 @@ (let ([f (tell #:type _NSRect (tell NSScreen mainScreen) frame)]) (make-NSPoint x (- (NSSize-height (NSRect-size f)) y))) belowWindowWithWindowNumber: #:type _NSInteger 0)]) - (atomically (hash-ref all-windows n #f)))) + (atomically (let ([b (hash-ref all-windows n #f)]) + (and b (weak-box-value b)))))) (set-fixup-window-locations! (lambda () - (for ([f (in-hash-values all-windows)]) - (send f fixup-locations-children)))) + ;; in atomic mode + (for ([b (in-hash-values all-windows)]) + (let ([f (weak-box-value b)]) + (send f fixup-locations-children))))) + diff --git a/collects/mred/private/wx/cocoa/printer-dc.rkt b/collects/mred/private/wx/cocoa/printer-dc.rkt index c1224ed17c..580ad92e1d 100644 --- a/collects/mred/private/wx/cocoa/printer-dc.rkt +++ b/collects/mred/private/wx/cocoa/printer-dc.rkt @@ -12,6 +12,7 @@ ffi/unsafe/objc "../../lock.rkt" "dc.rkt" + "frame.rkt" "bitmap.rkt" "cg.rkt" "utils.rkt" @@ -101,8 +102,13 @@ (send pss set-native pi make-print-info) pi)))]) (install-pss-to-print-info pss print-info) - (if (= (tell #:type _NSInteger (tell NSPageLayout pageLayout) runModalWithPrintInfo: print-info) - NSOkButton) + (if (atomically + (let ([front (get-front)]) + (begin0 + (= (tell #:type _NSInteger (tell NSPageLayout pageLayout) runModalWithPrintInfo: print-info) + NSOkButton) + (when front + (tellv (send front get-cocoa-window) makeKeyAndOrderFront: #f))))) (begin (let ([o (tell #:type _int print-info orientation)]) (send pss set-orientation (if (= o NSLandscapeOrientation) @@ -195,4 +201,8 @@ (set-ivar! view-cocoa wxb (->wxb this)) - (tellv op-cocoa runOperation)))) + (atomically + (let ([front (get-front)]) + (tellv op-cocoa runOperation) + (when front + (tellv (send front get-cocoa-window) makeKeyAndOrderFront: #f)))))))