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