From 44d59702c0b22624f8e0043ccf1c5e4f90ed9c4b Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 15 Apr 2013 16:37:08 -0600 Subject: [PATCH] racket/gui cocoa: fix `list-box%' visble-cell calculations There were especially problems with header columns, but also intercell spacing was not taken into account. Merge to v5.3.4 --- collects/mred/private/wx/cocoa/list-box.rkt | 25 ++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/collects/mred/private/wx/cocoa/list-box.rkt b/collects/mred/private/wx/cocoa/list-box.rkt index 919b12fc0c..778e030778 100644 --- a/collects/mred/private/wx/cocoa/list-box.rkt +++ b/collects/mred/private/wx/cocoa/list-box.rkt @@ -191,13 +191,32 @@ [else (cons i (loop (tell #:type _NSInteger v indexGreaterThanIndex: #:type _NSInteger i)))]))))))) + (define/private (header-height) + (let ([hv (tell content-cocoa headerView)]) + (if hv + (NSSize-height (NSRect-size (tell #:type _NSRect hv frame))) + 0))) + (define/public (number-of-visible-items) (define doc (tell #:type _NSRect cocoa documentVisibleRect)) - (define h (tell #:type _CGFloat content-cocoa rowHeight)) - (max 1 (inexact->exact (floor (/ (NSSize-height (NSRect-size doc)) h))))) + (define h (+ (tell #:type _CGFloat content-cocoa rowHeight) + (NSSize-height (tell #:type _NSSize content-cocoa intercellSpacing)))) + (define doc-h (- (NSSize-height (NSRect-size doc)) + (header-height))) + (define n (floor (/ doc-h h))) + (if (rational? n) + (max 1 (inexact->exact n)) + 1)) (define/public (get-first-item) (define doc (tell #:type _NSRect cocoa documentVisibleRect)) - (NSRange-location (tell #:type _NSRange content-cocoa rowsInRect: #:type _NSRect doc))) + (define h (header-height)) + (NSRange-location (tell #:type _NSRange content-cocoa + rowsInRect: #:type _NSRect + (if (zero? h) + doc + (make-NSRect (NSRect-origin doc) + (make-NSSize (NSSize-width (NSRect-size doc)) + (- (NSSize-height (NSRect-size doc)) h))))))) (define/public (set-first-visible-item i) (define num-vis (number-of-visible-items))