;;;; ;;;; f o n t - c h o o s e r . s t k l o s -- A simple font editor widget ;;;; ;;;; Copyright © 1999 Erick Gallesio - I3S-CNRS/ESSI ;;;; ;;;; 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. ;;;; ;;;; Author: Erick Gallesio [eg@unice.fr] ;;;; Creation date: 1-Feb-1999 08:55 ;;;; Last file update: 3-Sep-1999 19:51 (eg) (require "Tk-classes") (select-module STklos+Tk) (export make-font-chooser) ;============================================================================= ; ; Global variables ; ;============================================================================= (define *fc:font* #f) ;;; the prototype font (define *fc:lock* #f) ;;; to grab the window while choosing font ;============================================================================= ; ; Utilities ; ;============================================================================= (define (font-wait-result chooser) (let ((cur-grab (grab 'current chooser)) (old-font (font 'actual *fc:font*)) (pretty (lambda () (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) '()))))) (tkwait 'visibility chooser) (grab 'set chooser) (tkwait 'variable '*fc:lock*) (and cur-grab (grab 'set cur-grab)) ;; Compute result (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)))) (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 ;; (define (make-top-frame parent) (let* ((fonts (sort (font 'families) string :parent parent :relief "groove" :border-width 2)) (family (make