(module fontdialog mzscheme (require (lib "class.ss") (lib "etc.ss") (lib "list.ss") (prefix wx: "kernel.ss") "lock.ss" "wx.ss" "cycle.ss" "check.ss" "helper.ss" "gdi.ss" "editor.ss" "mrtop.ss" "mrcanvas.ss" "mrpopup.ss" "mrmenu.ss" "mritem.ss" "mrpanel.ss" "mrtextfield.ss") (provide get-font-from-user) (define get-font-from-user (case-lambda [() (get-font-from-user #f #f #f null)] [(message) (get-font-from-user message #f #f null)] [(message parent) (get-font-from-user message parent #f null)] [(message parent font) (get-font-from-user message parent font null)] [(message parent font style) (check-label-string/false 'get-font-from-user message) (check-top-level-parent/false 'get-font-from-user parent) (check-instance 'get-font-from-user wx:font% 'font% #t font) (check-style 'get-font-from-user #f null style) (letrec ([ok? #f] [f (make-object dialog% "Choose Font" parent 500 300)] [refresh-sample (lambda (b e) (let ([f (get-font)]) (send ok-button enable f) (when f (let ([s (send (send edit get-style-list) find-named-style "Standard")]) (send s set-delta (font->delta f))))))] [p (make-object horizontal-pane% f)] [face (make-object list-box% #f (let ([l (wx:get-face-list)] [ugly? (lambda (a) (and (positive? (string-length a)) (not (or (char-alphabetic? (string-ref a 0)) (char-numeric? (string-ref a 0)) (char=? #\- (string-ref a 0))))))]) ;; Sort space-starting first (for Xft), and ;; otherwise push names that start with an ;; ASCII non-letter/digit/hyphen to the end (sort l (lambda (a b) (let ([a-sp? (char=? #\space (string-ref a 0))] [b-sp? (char=? #\space (string-ref b 0))] [a-ugly? (ugly? a)] [b-ugly? (ugly? b)]) (cond [(eq? a-sp? b-sp?) (cond [(eq? a-ugly? b-ugly?) (string-locale-ciwx f) (get-font))]) (when new-font (reset-font new-font))))) ;; Spacer: (make-object pane% bp)) (void))] [cancel-button (make-object button% "Cancel" bp (done #f))] [ok-button (make-object button% "OK" bp (done #t) '(border))] [reset-font (lambda (font) (let* ([facen (if font (send font get-face) (get-family-builtin-face 'default))] [f (and facen (send face find-string facen))]) (and f (>= f 0) (send face set-selection f))) (when font (send style set-selection (case (send font get-style) [(normal) 0] [(italic) 1] [(slant) 2])) (send weight set-selection (case (send font get-weight) [(normal) 0] [(bold) 1] [(light) 2])) (send underlined set-value (send font get-underlined)) (send size set-value (send font get-point-size)) (send sip set-value (send font get-size-in-pixels))) (refresh-sample (void) (void)))]) (send bp set-alignment 'right 'center) (send face min-width (max 200 (let-values ([(w h) (send face get-graphical-min-size)]) w))) (reset-font font) (send f center) (send f show #t) (and ok? (get-font)))])) (set-get-font-from-user! get-font-from-user))