* wl-e21.el (wl-biff-init-icons): Don't generate icons of the display does not
[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 ;; Avoid byte compile warnings.
44 (eval-when-compile
45   (defalias-maybe 'bitmap-compose 'ignore)
46   (defalias-maybe 'bitmap-decode-xbm 'ignore)
47   (defalias-maybe 'bitmap-read-xbm-buffer 'ignore)
48   (defalias-maybe 'bitmap-read-xbm-file 'ignore)
49   (defalias-maybe 'create-image 'ignore)
50   (defalias-maybe 'device-on-window-system-p 'ignore)
51   (defalias-maybe 'display-graphic-p 'ignore)
52   (defalias-maybe 'frame-char-height 'ignore)
53   (defalias-maybe 'frame-char-width 'ignore)
54   (defalias-maybe 'frame-parameter 'ignore)
55   (defalias-maybe 'image-type-available-p 'ignore)
56   (defalias-maybe 'insert-image 'ignore)
57   (defalias-maybe 'make-extent 'ignore)
58   (defalias-maybe 'make-glyph 'ignore)
59   (defalias-maybe 'propertize 'ignore)
60   (defalias-maybe 'set-extent-end-glyph 'ignore)
61   (defalias-maybe 'set-glyph-face 'ignore)
62   (defalias-maybe 'set-specifier 'ignore)
63   (defalias-maybe 'window-pixel-height 'ignore)
64   (defalias-maybe 'window-pixel-width 'ignore))
65
66 ;;
67 ;; demo ;-)
68 ;;
69
70 (defvar wl-logo-ascii "        o$                  oo$$$$$$ooo
71      oo$$$      o$$      o$$$\"\"\"\"\"\"$$$$$o
72   $$$$$$\"     o$$$\"    o$\"\"          \"$$$
73     $$\"      o$\"\"    o$\"              $$$
74    $\"      oo$\"     $\"                $$$
75  o$     oo\"\"$$     $                  $$
76 o$$  oo$\"  \"$$$o  $                 o$$
77 $$$$\"\"       \"$$oo$    o          o$\"
78                \"$$o   \"$$$o oooo$\"\"
79                  $$       \"\"\"\"
80                Wanderlust
81                   \"$
82 Yet Another Message Interface On Emacsen")
83
84 (eval-when-compile
85   (defmacro wl-demo-with-temp-file-buffer (file &rest forms)
86     "Create a temporary buffer, insert FILE's contents without
87 any conversions and evaluate FORMS there like `progn'."
88     ( `(with-temp-buffer
89          (let ((coding-system-for-read 'binary)
90                (input-coding-system '*noconv*)
91                auto-mode-alist
92                file-name-handler-alist
93                format-alist
94                insert-file-contents-access-hook
95                insert-file-contents-post-hook
96                insert-file-contents-pre-hook
97                interpreter-mode-alist)
98            (insert-file-contents (, file))
99            (,@ forms)))))
100   (put 'wl-demo-with-temp-file-buffer 'lisp-indent-function 1))
101
102 (eval-when-compile
103   (defmacro wl-logo-xpm ()
104     ;; (WIDTH HEIGHT DATA)
105     (let ((file (expand-file-name
106                  (concat wl-demo-icon-name ".xpm")
107                  wl-icon-dir)))
108       (if (file-exists-p file)
109           (wl-demo-with-temp-file-buffer file
110             (re-search-forward
111              (concat "\"[\t ]*\\([0-9]+\\)[\t ]+\\([0-9]+\\)"
112                      "[\t ]+[0-9]+[\t ]+[0-9]+[\t ]*\""))
113             (list 'list
114                   (string-to-number (match-string 1))
115                   (string-to-number (match-string 2))
116                   (buffer-string))))))
117   (defmacro wl-logo-xbm ()
118     ;; (WIDTH HEIGHT DATA)
119     (let ((file (expand-file-name
120                  (concat wl-demo-icon-name ".xbm")
121                  wl-icon-dir)))
122       (if (file-exists-p file)
123           (wl-demo-with-temp-file-buffer file
124             (let ((case-fold-search t)
125                   width height)
126               (search-forward "width")
127               (setq width (read (current-buffer)))
128               (goto-char (point-min))
129               (search-forward "height")
130               (setq height (read (current-buffer)))
131               (goto-char (point-min))
132               (search-forward "{")
133               (delete-region (point-min) (point))
134               (while (re-search-forward "[^0-9a-fx]+" nil t)
135                 (replace-match ""))
136               (goto-char (point-min))
137               (insert "\"")
138               (while (search-forward "0x" nil t)
139                 (replace-match "\\\\x"))
140               (goto-char (point-max))
141               (insert "\"")
142               (goto-char (point-min))
143               (list 'list width height (read (current-buffer))))))))
144   (defmacro wl-logo-bitmap ()
145     ;; (DECODED-P . DATA)
146     (let ((file (expand-file-name (concat wl-demo-icon-name ".xbm")
147                                   wl-icon-dir)))
148       (if (file-exists-p file)
149           (if (condition-case nil (require 'bitmap) (error nil))
150               (list 'cons t (bitmap-decode-xbm
151                              (bitmap-read-xbm-file file)))
152             (wl-demo-with-temp-file-buffer file
153               (list 'cons nil (buffer-string))))))))
154
155 (let ((xpm (wl-logo-xpm)))
156   (if (and xpm (or (and (featurep 'xemacs)
157                         (featurep 'xpm))
158                    (and (condition-case nil (require 'image) (error nil))
159                         (image-type-available-p 'xpm))))
160       (progn
161         (put 'wl-logo-xpm 'width (car xpm))
162         (put 'wl-logo-xpm 'height (nth 1 xpm))
163         (put 'wl-logo-xpm 'image
164              (if (featurep 'xemacs)
165                  (make-glyph (vector 'xpm ':data (nth 2 xpm)))
166                (create-image (nth 2 xpm) 'xpm t))))))
167
168 (let ((xbm (wl-logo-xbm))
169       (bm (wl-logo-bitmap)))
170   (if (and xbm (or (featurep 'xemacs)
171                    (featurep 'image)
172                    (condition-case nil (require 'bitmap) (error nil))))
173       (progn
174         (put 'wl-logo-xbm 'width (car xbm))
175         (put 'wl-logo-xbm 'height (nth 1 xbm))
176         (put 'wl-logo-xbm 'image
177              (cond
178               ((featurep 'xemacs)
179                (make-glyph (vector 'xbm ':data xbm)))
180               ((featurep 'image)
181                (create-image (nth 2 xbm) 'xbm t
182                              ':width (car xbm) ':height (nth 1 xbm)))
183               (t
184                (let ((default-enable-multibyte-characters t)
185                      (default-mc-flag t))
186                  (with-temp-buffer
187                    (let* ((cmp (if (car bm)
188                                    (cdr bm)
189                                  (insert (cdr bm))
190                                  (prog1
191                                      (bitmap-decode-xbm (bitmap-read-xbm-buffer
192                                                          (current-buffer)))
193                                    (erase-buffer))))
194                           (len (length cmp))
195                           (i 1))
196                      (insert (bitmap-compose (aref cmp 0)))
197                      (while (< i len)
198                        (insert "\n" (bitmap-compose (aref cmp i)))
199                        (setq i (1+ i)))
200                      (buffer-string))))))))))
201
202 (defun wl-demo (&optional image-type)
203   "Demo on the startup screen.
204 Optional IMAGE-TYPE overrides the variable `wl-demo-display-logo'."
205   (interactive "P")
206   (if (and image-type (interactive-p))
207       (let* ((selection (append
208                          (if (and (get 'wl-logo-xbm 'width)
209                                   (cond ((featurep 'xemacs)
210                                          (device-on-window-system-p))
211                                         (wl-on-emacs21
212                                          (display-graphic-p))
213                                         (t window-system)))
214                              '(("xbm" . xbm)))
215                          (if (and (get 'wl-logo-xpm 'width)
216                                   (or (and (featurep 'xemacs)
217                                            (featurep 'xpm)
218                                            (device-on-window-system-p))
219                                       (and wl-on-emacs21
220                                            (display-graphic-p)
221                                            (featurep 'image)
222                                            (image-type-available-p 'xpm))))
223                              '(("xpm" . xpm)))
224                          '(("ascii"))))
225              (type (completing-read "Image type: " selection nil t)))
226         (setq image-type (if (assoc type selection)
227                              (cdr (assoc type selection)))))
228     (setq image-type (or image-type wl-demo-display-logo)))
229   (let ((demo-buf (let ((default-enable-multibyte-characters t)
230                         (default-mc-flag t)
231                         (default-line-spacing 0))
232                     (get-buffer-create "*WL Demo*"))))
233     (switch-to-buffer demo-buf)
234     (erase-buffer)
235     (setq truncate-lines t)
236     (cond ((featurep 'xemacs)
237            (if (device-on-window-system-p)
238                (progn
239                  (if (boundp 'default-gutter-visible-p)
240                      (set-specifier (symbol-value 'default-gutter-visible-p)
241                                     nil demo-buf))
242                  (set-specifier (symbol-value 'scrollbar-height) 0 demo-buf)
243                  (set-specifier (symbol-value 'scrollbar-width) 0 demo-buf))))
244           ((and wl-on-emacs21 (display-graphic-p))
245            (make-local-hook 'kill-buffer-hook)
246            (let* ((frame (selected-frame))
247                   (toolbar (frame-parameter frame 'tool-bar-lines)))
248              (modify-frame-parameters frame '((tool-bar-lines)))
249              (add-hook
250               'kill-buffer-hook
251               (` (lambda ()
252                    (let ((frame (, frame)))
253                      (when (frame-live-p frame)
254                        (, (if (and toolbar (> toolbar 0))
255                               (` (modify-frame-parameters
256                                   frame '((tool-bar-lines . (, toolbar)))))))
257                        (set-face-background
258                         'fringe (, (face-background 'fringe frame)) frame)))))
259               nil t)
260              (set-face-background 'fringe (face-background 'default frame)
261                                   frame))))
262     (let ((logo (cond ((eq 'xbm image-type)
263                        (if (and (get 'wl-logo-xbm 'width)
264                                 (cond ((featurep 'xemacs)
265                                        (device-on-window-system-p))
266                                       (wl-on-emacs21
267                                        (display-graphic-p))
268                                       (t window-system)))
269                            'wl-logo-xbm))
270                       ((eq 'xpm image-type)
271                        (if (and (get 'wl-logo-xpm 'width)
272                                 (or (and (featurep 'xemacs)
273                                          (featurep 'xpm)
274                                          (device-on-window-system-p))
275                                     (and wl-on-emacs21
276                                          (display-graphic-p)
277                                          (featurep 'image)
278                                          (image-type-available-p 'xpm))))
279                            'wl-logo-xpm))))
280           (ww (window-width))
281           (wh (window-height))
282           rest)
283       (if logo
284           (let ((lw (get logo 'width))
285                 (lh (get logo 'height))
286                 (image (get logo 'image)))
287             (cond
288              ((featurep 'xemacs)
289               (if (eq 'wl-logo-xbm logo)
290                   (set-glyph-face image 'wl-highlight-logo-face))
291               (setq rest (- wh 1 (/ (+ (* lh wh) (window-pixel-height) -1)
292                                     (window-pixel-height))))
293               (insert-char ?\  (max 0 (/ (- (* (window-pixel-width) (1+ ww))
294                                             (* lw ww))
295                                          2 (window-pixel-width))))
296               (set-extent-end-glyph (make-extent (point) (point)) image))
297              ((and wl-on-emacs21
298                    (display-graphic-p))
299               (if (eq 'wl-logo-xbm logo)
300                   (let ((bg (face-background 'wl-highlight-logo-face))
301                         (fg (face-foreground 'wl-highlight-logo-face)))
302                     (if (stringp bg)
303                         (plist-put (cdr image) ':background bg))
304                     (if (stringp fg)
305                         (plist-put (cdr image) ':foreground fg))))
306               (setq rest (/ (- (* wh (frame-char-height)) lh 1)
307                             (frame-char-height)))
308               (insert (propertize " " 'display
309                                   (list 'space ':align-to
310                                         (max 0 (/ (- (* (frame-char-width)
311                                                         (1+ ww)) lw)
312                                                   2 (frame-char-width))))))
313               (insert-image image))
314              (t
315               (insert image)
316               (put-text-property (point-min) (point) 'face
317                                  'wl-highlight-logo-face)
318               (setq rest (/ (- (* 16 wh) lh 8) 16))
319               (indent-rigidly (point-min) (point-max)
320                               (/ (- (* 8 (1+ ww)) lw) 16))))
321             (goto-char (point-min)))
322         (insert (or wl-logo-ascii (product-name (product-find 'wl-version))))
323         (put-text-property (point-min) (point) 'face 'wl-highlight-logo-face)
324         (setq rest (- wh (count-lines (point-min) (point)) 1))
325         (let ((lw (current-column))
326               (lh (count-lines (point-min) (point))))
327           (while (progn (beginning-of-line) (not (bobp)))
328             (backward-char)
329             (setq lw (max lw (current-column))))
330           (indent-rigidly (point) (point-max) (max 0 (/ (- ww lw) 2)))))
331       (insert-char ?\n (max 0 (/ (- rest 4) 2)))
332       (goto-char (point-max))
333       (insert "\n")
334       (let ((start (point))
335             (text (format (cond ((<= rest 2)
336                                  "version %s - \"%s\"\n%s")
337                                 ((eq rest 3)
338                                  "version %s - \"%s\"\n\n%s")
339                                 (t
340                                  "\nversion %s - \"%s\"\n\n%s"))
341                           (product-version-string (product-find 'wl-version))
342                           (product-code-name (product-find 'wl-version))
343                           wl-demo-copyright-notice)))
344         (if wl-on-emacs21
345             (let ((bg (face-background 'wl-highlight-demo-face))
346                   (fg (face-foreground 'wl-highlight-demo-face)))
347               (insert (propertize text
348                                   'face (nconc '(variable-pitch :slant oblique)
349                                                (if (stringp bg)
350                                                    (list ':background bg))
351                                                (if (stringp fg)
352                                                    (list ':foreground fg))))))
353           (insert text)
354           (put-text-property start (point) 'face 'wl-highlight-demo-face))
355         (let ((fill-column ww))
356           (center-region start (point))))
357       (goto-char (point-min))
358       (sit-for (if (featurep 'lisp-float-type) (/ (float 5) (float 10)) 1))
359       demo-buf)))
360
361 (require 'product)
362 (product-provide (provide 'wl-demo) (require 'wl-version))
363
364 ;;; wl-demo.el ends here