#include "gtkseparatortoolitem.h"
#include "gtkmenu.h"
#include "gtkradiobutton.h"
-#include "gtktoolbar.h"
#include "gtkbindings.h"
#include <gdk/gdkkeysyms.h>
#include "gtkmarshalers.h"
#include "gtkvbox.h"
#include "gtkimage.h"
#include "gtkseparatormenuitem.h"
+#include "gtkalias.h"
+#include <math.h>
typedef struct _ToolbarContent ToolbarContent;
-#define DEFAULT_IPADDING 0
+#define DEFAULT_IPADDING 0
#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
* pango_font_get_estimated_char_width().
*/
-#define SLIDE_SPEED 600 /* How fast the items slide, in pixels per second */
+#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"
+
/* Properties */
enum {
PROP_0,
PROP_ORIENTATION,
PROP_TOOLBAR_STYLE,
- PROP_SHOW_ARROW
+ PROP_SHOW_ARROW,
+ PROP_TOOLTIPS,
+ PROP_ICON_SIZE,
+ PROP_ICON_SIZE_SET
};
/* Child properties */
NOT_ALLOCATED,
NORMAL,
HIDDEN,
- OVERFLOWN,
+ OVERFLOWN
} ItemState;
struct _GtkToolbarPrivate
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 */
+
+ gulong settings_connection;
+
+ guint show_arrow : 1;
+ guint need_sync : 1;
+ guint is_sliding : 1;
+ guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
+ guint animation : 1;
};
-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,
static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
static gint get_internal_padding (GtkToolbar *toolbar);
+static gint get_max_child_expand (GtkToolbar *toolbar);
static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
static gint get_space_size (GtkToolbar *toolbar);
static GtkToolbarSpaceStyle get_space_style (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 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 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,
- "GtkToolbar",
- &type_info, 0);
- }
-
- return type;
-}
+G_DEFINE_TYPE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER)
static void
add_arrow_bindings (GtkBindingSet *binding_set,
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;
* Emitted when the orientation of the toolbar changes.
*/
toolbar_signals[ORIENTATION_CHANGED] =
- g_signal_new ("orientation-changed",
+ g_signal_new (I_("orientation-changed"),
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
* Emitted when the style of the toolbar changes.
*/
toolbar_signals[STYLE_CHANGED] =
- g_signal_new ("style-changed",
+ g_signal_new (I_("style-changed"),
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
* Return value: return %TRUE if the signal was handled, %FALSE if not
*/
toolbar_signals[POPUP_CONTEXT_MENU] =
- g_signal_new ("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),
* Return value: %TRUE if the signal was handled, %FALSE if not
*/
toolbar_signals[MOVE_FOCUS] =
- _gtk_binding_signal_new ("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),
* Return value: %TRUE if the signal was handled, %FALSE if not
*/
toolbar_signals[FOCUS_HOME_OR_END] =
- _gtk_binding_signal_new ("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),
P_("The orientation of the toolbar"),
GTK_TYPE_ORIENTATION,
GTK_ORIENTATION_HORIZONTAL,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_TOOLBAR_STYLE,
- g_param_spec_enum ("toolbar_style",
+ g_param_spec_enum ("toolbar-style",
P_("Toolbar Style"),
P_("How to draw the toolbar"),
GTK_TYPE_TOOLBAR_STYLE,
GTK_TOOLBAR_ICONS,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_SHOW_ARROW,
- g_param_spec_boolean ("show_arrow",
+ g_param_spec_boolean ("show-arrow",
P_("Show Arrow"),
P_("If an arrow should be shown if the toolbar doesn't fit"),
TRUE,
- G_PARAM_READWRITE));
+ 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:
+ *
+ * The size of the icons in a toolbar is normally determined by
+ * the toolbar-icon-size setting. When this property is set, it
+ * overrides the setting.
+ *
+ * This should only be used for special-purpose toolbars, normal
+ * application toolbars should respect the user preferences for the
+ * size of icons.
+ *
+ * Since: 2.10
+ */
+ 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));
+
+ /**
+ * GtkToolbar:icon-size-set:
+ *
+ * Is %TRUE if the icon-size property has been set.
+ *
+ * Since: 2.10
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_ICON_SIZE_SET,
+ g_param_spec_boolean ("icon-size-set",
+ P_("Icon size set"),
+ P_("Whether the icon-size property has been set"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
/* child properties */
gtk_container_class_install_child_property (container_class,
CHILD_PROP_EXPAND,
P_("Expand"),
P_("Whether the item should receive extra space when the toolbar grows"),
TRUE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
gtk_container_class_install_child_property (container_class,
CHILD_PROP_HOMOGENEOUS,
P_("Homogeneous"),
P_("Whether the item should be the same size as other homogeneous items"),
TRUE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
/* style properties */
gtk_widget_class_install_style_property (widget_class,
- g_param_spec_int ("space_size",
+ g_param_spec_int ("space-size",
P_("Spacer size"),
P_("Size of spacers"),
0,
G_MAXINT,
DEFAULT_SPACE_SIZE,
- G_PARAM_READABLE));
+ GTK_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
- g_param_spec_int ("internal_padding",
+ 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,
- G_PARAM_READABLE));
-
+ GTK_PARAM_READABLE));
+
gtk_widget_class_install_style_property (widget_class,
- g_param_spec_enum ("space_style",
+ 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"),
P_("Whether spacers are vertical lines or just blank"),
GTK_TYPE_TOOLBAR_SPACE_STYLE,
DEFAULT_SPACE_STYLE,
- G_PARAM_READABLE));
+ GTK_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
- g_param_spec_enum ("button_relief",
+ g_param_spec_enum ("button-relief",
P_("Button relief"),
P_("Type of bevel around toolbar buttons"),
GTK_TYPE_RELIEF_STYLE,
GTK_RELIEF_NONE,
- G_PARAM_READABLE));
+ GTK_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
- g_param_spec_enum ("shadow_type",
+ g_param_spec_enum ("shadow-type",
P_("Shadow type"),
P_("Style of bevel around the toolbar"),
GTK_TYPE_SHADOW_TYPE,
GTK_SHADOW_OUT,
- G_PARAM_READABLE));
+ 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,
- G_PARAM_READWRITE));
+ 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,
- G_PARAM_READWRITE));
-
+ GTK_PARAM_READWRITE));
+
binding_set = gtk_binding_set_by_class (klass);
add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
toolbar->style = DEFAULT_TOOLBAR_STYLE;
toolbar->icon_size = DEFAULT_ICON_SIZE;
+ priv->animation = DEFAULT_ANIMATION_STATE;
toolbar->tooltips = gtk_tooltips_new ();
- g_object_ref (toolbar->tooltips);
- gtk_object_sink (GTK_OBJECT (toolbar->tooltips));
+ g_object_ref_sink (toolbar->tooltips);
priv->arrow_button = gtk_toggle_button_new ();
g_signal_connect (priv->arrow_button, "button_press_event",
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));
+ break;
+ case PROP_ICON_SIZE_SET:
+ if (g_value_get_boolean (value))
+ toolbar->icon_size_set = TRUE;
+ else
+ gtk_toolbar_unset_icon_size (toolbar);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
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));
+ break;
+ case PROP_ICON_SIZE_SET:
+ g_value_set_boolean (value, toolbar->icon_size_set);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
{
GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
- GTK_WIDGET_CLASS (parent_class)->map (widget);
+ GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
if (priv->event_window)
gdk_window_show_unraised (priv->event_window);
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
priv->event_window = NULL;
}
- if (GTK_WIDGET_CLASS (parent_class)->unrealize)
- (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+ if (GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize)
+ (* GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize) (widget);
}
static gint
}
static gint
-position (gint from, gint to, gdouble elapsed)
+position (GtkToolbar *toolbar,
+ gint from,
+ gint to,
+ gdouble elapsed)
{
+ gint n_pixels;
+
+ if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
+ return to;
+
+ if (elapsed <= ACCEL_THRESHOLD)
+ {
+ n_pixels = SLIDE_SPEED * elapsed;
+ }
+ else
+ {
+ /* The formula is a second degree polynomial in
+ * @elapsed that has the line SLIDE_SPEED * @elapsed
+ * as tangent for @elapsed == ACCEL_THRESHOLD.
+ * This makes @n_pixels a smooth function of elapsed time.
+ */
+ n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
+ SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
+ }
+
if (to > from)
- return MIN (from + SLIDE_SPEED * elapsed, to);
+ return MIN (from + n_pixels, to);
else
- return MAX (from - SLIDE_SPEED * elapsed, to);
+ return MAX (from - n_pixels, to);
}
static void
{
GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
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
GtkToolbarPrivate *priv;
GList *list;
- GDK_THREADS_ENTER ();
-
priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
if (priv->need_sync)
priv->is_sliding = FALSE;
priv->idle_id = 0;
- GDK_THREADS_LEAVE();
return FALSE;
}
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);
rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
}
/* This resize will run before the first idle handler. This
- * will make sure that items get the right goal allocatiuon
+ * will make sure that items get the right goal allocation
* so that the idle handler will not immediately return
* FALSE
*/
GtkRequisition arrow_requisition;
gboolean overflowing;
gboolean size_changed;
- gdouble elapsed;
GtkAllocation item_area;
size_changed = FALSE;
else
size = available_size;
- /* calculate widths of items */
+ /* calculate widths and states of items */
overflowing = FALSE;
for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
{
if (need_arrow)
{
arrow_allocation.width = arrow_size;
- arrow_allocation.height = short_size;
+ arrow_allocation.height = MAX (short_size, 1);
}
/* expand expandable items */
*/
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;
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;
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--;
}
}
- elapsed = g_timer_elapsed (priv->timer, NULL);
for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
{
ToolbarContent *content = list->data;
new_states[i] == NORMAL)
{
GtkAllocation alloc;
- GtkAllocation start_allocation;
+ GtkAllocation start_allocation = { 0, };
GtkAllocation goal_allocation;
if (priv->is_sliding)
alloc = allocations[i];
}
- if (alloc.width == 0 || alloc.height == 0)
+ if (alloc.width <= 0 || alloc.height <= 0)
{
toolbar_content_set_child_visible (content, toolbar, FALSE);
}
return result;
}
+static GtkSettings *
+toolbar_get_settings (GtkToolbar *toolbar)
+{
+ GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ return priv->settings;
+}
+
static void
style_change_notify (GtkToolbar *toolbar)
{
if (!toolbar->style_set)
{
/* pretend it was set, then unset, thus reverting to new default */
- toolbar->style_set = TRUE;
+ toolbar->style_set = TRUE;
gtk_toolbar_unset_style (toolbar);
}
}
static void
icon_size_change_notify (GtkToolbar *toolbar)
-{
+{
if (!toolbar->icon_size_set)
{
/* pretend it was set, then unset, thus reverting to new default */
- toolbar->icon_size_set = TRUE;
+ toolbar->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 = GTK_TOOLBAR_GET_PRIVATE (toolbar);
- return priv->settings;
+ 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)
+{
+ 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
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);
+
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
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;
gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
&requisition);
+ toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
restart_sliding = FALSE;
toolbar_content_size_request (content, toolbar, &old_requisition);
gtk_toolbar_reconfigured (toolbar);
gtk_widget_queue_resize (GTK_WIDGET (toolbar));
- g_object_notify (G_OBJECT (toolbar), "toolbar_style");
+ g_object_notify (G_OBJECT (toolbar), "toolbar-style");
}
}
GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
GtkRequisition req;
GtkRequisition menu_req;
+ GdkRectangle monitor;
+ gint monitor_num;
+ GdkScreen *screen;
- gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
gtk_widget_size_request (priv->arrow_button, &req);
gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
+ screen = gtk_widget_get_screen (GTK_WIDGET (menu));
+ monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
+ if (monitor_num < 0)
+ monitor_num = 0;
+ gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+
+ gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
{
- *y += priv->arrow_button->allocation.height;
if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
*x += priv->arrow_button->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;
+ 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
+ *y -= menu_req.height;
}
else
{
*x += priv->arrow_button->allocation.width;
else
*x -= menu_req.width;
- *y += priv->arrow_button->allocation.height - req.height;
+
+ 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;
}
-
- *push_in = TRUE;
+
+ *push_in = FALSE;
}
static void
gtk_tooltips_enable (toolbar->tooltips);
else
gtk_tooltips_disable (toolbar->tooltips);
+
+ g_object_notify (G_OBJECT (toolbar), "tooltips");
}
/**
* @toolbar: a #GtkToolbar
* @n: A position on the toolbar
*
- * Returns the @n<!-- -->'s item on @toolbar, or %NULL if the
+ * 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.
+ * isn't an @n<!-- -->'th item.
*
* Since: 2.4
**/
* gtk_toolbar_get_icon_size:
* @toolbar: a #GtkToolbar
*
- * Retrieves the icon size fo the toolbar. See gtk_toolbar_set_icon_size().
+ * 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.
**/
gtk_widget_hide (priv->arrow_button);
gtk_widget_queue_resize (GTK_WIDGET (toolbar));
- g_object_notify (G_OBJECT (toolbar), "show_arrow");
+ g_object_notify (G_OBJECT (toolbar), "show-arrow");
}
}
* @toolbar: a #GtkToolbar
*
* Returns whether the toolbar has an overflow menu.
- * See gtk_toolbar_set_show_arrow()
+ * See gtk_toolbar_set_show_arrow().
*
- * Return value:
+ * Return value: %TRUE if the toolbar has an overflow menu.
*
* Since: 2.4
**/
if (toolbar->tooltips)
g_object_unref (toolbar->tooltips);
+ if (priv->arrow_button)
+ gtk_widget_unparent (priv->arrow_button);
+
for (list = priv->content; list != NULL; list = list->next)
{
ToolbarContent *content = list->data;
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);
}
-/*
- * Deprecated API
- */
-
/**
* gtk_toolbar_set_icon_size:
* @toolbar: A #GtkToolbar
* can call it both before you add the icons and after they've been
* added. The size you set will override user preferences for the default
* icon size.
+ *
+ * This should only be used for special-purpose toolbars, normal
+ * application toolbars should respect the user preferences for the
+ * size of icons.
**/
void
gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
GtkIconSize icon_size)
{
g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
+ g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
- toolbar->icon_size_set = TRUE;
-
+ if (!toolbar->icon_size_set)
+ {
+ toolbar->icon_size_set = TRUE;
+ g_object_notify (G_OBJECT (toolbar), "icon-size-set");
+ }
+
if (toolbar->icon_size == icon_size)
return;
toolbar->icon_size = icon_size;
+ g_object_notify (G_OBJECT (toolbar), "icon-size");
gtk_toolbar_reconfigured (toolbar);
size = DEFAULT_ICON_SIZE;
if (size != toolbar->icon_size)
- gtk_toolbar_set_icon_size (toolbar, size);
+ {
+ gtk_toolbar_set_icon_size (toolbar, size);
+ g_object_notify (G_OBJECT (toolbar), "icon-size");
+ }
toolbar->icon_size_set = FALSE;
+ g_object_notify (G_OBJECT (toolbar), "icon-size-set");
}
}
+/*
+ * Deprecated API
+ */
+
/**
* gtk_toolbar_append_item:
* @toolbar: a #GtkToolbar.
gboolean use_stock)
{
GtkWidget *box;
- ToolbarContent *content;
- GtkToolbarPrivate *priv;
char *free_me = NULL;
- gboolean is_button = FALSE;
GtkWidget *child_widget;
GtkWidget *child_label;
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;
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 ();
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);
/*
* ToolbarContent methods
*/
+typedef enum {
+ UNKNOWN,
+ YES,
+ NO,
+} TriState;
+
struct _ToolbarContent
{
ContentType type;
GtkAllocation goal_allocation;
guint is_placeholder : 1;
guint disappearing : 1;
+ TriState has_menu : 2;
} tool_item;
struct
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)
toolbar_content_get_expand (ToolbarContent *content)
{
if (content->type == TOOL_ITEM &&
- gtk_tool_item_get_expand (content->u.tool_item.item))
+ gtk_tool_item_get_expand (content->u.tool_item.item) &&
+ !content->u.tool_item.disappearing)
{
return TRUE;
}
}
else
{
- content->u.compatibility.space_visible = visible;
- gtk_widget_queue_draw (GTK_WIDGET (toolbar));
+ if (content->u.compatibility.space_visible != visible)
+ {
+ content->u.compatibility.space_visible = visible;
+ gtk_widget_queue_draw (GTK_WIDGET (toolbar));
+ }
}
break;
}
static gboolean
toolbar_content_has_proxy_menu_item (ToolbarContent *content)
{
- GtkWidget *menu_item;
+ if (content->type == TOOL_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;
- 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;
+ }
+}
- 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;
}
-
+
static gboolean
toolbar_content_is_separator (ToolbarContent *content)
{
return FALSE;
}
+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)
{
if (toolbar)
{
gtk_widget_style_get (GTK_WIDGET (toolbar),
- "space_size", &space_size,
+ "space-size", &space_size,
NULL);
}
if (toolbar)
{
gtk_widget_style_get (GTK_WIDGET (toolbar),
- "space_style", &space_style,
+ "space-style", &space_style,
NULL);
}
gtk_widget_ensure_style (GTK_WIDGET (toolbar));
gtk_widget_style_get (GTK_WIDGET (toolbar),
- "button_relief", &button_relief,
+ "button-relief", &button_relief,
NULL);
return button_relief;
gint ipadding = 0;
gtk_widget_style_get (GTK_WIDGET (toolbar),
- "internal_padding", &ipadding,
+ "internal-padding", &ipadding,
NULL);
return ipadding;
}
+static gint
+get_max_child_expand (GtkToolbar *toolbar)
+{
+ gint mexpand = G_MAXINT;
+
+ gtk_widget_style_get (GTK_WIDGET (toolbar),
+ "max-child-expand", &mexpand,
+ NULL);
+ return mexpand;
+}
+
static GtkShadowType
get_shadow_type (GtkToolbar *toolbar)
{
GtkShadowType shadow_type;
gtk_widget_style_get (GTK_WIDGET (toolbar),
- "shadow_type", &shadow_type,
+ "shadow-type", &shadow_type,
NULL);
return shadow_type;
/*
* API checks
*/
-#define mixed_api_warning \
- "mixing deprecated and non-deprecated GtkToolbar API is not allowed"
-
static gboolean
gtk_toolbar_check_old_api (GtkToolbar *toolbar)
{
if (priv->api_mode == NEW_API)
{
- g_warning (mixed_api_warning);
+ g_warning (MIXED_API_WARNING);
return FALSE;
}
if (priv->api_mode == OLD_API)
{
- g_warning (mixed_api_warning);
+ g_warning (MIXED_API_WARNING);
return FALSE;
}
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;
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;
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_paint_box (widget->style, widget->window,
+ GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
+ area, widget, "vseparator",
+ allocation->x + (allocation->width - separator_width) / 2,
+ allocation->y + allocation->height * start_fraction,
+ separator_width,
+ allocation->height * (end_fraction - start_fraction));
+ else
+ 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);
}
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_paint_box (widget->style, widget->window,
+ GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
+ area, widget, "hseparator",
+ allocation->x + allocation->width * start_fraction,
+ allocation->y + (allocation->height - separator_height) / 2,
+ allocation->width * (end_fraction - start_fraction),
+ separator_height);
+ 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);
}
}
_gtk_toolbar_elide_underscores (const gchar *original)
{
gchar *q, *result;
- const gchar *p;
+ const gchar *p, *end;
+ gsize len;
gboolean last_underscore;
- q = result = g_malloc (strlen (original) + 1);
+ if (!original)
+ return NULL;
+
+ 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 (*p != '_' && original + 2 <= p && p + 1 <= end && p[-2] == '(' && p[1] == ')')
+ {
+ q--;
+ *q = '\0';
+ p++;
+ }
+ else
+ *q++ = *p;
}
}
+
+ if (last_underscore)
+ *q++ = '_';
*q = '\0';
return result;
}
+
+void
+_gtk_toolbar_rebuild_menu (GtkToolbar *toolbar)
+{
+ GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GList *list;
+
+ priv->need_rebuild = TRUE;
+
+ for (list = priv->content; list != NULL; list = list->next)
+ {
+ ToolbarContent *content = list->data;
+
+ toolbar_content_set_unknown_menu_status (content);
+ }
+
+ gtk_widget_queue_resize (GTK_WIDGET (toolbar));
+}
+
+#define __GTK_TOOLBAR_C__
+#include "gtkaliasdef.c"