Seal GtkEntry

svn path=/trunk/; revision=20534
This commit is contained in:
Tim Janik 2008-06-20 11:01:56 +00:00
parent 66e81271ac
commit 49b07b9460
2 changed files with 145 additions and 42 deletions

View File

@ -133,7 +133,9 @@ enum {
PROP_TEXT,
PROP_XALIGN,
PROP_TRUNCATE_MULTILINE,
PROP_SHADOW_TYPE
PROP_SHADOW_TYPE,
PROP_OVERWRITE_MODE,
PROP_TEXT_LENGTH
};
static guint signals[LAST_SIGNAL] = { 0 };
@ -632,6 +634,37 @@ gtk_entry_class_init (GtkEntryClass *class)
GTK_SHADOW_IN,
GTK_PARAM_READWRITE));
/**
* GtkEntry:overwrite-mode:
*
* If text is overwritten when typing in the #GtkEntry.
*
* Since: 2.14
*/
g_object_class_install_property (gobject_class,
PROP_OVERWRITE_MODE,
g_param_spec_boolean ("overwrite-mode",
P_("Overwrite mode"),
P_("Whether new text overwrites existing text"),
FALSE,
GTK_PARAM_READWRITE));
/**
* GtkEntry:text-length:
*
* The length of the text in the #GtkEntry.
*
* Since: 2.14
*/
g_object_class_install_property (gobject_class,
PROP_TEXT_LENGTH,
g_param_spec_uint ("text-length",
P_("Text length"),
P_("Length of the text currently in the entry"),
0,
G_MAXUINT16,
0,
GTK_PARAM_READABLE));
signals[POPULATE_POPUP] =
g_signal_new (I_("populate_popup"),
G_OBJECT_CLASS_TYPE (gobject_class),
@ -1026,6 +1059,10 @@ gtk_entry_set_property (GObject *object,
priv->shadow_type = g_value_get_enum (value);
break;
case PROP_OVERWRITE_MODE:
gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
break;
case PROP_SCROLL_OFFSET:
case PROP_CURSOR_POSITION:
default:
@ -1090,6 +1127,12 @@ gtk_entry_get_property (GObject *object,
case PROP_SHADOW_TYPE:
g_value_set_enum (value, priv->shadow_type);
break;
case PROP_OVERWRITE_MODE:
g_value_set_boolean (value, entry->overwrite_mode);
break;
case PROP_TEXT_LENGTH:
g_value_set_boolean (value, entry->text_length);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -4629,6 +4672,43 @@ gtk_entry_set_editable (GtkEntry *entry,
gtk_editable_set_editable (GTK_EDITABLE (entry), editable);
}
/**
* gtk_entry_set_overwrite_mode:
* @entry: a #GtkEntry
* @setting: new value
*
* Sets whether the text is overwritten when typing in the #GtkEntry.
**/
void
gtk_entry_set_overwrite_mode (GtkEntry *entry,
gboolean setting)
{
g_return_if_fail (GTK_IS_ENTRY (entry));
if (entry->overwrite_mode == setting)
return;
gtk_entry_toggle_overwrite (entry);
g_object_notify (G_OBJECT (entry), "overwrite-mode");
}
/**
* gtk_entry_get_overwrite_mode:
* @entry: a #GtkEntry
*
* Gets the value set by gtk_entry_set_overwrite_mode().
*
* Return value: whether the text is overwritten when typing.
**/
gboolean
gtk_entry_get_overwrite_mode (GtkEntry *entry)
{
g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
return entry->overwrite_mode;
}
/**
* gtk_entry_get_text:
* @entry: a #GtkEntry
@ -4715,6 +4795,24 @@ gtk_entry_get_max_length (GtkEntry *entry)
return entry->text_max_length;
}
/**
* gtk_entry_get_text_length:
* @entry: a #GtkEntry
*
* Retrieves the current length of the text in
* @entry.
*
* Return value: the current number of characters
* in #GtkEntry, or 0 if there are none.
**/
guint16
gtk_entry_get_text_length (GtkEntry *entry)
{
g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
return entry->text_length;
}
/**
* gtk_entry_set_activates_default:
* @entry: a #GtkEntry

View File

@ -56,61 +56,62 @@ struct _GtkEntry
{
GtkWidget widget;
gchar *text;
gchar *GSEAL (text);
guint editable : 1;
guint visible : 1;
guint overwrite_mode : 1;
guint in_drag : 1; /* Dragging within the selection */
guint GSEAL (editable) : 1;
guint GSEAL (visible) : 1;
guint GSEAL (overwrite_mode) : 1;
guint GSEAL (in_drag) : 1; /* FIXME: Should be private?
Dragging within the selection */
guint16 text_length; /* length in use, in chars */
guint16 text_max_length;
guint16 GSEAL (text_length); /* length in use, in chars */
guint16 GSEAL (text_max_length);
/*< private >*/
GdkWindow *text_area;
GtkIMContext *im_context;
GtkWidget *popup_menu;
GdkWindow *GSEAL (text_area);
GtkIMContext *GSEAL (im_context);
GtkWidget *GSEAL (popup_menu);
gint current_pos;
gint selection_bound;
gint GSEAL (current_pos);
gint GSEAL (selection_bound);
PangoLayout *cached_layout;
PangoLayout *GSEAL (cached_layout);
guint cache_includes_preedit : 1;
guint need_im_reset : 1;
guint has_frame : 1;
guint activates_default : 1;
guint cursor_visible : 1;
guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
guint is_cell_renderer : 1;
guint editing_canceled : 1; /* Only used by GtkCellRendererText */
guint mouse_cursor_obscured : 1;
guint select_words : 1;
guint select_lines : 1;
guint resolved_dir : 4; /* PangoDirection */
guint truncate_multiline : 1;
guint GSEAL (cache_includes_preedit) : 1;
guint GSEAL (need_im_reset) : 1;
guint GSEAL (has_frame) : 1;
guint GSEAL (activates_default) : 1;
guint GSEAL (cursor_visible) : 1;
guint GSEAL (in_click) : 1; /* Flag so we don't select all when clicking in entry to focus in */
guint GSEAL (is_cell_renderer) : 1;
guint GSEAL (editing_canceled) : 1; /* Only used by GtkCellRendererText */
guint GSEAL (mouse_cursor_obscured) : 1;
guint GSEAL (select_words) : 1;
guint GSEAL (select_lines) : 1;
guint GSEAL (resolved_dir) : 4; /* PangoDirection */
guint GSEAL (truncate_multiline) : 1;
guint button;
guint blink_timeout;
guint recompute_idle;
gint scroll_offset;
gint ascent; /* font ascent, in pango units */
gint descent; /* font descent, in pango units */
guint GSEAL (button);
guint GSEAL (blink_timeout);
guint GSEAL (recompute_idle);
gint GSEAL (scroll_offset);
gint GSEAL (ascent); /* font ascent in pango units */
gint GSEAL (descent); /* font descent in pango units */
guint16 text_size; /* allocated size, in bytes */
guint16 n_bytes; /* length in use, in bytes */
guint16 GSEAL (text_size); /* allocated size, in bytes */
guint16 GSEAL (n_bytes); /* length in use, in bytes */
guint16 preedit_length; /* length of preedit string, in bytes */
guint16 preedit_cursor; /* offset of cursor within preedit string, in chars */
guint16 GSEAL (preedit_length); /* length of preedit string, in bytes */
guint16 GSEAL (preedit_cursor); /* offset of cursor within preedit string, in chars */
gint dnd_position; /* In chars, -1 == no DND cursor */
gint GSEAL (dnd_position); /* In chars, -1 == no DND cursor */
gint drag_start_x;
gint drag_start_y;
gint GSEAL (drag_start_x);
gint GSEAL (drag_start_y);
gunichar invisible_char;
gunichar GSEAL (invisible_char);
gint width_chars;
gint GSEAL (width_chars);
};
struct _GtkEntryClass
@ -165,10 +166,14 @@ gboolean gtk_entry_get_has_frame (GtkEntry *entry);
void gtk_entry_set_inner_border (GtkEntry *entry,
const GtkBorder *border);
G_CONST_RETURN GtkBorder* gtk_entry_get_inner_border (GtkEntry *entry);
void gtk_entry_set_overwrite_mode (GtkEntry *entry,
gboolean overwrite);
gboolean gtk_entry_get_overwrite_mode (GtkEntry *entry);
/* text is truncated if needed */
void gtk_entry_set_max_length (GtkEntry *entry,
gint max);
gint gtk_entry_get_max_length (GtkEntry *entry);
guint16 gtk_entry_get_text_length (GtkEntry *entry);
void gtk_entry_set_activates_default (GtkEntry *entry,
gboolean setting);
gboolean gtk_entry_get_activates_default (GtkEntry *entry);