diff options
author | Mathias Hasselmann <hasselmm@src.gnome.org> | 2007-12-14 10:57:46 +0000 |
---|---|---|
committer | Mathias Hasselmann <hasselmm@src.gnome.org> | 2007-12-14 10:57:46 +0000 |
commit | 95adf7ee26a5c113ef63805842578254789c06e9 (patch) | |
tree | fbec6dfbe1662b816a7164009766332b4446f963 /gtk | |
parent | ea8074a4077ac7bf90f3873160da35bd491e8079 (diff) | |
download | gtk+-95adf7ee26a5c113ef63805842578254789c06e9.tar.gz |
Change GtkToolItem to retrieve its properties from GtkToolShell interface,
instead of relying on being child of a GtkToolbar. (#5034079)
* gtk/gtk.symbols, docs/reference/gtk/gtk-docs.sgml,
docs/reference/gtk/gtk-sections.txt: Add GtkToolShell symbols.
* docs/reference/gtk/tmpl/gtktoolitem.sgml: Move section docs inline.
* gtk/gtktoolbar.c: Implement GtkToolShellIface.
* gtk/gtktoolbar.h: Remove _gtk_toolbar_rebuild_menu.
* gtk/gtktoolitem.c: Use GtkToolShell, instead of GtkToolbar.
Take section docs from template file and update them for GtkToolShell.
* gtk/Makefile.am: Add gtk/gtktoolshell.c and gtk/gtktoolshell.h.
* gtk/gtktoolshell.c, gtk/gtktoolshell.h: New GtkToolShellIface.
svn path=/trunk/; revision=19177
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/Makefile.am | 2 | ||||
-rw-r--r-- | gtk/gtk.symbols | 10 | ||||
-rw-r--r-- | gtk/gtktoolbar.c | 59 | ||||
-rw-r--r-- | gtk/gtktoolbar.h | 1 | ||||
-rw-r--r-- | gtk/gtktoolitem.c | 53 | ||||
-rw-r--r-- | gtk/gtktoolshell.c | 159 | ||||
-rw-r--r-- | gtk/gtktoolshell.h | 71 |
7 files changed, 331 insertions, 24 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 359d1c9cda..5a19467b55 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -299,6 +299,7 @@ gtk_public_h_sources = \ gtktoolbar.h \ gtktoolbutton.h \ gtktoolitem.h \ + gtktoolshell.h \ gtktooltip.h \ gtktooltips.h \ gtktree.h \ @@ -587,6 +588,7 @@ gtk_base_c_sources = \ gtktoolbar.c \ gtktoolbutton.c \ gtktoolitem.c \ + gtktoolshell.c \ gtktooltip.c \ gtktooltips.c \ gtktree.c \ diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 917c6e8ea9..c3aace362b 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -4049,6 +4049,16 @@ gtk_toolbar_unset_style #endif #endif +#if IN_HEADER(__GTK_TOOL_SHELL_H__) +#if IN_FILE(__GTK_TOOL_SHELL_C__) +gtk_tool_shell_get_icon_size +gtk_tool_shell_get_orientation +gtk_tool_shell_get_style +gtk_tool_shell_get_relief_style +gtk_tool_shell_rebuild_menu +#endif +#endif + #if IN_HEADER(__GTK_TOOL_BUTTON_H__) #if IN_FILE(__GTK_TOOL_BUTTON_C__) gtk_tool_button_get_icon_name diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c index 8b5141129b..8b1caddb77 100644 --- a/gtk/gtktoolbar.c +++ b/gtk/gtktoolbar.c @@ -34,6 +34,7 @@ #include <config.h> #include "gtkarrow.h" #include "gtktoolbar.h" +#include "gtktoolshell.h" #include "gtkradiotoolbutton.h" #include "gtkseparatortoolitem.h" #include "gtkmenu.h" @@ -299,12 +300,20 @@ static void toolbar_content_hide_all (ToolbarContent static void toolbar_content_set_expand (ToolbarContent *content, gboolean expand); +static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface); +static GtkIconSize toolbar_get_icon_size (GtkToolShell *shell); +static GtkOrientation toolbar_get_orientation (GtkToolShell *shell); +static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell); +static GtkReliefStyle toolbar_get_relief_style (GtkToolShell *shell); +static void toolbar_rebuild_menu (GtkToolShell *shell); + #define GTK_TOOLBAR_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate)) static guint toolbar_signals [LAST_SIGNAL] = { 0 }; -G_DEFINE_TYPE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER) +G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER, + G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL, toolbar_tool_shell_iface_init)) static void add_arrow_bindings (GtkBindingSet *binding_set, @@ -337,6 +346,16 @@ add_ctrl_tab_bindings (GtkBindingSet *binding_set, } static void +toolbar_tool_shell_iface_init (GtkToolShellIface *iface) +{ + iface->get_icon_size = toolbar_get_icon_size; + iface->get_orientation = toolbar_get_orientation; + iface->get_style = toolbar_get_style; + iface->get_relief_style = toolbar_get_relief_style; + iface->rebuild_menu = toolbar_rebuild_menu; +} + +static void gtk_toolbar_class_init (GtkToolbarClass *klass) { GObjectClass *gobject_class; @@ -846,7 +865,7 @@ gtk_toolbar_unrealize (GtkWidget *widget) } if (GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize) - (* GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize) (widget); + GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget); } static gint @@ -2527,14 +2546,14 @@ gtk_toolbar_forall (GtkContainer *container, GtkWidget *child = toolbar_content_get_widget (content); if (child) - (*callback) (child, callback_data); + callback (child, callback_data); } list = next; } if (include_internals) - (* callback) (priv->arrow_button, callback_data); + callback (priv->arrow_button, callback_data); } static GType @@ -4932,10 +4951,34 @@ _gtk_toolbar_elide_underscores (const gchar *original) return result; } -void -_gtk_toolbar_rebuild_menu (GtkToolbar *toolbar) +static GtkIconSize +toolbar_get_icon_size (GtkToolShell *shell) { - GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); + return GTK_TOOLBAR (shell)->icon_size; +} + +static GtkOrientation +toolbar_get_orientation (GtkToolShell *shell) +{ + return GTK_TOOLBAR (shell)->orientation; +} + +static GtkToolbarStyle +toolbar_get_style (GtkToolShell *shell) +{ + return GTK_TOOLBAR (shell)->style; +} + +static GtkReliefStyle +toolbar_get_relief_style (GtkToolShell *shell) +{ + return get_button_relief (GTK_TOOLBAR (shell)); +} + +static void +toolbar_rebuild_menu (GtkToolShell *shell) +{ + GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (shell); GList *list; priv->need_rebuild = TRUE; @@ -4947,7 +4990,7 @@ _gtk_toolbar_rebuild_menu (GtkToolbar *toolbar) toolbar_content_set_unknown_menu_status (content); } - gtk_widget_queue_resize (GTK_WIDGET (toolbar)); + gtk_widget_queue_resize (GTK_WIDGET (shell)); } #define __GTK_TOOLBAR_C__ diff --git a/gtk/gtktoolbar.h b/gtk/gtktoolbar.h index dbe72a8167..0a4652c746 100644 --- a/gtk/gtktoolbar.h +++ b/gtk/gtktoolbar.h @@ -175,7 +175,6 @@ void _gtk_toolbar_paint_space_line (GtkWidget *widget, GdkRectangle *area, GtkAllocation *allocation); gint _gtk_toolbar_get_default_space_size (void); -void _gtk_toolbar_rebuild_menu (GtkToolbar *toolbar); void gtk_toolbar_set_icon_size (GtkToolbar *toolbar, diff --git a/gtk/gtktoolitem.c b/gtk/gtktoolitem.c index 1916af938c..0fcf93e7e1 100644 --- a/gtk/gtktoolitem.c +++ b/gtk/gtktoolitem.c @@ -23,7 +23,7 @@ #include <config.h> #include "gtktoolitem.h" #include "gtkmarshalers.h" -#include "gtktoolbar.h" +#include "gtktoolshell.h" #include "gtkseparatormenuitem.h" #include "gtkintl.h" #include "gtkmain.h" @@ -32,6 +32,29 @@ #include <string.h> +/** + * SECTION:gtktoolitem + * @short_description: The base class of widgets that can be added to #GtkToolShell + * + * #GtkToolItem<!-- -->s are widgets that can appear on a toolbar. To + * create a toolbar item that contain something else than a button, use + * gtk_tool_item_new(). Use gtk_container_add() to add a child + * widget to the tool item. + * + * For toolbar items that contain buttons, see the #GtkToolButton, + * #GtkToggleToolButton and #GtkRadioToolButton classes. + * + * See the #GtkToolbar class for a description of the toolbar widget, and + * #GtkToolShell for a description of the tool shell interface. + */ + +/** + * GtkToolItem: + * + * The GtkToolItem struct contains only private data. + * It should only be accessed through the functions described below. + */ + enum { CREATE_MENU_PROXY, TOOLBAR_RECONFIGURED, @@ -192,10 +215,10 @@ gtk_tool_item_class_init (GtkToolItemClass *klass) * item is a child of changes. For custom subclasses of #GtkToolItem, * the default handler of this signal use the functions * <itemizedlist> - * <listitem>gtk_toolbar_get_orientation()</listitem> - * <listitem>gtk_toolbar_get_style()</listitem> - * <listitem>gtk_toolbar_get_icon_size()</listitem> - * <listitem>gtk_toolbar_get_relief_style()</listitem> + * <listitem>gtk_tool_shell_get_orientation()</listitem> + * <listitem>gtk_tool_shell_get_style()</listitem> + * <listitem>gtk_tool_shell_get_icon_size()</listitem> + * <listitem>gtk_tool_shell_get_relief_style()</listitem> * </itemizedlist> * to find out what the toolbar should look like and change * themselves accordingly. @@ -518,10 +541,10 @@ gtk_tool_item_get_icon_size (GtkToolItem *tool_item) g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR); parent = GTK_WIDGET (tool_item)->parent; - if (!parent || !GTK_IS_TOOLBAR (parent)) + if (!parent || !GTK_IS_TOOL_SHELL (parent)) return GTK_ICON_SIZE_LARGE_TOOLBAR; - return gtk_toolbar_get_icon_size (GTK_TOOLBAR (parent)); + return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent)); } /** @@ -545,10 +568,10 @@ gtk_tool_item_get_orientation (GtkToolItem *tool_item) g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL); parent = GTK_WIDGET (tool_item)->parent; - if (!parent || !GTK_IS_TOOLBAR (parent)) + if (!parent || !GTK_IS_TOOL_SHELL (parent)) return GTK_ORIENTATION_HORIZONTAL; - return gtk_toolbar_get_orientation (GTK_TOOLBAR (parent)); + return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent)); } /** @@ -588,10 +611,10 @@ gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item) g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS); parent = GTK_WIDGET (tool_item)->parent; - if (!parent || !GTK_IS_TOOLBAR (parent)) + if (!parent || !GTK_IS_TOOL_SHELL (parent)) return GTK_TOOLBAR_ICONS; - return gtk_toolbar_get_style (GTK_TOOLBAR (parent)); + return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent)); } /** @@ -616,10 +639,10 @@ gtk_tool_item_get_relief_style (GtkToolItem *tool_item) g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE); parent = GTK_WIDGET (tool_item)->parent; - if (!parent || !GTK_IS_TOOLBAR (parent)) + if (!parent || !GTK_IS_TOOL_SHELL (parent)) return GTK_RELIEF_NONE; - return gtk_toolbar_get_relief_style (GTK_TOOLBAR (parent)); + return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent)); } /** @@ -1095,8 +1118,8 @@ gtk_tool_item_rebuild_menu (GtkToolItem *tool_item) widget = GTK_WIDGET (tool_item); - if (widget->parent && GTK_IS_TOOLBAR (widget->parent)) - _gtk_toolbar_rebuild_menu (GTK_TOOLBAR (widget->parent)); + if (widget->parent && GTK_IS_TOOL_SHELL (widget->parent)) + gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (widget->parent)); } /** diff --git a/gtk/gtktoolshell.c b/gtk/gtktoolshell.c new file mode 100644 index 0000000000..2eab8bb219 --- /dev/null +++ b/gtk/gtktoolshell.c @@ -0,0 +1,159 @@ +/* gtktoolshell.c + * Copyright (C) 2007 Openismus GmbH + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: + * Mathias Hasselmann + */ + +#include <config.h> +#include "gtktoolshell.h" +#include "gtkwidget.h" +#include "gtkintl.h" +#include "gtkalias.h" + +/** + * SECTION:gtktoolshell + * @short_description: Interface for containers containing #GtkToolItem widgets. + * + * The #GtkToolShell interface allows container widgets to provide additional + * information when embedding #GtkToolItem widgets. + * + * @see_also: #GtkToolbar, #GtkToolItem + */ + +/** + * GtkToolShell: + * + * Dummy structure for accessing instances of #GtkToolShellIface. + */ + +GType +gtk_tool_shell_get_type (void) +{ + static GType type = 0; + + if (!type) + { + type = g_type_register_static_simple (G_TYPE_INTERFACE, I_("GtkToolShell"), + sizeof (GtkToolShellIface), + NULL, 0, NULL, 0); + g_type_interface_add_prerequisite (type, GTK_TYPE_WIDGET); + } + + return type; +} + +/** + * gtk_tool_shell_get_icon_size: + * @shell: a #GtkToolShell + * + * Retrieves the icon size for the tool shell. Tool items must not call this + * function directly, but rely on gtk_tool_item_get_icon_size() instead. + * + * Return value: the current size for icons of @shell + * + * Since: 2.16 + **/ +GtkIconSize +gtk_tool_shell_get_icon_size (GtkToolShell *shell) +{ + return GTK_TOOL_SHELL_GET_IFACE (shell)->get_icon_size (shell); +} + +/** + * gtk_tool_shell_get_orientation: + * @shell: a #GtkToolShell + * + * Retrieves the current orientation for the tool shell. Tool items must not + * call this function directly, but rely on gtk_tool_item_get_orientation() + * instead. + * + * Return value: the current orientation of @shell + * + * Since: 2.16 + **/ +GtkOrientation +gtk_tool_shell_get_orientation (GtkToolShell *shell) +{ + return GTK_TOOL_SHELL_GET_IFACE (shell)->get_orientation (shell); +} + +/** + * gtk_tool_shell_get_style: + * @shell: a #GtkToolShell + * + * Retrieves whether the tool shell has text, icons, or both. Tool items must + * not call this function directly, but rely on gtk_tool_item_get_style() + * instead. + * + * Return value: the current style of @shell + * + * Since: 2.16 + **/ +GtkToolbarStyle +gtk_tool_shell_get_style (GtkToolShell *shell) +{ + return GTK_TOOL_SHELL_GET_IFACE (shell)->get_style (shell); +} + +/** + * gtk_tool_shell_get_relief_style: + * @shell: a #GtkToolShell + * + * Returns the relief style of buttons on @shell. Tool items must not call this + * function directly, but rely on gtk_tool_item_get_relief_style() instead. + * + * Return value: The relief style of buttons on @shell. + * + * Since: 2.16 + **/ +GtkReliefStyle +gtk_tool_shell_get_relief_style (GtkToolShell *shell) +{ + GtkToolShellIface *iface = GTK_TOOL_SHELL_GET_IFACE (shell); + + if (iface->get_relief_style) + iface->get_relief_style (shell); + + return GTK_RELIEF_NONE; +} + +/** + * gtk_tool_shell_rebuild_menu: + * @shell: a #GtkToolShell + * + * Calling this function signals the tool shell that the overflow menu item for + * tool items have changed. If there is an overflow menu and if it is visible + * when this function it called, the menu will be rebuilt. + * + * Tool items must not call this function directly, but rely on + * gtk_tool_item_rebuild_menu() instead. + * + * Since: 2.16 + **/ +void +gtk_tool_shell_rebuild_menu (GtkToolShell *shell) +{ + GtkToolShellIface *iface = GTK_TOOL_SHELL_GET_IFACE (shell); + + if (iface->rebuild_menu) + iface->rebuild_menu (shell); +} + +#define __GTK_TOOL_SHELL_C__ +#include "gtkaliasdef.c" diff --git a/gtk/gtktoolshell.h b/gtk/gtktoolshell.h new file mode 100644 index 0000000000..684ad897a3 --- /dev/null +++ b/gtk/gtktoolshell.h @@ -0,0 +1,71 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2007 Openismus GmbH + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: + * Mathias Hasselmann + */ + +#ifndef __GTK_TOOL_SHELL_H__ +#define __GTK_TOOL_SHELL_H__ + +#include <gtk/gtkenums.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_TOOL_SHELL (gtk_tool_shell_get_type ()) +#define GTK_TOOL_SHELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TOOL_SHELL, GtkToolShell)) +#define GTK_IS_TOOL_SHELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TOOL_SHELL)) +#define GTK_TOOL_SHELL_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_TOOL_SHELL, GtkToolShellIface)) + +typedef struct _GtkToolShell GtkToolShell; /* dummy typedef */ +typedef struct _GtkToolShellIface GtkToolShellIface; + +/** + * GtkToolShellIface: + * @get_icon_size: mandatory implementation of gtk_tool_shell_get_icon_size(). + * @get_orientation: mandatory implementation of gtk_tool_shell_get_orientation(). + * @get_style: mandatory implementation of gtk_tool_shell_get_style(). + * @get_relief_style: optional implementation of gtk_tool_shell_get_relief_style(). + * @rebuild_menu: optional implementation of gtk_tool_shell_rebuild_menu(). + * + * Virtual function table for the #GtkToolShell interface. + */ +struct _GtkToolShellIface +{ + /*< private >*/ + GTypeInterface g_iface; + + /*< public >*/ + GtkIconSize (*get_icon_size) (GtkToolShell *shell); + GtkOrientation (*get_orientation) (GtkToolShell *shell); + GtkToolbarStyle (*get_style) (GtkToolShell *shell); + GtkReliefStyle (*get_relief_style) (GtkToolShell *shell); + void (*rebuild_menu) (GtkToolShell *shell); +}; + +GType gtk_tool_shell_get_type (void) G_GNUC_CONST; + +GtkIconSize gtk_tool_shell_get_icon_size (GtkToolShell *shell); +GtkOrientation gtk_tool_shell_get_orientation (GtkToolShell *shell); +GtkToolbarStyle gtk_tool_shell_get_style (GtkToolShell *shell); +GtkReliefStyle gtk_tool_shell_get_relief_style (GtkToolShell *shell); +void gtk_tool_shell_rebuild_menu (GtkToolShell *shell); + +G_END_DECLS + +#endif /* __GTK_TOOL_SHELL_H__ */ |