Widgets not showing up



I've written a simple UI with a menubar, a hpaned window with a ctree and a
clist packed into either side, and a status bar at the bottom of the
window.  Unfortunatley, only the hpaned container and its child widgets are
displayed; the menubar and the status bar are not.  Is there something
wrong with my code that would cause this?  I've writen simmilar interfaces
that have worked just fine in the past, but this one has me stumped.

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

void cb_delete_event(GtkWidget *widget,
                     GdkEvent *event,
                     gpointer data)
{
    g_print("A delete_event occured.\n");
    gtk_main_quit();
}

void cb_clist_selection_made(GtkWidget *clist,
                             gint row,
                             gint column,
                             GdkEventButton *event,
                             gpointer data)
{
    gchar *text;

    gtk_clist_get_text(GTK_CLIST(clist), row, column, &text);
    printf("%s was selected", text);
}

GtkWidget *create_main_window(void)
{
    GtkWidget *window;
    GtkWidget *mainbox;
    GtkWidget *paned;
    GtkWidget *vbox;
    GtkWidget *scrolled_window;
    GtkWidget *scrolled2;

    GtkWidget *clist;
    GtkWidget *ctree;
    GtkWidget *entry;
    GtkWidget *status_bar;

    /* Menubar stuff */

    GtkAccelGroup *group;
    GtkItemFactory *itemfactory;
    gint nmenu_items;
    GtkWidget *app_menubar;
    
    static GtkItemFactoryEntry menu_items[] = {
        { "/_File", "<control>F", NULL, 0, "<Branch>" },
        { "/File/File", NULL, NULL, 0, "<Title>"      },
        { "/File/sep1", NULL, NULL, 0, "<Separator>"  },
        { "/File/_Quit", "<control>Q", gtk_main_quit, 0, "<Item>" }
    };

    static gchar *clist_titles[] = { "Name", "Size" };

    /* Containers */
    
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_usize(GTK_WIDGET(window), 640, 480);
    gtk_window_set_title(GTK_WINDOW(window), "Paned window test");
    gtk_signal_connect(GTK_OBJECT(window), "delete_event",
                       GTK_SIGNAL_FUNC(cb_delete_event), NULL);

    mainbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window), vbox);

    paned = gtk_hpaned_new();
    gtk_paned_set_position(GTK_PANED(paned), 200);
    gtk_container_add(GTK_CONTAINER(window), paned); 

    vbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window), vbox);

    scrolled_window = gtk_scrolled_window_new(NULL, NULL);
    gtk_container_add(GTK_CONTAINER(window), scrolled_window);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
                                   GTK_POLICY_AUTOMATIC,
                                   GTK_POLICY_AUTOMATIC);

    scrolled2 = gtk_scrolled_window_new(NULL, NULL);
    gtk_container_add(GTK_CONTAINER(window), scrolled2);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled2),
                                   GTK_POLICY_AUTOMATIC,
                                   GTK_POLICY_AUTOMATIC);
                                                                                  

    /* Widgets */

    group = gtk_accel_group_new();
    gtk_window_add_accel_group(GTK_WINDOW(window), group);
    nmenu_items = (sizeof (menu_items) / sizeof (menu_items[0]));
    itemfactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR,
                                          "<main>", group);
    gtk_item_factory_create_items(itemfactory, nmenu_items,
                                  menu_items, NULL);
    app_menubar = gtk_item_factory_get_widget(itemfactory, "<main>");

    clist = gtk_clist_new_with_titles(2, clist_titles);
    gtk_clist_set_shadow_type(GTK_CLIST(clist), GTK_SHADOW_ETCHED_IN);
    gtk_signal_connect(GTK_OBJECT(clist), "select_row",
                       GTK_SIGNAL_FUNC(cb_clist_selection_made),
                       GTK_CLIST(clist));
   
    ctree = gtk_ctree_new(1,1);
   
    entry = gtk_entry_new();

    status_bar = gtk_statusbar_new();

    /* Pack widgets */

    gtk_box_pack_start(GTK_BOX(mainbox), app_menubar, TRUE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(mainbox), paned, TRUE, TRUE, 0);
    gtk_box_pack_end(GTK_BOX(mainbox), status_bar, TRUE, FALSE, 0);

    gtk_paned_add1(GTK_PANED(paned), vbox);
    gtk_paned_add2(GTK_PANED(paned), scrolled_window);

    gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(vbox), scrolled2, TRUE, TRUE, 0);

    gtk_container_add(GTK_CONTAINER(scrolled2), ctree);
    gtk_container_add(GTK_CONTAINER(scrolled_window), clist);

    /* Okay, all done. */

    return(window);
}

int main(int argc, char *argv[])
{
    GtkWidget *window;

    gtk_init(&argc, &argv);

    window = create_main_window();
    gtk_widget_show_all(window);

    gtk_main();

    return 0;
}


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