fix get-unscaled-client-size docs and Win32/GTK implementations

Fix `get-unscaled-client-size` for Win32 and GTK scaling, and make the
docs more generally sensible.
This commit is contained in:
Matthew Flatt 2015-08-18 14:03:40 -06:00
parent 92842cd195
commit 018dbd6add
4 changed files with 33 additions and 21 deletions

View File

@ -138,6 +138,30 @@ drawing.
}
@defmethod[(get-scaled-client-size) (values dimension-integer? dimension-integer?)]{
Returns the canvas's drawing-area dimensions in unscaled pixels---that
is, without scaling (see @secref["display-resolution"]) that is
implicitly applied to the canvas size and content.
For example, when a canvas on Mac OS X resides on a Retina display, it
has a backing scale of @racket[2], and so the results from
@method[canvas<%> get-scaled-client-size] will be twice as large as results from
@method[window<%> get-client-size]. If the same canvas's frame is dragged to a
non-Retina screen, its backing scale can change to @racket[1], in
which case @method[canvas<%> get-scaled-client-size] and
@method[window<%> get-client-size] will produce the same value. Whether
a canvas's backing scale can change depends on the platform.
The size reported by @method[canvas<%> get-scaled-client-size] may match
a viewport size for OpenGL drawing in @racket[canvas%] instance with
the @racket['gl] style. On Mac OS X, however, the viewport will match
the scaled size unless the canvas is created with a
@racket[gl-config%] specification that is adjusted to high-resolution
mode via @method[gl-config% set-hires-mode].
@history[#:added "1.13"]}
@defmethod*[([(min-client-height)
dimension-integer?]
@ -290,15 +314,4 @@ On Mac OS X, enables or disables space for a resize tab at the
See @racket[canvas<%>] for information on canvas flushing.
Beware that suspending flushing for a canvas can discourage refreshes
for other windows in the same frame on some platforms.}
@defmethod[(get-scaled-client-size) (values dimension-integer? dimension-integer?)]{
Returns the dimensions that the canvas supports drawing to. On Mac OS
X, this may be different than the result returned by
@racket[get-client-size] when the canvas is in "High Resolution" mode and the display is Retina-enabled.}
@history[#:added "1.13"]
}
for other windows in the same frame on some platforms.}}

View File

@ -504,7 +504,7 @@
(define wb (box #f))
(define hb (box #f))
(get-client-size wb hb)
(values (unbox wb) (unbox hb)))
(values (->screen (unbox wb)) (->screen (unbox hb))))
(define/override (get-client-gtk) client-gtk)
(define/override (get-container-gtk) container-gtk)

View File

@ -176,12 +176,6 @@
(and (memq 'control-border style)
(OpenThemeData canvas-hwnd "Edit")))
(define/public (get-scaled-client-size)
(define wb (box #f))
(define hb (box #f))
(get-client-size wb hb)
(values (unbox wb) (unbox hb)))
(define/override (get-content-hwnd)
content-hwnd)

View File

@ -483,9 +483,14 @@
(define/public (on-drop-file p) (void))
(define/public (get-client-size w h)
(define-values (uw uh) (get-scaled-client-size))
(set-box! w (->normal uw))
(set-box! h (->normal uh)))
(define/public (get-scaled-client-size)
(let ([r (GetClientRect (get-client-hwnd))])
(set-box! w (->normal (- (RECT-right r) (RECT-left r))))
(set-box! h (->normal (- (RECT-bottom r) (RECT-top r))))))
(values (- (RECT-right r) (RECT-left r))
(- (RECT-bottom r) (RECT-top r)))))
(define/public (get-size w h)
(let ([r (GetWindowRect (get-client-hwnd))])