summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorSoeren Sandmann <sandmann@daimi.au.dk>2003-10-25 19:58:51 +0000
committerSøren Sandmann Pedersen <ssp@src.gnome.org>2003-10-25 19:58:51 +0000
commit356df7f65002a47516b542ace1fe88badf9d4965 (patch)
treeeffb19a2188dff1b081eb353c61afa2539db64fa /gtk
parent3a7a64aa46ea1c312c06e17a177c81fddfa93683 (diff)
downloadgtk+-356df7f65002a47516b542ace1fe88badf9d4965.tar.gz
Make this function take an index and a GtkToolItem.
Thu Oct 23 21:55:10 2003 Soeren Sandmann <sandmann@daimi.au.dk> * gtk/gtktoolbar.c (gtk_toolbar_highlight_drop_location): Make this function take an index and a GtkToolItem. * tests/testtoolbar.c (main): Make "Show Arrow" default to true. Make one of the separators !draw and expand. Update for new highlight_drop_location() API. * gtk/gtktoolitem.[ch]: Remove "pack_end" property * gtk/gtktoolbar.h: Formatting fixes. * gtk/gtktoolbar.c: Remove "pack_end" child property. Allow separator tool items to expand. (logical_to_physical, physical_to_logical): Fix off-by-one errors (Fix #125472, Marco Pesenti Gritti) * gtk/gtkseparatortoolitem.[ch]: Add new "draw" property. (gtk_separator_tool_item_expose) only draw if "draw" is TRUE. Also return FALSE, not TRUE. (gtk_separator_too_item_{set|get}_property, (gtk_separator_tool_item_{set|get}_draw): new functions
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkseparatortoolitem.c181
-rw-r--r--gtk/gtkseparatortoolitem.h12
-rw-r--r--gtk/gtktoolbar.c366
-rw-r--r--gtk/gtktoolbar.h25
-rw-r--r--gtk/gtktoolitem.c47
-rw-r--r--gtk/gtktoolitem.h4
6 files changed, 343 insertions, 292 deletions
diff --git a/gtk/gtkseparatortoolitem.c b/gtk/gtkseparatortoolitem.c
index 34015b888b..5fcefc25d8 100644
--- a/gtk/gtkseparatortoolitem.c
+++ b/gtk/gtkseparatortoolitem.c
@@ -36,26 +36,48 @@
#define MENU_ID "gtk-separator-tool-item-menu-id"
-static void gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class);
-static gboolean gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item);
-static void gtk_separator_tool_item_size_request (GtkWidget *widget,
-
- GtkRequisition *requisition);
-static gboolean gtk_separator_tool_item_expose (GtkWidget *widget,
- GdkEventExpose *event);
-static void gtk_separator_tool_item_add (GtkContainer *container,
- GtkWidget *child);
-static GtkToolbarSpaceStyle get_space_style (GtkToolItem *tool_item);
-static gint get_space_size (GtkToolItem *tool_item);
+enum {
+ PROP_0,
+ PROP_DRAW
+};
+
+static void gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class);
+static void gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item,
+ GtkSeparatorToolItemClass *class);
+static gboolean gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item);
+static void gtk_separator_tool_item_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_separator_tool_item_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void gtk_separator_tool_item_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static gboolean gtk_separator_tool_item_expose (GtkWidget *widget,
+ GdkEventExpose *event);
+static void gtk_separator_tool_item_add (GtkContainer *container,
+ GtkWidget *child);
+static GtkToolbarSpaceStyle get_space_style (GtkToolItem *tool_item);
+static gint get_space_size (GtkToolItem *tool_item);
+
+
static GObjectClass *parent_class = NULL;
+#define GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM, GtkSeparatorToolItemPrivate))
+
+struct _GtkSeparatorToolItemPrivate
+{
+ guint draw : 1;
+};
GType
gtk_separator_tool_item_get_type (void)
{
static GType type = 0;
-
+
if (!type)
{
static const GTypeInfo type_info =
@@ -68,9 +90,9 @@ gtk_separator_tool_item_get_type (void)
NULL,
sizeof (GtkSeparatorToolItem),
0, /* n_preallocs */
- (GInstanceInitFunc) NULL,
+ (GInstanceInitFunc) gtk_separator_tool_item_init,
};
-
+
type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
"GtkSeparatorToolItem", &type_info, 0);
}
@@ -82,14 +104,14 @@ get_space_style (GtkToolItem *tool_item)
{
GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
-
+
if (GTK_IS_TOOLBAR (parent))
{
gtk_widget_style_get (parent,
"space_style", &space_style,
NULL);
}
-
+
return space_style;
}
@@ -105,27 +127,49 @@ get_space_size (GtkToolItem *tool_item)
"space_size", &space_size,
NULL);
}
-
+
return space_size;
}
static void
gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
{
+ GObjectClass *object_class;
GtkContainerClass *container_class;
GtkToolItemClass *toolitem_class;
GtkWidgetClass *widget_class;
-
+
parent_class = g_type_class_peek_parent (class);
+ object_class = (GObjectClass *)class;
container_class = (GtkContainerClass *)class;
toolitem_class = (GtkToolItemClass *)class;
widget_class = (GtkWidgetClass *)class;
+ object_class->set_property = gtk_separator_tool_item_set_property;
+ object_class->get_property = gtk_separator_tool_item_get_property;
widget_class->size_request = gtk_separator_tool_item_size_request;
widget_class->expose_event = gtk_separator_tool_item_expose;
toolitem_class->create_menu_proxy = gtk_separator_tool_item_create_menu_proxy;
-
+
container_class->add = gtk_separator_tool_item_add;
+
+ g_object_class_install_property (object_class,
+ PROP_DRAW,
+ g_param_spec_boolean ("draw",
+ _("Draw"),
+ _("Whether the separator is drawn, or just blank"),
+ TRUE,
+ G_PARAM_READWRITE));
+
+ g_type_class_add_private (object_class, sizeof (GtkSeparatorToolItemPrivate));
+}
+
+static void
+gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item,
+ GtkSeparatorToolItemClass *class)
+{
+ separator_item->priv = GTK_SEPARATOR_TOOL_ITEM_GET_PRIVATE (separator_item);
+ separator_item->priv->draw = TRUE;
}
static void
@@ -148,12 +192,50 @@ gtk_separator_tool_item_create_menu_proxy (GtkToolItem *item)
}
static void
+gtk_separator_tool_item_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
+
+ switch (prop_id)
+ {
+ case PROP_DRAW:
+ gtk_separator_tool_item_set_draw (item, g_value_get_boolean (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_separator_tool_item_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
+
+ switch (prop_id)
+ {
+ case PROP_DRAW:
+ g_value_set_boolean (value, gtk_separator_tool_item_get_draw (item));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
gtk_separator_tool_item_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkToolItem *item = GTK_TOOL_ITEM (widget);
GtkOrientation orientation = gtk_tool_item_get_orientation (item);
-
+
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
requisition->width = get_space_size (item);
@@ -171,18 +253,20 @@ gtk_separator_tool_item_expose (GtkWidget *widget,
GdkEventExpose *event)
{
GtkToolItem *tool_item = GTK_TOOL_ITEM (widget);
+ GtkSeparatorToolItem *separator_tool_item = GTK_SEPARATOR_TOOL_ITEM (widget);
gint space_size;
GtkAllocation *allocation;
GtkOrientation orientation;
GdkRectangle *area;
- if (get_space_style (tool_item) == GTK_TOOLBAR_SPACE_LINE)
+ if (separator_tool_item->priv->draw &&
+ get_space_style (tool_item) == GTK_TOOLBAR_SPACE_LINE)
{
space_size = get_space_size (tool_item);
allocation = &(widget->allocation);
orientation = gtk_tool_item_get_orientation (tool_item);
area = &(event->area);
-
+
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
gtk_paint_vline (widget->style, widget->window,
@@ -207,7 +291,7 @@ gtk_separator_tool_item_expose (GtkWidget *widget,
}
}
- return TRUE;
+ return FALSE;
}
/**
@@ -223,9 +307,58 @@ GtkToolItem *
gtk_separator_tool_item_new (void)
{
GtkToolItem *self;
-
+
self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
NULL);
return self;
}
+
+/**
+ * gtk_separator_tool_item_get_draw:
+ * @separator_tool_item: a #GtkSeparatorToolItem
+ *
+ * Returns whether @separator_tool_item is drawn as a
+ * line, or just blank. See gtk_separator_tool_item_set_draw().
+ *
+ * Return value: #TRUE if @separator_tool_item is drawn as a line, or just blank.
+ *
+ * Since: 2.4
+ **/
+gboolean
+gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *separator_tool_item)
+{
+ g_return_val_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (separator_tool_item), FALSE);
+
+ return separator_tool_item->priv->draw;
+}
+
+/**
+ * gtk_separator_tool_item_set_draw:
+ * @separator_tool_item: a #GtkSeparatorToolItem
+ * @draw: whether @separator_tool_item is drawn as a vertical iln
+ *
+ * When @separator_tool_items is drawn as a vertical line, or just blank.
+ * Setting this #FALSE along with gtk_tool_item_set_expand() is useful
+ * to create an item that forces following items to the end of the toolbar.
+ *
+ * Since: 2.4
+ **/
+void
+gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *separator_tool_item,
+ gboolean draw)
+{
+ g_return_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (separator_tool_item));
+
+ draw = draw != FALSE;
+
+ if (draw != separator_tool_item->priv->draw)
+ {
+ separator_tool_item->priv->draw = draw;
+
+ gtk_widget_queue_draw (GTK_WIDGET (separator_tool_item));
+
+ g_object_notify (G_OBJECT (separator_tool_item), "draw");
+ }
+}
+
diff --git a/gtk/gtkseparatortoolitem.h b/gtk/gtkseparatortoolitem.h
index 952d1f9a8d..3a2fbdcfe8 100644
--- a/gtk/gtkseparatortoolitem.h
+++ b/gtk/gtkseparatortoolitem.h
@@ -33,12 +33,16 @@ G_BEGIN_DECLS
#define GTK_IS_SEPARATOR_TOOL_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM))
#define GTK_SEPARATOR_TOOL_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM, GtkSeparatorToolItemClass))
-typedef struct _GtkSeparatorToolItem GtkSeparatorToolItem;
-typedef struct _GtkSeparatorToolItemClass GtkSeparatorToolItemClass;
+typedef struct _GtkSeparatorToolItem GtkSeparatorToolItem;
+typedef struct _GtkSeparatorToolItemClass GtkSeparatorToolItemClass;
+typedef struct _GtkSeparatorToolItemPrivate GtkSeparatorToolItemPrivate;
struct _GtkSeparatorToolItem
{
GtkToolItem parent;
+
+ /*< private >*/
+ GtkSeparatorToolItemPrivate *priv;
};
struct _GtkSeparatorToolItemClass
@@ -55,6 +59,10 @@ struct _GtkSeparatorToolItemClass
GType gtk_separator_tool_item_get_type (void) G_GNUC_CONST;
GtkToolItem *gtk_separator_tool_item_new (void);
+gboolean gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item);
+void gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *tool_item,
+ gboolean draw);
+
G_END_DECLS
#endif /* __GTK_SEPARATOR_TOOL_ITEM_H__ */
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index 81860a393c..42c318ecd1 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -72,8 +72,7 @@ enum {
enum {
CHILD_PROP_0,
CHILD_PROP_EXPAND,
- CHILD_PROP_HOMOGENEOUS,
- CHILD_PROP_PACK_END,
+ CHILD_PROP_HOMOGENEOUS
};
enum {
@@ -220,6 +219,7 @@ struct _GtkToolbarPrivate
gboolean leaving_dnd;
gboolean in_dnd;
gint n_overflow_items_when_dnd_started;
+ GtkToolItem *highlight_tool_item;
};
static GtkContainerClass *parent_class = NULL;
@@ -467,14 +467,6 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
TRUE,
G_PARAM_READWRITE));
- gtk_container_class_install_child_property (container_class,
- CHILD_PROP_PACK_END,
- g_param_spec_uint ("pack_end",
- _("Pack End"),
- _("Whether the item is positioned at the end of the toolbar"),
- 0, G_MAXINT, 0,
- G_PARAM_READWRITE));
-
/* style properties */
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("space_size",
@@ -849,7 +841,6 @@ gtk_toolbar_size_request (GtkWidget *widget,
gint max_homogeneous_child_height;
gint homogeneous_size;
gint long_req;
- gint pack_end_size;
gint pack_front_size;
gint ipadding;
GtkRequisition arrow_requisition;
@@ -884,7 +875,6 @@ gtk_toolbar_size_request (GtkWidget *widget,
else
homogeneous_size = max_homogeneous_child_height;
- pack_end_size = 0;
pack_front_size = 0;
for (list = priv->content; list != NULL; list = list->next)
{
@@ -911,10 +901,7 @@ gtk_toolbar_size_request (GtkWidget *widget,
size = requisition.height;
}
- if (gtk_tool_item_get_pack_end (item))
- pack_end_size += size;
- else
- pack_front_size += size;
+ pack_front_size += size;
}
if (priv->show_arrow && priv->api_mode == NEW_API)
@@ -929,14 +916,14 @@ gtk_toolbar_size_request (GtkWidget *widget,
/* There is no point requesting space for the arrow if that would take
* up more space than all the items combined
*/
- long_req = MIN (long_req, pack_front_size + pack_end_size);
+ long_req = MIN (long_req, pack_front_size);
}
else
{
arrow_requisition.height = 0;
arrow_requisition.width = 0;
- long_req = pack_end_size + pack_front_size;
+ long_req = pack_front_size;
}
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
@@ -1030,9 +1017,9 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
gint available_size;
gint n_items;
gint needed_size;
- GList *content;
GtkRequisition arrow_requisition;
gint n_overflowed;
+ gboolean overflowing;
widget->allocation = *allocation;
@@ -1097,56 +1084,21 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
else
size = available_size;
- content = g_list_copy (priv->content);
-
n_overflowed = 0;
-
- /* calculate widths of pack end items */
- for (list = g_list_last (content), i = 0; list != NULL; list = list->prev, ++i)
- {
- ToolbarContent *content = list->data;
- GtkToolItem *item = content->item;
- GtkAllocation *allocation = &(allocations[n_items - i - 1]);
- gint item_size;
-
- if (!gtk_tool_item_get_pack_end (item) ||
- !toolbar_item_visible (toolbar, item))
- continue;
-
- item_size = get_item_size (toolbar, GTK_WIDGET (item));
- if (item_size <= size)
- {
- size -= item_size;
- allocation->width = item_size;
- content->is_overflow = FALSE;
- }
- else
- {
- while (list)
- {
- content = list->data;
- item = content->item;
- if (gtk_tool_item_get_pack_end (item))
- content->is_overflow = TRUE;
- ++n_overflowed;
- list = list->prev;
- }
- break;
- }
- }
/* calculate widths of pack front items */
- for (list = content, i = 0; list != NULL; list = list->next, ++i)
+ overflowing = FALSE;
+ for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
{
ToolbarContent *content = list->data;
GtkToolItem *item = content->item;
gint item_size;
- if (gtk_tool_item_get_pack_end (item) || !toolbar_item_visible (toolbar, item))
+ if (!toolbar_item_visible (toolbar, item))
continue;
item_size = get_item_size (toolbar, GTK_WIDGET (item));
- if (item_size <= size)
+ if (item_size <= size && !overflowing)
{
size -= item_size;
allocations[i].width = item_size;
@@ -1154,16 +1106,9 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
}
else
{
- while (list)
- {
- content = list->data;
- item = content->item;
- if (!gtk_tool_item_get_pack_end (item))
- content->is_overflow = TRUE;
- ++n_overflowed;
- list = list->next;
- }
- break;
+ ++n_overflowed;
+ content->is_overflow = TRUE;
+ overflowing = TRUE;
}
}
@@ -1190,21 +1135,20 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
if (toolbar_item_visible (toolbar, item) &&
gtk_tool_item_get_expand (item) &&
- !content->is_overflow &&
- !GTK_IS_SEPARATOR_TOOL_ITEM (item))
+ !content->is_overflow)
{
n_expand_items++;
}
}
- for (list = content, i = 0; list != NULL; list = list->next, ++i)
+ for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
{
ToolbarContent *content = list->data;
GtkToolItem *item = content->item;
- if (toolbar_item_visible (toolbar, item) && gtk_tool_item_get_expand (item) &&
- !content->is_overflow &&
- !GTK_IS_SEPARATOR_TOOL_ITEM (item))
+ if (toolbar_item_visible (toolbar, item) &&
+ gtk_tool_item_get_expand (item) &&
+ !content->is_overflow)
{
gint extra = size / n_expand_items;
if (size % n_expand_items != 0)
@@ -1219,16 +1163,14 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
g_assert (n_expand_items == 0);
}
- /* position pack front items */
+ /* position regular items */
pos = border_width;
- for (list = content, i = 0; list != NULL; list = list->next, ++i)
+ for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
{
ToolbarContent *content = list->data;
GtkToolItem *item = content->item;
- if (toolbar_item_visible (toolbar, item) &&
- !content->is_overflow &&
- !gtk_tool_item_get_pack_end (item))
+ if (toolbar_item_visible (toolbar, item) && !content->is_overflow)
{
allocations[i].x = pos;
allocations[i].y = border_width;
@@ -1238,31 +1180,10 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
}
}
- /* position pack end items */
- pos = available_size + border_width;
- for (list = g_list_last (content), i = 0; list != NULL; list = list->prev, ++i)
- {
- ToolbarContent *content = list->data;
- GtkToolItem *item = content->item;
-
- if (toolbar_item_visible (toolbar, item) &&
- !content->is_overflow &&
- gtk_tool_item_get_pack_end (item))
- {
- GtkAllocation *allocation = &(allocations[n_items - i - 1]);
-
- allocation->x = pos - allocation->width;
- allocation->y = border_width;
- allocation->height = short_size;
-
- pos -= allocation->width;
- }
- }
-
/* position arrow */
if (need_arrow)
{
- arrow_allocation.x = pos - arrow_allocation.width;
+ arrow_allocation.x = available_size - border_width - arrow_allocation.width;
arrow_allocation.y = border_width;
}
@@ -1310,7 +1231,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
}
/* finally allocate the items */
- for (list = content, i = 0; list != NULL; list = list->next, i++)
+ for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
{
ToolbarContent *content = list->data;
GtkToolItem *item = content->item;
@@ -1338,7 +1259,6 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
}
g_free (allocations);
- g_list_free (content);
}
static void
@@ -1385,21 +1305,12 @@ gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
{
ToolbarContent *content = list->data;
GtkToolItem *item = content->item;
- if (!gtk_tool_item_get_pack_end (item))
- result = g_list_prepend (result, item);
+
+ result = g_list_prepend (result, item);
}
result = g_list_prepend (result, priv->arrow_button);
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
- GtkToolItem *item = content->item;
-
- if (gtk_tool_item_get_pack_end (item))
- result = g_list_prepend (result, item);
- }
-
rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
/* move in logical order when
@@ -1621,12 +1532,8 @@ find_drop_index (GtkToolbar *toolbar,
ToolbarContent *content = list->data;
GtkToolItem *item = content->item;
- if (!gtk_tool_item_get_pack_end (item) &&
- toolbar_item_visible (toolbar, item) &&
- !content->is_overflow)
- {
- interesting_content = g_list_prepend (interesting_content, content);
- }
+ if (toolbar_item_visible (toolbar, item) && !content->is_overflow)
+ interesting_content = g_list_prepend (interesting_content, content);
}
interesting_content = g_list_reverse (interesting_content);
@@ -1806,8 +1713,6 @@ update_dnd_animation (gpointer data)
gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
- GDK_THREADS_LEAVE();
-
if (!cont)
{
priv->idle_id = 0;
@@ -1818,9 +1723,13 @@ update_dnd_animation (gpointer data)
priv->n_overflow_items_when_dnd_started = 0;
}
+ GDK_THREADS_LEAVE();
+
return FALSE;
}
+ GDK_THREADS_LEAVE();
+
return TRUE;
}
@@ -1854,19 +1763,117 @@ reset_all_placeholders (GtkToolbar *toolbar)
g_timer_reset (priv->timer);
}
+static gint
+physical_to_logical (GtkToolbar *toolbar, gint physical)
+{
+ GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GList *list;
+ int logical;
+
+ g_assert (physical >= 0);
+
+ logical = 0;
+ for (list = priv->content; list && physical > 0; list = list->next)
+ {
+ ToolbarContent *content = list->data;
+
+ if (!content->is_placeholder)
+ logical++;
+ physical--;
+ }
+
+ g_assert (physical == 0);
+
+ return logical;
+}
+
+static gint
+logical_to_physical (GtkToolbar *toolbar, gint logical)
+{
+ GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GList *list;
+ gint physical;
+
+ g_assert (logical >= 0);
+
+ physical = 0;
+ for (list = priv->content; list && logical > 0; list = list->next)
+ {
+ ToolbarContent *content = list->data;
+
+ if (!content->is_placeholder)
+ logical--;
+ physical++;
+ }
+
+ g_assert (logical == 0);
+ return physical;
+}
+
+static void
+get_item_requisition (GtkToolbar *toolbar,
+ GtkToolItem *tool_item,
+ gint *width,
+ gint *height)
+{
+ GtkRequisition requisition;
+
+ g_object_ref (G_OBJECT (tool_item));
+ gtk_widget_set_parent (GTK_WIDGET (tool_item), GTK_WIDGET (toolbar));
+
+ gtk_widget_size_request (GTK_WIDGET (tool_item), &requisition);
+ *width = requisition.width;
+ *height = requisition.height;
+
+ gtk_widget_unparent (GTK_WIDGET (tool_item));
+ g_object_unref (G_OBJECT (tool_item));
+}
+
+/**
+ * gtk_toolbar_highlight_drop_location:
+ * @toolbar: a #GtkToolbar
+ * @index: the toolbar position to highlight, or -1
+ * @tool_item: a #GtkToolbar that isn't part of a widget hierarchy
+ *
+ * Highlights the position on the toolbar indicated by @index to give
+ * an idea of how @toolbar would look if @tool_item was added to it at
+ * @index.
+ *
+ * After calling this function gtk_toolbar_unhighlight_drop_location() must
+ * be called before @tool_item can be added to any widget hierarchy.
+ *
+ * Since: 2.4
+ **/
void
-gtk_toolbar_highlight_drop_location (GtkToolbar *toolbar,
- gint x,
- gint y,
- gint width,
- gint height)
+gtk_toolbar_highlight_drop_location (GtkToolbar *toolbar,
+ gint index,
+ GtkToolItem *tool_item)
{
- gint index;
ToolbarContent *content;
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+ GtkToolbarPrivate *priv;
gint start_width, start_height;
GList *list;
+ gint n_items;
+ GtkRequisition requisition;
+
+ g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
+ g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
+
+ priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+
+ if (tool_item != priv->highlight_tool_item)
+ {
+ if (priv->highlight_tool_item)
+ g_object_unref (priv->highlight_tool_item);
+
+ gtk_object_sink (GTK_OBJECT (g_object_ref (tool_item)));
+ priv->highlight_tool_item = tool_item;
+
+ gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
+ GTK_WIDGET (toolbar));
+ }
+
if (!priv->in_dnd)
{
priv->n_overflow_items_when_dnd_started = 0;
@@ -1880,9 +1887,13 @@ gtk_toolbar_highlight_drop_location (GtkToolbar *toolbar,
priv->in_dnd = TRUE;
priv->leaving_dnd = FALSE;
-
- index = find_drop_index (toolbar, x, y);
+ n_items = gtk_toolbar_get_n_items (toolbar);
+ if (index < 0 || index > n_items)
+ index = n_items;
+
+ index = logical_to_physical (toolbar, index);
+
content = g_list_nth_data (priv->content, index);
if (index > 0)
@@ -1913,17 +1924,20 @@ gtk_toolbar_highlight_drop_location (GtkToolbar *toolbar,
g_assert (content);
g_assert (content->is_placeholder);
+ gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
+ &requisition);
+
if (content->start_width != start_width ||
content->start_height != start_height ||
- content->goal_width != width ||
- content->goal_height != height)
+ content->goal_width != requisition.width ||
+ content->goal_height != requisition.height)
{
reset_all_placeholders (toolbar);
content->start_width = start_width;
- content->goal_width = width;
+ content->goal_width = requisition.width;
content->start_height = start_height;
- content->goal_height = height;
+ content->goal_height = requisition.height;
ensure_idle_handler (toolbar);
}
@@ -1937,6 +1951,13 @@ gtk_toolbar_unhighlight_drop_location (GtkToolbar *toolbar)
priv->leaving_dnd = TRUE;
reset_all_placeholders (toolbar);
ensure_idle_handler (toolbar);
+
+ if (priv->highlight_tool_item)
+ {
+ gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
+ g_object_unref (priv->highlight_tool_item);
+ priv->highlight_tool_item = NULL;
+ }
}
static void
@@ -1950,10 +1971,6 @@ gtk_toolbar_get_child_property (GtkContainer *container,
switch (property_id)
{
- case CHILD_PROP_PACK_END:
- g_value_set_boolean (value, gtk_tool_item_get_pack_end (item));
- break;
-
case CHILD_PROP_HOMOGENEOUS:
g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
break;
@@ -1977,10 +1994,6 @@ gtk_toolbar_set_child_property (GtkContainer *container,
{
switch (property_id)
{
- case CHILD_PROP_PACK_END:
- gtk_tool_item_set_pack_end (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
- break;
-
case CHILD_PROP_HOMOGENEOUS:
gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
break;
@@ -1988,7 +2001,7 @@ gtk_toolbar_set_child_property (GtkContainer *container,
case CHILD_PROP_EXPAND:
gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
break;
-
+
default:
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
break;
@@ -2369,56 +2382,6 @@ gtk_toolbar_check_new_api (GtkToolbar *toolbar)
return TRUE;
}
-static gint
-physical_to_logical (GtkToolbar *toolbar, gint physical)
-{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
- GList *list;
- int logical;
-
- if (physical < 0)
- return -1;
-
- logical = 0;
- for (list = priv->content; list; list = list->next)
- {
- ToolbarContent *content = list->data;
-
- if (!physical)
- return logical;
-
- if (!content->is_placeholder)
- logical++;
- physical--;
- }
- return -1;
-}
-
-static gint
-logical_to_physical (GtkToolbar *toolbar, gint logical)
-{
- GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
- GList *list;
- gint physical;
-
- if (logical < 0)
- return -1;
-
- physical = 0;
- for (list = priv->content; list; list = list->next)
- {
- ToolbarContent *content = list->data;
-
- if (!logical)
- return physical;
-
- if (!content->is_placeholder)
- logical--;
- physical++;
- }
- return -1;
-}
-
static void
gtk_toolbar_insert_tool_item (GtkToolbar *toolbar,
GtkToolItem *item,
@@ -2524,8 +2487,10 @@ gtk_toolbar_insert (GtkToolbar *toolbar,
if (!gtk_toolbar_check_new_api (toolbar))
return;
- gtk_toolbar_insert_tool_item (toolbar, item,
- logical_to_physical (toolbar, pos), FALSE);
+ if (pos >= 0)
+ pos = logical_to_physical (toolbar, pos);
+
+ gtk_toolbar_insert_tool_item (toolbar, item, pos, FALSE);
}
/**
@@ -2730,10 +2695,7 @@ gtk_toolbar_get_n_items (GtkToolbar *toolbar)
priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
- if (!priv->content)
- return 0;
-
- return physical_to_logical (toolbar, g_list_length (priv->content) - 1);
+ return physical_to_logical (toolbar, g_list_length (priv->content));
}
/**
@@ -2952,10 +2914,10 @@ gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
gint y)
{
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
-
+
if (!gtk_toolbar_check_new_api (toolbar))
return -1;
-
+
return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
}
diff --git a/gtk/gtktoolbar.h b/gtk/gtktoolbar.h
index 0e0f50d557..ec61e8f609 100644
--- a/gtk/gtktoolbar.h
+++ b/gtk/gtktoolbar.h
@@ -45,7 +45,7 @@
#include <gtk/gtkpixmap.h>
#include <gtk/gtksignal.h>
-#endif
+#endif /* GTK_DISABLE_DEPRECATED */
G_BEGIN_DECLS
@@ -91,7 +91,8 @@ typedef struct _GtkToolbarPrivate GtkToolbarPrivate;
struct _GtkToolbar
{
GtkContainer container;
-
+
+ /*< private >*/
gint num_children;
GList *children;
GtkOrientation orientation;
@@ -115,9 +116,9 @@ struct _GtkToolbarClass
GtkContainerClass parent_class;
/* signals */
- void (* orientation_changed) (GtkToolbar *toolbar,
+ void (* orientation_changed) (GtkToolbar *toolbar,
GtkOrientation orientation);
- void (* style_changed) (GtkToolbar *toolbar,
+ void (* style_changed) (GtkToolbar *toolbar,
GtkToolbarStyle style);
gboolean (* popup_context_menu) (GtkToolbar *toolbar,
gint x,
@@ -140,29 +141,27 @@ gint gtk_toolbar_get_item_index (GtkToolbar *toolbar,
gint gtk_toolbar_get_n_items (GtkToolbar *toolbar);
GtkToolItem * gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
gint n);
+gboolean gtk_toolbar_get_show_arrow (GtkToolbar *toolbar);
void gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
gboolean show_arrow);
+GtkOrientation gtk_toolbar_get_orientation (GtkToolbar *toolbar);
void gtk_toolbar_set_orientation (GtkToolbar *toolbar,
GtkOrientation orientation);
+gboolean gtk_toolbar_get_tooltips (GtkToolbar *toolbar);
void gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
gboolean enable);
-gboolean gtk_toolbar_get_show_arrow (GtkToolbar *toolbar);
-GtkOrientation gtk_toolbar_get_orientation (GtkToolbar *toolbar);
GtkToolbarStyle gtk_toolbar_get_style (GtkToolbar *toolbar);
-GtkIconSize gtk_toolbar_get_icon_size (GtkToolbar *toolbar);
-gboolean gtk_toolbar_get_tooltips (GtkToolbar *toolbar);
-GtkReliefStyle gtk_toolbar_get_relief_style (GtkToolbar *toolbar);
void gtk_toolbar_set_style (GtkToolbar *toolbar,
GtkToolbarStyle style);
void gtk_toolbar_unset_style (GtkToolbar *toolbar);
+GtkIconSize gtk_toolbar_get_icon_size (GtkToolbar *toolbar);
+GtkReliefStyle gtk_toolbar_get_relief_style (GtkToolbar *toolbar);
gint gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
gint x,
gint y);
void gtk_toolbar_highlight_drop_location (GtkToolbar *toolbar,
- gint x,
- gint y,
- gint width,
- gint height);
+ gint index,
+ GtkToolItem *tool_item);
void gtk_toolbar_unhighlight_drop_location (GtkToolbar *toolbar);
diff --git a/gtk/gtktoolitem.c b/gtk/gtktoolitem.c
index 8ec7a0ad2a..e7ac11a536 100644
--- a/gtk/gtktoolitem.c
+++ b/gtk/gtktoolitem.c
@@ -54,7 +54,6 @@ struct _GtkToolItemPrivate
guint visible_vertical : 1;
guint homogeneous : 1;
guint expand : 1;
- guint pack_end : 1;
guint use_drag_window : 1;
guint is_important : 1;
@@ -672,52 +671,6 @@ gtk_tool_item_get_expand (GtkToolItem *tool_item)
}
/**
- * gtk_tool_item_set_pack_end:
- * @tool_item: a #GtkToolItem:
- * @pack_end: whether @tool_item is allocated at the end of the toolbar.
- *
- * Sets whether @tool_item is allocated at the end of the toolbar. This is
- * useful for #GtkToolItem<!-- -->s that are used as "throbbers" in
- * web-browser-type applications.
- *
- * Since: 2.4
- **/
-void
-gtk_tool_item_set_pack_end (GtkToolItem *tool_item,
- gboolean pack_end)
-{
- g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
-
- pack_end = pack_end != FALSE;
-
- if (tool_item->priv->pack_end != pack_end)
- {
- tool_item->priv->pack_end = pack_end;
- gtk_widget_child_notify (GTK_WIDGET (tool_item), "pack_end");
- gtk_widget_queue_resize (GTK_WIDGET (tool_item));
- }
-}
-
-/**
- * gtk_tool_item_get_pack_end:
- * @tool_item: a #GtkToolItem:
- *
- * Returns whether @tool_item is packed at the end of the toolbar.
- * See gtk_tool_item_set_pack_end().
- *
- * Return value: %TRUE if @tool_item is packed at the end of the toolbar.
- *
- * Since: 2.4
- **/
-gboolean
-gtk_tool_item_get_pack_end (GtkToolItem *tool_item)
-{
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
-
- return tool_item->priv->pack_end;
-}
-
-/**
* gtk_tool_item_set_homogeneous:
* @tool_item: a #GtkToolItem:
* @homogeneous: whether @tool_item is the same size as other homogeneous items
diff --git a/gtk/gtktoolitem.h b/gtk/gtktoolitem.h
index d5a6f8c225..5c29701c7a 100644
--- a/gtk/gtktoolitem.h
+++ b/gtk/gtktoolitem.h
@@ -78,10 +78,6 @@ void gtk_tool_item_set_expand (GtkToolItem *tool_item,
gboolean expand);
gboolean gtk_tool_item_get_expand (GtkToolItem *tool_item);
-void gtk_tool_item_set_pack_end (GtkToolItem *tool_item,
- gboolean pack_end);
-gboolean gtk_tool_item_get_pack_end (GtkToolItem *tool_item);
-
void gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
GtkTooltips *tooltips,
const gchar *tip_text,