To define items in any other map, use `tool-bar-local-item'."
(apply 'tool-bar-local-item icon def key tool-bar-map props))
+(defun tool-bar--image-expression (icon)
+ "Return an expression that evaluates to an image spec for ICON."
+ (let* ((fg (face-attribute 'tool-bar :foreground))
+ (bg (face-attribute 'tool-bar :background))
+ (colors (nconc (if (eq fg 'unspecified) nil (list :foreground fg))
+ (if (eq bg 'unspecified) nil (list :background bg))))
+ (xpm-spec (list :type 'xpm :file (concat icon ".xpm")))
+ (xpm-lo-spec (list :type 'xpm :file
+ (concat "low-color/" icon ".xpm")))
+ (pbm-spec (append (list :type 'pbm :file
+ (concat icon ".pbm")) colors))
+ (xbm-spec (append (list :type 'xbm :file
+ (concat icon ".xbm")) colors)))
+ `(find-image (cond ((not (display-color-p))
+ ',(list pbm-spec xbm-spec xpm-lo-spec xpm-spec))
+ ((< (display-color-cells) 256)
+ ',(list xpm-lo-spec xpm-spec pbm-spec xbm-spec))
+ (t
+ ',(list xpm-spec pbm-spec xbm-spec))))))
+
;;;###autoload
(defun tool-bar-local-item (icon def key map &rest props)
"Add an item to the tool bar in map MAP.
function will first try to use low-color/ICON.xpm if `display-color-cells'
is less or equal to 256, then ICON.xpm, then ICON.pbm, and finally
ICON.xbm, using `find-image'."
- (let* ((fg (face-attribute 'tool-bar :foreground))
- (bg (face-attribute 'tool-bar :background))
- (colors (nconc (if (eq fg 'unspecified) nil (list :foreground fg))
- (if (eq bg 'unspecified) nil (list :background bg))))
- (xpm-spec (list :type 'xpm :file (concat icon ".xpm")))
- (xpm-lo-spec (list :type 'xpm :file
- (concat "low-color/" icon ".xpm")))
- (pbm-spec (append (list :type 'pbm :file
- (concat icon ".pbm")) colors))
- (xbm-spec (append (list :type 'xbm :file
- (concat icon ".xbm")) colors))
- (image-exp `(find-image
- (cond ((not (display-color-p))
- ',(list pbm-spec xbm-spec xpm-lo-spec xpm-spec))
- ((< (display-color-cells) 256)
- ',(list xpm-lo-spec xpm-spec pbm-spec xbm-spec))
- (t
- ',(list xpm-spec pbm-spec xbm-spec))))))
+ (let* ((image-exp (tool-bar--image-expression icon)))
(define-key-after map (vector key)
`(menu-item ,(symbol-name key) ,def :image ,image-exp ,@props))))
(setq from-map global-map))
(let* ((menu-bar-map (lookup-key from-map [menu-bar]))
(keys (where-is-internal command menu-bar-map))
- (fg (face-attribute 'tool-bar :foreground))
- (bg (face-attribute 'tool-bar :background))
- (colors (nconc (if (eq fg 'unspecified) nil (list :foreground fg))
- (if (eq bg 'unspecified) nil (list :background bg))))
- (xpm-spec (list :type 'xpm :file (concat icon ".xpm")))
- (xpm-lo-spec (list :type 'xpm :file
- (concat "low-color/" icon ".xpm")))
- (pbm-spec (append (list :type 'pbm :file
- (concat icon ".pbm")) colors))
- (xbm-spec (append (list :type 'xbm :file
- (concat icon ".xbm")) colors))
- (image-exp `(find-image
- (cond ((not (display-color-p))
- ',(list pbm-spec xbm-spec xpm-lo-spec xpm-spec))
- ((< (display-color-cells) 256)
- ',(list xpm-lo-spec xpm-spec pbm-spec xbm-spec))
- (t
- ',(list xpm-spec pbm-spec xbm-spec)))))
+ (image-exp (tool-bar--image-expression icon))
submap key)
;; We'll pick up the last valid entry in the list of keys if
;; there's more than one.
;;; Set up some global items. Additions/deletions up for grabs.
(defun tool-bar-setup ()
+ (setq tool-bar-separator-image-expression
+ (tool-bar--image-expression "separator"))
(tool-bar-add-item-from-menu 'find-file "new" nil :label "New File"
:vert-only t)
(tool-bar-add-item-from-menu 'menu-find-file-existing "open" nil
:label "Open" :vert-only t)
(tool-bar-add-item-from-menu 'dired "diropen" nil :vert-only t)
(tool-bar-add-item-from-menu 'kill-this-buffer "close" nil :vert-only t)
- (tool-bar-add-item-from-menu 'save-buffer "save" nil :vert-only t
+ (tool-bar-add-item-from-menu 'save-buffer "save" nil
:label "Save"
- :visible '(or buffer-file-name
+ :enable '(or buffer-file-name
(not (eq 'special
(get major-mode
'mode-class)))))
(define-key-after (default-value 'tool-bar-map) [separator-1] menu-bar-separator)
(tool-bar-add-item-from-menu 'undo "undo" nil :vert-only t
- :visible '(not (eq 'special (get major-mode
+ :enable '(not (eq 'special (get major-mode
'mode-class))))
(define-key-after (default-value 'tool-bar-map) [separator-2] menu-bar-separator)
(tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [cut])
"cut" nil :vert-only t
- :visible '(not (eq 'special (get major-mode
+ :enable '(not (eq 'special (get major-mode
'mode-class))))
(tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [copy])
"copy" nil :vert-only t)
(tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [paste])
"paste" nil :vert-only t
- :visible '(not (eq 'special (get major-mode
+ :enable '(not (eq 'special (get major-mode
'mode-class))))
(define-key-after (default-value 'tool-bar-map) [separator-3] menu-bar-separator)
(tool-bar-add-item-from-menu 'nonincremental-search-forward "search"
/* List of items that should move to the end of the menu bar. */
Lisp_Object Vmenu_bar_final_items;
+/* Expression to evaluate for the tool bar separator image.
+ This is used for build_desired_tool_bar_string only. For GTK, we
+ use GTK tool bar seperators. */
+
+Lisp_Object Vtool_bar_separator_image_expression;
+
/* Non-nil means show the equivalent key-binding for
any M-x command that has one.
The value can be a length of time to show the message for.
if (menu_separator_name_p (SDATA (caption)))
{
PROP (TOOL_BAR_ITEM_TYPE) = Qt;
+#if !defined (USE_GTK) && !defined (HAVE_NS)
+ /* If we use build_desired_tool_bar_string to render the
+ tool bar, the separator is rendered as an image. */
+ PROP (TOOL_BAR_ITEM_IMAGES)
+ = menu_item_eval_property (Vtool_bar_separator_image_expression);
+ PROP (TOOL_BAR_ITEM_ENABLED_P) = Qnil;
+ PROP (TOOL_BAR_ITEM_SELECTED_P) = Qnil;
+ PROP (TOOL_BAR_ITEM_CAPTION) = Qnil;
+#endif
return 1;
}
return 0;
The elements of the list are event types that may have menu bar bindings. */);
Vmenu_bar_final_items = Qnil;
+ DEFVAR_LISP ("tool-bar-separator-image-expression", &Vtool_bar_separator_image_expression,
+ doc: /* Expression evaluating to the image spec for a tool-bar separator.
+This is used internally by graphical displays that do not render
+tool-bar separators natively. Otherwise it is unused (e.g. on GTK). */);
+ Vtool_bar_separator_image_expression = Qnil;
+
DEFVAR_KBOARD ("overriding-terminal-local-map",
Voverriding_terminal_local_map,
doc: /* Per-terminal keymap that overrides all other local keymaps.
int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P));
int hmargin, vmargin, relief, idx, end;
- /* Ignore separator items. */
- if (EQ (PROP (TOOL_BAR_ITEM_TYPE), Qt))
- continue;
-
/* If image is a vector, choose the image according to the
button state. */
image = PROP (TOOL_BAR_ITEM_IMAGES);
row->used[TEXT_AREA] = n_glyphs_before;
*it = it_before;
/* If this is the only glyph on this line, it will never fit on the
- toolbar, so skip it. But ensure there is at least one glyph,
+ tool-bar, so skip it. But ensure there is at least one glyph,
so we don't accidentally disable the tool-bar. */
if (n_glyphs_before == 0
&& (it->vpos > 0 || IT_STRING_CHARPOS (*it) < it->end_charpos-1))
tool_bar_button_relief = DEFAULT_TOOL_BAR_BUTTON_RELIEF;
DEFVAR_LISP ("tool-bar-style", &Vtool_bar_style,
- doc: /* *Tool bar style to use.
+ doc: /* Tool bar style to use.
It can be one of
image - show images only
text - show text only