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.
29 ;; Using BITMAP-MULE to compose a logo image will take a long time.
30 ;; It will be used if you are using Mule, Emacs 20 or Emacs 21 without
31 ;; a new redisplay engine. If it makes you irritated, you can inhibit
32 ;; the use of BITMAP-MULE on the startup screen by the following line
35 ;; (setq wl-demo-display-logo nil)
39 (defconst wl-demo-copyright-notice
40 "Copyright (C) 1998-2001 Yuuichi Teranishi <teranisi@gohome.org>"
41 "A declaration of the copyright on Wanderlust.")
47 (require 'wl-highlight)
49 (defconst wl-demo-icon-name
50 (concat "wl-" (wl-version-status)
51 (if (string-match "^... Dec \\([ 1][0-9]\\|2[0-4]\\)"
52 (current-time-string))
55 "Basename of the logo file.")
57 (defvar wl-logo-ascii "\
59 oo$$$ o$$ o$$$\"\"\"\"\"\"$$$$$o
60 $$$$$$\" o$$$\" o$\"\" \"$$$
64 o$$ oo$\" \"$$$o $ o$$
65 $$$$\"\" \"$$oo$ o o$\"
66 \"$$o \"$$$o oooo$\"\"
70 Yet Another Message Interface On Emacsen"
71 "Ascii picture used to splash the startup screen.")
75 ;; `display-images-p' has not been available in Emacs versions
76 ;; prior to Emacs 21.0.105.
77 (defalias-maybe 'display-images-p 'display-graphic-p)))
79 ;; Avoid byte compile warnings.
81 (defalias-maybe 'bitmap-insert-xbm-file 'ignore)
82 (defalias-maybe 'create-image 'ignore)
83 (defalias-maybe 'device-on-window-system-p '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 'image-type-available-p 'ignore)
90 (defalias-maybe 'insert-image 'ignore)
91 (defalias-maybe 'make-extent 'ignore)
92 (defalias-maybe 'make-glyph 'ignore)
93 (defalias-maybe 'propertize 'ignore)
94 (defalias-maybe 'set-extent-end-glyph 'ignore)
95 (defalias-maybe 'set-glyph-face 'ignore)
96 (defalias-maybe 'set-specifier 'ignore)
97 (defalias-maybe 'window-pixel-height 'ignore)
98 (defalias-maybe 'window-pixel-width 'ignore))
100 (defun wl-demo-insert-image (image-type)
101 "Insert a logo image at the point and position it to be centered.
102 IMAGE-TYPE specifies what a type of image should be displayed.
103 Return a number of lines that an image occupies in the buffer."
104 (let ((file (cond ((eq image-type 'xpm)
105 (concat wl-demo-icon-name ".xpm"))
106 ((memq image-type '(xbm bitmap))
107 (concat wl-demo-icon-name ".xbm"))))
109 (when (featurep 'xemacs)
110 (when (boundp 'default-gutter-visible-p)
111 (set-specifier (symbol-value 'default-gutter-visible-p)
112 nil (current-buffer)))
113 (set-specifier (symbol-value 'scrollbar-height) 0 (current-buffer))
114 (set-specifier (symbol-value 'scrollbar-width) 0 (current-buffer)))
117 (file-directory-p wl-icon-dir))
118 (setq file (expand-file-name file wl-icon-dir))
119 (message "You should specify the value of `wl-icon-dir'")
121 (if (file-exists-p file)
122 (if (file-readable-p file)
124 (message "Permission denied: %s" file)
126 (message "File not found: %s" file)
129 (cond ((featurep 'xemacs)
130 (setq width (window-pixel-width)
131 height (window-pixel-height)
132 image (make-glyph (vector image-type ':file file)))
133 (when (eq 'xbm image-type)
134 (set-glyph-face image 'wl-highlight-logo-face))
135 (insert-char ?\ (max 0 (/ (+ (* (- width (glyph-width image))
136 (window-width)) width)
138 (set-extent-end-glyph (make-extent (point) (point)) image)
140 (/ (+ (* 2 (glyph-height image) (window-height)) height)
142 ((eq 'bitmap image-type)
143 (message "Composing a bitmap image...")
145 (narrow-to-region (point) (point))
146 (bitmap-insert-xbm-file file)
148 (indent-rigidly (point-min) (point-max)
149 (max 0 (/ (1+ (- (window-width)
152 (put-text-property (point-min) (point-max)
153 'face 'wl-highlight-logo-face)
154 (message "Composing a bitmap image...done")
155 (count-lines (point-min) (goto-char (point-max)))))
156 ((>= emacs-major-version 21)
157 (if (eq 'xpm image-type)
158 (setq image (create-image file 'xpm)
159 width (image-size image)
163 (setq case-fold-search t)
164 (insert-file-contents file)
165 (goto-char (point-min))
166 (re-search-forward "\
167 ^#define[[:blank:]]+[^[:blank:]]+_width[[:blank:]]+")
168 (setq width (read (current-buffer)))
169 (goto-char (point-min))
170 (re-search-forward "\
171 ^#define[[:blank:]]+[^[:blank:]]+_height[[:blank:]]+")
172 (setq height (read (current-buffer)))
174 (delete-region (point-min) (point))
175 (while (re-search-forward "[^0-9a-fx]+" nil t)
177 (goto-char (point-min))
179 (while (search-forward "0x" nil t)
180 (replace-match "\\\\x"))
181 (goto-char (point-max))
183 (goto-char (point-min))
184 (setq image (create-image (read (current-buffer))
188 width (/ (float width) (frame-char-width))
189 height (/ (float height) (frame-char-height)))
190 (let ((bg (face-background 'wl-highlight-logo-face))
191 (fg (face-foreground 'wl-highlight-logo-face)))
193 (plist-put (cdr image) ':background bg))
195 (plist-put (cdr image) ':foreground fg)))))
196 (insert (propertize " " 'display
197 (list 'space ':align-to
198 (max 0 (round (- (window-width)
205 (narrow-to-region (point) (point))
206 (insert wl-logo-ascii)
207 (put-text-property (point-min) (point) 'face 'wl-highlight-logo-face)
214 (setq width (max width (current-column))))
215 (indent-rigidly (point-min) (point-max)
216 (max 0 (/ (1+ (- (window-width) width)) 2)))
217 (count-lines (point-min) (goto-char (point-max)))))))
219 (defun wl-demo-insert-text (height)
220 "Insert a version and the copyright message after a logo image. HEIGHT
221 should be a number of lines that an image occupies in the buffer."
222 (let* ((height (- (window-height) height 1))
223 (text (format (cond ((<= height 2)
224 "version %s - \"%s\"\n%s")
226 "version %s - \"%s\"\n\n%s")
228 "\nversion %s - \"%s\"\n\n%s"))
229 (product-version-string (product-find 'wl-version))
230 (product-code-name (product-find 'wl-version))
231 wl-demo-copyright-notice))
233 (goto-char (point-min))
234 (insert-char ?\n (max 0 (/ (- height 4) 2)))
235 (setq start (goto-char (point-max)))
237 (let ((bg (face-background 'wl-highlight-demo-face))
238 (fg (face-foreground 'wl-highlight-demo-face)))
239 (insert (propertize text
240 'face (nconc '(variable-pitch :slant oblique)
242 (list ':background bg))
244 (list ':foreground fg))))))
246 (put-text-property start (point) 'face 'wl-highlight-demo-face))
247 (let ((fill-column (window-width)))
248 (center-region start (point)))))
250 (defun wl-demo-image-type-alist ()
251 "Return an alist of available logo image types on the current frame."
252 (if (or (and (featurep 'xemacs)
253 (device-on-window-system-p))
255 (let ((selection (append (when (or (and (featurep 'xemacs)
259 (image-type-available-p 'xpm)))
261 (when (or (featurep 'xemacs)
264 (image-type-available-p 'xbm)))
266 (unless (or selection
271 (when (featurep 'bitmap)
272 (setq selection (append selection '(("bitmap" . bitmap)))))
273 (append selection '(("ascii"))))
276 (defun wl-demo (&optional image-type)
277 "Demo on the startup screen. IMAGE-TYPE should be a symbol which
278 overrides the variable `wl-demo-display-logo'. It will prompt user
279 for the type of image when it is called interactively with a prefix
282 (let ((selection (wl-demo-image-type-alist))
284 (if (and image-type (interactive-p))
285 (setq type (completing-read "Image type: " selection nil t)
286 image-type (when (assoc type selection)
287 (cdr (assoc type selection))))
288 (if (setq type (assoc (format "%s" (or image-type wl-demo-display-logo))
290 (setq image-type (cdr type))
291 (setq image-type (when wl-demo-display-logo
292 (cdr (car selection)))))))
293 (when (eq 'bitmap image-type)
294 ;; Composing a bitmap image takes a long time. :-<
296 (let ((buffer (let ((default-enable-multibyte-characters t)
298 (default-line-spacing 0))
299 (get-buffer-create "*WL Demo*"))))
300 (switch-to-buffer buffer)
301 (setq buffer-read-only nil)
303 (setq truncate-lines t
305 (set (make-local-variable 'tab-stop-list)
306 '(8 16 24 32 40 48 56 64 72 80 88 96 104 112 120))
307 (wl-demo-insert-text (wl-demo-insert-image image-type))
308 (set-buffer-modified-p nil)
309 (goto-char (point-min))
310 (sit-for (if (featurep 'lisp-float-type)
311 (/ (float 5) (float 10))
316 (product-provide (provide 'wl-demo) (require 'wl-version))
318 ;;; wl-demo.el ends here