* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#undef GTK_DISABLE_DEPRECATED
#include "config.h"
#include "gtkvbox.h"
#include "gtkprivate.h"
#include "gtkintl.h"
-#include "gtkalias.h"
+
typedef struct _ToolbarContent ToolbarContent;
#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 {
LAST_SIGNAL
};
-/* API mode */
-typedef enum {
- DONT_KNOW,
- OLD_API,
- NEW_API
-} ApiMode;
-
-typedef enum {
- TOOL_ITEM,
- COMPATIBILITY
-} ContentType;
-
typedef enum {
NOT_ALLOCATED,
NORMAL,
GtkMenu * menu;
GdkWindow * event_window;
- ApiMode api_mode;
GtkSettings * settings;
int idle_id;
GtkToolItem * highlight_tool_item;
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,
- GCallback 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 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);
/* 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);
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:
toolbar->style = DEFAULT_TOOLBAR_STYLE;
toolbar->icon_size = DEFAULT_ICON_SIZE;
priv->animation = DEFAULT_ANIMATION_STATE;
- toolbar->tooltips = gtk_tooltips_new ();
- g_object_ref_sink (toolbar->tooltips);
-
+
priv->arrow_button = gtk_toggle_button_new ();
g_signal_connect (priv->arrow_button, "button-press-event",
G_CALLBACK (gtk_toolbar_arrow_button_press), 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);
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_int (value));
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_int (value, gtk_toolbar_get_icon_size (toolbar));
break;
{
GtkToolbar *toolbar = GTK_TOOLBAR (widget);
GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-
+
GdkWindowAttr attributes;
gint attributes_mask;
- gint border_width;
-
+ guint border_width;
+
gtk_widget_set_realized (widget, TRUE);
-
- border_width = GTK_CONTAINER (widget)->border_width;
-
+
+ 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;
GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
GList *list;
- gint border_width;
-
- border_width = GTK_CONTAINER (widget)->border_width;
-
+ guint border_width;
+
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
if (gtk_widget_is_drawable (widget))
{
gtk_paint_box (widget->style,
gint long_req;
gint pack_front_size;
gint ipadding;
+ guint border_width;
GtkRequisition arrow_requisition;
max_homogeneous_child_width = 0;
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);
/* 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);
+
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
+ requisition->width += 2 * (ipadding + border_width);
+ requisition->height += 2 * (ipadding + border_width);
if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
{
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;
+ border_width = get_internal_padding (toolbar) + gtk_container_get_border_width (GTK_CONTAINER (toolbar));
if (rtl)
{
gtk_toolbar_stop_sliding (toolbar);
widget->allocation = *allocation;
-
- border_width = GTK_CONTAINER (toolbar)->border_width;
-
+
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
+
if (gtk_widget_get_realized (widget))
{
gdk_window_move_resize (priv->event_window,
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))
{
new_states[i] != NORMAL)
{
/* an item disappeared and we didn't change size, so begin sliding */
- if (!size_changed && priv->api_mode == NEW_API)
+ if (!size_changed)
gtk_toolbar_begin_sliding (toolbar);
}
}
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_get_mapped (child) && gtk_widget_child_focus (child, dir))
{
GtkToolbar *toolbar = GTK_TOOLBAR (widget);
GtkContainer *container = GTK_CONTAINER (toolbar);
+ GtkWidget *focus_child;
GList *list;
gboolean try_focus = FALSE;
GList *children;
- if (container->focus_child &&
- gtk_widget_child_focus (container->focus_child, dir))
- {
- return;
- }
+ 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);
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;
}
* 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);
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);
if (!tool_item)
{
GtkToolbar *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);
+ gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
}
static void
gtk_toolbar_button_press (GtkWidget *toolbar,
GdkEventButton *event)
{
+ GtkWidget *window;
+
if (event->button == 3)
{
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;
}
-
+
+ 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_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);
n = 0;
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.
- *
- * Deprecated: 2.16: Use gtk_orientable_set_orientation() instead.
- **/
-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
- *
- * Deprecated: 2.16: Use gtk_orientable_get_orientation() instead.
- **/
-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_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.
- *
- * Deprecated: 2.14: The toolkit-wide #GtkSettings:gtk-enable-tooltips property
- * is now used instead.
- **/
-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");
-}
-
-/**
- * gtk_toolbar_get_tooltips:
- * @toolbar: a #GtkToolbar
- *
- * Retrieves whether tooltips are enabled. See
- * gtk_toolbar_set_tooltips().
- *
- * Return value: %TRUE if tooltips are enabled
- *
- * Deprecated: 2.14: The toolkit-wide #GtkSettings:gtk-enable-tooltips property
- * is now used instead.
- **/
-gboolean
-gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
-{
- g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
-
- return TRUE;
-}
-
/**
* gtk_toolbar_get_n_items:
* @toolbar: a #GtkToolbar
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);
return physical_to_logical (toolbar, g_list_length (priv->content));
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
- if (!gtk_toolbar_check_new_api (toolbar))
- return NULL;
-
n_items = gtk_toolbar_get_n_items (toolbar);
if (n < 0 || n >= n_items)
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;
{
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));
}
GtkToolbar *toolbar = GTK_TOOLBAR (object);
GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
- if (toolbar->tooltips)
- g_object_unref (toolbar->tooltips);
-
if (priv->arrow_button)
gtk_widget_unparent (priv->arrow_button);
}
/*
- * 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 G_CALLBACK() to cast the function to #GCallback.
- *
- * Return value: the new toolbar item as a #GtkWidget.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-GtkWidget *
-gtk_toolbar_append_item (GtkToolbar *toolbar,
- const char *text,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GtkWidget *icon,
- GCallback 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 G_CALLBACK() to cast the function to #GCallback.
- *
- * Return value: the new toolbar item as a #GtkWidget.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-GtkWidget *
-gtk_toolbar_prepend_item (GtkToolbar *toolbar,
- const char *text,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GtkWidget *icon,
- GCallback callback,
- gpointer user_data)
+ GtkToolItem *item;
+ GtkAllocation start_allocation;
+ GtkAllocation goal_allocation;
+ guint is_placeholder : 1;
+ guint disappearing : 1;
+ guint has_menu : 2;
+};
+
+static ToolbarContent *
+toolbar_content_new_tool_item (GtkToolbar *toolbar,
+ GtkToolItem *item,
+ gboolean is_placeholder,
+ gint pos)
{
- return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
- NULL, text,
- tooltip_text, tooltip_private_text,
- icon, callback, user_data,
- 0);
+ ToolbarContent *content;
+ GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+
+ content = g_slice_new0 (ToolbarContent);
+
+ content->state = NOT_ALLOCATED;
+ content->item = item;
+ content->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;
}
-/**
- * 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 G_CALLBACK() to cast the function to #GCallback.
- *
- * Return value: the new toolbar item as a #GtkWidget.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-GtkWidget *
-gtk_toolbar_insert_item (GtkToolbar *toolbar,
- const char *text,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GtkWidget *icon,
- GCallback callback,
- gpointer user_data,
- gint position)
+static void
+toolbar_content_remove (ToolbarContent *content,
+ GtkToolbar *toolbar)
{
- return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
- NULL, text,
- tooltip_text, tooltip_private_text,
- icon, callback, user_data,
- position);
+ GtkToolbarPrivate *priv;
+
+ priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+
+ gtk_widget_unparent (GTK_WIDGET (content->item));
+
+ 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;
}
-/**
- * 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 G_CALLBACK() to cast the function to #GCallback.
- *
- * Returns: the inserted widget
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- */
-GtkWidget*
-gtk_toolbar_insert_stock (GtkToolbar *toolbar,
- const gchar *stock_id,
- const char *tooltip_text,
- const char *tooltip_private_text,
- GCallback callback,
- gpointer user_data,
- gint position)
+static void
+toolbar_content_free (ToolbarContent *content)
{
- return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
- NULL, stock_id,
- tooltip_text, tooltip_private_text,
- NULL, callback, user_data,
- position, TRUE);
+ g_slice_free (ToolbarContent, content);
}
-/**
- * gtk_toolbar_append_space:
- * @toolbar: a #GtkToolbar.
- *
- * Adds a new space to the end of the toolbar.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-void
-gtk_toolbar_append_space (GtkToolbar *toolbar)
+static gint
+calculate_max_homogeneous_pixels (GtkWidget *widget)
{
- gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
- NULL, NULL,
- NULL, NULL,
- NULL, NULL, NULL,
- toolbar->num_children);
+ 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_language (context));
+ char_width = pango_font_metrics_get_approximate_char_width (metrics);
+ pango_font_metrics_unref (metrics);
+
+ return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
}
-/**
- * gtk_toolbar_prepend_space:
- * @toolbar: a #GtkToolbar.
- *
- * Adds a new space to the beginning of the toolbar.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-void
-gtk_toolbar_prepend_space (GtkToolbar *toolbar)
+static void
+toolbar_content_expose (ToolbarContent *content,
+ GtkContainer *container,
+ GdkEventExpose *expose)
{
- gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
- NULL, NULL,
- NULL, NULL,
- NULL, NULL, NULL,
- 0);
+ GtkWidget *widget;
+
+ if (!content->is_placeholder)
+ widget = GTK_WIDGET (content->item);
+
+ if (widget)
+ gtk_container_propagate_expose (container, widget, expose);
}
-/**
- * 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.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-void
-gtk_toolbar_insert_space (GtkToolbar *toolbar,
- gint position)
+static gboolean
+toolbar_content_visible (ToolbarContent *content,
+ GtkToolbar *toolbar)
{
- gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
- NULL, NULL,
- NULL, NULL,
- NULL, NULL, NULL,
- position);
-}
+ GtkToolItem *item;
-/**
- * gtk_toolbar_remove_space:
- * @toolbar: a #GtkToolbar.
- * @position: the index of the space to remove.
- *
- * Removes a space from the specified position.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-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: (allow-none): the element's tooltip.
- * @tooltip_private_text: (allow-none): used for context-sensitive help about this toolbar element.
- *
- * Adds a widget to the end of the given toolbar.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-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: (allow-none): the element's tooltip.
- * @tooltip_private_text: (allow-none): used for context-sensitive help about this toolbar element.
- *
- * Adds a widget to the beginning of the given toolbar.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-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: (allow-none): the element's tooltip.
- * @tooltip_private_text: (allow-none): 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.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-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: (allow-none): 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 G_CALLBACK() to cast the function to #GCallback.
- *
- * Return value: the new toolbar element as a #GtkWidget.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-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,
- GCallback 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: (allow-none): 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 G_CALLBACK() to cast the function to #GCallback.
- *
- * Return value: the new toolbar element as a #GtkWidget.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-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,
- GCallback 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: (allow-none): 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 G_CALLBACK() to cast the function to #GCallback.
- *
- * Return value: the new toolbar element as a #GtkWidget.
- *
- * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
- **/
-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,
- GCallback 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,
- GCallback callback,
- gpointer user_data,
- gint position,
- gboolean use_stock)
-{
- GtkWidget *box;
- ToolbarContent *content;
- char *free_me = NULL;
-
- 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;
-
- 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:
- 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);
-
- 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;
- guint 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_slice_new0 (ToolbarContent);
-
- 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_slice_new0 (ToolbarContent);
-
- 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_slice_free (ToolbarContent, content);
-}
-
-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_language (context));
- char_width = pango_font_metrics_get_approximate_char_width (metrics);
- pango_font_metrics_unref (metrics);
-
- return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
-}
-
-static void
-toolbar_content_expose (ToolbarContent *content,
- GtkContainer *container,
- GdkEventExpose *expose)
-{
- 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 (content->u.compatibility.space_visible &&
- get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE)
- _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
- &expose->area,
- &content->u.compatibility.space_allocation);
- return;
- }
-
- widget = child->widget;
- break;
- }
-
- if (widget)
- gtk_container_propagate_expose (container, widget, expose);
-}
+ item = content->item;
-static gboolean
-toolbar_content_visible (ToolbarContent *content,
- GtkToolbar *toolbar)
-{
- GtkToolItem *item;
-
- switch (content->type)
- {
- case TOOL_ITEM:
- item = content->u.tool_item.item;
-
- if (!gtk_widget_get_visible (GTK_WIDGET (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;
+ if (!gtk_widget_get_visible (GTK_WIDGET (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;
- case COMPATIBILITY:
- if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
- return gtk_widget_get_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_size_request (GTK_WIDGET (content->item),
+ requisition);
+ 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 */
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) &&
+ toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
+ toolbar->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_CHILD_VISIBLE (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;
- }
+ gtk_widget_get_allocation (GTK_WIDGET (content->item), 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
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;
- }
+ 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);
{
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)
{
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;
-}
-
/* GTK+ internal methods */
gint
gtk_widget_queue_resize (GTK_WIDGET (shell));
}
-
-#define __GTK_TOOLBAR_C__
-#include "gtkaliasdef.c"