From d2bd51898e48c2fd47a98a42654842a65feea7ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Dj=C3=A4rv?= Date: Sat, 20 Nov 2010 15:51:25 +0100 Subject: [PATCH] Add keyword :vert-only for tool bar items with labels not shown horizontally. * lisp/info.el (info-tool-bar-map): Add some :vert-only keywords. * lisp/tool-bar.el (tool-bar-setup): Add some :vert-only keywords. * src/dispextern.h (tool_bar_item_idx): Add TOOL_BAR_ITEM_VERT_ONLY. * src/gtkutil.c (xg_make_tool_item): Take vert_only as argument. Set important to ! vert_only. (xg_show_toolbar_item): Don't show label horizontally if tool item isn't important. (update_frame_tool_bar): Get TOOL_BAR_ITEM_VERT_ONLY and pass it to xg_make_tool_item, or update important on existing tool item. * src/keyboard.c (QCvert_only): New variable. (parse_tool_bar_item): Check for QCvert_only. (syms_of_keyboard): Initialize QCvert_only. --- lisp/ChangeLog | 6 ++++++ lisp/info.el | 9 ++++++--- lisp/tool-bar.el | 22 ++++++++++++---------- src/ChangeLog | 15 +++++++++++++++ src/dispextern.h | 3 +++ src/gtkutil.c | 18 +++++++++++++----- src/keyboard.c | 11 ++++++++--- 7 files changed, 63 insertions(+), 21 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 345f31fc8ff..0594cca0b8d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2010-11-20 Jan Djärv + + * tool-bar.el (tool-bar-setup): Add some :vert-only keywords. + + * info.el (info-tool-bar-map): Add some :vert-only keywords. + 2010-11-20 Eli Zaretskii * international/characters.el (glyphless-char-display-control): diff --git a/lisp/info.el b/lisp/info.el index 3e3ecc131cf..7c0333f6b8e 100644 --- a/lisp/info.el +++ b/lisp/info.el @@ -3763,15 +3763,18 @@ If FORK is non-nil, it is passed to `Info-goto-node'." (let ((map (make-sparse-keymap))) (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map :rtl "right-arrow" - :label "Back") + :label "Back" + :vert-only t) (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map :rtl "left-arrow" - :label "Forward") + :label "Forward" + :vert-only t) (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map :rtl "next-node") (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map :rtl "prev-node") - (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map) + (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map + :vert-only t) (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map) (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map) (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map diff --git a/lisp/tool-bar.el b/lisp/tool-bar.el index 6630d85cd3e..4b6fd970d8a 100644 --- a/lisp/tool-bar.el +++ b/lisp/tool-bar.el @@ -260,31 +260,33 @@ holds a keymap." ;; People say it's bad to have EXIT on the tool bar, since users ;; might inadvertently click that button. ;;(tool-bar-add-item-from-menu 'save-buffers-kill-emacs "exit") - (tool-bar-add-item-from-menu 'find-file "new" nil :label "New File") - (tool-bar-add-item-from-menu 'menu-find-file-existing "open") - (tool-bar-add-item-from-menu 'dired "diropen") - (tool-bar-add-item-from-menu 'kill-this-buffer "close") - (tool-bar-add-item-from-menu 'save-buffer "save" nil + (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 + :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 :visible '(or buffer-file-name (not (eq 'special (get major-mode 'mode-class))))) - (tool-bar-add-item-from-menu 'write-file "saveas" nil + (tool-bar-add-item-from-menu 'write-file "saveas" nil :vert-only t :visible '(or buffer-file-name (not (eq 'special (get major-mode 'mode-class))))) - (tool-bar-add-item-from-menu 'undo "undo" nil + (tool-bar-add-item-from-menu 'undo "undo" nil :vert-only t :visible '(not (eq 'special (get major-mode 'mode-class)))) (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [cut]) - "cut" nil + "cut" nil :vert-only t :visible '(not (eq 'special (get major-mode 'mode-class)))) (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [copy]) - "copy") + "copy" nil :vert-only t) (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [paste]) - "paste" nil + "paste" nil :vert-only t :visible '(not (eq 'special (get major-mode 'mode-class)))) (tool-bar-add-item-from-menu 'nonincremental-search-forward "search" diff --git a/src/ChangeLog b/src/ChangeLog index b7c1ef2c93c..552d8efe6f1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2010-11-20 Jan Djärv + + * gtkutil.c (xg_make_tool_item): Take vert_only as argument. + Set important to ! vert_only. + (xg_show_toolbar_item): Don't show label horizontally if + tool item isn't important. + (update_frame_tool_bar): Get TOOL_BAR_ITEM_VERT_ONLY and pass it to + xg_make_tool_item, or update important on existing tool item. + + * keyboard.c (QCvert_only): New variable. + (parse_tool_bar_item): Check for QCvert_only. + (syms_of_keyboard): Initialize QCvert_only. + + * dispextern.h (tool_bar_item_idx): Add TOOL_BAR_ITEM_VERT_ONLY. + 2010-11-20 Eli Zaretskii * msdos.c (dos_rawgetc): Use gen_help_event, instead of doing the diff --git a/src/dispextern.h b/src/dispextern.h index 0030aa8f184..7426c03b5ec 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -2887,6 +2887,9 @@ enum tool_bar_item_idx /* Label to show when text labels are enabled. */ TOOL_BAR_ITEM_LABEL, + /* If we shall show the label only below the icon and not beside it. */ + TOOL_BAR_ITEM_VERT_ONLY, + /* Sentinel = number of slots in tool_bar_items occupied by one tool-bar item. */ TOOL_BAR_ITEM_NSLOTS diff --git a/src/gtkutil.c b/src/gtkutil.c index 7103d2b1991..89b16a10fbc 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -4059,7 +4059,8 @@ xg_make_tool_item (FRAME_PTR f, GtkWidget *wimage, GtkWidget **wbutton, const char *label, - int i) + int i, + int vert_only) { GtkToolItem *ti = gtk_tool_item_new (); Lisp_Object style = Ftool_bar_get_system_style (); @@ -4071,6 +4072,10 @@ xg_make_tool_item (FRAME_PTR f, GtkWidget *wb = gtk_button_new (); GtkWidget *weventbox = gtk_event_box_new (); + /* We are not letting Gtk+ alter display on this, we only keep it here + so we can get it later in xg_show_toolbar_item. */ + gtk_tool_item_set_is_important (ti, !vert_only); + if (wimage && ! text_image) gtk_box_pack_start (GTK_BOX (vb), wimage, TRUE, TRUE, 0); @@ -4144,7 +4149,8 @@ xg_show_toolbar_item (GtkToolItem *ti) int text_image = EQ (style, Qtext_image_horiz); int horiz = both_horiz || text_image; - int show_label = ! EQ (style, Qimage); + int vert_only = ! gtk_tool_item_get_is_important (ti); + int show_label = ! EQ (style, Qimage) && ! (vert_only && horiz); int show_image = ! EQ (style, Qtext); GtkWidget *weventbox = gtk_bin_get_child (GTK_BIN (ti)); @@ -4301,7 +4307,8 @@ update_frame_tool_bar (FRAME_PTR f) Lisp_Object specified_file; const char *label = (STRINGP (PROP (TOOL_BAR_ITEM_LABEL)) ? SSDATA (PROP (TOOL_BAR_ITEM_LABEL)) : ""); - + int vert_only = ! NILP (PROP (TOOL_BAR_ITEM_VERT_ONLY)); + ti = gtk_toolbar_get_nth_item (GTK_TOOLBAR (wtoolbar), i); if (ti) @@ -4391,7 +4398,7 @@ update_frame_tool_bar (FRAME_PTR f) else { /* Insert an empty (non-image) button */ - ti = xg_make_tool_item (f, NULL, NULL, "", i); + ti = xg_make_tool_item (f, NULL, NULL, "", i, 0); gtk_toolbar_insert (GTK_TOOLBAR (wtoolbar), ti, -1); } continue; @@ -4425,7 +4432,7 @@ update_frame_tool_bar (FRAME_PTR f) } gtk_misc_set_padding (GTK_MISC (w), hmargin, vmargin); - ti = xg_make_tool_item (f, w, &wbutton, label, i); + ti = xg_make_tool_item (f, w, &wbutton, label, i, vert_only); gtk_toolbar_insert (GTK_TOOLBAR (wtoolbar), ti, -1); gtk_widget_set_sensitive (wbutton, enabled_p); } @@ -4442,6 +4449,7 @@ update_frame_tool_bar (FRAME_PTR f) gpointer old_icon_name = g_object_get_data (G_OBJECT (wimage), XG_TOOL_BAR_ICON_NAME); gtk_label_set_text (GTK_LABEL (wlbl), label); + gtk_tool_item_set_is_important (ti, !vert_only); if (stock_name && (! old_stock_name || strcmp (old_stock_name, stock_name) != 0)) { diff --git a/src/keyboard.c b/src/keyboard.c index ec5c24511c4..e96d0167fd4 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -489,10 +489,10 @@ Lisp_Object Qconfig_changed_event; Lisp_Object Qevent_kind; Lisp_Object Qevent_symbol_elements; -/* menu item parts */ +/* menu and tool bar item parts */ Lisp_Object Qmenu_enable; Lisp_Object QCenable, QCvisible, QChelp, QCfilter, QCkeys, QCkey_sequence; -Lisp_Object QCbutton, QCtoggle, QCradio, QClabel; +Lisp_Object QCbutton, QCtoggle, QCradio, QClabel, QCvert_only; /* An event header symbol HEAD may have a property named Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS); @@ -8269,9 +8269,12 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item) if (NILP (menu_item_eval_property (value))) return 0; } - else if (EQ (key, QChelp)) + else if (EQ (key, QChelp)) /* `:help HELP-STRING'. */ PROP (TOOL_BAR_ITEM_HELP) = value; + else if (EQ (key, QCvert_only)) + /* `:vert-only t/nil'. */ + PROP (TOOL_BAR_ITEM_VERT_ONLY) = value; else if (EQ (key, QClabel)) { const char *bad_label = "!!?GARBLED ITEM?!!"; @@ -11629,6 +11632,8 @@ syms_of_keyboard (void) staticpro (&QCradio); QClabel = intern_c_string (":label"); staticpro (&QClabel); + QCvert_only = intern_c_string (":vert-only"); + staticpro (&QCvert_only); Qmode_line = intern_c_string ("mode-line"); staticpro (&Qmode_line); -- 2.39.2