1999-02-02 06:13:40 -05:00
|
|
|
|
;;;;
|
|
|
|
|
;;;; f o n t - c h o o s e r . s t k l o s -- A simple font editor widget
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; Copyright <20> 1999 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
|
|
|
|
|
;;;;
|
1999-09-05 07:16:41 -04:00
|
|
|
|
;;;; Permission to use, copy, modify, distribute,and license this
|
|
|
|
|
;;;; software and its documentation for any purpose is hereby granted,
|
|
|
|
|
;;;; provided that existing copyright notices are retained in all
|
|
|
|
|
;;;; copies and that this notice is included verbatim in any
|
|
|
|
|
;;;; distributions. No written agreement, license, or royalty fee is
|
|
|
|
|
;;;; required for any of the authorized uses.
|
|
|
|
|
;;;; This software is provided ``AS IS'' without express or implied
|
|
|
|
|
;;;; warranty.
|
1999-02-02 06:13:40 -05:00
|
|
|
|
;;;;
|
|
|
|
|
;;;; Author: Erick Gallesio [eg@unice.fr]
|
|
|
|
|
;;;; Creation date: 1-Feb-1999 08:55
|
1999-09-05 07:16:41 -04:00
|
|
|
|
;;;; Last file update: 3-Sep-1999 19:51 (eg)
|
1999-02-02 06:13:40 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(require "Tk-classes")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(select-module STklos+Tk)
|
|
|
|
|
(export make-font-chooser)
|
|
|
|
|
|
1999-09-05 07:16:41 -04:00
|
|
|
|
;=============================================================================
|
|
|
|
|
;
|
|
|
|
|
; Global variables
|
|
|
|
|
;
|
|
|
|
|
;=============================================================================
|
|
|
|
|
|
|
|
|
|
(define *fc:font* #f) ;;; the prototype font
|
|
|
|
|
(define *fc:lock* #f) ;;; to grab the window while choosing font
|
1999-02-02 06:13:40 -05:00
|
|
|
|
|
|
|
|
|
;=============================================================================
|
|
|
|
|
;
|
|
|
|
|
; Utilities
|
|
|
|
|
;
|
|
|
|
|
;=============================================================================
|
|
|
|
|
|
|
|
|
|
(define (font-wait-result chooser)
|
|
|
|
|
(let ((cur-grab (grab 'current chooser))
|
1999-09-05 07:16:41 -04:00
|
|
|
|
(old-font (font 'actual *fc:font*))
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(pretty (lambda ()
|
1999-09-05 07:16:41 -04:00
|
|
|
|
(append
|
|
|
|
|
(list (font 'conf *fc:font* :family)
|
|
|
|
|
(font 'conf *fc:font* :size)
|
|
|
|
|
(string->symbol (font 'conf *fc:font* :weight))
|
|
|
|
|
(string->symbol (font 'conf *fc:font* :slant)))
|
|
|
|
|
(if (font 'conf *fc:font* :underline) '(underline) '())
|
|
|
|
|
(if (font 'conf *fc:font* :overstrike) '(overstrike) '())))))
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(tkwait 'visibility chooser)
|
|
|
|
|
(grab 'set chooser)
|
1999-09-05 07:16:41 -04:00
|
|
|
|
(tkwait 'variable '*fc:lock*)
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(and cur-grab (grab 'set cur-grab))
|
|
|
|
|
|
|
|
|
|
;; Compute result
|
1999-09-05 07:16:41 -04:00
|
|
|
|
(case *fc:lock*
|
|
|
|
|
((ok) (destroy chooser)
|
|
|
|
|
;; return a pretty result
|
|
|
|
|
(pretty))
|
|
|
|
|
((cancel) (destroy chooser)
|
|
|
|
|
;; restore the font we have when entering the widget
|
|
|
|
|
(apply font 'configure *fc:font* old-font)
|
|
|
|
|
#f))))
|
1999-02-02 06:13:40 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-09-05 07:16:41 -04:00
|
|
|
|
(define (%make-font-chooser fnt)
|
|
|
|
|
;;
|
|
|
|
|
;; Some utilities
|
|
|
|
|
;;
|
|
|
|
|
(define (toggle-weight)
|
|
|
|
|
(font 'configure *fc:font* :weight
|
|
|
|
|
(if (equal? (font 'conf *fc:font* :weight) "normal") "bold" "normal")))
|
|
|
|
|
|
|
|
|
|
(define (toggle-slant)
|
|
|
|
|
(font 'configure *fc:font* :slant
|
|
|
|
|
(if (equal? (font 'conf *fc:font* :slant) "roman") "italic" "roman")))
|
|
|
|
|
|
|
|
|
|
(define (toggle-underline)
|
|
|
|
|
(font 'configure *fc:font* :underline
|
|
|
|
|
(not (font 'configure *fc:font* :underline))))
|
|
|
|
|
|
|
|
|
|
(define (toggle-overstrike)
|
|
|
|
|
(font 'configure *fc:font* :overstrike
|
|
|
|
|
(not (font 'configure *fc:font* :overstrike))))
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
;; Top frame building
|
|
|
|
|
;;
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(define (make-top-frame parent)
|
1999-09-05 07:16:41 -04:00
|
|
|
|
(let* ((fonts (sort (font 'families) string<?))
|
|
|
|
|
(f (make <Frame> :parent parent :relief "groove" :border-width 2))
|
|
|
|
|
(family (make <Label> :parent f :text "Font Family:"))
|
|
|
|
|
(choice1 (make <Combobox> :parent f :values fonts :state "disabled"
|
|
|
|
|
:value (font 'configure *fc:font* :family)
|
|
|
|
|
:command (lambda (v)
|
|
|
|
|
(font 'conf *fc:font* :family v))))
|
|
|
|
|
(size (make <Label> :parent f :text "Font Size:"))
|
|
|
|
|
(choice2 (make <Combobox> :parent f :values '(8 10 12 14 20 24 36 48)
|
|
|
|
|
:width 3 :string-value #f
|
|
|
|
|
:value (font 'configure *fc:font* :size)
|
|
|
|
|
:command (lambda (v)
|
|
|
|
|
(font 'conf *fc:font* :size v))))
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(bold (make <Check-button> :parent f :text "B" :width 3
|
|
|
|
|
:font (font 'create :weight 'bold)
|
1999-09-05 07:16:41 -04:00
|
|
|
|
:indicator-on #f :command toggle-weight))
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(italic (make <Check-button> :parent f :text "i" :width 3
|
|
|
|
|
:font (font 'create :slant 'italic)
|
1999-09-05 07:16:41 -04:00
|
|
|
|
:indicator-on #f :command toggle-slant))
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(under (make <Check-button> :parent f :text "U" :width 3
|
|
|
|
|
:font (font 'create :underline #t)
|
1999-09-05 07:16:41 -04:00
|
|
|
|
:indicator-on #f
|
|
|
|
|
:command toggle-underline))
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(over (make <Check-button> :parent f :text "O" :width 3
|
|
|
|
|
:font (font 'create :overstrike #t)
|
1999-09-05 07:16:41 -04:00
|
|
|
|
:indicator-on #f
|
|
|
|
|
:command toggle-overstrike)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; See the buttons that must be toggled
|
|
|
|
|
(if (equal? (font 'conf *fc:font* :weight) "bold") (toggle bold))
|
|
|
|
|
(if (equal? (font 'conf *fc:font* :slant) "italic") (toggle italic))
|
|
|
|
|
(if (font 'conf *fc:font* :underline) (toggle under))
|
|
|
|
|
(if (font 'conf *fc:font* :overstrike) (toggle over))
|
1999-02-02 06:13:40 -05:00
|
|
|
|
|
|
|
|
|
|
1999-09-05 07:16:41 -04:00
|
|
|
|
;; Change binding of "Font size" box to allow direct manipulation
|
|
|
|
|
(bind (entry-of choice2) "<Return>"
|
|
|
|
|
(lambda () (font 'conf *fc:font* :size (value choice2))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Pack everybody
|
|
|
|
|
(pack family choice1 size choice2 :side 'left :padx 2)
|
|
|
|
|
(pack bold under italic over :fill 'y :side 'left :padx 2 :pady 2)
|
|
|
|
|
|
1999-02-02 06:13:40 -05:00
|
|
|
|
f))
|
|
|
|
|
|
1999-09-05 07:16:41 -04:00
|
|
|
|
;;;
|
|
|
|
|
;;; Center part of the widget (the sample)
|
|
|
|
|
;;;
|
|
|
|
|
(define (make-sample parent)
|
|
|
|
|
(make <Label> :parent parent :font *fc:font*
|
|
|
|
|
:text (string-append "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
|
|
|
|
|
"abcdefghijklmnopqrstuvwxyz\n"
|
|
|
|
|
"0123456789~`!@#$%^&*()_-+=\n"
|
|
|
|
|
"{}[]:;\"'<>,.?/")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Bottom part of the widget (the closing buttons)
|
|
|
|
|
;;;
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(define (make-buttons parent)
|
|
|
|
|
(let* ((f (make <Frame> :parent parent :relief "groove" :border-width 2))
|
|
|
|
|
(sel (make <Button> :parent f :text "Select"
|
1999-09-05 07:16:41 -04:00
|
|
|
|
:command (lambda () (set! *fc:lock* 'ok))))
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(cancel (make <Button> :parent f :text "Cancel"
|
1999-09-05 07:16:41 -04:00
|
|
|
|
:command (lambda () (set! *fc:lock* 'cancel)))))
|
|
|
|
|
(wm 'protocol parent "WM_DELETE_WINDOW" (lambda() (set! *fc:lock* 'cancel)))
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(pack sel cancel :side 'left :padx 2 :pady 2)
|
1999-09-05 07:16:41 -04:00
|
|
|
|
f))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Start of %make-font-chooser
|
|
|
|
|
;;;
|
|
|
|
|
(let* ((t (make <Toplevel> :title "Font chooser ..." :class "FontChooser"
|
|
|
|
|
:geometry "500x300"))
|
1999-02-02 06:13:40 -05:00
|
|
|
|
|
|
|
|
|
(top (make-top-frame t))
|
1999-09-05 07:16:41 -04:00
|
|
|
|
(txt (make-sample t))
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(but (make-buttons t)))
|
|
|
|
|
; The internal frame
|
|
|
|
|
(pack top :fill 'x :expand #f)
|
1999-09-05 07:16:41 -04:00
|
|
|
|
(pack txt :fill 'both :expand #t)
|
1999-02-02 06:13:40 -05:00
|
|
|
|
(pack but :fill 'x :expand #f :side 'bottom)
|
|
|
|
|
t))
|
|
|
|
|
|
|
|
|
|
;=============================================================================
|
|
|
|
|
;
|
1999-09-05 07:16:41 -04:00
|
|
|
|
; make-font-chooser (the only exported procedure)
|
1999-02-02 06:13:40 -05:00
|
|
|
|
;
|
|
|
|
|
;=============================================================================
|
|
|
|
|
(define (make-font-chooser . fnt)
|
1999-09-05 07:16:41 -04:00
|
|
|
|
(unless *fc:font*
|
|
|
|
|
;; If this is the first call to this function. Create the prototype font
|
|
|
|
|
;; with a plausible font
|
|
|
|
|
(let ((tmp (button (gensym ".tmp__font"))))
|
|
|
|
|
(set! *fc:font* (apply font 'create (font 'actual (tk-get tmp :font))))
|
|
|
|
|
(destroy tmp)))
|
|
|
|
|
|
|
|
|
|
(unless (null? fnt)
|
|
|
|
|
(apply font 'configure *fc:font* (font 'actual (car fnt))))
|
|
|
|
|
|
1999-02-02 06:13:40 -05:00
|
|
|
|
;; Call the chooser box
|
1999-09-05 07:16:41 -04:00
|
|
|
|
(font-wait-result (%make-font-chooser *fc:font*)))
|
|
|
|
|
|
1999-02-02 06:13:40 -05:00
|
|
|
|
|
|
|
|
|
(provide "font-chooser")
|