* Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
* Copyright (C) 2002 James Henstridge <james@daa.com.au>
* Copyright (C) 2003, 2004 Soeren Sandmann <sandmann@daimi.au.dk>
- *
+ *
* 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
* 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.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#undef GTK_DISABLE_DEPRECATED
-#include <config.h>
-#include "gtkarrow.h"
-#include "gtktoolbar.h"
-#include "gtkradiotoolbutton.h"
-#include "gtkseparatortoolitem.h"
-#include "gtkmenu.h"
-#include "gtkradiobutton.h"
+#include "config.h"
+
+#include <math.h>
+#include <string.h>
+
#include "gtktoolbar.h"
+
+#include "gtkarrow.h"
#include "gtkbindings.h"
-#include <gdk/gdkkeysyms.h>
-#include "gtkmarshalers.h"
+#include "gtkcontainerprivate.h"
+#include "gtkimage.h"
+#include "gtklabel.h"
#include "gtkmain.h"
+#include "gtkmarshalers.h"
+#include "gtkmenu.h"
+#include "gtkorientable.h"
+#include "gtkorientableprivate.h"
+#include "gtkradiobutton.h"
+#include "gtkradiotoolbutton.h"
+#include "gtkseparatormenuitem.h"
+#include "gtkseparatortoolitem.h"
#include "gtkstock.h"
-#include "gtklabel.h"
+#include "gtktoolshell.h"
+#include "gtkbox.h"
#include "gtkprivate.h"
#include "gtkintl.h"
-#include <string.h>
-#include "gtkhbox.h"
-#include "gtkvbox.h"
-#include "gtkimage.h"
-#include "gtkseparatormenuitem.h"
-#include "gtkalias.h"
-#include <math.h>
+#include "gtktypebuiltins.h"
+#include "gtkwidgetpath.h"
+#include "gtkwidgetprivate.h"
-typedef struct _ToolbarContent ToolbarContent;
-#define DEFAULT_IPADDING 0
+/**
+ * SECTION:gtktoolbar
+ * @Short_description: Create bars of buttons and other widgets
+ * @Title: GtkToolbar
+ * @See_also: #GtkToolItem
+ *
+ * A toolbar is created with a call to gtk_toolbar_new().
+ *
+ * A toolbar can contain instances of a subclass of #GtkToolItem. To add
+ * a #GtkToolItem to the a toolbar, use gtk_toolbar_insert(). To remove
+ * an item from the toolbar use gtk_container_remove(). To add a button
+ * to the toolbar, add an instance of #GtkToolButton.
+ *
+ * Toolbar items can be visually grouped by adding instances of
+ * #GtkSeparatorToolItem to the toolbar. If the GtkToolbar child property
+ * "expand" is #TRUE and the property #GtkSeparatorToolItem:draw is set to
+ * #FALSE, the effect is to force all following items to the end of the toolbar.
+ *
+ * Creating a context menu for the toolbar can be done by connecting to
+ * the #GtkToolbar::popup-context-menu signal.
+ */
+
+
+typedef struct _ToolbarContent ToolbarContent;
#define DEFAULT_SPACE_SIZE 12
#define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
#define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
#define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
+#define DEFAULT_ANIMATION_STATE TRUE
#define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
* in the homogeneous game. In units of
#define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
#define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
-#define MIXED_API_WARNING \
- "Mixing deprecated and non-deprecated GtkToolbar API is not allowed"
+struct _GtkToolbarPrivate
+{
+ GtkMenu *menu;
+ GtkSettings *settings;
+
+ GtkIconSize icon_size;
+ GtkToolbarStyle style;
+
+ GtkToolItem *highlight_tool_item;
+ GtkWidget *arrow;
+ GtkWidget *arrow_button;
+
+ GdkWindow *event_window;
+
+ GList *content;
+
+ GTimer *timer;
+
+ gulong settings_connection;
+
+ gint idle_id;
+ gint button_maxw; /* maximum width of homogeneous children */
+ gint button_maxh; /* maximum height of homogeneous children */
+ gint max_homogeneous_pixels;
+ gint num_children;
+
+ GtkOrientation orientation;
+
+ guint animation : 1;
+ guint icon_size_set : 1;
+ guint is_sliding : 1;
+ guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
+ guint need_sync : 1;
+ guint show_arrow : 1;
+ guint style_set : 1;
+};
/* Properties */
enum {
ORIENTATION_CHANGED,
STYLE_CHANGED,
POPUP_CONTEXT_MENU,
- MOVE_FOCUS,
FOCUS_HOME_OR_END,
LAST_SIGNAL
};
-/* API mode */
-typedef enum {
- DONT_KNOW,
- OLD_API,
- NEW_API
-} ApiMode;
-
-typedef enum {
- TOOL_ITEM,
- COMPATIBILITY
-} ContentType;
-
typedef enum {
NOT_ALLOCATED,
NORMAL,
OVERFLOWN
} ItemState;
-struct _GtkToolbarPrivate
-{
- GList * content;
-
- GtkWidget * arrow;
- GtkWidget * arrow_button;
- GtkMenu * menu;
-
- GdkWindow * event_window;
- ApiMode api_mode;
- GtkSettings * settings;
- int idle_id;
- GtkToolItem * highlight_tool_item;
- gint max_homogeneous_pixels;
-
- GTimer * timer;
-
- guint show_arrow : 1;
- guint need_sync : 1;
- guint is_sliding : 1;
- guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
-};
-static void gtk_toolbar_init (GtkToolbar *toolbar);
-static void gtk_toolbar_class_init (GtkToolbarClass *klass);
static void gtk_toolbar_set_property (GObject *object,
guint prop_id,
const GValue *value,
guint prop_id,
GValue *value,
GParamSpec *pspec);
-static gint gtk_toolbar_expose (GtkWidget *widget,
- GdkEventExpose *event);
+static gint gtk_toolbar_draw (GtkWidget *widget,
+ cairo_t *cr);
static void gtk_toolbar_realize (GtkWidget *widget);
static void gtk_toolbar_unrealize (GtkWidget *widget);
-static void gtk_toolbar_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
+static void gtk_toolbar_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
+static void gtk_toolbar_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
+
static void gtk_toolbar_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static void gtk_toolbar_style_set (GtkWidget *widget,
- GtkStyle *prev_style);
+static void gtk_toolbar_style_updated (GtkWidget *widget);
static gboolean gtk_toolbar_focus (GtkWidget *widget,
GtkDirectionType dir);
+static void gtk_toolbar_move_focus (GtkWidget *widget,
+ GtkDirectionType dir);
static void gtk_toolbar_screen_changed (GtkWidget *widget,
GdkScreen *previous_screen);
static void gtk_toolbar_map (GtkWidget *widget);
GValue *value,
GParamSpec *pspec);
static void gtk_toolbar_finalize (GObject *object);
+static void gtk_toolbar_dispose (GObject *object);
static void gtk_toolbar_show_all (GtkWidget *widget);
-static void gtk_toolbar_hide_all (GtkWidget *widget);
static void gtk_toolbar_add (GtkContainer *container,
GtkWidget *widget);
static void gtk_toolbar_remove (GtkContainer *container,
GtkCallback callback,
gpointer callback_data);
static GType gtk_toolbar_child_type (GtkContainer *container);
+static GtkWidgetPath * gtk_toolbar_get_path_for_child
+ (GtkContainer *container,
+ GtkWidget *child);
+static void gtk_toolbar_invalidate_order (GtkToolbar *toolbar);
+
+static void gtk_toolbar_direction_changed (GtkWidget *widget,
+ GtkTextDirection previous_direction);
static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
GtkOrientation orientation);
static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
GtkToolbarStyle style);
-static gboolean gtk_toolbar_move_focus (GtkToolbar *toolbar,
- GtkDirectionType dir);
static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
gboolean focus_home);
static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
GtkToolbar *toolbar);
static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
-static GtkWidget *internal_insert_element (GtkToolbar *toolbar,
- GtkToolbarChildType type,
- GtkWidget *widget,
- const char *text,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GtkWidget *icon,
- GtkSignalFunc callback,
- gpointer user_data,
- gint position,
- gboolean use_stock);
static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
-static gboolean gtk_toolbar_check_new_api (GtkToolbar *toolbar);
-static gboolean gtk_toolbar_check_old_api (GtkToolbar *toolbar);
static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
-static gint get_internal_padding (GtkToolbar *toolbar);
-static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
-static gint get_space_size (GtkToolbar *toolbar);
-static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar);
+static gint get_max_child_expand (GtkToolbar *toolbar);
/* methods on ToolbarContent 'class' */
static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
GtkToolItem *item,
gboolean is_placeholder,
gint pos);
-static ToolbarContent *toolbar_content_new_compatibility (GtkToolbar *toolbar,
- GtkToolbarChildType type,
- GtkWidget *widget,
- GtkWidget *icon,
- GtkWidget *label,
- gint pos);
static void toolbar_content_remove (ToolbarContent *content,
GtkToolbar *toolbar);
static void toolbar_content_free (ToolbarContent *content);
-static void toolbar_content_expose (ToolbarContent *content,
+static void toolbar_content_draw (ToolbarContent *content,
GtkContainer *container,
- GdkEventExpose *expose);
+ cairo_t *cr);
static gboolean toolbar_content_visible (ToolbarContent *content,
GtkToolbar *toolbar);
static void toolbar_content_size_request (ToolbarContent *content,
static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
static gboolean toolbar_content_is_separator (ToolbarContent *content);
static void toolbar_content_show_all (ToolbarContent *content);
-static void toolbar_content_hide_all (ToolbarContent *content);
static void toolbar_content_set_expand (ToolbarContent *content,
gboolean expand);
-#define GTK_TOOLBAR_GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
+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);
-static GtkContainerClass * parent_class = NULL;
-static guint toolbar_signals [LAST_SIGNAL] = { 0 };
-GType
-gtk_toolbar_get_type (void)
-{
- static GtkType type = 0;
-
- if (!type)
- {
- static const GTypeInfo type_info =
- {
- sizeof (GtkToolbarClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gtk_toolbar_class_init,
- (GClassFinalizeFunc) NULL,
- NULL,
- sizeof (GtkToolbar),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_toolbar_init,
- };
-
- type = g_type_register_static (GTK_TYPE_CONTAINER,
- I_("GtkToolbar"),
- &type_info, 0);
- }
-
- return type;
-}
+G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL,
+ toolbar_tool_shell_iface_init)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
+ NULL))
+
+static guint toolbar_signals[LAST_SIGNAL] = { 0 };
+
static void
add_arrow_bindings (GtkBindingSet *binding_set,
guint keysym,
GtkDirectionType dir)
{
- guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
+ guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
gtk_binding_entry_add_signal (binding_set, keysym, 0,
- "move_focus", 1,
+ "move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, dir);
gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
- "move_focus", 1,
+ "move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, dir);
}
GtkDirectionType direction)
{
gtk_binding_entry_add_signal (binding_set,
- GDK_Tab, GDK_CONTROL_MASK | modifiers,
- "move_focus", 1,
+ GDK_KEY_Tab, GDK_CONTROL_MASK | modifiers,
+ "move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set,
- GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
- "move_focus", 1,
+ GDK_KEY_KP_Tab, GDK_CONTROL_MASK | modifiers,
+ "move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
}
GtkContainerClass *container_class;
GtkBindingSet *binding_set;
- parent_class = g_type_class_peek_parent (klass);
-
gobject_class = (GObjectClass *)klass;
widget_class = (GtkWidgetClass *)klass;
container_class = (GtkContainerClass *)klass;
gobject_class->set_property = gtk_toolbar_set_property;
gobject_class->get_property = gtk_toolbar_get_property;
gobject_class->finalize = gtk_toolbar_finalize;
+ gobject_class->dispose = gtk_toolbar_dispose;
widget_class->button_press_event = gtk_toolbar_button_press;
- widget_class->expose_event = gtk_toolbar_expose;
- widget_class->size_request = gtk_toolbar_size_request;
+ widget_class->draw = gtk_toolbar_draw;
+ widget_class->get_preferred_width = gtk_toolbar_get_preferred_width;
+ widget_class->get_preferred_height = gtk_toolbar_get_preferred_height;
widget_class->size_allocate = gtk_toolbar_size_allocate;
- widget_class->style_set = gtk_toolbar_style_set;
+ widget_class->style_updated = gtk_toolbar_style_updated;
widget_class->focus = gtk_toolbar_focus;
+
+ gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_TOOL_BAR);
+
+ /* need to override the base class function via override_class_handler,
+ * because the signal slot is not available in GtkWidgetClass
+ */
+ g_signal_override_class_handler ("move-focus",
+ GTK_TYPE_TOOLBAR,
+ G_CALLBACK (gtk_toolbar_move_focus));
+
widget_class->screen_changed = gtk_toolbar_screen_changed;
widget_class->realize = gtk_toolbar_realize;
widget_class->unrealize = gtk_toolbar_unrealize;
widget_class->unmap = gtk_toolbar_unmap;
widget_class->popup_menu = gtk_toolbar_popup_menu;
widget_class->show_all = gtk_toolbar_show_all;
- widget_class->hide_all = gtk_toolbar_hide_all;
+ widget_class->direction_changed = gtk_toolbar_direction_changed;
container_class->add = gtk_toolbar_add;
container_class->remove = gtk_toolbar_remove;
container_class->child_type = gtk_toolbar_child_type;
container_class->get_child_property = gtk_toolbar_get_child_property;
container_class->set_child_property = gtk_toolbar_set_child_property;
-
+ container_class->get_path_for_child = gtk_toolbar_get_path_for_child;
+
klass->orientation_changed = gtk_toolbar_orientation_changed;
klass->style_changed = gtk_toolbar_real_style_changed;
* Return value: return %TRUE if the signal was handled, %FALSE if not
*/
toolbar_signals[POPUP_CONTEXT_MENU] =
- g_signal_new (I_("popup_context_menu"),
+ g_signal_new (I_("popup-context-menu"),
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
G_TYPE_BOOLEAN, 3,
G_TYPE_INT, G_TYPE_INT,
G_TYPE_INT);
- /**
- * GtkToolbar::move-focus:
- * @toolbar: the #GtkToolbar which emitted the signal
- * @dir: a #GtkDirection
- *
- * A keybinding signal used internally by GTK+. This signal can't
- * be used in application code.
- *
- * Return value: %TRUE if the signal was handled, %FALSE if not
- */
- toolbar_signals[MOVE_FOCUS] =
- _gtk_binding_signal_new (I_("move_focus"),
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_CALLBACK (gtk_toolbar_move_focus),
- NULL, NULL,
- _gtk_marshal_BOOLEAN__ENUM,
- G_TYPE_BOOLEAN, 1,
- GTK_TYPE_DIRECTION_TYPE);
+
/**
* GtkToolbar::focus-home-or-end:
* @toolbar: the #GtkToolbar which emitted the signal
* Return value: %TRUE if the signal was handled, %FALSE if not
*/
toolbar_signals[FOCUS_HOME_OR_END] =
- _gtk_binding_signal_new (I_("focus_home_or_end"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_CALLBACK (gtk_toolbar_focus_home_or_end),
- NULL, NULL,
- _gtk_marshal_BOOLEAN__BOOLEAN,
- G_TYPE_BOOLEAN, 1,
- G_TYPE_BOOLEAN);
-
+ g_signal_new_class_handler (I_("focus-home-or-end"),
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_CALLBACK (gtk_toolbar_focus_home_or_end),
+ NULL, NULL,
+ _gtk_marshal_BOOLEAN__BOOLEAN,
+ G_TYPE_BOOLEAN, 1,
+ G_TYPE_BOOLEAN);
+
/* properties */
- g_object_class_install_property (gobject_class,
- PROP_ORIENTATION,
- g_param_spec_enum ("orientation",
- P_("Orientation"),
- P_("The orientation of the toolbar"),
- GTK_TYPE_ORIENTATION,
- GTK_ORIENTATION_HORIZONTAL,
- GTK_PARAM_READWRITE));
-
+ g_object_class_override_property (gobject_class,
+ PROP_ORIENTATION,
+ "orientation");
+
g_object_class_install_property (gobject_class,
PROP_TOOLBAR_STYLE,
g_param_spec_enum ("toolbar-style",
P_("Toolbar Style"),
P_("How to draw the toolbar"),
GTK_TYPE_TOOLBAR_STYLE,
- GTK_TOOLBAR_ICONS,
+ DEFAULT_TOOLBAR_STYLE,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_SHOW_ARROW,
P_("If an arrow should be shown if the toolbar doesn't fit"),
TRUE,
GTK_PARAM_READWRITE));
-
-
- /**
- * GtkToolbar:tooltips:
- *
- * If the tooltips of the toolbar should be active or not.
- *
- * Since: 2.8
- */
- g_object_class_install_property (gobject_class,
- PROP_TOOLTIPS,
- g_param_spec_boolean ("tooltips",
- P_("Tooltips"),
- P_("If the tooltips of the toolbar should be active or not"),
- TRUE,
- GTK_PARAM_READWRITE));
-
/**
* GtkToolbar:icon-size:
*/
g_object_class_install_property (gobject_class,
PROP_ICON_SIZE,
- g_param_spec_enum ("icon-size",
- P_("Icon size"),
- P_("Size of icons in this toolbar"),
- GTK_TYPE_ICON_SIZE,
- DEFAULT_ICON_SIZE,
- GTK_PARAM_READWRITE));
+ g_param_spec_int ("icon-size",
+ P_("Icon size"),
+ P_("Size of icons in this toolbar"),
+ 0, G_MAXINT,
+ DEFAULT_ICON_SIZE,
+ GTK_PARAM_READWRITE));
/**
* GtkToolbar:icon-size-set:
g_param_spec_boolean ("expand",
P_("Expand"),
P_("Whether the item should receive extra space when the toolbar grows"),
- TRUE,
+ FALSE,
GTK_PARAM_READWRITE));
gtk_container_class_install_child_property (container_class,
g_param_spec_boolean ("homogeneous",
P_("Homogeneous"),
P_("Whether the item should be the same size as other homogeneous items"),
- TRUE,
+ FALSE,
GTK_PARAM_READWRITE));
/* style properties */
DEFAULT_SPACE_SIZE,
GTK_PARAM_READABLE));
+ /**
+ * GtkToolbar:internal-padding:
+ *
+ * Amount of border space between the toolbar shadow and the buttons.
+ *
+ * Deprecated: 3.6: Use the standard padding CSS property
+ * (through objects like #GtkStyleContext and #GtkCssProvider); the value
+ * of this style property is ignored.
+ */
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("internal-padding",
P_("Internal padding"),
P_("Amount of border space between the toolbar shadow and the buttons"),
0,
G_MAXINT,
- DEFAULT_IPADDING,
+ 0,
GTK_PARAM_READABLE));
-
+
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_int ("max-child-expand",
+ P_("Maximum child expand"),
+ P_("Maximum amount of space an expandable item will be given"),
+ 0,
+ G_MAXINT,
+ G_MAXINT,
+ GTK_PARAM_READABLE));
+
gtk_widget_class_install_style_property (widget_class,
g_param_spec_enum ("space-style",
P_("Space style"),
GTK_TYPE_RELIEF_STYLE,
GTK_RELIEF_NONE,
GTK_PARAM_READABLE));
+ /**
+ * GtkToolbar:shadow-type:
+ *
+ * Style of bevel around the toolbar.
+ *
+ * Deprecated: 3.6: Use the standard border CSS property
+ * (through objects like #GtkStyleContext and #GtkCssProvider); the value
+ * of this style property is ignored.
+ */
gtk_widget_class_install_style_property (widget_class,
g_param_spec_enum ("shadow-type",
P_("Shadow type"),
GTK_TYPE_SHADOW_TYPE,
GTK_SHADOW_OUT,
GTK_PARAM_READABLE));
-
- gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-style",
- P_("Toolbar style"),
- P_("Whether default toolbars have text only, text and icons, icons only, etc."),
- GTK_TYPE_TOOLBAR_STYLE,
- DEFAULT_TOOLBAR_STYLE,
- GTK_PARAM_READWRITE));
-
- gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-icon-size",
- P_("Toolbar icon size"),
- P_("Size of icons in default toolbars"),
- GTK_TYPE_ICON_SIZE,
- DEFAULT_ICON_SIZE,
- GTK_PARAM_READWRITE));
-
+
binding_set = gtk_binding_set_by_class (klass);
- add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
- add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
- add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
- add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
+ add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
+ add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
+ add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
+ add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
- "focus_home_or_end", 1,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Home, 0,
+ "focus-home-or-end", 1,
G_TYPE_BOOLEAN, TRUE);
- gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
- "focus_home_or_end", 1,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0,
+ "focus-home-or-end", 1,
G_TYPE_BOOLEAN, TRUE);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
- "focus_home_or_end", 1,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_End, 0,
+ "focus-home-or-end", 1,
G_TYPE_BOOLEAN, FALSE);
- gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
- "focus_home_or_end", 1,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0,
+ "focus-home-or-end", 1,
G_TYPE_BOOLEAN, FALSE);
add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
-
- g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
+
+ g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
+}
+
+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_init (GtkToolbar *toolbar)
{
GtkToolbarPrivate *priv;
-
- GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);
- GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
-
- priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
- toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
- toolbar->style = DEFAULT_TOOLBAR_STYLE;
- toolbar->icon_size = DEFAULT_ICON_SIZE;
- toolbar->tooltips = gtk_tooltips_new ();
- g_object_ref (toolbar->tooltips);
- gtk_object_sink (GTK_OBJECT (toolbar->tooltips));
-
+ GtkStyleContext *context;
+
+ toolbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (toolbar,
+ GTK_TYPE_TOOLBAR,
+ GtkToolbarPrivate);
+ priv = toolbar->priv;
+
+ gtk_widget_set_can_focus (GTK_WIDGET (toolbar), FALSE);
+ gtk_widget_set_has_window (GTK_WIDGET (toolbar), FALSE);
+
+ priv->orientation = GTK_ORIENTATION_HORIZONTAL;
+ priv->style = DEFAULT_TOOLBAR_STYLE;
+ priv->icon_size = DEFAULT_ICON_SIZE;
+ priv->animation = DEFAULT_ANIMATION_STATE;
+
priv->arrow_button = gtk_toggle_button_new ();
- g_signal_connect (priv->arrow_button, "button_press_event",
+ g_signal_connect (priv->arrow_button, "button-press-event",
G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
g_signal_connect (priv->arrow_button, "clicked",
G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
get_button_relief (toolbar));
-
- priv->api_mode = DONT_KNOW;
-
+
gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
-
+
priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
gtk_widget_show (priv->arrow);
priv->max_homogeneous_pixels = -1;
priv->timer = g_timer_new ();
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (toolbar));
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOOLBAR);
}
static void
GParamSpec *pspec)
{
GtkToolbar *toolbar = GTK_TOOLBAR (object);
-
+ GtkToolbarPrivate *priv = toolbar->priv;
+
switch (prop_id)
{
case PROP_ORIENTATION:
- gtk_toolbar_set_orientation (toolbar, g_value_get_enum (value));
+ g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0,
+ g_value_get_enum (value));
break;
case PROP_TOOLBAR_STYLE:
gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
case PROP_SHOW_ARROW:
gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
break;
- case PROP_TOOLTIPS:
- gtk_toolbar_set_tooltips (toolbar, g_value_get_boolean (value));
- break;
case PROP_ICON_SIZE:
- gtk_toolbar_set_icon_size (toolbar, g_value_get_enum (value));
+ gtk_toolbar_set_icon_size (toolbar, g_value_get_int (value));
break;
case PROP_ICON_SIZE_SET:
if (g_value_get_boolean (value))
- toolbar->icon_size_set = TRUE;
+ priv->icon_size_set = TRUE;
else
gtk_toolbar_unset_icon_size (toolbar);
break;
GParamSpec *pspec)
{
GtkToolbar *toolbar = GTK_TOOLBAR (object);
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
+ GtkToolbarPrivate *priv = toolbar->priv;
+
switch (prop_id)
{
case PROP_ORIENTATION:
- g_value_set_enum (value, toolbar->orientation);
+ g_value_set_enum (value, priv->orientation);
break;
case PROP_TOOLBAR_STYLE:
- g_value_set_enum (value, toolbar->style);
+ g_value_set_enum (value, priv->style);
break;
case PROP_SHOW_ARROW:
g_value_set_boolean (value, priv->show_arrow);
break;
- case PROP_TOOLTIPS:
- g_value_set_boolean (value, gtk_toolbar_get_tooltips (toolbar));
- break;
case PROP_ICON_SIZE:
- g_value_set_enum (value, gtk_toolbar_get_icon_size (toolbar));
+ g_value_set_int (value, gtk_toolbar_get_icon_size (toolbar));
break;
case PROP_ICON_SIZE_SET:
- g_value_set_boolean (value, toolbar->icon_size_set);
+ g_value_set_boolean (value, priv->icon_size_set);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
static void
gtk_toolbar_map (GtkWidget *widget)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
-
- GTK_WIDGET_CLASS (parent_class)->map (widget);
-
+ GtkToolbar *toolbar = GTK_TOOLBAR (widget);
+ GtkToolbarPrivate *priv = toolbar->priv;
+
+ GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
+
if (priv->event_window)
gdk_window_show_unraised (priv->event_window);
}
static void
gtk_toolbar_unmap (GtkWidget *widget)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
-
+ GtkToolbar *toolbar = GTK_TOOLBAR (widget);
+ GtkToolbarPrivate *priv = toolbar->priv;
+
if (priv->event_window)
gdk_window_hide (priv->event_window);
- GTK_WIDGET_CLASS (parent_class)->unmap (widget);
+ GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
}
static void
gtk_toolbar_realize (GtkWidget *widget)
{
+ GtkAllocation allocation;
GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
+ GtkToolbarPrivate *priv = toolbar->priv;
+ GdkWindow *window;
GdkWindowAttr attributes;
gint attributes_mask;
- gint border_width;
-
- GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
-
- border_width = GTK_CONTAINER (widget)->border_width;
-
+ guint border_width;
+
+ gtk_widget_set_realized (widget, TRUE);
+
+ gtk_widget_get_allocation (widget, &allocation);
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
attributes.wclass = GDK_INPUT_ONLY;
attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = widget->allocation.x + border_width;
- attributes.y = widget->allocation.y + border_width;
- attributes.width = widget->allocation.width - border_width * 2;
- attributes.height = widget->allocation.height - border_width * 2;
+ attributes.x = allocation.x + border_width;
+ attributes.y = allocation.y + border_width;
+ attributes.width = allocation.width - border_width * 2;
+ attributes.height = allocation.height - border_width * 2;
attributes.event_mask = gtk_widget_get_events (widget);
attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK);
-
+
attributes_mask = GDK_WA_X | GDK_WA_Y;
-
- widget->window = gtk_widget_get_parent_window (widget);
- g_object_ref (widget->window);
- widget->style = gtk_style_attach (widget->style, widget->window);
-
+
+ window = gtk_widget_get_parent_window (widget);
+ gtk_widget_set_window (widget, window);
+ g_object_ref (window);
+
priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask);
- gdk_window_set_user_data (priv->event_window, toolbar);
+ gtk_widget_register_window (widget, priv->event_window);
}
static void
gtk_toolbar_unrealize (GtkWidget *widget)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
-
+ GtkToolbar *toolbar = GTK_TOOLBAR (widget);
+ GtkToolbarPrivate *priv = toolbar->priv;
+
if (priv->event_window)
{
- gdk_window_set_user_data (priv->event_window, NULL);
+ gtk_widget_unregister_window (widget, priv->event_window);
gdk_window_destroy (priv->event_window);
priv->event_window = NULL;
}
-
- if (GTK_WIDGET_CLASS (parent_class)->unrealize)
- (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+
+ GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget);
}
static gint
-gtk_toolbar_expose (GtkWidget *widget,
- GdkEventExpose *event)
+gtk_toolbar_draw (GtkWidget *widget,
+ cairo_t *cr)
{
GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
+ GtkToolbarPrivate *priv = toolbar->priv;
+ GtkStyleContext *context;
GList *list;
- gint border_width;
-
- border_width = GTK_CONTAINER (widget)->border_width;
-
- if (GTK_WIDGET_DRAWABLE (widget))
- {
- gtk_paint_box (widget->style,
- widget->window,
- GTK_WIDGET_STATE (widget),
- get_shadow_type (toolbar),
- &event->area, widget, "toolbar",
- border_width + widget->allocation.x,
- border_width + widget->allocation.y,
- widget->allocation.width - 2 * border_width,
- widget->allocation.height - 2 * border_width);
- }
-
+ guint border_width;
+
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+ context = gtk_widget_get_style_context (widget);
+
+ gtk_render_background (context, cr, border_width, border_width,
+ gtk_widget_get_allocated_width (widget) - 2 * border_width,
+ gtk_widget_get_allocated_height (widget) - 2 * border_width);
+ gtk_render_frame (context, cr, border_width, border_width,
+ gtk_widget_get_allocated_width (widget) - 2 * border_width,
+ gtk_widget_get_allocated_height (widget) - 2 * border_width);
+
for (list = priv->content; list != NULL; list = list->next)
{
ToolbarContent *content = list->data;
- toolbar_content_expose (content, GTK_CONTAINER (widget), event);
+ toolbar_content_draw (content, GTK_CONTAINER (widget), cr);
}
- gtk_container_propagate_expose (GTK_CONTAINER (widget),
- priv->arrow_button,
- event);
-
+ gtk_container_propagate_draw (GTK_CONTAINER (widget),
+ priv->arrow_button,
+ cr);
+
return FALSE;
}
+static void
+get_widget_padding_and_border (GtkWidget *widget,
+ GtkBorder *padding)
+{
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkBorder tmp;
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_style_context_get_state (context);
+
+ gtk_style_context_get_padding (context, state, padding);
+ gtk_style_context_get_border (context, state, &tmp);
+
+ padding->top += tmp.top;
+ padding->right += tmp.right;
+ padding->bottom += tmp.bottom;
+ padding->left += tmp.left;
+}
+
static void
gtk_toolbar_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *list;
gint max_child_height;
gint max_child_width;
gint homogeneous_size;
gint long_req;
gint pack_front_size;
- gint ipadding;
+ GtkBorder padding;
+ guint border_width;
GtkRequisition arrow_requisition;
max_homogeneous_child_width = 0;
}
}
- if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
homogeneous_size = max_homogeneous_child_width;
else
homogeneous_size = max_homogeneous_child_height;
toolbar_content_size_request (content, toolbar, &requisition);
- if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
size = requisition.width;
else
size = requisition.height;
pack_front_size += size;
}
- if (priv->show_arrow && priv->api_mode == NEW_API)
+ if (priv->show_arrow)
{
- gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
-
- if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
+ gtk_widget_get_preferred_size (priv->arrow_button,
+ &arrow_requisition, NULL);
+
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
long_req = arrow_requisition.width;
else
long_req = arrow_requisition.height;
long_req = pack_front_size;
}
- if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
requisition->width = long_req;
requisition->height = MAX (max_child_height, arrow_requisition.height);
requisition->height = long_req;
requisition->width = MAX (max_child_width, arrow_requisition.width);
}
-
+
/* Extra spacing */
- ipadding = get_internal_padding (toolbar);
-
- requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
- requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
-
- if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
- {
- requisition->width += 2 * widget->style->xthickness;
- requisition->height += 2 * widget->style->ythickness;
- }
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
+ get_widget_padding_and_border (widget, &padding);
+
+ requisition->width += 2 * border_width + padding.left + padding.right;
+ requisition->height += 2 * border_width + padding.top + padding.bottom;
- toolbar->button_maxw = max_homogeneous_child_width;
- toolbar->button_maxh = max_homogeneous_child_height;
+ priv->button_maxw = max_homogeneous_child_width;
+ priv->button_maxh = max_homogeneous_child_height;
+}
+
+static void
+gtk_toolbar_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ GtkRequisition requisition;
+
+ gtk_toolbar_size_request (widget, &requisition);
+
+ *minimum = *natural = requisition.width;
+}
+
+static void
+gtk_toolbar_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ GtkRequisition requisition;
+
+ gtk_toolbar_size_request (widget, &requisition);
+
+ *minimum = *natural = requisition.height;
}
static gint
-position (gint from, gint to, gdouble elapsed)
+position (GtkToolbar *toolbar,
+ gint from,
+ gint to,
+ gdouble elapsed)
{
+ GtkToolbarPrivate *priv = toolbar->priv;
gint n_pixels;
+ if (!priv->animation)
+ return to;
+
if (elapsed <= ACCEL_THRESHOLD)
{
n_pixels = SLIDE_SPEED * elapsed;
n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
}
-
+
if (to > from)
return MIN (from + n_pixels, to);
else
const GtkAllocation *goal,
GtkAllocation *intermediate)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
-
- intermediate->x = position (start->x, goal->x, elapsed);
- intermediate->y = position (start->y, goal->y, elapsed);
- intermediate->width =
- position (start->x + start->width, goal->x + goal->width, elapsed) - intermediate->x;
- intermediate->height =
- position (start->y + start->height, goal->y + goal->height, elapsed) - intermediate->y;
+
+ intermediate->x = position (toolbar, start->x, goal->x, elapsed);
+ intermediate->y = position (toolbar, start->y, goal->y, elapsed);
+ intermediate->width = position (toolbar, start->x + start->width,
+ goal->x + goal->width,
+ elapsed) - intermediate->x;
+ intermediate->height = position (toolbar, start->y + start->height,
+ goal->y + goal->height,
+ elapsed) - intermediate->y;
}
static void
get_item_size (GtkToolbar *toolbar,
ToolbarContent *content)
{
+ GtkToolbarPrivate *priv = toolbar->priv;
GtkRequisition requisition;
toolbar_content_size_request (content, toolbar, &requisition);
-
- if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
+
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
if (toolbar_content_is_homogeneous (content, toolbar))
- return toolbar->button_maxw;
+ return priv->button_maxw;
else
return requisition.width;
}
else
{
if (toolbar_content_is_homogeneous (content, toolbar))
- return toolbar->button_maxh;
+ return priv->button_maxh;
else
return requisition.height;
}
static gboolean
slide_idle_handler (gpointer data)
{
- GtkToolbar *toolbar = data;
- GtkToolbarPrivate *priv;
+ GtkToolbar *toolbar = GTK_TOOLBAR (data);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *list;
-
- GDK_THREADS_ENTER ();
-
- priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
+
if (priv->need_sync)
{
gdk_flush ();
{
gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
- GDK_THREADS_LEAVE ();
return TRUE;
}
}
+ gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
+
priv->is_sliding = FALSE;
priv->idle_id = 0;
- GDK_THREADS_LEAVE();
return FALSE;
}
static void
gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
{
+ GtkAllocation allocation;
GtkWidget *widget = GTK_WIDGET (toolbar);
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *list;
gint cur_x;
gint cur_y;
gint border_width;
+ GtkBorder padding;
gboolean rtl;
gboolean vertical;
priv->is_sliding = TRUE;
if (!priv->idle_id)
- priv->idle_id = g_idle_add (slide_idle_handler, toolbar);
-
+ priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
+
+ gtk_widget_get_allocation (widget, &allocation);
+
rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
- vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
- border_width = get_internal_padding (toolbar) + GTK_CONTAINER (toolbar)->border_width;
-
+ vertical = (priv->orientation == GTK_ORIENTATION_VERTICAL);
+
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
+ get_widget_padding_and_border (GTK_WIDGET (toolbar), &padding);
+
if (rtl)
{
- cur_x = widget->allocation.width - border_width - widget->style->xthickness;
- cur_y = widget->allocation.height - border_width - widget->style->ythickness;
+ cur_x = allocation.width - border_width - padding.right;
+ cur_y = allocation.height - border_width - padding.top;
}
else
{
- cur_x = border_width + widget->style->xthickness;
- cur_y = border_width + widget->style->ythickness;
+ cur_x = border_width + padding.left;
+ cur_y = border_width + padding.top;
}
-
- cur_x += widget->allocation.x;
- cur_y += widget->allocation.y;
-
+
+ cur_x += allocation.x;
+ cur_y += allocation.y;
+
for (list = priv->content; list != NULL; list = list->next)
{
ToolbarContent *content = list->data;
toolbar_content_get_allocation (content, &item_allocation);
if ((state == NORMAL &&
- rect_within (&item_allocation, &(widget->allocation))) ||
+ rect_within (&item_allocation, &allocation)) ||
state == OVERFLOWN)
{
new_start_allocation = item_allocation;
if (vertical)
{
- new_start_allocation.width = widget->allocation.width -
- 2 * border_width - 2 * widget->style->xthickness;
+ new_start_allocation.width = allocation.width -
+ 2 * border_width -
+ padding.left - padding.right;
new_start_allocation.height = 0;
}
else
{
new_start_allocation.width = 0;
- new_start_allocation.height = widget->allocation.height -
- 2 * border_width - 2 * widget->style->ythickness;
+ new_start_allocation.height = allocation.height -
+ 2 * border_width -
+ padding.top - padding.bottom;
}
}
static void
gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
+ GtkToolbarPrivate *priv = toolbar->priv;
+
if (priv->is_sliding)
{
GList *list;
remove_item (GtkWidget *menu_item,
gpointer data)
{
- gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
+ gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (menu_item)),
+ menu_item);
}
static void
menu_deactivated (GtkWidget *menu,
GtkToolbar *toolbar)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
+
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
}
static void
-menu_detached (GtkWidget *toolbar,
+menu_detached (GtkWidget *widget,
GtkMenu *menu)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbar *toolbar = GTK_TOOLBAR (widget);
+ GtkToolbarPrivate *priv = toolbar->priv;
+
priv->menu = NULL;
}
static void
rebuild_menu (GtkToolbar *toolbar)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *list, *children;
-
+
if (!priv->menu)
{
priv->menu = GTK_MENU (gtk_menu_new());
GTK_WIDGET (toolbar),
menu_detached);
- g_signal_connect (priv->menu, "deactivate", G_CALLBACK (menu_deactivated), toolbar);
+ g_signal_connect (priv->menu, "deactivate",
+ G_CALLBACK (menu_deactivated), toolbar);
}
gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
gtk_toolbar_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
+ GtkAllocation widget_allocation;
GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
GtkAllocation *allocations;
ItemState *new_states;
GtkAllocation arrow_allocation;
+ GtkBorder padding;
gint arrow_size;
gint size, pos, short_size;
GList *list;
GtkRequisition arrow_requisition;
gboolean overflowing;
gboolean size_changed;
- gdouble elapsed;
GtkAllocation item_area;
-
+
+ gtk_widget_get_allocation (widget, &widget_allocation);
size_changed = FALSE;
- if (widget->allocation.x != allocation->x ||
- widget->allocation.y != allocation->y ||
- widget->allocation.width != allocation->width ||
- widget->allocation.height != allocation->height)
+ if (widget_allocation.x != allocation->x ||
+ widget_allocation.y != allocation->y ||
+ widget_allocation.width != allocation->width ||
+ widget_allocation.height != allocation->height)
{
size_changed = TRUE;
}
-
+
if (size_changed)
gtk_toolbar_stop_sliding (toolbar);
-
- widget->allocation = *allocation;
-
- border_width = GTK_CONTAINER (toolbar)->border_width;
-
- if (GTK_WIDGET_REALIZED (widget))
- {
- gdk_window_move_resize (priv->event_window,
- allocation->x + border_width,
- allocation->y + border_width,
- allocation->width - border_width * 2,
- allocation->height - border_width * 2);
- }
-
- border_width += get_internal_padding (toolbar);
-
- gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
- &arrow_requisition);
-
- if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
+
+ gtk_widget_set_allocation (widget, allocation);
+
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
+
+ if (gtk_widget_get_realized (widget))
+ gdk_window_move_resize (priv->event_window,
+ allocation->x + border_width,
+ allocation->y + border_width,
+ allocation->width - border_width * 2,
+ allocation->height - border_width * 2);
+
+
+ gtk_widget_get_preferred_size (priv->arrow_button,
+ &arrow_requisition, NULL);
+ get_widget_padding_and_border (widget, &padding);
+
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
- available_size = size = allocation->width - 2 * border_width;
- short_size = allocation->height - 2 * border_width;
+ available_size = size = allocation->width - 2 * border_width - padding.left - padding.right;
+ short_size = allocation->height - 2 * border_width - padding.top - padding.bottom;
arrow_size = arrow_requisition.width;
-
- if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
- {
- available_size -= 2 * widget->style->xthickness;
- short_size -= 2 * widget->style->ythickness;
- }
}
else
{
- available_size = size = allocation->height - 2 * border_width;
- short_size = allocation->width - 2 * border_width;
+ available_size = size = allocation->height - 2 * border_width - padding.top - padding.bottom;
+ short_size = allocation->width - 2 * border_width - padding.left - padding.right;
arrow_size = arrow_requisition.height;
-
- if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
- {
- available_size -= 2 * widget->style->ythickness;
- short_size -= 2 * widget->style->xthickness;
- }
}
-
+
n_items = g_list_length (priv->content);
allocations = g_new0 (GtkAllocation, n_items);
new_states = g_new0 (ItemState, n_items);
-
+
needed_size = 0;
need_arrow = FALSE;
for (list = priv->content; list != NULL; list = list->next)
{
ToolbarContent *content = list->data;
-
- if (toolbar_content_visible (content, toolbar))
- {
- needed_size += get_item_size (toolbar, content);
- /* Do we need an arrow?
- *
- * Assume we don't, and see if any non-separator item with a
- * proxy menu item is then going to overflow.
- */
- if (needed_size > available_size &&
- !need_arrow &&
- priv->show_arrow &&
- priv->api_mode == NEW_API &&
- toolbar_content_has_proxy_menu_item (content) &&
- !toolbar_content_is_separator (content))
- {
- need_arrow = TRUE;
- }
- }
+ if (toolbar_content_visible (content, toolbar))
+ {
+ needed_size += get_item_size (toolbar, content);
+
+ /* Do we need an arrow?
+ *
+ * Assume we don't, and see if any non-separator item
+ * with a proxy menu item is then going to overflow.
+ */
+ if (needed_size > available_size &&
+ !need_arrow &&
+ priv->show_arrow &&
+ toolbar_content_has_proxy_menu_item (content) &&
+ !toolbar_content_is_separator (content))
+ {
+ need_arrow = TRUE;
+ }
+ }
}
-
+
if (need_arrow)
size = available_size - arrow_size;
else
size = available_size;
-
+
/* calculate widths and states of items */
overflowing = FALSE;
for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
{
ToolbarContent *content = list->data;
gint item_size;
-
+
if (!toolbar_content_visible (content, toolbar))
- {
- new_states[i] = HIDDEN;
- continue;
- }
-
+ {
+ new_states[i] = HIDDEN;
+ continue;
+ }
+
item_size = get_item_size (toolbar, content);
if (item_size <= size && !overflowing)
- {
- size -= item_size;
- allocations[i].width = item_size;
- new_states[i] = NORMAL;
- }
+ {
+ size -= item_size;
+ allocations[i].width = item_size;
+ new_states[i] = NORMAL;
+ }
else
- {
- overflowing = TRUE;
- new_states[i] = OVERFLOWN;
- allocations[i].width = item_size;
- }
+ {
+ overflowing = TRUE;
+ new_states[i] = OVERFLOWN;
+ allocations[i].width = item_size;
+ }
}
-
- /* calculate width of arrow */
+
+ /* calculate width of arrow */
if (need_arrow)
{
arrow_allocation.width = arrow_size;
arrow_allocation.height = MAX (short_size, 1);
}
-
+
/* expand expandable items */
-
- /* We don't expand when there is an overflow menu, because that leads to
- * weird jumps when items get moved to the overflow menu and the expanding
+
+ /* We don't expand when there is an overflow menu,
+ * because that leads to weird jumps when items get
+ * moved to the overflow menu and the expanding
* items suddenly get a lot of extra space
*/
if (!overflowing)
{
+ gint max_child_expand;
n_expand_items = 0;
+
for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
- {
- ToolbarContent *content = list->data;
-
- if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
- n_expand_items++;
- }
-
+ {
+ ToolbarContent *content = list->data;
+
+ if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
+ n_expand_items++;
+ }
+
+ max_child_expand = get_max_child_expand (toolbar);
for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
- {
- ToolbarContent *content = list->data;
-
- if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
- {
- gint extra = size / n_expand_items;
- if (size % n_expand_items != 0)
- extra++;
-
- allocations[i].width += extra;
- size -= extra;
- n_expand_items--;
- }
- }
-
+ {
+ ToolbarContent *content = list->data;
+
+ if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
+ {
+ gint extra = size / n_expand_items;
+ if (size % n_expand_items != 0)
+ extra++;
+
+ if (extra > max_child_expand)
+ extra = max_child_expand;
+
+ allocations[i].width += extra;
+ size -= extra;
+ n_expand_items--;
+ }
+ }
+
g_assert (n_expand_items == 0);
}
-
+
/* position items */
pos = border_width;
for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
{
- /* both NORMAL and OVERFLOWN items get a position. This ensures
- * that sliding will work for OVERFLOWN items too
+ /* Both NORMAL and OVERFLOWN items get a position.
+ * This ensures that sliding will work for OVERFLOWN items too.
*/
- if (new_states[i] == NORMAL ||
- new_states[i] == OVERFLOWN)
- {
- allocations[i].x = pos;
- allocations[i].y = border_width;
- allocations[i].height = short_size;
-
- pos += allocations[i].width;
- }
+ if (new_states[i] == NORMAL || new_states[i] == OVERFLOWN)
+ {
+ allocations[i].x = pos;
+ allocations[i].y = border_width;
+ allocations[i].height = short_size;
+
+ pos += allocations[i].width;
+ }
}
-
+
/* position arrow */
if (need_arrow)
{
arrow_allocation.x = available_size - border_width - arrow_allocation.width;
arrow_allocation.y = border_width;
}
-
+
item_area.x = border_width;
item_area.y = border_width;
item_area.width = available_size - (need_arrow? arrow_size : 0);
item_area.height = short_size;
/* fix up allocations in the vertical or RTL cases */
- if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
+ if (priv->orientation == GTK_ORIENTATION_VERTICAL)
{
for (i = 0; i < n_items; ++i)
- fixup_allocation_for_vertical (&(allocations[i]));
-
+ fixup_allocation_for_vertical (&(allocations[i]));
+
if (need_arrow)
- fixup_allocation_for_vertical (&arrow_allocation);
+ fixup_allocation_for_vertical (&arrow_allocation);
fixup_allocation_for_vertical (&item_area);
}
else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
{
for (i = 0; i < n_items; ++i)
- fixup_allocation_for_rtl (available_size, &(allocations[i]));
-
+ fixup_allocation_for_rtl (available_size, &(allocations[i]));
+
if (need_arrow)
- fixup_allocation_for_rtl (available_size, &arrow_allocation);
+ fixup_allocation_for_rtl (available_size, &arrow_allocation);
fixup_allocation_for_rtl (available_size, &item_area);
}
-
+
/* translate the items by allocation->(x,y) */
for (i = 0; i < n_items; ++i)
{
- allocations[i].x += allocation->x;
- allocations[i].y += allocation->y;
-
- if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
- {
- allocations[i].x += widget->style->xthickness;
- allocations[i].y += widget->style->ythickness;
- }
+ allocations[i].x += allocation->x + padding.left;
+ allocations[i].y += allocation->y + padding.top;
}
-
+
if (need_arrow)
{
- arrow_allocation.x += allocation->x;
- arrow_allocation.y += allocation->y;
-
- if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
- {
- arrow_allocation.x += widget->style->xthickness;
- arrow_allocation.y += widget->style->ythickness;
- }
+ arrow_allocation.x += allocation->x + padding.left;
+ arrow_allocation.y += allocation->y + padding.top;
}
- item_area.x += allocation->x;
- item_area.y += allocation->y;
- if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
- {
- item_area.x += widget->style->xthickness;
- item_area.y += widget->style->ythickness;
- }
+ item_area.x += allocation->x + padding.left;
+ item_area.y += allocation->y + padding.top;
/* did anything change? */
for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
{
ToolbarContent *content = list->data;
-
+
if (toolbar_content_get_state (content) == NORMAL &&
- new_states[i] != NORMAL)
- {
- /* an item disappeared and we didn't change size, so begin sliding */
- if (!size_changed && priv->api_mode == NEW_API)
- gtk_toolbar_begin_sliding (toolbar);
- }
+ new_states[i] != NORMAL)
+ {
+ /* an item disappeared and we didn't change size, so begin sliding */
+ if (!size_changed)
+ gtk_toolbar_begin_sliding (toolbar);
+ }
}
-
+
/* finally allocate the items */
if (priv->is_sliding)
{
for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
- {
- ToolbarContent *content = list->data;
-
- toolbar_content_set_goal_allocation (content, &(allocations[i]));
- }
+ {
+ ToolbarContent *content = list->data;
+
+ toolbar_content_set_goal_allocation (content, &(allocations[i]));
+ }
}
- elapsed = g_timer_elapsed (priv->timer, NULL);
for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
{
ToolbarContent *content = list->data;
- if (new_states[i] == OVERFLOWN ||
- new_states[i] == NORMAL)
- {
- GtkAllocation alloc;
- GtkAllocation start_allocation;
- GtkAllocation goal_allocation;
-
- if (priv->is_sliding)
- {
- toolbar_content_get_start_allocation (content, &start_allocation);
- toolbar_content_get_goal_allocation (content, &goal_allocation);
-
- compute_intermediate_allocation (toolbar,
- &start_allocation,
- &goal_allocation,
- &alloc);
-
- priv->need_sync = TRUE;
- }
- else
- {
- alloc = allocations[i];
- }
-
- if (alloc.width <= 0 || alloc.height <= 0)
- {
- toolbar_content_set_child_visible (content, toolbar, FALSE);
- }
- else
- {
- if (!rect_within (&alloc, &item_area))
- {
- toolbar_content_set_child_visible (content, toolbar, FALSE);
- toolbar_content_size_allocate (content, &alloc);
- }
- else
- {
- toolbar_content_set_child_visible (content, toolbar, TRUE);
- toolbar_content_size_allocate (content, &alloc);
- }
- }
- }
+ if (new_states[i] == OVERFLOWN || new_states[i] == NORMAL)
+ {
+ GtkAllocation alloc;
+ GtkAllocation start_allocation = { 0, };
+ GtkAllocation goal_allocation;
+
+ if (priv->is_sliding)
+ {
+ toolbar_content_get_start_allocation (content, &start_allocation);
+ toolbar_content_get_goal_allocation (content, &goal_allocation);
+
+ compute_intermediate_allocation (toolbar,
+ &start_allocation,
+ &goal_allocation,
+ &alloc);
+
+ priv->need_sync = TRUE;
+ }
+ else
+ {
+ alloc = allocations[i];
+ }
+
+ if (alloc.width <= 0 || alloc.height <= 0)
+ {
+ toolbar_content_set_child_visible (content, toolbar, FALSE);
+ }
+ else
+ {
+ if (!rect_within (&alloc, &item_area))
+ {
+ toolbar_content_set_child_visible (content, toolbar, FALSE);
+ toolbar_content_size_allocate (content, &alloc);
+ }
+ else
+ {
+ toolbar_content_set_child_visible (content, toolbar, TRUE);
+ toolbar_content_size_allocate (content, &alloc);
+ }
+ }
+ }
else
- {
- toolbar_content_set_child_visible (content, toolbar, FALSE);
- }
-
+ {
+ toolbar_content_set_child_visible (content, toolbar, FALSE);
+ }
+
toolbar_content_set_state (content, new_states[i]);
}
-
+
if (priv->menu && priv->need_rebuild)
rebuild_menu (toolbar);
-
+
if (need_arrow)
{
gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
- &arrow_allocation);
+ &arrow_allocation);
gtk_widget_show (GTK_WIDGET (priv->arrow_button));
}
else
{
gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
- if (priv->menu && GTK_WIDGET_VISIBLE (priv->menu))
- gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
+ if (priv->menu && gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
+ gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
}
g_free (allocations);
static void
gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
- gtk_toolbar_reconfigured (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
+ GtkReliefStyle relief;
+
+ relief = get_button_relief (toolbar);
+
+ if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
+ {
+ gtk_toolbar_reconfigured (toolbar);
- gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), get_button_relief (toolbar));
+ gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
+ }
}
static void
-gtk_toolbar_style_set (GtkWidget *widget,
- GtkStyle *prev_style)
+gtk_toolbar_style_updated (GtkWidget *widget)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
-
+ GtkToolbar *toolbar = GTK_TOOLBAR (widget);
+ GtkToolbarPrivate *priv = toolbar->priv;
+
+ GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->style_updated (widget);
+
priv->max_homogeneous_pixels = -1;
-
- if (GTK_WIDGET_REALIZED (widget))
- gtk_style_set_background (widget->style, widget->window, widget->state);
-
- if (prev_style)
- gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
+ gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
}
static GList *
gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
GtkDirectionType dir)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *result = NULL;
GList *list;
gboolean rtl;
for (list = children; list != NULL; list = list->next)
{
GtkWidget *child = list->data;
-
- if (GTK_CONTAINER (toolbar)->focus_child == child)
+
+ if (gtk_container_get_focus_child (GTK_CONTAINER (toolbar)) == child)
break;
- if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
+ if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
break;
}
/* Keybinding handler. This function is called when the user presses
* Ctrl TAB or an arrow key.
*/
-static gboolean
-gtk_toolbar_move_focus (GtkToolbar *toolbar,
+static void
+gtk_toolbar_move_focus (GtkWidget *widget,
GtkDirectionType dir)
{
+ GtkToolbar *toolbar = GTK_TOOLBAR (widget);
+ GtkContainer *container = GTK_CONTAINER (toolbar);
+ GtkWidget *focus_child;
GList *list;
gboolean try_focus = FALSE;
GList *children;
- GtkContainer *container = GTK_CONTAINER (toolbar);
-
- if (container->focus_child &&
- gtk_widget_child_focus (container->focus_child, dir))
- {
- return TRUE;
- }
+
+ focus_child = gtk_container_get_focus_child (container);
+
+ if (focus_child && gtk_widget_child_focus (focus_child, dir))
+ return;
children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
{
GtkWidget *child = list->data;
- if (try_focus && GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
+ if (try_focus && gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
break;
- if (child == GTK_CONTAINER (toolbar)->focus_child)
+ if (child == focus_child)
try_focus = TRUE;
}
g_list_free (children);
-
- return FALSE;
}
/* The focus handler for the toolbar. It called when the user presses
* arrow keys or Ctrl TAB (both of which are handled by the
* gtk_toolbar_move_focus() keybinding function.
*/
- if (GTK_CONTAINER (widget)->focus_child)
+ if (gtk_container_get_focus_child (GTK_CONTAINER (widget)))
return FALSE;
children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
{
GtkWidget *child = list->data;
- if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
+ if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
{
result = TRUE;
break;
return result;
}
+static GtkSettings *
+toolbar_get_settings (GtkToolbar *toolbar)
+{
+ return toolbar->priv->settings;
+}
+
static void
style_change_notify (GtkToolbar *toolbar)
{
- if (!toolbar->style_set)
+ GtkToolbarPrivate *priv = toolbar->priv;
+
+ if (!priv->style_set)
{
/* pretend it was set, then unset, thus reverting to new default */
- toolbar->style_set = TRUE;
+ priv->style_set = TRUE;
gtk_toolbar_unset_style (toolbar);
}
}
static void
icon_size_change_notify (GtkToolbar *toolbar)
-{
- if (!toolbar->icon_size_set)
+{
+ GtkToolbarPrivate *priv = toolbar->priv;
+
+ if (!priv->icon_size_set)
{
/* pretend it was set, then unset, thus reverting to new default */
- toolbar->icon_size_set = TRUE;
+ priv->icon_size_set = TRUE;
gtk_toolbar_unset_icon_size (toolbar);
}
}
-static GtkSettings *
-toolbar_get_settings (GtkToolbar *toolbar)
+static void
+animation_change_notify (GtkToolbar *toolbar)
+{
+ GtkToolbarPrivate *priv = toolbar->priv;
+ GtkSettings *settings = toolbar_get_settings (toolbar);
+ gboolean animation;
+
+ if (settings)
+ g_object_get (settings,
+ "gtk-enable-animations", &animation,
+ NULL);
+ else
+ animation = DEFAULT_ANIMATION_STATE;
+
+ priv->animation = animation;
+}
+
+static void
+settings_change_notify (GtkSettings *settings,
+ const GParamSpec *pspec,
+ GtkToolbar *toolbar)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
- return priv->settings;
+ if (! strcmp (pspec->name, "gtk-toolbar-style"))
+ style_change_notify (toolbar);
+ else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
+ icon_size_change_notify (toolbar);
+ else if (! strcmp (pspec->name, "gtk-enable-animations"))
+ animation_change_notify (toolbar);
}
static void
gtk_toolbar_screen_changed (GtkWidget *widget,
GdkScreen *previous_screen)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
GtkToolbar *toolbar = GTK_TOOLBAR (widget);
+ GtkToolbarPrivate *priv = toolbar->priv;
GtkSettings *old_settings = toolbar_get_settings (toolbar);
GtkSettings *settings;
if (old_settings)
{
- g_signal_handler_disconnect (old_settings, toolbar->style_set_connection);
- g_signal_handler_disconnect (old_settings, toolbar->icon_size_connection);
-
+ g_signal_handler_disconnect (old_settings, priv->settings_connection);
+ priv->settings_connection = 0;
g_object_unref (old_settings);
}
-
+
if (settings)
{
- toolbar->style_set_connection =
- g_signal_connect_swapped (settings,
- "notify::gtk-toolbar-style",
- G_CALLBACK (style_change_notify),
- toolbar);
- toolbar->icon_size_connection =
- g_signal_connect_swapped (settings,
- "notify::gtk-toolbar-icon-size",
- G_CALLBACK (icon_size_change_notify),
- toolbar);
-
- g_object_ref (settings);
- priv->settings = settings;
+ priv->settings_connection =
+ g_signal_connect (settings, "notify",
+ G_CALLBACK (settings_change_notify),
+ toolbar);
+
+ priv->settings = g_object_ref (settings);
}
else
priv->settings = NULL;
-
+
style_change_notify (toolbar);
icon_size_change_notify (toolbar);
+ animation_change_notify (toolbar);
}
static int
gint x,
gint y)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *interesting_content;
GList *list;
GtkOrientation orientation;
if (!interesting_content)
return 0;
- orientation = toolbar->orientation;
+ orientation = priv->orientation;
direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
/* distance to first interesting item */
static void
reset_all_placeholders (GtkToolbar *toolbar)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *list;
for (list = priv->content; list != NULL; list = list->next)
physical_to_logical (GtkToolbar *toolbar,
gint physical)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *list;
int logical;
logical_to_physical (GtkToolbar *toolbar,
gint logical)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *list;
gint physical;
/**
* gtk_toolbar_set_drop_highlight_item:
* @toolbar: a #GtkToolbar
- * @tool_item: a #GtkToolItem, or %NULL to turn of highlighting
+ * @tool_item: (allow-none): a #GtkToolItem, or %NULL to turn of highlighting
* @index_: a position on @toolbar
- *
+ *
* Highlights @toolbar to give an idea of what it would look like
- * if @item was added to @toolbar at the position indicated by @index_.
+ * if @item was added to @toolbar at the position indicated by @index_.
* If @item is %NULL, highlighting is turned off. In that case @index_
* is ignored.
*
g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
-
- gtk_toolbar_check_new_api (toolbar);
-
- priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
+
+ priv = toolbar->priv;
+
if (!tool_item)
{
if (priv->highlight_tool_item)
if (priv->highlight_tool_item)
g_object_unref (priv->highlight_tool_item);
- g_object_ref (tool_item);
- gtk_object_sink (GTK_OBJECT (tool_item));
+ g_object_ref_sink (tool_item);
priv->highlight_tool_item = tool_item;
g_assert (content);
g_assert (toolbar_content_is_placeholder (content));
-
- gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
- &requisition);
+
+ gtk_widget_get_preferred_size (GTK_WIDGET (priv->highlight_tool_item),
+ &requisition, NULL);
toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
restart_sliding = FALSE;
toolbar_content_size_request (content, toolbar, &old_requisition);
- if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
requisition.height = -1;
if (requisition.width != old_requisition.width)
static void
gtk_toolbar_show_all (GtkWidget *widget)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
+ GtkToolbar *toolbar = GTK_TOOLBAR (widget);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *list;
for (list = priv->content; list != NULL; list = list->next)
gtk_widget_show (widget);
}
-static void
-gtk_toolbar_hide_all (GtkWidget *widget)
-{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
- GList *list;
-
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
-
- toolbar_content_hide_all (content);
- }
-
- gtk_widget_hide (widget);
-}
-
static void
gtk_toolbar_add (GtkContainer *container,
GtkWidget *widget)
{
- GtkToolbar *toolbar;
-
- g_return_if_fail (GTK_IS_TOOLBAR (container));
- g_return_if_fail (widget != NULL);
-
- toolbar = GTK_TOOLBAR (container);
-
- if (GTK_IS_TOOL_ITEM (widget))
- gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
- else
- gtk_toolbar_append_widget (toolbar, widget, NULL, NULL);
+ GtkToolbar *toolbar = GTK_TOOLBAR (container);
+
+ gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
}
static void
gtk_toolbar_remove (GtkContainer *container,
GtkWidget *widget)
{
- GtkToolbar *toolbar;
- GtkToolbarPrivate *priv;
+ GtkToolbar *toolbar = GTK_TOOLBAR (container);
+ GtkToolbarPrivate *priv = toolbar->priv;
ToolbarContent *content_to_remove;
GList *list;
-
- g_return_if_fail (GTK_IS_TOOLBAR (container));
- g_return_if_fail (GTK_IS_WIDGET (widget));
-
- toolbar = GTK_TOOLBAR (container);
- priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
+
content_to_remove = NULL;
for (list = priv->content; list != NULL; list = list->next)
{
static void
gtk_toolbar_forall (GtkContainer *container,
- gboolean include_internals,
- GtkCallback callback,
- gpointer callback_data)
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data)
{
GtkToolbar *toolbar = GTK_TOOLBAR (container);
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *list;
-
+
g_return_if_fail (callback != NULL);
-
+
list = priv->content;
while (list)
{
ToolbarContent *content = list->data;
GList *next = list->next;
-
+
if (include_internals || !toolbar_content_is_placeholder (content))
- {
- GtkWidget *child = toolbar_content_get_widget (content);
-
- if (child)
- (*callback) (child, callback_data);
- }
-
+ {
+ GtkWidget *child = toolbar_content_get_widget (content);
+
+ if (child)
+ callback (child, callback_data);
+ }
+
list = next;
}
-
- if (include_internals)
- (* callback) (priv->arrow_button, callback_data);
+
+ if (include_internals && priv->arrow_button)
+ callback (priv->arrow_button, callback_data);
}
static GType
static void
gtk_toolbar_reconfigured (GtkToolbar *toolbar)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *list;
list = priv->content;
gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
GtkOrientation orientation)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
- if (toolbar->orientation != orientation)
+ GtkToolbarPrivate *priv = toolbar->priv;
+
+ if (priv->orientation != orientation)
{
- toolbar->orientation = orientation;
+ priv->orientation = orientation;
if (orientation == GTK_ORIENTATION_HORIZONTAL)
gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
gtk_toolbar_reconfigured (toolbar);
+ _gtk_orientable_set_style_classes (GTK_ORIENTABLE (toolbar));
gtk_widget_queue_resize (GTK_WIDGET (toolbar));
g_object_notify (G_OBJECT (toolbar), "orientation");
}
gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
GtkToolbarStyle style)
{
- if (toolbar->style != style)
+ GtkToolbarPrivate *priv = toolbar->priv;
+
+ if (priv->style != style)
{
- toolbar->style = style;
-
+ priv->style = style;
+
gtk_toolbar_reconfigured (toolbar);
gtk_widget_queue_resize (GTK_WIDGET (toolbar));
gboolean *push_in,
gpointer user_data)
{
+ GtkAllocation allocation;
GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
GtkRequisition req;
GtkRequisition menu_req;
GdkRectangle monitor;
gint monitor_num;
GdkScreen *screen;
-
- gtk_widget_size_request (priv->arrow_button, &req);
- gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
-
+
+ gtk_widget_get_preferred_size (priv->arrow_button,
+ &req, NULL);
+ gtk_widget_get_preferred_size (GTK_WIDGET (menu),
+ &menu_req, NULL);
+
screen = gtk_widget_get_screen (GTK_WIDGET (menu));
- monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
+ monitor_num = gdk_screen_get_monitor_at_window (screen,
+ gtk_widget_get_window (priv->arrow_button));
if (monitor_num < 0)
monitor_num = 0;
- gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+ gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
+
+ gtk_widget_get_allocation (priv->arrow_button, &allocation);
- gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
- if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
+ gdk_window_get_origin (gtk_button_get_event_window (GTK_BUTTON (priv->arrow_button)), x, y);
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
- *x += priv->arrow_button->allocation.width - req.width;
+ *x += allocation.width - req.width;
else
*x += req.width - menu_req.width;
- if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
- *y += priv->arrow_button->allocation.height;
+ if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height)
+ *y += allocation.height;
else if ((*y - menu_req.height) >= monitor.y)
*y -= menu_req.height;
- else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
- *y += priv->arrow_button->allocation.height;
+ else if (monitor.y + monitor.height - (*y + allocation.height) > *y)
+ *y += allocation.height;
else
*y -= menu_req.height;
}
else
{
if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
- *x += priv->arrow_button->allocation.width;
+ *x += allocation.width;
else
*x -= menu_req.width;
if (*y + menu_req.height > monitor.y + monitor.height &&
- *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
- *y += priv->arrow_button->allocation.height - menu_req.height;
+ *y + allocation.height - monitor.y > monitor.y + monitor.height - *y)
+ *y += allocation.height - menu_req.height;
}
*push_in = FALSE;
show_menu (GtkToolbar *toolbar,
GdkEventButton *event)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv = toolbar->priv;
rebuild_menu (toolbar);
gtk_toolbar_arrow_button_clicked (GtkWidget *button,
GtkToolbar *toolbar)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
+ GtkToolbarPrivate *priv = toolbar->priv;
+
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
- (!priv->menu || !GTK_WIDGET_VISIBLE (priv->menu)))
+ (!priv->menu || !gtk_widget_get_visible (GTK_WIDGET (priv->menu))))
{
/* We only get here when the button is clicked with the keyboard,
* because mouse button presses result in the menu being shown so
gtk_toolbar_button_press (GtkWidget *toolbar,
GdkEventButton *event)
{
- if (event->button == 3)
+ GtkWidget *window;
+
+ if (gdk_event_triggers_context_menu ((GdkEvent *) event))
{
gboolean return_value;
-
+
g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
(int)event->x_root, (int)event->y_root, event->button,
&return_value);
-
+
return return_value;
}
-
+
+ if (event->type != GDK_BUTTON_PRESS)
+ return FALSE;
+
+ window = gtk_widget_get_toplevel (toolbar);
+
+ if (window)
+ {
+ gboolean window_drag = FALSE;
+
+ gtk_widget_style_get (toolbar,
+ "window-dragging", &window_drag,
+ NULL);
+
+ if (window_drag)
+ {
+ gtk_window_begin_move_drag (GTK_WINDOW (window),
+ event->button,
+ event->x_root,
+ event->y_root,
+ event->time);
+
+ return TRUE;
+ }
+ }
+
return FALSE;
}
g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
g_return_if_fail (GTK_IS_TOOL_ITEM (item));
- if (!gtk_toolbar_check_new_api (toolbar))
- return;
-
if (pos >= 0)
pos = logical_to_physical (toolbar, pos);
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
- g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
-
- if (!gtk_toolbar_check_new_api (toolbar))
- return -1;
-
- priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
+ g_return_val_if_fail (gtk_widget_get_parent (GTK_WIDGET (item)) == GTK_WIDGET (toolbar), -1);
+
+ priv = toolbar->priv;
+
n = 0;
for (list = priv->content; list != NULL; list = list->next)
{
return physical_to_logical (toolbar, n);
}
-/**
- * gtk_toolbar_set_orientation:
- * @toolbar: a #GtkToolbar.
- * @orientation: a new #GtkOrientation.
- *
- * Sets whether a toolbar should appear horizontally or vertically.
- **/
-void
-gtk_toolbar_set_orientation (GtkToolbar *toolbar,
- GtkOrientation orientation)
-{
- g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
-
- g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation);
-}
-
-/**
- * gtk_toolbar_get_orientation:
- * @toolbar: a #GtkToolbar
- *
- * Retrieves the current orientation of the toolbar. See
- * gtk_toolbar_set_orientation().
- *
- * Return value: the orientation
- **/
-GtkOrientation
-gtk_toolbar_get_orientation (GtkToolbar *toolbar)
-{
- g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL);
-
- return toolbar->orientation;
-}
-
/**
* gtk_toolbar_set_style:
* @toolbar: a #GtkToolbar.
gtk_toolbar_set_style (GtkToolbar *toolbar,
GtkToolbarStyle style)
{
+ GtkToolbarPrivate *priv;
+
g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
-
- toolbar->style_set = TRUE;
+
+ priv = toolbar->priv;
+
+ priv->style_set = TRUE;
g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
}
gtk_toolbar_get_style (GtkToolbar *toolbar)
{
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
-
- return toolbar->style;
+
+ return toolbar->priv->style;
}
/**
void
gtk_toolbar_unset_style (GtkToolbar *toolbar)
{
+ GtkToolbarPrivate *priv;
GtkToolbarStyle style;
g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
-
- if (toolbar->style_set)
+
+ priv = toolbar->priv;
+
+ if (priv->style_set)
{
GtkSettings *settings = toolbar_get_settings (toolbar);
NULL);
else
style = DEFAULT_TOOLBAR_STYLE;
-
- if (style != toolbar->style)
- g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
-
- toolbar->style_set = FALSE;
- }
-}
-
-/**
- * gtk_toolbar_set_tooltips:
- * @toolbar: a #GtkToolbar.
- * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them.
- *
- * Sets if the tooltips of a toolbar should be active or not.
- **/
-void
-gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
- gboolean enable)
-{
- g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
-
- if (enable)
- gtk_tooltips_enable (toolbar->tooltips);
- else
- gtk_tooltips_disable (toolbar->tooltips);
- g_object_notify (G_OBJECT (toolbar), "tooltips");
-}
+ if (style != priv->style)
+ g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
-/**
- * gtk_toolbar_get_tooltips:
- * @toolbar: a #GtkToolbar
- *
- * Retrieves whether tooltips are enabled. See
- * gtk_toolbar_set_tooltips().
- *
- * Return value: %TRUE if tooltips are enabled
- **/
-gboolean
-gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
-{
- g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
-
- return toolbar->tooltips->enabled;
+ priv->style_set = FALSE;
+ }
}
/**
gtk_toolbar_get_n_items (GtkToolbar *toolbar)
{
GtkToolbarPrivate *priv;
-
+
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
-
- if (!gtk_toolbar_check_new_api (toolbar))
- return -1;
-
- priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
+
+ priv = toolbar->priv;
+
return physical_to_logical (toolbar, g_list_length (priv->content));
}
*
* Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
* toolbar does not contain an @n<!-- -->'th item.
- *
- * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
- * isn't an @n<!-- -->'th item.
- *
+ *
+ * Return value: (transfer none): The @n<!-- -->'th #GtkToolItem on @toolbar,
+ * or %NULL if there isn't an @n<!-- -->'th item.
+ *
* Since: 2.4
**/
GtkToolItem *
gint n_items;
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
-
- if (!gtk_toolbar_check_new_api (toolbar))
- return NULL;
-
+
+ priv = toolbar->priv;
+
n_items = gtk_toolbar_get_n_items (toolbar);
if (n < 0 || n >= n_items)
return NULL;
-
- priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
+
content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
g_assert (content);
*
* Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
*
- * Return value: the current icon size for the icons on the toolbar.
+ * Return value: (type int): the current icon size for the icons on
+ * the toolbar.
**/
GtkIconSize
gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
{
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
-
- return toolbar->icon_size;
+
+ return toolbar->priv->icon_size;
}
/**
gboolean show_arrow)
{
GtkToolbarPrivate *priv;
-
+
g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
-
- priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+
+ priv = toolbar->priv;
+
show_arrow = show_arrow != FALSE;
if (priv->show_arrow != show_arrow)
gboolean
gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
{
- GtkToolbarPrivate *priv;
-
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
-
- if (!gtk_toolbar_check_new_api (toolbar))
- return FALSE;
-
- priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
- return priv->show_arrow;
+
+ return toolbar->priv->show_arrow;
}
/**
{
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
- if (!gtk_toolbar_check_new_api (toolbar))
- return -1;
-
return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
}
static void
-gtk_toolbar_finalize (GObject *object)
+gtk_toolbar_dispose (GObject *object)
{
- GList *list;
GtkToolbar *toolbar = GTK_TOOLBAR (object);
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
- if (toolbar->tooltips)
- g_object_unref (toolbar->tooltips);
-
+ GtkToolbarPrivate *priv = toolbar->priv;
+
if (priv->arrow_button)
- gtk_widget_unparent (priv->arrow_button);
+ {
+ gtk_widget_unparent (priv->arrow_button);
+ priv->arrow_button = NULL;
+ }
- for (list = priv->content; list != NULL; list = list->next)
+ if (priv->menu)
{
- ToolbarContent *content = list->data;
+ g_signal_handlers_disconnect_by_func (priv->menu,
+ menu_deactivated, toolbar);
+ gtk_widget_destroy (GTK_WIDGET (priv->menu));
+ priv->menu = NULL;
+ }
- toolbar_content_free (content);
+ if (priv->settings_connection > 0)
+ {
+ g_signal_handler_disconnect (priv->settings, priv->settings_connection);
+ priv->settings_connection = 0;
}
-
- g_list_free (priv->content);
- g_list_free (toolbar->children);
-
+
+ g_clear_object (&priv->settings);
+
+ G_OBJECT_CLASS (gtk_toolbar_parent_class)->dispose (object);
+}
+
+static void
+gtk_toolbar_finalize (GObject *object)
+{
+ GtkToolbar *toolbar = GTK_TOOLBAR (object);
+ GtkToolbarPrivate *priv = toolbar->priv;
+
+ g_list_free_full (priv->content, (GDestroyNotify)toolbar_content_free);
+
g_timer_destroy (priv->timer);
-
- if (priv->menu)
- gtk_widget_destroy (GTK_WIDGET (priv->menu));
-
+
if (priv->idle_id)
g_source_remove (priv->idle_id);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
}
/**
* gtk_toolbar_set_icon_size:
* @toolbar: A #GtkToolbar
- * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have.
+ * @icon_size: (type int): The #GtkIconSize that stock icons in the
+ * toolbar shall have.
*
* This function sets the size of stock icons in the toolbar. You
* can call it both before you add the icons and after they've been
gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
GtkIconSize icon_size)
{
+ GtkToolbarPrivate *priv;
+
g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
-
- if (!toolbar->icon_size_set)
+
+ priv = toolbar->priv;
+
+ if (!priv->icon_size_set)
{
- toolbar->icon_size_set = TRUE;
+ priv->icon_size_set = TRUE;
g_object_notify (G_OBJECT (toolbar), "icon-size-set");
}
- if (toolbar->icon_size == icon_size)
+ if (priv->icon_size == icon_size)
return;
-
- toolbar->icon_size = icon_size;
+
+ priv->icon_size = icon_size;
g_object_notify (G_OBJECT (toolbar), "icon-size");
gtk_toolbar_reconfigured (toolbar);
void
gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
{
+ GtkToolbarPrivate *priv;
GtkIconSize size;
-
+
g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
-
- if (toolbar->icon_size_set)
+
+ priv = toolbar->priv;
+
+ if (priv->icon_size_set)
{
GtkSettings *settings = toolbar_get_settings (toolbar);
}
else
size = DEFAULT_ICON_SIZE;
-
- if (size != toolbar->icon_size)
+
+ if (size != priv->icon_size)
{
gtk_toolbar_set_icon_size (toolbar, size);
g_object_notify (G_OBJECT (toolbar), "icon-size");
}
-
- toolbar->icon_size_set = FALSE;
+
+ priv->icon_size_set = FALSE;
g_object_notify (G_OBJECT (toolbar), "icon-size-set");
}
}
/*
- * Deprecated API
+ * ToolbarContent methods
*/
+typedef enum {
+ UNKNOWN,
+ YES,
+ NO
+} TriState;
-/**
- * gtk_toolbar_append_item:
- * @toolbar: a #GtkToolbar.
- * @text: give your toolbar button a label.
- * @tooltip_text: a string that appears when the user holds the mouse over this item.
- * @tooltip_private_text: use with #GtkTipsQuery.
- * @icon: a #GtkWidget that should be used as the button's icon.
- * @callback: the function to be executed when the button is pressed.
- * @user_data: a pointer to any data you wish to be passed to the callback.
- *
- * Inserts a new item into the toolbar. You must specify the position
- * in the toolbar where it will be inserted.
- *
- * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
- * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
- *
- * Return value: the new toolbar item as a #GtkWidget.
- **/
-GtkWidget *
-gtk_toolbar_append_item (GtkToolbar *toolbar,
- const char *text,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GtkWidget *icon,
- GtkSignalFunc callback,
- gpointer user_data)
+struct _ToolbarContent
{
- return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
- NULL, text,
- tooltip_text, tooltip_private_text,
- icon, callback, user_data,
- toolbar->num_children);
-}
+ ItemState state;
-/**
- * gtk_toolbar_prepend_item:
- * @toolbar: a #GtkToolbar.
- * @text: give your toolbar button a label.
- * @tooltip_text: a string that appears when the user holds the mouse over this item.
- * @tooltip_private_text: use with #GtkTipsQuery.
- * @icon: a #GtkWidget that should be used as the button's icon.
- * @callback: the function to be executed when the button is pressed.
- * @user_data: a pointer to any data you wish to be passed to the callback.
- *
- * Adds a new button to the beginning (top or left edges) of the given toolbar.
- *
- * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
- * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
- *
- * Return value: the new toolbar item as a #GtkWidget.
- **/
-GtkWidget *
-gtk_toolbar_prepend_item (GtkToolbar *toolbar,
- const char *text,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GtkWidget *icon,
- GtkSignalFunc callback,
- gpointer user_data)
-{
- return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
- NULL, text,
- tooltip_text, tooltip_private_text,
- icon, callback, user_data,
- 0);
-}
+ GtkToolItem *item;
+ GtkAllocation allocation;
+ GtkAllocation start_allocation;
+ GtkAllocation goal_allocation;
+ guint is_placeholder : 1;
+ guint disappearing : 1;
+ guint has_menu : 2;
+};
-/**
- * gtk_toolbar_insert_item:
- * @toolbar: a #GtkToolbar.
- * @text: give your toolbar button a label.
- * @tooltip_text: a string that appears when the user holds the mouse over this item.
- * @tooltip_private_text: use with #GtkTipsQuery.
- * @icon: a #GtkWidget that should be used as the button's icon.
- * @callback: the function to be executed when the button is pressed.
- * @user_data: a pointer to any data you wish to be passed to the callback.
- * @position: the number of widgets to insert this item after.
- *
- * Inserts a new item into the toolbar. You must specify the position in the
- * toolbar where it will be inserted.
- *
- * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
- * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
- *
- * Return value: the new toolbar item as a #GtkWidget.
- **/
-GtkWidget *
-gtk_toolbar_insert_item (GtkToolbar *toolbar,
- const char *text,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GtkWidget *icon,
- GtkSignalFunc callback,
- gpointer user_data,
- gint position)
-{
- return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
- NULL, text,
- tooltip_text, tooltip_private_text,
- icon, callback, user_data,
- position);
-}
+static void
+toolbar_item_visiblity_notify_cb (GObject *obj,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ GtkToolbar *toolbar = user_data;
-/**
- * gtk_toolbar_insert_stock:
- * @toolbar: A #GtkToolbar
- * @stock_id: The id of the stock item you want to insert
- * @tooltip_text: The text in the tooltip of the toolbar button
- * @tooltip_private_text: The private text of the tooltip
- * @callback: The callback called when the toolbar button is clicked.
- * @user_data: user data passed to callback
- * @position: The position the button shall be inserted at.
- * -1 means at the end.
- *
- * Inserts a stock item at the specified position of the toolbar. If
- * @stock_id is not a known stock item ID, it's inserted verbatim,
- * except that underscores used to mark mnemonics are removed.
- *
- * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
- * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
- *
- * Returns: the inserted widget
- */
-GtkWidget*
-gtk_toolbar_insert_stock (GtkToolbar *toolbar,
- const gchar *stock_id,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GtkSignalFunc callback,
- gpointer user_data,
- gint position)
-{
- return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
- NULL, stock_id,
- tooltip_text, tooltip_private_text,
- NULL, callback, user_data,
- position, TRUE);
+ gtk_toolbar_invalidate_order (toolbar);
}
-/**
- * gtk_toolbar_append_space:
- * @toolbar: a #GtkToolbar.
- *
- * Adds a new space to the end of the toolbar.
- **/
-void
-gtk_toolbar_append_space (GtkToolbar *toolbar)
+static ToolbarContent *
+toolbar_content_new_tool_item (GtkToolbar *toolbar,
+ GtkToolItem *item,
+ gboolean is_placeholder,
+ gint pos)
{
- gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
- NULL, NULL,
- NULL, NULL,
- NULL, NULL, NULL,
- toolbar->num_children);
+ GtkToolbarPrivate *priv = toolbar->priv;
+ ToolbarContent *content;
+
+ content = g_slice_new0 (ToolbarContent);
+
+ content->state = NOT_ALLOCATED;
+ content->item = item;
+ content->is_placeholder = is_placeholder;
+
+ priv->content = g_list_insert (priv->content, content, pos);
+
+ gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
+ gtk_toolbar_invalidate_order (toolbar);
+
+ g_signal_connect (content->item, "notify::visible",
+ G_CALLBACK (toolbar_item_visiblity_notify_cb), toolbar);
+
+ if (!is_placeholder)
+ {
+ priv->num_children++;
+
+ gtk_toolbar_stop_sliding (toolbar);
+ }
+
+ gtk_widget_queue_resize (GTK_WIDGET (toolbar));
+ priv->need_rebuild = TRUE;
+
+ return content;
}
-/**
- * gtk_toolbar_prepend_space:
- * @toolbar: a #GtkToolbar.
- *
- * Adds a new space to the beginning of the toolbar.
- **/
-void
-gtk_toolbar_prepend_space (GtkToolbar *toolbar)
+static void
+toolbar_content_remove (ToolbarContent *content,
+ GtkToolbar *toolbar)
{
- gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
- NULL, NULL,
- NULL, NULL,
- NULL, NULL, NULL,
- 0);
+ GtkToolbarPrivate *priv = toolbar->priv;
+
+ gtk_toolbar_invalidate_order (toolbar);
+ gtk_widget_unparent (GTK_WIDGET (content->item));
+
+ g_signal_handlers_disconnect_by_func (content->item,
+ toolbar_item_visiblity_notify_cb,
+ toolbar);
+
+ priv->content = g_list_remove (priv->content, content);
+
+ if (!toolbar_content_is_placeholder (content))
+ priv->num_children--;
+
+ gtk_widget_queue_resize (GTK_WIDGET (toolbar));
+ priv->need_rebuild = TRUE;
}
-/**
- * gtk_toolbar_insert_space:
- * @toolbar: a #GtkToolbar
- * @position: the number of widgets after which a space should be inserted.
- *
- * Inserts a new space in the toolbar at the specified position.
- **/
-void
-gtk_toolbar_insert_space (GtkToolbar *toolbar,
- gint position)
+static void
+toolbar_content_free (ToolbarContent *content)
{
- gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
- NULL, NULL,
- NULL, NULL,
- NULL, NULL, NULL,
- position);
+ g_slice_free (ToolbarContent, content);
}
-/**
- * gtk_toolbar_remove_space:
- * @toolbar: a #GtkToolbar.
- * @position: the index of the space to remove.
- *
- * Removes a space from the specified position.
- **/
-void
-gtk_toolbar_remove_space (GtkToolbar *toolbar,
- gint position)
-{
- GtkToolbarPrivate *priv;
- ToolbarContent *content;
-
- g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
-
- if (!gtk_toolbar_check_old_api (toolbar))
- return;
-
- priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
- content = g_list_nth_data (priv->content, position);
-
- if (!content)
- {
- g_warning ("Toolbar position %d doesn't exist", position);
- return;
- }
-
- if (!toolbar_content_is_separator (content))
- {
- g_warning ("Toolbar position %d is not a space", position);
- return;
- }
-
- toolbar_content_remove (content, toolbar);
- toolbar_content_free (content);
-}
-
-/**
- * gtk_toolbar_append_widget:
- * @toolbar: a #GtkToolbar.
- * @widget: a #GtkWidget to add to the toolbar.
- * @tooltip_text: the element's tooltip.
- * @tooltip_private_text: used for context-sensitive help about this toolbar element.
- *
- * Adds a widget to the end of the given toolbar.
- **/
-void
-gtk_toolbar_append_widget (GtkToolbar *toolbar,
- GtkWidget *widget,
- const gchar *tooltip_text,
- const gchar *tooltip_private_text)
-{
- gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
- widget, NULL,
- tooltip_text, tooltip_private_text,
- NULL, NULL, NULL,
- toolbar->num_children);
-}
-
-/**
- * gtk_toolbar_prepend_widget:
- * @toolbar: a #GtkToolbar.
- * @widget: a #GtkWidget to add to the toolbar.
- * @tooltip_text: the element's tooltip.
- * @tooltip_private_text: used for context-sensitive help about this toolbar element.
- *
- * Adds a widget to the beginning of the given toolbar.
- **/
-void
-gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
- GtkWidget *widget,
- const gchar *tooltip_text,
- const gchar *tooltip_private_text)
-{
- gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
- widget, NULL,
- tooltip_text, tooltip_private_text,
- NULL, NULL, NULL,
- 0);
-}
-
-/**
- * gtk_toolbar_insert_widget:
- * @toolbar: a #GtkToolbar.
- * @widget: a #GtkWidget to add to the toolbar.
- * @tooltip_text: the element's tooltip.
- * @tooltip_private_text: used for context-sensitive help about this toolbar element.
- * @position: the number of widgets to insert this widget after.
- *
- * Inserts a widget in the toolbar at the given position.
- **/
-void
-gtk_toolbar_insert_widget (GtkToolbar *toolbar,
- GtkWidget *widget,
- const char *tooltip_text,
- const char *tooltip_private_text,
- gint position)
-{
- gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
- widget, NULL,
- tooltip_text, tooltip_private_text,
- NULL, NULL, NULL,
- position);
-}
-
-/**
- * gtk_toolbar_append_element:
- * @toolbar: a #GtkToolbar.
- * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
- * @widget: a #GtkWidget, or %NULL.
- * @text: the element's label.
- * @tooltip_text: the element's tooltip.
- * @tooltip_private_text: used for context-sensitive help about this toolbar element.
- * @icon: a #GtkWidget that provides pictorial representation of the element's function.
- * @callback: the function to be executed when the button is pressed.
- * @user_data: any data you wish to pass to the callback.
- *
- * Adds a new element to the end of a toolbar.
- *
- * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
- * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
- * the radio group for the new element. In all other cases, @widget must
- * be %NULL.
- *
- * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
- * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
- *
- * Return value: the new toolbar element as a #GtkWidget.
- **/
-GtkWidget*
-gtk_toolbar_append_element (GtkToolbar *toolbar,
- GtkToolbarChildType type,
- GtkWidget *widget,
- const char *text,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GtkWidget *icon,
- GtkSignalFunc callback,
- gpointer user_data)
-{
- return gtk_toolbar_insert_element (toolbar, type, widget, text,
- tooltip_text, tooltip_private_text,
- icon, callback, user_data,
- toolbar->num_children);
-}
-
-/**
- * gtk_toolbar_prepend_element:
- * @toolbar: a #GtkToolbar.
- * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
- * @widget: a #GtkWidget, or %NULL
- * @text: the element's label.
- * @tooltip_text: the element's tooltip.
- * @tooltip_private_text: used for context-sensitive help about this toolbar element.
- * @icon: a #GtkWidget that provides pictorial representation of the element's function.
- * @callback: the function to be executed when the button is pressed.
- * @user_data: any data you wish to pass to the callback.
- *
- * Adds a new element to the beginning of a toolbar.
- *
- * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
- * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
- * the radio group for the new element. In all other cases, @widget must
- * be %NULL.
- *
- * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
- * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
- *
- * Return value: the new toolbar element as a #GtkWidget.
- **/
-GtkWidget *
-gtk_toolbar_prepend_element (GtkToolbar *toolbar,
- GtkToolbarChildType type,
- GtkWidget *widget,
- const char *text,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GtkWidget *icon,
- GtkSignalFunc callback,
- gpointer user_data)
-{
- return gtk_toolbar_insert_element (toolbar, type, widget, text,
- tooltip_text, tooltip_private_text,
- icon, callback, user_data, 0);
-}
-
-/**
- * gtk_toolbar_insert_element:
- * @toolbar: a #GtkToolbar.
- * @type: a value of type #GtkToolbarChildType that determines what @widget
- * will be.
- * @widget: a #GtkWidget, or %NULL.
- * @text: the element's label.
- * @tooltip_text: the element's tooltip.
- * @tooltip_private_text: used for context-sensitive help about this toolbar element.
- * @icon: a #GtkWidget that provides pictorial representation of the element's function.
- * @callback: the function to be executed when the button is pressed.
- * @user_data: any data you wish to pass to the callback.
- * @position: the number of widgets to insert this element after.
- *
- * Inserts a new element in the toolbar at the given position.
- *
- * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
- * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
- * the radio group for the new element. In all other cases, @widget must
- * be %NULL.
- *
- * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
- * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
- *
- * Return value: the new toolbar element as a #GtkWidget.
- **/
-GtkWidget *
-gtk_toolbar_insert_element (GtkToolbar *toolbar,
- GtkToolbarChildType type,
- GtkWidget *widget,
- const char *text,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GtkWidget *icon,
- GtkSignalFunc callback,
- gpointer user_data,
- gint position)
-{
- return internal_insert_element (toolbar, type, widget, text,
- tooltip_text, tooltip_private_text,
- icon, callback, user_data, position, FALSE);
-}
-
-static void
-set_child_packing_and_visibility(GtkToolbar *toolbar,
- GtkToolbarChild *child)
-{
- GtkWidget *box;
- gboolean expand;
-
- box = gtk_bin_get_child (GTK_BIN (child->widget));
-
- g_return_if_fail (GTK_IS_BOX (box));
-
- if (child->label)
- {
- expand = (toolbar->style != GTK_TOOLBAR_BOTH);
-
- gtk_box_set_child_packing (GTK_BOX (box), child->label,
- expand, expand, 0, GTK_PACK_END);
-
- if (toolbar->style != GTK_TOOLBAR_ICONS)
- gtk_widget_show (child->label);
- else
- gtk_widget_hide (child->label);
- }
-
- if (child->icon)
- {
- expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
-
- gtk_box_set_child_packing (GTK_BOX (box), child->icon,
- expand, expand, 0, GTK_PACK_END);
-
- if (toolbar->style != GTK_TOOLBAR_TEXT)
- gtk_widget_show (child->icon);
- else
- gtk_widget_hide (child->icon);
- }
-}
-
-static GtkWidget *
-internal_insert_element (GtkToolbar *toolbar,
- GtkToolbarChildType type,
- GtkWidget *widget,
- const char *text,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GtkWidget *icon,
- GtkSignalFunc callback,
- gpointer user_data,
- gint position,
- gboolean use_stock)
-{
- GtkWidget *box;
- ToolbarContent *content;
- GtkToolbarPrivate *priv;
- char *free_me = NULL;
- gboolean is_button = FALSE;
-
- GtkWidget *child_widget;
- GtkWidget *child_label;
- GtkWidget *child_icon;
-
- g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
- if (type == GTK_TOOLBAR_CHILD_WIDGET)
- g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
- else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
- g_return_val_if_fail (widget == NULL, NULL);
- if (GTK_IS_TOOL_ITEM (widget))
- g_warning (MIXED_API_WARNING);
-
- if (!gtk_toolbar_check_old_api (toolbar))
- return NULL;
-
- priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
- child_widget = NULL;
- child_label = NULL;
- child_icon = NULL;
-
- switch (type)
- {
- case GTK_TOOLBAR_CHILD_SPACE:
- break;
-
- case GTK_TOOLBAR_CHILD_WIDGET:
- child_widget = widget;
- break;
-
- case GTK_TOOLBAR_CHILD_BUTTON:
- case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
- case GTK_TOOLBAR_CHILD_RADIOBUTTON:
- is_button = TRUE;
- if (type == GTK_TOOLBAR_CHILD_BUTTON)
- {
- child_widget = gtk_button_new ();
- }
- else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
- {
- child_widget = gtk_toggle_button_new ();
- gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
- }
- else /* type == GTK_TOOLBAR_CHILD_RADIOBUTTON */
- {
- GSList *group = NULL;
-
- if (widget)
- group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
-
- child_widget = gtk_radio_button_new (group);
- gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
- }
-
- gtk_button_set_relief (GTK_BUTTON (child_widget), get_button_relief (toolbar));
- gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), FALSE);
-
- if (callback)
- {
- g_signal_connect (child_widget, "clicked",
- callback, user_data);
- }
-
- if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
- box = gtk_hbox_new (FALSE, 0);
- else
- box = gtk_vbox_new (FALSE, 0);
-
- gtk_container_add (GTK_CONTAINER (child_widget), box);
- gtk_widget_show (box);
-
- if (text && use_stock)
- {
- GtkStockItem stock_item;
- if (gtk_stock_lookup (text, &stock_item))
- {
- if (!icon)
- icon = gtk_image_new_from_stock (text, toolbar->icon_size);
-
- text = free_me = _gtk_toolbar_elide_underscores (stock_item.label);
- }
- }
-
- if (text)
- {
- child_label = gtk_label_new (text);
-
- gtk_container_add (GTK_CONTAINER (box), child_label);
- }
-
- if (icon)
- {
- child_icon = GTK_WIDGET (icon);
- gtk_container_add (GTK_CONTAINER (box), child_icon);
- }
-
- gtk_widget_show (child_widget);
- break;
-
- default:
- g_assert_not_reached ();
- break;
- }
-
- if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text)
- {
- gtk_tooltips_set_tip (toolbar->tooltips, child_widget,
- tooltip_text, tooltip_private_text);
- }
-
- content = toolbar_content_new_compatibility (toolbar, type, child_widget,
- child_icon, child_label, position);
-
- if (free_me)
- g_free (free_me);
-
- return child_widget;
-}
-
-/*
- * ToolbarContent methods
- */
-typedef enum {
- UNKNOWN,
- YES,
- NO,
-} TriState;
-
-struct _ToolbarContent
-{
- ContentType type;
- ItemState state;
-
- union
- {
- struct
- {
- GtkToolItem * item;
- GtkAllocation start_allocation;
- GtkAllocation goal_allocation;
- guint is_placeholder : 1;
- guint disappearing : 1;
- TriState has_menu : 2;
- } tool_item;
-
- struct
- {
- GtkToolbarChild child;
- GtkAllocation space_allocation;
- guint space_visible : 1;
- } compatibility;
- } u;
-};
-
-static ToolbarContent *
-toolbar_content_new_tool_item (GtkToolbar *toolbar,
- GtkToolItem *item,
- gboolean is_placeholder,
- gint pos)
-{
- ToolbarContent *content;
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
- content = g_new0 (ToolbarContent, 1);
-
- content->type = TOOL_ITEM;
- content->state = NOT_ALLOCATED;
- content->u.tool_item.item = item;
- content->u.tool_item.is_placeholder = is_placeholder;
-
- gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
-
- priv->content = g_list_insert (priv->content, content, pos);
-
- if (!is_placeholder)
- {
- toolbar->num_children++;
-
- gtk_toolbar_stop_sliding (toolbar);
- }
-
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
- priv->need_rebuild = TRUE;
-
- return content;
-}
-
-static ToolbarContent *
-toolbar_content_new_compatibility (GtkToolbar *toolbar,
- GtkToolbarChildType type,
- GtkWidget *widget,
- GtkWidget *icon,
- GtkWidget *label,
- gint pos)
-{
- ToolbarContent *content;
- GtkToolbarChild *child;
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
- content = g_new0 (ToolbarContent, 1);
-
- child = &(content->u.compatibility.child);
-
- content->type = COMPATIBILITY;
- child->type = type;
- child->widget = widget;
- child->icon = icon;
- child->label = label;
-
- if (type != GTK_TOOLBAR_CHILD_SPACE)
- {
- gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
- }
- else
- {
- content->u.compatibility.space_visible = TRUE;
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
- }
-
- if (type == GTK_TOOLBAR_CHILD_BUTTON ||
- type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
- type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
- {
- set_child_packing_and_visibility (toolbar, child);
- }
-
- priv->content = g_list_insert (priv->content, content, pos);
- toolbar->children = g_list_insert (toolbar->children, child, pos);
- priv->need_rebuild = TRUE;
-
- toolbar->num_children++;
-
- return content;
-}
-
-static void
-toolbar_content_remove (ToolbarContent *content,
- GtkToolbar *toolbar)
-{
- GtkToolbarChild *child;
- GtkToolbarPrivate *priv;
-
- priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
- switch (content->type)
- {
- case TOOL_ITEM:
- gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
- break;
-
- case COMPATIBILITY:
- child = &(content->u.compatibility.child);
-
- if (child->type != GTK_TOOLBAR_CHILD_SPACE)
- {
- g_object_ref (child->widget);
- gtk_widget_unparent (child->widget);
- gtk_widget_destroy (child->widget);
- g_object_unref (child->widget);
- }
-
- toolbar->children = g_list_remove (toolbar->children, child);
- break;
- }
-
- priv->content = g_list_remove (priv->content, content);
-
- if (!toolbar_content_is_placeholder (content))
- toolbar->num_children--;
-
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
- priv->need_rebuild = TRUE;
-}
-
-static void
-toolbar_content_free (ToolbarContent *content)
-{
- g_free (content);
-}
-
-static gint
-calculate_max_homogeneous_pixels (GtkWidget *widget)
+static gint
+calculate_max_homogeneous_pixels (GtkWidget *widget)
{
PangoContext *context;
PangoFontMetrics *metrics;
gint char_width;
context = gtk_widget_get_pango_context (widget);
+
metrics = pango_context_get_metrics (context,
- widget->style->font_desc,
+ pango_context_get_font_description (context),
pango_context_get_language (context));
char_width = pango_font_metrics_get_approximate_char_width (metrics);
pango_font_metrics_unref (metrics);
}
static void
-toolbar_content_expose (ToolbarContent *content,
- GtkContainer *container,
- GdkEventExpose *expose)
+toolbar_content_draw (ToolbarContent *content,
+ GtkContainer *container,
+ cairo_t *cr)
{
- GtkToolbar *toolbar = GTK_TOOLBAR (container);
- GtkToolbarChild *child;
- GtkWidget *widget = NULL; /* quiet gcc */
-
- switch (content->type)
- {
- case TOOL_ITEM:
- if (!content->u.tool_item.is_placeholder)
- widget = GTK_WIDGET (content->u.tool_item.item);
- break;
-
- case COMPATIBILITY:
- child = &(content->u.compatibility.child);
-
- if (child->type == GTK_TOOLBAR_CHILD_SPACE)
- {
- if (get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE &&
- content->u.compatibility.space_visible)
- {
- _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
- &expose->area,
- &content->u.compatibility.space_allocation);
- }
- return;
- }
-
- widget = child->widget;
- break;
- }
+ GtkWidget *widget;
+
+ if (content->is_placeholder)
+ return;
+ widget = GTK_WIDGET (content->item);
+
if (widget)
- gtk_container_propagate_expose (container, widget, expose);
+ gtk_container_propagate_draw (container, widget, cr);
}
static gboolean
toolbar_content_visible (ToolbarContent *content,
GtkToolbar *toolbar)
{
+ GtkToolbarPrivate *priv = toolbar->priv;
GtkToolItem *item;
-
- switch (content->type)
- {
- case TOOL_ITEM:
- item = content->u.tool_item.item;
-
- if (!GTK_WIDGET_VISIBLE (item))
- return FALSE;
-
- if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
- gtk_tool_item_get_visible_horizontal (item))
- {
- return TRUE;
- }
-
- if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
- gtk_tool_item_get_visible_vertical (item)))
- {
- return TRUE;
- }
-
- return FALSE;
- break;
+
+ item = content->item;
+
+ if (!gtk_widget_get_visible (GTK_WIDGET (item)))
+ return FALSE;
+
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
+ gtk_tool_item_get_visible_horizontal (item))
+ return TRUE;
+
+ if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
+ gtk_tool_item_get_visible_vertical (item))
+ return TRUE;
- case COMPATIBILITY:
- if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
- return GTK_WIDGET_VISIBLE (content->u.compatibility.child.widget);
- else
- return TRUE;
- break;
- }
-
- g_assert_not_reached ();
return FALSE;
}
GtkToolbar *toolbar,
GtkRequisition *requisition)
{
- gint space_size;
-
- switch (content->type)
+ gtk_widget_get_preferred_size (GTK_WIDGET (content->item),
+ requisition, NULL);
+ if (content->is_placeholder &&
+ content->disappearing)
{
- case TOOL_ITEM:
- gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
- requisition);
- if (content->u.tool_item.is_placeholder &&
- content->u.tool_item.disappearing)
- {
- requisition->width = 0;
- requisition->height = 0;
- }
- break;
-
- case COMPATIBILITY:
- space_size = get_space_size (toolbar);
-
- if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
- {
- gtk_widget_size_request (content->u.compatibility.child.widget,
- requisition);
- }
- else
- {
- if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- requisition->width = space_size;
- requisition->height = 0;
- }
- else
- {
- requisition->height = space_size;
- requisition->width = 0;
- }
- }
-
- break;
+ requisition->width = 0;
+ requisition->height = 0;
}
}
toolbar_content_is_homogeneous (ToolbarContent *content,
GtkToolbar *toolbar)
{
- gboolean result = FALSE; /* quiet gcc */
+ GtkToolbarPrivate *priv = toolbar->priv;
GtkRequisition requisition;
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ gboolean result;
if (priv->max_homogeneous_pixels < 0)
{
if (requisition.width > priv->max_homogeneous_pixels)
return FALSE;
-
- switch (content->type)
+
+ result = gtk_tool_item_get_homogeneous (content->item) &&
+ !GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
+
+ if (gtk_tool_item_get_is_important (content->item) &&
+ priv->style == GTK_TOOLBAR_BOTH_HORIZ &&
+ priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
- case TOOL_ITEM:
- result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
- !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
-
- if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
- toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
- toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- result = FALSE;
- }
- break;
-
- case COMPATIBILITY:
- if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
- content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
- content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
- {
- result = TRUE;
- }
- else
- {
- result = FALSE;
- }
- break;
+ result = FALSE;
}
-
+
return result;
}
static gboolean
toolbar_content_is_placeholder (ToolbarContent *content)
{
- if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
+ if (content->is_placeholder)
return TRUE;
return FALSE;
static gboolean
toolbar_content_disappearing (ToolbarContent *content)
{
- if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
+ if (content->disappearing)
return TRUE;
return FALSE;
static gboolean
toolbar_content_child_visible (ToolbarContent *content)
{
- switch (content->type)
- {
- case TOOL_ITEM:
- return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
- break;
-
- case COMPATIBILITY:
- if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
- {
- return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
- }
- else
- {
- return content->u.compatibility.space_visible;
- }
- break;
- }
-
- return FALSE; /* quiet gcc */
+ return gtk_widget_get_child_visible (GTK_WIDGET (content->item));
}
static void
toolbar_content_get_goal_allocation (ToolbarContent *content,
GtkAllocation *allocation)
{
- switch (content->type)
- {
- case TOOL_ITEM:
- *allocation = content->u.tool_item.goal_allocation;
- break;
-
- case COMPATIBILITY:
- /* Goal allocations are only relevant when we are
- * using the new API, so we should never get here
- */
- g_assert_not_reached ();
- break;
- }
+ *allocation = content->goal_allocation;
}
static void
toolbar_content_get_allocation (ToolbarContent *content,
GtkAllocation *allocation)
{
- GtkToolbarChild *child;
-
- switch (content->type)
- {
- case TOOL_ITEM:
- *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
- break;
-
- case COMPATIBILITY:
- child = &(content->u.compatibility.child);
-
- if (child->type == GTK_TOOLBAR_CHILD_SPACE)
- *allocation = content->u.compatibility.space_allocation;
- else
- *allocation = child->widget->allocation;
- break;
- }
+ *allocation = content->allocation;
}
static void
toolbar_content_set_start_allocation (ToolbarContent *content,
GtkAllocation *allocation)
{
- switch (content->type)
- {
- case TOOL_ITEM:
- content->u.tool_item.start_allocation = *allocation;
- break;
-
- case COMPATIBILITY:
- /* start_allocation is only relevant when using the new API */
- g_assert_not_reached ();
- break;
- }
+ content->start_allocation = *allocation;
}
static gboolean
toolbar_content_get_expand (ToolbarContent *content)
{
- if (content->type == TOOL_ITEM &&
- gtk_tool_item_get_expand (content->u.tool_item.item) &&
- !content->u.tool_item.disappearing)
- {
- return TRUE;
- }
-
+ if (!content->disappearing &&
+ gtk_tool_item_get_expand (content->item))
+ return TRUE;
+
return FALSE;
}
toolbar_content_set_goal_allocation (ToolbarContent *content,
GtkAllocation *allocation)
{
- switch (content->type)
- {
- case TOOL_ITEM:
- content->u.tool_item.goal_allocation = *allocation;
- break;
-
- case COMPATIBILITY:
- /* Only relevant when using new API */
- g_assert_not_reached ();
- break;
- }
+ content->goal_allocation = *allocation;
}
static void
toolbar_content_set_child_visible (ToolbarContent *content,
GtkToolbar *toolbar,
gboolean visible)
-{
- GtkToolbarChild *child;
-
- switch (content->type)
- {
- case TOOL_ITEM:
- gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
- visible);
- break;
-
- case COMPATIBILITY:
- child = &(content->u.compatibility.child);
-
- if (child->type != GTK_TOOLBAR_CHILD_SPACE)
- {
- gtk_widget_set_child_visible (child->widget, visible);
- }
- else
- {
- if (content->u.compatibility.space_visible != visible)
- {
- content->u.compatibility.space_visible = visible;
- gtk_widget_queue_draw (GTK_WIDGET (toolbar));
- }
- }
- break;
- }
+{
+ gtk_widget_set_child_visible (GTK_WIDGET (content->item),
+ visible);
}
static void
toolbar_content_get_start_allocation (ToolbarContent *content,
GtkAllocation *start_allocation)
{
- switch (content->type)
- {
- case TOOL_ITEM:
- *start_allocation = content->u.tool_item.start_allocation;
- break;
-
- case COMPATIBILITY:
- /* Only relevant for new API */
- g_assert_not_reached ();
- break;
- }
+ *start_allocation = content->start_allocation;
}
static void
toolbar_content_size_allocate (ToolbarContent *content,
GtkAllocation *allocation)
{
- switch (content->type)
- {
- case TOOL_ITEM:
- gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
- allocation);
- break;
-
- case COMPATIBILITY:
- if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
- {
- gtk_widget_size_allocate (content->u.compatibility.child.widget,
- allocation);
- }
- else
- {
- content->u.compatibility.space_allocation = *allocation;
- }
- break;
- }
+ content->allocation = *allocation;
+ gtk_widget_size_allocate (GTK_WIDGET (content->item),
+ allocation);
}
static void
static GtkWidget *
toolbar_content_get_widget (ToolbarContent *content)
{
- GtkToolbarChild *child;
-
- switch (content->type)
- {
- case TOOL_ITEM:
- return GTK_WIDGET (content->u.tool_item.item);
- break;
-
- case COMPATIBILITY:
- child = &(content->u.compatibility.child);
- if (child->type != GTK_TOOLBAR_CHILD_SPACE)
- return child->widget;
- else
- return NULL;
- break;
- }
-
- return NULL;
+ return GTK_WIDGET (content->item);
}
+
static void
toolbar_content_set_disappearing (ToolbarContent *content,
gboolean disappearing)
{
- switch (content->type)
- {
- case TOOL_ITEM:
- content->u.tool_item.disappearing = disappearing;
- break;
-
- case COMPATIBILITY:
- /* Only relevant for new API */
- g_assert_not_reached ();
- break;
- }
+ content->disappearing = disappearing;
}
static void
gint width,
gint height)
{
- switch (content->type)
- {
- case TOOL_ITEM:
- gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
- width, height);
- break;
-
- case COMPATIBILITY:
- /* Setting size requests only happens with sliding,
- * so not relevant here
- */
- g_assert_not_reached ();
- break;
- }
-}
-
-static void
-toolbar_child_reconfigure (GtkToolbar *toolbar,
- GtkToolbarChild *child)
-{
- GtkWidget *box;
- GtkImage *image;
- GtkToolbarStyle style;
- GtkIconSize icon_size;
- GtkReliefStyle relief;
- gchar *stock_id;
-
- style = gtk_toolbar_get_style (toolbar);
- icon_size = gtk_toolbar_get_icon_size (toolbar);
- relief = gtk_toolbar_get_relief_style (toolbar);
-
- /* style */
- if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
- child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
- child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
- {
- box = gtk_bin_get_child (GTK_BIN (child->widget));
-
- if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
- {
- GtkWidget *vbox;
-
- vbox = gtk_vbox_new (FALSE, 0);
-
- if (child->label)
- gtk_widget_reparent (child->label, vbox);
- if (child->icon)
- gtk_widget_reparent (child->icon, vbox);
-
- gtk_widget_destroy (box);
- gtk_container_add (GTK_CONTAINER (child->widget), vbox);
-
- gtk_widget_show (vbox);
- }
- else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
- {
- GtkWidget *hbox;
-
- hbox = gtk_hbox_new (FALSE, 0);
-
- if (child->label)
- gtk_widget_reparent (child->label, hbox);
- if (child->icon)
- gtk_widget_reparent (child->icon, hbox);
-
- gtk_widget_destroy (box);
- gtk_container_add (GTK_CONTAINER (child->widget), hbox);
-
- gtk_widget_show (hbox);
- }
-
- set_child_packing_and_visibility (toolbar, child);
- }
-
- /* icon size */
-
- if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
- child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
- child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
- GTK_IS_IMAGE (child->icon))
- {
- image = GTK_IMAGE (child->icon);
- if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
- {
- gtk_image_get_stock (image, &stock_id, NULL);
- stock_id = g_strdup (stock_id);
- gtk_image_set_from_stock (image,
- stock_id,
- icon_size);
- g_free (stock_id);
- }
- }
-
- /* relief */
- if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
- child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
- child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
- {
- gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
- }
+ gtk_widget_set_size_request (GTK_WIDGET (content->item),
+ width, height);
}
static void
toolbar_content_toolbar_reconfigured (ToolbarContent *content,
GtkToolbar *toolbar)
{
- switch (content->type)
- {
- case TOOL_ITEM:
- _gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
- break;
-
- case COMPATIBILITY:
- toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
- break;
- }
+ gtk_tool_item_toolbar_reconfigured (content->item);
}
static GtkWidget *
toolbar_content_retrieve_menu_item (ToolbarContent *content)
{
- if (content->type == TOOL_ITEM)
- return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
-
- /* FIXME - we might actually be able to do something meaningful here */
- return NULL;
+ return gtk_tool_item_retrieve_proxy_menu_item (content->item);
}
static gboolean
toolbar_content_has_proxy_menu_item (ToolbarContent *content)
{
- if (content->type == TOOL_ITEM)
- {
- GtkWidget *menu_item;
+ GtkWidget *menu_item;
- if (content->u.tool_item.has_menu == YES)
- return TRUE;
- else if (content->u.tool_item.has_menu == NO)
- return FALSE;
+ if (content->has_menu == YES)
+ return TRUE;
+ else if (content->has_menu == NO)
+ return FALSE;
- menu_item = toolbar_content_retrieve_menu_item (content);
+ menu_item = toolbar_content_retrieve_menu_item (content);
- content->u.tool_item.has_menu = menu_item? YES : NO;
-
- return menu_item != NULL;
- }
- else
- {
- return FALSE;
- }
+ content->has_menu = menu_item? YES : NO;
+
+ return menu_item != NULL;
}
static void
toolbar_content_set_unknown_menu_status (ToolbarContent *content)
{
- if (content->type == TOOL_ITEM)
- content->u.tool_item.has_menu = UNKNOWN;
+ content->has_menu = UNKNOWN;
}
static gboolean
toolbar_content_is_separator (ToolbarContent *content)
{
- GtkToolbarChild *child;
-
- switch (content->type)
- {
- case TOOL_ITEM:
- return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
- break;
-
- case COMPATIBILITY:
- child = &(content->u.compatibility.child);
- return (child->type == GTK_TOOLBAR_CHILD_SPACE);
- break;
- }
-
- return FALSE;
+ return GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
}
static void
toolbar_content_set_expand (ToolbarContent *content,
- gboolean expand)
-{
- if (content->type == TOOL_ITEM)
- gtk_tool_item_set_expand (content->u.tool_item.item, expand);
-}
-
-static gboolean
-ignore_show_and_hide_all (ToolbarContent *content)
+ gboolean expand)
{
- if (content->type == COMPATIBILITY)
- {
- GtkToolbarChildType type = content->u.compatibility.child.type;
-
- if (type == GTK_TOOLBAR_CHILD_BUTTON ||
- type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
- type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
- {
- return TRUE;
- }
- }
-
- return FALSE;
+ gtk_tool_item_set_expand (content->item, expand);
}
static void
{
GtkWidget *widget;
- if (ignore_show_and_hide_all (content))
- return;
-
widget = toolbar_content_get_widget (content);
if (widget)
gtk_widget_show_all (widget);
}
-static void
-toolbar_content_hide_all (ToolbarContent *content)
-{
- GtkWidget *widget;
-
- if (ignore_show_and_hide_all (content))
- return;
-
- widget = toolbar_content_get_widget (content);
- if (widget)
- gtk_widget_hide_all (widget);
-}
-
/*
* Getters
*/
-static gint
-get_space_size (GtkToolbar *toolbar)
-{
- gint space_size = DEFAULT_SPACE_SIZE;
-
- if (toolbar)
- {
- gtk_widget_style_get (GTK_WIDGET (toolbar),
- "space-size", &space_size,
- NULL);
- }
-
- return space_size;
-}
-
-static GtkToolbarSpaceStyle
-get_space_style (GtkToolbar *toolbar)
-{
- GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
-
- if (toolbar)
- {
- gtk_widget_style_get (GTK_WIDGET (toolbar),
- "space-style", &space_style,
- NULL);
- }
-
- return space_style;
-}
-
static GtkReliefStyle
get_button_relief (GtkToolbar *toolbar)
{
GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
-
- gtk_widget_ensure_style (GTK_WIDGET (toolbar));
-
+
gtk_widget_style_get (GTK_WIDGET (toolbar),
"button-relief", &button_relief,
NULL);
}
static gint
-get_internal_padding (GtkToolbar *toolbar)
+get_max_child_expand (GtkToolbar *toolbar)
{
- gint ipadding = 0;
-
- gtk_widget_style_get (GTK_WIDGET (toolbar),
- "internal-padding", &ipadding,
- NULL);
-
- return ipadding;
-}
+ gint mexpand = G_MAXINT;
-static GtkShadowType
-get_shadow_type (GtkToolbar *toolbar)
-{
- GtkShadowType shadow_type;
-
gtk_widget_style_get (GTK_WIDGET (toolbar),
- "shadow-type", &shadow_type,
- NULL);
-
- return shadow_type;
-}
-
-/*
- * API checks
- */
-static gboolean
-gtk_toolbar_check_old_api (GtkToolbar *toolbar)
-{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
- if (priv->api_mode == NEW_API)
- {
- g_warning (MIXED_API_WARNING);
- return FALSE;
- }
-
- priv->api_mode = OLD_API;
- return TRUE;
-}
-
-static gboolean
-gtk_toolbar_check_new_api (GtkToolbar *toolbar)
-{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
- if (priv->api_mode == OLD_API)
- {
- g_warning (MIXED_API_WARNING);
- return FALSE;
- }
-
- priv->api_mode = NEW_API;
- return TRUE;
+ "max-child-expand", &mexpand,
+ NULL);
+ return mexpand;
}
/* GTK+ internal methods */
}
void
-_gtk_toolbar_paint_space_line (GtkWidget *widget,
- GtkToolbar *toolbar,
- GdkRectangle *area,
- GtkAllocation *allocation)
+_gtk_toolbar_paint_space_line (GtkWidget *widget,
+ GtkToolbar *toolbar,
+ cairo_t *cr)
{
- const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
- const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
-
- GtkToolbarSpaceStyle space_style;
GtkOrientation orientation;
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkBorder padding;
+ gint width, height;
+ const gdouble start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
+ const gdouble end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
g_return_if_fail (GTK_IS_WIDGET (widget));
-
- space_style = toolbar? get_space_style (toolbar) : DEFAULT_SPACE_STYLE;
- orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
+
+ orientation = toolbar ? toolbar->priv->orientation : GTK_ORIENTATION_HORIZONTAL;
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+ width = gtk_widget_get_allocated_width (widget);
+ height = gtk_widget_get_allocated_height (widget);
+ gtk_style_context_get_padding (context, state, &padding);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
- gtk_paint_vline (widget->style, widget->window,
- GTK_WIDGET_STATE (widget), area, widget,
- "toolbar",
- allocation->y + allocation->height * start_fraction,
- allocation->y + allocation->height * end_fraction,
- allocation->x + (allocation->width - widget->style->xthickness) / 2);
+ gboolean wide_separators;
+ gint separator_width;
+
+ gtk_widget_style_get (widget,
+ "wide-separators", &wide_separators,
+ "separator-width", &separator_width,
+ NULL);
+
+ if (wide_separators)
+ gtk_render_frame (context, cr,
+ (width - separator_width) / 2,
+ height * start_fraction,
+ separator_width,
+ height * (end_fraction - start_fraction));
+ else
+ gtk_render_line (context, cr,
+ (width - padding.left) / 2,
+ height * start_fraction,
+ (width - padding.left) / 2,
+ height * end_fraction);
}
else
{
- gtk_paint_hline (widget->style, widget->window,
- GTK_WIDGET_STATE (widget), area, widget,
- "toolbar",
- allocation->x + allocation->width * start_fraction,
- allocation->x + allocation->width * end_fraction,
- allocation->y + (allocation->height - widget->style->ythickness) / 2);
+ gboolean wide_separators;
+ gint separator_height;
+
+ gtk_widget_style_get (widget,
+ "wide-separators", &wide_separators,
+ "separator-height", &separator_height,
+ NULL);
+
+ if (wide_separators)
+ gtk_render_frame (context, cr,
+ width * start_fraction,
+ (height - separator_height) / 2,
+ width * (end_fraction - start_fraction),
+ separator_height);
+ else
+ gtk_render_line (context, cr,
+ width * start_fraction,
+ (height - padding.top) / 2,
+ width * end_fraction,
+ (height - padding.top) / 2);
}
}
_gtk_toolbar_elide_underscores (const gchar *original)
{
gchar *q, *result;
- const gchar *p;
+ const gchar *p, *end;
+ gsize len;
gboolean last_underscore;
if (!original)
return NULL;
- q = result = g_malloc (strlen (original) + 1);
+ len = strlen (original);
+ q = result = g_malloc (len + 1);
last_underscore = FALSE;
- for (p = original; *p; p++)
+ end = original + len;
+ for (p = original; p < end; p++)
{
if (!last_underscore && *p == '_')
last_underscore = TRUE;
else
{
last_underscore = FALSE;
- *q++ = *p;
+ if (original + 2 <= p && p + 1 <= end &&
+ p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
+ {
+ q--;
+ *q = '\0';
+ p++;
+ }
+ else
+ *q++ = *p;
}
}
+
+ if (last_underscore)
+ *q++ = '_';
*q = '\0';
return result;
}
-void
-_gtk_toolbar_rebuild_menu (GtkToolbar *toolbar)
+static GtkIconSize
+toolbar_get_icon_size (GtkToolShell *shell)
+{
+ GtkToolbar *toolbar = GTK_TOOLBAR (shell);
+ GtkToolbarPrivate *priv = toolbar->priv;
+
+ return priv->icon_size;
+}
+
+static GtkOrientation
+toolbar_get_orientation (GtkToolShell *shell)
+{
+ GtkToolbar *toolbar = GTK_TOOLBAR (shell);
+ GtkToolbarPrivate *priv = toolbar->priv;
+
+ return priv->orientation;
+}
+
+static GtkToolbarStyle
+toolbar_get_style (GtkToolShell *shell)
+{
+ GtkToolbar *toolbar = GTK_TOOLBAR (shell);
+ GtkToolbarPrivate *priv = toolbar->priv;
+
+ return priv->style;
+}
+
+static GtkReliefStyle
+toolbar_get_relief_style (GtkToolShell *shell)
{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ return get_button_relief (GTK_TOOLBAR (shell));
+}
+
+static void
+toolbar_rebuild_menu (GtkToolShell *shell)
+{
+ GtkToolbar *toolbar = GTK_TOOLBAR (shell);
+ GtkToolbarPrivate *priv = toolbar->priv;
GList *list;
priv->need_rebuild = TRUE;
toolbar_content_set_unknown_menu_status (content);
}
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
+ gtk_widget_queue_resize (GTK_WIDGET (shell));
+}
+
+typedef struct _CountingData CountingData;
+struct _CountingData {
+ GtkWidget *widget;
+ gboolean found;
+ guint before;
+ guint after;
+};
+
+static void
+count_widget_position (GtkWidget *widget,
+ gpointer data)
+{
+ CountingData *count = data;
+
+ if (!gtk_widget_get_visible (widget))
+ return;
+
+ if (count->widget == widget)
+ count->found = TRUE;
+ else if (count->found)
+ count->after++;
+ else
+ count->before++;
+}
+
+static guint
+gtk_toolbar_get_visible_position (GtkToolbar *toolbar,
+ GtkWidget *child)
+{
+ CountingData count = { child, FALSE, 0, 0 };
+
+ if (child == (GtkWidget*)toolbar->priv->highlight_tool_item)
+ return 0;
+
+ /* foreach iterates in visible order */
+ gtk_container_forall (GTK_CONTAINER (toolbar),
+ count_widget_position,
+ &count);
+
+ g_assert (count.found);
+
+ if (toolbar->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
+ gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
+ return count.after;
+
+ return count.before;
+}
+
+static void
+add_widget_to_path (gpointer data,
+ gpointer user_data)
+{
+ GtkWidget *widget = data;
+ GtkWidgetPath *path = user_data;
+
+ if (gtk_widget_get_visible (widget))
+ gtk_widget_path_append_for_widget (path, widget);
+}
+
+static GtkWidgetPath *
+gtk_toolbar_get_path_for_child (GtkContainer *container,
+ GtkWidget *child)
+{
+ GtkWidgetPath *path;
+ GtkToolbar *toolbar;
+ GtkToolbarPrivate *priv;
+ GtkWidgetPath *sibling_path;
+ gint vis_index;
+ GList *children;
+
+ toolbar = GTK_TOOLBAR (container);
+ priv = toolbar->priv;
+
+ /* build a path for all the visible children;
+ * get_children works in visible order
+ */
+ sibling_path = gtk_widget_path_new ();
+ children = _gtk_container_get_all_children (container);
+
+ if (priv->orientation != GTK_ORIENTATION_HORIZONTAL ||
+ gtk_widget_get_direction (GTK_WIDGET (toolbar)) != GTK_TEXT_DIR_RTL)
+ children = g_list_reverse (children);
+
+ g_list_foreach (children, add_widget_to_path, sibling_path);
+ g_list_free (children);
+
+ path = _gtk_widget_create_path (GTK_WIDGET (container));
+ if (gtk_widget_get_visible (child))
+ {
+ vis_index = gtk_toolbar_get_visible_position (toolbar, child);
+
+ if (vis_index < gtk_widget_path_length (sibling_path))
+ gtk_widget_path_append_with_siblings (path,
+ sibling_path,
+ vis_index);
+ else
+ gtk_widget_path_append_for_widget (path, child);
+ }
+ else
+ gtk_widget_path_append_for_widget (path, child);
+
+ gtk_widget_path_unref (sibling_path);
+ return path;
+}
+
+static void
+gtk_toolbar_invalidate_order_foreach (GtkWidget *widget)
+{
+ _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_POSITION | GTK_CSS_CHANGE_SIBLING_POSITION);
+}
+
+static void
+gtk_toolbar_invalidate_order (GtkToolbar *toolbar)
+{
+ gtk_container_forall (GTK_CONTAINER (toolbar),
+ (GtkCallback) gtk_toolbar_invalidate_order_foreach,
+ NULL);
+}
+
+static void
+gtk_toolbar_direction_changed (GtkWidget *widget,
+ GtkTextDirection previous_direction)
+{
+ GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->direction_changed (widget, previous_direction);
+
+ gtk_toolbar_invalidate_order (GTK_TOOLBAR (widget));
}
-#define __GTK_TOOLBAR_C__
-#include "gtkaliasdef.c"