Added caution when re-install APEL, FLIM, or SEMI.
[elisp/wanderlust.git] / wl / wl-demo.el
1 ;;; wl-demo.el -- Opening demo on Wanderlust.
2
3 ;; Copyright (C) 1998,1999,2000,2001 Yuuichi Teranishi <teranisi@gohome.org>
4 ;; Copyright (C) 2000,2001 Katsumi Yamaoka <yamaoka@jpl.org>
5
6 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
7 ;;      Katsumi Yamaoka <yamaoka@jpl.org>
8 ;; Keywords: mail, net news
9
10 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
11
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)
15 ;; any later version.
16 ;;
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.
21 ;;
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.
26 ;;
27
28 ;;; Commentary:
29 ;;
30
31 ;;; Code:
32 ;;
33
34 (defconst wl-demo-copyright-notice
35   "Copyright (C) 1998-2001 Yuuichi Teranishi <teranisi@gohome.org>")
36
37 (require 'wl-vars)
38 (require 'wl-version)
39 (require 'wl-highlight)
40
41 (defconst wl-demo-icon-name (concat "wl-" (wl-version-status) "-logo"))
42
43 (eval-and-compile
44   (if wl-on-emacs21
45       ;; `display-images-p' has not been available prior to Emacs 21.0.105.
46       (defalias-maybe 'display-images-p 'display-graphic-p)))
47
48 ;; Avoid byte compile warnings.
49 (eval-when-compile
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))
70
71 ;;
72 ;; demo ;-)
73 ;;
74
75 (defvar wl-logo-ascii "\
76         o$                  oo$$$$$$ooo
77      oo$$$      o$$      o$$$\"\"\"\"\"\"$$$$$o
78   $$$$$$\"     o$$$\"    o$\"\"          \"$$$
79     $$\"      o$\"\"    o$\"              $$$
80    $\"      oo$\"     $\"                $$$
81  o$     oo\"\"$$     $                  $$
82 o$$  oo$\"  \"$$$o  $                 o$$
83 $$$$\"\"       \"$$oo$    o          o$\"
84                \"$$o   \"$$$o oooo$\"\"
85                  $$       \"\"\"\"
86                Wanderlust
87                   \"$
88 Yet Another Message Interface On Emacsen")
89
90 (eval-when-compile
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'."
94     ( `(with-temp-buffer
95          (let ((coding-system-for-read 'binary)
96                (input-coding-system '*noconv*)
97                auto-mode-alist
98                file-name-handler-alist
99                format-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))
105            (,@ forms)))))
106   (put 'wl-demo-with-temp-file-buffer 'lisp-indent-function 1))
107
108 (eval-when-compile
109   (defmacro wl-logo-xpm ()
110     ;; (WIDTH HEIGHT DATA)
111     (let ((file (expand-file-name (concat wl-demo-icon-name ".xpm")
112                                   wl-icon-dir)))
113       (if (file-exists-p file)
114           (wl-demo-with-temp-file-buffer file
115             (re-search-forward
116              (concat "\"[\t ]*\\([0-9]+\\)[\t ]+\\([0-9]+\\)"
117                      "[\t ]+[0-9]+[\t ]+[0-9]+[\t ]*\""))
118             (list 'list
119                   (string-to-number (match-string 1))
120                   (string-to-number (match-string 2))
121                   (buffer-string))))))
122   (defmacro wl-logo-xbm ()
123     ;; (WIDTH HEIGHT DATA)
124     (let ((file (expand-file-name (concat wl-demo-icon-name ".xbm")
125                                   wl-icon-dir)))
126       (if (file-exists-p file)
127           (wl-demo-with-temp-file-buffer file
128             (let ((case-fold-search t)
129                   width height)
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))
136               (search-forward "{")
137               (delete-region (point-min) (point))
138               (while (re-search-forward "[^0-9a-fx]+" nil t)
139                 (replace-match ""))
140               (goto-char (point-min))
141               (insert "\"")
142               (while (search-forward "0x" nil t)
143                 (replace-match "\\\\x"))
144               (goto-char (point-max))
145               (insert "\"")
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")
151                                   wl-icon-dir)))
152       (if (file-exists-p file)
153           (if (condition-case nil
154                   (require 'bitmap)
155                 (error 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))))))))
159
160 (let ((xpm (wl-logo-xpm)))
161   (if (and xpm
162            (or (and (featurep 'xemacs)
163                     (featurep 'xpm))
164                (condition-case nil
165                    (require 'image)
166                  (error nil))))
167       (progn
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)))
173                (condition-case nil
174                    (let ((image-types '(xpm)))
175                      (create-image (nth 2 xpm) 'xpm t))
176                  (error
177                   (put 'wl-logo-xpm 'width nil)
178                   (put 'wl-logo-xpm 'height nil)
179                   nil)))))))
180
181 (let (width height)
182   (let ((xbm (wl-logo-xbm)))
183     (setq width (car xbm)
184           height (nth 1 xbm))
185     (if (and xbm
186              (or (featurep 'xemacs)
187                  (condition-case nil
188                      (require 'image)
189                    (error nil))))
190         (progn
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))
196                  (condition-case nil
197                      (let ((image-types '(xbm)))
198                        (create-image (nth 2 xbm) 'xbm t
199                                      ':width (car xbm) ':height (nth 1 xbm)))
200                    (error
201                     (put 'wl-logo-xbm 'width nil)
202                     (put 'wl-logo-xbm 'height nil)
203                     nil)))))))
204   (if (and width
205            (not (featurep 'xemacs))
206            (condition-case nil
207                (require 'bitmap)
208              (error nil)))
209       (progn
210         (put 'wl-logo-bitmap 'width width)
211         (put 'wl-logo-bitmap 'height height)
212         (let ((default-enable-multibyte-characters t)
213               (default-mc-flag t))
214           (with-temp-buffer
215             (let* ((bm (wl-logo-bitmap))
216                    (cmp (if (car bm)
217                             (cdr bm)
218                           (insert (cdr bm))
219                           (prog1
220                               (bitmap-decode-xbm (bitmap-read-xbm-buffer
221                                                   (current-buffer)))
222                             (erase-buffer))))
223                    (len (length cmp))
224                    (i 1))
225               (insert (bitmap-compose (aref cmp 0)))
226               (while (< i len)
227                 (insert "\n" (bitmap-compose (aref cmp i)))
228                 (setq i (1+ i)))
229               (put 'wl-logo-bitmap 'image (buffer-string))))))))
230
231 (eval-when-compile
232   (defmacro wl-demo-image-type-alist ()
233     '(append (if (and (get 'wl-logo-xpm 'width)
234                       (or (and (featurep 'xemacs)
235                                (featurep 'xpm)
236                                (device-on-window-system-p))
237                           (and wl-on-emacs21
238                                (display-images-p)
239                                (image-type-available-p 'xpm))))
240                  '(("xpm" . xpm)))
241              (if (and (get 'wl-logo-xbm 'width)
242                       (or (and (featurep 'xemacs)
243                                (device-on-window-system-p))
244                           (and wl-on-emacs21
245                                (display-images-p)
246                                (image-type-available-p 'xbm))))
247                  '(("xbm" . xbm)))
248              (if (and (get 'wl-logo-bitmap 'width)
249                       (not (featurep 'xemacs))
250                       window-system
251                       (featurep 'bitmap))
252                  '(("bitmap" . bitmap)))
253              '(("ascii")))))
254
255 (defun wl-demo (&optional image-type)
256   "Demo on the startup screen.
257 Optional IMAGE-TYPE overrides the variable `wl-demo-display-logo'."
258   (interactive "P")
259   (let ((selection (wl-demo-image-type-alist))
260         type)
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))
266                             selection))
267           (setq image-type (cdr type))
268         (setq image-type (cdr (car selection))))))
269   (if image-type
270       (setq image-type (intern (format "wl-logo-%s" image-type))))
271   (let ((demo-buf (let ((default-enable-multibyte-characters t)
272                         (default-mc-flag t)
273                         (default-line-spacing 0))
274                     (get-buffer-create "*WL Demo*"))))
275     (switch-to-buffer demo-buf)
276     (erase-buffer)
277     (setq truncate-lines t
278           tab-width 8)
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)
285                          nil demo-buf))
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))
289           (wh (window-height))
290           rest)
291       (if image-type
292           (let ((lw (get image-type 'width))
293                 (lh (get image-type 'height))
294                 (image (get image-type 'image)))
295             (cond
296              ((featurep 'xemacs)
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))
302                                             (* lw ww))
303                                          2 (window-pixel-width))))
304               (set-extent-end-glyph (make-extent (point) (point)) image))
305              ((and wl-on-emacs21
306                    (display-images-p)
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)))
311                     (if (stringp bg)
312                         (plist-put (cdr image) ':background bg))
313                     (if (stringp fg)
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)
320                                                         (1+ ww)) lw)
321                                                   2 (frame-char-width))))))
322               (insert-image image))
323              (t
324               (insert 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)))
337             (backward-char)
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))
342       (insert "\n")
343       (let ((start (point))
344             (text (format (cond ((<= rest 2)
345                                  "version %s - \"%s\"\n%s")
346                                 ((eq rest 3)
347                                  "version %s - \"%s\"\n\n%s")
348                                 (t
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)))
353         (if wl-on-emacs21
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)
358                                                (if (stringp bg)
359                                                    (list ':background bg))
360                                                (if (stringp fg)
361                                                    (list ':foreground fg))))))
362           (insert text)
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))
368       demo-buf)))
369
370 (require 'product)
371 (product-provide (provide 'wl-demo) (require 'wl-version))
372
373 ;;; wl-demo.el ends here