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