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