cocoa: avoid 10.6-specific method for menu popup

This commit is contained in:
Matthew Flatt 2010-11-10 16:47:09 -07:00
parent 6efc3c5550
commit b6b3298567
3 changed files with 31 additions and 8 deletions

View File

@ -5,15 +5,17 @@
(only-in scheme/list drop take) (only-in scheme/list drop take)
"../common/event.rkt" "../common/event.rkt"
"../../syntax.rkt" "../../syntax.rkt"
"../../lock.rkt"
"utils.rkt" "utils.rkt"
"types.rkt" "types.rkt"
"const.rkt"
"window.rkt" "window.rkt"
"menu-item.rkt") "menu-item.rkt")
(provide (provide
(protect-out menu%)) (protect-out menu%))
(import-class NSMenu NSMenuItem) (import-class NSMenu NSMenuItem NSEvent)
(define-struct mitem (item checkable?)) (define-struct mitem (item checkable?))
@ -56,15 +58,36 @@
(define popup-box #f) (define popup-box #f)
(define/public (do-popup v x y queue-cb) (define/public (do-popup v win x y queue-cb)
(unless (null? items) (unless (null? items)
(create-menu "menu") (create-menu "menu")
(let ([b (box #f)]) (let ([b (box #f)])
(set! popup-box b) (set! popup-box b)
(tellv cocoa-menu (if #t ;; use the 10.5 code, for now
popUpMenuPositioningItem: (tell cocoa-menu itemAtIndex: #:type _NSUInteger 0) ;; For 10.5 and earlier:
atLocation: #:type _NSPoint (make-NSPoint x y) (let ([p (tell #:type _NSPoint v
inView: v) convertPoint: #:type _NSPoint (make-NSPoint x y)
toView: #f)])
(atomically
(with-autorelease
(tellv NSMenu popUpContextMenu: cocoa-menu
withEvent: (tell NSEvent
mouseEventWithType: #:type _int NSLeftMouseDown
location: #:type _NSPoint p
modifierFlags: #:type _NSUInteger 0
timestamp: #:type _double 0.0
windowNumber: #:type _NSUInteger
(tell #:type _NSInteger win windowNumber)
context: #:type _pointer #f
eventNumber: #:type _NSInteger 0
clickCount: #:type _NSInteger 1
pressure: #:type _float 1.0)
forView: v))))
;; 10.6 and later:
(tellv cocoa-menu
popUpMenuPositioningItem: (tell cocoa-menu itemAtIndex: #:type _NSUInteger 0)
atLocation: #:type _NSPoint (make-NSPoint x y)
inView: v))
(set! popup-box #f) (set! popup-box #f)
(let* ([i (unbox b)] (let* ([i (unbox b)]
[e (new popup-event% [event-type 'menu-popdown])]) [e (new popup-event% [event-type 'menu-popdown])])

View File

@ -103,7 +103,7 @@
(define wake-evt (define wake-evt
(tell NSEvent (tell NSEvent
otherEventWithType: #:type _int NSApplicationDefined otherEventWithType: #:type _int NSApplicationDefined
location: #:type _NSPoint-pointer (make-NSPoint 0.0 0.0) location: #:type _NSPoint (make-NSPoint 0.0 0.0)
modifierFlags: #:type _NSUInteger 0 modifierFlags: #:type _NSUInteger 0
timestamp: #:type _double 0.0 timestamp: #:type _double 0.0
windowNumber: #:type _NSUInteger 0 windowNumber: #:type _NSUInteger 0

View File

@ -650,7 +650,7 @@
(define/public (get-handle) (get-cocoa)) (define/public (get-handle) (get-cocoa))
(define/public (popup-menu m x y) (define/public (popup-menu m x y)
(send m do-popup (get-cocoa-content) x (flip-client y) (send m do-popup (get-cocoa-content) (get-cocoa-window) x (flip-client y)
(lambda (thunk) (lambda (thunk)
(queue-window-event this thunk)))) (queue-window-event this thunk))))