Merge remote-tracking branch 'origin/master' into for-steve
[sxemacs] / lisp / x-misc.el
1 ;;; x-misc.el --- miscellaneous X functions.
2
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995 Sun Microsystems.
5 ;; Copyright (C) 1995, 1996 Ben Wing.
6
7 ;; Author: Ben Wing <ben@xemacs.org>
8 ;; Maintainer: SXEmacs Development Team
9 ;; Keywords: extensions, dumped
10
11 ;; This file is part of SXEmacs.
12
13 ;; SXEmacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
17
18 ;; SXEmacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Commentary:
27
28 ;; This file is dumped with SXEmacs (when X support is compiled in).
29
30 ;;; Code:
31
32 (defun x-bogosity-check-resource (name class type)
33   "Check for a bogus resource specification."
34   (let ((bogus (x-get-resource
35                 (concat "__no-such-friggin-locale__." name)
36                 (concat "__No-such-friggin-widget__." class)
37                 type 'global nil t)))
38     (if bogus
39         (display-warning
40          'resource
41          (format "Bad resource specification encountered: something like
42      Emacs*%s: %s
43 You should replace the * with a . in order to get proper behavior when
44 you use the specifier and/or `set-face-*' functions." name bogus)))))
45
46 (defun x-init-specifier-from-resources (specifier type locale
47                                                   &rest resource-list)
48   "Initialize a specifier from the resource database.
49 LOCALE specifies the locale that is to be initialized and should be
50 a frame, a device, or 'global.  TYPE is the type of the resource and
51 should be one of 'string, 'boolean, 'integer, or 'natnum.  The
52 remaining args should be conses of names and classes of resources
53 to be examined.  The first resource with a value specified becomes
54 the spec for SPECIFIER in LOCALE. (However, if SPECIFIER already
55 has a spec in LOCALE, nothing is done.) Finally, if LOCALE is 'global,
56 a check is done for bogus resource specifications."
57   (if (eq locale 'global)
58       (mapcar #'(lambda (x)
59                   (x-bogosity-check-resource (car x) (cdr x) type))
60               resource-list))
61   (if (not (specifier-spec-list specifier locale))
62       (catch 'done
63         (while resource-list
64           (let* ((name (caar resource-list))
65                  (class (cdar resource-list))
66                  (resource
67                   (x-get-resource name class type locale nil 'warn)))
68             (if resource
69                 (progn
70                   (add-spec-to-specifier specifier resource locale)
71                   (throw 'done t))))
72           (setq resource-list (cdr resource-list))))))
73
74 (defun x-get-resource-and-bogosity-check (name class type &optional locale)
75   (x-bogosity-check-resource name class type)
76   (x-get-resource name class type locale nil 'warn))
77
78 (defun x-get-resource-and-maybe-bogosity-check (name class type &optional
79                                                      locale)
80   (if (eq locale 'global)
81       (x-bogosity-check-resource name class type))
82   (x-get-resource name class type locale nil 'warn))
83
84 ;;; x-misc.el ends here