diff options
author | Shawn Amundson <amundson@src.gnome.org> | 1998-03-31 23:43:49 +0000 |
---|---|---|
committer | Shawn Amundson <amundson@src.gnome.org> | 1998-03-31 23:43:49 +0000 |
commit | c36ca76bb84879ed1e2ba51541c95eacd56e550e (patch) | |
tree | 8a01644357246180f22165e28d7f0cdf8cf67afe /examples/entry/entry.c | |
parent | 30f22e0208593dba5ca5d3b824d8d03519414296 (diff) | |
download | gdk-pixbuf-c36ca76bb84879ed1e2ba51541c95eacd56e550e.tar.gz |
Tue Mar 31 15:41:57 PST 1998 Shawn T. Amundson
* Makefile.am:
* examples/*: added the rest of the tutorial examples
Diffstat (limited to 'examples/entry/entry.c')
-rw-r--r-- | examples/entry/entry.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/examples/entry/entry.c b/examples/entry/entry.c new file mode 100644 index 000000000..d34153889 --- /dev/null +++ b/examples/entry/entry.c @@ -0,0 +1,92 @@ +/* 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); +} |