On Thu, May 04, 2006 at 11:12:32PM +0200, Felix Kater wrote:
> my table widget simply contains a label (first row) and a scrolled window 
> (second row). I need the scrolled window (with a large drawing area inside) 
> to expand. However, it doesn't.
> 
> To achieve this I assume I need to do two things: tell the table to expand 
> itself to the maximum, and tell it to expand the second row only (the 
> scrolled window) and not the first (the label).

Please see the attached example, I hope it does what you
need.

The various expansion options are nicely explained in the
tutorial, namely here:
http://www.gtk.org/tutorial/x383.html
and here:
http://www.gtk.org/tutorial/x409.html

Yeti


--
Anonyms eat their boogers.


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

static gboolean
expose(GtkWidget *widget, GdkEventExpose *event)
{
    gdk_draw_line(widget->window,
                  widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
                  0, 0, widget->allocation.width, widget->allocation.height);
    gdk_draw_line(widget->window,
                  widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
                  0, widget->allocation.height, widget->allocation.width, 0);
    return FALSE;
}

int
main(int argc, char *argv[])
{
    GtkWidget *window, *darea, *table, *label, *scwin, *vbox, *whatever;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Expansion");
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

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

    table = gtk_table_new(2, 1, FALSE);
    gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);

    label = gtk_label_new("A label in the table, does not expand vertically");
    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
                     GTK_EXPAND | GTK_FILL, 0, 0, 0);

    darea = gtk_drawing_area_new();
    g_signal_connect(darea, "expose-event", G_CALLBACK(expose), NULL);

    scwin = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scwin),
                                        GTK_SHADOW_NONE);
    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scwin), darea);
    gtk_table_attach(GTK_TABLE(table), scwin, 0, 1, 1, 2,
                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

    whatever = gtk_entry_new();
    gtk_entry_set_text(GTK_ENTRY(whatever), "This entry is not in the table "
                       "and does not expand either");
    gtk_box_pack_start(GTK_BOX(vbox), whatever, FALSE, FALSE, 0);

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to