1
#| nokogiri-widgets/font.jl -- font selection widget
3
$Id: font.jl.in,v 1.1 2003/08/16 18:35:38 jsh Exp $
5
Copyright (C) 2000 John Harper <john@dcs.warwick.ac.uk>
7
This file is part of sawfish.
9
sawfish is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2, or (at your option)
14
sawfish is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with sawfish; see the file COPYING. If not, write to
21
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
(define-structure sawfish.gtk.widgets.font ()
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"))
42
(define (make-font-item changed-callback)
43
(let* ((box (gtk-hbox-new nil box-spacing))
44
(entry (gtk-entry-new))
45
(button (gtk-button-new-with-label (_ "Browse..."))))
46
(gtk-editable-set-editable entry nil)
47
(gtk-box-pack-start box entry t t)
48
(gtk-box-pack-start box button)
49
(when changed-callback
51
entry "changed" (make-signal-callback changed-callback)))
55
(let ((fontsel (gtk-font-selection-dialog-new (_ "Select font"))))
56
(gtk-font-selection-dialog-set-font-name
57
fontsel (gtk-entry-get-text entry))
59
(gtk-font-selection-dialog-ok-button fontsel) "clicked"
62
entry (gtk-font-selection-dialog-get-font-name fontsel))
63
(gtk-widget-destroy fontsel)))
65
(gtk-font-selection-dialog-cancel-button fontsel) "clicked"
66
(lambda () (gtk-widget-destroy fontsel)))
67
(g-signal-connect fontsel "delete_event"
68
(lambda () (gtk-widget-destroy fontsel)))
69
(gtk-widget-show fontsel)
70
(gtk-grab-add fontsel))))
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)))))
90
(gtk-entry-set-text entry default-font)))
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)))))))
101
((validp) (lambda (x) (stringp x)))))))
103
(define-widget-type 'font make-font-item))