summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGMT 1998 Tony Gale <gale@gtk.org>1998-12-13 22:25:07 +0000
committerTony Gale <gale@src.gnome.org>1998-12-13 22:25:07 +0000
commit113448e030fa5a554354ce8a77771d8de44d5b02 (patch)
tree531e212a6beed1410e4dc5ec5c38a2d009042134 /examples
parent6d6d3a59b88c31fefae4a7de5bc190e056c5417e (diff)
downloadgdk-pixbuf-113448e030fa5a554354ce8a77771d8de44d5b02.tar.gz
Update the following sections to the current API: - Container Widgets -
Sun Dec 13 22:15:48 GMT 1998 Tony Gale <gale@gtk.org> * docs/gtk_tut.sgml: Update the following sections to the current API: - Container Widgets - CList Widget - List Widget - Tree Widget
Diffstat (limited to 'examples')
-rw-r--r--examples/clist/clist.c8
-rw-r--r--examples/list/list.c147
-rw-r--r--examples/notebook/notebook.c25
-rw-r--r--examples/paned/paned.c10
-rw-r--r--examples/scrolledwin/scrolledwin.c9
-rw-r--r--examples/tree/tree.c3
6 files changed, 98 insertions, 104 deletions
diff --git a/examples/clist/clist.c b/examples/clist/clist.c
index 430deb268..69a252dee 100644
--- a/examples/clist/clist.c
+++ b/examples/clist/clist.c
@@ -45,7 +45,7 @@ gint main (int argc, gchar *argv[])
NULL);
/* It isn't necessary to shadow the border, but it looks nice :) */
- gtk_clist_set_border(GTK_CLIST(clist), GTK_SHADOW_OUT);
+ gtk_clist_set_shadow_type (GTK_CLIST(clist), GTK_SHADOW_OUT);
/* What however is important, is that we set the column widths as
* they will never be right otherwise. Note that the columns are
@@ -53,10 +53,6 @@ gint main (int argc, gchar *argv[])
*/
gtk_clist_set_column_width (GTK_CLIST(clist), 0, 150);
- /* Scollbars _only when needed_ */
- gtk_clist_set_policy(GTK_CLIST(clist), GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
-
/* Add the GtkCList widget to the vertical box and show it. */
gtk_box_pack_start(GTK_BOX(vbox), clist, TRUE, TRUE, 0);
gtk_widget_show(clist);
@@ -97,7 +93,7 @@ gint main (int argc, gchar *argv[])
gtk_widget_show(window);
gtk_main();
- return 0;
+ return(0);
}
/* User clicked the "Add List" button. */
diff --git a/examples/list/list.c b/examples/list/list.c
index abf81f2c0..2cc4092b2 100644
--- a/examples/list/list.c
+++ b/examples/list/list.c
@@ -1,50 +1,52 @@
/* example-start list list.c */
-/* include the gtk+ header files
- * include stdio.h, we need that for the printf() function
+/* Include the gtk+ header files
+ * Include stdio.h, we need that for the printf() function
*/
#include <gtk/gtk.h>
#include <stdio.h>
-/* this is our data identification string to store
+/* This is our data identification string to store
* data in list items
*/
-const gchar *list_item_data_key="list_item_data";
+const gchar *list_item_data_key="list_item_data";
/* prototypes for signal handler that we are going to connect
* to the GtkList widget
*/
-static void sigh_print_selection (GtkWidget *gtklist,
- gpointer func_data);
-static void sigh_button_event (GtkWidget *gtklist,
- GdkEventButton *event,
- GtkWidget *frame);
+static void sigh_print_selection( GtkWidget *gtklist,
+ gpointer func_data);
+static void sigh_button_event( GtkWidget *gtklist,
+ GdkEventButton *event,
+ GtkWidget *frame );
-/* main function to set up the user interface */
-gint main (int argc, gchar *argv[])
+/* Main function to set up the user interface */
+
+gint main (int argc,
+ gchar *argv[])
{
- GtkWidget *separator;
- GtkWidget *window;
- GtkWidget *vbox;
- GtkWidget *scrolled_window;
- GtkWidget *frame;
- GtkWidget *gtklist;
- GtkWidget *button;
- GtkWidget *list_item;
- GList *dlist;
- guint i;
- gchar buffer[64];
+ GtkWidget *separator;
+ GtkWidget *window;
+ GtkWidget *vbox;
+ GtkWidget *scrolled_window;
+ GtkWidget *frame;
+ GtkWidget *gtklist;
+ GtkWidget *button;
+ GtkWidget *list_item;
+ GList *dlist;
+ guint i;
+ gchar buffer[64];
- /* initialize gtk+ (and subsequently gdk) */
+ /* Initialize gtk+ (and subsequently gdk) */
gtk_init(&argc, &argv);
- /* create a window to put all the widgets in
+ /* Create a window to put all the widgets in
* connect gtk_main_quit() to the "destroy" event of
* the window to handle window manager close-window-events
*/
@@ -56,34 +58,34 @@ gint main (int argc, gchar *argv[])
NULL);
- /* inside the window we need a box to arrange the widgets
+ /* Inside the window we need a box to arrange the widgets
* vertically */
vbox=gtk_vbox_new(FALSE, 5);
gtk_container_border_width(GTK_CONTAINER(vbox), 5);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show(vbox);
- /* this is the scrolled window to put the GtkList widget inside */
+ /* This is the scrolled window to put the GtkList widget inside */
scrolled_window=gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_usize(scrolled_window, 250, 150);
gtk_container_add(GTK_CONTAINER(vbox), scrolled_window);
gtk_widget_show(scrolled_window);
- /* create the GtkList widget
- * connect the sigh_print_selection() signal handler
+ /* Create the GtkList widget.
+ * Connect the sigh_print_selection() signal handler
* function to the "selection_changed" signal of the GtkList
* to print out the selected items each time the selection
* has changed */
gtklist=gtk_list_new();
- gtk_container_add(GTK_CONTAINER(scrolled_window), gtklist);
+ gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(scrolled_window),
+ gtklist);
gtk_widget_show(gtklist);
gtk_signal_connect(GTK_OBJECT(gtklist),
"selection_changed",
GTK_SIGNAL_FUNC(sigh_print_selection),
NULL);
- /* we create a "Prison" to put a list item in ;)
- */
+ /* We create a "Prison" to put a list item in ;) */
frame=gtk_frame_new("Prison");
gtk_widget_set_usize(frame, 200, 50);
gtk_container_border_width(GTK_CONTAINER(frame), 5);
@@ -91,7 +93,7 @@ gint main (int argc, gchar *argv[])
gtk_container_add(GTK_CONTAINER(vbox), frame);
gtk_widget_show(frame);
- /* connect the sigh_button_event() signal handler to the GtkList
+ /* Connect the sigh_button_event() signal handler to the GtkList
* which will handle the "arresting" of list items
*/
gtk_signal_connect(GTK_OBJECT(gtklist),
@@ -99,15 +101,13 @@ gint main (int argc, gchar *argv[])
GTK_SIGNAL_FUNC(sigh_button_event),
frame);
- /* create a separator
- */
+ /* Create a separator */
separator=gtk_hseparator_new();
gtk_container_add(GTK_CONTAINER(vbox), separator);
gtk_widget_show(separator);
- /* finally create a button and connect itīs "clicked" signal
- * to the destruction of the window
- */
+ /* Finally create a button and connect it's "clicked" signal
+ * to the destruction of the window */
button=gtk_button_new_with_label("Close");
gtk_container_add(GTK_CONTAINER(vbox), button);
gtk_widget_show(button);
@@ -117,9 +117,9 @@ gint main (int argc, gchar *argv[])
GTK_OBJECT(window));
- /* now we create 5 list items, each having itīs own
+ /* Now we create 5 list items, each having it's own
* label and add them to the GtkList using gtk_container_add()
- * also we query the text string from the label and
+ * Also we query the text string from the label and
* associate it with the list_item_data_key for each list item
*/
for (i=0; i<5; i++) {
@@ -138,16 +138,16 @@ gint main (int argc, gchar *argv[])
list_item_data_key,
string);
}
- /* here, we are creating another 5 labels, this time
+ /* Here, we are creating another 5 labels, this time
* we use gtk_list_item_new_with_label() for the creation
- * we canīt query the text string from the label because
- * we donīt have the labels pointer and therefore
+ * we can't query the text string from the label because
+ * we don't have the labels pointer and therefore
* we just associate the list_item_data_key of each
- * list item with the same text string
- * for adding of the list items we put them all into a doubly
+ * list item with the same text string.
+ * For adding of the list items we put them all into a doubly
* linked list (GList), and then add them by a single call to
- * gtk_list_append_items()
- * because we use g_list_prepend() to put the items into the
+ * gtk_list_append_items().
+ * Because we use g_list_prepend() to put the items into the
* doubly linked list, their order will be descending (instead
* of ascending when using g_list_append())
*/
@@ -163,29 +163,26 @@ gint main (int argc, gchar *argv[])
}
gtk_list_append_items(GTK_LIST(gtklist), dlist);
- /* finally we want to see the window, don't we? ;)
- */
+ /* Finally we want to see the window, don't we? ;) */
gtk_widget_show(window);
- /* fire up the main event loop of gtk
- */
+ /* Fire up the main event loop of gtk */
gtk_main();
- /* we get here after gtk_main_quit() has been called which
+ /* We get here after gtk_main_quit() has been called which
* happens if the main window gets destroyed
*/
- return 0;
+ return(0);
}
-/* this is the signal handler that got connected to button
+/* This is the signal handler that got connected to button
* press/release events of the GtkList
*/
-void
-sigh_button_event (GtkWidget *gtklist,
- GdkEventButton *event,
- GtkWidget *frame)
+void sigh_button_event( GtkWidget *gtklist,
+ GdkEventButton *event,
+ GtkWidget *frame )
{
- /* we only do something if the third (rightmost mouse button
+ /* We only do something if the third (rightmost mouse button
* was released
*/
if (event->type==GDK_BUTTON_RELEASE &&
@@ -193,7 +190,7 @@ sigh_button_event (GtkWidget *gtklist,
GList *dlist, *free_list;
GtkWidget *new_prisoner;
- /* fetch the currently selected list item which
+ /* Fetch the currently selected list item which
* will be our next prisoner ;)
*/
dlist=GTK_LIST(gtklist)->selection;
@@ -202,9 +199,9 @@ sigh_button_event (GtkWidget *gtklist,
else
new_prisoner=NULL;
- /* look for already imprisoned list items, we
- * will put them back into the list
- * remember to free the doubly linked list that
+ /* Look for already imprisoned list items, we
+ * will put them back into the list.
+ * Remember to free the doubly linked list that
* gtk_container_children() returns
*/
dlist=gtk_container_children(GTK_CONTAINER(frame));
@@ -220,9 +217,9 @@ sigh_button_event (GtkWidget *gtklist,
}
g_list_free(free_list);
- /* if we have a new prisoner, remove him from the
- * GtkList and put him into the frame "Prison"
- * we need to unselect the item before
+ /* If we have a new prisoner, remove him from the
+ * GtkList and put him into the frame "Prison".
+ * We need to unselect the item first.
*/
if (new_prisoner) {
GList static_dlist;
@@ -238,35 +235,33 @@ sigh_button_event (GtkWidget *gtklist,
}
}
-/* this is the signal handler that gets called if GtkList
+/* This is the signal handler that gets called if GtkList
* emits the "selection_changed" signal
*/
-void
-sigh_print_selection (GtkWidget *gtklist,
- gpointer func_data)
+void sigh_print_selection( GtkWidget *gtklist,
+ gpointer func_data)
{
GList *dlist;
- /* fetch the doubly linked list of selected items
+ /* Fetch the doubly linked list of selected items
* of the GtkList, remember to treat this as read-only!
*/
dlist=GTK_LIST(gtklist)->selection;
- /* if there are no selected items there is nothing more
+ /* If there are no selected items there is nothing more
* to do than just telling the user so
*/
if (!dlist) {
g_print("Selection cleared\n");
return;
}
- /* ok, we got a selection and so we print it
+ /* Ok, we got a selection and so we print it
*/
g_print("The selection is a ");
- /* get the list item from the doubly linked list
- * and then query the data associated with list_item_data_key
- * we then just print it
- */
+ /* Get the list item from the doubly linked list
+ * and then query the data associated with list_item_data_key.
+ * We then just print it */
while (dlist) {
GtkObject *list_item;
gchar *item_data_string;
diff --git a/examples/notebook/notebook.c b/examples/notebook/notebook.c
index 62508eab0..f1c8a4767 100644
--- a/examples/notebook/notebook.c
+++ b/examples/notebook/notebook.c
@@ -27,7 +27,7 @@ void remove_book (GtkButton *button, GtkNotebook *notebook)
{
gint page;
- page = gtk_notebook_current_page(notebook);
+ page = gtk_notebook_get_current_page(notebook);
gtk_notebook_remove_page (notebook, page);
/* Need to refresh the widget --
This forces the widget to redraw itself. */
@@ -60,8 +60,8 @@ int main (int argc, char *argv[])
GTK_SIGNAL_FUNC (delete), NULL);
gtk_container_border_width (GTK_CONTAINER (window), 10);
-
- table = gtk_table_new(2,6,TRUE);
+
+ table = gtk_table_new(3,6,FALSE);
gtk_container_add (GTK_CONTAINER (window), table);
/* Create a new notebook, place the position of the tabs */
@@ -70,7 +70,7 @@ int main (int argc, char *argv[])
gtk_table_attach_defaults(GTK_TABLE(table), notebook, 0,6,0,1);
gtk_widget_show(notebook);
- /* lets append a bunch of pages to the notebook */
+ /* Lets append a bunch of pages to the notebook */
for (i=0; i < 5; i++) {
sprintf(bufferf, "Append Frame %d", i+1);
sprintf(bufferl, "Page %d", i+1);
@@ -87,16 +87,12 @@ int main (int argc, char *argv[])
label = gtk_label_new (bufferl);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
}
-
-
- /* now lets add a page to a specific spot */
+
+ /* Now lets add a page to a specific spot */
checkbutton = gtk_check_button_new_with_label ("Check me please!");
gtk_widget_set_usize(checkbutton, 100, 75);
gtk_widget_show (checkbutton);
-
- label = gtk_label_new ("Add spot");
- gtk_container_add (GTK_CONTAINER (checkbutton), label);
- gtk_widget_show (label);
+
label = gtk_label_new ("Add page");
gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), checkbutton, label, 2);
@@ -120,9 +116,8 @@ int main (int argc, char *argv[])
/* Set what page to start at (page 4) */
gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 3);
-
-
- /* create a bunch of buttons */
+
+ /* Create a bunch of buttons */
button = gtk_button_new_with_label ("close");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (delete), NULL);
@@ -168,6 +163,6 @@ int main (int argc, char *argv[])
gtk_main ();
- return 0;
+ return(0);
}
/* example-end */
diff --git a/examples/paned/paned.c b/examples/paned/paned.c
index 86c31081a..249d568ae 100644
--- a/examples/paned/paned.c
+++ b/examples/paned/paned.c
@@ -22,7 +22,8 @@ create_list (void)
/* Create a new list and put it in the scrolled window */
list = gtk_list_new ();
- gtk_container_add (GTK_CONTAINER(scrolled_window), list);
+ gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
+ list);
gtk_widget_show (list);
/* Add some messages to the window */
@@ -114,11 +115,16 @@ main (int argc, char *argv[])
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
gtk_container_border_width (GTK_CONTAINER (window), 10);
-
+ gtk_widget_set_usize (GTK_WIDGET(window), 450, 400);
+
/* create a vpaned widget and add it to our toplevel window */
vpaned = gtk_vpaned_new ();
gtk_container_add (GTK_CONTAINER(window), vpaned);
+ gtk_paned_set_handle_size (GTK_PANED(vpaned),
+ 10);
+ gtk_paned_set_gutter_size (GTK_PANED(vpaned),
+ 15);
gtk_widget_show (vpaned);
/* Now create the contents of the two halves of the window */
diff --git a/examples/scrolledwin/scrolledwin.c b/examples/scrolledwin/scrolledwin.c
index f222d7510..29df87a9d 100644
--- a/examples/scrolledwin/scrolledwin.c
+++ b/examples/scrolledwin/scrolledwin.c
@@ -19,13 +19,13 @@ int main (int argc, char *argv[])
gtk_init (&argc, &argv);
/* Create a new dialog window for the scrolled window to be
- * packed into. A dialog is just like a normal window except it has a
- * vbox and a horizontal separator packed into it. It's just a shortcut
+ * packed into. A dialog is just like a normal window except it has a
+ * vbox and a horizontal separator packed into it. It's just a shortcut
* for creating dialogs */
window = gtk_dialog_new ();
gtk_signal_connect (GTK_OBJECT (window), "destroy",
(GtkSignalFunc) destroy, NULL);
- gtk_window_set_title (GTK_WINDOW (window), "dialog");
+ gtk_window_set_title (GTK_WINDOW (window), "GtkScrolledWindow example");
gtk_container_border_width (GTK_CONTAINER (window), 0);
gtk_widget_set_usize(window, 300, 300);
@@ -54,7 +54,8 @@ int main (int argc, char *argv[])
gtk_table_set_col_spacings (GTK_TABLE (table), 10);
/* pack the table into the scrolled window */
- gtk_container_add (GTK_CONTAINER (scrolled_window), table);
+ gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
+ table);
gtk_widget_show (table);
/* this simply creates a grid of toggle buttons on the table
diff --git a/examples/tree/tree.c b/examples/tree/tree.c
index e4613ef7d..d709300fa 100644
--- a/examples/tree/tree.c
+++ b/examples/tree/tree.c
@@ -93,7 +93,8 @@ int main (int argc, char *argv[])
gtk_signal_connect (GTK_OBJECT(tree), "selection_changed",
GTK_SIGNAL_FUNC(cb_selection_changed), tree);
/* Add it to the scrolled window */
- gtk_container_add (GTK_CONTAINER(scrolled_win), tree);
+ gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrolled_win),
+ tree);
/* Set the selection mode */
gtk_tree_set_selection_mode (GTK_TREE(tree),
GTK_SELECTION_MULTIPLE);