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.
34 (defconst wl-demo-copyright-notice
35 "Copyright (C) 1998-2001 Yuuichi Teranishi <teranisi@gohome.org>")
39 (require 'wl-highlight)
41 (defconst wl-demo-icon-name (concat "wl-" (wl-version-status) "-logo"))
45 ;; `display-images-p' has not been available prior to Emacs 21.0.105.
46 (defalias-maybe 'display-images-p 'display-graphic-p)))
48 ;; Avoid byte compile warnings.
50 (defalias-maybe 'bitmap-compose 'ignore)
51 (defalias-maybe 'bitmap-decode-xbm 'ignore)
52 (defalias-maybe 'bitmap-read-xbm-buffer 'ignore)
53 (defalias-maybe 'bitmap-read-xbm-file 'ignore)
54 (defalias-maybe 'create-image 'ignore)
55 (defalias-maybe 'device-on-window-system-p 'ignore)
56 (defalias-maybe 'display-images-p 'ignore)
57 (defalias-maybe 'frame-char-height 'ignore)
58 (defalias-maybe 'frame-char-width 'ignore)
59 (defalias-maybe 'frame-parameter 'ignore)
60 (defalias-maybe 'image-type-available-p 'ignore)
61 (defalias-maybe 'insert-image 'ignore)
62 (defalias-maybe 'make-extent 'ignore)
63 (defalias-maybe 'make-glyph 'ignore)
64 (defalias-maybe 'propertize 'ignore)
65 (defalias-maybe 'set-extent-end-glyph 'ignore)
66 (defalias-maybe 'set-glyph-face 'ignore)
67 (defalias-maybe 'set-specifier 'ignore)
68 (defalias-maybe 'window-pixel-height 'ignore)
69 (defalias-maybe 'window-pixel-width 'ignore))
75 (defvar wl-logo-ascii "\
77 oo$$$ o$$ o$$$\"\"\"\"\"\"$$$$$o
78 $$$$$$\" o$$$\" o$\"\" \"$$$
82 o$$ oo$\" \"$$$o $ o$$
83 $$$$\"\" \"$$oo$ o o$\"
84 \"$$o \"$$$o oooo$\"\"
88 Yet Another Message Interface On Emacsen")
91 (defmacro wl-demo-with-temp-file-buffer (file &rest forms)
92 "Create a temporary buffer, insert FILE's contents without
93 any conversions and evaluate FORMS there like `progn'."
95 (let ((coding-system-for-read 'binary)
96 (input-coding-system '*noconv*)
98 file-name-handler-alist
100 insert-file-contents-access-hook
101 insert-file-contents-post-hook
102 insert-file-contents-pre-hook
103 interpreter-mode-alist)
104 (insert-file-contents (, file))
106 (put 'wl-demo-with-temp-file-buffer 'lisp-indent-function 1))
109 (defmacro wl-logo-xpm ()
110 ;; (WIDTH HEIGHT DATA)
111 (let ((file (expand-file-name (concat wl-demo-icon-name ".xpm")
113 (if (file-exists-p file)
114 (wl-demo-with-temp-file-buffer file
116 (concat "\"[\t ]*\\([0-9]+\\)[\t ]+\\([0-9]+\\)"
117 "[\t ]+[0-9]+[\t ]+[0-9]+[\t ]*\""))
119 (string-to-number (match-string 1))
120 (string-to-number (match-string 2))
122 (defmacro wl-logo-xbm ()
123 ;; (WIDTH HEIGHT DATA)
124 (let ((file (expand-file-name (concat wl-demo-icon-name ".xbm")
126 (if (file-exists-p file)
127 (wl-demo-with-temp-file-buffer file
128 (let ((case-fold-search t)
130 (search-forward "width")
131 (setq width (read (current-buffer)))
132 (goto-char (point-min))
133 (search-forward "height")
134 (setq height (read (current-buffer)))
135 (goto-char (point-min))
137 (delete-region (point-min) (point))
138 (while (re-search-forward "[^0-9a-fx]+" nil t)
140 (goto-char (point-min))
142 (while (search-forward "0x" nil t)
143 (replace-match "\\\\x"))
144 (goto-char (point-max))
146 (goto-char (point-min))
147 (list 'list width height (read (current-buffer))))))))
148 (defmacro wl-logo-bitmap ()
149 ;; (DECODED-P . DATA)
150 (let ((file (expand-file-name (concat wl-demo-icon-name ".xbm")
152 (if (file-exists-p file)
153 (if (condition-case nil
156 (list 'cons t (bitmap-decode-xbm (bitmap-read-xbm-file file)))
157 (wl-demo-with-temp-file-buffer file
158 (list 'cons nil (buffer-string))))))))
160 (let ((xpm (wl-logo-xpm)))
162 (or (and (featurep 'xemacs)
168 (put 'wl-logo-xpm 'width (car xpm))
169 (put 'wl-logo-xpm 'height (nth 1 xpm))
170 (put 'wl-logo-xpm 'image
171 (if (featurep 'xemacs)
172 (make-glyph (vector 'xpm ':data (nth 2 xpm)))
174 (let ((image-types '(xpm)))
175 (create-image (nth 2 xpm) 'xpm t))
177 (put 'wl-logo-xpm 'width nil)
178 (put 'wl-logo-xpm 'height nil)
182 (let ((xbm (wl-logo-xbm)))
183 (setq width (car xbm)
186 (or (featurep 'xemacs)
191 (put 'wl-logo-xbm 'width width)
192 (put 'wl-logo-xbm 'height height)
193 (put 'wl-logo-xbm 'image
194 (if (featurep 'xemacs)
195 (make-glyph (vector 'xbm ':data xbm))
197 (let ((image-types '(xbm)))
198 (create-image (nth 2 xbm) 'xbm t
199 ':width (car xbm) ':height (nth 1 xbm)))
201 (put 'wl-logo-xbm 'width nil)
202 (put 'wl-logo-xbm 'height nil)
205 (not (featurep 'xemacs))
210 (put 'wl-logo-bitmap 'width width)
211 (put 'wl-logo-bitmap 'height height)
212 (let ((default-enable-multibyte-characters t)
215 (let* ((bm (wl-logo-bitmap))
220 (bitmap-decode-xbm (bitmap-read-xbm-buffer
225 (insert (bitmap-compose (aref cmp 0)))
227 (insert "\n" (bitmap-compose (aref cmp i)))
229 (put 'wl-logo-bitmap 'image (buffer-string))))))))
232 (defmacro wl-demo-image-type-alist ()
233 '(append (if (and (get 'wl-logo-xpm 'width)
234 (or (and (featurep 'xemacs)
236 (device-on-window-system-p))
239 (image-type-available-p 'xpm))))
241 (if (and (get 'wl-logo-xbm 'width)
242 (or (and (featurep 'xemacs)
243 (device-on-window-system-p))
246 (image-type-available-p 'xbm))))
248 (if (and (get 'wl-logo-bitmap 'width)
249 (not (featurep 'xemacs))
252 '(("bitmap" . bitmap)))
255 (defun wl-demo (&optional image-type)
256 "Demo on the startup screen.
257 Optional IMAGE-TYPE overrides the variable `wl-demo-display-logo'."
259 (let ((selection (wl-demo-image-type-alist))
261 (if (and image-type (interactive-p))
262 (setq type (completing-read "Image type: " selection nil t)
263 image-type (if (assoc type selection)
264 (cdr (assoc type selection))))
265 (if (setq type (assoc (format "%s" (or image-type wl-demo-display-logo))
267 (setq image-type (cdr type))
268 (setq image-type (cdr (car selection))))))
270 (setq image-type (intern (format "wl-logo-%s" image-type))))
271 (let ((demo-buf (let ((default-enable-multibyte-characters t)
273 (default-line-spacing 0))
274 (get-buffer-create "*WL Demo*"))))
275 (switch-to-buffer demo-buf)
277 (setq truncate-lines t
279 (set (make-local-variable 'tab-stop-list)
280 '(8 16 24 32 40 48 56 64 72 80 88 96 104 112 120))
281 (when (and (featurep 'xemacs)
282 (device-on-window-system-p))
283 (if (boundp 'default-gutter-visible-p)
284 (set-specifier (symbol-value 'default-gutter-visible-p)
286 (set-specifier (symbol-value 'scrollbar-height) 0 demo-buf)
287 (set-specifier (symbol-value 'scrollbar-width) 0 demo-buf))
288 (let ((ww (window-width))
292 (let ((lw (get image-type 'width))
293 (lh (get image-type 'height))
294 (image (get image-type 'image)))
297 (if (eq 'wl-logo-xbm image-type)
298 (set-glyph-face image 'wl-highlight-logo-face))
299 (setq rest (- wh 1 (/ (+ (* lh wh) (window-pixel-height) -1)
300 (window-pixel-height))))
301 (insert-char ?\ (max 0 (/ (- (* (window-pixel-width) (1+ ww))
303 2 (window-pixel-width))))
304 (set-extent-end-glyph (make-extent (point) (point)) image))
307 (not (eq 'wl-logo-bitmap image-type)))
308 (if (eq 'wl-logo-xbm image-type)
309 (let ((bg (face-background 'wl-highlight-logo-face))
310 (fg (face-foreground 'wl-highlight-logo-face)))
312 (plist-put (cdr image) ':background bg))
314 (plist-put (cdr image) ':foreground fg))))
315 (setq rest (/ (- (* wh (frame-char-height)) lh 1)
316 (frame-char-height)))
317 (insert (propertize " " 'display
318 (list 'space ':align-to
319 (max 0 (/ (- (* (frame-char-width)
321 2 (frame-char-width))))))
322 (insert-image image))
325 (put-text-property (point-min) (point) 'face
326 'wl-highlight-logo-face)
327 (setq rest (/ (- (* 16 wh) lh 8) 16))
328 (indent-rigidly (point-min) (point-max)
329 (/ (- (* 8 (1+ ww)) lw) 16))))
330 (goto-char (point-min)))
331 (insert (or wl-logo-ascii (product-name (product-find 'wl-version))))
332 (put-text-property (point-min) (point) 'face 'wl-highlight-logo-face)
333 (setq rest (- wh (count-lines (point-min) (point)) 1))
334 (let ((lw (current-column))
335 (lh (count-lines (point-min) (point))))
336 (while (progn (beginning-of-line) (not (bobp)))
338 (setq lw (max lw (current-column))))
339 (indent-rigidly (point) (point-max) (max 0 (/ (- ww lw) 2)))))
340 (insert-char ?\n (max 0 (/ (- rest 4) 2)))
341 (goto-char (point-max))
343 (let ((start (point))
344 (text (format (cond ((<= rest 2)
345 "version %s - \"%s\"\n%s")
347 "version %s - \"%s\"\n\n%s")
349 "\nversion %s - \"%s\"\n\n%s"))
350 (product-version-string (product-find 'wl-version))
351 (product-code-name (product-find 'wl-version))
352 wl-demo-copyright-notice)))
354 (let ((bg (face-background 'wl-highlight-demo-face))
355 (fg (face-foreground 'wl-highlight-demo-face)))
356 (insert (propertize text
357 'face (nconc '(variable-pitch :slant oblique)
359 (list ':background bg))
361 (list ':foreground fg))))))
363 (put-text-property start (point) 'face 'wl-highlight-demo-face))
364 (let ((fill-column ww))
365 (center-region start (point))))
366 (goto-char (point-min))
367 (sit-for (if (featurep 'lisp-float-type) (/ (float 5) (float 10)) 1))
371 (product-provide (provide 'wl-demo) (require 'wl-version))
373 ;;; wl-demo.el ends here