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