racket/gui: fix access of scrollbar values for canvas without a scrollbar

original commit: 1800680c6ba0dec0f8b2f7d0495c615906b27b47
This commit is contained in:
Matthew Flatt 2012-08-12 19:08:17 -06:00
parent 7dde3f4f90
commit 0e2b88e51a
5 changed files with 58 additions and 18 deletions

View File

@ -233,7 +233,8 @@
get-size get-position get-size get-position
set-focus set-focus
client-to-screen client-to-screen
is-auto-scroll? get-virtual-width get-virtual-height is-auto-scroll? is-disabled-scroll?
get-virtual-width get-virtual-height
reset-auto-scroll reset-auto-scroll
refresh-for-autoscroll refresh-for-autoscroll
refresh-all-children refresh-all-children
@ -521,25 +522,32 @@
(define/public (set-scroll-pos which v) (define/public (set-scroll-pos which v)
(update which scroll-pos v)) (update which scroll-pos v))
(define/private (guard-scroll skip-guard? which v) (define/private (guard-scroll skip-guard? which get-v)
(if skip-guard? (if skip-guard?
v (get-v)
(if (is-auto-scroll?) (if (or (if (eq? which 'vertical)
(not vscroll-ok?)
(not hscroll-ok?))
(is-disabled-scroll?)
(is-auto-scroll?))
0 0
v))) (get-v))))
(define/public (get-scroll-page which [skip-guard? #f]) (define/public (get-scroll-page which [skip-guard? #f])
(guard-scroll skip-guard? (guard-scroll skip-guard?
which which
(scroll-page (if (eq? which 'vertical) v-scroller h-scroller)))) (lambda ()
(scroll-page (if (eq? which 'vertical) v-scroller h-scroller)))))
(define/public (get-scroll-range which [skip-guard? #f]) (define/public (get-scroll-range which [skip-guard? #f])
(guard-scroll skip-guard? (guard-scroll skip-guard?
which which
(scroll-range (if (eq? which 'vertical) v-scroller h-scroller)))) (lambda ()
(scroll-range (if (eq? which 'vertical) v-scroller h-scroller)))))
(define/public (get-scroll-pos which [skip-guard? #f]) (define/public (get-scroll-pos which [skip-guard? #f])
(guard-scroll skip-guard? (guard-scroll skip-guard?
which which
(scroll-pos (if (eq? which 'vertical) v-scroller h-scroller)))) (lambda ()
(scroll-pos (if (eq? which 'vertical) v-scroller h-scroller)))))
(define v-scroller (define v-scroller
(and vscroll-ok? (and vscroll-ok?

View File

@ -18,11 +18,13 @@
(inherit get-client-size (inherit get-client-size
refresh) refresh)
(define any-scroll? #f)
(define auto-scroll? #f) (define auto-scroll? #f)
(define virtual-height #f) (define virtual-height #f)
(define virtual-width #f) (define virtual-width #f)
(define/public (is-auto-scroll?) auto-scroll?) (define/public (is-auto-scroll?) auto-scroll?)
(define/public (is-disabled-scroll?) (not any-scroll?))
(define/public (get-virtual-height) virtual-height) (define/public (get-virtual-height) virtual-height)
(define/public (get-virtual-width) virtual-width) (define/public (get-virtual-width) virtual-width)
@ -31,6 +33,7 @@
h-page v-page h-page v-page
h-pos v-pos h-pos v-pos
auto?) auto?)
(set! any-scroll? #t)
(cond (cond
[auto? [auto?
(set! auto-scroll? #t) (set! auto-scroll? #t)

View File

@ -239,7 +239,8 @@
get-top-win get-top-win
set-auto-size set-auto-size
adjust-client-delta infer-client-delta adjust-client-delta infer-client-delta
is-auto-scroll? get-virtual-width get-virtual-height is-auto-scroll? is-disabled-scroll?
get-virtual-width get-virtual-height
refresh-for-autoscroll refresh-all-children refresh-for-autoscroll refresh-all-children
get-eventspace) get-eventspace)
@ -609,19 +610,25 @@
(lambda () (lambda ()
(gtk_adjustment_set_value adj v)))))) (gtk_adjustment_set_value adj v))))))
(define/private (is-disabled-scroll-dir? which)
(or (if (eq? which 'vertical)
(not vscroll-gtk)
(not hscroll-gtk))
(is-disabled-scroll?)))
(define/public (get-scroll-page which) (define/public (get-scroll-page which)
(if (is-auto-scroll?) (if (or (is-disabled-scroll-dir? which) (is-auto-scroll?))
0 0
(->long (dispatch which gtk_adjustment_get_page_size 0)))) (->long (dispatch which gtk_adjustment_get_page_size 0))))
(define/public (get-scroll-range which) (define/public (get-scroll-range which)
(if (is-auto-scroll?) (if (or (is-disabled-scroll-dir? which) (is-auto-scroll?))
0 0
(->long (dispatch which (lambda (adj) (->long (dispatch which (lambda (adj)
(- (gtk_adjustment_get_upper adj) (- (gtk_adjustment_get_upper adj)
(gtk_adjustment_get_page_size adj))) (gtk_adjustment_get_page_size adj)))
0)))) 0))))
(define/public (get-scroll-pos which) (define/public (get-scroll-pos which)
(if (is-auto-scroll?) (if (or (is-disabled-scroll-dir? which) (is-auto-scroll?))
0 0
(->long (dispatch which gtk_adjustment_get_value 0)))) (->long (dispatch which gtk_adjustment_get_value 0))))

View File

@ -70,7 +70,7 @@
SIF_PAGE SIF_TRACKPOS) SIF_PAGE SIF_TRACKPOS)
0 0 0 0 0)) 0 0 0 0 0))
-> (r : _BOOL) -> (r : _BOOL)
-> (if r i (error 'GetScrollInfo "failed")))) -> (if r i (failed 'GetScrollInfo))))
(define COMBO-WIDTH 18) (define COMBO-WIDTH 18)
@ -87,7 +87,8 @@
get-client-size get-client-size
get-eventspace get-eventspace
set-control-font set-control-font
is-auto-scroll? get-virtual-width get-virtual-height is-auto-scroll? is-disabled-scroll?
get-virtual-width get-virtual-height
reset-auto-scroll reset-auto-scroll
refresh-for-autoscroll) refresh-for-autoscroll)
@ -416,12 +417,18 @@
(define/override (get-virtual-v-pos) (define/override (get-virtual-v-pos)
(GetScrollPos canvas-hwnd SB_VERT)) (GetScrollPos canvas-hwnd SB_VERT))
(define/private (is-disabled-scroll-dir? which)
(or (if (eq? which 'vertical)
(not vscroll?)
(not hscroll?))
(is-disabled-scroll?)))
(define/public (get-scroll-pos which) (define/public (get-scroll-pos which)
(if (is-auto-scroll?) (if (or (is-disabled-scroll-dir? which) (is-auto-scroll?))
0 0
(GetScrollPos canvas-hwnd (if (eq? which 'vertical) SB_VERT SB_HORZ)))) (GetScrollPos canvas-hwnd (if (eq? which 'vertical) SB_VERT SB_HORZ))))
(define/public (get-scroll-range which) (define/public (get-scroll-range which)
(if (is-auto-scroll?) (if (or (is-disabled-scroll-dir? which) (is-auto-scroll?))
0 0
(get-real-scroll-range which))) (get-real-scroll-range which)))
(define/public (get-real-scroll-range which) (define/public (get-real-scroll-range which)
@ -430,7 +437,7 @@
(SCROLLINFO-nPage i)) (SCROLLINFO-nPage i))
1))) 1)))
(define/public (get-scroll-page which) (define/public (get-scroll-page which)
(if (is-auto-scroll?) (if (or (is-disabled-scroll-dir? which) (is-auto-scroll?))
0 0
(let ([i (GetScrollInfo canvas-hwnd (if (eq? which 'vertical) SB_VERT SB_HORZ))]) (let ([i (GetScrollInfo canvas-hwnd (if (eq? which 'vertical) SB_VERT SB_HORZ))])
(SCROLLINFO-nPage i)))) (SCROLLINFO-nPage i))))

View File

@ -909,6 +909,19 @@
(send parent delete-child t) (send parent delete-child t)
(loop (cdr styles))))) (loop (cdr styles)))))
(define (check-canvas-no-scroll c)
(st 0 c get-scroll-range 'vertical)
(st 0 c get-scroll-range 'horizontal)
(st 0 c get-scroll-page 'vertical)
(st 0 c get-scroll-page 'horizontal)
(st 0 c get-scroll-pos 'vertical)
(st 0 c get-scroll-pos 'horizontal))
(let ([c (make-object canvas% parent '())])
(check-canvas-no-scroll c)
(stv c init-manual-scrollbars 5 6 2 3 4 5)
(check-canvas-no-scroll c))
(let ([c (make-object canvas% parent '(hscroll vscroll))]) (let ([c (make-object canvas% parent '(hscroll vscroll))])
(printf "Tab Focus\n") (printf "Tab Focus\n")
@ -918,6 +931,8 @@
(stv c accept-tab-focus #f) (stv c accept-tab-focus #f)
(st #f c accept-tab-focus) (st #f c accept-tab-focus)
(check-canvas-no-scroll c)
(stv c init-auto-scrollbars 500 606 .02 .033) (stv c init-auto-scrollbars 500 606 .02 .033)
; (stv c set-scrollbars 100 101 5 6 2 3 10 20 #t) ; (stv c set-scrollbars 100 101 5 6 2 3 10 20 #t)
(let-values ([(w h) (send c get-virtual-size)] (let-values ([(w h) (send c get-virtual-size)]