From e19f939b53c833ac2fc47d6fe18c88fcbb0b7e39 Mon Sep 17 00:00:00 2001 From: BST 1998 Tony Gale Date: Sat, 4 Apr 1998 11:31:51 +0000 Subject: [PATCH] subsections on Aspect Frames and Paned widgets. Sat Apr 4 12:23:23 BST 1998 Tony Gale * docs/gtk_tut.sgml: (gtk-crichton-980403-0) subsections on Aspect Frames and Paned widgets. * examples/paned examples/aspectframe: new examples --- ChangeLog | 7 + ChangeLog.pre-2-0 | 7 + ChangeLog.pre-2-10 | 7 + ChangeLog.pre-2-2 | 7 + ChangeLog.pre-2-4 | 7 + ChangeLog.pre-2-6 | 7 + ChangeLog.pre-2-8 | 7 + docs/gtk_tut.sgml | 292 +++++++++++++++++++++++++++-- docs/tutorial/gtk_tut.sgml | 292 +++++++++++++++++++++++++++-- examples/aspectframe/Makefile | 8 + examples/aspectframe/aspectframe.c | 43 +++++ examples/paned/Makefile | 8 + examples/paned/paned.c | 136 ++++++++++++++ 13 files changed, 804 insertions(+), 24 deletions(-) create mode 100644 examples/aspectframe/Makefile create mode 100644 examples/aspectframe/aspectframe.c create mode 100644 examples/paned/Makefile create mode 100644 examples/paned/paned.c diff --git a/ChangeLog b/ChangeLog index 4b73725934..923e4d2cd9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Apr 4 12:23:23 BST 1998 Tony Gale + + * docs/gtk_tut.sgml: (gtk-crichton-980403-0) subsections on + Aspect Frames and Paned widgets. + + * examples/paned examples/aspectframe: new examples + Fri Apr 3 23:15:55 1998 Owen Taylor * gtk/gtktext.c: Test for need to recompute geometry with diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 4b73725934..923e4d2cd9 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,10 @@ +Sat Apr 4 12:23:23 BST 1998 Tony Gale + + * docs/gtk_tut.sgml: (gtk-crichton-980403-0) subsections on + Aspect Frames and Paned widgets. + + * examples/paned examples/aspectframe: new examples + Fri Apr 3 23:15:55 1998 Owen Taylor * gtk/gtktext.c: Test for need to recompute geometry with diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 4b73725934..923e4d2cd9 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +Sat Apr 4 12:23:23 BST 1998 Tony Gale + + * docs/gtk_tut.sgml: (gtk-crichton-980403-0) subsections on + Aspect Frames and Paned widgets. + + * examples/paned examples/aspectframe: new examples + Fri Apr 3 23:15:55 1998 Owen Taylor * gtk/gtktext.c: Test for need to recompute geometry with diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 4b73725934..923e4d2cd9 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,10 @@ +Sat Apr 4 12:23:23 BST 1998 Tony Gale + + * docs/gtk_tut.sgml: (gtk-crichton-980403-0) subsections on + Aspect Frames and Paned widgets. + + * examples/paned examples/aspectframe: new examples + Fri Apr 3 23:15:55 1998 Owen Taylor * gtk/gtktext.c: Test for need to recompute geometry with diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 4b73725934..923e4d2cd9 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +Sat Apr 4 12:23:23 BST 1998 Tony Gale + + * docs/gtk_tut.sgml: (gtk-crichton-980403-0) subsections on + Aspect Frames and Paned widgets. + + * examples/paned examples/aspectframe: new examples + Fri Apr 3 23:15:55 1998 Owen Taylor * gtk/gtktext.c: Test for need to recompute geometry with diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 4b73725934..923e4d2cd9 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +Sat Apr 4 12:23:23 BST 1998 Tony Gale + + * docs/gtk_tut.sgml: (gtk-crichton-980403-0) subsections on + Aspect Frames and Paned widgets. + + * examples/paned examples/aspectframe: new examples + Fri Apr 3 23:15:55 1998 Owen Taylor * gtk/gtktext.c: Test for need to recompute geometry with diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 4b73725934..923e4d2cd9 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +Sat Apr 4 12:23:23 BST 1998 Tony Gale + + * docs/gtk_tut.sgml: (gtk-crichton-980403-0) subsections on + Aspect Frames and Paned widgets. + + * examples/paned examples/aspectframe: new examples + Fri Apr 3 23:15:55 1998 Owen Taylor * gtk/gtktext.c: Test for need to recompute geometry with diff --git a/docs/gtk_tut.sgml b/docs/gtk_tut.sgml index 6365508e26..4319216073 100644 --- a/docs/gtk_tut.sgml +++ b/docs/gtk_tut.sgml @@ -9,7 +9,7 @@ Ian Main , Tony Gale March 29th, 1998 @@ -3801,9 +3801,9 @@ direction, and the second, the adjustment for the vertical direction. These are almost always set to NULL. -void gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window, - GtkPolicyType hscrollbar_policy, - GtkPolicyType vscrollbar_policy); +void gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window, + GtkPolicyType hscrollbar_policy, + GtkPolicyType vscrollbar_policy); This sets the policy to be used with respect to the scrollbars. @@ -3882,13 +3882,13 @@ int main (int argc, char *argv[]) /* this simply creates a grid of toggle buttons on the table * to demonstrate the scrolled window. */ for (i = 0; i < 10; i++) - for (j = 0; j < 10; j++) { - sprintf (buffer, "button (%d,%d)\n", i, j); - button = gtk_toggle_button_new_with_label (buffer); - gtk_table_attach_defaults (GTK_TABLE (table), button, - i, i+1, j, j+1); - gtk_widget_show (button); - } + for (j = 0; j < 10; j++) { + sprintf (buffer, "button (%d,%d)\n", i, j); + button = gtk_toggle_button_new_with_label (buffer); + gtk_table_attach_defaults (GTK_TABLE (table), button, + i, i+1, j, j+1); + gtk_widget_show (button); + } /* Add a "close" button to the bottom of the dialog */ button = gtk_button_new_with_label ("close"); @@ -3918,6 +3918,274 @@ Try playing with resizing the window. You'll notice how the scrollbars react. You may also wish to use the gtk_widget_set_usize() call to set the default size of the window or other widgets. + + Paned Window Widgets +

+The paned window widgets are useful when you want to divide an area +into two parts, with the relative size of the two parts controlled by +the user. A groove is drawn between the two portions with a handle +that the user can drag to change the ratio. The division can either +be horizontal (HPaned) or vertical (VPaned). + +To create a new paned window, call one of: + + +GtkWidget* gtk_hpaned_new (void) +GtkWidget* gtk_vpaned_new (void) + + +After creating the paned window widget, you need to add child widgets +to its two halves. To do this, use the functions: + + +void gtk_paned_add1 (GtkPaned *paned, GtkWidget *child) +void gtk_paned_add2 (GtkPaned *paned, GtkWidget *child) + + + +/* paned.c */ + +#include + +/* Create the list of "messages" */ +GtkWidget * +create_list (void) +{ + + GtkWidget *scrolled_window; + GtkWidget *list; + GtkWidget *list_item; + + int i; + char buffer[16]; + + /* Create a new scrolled window, with scrollbars only if needed */ + scrolled_window = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + + /* Create a new list and put it in the scrolled window */ + list = gtk_list_new (); + gtk_container_add (GTK_CONTAINER(scrolled_window), list); + gtk_widget_show (list); + + /* Add some messages to the window */ + for (i=0; i<10; i++) { + + sprintf(buffer,"Message #%d",i); + list_item = gtk_list_item_new_with_label (buffer); + gtk_container_add (GTK_CONTAINER(list), list_item); + gtk_widget_show (list_item); + + } + + return scrolled_window; +} + +/* Add some text to our text widget - this is a callback that is invoked +when our window is realized. We could also force our window to be +realized with gtk_widget_realize, but it would have to be part of +a hierarchy first */ + +void +realize_text (GtkWidget *text, gpointer data) +{ + gtk_text_freeze (GTK_TEXT (text)); + gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, + "From: pathfinder@nasa.gov\n" + "To: mom@nasa.gov\n" + "Subject: Made it!\n" + "\n" + "We just got in this morning. The weather has been\n" + "great - clear but cold, and there are lots of fun sights.\n" + "Sojourner says hi. See you soon.\n" + " -Path\n", -1); + + gtk_text_thaw (GTK_TEXT (text)); +} + +/* Create a scrolled text area that displays a "message" */ +GtkWidget * +create_text (void) +{ + GtkWidget *table; + GtkWidget *text; + GtkWidget *hscrollbar; + GtkWidget *vscrollbar; + + /* Create a table to hold the text widget and scrollbars */ + table = gtk_table_new (2, 2, FALSE); + + /* Put a text widget in the upper left hand corner. Note the use of + * GTK_SHRINK in the y direction */ + text = gtk_text_new (NULL, NULL); + gtk_table_attach (GTK_TABLE (table), text, 0, 1, 0, 1, + GTK_FILL | GTK_EXPAND, + GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0); + gtk_widget_show (text); + + /* Put a HScrollbar in the lower left hand corner */ + hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj); + gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2, + GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); + gtk_widget_show (hscrollbar); + + /* And a VScrollbar in the upper right */ + vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj); + gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1, + GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); + gtk_widget_show (vscrollbar); + + /* Add a handler to put a message in the text widget when it is realized */ + gtk_signal_connect (GTK_OBJECT (text), "realize", + GTK_SIGNAL_FUNC (realize_text), NULL); + + return table; +} + +int +main (int argc, char *argv[]) +{ + GtkWidget *window; + GtkWidget *vpaned; + GtkWidget *list; + GtkWidget *text; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), "Paned Windows"); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_main_quit), NULL); + gtk_container_border_width (GTK_CONTAINER (window), 10); + + /* create a vpaned widget and add it to our toplevel window */ + + vpaned = gtk_vpaned_new (); + gtk_container_add (GTK_CONTAINER(window), vpaned); + gtk_widget_show (vpaned); + + /* Now create the contents of the two halves of the window */ + + list = create_list (); + gtk_paned_add1 (GTK_PANED(vpaned), list); + gtk_widget_show (list); + + text = create_text (); + gtk_paned_add2 (GTK_PANED(vpaned), text); + gtk_widget_show (text); + gtk_widget_show (window); + gtk_main (); + return 0; +} + + + + + Aspect Frames +

+The aspect frame widget is like a frame widget, except that it also +enforces the aspect ratio (that is, the ratio of the width to the +height) of the child widget to have a certain value, adding extra +space if necessary. This is useful, for instance, if you want to +preview a larger image. The size of the preview should vary when +the user resizes the window, but the aspect ratio needs to always match +the original image. + +To create a new aspect frame, use: + + +GtkWidget* gtk_aspect_frame_new (const gchar *label, + gfloat xalign, + gfloat yalign, + gfloat ratio, + gint obey_child) + + + +void gtk_aspect_frame_set (GtkAspectFrame *aspect_frame, + gfloat xalign, + gfloat yalign, + gfloat ratio, + gint obey_child) + + +

+As an example, the following program uses an AspectFrame to +present a drawing area whose aspect ratio will always be 2:1, no +matter how the user resizes the top-level window. + + +/* aspectframe.c */ + +#include + +int +main (int argc, char *argv[]) +{ + GtkWidget *window; + GtkWidget *aspect_frame; + GtkWidget *drawing_area; + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), "Aspect Frame"); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_main_quit), NULL); + gtk_container_border_width (GTK_CONTAINER (window), 10); + + /* Create an aspect_frame and add it to our toplevel window */ + + aspect_frame = gtk_aspect_frame_new ("2x1", /* label */ + 0.5, /* center x */ + 0.5, /* center y */ + 2, /* xsize/ysize = 2 */ + FALSE /* ignore child's aspect */); + + gtk_container_add (GTK_CONTAINER(window), aspect_frame); + gtk_widget_show (aspect_frame); + + /* Now add a child widget to the aspect frame */ + + drawing_area = gtk_drawing_area_new (); + + /* Ask for a 200x200 window, but the AspectFrame will give us a 200x100 + * window since we are forcing a 2x1 aspect ratio */ + gtk_widget_set_usize (drawing_area, 200, 200); + gtk_container_add (GTK_CONTAINER(aspect_frame), drawing_area); + gtk_widget_show (drawing_area); + + gtk_widget_show (window); + gtk_main (); + return 0; +} + + List Widgets @@ -4751,7 +5019,7 @@ int main (int argc, char *argv[]) gtk_widget_set_usize( GTK_WIDGET (window), 200, 100); gtk_window_set_title(GTK_WINDOW (window), "GTK Menu Test"); gtk_signal_connect(GTK_OBJECT (window), "delete_event", - (GtkSignalFunc) gtk_exit, NULL); + (GtkSignalFunc) gtk_main_quit, NULL); /* Init the menu-widget, and remember -- never * gtk_show_widget() the menu widget!! diff --git a/docs/tutorial/gtk_tut.sgml b/docs/tutorial/gtk_tut.sgml index 6365508e26..4319216073 100644 --- a/docs/tutorial/gtk_tut.sgml +++ b/docs/tutorial/gtk_tut.sgml @@ -9,7 +9,7 @@ Ian Main , Tony Gale March 29th, 1998 @@ -3801,9 +3801,9 @@ direction, and the second, the adjustment for the vertical direction. These are almost always set to NULL. -void gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window, - GtkPolicyType hscrollbar_policy, - GtkPolicyType vscrollbar_policy); +void gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window, + GtkPolicyType hscrollbar_policy, + GtkPolicyType vscrollbar_policy); This sets the policy to be used with respect to the scrollbars. @@ -3882,13 +3882,13 @@ int main (int argc, char *argv[]) /* this simply creates a grid of toggle buttons on the table * to demonstrate the scrolled window. */ for (i = 0; i < 10; i++) - for (j = 0; j < 10; j++) { - sprintf (buffer, "button (%d,%d)\n", i, j); - button = gtk_toggle_button_new_with_label (buffer); - gtk_table_attach_defaults (GTK_TABLE (table), button, - i, i+1, j, j+1); - gtk_widget_show (button); - } + for (j = 0; j < 10; j++) { + sprintf (buffer, "button (%d,%d)\n", i, j); + button = gtk_toggle_button_new_with_label (buffer); + gtk_table_attach_defaults (GTK_TABLE (table), button, + i, i+1, j, j+1); + gtk_widget_show (button); + } /* Add a "close" button to the bottom of the dialog */ button = gtk_button_new_with_label ("close"); @@ -3918,6 +3918,274 @@ Try playing with resizing the window. You'll notice how the scrollbars react. You may also wish to use the gtk_widget_set_usize() call to set the default size of the window or other widgets. + + Paned Window Widgets +

+The paned window widgets are useful when you want to divide an area +into two parts, with the relative size of the two parts controlled by +the user. A groove is drawn between the two portions with a handle +that the user can drag to change the ratio. The division can either +be horizontal (HPaned) or vertical (VPaned). + +To create a new paned window, call one of: + + +GtkWidget* gtk_hpaned_new (void) +GtkWidget* gtk_vpaned_new (void) + + +After creating the paned window widget, you need to add child widgets +to its two halves. To do this, use the functions: + + +void gtk_paned_add1 (GtkPaned *paned, GtkWidget *child) +void gtk_paned_add2 (GtkPaned *paned, GtkWidget *child) + + + +/* paned.c */ + +#include + +/* Create the list of "messages" */ +GtkWidget * +create_list (void) +{ + + GtkWidget *scrolled_window; + GtkWidget *list; + GtkWidget *list_item; + + int i; + char buffer[16]; + + /* Create a new scrolled window, with scrollbars only if needed */ + scrolled_window = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + + /* Create a new list and put it in the scrolled window */ + list = gtk_list_new (); + gtk_container_add (GTK_CONTAINER(scrolled_window), list); + gtk_widget_show (list); + + /* Add some messages to the window */ + for (i=0; i<10; i++) { + + sprintf(buffer,"Message #%d",i); + list_item = gtk_list_item_new_with_label (buffer); + gtk_container_add (GTK_CONTAINER(list), list_item); + gtk_widget_show (list_item); + + } + + return scrolled_window; +} + +/* Add some text to our text widget - this is a callback that is invoked +when our window is realized. We could also force our window to be +realized with gtk_widget_realize, but it would have to be part of +a hierarchy first */ + +void +realize_text (GtkWidget *text, gpointer data) +{ + gtk_text_freeze (GTK_TEXT (text)); + gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, + "From: pathfinder@nasa.gov\n" + "To: mom@nasa.gov\n" + "Subject: Made it!\n" + "\n" + "We just got in this morning. The weather has been\n" + "great - clear but cold, and there are lots of fun sights.\n" + "Sojourner says hi. See you soon.\n" + " -Path\n", -1); + + gtk_text_thaw (GTK_TEXT (text)); +} + +/* Create a scrolled text area that displays a "message" */ +GtkWidget * +create_text (void) +{ + GtkWidget *table; + GtkWidget *text; + GtkWidget *hscrollbar; + GtkWidget *vscrollbar; + + /* Create a table to hold the text widget and scrollbars */ + table = gtk_table_new (2, 2, FALSE); + + /* Put a text widget in the upper left hand corner. Note the use of + * GTK_SHRINK in the y direction */ + text = gtk_text_new (NULL, NULL); + gtk_table_attach (GTK_TABLE (table), text, 0, 1, 0, 1, + GTK_FILL | GTK_EXPAND, + GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0); + gtk_widget_show (text); + + /* Put a HScrollbar in the lower left hand corner */ + hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj); + gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2, + GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); + gtk_widget_show (hscrollbar); + + /* And a VScrollbar in the upper right */ + vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj); + gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1, + GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); + gtk_widget_show (vscrollbar); + + /* Add a handler to put a message in the text widget when it is realized */ + gtk_signal_connect (GTK_OBJECT (text), "realize", + GTK_SIGNAL_FUNC (realize_text), NULL); + + return table; +} + +int +main (int argc, char *argv[]) +{ + GtkWidget *window; + GtkWidget *vpaned; + GtkWidget *list; + GtkWidget *text; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), "Paned Windows"); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_main_quit), NULL); + gtk_container_border_width (GTK_CONTAINER (window), 10); + + /* create a vpaned widget and add it to our toplevel window */ + + vpaned = gtk_vpaned_new (); + gtk_container_add (GTK_CONTAINER(window), vpaned); + gtk_widget_show (vpaned); + + /* Now create the contents of the two halves of the window */ + + list = create_list (); + gtk_paned_add1 (GTK_PANED(vpaned), list); + gtk_widget_show (list); + + text = create_text (); + gtk_paned_add2 (GTK_PANED(vpaned), text); + gtk_widget_show (text); + gtk_widget_show (window); + gtk_main (); + return 0; +} + + + + + Aspect Frames +

+The aspect frame widget is like a frame widget, except that it also +enforces the aspect ratio (that is, the ratio of the width to the +height) of the child widget to have a certain value, adding extra +space if necessary. This is useful, for instance, if you want to +preview a larger image. The size of the preview should vary when +the user resizes the window, but the aspect ratio needs to always match +the original image. + +To create a new aspect frame, use: + + +GtkWidget* gtk_aspect_frame_new (const gchar *label, + gfloat xalign, + gfloat yalign, + gfloat ratio, + gint obey_child) + + + +void gtk_aspect_frame_set (GtkAspectFrame *aspect_frame, + gfloat xalign, + gfloat yalign, + gfloat ratio, + gint obey_child) + + +

+As an example, the following program uses an AspectFrame to +present a drawing area whose aspect ratio will always be 2:1, no +matter how the user resizes the top-level window. + + +/* aspectframe.c */ + +#include + +int +main (int argc, char *argv[]) +{ + GtkWidget *window; + GtkWidget *aspect_frame; + GtkWidget *drawing_area; + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), "Aspect Frame"); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_main_quit), NULL); + gtk_container_border_width (GTK_CONTAINER (window), 10); + + /* Create an aspect_frame and add it to our toplevel window */ + + aspect_frame = gtk_aspect_frame_new ("2x1", /* label */ + 0.5, /* center x */ + 0.5, /* center y */ + 2, /* xsize/ysize = 2 */ + FALSE /* ignore child's aspect */); + + gtk_container_add (GTK_CONTAINER(window), aspect_frame); + gtk_widget_show (aspect_frame); + + /* Now add a child widget to the aspect frame */ + + drawing_area = gtk_drawing_area_new (); + + /* Ask for a 200x200 window, but the AspectFrame will give us a 200x100 + * window since we are forcing a 2x1 aspect ratio */ + gtk_widget_set_usize (drawing_area, 200, 200); + gtk_container_add (GTK_CONTAINER(aspect_frame), drawing_area); + gtk_widget_show (drawing_area); + + gtk_widget_show (window); + gtk_main (); + return 0; +} + + List Widgets @@ -4751,7 +5019,7 @@ int main (int argc, char *argv[]) gtk_widget_set_usize( GTK_WIDGET (window), 200, 100); gtk_window_set_title(GTK_WINDOW (window), "GTK Menu Test"); gtk_signal_connect(GTK_OBJECT (window), "delete_event", - (GtkSignalFunc) gtk_exit, NULL); + (GtkSignalFunc) gtk_main_quit, NULL); /* Init the menu-widget, and remember -- never * gtk_show_widget() the menu widget!! diff --git a/examples/aspectframe/Makefile b/examples/aspectframe/Makefile new file mode 100644 index 0000000000..fe8b11e286 --- /dev/null +++ b/examples/aspectframe/Makefile @@ -0,0 +1,8 @@ + +CC = gcc + +aspectframe: aspectframe.c + $(CC) `gtk-config --cflags` `gtk-config --libs` aspectframe.c -o aspectframe + +clean: + rm -f *.o aspectframe diff --git a/examples/aspectframe/aspectframe.c b/examples/aspectframe/aspectframe.c new file mode 100644 index 0000000000..0376bf92b9 --- /dev/null +++ b/examples/aspectframe/aspectframe.c @@ -0,0 +1,43 @@ +/* aspectframe.c */ + +#include + +int +main (int argc, char *argv[]) +{ + GtkWidget *window; + GtkWidget *aspect_frame; + GtkWidget *drawing_area; + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), "Aspect Frame"); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_main_quit), NULL); + gtk_container_border_width (GTK_CONTAINER (window), 10); + + /* Create an aspect_frame and add it to our toplevel window */ + + aspect_frame = gtk_aspect_frame_new ("2x1", /* label */ + 0.5, /* center x */ + 0.5, /* center y */ + 2, /* xsize/ysize = 2 */ + FALSE /* ignore child's aspect */); + + gtk_container_add (GTK_CONTAINER(window), aspect_frame); + gtk_widget_show (aspect_frame); + + /* Now add a child widget to the aspect frame */ + + drawing_area = gtk_drawing_area_new (); + + /* Ask for a 200x200 window, but the AspectFrame will give us a 200x100 + * window since we are forcing a 2x1 aspect ratio */ + gtk_widget_set_usize (drawing_area, 200, 200); + gtk_container_add (GTK_CONTAINER(aspect_frame), drawing_area); + gtk_widget_show (drawing_area); + + gtk_widget_show (window); + gtk_main (); + return 0; +} diff --git a/examples/paned/Makefile b/examples/paned/Makefile new file mode 100644 index 0000000000..7e2c010867 --- /dev/null +++ b/examples/paned/Makefile @@ -0,0 +1,8 @@ + +CC = gcc + +paned: paned.c + $(CC) `gtk-config --cflags` `gtk-config --libs` paned.c -o paned + +clean: + rm -f *.o paned diff --git a/examples/paned/paned.c b/examples/paned/paned.c new file mode 100644 index 0000000000..46b7c6e12d --- /dev/null +++ b/examples/paned/paned.c @@ -0,0 +1,136 @@ +/* paned.c */ + +#include + +/* Create the list of "messages" */ +GtkWidget * +create_list (void) +{ + + GtkWidget *scrolled_window; + GtkWidget *list; + GtkWidget *list_item; + + int i; + char buffer[16]; + + /* Create a new scrolled window, with scrollbars only if needed */ + scrolled_window = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + + /* Create a new list and put it in the scrolled window */ + list = gtk_list_new (); + gtk_container_add (GTK_CONTAINER(scrolled_window), list); + gtk_widget_show (list); + + /* Add some messages to the window */ + for (i=0; i<10; i++) { + + sprintf(buffer,"Message #%d",i); + list_item = gtk_list_item_new_with_label (buffer); + gtk_container_add (GTK_CONTAINER(list), list_item); + gtk_widget_show (list_item); + + } + + return scrolled_window; +} + +/* Add some text to our text widget - this is a callback that is invoked +when our window is realized. We could also force our window to be +realized with gtk_widget_realize, but it would have to be part of +a hierarchy first */ + +void +realize_text (GtkWidget *text, gpointer data) +{ + gtk_text_freeze (GTK_TEXT (text)); + gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, + "From: pathfinder@nasa.gov\n" + "To: mom@nasa.gov\n" + "Subject: Made it!\n" + "\n" + "We just got in this morning. The weather has been\n" + "great - clear but cold, and there are lots of fun sights.\n" + "Sojourner says hi. See you soon.\n" + " -Path\n", -1); + + gtk_text_thaw (GTK_TEXT (text)); +} + +/* Create a scrolled text area that displays a "message" */ +GtkWidget * +create_text (void) +{ + GtkWidget *table; + GtkWidget *text; + GtkWidget *hscrollbar; + GtkWidget *vscrollbar; + + /* Create a table to hold the text widget and scrollbars */ + table = gtk_table_new (2, 2, FALSE); + + /* Put a text widget in the upper left hand corner. Note the use of + * GTK_SHRINK in the y direction */ + text = gtk_text_new (NULL, NULL); + gtk_table_attach (GTK_TABLE (table), text, 0, 1, 0, 1, + GTK_FILL | GTK_EXPAND, + GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0); + gtk_widget_show (text); + + /* Put a HScrollbar in the lower left hand corner */ + hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj); + gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2, + GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); + gtk_widget_show (hscrollbar); + + /* And a VScrollbar in the upper right */ + vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj); + gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1, + GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); + gtk_widget_show (vscrollbar); + + /* Add a handler to put a message in the text widget when it is realized */ + gtk_signal_connect (GTK_OBJECT (text), "realize", + GTK_SIGNAL_FUNC (realize_text), NULL); + + return table; +} + +int +main (int argc, char *argv[]) +{ + GtkWidget *window; + GtkWidget *vpaned; + GtkWidget *list; + GtkWidget *text; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), "Paned Windows"); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_main_quit), NULL); + gtk_container_border_width (GTK_CONTAINER (window), 10); + + /* create a vpaned widget and add it to our toplevel window */ + + vpaned = gtk_vpaned_new (); + gtk_container_add (GTK_CONTAINER(window), vpaned); + gtk_widget_show (vpaned); + + /* Now create the contents of the two halves of the window */ + + list = create_list (); + gtk_paned_add1 (GTK_PANED(vpaned), list); + gtk_widget_show (list); + + text = create_text (); + gtk_paned_add2 (GTK_PANED(vpaned), text); + gtk_widget_show (text); + gtk_widget_show (window); + gtk_main (); + return 0; +}