Problem with resizing frames
- From: Kjetil Thuen <Kjetil Thuen student uib no>
- To: gtk-app-devel-list gnome org
- Subject: Problem with resizing frames
- Date: 02 Dec 2000 02:50:14 +0100
I am working on an app, and have recently come across a problem. Its a
little hard to explain, so I have isolated the problem in small example
to help illustrate the problem.
The example consists of the following widgets:
|Top Level window
|_scrolled window
|_viewport
|_vbox
|_togglebutton
|_frame1
| |_vbox
| |_button1
| |_frame2
| |_button2
|_frame3
|_button3
frame 2 will be hidden or shown when the togglebutton is toggled. When
this happens. I want frame1 to decrease its size to reflect the change,
but instead button1 increases its size.
However, if the top level window is too small to show all three frames
(the third frame needs to be completely obscured), the behaviour I want
occurs. Also, the desired effect takes place if I resize the top level
window. Any resize event from the top level window will do.
I hope this made sense :) Anyway - if anyone finds this problem
interesting, or just feels like helping out, please look at the
enclosed code, and see if you can spot the problem.
--snip--
#include <gtk/gtk.h>
void toggled (GtkToggleButton *togglebutton);
GtkWidget *window;
int
main (int argc, char *argv[])
{
int n;
GtkWidget *scrolledwindow;
GtkWidget *viewport;
GtkWidget *checkbutton;
GtkWidget *vbox1,*vbox2;
GtkWidget *frames[3];
GtkWidget *buttons[3];
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (scrolledwindow);
gtk_container_add (GTK_CONTAINER (window), scrolledwindow);
viewport = gtk_viewport_new (NULL, NULL);
gtk_widget_show (viewport);
gtk_container_add (GTK_CONTAINER (scrolledwindow), viewport);
/* Top level vertical box */
vbox1 = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox1);
gtk_container_add (GTK_CONTAINER (viewport), vbox1);
/* toggle button to toggle visibility of inner frame */
checkbutton = gtk_check_button_new_with_label ("Hide inner frame");
gtk_widget_show (checkbutton);
gtk_box_pack_start (GTK_BOX (vbox1), checkbutton, FALSE, FALSE, 0);
/* Upper frame */
frames[0] = gtk_frame_new ("Frame 1");
gtk_widget_show (frames[0]);
gtk_box_pack_start (GTK_BOX (vbox1), frames[0], FALSE, FALSE, 0);
/* Lower frame */
frames[1] = gtk_frame_new ("Frame 2");
gtk_widget_show (frames[1]);
gtk_box_pack_start (GTK_BOX (vbox1), frames[1], FALSE, FALSE, 0);
/* Vertical box of upper frame */
vbox2 = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox2);
gtk_container_add (GTK_CONTAINER (frames[0]), vbox2);
/* Inner frame (inside upper frame) */
frames[2] = gtk_frame_new ("Inner frame");
gtk_widget_set_name (frames[2], "frame3");
gtk_object_set_data_full (GTK_OBJECT (window), "frame3", frames[2],
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (frames[2]);
gtk_box_pack_start (GTK_BOX (vbox2), frames[2], TRUE, FALSE, 0);
/* buttons to fill up the frames */
for (n=0; n<3; n++) {
buttons[n] = gtk_button_new_with_label ("Foo");
gtk_widget_show (buttons[n]);
}
gtk_box_pack_start (GTK_BOX (vbox2), buttons[0], TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (frames[1]), buttons[1]);
gtk_container_add (GTK_CONTAINER (frames[2]), buttons[2]);
gtk_signal_connect (GTK_OBJECT (checkbutton), "toggled",
GTK_SIGNAL_FUNC (toggled),
NULL);
gtk_widget_show (window);
gtk_main ();
return 0;
}
void
toggled (GtkToggleButton *togglebutton)
{
if (togglebutton->active)
gtk_widget_hide (gtk_object_get_data(GTK_OBJECT(window),"frame3"));
else
gtk_widget_show (gtk_object_get_data(GTK_OBJECT(window),"frame3"));
}
--snap--
Kjetil
--
Quidquid latine dictum sit, altum viditur
PGP: http://grustibus.sourceforge.net/kjetilt-pgp.asc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]