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