location of widgets in a gtk_table



Hi all,

I need to use Gtk_tables but I still have problems in placing widgets the way I want in them. After several days of "fight" with my code, I guess I now accurately identify what I do not understand. I've thus build an example code that shows where the problem is.

My main window contains a vertical box that contains two elements: a Gtk_frame and a Gtk_table.

Here is the code:

/* working with tables */
#include <stdlib.h>
#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
 GtkWidget *win=NULL;
 GtkWidget *pTable=NULL;
 GtkWidget *pTable_titre=NULL;
 GtkWidget *pTable_bandeau=NULL;
 GtkWidget *pTable_liste=NULL;
 GtkWidget *boxv=NULL;
 GtkWidget *boxv2=NULL;
 GtkWidget *label[300];
 GtkWidget *label_titre=NULL;
 GtkWidget *titre_principal=NULL;
 GtkWidget *frame0=NULL;
 GtkWidget *frame1=NULL;
 GtkWidget *frame2=NULL;
 GtkWidget *barre_defilement=NULL;
 char tmp[500];
 int i;
 /* Initializing GTK+ */
 gtk_init (&argc, &argv);
 /* Creating the main window */
 win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 gtk_container_set_border_width (GTK_CONTAINER (win), 8);
 gtk_window_set_title (GTK_WINDOW (win), "testing table..");
 gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
 gtk_window_set_default_size(GTK_WINDOW(win), 750, 500);
 g_signal_connect(win, "destroy", G_CALLBACK(gtk_main_quit), NULL);
 /* creating a vertical box */
 boxv=gtk_vbox_new(FALSE, 0);
 /* creating another vertical box */
 boxv2=gtk_vbox_new(FALSE, 0);
 /* creating labels and placing them in boxv*/
 for (i=0;i<300;i++)
 {
     (void)sprintf(tmp,"texte%d",i);
     label[i]=gtk_label_new(tmp);
     gtk_box_pack_start(GTK_BOX(boxv),label[i], FALSE, FALSE, 5);
 }
 /* creating a scrolling window for it */
 barre_defilement=gtk_scrolled_window_new(NULL, NULL);
 /* only the vertical scrolling - if needed */
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(barre_defilement), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
 /* no border around */
 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(barre_defilement), GTK_SHADOW_NONE);
 /* scrolling on the left */
 gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(barre_defilement), GTK_CORNER_BOTTOM_RIGHT);
 /* placing boxv in the scrolling window *
/ gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(barre_defilement), boxv);
 /* creation of titre principal */
 (void)sprintf(tmp,"titre Principal"); titre_principal=gtk_label_new(tmp);
 /* creation of table titre */
 pTable_titre=gtk_table_new((guint)3,(guint)20,FALSE);
 /* creation of frame0 */
 frame0=gtk_frame_new(NULL);
 gtk_frame_set_shadow_type(GTK_FRAME(frame0), GTK_SHADOW_ETCHED_OUT);
 /* placing titre in the table and the table in the frame */
gtk_table_attach(GTK_TABLE(pTable_titre), titre_principal, 0,20,0,3,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0 ); gtk_container_add(GTK_CONTAINER(frame0), GTK_WIDGET(pTable_titre));
 /* creating titre "bandeau" */
 (void)sprintf(tmp,"bandeau du titre");
 label_titre=gtk_label_new(tmp);
 /* creating of table liste */
 pTable_liste=gtk_table_new((guint)18,(guint)4,FALSE);
 /* creating of table bandeau */
 pTable_bandeau=gtk_table_new((guint)2,(guint)20,FALSE);
 /* placing titre bandeau in it */
gtk_table_attach(GTK_TABLE(pTable_bandeau), label_titre, 0,20,0,2,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0 );
 /* placing boxv and its scrolling window in it */
gtk_table_attach(GTK_TABLE(pTable_liste), barre_defilement, 0,4,0,18,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0 );
 /*creating the main table */
 pTable=gtk_table_new((guint)20,(guint)20,FALSE);
 /* Creating two frames */
 frame1=gtk_frame_new(NULL);
 gtk_frame_set_shadow_type(GTK_FRAME(frame1), GTK_SHADOW_ETCHED_OUT);
 frame2=gtk_frame_new(NULL);
 gtk_frame_set_shadow_type(GTK_FRAME(frame2), GTK_SHADOW_ETCHED_OUT);
 /* placing table bandeau in the 1st frame et table liste in the 2nd */
 gtk_container_add(GTK_CONTAINER(frame1), GTK_WIDGET(pTable_bandeau));
 gtk_container_add(GTK_CONTAINER(frame2), GTK_WIDGET(pTable_liste));
 /* placing frames in the table */
gtk_table_attach(GTK_TABLE(pTable), frame1, 0,20,0,2,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0 ); gtk_table_attach(GTK_TABLE(pTable), frame2, 0,4,2,20,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0 );
 /* placing all of this in boxv2 */
 gtk_box_pack_start(GTK_BOX(boxv2),frame0, FALSE, FALSE, 5);
 gtk_box_pack_start(GTK_BOX(boxv2),pTable, FALSE, FALSE, 5);
 /* adding the table to the window */
 gtk_container_add (GTK_CONTAINER (win), boxv2);
 /* Enter the main loop */
 gtk_widget_show_all (win);
 gtk_main();
 return 0;
}

The position of the frame on the left is ridiculously small and does not correspond at all to the location I assigned to it!

However, if I delete the Gtk_frame on top, in other words, if I replace the last 9 lines of the code by:

 /* placing all of this in boxv2 */
 /* gtk_box_pack_start(GTK_BOX(boxv2),frame0, FALSE, FALSE, 5); */
 /* gtk_box_pack_start(GTK_BOX(boxv2),pTable, FALSE, FALSE, 5); */
 /* adding the table to the window */
 /* gtk_container_add (GTK_CONTAINER (win), boxv2); */
gtk_container_add (GTK_CONTAINER (win), pTable);
 /* Enter the main loop */
 gtk_widget_show_all (win);
 gtk_main();
 return 0;

Hence, if the main windows only contains the Gtk_table, then everything works fine.

This looks really weird to me. How come locations of widgets within a Gtk_table can be modified if such a Gtk_table is included in a box with other widgets??

I really do not have any idea, and any help on this will be more than welcomed!

Thanks is all cases for your time!

Cheers, Eric.


--
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Eric Wajnberg
    Associated Professor at the
    University of Montreal (Quebec, Canada)
    I.N.R.A.
    400 Route des Chappes, BP 167,
    06903 Sophia Antipolis Cedex, France
    Tel: (33-0) 4.92.38.64.47
    Fax: (33-0) 4.92.38.65.57
    e-mail: wajnberg sophia inra fr
    Web page: http://www.sophia.inra.fr/perso/wajnberg/

    Editor-in-Chief of BioControl, Published by Springer.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



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