fix various cocoa problems
This commit is contained in:
parent
2a4ea2ef98
commit
8ed2fba67d
|
@ -33,7 +33,8 @@
|
||||||
(init parent cb label x y w h style font
|
(init parent cb label x y w h style font
|
||||||
[button-type #f])
|
[button-type #f])
|
||||||
(init-field [event-type 'button])
|
(init-field [event-type 'button])
|
||||||
(inherit get-cocoa get-cocoa-window init-font)
|
(inherit get-cocoa get-cocoa-window init-font
|
||||||
|
register-as-child)
|
||||||
|
|
||||||
(define button-cocoa
|
(define button-cocoa
|
||||||
(let ([cocoa
|
(let ([cocoa
|
||||||
|
@ -119,6 +120,9 @@
|
||||||
|
|
||||||
(define/override (get-cocoa-control) button-cocoa)
|
(define/override (get-cocoa-control) button-cocoa)
|
||||||
|
|
||||||
|
(define/override (maybe-register-as-child parent on?)
|
||||||
|
(register-as-child parent on?))
|
||||||
|
|
||||||
(define/override (set-label label)
|
(define/override (set-label label)
|
||||||
(cond
|
(cond
|
||||||
[(string? label)
|
[(string? label)
|
||||||
|
|
|
@ -202,27 +202,37 @@
|
||||||
(tellv cocoa setNeedsDisplay: #:type _BOOL #t))
|
(tellv cocoa setNeedsDisplay: #:type _BOOL #t))
|
||||||
(super focus-is-on on?))
|
(super focus-is-on on?))
|
||||||
|
|
||||||
;; Avoid multiple queued paints:
|
;; Avoid multiple queued paints, and also allow cancel
|
||||||
(define paint-queued? #f)
|
;; of queued paint:
|
||||||
|
(define paint-queued #f) ; #f or (box #t)
|
||||||
|
|
||||||
(define/public (queue-paint)
|
(define/public (queue-paint)
|
||||||
;; can be called from any thread, including the event-pump thread
|
;; can be called from any thread, including the event-pump thread
|
||||||
(unless paint-queued?
|
(unless paint-queued
|
||||||
(set! paint-queued? #t)
|
(let ([b (box #t)])
|
||||||
(let ([req (request-flush-delay (get-cocoa-window))])
|
(set! paint-queued b)
|
||||||
(queue-window-event this (lambda ()
|
(let ([req (request-flush-delay (get-cocoa-window))])
|
||||||
(set! paint-queued? #f)
|
(queue-window-event this (lambda ()
|
||||||
(when (is-shown-to-root?)
|
(do-on-paint req b)))))))
|
||||||
(send dc reset-backing-retained) ; start with a clean slate
|
|
||||||
(let ([bg (get-canvas-background)])
|
(define/private (do-on-paint req b)
|
||||||
(when bg
|
;; only called in the handler thread
|
||||||
(let ([old-bg (send dc get-background)])
|
(when (or (not b) (unbox b))
|
||||||
(send dc set-background bg)
|
(let ([pq paint-queued])
|
||||||
(send dc clear)
|
(when pq (set-box! pq #f)))
|
||||||
(send dc set-background old-bg))))
|
(set! paint-queued #f)
|
||||||
(on-paint)
|
(when (or (not b) (is-shown-to-root?))
|
||||||
(queue-backing-flush)
|
(send dc reset-backing-retained) ; start with a clean slate
|
||||||
(cancel-flush-delay req)))))))
|
(let ([bg (get-canvas-background)])
|
||||||
|
(when bg
|
||||||
|
(let ([old-bg (send dc get-background)])
|
||||||
|
(send dc set-background bg)
|
||||||
|
(send dc clear)
|
||||||
|
(send dc set-background old-bg))))
|
||||||
|
(on-paint)
|
||||||
|
(queue-backing-flush)))
|
||||||
|
(when req
|
||||||
|
(cancel-flush-delay req)))
|
||||||
|
|
||||||
(define/public (paint-or-queue-paint)
|
(define/public (paint-or-queue-paint)
|
||||||
(or (do-backing-flush this dc (tell NSGraphicsContext currentContext)
|
(or (do-backing-flush this dc (tell NSGraphicsContext currentContext)
|
||||||
|
@ -231,6 +241,11 @@
|
||||||
(queue-paint)
|
(queue-paint)
|
||||||
#f)))
|
#f)))
|
||||||
|
|
||||||
|
(define/override (paint-children)
|
||||||
|
(when (or paint-queued
|
||||||
|
(not (send dc can-backing-flush?)))
|
||||||
|
(do-on-paint #f #f)))
|
||||||
|
|
||||||
(define/override (refresh)
|
(define/override (refresh)
|
||||||
;; can be called from any thread, including the event-pump thread
|
;; can be called from any thread, including the event-pump thread
|
||||||
(queue-paint))
|
(queue-paint))
|
||||||
|
@ -283,7 +298,7 @@
|
||||||
|
|
||||||
(define/public (get-dc) dc)
|
(define/public (get-dc) dc)
|
||||||
|
|
||||||
(define/public (fix-dc [refresh? #t])
|
(define/override (fix-dc [refresh? #t])
|
||||||
(when (dc . is-a? . dc%)
|
(when (dc . is-a? . dc%)
|
||||||
(send dc reset-backing-retained)
|
(send dc reset-backing-retained)
|
||||||
(send dc set-auto-scroll
|
(send dc set-auto-scroll
|
||||||
|
@ -608,8 +623,7 @@
|
||||||
|
|
||||||
(define/override (definitely-wants-event? e)
|
(define/override (definitely-wants-event? e)
|
||||||
;; Called in Cocoa event-handling mode
|
;; Called in Cocoa event-handling mode
|
||||||
(when (and is-combo?
|
(when (and (e . is-a? . mouse-event%)
|
||||||
(e . is-a? . mouse-event%)
|
|
||||||
(send e button-down? 'left))
|
(send e button-down? 'left))
|
||||||
(set-focus))
|
(set-focus))
|
||||||
(or (not is-combo?)
|
(or (not is-combo?)
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
(init parent cb label
|
(init parent cb label
|
||||||
x y w h
|
x y w h
|
||||||
choices style font)
|
choices style font)
|
||||||
(inherit get-cocoa init-font)
|
(inherit get-cocoa init-font register-as-child)
|
||||||
|
|
||||||
(super-new [parent parent]
|
(super-new [parent parent]
|
||||||
[cocoa
|
[cocoa
|
||||||
|
@ -68,4 +68,7 @@
|
||||||
(define/public (append lbl)
|
(define/public (append lbl)
|
||||||
(tellv (get-cocoa)
|
(tellv (get-cocoa)
|
||||||
insertItemWithTitle: #:type _NSString lbl
|
insertItemWithTitle: #:type _NSString lbl
|
||||||
atIndex: #:type _NSInteger (number))))
|
atIndex: #:type _NSInteger (number)))
|
||||||
|
|
||||||
|
(define/override (maybe-register-as-child parent on?)
|
||||||
|
(register-as-child parent on?)))
|
||||||
|
|
|
@ -254,11 +254,21 @@
|
||||||
(set-wait-cursor-mode (not (zero? b))))))))
|
(set-wait-cursor-mode (not (zero? b))))))))
|
||||||
|
|
||||||
(define/override (show on?)
|
(define/override (show on?)
|
||||||
(when on?
|
(let ([es (get-eventspace)])
|
||||||
(when (eventspace-shutdown? (get-eventspace))
|
(when on?
|
||||||
(error (string->symbol
|
(when (eventspace-shutdown? es)
|
||||||
(format "show method in ~a" (if is-a-dialog? 'dialog% 'frame%)))
|
(error (string->symbol
|
||||||
"the eventspace hash been shutdown")))
|
(format "show method in ~a" (if is-a-dialog? 'dialog% 'frame%)))
|
||||||
|
"the eventspace hash been shutdown"))
|
||||||
|
(when saved-child
|
||||||
|
(if (eq? (current-thread) (eventspace-handler-thread es))
|
||||||
|
(send saved-child paint-children)
|
||||||
|
(let ([s (make-semaphore)])
|
||||||
|
(queue-callback (lambda ()
|
||||||
|
(when saved-child
|
||||||
|
(send saved-child paint-children))
|
||||||
|
(semaphore-post s)))
|
||||||
|
(sync/timeout 0.2 s))))))
|
||||||
(direct-show on?))
|
(direct-show on?))
|
||||||
|
|
||||||
(define/public (destroy)
|
(define/public (destroy)
|
||||||
|
@ -305,11 +315,13 @@
|
||||||
(lambda () (send wx on-kill-focus)))))
|
(lambda () (send wx on-kill-focus)))))
|
||||||
|
|
||||||
(define/override (is-responder wx on?)
|
(define/override (is-responder wx on?)
|
||||||
(if on?
|
(unless (and (not on?)
|
||||||
(set! first-responder wx)
|
(not (eq? first-responder wx)))
|
||||||
(set! first-responder #f))
|
(if on?
|
||||||
(when is-main?
|
(set! first-responder wx)
|
||||||
(do-notify-responder wx on?)))
|
(set! first-responder #f))
|
||||||
|
(when is-main?
|
||||||
|
(do-notify-responder wx on?))))
|
||||||
|
|
||||||
(define/public (install-wait-cursor)
|
(define/public (install-wait-cursor)
|
||||||
(when (positive? (eventspace-wait-cursor-count (get-eventspace)))
|
(when (positive? (eventspace-wait-cursor-count (get-eventspace)))
|
||||||
|
|
|
@ -59,7 +59,8 @@
|
||||||
label kind x y w h
|
label kind x y w h
|
||||||
choices style
|
choices style
|
||||||
font label-font)
|
font label-font)
|
||||||
(inherit set-size init-font)
|
(inherit set-size init-font
|
||||||
|
register-as-child)
|
||||||
|
|
||||||
(define source (as-objc-allocation
|
(define source (as-objc-allocation
|
||||||
(tell (tell MyDataSource alloc) init)))
|
(tell (tell MyDataSource alloc) init)))
|
||||||
|
@ -194,4 +195,7 @@
|
||||||
|
|
||||||
(define/public (reset)
|
(define/public (reset)
|
||||||
(tellv content-cocoa noteNumberOfRowsChanged)
|
(tellv content-cocoa noteNumberOfRowsChanged)
|
||||||
(tellv content-cocoa reloadData)))
|
(tellv content-cocoa reloadData))
|
||||||
|
|
||||||
|
(define/override (maybe-register-as-child parent on?)
|
||||||
|
(register-as-child parent on?)))
|
||||||
|
|
|
@ -32,11 +32,11 @@
|
||||||
"NSApplicationPath")))
|
"NSApplicationPath")))
|
||||||
|
|
||||||
(define-objc-class MyTextField NSTextField
|
(define-objc-class MyTextField NSTextField
|
||||||
#:mixins (FocusResponder KeyMouseResponder CursorDisplayer)
|
#:mixins (KeyMouseResponder CursorDisplayer)
|
||||||
[wxb])
|
[wxb])
|
||||||
|
|
||||||
(define-objc-class MyImageView NSImageView
|
(define-objc-class MyImageView NSImageView
|
||||||
#:mixins (FocusResponder KeyMouseResponder CursorDisplayer)
|
#:mixins (KeyMouseResponder CursorDisplayer)
|
||||||
[wxb])
|
[wxb])
|
||||||
|
|
||||||
(defclass message% item%
|
(defclass message% item%
|
||||||
|
|
|
@ -30,9 +30,17 @@
|
||||||
(define/public (get-label-position) lbl-pos)
|
(define/public (get-label-position) lbl-pos)
|
||||||
(define/public (set-label-position pos) (set! lbl-pos pos))
|
(define/public (set-label-position pos) (set! lbl-pos pos))
|
||||||
|
|
||||||
(define/public (fix-dc)
|
(define/override (fix-dc)
|
||||||
(for ([child (in-list children)])
|
(for ([child (in-list children)])
|
||||||
(send child fix-dc)))
|
(send child fix-dc)))
|
||||||
|
|
||||||
|
(define/override (hide-children)
|
||||||
|
(for ([child (in-list children)])
|
||||||
|
(send child hide-children)))
|
||||||
|
|
||||||
|
(define/override (paint-children)
|
||||||
|
(for ([child (in-list children)])
|
||||||
|
(send child paint-children)))
|
||||||
|
|
||||||
(define/override (set-size x y w h)
|
(define/override (set-size x y w h)
|
||||||
(super set-size x y w h)
|
(super set-size x y w h)
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
val
|
val
|
||||||
style
|
style
|
||||||
font)
|
font)
|
||||||
(inherit get-cocoa set-focus init-font)
|
(inherit get-cocoa set-focus init-font register-as-child)
|
||||||
|
|
||||||
(define horiz? (and (memq 'horizontal style) #t))
|
(define horiz? (and (memq 'horizontal style) #t))
|
||||||
|
|
||||||
|
@ -136,4 +136,7 @@
|
||||||
(if horiz?
|
(if horiz?
|
||||||
(tell #:type _NSInteger (get-cocoa) selectedColumn)
|
(tell #:type _NSInteger (get-cocoa) selectedColumn)
|
||||||
(tell #:type _NSInteger (get-cocoa) selectedRow)))
|
(tell #:type _NSInteger (get-cocoa) selectedRow)))
|
||||||
(define/public (number) count))
|
(define/public (number) count)
|
||||||
|
|
||||||
|
(define/override (maybe-register-as-child parent on?)
|
||||||
|
(register-as-child parent on?)))
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
x y w
|
x y w
|
||||||
style
|
style
|
||||||
font)
|
font)
|
||||||
(inherit get-cocoa)
|
(inherit get-cocoa register-as-child)
|
||||||
|
|
||||||
(super-new [parent parent]
|
(super-new [parent parent]
|
||||||
[cocoa (let ([cocoa (as-objc-allocation
|
[cocoa (let ([cocoa (as-objc-allocation
|
||||||
|
@ -76,5 +76,8 @@
|
||||||
(define/public (set-value v)
|
(define/public (set-value v)
|
||||||
(tellv cocoa setDoubleValue: #:type _double* v))
|
(tellv cocoa setDoubleValue: #:type _double* v))
|
||||||
(define/public (get-value)
|
(define/public (get-value)
|
||||||
(inexact->exact (floor (tell #:type _double cocoa doubleValue)))))
|
(inexact->exact (floor (tell #:type _double cocoa doubleValue))))
|
||||||
|
|
||||||
|
(define/override (maybe-register-as-child parent on?)
|
||||||
|
(register-as-child parent on?)))
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
x y w h
|
x y w h
|
||||||
style
|
style
|
||||||
labels)
|
labels)
|
||||||
(inherit get-cocoa)
|
(inherit get-cocoa register-as-child)
|
||||||
|
|
||||||
(define tabv-cocoa (as-objc-allocation
|
(define tabv-cocoa (as-objc-allocation
|
||||||
(tell (tell MyTabView alloc) init)))
|
(tell (tell MyTabView alloc) init)))
|
||||||
|
@ -147,4 +147,8 @@
|
||||||
[no-show? (memq 'deleted style)])
|
[no-show? (memq 'deleted style)])
|
||||||
|
|
||||||
(when control-cocoa
|
(when control-cocoa
|
||||||
(set-ivar! control-cocoa wxb (->wxb this))))
|
(set-ivar! control-cocoa wxb (->wxb this)))
|
||||||
|
|
||||||
|
(define/override (maybe-register-as-child parent on?)
|
||||||
|
(register-as-child parent on?)))
|
||||||
|
|
||||||
|
|
|
@ -287,9 +287,21 @@
|
||||||
|
|
||||||
(define/public (focus-is-on on?)
|
(define/public (focus-is-on on?)
|
||||||
(void))
|
(void))
|
||||||
|
|
||||||
|
(define is-responder? #f)
|
||||||
|
|
||||||
(define/public (is-responder wx on?)
|
(define/public (is-responder wx on?)
|
||||||
(send parent is-responder wx on?))
|
(unless (eq? on? is-responder?)
|
||||||
|
(set! is-responder? (and on? #t))
|
||||||
|
(send parent is-responder wx on?)))
|
||||||
|
|
||||||
|
(define/public (hide-children)
|
||||||
|
(is-responder this #f)
|
||||||
|
(focus-is-on #f))
|
||||||
|
(define/public (fix-dc)
|
||||||
|
(void))
|
||||||
|
(define/public (paint-children)
|
||||||
|
(void))
|
||||||
|
|
||||||
(define/public (get-cocoa) cocoa)
|
(define/public (get-cocoa) cocoa)
|
||||||
(define/public (get-cocoa-content) cocoa)
|
(define/public (get-cocoa-content) cocoa)
|
||||||
|
@ -321,9 +333,11 @@
|
||||||
(set! is-on? (and on? #t))))
|
(set! is-on? (and on? #t))))
|
||||||
(maybe-register-as-child parent on?)
|
(maybe-register-as-child parent on?)
|
||||||
(unless on?
|
(unless on?
|
||||||
(focus-is-on #f)
|
(hide-children)
|
||||||
(is-responder this #f)))
|
(is-responder this #f)))
|
||||||
(define/public (maybe-register-as-child parent on?)
|
(define/public (maybe-register-as-child parent on?)
|
||||||
|
;; override this to call register-as-child if the window
|
||||||
|
;; can have the focus or otherwise needs show-state notifications.
|
||||||
(void))
|
(void))
|
||||||
(define/public (register-as-child parent on?)
|
(define/public (register-as-child parent on?)
|
||||||
(send parent register-child this on?))
|
(send parent register-child this on?))
|
||||||
|
@ -538,12 +552,9 @@
|
||||||
(when wx
|
(when wx
|
||||||
(queue-event (send wx get-eventspace) (lambda () (proc wx))))))
|
(queue-event (send wx get-eventspace) (lambda () (proc wx))))))
|
||||||
|
|
||||||
(define depth 0)
|
|
||||||
|
|
||||||
(define (request-flush-delay cocoa-win)
|
(define (request-flush-delay cocoa-win)
|
||||||
(atomically
|
(atomically
|
||||||
(let ([req (box cocoa-win)])
|
(let ([req (box cocoa-win)])
|
||||||
(set! depth (add1 depth))
|
|
||||||
(tellv cocoa-win disableFlushWindow)
|
(tellv cocoa-win disableFlushWindow)
|
||||||
(add-event-boundary-sometimes-callback!
|
(add-event-boundary-sometimes-callback!
|
||||||
req
|
req
|
||||||
|
@ -551,9 +562,8 @@
|
||||||
;; in atomic mode
|
;; in atomic mode
|
||||||
(when (unbox req)
|
(when (unbox req)
|
||||||
(set-box! req #f)
|
(set-box! req #f)
|
||||||
(set! depth (sub1 depth))
|
|
||||||
(tellv cocoa-win enableFlushWindow)
|
(tellv cocoa-win enableFlushWindow)
|
||||||
(tellv cocoa-win flushWindow))))
|
(tellv cocoa-win flushWindowIfNeeded))))
|
||||||
req)))
|
req)))
|
||||||
|
|
||||||
(define (cancel-flush-delay req)
|
(define (cancel-flush-delay req)
|
||||||
|
@ -561,8 +571,11 @@
|
||||||
(let ([cocoa-win (unbox req)])
|
(let ([cocoa-win (unbox req)])
|
||||||
(when cocoa-win
|
(when cocoa-win
|
||||||
(set-box! req #f)
|
(set-box! req #f)
|
||||||
(set! depth (sub1 depth))
|
|
||||||
(tellv cocoa-win enableFlushWindow)
|
(tellv cocoa-win enableFlushWindow)
|
||||||
|
(add-event-boundary-sometimes-callback!
|
||||||
|
cocoa-win
|
||||||
|
(lambda (v)
|
||||||
|
(tellv cocoa-win flushWindowIfNeeded)))
|
||||||
(remove-event-boundary-callback! req)))))
|
(remove-event-boundary-callback! req)))))
|
||||||
|
|
||||||
(define (make-init-point x y)
|
(define (make-init-point x y)
|
||||||
|
|
|
@ -62,6 +62,9 @@
|
||||||
[else
|
[else
|
||||||
(reset-backing-retained proc)
|
(reset-backing-retained proc)
|
||||||
#t]))
|
#t]))
|
||||||
|
|
||||||
|
(define/public (can-backing-flush?)
|
||||||
|
(and retained-cr #t))
|
||||||
|
|
||||||
(define/public (reset-backing-retained [proc void])
|
(define/public (reset-backing-retained [proc void])
|
||||||
(let ([cr retained-cr])
|
(let ([cr retained-cr])
|
||||||
|
|
|
@ -1840,9 +1840,6 @@
|
||||||
(send dc set-font font)
|
(send dc set-font font)
|
||||||
(let-values ([(w h) (get-client-size)]
|
(let-values ([(w h) (get-client-size)]
|
||||||
[(tw th ta td) (send dc get-text-extent message)])
|
[(tw th ta td) (send dc get-text-extent message)])
|
||||||
(send dc set-pen (send the-pen-list find-or-create-pen (get-panel-background) 1 'transparent))
|
|
||||||
(send dc set-brush (send the-brush-list find-or-create-brush (get-panel-background) 'panel))
|
|
||||||
(send dc draw-rectangle 0 0 w h)
|
|
||||||
(send dc draw-text message
|
(send dc draw-text message
|
||||||
(- (/ w 2) (/ tw 2))
|
(- (/ w 2) (/ tw 2))
|
||||||
(- (/ h 2) (/ th 2))
|
(- (/ h 2) (/ th 2))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user