From f04e67e91f7a0b0acfd6791e2fb9fd4d04d764ec Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 4 Feb 2011 07:25:02 -0700 Subject: [PATCH] cocoa: fix problems with `radio-box%' in no-selection mode Closes PR 11708 Merge to 5.1 original commit: 5d1b78384d390520edf970021bc0c144f78c259e --- collects/mred/private/wx/cocoa/radio-box.rkt | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/collects/mred/private/wx/cocoa/radio-box.rkt b/collects/mred/private/wx/cocoa/radio-box.rkt index 237ec581..558418df 100644 --- a/collects/mred/private/wx/cocoa/radio-box.rkt +++ b/collects/mred/private/wx/cocoa/radio-box.rkt @@ -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?)