diff --git a/ChangeLog b/ChangeLog index 440eef47a3..53f34a5bb9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-07-29 Anders Carlsson + + * demos/gtk-demo/Makefile.am: + * demos/gtk-demo/clipboard.c: (copy_button_clicked), + (paste_received), (paste_button_clicked), (do_clipboard): + Add clipboard demo. + 2004-07-28 Federico Mena Quintero * gtk/gtkfilechooserdefault.c (struct _GtkFileChooserDefault): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 440eef47a3..53f34a5bb9 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +2004-07-29 Anders Carlsson + + * demos/gtk-demo/Makefile.am: + * demos/gtk-demo/clipboard.c: (copy_button_clicked), + (paste_received), (paste_button_clicked), (do_clipboard): + Add clipboard demo. + 2004-07-28 Federico Mena Quintero * gtk/gtkfilechooserdefault.c (struct _GtkFileChooserDefault): diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 440eef47a3..53f34a5bb9 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +2004-07-29 Anders Carlsson + + * demos/gtk-demo/Makefile.am: + * demos/gtk-demo/clipboard.c: (copy_button_clicked), + (paste_received), (paste_button_clicked), (do_clipboard): + Add clipboard demo. + 2004-07-28 Federico Mena Quintero * gtk/gtkfilechooserdefault.c (struct _GtkFileChooserDefault): diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 440eef47a3..53f34a5bb9 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +2004-07-29 Anders Carlsson + + * demos/gtk-demo/Makefile.am: + * demos/gtk-demo/clipboard.c: (copy_button_clicked), + (paste_received), (paste_button_clicked), (do_clipboard): + Add clipboard demo. + 2004-07-28 Federico Mena Quintero * gtk/gtkfilechooserdefault.c (struct _GtkFileChooserDefault): diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am index 7557fb91bb..65a52ca9b8 100644 --- a/demos/gtk-demo/Makefile.am +++ b/demos/gtk-demo/Makefile.am @@ -8,6 +8,7 @@ demos = \ appwindow.c \ button_box.c \ changedisplay.c \ + clipboard.c \ colorsel.c \ dialog.c \ drawingarea.c \ diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c new file mode 100644 index 0000000000..c4f04c7540 --- /dev/null +++ b/demos/gtk-demo/clipboard.c @@ -0,0 +1,124 @@ +/* Clipboard + * + * GtkClipboard is used for clipboard handling. This demo shows how to + * copy and paste text to and from the clipboard. + */ + +#include +#include +#include + +static GtkWidget *window = NULL; + +void +copy_button_clicked (GtkWidget *button, + gpointer user_data) +{ + GtkWidget *entry; + GtkClipboard *clipboard; + + entry = GTK_WIDGET (user_data); + + /* Get the clipboard object */ + clipboard = gtk_widget_get_clipboard (entry, + GDK_SELECTION_CLIPBOARD); + + /* Set clipboard text */ + gtk_clipboard_set_text (clipboard, gtk_entry_get_text (GTK_ENTRY (entry)), -1); +} + +void +paste_received (GtkClipboard *clipboard, + const gchar *text, + gpointer user_data) +{ + GtkWidget *entry; + + entry = GTK_WIDGET (user_data); + + /* Set the entry text */ + gtk_entry_set_text (GTK_ENTRY (entry), text); +} + +void +paste_button_clicked (GtkWidget *button, + gpointer user_data) +{ + GtkWidget *entry; + GtkClipboard *clipboard; + + entry = GTK_WIDGET (user_data); + + /* Get the clipboard object */ + clipboard = gtk_widget_get_clipboard (entry, + GDK_SELECTION_CLIPBOARD); + + /* Request the contents of the clipboard, contents_received will be + called when we do get the contents. + */ + gtk_clipboard_request_text (clipboard, + paste_received, entry); +} + +GtkWidget * +do_clipboard (GtkWidget *do_widget) +{ + if (!window) + { + GtkWidget *vbox, *hbox; + GtkWidget *label; + GtkWidget *entry, *button; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 8); + + gtk_container_add (GTK_CONTAINER (window), vbox); + + label = gtk_label_new ("\"Copy\" will copy the text\nin the entry to the clipboard"); + + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); + + hbox = gtk_hbox_new (FALSE, 4); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 8); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + + /* Create the first entry */ + entry = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); + + /* Create the button */ + button = gtk_button_new_from_stock (GTK_STOCK_COPY); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); + g_signal_connect (button, "clicked", + G_CALLBACK (copy_button_clicked), entry); + + label = gtk_label_new ("\"Paste\" will paste the text from the clipboard to the entry"); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); + + hbox = gtk_hbox_new (FALSE, 4); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 8); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + + /* Create the second entry */ + entry = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); + + /* Create the button */ + button = gtk_button_new_from_stock (GTK_STOCK_PASTE); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); + g_signal_connect (button, "clicked", + G_CALLBACK (paste_button_clicked), entry); + + } + + if (!GTK_WIDGET_VISIBLE (window)) + gtk_widget_show_all (window); + else + { + gtk_widget_destroy (window); + window = NULL; + } + + return window; +}