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