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
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis * This library is free software; you can redistribute it and/or
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis * modify it under the terms of the GNU Library General Public
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis * License as published by the Free Software Foundation; either
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis * version 2 of the License, or (at your option) any later version.
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis * This library 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
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis * Library General Public License for more details.
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis * You should have received a copy of the GNU Library General Public
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis * License along with this library; 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 {
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex ValavanisG_DEFINE_TYPE (GdlSwitcher, gdl_switcher, 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. */
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanisgdl_switcher_long_name_changed (GObject* object,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_object_get (object, "long-name", &label, NULL);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gtk_label_set_text (GTK_LABEL (button->label), label);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanisgdl_switcher_stock_id_changed (GObject* object,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_object_get (object, "stock-id", &id, NULL);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gtk_image_set_from_stock (GTK_IMAGE(button->icon), id, GTK_ICON_SIZE_MENU);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bbutton_new (GtkWidget *button_widget, GtkWidget *label, GtkWidget *icon,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis GtkWidget *arrow, GtkWidget *hbox, int id, GtkWidget *page)
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_signal_connect (page, "notify::long-name", G_CALLBACK (gdl_switcher_long_name_changed),
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_signal_connect (page, "notify::stock-id", G_CALLBACK (gdl_switcher_stock_id_changed),
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_signal_handlers_disconnect_by_func (button->page,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_signal_handlers_disconnect_by_func (button->page,
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 */
590e6c721a8540ebed996b273c08f35b1888426eJohan B. C. Engelen GtkRequisition client_requisition = {0,0};
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int num_btns = g_slist_length (switcher->priv->buttons);
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis gtk_widget_get_allocation (GTK_WIDGET (switcher), &allocation);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b last_buttons_height = switcher->priv->buttons_height_request;
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GTK_WIDGET_CLASS (gdl_switcher_parent_class)->size_request (GTK_WIDGET (switcher), &client_requisition);
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis 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. */
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis btns_per_row = allocation.width / (max_btn_width + H_PADDING);
d33f1f862d884340d7bbf1aeee9216b83966ef8fAlex Valavanis /* Use at least one column */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* If all the buttons could fit in the single row, have it so */
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis if (allocation.width >= optimal_layout_width)
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)
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen /* Layout the buttons. */
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen for (i = row_last; i >= 0; i --) {
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen /* Check for possible size over flow (taking into account client
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen if (y < (allocation.y + client_requisition.height)) {
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen /* We have an overflow: Insufficient allocation */
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen if (last_buttons_height < switcher->priv->buttons_height_request) {
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen /* Request for a new resize */
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen gtk_widget_queue_resize (GTK_WIDGET (switcher));
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen if (switcher_style == GDL_SWITCHER_STYLE_TEXT ||
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen switcher_style == GDL_SWITCHER_STYLE_BOTH)
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen extra_width = (allocation.width - (len * max_btn_width )
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen for (p = rows [i]; p != NULL; p = p->next) {
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen gtk_widget_size_request (GTK_WIDGET (p->data),
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen child_allocation.width = child_requisition.width;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen child_allocation.width = max_btn_width + extra_width;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen child_allocation.height = max_btn_height;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen gtk_widget_size_allocate (GTK_WIDGET (p->data), &child_allocation);
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen x += child_allocation.width + H_PADDING;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen for (i = 0; i <= row_last; i ++) {
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis gtk_widget_get_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. */
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GTK_WIDGET_CLASS (gdl_switcher_parent_class)->size_allocate (GTK_WIDGET (switcher), &child_allocation);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* GtkContainer methods. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_forall (GtkContainer *container, gboolean include_internals,
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GTK_CONTAINER_CLASS (gdl_switcher_parent_class)->forall (GTK_CONTAINER (switcher),
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) {
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GTK_CONTAINER_CLASS (gdl_switcher_parent_class)->remove (GTK_CONTAINER (switcher), widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* GtkWidget methods. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_size_request (GtkWidget *widget, GtkRequisition *requisition)
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GTK_WIDGET_CLASS (gdl_switcher_parent_class)->size_request (GTK_WIDGET (switcher), 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)
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis gtk_widget_set_allocation (widget, 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),
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis return GTK_WIDGET_CLASS (gdl_switcher_parent_class)->expose_event (widget, event);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *button = ((Button *) p->data)->button_widget;
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GTK_WIDGET_CLASS (gdl_switcher_parent_class)->map (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);
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis G_OBJECT_CLASS (gdl_switcher_parent_class)->dispose (object);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcherPrivate *priv = GDL_SWITCHER (object)->priv;
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis G_OBJECT_CLASS (gdl_switcher_parent_class)->finalize (object);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* Signal handlers */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_notify_cb (GObject *g_object, GParamSpec *pspec,
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,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gdl_switcher_add_button (switcher, label, tooltips, stock_id, pixbuf_icon, switcher_id, page);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b ret_position = gtk_notebook_insert_page (GTK_NOTEBOOK (switcher), page,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanisset_switcher_style_toolbar (GdlSwitcher *switcher,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis if (switcher_style == GDL_SWITCHER_STYLE_NONE
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis || switcher_style == GDL_SWITCHER_STYLE_TABS)
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis if (switcher_style == GDL_SWITCHER_STYLE_TOOLBAR)
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis 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);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_container_remove (GTK_CONTAINER (button->hbox), button->icon);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_container_remove (GTK_CONTAINER (button->hbox), button->label);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_box_pack_start (GTK_BOX (button->hbox), button->label,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_box_pack_start (GTK_BOX (button->hbox), button->icon,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_box_pack_start (GTK_BOX (button->hbox), button->icon,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_box_pack_start (GTK_BOX (button->hbox), button->label,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_box_pack_start (GTK_BOX (button->hbox), button->arrow,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gdl_switcher_set_show_buttons (switcher, TRUE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_set_style (GdlSwitcher *switcher, GdlSwitcherStyle switcher_style)
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis if (switcher->priv->switcher_style == switcher_style)
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis if (switcher_style == GDL_SWITCHER_STYLE_NONE) {
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gdl_switcher_set_show_buttons (switcher, FALSE);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_notebook_set_show_tabs (GTK_NOTEBOOK (switcher), FALSE);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis else if (switcher_style == GDL_SWITCHER_STYLE_TABS) {
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gdl_switcher_set_show_buttons (switcher, FALSE);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_notebook_set_show_tabs (GTK_NOTEBOOK (switcher), TRUE);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis set_switcher_style_toolbar (switcher, switcher_style);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis switcher->priv->switcher_style = switcher_style;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_set_show_buttons (GdlSwitcher *switcher, gboolean show)