(wl-message-overload-functions): Do nothing if `current-local-map' is not
[elisp/wanderlust.git] / wl / wl-demo.el
1 ;;; wl-demo.el -- Opening demo on Wanderlust.
2
3 ;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7
8 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14 ;;
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19 ;;
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24 ;;
25
26 ;;; Commentary:
27 ;;
28
29 ;;; Code:
30 ;;
31
32 (defconst wl-demo-copyright-notice
33   "Copyright (C) 1998-2000 Yuuichi Teranishi <teranisi@gohome.org>")
34
35 (require 'wl-vars)
36 (require 'wl-version)
37 (require 'wl-highlight)
38 (require 'product)
39 (product-provide (provide 'wl-demo) (require 'wl-version))
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 'tool-bar-mode 'ignore)
64   (defalias-maybe 'window-pixel-height 'ignore)
65   (defalias-maybe 'window-pixel-width 'ignore))
66
67 ;;
68 ;; demo ;-)
69 ;;
70
71 (defvar wl-logo-ascii "        o$                  oo$$$$$$ooo
72      oo$$$      o$$      o$$$\"\"\"\"\"\"$$$$$o
73   $$$$$$\"     o$$$\"    o$\"\"          \"$$$
74     $$\"      o$\"\"    o$\"              $$$
75    $\"      oo$\"     $\"                $$$
76  o$     oo\"\"$$     $                  $$
77 o$$  oo$\"  \"$$$o  $                 o$$
78 $$$$\"\"       \"$$oo$    o          o$\"
79                \"$$o   \"$$$o oooo$\"\"
80                  $$       \"\"\"\"
81                Wanderlust
82                   \"$
83 Yet Another Message Interface On Emacsen")
84
85 (eval-when-compile
86   (defmacro wl-demo-with-temp-file-buffer (file &rest forms)
87     "Create a temporary buffer, insert FILE's contents without
88 any conversions and evaluate FORMS there like `progn'."
89     ( `(with-temp-buffer
90          (let ((coding-system-for-read 'binary)
91                (input-coding-system '*noconv*)
92                auto-mode-alist
93                file-name-handler-alist
94                format-alist
95                insert-file-contents-access-hook
96                insert-file-contents-post-hook
97                insert-file-contents-pre-hook
98                interpreter-mode-alist)
99            (insert-file-contents (, file))
100            (,@ forms)))))
101   (put 'wl-demo-with-temp-file-buffer 'lisp-indent-function 1))
102
103 (eval-when-compile
104   (defmacro wl-logo-xpm ()
105     ;; (WIDTH HEIGHT DATA)
106     (let ((file (expand-file-name
107                  (concat wl-demo-icon-name ".xpm")
108                  wl-icon-dir)))
109       (if (file-exists-p file)
110           (wl-demo-with-temp-file-buffer file
111             (re-search-forward
112              (concat "\"[\t ]*\\([0-9]+\\)[\t ]+\\([0-9]+\\)"
113                      "[\t ]+[0-9]+[\t ]+[0-9]+[\t ]*\""))
114             (list 'list
115                   (string-to-number (match-string 1))
116                   (string-to-number (match-string 2))
117                   (buffer-string))))))
118   (defmacro wl-logo-xbm ()
119     ;; (WIDTH HEIGHT DATA)
120     (let ((file (expand-file-name
121                  (concat wl-demo-icon-name ".xbm")
122                  wl-icon-dir)))
123       (if (file-exists-p file)
124           (wl-demo-with-temp-file-buffer file
125             (let ((case-fold-search t)
126                   width height)
127               (search-forward "width")
128               (setq width (read (current-buffer)))
129               (goto-char (point-min))
130               (search-forward "height")
131               (setq height (read (current-buffer)))
132               (goto-char (point-min))
133               (search-forward "{")
134               (delete-region (point-min) (point))
135               (while (re-search-forward "[^0-9a-fx]+" nil t)
136                 (replace-match ""))
137               (goto-char (point-min))
138               (insert "\"")
139               (while (search-forward "0x" nil t)
140                 (replace-match "\\\\x"))
141               (goto-char (point-max))
142               (insert "\"")
143               (goto-char (point-min))
144               (list 'list width height (read (current-buffer))))))))
145   (defmacro wl-logo-bitmap ()
146     ;; (DECODED-P . DATA)
147     (let ((file (expand-file-name (concat wl-demo-icon-name ".xbm")
148                                   wl-icon-dir)))
149       (if (file-exists-p file)
150           (if (condition-case nil (require 'bitmap) (error nil))
151               (list 'cons t (bitmap-decode-xbm
152                              (bitmap-read-xbm-file file)))
153             (wl-demo-with-temp-file-buffer file
154               (list 'cons nil (buffer-string))))))))
155
156 (let ((xpm (wl-logo-xpm)))
157   (if (and xpm (or (and (featurep 'xemacs)
158                         (featurep 'xpm))
159                    (and (condition-case nil (require 'image) (error nil))
160                         (image-type-available-p 'xpm))))
161       (progn
162         (put 'wl-logo-xpm 'width (car xpm))
163         (put 'wl-logo-xpm 'height (nth 1 xpm))
164         (put 'wl-logo-xpm 'image
165              (if (featurep 'xemacs)
166                  (make-glyph (vector 'xpm ':data (nth 2 xpm)))
167                (create-image (nth 2 xpm) 'xpm t))))))
168
169 (let ((xbm (wl-logo-xbm))
170       (bm (wl-logo-bitmap)))
171   (if (and xbm (or (featurep 'xemacs)
172                    (featurep 'image)
173                    (condition-case nil (require 'bitmap) (error nil))))
174       (progn
175         (put 'wl-logo-xbm 'width (car xbm))
176         (put 'wl-logo-xbm 'height (nth 1 xbm))
177         (put 'wl-logo-xbm 'image
178              (cond
179               ((featurep 'xemacs)
180                (make-glyph (vector 'xbm ':data xbm)))
181               ((featurep 'image)
182                (create-image (nth 2 xbm) 'xbm t
183                              ':width (car xbm) ':height (nth 1 xbm)))
184               (t
185                (let ((default-enable-multibyte-characters t)
186                      (default-mc-flag t))
187                  (with-temp-buffer
188                    (let* ((cmp (if (car bm)
189                                    (cdr bm)
190                                  (insert (cdr bm))
191                                  (prog1
192                                      (bitmap-decode-xbm (bitmap-read-xbm-buffer
193                                                          (current-buffer)))
194                                    (erase-buffer))))
195                           (len (length cmp))
196                           (i 1))
197                      (insert (bitmap-compose (aref cmp 0)))
198                      (while (< i len)
199                        (insert "\n" (bitmap-compose (aref cmp i)))
200                        (setq i (1+ i)))
201                      (buffer-string))))))))))
202
203 (defun wl-demo (&optional image-type)
204   "Demo on the startup screen.
205 Optional IMAGE-TYPE overrides the variable `wl-demo-display-logo'."
206   (interactive "P")
207   (let ((demo-buf (let ((default-enable-multibyte-characters t)
208                         (default-mc-flag t)
209                         (default-line-spacing 0))
210                     (get-buffer-create "*WL Demo*"))))
211     (switch-to-buffer demo-buf)
212     (cond ((featurep 'xemacs)
213            (if (device-on-window-system-p)
214                (progn
215                  (if (boundp 'default-gutter-visible-p)
216                      (set-specifier (symbol-value 'default-gutter-visible-p)
217                                     nil demo-buf))
218                  (set-specifier (symbol-value 'scrollbar-height) 0 demo-buf)
219                  (set-specifier (symbol-value 'scrollbar-width) 0 demo-buf))))
220           ((and (> emacs-major-version 20) (display-graphic-p))
221            (make-local-hook 'kill-buffer-hook)
222            (let* ((frame (selected-frame))
223                   (toolbar (frame-parameter frame 'tool-bar-lines)))
224              (modify-frame-parameters frame '((tool-bar-lines)))
225              (add-hook
226               'kill-buffer-hook
227               (` (lambda ()
228                    (let ((frame (, frame)))
229                      (when (frame-live-p frame)
230                        (, (if (and toolbar (> toolbar 0))
231                               (` (modify-frame-parameters
232                                   frame '((tool-bar-lines . (, toolbar)))))))
233                        (set-face-background
234                         'fringe (, (face-background 'fringe frame)) frame)))))
235               nil t)
236              (set-face-background 'fringe (face-background 'default frame)
237                                   frame))))
238     (erase-buffer)
239     (setq truncate-lines t)
240     (let* ((wl-demo-display-logo
241             (if (and image-type (interactive-p))
242                 (let* ((selection '(("xbm" . xbm) ("xpm" . xpm) ("ascii")))
243                        (type (completing-read "Image type: " selection nil t)))
244                   (if (assoc type selection)
245                       (cdr (assoc type selection))
246                     t))
247               (or image-type wl-demo-display-logo)))
248            (logo (if (cond ((featurep 'xemacs)
249                             (device-on-window-system-p))
250                            ((featurep 'image)
251                             (display-graphic-p))
252                            (t window-system))
253                      (cond ((and (eq 'xbm wl-demo-display-logo)
254                                  (get 'wl-logo-xbm 'width))
255                             'wl-logo-xbm)
256                            (wl-demo-display-logo
257                             (cond ((get 'wl-logo-xpm 'width)
258                                    'wl-logo-xpm)
259                                   ((get 'wl-logo-xbm 'width)
260                                    'wl-logo-xbm))))))
261            (ww (window-width))
262            (wh (window-height))
263            rest)
264       (if logo
265           (let ((lw (get logo 'width))
266                 (lh (get logo 'height))
267                 (image (get logo 'image)))
268             (cond
269              ((featurep 'xemacs)
270               (if (eq 'wl-logo-xbm logo)
271                   (set-glyph-face image 'wl-highlight-logo-face))
272               (setq rest (- wh 1 (/ (+ (* lh wh) (window-pixel-height) -1)
273                                     (window-pixel-height))))
274               (insert-char ?\  (max 0 (/ (- (* (window-pixel-width) (1+ ww))
275                                             (* lw ww))
276                                          2 (window-pixel-width))))
277               (set-extent-end-glyph (make-extent (point) (point)) image))
278              ((featurep 'image)
279               (if (eq 'wl-logo-xbm logo)
280                   (let ((bg (face-background 'wl-highlight-logo-face))
281                         (fg (face-foreground 'wl-highlight-logo-face)))
282                     (if (stringp bg)
283                         (plist-put (cdr image) ':background bg))
284                     (if (stringp fg)
285                         (plist-put (cdr image) ':foreground fg))))
286               (setq rest (/ (- (* wh (frame-char-height)) lh 1)
287                             (frame-char-height)))
288               (insert (propertize " " 'display
289                                   (list 'space ':align-to
290                                         (max 0 (/ (- (* (frame-char-width)
291                                                         (1+ ww)) lw)
292                                                   2 (frame-char-width))))))
293               (insert-image image))
294              (t
295               (insert image)
296               (put-text-property (point-min) (point) 'face
297                                  'wl-highlight-logo-face)
298               (setq rest (/ (- (* 16 wh) lh 8) 16))
299               (indent-rigidly (point-min) (point-max)
300                               (/ (- (* 8 (1+ ww)) lw) 16))))
301             (goto-char (point-min)))
302         (insert (or wl-logo-ascii (product-name (product-find 'wl-version))))
303         (put-text-property (point-min) (point) 'face 'wl-highlight-logo-face)
304         (setq rest (- wh (count-lines (point-min) (point)) 1))
305         (let ((lw (current-column))
306               (lh (count-lines (point-min) (point))))
307           (while (progn (beginning-of-line) (not (bobp)))
308             (backward-char)
309             (setq lw (max lw (current-column))))
310           (indent-rigidly (point) (point-max) (max 0 (/ (- ww lw) 2)))))
311       (insert-char ?\n (max 0 (/ (- rest 4) 2)))
312       (goto-char (point-max))
313       (insert "\n")
314       (let ((start (point))
315             (text (format (cond ((<= rest 2)
316                                  "version %s - \"%s\"\n%s")
317                                 ((eq rest 3)
318                                  "version %s - \"%s\"\n\n%s")
319                                 (t
320                                  "\nversion %s - \"%s\"\n\n%s"))
321                           (product-version-string (product-find 'wl-version))
322                           (product-code-name (product-find 'wl-version))
323                           wl-demo-copyright-notice)))
324         (if wl-on-emacs21
325             (let ((bg (face-background 'wl-highlight-demo-face))
326                   (fg (face-foreground 'wl-highlight-demo-face)))
327               (insert (propertize text
328                                   'face (nconc '(variable-pitch)
329                                                (if (stringp bg)
330                                                    (list ':background bg))
331                                                (if (stringp fg)
332                                                    (list ':foreground fg))))))
333           (insert text)
334           (put-text-property start (point) 'face 'wl-highlight-demo-face))
335         (let ((fill-column ww))
336           (center-region start (point))))
337       (goto-char (point-min))
338       (sit-for (if (featurep 'lisp-float-type) (/ (float 5) (float 10)) 1))
339       demo-buf)))
340
341 ;;; wl-demo.el ends here