gdl-switcher.c revision d6b764cc205f348b6d2398edd654e8a9684f5dad
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * Copyright (C) 2003 Ettore Perazzoli,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * 2007 Naba Kumar
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * This program is free software; you can redistribute it and/or
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * modify it under the terms of version 2 of the GNU General Public
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * License as published by the Free Software Foundation.
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * This program is distributed in the hope that it will be useful,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * but WITHOUT ANY WARRANTY; without even the implied warranty of
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * General Public License for more details.
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * You should have received a copy of the GNU General Public
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * License along with this program; if not, write to the
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * Boston, MA 02111-1307, USA.
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * Copied and adapted from ESidebar.[ch] from evolution
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * Authors: Ettore Perazzoli <ettore@ximian.com>
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * Naba Kumar <naba@gnome.org>
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void gdl_switcher_set_property (GObject *object,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void gdl_switcher_get_property (GObject *object,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void gdl_switcher_add_button (GdlSwitcher *switcher,
7a10406c7610c65f3600986ded11320fe870ccb9Alex Valavanis/* static void gdl_switcher_remove_button (GdlSwitcher *switcher, gint switcher_id); */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void gdl_switcher_select_page (GdlSwitcher *switcher, gint switcher_id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void gdl_switcher_select_button (GdlSwitcher *switcher, gint switcher_id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void gdl_switcher_set_show_buttons (GdlSwitcher *switcher, gboolean show);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void gdl_switcher_set_style (GdlSwitcher *switcher,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic GdlSwitcherStyle gdl_switcher_get_style (GdlSwitcher *switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_btypedef struct {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bGDL_CLASS_BOILERPLATE (GdlSwitcher, gdl_switcher, GtkNotebook, GTK_TYPE_NOTEBOOK)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#define INTERNAL_MODE(switcher) (switcher->priv->switcher_style == \
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GDL_SWITCHER_STYLE_TOOLBAR ? switcher->priv->toolbar_style : \
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* Utility functions. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bbutton_new (GtkWidget *button_widget, GtkWidget *label, GtkWidget *icon,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b "__switcher_id"));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_set_data (G_OBJECT (widget), "__switcher_id",
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bupdate_buttons (GdlSwitcher *switcher, int new_selected_id)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* Callbacks. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bbutton_toggled_callback (GtkToggleButton *toggle_button,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (button->button_widget != GTK_WIDGET (toggle_button)) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* Returns -1 if layout didn't happen because a resize request was queued */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkAllocation *allocation = & GTK_WIDGET (switcher)->allocation;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int num_btns = g_slist_length (switcher->priv->buttons);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b last_buttons_height = switcher->priv->buttons_height_request;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b y = allocation->y + allocation->height - V_PADDING - 1;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b icons_only = (switcher_style == GDL_SWITCHER_STYLE_ICON);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Figure out the max width and height */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_size_request (GTK_WIDGET (button->button_widget),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b optimal_layout_width += requisition.width + H_PADDING;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b max_btn_height = MAX (max_btn_height, requisition.height);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b max_btn_width = MAX (max_btn_width, requisition.width);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Figure out how many rows and columns we'll use. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b btns_per_row = allocation->width / (max_btn_width + H_PADDING);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* If all the buttons could fit in the single row, have it so */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* If using text buttons, we want to try to have a
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * completely filled-in grid, but if we can't, we want
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * the odd row to have just a single button.
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Assign buttons to rows */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b rows [0] = g_slist_append (rows [0], button->button_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (g_slist_length (rows [row_number]) == btns_per_row)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b rows [row_number] = g_slist_append (rows [row_number],
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* If there are more than 1 row of buttons, save the current height
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * requirement for subsequent size requests.
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b } else { /* Otherwize clear it */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* If it turns out that we now require smaller height for the buttons
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * than it was last time, make a resize request to ensure our
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * size requisition is properly communicated to the parent (otherwise
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * parent tend to keep assuming the older size).
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (last_buttons_height > switcher->priv->buttons_height_request)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Layout the buttons. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (i = row_last; i >= 0; i --) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Check for possible size over flow (taking into account client
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * requisition
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (y < (allocation->y + client_requisition.height)) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* We have an overflow: Insufficient allocation */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (last_buttons_height < switcher->priv->buttons_height_request) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Request for a new resize */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b extra_width = (allocation->width - (len * max_btn_width )
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b child_allocation.width = max_btn_width + extra_width;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_size_allocate (GTK_WIDGET (p->data), &child_allocation);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (i = 0; i <= row_last; i ++)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkAllocation *allocation = & GTK_WIDGET (switcher)->allocation;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (y < 0) /* Layout did not happen and a resize was requested */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Place the parent widget. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* GtkContainer methods. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_forall (GtkContainer *container, gboolean include_internals,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *widget = ((Button *) p->data)->button_widget;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_remove (GtkContainer *container, GtkWidget *widget)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* GtkWidget methods. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_size_request (GtkWidget *widget, GtkRequisition *requisition)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_size_request (button->button_widget, &button_requisition);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button_width = button_requisition.width + 2 * H_PADDING;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b requisition->width = MAX (requisition->width, button_width);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b requisition->height += switcher->priv->buttons_height_request;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_expose (GtkWidget *widget, GdkEventExpose *event)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *button = ((Button *) p->data)->button_widget;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_propagate_expose (GTK_CONTAINER (widget),
456c673d721e5463a5a8d0a710e1cc920c4cac05Jon A. Cruz return GDL_CALL_PARENT_WITH_DEFAULT (GTK_WIDGET_CLASS, expose_event,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *button = ((Button *) p->data)->button_widget;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* GObject methods. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_set_style (switcher, g_value_get_enum (value));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_value_set_enum (value, gdl_switcher_get_style (switcher));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcherPrivate *priv = GDL_SWITCHER (object)->priv;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GConfClient *gconf_client = gconf_client_get_default ();
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gconf_client_notify_remove (gconf_client, priv->style_changed_id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_slist_foreach (priv->buttons, (GFunc) button_free, NULL);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GDL_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcherPrivate *priv = GDL_SWITCHER (object)->priv;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GDL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* Signal handlers */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_notify_cb (GObject *g_object, GParamSpec *pspec,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_return_if_fail (switcher != NULL && GDL_IS_SWITCHER (switcher));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b show_tabs = gtk_notebook_get_show_tabs (GTK_NOTEBOOK (switcher));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_set_show_buttons (switcher, !show_tabs);
aa99761247ff88d39faf6a989c4e06a6c5dd8e57Alex Valavanisgdl_switcher_switch_page_cb (GtkNotebook *nb, GtkWidget *page_widget,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Change switcher button */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher_id = gdl_switcher_get_page_id (page_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_select_button (GDL_SWITCHER (switcher), switcher_id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_page_added_cb (GtkNotebook *nb, GtkWidget *page,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_add_button (GDL_SWITCHER (switcher), NULL, NULL, NULL, NULL,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_select_button (GDL_SWITCHER (switcher), switcher_id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_select_page (GdlSwitcher *switcher, gint id)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b children = gtk_container_get_children (GTK_CONTAINER (switcher));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher_id = gdl_switcher_get_page_id (GTK_WIDGET (node->data));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b page_num = gtk_notebook_page_num (GTK_NOTEBOOK (switcher),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_notebook_set_current_page (GTK_NOTEBOOK (switcher), page_num);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* Initialization. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GObjectClass *object_class = G_OBJECT_CLASS (klass);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b widget_class->size_request = gdl_switcher_size_request;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b widget_class->size_allocate = gdl_switcher_size_allocate;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b object_class->set_property = gdl_switcher_set_property;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b object_class->get_property = gdl_switcher_get_property;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_param_spec_enum ("switcher-style", _("Switcher Style"),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b _("Switcher buttons style"),
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis gtk_rc_parse_string ("style \"gdl-button-style\"\n"
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis "GtkWidget::focus-padding = 1\n"
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis "GtkWidget::focus-line-width = 1\n"
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis "xthickness = 0\n"
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis "ythickness = 0\n"
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis "widget \"*.gdl-button\" style \"gdl-button-style\"");
9f32e6203d2f30a5bd17dbb294c8956b714e59e6Alex Valavanis gtk_widget_set_has_window (GTK_WIDGET (switcher), FALSE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_notebook_set_tab_pos (GTK_NOTEBOOK (switcher), GTK_POS_BOTTOM);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_notebook_set_show_tabs (GTK_NOTEBOOK (switcher), FALSE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_notebook_set_show_border (GTK_NOTEBOOK (switcher), FALSE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_set_style (switcher, GDL_SWITCHER_STYLE_BOTH);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* notebook signals */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b G_CALLBACK (gdl_switcher_switch_page_cb), switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b G_CALLBACK (gdl_switcher_page_added_cb), switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcher *switcher = g_object_new (gdl_switcher_get_type (), NULL);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_add_button (GdlSwitcher *switcher, const gchar *label,
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis gtk_widget_set_name (button_widget, "gdl-button");
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis gtk_button_set_relief (GTK_BUTTON(button_widget), GTK_RELIEF_HALF);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_add (GTK_CONTAINER (button_widget), hbox);
7a10406c7610c65f3600986ded11320fe870ccb9Alex Valavanis icon_widget = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b icon_widget = gtk_image_new_from_pixbuf (pixbuf_icon);
7a10406c7610c65f3600986ded11320fe870ccb9Alex Valavanis icon_widget = gtk_image_new_from_stock (GTK_STOCK_NEW, GTK_ICON_SIZE_MENU);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gchar *text = g_strdup_printf ("Item %d", switcher_id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (hbox), label_widget, TRUE, TRUE, 0);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (hbox), icon_widget, TRUE, TRUE, 0);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (hbox), icon_widget, FALSE, TRUE, 0);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (hbox), label_widget, TRUE, TRUE, 0);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b arrow = gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_NONE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_set_parent (button_widget, GTK_WIDGET (switcher));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_remove_button (GdlSwitcher *switcher, gint switcher_id)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_select_button (GdlSwitcher *switcher, gint switcher_id)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Select the notebook page associated with this button */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_insert_page (GdlSwitcher *switcher, GtkWidget *page,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_add_button (switcher, label, tooltips, stock_id, pixbuf_icon, switcher_id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b ret_position = gtk_notebook_insert_page (GTK_NOTEBOOK (switcher), page,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_notebook_set_show_tabs (GTK_NOTEBOOK (switcher), TRUE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_notebook_set_show_tabs (GTK_NOTEBOOK (switcher), FALSE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_remove (GTK_CONTAINER (button->hbox), button->arrow);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_remove (GTK_CONTAINER (button->hbox), button->icon);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (button->hbox), button->label,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_remove(GTK_CONTAINER (button->hbox), button->label);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (button->hbox), button->icon,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_child_set (GTK_CONTAINER (button->hbox),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_remove (GTK_CONTAINER (button->hbox),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (button->hbox), button->icon,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_child_set (GTK_CONTAINER (button->hbox),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (button->hbox), button->label, TRUE,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (button->hbox), button->arrow, FALSE,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstyle_changed_notify (GConfClient *gconf, guint id, GConfEntry *entry,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (val == NULL || !gconf_string_to_enum (toolbar_styles, val,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b set_switcher_style_internal (GDL_SWITCHER (switcher), switcher_style);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_set_style (GdlSwitcher *switcher, GdlSwitcherStyle switcher_style)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GConfClient *gconf_client = gconf_client_get_default ();
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher->priv->switcher_style == switcher_style &&
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher->priv->switcher_style == GDL_SWITCHER_STYLE_TOOLBAR) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher_style != GDL_SWITCHER_STYLE_TOOLBAR) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b set_switcher_style_internal (switcher, switcher_style);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* This is a little bit tricky, toolbar style is more
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * of a meta-style where the actual style is dictated by
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * the gnome toolbar setting, so that is why we have
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * the is_toolbar_style bool - it tracks the toolbar
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * style while the switcher_style member is the actual look and
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b style_changed_notify (gconf_client, 0, NULL, switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#else /* HAVE_GNOME */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_set_style (GdlSwitcher *switcher, GdlSwitcherStyle switcher_style)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher->priv->switcher_style == switcher_style &&
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#endif /* HAVE_GNOME */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_set_show_buttons (GdlSwitcher *switcher, gboolean show)