(U+6215): Apply new conventions for glyph granularity.
[chise/xemacs-chise.git.1] / lisp / toolbar-items.el
1 ;;; toolbar-items.el -- Static initialization of XEmacs toolbar
2
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1994 Andy Piper <andyp@parallax.demon.co.uk>
5 ;; Copyright (C) 1995 Board of Trustees, University of Illinois
6 ;; Copyright (C) 1996 Ben Wing <ben@xemacs.org>
7
8 ;; Maintainer: XEmacs development team
9 ;; Keywords: frames, dumped
10
11 ;; This file is part of XEmacs.
12
13 ;; XEmacs is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; XEmacs is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 ;; General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with XEmacs; see the file COPYING.  If not, write to the 
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
27
28 ;;; Synched up:  Not in FSF
29
30 ;;; Commentary:
31
32 ;; This file is dumped with XEmacs (when window system and toolbar support
33 ;; is compiled in).
34
35 ;; Miscellaneous toolbar functions, useful for users to redefine, in
36 ;; order to get different behavior.
37
38 ;;; Code:
39
40 ;; Suppress warning message from bytecompiler
41 (eval-when-compile
42   (defvar pending-delete-mode)
43   ;; #### The compiler still warns about missing
44   ;; `pending-delete-pre-hook'.  Any way to get rid of the warning?
45   )
46
47 (defgroup toolbar nil
48   "Configure XEmacs Toolbar functions and properties"
49   :group 'environment)
50
51 ;; #### The following function is slightly obnoxious as it stands.  I
52 ;; think it should print a message like "Toolbar not configured; press
53 ;; me again to configure it", and when the button is pressed again
54 ;; (within a reasonable period of time), `customize-variable' should
55 ;; be invoked for the appropriate variable.
56
57 (defun toolbar-not-configured ()
58   (interactive)
59   ;; Note: we don't use `susbtitute-command-keys' here, because
60   ;; Customize is bound to `C-h C' by default, and that binding is not
61   ;; familiar to people.  This is more descriptive.
62   (error
63    "Configure the item via `M-x customize RET toolbar RET'"))
64
65 (defcustom toolbar-open-function 'find-file
66   "*Function to call when the open icon is selected."
67   :type '(radio (function-item find-file)
68                 (function :tag "Other"))
69   :group 'toolbar)
70
71 (defun toolbar-open ()
72   (interactive)
73   (call-interactively toolbar-open-function))
74
75 (defcustom toolbar-dired-function 'dired
76   "*Function to call when the dired icon is selected."
77   :type '(radio (function-item dired)
78                 (function :tag "Other"))
79   :group 'toolbar)
80
81 (defun toolbar-dired (dir)
82   (interactive "DDired directory: ")
83   (funcall toolbar-dired-function dir))
84
85 (defcustom toolbar-save-function 'save-buffer
86   "*Function to call when the save icon is selected."
87   :type '(radio (function-item save-buffer)
88                 (function :tag "Other"))
89   :group 'toolbar)
90
91 (defun toolbar-save ()
92   (interactive)
93   (call-interactively toolbar-save-function))
94
95 (defcustom toolbar-print-function 'lpr-buffer
96   "*Function to call when the print icon is selected."
97   :type '(radio (function-item lpr-buffer)
98                 (function :tag "Other"))
99   :group 'toolbar)
100
101 (defun toolbar-print ()
102   (interactive)
103   (call-interactively toolbar-print-function))
104
105 (defcustom toolbar-cut-function 'kill-primary-selection
106   "*Function to call when the cut icon is selected."
107   :type '(radio (function-item kill-primary-selection)
108                 (function :tag "Other"))
109   :group 'toolbar)
110
111 (defun toolbar-cut ()
112   (interactive)
113   (call-interactively toolbar-cut-function))
114
115 (defcustom toolbar-copy-function 'copy-primary-selection
116   "*Function to call when the copy icon is selected."
117   :type '(radio (function-item copy-primary-selection)
118                 (function :tag "Other"))
119   :group 'toolbar)
120
121 (defun toolbar-copy ()
122   (interactive)
123   (call-interactively toolbar-copy-function))
124
125 (defcustom toolbar-paste-function 'yank-clipboard-selection
126   "*Function to call when the paste icon is selected."
127   :type '(radio (function-item yank-clipboard-selection)
128                 (function :tag "Other"))
129   :group 'toolbar)
130
131 (defun toolbar-paste ()
132   (interactive)
133   ;; This horrible kludge is for pending-delete to work correctly.
134   (and (boundp 'pending-delete-mode)
135        pending-delete-mode
136        (let ((this-command toolbar-paste-function))
137          (pending-delete-pre-hook)))
138   (call-interactively toolbar-paste-function))
139
140 (defcustom toolbar-undo-function 'undo
141   "*Function to call when the undo icon is selected."
142   :type '(radio (function-item undo)
143                 (function :tag "Other"))
144   :group 'toolbar)
145
146 (defun toolbar-undo ()
147   (interactive)
148   (call-interactively toolbar-undo-function))
149
150 (defcustom toolbar-replace-function 'query-replace
151   "*Function to call when the replace icon is selected."
152   :type '(radio (function-item query-replace)
153                 (function :tag "Other"))
154   :group 'toolbar)
155
156 (defun toolbar-replace ()
157   (interactive)
158   (call-interactively toolbar-replace-function))
159
160 ;;
161 ;; toolbar ispell variables and defuns
162 ;;
163
164 (defun toolbar-ispell-internal ()
165   (interactive)
166   (cond
167    ((region-active-p) (ispell-region (region-beginning) (region-end)))
168    ((eq major-mode 'mail-mode) (ispell-message))
169    ((eq major-mode 'message-mode) (ispell-message))
170    (t (ispell-buffer))))
171
172 (defcustom toolbar-ispell-function 'toolbar-ispell-internal
173   "*Function to call when the ispell icon is selected."
174   :type '(radio (function-item toolbar-ispell-internal)
175                 (function :tag "Other"))
176   :group 'toolbar)
177
178 (defun toolbar-ispell ()
179   "Intelligently spell the region or buffer."
180   (interactive)
181   (call-interactively toolbar-ispell-function))
182
183 ;;
184 ;; toolbar mail variables and defuns
185 ;;
186
187 ;; This used to be a macro that expanded its arguments to a form that
188 ;; called `call-process'.  With the advent of customize, it's better
189 ;; to have it as a defun, to make customization easier.
190 (defun toolbar-external (process &rest args)
191   (interactive)
192   (apply 'call-process process nil 0 nil args))
193
194 (defcustom toolbar-mail-commands-alist
195   `((not-configured . toolbar-not-configured)
196     (vm         . vm)
197     (gnus       . gnus-no-server)
198     (rmail      . rmail)
199     (mh         . mh-rmail)
200     (pine       . (toolbar-external "xterm" "-e" "pine")) ; *gag*
201     (elm        . (toolbar-external "xterm" "-e" "elm"))
202     (mutt       . (toolbar-external "xterm" "-e" "mutt"))
203     (exmh       . (toolbar-external "exmh"))
204     (netscape   . (toolbar-external "netscape" "mailbox:"))
205     (send       . mail))
206   "*Alist of mail readers and their commands.
207 The car of each alist element is the mail reader, and the cdr is the form
208 used to start it."
209   :type '(repeat (cons :format "%v"
210                        (symbol :tag "Mailer") (function :tag "Start with")))
211   :group 'toolbar)
212
213 (defcustom toolbar-mail-reader 'not-configured
214   "*Mail reader toolbar will invoke.
215 The legal values are the keys from `toolbar-mail-command-alist', which
216  should be used to add new mail readers.
217 Mail readers known by default are vm, gnus, rmail, mh, pine, elm,
218  mutt, exmh, netscape and send."
219   :type '(choice (const :tag "Not Configured" not-configured)
220                  (const vm) (const gnus) (const rmail) (const mh)
221                  (const pine) (const elm) (const mutt) (const exmh)
222                  (const netscape)
223                  (const send)
224                  (symbol :tag "Other"
225                          :validate (lambda (wid)
226                                      (if (assq (widget-value wid)
227                                                toolbar-mail-commands-alist)
228                                          nil
229                                        (widget-put wid :error
230                                                    "Unknown mail reader")
231                                        wid))))
232   :group 'toolbar)
233
234
235 (defun toolbar-mail ()
236   "Run mail in a separate frame."
237   (interactive)
238   (let ((command (cdr (assq toolbar-mail-reader toolbar-mail-commands-alist))))
239     (or command
240         (error "Uknown mail reader %s" toolbar-mail-reader))
241     (if (symbolp command)
242         (call-interactively command)
243       (eval command))))
244
245 ;;
246 ;; toolbar info variables and defuns
247 ;;
248
249 (defcustom toolbar-info-use-separate-frame t
250   "*Whether Info is invoked in a separate frame."
251   :type 'boolean
252   :group 'toolbar)
253
254 (defcustom toolbar-info-frame-plist
255   ;; Info pages are 80 characters wide, so it makes a good default.
256   `(width 80 ,@(let ((h (plist-get default-frame-plist 'height)))
257                  (and h `(height ,h))))
258   "*The properties of the frame in which news is displayed."
259   :type 'plist
260   :group 'info)
261
262 (define-obsolete-variable-alias 'Info-frame-plist
263   'toolbar-info-frame-plist)
264
265 (defvar toolbar-info-frame nil
266   "The frame in which info is displayed.")
267
268 (defun toolbar-info ()
269   "Run info in a separate frame."
270   (interactive)
271   (when toolbar-info-use-separate-frame
272     (cond ((or (not toolbar-info-frame)
273                (not (frame-live-p toolbar-info-frame)))
274            ;; We used to raise frame here, but it's a bad idea,
275            ;; because raising is a matter of WM policy.  However, we
276            ;; *must* select it, to ensure that the info buffer goes to
277            ;; the right frame.
278            (setq toolbar-info-frame (make-frame toolbar-info-frame-plist))
279            (select-frame toolbar-info-frame))
280           (t
281            ;; However, if the frame already exists, and the user
282            ;; clicks on info, it's OK to raise it.
283            (select-frame toolbar-info-frame)
284            (raise-frame toolbar-info-frame)))
285     (when (frame-iconified-p toolbar-info-frame)
286       (deiconify-frame toolbar-info-frame)))
287   (info))
288
289 ;;
290 ;; toolbar debug variables and defuns
291 ;;
292
293 (defun toolbar-debug ()
294   (interactive)
295   (if (featurep 'eos-debugger)
296       (call-interactively 'eos::start-debugger)
297     (require 'gdbsrc)
298     (call-interactively 'gdbsrc)))
299
300 (defun toolbar-compile ()
301   "Run compile without having to touch the keyboard."
302   (interactive)
303   (declare (special compile-command toolbar-compile-already-run))
304   (require 'compile)
305   (if (boundp 'toolbar-compile-already-run)
306       (compile compile-command)
307     (setq toolbar-compile-already-run t)
308     (if (should-use-dialog-box-p)
309        (make-dialog-box 'question
310                         :question (concat "Compile:\n        " compile-command)
311                         :buttons
312                         '(["Compile" (compile compile-command) t]
313                           ["Edit command" compile t]
314                           nil
315                           ["Cancel" (message "Quit") t]))
316       (compile compile-command))))
317
318 ;;
319 ;; toolbar news variables and defuns
320 ;;
321
322 (defcustom toolbar-news-commands-alist
323   `((not-configured . toolbar-not-configured)
324     (gnus       . toolbar-gnus)                 ; M-x all-hail-gnus
325     (rn         . (toolbar-external "xterm" "-e" "rn"))
326     (nn         . (toolbar-external "xterm" "-e" "nn"))
327     (trn        . (toolbar-external "xterm" "-e" "trn"))
328     (xrn        . (toolbar-external "xrn"))
329     (slrn       . (toolbar-external "xterm" "-e" "slrn"))
330     (pine       . (toolbar-external "xterm" "-e" "pine")) ; *gag*
331     (tin        . (toolbar-external "xterm" "-e" "tin")) ; *gag*
332     (netscape   . (toolbar-external "netscape" "news:")))
333   "*Alist of news readers and their commands.
334 The car of each alist element the pair is the news reader, and the cdr
335 is the form used to start it."
336   :type '(repeat (cons :format "%v"
337                        (symbol :tag "Reader") (sexp :tag "Start with")))
338   :group 'toolbar)
339
340 (defcustom toolbar-news-reader 'gnus
341   "*News reader toolbar will invoke.
342 The legal values are the keys from `toolbar-news-command-alist', which should
343  be used to add new news readers.
344 Newsreaders known by default are gnus, rn, nn, trn, xrn, slrn, pine
345  and netscape."
346   :type '(choice (const :tag "Not Configured" not-configured)
347                  (const gnus) (const rn) (const nn) (const trn)
348                  (const xrn) (const slrn) (const pine) (const tin)
349                  (const netscape)
350                  (symbol :tag "Other"
351                          :validate (lambda (wid)
352                                      (if (assq (widget-value wid)
353                                                toolbar-news-commands-alist)
354                                          nil
355                                        (widget-put wid :error
356                                                    "Unknown news reader")
357                                        wid))))
358   :group 'toolbar)
359
360 (defcustom toolbar-news-use-separate-frame t
361   "*Whether Gnus is invoked in a separate frame."
362   :type 'boolean
363   :group 'toolbar)
364
365 (defvar toolbar-news-frame nil
366   "The frame in which news is displayed.")
367
368 (defcustom toolbar-news-frame-plist nil
369   "*The properties of the frame in which news is displayed."
370   :type 'plist
371   :group 'toolbar)
372
373 (define-obsolete-variable-alias 'toolbar-news-frame-properties
374   'toolbar-news-frame-plist)
375
376 (defun toolbar-gnus ()
377   "Run Gnus in a separate frame."
378   (interactive)
379   (if (not toolbar-news-use-separate-frame)
380       (gnus)
381     (unless (frame-live-p toolbar-news-frame)
382       (setq toolbar-news-frame (make-frame toolbar-news-frame-plist))
383       (add-hook 'gnus-exit-gnus-hook
384                 (lambda ()
385                   (when (frame-live-p toolbar-news-frame)
386                     (if (cdr (frame-list))
387                         (delete-frame toolbar-news-frame))
388                     (setq toolbar-news-frame nil))))
389       (select-frame toolbar-news-frame)
390       (gnus))
391     (when (framep toolbar-news-frame)
392       (when (frame-iconified-p toolbar-news-frame)
393         (deiconify-frame toolbar-news-frame))
394       (select-frame toolbar-news-frame)
395       (raise-frame toolbar-news-frame))))
396
397 (defun toolbar-news ()
398   "Run News."
399   (interactive)
400   (let ((command (cdr-safe
401                   (assq toolbar-news-reader toolbar-news-commands-alist))))
402     (or command
403         (error "Unknown news reader %s" toolbar-news-reader))
404     (if (symbolp command)
405         (call-interactively command)
406       (eval command))))
407
408 (defvar toolbar-last-win-icon nil "A `last-win' icon set.")
409 (defvar toolbar-next-win-icon nil "A `next-win' icon set.")
410 (defvar toolbar-file-icon     nil "A `file' icon set.")
411 (defvar toolbar-folder-icon   nil "A `folder' icon set")
412 (defvar toolbar-disk-icon     nil "A `disk' icon set.")
413 (defvar toolbar-printer-icon  nil "A `printer' icon set.")
414 (defvar toolbar-cut-icon      nil "A `cut' icon set.")
415 (defvar toolbar-copy-icon     nil "A `copy' icon set.")
416 (defvar toolbar-paste-icon    nil "A `paste' icon set.")
417 (defvar toolbar-undo-icon     nil "An `undo' icon set.")
418 (defvar toolbar-spell-icon    nil "A `spell' icon set.")
419 (defvar toolbar-replace-icon  nil "A `replace' icon set.")
420 (defvar toolbar-mail-icon     nil "A `mail' icon set.")
421 (defvar toolbar-info-icon     nil "An `info' icon set.")
422 (defvar toolbar-compile-icon  nil "A `compile' icon set.")
423 (defvar toolbar-debug-icon    nil "A `debugger' icon set.")
424 (defvar toolbar-news-icon     nil "A `news' icon set.")
425
426 ;;; each entry maps a variable to the prefix used.
427
428 (defvar init-x-toolbar-list
429   '((toolbar-last-win-icon . "last-win")
430     (toolbar-next-win-icon . "next-win")
431     (toolbar-file-icon     . "file")
432     (toolbar-folder-icon   . "folder")
433     (toolbar-disk-icon     . "disk")
434     (toolbar-printer-icon  . "printer")
435     (toolbar-cut-icon      . "cut")
436     (toolbar-copy-icon     . "copy")
437     (toolbar-paste-icon    . "paste")
438     (toolbar-undo-icon     . "undo")
439     (toolbar-spell-icon    . "spell")
440     (toolbar-replace-icon  . "replace")
441     (toolbar-mail-icon     . "mail")
442     (toolbar-info-icon     . "info-def")
443     (toolbar-compile-icon  . "compile")
444     (toolbar-debug-icon    . "debug")
445     (toolbar-news-icon     . "news")))
446
447 (defun init-x-toolbar ()
448   (toolbar-add-item-data init-x-toolbar-list )
449   ;; do this now because errors will occur if the icon symbols
450   ;; are not initted
451   (set-specifier default-toolbar initial-toolbar-spec))
452   
453 (defun toolbar-add-item-data ( icon-list &optional icon-dir )
454   (if (eq icon-dir nil)
455       (setq icon-dir toolbar-icon-directory))
456   (mapcar
457    (lambda (cons)
458      (let ((prefix (expand-file-name (cdr cons)  icon-dir)))
459        ;; #### This should use a better mechanism for finding the
460        ;; glyphs, allowing for formats other than x[pb]m.  Look at
461        ;; `widget-glyph-find' for an example how it might be done.
462        (set (car cons)
463             (if (featurep 'xpm)
464                 (toolbar-make-button-list
465                  (concat prefix "-up.xpm")
466                  nil
467                  (concat prefix "-xx.xpm")
468                  (concat prefix "-cap-up.xpm")
469                  nil
470                  (concat prefix "-cap-xx.xpm"))
471               (toolbar-make-button-list
472                (concat prefix "-up.xbm")
473                (concat prefix "-dn.xbm")
474                (concat prefix "-xx.xbm"))))))
475    icon-list))
476
477 (defvar toolbar-vector-open 
478   [toolbar-file-icon            toolbar-open    t       "Open a file"]
479   "Define the vector for the \"Open\" toolbar button")
480
481 (defvar toolbar-vector-dired
482   [toolbar-folder-icon          toolbar-dired   t       "Edit a directory"]
483   "Define the vector for the \"Dired\" toolbar button")
484
485 (defvar toolbar-vector-save
486   [toolbar-disk-icon            toolbar-save    t       "Save buffer"]
487   "Define the vector for the \"Save\" toolbar button")
488
489 (defvar toolbar-vector-print
490   [toolbar-printer-icon         toolbar-print   t       "Print buffer"]
491   "Define the vector for the \"Printer\" toolbar button")
492
493 (defvar toolbar-vector-cut
494   [toolbar-cut-icon             toolbar-cut     t       "Kill region"]
495   "Define the vector for the \"Cut\" toolbar button")
496
497 (defvar toolbar-vector-copy
498   [toolbar-copy-icon            toolbar-copy    t       "Copy region"]
499   "Define the vector for the \"Copy\" toolbar button")
500
501 (defvar toolbar-vector-paste
502   [toolbar-paste-icon           toolbar-paste   t       "Paste from clipboard"]
503   "Define the vector for the \"Paste\" toolbar button")
504
505 (defvar toolbar-vector-undo
506   [toolbar-undo-icon            toolbar-undo    t       "Undo edit"]
507   "Define the vector for the \"Undo\" toolbar button")
508
509 (defvar toolbar-vector-spell
510   [toolbar-spell-icon           toolbar-ispell  t       "Check spelling"]
511   "Define the vector for the \"Spell\" toolbar button")
512
513 (defvar toolbar-vector-replace
514   [toolbar-replace-icon         toolbar-replace t       "Search & Replace"]  
515   "Define the vector for the \"Replace\" toolbar button")
516
517 (defvar toolbar-vector-mail
518   [toolbar-mail-icon            toolbar-mail    t       "Read mail"]
519   "Define the vector for the \"Mail\" toolbar button")
520
521 (defvar toolbar-vector-info
522   [toolbar-info-icon            toolbar-info    t       "Info documentation"]
523   "Define the vector for the \"Info\" toolbar button")
524
525 (defvar toolbar-vector-compile
526   [toolbar-compile-icon         toolbar-compile t       "Start a compilation"]
527   "Define the vector for the \"Compile\" toolbar button")
528
529 (defvar toolbar-vector-debug
530   [toolbar-debug-icon           toolbar-debug   t       "Start a debugger"]
531   "Define the vector for the \"Debug\" toolbar button")
532
533 (defvar toolbar-vector-news
534   [toolbar-news-icon            toolbar-news    t       "Read news"]
535   "Define the vector for the \"News\" toolbar button")
536
537 (defvar initial-toolbar-spec
538   (list
539     ;;[toolbar-last-win-icon    pop-window-configuration
540     ;;(frame-property (selected-frame)
541     ;;          'window-config-stack) t "Most recent window config"]
542     ;; #### Illicit knowledge?
543     ;; #### These don't work right - not consistent!
544     ;; I don't know what's wrong; perhaps `selected-frame' is wrong
545     ;; sometimes when this is evaluated.  Note that I even tried to
546     ;; kludge-fix this by calls to `set-specifier-dirty-flag' in
547     ;; pop-window-configuration and such.
548
549     ;;[toolbar-next-win-icon    unpop-window-configuration
550     ;;(frame-property (selected-frame)
551     ;;  'window-config-unpop-stack) t "Undo \"Most recent window config\""]
552     ;; #### Illicit knowledge?
553     toolbar-vector-open
554     toolbar-vector-dired
555     toolbar-vector-save
556     toolbar-vector-print
557     toolbar-vector-cut
558     toolbar-vector-copy
559     toolbar-vector-paste
560     toolbar-vector-undo
561     toolbar-vector-spell
562     toolbar-vector-replace
563     toolbar-vector-mail
564     toolbar-vector-info
565     toolbar-vector-compile
566     toolbar-vector-debug
567     toolbar-vector-news
568     )
569   "The initial toolbar for a buffer.")
570
571 (defun x-init-toolbar-from-resources (locale)
572   (x-init-specifier-from-resources
573    top-toolbar-height 'natnum locale
574    '("topToolBarHeight" . "TopToolBarHeight"))
575   (x-init-specifier-from-resources
576    bottom-toolbar-height 'natnum locale
577    '("bottomToolBarHeight" . "BottomToolBarHeight"))
578   (x-init-specifier-from-resources
579    left-toolbar-width 'natnum locale
580    '("leftToolBarWidth" . "LeftToolBarWidth"))
581   (x-init-specifier-from-resources
582    right-toolbar-width 'natnum locale
583    '("rightToolBarWidth" . "RightToolBarWidth"))
584   (x-init-specifier-from-resources
585    top-toolbar-border-width 'natnum locale
586    '("topToolBarBorderWidth" . "TopToolBarBorderWidth"))
587   (x-init-specifier-from-resources
588    bottom-toolbar-border-width 'natnum locale
589    '("bottomToolBarBorderWidth" . "BottomToolBarBorderWidth"))
590   (x-init-specifier-from-resources
591    left-toolbar-border-width 'natnum locale
592    '("leftToolBarBorderWidth" . "LeftToolBarBorderWidth"))
593   (x-init-specifier-from-resources
594    right-toolbar-border-width 'natnum locale
595    '("rightToolBarBorderWidth" . "RightToolBarBorderWidth")))
596
597 ;;; toolbar-items.el ends here