Commit eab02f69 authored by Stef Walter's avatar Stef Walter

GtkEntryBuffer holds text for GtkEntry

Adds a 'model' type buffer for GtkEntry in which the actual
textual data is stored. GtkEntryBuffer can be subclassed.

Among other things, this allows GtkEntry to be used for secrets
that need to be stored in non-pageable memory. It also allows
buffers to be shared by entries.

See bug #576801.
parent 9ef87ea1
......@@ -17,6 +17,7 @@ demos = \
dialog.c \
drawingarea.c \
editable_cells.c \
entry_buffer.c \
entry_completion.c \
expander.c \
hypertext.c \
......
/* Entry/Entry Buffer
*
* GtkEntryBuffer provides the text content in a GtkEntry.
*
*/
#include <gtk/gtk.h>
static GtkWidget *window = NULL;
GtkWidget *
do_entry_buffer (GtkWidget *do_widget)
{
GtkWidget *vbox;
GtkWidget *label;
GtkWidget *entry;
GtkEntryBuffer *buffer;
if (!window)
{
window = gtk_dialog_new_with_buttons ("GtkEntryBuffer",
GTK_WINDOW (do_widget),
0,
GTK_STOCK_CLOSE,
GTK_RESPONSE_NONE,
NULL);
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
g_signal_connect (window, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
vbox = gtk_vbox_new (FALSE, 5);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, TRUE, TRUE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), "Entries share a buffer. Typing in one is reflected in the other.");
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
/* Create a buffer */
buffer = gtk_entry_buffer_new (NULL, 0);
/* Create our first entry */
entry = gtk_entry_new_with_buffer (buffer);
gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
/* Create the second entry */
entry = gtk_entry_new_with_buffer (buffer);
gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
g_object_unref (buffer);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show_all (window);
else
gtk_widget_destroy (window);
return window;
}
......@@ -177,6 +177,7 @@ that is, GUI components such as #GtkButton or #GtkTextView.
<chapter id="NumericEntry">
<title>Numeric/Text Data Entry</title>
<xi:include href="xml/gtkentry.xml" />
<xi:include href="xml/gtkentrybuffer.xml" />
<xi:include href="xml/gtkentrycompletion.xml" />
<xi:include href="xml/gtkhscale.xml" />
<xi:include href="xml/gtkvscale.xml" />
......
......@@ -1268,7 +1268,10 @@ gtk_old_editable_get_type
<TITLE>GtkEntry</TITLE>
GtkEntry
gtk_entry_new
gtk_entry_new_with_buffer
gtk_entry_new_with_max_length
gtk_entry_get_buffer
gtk_entry_set_buffer
gtk_entry_set_text
gtk_entry_append_text
gtk_entry_prepend_text
......@@ -1342,6 +1345,34 @@ GTK_ENTRY_GET_CLASS
gtk_entry_get_type
</SECTION>
<SECTION>
<FILE>gtkentrybuffer</FILE>
<TITLE>GtkEntryBuffer</TITLE>
GtkEntryBuffer
gtk_entry_buffer_new
gtk_entry_buffer_get_text
gtk_entry_buffer_set_text
gtk_entry_buffer_get_bytes
gtk_entry_buffer_get_length
gtk_entry_buffer_get_max_length
gtk_entry_buffer_set_max_length
gtk_entry_buffer_insert_text
gtk_entry_buffer_delete_text
gtk_entry_buffer_emit_deleted_text
gtk_entry_buffer_emit_inserted_text
<SUBSECTION Standard>
GTK_ENTRY_BUFFER
GTK_IS_ENTRY_BUFFER
GTK_TYPE_ENTRY_BUFFER
GTK_ENTRY_BUFFER_CLASS
GTK_IS_ENTRY_BUFFER_CLASS
GTK_ENTRY_BUFFER_GET_CLASS
GTK_ENTRY_BUFFER_MAX_SIZE
<SUBSECTION Private>
gtk_entry_buffer_get_type
</SECTION>
<SECTION>
<FILE>gtkentrycompletion</FILE>
<TITLE>GtkEntryCompletion</TITLE>
......
......@@ -48,6 +48,7 @@ gtk_curve_get_type
gtk_dialog_get_type
gtk_drawing_area_get_type
gtk_editable_get_type
gtk_entry_buffer_get_type
gtk_entry_completion_get_type
gtk_entry_get_type
gtk_event_box_get_type
......
......@@ -1033,6 +1033,25 @@ You may not attach these to signals created with the
</para>
<!-- ##### STRUCT GtkEntryBufferClass ##### -->
<para>
</para>
@parent_class:
@inserted_text:
@deleted_text:
@get_text:
@get_length:
@insert_text:
@delete_text:
@_gtk_reserved0:
@_gtk_reserved1:
@_gtk_reserved2:
@_gtk_reserved3:
@_gtk_reserved4:
@_gtk_reserved5:
<!-- ##### ARG GtkFileChooser:file-system ##### -->
<para>
......
......@@ -173,6 +173,11 @@ The #GtkEntry-struct struct contains only private data.
</para>
<!-- ##### ARG GtkEntry:buffer ##### -->
<para>
</para>
<!-- ##### ARG GtkEntry:caps-lock-warning ##### -->
<para>
......@@ -401,6 +406,15 @@ The #GtkEntry-struct struct contains only private data.
@Returns:
<!-- ##### FUNCTION gtk_entry_new_with_buffer ##### -->
<para>
</para>
@buffer:
@Returns:
<!-- ##### FUNCTION gtk_entry_new_with_max_length ##### -->
<para>
</para>
......@@ -409,6 +423,24 @@ The #GtkEntry-struct struct contains only private data.
@Returns:
<!-- ##### FUNCTION gtk_entry_get_buffer ##### -->
<para>
</para>
@entry:
@Returns:
<!-- ##### FUNCTION gtk_entry_set_buffer ##### -->
<para>
</para>
@entry:
@buffer:
<!-- ##### FUNCTION gtk_entry_set_text ##### -->
<para>
......
<!-- ##### SECTION Title ##### -->
GtkEntryBuffer
<!-- ##### SECTION Short_Description ##### -->
<!-- ##### SECTION Long_Description ##### -->
<para>
</para>
<!-- ##### SECTION See_Also ##### -->
<para>
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### STRUCT GtkEntryBuffer ##### -->
<para>
</para>
<!-- ##### SIGNAL GtkEntryBuffer::deleted-text ##### -->
<para>
</para>
@entrybuffer: the object which received the signal.
@arg1:
@arg2:
<!-- ##### SIGNAL GtkEntryBuffer::inserted-text ##### -->
<para>
</para>
@entrybuffer: the object which received the signal.
@arg1:
@arg2:
@arg3:
<!-- ##### ARG GtkEntryBuffer:length ##### -->
<para>
</para>
<!-- ##### ARG GtkEntryBuffer:max-length ##### -->
<para>
</para>
<!-- ##### ARG GtkEntryBuffer:text ##### -->
<para>
</para>
<!-- ##### FUNCTION gtk_entry_buffer_new ##### -->
<para>
</para>
@initial_chars:
@n_initial_chars:
@Returns:
<!-- ##### FUNCTION gtk_entry_buffer_get_text ##### -->
<para>
</para>
@buffer:
@Returns:
<!-- ##### FUNCTION gtk_entry_buffer_set_text ##### -->
<para>
</para>
@buffer:
@chars:
@n_chars:
<!-- ##### FUNCTION gtk_entry_buffer_get_bytes ##### -->
<para>
</para>
@buffer:
@Returns:
<!-- ##### FUNCTION gtk_entry_buffer_get_length ##### -->
<para>
</para>
@buffer:
@Returns:
<!-- ##### FUNCTION gtk_entry_buffer_get_max_length ##### -->
<para>
</para>
@buffer:
@Returns:
<!-- ##### FUNCTION gtk_entry_buffer_set_max_length ##### -->
<para>
</para>
@buffer:
@max_length:
<!-- ##### FUNCTION gtk_entry_buffer_insert_text ##### -->
<para>
</para>
@buffer:
@position:
@chars:
@n_chars:
@Returns:
<!-- ##### FUNCTION gtk_entry_buffer_delete_text ##### -->
<para>
</para>
@buffer:
@position:
@n_chars:
@Returns:
<!-- ##### FUNCTION gtk_entry_buffer_emit_deleted_text ##### -->
<para>
</para>
@buffer:
@position:
@n_chars:
<!-- ##### FUNCTION gtk_entry_buffer_emit_inserted_text ##### -->
<para>
</para>
@buffer:
@position:
@chars:
@n_chars:
......@@ -197,6 +197,7 @@ gtk_public_h_sources = \
gtkdrawingarea.h \
gtkeditable.h \
gtkentry.h \
gtkentrybuffer.h \
gtkentrycompletion.h \
gtkenums.h \
gtkeventbox.h \
......@@ -447,6 +448,7 @@ gtk_base_c_sources = \
gtkdrawingarea.c \
gtkeditable.c \
gtkentry.c \
gtkentrybuffer.c \
gtkentrycompletion.c \
gtkeventbox.c \
gtkexpander.c \
......
......@@ -78,6 +78,7 @@
#include <gtk/gtkdrawingarea.h>
#include <gtk/gtkeditable.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkentrybuffer.h>
#include <gtk/gtkentrycompletion.h>
#include <gtk/gtkenums.h>
#include <gtk/gtkeventbox.h>
......
This diff is collapsed.
......@@ -39,6 +39,7 @@
#include <gtk/gtkeditable.h>
#include <gtk/gtkimcontext.h>
#include <gtk/gtkmenu.h>
#include <gtk/gtkentrybuffer.h>
#include <gtk/gtkentrycompletion.h>
#include <gtk/gtkimage.h>
#include <gtk/gtkselection.h>
......@@ -66,7 +67,7 @@ struct _GtkEntry
{
GtkWidget widget;
gchar *GSEAL (text);
gchar *GSEAL (text); /* COMPAT: Deprecated, not used. Remove in GTK+ 3.x */
guint GSEAL (editable) : 1;
guint GSEAL (visible) : 1;
......@@ -74,8 +75,8 @@ struct _GtkEntry
guint GSEAL (in_drag) : 1; /* FIXME: Should be private?
Dragging within the selection */
guint16 GSEAL (text_length); /* length in use, in chars */
guint16 GSEAL (text_max_length);
guint16 GSEAL (text_length); /* COMPAT: Deprecated, not used. Remove in GTK+ 3.x */
guint16 GSEAL (text_max_length); /* COMPAT: Deprecated, not used. Remove in GTK+ 3.x */
/*< private >*/
GdkWindow *GSEAL (text_area);
......@@ -108,8 +109,8 @@ struct _GtkEntry
gint GSEAL (ascent); /* font ascent in pango units */
gint GSEAL (descent); /* font descent in pango units */
guint16 GSEAL (text_size); /* allocated size, in bytes */
guint16 GSEAL (n_bytes); /* length in use, in bytes */
guint16 GSEAL (x_text_size); /* allocated size, in bytes */
guint16 GSEAL (x_n_bytes); /* length in use, in bytes */
guint16 GSEAL (preedit_length); /* length of preedit string, in bytes */
guint16 GSEAL (preedit_cursor); /* offset of cursor within preedit string, in chars */
......@@ -164,6 +165,10 @@ struct _GtkEntryClass
GType gtk_entry_get_type (void) G_GNUC_CONST;
GtkWidget* gtk_entry_new (void);
GtkWidget* gtk_entry_new_with_buffer (GtkEntryBuffer *buffer);
GtkEntryBuffer* gtk_entry_get_buffer (GtkEntry *entry);
void gtk_entry_set_buffer (GtkEntry *entry,
GtkEntryBuffer *buffer);
void gtk_entry_set_visibility (GtkEntry *entry,
gboolean visible);
gboolean gtk_entry_get_visibility (GtkEntry *entry);
......
This diff is collapsed.
/* gtkentrybuffer.h
* Copyright (C) 2009 Stefan Walter <stef@memberwebs.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#if defined(GTK_DISABLE_SINGLE_INCLUDES) && !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#ifndef __GTK_ENTRY_BUFFER_H__
#define __GTK_ENTRY_BUFFER_H__
#include <glib-object.h>
G_BEGIN_DECLS
/* Maximum size of text buffer, in bytes */
#define GTK_ENTRY_BUFFER_MAX_SIZE G_MAXUSHORT
#define GTK_TYPE_ENTRY_BUFFER (gtk_entry_buffer_get_type ())
#define GTK_ENTRY_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ENTRY_BUFFER, GtkEntryBuffer))
#define GTK_ENTRY_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_ENTRY_BUFFER, GtkEntryBufferClass))
#define GTK_IS_ENTRY_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ENTRY_BUFFER))
#define GTK_IS_ENTRY_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ENTRY_BUFFER))
#define GTK_ENTRY_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ENTRY_BUFFER, GtkEntryBufferClass))
typedef struct _GtkEntryBuffer GtkEntryBuffer;
typedef struct _GtkEntryBufferClass GtkEntryBufferClass;
typedef struct _GtkEntryBufferPrivate GtkEntryBufferPrivate;
struct _GtkEntryBuffer
{
GObject parent_instance;
/*< private >*/
GtkEntryBufferPrivate *priv;
};
struct _GtkEntryBufferClass
{
GObjectClass parent_class;
/* Signals */
void (*inserted_text) (GtkEntryBuffer *buffer,
guint position,
const gchar *chars,
guint n_chars);
void (*deleted_text) (GtkEntryBuffer *buffer,
guint position,
guint n_chars);
/* Virtual Methods */
const gchar* (*get_text) (GtkEntryBuffer *buffer,
gsize *n_bytes);
guint (*get_length) (GtkEntryBuffer *buffer);
guint (*insert_text) (GtkEntryBuffer *buffer,
guint position,
const gchar *chars,
guint n_chars);
guint (*delete_text) (GtkEntryBuffer *buffer,
guint position,
guint n_chars);
/* Padding for future expansion */
void (*_gtk_reserved0) (void);
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
void (*_gtk_reserved5) (void);
};
GType gtk_entry_buffer_get_type (void) G_GNUC_CONST;
GtkEntryBuffer* gtk_entry_buffer_new (const gchar *initial_chars,
gint n_initial_chars);
gsize gtk_entry_buffer_get_bytes (GtkEntryBuffer *buffer);
guint gtk_entry_buffer_get_length (GtkEntryBuffer *buffer);
const gchar* gtk_entry_buffer_get_text (GtkEntryBuffer *buffer);
void gtk_entry_buffer_set_text (GtkEntryBuffer *buffer,
const gchar *chars,
gint n_chars);
void gtk_entry_buffer_set_max_length (GtkEntryBuffer *buffer,
guint max_length);
guint gtk_entry_buffer_get_max_length (GtkEntryBuffer *buffer);
guint gtk_entry_buffer_insert_text (GtkEntryBuffer *buffer,
guint position,
const gchar *chars,
gint n_chars);
guint gtk_entry_buffer_delete_text (GtkEntryBuffer *buffer,
guint position,
gint n_chars);
void gtk_entry_buffer_emit_inserted_text (GtkEntryBuffer *buffer,
guint position,
const gchar *chars,
guint n_chars);
void gtk_entry_buffer_emit_deleted_text (GtkEntryBuffer *buffer,
guint position,
guint n_chars);
G_END_DECLS
#endif /* __GTK_ENTRY_BUFFER_H__ */
......@@ -107,5 +107,7 @@ VOID:UINT,UINT
VOID:UINT,STRING
VOID:UINT,BOXED,UINT,FLAGS,FLAGS
VOID:UINT,OBJECT,UINT,FLAGS,FLAGS
VOID:UINT,STRING,UINT
VOID:UINT,UINT
VOID:VOID
OBJECT:OBJECT,INT,INT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment