Commit c36ca76b authored by Shawn Amundson's avatar Shawn Amundson

Tue Mar 31 15:41:57 PST 1998 Shawn T. Amundson

        * Makefile.am:
	* examples/*: added the rest of the tutorial examples
parent 30f22e02
Tue Mar 31 15:41:57 PST 1998 Shawn T. Amundson
* Makefile.am:
* examples/*: added the rest of the tutorial examples
Tue Mar 31 06:37:16 1998 Tim Janik <timj@gtk.org>
* gtk/testgtk.c (create_cursors): forgot to set the initial `0' cursor.
......
Tue Mar 31 15:41:57 PST 1998 Shawn T. Amundson
* Makefile.am:
* examples/*: added the rest of the tutorial examples
Tue Mar 31 06:37:16 1998 Tim Janik <timj@gtk.org>
* gtk/testgtk.c (create_cursors): forgot to set the initial `0' cursor.
......
Tue Mar 31 15:41:57 PST 1998 Shawn T. Amundson
* Makefile.am:
* examples/*: added the rest of the tutorial examples
Tue Mar 31 06:37:16 1998 Tim Janik <timj@gtk.org>
* gtk/testgtk.c (create_cursors): forgot to set the initial `0' cursor.
......
Tue Mar 31 15:41:57 PST 1998 Shawn T. Amundson
* Makefile.am:
* examples/*: added the rest of the tutorial examples
Tue Mar 31 06:37:16 1998 Tim Janik <timj@gtk.org>
* gtk/testgtk.c (create_cursors): forgot to set the initial `0' cursor.
......
Tue Mar 31 15:41:57 PST 1998 Shawn T. Amundson
* Makefile.am:
* examples/*: added the rest of the tutorial examples
Tue Mar 31 06:37:16 1998 Tim Janik <timj@gtk.org>
* gtk/testgtk.c (create_cursors): forgot to set the initial `0' cursor.
......
Tue Mar 31 15:41:57 PST 1998 Shawn T. Amundson
* Makefile.am:
* examples/*: added the rest of the tutorial examples
Tue Mar 31 06:37:16 1998 Tim Janik <timj@gtk.org>
* gtk/testgtk.c (create_cursors): forgot to set the initial `0' cursor.
......
Tue Mar 31 15:41:57 PST 1998 Shawn T. Amundson
* Makefile.am:
* examples/*: added the rest of the tutorial examples
Tue Mar 31 06:37:16 1998 Tim Janik <timj@gtk.org>
* gtk/testgtk.c (create_cursors): forgot to set the initial `0' cursor.
......
......@@ -12,6 +12,7 @@ EXTRA_DIST = \
TODO \
examples/gtkdial/Makefile \
examples/gtkdial/dial_test.c \
examples/gtkdial/gtkdial.h \
examples/gtkdial/gtkdial.c \
examples/helloworld/Makefile \
examples/helloworld/helloworld.c \
......@@ -20,11 +21,49 @@ EXTRA_DIST = \
examples/scribble-simple/Makefile \
examples/scribble-simple/scribble-simple.c \
examples/tictactoe/Makefile \
examples/tictactoe/tictactoe.h \
examples/tictactoe/tictactoe.c \
examples/tictactoe/ttt_test.c \
examples/buttons/Makefile \
examples/buttons/info.xpm \
examples/buttons/buttons.c
examples/buttons/buttons.c \
examples/packbox/Makefile \
examples/packbox/packbox.c \
examples/entry/Makefile \
examples/entry/entry.c \
examples/eventbox/Makefile \
examples/eventbox/eventbox.c \
examples/list/Makefile \
examples/list/list.c \
examples/menu/Makefile \
examples/menu/menufactory.h \
examples/menu/menu.c \
examples/menu/mfmain.c \
examples/menu/menufactory.c \
examples/menu/mfmain.h \
examples/notebook/Makefile \
examples/notebook/notebook.c \
examples/pixmap/Makefile \
examples/pixmap/pixmap.c \
examples/progressbar/Makefile \
examples/progressbar/progressbar.c \
examples/table/Makefile \
examples/table/table.c \
examples/radiobuttons/Makefile \
examples/radiobuttons/radiobuttons.c \
examples/rulers/Makefile \
examples/rulers/rulers.c \
examples/scrolledwin/Makefile \
examples/scrolledwin/scrolledwin.c \
examples/wheelbarrow/Makefile \
examples/wheelbarrow/wheelbarrow.c \
examples/statusbar/Makefile \
examples/statusbar/statusbar.c \
examples/selection/Makefile \
examples/selection/gettargets.c \
examples/selection/setselection.c \
examples/filesel/Makefile \
examples/filesel/filesel.c
m4datadir = $(datadir)/aclocal
......
CC = gcc
entry: entry.c
$(CC) `gtk-config --cflags` `gtk-config --libs` entry.c -o entry
clean:
rm -f *.o entry
/* This file extracted from the GTK tutorial. */
/* entry.c */
#include <gtk/gtk.h>
void enter_callback(GtkWidget *widget, GtkWidget *entry)
{
gchar *entry_text;
entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
printf("Entry contents: %s\n", entry_text);
}
void entry_toggle_editable (GtkWidget *checkbutton,
GtkWidget *entry)
{
gtk_entry_set_editable(GTK_ENTRY(entry),
GTK_TOGGLE_BUTTON(checkbutton)->active);
}
void entry_toggle_visibility (GtkWidget *checkbutton,
GtkWidget *entry)
{
gtk_entry_set_visibility(GTK_ENTRY(entry),
GTK_TOGGLE_BUTTON(checkbutton)->active);
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox, *hbox;
GtkWidget *entry;
GtkWidget *button;
GtkWidget *check;
gtk_init (&argc, &argv);
/* create a new window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize( GTK_WIDGET (window), 200, 100);
gtk_window_set_title(GTK_WINDOW (window), "GTK Entry");
gtk_signal_connect(GTK_OBJECT (window), "delete_event",
(GtkSignalFunc) gtk_exit, NULL);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);
entry = gtk_entry_new_with_max_length (50);
gtk_signal_connect(GTK_OBJECT(entry), "activate",
GTK_SIGNAL_FUNC(enter_callback),
entry);
gtk_entry_set_text (GTK_ENTRY (entry), "hello");
gtk_entry_append_text (GTK_ENTRY (entry), " world");
gtk_entry_select_region (GTK_ENTRY (entry),
0, GTK_ENTRY(entry)->text_length);
gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
gtk_widget_show (entry);
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_widget_show (hbox);
check = gtk_check_button_new_with_label("Editable");
gtk_box_pack_start (GTK_BOX (hbox), check, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT(check), "toggled",
GTK_SIGNAL_FUNC(entry_toggle_editable), entry);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(check), TRUE);
gtk_widget_show (check);
check = gtk_check_button_new_with_label("Visible");
gtk_box_pack_start (GTK_BOX (hbox), check, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT(check), "toggled",
GTK_SIGNAL_FUNC(entry_toggle_visibility), entry);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(check), TRUE);
gtk_widget_show (check);
button = gtk_button_new_with_label ("Close");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(gtk_exit),
GTK_OBJECT (window));
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
gtk_widget_show (button);
gtk_widget_show(window);
gtk_main();
return(0);
}
CC = gcc
eventbox: eventbox.c
$(CC) `gtk-config --cflags` `gtk-config --libs` eventbox.c -o eventbox
clean:
rm -f *.o eventbox
/* This file extracted from the GTK tutorial. */
/* eventbox.c */
#include <gtk/gtk.h>
int
main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *event_box;
GtkWidget *label;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Event Box");
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_exit), NULL);
gtk_container_border_width (GTK_CONTAINER (window), 10);
/* Create an EventBox and add it to our toplevel window */
event_box = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER(window), event_box);
gtk_widget_show (event_box);
/* Create a long label */
label = gtk_label_new ("Click here to quit, quit, quit, quit, quit");
gtk_container_add (GTK_CONTAINER (event_box), label);
gtk_widget_show (label);
/* Clip it short. */
gtk_widget_set_usize (label, 110, 20);
/* And bind an action to it */
gtk_widget_set_events (event_box, GDK_BUTTON_PRESS_MASK);
gtk_signal_connect (GTK_OBJECT(event_box), "button_press_event",
GTK_SIGNAL_FUNC (gtk_exit), NULL);
/* Yet one more thing you need an X window for ... */
gtk_widget_realize (event_box);
gdk_window_set_cursor (event_box->window, gdk_cursor_new (GDK_HAND1));
gtk_widget_show (window);
gtk_main ();
return 0;
}
CC = gcc
filesel: filesel.c
$(CC) `gtk-config --cflags` `gtk-config --libs` filesel.c -o filesel
clean:
rm -f *.o filesel
/* This file extracted from the GTK tutorial. */
/* filesel.c */
#include <gtk/gtk.h>
/* Get the selected filename and print it to the console */
void file_ok_sel (GtkWidget *w, GtkFileSelection *fs)
{
g_print ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
}
void destroy (GtkWidget *widget, gpointer *data)
{
gtk_main_quit ();
}
int main (int argc, char *argv[])
{
GtkWidget *filew;
gtk_init (&argc, &argv);
/* Create a new file selection widget */
filew = gtk_file_selection_new ("File selection");
gtk_signal_connect (GTK_OBJECT (filew), "destroy",
(GtkSignalFunc) destroy, &filew);
/* Connect the ok_button to file_ok_sel function */
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
"clicked", (GtkSignalFunc) file_ok_sel, filew );
/* Connect the cancel_button to destroy the widget */
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button),
"clicked", (GtkSignalFunc) gtk_widget_destroy,
GTK_OBJECT (filew));
/* Lets set the filename, as if this were a save dialog, and we are giving
a default filename */
gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew),
"penguin.png");
gtk_widget_show(filew);
gtk_main ();
return 0;
}
CC = gcc
list: list.c
$(CC) `gtk-config --cflags` `gtk-config --libs` list.c -o list
clean:
rm -f *.o list
/* This file extracted from the GTK tutorial. */
/* list.c */
/* 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
* data in list items
*/
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);
/* 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];
/* initialize gtk+ (and subsequently gdk) */
gtk_init(&argc, &argv);
/* 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
*/
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "GtkList Example");
gtk_signal_connect(GTK_OBJECT(window),
"destroy",
GTK_SIGNAL_FUNC(gtk_main_quit),
NULL);
/* 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 scolled 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
* 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_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 ;)
*/
frame=gtk_frame_new("Prison");
gtk_widget_set_usize(frame, 200, 50);
gtk_container_border_width(GTK_CONTAINER(frame), 5);
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
gtk_container_add(GTK_CONTAINER(vbox), frame);
gtk_widget_show(frame);
/* connect the sigh_button_event() signal handler to the GtkList
* wich will handle the "arresting" of list items
*/
gtk_signal_connect(GTK_OBJECT(gtklist),
"button_release_event",
GTK_SIGNAL_FUNC(sigh_button_event),
frame);
/* create a separator
*/
separator=gtk_hseparator_new();
gtk_container_add(GTK_CONTAINER(vbox), separator);
gtk_widget_show(separator);
/* finaly create a button and connect its "clicked" signal
* to the destroyment of the window
*/
button=gtk_button_new_with_label("Close");
gtk_container_add(GTK_CONTAINER(vbox), button);
gtk_widget_show(button);
gtk_signal_connect_object(GTK_OBJECT(button),
"clicked",
GTK_SIGNAL_FUNC(gtk_widget_destroy),
GTK_OBJECT(window));
/* now we create 5 list items, each having its own
* label and add them to the GtkList using gtk_container_add()
* 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++) {
GtkWidget *label;
gchar *string;
sprintf(buffer, "ListItemContainer with Label #%d", i);
label=gtk_label_new(buffer);
list_item=gtk_list_item_new();
gtk_container_add(GTK_CONTAINER(list_item), label);
gtk_widget_show(label);
gtk_container_add(GTK_CONTAINER(gtklist), list_item);
gtk_widget_show(list_item);
gtk_label_get(GTK_LABEL(label), &string);
gtk_object_set_data(GTK_OBJECT(list_item),
list_item_data_key,
string);
}
/* here, we are creating another 5 labels, this time
* we use gtk_list_item_new_with_label() for the creation
* we cant query the text string from the label because
* we dont 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
* 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
* doubly linked list, their order will be descending (instead
* of ascending when using g_list_append())
*/
dlist=NULL;
for (; i<10; i++) {
sprintf(buffer, "List Item with Label %d", i);
list_item=gtk_list_item_new_with_label(buffer);
dlist=g_list_prepend(dlist, list_item);
gtk_widget_show(list_item);
gtk_object_set_data(GTK_OBJECT(list_item),
list_item_data_key,
"ListItem with integrated Label");
}
gtk_list_append_items(GTK_LIST(gtklist), dlist);
/* finaly we want to see the window, dont we? ;)
*/
gtk_widget_show(window);
/* fire up the main event loop of gtk
*/
gtk_main();
/* we get here after gtk_main_quit() has been called which
* happens if the main window gets destroyed
*/
return 0;
}
/* 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)
{
/* we only do something if the third (rightmost mouse button
* was released
*/
if (event->type==GDK_BUTTON_RELEASE &&
event->button==3) {
GList *dlist, *free_list;
GtkWidget *new_prisoner;
/* fetch the currently selected list item which
* will be our next prisoner ;)
*/
dlist=GTK_LIST(gtklist)->selection;
if (dlist)
new_prisoner=GTK_WIDGET(dlist->data);
else
new_prisoner=NULL;
/* look for already prisoned 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));
free_list=dlist;
while (dlist) {
GtkWidget *list_item;
list_item=dlist->data;
gtk_widget_reparent(list_item, gtklist);
dlist=dlist->next;
}
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 (new_prisoner) {
GList static_dlist;
static_dlist.data=new_prisoner;
static_dlist.next=NULL;
static_dlist.prev=NULL;
gtk_list_unselect_child(GTK_LIST(gtklist),
new_prisoner);
gtk_widget_reparent(new_prisoner, frame);
}
}
}
/* this is the signal handler that gets called if GtkList
* emits the "selection_changed" signal
*/
void
sigh_print_selection (GtkWidget *gtklist,
gpointer func_data)
{
GList *dlist;
/* 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
* 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
*/
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
*/
while (dlist) {
GtkObject *list_item;
gchar *item_data_string;
list_item=GTK_OBJECT(dlist->data);
item_data_string=gtk_object_get_data(list_item,
list_item_data_key);
g_print("%s ", item_data_string);
dlist=dlist->next;
}
g_print("\n");
}
CC = gcc
all: menu menufactory
menu: menu.c
$(CC) `gtk-config --cflags` `gtk-config --libs` menu.c -o menu
menufactory: menufactory.o mfmain.o
$(CC) `gtk-config --libs` menufactory.o mfmain.o -o menufactory
menufactory.o:
$(CC) `gtk-config --cflags` -c menufactory.c -o menufactory.o
mfmain.o:
$(CC) `gtk-config --cflags` -c mfmain.c -o mfmain.o
clean:
rm -f *.o menu menufactory
/* This file extracted from the GTK tutorial. */
/* menu.c */
#include <gtk/gtk.h>
static gint button_press (GtkWidget *, GdkEvent *);
static void menuitem_response (gchar *);
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *menu;
GtkWidget *menu_bar;
GtkWidget *root_menu;
GtkWidget *menu_items;
GtkWidget *vbox;
GtkWidget *button;
char buf[128];
int i;
gtk_init (&argc, &argv);
/* create a new window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize( GTK_WIDGET (window), 200, 100);