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