xfburn-notebook-tab.c 6.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
/*
 *  Copyright (c) 2005-2006 Jean-François Wauthy (pollux@xfce.org)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifdef	HAVE_CONFIG_H
#include <config.h>
#endif /* !HAVE_CONFIG_H */

#include <gtk/gtk.h>

#include <libxfce4util/libxfce4util.h>

#include "xfburn-notebook-tab.h"

#define XFBURN_NOTEBOOK_TAB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), XFBURN_TYPE_NOTEBOOK_TAB, XfburnNotebookTabPrivate))

enum {
  BUTTON_CLOSE_CLICKED,
  LAST_SIGNAL,
};

enum {
  PROP_0,
  PROP_LABEL,
  PROP_SHOW_BUTTON_CLOSE,
};

/* private members */
typedef struct
{
  GtkWidget *label;
  GtkWidget *button_close;
} XfburnNotebookTabPrivate;


/* prototypes */
static void xfburn_notebook_tab_class_init (XfburnNotebookTabClass * klass);
static void xfburn_notebook_tab_init (XfburnNotebookTab * tab);
static void xfburn_notebook_tab_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
static void xfburn_notebook_tab_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);

static void cb_composition_close (GtkButton *button, XfburnNotebookTab *tab);

/* static member */
static GtkHBoxClass *parent_class = NULL;
static guint notebook_tab_signals[LAST_SIGNAL];

/************************/
/* class initiliazation */
/************************/
GType
xfburn_notebook_tab_get_type (void)
{
  static GType type = 0;

  if (type == 0) {
    static const GTypeInfo our_info = {
      sizeof (XfburnNotebookTabClass),
      NULL,
      NULL,
      (GClassInitFunc) xfburn_notebook_tab_class_init,
      NULL,
      NULL,
      sizeof (XfburnNotebookTab),
      0,
      (GInstanceInitFunc) xfburn_notebook_tab_init,
      NULL
    };

    type = g_type_register_static (GTK_TYPE_HBOX, "XfburnNotebookTab", &our_info, 0);
  }

  return type;
}

static void
xfburn_notebook_tab_class_init (XfburnNotebookTabClass * klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  g_type_class_add_private (klass, sizeof (XfburnNotebookTabPrivate));

  parent_class = g_type_class_peek_parent (klass);
  
  object_class->set_property = xfburn_notebook_tab_set_property;
  object_class->get_property = xfburn_notebook_tab_get_property;
  
  notebook_tab_signals[BUTTON_CLOSE_CLICKED] = g_signal_new ("button-close-clicked",
                                                             G_TYPE_FROM_CLASS (object_class), G_SIGNAL_ACTION,
                                                             G_STRUCT_OFFSET (XfburnNotebookTabClass, button_close_clicked),
                                                             NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
  
  g_object_class_install_property (object_class, PROP_LABEL, 
                                   g_param_spec_string ("label", _("Label"), _("The text of the label"), 
                                                        NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
  g_object_class_install_property (object_class, PROP_SHOW_BUTTON_CLOSE, 
                                   g_param_spec_boolean ("show-button-close", _("Show close button"), _("Determine whether the close button is visible"), 
                                                        TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}

static void
xfburn_notebook_tab_init (XfburnNotebookTab * tab)
{
  XfburnNotebookTabPrivate *priv = XFBURN_NOTEBOOK_TAB_GET_PRIVATE (tab);
  GtkBox *hbox = GTK_BOX (tab);
  GtkWidget *img;
  
  priv->label = gtk_label_new ("");
  gtk_widget_show (priv->label);
  gtk_box_pack_start (hbox, priv->label, TRUE, TRUE, 0);
    
  priv->button_close = gtk_button_new ();
  gtk_button_set_relief (GTK_BUTTON (priv->button_close), GTK_RELIEF_NONE);
  gtk_widget_show (priv->button_close);
	
  img = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
  gtk_widget_show (img);
  gtk_container_add (GTK_CONTAINER (priv->button_close), img);
  gtk_box_pack_start (hbox, priv->button_close, FALSE, FALSE, 0);

  g_signal_connect (G_OBJECT (priv->button_close), "clicked", G_CALLBACK (cb_composition_close), tab);
}

static void
xfburn_notebook_tab_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
  XfburnNotebookTabPrivate *priv = XFBURN_NOTEBOOK_TAB_GET_PRIVATE (object);

  switch (prop_id) {
  case PROP_LABEL:
    g_value_set_string (value, gtk_label_get_text (GTK_LABEL (priv->label)));
    break;
  case PROP_SHOW_BUTTON_CLOSE:
    g_object_get_property (G_OBJECT (priv->button_close), "visible", value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    break;
  }
}

static void
xfburn_notebook_tab_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
  XfburnNotebookTabPrivate *priv = XFBURN_NOTEBOOK_TAB_GET_PRIVATE (object);
  
  switch (prop_id) {
  case PROP_LABEL:
    gtk_label_set_text (GTK_LABEL (priv->label), g_value_get_string (value));
    break;
  case PROP_SHOW_BUTTON_CLOSE:
    if (g_value_get_boolean (value))
      gtk_widget_show (priv->button_close);
    else
      gtk_widget_hide (priv->button_close);
	
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    break;
  }
}
                                          
/*************/
/* internals */
/*************/
static void
cb_composition_close (GtkButton *button, XfburnNotebookTab *tab)
{
  g_signal_emit (G_OBJECT (tab), notebook_tab_signals[BUTTON_CLOSE_CLICKED], 0);
}

/**********/
/* public */
/**********/
GtkWidget *
xfburn_notebook_tab_new (const gchar *label, gboolean show_button_close)
{
  GtkWidget *obj;

  obj = GTK_WIDGET (g_object_new (XFBURN_TYPE_NOTEBOOK_TAB, "homogeneous", FALSE, 
				  "label", label, "show-button-close", show_button_close, NULL));

  return obj;
}

void
xfburn_notebook_tab_set_label (XfburnNotebookTab *tab, const gchar *label)
{
  XfburnNotebookTabPrivate *priv = XFBURN_NOTEBOOK_TAB_GET_PRIVATE (tab);
  
  gtk_label_set_text (GTK_LABEL (priv->label), label);
}

void
xfburn_notebook_tab_show_button_close (XfburnNotebookTab *tab)
{
  XfburnNotebookTabPrivate *priv = XFBURN_NOTEBOOK_TAB_GET_PRIVATE (tab);
  
  gtk_widget_show (priv->button_close);
}

void
xfburn_notebook_tab_show_button_hide (XfburnNotebookTab *tab)
{
  XfburnNotebookTabPrivate *priv = XFBURN_NOTEBOOK_TAB_GET_PRIVATE (tab);
  
  gtk_widget_hide (priv->button_close);
}