2009-07-09 01:41:53 +00:00
|
|
|
/* Entry/Entry Buffer
|
|
|
|
*
|
|
|
|
* GtkEntryBuffer provides the text content in a GtkEntry.
|
2015-06-20 01:59:15 +00:00
|
|
|
* Applications can provide their own buffer implementation,
|
|
|
|
* e.g. to provide secure handling for passwords in memory.
|
2009-07-09 01:41:53 +00:00
|
|
|
*/
|
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
#include <glib/gi18n.h>
|
2009-07-09 01:41:53 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
do_entry_buffer (GtkWidget *do_widget)
|
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
static GtkWidget *window = NULL;
|
2009-07-09 01:41:53 +00:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *entry;
|
|
|
|
GtkEntryBuffer *buffer;
|
|
|
|
|
|
|
|
if (!window)
|
2015-06-28 13:23:28 +00:00
|
|
|
{
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Entry Buffer");
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
|
|
|
g_signal_connect (window, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &window);
|
|
|
|
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
|
2016-10-26 19:11:18 +00:00
|
|
|
g_object_set (vbox, "margin", 5, NULL);
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL (label),
|
|
|
|
"Entries share a buffer. Typing in one is reflected in the other.");
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), label);
|
2015-06-28 13:23:28 +00:00
|
|
|
|
|
|
|
/* Create a buffer */
|
|
|
|
buffer = gtk_entry_buffer_new (NULL, 0);
|
|
|
|
|
|
|
|
/* Create our first entry */
|
|
|
|
entry = gtk_entry_new_with_buffer (buffer);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), entry);
|
2015-06-28 13:23:28 +00:00
|
|
|
|
|
|
|
/* Create the second entry */
|
|
|
|
entry = gtk_entry_new_with_buffer (buffer);
|
|
|
|
gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), entry);
|
2015-06-28 13:23:28 +00:00
|
|
|
|
|
|
|
g_object_unref (buffer);
|
|
|
|
}
|
2009-07-09 01:41:53 +00:00
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (window))
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2009-07-09 01:41:53 +00:00
|
|
|
else
|
|
|
|
gtk_widget_destroy (window);
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|