special-option-key for cocoa

original commit: a7470471451607980b2331c0e56a83994687272b
This commit is contained in:
Matthew Flatt 2010-09-06 11:03:13 -06:00
parent 79d46e5164
commit fee7c80590
3 changed files with 37 additions and 8 deletions

View File

@ -10,8 +10,6 @@
"../common/handlers.rkt") "../common/handlers.rkt")
(provide (provide
special-control-key
special-option-key
application-file-handler application-file-handler
application-quit-handler application-quit-handler
application-about-handler application-about-handler
@ -62,8 +60,6 @@
(import-class NSScreen NSCursor) (import-class NSScreen NSCursor)
(define-unimplemented special-control-key)
(define (special-option-key on?) (void))
(define-unimplemented get-color-from-user) (define-unimplemented get-color-from-user)
(define-unimplemented get-font-from-user) (define-unimplemented get-font-from-user)
(define (get-panel-background) (make-object color% "gray")) (define (get-panel-background) (make-object color% "gray"))

View File

@ -29,12 +29,29 @@
queue-window*-event queue-window*-event
request-flush-delay request-flush-delay
cancel-flush-delay cancel-flush-delay
make-init-point) make-init-point
special-control-key
special-option-key)
(define-local-member-name flip-client) (define-local-member-name flip-client)
;; ---------------------------------------- ;; ----------------------------------------
(define special-control-key? #f)
(define special-control-key
(case-lambda
[() special-control-key?]
[(on?) (set! special-control-key? (and on? #t))]))
(define special-option-key? #f)
(define special-option-key
(case-lambda
[() special-option-key?]
[(on?) (set! special-option-key? (and on? #t))]))
;; ----------------------------------------
(define-objc-mixin (FocusResponder Superclass) (define-objc-mixin (FocusResponder Superclass)
[wxb] [wxb]
[-a _BOOL (acceptsFirstResponder) [-a _BOOL (acceptsFirstResponder)
@ -170,7 +187,8 @@
[bit? (lambda (m b) (positive? (bitwise-and m b)))] [bit? (lambda (m b) (positive? (bitwise-and m b)))]
[pos (tell #:type _NSPoint event locationInWindow)] [pos (tell #:type _NSPoint event locationInWindow)]
[str (tell #:type _NSString event characters)] [str (tell #:type _NSString event characters)]
[control? (bit? modifiers NSControlKeyMask)]) [control? (bit? modifiers NSControlKeyMask)]
[option? (bit? modifiers NSAlternateKeyMask)])
(let-values ([(x y) (send wx window-point-to-view pos)]) (let-values ([(x y) (send wx window-point-to-view pos)])
(let ([k (new key-event% (let ([k (new key-event%
[key-code (or [key-code (or
@ -188,7 +206,7 @@
[shift-down (bit? modifiers NSShiftKeyMask)] [shift-down (bit? modifiers NSShiftKeyMask)]
[control-down control?] [control-down control?]
[meta-down (bit? modifiers NSCommandKeyMask)] [meta-down (bit? modifiers NSCommandKeyMask)]
[alt-down (bit? modifiers NSAlternateKeyMask)] [alt-down option?]
[x (->long x)] [x (->long x)]
[y (->long y)] [y (->long y)]
[time-stamp (->long (* (tell #:type _double event timestamp) 1000.0))] [time-stamp (->long (* (tell #:type _double event timestamp) 1000.0))]
@ -199,6 +217,13 @@
(let ([alt-code (string-ref alt-str 0)]) (let ([alt-code (string-ref alt-str 0)])
(unless (equal? alt-code (send k get-key-code)) (unless (equal? alt-code (send k get-key-code))
(send k set-other-altgr-key-code alt-code))))) (send k set-other-altgr-key-code alt-code)))))
(when (and option?
special-option-key?
(send k get-other-altgr-key-code))
;; swap altenate with main
(let ([other (send k get-other-altgr-key-code)])
(send k set-other-altgr-key-code (send k get-key-code))
(send k set-key-code other)))
(if (send wx definitely-wants-event? k) (if (send wx definitely-wants-event? k)
(begin (begin
(queue-window-event wx (lambda () (queue-window-event wx (lambda ()

View File

@ -1,6 +1,14 @@
#lang racket/base #lang racket/base
(require racket/gui/base (require racket/gui/base
racket/class) racket/class
racket/cmdline)
(command-line
#:once-each
[("--option") "set special Option key"
(special-option-key #t)]
[("--control") "set special Control key"
(special-control-key #t)])
(let () (let ()
(define iter 0) (define iter 0)