1
1
#| nokogiri-widgets/font.jl -- font selection widget
3
$Id: font.jl,v 1.4 2000/11/27 18:13:19 jsh Exp $
3
$Id: font.jl.in,v 1.1 2003/08/16 18:35:38 jsh Exp $
5
5
Copyright (C) 2000 John Harper <john@dcs.warwick.ac.uk>
24
24
(define-structure sawfish.gtk.widgets.font ()
30
(defconst default-font "fixed")
32
;; FIXME: this is broken, in that only if Xrender is present
33
;; does gdk use Xft. But, it's the best I can do..
34
(define use-xft (let ((x (getenv "GDK_USE_XFT")))
35
(or (not x) (/= (string->number x) 0))))
37
;; defined by configure
38
(define have-pango-xft (eq 'yes 'yes))
40
(define default-font (if use-xft "Sans" "fixed"))
32
42
(define (make-font-item changed-callback)
33
43
(let* ((box (gtk-hbox-new nil box-spacing))
34
44
(entry (gtk-entry-new))
35
45
(button (gtk-button-new-with-label (_ "Browse..."))))
46
(gtk-editable-set-editable entry nil)
36
47
(gtk-box-pack-start box entry t t)
37
48
(gtk-box-pack-start box button)
38
49
(when changed-callback
40
51
entry "changed" (make-signal-callback changed-callback)))
44
55
(let ((fontsel (gtk-font-selection-dialog-new (_ "Select font"))))
45
56
(gtk-font-selection-dialog-set-font-name
46
57
fontsel (gtk-entry-get-text entry))
48
59
(gtk-font-selection-dialog-ok-button fontsel) "clicked"
50
61
(gtk-entry-set-text
51
62
entry (gtk-font-selection-dialog-get-font-name fontsel))
52
63
(gtk-widget-destroy fontsel)))
54
65
(gtk-font-selection-dialog-cancel-button fontsel) "clicked"
55
66
(lambda () (gtk-widget-destroy fontsel)))
56
(gtk-signal-connect fontsel "delete_event"
67
(g-signal-connect fontsel "delete_event"
57
68
(lambda () (gtk-widget-destroy fontsel)))
58
69
(gtk-widget-show fontsel)
59
70
(gtk-grab-add fontsel))))
64
(gtk-entry-set-text entry (and (stringp x) x))))
76
(gtk-entry-set-text entry x))
79
((string-equal (car x) "Xft")
80
(xft-description->face (cdr x)))
81
((string-equal (car x) "xlfd")
82
(xlfd-description->face (cdr x)))
83
((string-equal (car x) "pango")
84
(pango-description->face (cdr x))))))
87
entry (face->pango-description face)))))
88
(t (gtk-entry-set-text entry default-font)))))
65
89
((clear) (lambda ()
66
90
(gtk-entry-set-text entry default-font)))
67
((ref) (lambda () (gtk-entry-get-text entry)))
92
(let* ((pango-name (gtk-entry-get-text entry))
93
(face (pango-description->face pango-name)))
94
(cond ((not face) nil)
97
(cons "Pango" (face->pango-description face))
98
(cons "Xft" (face->xft-description face))))
99
(t (cons "xlfd" (face->xlfd-description face)))))))
68
100
((gtk-widget) box)
69
101
((validp) (lambda (x) (stringp x)))))))