summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGMT 1999 Tony Gale <gale@gtk.org>1999-02-01 10:44:36 +0000
committerTony Gale <gale@src.gnome.org>1999-02-01 10:44:36 +0000
commit5ef056ea949b4a6c6d3bf970ba712f31c8835f5e (patch)
tree7c8ae244a8e9934cd7437308594e2d9443cf73b1 /examples
parentc39dffed55915a9367df8aba7c6eb237da30a66f (diff)
downloadgtk+-5ef056ea949b4a6c6d3bf970ba712f31c8835f5e.tar.gz
- Complete documentation of Label widget API - New sections for the
Mon Feb 1 09:16:03 GMT 1999 Tony Gale <gale@gtk.org> * docs/gtk_tut.sgml: - Complete documentation of Label widget API - New sections for the following: * Arrows * Alignment * Button Boxes * Viewports * examples/arrow/*, examples/buttonbox/*, examples/label/* - New code examples
Diffstat (limited to 'examples')
-rw-r--r--examples/arrow/Makefile8
-rw-r--r--examples/arrow/arrow.c74
-rw-r--r--examples/buttonbox/Makefile8
-rw-r--r--examples/buttonbox/buttonbox.c122
-rw-r--r--examples/label/Makefile8
-rw-r--r--examples/label/label.c102
6 files changed, 322 insertions, 0 deletions
diff --git a/examples/arrow/Makefile b/examples/arrow/Makefile
new file mode 100644
index 0000000000..1430c18141
--- /dev/null
+++ b/examples/arrow/Makefile
@@ -0,0 +1,8 @@
+
+CC = gcc
+
+arrow: arrow.c
+ $(CC) `gtk-config --cflags` arrow.c -o arrow `gtk-config --libs`
+
+clean:
+ rm -f *.o arrow
diff --git a/examples/arrow/arrow.c b/examples/arrow/arrow.c
new file mode 100644
index 0000000000..69cb49c434
--- /dev/null
+++ b/examples/arrow/arrow.c
@@ -0,0 +1,74 @@
+/* example-start arrow arrow.c */
+
+#include <gtk/gtk.h>
+
+/* Create an Arrow widget with the specified parameters
+ * and pack it into a button */
+GtkWidget *create_arrow_button( GtkArrowType arrow_type,
+ GtkShadowType shadow_type )
+{
+ GtkWidget *button;
+ GtkWidget *arrow;
+
+ button = gtk_button_new();
+ arrow = gtk_arrow_new (arrow_type, shadow_type);
+
+ gtk_container_add (GTK_CONTAINER (button), arrow);
+
+ gtk_widget_show(button);
+ gtk_widget_show(arrow);
+
+ return(button);
+}
+
+int main( int argc,
+ char *argv[] )
+{
+ /* GtkWidget is the storage type for widgets */
+ GtkWidget *window;
+ GtkWidget *button;
+ GtkWidget *box;
+
+ /* Initialize the toolkit */
+ gtk_init (&argc, &argv);
+
+ /* Create a new window */
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ gtk_window_set_title (GTK_WINDOW (window), "Arrow Buttons");
+
+ /* It's a good idea to do this for all windows. */
+ gtk_signal_connect (GTK_OBJECT (window), "destroy",
+ GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
+
+ /* Sets the border width of the window. */
+ gtk_container_set_border_width (GTK_CONTAINER (window), 10);
+
+ /* Create a box to hold the arrows/buttons */
+ box = gtk_hbox_new (FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (box), 2);
+ gtk_container_add (GTK_CONTAINER (window), box);
+
+ /* Pack and show all our widgets */
+ gtk_widget_show(box);
+
+ button = create_arrow_button(GTK_ARROW_UP, GTK_SHADOW_IN);
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 3);
+
+ button = create_arrow_button(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 3);
+
+ button = create_arrow_button(GTK_ARROW_LEFT, GTK_SHADOW_ETCHED_IN);
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 3);
+
+ button = create_arrow_button(GTK_ARROW_RIGHT, GTK_SHADOW_ETCHED_OUT);
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 3);
+
+ gtk_widget_show (window);
+
+ /* Rest in gtk_main and wait for the fun to begin! */
+ gtk_main ();
+
+ return(0);
+}
+/* example-end */
diff --git a/examples/buttonbox/Makefile b/examples/buttonbox/Makefile
new file mode 100644
index 0000000000..4457ff3fc6
--- /dev/null
+++ b/examples/buttonbox/Makefile
@@ -0,0 +1,8 @@
+
+CC = gcc
+
+buttonbox: buttonbox.c
+ $(CC) `gtk-config --cflags` buttonbox.c -o buttonbox `gtk-config --libs`
+
+clean:
+ rm -f *.o buttonbox
diff --git a/examples/buttonbox/buttonbox.c b/examples/buttonbox/buttonbox.c
new file mode 100644
index 0000000000..46ee861a07
--- /dev/null
+++ b/examples/buttonbox/buttonbox.c
@@ -0,0 +1,122 @@
+/* example-start buttonbox buttonbox.c */
+
+#include <gtk/gtk.h>
+
+/* Create a Button Box with the specified parameters */
+GtkWidget *create_bbox (gint horizontal,
+ char* title,
+ gint spacing,
+ gint child_w,
+ gint child_h,
+ gint layout)
+{
+ GtkWidget *frame;
+ GtkWidget *bbox;
+ GtkWidget *button;
+
+ frame = gtk_frame_new (title);
+
+ if (horizontal)
+ bbox = gtk_hbutton_box_new ();
+ else
+ bbox = gtk_vbutton_box_new ();
+
+ gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
+ gtk_container_add (GTK_CONTAINER (frame), bbox);
+
+ /* Set the appearance of the Button Box */
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
+ gtk_button_box_set_spacing (GTK_BUTTON_BOX (bbox), spacing);
+ gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), child_w, child_h);
+
+ button = gtk_button_new_with_label ("OK");
+ gtk_container_add (GTK_CONTAINER (bbox), button);
+
+ button = gtk_button_new_with_label ("Cancel");
+ gtk_container_add (GTK_CONTAINER (bbox), button);
+
+ button = gtk_button_new_with_label ("Help");
+ gtk_container_add (GTK_CONTAINER (bbox), button);
+
+ return(frame);
+}
+
+int main( int argc,
+ char *argv[] )
+{
+ static GtkWidget* window = NULL;
+ GtkWidget *main_vbox;
+ GtkWidget *vbox;
+ GtkWidget *hbox;
+ GtkWidget *frame_horz;
+ GtkWidget *frame_vert;
+
+ /* Initialize GTK */
+ gtk_init( &argc, &argv );
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (window), "Button Boxes");
+
+ gtk_signal_connect (GTK_OBJECT (window), "destroy",
+ GTK_SIGNAL_FUNC(gtk_main_quit),
+ NULL);
+
+ gtk_container_set_border_width (GTK_CONTAINER (window), 10);
+
+ main_vbox = gtk_vbox_new (FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (window), main_vbox);
+
+ frame_horz = gtk_frame_new ("Horizontal Button Boxes");
+ gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10);
+
+ vbox = gtk_vbox_new (FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
+ gtk_container_add (GTK_CONTAINER (frame_horz), vbox);
+
+ gtk_box_pack_start (GTK_BOX (vbox),
+ create_bbox (TRUE, "Spread (spacing 40)", 40, 85, 20, GTK_BUTTONBOX_SPREAD),
+ TRUE, TRUE, 0);
+
+ gtk_box_pack_start (GTK_BOX (vbox),
+ create_bbox (TRUE, "Edge (spacing 30)", 30, 85, 20, GTK_BUTTONBOX_EDGE),
+ TRUE, TRUE, 5);
+
+ gtk_box_pack_start (GTK_BOX (vbox),
+ create_bbox (TRUE, "Start (spacing 20)", 20, 85, 20, GTK_BUTTONBOX_START),
+ TRUE, TRUE, 5);
+
+ gtk_box_pack_start (GTK_BOX (vbox),
+ create_bbox (TRUE, "End (spacing 10)", 10, 85, 20, GTK_BUTTONBOX_END),
+ TRUE, TRUE, 5);
+
+ frame_vert = gtk_frame_new ("Vertical Button Boxes");
+ gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert, TRUE, TRUE, 10);
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
+ gtk_container_add (GTK_CONTAINER (frame_vert), hbox);
+
+ gtk_box_pack_start (GTK_BOX (hbox),
+ create_bbox (FALSE, "Spread (spacing 5)", 5, 85, 20, GTK_BUTTONBOX_SPREAD),
+ TRUE, TRUE, 0);
+
+ gtk_box_pack_start (GTK_BOX (hbox),
+ create_bbox (FALSE, "Edge (spacing 30)", 30, 85, 20, GTK_BUTTONBOX_EDGE),
+ TRUE, TRUE, 5);
+
+ gtk_box_pack_start (GTK_BOX (hbox),
+ create_bbox (FALSE, "Start (spacing 20)", 20, 85, 20, GTK_BUTTONBOX_START),
+ TRUE, TRUE, 5);
+
+ gtk_box_pack_start (GTK_BOX (hbox),
+ create_bbox (FALSE, "End (spacing 20)", 20, 85, 20, GTK_BUTTONBOX_END),
+ TRUE, TRUE, 5);
+
+ gtk_widget_show_all (window);
+
+ /* Enter the event loop */
+ gtk_main ();
+
+ return(0);
+}
+/* example-end */
diff --git a/examples/label/Makefile b/examples/label/Makefile
new file mode 100644
index 0000000000..a5b299845e
--- /dev/null
+++ b/examples/label/Makefile
@@ -0,0 +1,8 @@
+
+CC = gcc
+
+label: label.c
+ $(CC) `gtk-config --cflags` label.c -o label `gtk-config --libs`
+
+clean:
+ rm -f *.o label
diff --git a/examples/label/label.c b/examples/label/label.c
new file mode 100644
index 0000000000..2a22a73d5e
--- /dev/null
+++ b/examples/label/label.c
@@ -0,0 +1,102 @@
+/* example-start label label.c */
+
+#include <gtk/gtk.h>
+
+int main( int argc,
+ char *argv[] )
+{
+ static GtkWidget *window = NULL;
+ GtkWidget *hbox;
+ GtkWidget *vbox;
+ GtkWidget *frame;
+ GtkWidget *label;
+
+ /* Initialise GTK */
+ gtk_init(&argc, &argv);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_signal_connect (GTK_OBJECT (window), "destroy",
+ GTK_SIGNAL_FUNC(gtk_main_quit),
+ NULL);
+
+ gtk_window_set_title (GTK_WINDOW (window), "Label");
+ vbox = gtk_vbox_new (FALSE, 5);
+ hbox = gtk_hbox_new (FALSE, 5);
+ gtk_container_add (GTK_CONTAINER (window), hbox);
+ gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (window), 5);
+
+ frame = gtk_frame_new ("Normal Label");
+ label = gtk_label_new ("This is a Normal label");
+ gtk_container_add (GTK_CONTAINER (frame), label);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+
+ frame = gtk_frame_new ("Multi-line Label");
+ label = gtk_label_new ("This is a Multi-line label.\nSecond line\n" \
+ "Third line");
+ gtk_container_add (GTK_CONTAINER (frame), label);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+
+ frame = gtk_frame_new ("Left Justified Label");
+ label = gtk_label_new ("This is a Left-Justified\n" \
+ "Multi-line label.\nThird line");
+ gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
+ gtk_container_add (GTK_CONTAINER (frame), label);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+
+ frame = gtk_frame_new ("Right Justified Label");
+ label = gtk_label_new ("This is a Right-Justified\nMulti-line label.\n" \
+ "Fourth line, (j/k)");
+ gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
+ gtk_container_add (GTK_CONTAINER (frame), label);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+
+ vbox = gtk_vbox_new (FALSE, 5);
+ gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
+ frame = gtk_frame_new ("Line wrapped label");
+ label = gtk_label_new ("This is an example of a line-wrapped label. It " \
+ "should not be taking up the entire " /* big space to test spacing */\
+ "width allocated to it, but automatically " \
+ "wraps the words to fit. " \
+ "The time has come, for all good men, to come to " \
+ "the aid of their party. " \
+ "The sixth sheik's six sheep's sick.\n" \
+ " It supports multiple paragraphs correctly, " \
+ "and correctly adds "\
+ "many extra spaces. ");
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_container_add (GTK_CONTAINER (frame), label);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+
+ frame = gtk_frame_new ("Filled, wrapped label");
+ label = gtk_label_new ("This is an example of a line-wrapped, filled label. " \
+ "It should be taking "\
+ "up the entire width allocated to it. " \
+ "Here is a seneance to prove "\
+ "my point. Here is another sentence. "\
+ "Here comes the sun, do de do de do.\n"\
+ " This is a new paragraph.\n"\
+ " This is another newer, longer, better " \
+ "paragraph. It is coming to an end, "\
+ "unfortunately.");
+ gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_FILL);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_container_add (GTK_CONTAINER (frame), label);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+
+ frame = gtk_frame_new ("Underlined label");
+ label = gtk_label_new ("This label is underlined!\n"
+ "This one is underlined in quite a funky fashion");
+ gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
+ gtk_label_set_pattern (GTK_LABEL (label),
+ "_________________________ _ _________ _ ______ __ _______ ___");
+ gtk_container_add (GTK_CONTAINER (frame), label);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+
+ gtk_widget_show_all (window);
+
+ gtk_main ();
+
+ return(0);
+}
+/* example-end */