clean up handling of not-ok?', bitmap-dc%'-selected, and mutated bitmaps

original commit: eddae6749d698d2ec039fe1d3fc8b6cfe1a70e39
This commit is contained in:
Matthew Flatt 2010-12-30 08:35:56 -07:00
parent 0e0139ebb4
commit d83ad03114
13 changed files with 26 additions and 58 deletions

View File

@ -54,12 +54,10 @@
(cond (cond
[(string? label) [(string? label)
(tellv cocoa setTitleWithMnemonic: #:type _NSString label)] (tellv cocoa setTitleWithMnemonic: #:type _NSString label)]
[(send label ok?) [else
(if button-type (if button-type
(tellv cocoa setTitle: #:type _NSString "") (tellv cocoa setTitle: #:type _NSString "")
(tellv cocoa setImage: (bitmap->image label)))] (tellv cocoa setImage: (bitmap->image label)))])
[else
(tellv cocoa setTitle: #:type _NSString "<bad>")])
(init-font cocoa font) (init-font cocoa font)
(tellv cocoa sizeToFit) (tellv cocoa sizeToFit)
(when (and (eq? event-type 'button) (when (and (eq? event-type 'button)
@ -89,8 +87,7 @@
(define-values (cocoa image-cocoa) (define-values (cocoa image-cocoa)
(if (and button-type (if (and button-type
(not (string? label)) (not (string? label)))
(send label ok?))
;; Check-box image: need an view to join a button and an image view: ;; Check-box image: need an view to join a button and an image view:
;; (Could we use the NSImageButtonCell from the radio-box implementation ;; (Could we use the NSImageButtonCell from the radio-box implementation
;; instead?) ;; instead?)

View File

@ -80,8 +80,7 @@
[cocoa (let* ([label (cond [cocoa (let* ([label (cond
[(string? label) label] [(string? label) label]
[(symbol? label) (get-icon label)] [(symbol? label) (get-icon label)]
[(send label ok?) label] [else label])]
[else "<bad>"])]
[cocoa [cocoa
(if (string? label) (if (string? label)
(as-objc-allocation (as-objc-allocation

View File

@ -85,8 +85,7 @@
(let ([button (tell cocoa (let ([button (tell cocoa
cellAtRow: #:type _NSInteger (if horiz? 0 i) cellAtRow: #:type _NSInteger (if horiz? 0 i)
column: #:type _NSInteger (if horiz? i 0))]) column: #:type _NSInteger (if horiz? i 0))])
(if (and (not (string? label)) (if (not (string? label))
(send label ok?))
(begin (begin
(tellv button setTitle: #:type _NSString "") (tellv button setTitle: #:type _NSString "")
(set-ivar! button img (bitmap->image label))) (set-ivar! button img (bitmap->image label)))

View File

@ -46,7 +46,7 @@
[(or (string? label) (not label)) [(or (string? label) (not label))
(as-gtk-allocation (as-gtk-allocation
(gtk_new_with_mnemonic (or (mnemonic-string label) "")))] (gtk_new_with_mnemonic (or (mnemonic-string label) "")))]
[(send label ok?) [else
(let ([pixbuf (bitmap->pixbuf label)]) (let ([pixbuf (bitmap->pixbuf label)])
(atomically (atomically
(let ([gtk (as-gtk-allocation (gtk_new))] (let ([gtk (as-gtk-allocation (gtk_new))]
@ -54,9 +54,7 @@
(release-pixbuf pixbuf) (release-pixbuf pixbuf)
(gtk_container_add gtk image-gtk) (gtk_container_add gtk image-gtk)
(gtk_widget_show image-gtk) (gtk_widget_show image-gtk)
gtk)))] gtk)))])]
[else
(as-gtk-allocation (gtk_new_with_mnemonic "<bad>"))])]
[callback cb] [callback cb]
[font font] [font font]
[no-show? (memq 'deleted style)]) [no-show? (memq 'deleted style)])

View File

@ -60,14 +60,11 @@
[(caution) (gtk_image_new_from_stock "gtk-dialog-warning" icon-size)] [(caution) (gtk_image_new_from_stock "gtk-dialog-warning" icon-size)]
[(stop) (gtk_image_new_from_stock "gtk-dialog-error" icon-size)] [(stop) (gtk_image_new_from_stock "gtk-dialog-error" icon-size)]
[else (gtk_image_new_from_stock "gtk-dialog-question" icon-size)])) [else (gtk_image_new_from_stock "gtk-dialog-question" icon-size)]))
(if (send label ok?) (let ([pixbuf (bitmap->pixbuf label)])
(let ([pixbuf (bitmap->pixbuf label)]) (begin0
(begin0 (as-gtk-allocation
(as-gtk-allocation (gtk_image_new_from_pixbuf pixbuf))
(gtk_image_new_from_pixbuf pixbuf)) (release-pixbuf pixbuf)))))]
(release-pixbuf pixbuf)))
(as-gtk-allocation
(gtk_label_new_with_mnemonic "<bad-image>")))))]
[font font] [font font]
[no-show? (memq 'deleted style)]) [no-show? (memq 'deleted style)])

View File

@ -54,16 +54,14 @@
(let ([radio-gtk (cond (let ([radio-gtk (cond
[(string? lbl) [(string? lbl)
(gtk_radio_button_new_with_mnemonic #f (mnemonic-string lbl))] (gtk_radio_button_new_with_mnemonic #f (mnemonic-string lbl))]
[(send lbl ok?) [else
(let ([pixbuf (bitmap->pixbuf lbl)]) (let ([pixbuf (bitmap->pixbuf lbl)])
(let ([radio-gtk (gtk_radio_button_new #f)] (let ([radio-gtk (gtk_radio_button_new #f)]
[image-gtk (gtk_image_new_from_pixbuf pixbuf)]) [image-gtk (gtk_image_new_from_pixbuf pixbuf)])
(release-pixbuf pixbuf) (release-pixbuf pixbuf)
(gtk_container_add radio-gtk image-gtk) (gtk_container_add radio-gtk image-gtk)
(gtk_widget_show image-gtk) (gtk_widget_show image-gtk)
radio-gtk))] radio-gtk))])])
[else
(gtk_radio_button_new_with_mnemonic #f "<bad bitmap>")])])
(gtk_box_pack_start gtk radio-gtk #t #t 0) (gtk_box_pack_start gtk radio-gtk #t #t 0)
(install-control-font (gtk_bin_get_child radio-gtk) font) (install-control-font (gtk_bin_get_child radio-gtk) font)
(gtk_widget_show radio-gtk) (gtk_widget_show radio-gtk)

View File

@ -27,9 +27,7 @@
(define callback cb) (define callback cb)
(define bitmap? (define bitmap? (label . is-a? . bitmap%))
(and (label . is-a? . bitmap%)
(send label ok?)))
(define/public (get-class) "PLTBUTTON") (define/public (get-class) "PLTBUTTON")
(define/public (get-flags) BS_PUSHBUTTON) (define/public (get-flags) BS_PUSHBUTTON)

View File

@ -71,9 +71,7 @@
x y x y
style font) style font)
(define bitmap? (define bitmap? (label . is-a? . bitmap%))
(and (label . is-a? . bitmap%)
(send label ok?)))
(define/public (get-class) "PLTSTATIC") (define/public (get-class) "PLTSTATIC")

View File

@ -55,8 +55,7 @@
(MoveWindow hwnd 0 0 w y #t) (MoveWindow hwnd 0 0 w y #t)
null) null)
(let* ([label (car labels)] (let* ([label (car labels)]
[bitmap? (and (label . is-a? . bitmap%) [bitmap? (label . is-a? . bitmap%)]
(send label ok?))]
[radio-hwnd [radio-hwnd
(CreateWindowExW/control 0 (CreateWindowExW/control 0
"PLTBUTTON" "PLTBUTTON"

View File

@ -40,25 +40,22 @@
@elem{If @litchar{&} occurs in @|where|@|detail|, it @elem{If @litchar{&} occurs in @|where|@|detail|, it
is specially parsed as for @scheme[button%].}) is specially parsed as for @scheme[button%].})
(define (bitmapuseinfo pre what thing then detail) (define (bitmapuseinfo pre what thing and the)
@elem{@|pre| @|what| is @|thing|, @|then| the bitmap@|detail| @elem{@|pre| @|what| is @|thing|,@|and| if @|the|
must be valid (see @xmethod[bitmap% ok?]) and not installed
in a @scheme[bitmap-dc%] object; otherwise, @|MismatchExn|. If the
bitmap has a mask (see @xmethod[bitmap% get-loaded-mask]) bitmap has a mask (see @xmethod[bitmap% get-loaded-mask])
that is the same size as the bitmap, then the mask is used for the that is the same size as the bitmap, then the mask is used for the
label; furthermore, in contrast to the limitations of label. Modifying a bitmap while it is used as a label has
@xmethod[dc<%> draw-bitmap], non-monochrome label masks work an unspecified effect on the displayed label.})
consistently on all platforms.})
(define-syntax bitmaplabeluse (define-syntax bitmaplabeluse
(syntax-rules () (syntax-rules ()
[(_ id) @bitmapuseinfo["If" (scheme id) "a bitmap" "then" ""]])) [(_ id) @bitmapuseinfo["If" (scheme id) "a bitmap" " and" "the"]]))
(define-syntax bitmaplabelusearray (define-syntax bitmaplabelusearray
(syntax-rules () (syntax-rules ()
[(_ id) @bitmapuseinfo["If" (scheme id) "a list of bitmaps" "then" "s"]])) [(_ id) @bitmapuseinfo["If" (scheme id) "a list of bitmaps" " and" "a"]]))
(define-syntax bitmaplabeluseisbm (define-syntax bitmaplabeluseisbm
(syntax-rules () (syntax-rules ()
[(_ id) @bitmapuseinfo["Since" (scheme id) "a bitmap" "" ""]])) [(_ id) @bitmapuseinfo["Since" (scheme id) "a bitmap" "" "the"]]))
(define bitmapiforiglabel (define bitmapiforiglabel
@elem{The bitmap label is installed only @elem{The bitmap label is installed only

View File

@ -50,10 +50,6 @@ Returns the bitmap that is displayed by the snip, whether set through
@method[image-snip% set-bitmap] or @method[image-snip% load-file]. If @method[image-snip% set-bitmap] or @method[image-snip% load-file]. If
no bitmap is displayed, the result is @racket[#f]. no bitmap is displayed, the result is @racket[#f].
The returned bitmap cannot be selected into a @racket[bitmap-dc%] as
long as it belongs to the snip, but it can be used as a pen or
brush stipple.
} }
@defmethod[(get-bitmap-mask) @defmethod[(get-bitmap-mask)
@ -63,10 +59,6 @@ Returns the mask bitmap that is used for displaying by the snip, if
one was installed with @method[image-snip% set-bitmap]. If no mask one was installed with @method[image-snip% set-bitmap]. If no mask
is used, the result is @racket[#f]. is used, the result is @racket[#f].
The returned bitmap cannot be selected into a @racket[bitmap-dc%] as
long as it belongs to the snip, but it can be used as a pen or
brush stipple.
} }
@defmethod[(get-filename [relative-path (or/c (box/c any/c) #f) #f]) @defmethod[(get-filename [relative-path (or/c (box/c any/c) #f) #f])

View File

@ -5,7 +5,7 @@
A message control is a static line of text or a static bitmap. The A message control is a static line of text or a static bitmap. The
text or bitmap corresponds to the message's label (see text or bitmap corresponds to the message's label (see
@method[window<%> set-label]). @method[message% set-label]).
@defconstructor[([label (or/c label-string? (is-a?/c bitmap%) @defconstructor[([label (or/c label-string? (is-a?/c bitmap%)
@ -28,7 +28,7 @@ Creates a string or bitmap message initially showing @scheme[label].
@indexed-scheme['caution], or @indexed-scheme['stop] symbol for @indexed-scheme['caution], or @indexed-scheme['stop] symbol for
@scheme[label] indicates an icon; @scheme['app] is the application @scheme[label] indicates an icon; @scheme['app] is the application
icon (Windows and Mac OS X) or a generic ``info'' icon (X), icon (Windows and Mac OS X) or a generic ``info'' icon (X),
@scheme['caution] is a caution-sign icon, and @scheme['stop] a @scheme['caution] is a caution-sign icon, and @scheme['stop] is a
stop-sign icon. stop-sign icon.
@labelsimplestripped[(scheme label) @elem{message}] @labelsimplestripped[(scheme label) @elem{message}]

View File

@ -1799,10 +1799,6 @@ If @scheme[bitmap] is @scheme[#f], no autowrap indicator is drawn
(this is the default). The previously used bitmap (possibly (this is the default). The previously used bitmap (possibly
@scheme[#f]) is returned. @scheme[#f]) is returned.
The bitmap will not be modified. It may be selected into a
@scheme[bitmap-dc%] object, but it will be selected out if this
method is called again.
Setting the bitmap is disallowed when the editor is internally locked Setting the bitmap is disallowed when the editor is internally locked
for reflowing (see also @|lockdiscuss|). for reflowing (see also @|lockdiscuss|).