1 ;;; wl-demo.el --- Opening demo on Wanderlust
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004
4 ;; Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Copyright (C) 2000,2001,2004
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
8 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
9 ;; Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; Keywords: mail, net news
12 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
14 ;; This program is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
33 (defconst wl-demo-copyright-notice
34 "Copyright (C) 1998-2012 Yuuichi Teranishi <teranisi@gohome.org>"
35 "A declaration of the copyright on Wanderlust.")
42 (require 'wl-highlight)
44 (defun wl-demo-icon-name ()
45 "A function to determine logo file name."
47 (dolist (pair wl-demo-icon-name-alist)
48 (when (eval (car pair))
49 (throw 'found (eval (cdr pair)))))))
51 (defvar wl-logo-ascii "\
53 oo$$$ o$$ o$$$\"\"\"\"\"\"$$$$$o
54 $$$$$$\" o$$$\" o$\"\" \"$$$
58 o$$ oo$\" \"$$$o $ o$$
59 $$$$\"\" \"$$oo$ o o$\"
60 \"$$o \"$$$o oooo$\"\"
64 Yet Another Message Interface On Emacsen"
65 "Ascii picture used to splash the startup screen.")
69 ;; `display-images-p' has not been available in Emacs versions
70 ;; prior to Emacs 21.0.105.
71 (defalias-maybe 'display-images-p 'display-graphic-p)))
73 ;; Avoid byte compile warnings.
75 (autoload 'bitmap-insert-xbm-file "bitmap" nil t)
76 (autoload 'create-image "image")
77 (autoload 'device-on-window-system-p "device")
78 (autoload 'image-type-available-p "image")
79 (autoload 'insert-image "image")
80 (autoload 'make-glyph "glyphs")
81 (autoload 'set-glyph-face "glyphs")
82 (autoload 'set-specifier "specifier")
83 (defalias-maybe 'face-background-name 'ignore)
84 (defalias-maybe 'frame-char-height 'ignore)
85 (defalias-maybe 'frame-char-width 'ignore)
86 (defalias-maybe 'glyph-height 'ignore)
87 (defalias-maybe 'glyph-width 'ignore)
88 (defalias-maybe 'image-size 'ignore)
89 (defalias-maybe 'make-extent 'ignore)
90 (defalias-maybe 'propertize 'ignore)
91 (defalias-maybe 'set-extent-end-glyph 'ignore)
92 (defalias-maybe 'window-pixel-height 'ignore)
93 (defalias-maybe 'window-pixel-width 'ignore))
95 (defvar wl-demo-bitmap-mule-available-p 'unknown
96 "Internal variable to say whether the BITMAP-MULE package is available.")
98 (defun wl-demo-image-type-alist ()
99 "Return an alist of available logo image types on the current frame."
100 (if (or (and (featurep 'xemacs)
101 (device-on-window-system-p))
104 (when (or (and (featurep 'xemacs)
108 (image-type-available-p 'xpm)))
111 (when (or (featurep 'xemacs)
114 (image-type-available-p 'xbm))
115 (eq t wl-demo-bitmap-mule-available-p)
116 (and (eq 'unknown wl-demo-bitmap-mule-available-p)
117 (module-installed-p 'bitmap)
118 (setq wl-demo-bitmap-mule-available-p t)))
121 (when (and (not (featurep 'xemacs))
122 (or (eq t wl-demo-bitmap-mule-available-p)
123 (and (eq 'unknown wl-demo-bitmap-mule-available-p)
124 (module-installed-p 'bitmap)
125 (setq wl-demo-bitmap-mule-available-p t))))
126 '("bitmap" . bitmap))))
127 (if (and wl-on-emacs21
128 (image-type-available-p 'xbm))
129 ;; Prefer xbm rather than bitmap on Emacs 21.
130 (delq nil (list xpm xbm bitmap '("ascii")))
131 (delq nil (list xpm bitmap xbm '("ascii")))))
134 (defun wl-demo-image-filter (file type)
135 "Get filtered image data.
136 FILE is the image file name.
137 TYPE is the filter function."
138 (let ((filter (catch 'found
139 (dolist (pair wl-demo-image-filter-alist)
140 (when (eq (car pair) type)
141 (throw 'found (cdr pair)))))))
143 (set-buffer-multibyte nil)
144 (insert-file-contents file)
145 (goto-char (point-min))
150 (defun wl-demo-insert-image (image-type)
151 "Insert a logo image at the point and position it to be centered.
152 IMAGE-TYPE specifies what a type of image should be displayed.
153 Return a number of lines that an image occupies in the buffer."
154 (let ((file (cond ((eq 'xpm image-type)
155 (concat (wl-demo-icon-name) ".xpm"))
156 ((eq 'bitmap image-type)
157 (concat (wl-demo-icon-name) ".img"))
158 ((eq 'xbm image-type)
159 (concat (wl-demo-icon-name) ".xbm"))))
161 (when (featurep 'xemacs)
162 (when (boundp 'default-gutter-visible-p)
163 (set-specifier (symbol-value 'default-gutter-visible-p)
164 nil (current-buffer)))
165 (when (featurep 'scrollbar)
166 (set-specifier (symbol-value 'scrollbar-height) 0 (current-buffer))
167 (set-specifier (symbol-value 'scrollbar-width) 0 (current-buffer))))
169 (if (and wl-icon-directory
170 (file-directory-p wl-icon-directory))
171 (setq file (expand-file-name file wl-icon-directory))
172 (message "You have to specify the value of `wl-icon-directory'")
174 (if (file-exists-p file)
175 (if (file-readable-p file)
177 (message "Permission denied: %s" file)
179 (message "File not found: %s" file)
182 (cond ((featurep 'xemacs)
183 (setq width (window-pixel-width)
184 height (window-pixel-height)
186 (if (eq image-type 'xbm)
187 (vector image-type ':file file)
188 (vector image-type ':data
189 (wl-demo-image-filter
191 (when (eq 'xbm image-type)
192 (set-glyph-face image 'wl-highlight-logo-face))
193 (insert-char (string-to-char " ")
194 (max 0 (/ (+ (* (- width (glyph-width image))
195 (window-width)) width)
197 (set-extent-end-glyph (make-extent (point) (point)) image)
199 (/ (+ (* 2 (glyph-height image) (window-height)) height)
202 (or (eq 'xpm image-type)
203 (and (eq 'xbm image-type)
204 (image-type-available-p 'xbm))))
205 ;; Use the new redisplay engine on Emacs 21.
206 (setq image (create-image (wl-demo-image-filter file
209 width (image-size image)
212 (when (eq 'xbm image-type)
213 (let ((bg (face-background 'wl-highlight-demo-face))
214 (fg (face-foreground 'wl-highlight-logo-face)))
216 (plist-put (cdr image) ':background bg))
218 (plist-put (cdr image) ':foreground fg))))
219 (insert (propertize " " 'display
220 (list 'space ':align-to
221 (max 0 (round (- (window-width)
227 ((eq 'bitmap image-type)
228 ;; Use ready-composed bitmap image.
230 (let ((coding-system-for-read 'iso-2022-7bit)
231 (input-coding-system '*iso-2022-jp*))
232 (insert-file-contents file))
233 (goto-char (point-max))
237 ;; Emacs 21.x may fail on computing the end of the
238 ;; column if there're bitmap characters.
243 ;;; (setq width (max width (current-column))))
248 (setq width (min width (current-column))))
250 ;; Emacs 21.1 would fail to decode composite chars
251 ;; if it has been built without fixing coding.c.
252 (when (and wl-on-emacs21
255 (let ((coding-system-for-read 'raw-text))
256 (insert-file-contents file))
257 (goto-char (point-max))
264 ;; Decode bitmap data line by line.
265 (decode-coding-region (line-beginning-position)
268 (setq width (max width (current-column)))))
269 (indent-rigidly (point-min) (point-max)
270 (max 0 (/ (1+ (- (window-width) width)) 2)))
271 (put-text-property (point-min) (point-max) 'fixed-width t)
272 (count-lines (point-min) (goto-char (point-max))))
273 ((eq 'xbm image-type)
274 (message "Composing a bitmap image...")
276 (bitmap-insert-xbm-file file)
278 (indent-rigidly (point-min) (point-max)
279 (max 0 (/ (1+ (- (window-width)
282 (put-text-property (point-min) (point-max) 'fixed-width t)
283 (message "Composing a bitmap image...done")
284 (count-lines (point-min) (goto-char (point-max))))))
285 (insert wl-logo-ascii)
292 (setq width (max width (current-column))))
293 (indent-rigidly (point-min) (point-max)
294 (max 0 (/ (1+ (- (window-width) width)) 2)))
295 (put-text-property (point-min) (point-max) 'fixed-width t)
296 (count-lines (point-min) (goto-char (point-max))))))
298 (defun wl-demo-setup-properties ()
299 "Set up properties of the demo buffer."
302 ;; I think there should be a better way to set face background
303 ;; for the buffer only. But I don't know how to do it on Emacs21.
304 (goto-char (point-max))
305 (dotimes (i (- (window-height)
306 (count-lines (point-min) (point))))
308 (let* ((fg (face-foreground 'wl-highlight-demo-face))
309 (bg (face-background 'wl-highlight-demo-face))
310 (oblique (nconc '(variable-pitch :slant oblique)
312 (list ':background bg))
314 (list ':foreground fg))))
315 (start (text-property-any (point-min) (point-max) 'fixed-width t))
319 (put-text-property (point-min) start 'face oblique)
320 (setq end (or (text-property-not-all start (point-max)
323 (put-text-property start end 'face
324 (nconc '(wl-highlight-logo-face)
326 (list ':background bg))))
327 (put-text-property end (point-max) 'face oblique))
328 (put-text-property (point-min) (point-max) 'face oblique))))
329 ((and (featurep 'xemacs)
330 (face-background-name 'wl-highlight-demo-face))
331 (set-face-background 'default
332 (face-background-name 'wl-highlight-demo-face)
335 (goto-char (point-max))
336 (dotimes (i (- (window-height)
337 (count-lines (point-min) (point))))
339 (let ((start (text-property-any (point-min) (point-max) 'fixed-width t))
343 (put-text-property (point-min) start 'face 'wl-highlight-demo-face)
344 (setq end (or (text-property-not-all start (point-max)
347 (put-text-property start end 'face 'wl-highlight-logo-face)
348 (put-text-property end (point-max) 'face 'wl-highlight-demo-face))
349 (put-text-property (point-min) (point-max)
350 'face 'wl-highlight-demo-face))))))
352 (defun wl-demo-insert-text (height)
353 "Insert a version and the copyright message after a logo image. HEIGHT
354 should be a number of lines that an image occupies in the buffer."
355 (let* ((height (- (window-height) height 1))
356 (text (format (cond ((<= height 2)
357 "version %s - \"%s\"\n%s\n")
359 "version %s - \"%s\"\n\n%s\n")
361 "\nversion %s - \"%s\"\n\n%s\n"))
362 (product-version-string (product-find 'wl-version))
363 (product-code-name (product-find 'wl-version))
364 wl-demo-copyright-notice))
366 (goto-char (point-min))
367 (insert-char ?\n (max 0 (/ (- height 4) 2)))
368 (setq start (goto-char (point-max)))
370 (let ((fill-column (window-width)))
371 (center-region start (point)))))
373 (defun wl-demo (&optional image-type)
374 "Demo on the startup screen. IMAGE-TYPE should be a symbol which
375 overrides the variable `wl-demo-display-logo'. It will prompt user
376 for the type of image when it is called interactively with a prefix
379 (let ((selection (wl-demo-image-type-alist))
381 (if (and image-type (interactive-p))
382 (setq type (completing-read "Image type: " selection nil t)
383 image-type (when (assoc type selection)
384 (cdr (assoc type selection))))
385 (if (setq type (assoc (format "%s" (or image-type wl-demo-display-logo))
387 (setq image-type (cdr type))
388 (setq image-type (when wl-demo-display-logo
389 (cdr (car selection)))))))
390 (let ((buffer (let ((default-enable-multibyte-characters t)
392 (default-line-spacing 0))
393 (get-buffer-create "*WL Demo*"))))
394 (switch-to-buffer buffer)
395 (setq buffer-read-only nil)
396 (buffer-disable-undo)
398 (setq truncate-lines t
400 (set (make-local-variable 'tab-stop-list)
401 '(8 16 24 32 40 48 56 64 72 80 88 96 104 112 120))
402 (wl-demo-insert-text (wl-demo-insert-image image-type))
403 (wl-demo-setup-properties)
404 (set-buffer-modified-p nil)
405 (goto-char (point-min))
406 (sit-for (if (featurep 'lisp-float-type)
407 (/ (float 5) (float 10))
411 ;; Prune functions provided temporarily to avoid compile warnings.
413 (dolist (fn '(face-background-name
414 frame-char-height frame-char-width glyph-height glyph-width
415 image-size make-extent propertize set-extent-end-glyph
416 window-pixel-height window-pixel-width))
417 (when (and (get fn 'defalias-maybe)
418 (eq (symbol-function fn) 'ignore))
419 (put fn 'defalias-maybe nil)
423 (product-provide (provide 'wl-demo) (require 'wl-version))
425 ;;; wl-demo.el ends here