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