Commit 9b1a0871 authored by Ramiro Estrugo's avatar Ramiro Estrugo

Adding nautilus-widgets to the tree - a place to put generic widgets that are

not necessarily coupled to nautilus.
parent 852b8ec5
SUBDIRS=libnautilus src components icons
SUBDIRS =\
libnautilus \
nautilus-widgets \
src \
components \
icons
EXTRA_DIST=COPYING.LIB
......@@ -138,6 +138,7 @@ icons/Makefile
icons/eazel/Makefile
idl/Makefile
libnautilus/Makefile
nautilus-widgets/Makefile
src/Makefile
src/file-manager/Makefile
components/Makefile
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-radio-button-group.c - A radio button group container.
Copyright (C) 1999, 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library 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 Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Ramiro Estrugo <ramiro@eazel.com>
*/
#include <nautilus-widgets/nautilus-radio-button-group.h>
#include <gtk/gtkradiobutton.h>
#include <gtk/gtksignal.h>
#include <libnautilus/nautilus-gtk-macros.h>
static const gint RADIO_BUTTON_GROUP_INVALID = -1;
/* Signals */
typedef enum
{
CHANGED,
LAST_SIGNAL
} RadioGroupSignals;
struct _NautilusRadioButtonGroupDetails
{
GList *buttons;
GSList *group;
};
/* NautilusRadioButtonGroupClass methods */
static void nautilus_radio_button_group_initialize_class (NautilusRadioButtonGroupClass *klass);
static void nautilus_radio_button_group_initialize (NautilusRadioButtonGroup *button_group);
/* GtkObjectClass methods */
static void nautilus_radio_button_group_destroy (GtkObject *object);
/* Private stuff */
static void radio_button_group_free_button_group (NautilusRadioButtonGroup *button_group);
static void radio_button_group_emit_changed_signal (NautilusRadioButtonGroup *button_group,
GtkWidget *button);
/* Radio button callbacks */
static void button_toggled (GtkWidget *button,
gpointer user_data);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusRadioButtonGroup,
nautilus_radio_button_group,
GTK_TYPE_VBOX)
static guint radio_group_signals[LAST_SIGNAL] = { 0 };
/*
* NautilusRadioButtonGroupClass methods
*/
static void
nautilus_radio_button_group_initialize_class (NautilusRadioButtonGroupClass *radio_button_group_class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = GTK_OBJECT_CLASS (radio_button_group_class);
widget_class = GTK_WIDGET_CLASS (radio_button_group_class);
parent_class = gtk_type_class (gtk_vbox_get_type ());
/* GtkObjectClass */
object_class->destroy = nautilus_radio_button_group_destroy;
/* Signals */
radio_group_signals[CHANGED] =
gtk_signal_new ("changed",
GTK_RUN_LAST,
object_class->type,
0,
gtk_marshal_NONE__OBJECT,
GTK_TYPE_NONE,
1,
GTK_TYPE_POINTER);
gtk_object_class_add_signals (object_class, radio_group_signals, LAST_SIGNAL);
}
static void
nautilus_radio_button_group_initialize (NautilusRadioButtonGroup *button_group)
{
button_group->details = g_new (NautilusRadioButtonGroupDetails, 1);
button_group->details->buttons = NULL;
button_group->details->group = NULL;
}
/*
* GtkObjectClass methods
*/
static void
nautilus_radio_button_group_destroy(GtkObject* object)
{
NautilusRadioButtonGroup * button_group;
g_return_if_fail (object != NULL);
g_return_if_fail (NAUTILUS_IS_RADIO_BUTTON_GROUP (object));
button_group = NAUTILUS_RADIO_BUTTON_GROUP (object);
radio_button_group_free_button_group (button_group);
g_free (button_group->details);
/* Chain */
if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
/*
* Private stuff
*/
static void
radio_button_group_emit_changed_signal (NautilusRadioButtonGroup *button_group,
GtkWidget *button)
{
g_assert (button_group != NULL);
g_assert (button_group->details != NULL);
g_assert (button != NULL);
gtk_signal_emit (GTK_OBJECT (button_group),
radio_group_signals[CHANGED],
button);
}
static void
radio_button_group_free_button_group (NautilusRadioButtonGroup *button_group)
{
g_assert (button_group != NULL);
g_assert (button_group->details != NULL);
if (button_group->details->buttons)
{
g_list_free (button_group->details->buttons);
}
button_group->details->buttons = NULL;
button_group->details->group = NULL;
}
/*
* Radio button callbacks
*/
static void
button_toggled (GtkWidget *button, gpointer user_data)
{
NautilusRadioButtonGroup *button_group = (NautilusRadioButtonGroup *) user_data;
g_assert (button_group != NULL);
g_assert (button_group->details != NULL);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
{
radio_button_group_emit_changed_signal (button_group, button);
}
}
/*
* NautilusRadioButtonGroup public methods
*/
GtkWidget*
nautilus_radio_button_group_new (void)
{
NautilusRadioButtonGroup *button_group;
button_group = gtk_type_new (nautilus_radio_button_group_get_type ());
return GTK_WIDGET (button_group);
}
/**
* nautilus_radio_button_group_insert:
* @button_group: The button group
* @label: Label to use for the new button
*
* Create and insert a new radio button to the collection.
*
* Returns: The index of the new button.
*/
guint
nautilus_radio_button_group_insert (NautilusRadioButtonGroup *button_group,
const gchar *label)
{
GtkWidget *button;
g_return_val_if_fail (button_group != NULL, 0);
g_return_val_if_fail (NAUTILUS_IS_RADIO_BUTTON_GROUP (button_group), 0);
g_return_val_if_fail (label != NULL, 0);
button = gtk_radio_button_new_with_label (button_group->details->group, label);
/*
* For some crazy reason I dont grok, the group has to be fetched each
* time from the previous button
*/
button_group->details->group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
gtk_signal_connect (GTK_OBJECT (button),
"toggled",
GTK_SIGNAL_FUNC (button_toggled),
(gpointer) button_group);
gtk_box_pack_start (GTK_BOX (button_group),
button,
TRUE,
TRUE,
0);
gtk_widget_show (button);
button_group->details->buttons = g_list_append (button_group->details->buttons,
(gpointer) button);
return g_list_length (button_group->details->buttons) - 1;
}
/**
* nautilus_radio_button_group_get_active_index:
* @button_group: The button group
*
* Returns: The index of the active button. There is always one active by law.
*/
guint
nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_group)
{
GList *button_iterator;
gint i = 0;
g_return_val_if_fail (button_group != NULL, 0);
g_return_val_if_fail (NAUTILUS_IS_RADIO_BUTTON_GROUP (button_group), 0);
g_assert (button_group != NULL);
button_iterator = button_group->details->buttons;
while (button_iterator)
{
g_assert (GTK_TOGGLE_BUTTON (button_iterator->data));
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_iterator->data)))
{
return i;
}
button_iterator = button_iterator->next;
i++;
}
g_assert (0);
return 0;
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-radio-button-group.h - A radio button group container.
Copyright (C) 1999, 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library 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 Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Ramiro Estrugo <ramiro@eazel.com>
*/
#ifndef NAUTILUS_RADIO_BUTTON_GROUP_H
#define NAUTILUS_RADIO_BUTTON_GROUP_H
#include <gtk/gtkvbox.h>
#include <gnome.h>
/*
* NautilusRadioButtonGroup is a collection of radio buttons.
*/
BEGIN_GNOME_DECLS
#define NAUTILUS_TYPE_RADIO_BUTTON_GROUP (nautilus_radio_button_group_get_type ())
#define NAUTILUS_RADIO_BUTTON_GROUP(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_RADIO_BUTTON_GROUP, NautilusRadioButtonGroup))
#define NAUTILUS_RADIO_BUTTON_GROUP_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_RADIO_BUTTON_GROUP, NautilusRadioButtonGroupClass))
#define NAUTILUS_IS_RADIO_BUTTON_GROUP(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_RADIO_BUTTON_GROUP))
typedef struct _NautilusRadioButtonGroup NautilusRadioButtonGroup;
typedef struct _NautilusRadioButtonGroupClass NautilusRadioButtonGroupClass;
typedef struct _NautilusRadioButtonGroupDetails NautilusRadioButtonGroupDetails;
struct _NautilusRadioButtonGroup
{
/* Super Class */
GtkVBox vbox;
/* Private stuff */
NautilusRadioButtonGroupDetails *details;
};
struct _NautilusRadioButtonGroupClass
{
GtkVBoxClass parent_class;
};
typedef struct
{
guint active_button_index;
} NautilusRadioButtonGroupSignalData;
GtkType nautilus_radio_button_group_get_type (void);
GtkWidget* nautilus_radio_button_group_new (void);
/* Insert a new item to the group. Returns the new item's index */
guint nautilus_radio_button_group_insert (NautilusRadioButtonGroup *button_group,
const gchar *label);
/* Get the active item index. By law there always is an active item */
guint nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_group);
BEGIN_GNOME_DECLS
#endif /* NAUTILUS_RADIO_BUTTON_GROUP_H */
#include <nautilus-widgets/nautilus-radio-button-group.h>
#include <gtk/gtk.h>
#include <stdio.h>
static void test_radio_group (void);
static void test_radio_changed_signal (GtkWidget *button_group, gpointer user_data);
int
main (int argc, char * argv[])
{
gtk_init (&argc, &argv);
test_radio_group ();
gtk_main ();
return 0;
}
static void
test_radio_group (void)
{
GtkWidget * window;
GtkWidget * buttons;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
buttons = nautilus_radio_button_group_new ();
nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Apples");
nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Oranges");
nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Strawberries");
gtk_signal_connect (GTK_OBJECT (buttons),
"changed",
GTK_SIGNAL_FUNC (test_radio_changed_signal),
(gpointer) NULL);
gtk_container_add (GTK_CONTAINER (window), buttons);
gtk_widget_show (buttons);
gtk_widget_show (window);
}
static void
test_radio_changed_signal (GtkWidget *buttons, gpointer user_data)
{
gint i;
i = nautilus_radio_button_group_get_active_index (NAUTILUS_RADIO_BUTTON_GROUP (buttons));
printf ("test_radio_changed_signal (%d)\n", i);
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-radio-button-group.c - A radio button group container.
Copyright (C) 1999, 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library 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 Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Ramiro Estrugo <ramiro@eazel.com>
*/
#include <nautilus-widgets/nautilus-radio-button-group.h>
#include <gtk/gtkradiobutton.h>
#include <gtk/gtksignal.h>
#include <libnautilus/nautilus-gtk-macros.h>
static const gint RADIO_BUTTON_GROUP_INVALID = -1;
/* Signals */
typedef enum
{
CHANGED,
LAST_SIGNAL
} RadioGroupSignals;
struct _NautilusRadioButtonGroupDetails
{
GList *buttons;
GSList *group;
};
/* NautilusRadioButtonGroupClass methods */
static void nautilus_radio_button_group_initialize_class (NautilusRadioButtonGroupClass *klass);
static void nautilus_radio_button_group_initialize (NautilusRadioButtonGroup *button_group);
/* GtkObjectClass methods */
static void nautilus_radio_button_group_destroy (GtkObject *object);
/* Private stuff */
static void radio_button_group_free_button_group (NautilusRadioButtonGroup *button_group);
static void radio_button_group_emit_changed_signal (NautilusRadioButtonGroup *button_group,
GtkWidget *button);
/* Radio button callbacks */
static void button_toggled (GtkWidget *button,
gpointer user_data);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusRadioButtonGroup,
nautilus_radio_button_group,
GTK_TYPE_VBOX)
static guint radio_group_signals[LAST_SIGNAL] = { 0 };
/*
* NautilusRadioButtonGroupClass methods
*/
static void
nautilus_radio_button_group_initialize_class (NautilusRadioButtonGroupClass *radio_button_group_class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = GTK_OBJECT_CLASS (radio_button_group_class);
widget_class = GTK_WIDGET_CLASS (radio_button_group_class);
parent_class = gtk_type_class (gtk_vbox_get_type ());
/* GtkObjectClass */
object_class->destroy = nautilus_radio_button_group_destroy;
/* Signals */
radio_group_signals[CHANGED] =
gtk_signal_new ("changed",
GTK_RUN_LAST,
object_class->type,
0,
gtk_marshal_NONE__OBJECT,
GTK_TYPE_NONE,
1,
GTK_TYPE_POINTER);
gtk_object_class_add_signals (object_class, radio_group_signals, LAST_SIGNAL);
}
static void
nautilus_radio_button_group_initialize (NautilusRadioButtonGroup *button_group)
{
button_group->details = g_new (NautilusRadioButtonGroupDetails, 1);
button_group->details->buttons = NULL;
button_group->details->group = NULL;
}
/*
* GtkObjectClass methods
*/
static void
nautilus_radio_button_group_destroy(GtkObject* object)
{
NautilusRadioButtonGroup * button_group;
g_return_if_fail (object != NULL);
g_return_if_fail (NAUTILUS_IS_RADIO_BUTTON_GROUP (object));
button_group = NAUTILUS_RADIO_BUTTON_GROUP (object);
radio_button_group_free_button_group (button_group);
g_free (button_group->details);
/* Chain */
if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
/*
* Private stuff
*/
static void
radio_button_group_emit_changed_signal (NautilusRadioButtonGroup *button_group,
GtkWidget *button)
{
g_assert (button_group != NULL);
g_assert (button_group->details != NULL);
g_assert (button != NULL);
gtk_signal_emit (GTK_OBJECT (button_group),
radio_group_signals[CHANGED],
button);
}
static void
radio_button_group_free_button_group (NautilusRadioButtonGroup *button_group)
{
g_assert (button_group != NULL);
g_assert (button_group->details != NULL);
if (button_group->details->buttons)
{
g_list_free (button_group->details->buttons);
}
button_group->details->buttons = NULL;
button_group->details->group = NULL;
}
/*
* Radio button callbacks
*/
static void
button_toggled (GtkWidget *button, gpointer user_data)
{
NautilusRadioButtonGroup *button_group = (NautilusRadioButtonGroup *) user_data;
g_assert (button_group != NULL);
g_assert (button_group->details != NULL);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
{
radio_button_group_emit_changed_signal (button_group, button);
}
}
/*
* NautilusRadioButtonGroup public methods
*/
GtkWidget*
nautilus_radio_button_group_new (void)
{
NautilusRadioButtonGroup *button_group;
button_group = gtk_type_new (nautilus_radio_button_group_get_type ());
return GTK_WIDGET (button_group);
}
/**
* nautilus_radio_button_group_insert:
* @button_group: The button group
* @label: Label to use for the new button
*
* Create and insert a new radio button to the collection.
*
* Returns: The index of the new button.
*/
guint
nautilus_radio_button_group_insert (NautilusRadioButtonGroup *button_group,
const gchar *label)