*** empty log message ***
[gnus] / lisp / gnus-xmas.el
1 ;;; gnus-xmas.el --- Gnus functions for XEmacs
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'text-props)
29 (defvar menu-bar-mode (featurep 'menubar))
30 (require 'messagexmas)
31
32 (defun gnus-xmas-redefine ()
33   "Redefine lots of Gnus functions for XEmacs."
34   (fset 'gnus-summary-set-display-table 'gnus-xmas-summary-set-display-table)
35   (fset 'gnus-visual-turn-off-edit-menu 'identity)
36   (fset 'gnus-summary-recenter 'gnus-xmas-summary-recenter)
37   (fset 'gnus-extent-start-open 'gnus-xmas-extent-start-open)
38   (fset 'gnus-article-push-button 'gnus-xmas-article-push-button)
39   (fset 'gnus-article-add-button 'gnus-xmas-article-add-button)
40   (fset 'gnus-window-top-edge 'gnus-xmas-window-top-edge)
41   (fset 'gnus-read-event-char 'gnus-xmas-read-event-char)
42   (fset 'gnus-group-startup-message 'gnus-xmas-group-startup-message)
43   (fset 'gnus-tree-minimize 'gnus-xmas-tree-minimize)
44   (fset 'gnus-appt-select-lowest-window
45         'gnus-xmas-appt-select-lowest-window)
46   (fset 'gnus-mail-strip-quoted-names 'gnus-xmas-mail-strip-quoted-names)
47   (fset 'gnus-character-to-event 'character-to-event)
48   (fset 'gnus-mode-line-buffer-identification
49         'gnus-xmas-mode-line-buffer-identification)
50   (fset 'gnus-key-press-event-p 'key-press-event-p)
51   (fset 'gnus-region-active-p 'region-active-p)
52
53   (add-hook 'gnus-group-mode-hook 'gnus-xmas-group-menu-add)
54   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
55   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add)
56   (add-hook 'gnus-score-mode-hook 'gnus-xmas-score-menu-add)
57
58   (add-hook 'gnus-pick-mode-hook 'gnus-xmas-pick-menu-add)
59   (add-hook 'gnus-topic-mode-hook 'gnus-xmas-topic-menu-add)
60   (add-hook 'gnus-tree-mode-hook 'gnus-xmas-tree-menu-add)
61   (add-hook 'gnus-binary-mode-hook 'gnus-xmas-binary-menu-add)
62   (add-hook 'gnus-grouplens-mode-hook 'gnus-xmas-grouplens-menu-add)
63   (add-hook 'gnus-server-mode-hook 'gnus-xmas-server-menu-add)
64   (add-hook 'gnus-browse-mode-hook 'gnus-xmas-browse-menu-add)
65
66   (add-hook 'gnus-group-mode-hook 'gnus-xmas-setup-group-toolbar)
67   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
68
69   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-switch-horizontal-scrollbar-off)
70
71   (when (and (<= emacs-major-version 19)
72              (<= emacs-minor-version 13))
73     (setq gnus-article-x-face-too-ugly (when (eq (device-type) 'tty)
74                                          "."))
75     (fset 'gnus-highlight-selected-summary
76           'gnus-xmas-highlight-selected-summary)
77     (fset 'gnus-group-remove-excess-properties
78           'gnus-xmas-group-remove-excess-properties)
79     (fset 'gnus-topic-remove-excess-properties
80           'gnus-xmas-topic-remove-excess-properties)
81     (fset 'gnus-mode-line-buffer-identification 'identity)
82     (unless (boundp 'shell-command-switch)
83       (setq shell-command-switch "-c"))))
84
85 (defun gnus-xmas-define ()
86   (setq gnus-mouse-2 [button2])
87
88   (unless (memq 'underline (face-list))
89     (and (fboundp 'make-face)
90          (funcall (intern "make-face") 'underline)))
91   ;; Must avoid calling set-face-underline-p directly, because it
92   ;; is a defsubst in emacs19, and will make the .elc files non
93   ;; portable!
94   (unless (face-differs-from-default-p 'underline)
95     (funcall (intern "set-face-underline-p") 'underline t))
96
97   (cond
98    ((fboundp 'char-or-char-int-p)
99     ;; Handle both types of marks for XEmacs-20.x.
100     (fset 'gnus-characterp 'char-or-char-int-p))
101    ;; V19 of XEmacs, probably.
102    (t
103     (fset 'gnus-characterp 'characterp)))
104
105   (fset 'gnus-make-overlay 'make-extent)
106   (fset 'gnus-overlay-put 'set-extent-property)
107   (fset 'gnus-move-overlay 'gnus-xmas-move-overlay)
108   (fset 'gnus-overlay-end 'extent-end-position)
109   (fset 'gnus-extent-detached-p 'extent-detached-p)
110   (fset 'gnus-add-text-properties 'gnus-xmas-add-text-properties)
111   (fset 'gnus-put-text-property 'gnus-xmas-put-text-property)
112
113   (require 'text-props)
114   (if (and (<= emacs-major-version 19)
115            (< emacs-minor-version 14))
116       (fset 'gnus-set-text-properties 'gnus-xmas-set-text-properties))
117
118   (when (fboundp 'turn-off-scroll-in-place)
119     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
120
121   (unless (boundp 'standard-display-table)
122     (setq standard-display-table nil))
123
124   (defvar gnus-mouse-face-prop 'highlight)
125
126   (unless (fboundp 'encode-time)
127     (defun encode-time (sec minute hour day month year &optional zone)
128       (let ((seconds
129              (gnus-xmas-seconds-since-epoch
130               (timezone-make-arpa-date
131                year month day (timezone-make-time-string hour minute sec)
132                zone))))
133         (list (floor (/ seconds (expt 2 16)))
134               (round (mod seconds (expt 2 16)))))))
135
136   (defun gnus-byte-code (func)
137     "Return a form that can be `eval'ed based on FUNC."
138     (let ((fval (symbol-function func)))
139       (if (compiled-function-p fval)
140           (list 'funcall fval)
141         (cons 'progn (cdr (cdr fval))))))
142
143   (fset 'gnus-x-color-values
144         (if (fboundp 'x-color-values)
145             'x-color-values
146           (lambda (color)
147             (color-instance-rgb-components
148              (make-color-instance color))))))
149
150 (require 'gnus-art) ;; Circular
151
152 (defgroup gnus-xmas nil
153   "XEmacsoid support for Gnus"
154   :group 'gnus)
155
156 (defcustom gnus-xmas-glyph-directory nil
157   "*Directory where Gnus logos and icons are located.
158 If this variable is nil, Gnus will try to locate the directory
159 automatically."
160   :type '(choice (const :tag "autodetect" nil)
161                  directory)
162   :group 'gnus-xmas)
163
164 (defvar gnus-xmas-logo-color-alist
165   '((flame "#cc3300" "#ff2200")
166     (pine "#c0cc93" "#f8ffb8")
167     (moss "#a1cc93" "#d2ffb8")
168     (irish "#04cc90" "#05ff97")
169     (sky "#049acc" "#05deff")
170     (tin "#6886cc" "#82b6ff")
171     (velvet "#7c68cc" "#8c82ff")
172     (grape "#b264cc" "#cf7df")
173     (labia "#cc64c2" "#fd7dff")
174     (berry "#cc6485" "#ff7db5")
175     (neutral "#b4b4b4" "#878787")
176     (september "#bf9900" "#ffcc00"))
177   "Color alist used for the Gnus logo.")
178
179 (defcustom gnus-xmas-logo-color-style 'flame
180   "Color styles used for the Gnus logo."
181   :type '(choice (const flame) (const pine) (const moss)
182                  (const irish) (const sky) (const tin)
183                  (const velvet) (const grape) (const labia)
184                  (const berry) (const neutral) (const september))
185   :group 'gnus-xmas)
186
187 (defvar gnus-xmas-logo-colors
188   (cdr (assq gnus-xmas-logo-color-style gnus-xmas-logo-color-alist))
189   "Colors used for the Gnus logo.")
190
191 (defcustom gnus-article-x-face-command
192   (if (featurep 'xface)
193       'gnus-xmas-article-display-xface
194     "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -")
195   "String or function to be executed to display an X-Face header.
196 If it is a string, the command will be executed in a sub-shell
197 asynchronously.  The compressed face will be piped to this command."
198   :type '(choice string function))
199
200 ;;; Internal variables.
201
202 ;; Don't warn about these undefined variables.
203
204 (defvar gnus-group-mode-hook)
205 (defvar gnus-summary-mode-hook)
206 (defvar gnus-article-mode-hook)
207
208 ;;defined in gnus.el
209 (defvar gnus-active-hashtb)
210 (defvar gnus-article-buffer)
211 (defvar gnus-auto-center-summary)
212 (defvar gnus-buffer-list)
213 (defvar gnus-current-headers)
214 (defvar gnus-level-killed)
215 (defvar gnus-level-zombie)
216 (defvar gnus-newsgroup-bookmarks)
217 (defvar gnus-newsgroup-dependencies)
218 (defvar gnus-newsgroup-selected-overlay)
219 (defvar gnus-newsrc-hashtb)
220 (defvar gnus-read-mark)
221 (defvar gnus-refer-article-method)
222 (defvar gnus-reffed-article-number)
223 (defvar gnus-unread-mark)
224 (defvar gnus-version)
225 (defvar gnus-view-pseudos)
226 (defvar gnus-view-pseudos-separately)
227 (defvar gnus-visual)
228 (defvar gnus-zombie-list)
229 ;;defined in gnus-msg.el
230 (defvar gnus-article-copy)
231 (defvar gnus-check-before-posting)
232 ;;defined in gnus-vis.el
233 (defvar gnus-article-button-face)
234 (defvar gnus-article-mouse-face)
235 (defvar gnus-summary-selected-face)
236 (defvar gnus-group-reading-menu)
237 (defvar gnus-group-group-menu)
238 (defvar gnus-group-misc-menu)
239 (defvar gnus-summary-article-menu)
240 (defvar gnus-summary-thread-menu)
241 (defvar gnus-summary-misc-menu)
242 (defvar gnus-summary-post-menu)
243 (defvar gnus-summary-kill-menu)
244 (defvar gnus-article-article-menu)
245 (defvar gnus-article-treatment-menu)
246 (defvar gnus-mouse-2)
247 (defvar standard-display-table)
248 (defvar gnus-tree-minimize-window)
249
250 (defun gnus-xmas-set-text-properties (start end props &optional buffer)
251   "You should NEVER use this function.  It is ideologically blasphemous.
252 It is provided only to ease porting of broken FSF Emacs programs."
253   (if (stringp buffer)
254       nil
255     (map-extents (lambda (extent ignored)
256                    (remove-text-properties
257                     start end
258                     (list (extent-property extent 'text-prop) nil)
259                     buffer))
260                  buffer start end nil nil 'text-prop)
261     (gnus-add-text-properties start end props buffer)))
262
263 (defun gnus-xmas-highlight-selected-summary ()
264   ;; Highlight selected article in summary buffer
265   (when gnus-summary-selected-face
266     (when gnus-newsgroup-selected-overlay
267       (delete-extent gnus-newsgroup-selected-overlay))
268     (setq gnus-newsgroup-selected-overlay
269           (make-extent (gnus-point-at-bol) (gnus-point-at-eol)))
270     (set-extent-face gnus-newsgroup-selected-overlay
271                      gnus-summary-selected-face)))
272
273 (defcustom gnus-xmas-force-redisplay nil
274   "If non-nil, force a redisplay before recentering the summary buffer.
275 This is ugly, but it works around a bug in `window-displayed-height'."
276   :type 'boolean
277   :group 'gnus-xmas)
278
279 (defun gnus-xmas-switch-horizontal-scrollbar-off ()
280   (when (featurep 'scrollbar)
281     (set-specifier scrollbar-height (cons (current-buffer) 0))))
282
283 (defun gnus-xmas-summary-recenter ()
284   "\"Center\" point in the summary window.
285 If `gnus-auto-center-summary' is nil, or the article buffer isn't
286 displayed, no centering will be performed."
287   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
288   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
289   ;; Force redisplay to get properly computed window height.
290   (when gnus-xmas-force-redisplay
291     (sit-for 0))
292   (when gnus-auto-center-summary
293     (let* ((height (if (fboundp 'window-displayed-height)
294                        (window-displayed-height)
295                      (- (window-height) 2)))
296            (top (cond ((< height 4) 0)
297                       ((< height 7) 1)
298                       (t 2)))
299            (bottom (save-excursion (goto-char (point-max))
300                                    (forward-line (- height))
301                                    (point)))
302            (window (get-buffer-window (current-buffer))))
303       (when (get-buffer-window gnus-article-buffer)
304         ;; Only do recentering when the article buffer is displayed,
305         ;; Set the window start to either `bottom', which is the biggest
306         ;; possible valid number, or the second line from the top,
307         ;; whichever is the least.
308         (set-window-start
309          window (min bottom (save-excursion (forward-line (- top)) (point)))))
310       ;; Do horizontal recentering while we're at it.
311       (when (and (get-buffer-window (current-buffer) t)
312                  (not (eq gnus-auto-center-summary 'vertical)))
313         (let ((selected (selected-window)))
314           (select-window (get-buffer-window (current-buffer) t))
315           (gnus-summary-position-point)
316           (gnus-horizontal-recenter)
317           (select-window selected))))))
318
319 (defun gnus-xmas-summary-set-display-table ()
320   ;; Setup the display table -- like `gnus-summary-setup-display-table',
321   ;; but done in an XEmacsish way.
322   (let ((table (make-display-table))
323         (i 32))
324     ;; Nix out all the control chars...
325     (while (>= (setq i (1- i)) 0)
326       (aset table i [??]))
327     ;; ... but not newline and cr, of course.  (cr is necessary for the
328     ;; selective display).
329     (aset table ?\n nil)
330     (aset table ?\r nil)
331     ;; We nix out any glyphs over 126 below ctl-arrow.
332     (let ((i (if (integerp ctl-arrow) ctl-arrow 160)))
333       (while (>= (setq i (1- i)) 127)
334         (aset table i [??])))
335     ;; Can't use `set-specifier' because of a bug in 19.14 and earlier
336     (add-spec-to-specifier current-display-table table (current-buffer) nil)))
337
338 (defun gnus-xmas-add-text-properties (start end props &optional object)
339   (add-text-properties start end props object)
340   (put-text-property start end 'start-closed nil object))
341
342 (defun gnus-xmas-put-text-property (start end prop value &optional object)
343   (put-text-property start end prop value object)
344   (put-text-property start end 'start-closed nil object))
345
346 (defun gnus-xmas-extent-start-open (point)
347   (map-extents (lambda (extent arg)
348                  (set-extent-property extent 'start-open t))
349                nil point (min (1+ (point)) (point-max))))
350
351 (defun gnus-xmas-article-push-button (event)
352   "Check text under the mouse pointer for a callback function.
353 If the text under the mouse pointer has a `gnus-callback' property,
354 call it with the value of the `gnus-data' text property."
355   (interactive "e")
356   (set-buffer (window-buffer (event-window event)))
357   (let* ((pos (event-closest-point event))
358          (data (get-text-property pos 'gnus-data))
359          (fun (get-text-property pos 'gnus-callback)))
360     (when fun
361       (funcall fun data))))
362
363 (defun gnus-xmas-move-overlay (extent start end &optional buffer)
364   (set-extent-endpoints extent start end))
365
366 ;; Fixed by Christopher Davis <ckd@loiosh.kei.com>.
367 (defun gnus-xmas-article-add-button (from to fun &optional data)
368   "Create a button between FROM and TO with callback FUN and data DATA."
369   (when gnus-article-button-face
370     (gnus-overlay-put (gnus-make-overlay from to)
371                       'face gnus-article-button-face))
372   (gnus-add-text-properties
373    from to
374    (nconc
375     (and gnus-article-mouse-face
376          (list 'mouse-face gnus-article-mouse-face))
377     (list 'gnus-callback fun)
378     (and data (list 'gnus-data data))
379     (list 'highlight t))))
380
381 (defun gnus-xmas-window-top-edge (&optional window)
382   (nth 1 (window-pixel-edges window)))
383
384 (defun gnus-xmas-tree-minimize ()
385   (when (and gnus-tree-minimize-window
386              (not (one-window-p)))
387     (let* ((window-min-height 2)
388            (height (1+ (count-lines (point-min) (point-max))))
389            (min (max (1- window-min-height) height))
390            (tot (if (numberp gnus-tree-minimize-window)
391                     (min gnus-tree-minimize-window min)
392                   min))
393            (win (get-buffer-window (current-buffer)))
394            (wh (and win (1- (window-height win)))))
395       (when (and win
396                  (not (eq tot wh)))
397         (let ((selected (selected-window)))
398           (select-window win)
399           (enlarge-window (- tot wh))
400           (select-window selected))))))
401
402 ;; Select the lowest window on the frame.
403 (defun gnus-xmas-appt-select-lowest-window ()
404   (let* ((lowest-window (selected-window))
405          (bottom-edge (car (cdr (cdr (cdr (window-pixel-edges))))))
406          (last-window (previous-window))
407          (window-search t))
408     (while window-search
409       (let* ((this-window (next-window))
410              (next-bottom-edge (car (cdr (cdr (cdr
411                                                (window-pixel-edges
412                                                 this-window)))))))
413         (when (< bottom-edge next-bottom-edge)
414           (setq bottom-edge next-bottom-edge)
415           (setq lowest-window this-window))
416
417         (select-window this-window)
418         (when (eq last-window this-window)
419           (select-window lowest-window)
420           (setq window-search nil))))))
421
422 (defmacro gnus-xmas-menu-add (type &rest menus)
423   `(gnus-xmas-menu-add-1 ',type ',menus))
424 (put 'gnus-xmas-menu-add 'lisp-indent-function 1)
425
426 (defun gnus-xmas-menu-add-1 (type menus)
427   (when (and menu-bar-mode
428              (gnus-visual-p (intern (format "%s-menu" type)) 'menu))
429     (while menus
430       (easy-menu-add (symbol-value (pop menus))))))
431
432 (defun gnus-xmas-group-menu-add ()
433   (gnus-xmas-menu-add group
434     gnus-group-reading-menu gnus-group-group-menu gnus-group-misc-menu))
435
436 (defun gnus-xmas-summary-menu-add ()
437   (gnus-xmas-menu-add summary
438     gnus-summary-misc-menu gnus-summary-kill-menu
439     gnus-summary-article-menu gnus-summary-thread-menu
440     gnus-summary-post-menu ))
441
442 (defun gnus-xmas-article-menu-add ()
443   (gnus-xmas-menu-add article
444     gnus-article-article-menu gnus-article-treatment-menu))
445
446 (defun gnus-xmas-score-menu-add ()
447   (gnus-xmas-menu-add score
448     gnus-score-menu))
449
450 (defun gnus-xmas-pick-menu-add ()
451   (gnus-xmas-menu-add pick
452     gnus-pick-menu))
453
454 (defun gnus-xmas-topic-menu-add ()
455   (gnus-xmas-menu-add topic
456     gnus-topic-menu))
457
458 (defun gnus-xmas-binary-menu-add ()
459   (gnus-xmas-menu-add binary
460     gnus-binary-menu))
461
462 (defun gnus-xmas-tree-menu-add ()
463   (gnus-xmas-menu-add tree
464     gnus-tree-menu))
465
466 (defun gnus-xmas-server-menu-add ()
467   (gnus-xmas-menu-add menu
468     gnus-server-server-menu gnus-server-connections-menu))
469
470 (defun gnus-xmas-browse-menu-add ()
471   (gnus-xmas-menu-add browse
472     gnus-browse-menu))
473
474 (defun gnus-xmas-grouplens-menu-add ()
475   (gnus-xmas-menu-add grouplens
476     gnus-grouplens-menu))
477
478 (defun gnus-xmas-read-event-char ()
479   "Get the next event."
480   (let ((event (next-command-event)))
481     (sit-for 0)
482     ;; We junk all non-key events.  Is this naughty?
483     (while (not (or (key-press-event-p event)
484                     (button-press-event-p event)))
485       (dispatch-event event)
486       (setq event (next-command-event)))
487     (cons (and (key-press-event-p event)
488                (event-to-character event))
489           event)))
490
491 (defun gnus-xmas-group-remove-excess-properties ()
492   (let ((end (point))
493         (beg (progn (forward-line -1) (point))))
494     (remove-text-properties (1+ beg) end '(gnus-group nil))
495     (remove-text-properties
496      beg end
497      '(gnus-topic nil gnus-topic-level nil gnus-topic-visible nil))
498     (goto-char end)
499     (map-extents
500      (lambda (e ma)
501        (set-extent-property e 'start-closed t))
502      (current-buffer) beg end)))
503
504 (defun gnus-xmas-topic-remove-excess-properties ()
505   (let ((end (point))
506         (beg (progn (forward-line -1) (point))))
507     (remove-text-properties beg end '(gnus-group nil gnus-unread nil))
508     (remove-text-properties (1+ beg) end '(gnus-topic nil))
509     (goto-char end)))
510
511 (defun gnus-xmas-seconds-since-epoch (date)
512   "Return a floating point number that says how many seconds have lapsed between Jan 1 12:00:00 1970 and DATE."
513   (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
514                         (timezone-parse-date date)))
515          (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
516                         (timezone-parse-time
517                          (aref (timezone-parse-date date) 3))))
518          (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
519                         (timezone-parse-date "Jan 1 12:00:00 1970")))
520          (tday (- (timezone-absolute-from-gregorian
521                    (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
522                   (timezone-absolute-from-gregorian
523                    (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
524     (+ (nth 2 ttime)
525        (* (nth 1 ttime) 60)
526        (* (float (nth 0 ttime)) 60 60)
527        (* (float tday) 60 60 24))))
528
529 ;;; XEmacs logo and toolbar.
530
531 (defun gnus-xmas-group-startup-message (&optional x y)
532   "Insert startup message in current buffer."
533   ;; Insert the message.
534   (setq gnus-xmas-glyph-directory (message-xmas-find-glyph-directory "gnus"))
535   (erase-buffer)
536   (let ((logo (and gnus-xmas-glyph-directory
537                    (concat
538                     (file-name-as-directory gnus-xmas-glyph-directory)
539                     "gnus."
540                     (if (featurep 'xpm) "xpm" "xbm"))))
541         (xpm-color-symbols
542          (and (featurep 'xpm)
543               (append `(("thing" ,(car gnus-xmas-logo-colors))
544                         ("shadow" ,(cadr gnus-xmas-logo-colors)))
545                       xpm-color-symbols))))
546     (if (and (featurep 'xpm)
547              (not (equal (device-type) 'tty))
548              logo
549              (file-exists-p logo))
550         (progn
551           (setq logo (make-glyph logo))
552           (insert " ")
553           (set-extent-begin-glyph (make-extent (point) (point)) logo)
554           (goto-char (point-min))
555           (while (not (eobp))
556             (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
557                                  ? ))
558             (forward-line 1))
559           (goto-char (point-min))
560           (let* ((pheight (+ 20 (count-lines (point-min) (point-max))))
561                  (wheight (window-height))
562                  (rest (- wheight pheight)))
563             (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
564
565       (insert
566        (format "              %s
567           _    ___ _             _
568           _ ___ __ ___  __    _ ___
569           __   _     ___    __  ___
570               _           ___     _
571              _  _ __             _
572              ___   __            _
573                    __           _
574                     _      _   _
575                    _      _    _
576                       _  _    _
577                   __  ___
578                  _   _ _     _
579                 _   _
580               _    _
581              _    _
582             _
583           __
584
585 "
586                ""))
587       ;; And then hack it.
588       (gnus-indent-rigidly (point-min) (point-max)
589                            (/ (max (- (window-width) (or x 46)) 0) 2))
590       (goto-char (point-min))
591       (forward-line 1)
592       (let* ((pheight (count-lines (point-min) (point-max)))
593              (wheight (window-height))
594              (rest (- wheight pheight)))
595         (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
596     ;; Fontify some.
597     (goto-char (point-min))
598     (put-text-property (point-min) (point-max) 'face 'gnus-splash-face)
599     (goto-char (point-min))
600     (setq modeline-buffer-identification
601           (list (concat gnus-version ": *Group*")))
602     (set-buffer-modified-p t)))
603
604
605 ;;; The toolbar.
606
607 (defcustom gnus-use-toolbar (if (featurep 'toolbar)
608                                 'default-toolbar
609                               nil)
610   "*If nil, do not use a toolbar.
611 If it is non-nil, it must be a toolbar.  The five legal values are
612 `default-toolbar', `top-toolbar', `bottom-toolbar',
613 `right-toolbar', and `left-toolbar'."
614   :type '(choice (const default-toolbar)
615                  (const top-toolbar) (const bottom-toolbar)
616                  (const left-toolbar) (const right-toolbar)
617                  (const :tag "no toolbar" nil))
618   :group 'gnus-xmas)
619
620 (defvar gnus-group-toolbar
621   '([gnus-group-get-new-news gnus-group-get-new-news t "Get new news"]
622     [gnus-group-get-new-news-this-group
623      gnus-group-get-new-news-this-group t "Get new news in this group"]
624     [gnus-group-catchup-current
625      gnus-group-catchup-current t "Catchup group"]
626     [gnus-group-describe-group
627      gnus-group-describe-group t "Describe group"]
628     [gnus-group-unsubscribe gnus-group-unsubscribe t "Unsubscribe group"]
629     [gnus-group-subscribe gnus-group-subscribe t "Subscribe group"]
630     [gnus-group-kill-group gnus-group-kill-group t "Kill group"]
631     [gnus-group-exit gnus-group-exit t "Exit Gnus"]
632     )
633   "The group buffer toolbar.")
634
635 (defvar gnus-summary-toolbar
636   '([gnus-summary-prev-unread
637      gnus-summary-prev-page-or-article t "Page up"]
638     [gnus-summary-next-unread
639      gnus-summary-next-page t "Page down"]
640     [gnus-summary-post-news
641      gnus-summary-post-news t "Post an article"]
642     [gnus-summary-followup-with-original
643      gnus-summary-followup-with-original t
644      "Post a followup and yank the original"]
645     [gnus-summary-followup
646      gnus-summary-followup t "Post a followup"]
647     [gnus-summary-reply-with-original
648      gnus-summary-reply-with-original t "Mail a reply and yank the original"]
649     [gnus-summary-reply
650      gnus-summary-reply t "Mail a reply"]
651     [gnus-summary-caesar-message
652      gnus-summary-caesar-message t "Rot 13"]
653     [gnus-uu-decode-uu
654      gnus-uu-decode-uu t "Decode uuencoded articles"]
655     [gnus-summary-save-article-file
656      gnus-summary-save-article-file t "Save article in file"]
657     [gnus-summary-save-article
658      gnus-summary-save-article t "Save article"]
659     [gnus-uu-post-news
660      gnus-uu-post-news t "Post an uuencoded article"]
661     [gnus-summary-cancel-article
662      gnus-summary-cancel-article t "Cancel article"]
663     [gnus-summary-catchup
664      gnus-summary-catchup t "Catchup"]
665     [gnus-summary-catchup-and-exit
666      gnus-summary-catchup-and-exit t "Catchup and exit"]
667     [gnus-summary-exit gnus-summary-exit t "Exit this summary"]
668     )
669   "The summary buffer toolbar.")
670
671 (defvar gnus-summary-mail-toolbar
672   '(
673     [gnus-summary-prev-unread
674      gnus-summary-prev-unread-article t "Prev unread article"]
675     [gnus-summary-next-unread
676      gnus-summary-next-unread-article t "Next unread article"]
677     [gnus-summary-mail-reply gnus-summary-reply t "Reply"]
678 ;    [gnus-summary-mail-get gnus-mail-get t "Message get"]
679     [gnus-summary-mail-originate gnus-summary-post-news t "Originate"]
680     [gnus-summary-mail-save gnus-summary-save-article t "Save"]
681     [gnus-summary-mail-copy gnus-summary-copy-article t "Copy message"]
682 ;    [gnus-summary-mail-delete gnus-summary-delete-article t "Delete message"]
683     [gnus-summary-mail-forward gnus-summary-mail-forward t "Forward message"]
684 ;    [gnus-summary-mail-spell gnus-mail-spell t "Spell"]
685 ;    [gnus-summary-mail-help gnus-mail-help  t "Message help"]
686     [gnus-summary-caesar-message
687      gnus-summary-caesar-message t "Rot 13"]
688     [gnus-uu-decode-uu
689      gnus-uu-decode-uu t "Decode uuencoded articles"]
690     [gnus-summary-save-article-file
691      gnus-summary-save-article-file t "Save article in file"]
692     [gnus-summary-save-article
693      gnus-summary-save-article t "Save article"]
694     [gnus-summary-catchup
695      gnus-summary-catchup t "Catchup"]
696     [gnus-summary-catchup-and-exit
697      gnus-summary-catchup-and-exit t "Catchup and exit"]
698     [gnus-summary-exit gnus-summary-exit t "Exit this summary"]
699     )
700   "The summary buffer mail toolbar.")
701
702 (defun gnus-xmas-setup-group-toolbar ()
703   (and gnus-use-toolbar
704        (message-xmas-setup-toolbar gnus-group-toolbar nil "gnus")
705        (set-specifier (symbol-value gnus-use-toolbar)
706                       (cons (current-buffer) gnus-group-toolbar))))
707
708 (defun gnus-xmas-setup-summary-toolbar ()
709   (let ((bar (if (gnus-news-group-p gnus-newsgroup-name)
710                  gnus-summary-toolbar gnus-summary-mail-toolbar)))
711     (and gnus-use-toolbar
712          (message-xmas-setup-toolbar bar nil "gnus")
713          (set-specifier (symbol-value gnus-use-toolbar)
714                         (cons (current-buffer) bar)))))
715
716 (defun gnus-xmas-mail-strip-quoted-names (address)
717   "Protect mail-strip-quoted-names from NIL input.
718 XEmacs compatibility workaround."
719   (if (null address)
720       nil
721     (mail-strip-quoted-names address)))
722
723 (defun gnus-xmas-call-region (command &rest args)
724   (apply
725    'call-process-region (point-min) (point-max) command t '(t nil) nil
726    args))
727
728 (defface gnus-x-face '((t (:foreground "black" :background "white")))
729   "Face to show X face"
730   :group 'gnus-xmas)
731
732 (defun gnus-xmas-article-display-xface (beg end)
733   "Display any XFace headers in the current article."
734   (save-excursion
735     (let ((xface-glyph
736            (if (featurep 'xface)
737                (make-glyph (vector 'xface :data
738                                    (concat "X-Face: "
739                                            (buffer-substring beg end))))
740              (let ((cur (current-buffer)))
741                (save-excursion
742                  (gnus-set-work-buffer)
743                  (insert (format "%s" (buffer-substring beg end cur)))
744                  (gnus-xmas-call-region "uncompface")
745                  (goto-char (point-min))
746                  (insert "/* Width=48, Height=48 */\n")
747                  (gnus-xmas-call-region "icontopbm")
748                  (gnus-xmas-call-region "ppmtoxpm")
749                  (make-glyph
750                   (vector 'xpm :data (buffer-string))))))))
751       (set-glyph-face xface-glyph 'gnus-x-face)
752       (goto-char (point-min))
753       (re-search-forward "^From:" nil t)
754       (set-extent-begin-glyph
755        (make-extent (point) (1+ (point))) xface-glyph))))
756
757 (defvar gnus-xmas-pointer-glyph
758   (progn
759     (setq gnus-xmas-glyph-directory (message-xmas-find-glyph-directory "gnus"))
760     (make-pointer-glyph (concat gnus-xmas-glyph-directory "gnus-pointer."
761                                 (if (featurep 'xpm) "xpm" "xbm")))))
762
763 (defvar gnus-xmas-modeline-left-extent
764   (let ((ext (copy-extent modeline-buffer-id-left-extent)))
765     ;(set-extent-property ext 'pointer gnus-xmas-pointer-glyph)
766     ext))
767
768 (defvar gnus-xmas-modeline-right-extent
769   (let ((ext (copy-extent modeline-buffer-id-right-extent)))
770     ;(set-extent-property ext 'pointer gnus-xmas-pointer-glyph)
771     ext))
772
773 (defvar gnus-xmas-modeline-glyph
774   (progn
775     (setq gnus-xmas-glyph-directory (message-xmas-find-glyph-directory "gnus"))
776     (let* ((file (concat gnus-xmas-glyph-directory "gnus-pointer."
777                          (if (featurep 'xpm) "xpm" "xbm")))
778            (glyph (make-glyph file)))
779       (when (and (featurep 'x)
780                  (file-exists-p file))
781         (set-glyph-face glyph 'modeline-buffer-id)
782         (set-glyph-property glyph 'image (cons 'tty "Gnus:"))
783         glyph))))
784
785 (defun gnus-xmas-mode-line-buffer-identification (line)
786   (let ((line (car line))
787         chop)
788     (cond
789      ;; This is some weird type of id.
790      ((not (stringp line))
791       (list line))
792      ;; This is non-standard, so we just pass it through.
793      ((not (string-match "^Gnus:" line))
794       (list line))
795      ;; We have a standard line, so we colorize and glyphize it a bit.
796      (t
797       (setq chop (match-end 0))
798       (list
799        (if gnus-xmas-modeline-glyph
800            (cons gnus-xmas-modeline-left-extent gnus-xmas-modeline-glyph)
801          (cons gnus-xmas-modeline-left-extent (substring line 0 chop)))
802        (cons gnus-xmas-modeline-right-extent (substring line chop)))))))
803
804 (defun gnus-xmas-splash ()
805   (when (eq (device-type) 'x)
806     (gnus-splash)))
807
808 (provide 'gnus-xmas)
809
810 ;;; gnus-xmas.el ends here