Develop a composite widget
- From: Ottavio Campana <bott iol it>
- To: Gtk-list <gtk-list gnome org>
- Subject: Develop a composite widget
- Date: Wed, 13 Sep 2000 23:44:32 +0200
Hi,
I'm writing a new widget. I will use it in a linux installer to choose
which swap partitions to use and which partition to initialize. It is
easy to explain: it is a scrolled window witha table inside. The table
has got 3 columns (one for the name of the partition, one for a
checkbutton to know if it has to be used and the last column for a
checkbutton to know if it has to be initialized).
Following the gtk tutorial I've tried to develop this new widget. I've
tried to compile an example application but when I run it I get a
segmentation fault. Debbugging it I've seen that the problem is in the
function gtkswap_init .
Can anyone of you help me and find the bug?
Thanks.
PS: the source will be released under GPL, so if you want to use it do
it. I just would like to know if you're interested on it, so that we can
work together :)
--
Non c'e' pił forza nella normalita', c'e' solo monotonia.
#include "gtkswap.h"
static void gtkswap_class_init (GtkSwapClass *class);
static void gtkswap_init (GtkSwap *gswap);
guint
gtkswap_get_type ()
{
static guint swap_type = 0;
if (!swap_type)
{
GtkTypeInfo swap_info =
{
"GtkSwap",
sizeof (GtkSwap),
sizeof (GtkSwapClass),
(GtkClassInitFunc) gtkswap_class_init,
(GtkObjectInitFunc) gtkswap_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL
};
swap_type = gtk_type_unique (gtk_scrolled_window_get_type (), &swap_info);
}
return swap_type;
}
static void
gtkswap_class_init (GtkSwapClass *class)
{
GtkObjectClass *object_class;
object_class = (GtkObjectClass*) class;
class->gtkswap = NULL;
}
static void
gtkswap_init (GtkSwap *gswap)
{
/**
* creazione del widget composito
*/
guint rows = 1; /* fix me */
gswap->scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_ref (gswap->scrolledwindow);
gtk_widget_show (gswap->scrolledwindow);
gswap->viewport = gtk_viewport_new (NULL, NULL);
gtk_widget_ref (gswap->viewport);
gtk_widget_show (gswap->viewport);
gtk_container_add (GTK_CONTAINER (gswap->scrolledwindow), gswap->viewport);
gswap->table = gtk_table_new (rows, 3, FALSE);
gtk_widget_ref (gswap->table);
gtk_widget_show (gswap->table);
gtk_container_add (GTK_CONTAINER (gswap->viewport), gswap->table);
gswap->label1 = gtk_label_new ("Partizione");
gtk_widget_ref (gswap->label1);
gtk_widget_show (gswap->label1);
gtk_table_attach (GTK_TABLE (gswap->table), gswap->label1, 0, 1, 0, 1,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gswap->label2 = gtk_label_new ("Usare");
gtk_widget_ref (gswap->label2);
gtk_widget_show (gswap->label2);
gtk_table_attach (GTK_TABLE (gswap->table), gswap->label2, 1, 2, 0, 1,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gswap->label3 = gtk_label_new ("Inizializzare");
gtk_widget_ref (gswap->label3);
gtk_widget_show (gswap->label3);
gtk_table_attach (GTK_TABLE (gswap->table), gswap->label3, 2, 3, 0, 1,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
}
GtkWidget*
gtk_swap_new ()
{
return GTK_WIDGET ( gtk_type_new (gtkswap_get_type ()));
}
#ifndef __GTKSWAP_H__
#define __GTKSWAP_H__
#include <gtk/gtkscrolledwindow.h>
#include <gtk/gtkviewport.h>
#include <gtk/gtktable.h>
#include <gtk/gtklabel.h>
#include <glib.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define GTK_TYPE_SWAP (gtk_swap_get_type ())
#define GTK_SWAP(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_SWAP, GtkSwap))
#define GTK_SWAP_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_SWAP, GtkSwapClass))
#define GTK_IS_SWAP(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_SWAP))
#define GTK_IS_SWAP_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SWAP))
typedef struct _GtkSwap GtkSwap;
typedef struct _GtkSwapClass GtkSwapClass;
struct _GtkSwap
{
GtkWidget *scrolledwindow;
GtkWidget *viewport;
GtkWidget *table;
GtkWidget *label1;
GtkWidget *label2;
GtkWidget *label3;
GList *swap_list;
};
struct _GtkSwapClass
{
GtkScrolledWindowClass parent_class;
void (* gtkswap) (GtkSwap *gswap);
};
guint gtk_swap_get_type (void);
GtkWidget* gtk_swap_new (void);
GList* gtk_swap_get_swap_list (void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GTKSWAP_H__ */
#include <gtk/gtk.h>
#include "gtkswap.c"
int
main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *swap;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Prova gtkswap");
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_exit), NULL);
gtk_container_border_width (GTK_CONTAINER (window), 10);
/* Crea un nuovo widget GtkSwap. */
swap = gtk_swap_new ();
gtk_container_add (GTK_CONTAINER (window), swap);
gtk_widget_show (swap);
gtk_widget_show (window);
gtk_main ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]