1 ;;; wl-demo.el --- Opening demo on Wanderlust
3 ;; Copyright (C) 1998,1999,2000,2001 Yuuichi Teranishi <teranisi@gohome.org>
4 ;; Copyright (C) 2000,2001 Katsumi Yamaoka <yamaoka@jpl.org>
6 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
7 ;; Katsumi Yamaoka <yamaoka@jpl.org>
8 ;; Keywords: mail, net news
10 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
12 ;; This program is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
31 (defconst wl-demo-copyright-notice
32 "Copyright (C) 1998-2001 Yuuichi Teranishi <teranisi@gohome.org>"
33 "A declaration of the copyright on Wanderlust.")
40 (require 'wl-highlight)
42 (defconst wl-demo-icon-name
43 (concat "wl-" (wl-version-status)
44 (if (string-match "^... Dec \\([ 1][0-9]\\|2[0-5]\\)"
45 (current-time-string))
48 "Basename of the logo file.")
50 (defvar wl-logo-ascii "\
52 oo$$$ o$$ o$$$\"\"\"\"\"\"$$$$$o
53 $$$$$$\" o$$$\" o$\"\" \"$$$
57 o$$ oo$\" \"$$$o $ o$$
58 $$$$\"\" \"$$oo$ o o$\"
59 \"$$o \"$$$o oooo$\"\"
63 Yet Another Message Interface On Emacsen"
64 "Ascii picture used to splash the startup screen.")
68 ;; `display-images-p' has not been available in Emacs versions
69 ;; prior to Emacs 21.0.105.
70 (defalias-maybe 'display-images-p 'display-graphic-p)))
72 ;; Avoid byte compile warnings.
74 (autoload 'bitmap-insert-xbm-file "bitmap" nil t)
75 (autoload 'create-image "image")
76 (autoload 'device-on-window-system-p "device")
77 (autoload 'image-type-available-p "image")
78 (autoload 'insert-image "image")
79 (autoload 'make-glyph "glyphs")
80 (autoload 'set-glyph-face "glyphs")
81 (autoload 'set-specifier "specifier")
82 (defalias-maybe 'frame-char-height 'ignore)
83 (defalias-maybe 'frame-char-width 'ignore)
84 (defalias-maybe 'glyph-height 'ignore)
85 (defalias-maybe 'glyph-width 'ignore)
86 (defalias-maybe 'image-size 'ignore)
87 (defalias-maybe 'make-extent 'ignore)
88 (defalias-maybe 'propertize 'ignore)
89 (defalias-maybe 'set-extent-end-glyph 'ignore)
90 (defalias-maybe 'window-pixel-height 'ignore)
91 (defalias-maybe 'window-pixel-width 'ignore))
93 (defvar wl-demo-bitmap-mule-available-p 'unknown
94 "Internal variable to say whether the BITMAP-MULE package is available.")
96 (defun wl-demo-image-type-alist ()
97 "Return an alist of available logo image types on the current frame."
98 (if (or (and (featurep 'xemacs)
99 (device-on-window-system-p))
102 (when (or (and (featurep 'xemacs)
106 (image-type-available-p 'xpm)))
109 (when (or (featurep 'xemacs)
112 (image-type-available-p 'xbm))
113 (eq t wl-demo-bitmap-mule-available-p)
114 (and (eq 'unknown wl-demo-bitmap-mule-available-p)
115 (module-installed-p 'bitmap)
116 (setq wl-demo-bitmap-mule-available-p t)))
119 (when (and (not (featurep 'xemacs))
120 (or (eq t wl-demo-bitmap-mule-available-p)
121 (and (eq 'unknown wl-demo-bitmap-mule-available-p)
122 (module-installed-p 'bitmap)
123 (setq wl-demo-bitmap-mule-available-p t))))
124 '("bitmap" . bitmap))))
125 (if (and wl-on-emacs21
126 (image-type-available-p 'xbm))
127 ;; Prefer xbm rather than bitmap on Emacs 21.
128 (delq nil (list xpm xbm bitmap '("ascii")))
129 (delq nil (list xpm bitmap xbm '("ascii")))))
132 (defun wl-demo-insert-image (image-type)
133 "Insert a logo image at the point and position it to be centered.
134 IMAGE-TYPE specifies what a type of image should be displayed.
135 Return a number of lines that an image occupies in the buffer."
136 (let ((file (cond ((eq 'xpm image-type)
137 (concat wl-demo-icon-name ".xpm"))
138 ((eq 'bitmap image-type)
139 (concat wl-demo-icon-name ".img"))
140 ((eq 'xbm image-type)
141 (concat wl-demo-icon-name ".xbm"))))
143 (when (featurep 'xemacs)
144 (when (boundp 'default-gutter-visible-p)
145 (set-specifier (symbol-value 'default-gutter-visible-p)
146 nil (current-buffer)))
147 (set-specifier (symbol-value 'scrollbar-height) 0 (current-buffer))
148 (set-specifier (symbol-value 'scrollbar-width) 0 (current-buffer)))
150 (if (and wl-icon-directory
151 (file-directory-p wl-icon-directory))
152 (setq file (expand-file-name file wl-icon-directory))
153 (message "You have to specify the value of `wl-icon-directory'")
155 (if (file-exists-p file)
156 (if (file-readable-p file)
158 (message "Permission denied: %s" file)
160 (message "File not found: %s" file)
163 (cond ((featurep 'xemacs)
164 (setq width (window-pixel-width)
165 height (window-pixel-height)
166 image (make-glyph (vector image-type ':file file)))
167 (when (eq 'xbm image-type)
168 (set-glyph-face image 'wl-highlight-logo-face))
169 (insert-char ?\ (max 0 (/ (+ (* (- width (glyph-width image))
170 (window-width)) width)
172 (set-extent-end-glyph (make-extent (point) (point)) image)
174 (/ (+ (* 2 (glyph-height image) (window-height)) height)
177 (or (eq 'xpm image-type)
178 (and (eq 'xbm image-type)
179 (image-type-available-p 'xbm))))
180 ;; Use the new redisplay engine on Emacs 21.
181 (setq image (create-image file image-type)
182 width (image-size image)
185 (when (eq 'xbm image-type)
186 (let ((bg (face-background 'wl-highlight-logo-face))
187 (fg (face-foreground 'wl-highlight-logo-face)))
189 (plist-put (cdr image) ':background bg))
191 (plist-put (cdr image) ':foreground fg))))
192 (insert (propertize " " 'display
193 (list 'space ':align-to
194 (max 0 (round (- (window-width)
200 ((eq 'bitmap image-type)
201 ;; Use ready-composed bitmap image.
203 (let ((coding-system-for-read 'iso-2022-7bit)
204 (input-coding-system '*iso-2022-jp*))
205 (insert-file-contents file))
206 (goto-char (point-max))
213 (setq width (max width (current-column))))
214 ;; Emacs 21.1 would fail to decode composite chars
215 ;; if it has been built without fixing coding.c.
216 (when (and wl-on-emacs21
219 (let ((coding-system-for-read 'raw-text))
220 (insert-file-contents file))
221 (goto-char (point-max))
228 ;; Decode bitmap data line by line.
229 (decode-coding-region (line-beginning-position)
232 (setq width (max width (current-column)))))
233 (indent-rigidly (point-min) (point-max)
234 (max 0 (/ (1+ (- (window-width) width)) 2)))
235 (put-text-property (point-min) (point-max)
236 'face 'wl-highlight-logo-face)
237 (count-lines (point-min) (goto-char (point-max))))
238 ((eq 'xbm image-type)
239 (message "Composing a bitmap image...")
241 (bitmap-insert-xbm-file file)
243 (indent-rigidly (point-min) (point-max)
244 (max 0 (/ (1+ (- (window-width)
247 (put-text-property (point-min) (point-max)
248 'face 'wl-highlight-logo-face)
249 (message "Composing a bitmap image...done")
250 (count-lines (point-min) (goto-char (point-max))))))
251 (insert wl-logo-ascii)
252 (put-text-property (point-min) (point) 'face 'wl-highlight-logo-face)
259 (setq width (max width (current-column))))
260 (indent-rigidly (point-min) (point-max)
261 (max 0 (/ (1+ (- (window-width) width)) 2)))
262 (count-lines (point-min) (goto-char (point-max))))))
264 (defun wl-demo-insert-text (height)
265 "Insert a version and the copyright message after a logo image. HEIGHT
266 should be a number of lines that an image occupies in the buffer."
267 (let* ((height (- (window-height) height 1))
268 (text (format (cond ((<= height 2)
269 "version %s - \"%s\"\n%s")
271 "version %s - \"%s\"\n\n%s")
273 "\nversion %s - \"%s\"\n\n%s"))
274 (product-version-string (product-find 'wl-version))
275 (product-code-name (product-find 'wl-version))
276 wl-demo-copyright-notice))
278 (goto-char (point-min))
279 (insert-char ?\n (max 0 (/ (- height 4) 2)))
280 (setq start (goto-char (point-max)))
282 (let ((bg (face-background 'wl-highlight-demo-face))
283 (fg (face-foreground 'wl-highlight-demo-face)))
284 (insert (propertize text
285 'face (nconc '(variable-pitch :slant oblique)
287 (list ':background bg))
289 (list ':foreground fg))))))
291 (put-text-property start (point) 'face 'wl-highlight-demo-face))
292 (let ((fill-column (window-width)))
293 (center-region start (point)))))
295 (defun wl-demo (&optional image-type)
296 "Demo on the startup screen. IMAGE-TYPE should be a symbol which
297 overrides the variable `wl-demo-display-logo'. It will prompt user
298 for the type of image when it is called interactively with a prefix
301 (let ((selection (wl-demo-image-type-alist))
303 (if (and image-type (interactive-p))
304 (setq type (completing-read "Image type: " selection nil t)
305 image-type (when (assoc type selection)
306 (cdr (assoc type selection))))
307 (if (setq type (assoc (format "%s" (or image-type wl-demo-display-logo))
309 (setq image-type (cdr type))
310 (setq image-type (when wl-demo-display-logo
311 (cdr (car selection)))))))
312 (let ((buffer (let ((default-enable-multibyte-characters t)
314 (default-line-spacing 0))
315 (get-buffer-create "*WL Demo*"))))
316 (switch-to-buffer buffer)
317 (setq buffer-read-only nil)
318 (buffer-disable-undo)
320 (setq truncate-lines t
322 (set (make-local-variable 'tab-stop-list)
323 '(8 16 24 32 40 48 56 64 72 80 88 96 104 112 120))
324 (wl-demo-insert-text (wl-demo-insert-image image-type))
325 (set-buffer-modified-p nil)
326 (goto-char (point-min))
327 (sit-for (if (featurep 'lisp-float-type)
328 (/ (float 5) (float 10))
333 (product-provide (provide 'wl-demo) (require 'wl-version))
335 ;;; wl-demo.el ends here