1998-03-31 23:43:49 +00:00
|
|
|
|
2004-03-06 03:38:59 +00:00
|
|
|
#include <config.h>
|
2002-02-16 23:52:30 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1998-03-31 23:43:49 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
void enter_callback( GtkWidget *widget,
|
|
|
|
GtkWidget *entry )
|
1998-03-31 23:43:49 +00:00
|
|
|
{
|
2002-02-16 23:52:30 +00:00
|
|
|
const gchar *entry_text;
|
2002-02-19 01:25:26 +00:00
|
|
|
entry_text = gtk_entry_get_text (GTK_ENTRY (entry));
|
1998-03-31 23:43:49 +00:00
|
|
|
printf("Entry contents: %s\n", entry_text);
|
|
|
|
}
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
void entry_toggle_editable( GtkWidget *checkbutton,
|
|
|
|
GtkWidget *entry )
|
1998-03-31 23:43:49 +00:00
|
|
|
{
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_editable_set_editable (GTK_EDITABLE (entry),
|
|
|
|
GTK_TOGGLE_BUTTON (checkbutton)->active);
|
1998-03-31 23:43:49 +00:00
|
|
|
}
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
void entry_toggle_visibility( GtkWidget *checkbutton,
|
|
|
|
GtkWidget *entry )
|
1998-03-31 23:43:49 +00:00
|
|
|
{
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_entry_set_visibility (GTK_ENTRY (entry),
|
|
|
|
GTK_TOGGLE_BUTTON (checkbutton)->active);
|
1998-03-31 23:43:49 +00:00
|
|
|
}
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
int main( int argc,
|
|
|
|
char *argv[] )
|
1998-03-31 23:43:49 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *vbox, *hbox;
|
|
|
|
GtkWidget *entry;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *check;
|
2002-02-16 23:52:30 +00:00
|
|
|
gint tmp_pos;
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
|
|
|
/* create a new window */
|
2002-02-19 01:25:26 +00:00
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (window), 200, 100);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "GTK Entry");
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect (G_OBJECT (window), "destroy",
|
|
|
|
G_CALLBACK (gtk_main_quit), NULL);
|
|
|
|
g_signal_connect_swapped (G_OBJECT (window), "delete_event",
|
|
|
|
G_CALLBACK (gtk_widget_destroy),
|
2002-08-24 11:53:26 +00:00
|
|
|
G_OBJECT (window));
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
entry = gtk_entry_new ();
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (entry), 50);
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect (G_OBJECT (entry), "activate",
|
|
|
|
G_CALLBACK (enter_callback),
|
2002-08-24 11:53:26 +00:00
|
|
|
(gpointer) entry);
|
1998-03-31 23:43:49 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), "hello");
|
2002-02-16 23:52:30 +00:00
|
|
|
tmp_pos = GTK_ENTRY (entry)->text_length;
|
|
|
|
gtk_editable_insert_text (GTK_EDITABLE (entry), " world", -1, &tmp_pos);
|
|
|
|
gtk_editable_select_region (GTK_EDITABLE (entry),
|
2002-02-19 01:25:26 +00:00
|
|
|
0, GTK_ENTRY (entry)->text_length);
|
1998-03-31 23:43:49 +00:00
|
|
|
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);
|
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
check = gtk_check_button_new_with_label ("Editable");
|
1998-03-31 23:43:49 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), check, TRUE, TRUE, 0);
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect (G_OBJECT (check), "toggled",
|
2002-08-24 11:53:26 +00:00
|
|
|
G_CALLBACK (entry_toggle_editable), (gpointer) entry);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE);
|
1998-03-31 23:43:49 +00:00
|
|
|
gtk_widget_show (check);
|
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
check = gtk_check_button_new_with_label ("Visible");
|
1998-03-31 23:43:49 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), check, TRUE, TRUE, 0);
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect (G_OBJECT (check), "toggled",
|
2002-08-24 11:53:26 +00:00
|
|
|
G_CALLBACK (entry_toggle_visibility), (gpointer) entry);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE);
|
1998-03-31 23:43:49 +00:00
|
|
|
gtk_widget_show (check);
|
|
|
|
|
2002-02-19 19:47:16 +00:00
|
|
|
button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
|
|
|
|
g_signal_connect_swapped (G_OBJECT (button), "clicked",
|
|
|
|
G_CALLBACK (gtk_widget_destroy),
|
2002-08-24 11:53:26 +00:00
|
|
|
G_OBJECT (window));
|
1998-03-31 23:43:49 +00:00
|
|
|
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);
|
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_widget_show (window);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
gtk_main();
|
2002-02-19 01:25:26 +00:00
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
return 0;
|
1998-03-31 23:43:49 +00:00
|
|
|
}
|