]> code.delx.au - gnu-emacs/blobdiff - lisp/tool-bar.el
(end-of-defun): Don't skip to next line after
[gnu-emacs] / lisp / tool-bar.el
index 59a73e2aa4e0d1dca6b21b5271d4574ec7004ce2..226b1ddba5cda731d49052873aeab3f1d2fe4e0f 100644 (file)
@@ -1,7 +1,7 @@
 ;;; tool-bar.el --- setting up the tool bar
 ;;
 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 ;;
 ;; Author: Dave Love <fx@gnu.org>
 ;; Keywords: mouse frames
@@ -54,9 +54,12 @@ conveniently adding tool bar items."
   :group 'frames
   (if tool-bar-mode
       (progn
-       (dolist (frame (frame-list))
-         (if (display-graphic-p frame)
-             (set-frame-parameter frame 'tool-bar-lines 1)))
+       ;; Make one tool-bar-line for any - including non-graphical -
+       ;; terminal, see Bug#1754.  If this causes problems, we should
+       ;; handle the problem in `modify-frame-parameters' or do not
+       ;; call `modify-all-frames-parameters' when toggling the tool
+       ;; bar off either.
+       (modify-all-frames-parameters (list (cons 'tool-bar-lines 1)))
        (if (= 1 (length (default-value 'tool-bar-map))) ; not yet setup
            (tool-bar-setup)))
     (modify-all-frames-parameters (list (cons 'tool-bar-lines 0)))))
@@ -92,10 +95,18 @@ Define this locally to override the global tool bar.")
 
 (declare-function image-mask-p "image.c" (spec &optional frame))
 
+(defconst tool-bar-keymap-cache (make-hash-table :weakness t :test 'equal))
+
 (defun tool-bar-make-keymap (&optional ignore)
   "Generate an actual keymap from `tool-bar-map'.
 Its main job is to figure out which images to use based on the display's
 color capability and based on the available image libraries."
+  (let ((key (cons (frame-terminal) tool-bar-map)))
+    (or (gethash key tool-bar-keymap-cache)
+       (puthash key (tool-bar-make-keymap-1) tool-bar-keymap-cache))))
+
+(defun tool-bar-make-keymap-1 ()
+  "Generate an actual keymap from `tool-bar-map', without caching."
   (mapcar (lambda (bind)
             (let (image-exp plist)
               (when (and (eq (car-safe (cdr-safe bind)) 'menu-item)
@@ -119,13 +130,6 @@ color capability and based on the available image libraries."
              bind))
          tool-bar-map))
 
-(defconst tool-bar-find-image-cache (make-hash-table :weakness t :test 'equal))
-
-(defun tool-bar-find-image (specs)
-  "Like `find-image' but with caching."
-  (or (gethash specs tool-bar-find-image-cache)
-      (puthash specs (find-image specs) tool-bar-find-image-cache)))
-
 ;;;###autoload
 (defun tool-bar-add-item (icon def key &rest props)
   "Add an item to the tool bar.
@@ -166,7 +170,7 @@ ICON.xbm, using `find-image'."
                                  (concat icon ".pbm")) colors))
         (xbm-spec (append (list :type 'xbm :file
                                  (concat icon ".xbm")) colors))
-        (image-exp `(tool-bar-find-image
+        (image-exp `(find-image
                      (cond ((not (display-color-p))
                             ',(list pbm-spec xbm-spec xpm-lo-spec xpm-spec))
                            ((< (display-color-cells) 256)
@@ -218,7 +222,7 @@ holds a keymap."
                                  (concat icon ".pbm")) colors))
         (xbm-spec (append (list :type 'xbm :file
                                  (concat icon ".xbm")) colors))
-        (image-exp `(tool-bar-find-image
+        (image-exp `(find-image
                      (cond ((not (display-color-p))
                             ',(list pbm-spec xbm-spec xpm-lo-spec xpm-spec))
                            ((< (display-color-cells) 256)