*** 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 (require 'gnus-art)
32
33 (defgroup gnus-xmas nil
34   "XEmacsoid support for Gnus"
35   :group 'gnus)
36
37 (defcustom gnus-xmas-glyph-directory nil
38   "*Directory where Gnus logos and icons are located.
39 If this variable is nil, Gnus will try to locate the directory
40 automatically."
41   :type '(choice (const :tag "autodetect" nil)
42                  directory)
43   :group 'gnus-xmas)
44
45 (defvar gnus-xmas-logo-color-alist
46   '((flame "#cc3300" "#ff2200")
47     (pine "#c0cc93" "#f8ffb8")
48     (moss "#a1cc93" "#d2ffb8")
49     (irish "#04cc90" "#05ff97")
50     (sky "#049acc" "#05deff")
51     (tin "#6886cc" "#82b6ff")
52     (velvet "#7c68cc" "#8c82ff")
53     (grape "#b264cc" "#cf7df")
54     (labia "#cc64c2" "#fd7dff")
55     (berry "#cc6485" "#ff7db5")
56     (neutral "#b4b4b4" "#878787")
57     (september "#bf9900" "#ffcc00"))
58   "Color alist used for the Gnus logo.")
59
60 (defcustom gnus-xmas-logo-color-style 'flame
61   "Color styles used for the Gnus logo."
62   :type '(choice (const flame) (const pine) (const moss)
63                  (const irish) (const sky) (const tin)
64                  (const velvet) (const grape) (const labia)
65                  (const berry) (const neutral) (const september))
66   :group 'gnus-xmas)
67
68 (defvar gnus-xmas-logo-colors
69   (cdr (assq gnus-xmas-logo-color-style gnus-xmas-logo-color-alist))
70   "Colors used for the Gnus logo.")
71
72 (defcustom gnus-article-x-face-command
73   (if (featurep 'xface)
74       'gnus-xmas-article-display-xface
75     "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -")
76   "String or function to be executed to display an X-Face header.
77 If it is a string, the command will be executed in a sub-shell
78 asynchronously.  The compressed face will be piped to this command."
79   :type '(choice string function))
80
81 ;;; Internal variables.
82
83 ;; Don't warn about these undefined variables.
84
85 (defvar gnus-group-mode-hook)
86 (defvar gnus-summary-mode-hook)
87 (defvar gnus-article-mode-hook)
88
89 ;;defined in gnus.el
90 (defvar gnus-active-hashtb)
91 (defvar gnus-article-buffer)
92 (defvar gnus-auto-center-summary)
93 (defvar gnus-buffer-list)
94 (defvar gnus-current-headers)
95 (defvar gnus-level-killed)
96 (defvar gnus-level-zombie)
97 (defvar gnus-newsgroup-bookmarks)
98 (defvar gnus-newsgroup-dependencies)
99 (defvar gnus-newsgroup-selected-overlay)
100 (defvar gnus-newsrc-hashtb)
101 (defvar gnus-read-mark)
102 (defvar gnus-refer-article-method)
103 (defvar gnus-reffed-article-number)
104 (defvar gnus-unread-mark)
105 (defvar gnus-version)
106 (defvar gnus-view-pseudos)
107 (defvar gnus-view-pseudos-separately)
108 (defvar gnus-visual)
109 (defvar gnus-zombie-list)
110 ;;defined in gnus-msg.el
111 (defvar gnus-article-copy)
112 (defvar gnus-check-before-posting)
113 ;;defined in gnus-vis.el
114 (defvar gnus-article-button-face)
115 (defvar gnus-article-mouse-face)
116 (defvar gnus-summary-selected-face)
117 (defvar gnus-group-reading-menu)
118 (defvar gnus-group-group-menu)
119 (defvar gnus-group-misc-menu)
120 (defvar gnus-summary-article-menu)
121 (defvar gnus-summary-thread-menu)
122 (defvar gnus-summary-misc-menu)
123 (defvar gnus-summary-post-menu)
124 (defvar gnus-summary-kill-menu)
125 (defvar gnus-article-article-menu)
126 (defvar gnus-article-treatment-menu)
127 (defvar gnus-mouse-2)
128 (defvar standard-display-table)
129 (defvar gnus-tree-minimize-window)
130
131 (defun gnus-xmas-set-text-properties (start end props &optional buffer)
132   "You should NEVER use this function.  It is ideologically blasphemous.
133 It is provided only to ease porting of broken FSF Emacs programs."
134   (if (stringp buffer)
135       nil
136     (map-extents (lambda (extent ignored)
137                    (remove-text-properties
138                     start end
139                     (list (extent-property extent 'text-prop) nil)
140                     buffer))
141                  buffer start end nil nil 'text-prop)
142     (gnus-add-text-properties start end props buffer)))
143
144 (defun gnus-xmas-highlight-selected-summary ()
145   ;; Highlight selected article in summary buffer
146   (when gnus-summary-selected-face
147     (when gnus-newsgroup-selected-overlay
148       (delete-extent gnus-newsgroup-selected-overlay))
149     (setq gnus-newsgroup-selected-overlay
150           (make-extent (gnus-point-at-bol) (gnus-point-at-eol)))
151     (set-extent-face gnus-newsgroup-selected-overlay
152                      gnus-summary-selected-face)))
153
154 (defcustom gnus-xmas-force-redisplay nil
155   "If non-nil, force a redisplay before recentering the summary buffer.
156 This is ugly, but it works around a bug in `window-displayed-height'."
157   :type 'boolean
158   :group 'gnus-xmas)
159
160 (defun gnus-xmas-switch-horizontal-scrollbar-off ()
161   (when (featurep 'scrollbar)
162     (set-specifier scrollbar-height (cons (current-buffer) 0))))
163
164 (defun gnus-xmas-summary-recenter ()
165   "\"Center\" point in the summary window.
166 If `gnus-auto-center-summary' is nil, or the article buffer isn't
167 displayed, no centering will be performed."
168   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
169   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
170   ;; Force redisplay to get properly computed window height.
171   (when gnus-xmas-force-redisplay
172     (sit-for 0))
173   (when gnus-auto-center-summary
174     (let* ((height (if (fboundp 'window-displayed-height)
175                        (window-displayed-height)
176                      (- (window-height) 2)))
177            (top (cond ((< height 4) 0)
178                       ((< height 7) 1)
179                       (t 2)))
180            (bottom (save-excursion (goto-char (point-max))
181                                    (forward-line (- height))
182                                    (point)))
183            (window (get-buffer-window (current-buffer))))
184       (when (get-buffer-window gnus-article-buffer)
185         ;; Only do recentering when the article buffer is displayed,
186         ;; Set the window start to either `bottom', which is the biggest
187         ;; possible valid number, or the second line from the top,
188         ;; whichever is the least.
189         (set-window-start
190          window (min bottom (save-excursion (forward-line (- top)) (point)))))
191       ;; Do horizontal recentering while we're at it.
192       (when (and (get-buffer-window (current-buffer) t)
193                  (not (eq gnus-auto-center-summary 'vertical)))
194         (let ((selected (selected-window)))
195           (select-window (get-buffer-window (current-buffer) t))
196           (gnus-summary-position-point)
197           (gnus-horizontal-recenter)
198           (select-window selected))))))
199
200 (defun gnus-xmas-summary-set-display-table ()
201   ;; Setup the display table -- like `gnus-summary-setup-display-table',
202   ;; but done in an XEmacsish way.
203   (let ((table (make-display-table))
204         (i 32))
205     ;; Nix out all the control chars...
206     (while (>= (setq i (1- i)) 0)
207       (aset table i [??]))
208     ;; ... but not newline and cr, of course.  (cr is necessary for the
209     ;; selective display).
210     (aset table ?\n nil)
211     (aset table ?\r nil)
212     ;; We nix out any glyphs over 126 below ctl-arrow.
213     (let ((i (if (integerp ctl-arrow) ctl-arrow 160)))
214       (while (>= (setq i (1- i)) 127)
215         (aset table i [??])))
216     ;; Can't use `set-specifier' because of a bug in 19.14 and earlier
217     (add-spec-to-specifier current-display-table table (current-buffer) nil)))
218
219 (defun gnus-xmas-add-text-properties (start end props &optional object)
220   (add-text-properties start end props object)
221   (put-text-property start end 'start-closed nil object))
222
223 (defun gnus-xmas-put-text-property (start end prop value &optional object)
224   (put-text-property start end prop value object)
225   (put-text-property start end 'start-closed nil object))
226
227 (defun gnus-xmas-extent-start-open (point)
228   (map-extents (lambda (extent arg)
229                  (set-extent-property extent 'start-open t))
230                nil point (min (1+ (point)) (point-max))))
231
232 (defun gnus-xmas-article-push-button (event)
233   "Check text under the mouse pointer for a callback function.
234 If the text under the mouse pointer has a `gnus-callback' property,
235 call it with the value of the `gnus-data' text property."
236   (interactive "e")
237   (set-buffer (window-buffer (event-window event)))
238   (let* ((pos (event-closest-point event))
239          (data (get-text-property pos 'gnus-data))
240          (fun (get-text-property pos 'gnus-callback)))
241     (when fun
242       (funcall fun data))))
243
244 (defun gnus-xmas-move-overlay (extent start end &optional buffer)
245   (set-extent-endpoints extent start end))
246
247 ;; Fixed by Christopher Davis <ckd@loiosh.kei.com>.
248 (defun gnus-xmas-article-add-button (from to fun &optional data)
249   "Create a button between FROM and TO with callback FUN and data DATA."
250   (when gnus-article-button-face
251     (gnus-overlay-put (gnus-make-overlay from to)
252                       'face gnus-article-button-face))
253   (gnus-add-text-properties
254    from to
255    (nconc
256     (and gnus-article-mouse-face
257          (list 'mouse-face gnus-article-mouse-face))
258     (list 'gnus-callback fun)
259     (and data (list 'gnus-data data))
260     (list 'highlight t))))
261
262 (defun gnus-xmas-window-top-edge (&optional window)
263   (nth 1 (window-pixel-edges window)))
264
265 (defun gnus-xmas-tree-minimize ()
266   (when (and gnus-tree-minimize-window
267              (not (one-window-p)))
268     (let* ((window-min-height 2)
269            (height (1+ (count-lines (point-min) (point-max))))
270            (min (max (1- window-min-height) height))
271            (tot (if (numberp gnus-tree-minimize-window)
272                     (min gnus-tree-minimize-window min)
273                   min))
274            (win (get-buffer-window (current-buffer)))
275            (wh (and win (1- (window-height win)))))
276       (when (and win
277                  (not (eq tot wh)))
278         (let ((selected (selected-window)))
279           (select-window win)
280           (enlarge-window (- tot wh))
281           (select-window selected))))))
282
283 ;; Select the lowest window on the frame.
284 (defun gnus-xmas-appt-select-lowest-window ()
285   (let* ((lowest-window (selected-window))
286          (bottom-edge (car (cdr (cdr (cdr (window-pixel-edges))))))
287          (last-window (previous-window))
288          (window-search t))
289     (while window-search
290       (let* ((this-window (next-window))
291              (next-bottom-edge (car (cdr (cdr (cdr
292                                                (window-pixel-edges
293                                                 this-window)))))))
294         (when (< bottom-edge next-bottom-edge)
295           (setq bottom-edge next-bottom-edge)
296           (setq lowest-window this-window))
297
298         (select-window this-window)
299         (when (eq last-window this-window)
300           (select-window lowest-window)
301           (setq window-search nil))))))
302
303 (defmacro gnus-xmas-menu-add (type &rest menus)
304   `(gnus-xmas-menu-add-1 ',type ',menus))
305 (put 'gnus-xmas-menu-add 'lisp-indent-function 1)
306
307 (defun gnus-xmas-menu-add-1 (type menus)
308   (when (and menu-bar-mode
309              (gnus-visual-p (intern (format "%s-menu" type)) 'menu))
310     (while menus
311       (easy-menu-add (symbol-value (pop menus))))))
312
313 (defun gnus-xmas-group-menu-add ()
314   (gnus-xmas-menu-add group
315     gnus-group-reading-menu gnus-group-group-menu gnus-group-misc-menu))
316
317 (defun gnus-xmas-summary-menu-add ()
318   (gnus-xmas-menu-add summary
319     gnus-summary-misc-menu gnus-summary-kill-menu
320     gnus-summary-article-menu gnus-summary-thread-menu
321     gnus-summary-post-menu ))
322
323 (defun gnus-xmas-article-menu-add ()
324   (gnus-xmas-menu-add article
325     gnus-article-article-menu gnus-article-treatment-menu))
326
327 (defun gnus-xmas-score-menu-add ()
328   (gnus-xmas-menu-add score
329     gnus-score-menu))
330
331 (defun gnus-xmas-pick-menu-add ()
332   (gnus-xmas-menu-add pick
333     gnus-pick-menu))
334
335 (defun gnus-xmas-topic-menu-add ()
336   (gnus-xmas-menu-add topic
337     gnus-topic-menu))
338
339 (defun gnus-xmas-binary-menu-add ()
340   (gnus-xmas-menu-add binary
341     gnus-binary-menu))
342
343 (defun gnus-xmas-tree-menu-add ()
344   (gnus-xmas-menu-add tree
345     gnus-tree-menu))
346
347 (defun gnus-xmas-server-menu-add ()
348   (gnus-xmas-menu-add menu
349     gnus-server-server-menu gnus-server-connections-menu))
350
351 (defun gnus-xmas-browse-menu-add ()
352   (gnus-xmas-menu-add browse
353     gnus-browse-menu))
354
355 (defun gnus-xmas-grouplens-menu-add ()
356   (gnus-xmas-menu-add grouplens
357     gnus-grouplens-menu))
358
359 (defun gnus-xmas-read-event-char ()
360   "Get the next event."
361   (let ((event (next-command-event)))
362     (sit-for 0)
363     ;; We junk all non-key events.  Is this naughty?
364     (while (not (or (key-press-event-p event)
365                     (button-press-event-p event)))
366       (dispatch-event event)
367       (setq event (next-command-event)))
368     (cons (and (key-press-event-p event)
369                (event-to-character event))
370           event)))
371
372 (defun gnus-xmas-group-remove-excess-properties ()
373   (let ((end (point))
374         (beg (progn (forward-line -1) (point))))
375     (remove-text-properties (1+ beg) end '(gnus-group nil))
376     (remove-text-properties
377      beg end
378      '(gnus-topic nil gnus-topic-level nil gnus-topic-visible nil))
379     (goto-char end)
380     (map-extents
381      (lambda (e ma)
382        (set-extent-property e 'start-closed t))
383      (current-buffer) beg end)))
384
385 (defun gnus-xmas-topic-remove-excess-properties ()
386   (let ((end (point))
387         (beg (progn (forward-line -1) (point))))
388     (remove-text-properties beg end '(gnus-group nil gnus-unread nil))
389     (remove-text-properties (1+ beg) end '(gnus-topic nil))
390     (goto-char end)))
391
392 (defun gnus-xmas-seconds-since-epoch (date)
393   "Return a floating point number that says how many seconds have lapsed between Jan 1 12:00:00 1970 and DATE."
394   (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
395                         (timezone-parse-date date)))
396          (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
397                         (timezone-parse-time
398                          (aref (timezone-parse-date date) 3))))
399          (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
400                         (timezone-parse-date "Jan 1 12:00:00 1970")))
401          (tday (- (timezone-absolute-from-gregorian
402                    (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
403                   (timezone-absolute-from-gregorian
404                    (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
405     (+ (nth 2 ttime)
406        (* (nth 1 ttime) 60)
407        (* (float (nth 0 ttime)) 60 60)
408        (* (float tday) 60 60 24))))
409
410 (defun gnus-xmas-define ()
411   (setq gnus-mouse-2 [button2])
412
413   (unless (memq 'underline (face-list))
414     (and (fboundp 'make-face)
415          (funcall (intern "make-face") 'underline)))
416   ;; Must avoid calling set-face-underline-p directly, because it
417   ;; is a defsubst in emacs19, and will make the .elc files non
418   ;; portable!
419   (unless (face-differs-from-default-p 'underline)
420     (funcall (intern "set-face-underline-p") 'underline t))
421
422   (cond
423    ((fboundp 'char-or-char-int-p)
424     ;; Handle both types of marks for XEmacs-20.x.
425     (fset 'gnus-characterp 'char-or-char-int-p))
426    ;; V19 of XEmacs, probably.
427    (t
428     (fset 'gnus-characterp 'characterp)))
429
430   (fset 'gnus-make-overlay 'make-extent)
431   (fset 'gnus-overlay-put 'set-extent-property)
432   (fset 'gnus-move-overlay 'gnus-xmas-move-overlay)
433   (fset 'gnus-overlay-end 'extent-end-position)
434   (fset 'gnus-extent-detached-p 'extent-detached-p)
435   (fset 'gnus-add-text-properties 'gnus-xmas-add-text-properties)
436   (fset 'gnus-put-text-property 'gnus-xmas-put-text-property)
437
438   (require 'text-props)
439   (if (and (<= emacs-major-version 19)
440            (< emacs-minor-version 14))
441       (fset 'gnus-set-text-properties 'gnus-xmas-set-text-properties))
442
443   (when (fboundp 'turn-off-scroll-in-place)
444     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
445
446   (unless (boundp 'standard-display-table)
447     (setq standard-display-table nil))
448
449   (defvar gnus-mouse-face-prop 'highlight)
450
451   (unless (fboundp 'encode-time)
452     (defun encode-time (sec minute hour day month year &optional zone)
453       (let ((seconds
454              (gnus-xmas-seconds-since-epoch
455               (timezone-make-arpa-date
456                year month day (timezone-make-time-string hour minute sec)
457                zone))))
458         (list (floor (/ seconds (expt 2 16)))
459               (round (mod seconds (expt 2 16)))))))
460
461   (defun gnus-byte-code (func)
462     "Return a form that can be `eval'ed based on FUNC."
463     (let ((fval (symbol-function func)))
464       (if (compiled-function-p fval)
465           (list 'funcall fval)
466         (cons 'progn (cdr (cdr fval))))))
467
468   (fset 'gnus-x-color-values
469         (if (fboundp 'x-color-values)
470             'x-color-values
471           (lambda (color)
472             (color-instance-rgb-components
473              (make-color-instance color))))))
474
475 (defun gnus-xmas-redefine ()
476   "Redefine lots of Gnus functions for XEmacs."
477   (fset 'gnus-summary-set-display-table 'gnus-xmas-summary-set-display-table)
478   (fset 'gnus-visual-turn-off-edit-menu 'identity)
479   (fset 'gnus-summary-recenter 'gnus-xmas-summary-recenter)
480   (fset 'gnus-extent-start-open 'gnus-xmas-extent-start-open)
481   (fset 'gnus-article-push-button 'gnus-xmas-article-push-button)
482   (fset 'gnus-article-add-button 'gnus-xmas-article-add-button)
483   (fset 'gnus-window-top-edge 'gnus-xmas-window-top-edge)
484   (fset 'gnus-read-event-char 'gnus-xmas-read-event-char)
485   (fset 'gnus-group-startup-message 'gnus-xmas-group-startup-message)
486   (fset 'gnus-tree-minimize 'gnus-xmas-tree-minimize)
487   (fset 'gnus-appt-select-lowest-window
488         'gnus-xmas-appt-select-lowest-window)
489   (fset 'gnus-mail-strip-quoted-names 'gnus-xmas-mail-strip-quoted-names)
490   (fset 'gnus-character-to-event 'character-to-event)
491   (fset 'gnus-mode-line-buffer-identification
492         'gnus-xmas-mode-line-buffer-identification)
493   (fset 'gnus-key-press-event-p 'key-press-event-p)
494   (fset 'gnus-region-active-p 'region-active-p)
495
496   (add-hook 'gnus-group-mode-hook 'gnus-xmas-group-menu-add)
497   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
498   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add)
499   (add-hook 'gnus-score-mode-hook 'gnus-xmas-score-menu-add)
500
501   (add-hook 'gnus-pick-mode-hook 'gnus-xmas-pick-menu-add)
502   (add-hook 'gnus-topic-mode-hook 'gnus-xmas-topic-menu-add)
503   (add-hook 'gnus-tree-mode-hook 'gnus-xmas-tree-menu-add)
504   (add-hook 'gnus-binary-mode-hook 'gnus-xmas-binary-menu-add)
505   (add-hook 'gnus-grouplens-mode-hook 'gnus-xmas-grouplens-menu-add)
506   (add-hook 'gnus-server-mode-hook 'gnus-xmas-server-menu-add)
507   (add-hook 'gnus-browse-mode-hook 'gnus-xmas-browse-menu-add)
508
509   (add-hook 'gnus-group-mode-hook 'gnus-xmas-setup-group-toolbar)
510   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
511
512   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-switch-horizontal-scrollbar-off)
513
514   (when (and (<= emacs-major-version 19)
515              (<= emacs-minor-version 13))
516     (setq gnus-article-x-face-too-ugly (when (eq (device-type) 'tty)
517                                          "."))
518     (fset 'gnus-highlight-selected-summary
519           'gnus-xmas-highlight-selected-summary)
520     (fset 'gnus-group-remove-excess-properties
521           'gnus-xmas-group-remove-excess-properties)
522     (fset 'gnus-topic-remove-excess-properties
523           'gnus-xmas-topic-remove-excess-properties)
524     (fset 'gnus-mode-line-buffer-identification 'identity)
525     (unless (boundp 'shell-command-switch)
526       (setq shell-command-switch "-c"))))
527
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