From ea1f6ecc1ba82da8f27019fb20cf72b785db43b3 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 6 Jan 2014 10:47:02 -0700 Subject: [PATCH] racket/gui cocoa: fix "&" in labels As of Mac OS X 10.8, `setTitleWithMnemonic:` doesn't strip away "&". original commit: 75dade281885f7b654ee49e93e1b6349b319c1c2 --- pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/button.rkt | 4 ++-- pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/item.rkt | 6 +++++- pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/message.rkt | 4 ++-- pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/radio-box.rkt | 6 +++--- pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/slider.rkt | 8 ++++---- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/button.rkt b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/button.rkt index 494729e7..e76b6dae 100644 --- a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/button.rkt +++ b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/button.rkt @@ -59,7 +59,7 @@ NSRoundedBezelStyle))) (cond [(string? label) - (tellv cocoa setTitleWithMnemonic: #:type _NSString label)] + (tellv cocoa setTitle: #:type _NSString (strip-mnemonic label))] [else (if button-type (tellv cocoa setTitle: #:type _NSString "") @@ -182,7 +182,7 @@ (define/override (set-label label) (cond [(string? label) - (tellv cocoa setTitleWithMnemonic: #:type _NSString label)] + (tellv cocoa setTitle: #:type _NSString (strip-mnemonic label))] [else (tellv (or image-cocoa cocoa) setImage: (bitmap->image label))])) diff --git a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/item.rkt b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/item.rkt index 2ff73fa1..6760e2e8 100644 --- a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/item.rkt +++ b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/item.rkt @@ -12,7 +12,8 @@ (provide (protect-out item% install-control-font - sys-font-size)) + sys-font-size + strip-mnemonic)) (import-class NSFont) @@ -28,6 +29,9 @@ (tellv cocoa setFont: (font->NSFont font)) (tellv cocoa setFont: sys-font))) +(define (strip-mnemonic s) + (regexp-replace #rx"[&](.)" s "\\1")) + (defclass item% window% (inherit get-cocoa is-window-enabled?) diff --git a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/message.rkt b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/message.rkt index 08fa7bea..360f4e8f 100644 --- a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/message.rkt +++ b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/message.rkt @@ -94,7 +94,7 @@ (tellv cocoa setEditable: #:type _BOOL #f) (tellv cocoa setBordered: #:type _BOOL #f) (tellv cocoa setDrawsBackground: #:type _BOOL #f) - (tellv cocoa setTitleWithMnemonic: #:type _NSString label) + (tellv cocoa setStringValue: #:type _NSString (strip-mnemonic label)) (tellv cocoa sizeToFit)] [else (tellv cocoa setImage: (if (label . is-a? . bitmap%) @@ -113,7 +113,7 @@ (define/override (set-label label) (cond [(string? label) - (tellv (get-cocoa) setTitleWithMnemonic: #:type _NSString label)] + (tellv (get-cocoa) setStringValue: #:type _NSString (strip-mnemonic label))] [else (tellv (get-cocoa) setImage: (bitmap->image label))])) diff --git a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/radio-box.rkt b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/radio-box.rkt index 79f90406..e3c5068b 100644 --- a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/radio-box.rkt +++ b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/radio-box.rkt @@ -95,9 +95,9 @@ (set-ivar! button img (bitmap->image label))) (begin (init-font button font) - (tellv button setTitleWithMnemonic: #:type _NSString (if (string? label) - label - "")))) + (tellv button setTitle: #:type _NSString (if (string? label) + (strip-mnemonic label) + "")))) (tellv button setButtonType: #:type _int NSRadioButton))) (tellv cocoa sizeToFit) (tellv cocoa setTarget: cocoa) diff --git a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/slider.rkt b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/slider.rkt index 3dc9f1c5..ac07d28b 100644 --- a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/slider.rkt +++ b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/slider.rkt @@ -77,13 +77,13 @@ (tellv cocoa setEditable: #:type _BOOL #f) (tellv cocoa setBordered: #:type _BOOL #f) (tellv cocoa setDrawsBackground: #:type _BOOL #f) - (tellv cocoa setTitleWithMnemonic: #:type _NSString (format "~a" hi)) + (tellv cocoa setStringValue: #:type _NSString (format "~a" hi)) (tellv cocoa sizeToFit) (let ([r1 (tell #:type _NSRect cocoa frame)]) - (tellv cocoa setTitleWithMnemonic: #:type _NSString (format "~a" lo)) + (tellv cocoa setStringValue: #:type _NSString (format "~a" lo)) (tellv cocoa sizeToFit) (let ([r2 (tell #:type _NSRect cocoa frame)]) - (tellv cocoa setTitleWithMnemonic: #:type _NSString (format "~a" val)) + (tellv cocoa setStringValue: #:type _NSString (format "~a" val)) (values cocoa (max (NSSize-width (NSRect-size r1)) (NSSize-width (NSRect-size r2))) @@ -164,7 +164,7 @@ (flip (inexact->exact (floor (tell #:type _double slider-cocoa doubleValue))))) (define/public (update-message [val (get-value)]) - (tellv message-cocoa setTitleWithMnemonic: #:type _NSString (format "~a" val))) + (tellv message-cocoa setStringValue: #:type _NSString (format "~a" val))) (inherit get-cocoa-window) (define/override (post-mouse-down)