*** empty log message ***
[gnus] / lisp / gnus-xmas.el
1 ;;; gnus-xmas.el --- Gnus functions for XEmacs
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'text-props)
29 (defvar menu-bar-mode (featurep 'menubar))
30 (require 'messagexmas)
31
32 (defvar gnus-xmas-glyph-directory nil
33   "*Directory where Gnus logos and icons are located.
34 If this variable is nil, Gnus will try to locate the directory
35 automatically.")
36
37 (defvar gnus-xmas-logo-color-alist
38   '((flame "#cc3300" "#ff2200")
39     (pine "#c0cc93" "#f8ffb8")
40     (moss "#a1cc93" "#d2ffb8")
41     (irish "#04cc90" "#05ff97")
42     (sky "#049acc" "#05deff")
43     (tin "#6886cc" "#82b6ff")
44     (velvet "#7c68cc" "#8c82ff")
45     (grape "#b264cc" "#cf7df")
46     (labia "#cc64c2" "#fd7dff")
47     (berry "#cc6485" "#ff7db5")
48     (neutral "#b4b4b4" "#878787")
49     (september "#bf9900" "#ffcc00"))
50   "Color alist used for the Gnus logo.")
51
52 (defvar gnus-xmas-logo-color-style 'flame
53   "Color styles used for the Gnus logo.")
54
55 (defvar gnus-xmas-logo-colors
56   (cdr (assq gnus-xmas-logo-color-style gnus-xmas-logo-color-alist))
57   "Colors used for the Gnus logo.")
58
59 (defvar gnus-article-x-face-command
60   (if (featurep 'xface)
61       'gnus-xmas-article-display-xface
62     "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -")
63   "String or function to be executed to display an X-Face header.
64 If it is a string, the command will be executed in a sub-shell
65 asynchronously.  The compressed face will be piped to this command.")
66
67 ;;; Internal variables.
68
69 ;; Don't warn about these undefined variables.
70
71 (defvar gnus-group-mode-hook)
72 (defvar gnus-summary-mode-hook)
73 (defvar gnus-article-mode-hook)
74
75 ;;defined in gnus.el
76 (defvar gnus-active-hashtb)
77 (defvar gnus-article-buffer)
78 (defvar gnus-auto-center-summary)
79 (defvar gnus-buffer-list)
80 (defvar gnus-current-headers)
81 (defvar gnus-level-killed)
82 (defvar gnus-level-zombie)
83 (defvar gnus-newsgroup-bookmarks)
84 (defvar gnus-newsgroup-dependencies)
85 (defvar gnus-newsgroup-selected-overlay)
86 (defvar gnus-newsrc-hashtb)
87 (defvar gnus-read-mark)
88 (defvar gnus-refer-article-method)
89 (defvar gnus-reffed-article-number)
90 (defvar gnus-unread-mark)
91 (defvar gnus-version)
92 (defvar gnus-view-pseudos)
93 (defvar gnus-view-pseudos-separately)
94 (defvar gnus-visual)
95 (defvar gnus-zombie-list)
96 ;;defined in gnus-msg.el
97 (defvar gnus-article-copy)
98 (defvar gnus-check-before-posting)
99 ;;defined in gnus-vis.el
100 (defvar gnus-article-button-face)
101 (defvar gnus-article-mouse-face)
102 (defvar gnus-summary-selected-face)
103 (defvar gnus-group-reading-menu)
104 (defvar gnus-group-group-menu)
105 (defvar gnus-group-misc-menu)
106 (defvar gnus-summary-article-menu)
107 (defvar gnus-summary-thread-menu)
108 (defvar gnus-summary-misc-menu)
109 (defvar gnus-summary-post-menu)
110 (defvar gnus-summary-kill-menu)
111 (defvar gnus-article-article-menu)
112 (defvar gnus-article-treatment-menu)
113 (defvar gnus-mouse-2)
114 (defvar standard-display-table)
115 (defvar gnus-tree-minimize-window)
116
117 (defun gnus-xmas-set-text-properties (start end props &optional buffer)
118   "You should NEVER use this function.  It is ideologically blasphemous.
119 It is provided only to ease porting of broken FSF Emacs programs."
120   (if (stringp buffer)
121       nil
122     (map-extents (lambda (extent ignored)
123                    (remove-text-properties 
124                     start end
125                     (list (extent-property extent 'text-prop) nil)
126                     buffer))
127                  buffer start end nil nil 'text-prop)
128     (gnus-add-text-properties start end props buffer)))
129
130 (defun gnus-xmas-highlight-selected-summary ()
131   ;; Highlight selected article in summary buffer
132   (when gnus-summary-selected-face
133     (when gnus-newsgroup-selected-overlay
134       (delete-extent gnus-newsgroup-selected-overlay))
135     (setq gnus-newsgroup-selected-overlay 
136           (make-extent (gnus-point-at-bol) (gnus-point-at-eol)))
137     (set-extent-face gnus-newsgroup-selected-overlay
138                      gnus-summary-selected-face)))
139
140 (defvar gnus-xmas-force-redisplay nil
141   "If non-nil, force a redisplay before recentering the summary buffer.
142 This is ugly, but it works around a bug in `window-displayed-height'.")
143
144 (defun gnus-xmas-switch-horizontal-scrollbar-off ()
145   (set-specifier scrollbar-height (cons (current-buffer) 0)))
146
147 (defun gnus-xmas-summary-recenter ()
148   "\"Center\" point in the summary window.
149 If `gnus-auto-center-summary' is nil, or the article buffer isn't
150 displayed, no centering will be performed."
151   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
152   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
153   ;; Force redisplay to get properly computed window height.
154   (when gnus-xmas-force-redisplay
155     (sit-for 0))
156   (when gnus-auto-center-summary
157     (let* ((height (if (fboundp 'window-displayed-height)
158                        (window-displayed-height)
159                      (- (window-height) 2)))
160            (top (cond ((< height 4) 0)
161                       ((< height 7) 1)
162                       (t 2)))
163            (bottom (save-excursion (goto-char (point-max))
164                                    (forward-line (- height))
165                                    (point)))
166            (window (get-buffer-window (current-buffer))))
167       (when (get-buffer-window gnus-article-buffer)
168         ;; Only do recentering when the article buffer is displayed,
169         ;; Set the window start to either `bottom', which is the biggest
170         ;; possible valid number, or the second line from the top,
171         ;; whichever is the least.
172         (set-window-start
173          window (min bottom (save-excursion (forward-line (- top)) (point)))))
174       ;; Do horizontal recentering while we're at it.
175       (when (and (get-buffer-window (current-buffer) t)
176                  (not (eq gnus-auto-center-summary 'vertical)))
177         (let ((selected (selected-window)))
178           (select-window (get-buffer-window (current-buffer) t))
179           (gnus-summary-position-point)
180           (gnus-horizontal-recenter)
181           (select-window selected))))))
182
183 (defun gnus-xmas-add-hook (hook function &optional append local)
184   (add-hook hook function))
185
186 (defun gnus-xmas-add-text-properties (start end props &optional object)
187   (add-text-properties start end props object)
188   (put-text-property start end 'start-closed nil object))
189
190 (defun gnus-xmas-put-text-property (start end prop value &optional object)
191   (put-text-property start end prop value object)
192   (put-text-property start end 'start-closed nil object))
193
194 (defun gnus-xmas-extent-start-open (point)
195   (map-extents (lambda (extent arg)
196                  (set-extent-property extent 'start-open t))
197                nil point (min (1+ (point)) (point-max))))
198                   
199 (defun gnus-xmas-article-push-button (event)
200   "Check text under the mouse pointer for a callback function.
201 If the text under the mouse pointer has a `gnus-callback' property,
202 call it with the value of the `gnus-data' text property."
203   (interactive "e")
204   (set-buffer (window-buffer (event-window event)))
205   (let* ((pos (event-closest-point event))
206          (data (get-text-property pos 'gnus-data))
207          (fun (get-text-property pos 'gnus-callback)))
208     (when fun
209       (funcall fun data))))
210
211 (defun gnus-xmas-move-overlay (extent start end &optional buffer)
212   (set-extent-endpoints extent start end))
213
214 ;; Fixed by Christopher Davis <ckd@loiosh.kei.com>.
215 (defun gnus-xmas-article-add-button (from to fun &optional data)
216   "Create a button between FROM and TO with callback FUN and data DATA."
217   (when gnus-article-button-face
218     (gnus-overlay-put (gnus-make-overlay from to)
219                       'face gnus-article-button-face))
220   (gnus-add-text-properties 
221    from to
222    (nconc
223     (and gnus-article-mouse-face
224          (list 'mouse-face gnus-article-mouse-face))
225     (list 'gnus-callback fun)
226     (and data (list 'gnus-data data))
227     (list 'highlight t))))
228
229 (defun gnus-xmas-window-top-edge (&optional window)
230   (nth 1 (window-pixel-edges window)))
231
232 (defun gnus-xmas-tree-minimize ()
233   (when (and gnus-tree-minimize-window
234              (not (one-window-p)))
235     (let* ((window-min-height 2)
236            (height (1+ (count-lines (point-min) (point-max))))
237            (min (max (1- window-min-height) height))
238            (tot (if (numberp gnus-tree-minimize-window)
239                     (min gnus-tree-minimize-window min)
240                   min))
241            (win (get-buffer-window (current-buffer)))
242            (wh (and win (1- (window-height win)))))
243       (when (and win
244                  (not (eq tot wh)))
245         (let ((selected (selected-window)))
246           (select-window win)
247           (enlarge-window (- tot wh))
248           (select-window selected))))))
249
250 ;; Select the lowest window on the frame.
251 (defun gnus-xmas-appt-select-lowest-window ()
252   (let* ((lowest-window (selected-window))
253          (bottom-edge (car (cdr (cdr (cdr (window-pixel-edges))))))
254          (last-window (previous-window))
255          (window-search t))
256     (while window-search
257       (let* ((this-window (next-window))
258              (next-bottom-edge (car (cdr (cdr (cdr 
259                                                (window-pixel-edges 
260                                                 this-window)))))))
261         (when (< bottom-edge next-bottom-edge)
262           (setq bottom-edge next-bottom-edge)
263           (setq lowest-window this-window))
264
265         (select-window this-window)
266         (when (eq last-window this-window)
267           (select-window lowest-window)
268           (setq window-search nil))))))
269
270 (defmacro gnus-xmas-menu-add (type &rest menus)
271   `(gnus-xmas-menu-add-1 ',type ',menus))
272 (put 'gnus-xmas-menu-add 'lisp-indent-function 1)
273
274 (defun gnus-xmas-menu-add-1 (type menus)
275   (when (and menu-bar-mode
276              (gnus-visual-p (intern (format "%s-menu" type)) 'menu))
277     (while menus
278       (easy-menu-add (symbol-value (pop menus))))))
279
280 (defun gnus-xmas-group-menu-add ()
281   (gnus-xmas-menu-add group
282     gnus-group-reading-menu gnus-group-group-menu gnus-group-misc-menu))
283
284 (defun gnus-xmas-summary-menu-add ()
285   (gnus-xmas-menu-add summary
286     gnus-summary-misc-menu gnus-summary-kill-menu
287     gnus-summary-article-menu gnus-summary-thread-menu
288     gnus-summary-post-menu ))
289
290 (defun gnus-xmas-article-menu-add ()
291   (gnus-xmas-menu-add article
292     gnus-article-article-menu gnus-article-treatment-menu))
293
294 (defun gnus-xmas-score-menu-add ()
295   (gnus-xmas-menu-add score
296     gnus-score-menu))
297
298 (defun gnus-xmas-pick-menu-add ()
299   (gnus-xmas-menu-add pick
300     gnus-pick-menu))
301
302 (defun gnus-xmas-topic-menu-add ()
303   (gnus-xmas-menu-add topic
304     gnus-topic-menu))
305
306 (defun gnus-xmas-binary-menu-add ()
307   (gnus-xmas-menu-add binary
308     gnus-binary-menu))
309
310 (defun gnus-xmas-tree-menu-add ()
311   (gnus-xmas-menu-add tree
312     gnus-tree-menu))
313
314 (defun gnus-xmas-server-menu-add ()
315   (gnus-xmas-menu-add menu
316     gnus-server-server-menu gnus-server-connections-menu))
317
318 (defun gnus-xmas-browse-menu-add ()
319   (gnus-xmas-menu-add browse
320     gnus-browse-menu))
321
322 (defun gnus-xmas-grouplens-menu-add ()
323   (gnus-xmas-menu-add grouplens
324     gnus-grouplens-menu))
325
326 (defun gnus-xmas-read-event-char ()
327   "Get the next event."
328   (let ((event (next-command-event)))
329     (sit-for 0)
330     ;; We junk all non-key events.  Is this naughty?
331     (while (not (key-press-event-p event))
332       (setq event (next-command-event)))
333     (cons (and (key-press-event-p event) 
334                (event-to-character event)) 
335           event)))
336
337 (defun gnus-xmas-group-remove-excess-properties ()
338   (let ((end (point))
339         (beg (progn (forward-line -1) (point))))
340     (remove-text-properties (1+ beg) end '(gnus-group nil))
341     (remove-text-properties 
342      beg end 
343      '(gnus-topic nil gnus-topic-level nil gnus-topic-visible nil))
344     (goto-char end)
345     (map-extents 
346      (lambda (e ma)
347        (set-extent-property e 'start-closed t))
348      (current-buffer) beg end)))
349                   
350 (defun gnus-xmas-topic-remove-excess-properties ()
351   (let ((end (point))
352         (beg (progn (forward-line -1) (point))))
353     (remove-text-properties beg end '(gnus-group nil gnus-unread nil))
354     (remove-text-properties (1+ beg) end '(gnus-topic nil))
355     (goto-char end)))
356
357 (defun gnus-xmas-seconds-since-epoch (date)
358   "Return a floating point number that says how many seconds have lapsed between Jan 1 12:00:00 1970 and DATE."
359   (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
360                         (timezone-parse-date date)))
361          (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
362                         (timezone-parse-time
363                          (aref (timezone-parse-date date) 3))))
364          (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
365                         (timezone-parse-date "Jan 1 12:00:00 1970")))
366          (tday (- (timezone-absolute-from-gregorian 
367                    (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
368                   (timezone-absolute-from-gregorian 
369                    (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
370     (+ (nth 2 ttime)
371        (* (nth 1 ttime) 60)
372        (* (float (nth 0 ttime)) 60 60)
373        (* (float tday) 60 60 24))))
374
375 (defun gnus-xmas-define ()
376   (setq gnus-mouse-2 [button2])
377
378   (unless (memq 'underline (face-list))
379     (and (fboundp 'make-face)
380          (funcall (intern "make-face") 'underline)))
381   ;; Must avoid calling set-face-underline-p directly, because it
382   ;; is a defsubst in emacs19, and will make the .elc files non
383   ;; portable!
384   (unless (face-differs-from-default-p 'underline)
385     (funcall (intern "set-face-underline-p") 'underline t))
386
387   (cond
388    ((fboundp 'char-or-char-int-p)
389     ;; Handle both types of marks for XEmacs-20.x.
390     (fset 'gnus-characterp 'char-or-char-int-p))
391    ;; V19 of XEmacs, probably.
392    (t
393     (fset 'gnus-characterp 'characterp)))
394
395   (fset 'gnus-make-overlay 'make-extent)
396   (fset 'gnus-overlay-put 'set-extent-property)
397   (fset 'gnus-move-overlay 'gnus-xmas-move-overlay)
398   (fset 'gnus-overlay-end 'extent-end-position)
399   (fset 'gnus-extent-detached-p 'extent-detached-p)
400   (fset 'gnus-add-text-properties 'gnus-xmas-add-text-properties)
401   (fset 'gnus-put-text-property 'gnus-xmas-put-text-property)
402       
403   (require 'text-props)
404   (if (and (<= emacs-major-version 19)
405            (< emacs-minor-version 14))
406       (fset 'gnus-set-text-properties 'gnus-xmas-set-text-properties))
407
408   (when (fboundp 'turn-off-scroll-in-place)
409     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
410
411   (unless (boundp 'standard-display-table)
412     (setq standard-display-table nil))
413
414   (defvar gnus-mouse-face-prop 'highlight)
415
416   (unless (fboundp 'encode-time)
417     (defun encode-time (sec minute hour day month year &optional zone)
418       (let ((seconds
419              (gnus-xmas-seconds-since-epoch
420               (timezone-make-arpa-date 
421                year month day (timezone-make-time-string hour minute sec)
422                zone))))
423         (list (floor (/ seconds (expt 2 16)))
424               (round (mod seconds (expt 2 16)))))))
425       
426   (defun gnus-byte-code (func)
427     "Return a form that can be `eval'ed based on FUNC."
428     (let ((fval (symbol-function func)))
429       (if (compiled-function-p fval)
430           (list 'funcall fval)
431         (cons 'progn (cdr (cdr fval))))))
432
433   (fset 'gnus-x-color-values 
434         (if (fboundp 'x-color-values)
435             'x-color-values
436           (lambda (color)
437             (color-instance-rgb-components
438              (make-color-instance color))))))
439
440 (defun gnus-xmas-region-active-p ()
441   (and (fboundp 'region-active-p)
442        (region-active-p)))
443
444 (defun gnus-xmas-redefine ()
445   "Redefine lots of Gnus functions for XEmacs."
446   (fset 'gnus-summary-make-display-table 'ignore)
447   (fset 'gnus-visual-turn-off-edit-menu 'identity)
448   (fset 'gnus-summary-recenter 'gnus-xmas-summary-recenter)
449   (fset 'gnus-extent-start-open 'gnus-xmas-extent-start-open)
450   (fset 'gnus-article-push-button 'gnus-xmas-article-push-button)
451   (fset 'gnus-article-add-button 'gnus-xmas-article-add-button)
452   (fset 'gnus-window-top-edge 'gnus-xmas-window-top-edge)
453   (fset 'gnus-read-event-char 'gnus-xmas-read-event-char)
454   (fset 'gnus-group-startup-message 'gnus-xmas-group-startup-message)
455   (fset 'gnus-tree-minimize 'gnus-xmas-tree-minimize)
456   (fset 'gnus-appt-select-lowest-window 
457         'gnus-xmas-appt-select-lowest-window)
458   (fset 'gnus-mail-strip-quoted-names 'gnus-xmas-mail-strip-quoted-names)
459   (fset 'gnus-add-hook 'gnus-xmas-add-hook)
460   (fset 'gnus-character-to-event 'character-to-event)
461   (fset 'gnus-mode-line-buffer-identification
462         'gnus-xmas-mode-line-buffer-identification)
463   (fset 'gnus-key-press-event-p 'key-press-event-p)
464   (fset 'gnus-region-active-p 'gnus-xmas-region-active-p)
465   
466   (add-hook 'gnus-group-mode-hook 'gnus-xmas-group-menu-add)
467   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
468   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add)
469   (add-hook 'gnus-score-mode-hook 'gnus-xmas-score-menu-add)
470
471   (add-hook 'gnus-pick-mode-hook 'gnus-xmas-pick-menu-add)
472   (add-hook 'gnus-topic-mode-hook 'gnus-xmas-topic-menu-add)
473   (add-hook 'gnus-tree-mode-hook 'gnus-xmas-tree-menu-add)
474   (add-hook 'gnus-binary-mode-hook 'gnus-xmas-binary-menu-add)
475   (add-hook 'gnus-grouplens-mode-hook 'gnus-xmas-grouplens-menu-add)
476   (add-hook 'gnus-server-mode-hook 'gnus-xmas-server-menu-add)
477   (add-hook 'gnus-browse-mode-hook 'gnus-xmas-browse-menu-add)
478
479   (add-hook 'gnus-group-mode-hook 'gnus-xmas-setup-group-toolbar)
480   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
481
482   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-switch-horizontal-scrollbar-off)
483
484   (when (and (<= emacs-major-version 19)
485              (<= emacs-minor-version 13))
486     (setq gnus-article-x-face-too-ugly (when (eq (device-type) 'tty)
487                                          "."))
488     (fset 'gnus-highlight-selected-summary
489           'gnus-xmas-highlight-selected-summary)
490     (fset 'gnus-group-remove-excess-properties
491           'gnus-xmas-group-remove-excess-properties)
492     (fset 'gnus-topic-remove-excess-properties
493           'gnus-xmas-topic-remove-excess-properties)
494     (fset 'gnus-mode-line-buffer-identification 'identity)
495     (unless (boundp 'shell-command-switch)
496       (setq shell-command-switch "-c"))))
497
498
499 ;;; XEmacs logo and toolbar.
500
501 (defun gnus-xmas-group-startup-message (&optional x y)
502   "Insert startup message in current buffer."
503   ;; Insert the message.
504   (setq gnus-xmas-glyph-directory (message-xmas-find-glyph-directory "gnus"))
505   (erase-buffer)
506   (let ((logo (and gnus-xmas-glyph-directory
507                    (concat 
508                     (file-name-as-directory gnus-xmas-glyph-directory)
509                     "gnus."
510                     (if (featurep 'xpm) "xpm" "xbm"))))
511         (xpm-color-symbols 
512          (and (featurep 'xpm)
513               (append `(("thing" ,(car gnus-xmas-logo-colors))
514                         ("shadow" ,(cadr gnus-xmas-logo-colors)))
515                       xpm-color-symbols))))
516     (if (and (featurep 'xpm)
517              (not (equal (device-type) 'tty))
518              logo
519              (file-exists-p logo))
520         (progn
521           (setq logo (make-glyph logo))
522           (insert " ")
523           (set-extent-begin-glyph (make-extent (point) (point)) logo)
524           (goto-char (point-min))
525           (while (not (eobp))
526             (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
527                                  ? ))
528             (forward-line 1))
529           (goto-char (point-min))
530           (let* ((pheight (+ 20 (count-lines (point-min) (point-max))))
531                  (wheight (window-height))
532                  (rest (- wheight pheight)))
533             (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
534
535       (insert
536        (format "              %s
537           _    ___ _             _      
538           _ ___ __ ___  __    _ ___     
539           __   _     ___    __  ___     
540               _           ___     _     
541              _  _ __             _      
542              ___   __            _      
543                    __           _       
544                     _      _   _        
545                    _      _    _        
546                       _  _    _         
547                   __  ___               
548                  _   _ _     _          
549                 _   _                   
550               _    _                    
551              _    _                     
552             _                         
553           __                             
554
555
556                ""))
557       ;; And then hack it.
558       (gnus-indent-rigidly (point-min) (point-max)
559                            (/ (max (- (window-width) (or x 46)) 0) 2))
560       (goto-char (point-min))
561       (forward-line 1)
562       (let* ((pheight (count-lines (point-min) (point-max)))
563              (wheight (window-height))
564              (rest (- wheight pheight)))
565         (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
566     ;; Fontify some.
567     (goto-char (point-min))
568     (put-text-property (point-min) (point-max) 'face 'gnus-splash-face)
569     (goto-char (point-min))
570     (setq modeline-buffer-identification 
571           (list (concat gnus-version ": *Group*")))
572     (set-buffer-modified-p t)))
573
574
575 ;;; The toolbar.
576
577 (defvar gnus-use-toolbar (if (featurep 'toolbar)
578                              'default-toolbar
579                            nil)
580   "*If nil, do not use a toolbar.
581 If it is non-nil, it must be a toolbar.  The five legal values are
582 `default-toolbar', `top-toolbar', `bottom-toolbar',
583 `right-toolbar', and `left-toolbar'.")
584
585 (defvar gnus-group-toolbar 
586   '([gnus-group-get-new-news gnus-group-get-new-news t "Get new news"]
587     [gnus-group-get-new-news-this-group 
588      gnus-group-get-new-news-this-group t "Get new news in this group"]
589     [gnus-group-catchup-current 
590      gnus-group-catchup-current t "Catchup group"]
591     [gnus-group-describe-group 
592      gnus-group-describe-group t "Describe group"]
593     [gnus-group-unsubscribe gnus-group-unsubscribe t "Unsubscribe group"]
594     [gnus-group-subscribe gnus-group-subscribe t "Subscribe group"]
595     [gnus-group-kill-group gnus-group-kill-group t "Kill group"]
596     [gnus-group-exit gnus-group-exit t "Exit Gnus"]
597     )
598   "The group buffer toolbar.")
599
600 (defvar gnus-summary-toolbar 
601   '([gnus-summary-prev-unread 
602      gnus-summary-prev-unread-article t "Prev unread article"]
603     [gnus-summary-next-unread 
604      gnus-summary-next-unread-article t "Next unread article"]
605     [gnus-summary-post-news 
606      gnus-summary-post-news t "Post an article"]
607     [gnus-summary-followup-with-original
608      gnus-summary-followup-with-original t 
609      "Post a followup and yank the original"]
610     [gnus-summary-followup 
611      gnus-summary-followup t "Post a followup"]
612     [gnus-summary-reply-with-original
613      gnus-summary-reply-with-original t "Mail a reply and yank the original"]
614     [gnus-summary-reply 
615      gnus-summary-reply t "Mail a reply"]
616     [gnus-summary-caesar-message
617      gnus-summary-caesar-message t "Rot 13"]
618     [gnus-uu-decode-uu
619      gnus-uu-decode-uu t "Decode uuencoded articles"]
620     [gnus-summary-save-article-file
621      gnus-summary-save-article-file t "Save article in file"]
622     [gnus-summary-save-article
623      gnus-summary-save-article t "Save article"]
624     [gnus-uu-post-news 
625      gnus-uu-post-news t "Post an uuencoded article"]
626     [gnus-summary-cancel-article
627      gnus-summary-cancel-article t "Cancel article"]
628     [gnus-summary-catchup
629      gnus-summary-catchup t "Catchup"]
630     [gnus-summary-catchup-and-exit
631      gnus-summary-catchup-and-exit t "Catchup and exit"]
632     [gnus-summary-exit gnus-summary-exit t "Exit this summary"]
633     )
634   "The summary buffer toolbar.")
635
636 (defvar gnus-summary-mail-toolbar
637   '(
638     [gnus-summary-prev-unread 
639      gnus-summary-prev-unread-article t "Prev unread article"]
640     [gnus-summary-next-unread 
641      gnus-summary-next-unread-article t "Next unread article"]
642     [gnus-summary-mail-reply gnus-summary-reply t "Reply"]
643 ;    [gnus-summary-mail-get gnus-mail-get t "Message get"]
644     [gnus-summary-mail-originate gnus-summary-post-news t "Originate"]
645     [gnus-summary-mail-save gnus-summary-save-article t "Save"]
646     [gnus-summary-mail-copy gnus-summary-copy-article t "Copy message"]
647 ;    [gnus-summary-mail-delete gnus-summary-delete-article t "Delete message"]
648     [gnus-summary-mail-forward gnus-summary-mail-forward t "Forward message"]
649 ;    [gnus-summary-mail-spell gnus-mail-spell t "Spell"]
650 ;    [gnus-summary-mail-help gnus-mail-help  t "Message help"]
651     [gnus-summary-caesar-message
652      gnus-summary-caesar-message t "Rot 13"]
653     [gnus-uu-decode-uu
654      gnus-uu-decode-uu t "Decode uuencoded articles"]
655     [gnus-summary-save-article-file
656      gnus-summary-save-article-file t "Save article in file"]
657     [gnus-summary-save-article
658      gnus-summary-save-article t "Save article"]
659     [gnus-summary-catchup
660      gnus-summary-catchup t "Catchup"]
661     [gnus-summary-catchup-and-exit
662      gnus-summary-catchup-and-exit t "Catchup and exit"]
663     [gnus-summary-exit gnus-summary-exit t "Exit this summary"]
664     )
665   "The summary buffer mail toolbar.")
666
667 (defun gnus-xmas-setup-group-toolbar ()
668   (and gnus-use-toolbar
669        (message-xmas-setup-toolbar gnus-group-toolbar nil "gnus")
670        (set-specifier (symbol-value gnus-use-toolbar)
671                       (cons (current-buffer) gnus-group-toolbar))))
672
673 (defun gnus-xmas-setup-summary-toolbar ()
674   (let ((bar (if (gnus-news-group-p gnus-newsgroup-name)
675                  gnus-summary-toolbar gnus-summary-mail-toolbar)))
676     (and gnus-use-toolbar
677          (message-xmas-setup-toolbar bar nil "gnus")
678          (set-specifier (symbol-value gnus-use-toolbar)
679                         (cons (current-buffer) bar)))))
680
681 (defun gnus-xmas-mail-strip-quoted-names (address)
682   "Protect mail-strip-quoted-names from NIL input.
683 XEmacs compatibility workaround."
684   (if (null address)
685       nil
686     (mail-strip-quoted-names address)))
687
688 (defun gnus-xmas-call-region (command &rest args)
689   (apply
690    'call-process-region (point-min) (point-max) command t '(t nil) nil
691    args))
692
693 (unless (find-face 'gnus-x-face)
694   (copy-face 'default 'gnus-x-face)
695   (set-face-foreground 'gnus-x-face "black")
696   (set-face-background 'gnus-x-face "white"))
697
698 (defun gnus-xmas-article-display-xface (beg end)
699   "Display any XFace headers in the current article."
700   (save-excursion
701     (let (xface-glyph)
702       (if (featurep 'xface)
703           (setq xface-glyph
704                 (make-glyph (vector 'xface :data 
705                                     (concat "X-Face: "
706                                             (buffer-substring beg end)))))
707         (let ((cur (current-buffer)))
708           (save-excursion
709             (gnus-set-work-buffer)
710             (insert (format "%s" (buffer-substring beg end cur)))
711             (gnus-xmas-call-region "uncompface")
712             (goto-char (point-min))
713             (insert "/* Width=48, Height=48 */\n")
714             (gnus-xmas-call-region "icontopbm")
715             (gnus-xmas-call-region "ppmtoxpm")
716             (setq xface-glyph
717                   (make-glyph
718                    (vector 'xpm :data (buffer-string )))))))
719       (set-glyph-face xface-glyph 'gnus-x-face)
720       (goto-char (point-min))
721       (re-search-forward "^From:" nil t)
722       (set-extent-begin-glyph 
723        (make-extent (point) (1+ (point))) xface-glyph))))
724
725 (defvar gnus-xmas-pointer-glyph 
726   (progn
727     (setq gnus-xmas-glyph-directory (message-xmas-find-glyph-directory "gnus"))
728     (make-pointer-glyph (concat gnus-xmas-glyph-directory "gnus-pointer."
729                                 (if (featurep 'xpm) "xpm" "xbm")))))
730
731 (defvar gnus-xmas-modeline-left-extent 
732   (let ((ext (copy-extent modeline-buffer-id-left-extent)))
733     ;(set-extent-property ext 'pointer gnus-xmas-pointer-glyph)
734     ext))
735       
736 (defvar gnus-xmas-modeline-right-extent 
737   (let ((ext (copy-extent modeline-buffer-id-right-extent)))
738     ;(set-extent-property ext 'pointer gnus-xmas-pointer-glyph)
739     ext))
740
741 (defvar gnus-xmas-modeline-glyph
742   (progn
743     (setq gnus-xmas-glyph-directory (message-xmas-find-glyph-directory "gnus"))
744     (let* ((file (concat gnus-xmas-glyph-directory "gnus-pointer."
745                          (if (featurep 'xpm) "xpm" "xbm")))
746            (glyph (make-glyph file)))
747       (when (and (featurep 'x)
748                  (file-exists-p file))
749         (set-glyph-face glyph 'modeline-buffer-id)
750         (set-glyph-property glyph 'image (cons 'tty "Gnus:"))
751         glyph))))
752
753 (defun gnus-xmas-mode-line-buffer-identification (line)
754   (let ((line (car line))
755         chop)
756     (cond
757      ;; This is some weird type of id.
758      ((not (stringp line))
759       (list line))
760      ;; This is non-standard, so we just pass it through.
761      ((not (string-match "^Gnus:" line))
762       (list line))
763      ;; We have a standard line, so we colorize and glyphize it a bit.
764      (t
765       (setq chop (match-end 0))
766       (list 
767        (if gnus-xmas-modeline-glyph
768            (cons gnus-xmas-modeline-left-extent gnus-xmas-modeline-glyph)
769          (cons gnus-xmas-modeline-left-extent (substring line 0 chop)))
770        (cons gnus-xmas-modeline-right-extent (substring line chop)))))))
771
772 (defun gnus-xmas-splash ()
773   (when (eq (device-type) 'x)
774     (gnus-splash)))
775
776 (provide 'gnus-xmas)
777
778 ;;; gnus-xmas.el ends here