Re: Develop a composite widget



Hi Ottavio,

>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?
>

First, the structure of your custom widget is invalid. You MUST
derive this structure from the base widget structure, i.e. the base
structure, not a pointer, should be the first slot of  the custom
widget structure. In your case it should look like that:

struct _GtkSwap
{
  GtkScrolledWindow w;

  ...

  GList *swap_list;
};

Second, the GtkScrolledWindow structure needs to be initialized, so
the gtkswap_init should be rewritten as follows (note gtk_object_set()
call):

gtkswap_init (GtkSwap *gswap)
{
  
  guint rows = 1;

  /* This creates the adjustment objects */
  gtk_object_set(GTK_OBJECT(gswap),
		 "hadjustment", NULL,
		 "vadjustment", NULL,
		 NULL);

  gswap->table = gtk_table_new (rows, 3, FALSE);
  gtk_scrolled_window_add_with_viewport (scrolled_win, gswap->table);

  gtk_table_attach_defaults (GTK_TABLE (gswap->table),
    gtk_label_new ("Partizione"), 0, 1, 0, 1);
  gtk_table_attach_defaults (GTK_TABLE (gswap->table),
    gtk_label_new ("Usare"), 1, 2, 0, 1);
  gtk_table_attach_defaults (GTK_TABLE (gswap->table),
    gtk_label_new ("Inizializzare"), 2, 3, 0, 1);
  gtk_widget_show_all(GTK_WIDGET(gswap));
}

The result window shows the viewport with two scrollbars with a table
with three labels. No segmentation faults anymore!

Hope that helps,

Vladimir V. Tsichevski
senior expert

-----------------------------------------------------
                  Jet Infosystems
Krasnoproletarskaya 6,		Tel. (+7 095) 972-1182
Moscow 103006, Russia		Fax  (+7 095) 972-0791
-----------------------------------------------------
Any opinions or recommendations herein are those of
the author and not of his computer.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]