gtk_widget_realize and allocation



Hi, 

I'm trying to make a little app where all the widgets 
are defined by a text file. In order to place the 
widgets on my window I need to know their allocated
size, so I can fixed them correctly. For that I use
gtk_widget_realize() to force the allocation (I get
the height for example with widget->allocation.height
). But the problem is that it works only for the first
widget; gtk_widget_realize() don't seem to work for
the following widgets. 

Here is a simple sample code where I show 3 GtkLabels
in a fixed. The two first GtkLabels are shown
correctly but not the third (the second and the third
are at the same place because the third is not
allocated after gtk_widget_realize). I know that
normally all the widgets are realized when the
toplevel window is shown, that's why I used
gtk_widget_realize. Maybe there's another way of doing
it (with signals?). Do you have any idea?

Thanks for your help (!),
             Victor


#include <gtk/gtk.h> 
#include <stdio.h> 


int main (int argc, char *argv[]) 
{   
  GtkWidget *window,*fixed,*label1,*label2,*label3; 
  int y=0; 
   
  // GTK Init 
  gtk_set_locale (); 
  gtk_init (NULL, NULL); 

  
/*------------------------------window---------------------------------*/

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 
  gtk_window_set_title (GTK_WINDOW (window), 
"Window"); 
  gtk_window_set_position (GTK_WINDOW (window), 
GTK_WIN_POS_CENTER); 
     
   
  
/*--------------------------Fixed-------------------------------------*/

  fixed = gtk_fixed_new (); 
  gtk_widget_show (fixed); 
  gtk_container_add (GTK_CONTAINER (window), fixed); 
   
  /*-------------------------Label
1-----------------------------*/ 
  label1 = gtk_label_new ("Label 1"); 
  gtk_widget_show (label1); 
  gtk_fixed_put (GTK_FIXED (fixed), label1, 45, 5); 
     
  gtk_widget_realize(label1); 
//?gtk_widget_realize(window);? 
   
  printf(" height=%d\n",label1->allocation.height); 
  printf(" height2=%d\n",label1->requisition.height); 
  y+=label1->allocation.height; 

   
  /*-------------------------Label
2------------------------------*/ 
  label2 = gtk_label_new ("Label 2"); 
  gtk_widget_show (label2);   
  gtk_fixed_put (GTK_FIXED (fixed), label2, 45, 5+y); 

  gtk_widget_realize(label2); 
   
  printf(" height1=%d\n",label2->allocation.height); 
  printf(" height2=%d\n",label2->requisition.height); 
  y+=label2->allocation.height; 

   
  /*-------------------------Label
3------------------------------*/ 
  label3 = gtk_label_new ("Label 3"); 
  gtk_widget_show (label3); 
  gtk_fixed_put (GTK_FIXED (fixed), label3, 45, 5+y); 
   

  gtk_widget_show (window); 
   
  /* GTK Main Loop */ 
  gtk_main (); 
   
  return(0); 
} 


___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com



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