cocoa: fix problems with `radio-box%' in no-selection mode

Closes PR 11708
 Merge to 5.1
(cherry picked from commit 5d1b78384d)
This commit is contained in:
Matthew Flatt 2011-02-04 07:25:02 -07:00 committed by Eli Barzilay
parent 4e33afc100
commit 9721ad1ce7

View File

@ -26,6 +26,9 @@
#:mixins (FocusResponder KeyMouseResponder CursorDisplayer)
[wxb]
(-a _void (clicked: [_id sender])
;; In case we were in 0-item mode, switch to Radio mode to
;; ensure that only one button is selected:
(tellv self setMode: #:type _int NSRadioModeMatrix)
(queue-window*-event wxb (lambda (wx) (send wx clicked)))))
(define-objc-class MyImageButtonCell NSButtonCell
@ -127,15 +130,21 @@
(if (= i -1)
(begin
;; Need to change to NSListModeMatrix to disable all.
;; It seem that we don't have to change the mode back, for some reason.
(tellv (get-cocoa) setMode: #:type _int NSListModeMatrix)
(tellv (get-cocoa) deselectAllCells))
(tellv (get-cocoa) selectCellAtRow: #:type _NSInteger (if horiz? 0 i)
column: #:type _NSInteger (if horiz? i 0))))
(begin
(tellv (get-cocoa) setMode: #:type _int NSRadioModeMatrix)
(tellv (get-cocoa) selectCellAtRow: #:type _NSInteger (if horiz? 0 i)
column: #:type _NSInteger (if horiz? i 0)))))
(define/public (get-selection)
(if horiz?
(tell #:type _NSInteger (get-cocoa) selectedColumn)
(tell #:type _NSInteger (get-cocoa) selectedRow)))
(let ([c (tell (get-cocoa) selectedCell)]
[pos (if horiz?
(tell #:type _NSInteger (get-cocoa) selectedColumn)
(tell #:type _NSInteger (get-cocoa) selectedRow))])
(if (and c
(positive? (tell #:type _NSInteger c state)))
pos
-1)))
(define/public (number) count)
(define/override (maybe-register-as-child parent on?)