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