Merge the t-gnus-6_17-quimby branch.
[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 ;;   2005, 2006 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., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, 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 'timer-funcs)
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-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-read-event-char (&optional prompt)
336   "Get the next event."
337   (when prompt
338     (message "%s" prompt))
339   (let ((event (next-command-event)))
340     (sit-for 0)
341     ;; We junk all non-key events.  Is this naughty?
342     (while (not (or (key-press-event-p event)
343                     (button-press-event-p event)))
344       (dispatch-event event)
345       (setq event (next-command-event)))
346     (cons (and (key-press-event-p event)
347                (event-to-character event))
348           event)))
349
350 (defun gnus-xmas-define ()
351   (setq gnus-mouse-2 [button2])
352   (setq gnus-mouse-3 [button3])
353   (setq gnus-widget-button-keymap widget-button-keymap)
354
355   (unless (memq 'underline (face-list))
356     (and (fboundp 'make-face)
357          (funcall (intern "make-face") 'underline)))
358   ;; Must avoid calling set-face-underline-p directly, because it
359   ;; is a defsubst in emacs19, and will make the .elc files non
360   ;; portable!
361   (unless (face-differs-from-default-p 'underline)
362     (funcall (intern "set-face-underline-p") 'underline t))
363
364   (cond
365    ((fboundp 'char-or-char-int-p)
366     ;; Handle both types of marks for XEmacs-20.x.
367     (defalias 'gnus-characterp 'char-or-char-int-p))
368    ;; V19 of XEmacs, probably.
369    (t
370     (defalias 'gnus-characterp 'characterp)))
371
372   (defalias 'gnus-make-overlay 'make-extent)
373   (defalias 'gnus-delete-overlay 'delete-extent)
374   (defalias 'gnus-overlay-put 'set-extent-property)
375   (defalias 'gnus-move-overlay 'gnus-xmas-move-overlay)
376   (defalias 'gnus-overlay-buffer 'extent-object)
377   (defalias 'gnus-overlay-start 'extent-start-position)
378   (defalias 'gnus-overlay-end 'extent-end-position)
379   (defalias 'gnus-kill-all-overlays 'gnus-xmas-kill-all-overlays)
380   (defalias 'gnus-extent-detached-p 'extent-detached-p)
381   (defalias 'gnus-add-text-properties 'gnus-xmas-add-text-properties)
382   (defalias 'gnus-put-text-property 'gnus-xmas-put-text-property)
383   (defalias 'gnus-deactivate-mark 'ignore)
384   (defalias 'gnus-window-edges 'window-pixel-edges)
385   (defalias 'gnus-assq-delete-all 'gnus-xmas-assq-delete-all)
386
387   (unless (boundp 'standard-display-table)
388     (setq standard-display-table nil))
389
390   (defvar gnus-mouse-face-prop 'highlight)
391
392   (defun gnus-byte-code (func)
393     "Return a form that can be `eval'ed based on FUNC."
394     (let ((fval (indirect-function func)))
395       (if (compiled-function-p fval)
396           (list 'funcall fval)
397         (cons 'progn (cdr (cdr fval))))))
398
399   (defalias 'gnus-x-color-values
400     (if (fboundp 'x-color-values)
401         'x-color-values
402       (lambda (color)
403         (color-instance-rgb-components
404          (make-color-instance color)))))
405
406   (unless (fboundp 'char-width)
407     (defalias 'char-width (lambda (ch) 1))))
408
409 (defun gnus-xmas-redefine ()
410   "Redefine lots of Gnus functions for XEmacs."
411   (defalias 'gnus-summary-set-display-table 'gnus-xmas-summary-set-display-table)
412   (defalias 'gnus-visual-turn-off-edit-menu 'identity)
413   (defalias 'gnus-summary-recenter 'gnus-xmas-summary-recenter)
414   (defalias 'gnus-extent-start-open 'gnus-xmas-extent-start-open)
415   (defalias 'gnus-article-push-button 'gnus-xmas-article-push-button)
416   (defalias 'gnus-window-top-edge 'gnus-xmas-window-top-edge)
417   (defalias 'gnus-read-event-char 'gnus-xmas-read-event-char)
418   (defalias 'gnus-group-startup-message 'gnus-xmas-group-startup-message)
419   (defalias 'gnus-tree-minimize 'gnus-xmas-tree-minimize)
420   (defalias 'gnus-select-lowest-window
421     'gnus-xmas-select-lowest-window)
422   (defalias 'gnus-mail-strip-quoted-names 'gnus-xmas-mail-strip-quoted-names)
423   (defalias 'gnus-character-to-event 'character-to-event)
424   (defalias 'gnus-mode-line-buffer-identification
425     'gnus-xmas-mode-line-buffer-identification)
426   (defalias 'gnus-key-press-event-p 'key-press-event-p)
427   (defalias 'gnus-region-active-p 'region-active-p)
428   (defalias 'gnus-mark-active-p 'region-exists-p)
429   (defalias 'gnus-annotation-in-region-p 'gnus-xmas-annotation-in-region-p)
430   (defalias 'gnus-mime-button-menu 'gnus-xmas-mime-button-menu)
431   (defalias 'gnus-mime-security-button-menu
432     'gnus-xmas-mime-security-button-menu)
433   (defalias 'gnus-image-type-available-p 'gnus-xmas-image-type-available-p)
434   (defalias 'gnus-put-image 'gnus-xmas-put-image)
435   (defalias 'gnus-create-image 'gnus-xmas-create-image)
436   (defalias 'gnus-remove-image 'gnus-xmas-remove-image)
437
438   ;; These ones are not defcutom'ed, sometimes not even defvar'ed. They
439   ;; probably should. If that is done, the code below should then be moved
440   ;; where each variable is defined, in order not to mess with user settings.
441   ;; -- didier
442   (add-hook 'gnus-score-mode-hook 'gnus-xmas-score-menu-add)
443   (add-hook 'gnus-binary-mode-hook 'gnus-xmas-binary-menu-add)
444   (add-hook 'gnus-server-mode-hook 'gnus-xmas-server-menu-add)
445   (add-hook 'gnus-browse-mode-hook 'gnus-xmas-browse-menu-add)
446   (add-hook 'gnus-draft-mode-hook 'gnus-xmas-draft-menu-add)
447   (add-hook 'gnus-mailing-list-mode-hook 'gnus-xmas-mailing-list-menu-add)
448
449   (when (featurep 'mule)
450     (defun gnus-truncate-string (str end-column &optional start-column padding)
451       "Truncate string STR to end at column END-COLUMN.
452 The optional 2nd arg START-COLUMN, if non-nil, specifies
453 the starting column; that means to return the characters occupying
454 columns START-COLUMN ... END-COLUMN of STR.
455
456 The optional 3rd arg PADDING, if non-nil, specifies a padding character
457 to add at the end of the result if STR doesn't reach column END-COLUMN,
458 or if END-COLUMN comes in the middle of a character in STR.
459 PADDING is also added at the beginning of the result
460 if column START-COLUMN appears in the middle of a character in STR.
461
462 If PADDING is nil, no padding is added in these cases, so
463 the resulting string may be narrower than END-COLUMN.
464 \[Emacs 20.3 emulating function]"
465       (or start-column
466           (setq start-column 0))
467       (let ((len (length str))
468             (idx 0)
469             (column 0)
470             (head-padding "") (tail-padding "")
471             ch last-column last-idx from-idx)
472         (condition-case nil
473             (while (< column start-column)
474               (setq ch (aref str idx)
475                     column (+ column (char-width ch))
476                     idx (1+ idx)))
477           (args-out-of-range (setq idx len)))
478         (if (< column start-column)
479             (if padding (make-string end-column padding) "")
480           (if (and padding (> column start-column))
481               (setq head-padding
482                     (make-string (- column start-column) padding)))
483           (setq from-idx idx)
484           (if (< end-column column)
485               (setq idx from-idx)
486             (condition-case nil
487                 (while (< column end-column)
488                   (setq last-column column
489                         last-idx idx
490                         ch (aref str idx)
491                         column (+ column (char-width ch))
492                         idx (1+ idx)))
493               (args-out-of-range (setq idx len)))
494             (if (> column end-column)
495                 (setq column last-column idx last-idx))
496             (if (and padding (< column end-column))
497                 (setq tail-padding
498                       (make-string (- end-column column) padding))))
499           (setq str (substring str from-idx idx))
500           (if padding
501               (concat head-padding str tail-padding)
502             str))))))
503
504 ;;; XEmacs logo and toolbar.
505
506 (defun gnus-xmas-group-startup-message (&optional x y)
507   "Insert startup message in current buffer."
508   ;; Insert the message.
509   (erase-buffer)
510   (cond
511    ((and (console-on-window-system-p)
512          (or (featurep 'xpm)
513              (featurep 'xbm)))
514     (let* ((logo-xpm (expand-file-name "gnus.xpm" gnus-xmas-glyph-directory))
515            (logo-xbm (expand-file-name "gnus.xbm" gnus-xmas-glyph-directory))
516            (glyph (make-glyph
517                    (cond ((featurep 'xpm)
518                           `[xpm
519                             :file ,logo-xpm
520                             :color-symbols
521                             (("thing" . ,(car gnus-logo-colors))
522                              ("shadow" . ,(cadr gnus-logo-colors))
523                              ("oort" . "#eeeeee")
524                              ("background" . ,(face-background 'default)))])
525                          ((featurep 'xbm)
526                           `[xbm :file ,logo-xbm])
527                          (t [nothing]))))
528            (wpheight (window-pixel-height))
529            (rest (max 0 (1- (/ (* (- wpheight (glyph-height glyph))
530                                   (window-height))
531                                wpheight 2)))))
532       (insert " ")
533       (set-extent-begin-glyph (make-extent (point) (point)) glyph)
534       (goto-char (point-min))
535       (while (not (eobp))
536         (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
537                              ?\ ))
538         (forward-line 1))
539       (setq gnus-simple-splash nil)
540       (goto-char (point-min))
541       (insert gnus-product-name " " gnus-version-number
542               (if (zerop (string-to-number gnus-revision-number))
543                   ""
544                 (concat " (r" gnus-revision-number ")"))
545               " based on " gnus-original-product-name " v"
546               gnus-original-version-number "\n")
547       (end-of-line 0)
548       (put-text-property (point-min) (point) 'face 'gnus-splash)
549       (insert-char ?\  (prog1
550                            (max 0 (/ (- (window-width) (point)) 2))
551                          (goto-char (point-min))))
552       (forward-line 1)
553       (insert-char ?\n rest)
554       (set-window-start (selected-window) (point-min))))
555    (t
556     (insert "
557           _    ___ _             _
558           _ ___ __ ___  __    _ ___
559           __   _     ___    __  ___
560               _           ___     _
561              _  _ __             _
562              ___   __            _
563                    __           _
564                     _      _   _
565                    _      _    _
566                       _  _    _
567                   __  ___
568                  _   _ _     _
569                 _   _
570               _    _
571              _    _
572             _
573           __
574
575 "
576             )
577     (goto-char (point-min))
578     (insert gnus-product-name " " gnus-version-number
579             (if (zerop (string-to-number gnus-revision-number))
580                 ""
581               (concat " (r" gnus-revision-number ")"))
582             " based on " gnus-original-product-name " v"
583             gnus-original-version-number)
584     (insert-char ?\  (prog1
585                          (max 0 (/ (- (window-width) (point)) 2))
586                        (goto-char (point-min))))
587     (forward-line 1)
588     ;; And then hack it.
589     (gnus-indent-rigidly (point) (point-max)
590                          (/ (max (- (window-width) (or x 46)) 0) 2))
591     (goto-char (point-min))
592     (forward-line 1)
593     (let* ((pheight (count-lines (point-min) (point-max)))
594            (wheight (window-height))
595            (rest (- wheight pheight)))
596       (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
597     ;; Paint it.
598     (put-text-property (point-min) (point-max) 'face 'gnus-splash)))
599   (goto-char (point-min))
600   (setq modeline-buffer-identification
601         (list (concat gnus-version ": *Group*")))
602   (set-buffer-modified-p t))
603
604
605 ;;; The toolbar.
606
607 (defun gnus-xmas-update-toolbars ()
608   "Update the toolbars' appearance."
609   (when (and (not noninteractive)
610              (featurep 'gnus-xmas))
611     (save-excursion
612       (dolist (buffer (buffer-list))
613         (set-buffer buffer)
614         (cond ((eq major-mode 'gnus-group-mode)
615                (gnus-xmas-setup-group-toolbar))
616               ((eq major-mode 'gnus-summary-mode)
617                (gnus-xmas-setup-summary-toolbar)))))))
618
619 (defcustom gnus-use-toolbar (if (featurep 'toolbar) 'default)
620   "*Position to display the toolbar.  Nil means do not use a toolbar.
621 If it is non-nil, it should be one of the symbols `default', `top',
622 `bottom', `right', and `left'.  `default' means to use the default
623 toolbar, the rest mean to display the toolbar on the place which those
624 names show."
625   :type '(choice (const default)
626                  (const top) (const bottom) (const left) (const right)
627                  (const :tag "no toolbar" nil))
628   :set (lambda (symbol value)
629          (set-default
630           symbol
631           (if (or (not value)
632                   (memq value (list 'default 'top 'bottom 'right 'left)))
633               value
634             'default))
635          (gnus-xmas-update-toolbars))
636   :group 'gnus-xmas)
637
638 (defcustom gnus-toolbar-thickness
639   (if (featurep 'toolbar)
640       (cons (specifier-instance default-toolbar-height)
641             (specifier-instance default-toolbar-width)))
642   "*Cons of the height and the width specifying the thickness of a toolbar.
643 The height is used for the toolbar displayed on the top or the bottom,
644 the width is used for the toolbar displayed on the right or the left."
645   :type '(cons :tag "height & width"
646                (integer :tag "height") (integer :tag "width"))
647   :set (lambda (symbol value)
648          (set-default
649           symbol
650           (if (and (consp value) (natnump (car value)) (natnump (cdr value)))
651               value
652             '(37 . 40)))
653          (gnus-xmas-update-toolbars))
654   :group 'gnus-xmas)
655
656 (defvar gnus-group-toolbar
657   '([gnus-group-get-new-news gnus-group-get-new-news t "Get new news"]
658     [gnus-group-get-new-news-this-group
659      gnus-group-get-new-news-this-group t "Get new news in this group"]
660     [gnus-group-catchup-current
661      gnus-group-catchup-current t "Catchup group"]
662     [gnus-group-describe-group
663      gnus-group-describe-group t "Describe group"]
664     [gnus-group-unsubscribe gnus-group-unsubscribe t "Unsubscribe group"]
665     [gnus-group-subscribe gnus-group-subscribe t "Subscribe group"]
666     [gnus-group-kill-group gnus-group-kill-group t "Kill group"]
667     [gnus-summary-mail-save
668      gnus-group-save-newsrc t "Save .newsrc files"] ; borrowed icon.
669     [gnus-group-exit gnus-group-exit t "Exit Gnus"])
670   "The group buffer toolbar.")
671
672 (defvar gnus-summary-toolbar
673   '([gnus-summary-prev-unread
674      gnus-summary-prev-page-or-article t "Page up"]
675     [gnus-summary-next-unread
676      gnus-summary-next-page t "Page down"]
677     [gnus-summary-post-news
678      gnus-summary-post-news t "Post an article"]
679     [gnus-summary-followup-with-original
680      gnus-summary-followup-with-original t
681      "Post a followup and yank the original"]
682     [gnus-summary-followup
683      gnus-summary-followup t "Post a followup"]
684     [gnus-summary-reply-with-original
685      gnus-summary-reply-with-original t "Mail a reply and yank the original"]
686     [gnus-summary-reply
687      gnus-summary-reply t "Mail a reply"]
688     [gnus-summary-caesar-message
689      gnus-summary-caesar-message t "Rot 13"]
690     [gnus-uu-decode-uu
691      gnus-uu-decode-uu t "Decode uuencoded articles"]
692     [gnus-summary-save-article-file
693      gnus-summary-save-article-file t "Save article in file"]
694     [gnus-summary-save-article
695      gnus-summary-save-article t "Save article"]
696     [gnus-uu-post-news
697      gnus-uu-post-news t "Post a uuencoded article"]
698     [gnus-summary-cancel-article
699      gnus-summary-cancel-article t "Cancel article"]
700     [gnus-summary-catchup
701      gnus-summary-catchup t "Catchup"]
702     [gnus-summary-catchup-and-exit
703      gnus-summary-catchup-and-exit t "Catchup and exit"]
704     [gnus-summary-exit gnus-summary-exit t "Exit this summary"])
705   "The summary buffer toolbar.")
706
707 (defvar gnus-summary-mail-toolbar
708   '(
709     [gnus-summary-prev-unread
710      gnus-summary-prev-unread-article t "Prev unread article"]
711     [gnus-summary-next-unread
712      gnus-summary-next-unread-article t "Next unread article"]
713     [gnus-summary-mail-reply gnus-summary-reply t "Reply"]
714     [gnus-summary-mail-originate gnus-summary-post-news t "Originate"]
715     [gnus-summary-mail-save gnus-summary-save-article t "Save"]
716     [gnus-summary-mail-copy gnus-summary-copy-article t "Copy message"]
717     [gnus-summary-mail-forward gnus-summary-mail-forward t "Forward message"]
718     [gnus-summary-caesar-message
719      gnus-summary-caesar-message t "Rot 13"]
720     [gnus-uu-decode-uu
721      gnus-uu-decode-uu t "Decode uuencoded articles"]
722     [gnus-summary-save-article-file
723      gnus-summary-save-article-file t "Save article in file"]
724     [gnus-summary-save-article
725      gnus-summary-save-article t "Save article"]
726     [gnus-summary-cancel-article ; usenet : cancellation :: mail : deletion.
727      gnus-summary-delete-article t "Delete message"]
728     [gnus-summary-catchup
729      gnus-summary-catchup t "Catchup"]
730     [gnus-summary-catchup-and-exit
731      gnus-summary-catchup-and-exit t "Catchup and exit"]
732     [gnus-summary-exit gnus-summary-exit t "Exit this summary"])
733   "The summary buffer mail toolbar.")
734
735 (defun gnus-xmas-setup-toolbar (toolbar)
736   (when (featurep 'toolbar)
737     (if (and gnus-use-toolbar
738              (message-xmas-setup-toolbar toolbar nil "gnus"))
739         (let ((bar (or (intern-soft (format "%s-toolbar" gnus-use-toolbar))
740                        'default-toolbar))
741               (height (car gnus-toolbar-thickness))
742               (width (cdr gnus-toolbar-thickness))
743               (cur (current-buffer))
744               bars)
745           (set-specifier (symbol-value bar) toolbar cur)
746           (set-specifier default-toolbar-height height cur)
747           (set-specifier default-toolbar-width width cur)
748           (set-specifier top-toolbar-height height cur)
749           (set-specifier bottom-toolbar-height height cur)
750           (set-specifier right-toolbar-width width cur)
751           (set-specifier left-toolbar-width width cur)
752           (if (eq bar 'default-toolbar)
753               (progn
754                 (remove-specifier default-toolbar-visible-p cur)
755                 (remove-specifier top-toolbar cur)
756                 (remove-specifier top-toolbar-visible-p cur)
757                 (remove-specifier bottom-toolbar cur)
758                 (remove-specifier bottom-toolbar-visible-p cur)
759                 (remove-specifier right-toolbar cur)
760                 (remove-specifier right-toolbar-visible-p cur)
761                 (remove-specifier left-toolbar cur)
762                 (remove-specifier left-toolbar-visible-p cur))
763             (set-specifier (symbol-value (intern (format "%s-visible-p" bar)))
764                            t cur)
765             (setq bars (delq bar (list 'default-toolbar
766                                        'bottom-toolbar 'top-toolbar
767                                        'right-toolbar 'left-toolbar)))
768             (while bars
769               (set-specifier (symbol-value (intern (format "%s-visible-p"
770                                                            (pop bars))))
771                              nil cur))))
772       (let ((cur (current-buffer)))
773         (set-specifier default-toolbar-visible-p nil cur)
774         (set-specifier top-toolbar-visible-p nil cur)
775         (set-specifier bottom-toolbar-visible-p nil cur)
776         (set-specifier right-toolbar-visible-p nil cur)
777         (set-specifier left-toolbar-visible-p nil cur)))))
778
779 (defun gnus-xmas-setup-group-toolbar ()
780   (gnus-xmas-setup-toolbar gnus-group-toolbar))
781
782 (defun gnus-xmas-setup-summary-toolbar ()
783   (gnus-xmas-setup-toolbar (if (gnus-news-group-p gnus-newsgroup-name)
784                                gnus-summary-toolbar
785                              gnus-summary-mail-toolbar)))
786
787 (defun gnus-xmas-mail-strip-quoted-names (address)
788   "Protect mail-strip-quoted-names from nil input.
789 XEmacs compatibility workaround."
790   (if (null address)
791       nil
792     (mail-strip-quoted-names address)))
793
794 (defun gnus-xmas-call-region (command &rest args)
795   (apply
796    'call-process-region (point-min) (point-max) command t '(t nil) nil
797    args))
798
799 (defvar gnus-xmas-modeline-left-extent
800   (let ((ext (copy-extent modeline-buffer-id-left-extent)))
801     ext))
802
803 (defvar gnus-xmas-modeline-right-extent
804   (let ((ext (copy-extent modeline-buffer-id-right-extent)))
805     ext))
806
807 (defvar gnus-xmas-modeline-glyph
808   (progn
809     (let* ((file-xpm (expand-file-name "gnus-pointer.xpm"
810                                        gnus-xmas-glyph-directory))
811            (file-xbm (expand-file-name "gnus-pointer.xbm"
812                                        gnus-xmas-glyph-directory))
813            (glyph (make-glyph
814                    ;; Gag gag gag.
815                    (cond ((featurep 'xpm)
816                           ;; Let's try a nifty XPM
817                           `[xpm :file ,file-xpm])
818                          ((featurep 'xbm)
819                           ;; Then a not-so-nifty XBM
820                           `[xbm :file ,file-xbm])
821                          ;; Then the simple string
822                          (t [string :data "Gnus:"])))))
823       (set-glyph-face glyph 'modeline-buffer-id)
824       glyph)))
825
826 (defun gnus-xmas-mode-line-buffer-identification (line)
827   (let ((line (car line))
828         chop)
829     (cond
830      ;; This is some weird type of id.
831      ((not (stringp line))
832       (list line))
833      ;; This is non-standard, so we just pass it through.
834      ((not (string-match "^Gnus:" line))
835       (list line))
836      ;; We have a standard line, so we colorize and glyphize it a bit.
837      (t
838       (setq chop (match-end 0))
839       (list
840        (if gnus-xmas-modeline-glyph
841            (cons gnus-xmas-modeline-left-extent gnus-xmas-modeline-glyph)
842          (cons gnus-xmas-modeline-left-extent (substring line 0 chop)))
843        (cons gnus-xmas-modeline-right-extent (substring line chop)))))))
844
845 (defun gnus-xmas-splash ()
846   (when (eq (device-type) 'x)
847     (gnus-splash)))
848
849 (defun gnus-xmas-annotation-in-region-p (b e)
850   (or (map-extents (lambda (e u) t) nil b e nil nil 'mm t)
851       (if (= b e)
852           (eq (cadr (memq 'gnus-undeletable (text-properties-at b))) t)
853         (text-property-any b e 'gnus-undeletable t))))
854
855 (defun gnus-xmas-mime-button-menu (event prefix)
856   "Construct a context-sensitive menu of MIME commands."
857   (interactive "e\nP")
858   (let ((response (get-popup-menu-response
859                    `("MIME Part"
860                      ,@(mapcar (lambda (c) `[,(caddr c) ,(car c) t])
861                                gnus-mime-button-commands)))))
862     (set-buffer (event-buffer event))
863     (goto-char (event-point event))
864     (funcall (event-function response) (event-object response))))
865
866 (defun gnus-xmas-mime-security-button-menu (event prefix)
867   "Construct a context-sensitive menu of security commands."
868   (interactive "e\nP")
869   (let ((response
870          (get-popup-menu-response
871           `("Security Part"
872             ,@(delq nil
873                     (mapcar (lambda (c)
874                               (unless (eq (car c) 'undefined)
875                                 `[,(caddr c) ,(car c) t]))
876                             gnus-mime-security-button-commands))))))
877     (set-buffer (event-buffer event))
878     (goto-char (event-point event))
879     (funcall (event-function response) (event-object response))))
880
881 (defun gnus-group-add-icon ()
882   "Add an icon to the current line according to `gnus-group-icon-list'."
883   (let* ((p (point))
884          (end (point-at-eol))
885          ;; now find out where the line starts and leave point there.
886          (beg (progn (beginning-of-line) (point))))
887     (save-restriction
888       (narrow-to-region beg end)
889       (goto-char beg)
890       (when (search-forward "==&&==" nil t)
891         (let* ((group (gnus-group-group-name))
892                (entry (gnus-group-entry group))
893                (unread (if (numberp (car entry)) (car entry) 0))
894                (active (gnus-active group))
895                (total (if active (1+ (- (cdr active) (car active))) 0))
896                (info (nth 2 entry))
897                (method (gnus-server-get-method group (gnus-info-method info)))
898                (marked (gnus-info-marks info))
899                (mailp (memq 'mail (assoc (symbol-name
900                                           (car (or method gnus-select-method)))
901                                          gnus-valid-select-methods)))
902                (level (or (gnus-info-level info) gnus-level-killed))
903                (score (or (gnus-info-score info) 0))
904                (ticked (gnus-range-length (cdr (assq 'tick marked))))
905                (group-age (gnus-group-timestamp-delta group))
906                (inhibit-read-only t)
907                (list gnus-group-icon-list)
908                (mystart (match-beginning 0))
909                (myend (match-end 0)))
910           (goto-char (point-min))
911           (while (and list
912                       (not (eval (caar list))))
913             (setq list (cdr list)))
914           (if list
915               (let* ((file (cdar list))
916                      (glyph (gnus-group-icon-create-glyph
917                              (buffer-substring mystart myend)
918                              file)))
919                 (if glyph
920                     (progn
921                       (mapcar 'delete-annotation (annotations-at myend))
922                       (let ((ext (make-extent mystart myend))
923                             (ant (make-annotation glyph myend 'text)))
924                         ;; set text extent params
925                         (set-extent-property ext 'end-open t)
926                         (set-extent-property ext 'start-open t)
927                         (set-extent-property ext 'invisible t)))
928                   (delete-region mystart myend)))
929             (delete-region mystart myend))))
930       (widen))
931     (goto-char p)))
932
933 (defun gnus-group-icon-create-glyph (substring pixmap)
934   "Create a glyph for insertion into a group line."
935   (or
936    (cdr-safe (assoc pixmap gnus-group-icon-cache))
937    (let* ((glyph (make-glyph
938                   (list
939                    (cons 'x
940                          (expand-file-name pixmap gnus-xmas-glyph-directory))
941                    (cons 'mswindows
942                          (expand-file-name pixmap gnus-xmas-glyph-directory))
943                    (cons 'tty substring)))))
944      (setq gnus-group-icon-cache
945            (cons (cons pixmap glyph) gnus-group-icon-cache))
946      (set-glyph-face glyph 'default)
947      glyph)))
948
949 (defun gnus-xmas-mailing-list-menu-add ()
950   (gnus-xmas-menu-add mailing-list
951     gnus-mailing-list-menu))
952
953 (defun gnus-xmas-image-type-available-p (type)
954   (and window-system
955        (featurep (if (eq type 'pbm) 'xbm type))))
956
957 (defun gnus-xmas-create-image (file &optional type data-p &rest props)
958   (let ((type (if type
959                   (symbol-name type)
960                 (car (last (split-string file "[.]")))))
961         (face (plist-get props :face))
962         glyph)
963     (when (equal type "pbm")
964       (with-temp-buffer
965         (if data-p
966             (insert file)
967           (insert-file-contents-literally file))
968         (shell-command-on-region (point-min) (point-max)
969                                  "ppmtoxpm 2>/dev/null" t)
970         (setq file (buffer-string)
971               type "xpm"
972               data-p t)))
973     (setq glyph
974           (if (equal type "xbm")
975               (make-glyph (list (cons 'x file)))
976             (with-temp-buffer
977               (if data-p
978                   (insert file)
979                 (insert-file-contents-literally file))
980               (make-glyph
981                (vector
982                 (or (intern type)
983                     (mm-image-type-from-buffer))
984                 :data (buffer-string))))))
985     (when face
986       (set-glyph-face glyph face))
987     glyph))
988
989 (defun gnus-xmas-put-image (glyph &optional string category)
990   "Insert STRING, but display GLYPH.
991 Warning: Don't insert text immediately after the image."
992   (let ((begin (point))
993         extent)
994     (if (and (bobp) (not string))
995         (setq string " "))
996     (if string
997         (insert string)
998       (setq begin (1- begin)))
999     (setq extent (make-extent begin (point)))
1000     (set-extent-property extent 'gnus-image category)
1001     (set-extent-property extent 'duplicable t)
1002     (if string
1003         (set-extent-property extent 'invisible t))
1004     (set-extent-property extent 'end-glyph glyph))
1005   glyph)
1006
1007 (defun gnus-xmas-remove-image (image &optional category)
1008   "Remove the image matching IMAGE and CATEGORY found first."
1009   (map-extents
1010    (lambda (ext unused)
1011      (when (equal (extent-end-glyph ext) image)
1012        (set-extent-property ext 'invisible nil)
1013        (set-extent-property ext 'end-glyph nil)
1014        t))
1015    nil nil nil nil nil 'gnus-image category))
1016
1017 (defun gnus-xmas-assq-delete-all (key alist)
1018   (let ((elem nil))
1019     (while (setq elem (assq key alist))
1020       (setq alist (delq elem alist)))
1021     alist))
1022
1023 (provide 'gnus-xmas)
1024
1025 ;;; gnus-xmas.el ends here