From 9c5d68ead5606a0a6e2ff4201152f6b14ed8dcf0 Mon Sep 17 00:00:00 2001 From: Neil Toronto Date: Tue, 22 Nov 2011 14:34:25 -0700 Subject: [PATCH] Plot snips no longer get focus Right-click on plot snips now opens editor pop-up menu --- collects/plot/common/snip.rkt | 23 ++++++++++++- collects/plot/plot2d/snip.rkt | 34 ++++++++------------ collects/plot/plot3d/snip.rkt | 18 +++++------ collects/plot/tests/axis-transform-tests.rkt | 7 +--- 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/collects/plot/common/snip.rkt b/collects/plot/common/snip.rkt index a47bc2a1f8..e0f8d63849 100644 --- a/collects/plot/common/snip.rkt +++ b/collects/plot/common/snip.rkt @@ -80,4 +80,25 @@ ;(send dc draw-bitmap-section bm x y 0 0 width height) (when message (parameterize/group ([plot-parameters saved-plot-parameters]) - (draw-message dc x y)))))) + (draw-message dc x y)))) + + (send this set-flags (list* 'handles-events 'handles-all-mouse-events (send this get-flags))) + + (define/override (on-event dc x y editorx editory evt) + (define editor (send (send this get-admin) get-editor)) + (when (member (send evt get-event-type) '(left-down middle-down right-down)) + ;; The snip has been given caret ownership by now. But we don't want the snip to own the + ;; caret because it'll hog all the mouse move events, keeping the other plot snips from + ;; showing messages when the mouse hovers over them. Besides, a plot snip has no selectable + ;; text or any other reason to own the caret. + ;; This gives ownership to the editor: + (send editor set-caret-owner #f)) + (when (eq? (send evt get-event-type) 'right-down) + ;; The 'handles-events flag keeps the editor from handling the right-click event, meaning the + ;; pop-up menu won't pop up. So we call the "local" event handler, which would have been + ;; called had this snip not trapped events: + (send editor on-local-event evt))) + + (define cross-cursor (make-object cursor% 'cross)) + (define/override (adjust-cursor dc x y editorx editory evt) cross-cursor) + )) diff --git a/collects/plot/plot2d/snip.rkt b/collects/plot/plot2d/snip.rkt index 2adabbfa09..cd904ab196 100644 --- a/collects/plot/plot2d/snip.rkt +++ b/collects/plot/plot2d/snip.rkt @@ -11,6 +11,7 @@ (provide 2d-plot-snip% make-2d-plot-snip) (define zoom-delay 16) ; about 60 fps (just over) +(define show-zoom-message? #t) (define 2d-plot-snip% (class plot-snip% @@ -42,22 +43,19 @@ (define dragging? #f) (define left-down? #f) ; only #t if left-down happened on this snip - (define zoom-timer #f) + (define zoom-timer #f) (define (set-zoom-timer) (when (not zoom-timer) - (set! zoom-timer (make-object timer% (λ () - (set! zoom-timer #f) - (refresh)) + (set! zoom-timer (make-object timer% + (λ () + (set! zoom-timer #f) + (refresh)) zoom-delay #t)))) - (define zoomed? #f) - (define unzoomed? #f) (define (set-click-message) - (cond [(and zoomed? unzoomed?) (void)] - [zoomed? (set-message "Click to unzoom once")] - [unzoomed? (set-message "Click and drag to zoom")] - [else (set-message "Click and drag to zoom\n Click to unzoom once")])) + (when show-zoom-message? + (set-message "Click and drag to zoom\n Click to unzoom once"))) (define (update-plot new-plot-bounds-rect) (define-values (new-bm new-area-bounds-rect new-area-bounds->plot-bounds) @@ -90,14 +88,13 @@ #;(printf "~a: new-plot-bounds-rect = ~v~n" (current-milliseconds) new-rect) (set! plot-bounds-rects (cons plot-bounds-rect plot-bounds-rects)) - (update-plot new-rect) - (set! zoomed? #t)] + (update-plot new-rect)] [else (refresh)])] [(not (empty? plot-bounds-rects)) (define new-rect (first plot-bounds-rects)) (set! plot-bounds-rects (rest plot-bounds-rects)) (update-plot new-rect) - (set! unzoomed? #t)])] + (set! show-zoom-message? #f)])] [(motion) (cond [left-down? ; not event's left-down: only #t if clicked on snip (when (not (and (= left-drag-x mouse-x) (= left-drag-y mouse-y))) @@ -108,7 +105,8 @@ [(and (not (send evt get-left-down)) (<= 0 mouse-x (send (get-bitmap) get-width)) (<= 0 mouse-y (send (get-bitmap) get-height))) - (set-click-message)])])) + (set-click-message)])]) + (super on-event dc x y editorx editory evt)) (define/override (draw dc dc-x-min dc-y-min left top right bottom dx dy draw-caret) ;(printf "~a: drawing~n" (current-milliseconds)) @@ -128,7 +126,7 @@ ;; inside of selection box (send pd set-pen select-color 1 'transparent) (send pd set-brush select-color 'solid) - (send pd set-alpha 1/8) + (send pd set-alpha 1/4) (send pd draw-rect draw-rect) ;; border of selection box @@ -176,11 +174,7 @@ 'center #:outline? #t)) (send pd restore-drawing-params)))) - - (define cross-cursor (make-object cursor% 'cross)) - (define/override (adjust-cursor dc x y editorx editory evt) cross-cursor) - - (send this set-flags (list* 'handles-events 'handles-all-mouse-events (send this get-flags))))) + )) (define (make-2d-plot-snip bm saved-plot-parameters make-plot plot-bounds-rect area-bounds-rect area-bounds->plot-bounds) diff --git a/collects/plot/plot3d/snip.rkt b/collects/plot/plot3d/snip.rkt index 3ba5412397..ab3112207b 100644 --- a/collects/plot/plot3d/snip.rkt +++ b/collects/plot/plot3d/snip.rkt @@ -9,6 +9,7 @@ (provide 3d-plot-snip% make-3d-plot-snip) (define update-delay 16) ; about 60 fps (just over) +(define show-rotate-message? #t) (struct draw-command (animating? angle altitude) #:transparent) @@ -51,8 +52,9 @@ (define draw? #t) (define left-down? #f) ; only #t if left-down happened on this snip - (define update-timer #f) + (define rth (make-render-thread make-bm saved-plot-parameters)) + (define update-timer #f) (define (stop-update-timer) (when update-timer @@ -85,9 +87,8 @@ (number->string (inexact->exact (round altitude)))) #:refresh? #f)) - (define rotated? #f) (define (set-click-message) - (unless rotated? + (when show-rotate-message? (set-message "Click and drag to rotate"))) (define/override (on-event dc x y editorx editory evt) @@ -125,16 +126,13 @@ (set! left-drag-x mouse-x) (set! left-drag-y mouse-y) (set! draw? #t) - (set! rotated? #t))] + (set! show-rotate-message? #f))] [else (and (not (send evt get-left-down)) (<= 0 mouse-x (send (get-bitmap) get-width)) (<= 0 mouse-y (send (get-bitmap) get-height))) - (set-click-message)])])) - - (define cross-cursor (make-object cursor% 'cross)) - (define/override (adjust-cursor dc x y editorx editory evt) cross-cursor) - - (send this set-flags (list* 'handles-events 'handles-all-mouse-events (send this get-flags))))) + (set-click-message)])]) + (super on-event dc x y editorx editory evt)) + )) (define (make-3d-plot-snip bm saved-plot-parameters make-bm angle altitude) (make-object 3d-plot-snip% bm saved-plot-parameters make-bm angle altitude)) diff --git a/collects/plot/tests/axis-transform-tests.rkt b/collects/plot/tests/axis-transform-tests.rkt index dc366b7544..c5ee9a0e35 100644 --- a/collects/plot/tests/axis-transform-tests.rkt +++ b/collects/plot/tests/axis-transform-tests.rkt @@ -1,11 +1,6 @@ #lang racket -(require racket/flonum - plot - plot/utils - plot/common/contract - plot/common/contract-doc - ) +(require plot plot/utils) (x-axis-ticks? #f) (y-axis-ticks? #f)