a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* gdl-switcher.c
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b *
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * Copyright (C) 2003 Ettore Perazzoli,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * 2007 Naba Kumar
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b *
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.
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b *
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.
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b *
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 *
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis *
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * Copied and adapted from ESidebar.[ch] from evolution
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b *
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * Authors: Ettore Perazzoli <ettore@ximian.com>
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * Naba Kumar <naba@gnome.org>
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#ifdef HAVE_CONFIG_H
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#include <config.h>
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#endif
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#include "gdl-i18n.h"
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#include "gdl-switcher.h"
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#include "libgdlmarshal.h"
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#include "libgdltypebuiltins.h"
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#include <gtk/gtk.h>
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void gdl_switcher_set_property (GObject *object,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b guint prop_id,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b const GValue *value,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GParamSpec *pspec);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void gdl_switcher_get_property (GObject *object,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b guint prop_id,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GValue *value,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GParamSpec *pspec);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void gdl_switcher_add_button (GdlSwitcher *switcher,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b const gchar *label,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b const gchar *tooltips,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b const gchar *stock_id,
51d360771338a88b41d6eb121c945f6655eaee7eAlex Valavanis GdkPixbuf *pixbuf_icon,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gint switcher_id,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis GtkWidget *page);
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_b GdlSwitcherStyle switcher_style);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic GdlSwitcherStyle gdl_switcher_get_style (GdlSwitcher *switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_benum {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b PROP_0,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b PROP_SWITCHER_STYLE
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b};
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_btypedef struct {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *button_widget;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *label;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *icon;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *arrow;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *hbox;
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis GtkWidget *page;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int id;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b} Button;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstruct _GdlSwitcherPrivate {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcherStyle switcher_style;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcherStyle toolbar_style;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gboolean show;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GSList *buttons;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b guint style_changed_id;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint buttons_height_request;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gboolean in_toggle;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b};
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex ValavanisG_DEFINE_TYPE (GdlSwitcher, gdl_switcher, GTK_TYPE_NOTEBOOK)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#define INTERNAL_MODE(switcher) (switcher->priv->switcher_style == \
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GDL_SWITCHER_STYLE_TOOLBAR ? switcher->priv->toolbar_style : \
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher->priv->switcher_style)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#define H_PADDING 2
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#define V_PADDING 2
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* Utility functions. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanisstatic void
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanisgdl_switcher_long_name_changed (GObject* object,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis GParamSpec* spec,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gpointer user_data)
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis{
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis Button* button = user_data;
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gchar* label;
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_object_get (object, "long-name", &label, NULL);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gtk_label_set_text (GTK_LABEL (button->label), label);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_free (label);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis}
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanisstatic void
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanisgdl_switcher_stock_id_changed (GObject* object,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis GParamSpec* spec,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gpointer user_data)
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis{
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis Button* button = user_data;
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gchar* id;
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis
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);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_free (id);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis}
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic Button *
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bbutton_new (GtkWidget *button_widget, GtkWidget *label, GtkWidget *icon,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis GtkWidget *arrow, GtkWidget *hbox, int id, GtkWidget *page)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b Button *button = g_new (Button, 1);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button->button_widget = button_widget;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button->label = label;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button->icon = icon;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button->arrow = arrow;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button->hbox = hbox;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button->id = id;
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis button->page = page;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_signal_connect (page, "notify::long-name", G_CALLBACK (gdl_switcher_long_name_changed),
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis button);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_signal_connect (page, "notify::stock-id", G_CALLBACK (gdl_switcher_stock_id_changed),
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis button);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_ref (button_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_ref (label);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_ref (icon);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_ref (arrow);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_ref (hbox);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return button;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bbutton_free (Button *button)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_signal_handlers_disconnect_by_func (button->page,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gdl_switcher_long_name_changed,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis button);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis g_signal_handlers_disconnect_by_func (button->page,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gdl_switcher_stock_id_changed,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis button);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_unref (button->button_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_unref (button->label);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_unref (button->icon);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_unref (button->hbox);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_free (button);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic gint
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_get_page_id (GtkWidget *widget)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b static gint switcher_id_count = 0;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint switcher_id;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b "__switcher_id"));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher_id <= 0) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher_id = ++switcher_id_count;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_set_data (G_OBJECT (widget), "__switcher_id",
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GINT_TO_POINTER (switcher_id));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return switcher_id;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bupdate_buttons (GdlSwitcher *switcher, int new_selected_id)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GSList *p;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher->priv->in_toggle = TRUE;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b Button *button = p->data;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (button->id == new_selected_id) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b (button->button_widget), TRUE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_set_sensitive (button->arrow, TRUE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b } else {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b (button->button_widget), FALSE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_set_sensitive (button->arrow, FALSE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher->priv->in_toggle = FALSE;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* Callbacks. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bbutton_toggled_callback (GtkToggleButton *toggle_button,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcher *switcher)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int id = 0;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gboolean is_active = FALSE;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GSList *p;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher->priv->in_toggle)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher->priv->in_toggle = TRUE;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (gtk_toggle_button_get_active (toggle_button))
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b is_active = TRUE;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b Button *button = p->data;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (button->button_widget != GTK_WIDGET (toggle_button)) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b (button->button_widget), FALSE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_set_sensitive (button->arrow, FALSE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b } else {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b (button->button_widget), TRUE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_set_sensitive (button->arrow, TRUE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b id = button->id;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher->priv->in_toggle = FALSE;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (is_active)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_select_page (switcher, id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* Returns -1 if layout didn't happen because a resize request was queued */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic int
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_blayout_buttons (GdlSwitcher *switcher)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
590e6c721a8540ebed996b273c08f35b1888426eJohan B. C. Engelen GtkRequisition client_requisition = {0,0};
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GtkAllocation allocation;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcherStyle switcher_style;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gboolean icons_only;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int num_btns = g_slist_length (switcher->priv->buttons);
590e6c721a8540ebed996b273c08f35b1888426eJohan B. C. Engelen unsigned int btns_per_row;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GSList **rows, *p;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b Button *button;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int row_number;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int max_btn_width = 0, max_btn_height = 0;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int optimal_layout_width = 0;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int row_last;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int x, y;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int i;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int rows_count;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int last_buttons_height;
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis gtk_widget_get_allocation (GTK_WIDGET (switcher), &allocation);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b last_buttons_height = switcher->priv->buttons_height_request;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GTK_WIDGET_CLASS (gdl_switcher_parent_class)->size_request (GTK_WIDGET (switcher), &client_requisition);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis y = allocation.y + allocation.height - V_PADDING - 1;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (num_btns == 0)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return y;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher_style = INTERNAL_MODE (switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b icons_only = (switcher_style == GDL_SWITCHER_STYLE_ICON);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Figure out the max width and height */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b optimal_layout_width = H_PADDING;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkRequisition requisition;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button = p->data;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_size_request (GTK_WIDGET (button->button_widget),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b &requisition);
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 }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
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 */
d33f1f862d884340d7bbf1aeee9216b83966ef8fAlex Valavanis if (btns_per_row == 0) btns_per_row = 1;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
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 {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b btns_per_row = num_btns;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (!icons_only) {
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 */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b while (num_btns % btns_per_row > 1)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b btns_per_row--;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b rows_count = num_btns / btns_per_row;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (num_btns % btns_per_row != 0)
9da72320667347f97b641753dd3b4591f95df939Alex Valavanis rows_count++;
9da72320667347f97b641753dd3b4591f95df939Alex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Assign buttons to rows */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b rows = g_new0 (GSList *, rows_count);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (!icons_only && num_btns % btns_per_row != 0) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button = switcher->priv->buttons->data;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b rows [0] = g_slist_append (rows [0], button->button_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b p = switcher->priv->buttons->next;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b row_number = p ? 1 : 0;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b } else {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b p = switcher->priv->buttons;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b row_number = 0;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button = p->data;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (g_slist_length (rows [row_number]) == btns_per_row)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b row_number ++;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b rows [row_number] = g_slist_append (rows [row_number],
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button->button_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b row_last = row_number;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* If there are more than 1 row of buttons, save the current height
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b * requirement for subsequent size requests.
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (row_last > 0)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher->priv->buttons_height_request =
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b (row_last + 1) * (max_btn_height + V_PADDING) + 1;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b } else { /* Otherwize clear it */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (last_buttons_height >= 0) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher->priv->buttons_height_request = -1;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
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 */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (last_buttons_height > switcher->priv->buttons_height_request)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_queue_resize (GTK_WIDGET (switcher));
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen y = -1; // set return value
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen else
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen {
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen /* Layout the buttons. */
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen for (i = row_last; i >= 0; i --) {
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen int len, extra_width;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen y -= max_btn_height;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen /* Check for possible size over flow (taking into account client
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen * requisition
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen */
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));
6aa6fc2eb657525c1082b349450b7b270aab29a1Johan B. C. Engelen y = -1; // set return value
6aa6fc2eb657525c1082b349450b7b270aab29a1Johan B. C. Engelen goto exit;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen x = H_PADDING + allocation.x;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen len = g_slist_length (rows[i]);
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 - (len * H_PADDING)) / len;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b else
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen extra_width = 0;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen for (p = rows [i]; p != NULL; p = p->next) {
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen GtkAllocation child_allocation;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen child_allocation.x = x;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen child_allocation.y = y;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen if (rows_count == 1 && row_number == 0)
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen {
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen GtkRequisition child_requisition;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen gtk_widget_size_request (GTK_WIDGET (p->data),
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen &child_requisition);
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen child_allocation.width = child_requisition.width;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen }
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen else
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen {
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen child_allocation.width = max_btn_width + extra_width;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen }
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen child_allocation.height = max_btn_height;
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen gtk_widget_size_allocate (GTK_WIDGET (p->data), &child_allocation);
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen x += child_allocation.width + H_PADDING;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen y -= V_PADDING;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen
6aa6fc2eb657525c1082b349450b7b270aab29a1Johan B. C. Engelen exit:
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen for (i = 0; i <= row_last; i ++) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_slist_free (rows [i]);
f78135cb8a189cf99c5c76295edca9d7465d3b63Johan B. C. Engelen }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_free (rows);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return y;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bdo_layout (GdlSwitcher *switcher)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GtkAllocation allocation;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkAllocation child_allocation;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b int y;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis gtk_widget_get_allocation (GTK_WIDGET (switcher), &allocation);
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher->priv->show) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b y = layout_buttons (switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (y < 0) /* Layout did not happen and a resize was requested */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b else
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis y = allocation.y + allocation.height;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Place the parent widget. */
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis child_allocation.x = allocation.x;
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis child_allocation.y = allocation.y;
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis child_allocation.width = allocation.width;
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis child_allocation.height = y - allocation.y;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GTK_WIDGET_CLASS (gdl_switcher_parent_class)->size_allocate (GTK_WIDGET (switcher), &child_allocation);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* GtkContainer methods. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_forall (GtkContainer *container, gboolean include_internals,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkCallback callback, void *callback_data)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcher *switcher =
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GDL_SWITCHER (container);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GSList *p;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GTK_CONTAINER_CLASS (gdl_switcher_parent_class)->forall (GTK_CONTAINER (switcher),
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis include_internals,
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis callback, callback_data);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (include_internals) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *widget = ((Button *) p->data)->button_widget;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b (* callback) (widget, callback_data);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_remove (GtkContainer *container, GtkWidget *widget)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint switcher_id;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcher *switcher =
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GDL_SWITCHER (container);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GSList *p;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher_id = gdl_switcher_get_page_id (widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b Button *b = (Button *) p->data;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (b->id == switcher_id) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_unparent (b->button_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher->priv->buttons =
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_slist_remove_link (switcher->priv->buttons, p);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button_free (b);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_queue_resize (GTK_WIDGET (switcher));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GTK_CONTAINER_CLASS (gdl_switcher_parent_class)->remove (GTK_CONTAINER (switcher), widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* GtkWidget methods. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_size_request (GtkWidget *widget, GtkRequisition *requisition)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcher *switcher = GDL_SWITCHER (widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GSList *p;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint button_height = 0;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GTK_WIDGET_CLASS (gdl_switcher_parent_class)->size_request (GTK_WIDGET (switcher), requisition);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (!switcher->priv->show)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint button_width;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b Button *button = p->data;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkRequisition button_requisition;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
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 button_height = MAX (button_height,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button_requisition.height + 2 * V_PADDING);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher->priv->buttons_height_request > 0) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b requisition->height += switcher->priv->buttons_height_request;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b } else {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b requisition->height += button_height + V_PADDING;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis gtk_widget_set_allocation (widget, allocation);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b do_layout (GDL_SWITCHER (widget));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic gint
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_expose (GtkWidget *widget, GdkEventExpose *event)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GSList *p;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcher *switcher = GDL_SWITCHER (widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher->priv->show) {
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),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button, event);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis return GTK_WIDGET_CLASS (gdl_switcher_parent_class)->expose_event (widget, event);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_map (GtkWidget *widget)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GSList *p;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcher *switcher = GDL_SWITCHER (widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher->priv->show) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *button = ((Button *) p->data)->button_widget;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_map (button);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis GTK_WIDGET_CLASS (gdl_switcher_parent_class)->map (widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* GObject methods. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_set_property (GObject *object,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b guint prop_id,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b const GValue *value,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GParamSpec *pspec)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcher *switcher = GDL_SWITCHER (object);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switch (prop_id) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b case PROP_SWITCHER_STYLE:
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_set_style (switcher, g_value_get_enum (value));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b default:
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_get_property (GObject *object,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b guint prop_id,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GValue *value,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GParamSpec *pspec)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcher *switcher = GDL_SWITCHER (object);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switch (prop_id) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b case PROP_SWITCHER_STYLE:
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_value_set_enum (value, gdl_switcher_get_style (switcher));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b default:
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_dispose (GObject *object)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcherPrivate *priv = GDL_SWITCHER (object)->priv;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#if HAVE_GNOME
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GConfClient *gconf_client = gconf_client_get_default ();
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (priv->style_changed_id) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gconf_client_notify_remove (gconf_client, priv->style_changed_id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b priv->style_changed_id = 0;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_unref (gconf_client);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b#endif
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_slist_foreach (priv->buttons, (GFunc) button_free, NULL);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_slist_free (priv->buttons);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b priv->buttons = NULL;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis G_OBJECT_CLASS (gdl_switcher_parent_class)->dispose (object);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_finalize (GObject *object)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcherPrivate *priv = GDL_SWITCHER (object)->priv;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_free (priv);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanis G_OBJECT_CLASS (gdl_switcher_parent_class)->finalize (object);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* Signal handlers */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_notify_cb (GObject *g_object, GParamSpec *pspec,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcher *switcher)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
aa99761247ff88d39faf6a989c4e06a6c5dd8e57Alex Valavanisgdl_switcher_switch_page_cb (GtkNotebook *nb, GtkWidget *page_widget,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint page_num, GdlSwitcher *switcher)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint switcher_id;
9da72320667347f97b641753dd3b4591f95df939Alex Valavanis
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_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_page_added_cb (GtkNotebook *nb, GtkWidget *page,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint page_num, GdlSwitcher *switcher)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint switcher_id;
031bc7c8466696f17530077ee74a3a983df28f3eJon A. Cruz
031bc7c8466696f17530077ee74a3a983df28f3eJon A. Cruz (void)nb;
031bc7c8466696f17530077ee74a3a983df28f3eJon A. Cruz (void)page_num;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher_id = gdl_switcher_get_page_id (page);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_add_button (GDL_SWITCHER (switcher), NULL, NULL, NULL, NULL,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis switcher_id, page);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_select_button (GDL_SWITCHER (switcher), switcher_id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_select_page (GdlSwitcher *switcher, gint id)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GList *children, *node;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b children = gtk_container_get_children (GTK_CONTAINER (switcher));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b node = children;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b while (node)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint switcher_id;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher_id = gdl_switcher_get_page_id (GTK_WIDGET (node->data));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher_id == id)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint page_num;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b page_num = gtk_notebook_page_num (GTK_NOTEBOOK (switcher),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GTK_WIDGET (node->data));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_signal_handlers_block_by_func (switcher,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_switch_page_cb,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_notebook_set_current_page (GTK_NOTEBOOK (switcher), page_num);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_signal_handlers_unblock_by_func (switcher,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_switch_page_cb,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b node = g_list_next (node);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_list_free (children);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b/* Initialization. */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_class_init (GdlSwitcherClass *klass)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
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
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b container_class->forall = gdl_switcher_forall;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b container_class->remove = gdl_switcher_remove;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b widget_class->size_request = gdl_switcher_size_request;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b widget_class->size_allocate = gdl_switcher_size_allocate;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b widget_class->expose_event = gdl_switcher_expose;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b widget_class->map = gdl_switcher_map;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b object_class->dispose = gdl_switcher_dispose;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b object_class->finalize = gdl_switcher_finalize;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b object_class->set_property = gdl_switcher_set_property;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b object_class->get_property = gdl_switcher_get_property;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_object_class_install_property (
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b object_class, PROP_SWITCHER_STYLE,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_param_spec_enum ("switcher-style", _("Switcher Style"),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b _("Switcher buttons style"),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GDL_TYPE_SWITCHER_STYLE,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GDL_SWITCHER_STYLE_BOTH,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b G_PARAM_READWRITE));
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis gtk_rc_parse_string ("style \"gdl-button-style\"\n"
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis "{\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 "}\n"
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis "widget \"*.gdl-button\" style \"gdl-button-style\"");
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
d19de0ff8b0793e74e98429ded50868ce7e9f75cAlex Valavanisgdl_switcher_init (GdlSwitcher *switcher)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcherPrivate *priv;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
9f32e6203d2f30a5bd17dbb294c8956b714e59e6Alex Valavanis gtk_widget_set_has_window (GTK_WIDGET (switcher), FALSE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b priv = g_new0 (GdlSwitcherPrivate, 1);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher->priv = priv;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b priv->show = TRUE;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b priv->buttons_height_request = -1;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
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
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* notebook signals */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_signal_connect (switcher, "switch-page",
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b G_CALLBACK (gdl_switcher_switch_page_cb), switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_signal_connect (switcher, "page-added",
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b G_CALLBACK (gdl_switcher_page_added_cb), switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_signal_connect (switcher, "notify::show-tabs",
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b G_CALLBACK (gdl_switcher_notify_cb), switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bGtkWidget *
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_new (void)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GdlSwitcher *switcher = g_object_new (gdl_switcher_get_type (), NULL);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return GTK_WIDGET (switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
51d360771338a88b41d6eb121c945f6655eaee7eAlex Valavanisstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_add_button (GdlSwitcher *switcher, const gchar *label,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b const gchar *tooltips, const gchar *stock_id,
51d360771338a88b41d6eb121c945f6655eaee7eAlex Valavanis GdkPixbuf *pixbuf_icon,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gint switcher_id, GtkWidget* page)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *button_widget;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *hbox;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *icon_widget;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *label_widget;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *arrow;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button_widget = gtk_toggle_button_new ();
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 if (switcher->priv->show)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_show (button_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_signal_connect (button_widget, "toggled",
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b G_CALLBACK (button_toggled_callback),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b hbox = gtk_hbox_new (FALSE, 3);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_add (GTK_CONTAINER (button_widget), hbox);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_show (hbox);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
031bc7c8466696f17530077ee74a3a983df28f3eJon A. Cruz if (stock_id) {
7a10406c7610c65f3600986ded11320fe870ccb9Alex Valavanis icon_widget = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
031bc7c8466696f17530077ee74a3a983df28f3eJon A. Cruz } else if (pixbuf_icon) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b icon_widget = gtk_image_new_from_pixbuf (pixbuf_icon);
031bc7c8466696f17530077ee74a3a983df28f3eJon A. Cruz } else {
7a10406c7610c65f3600986ded11320fe870ccb9Alex Valavanis icon_widget = gtk_image_new_from_stock (GTK_STOCK_NEW, GTK_ICON_SIZE_MENU);
031bc7c8466696f17530077ee74a3a983df28f3eJon A. Cruz }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_show (icon_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (!label) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gchar *text = g_strdup_printf ("Item %d", switcher_id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b label_widget = gtk_label_new (text);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_free (text);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b } else {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b label_widget = gtk_label_new (label);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_show (label_widget);
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis gtk_widget_set_tooltip_text (button_widget,
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis tooltips);
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switch (INTERNAL_MODE (switcher)) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b case GDL_SWITCHER_STYLE_TEXT:
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (hbox), label_widget, TRUE, TRUE, 0);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b case GDL_SWITCHER_STYLE_ICON:
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (hbox), icon_widget, TRUE, TRUE, 0);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b case GDL_SWITCHER_STYLE_BOTH:
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b default:
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 break;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b arrow = gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_NONE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_show (arrow);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_box_pack_start (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher->priv->buttons =
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_slist_append (switcher->priv->buttons,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button_new (button_widget, label_widget,
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis icon_widget,
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis arrow, hbox, switcher_id, page));
d6b764cc205f348b6d2398edd654e8a9684f5dadAlex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_set_parent (button_widget, GTK_WIDGET (switcher));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_queue_resize (GTK_WIDGET (switcher));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
7a10406c7610c65f3600986ded11320fe870ccb9Alex Valavanis#if 0
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_remove_button (GdlSwitcher *switcher, gint switcher_id)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GSList *p;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b Button *button = p->data;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (button->id == switcher_id)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_remove (GTK_CONTAINER (switcher),
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b button->button_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_queue_resize (GTK_WIDGET (switcher));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
7a10406c7610c65f3600986ded11320fe870ccb9Alex Valavanis#endif
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_select_button (GdlSwitcher *switcher, gint switcher_id)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b update_buttons (switcher, switcher_id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b /* Select the notebook page associated with this button */
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_select_page (switcher, switcher_id);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgint
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_insert_page (GdlSwitcher *switcher, GtkWidget *page,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GtkWidget *tab_widget, const gchar *label,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b const gchar *tooltips, const gchar *stock_id,
51d360771338a88b41d6eb121c945f6655eaee7eAlex Valavanis GdkPixbuf *pixbuf_icon, gint position)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint ret_position;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gint switcher_id;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_signal_handlers_block_by_func (switcher,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_page_added_cb,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (!tab_widget) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b tab_widget = gtk_label_new (label);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_show (tab_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher_id = gdl_switcher_get_page_id (page);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis gdl_switcher_add_button (switcher, label, tooltips, stock_id, pixbuf_icon, switcher_id, page);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b ret_position = gtk_notebook_insert_page (GTK_NOTEBOOK (switcher), page,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b tab_widget, position);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b g_signal_handlers_unblock_by_func (switcher,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gdl_switcher_page_added_cb,
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher);
f6d8c168c2d1b1e168545b090dfbb22a3f4923a3Alex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return ret_position;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanisset_switcher_style_toolbar (GdlSwitcher *switcher,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis GdlSwitcherStyle switcher_style)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GSList *p;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis if (switcher_style == GDL_SWITCHER_STYLE_NONE
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis || switcher_style == GDL_SWITCHER_STYLE_TABS)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis if (switcher_style == GDL_SWITCHER_STYLE_TOOLBAR)
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis switcher_style = GDL_SWITCHER_STYLE_BOTH;
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher_style == INTERNAL_MODE (switcher))
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return;
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_notebook_set_show_tabs (GTK_NOTEBOOK (switcher), FALSE);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b Button *button = p->data;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_container_remove (GTK_CONTAINER (button->hbox), button->arrow);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis if (gtk_widget_get_parent (button->icon))
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_container_remove (GTK_CONTAINER (button->hbox), button->icon);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis if (gtk_widget_get_parent (button->label))
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_container_remove (GTK_CONTAINER (button->hbox), button->label);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switch (switcher_style) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b case GDL_SWITCHER_STYLE_TEXT:
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_box_pack_start (GTK_BOX (button->hbox), button->label,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis TRUE, TRUE, 0);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_widget_show (button->label);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b case GDL_SWITCHER_STYLE_ICON:
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_box_pack_start (GTK_BOX (button->hbox), button->icon,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis TRUE, TRUE, 0);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_widget_show (button->icon);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis case GDL_SWITCHER_STYLE_BOTH:
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_box_pack_start (GTK_BOX (button->hbox), button->icon,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis FALSE, TRUE, 0);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_box_pack_start (GTK_BOX (button->hbox), button->label,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis TRUE, TRUE, 0);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_widget_show (button->icon);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_show (button->label);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b default:
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b break;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gtk_box_pack_start (GTK_BOX (button->hbox), button->arrow,
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis FALSE, FALSE, 0);
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis gdl_switcher_set_show_buttons (switcher, TRUE);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_set_style (GdlSwitcher *switcher, GdlSwitcherStyle switcher_style)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis if (switcher->priv->switcher_style == switcher_style)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
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);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
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);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis else
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis set_switcher_style_toolbar (switcher, switcher_style);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_queue_resize (GTK_WIDGET (switcher));
2eefc362ae6a0a94b84ee5bc9e7844ef45c3642cAlex Valavanis switcher->priv->switcher_style = switcher_style;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic void
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_set_show_buttons (GdlSwitcher *switcher, gboolean show)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b GSList *p;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (switcher->priv->show == show)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b for (p = switcher->priv->buttons; p != NULL; p = p->next) {
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b Button *button = p->data;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (show)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_show (button->button_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b else
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_hide (button->button_widget);
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b }
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b switcher->priv->show = show;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b gtk_widget_queue_resize (GTK_WIDGET (switcher));
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bstatic GdlSwitcherStyle
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_bgdl_switcher_get_style (GdlSwitcher *switcher)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b{
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b if (!switcher->priv->show)
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return GDL_SWITCHER_STYLE_TABS;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b return switcher->priv->switcher_style;
a0df1b8dd5b14367c583ce2f72a2ca6bf1cde799gustav_b}