#include "gtkclipboard.h"
#include "gtkdnd.h"
#include "gtkentry.h"
+#include "gtkentrybuffer.h"
#include "gtkimagemenuitem.h"
#include "gtkimcontextsimple.h"
#include "gtkimmulticontext.h"
#define COMPLETION_TIMEOUT 300
#define PASSWORD_HINT_MAX 8
-/* Initial size of buffer, in bytes */
-#define MIN_SIZE 16
-
-/* Maximum size of text buffer, in bytes */
-#define MAX_SIZE G_MAXUSHORT
-
#define MAX_ICONS 2
#define IS_VALID_ICON_POSITION(pos) \
struct _GtkEntryPrivate
{
+ GtkEntryBuffer* buffer;
+
gfloat xalign;
gint insert_pos;
guint blink_time; /* time in msec the cursor has blinked since last user event */
gint start_y;
gchar *im_module;
+
+ GdkDevice *completion_device;
};
typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
struct _GtkEntryPasswordHint
{
- gchar password_hint[PASSWORD_HINT_MAX];
- guint password_hint_timeout_id;
- gint password_hint_length;
- gint password_hint_position;
+ gint position; /* Position (in text) of the last password hint */
+ guint source_id; /* Timeout source id */
};
typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
TOGGLE_OVERWRITE,
ICON_PRESS,
ICON_RELEASE,
+ PREEDIT_CHANGED,
LAST_SIGNAL
};
enum {
PROP_0,
+ PROP_BUFFER,
PROP_CURSOR_POSITION,
PROP_SELECTION_BOUND,
PROP_EDITABLE,
PROP_TOOLTIP_TEXT_SECONDARY,
PROP_TOOLTIP_MARKUP_PRIMARY,
PROP_TOOLTIP_MARKUP_SECONDARY,
- PROP_IM_MODULE
+ PROP_IM_MODULE,
+ PROP_EDITING_CANCELED
};
static guint signals[LAST_SIGNAL] = { 0 };
CURSOR_DND
} CursorType;
+typedef enum
+{
+ DISPLAY_NORMAL, /* The entry text is being shown */
+ DISPLAY_INVISIBLE, /* In invisible mode, text replaced by (eg) bullets */
+ DISPLAY_BLANK /* In invisible mode, nothing shown at all */
+} DisplayMode;
+
/* GObject, GtkObject methods
*/
static void gtk_entry_editable_init (GtkEditableClass *iface);
static void gtk_entry_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_entry_draw_frame (GtkWidget *widget,
- GdkRectangle *area);
+ GdkEventExpose *event);
static void gtk_entry_draw_progress (GtkWidget *widget,
GdkEventExpose *event);
static gint gtk_entry_expose (GtkWidget *widget,
static void gtk_entry_delete_whitespace (GtkEntry *entry);
static void gtk_entry_select_word (GtkEntry *entry);
static void gtk_entry_select_line (GtkEntry *entry);
-static char * gtk_entry_get_public_chars (GtkEntry *entry,
- gint start,
- gint end);
static void gtk_entry_paste (GtkEntry *entry,
GdkAtom selection);
static void gtk_entry_update_primary_selection (GtkEntry *entry);
GdkEventButton *event);
static gboolean gtk_entry_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling);
-static void gtk_entry_state_changed (GtkWidget *widget,
- GtkStateType previous_state);
static void gtk_entry_check_cursor_blink (GtkEntry *entry);
static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
static void gtk_entry_reset_blink_time (GtkEntry *entry);
gint *y,
gint *width,
gint *height);
+static void get_text_area_size (GtkEntry *entry,
+ gint *x,
+ gint *y,
+ gint *width,
+ gint *height);
static void get_widget_window_size (GtkEntry *entry,
gint *x,
gint *y,
static void emit_changed (GtkEntry *entry);
+static void buffer_inserted_text (GtkEntryBuffer *buffer,
+ guint position,
+ const gchar *chars,
+ guint n_chars,
+ GtkEntry *entry);
+static void buffer_deleted_text (GtkEntryBuffer *buffer,
+ guint position,
+ guint n_chars,
+ GtkEntry *entry);
+static void buffer_notify_text (GtkEntryBuffer *buffer,
+ GParamSpec *spec,
+ GtkEntry *entry);
+static void buffer_notify_length (GtkEntryBuffer *buffer,
+ GParamSpec *spec,
+ GtkEntry *entry);
+static void buffer_notify_max_length (GtkEntryBuffer *buffer,
+ GParamSpec *spec,
+ GtkEntry *entry);
+static void buffer_connect_signals (GtkEntry *entry);
+static void buffer_disconnect_signals (GtkEntry *entry);
+static GtkEntryBuffer *get_buffer (GtkEntry *entry);
+
+
G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
gtk_entry_editable_init)
quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
+ g_object_class_override_property (gobject_class,
+ PROP_EDITING_CANCELED,
+ "editing-canceled");
+
+ g_object_class_install_property (gobject_class,
+ PROP_BUFFER,
+ g_param_spec_object ("buffer",
+ P_("Text Buffer"),
+ P_("Text buffer object which actually stores entry text"),
+ GTK_TYPE_ENTRY_BUFFER,
+ GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
g_object_class_install_property (gobject_class,
PROP_CURSOR_POSITION,
g_param_spec_int ("cursor-position",
P_("Cursor Position"),
P_("The current position of the insertion cursor in chars"),
0,
- MAX_SIZE,
+ GTK_ENTRY_BUFFER_MAX_SIZE,
0,
GTK_PARAM_READABLE));
P_("Selection Bound"),
P_("The position of the opposite end of the selection from the cursor in chars"),
0,
- MAX_SIZE,
+ GTK_ENTRY_BUFFER_MAX_SIZE,
0,
GTK_PARAM_READABLE));
P_("Maximum length"),
P_("Maximum number of characters for this entry. Zero if no maximum"),
0,
- MAX_SIZE,
+ GTK_ENTRY_BUFFER_MAX_SIZE,
0,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
P_("Whether activatable icons should prelight when hovered"),
TRUE,
GTK_PARAM_READABLE));
+
+ /**
+ * GtkEntry:progress-border:
+ *
+ * The border around the progress bar in the entry.
+ *
+ * Since: 2.16
+ */
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_boxed ("progress-border",
+ P_("Progress Border"),
+ P_("Border around the progress bar"),
+ GTK_TYPE_BORDER,
+ GTK_PARAM_READABLE));
+
+ /**
+ * GtkEntry:invisible-char:
+ *
+ * The invisible character is used when masking entry contents (in
+ * \"password mode\")"). When it is not explicitly set with the
+ * #GtkEntry::invisible-char property, GTK+ determines the character
+ * to use from a list of possible candidates, depending on availability
+ * in the current font.
+ *
+ * This style property allows the theme to prepend a character
+ * to the list of candidates.
+ *
+ * Since: 2.18
+ */
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_unichar ("invisible-char",
+ P_("Invisible character"),
+ P_("The character to use when masking entry contents (in \"password mode\")"),
+ 0,
+ GTK_PARAM_READABLE));
/**
* GtkEntry::populate-popup:
* @icon_pos: The position of the clicked icon
* @event: the button press event
*
- * The ::icon-press signal is emitted when an activatable icon
+ * The ::icon-press signal is emitted when an activatable icon
* is clicked.
*
* Since: 2.16
signals[ICON_PRESS] =
g_signal_new (I_("icon-press"),
G_TYPE_FROM_CLASS (gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
_gtk_marshal_VOID__ENUM_BOXED,
signals[ICON_RELEASE] =
g_signal_new (I_("icon-release"),
G_TYPE_FROM_CLASS (gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
_gtk_marshal_VOID__ENUM_BOXED,
GTK_TYPE_ENTRY_ICON_POSITION,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+ /**
+ * GtkEntry::preedit-changed:
+ * @entry: the object which received the signal
+ * @preedit: the current preedit string
+ *
+ * If an input method is used, the typed text will not immediately
+ * be committed to the buffer. So if you are interested in the text,
+ * connect to this signal.
+ *
+ * Since: 2.20
+ */
+ signals[PREEDIT_CHANGED] =
+ g_signal_new_class_handler (I_("preedit-changed"),
+ G_OBJECT_CLASS_TYPE (gobject_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ NULL,
+ NULL, NULL,
+ _gtk_marshal_VOID__STRING,
+ G_TYPE_NONE, 1,
+ G_TYPE_STRING);
+
/*
* Key bindings
{
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
GtkEntry *entry = GTK_ENTRY (object);
+ GtkWidget *widget;
switch (prop_id)
{
+ case PROP_BUFFER:
+ gtk_entry_set_buffer (entry, g_value_get_object (value));
+ break;
+
case PROP_EDITABLE:
{
gboolean new_value = g_value_get_boolean (value);
if (new_value != entry->editable)
{
+ widget = GTK_WIDGET (entry);
if (!new_value)
{
_gtk_entry_reset_im_context (entry);
- if (GTK_WIDGET_HAS_FOCUS (entry))
+ if (gtk_widget_has_focus (widget))
gtk_im_context_focus_out (entry->im_context);
entry->preedit_length = 0;
entry->editable = new_value;
- if (new_value && GTK_WIDGET_HAS_FOCUS (entry))
+ if (new_value && gtk_widget_has_focus (widget))
gtk_im_context_focus_in (entry->im_context);
gtk_entry_queue_draw (entry);
case PROP_IM_MODULE:
g_free (priv->im_module);
- priv->im_module = g_strdup (g_value_get_string (value));
+ priv->im_module = g_value_dup_string (value);
if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
break;
+ case PROP_EDITING_CANCELED:
+ entry->editing_canceled = g_value_get_boolean (value);
+ break;
+
case PROP_SCROLL_OFFSET:
case PROP_CURSOR_POSITION:
default:
switch (prop_id)
{
+ case PROP_BUFFER:
+ g_value_set_object (value, gtk_entry_get_buffer (entry));
+ break;
+
case PROP_CURSOR_POSITION:
g_value_set_int (value, entry->current_pos);
break;
break;
case PROP_MAX_LENGTH:
- g_value_set_int (value, entry->text_max_length);
+ g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
break;
case PROP_VISIBILITY:
break;
case PROP_TEXT_LENGTH:
- g_value_set_uint (value, entry->text_length);
+ g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
break;
case PROP_INVISIBLE_CHAR_SET:
gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
break;
+ case PROP_EDITING_CANCELED:
+ g_value_set_boolean (value,
+ entry->editing_canceled);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
PangoAttrList *attr_list;
gint i;
gunichar invisible_chars [] = {
+ 0,
0x25cf, /* BLACK CIRCLE */
0x2022, /* BULLET */
0x2731, /* HEAVY ASTERISK */
0x273a /* SIXTEEN POINTED ASTERISK */
};
+ if (widget->style)
+ gtk_widget_style_get (widget,
+ "invisible-char", &invisible_chars[0],
+ NULL);
+
layout = gtk_widget_create_pango_layout (widget, NULL);
attr_list = pango_attr_list_new ();
pango_layout_set_attributes (layout, attr_list);
pango_attr_list_unref (attr_list);
- for (i = 0; i < G_N_ELEMENTS (invisible_chars); i++)
+ for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
{
gchar text[7] = { 0, };
gint len, count;
}
g_object_unref (layout);
+
return '*';
}
gtk_entry_init (GtkEntry *entry)
{
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
-
- GTK_WIDGET_SET_FLAGS (entry, GTK_CAN_FOCUS);
- entry->text_size = MIN_SIZE;
- entry->text = g_malloc (entry->text_size);
- entry->text[0] = '\0';
+ gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
entry->editable = TRUE;
entry->visible = TRUE;
G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
g_signal_connect (entry->im_context, "delete-surrounding",
G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
+
}
static gint
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
gint x, y, width, height;
- gtk_entry_get_text_area_size (entry, &x, &y, &width, &height);
+ get_text_area_size (entry, &x, &y, &width, &height);
+
+ if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
+ y += priv->focus_width;
primary->y = y;
primary->height = height;
priv->real_changed = TRUE;
}
-/*
- * Overwrite a memory that might contain sensitive information.
- */
-static void
-trash_area (gchar *area, gsize len)
-{
- volatile gchar *varea = (volatile gchar *)area;
- while (len-- > 0)
- *varea++ = 0;
-}
-
static void
gtk_entry_destroy (GtkObject *object)
{
GtkEntry *entry = GTK_ENTRY (object);
- entry->n_bytes = 0;
- entry->current_pos = entry->selection_bound = entry->text_length = 0;
+ entry->current_pos = entry->selection_bound = 0;
_gtk_entry_reset_im_context (entry);
gtk_entry_reset_layout (entry);
entry->recompute_idle = 0;
}
- if (!entry->visible)
- {
- /* We want to trash the text here because the entry might be leaked. */
- trash_area (entry->text, strlen (entry->text));
- }
-
GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
}
gtk_entry_dispose (GObject *object)
{
GtkEntry *entry = GTK_ENTRY (object);
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
+ if (priv->buffer)
+ {
+ buffer_disconnect_signals (entry);
+ g_object_unref (priv->buffer);
+ priv->buffer = NULL;
+ }
+
G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
}
if (entry->recompute_idle)
g_source_remove (entry->recompute_idle);
- entry->text_size = 0;
+ g_free (priv->im_module);
+
+ G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
+}
+
+static DisplayMode
+gtk_entry_get_display_mode (GtkEntry *entry)
+{
+ GtkEntryPrivate *priv;
+ if (entry->visible)
+ return DISPLAY_NORMAL;
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
+ if (entry->invisible_char == 0 && priv->invisible_char_set)
+ return DISPLAY_BLANK;
+ return DISPLAY_INVISIBLE;
+}
+
+static gchar*
+gtk_entry_get_display_text (GtkEntry *entry,
+ gint start_pos,
+ gint end_pos)
+{
+ GtkEntryPasswordHint *password_hint;
+ GtkEntryPrivate *priv;
+ gunichar invisible_char;
+ const gchar *start;
+ const gchar *end;
+ const gchar *text;
+ gchar char_str[7];
+ gint char_len;
+ GString *str;
+ guint length;
+ gint i;
+
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
+ text = gtk_entry_buffer_get_text (get_buffer (entry));
+ length = gtk_entry_buffer_get_length (get_buffer (entry));
+
+ if (end_pos < 0)
+ end_pos = length;
+ if (start_pos > length)
+ start_pos = length;
- if (entry->text)
+ if (end_pos <= start_pos)
+ return g_strdup ("");
+ else if (entry->visible)
{
- if (!entry->visible)
- trash_area (entry->text, strlen (entry->text));
- g_free (entry->text);
- entry->text = NULL;
+ start = g_utf8_offset_to_pointer (text, start_pos);
+ end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
+ return g_strndup (start, end - start);
}
+ else
+ {
+ str = g_string_sized_new (length * 2);
- g_free (priv->im_module);
+ /* Figure out what our invisible char is and encode it */
+ if (!entry->invisible_char)
+ invisible_char = priv->invisible_char_set ? ' ' : '*';
+ else
+ invisible_char = entry->invisible_char;
+ char_len = g_unichar_to_utf8 (invisible_char, char_str);
+
+ /*
+ * Add hidden characters for each character in the text
+ * buffer. If there is a password hint, then keep that
+ * character visible.
+ */
+
+ password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
+ for (i = start_pos; i < end_pos; ++i)
+ {
+ if (password_hint && i == password_hint->position)
+ {
+ start = g_utf8_offset_to_pointer (text, i);
+ g_string_append_len (str, start, g_utf8_next_char (start) - start);
+ }
+ else
+ {
+ g_string_append_len (str, char_str, char_len);
+ }
+ }
+
+ return g_string_free (str, FALSE);
+ }
- G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
}
static void
{
if ((icon_info = priv->icons[i]) != NULL)
{
- if (icon_info->pixbuf != NULL)
+ if (icon_info->pixbuf != NULL && icon_info->window != NULL)
gdk_window_show_unraised (icon_info->window);
/* The icon windows are not children of the visible entry window,
* here is that for the entry, insensitive => arrow cursor, but for
* an icon in a sensitive entry, insensitive => xterm cursor.
*/
- if (GTK_WIDGET_IS_SENSITIVE (widget) &&
+ if (gtk_widget_is_sensitive (widget) &&
(icon_info->insensitive ||
(icon_info->nonactivatable && icon_info->target_list == NULL)))
{
attributes_mask);
gdk_window_set_user_data (icon_info->window, widget);
gdk_window_set_background (icon_info->window,
- &widget->style->base[GTK_WIDGET_STATE (widget)]);
+ &widget->style->base[gtk_widget_get_state (widget)]);
gtk_widget_queue_resize (widget);
}
icon_info = g_slice_new0 (EntryIconInfo);
priv->icons[icon_pos] = icon_info;
- if (GTK_WIDGET_REALIZED (widget))
+ if (gtk_widget_get_realized (widget))
realize_icon_info (widget, icon_pos);
- if (GTK_WIDGET_MAPPED (widget))
- gdk_window_show_unraised (icon_info->window);
-
return icon_info;
}
EntryIconInfo *icon_info = NULL;
gint i;
- if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_MAPPED (widget))
+ if (gtk_widget_get_realized (widget) && !gtk_widget_get_mapped (widget))
{
GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
EntryIconInfo *icon_info = NULL;
gint i;
- if (GTK_WIDGET_MAPPED (widget))
+ if (gtk_widget_get_mapped (widget))
{
for (i = 0; i < MAX_ICONS; i++)
{
gint attributes_mask;
int i;
- GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+ gtk_widget_set_realized (widget, TRUE);
entry = GTK_ENTRY (widget);
priv = GTK_ENTRY_GET_PRIVATE (entry);
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
gdk_window_set_user_data (widget->window, entry);
- gtk_entry_get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
+ get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
- if (GTK_WIDGET_IS_SENSITIVE (widget))
+ if (gtk_widget_is_sensitive (widget))
{
attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
attributes_mask |= GDK_WA_CURSOR;
widget->style = gtk_style_attach (widget->style, widget->window);
- gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
- gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
+ gdk_window_set_background (widget->window, &widget->style->base[gtk_widget_get_state (widget)]);
+ gdk_window_set_background (entry->text_area, &widget->style->base[gtk_widget_get_state (widget)]);
gdk_window_show (entry->text_area);
static void
place_windows (GtkEntry *entry)
-
{
+ GtkWidget *widget = GTK_WIDGET (entry);
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
gint x, y, width, height;
GtkAllocation primary;
GtkAllocation secondary;
EntryIconInfo *icon_info = NULL;
- gtk_entry_get_text_area_size (entry, &x, &y, &width, &height);
-
+ get_text_area_size (entry, &x, &y, &width, &height);
get_icon_allocations (entry, &primary, &secondary);
- if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
+ if (gtk_widget_has_focus (widget) && !priv->interior_focus)
+ y += priv->focus_width;
+
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
x += secondary.width;
else
x += primary.width;
width -= primary.width + secondary.width;
if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
- gdk_window_move_resize (icon_info->window,
+ gdk_window_move_resize (icon_info->window,
primary.x, primary.y,
primary.width, primary.height);
secondary.x, secondary.y,
secondary.width, secondary.height);
- gdk_window_move_resize (GTK_ENTRY (entry)->text_area, x, y, width, height);
+ gdk_window_move_resize (entry->text_area, x, y, width, height);
}
static void
gtk_widget_get_child_requisition (widget, &requisition);
_gtk_entry_get_borders (entry, &xborder, &yborder);
- if (GTK_WIDGET_REALIZED (widget))
+ if (gtk_widget_get_realized (widget))
gdk_drawable_get_size (widget->window, NULL, &frame_height);
else
frame_height = requisition.height;
- if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
+ if (gtk_widget_has_focus (widget) && !priv->interior_focus)
frame_height -= 2 * priv->focus_width;
if (x)
*height = requisition.height - yborder * 2;
}
+static void
+get_text_area_size (GtkEntry *entry,
+ gint *x,
+ gint *y,
+ gint *width,
+ gint *height)
+{
+ GtkEntryClass *class;
+
+ g_return_if_fail (GTK_IS_ENTRY (entry));
+
+ class = GTK_ENTRY_GET_CLASS (entry);
+
+ if (class->get_text_area_size)
+ class->get_text_area_size (entry, x, y, width, height);
+}
+
+
static void
get_widget_window_size (GtkEntry *entry,
gint *x,
widget->allocation = *allocation;
- if (GTK_WIDGET_REALIZED (widget))
+ if (gtk_widget_get_realized (widget))
{
/* We call gtk_widget_get_child_requisition, since we want (for
* backwards compatibility reasons) the realization here to
GtkEntryCompletion* completion;
get_widget_window_size (entry, &x, &y, &width, &height);
- gdk_window_move_resize (widget->window, x, y, width, height);
+ gdk_window_move_resize (widget->window, x, y, width, height);
place_windows (entry);
gtk_entry_recompute (entry);
completion = gtk_entry_get_completion (entry);
- if (completion && GTK_WIDGET_MAPPED (completion->priv->popup_window))
+ if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
_gtk_entry_completion_resize_popup (completion);
}
}
x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
- if (!GTK_WIDGET_IS_SENSITIVE (widget) ||
+ if (!gtk_widget_is_sensitive (widget) ||
icon_info->insensitive)
{
GdkPixbuf *temp_pixbuf;
static void
-gtk_entry_draw_frame (GtkWidget *widget,
- GdkRectangle *area)
+gtk_entry_draw_frame (GtkWidget *widget,
+ GdkEventExpose *event)
{
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
gint x = 0, y = 0, width, height;
width += xborder * 2;
}
- if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
+ if (gtk_widget_has_focus (widget) && !priv->interior_focus)
{
x += priv->focus_width;
y += priv->focus_width;
gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
if (state_hint)
- state = GTK_WIDGET_HAS_FOCUS (widget) ?
- GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
+ state = gtk_widget_has_focus (widget) ?
+ GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
else
state = GTK_STATE_NORMAL;
gtk_paint_shadow (widget->style, widget->window,
state, priv->shadow_type,
- area, widget, "entry", x, y, width, height);
+ &event->area, widget, "entry", x, y, width, height);
+
- if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
+ gtk_entry_draw_progress (widget, event);
+
+ if (gtk_widget_has_focus (widget) && !priv->interior_focus)
{
x -= priv->focus_width;
y -= priv->focus_width;
width += 2 * priv->focus_width;
height += 2 * priv->focus_width;
- gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
- area, widget, "entry",
+ gtk_paint_focus (widget->style, widget->window,
+ gtk_widget_get_state (widget),
+ &event->area, widget, "entry",
0, 0, width, height);
}
}
static void
-gtk_entry_draw_progress (GtkWidget *widget,
- GdkEventExpose *event)
+gtk_entry_get_progress_border (GtkWidget *widget,
+ GtkBorder *progress_border)
+{
+ GtkBorder *tmp_border;
+
+ gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
+ if (tmp_border)
+ {
+ *progress_border = *tmp_border;
+ gtk_border_free (tmp_border);
+ }
+ else
+ {
+ progress_border->left = widget->style->xthickness;
+ progress_border->right = widget->style->xthickness;
+ progress_border->top = widget->style->ythickness;
+ progress_border->bottom = widget->style->ythickness;
+ }
+}
+
+static void
+get_progress_area (GtkWidget *widget,
+ gint *x,
+ gint *y,
+ gint *width,
+ gint *height)
{
GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
GtkEntry *entry = GTK_ENTRY (widget);
+ GtkBorder progress_border;
+
+ gtk_entry_get_progress_border (widget, &progress_border);
+
+ *x = progress_border.left;
+ *y = progress_border.top;
+
+ gdk_drawable_get_size (widget->window, width, height);
+
+ *width -= progress_border.left + progress_border.right;
+ *height -= progress_border.top + progress_border.bottom;
+
+ if (gtk_widget_has_focus (widget) && !private->interior_focus)
+ {
+ *x += private->focus_width;
+ *y += private->focus_width;
+ *width -= 2 * private->focus_width;
+ *height -= 2 * private->focus_width;
+ }
if (private->progress_pulse_mode)
{
gdouble value = private->progress_pulse_current;
- gint area_width, area_height;
-
- gdk_drawable_get_size (entry->text_area, &area_width, &area_height);
- gtk_paint_box (widget->style, entry->text_area,
- GTK_STATE_SELECTED, GTK_SHADOW_OUT,
- &event->area, widget, "entry-progress",
- value * area_width, 0,
- private->progress_pulse_fraction * area_width, area_height);
+ *x += (gint) floor(value * (*width));
+ *width = (gint) ceil(private->progress_pulse_fraction * (*width));
}
else if (private->progress_fraction > 0)
{
gdouble value = private->progress_fraction;
- gint area_width, area_height;
-
- gdk_drawable_get_size (entry->text_area, &area_width, &area_height);
if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
{
- gtk_paint_box (widget->style, entry->text_area,
- GTK_STATE_SELECTED, GTK_SHADOW_OUT,
- &event->area, widget, "entry-progress",
- area_width - value * area_width, 0,
- value * area_width, area_height);
+ gint bar_width;
+
+ bar_width = floor(value * (*width) + 0.5);
+ *x += *width - bar_width;
+ *width = bar_width;
}
else
{
- gtk_paint_box (widget->style, entry->text_area,
- GTK_STATE_SELECTED, GTK_SHADOW_OUT,
- &event->area, widget, "entry-progress",
- 0, 0,
- value * area_width, area_height);
+ *width = (gint) floor(value * (*width) + 0.5);
}
}
+ else
+ {
+ *width = 0;
+ *height = 0;
+ }
+}
+
+static void
+gtk_entry_draw_progress (GtkWidget *widget,
+ GdkEventExpose *event)
+{
+ gint x, y, width, height;
+ GtkStateType state;
+
+ get_progress_area (widget, &x, &y, &width, &height);
+
+ if ((width <= 0) || (height <= 0))
+ return;
+
+ if (event->window != widget->window)
+ {
+ gint pos_x, pos_y;
+
+ gdk_window_get_position (event->window, &pos_x, &pos_y);
+
+ x -= pos_x;
+ y -= pos_y;
+ }
+
+ state = GTK_STATE_SELECTED;
+ if (!gtk_widget_get_sensitive (widget))
+ state = GTK_STATE_INSENSITIVE;
+
+ gtk_paint_box (widget->style, event->window,
+ state, GTK_SHADOW_OUT,
+ &event->area, widget, "entry-progress",
+ x, y,
+ width, height);
}
static gint
gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
if (state_hint)
- state = GTK_WIDGET_HAS_FOCUS (widget) ?
- GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
+ state = gtk_widget_has_focus (widget) ?
+ GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
else
- state = GTK_WIDGET_STATE(widget);
+ state = gtk_widget_get_state(widget);
if (widget->window == event->window)
{
- gtk_entry_draw_frame (widget, &event->area);
+ gtk_entry_draw_frame (widget, event);
}
else if (entry->text_area == event->window)
{
gtk_entry_draw_text (GTK_ENTRY (widget));
- if ((entry->visible || entry->invisible_char != 0) &&
- GTK_WIDGET_HAS_FOCUS (widget) &&
- entry->selection_bound == entry->current_pos && entry->cursor_visible)
- gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
+ /* When no text is being displayed at all, don't show the cursor */
+ if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
+ gtk_widget_has_focus (widget) &&
+ entry->selection_bound == entry->current_pos && entry->cursor_visible)
+ gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
}
else
{
gdk_drawable_get_size (icon_info->window, &width, &height);
gtk_paint_flat_box (widget->style, icon_info->window,
- GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
+ gtk_widget_get_state (widget), GTK_SHADOW_NONE,
NULL, widget, "entry_bg",
0, 0, width, height);
+ gtk_entry_draw_progress (widget, event);
draw_icon (widget, i);
break;
if (icon_info != NULL && event->window == icon_info->window)
{
+ /* a grab means that we may never see the button release */
+ if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
+ icon_info->pressed = FALSE;
+
if (should_prelight (entry, i))
{
icon_info->prelight = FALSE;
entry->button = event->button;
- if (!GTK_WIDGET_HAS_FOCUS (widget))
+ if (!gtk_widget_has_focus (widget))
{
entry->in_click = TRUE;
gtk_widget_grab_focus (widget);
if (entry->in_drag)
{
- if (entry->visible &&
+ if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
gtk_drag_check_threshold (widget,
entry->drag_start_x, entry->drag_start_y,
event->x + entry->scroll_offset, event->y))
if (event->y < 0)
tmp_pos = 0;
else if (event->y >= height)
- tmp_pos = entry->text_length;
+ tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
else
tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
gtk_entry_set_positions (entry, pos, bound);
}
else
- gtk_entry_set_positions (entry, tmp_pos, -1);
+ gtk_entry_set_positions (entry, tmp_pos, -1);
}
return TRUE;
GtkEntry *entry = GTK_ENTRY (widget);
GtkEntryCompletion *completion;
GdkKeymap *keymap;
-
+
gtk_widget_queue_draw (widget);
keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
GdkCursor *cursor;
gint i;
- if (GTK_WIDGET_REALIZED (widget))
+ if (gtk_widget_get_realized (widget))
{
- gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
- gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
+ gdk_window_set_background (widget->window, &widget->style->base[gtk_widget_get_state (widget)]);
+ gdk_window_set_background (entry->text_area, &widget->style->base[gtk_widget_get_state (widget)]);
for (i = 0; i < MAX_ICONS; i++)
{
EntryIconInfo *icon_info = priv->icons[i];
if (icon_info && icon_info->window)
- gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
+ gdk_window_set_background (icon_info->window, &widget->style->base[gtk_widget_get_state (widget)]);
}
- if (GTK_WIDGET_IS_SENSITIVE (widget))
+ if (gtk_widget_is_sensitive (widget))
cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
else
cursor = NULL;
update_cursors (widget);
}
- if (!GTK_WIDGET_IS_SENSITIVE (widget))
+ if (!gtk_widget_is_sensitive (widget))
{
/* Clear any selection */
gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
gint new_text_length,
gint *position)
{
- GtkEntry *entry = GTK_ENTRY (editable);
- gchar buf[64];
- gchar *text;
-
- if (*position < 0 || *position > entry->text_length)
- *position = entry->text_length;
-
g_object_ref (editable);
-
- if (new_text_length <= 63)
- text = buf;
- else
- text = g_new (gchar, new_text_length + 1);
-
- text[new_text_length] = '\0';
- strncpy (text, new_text, new_text_length);
-
- g_signal_emit_by_name (editable, "insert-text", text, new_text_length, position);
- if (!entry->visible)
- trash_area (text, new_text_length);
+ /*
+ * The incoming text may a password or other secret. We make sure
+ * not to copy it into temporary buffers.
+ */
- if (new_text_length > 63)
- g_free (text);
+ g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
g_object_unref (editable);
}
gint start_pos,
gint end_pos)
{
- GtkEntry *entry = GTK_ENTRY (editable);
-
- if (end_pos < 0 || end_pos > entry->text_length)
- end_pos = entry->text_length;
- if (start_pos < 0)
- start_pos = 0;
- if (start_pos > end_pos)
- start_pos = end_pos;
-
g_object_ref (editable);
g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
gint end_pos)
{
GtkEntry *entry = GTK_ENTRY (editable);
+ const gchar *text;
+ gint text_length;
gint start_index, end_index;
-
+
+ text = gtk_entry_buffer_get_text (get_buffer (entry));
+ text_length = gtk_entry_buffer_get_length (get_buffer (entry));
+
if (end_pos < 0)
- end_pos = entry->text_length;
+ end_pos = text_length;
- start_pos = MIN (entry->text_length, start_pos);
- end_pos = MIN (entry->text_length, end_pos);
+ start_pos = MIN (text_length, start_pos);
+ end_pos = MIN (text_length, end_pos);
- start_index = g_utf8_offset_to_pointer (entry->text, start_pos) - entry->text;
- end_index = g_utf8_offset_to_pointer (entry->text, end_pos) - entry->text;
+ start_index = g_utf8_offset_to_pointer (text, start_pos) - entry->text;
+ end_index = g_utf8_offset_to_pointer (text, end_pos) - entry->text;
- return g_strndup (entry->text + start_index, end_index - start_index);
+ return g_strndup (text + start_index, end_index - start_index);
}
static void
{
GtkEntry *entry = GTK_ENTRY (editable);
- if (position < 0 || position > entry->text_length)
- position = entry->text_length;
+ guint length;
+
+ length = gtk_entry_buffer_get_length (get_buffer (entry));
+ if (position < 0 || position > length)
+ position = length;
if (position != entry->current_pos ||
position != entry->selection_bound)
gint end)
{
GtkEntry *entry = GTK_ENTRY (editable);
+ guint length;
+ length = gtk_entry_buffer_get_length (get_buffer (entry));
if (start < 0)
- start = entry->text_length;
+ start = length;
if (end < 0)
- end = entry->text_length;
+ end = length;
_gtk_entry_reset_im_context (entry);
gtk_entry_set_positions (entry,
- MIN (end, entry->text_length),
- MIN (start, entry->text_length));
+ MIN (end, length),
+ MIN (start, length));
gtk_entry_update_primary_selection (entry);
}
gtk_entry_recompute (entry);
- if (previous_style && GTK_WIDGET_REALIZED (widget))
+ if (previous_style && gtk_widget_get_realized (widget))
{
- gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
- gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
+ gdk_window_set_background (widget->window, &widget->style->base[gtk_widget_get_state (widget)]);
+ gdk_window_set_background (entry->text_area, &widget->style->base[gtk_widget_get_state (widget)]);
for (i = 0; i < MAX_ICONS; i++)
{
EntryIconInfo *icon_info = priv->icons[i];
if (icon_info && icon_info->window)
- gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
+ gdk_window_set_background (icon_info->window, &widget->style->base[gtk_widget_get_state (widget)]);
}
}
static void
gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
{
- if (password_hint->password_hint_timeout_id)
- g_source_remove (password_hint->password_hint_timeout_id);
+ if (password_hint->source_id)
+ g_source_remove (password_hint->source_id);
g_slice_free (GtkEntryPasswordHint, password_hint);
}
+
+static gboolean
+gtk_entry_remove_password_hint (gpointer data)
+{
+ GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
+ password_hint->position = -1;
+
+ /* Force the string to be redrawn, but now without a visible character */
+ gtk_entry_recompute (GTK_ENTRY (data));
+ return FALSE;
+}
+
/* Default signal handlers
*/
static void
gint new_text_length,
gint *position)
{
- GtkEntry *entry = GTK_ENTRY (editable);
- gint index;
+ guint n_inserted;
gint n_chars;
- if (new_text_length < 0)
- new_text_length = strlen (new_text);
-
n_chars = g_utf8_strlen (new_text, new_text_length);
- if (entry->text_max_length > 0 && n_chars + entry->text_length > entry->text_max_length)
- {
- gtk_widget_error_bell (GTK_WIDGET (entry));
- n_chars = entry->text_max_length - entry->text_length;
- new_text_length = g_utf8_offset_to_pointer (new_text, n_chars) - new_text;
- }
- if (new_text_length + entry->n_bytes + 1 > entry->text_size)
- {
- gsize prev_size = entry->text_size;
+ /*
+ * The actual insertion into the buffer. This will end up firing the
+ * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
+ * buffer_notify_text(), buffer_notify_length()
+ */
+ n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
- while (new_text_length + entry->n_bytes + 1 > entry->text_size)
- {
- if (entry->text_size == 0)
- entry->text_size = MIN_SIZE;
- else
- {
- if (2 * (guint)entry->text_size < MAX_SIZE &&
- 2 * (guint)entry->text_size > entry->text_size)
- entry->text_size *= 2;
- else
- {
- entry->text_size = MAX_SIZE;
- if (new_text_length > (gint)entry->text_size - (gint)entry->n_bytes - 1)
- {
- new_text_length = (gint)entry->text_size - (gint)entry->n_bytes - 1;
- new_text_length = g_utf8_find_prev_char (new_text, new_text + new_text_length + 1) - new_text;
- n_chars = g_utf8_strlen (new_text, new_text_length);
- }
- break;
- }
- }
- }
+ if (n_inserted != n_chars)
+ gtk_widget_error_bell (GTK_WIDGET (editable));
- if (entry->visible)
- entry->text = g_realloc (entry->text, entry->text_size);
- else
- {
- /* Same thing, just slower and without leaving stuff in memory. */
- gchar *et_new = g_malloc (entry->text_size);
- memcpy (et_new, entry->text, MIN (prev_size, entry->text_size));
- trash_area (entry->text, prev_size);
- g_free (entry->text);
- entry->text = et_new;
- }
- }
+ *position += n_inserted;
+}
- index = g_utf8_offset_to_pointer (entry->text, *position) - entry->text;
+static void
+gtk_entry_real_delete_text (GtkEditable *editable,
+ gint start_pos,
+ gint end_pos)
+{
+ /*
+ * The actual deletion from the buffer. This will end up firing the
+ * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
+ * buffer_notify_text(), buffer_notify_length()
+ */
- g_memmove (entry->text + index + new_text_length, entry->text + index, entry->n_bytes - index);
- memcpy (entry->text + index, new_text, new_text_length);
+ gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
+}
- entry->n_bytes += new_text_length;
- entry->text_length += n_chars;
+/* GtkEntryBuffer signal handlers
+ */
+static void
+buffer_inserted_text (GtkEntryBuffer *buffer,
+ guint position,
+ const gchar *chars,
+ guint n_chars,
+ GtkEntry *entry)
+{
+ guint password_hint_timeout;
- /* NUL terminate for safety and convenience */
- entry->text[entry->n_bytes] = '\0';
-
- if (entry->current_pos > *position)
+ if (entry->current_pos > position)
entry->current_pos += n_chars;
-
- if (entry->selection_bound > *position)
+
+ if (entry->selection_bound > position)
entry->selection_bound += n_chars;
- if (n_chars == 1 && !entry->visible && (new_text_length < PASSWORD_HINT_MAX))
+ /* Calculate the password hint if it needs to be displayed. */
+ if (n_chars == 1 && !entry->visible)
{
- guint password_hint_timeout;
-
g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
"gtk-entry-password-hint-timeout", &password_hint_timeout,
NULL);
{
GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
quark_password_hint);
-
if (!password_hint)
{
password_hint = g_slice_new0 (GtkEntryPasswordHint);
- g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint,
- password_hint,
- (GDestroyNotify) gtk_entry_password_hint_free);
+ g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
+ (GDestroyNotify)gtk_entry_password_hint_free);
}
- memset (&password_hint->password_hint, 0x0, PASSWORD_HINT_MAX);
- password_hint->password_hint_length = new_text_length;
- memcpy (&password_hint->password_hint, new_text, new_text_length);
- password_hint->password_hint_position = *position + n_chars;
- }
- }
- else
- {
- g_object_set_qdata (G_OBJECT (entry), quark_password_hint, NULL);
+ password_hint->position = position;
+ if (password_hint->source_id)
+ g_source_remove (password_hint->source_id);
+ password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
+ (GSourceFunc)gtk_entry_remove_password_hint, entry);
+ }
}
-
- *position += n_chars;
-
- gtk_entry_recompute (entry);
-
- emit_changed (entry);
- g_object_notify (G_OBJECT (editable), "text");
- g_object_notify (G_OBJECT (editable), "text-length");
}
static void
-gtk_entry_real_delete_text (GtkEditable *editable,
- gint start_pos,
- gint end_pos)
+buffer_deleted_text (GtkEntryBuffer *buffer,
+ guint position,
+ guint n_chars,
+ GtkEntry *entry)
{
- GtkEntry *entry = GTK_ENTRY (editable);
+ guint end_pos = position + n_chars;
+ gint selection_bound;
+ guint current_pos;
- if (start_pos < 0)
- start_pos = 0;
- if (end_pos < 0 || end_pos > entry->text_length)
- end_pos = entry->text_length;
-
- if (start_pos < end_pos)
- {
- gint start_index = g_utf8_offset_to_pointer (entry->text, start_pos) - entry->text;
- gint end_index = g_utf8_offset_to_pointer (entry->text, end_pos) - entry->text;
- gint current_pos;
- gint selection_bound;
+ current_pos = entry->current_pos;
+ if (current_pos > position)
+ current_pos -= MIN (current_pos, end_pos) - position;
- g_memmove (entry->text + start_index, entry->text + end_index, entry->n_bytes + 1 - end_index);
- entry->text_length -= (end_pos - start_pos);
- entry->n_bytes -= (end_index - start_index);
+ selection_bound = entry->selection_bound;
+ if (selection_bound > position)
+ selection_bound -= MIN (selection_bound, end_pos) - position;
- /* In password-mode, make sure we don't leave anything sensitive after
- * the terminating zero. Note, that the terminating zero already trashed
- * one byte.
- */
- if (!entry->visible)
- trash_area (entry->text + entry->n_bytes + 1, end_index - start_index - 1);
-
- current_pos = entry->current_pos;
- if (current_pos > start_pos)
- current_pos -= MIN (current_pos, end_pos) - start_pos;
+ gtk_entry_set_positions (entry, current_pos, selection_bound);
- selection_bound = entry->selection_bound;
- if (selection_bound > start_pos)
- selection_bound -= MIN (selection_bound, end_pos) - start_pos;
+ /* We might have deleted the selection */
+ gtk_entry_update_primary_selection (entry);
- gtk_entry_set_positions (entry, current_pos, selection_bound);
+ /* Disable the password hint if one exists. */
+ if (!entry->visible)
+ {
+ GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
+ quark_password_hint);
+ if (password_hint)
+ {
+ if (password_hint->source_id)
+ g_source_remove (password_hint->source_id);
+ password_hint->source_id = 0;
+ password_hint->position = -1;
+ }
+ }
+}
- /* We might have deleted the selection
- */
- gtk_entry_update_primary_selection (entry);
-
- gtk_entry_recompute (entry);
+static void
+buffer_notify_text (GtkEntryBuffer *buffer,
+ GParamSpec *spec,
+ GtkEntry *entry)
+{
+ /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
+ entry->text = (gchar*)gtk_entry_buffer_get_text (buffer);
- emit_changed (entry);
- g_object_notify (G_OBJECT (editable), "text");
- g_object_notify (G_OBJECT (editable), "text-length");
- }
+ gtk_entry_recompute (entry);
+ emit_changed (entry);
+ g_object_notify (G_OBJECT (entry), "text");
+}
+
+static void
+buffer_notify_length (GtkEntryBuffer *buffer,
+ GParamSpec *spec,
+ GtkEntry *entry)
+{
+ /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
+ entry->text_length = gtk_entry_buffer_get_length (buffer);
+
+ g_object_notify (G_OBJECT (entry), "text-length");
+}
+
+static void
+buffer_notify_max_length (GtkEntryBuffer *buffer,
+ GParamSpec *spec,
+ GtkEntry *entry)
+{
+ /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
+ entry->text_max_length = gtk_entry_buffer_get_max_length (buffer);
+
+ g_object_notify (G_OBJECT (entry), "max-length");
+}
+
+static void
+buffer_connect_signals (GtkEntry *entry)
+{
+ g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
+ g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
+ g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
+ g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
+ g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
+}
+
+static void
+buffer_disconnect_signals (GtkEntry *entry)
+{
+ g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
+ g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
+ g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
+ g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
+ g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
}
/* Compute the X position for an offset that corresponds to the "more important
gboolean extend_selection)
{
gint new_pos = entry->current_pos;
+ GtkEntryPrivate *priv;
_gtk_entry_reset_im_context (entry);
case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
case GTK_MOVEMENT_PARAGRAPH_ENDS:
case GTK_MOVEMENT_BUFFER_ENDS:
- new_pos = count < 0 ? 0 : entry->text_length;
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
+ new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
break;
case GTK_MOVEMENT_DISPLAY_LINES:
case GTK_MOVEMENT_PARAGRAPHS:
case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
case GTK_MOVEMENT_PARAGRAPH_ENDS:
case GTK_MOVEMENT_BUFFER_ENDS:
- new_pos = count < 0 ? 0 : entry->text_length;
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
+ new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
if (entry->current_pos == new_pos)
gtk_widget_error_bell (GTK_WIDGET (entry));
break;
GtkEditable *editable = GTK_EDITABLE (entry);
gint start_pos = entry->current_pos;
gint end_pos = entry->current_pos;
- gint old_n_bytes = entry->n_bytes;
+ gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
_gtk_entry_reset_im_context (entry);
break;
}
- if (entry->n_bytes == old_n_bytes)
+ if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
gtk_widget_error_bell (GTK_WIDGET (entry));
gtk_entry_pend_cursor_blink (entry);
_gtk_entry_reset_im_context (entry);
- if (!entry->editable || !entry->text)
+ if (!entry->editable)
{
gtk_widget_error_bell (GTK_WIDGET (entry));
return;
pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
- if (entry->visible &&
- log_attrs[entry->current_pos].backspace_deletes_character)
+ /* Deleting parts of characters */
+ if (log_attrs[entry->current_pos].backspace_deletes_character)
{
gchar *cluster_text;
gchar *normalized_text;
glong len;
- cluster_text = gtk_editable_get_chars (editable,
- prev_pos,
- entry->current_pos);
+ cluster_text = gtk_entry_get_display_text (entry, prev_pos,
+ entry->current_pos);
normalized_text = g_utf8_normalize (cluster_text,
strlen (cluster_text),
G_NORMALIZE_NFD);
return;
}
- str = gtk_entry_get_public_chars (entry, start, end);
+ str = gtk_entry_get_display_text (entry, start, end);
gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
GDK_SELECTION_CLIPBOARD),
str, -1);
if (window &&
widget != window->default_widget &&
!(widget == window->focus_widget &&
- (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
+ (!window->default_widget || !gtk_widget_get_sensitive (window->default_widget))))
gtk_window_activate_default (window);
}
}
gtk_im_context_get_preedit_string (entry->im_context,
&preedit_string, NULL,
&cursor_pos);
+ g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
entry->preedit_length = strlen (preedit_string);
cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
entry->preedit_cursor = cursor_pos;
gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
GtkEntry *entry)
{
- gtk_im_context_set_surrounding (context,
- entry->text,
- entry->n_bytes,
- g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text);
+ gchar *text;
+
+ /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
+ text = gtk_entry_get_display_text (entry, 0, -1);
+ gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
+ g_utf8_offset_to_pointer (text, entry->current_pos) - text);
+ g_free (text);
return TRUE;
}
}
}
-static void
-append_char (GString *str,
- gunichar ch,
- gint count)
-{
- gint i;
- gint char_len;
- gchar buf[7];
-
- char_len = g_unichar_to_utf8 (ch, buf);
-
- i = 0;
- while (i < count)
- {
- g_string_append_len (str, buf, char_len);
- ++i;
- }
-}
-
-static gboolean
-gtk_entry_remove_password_hint (gpointer data)
-{
- /* Force the string to be redrawn, but now without a visible character */
- gtk_entry_recompute (GTK_ENTRY (data));
-
- return FALSE;
-}
-
static PangoLayout *
gtk_entry_create_layout (GtkEntry *entry,
gboolean include_preedit)
GtkWidget *widget = GTK_WIDGET (entry);
PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
PangoAttrList *tmp_attrs = pango_attr_list_new ();
-
+
gchar *preedit_string = NULL;
gint preedit_length = 0;
PangoAttrList *preedit_attrs = NULL;
+ gchar *display;
+ guint n_bytes;
+
pango_layout_set_single_paragraph_mode (layout, TRUE);
+ display = gtk_entry_get_display_text (entry, 0, -1);
+ n_bytes = strlen (display);
+
if (include_preedit)
{
gtk_im_context_get_preedit_string (entry->im_context,
if (preedit_length)
{
- GString *tmp_string = g_string_new (NULL);
+ GString *tmp_string = g_string_new (display);
+ gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
- gint cursor_index = g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text;
-
- if (entry->visible)
- {
- g_string_prepend_len (tmp_string, entry->text, entry->n_bytes);
- g_string_insert (tmp_string, cursor_index, preedit_string);
- }
- else
- {
- gint ch_len;
- gunichar invisible_char;
-
- if (entry->invisible_char != 0)
- invisible_char = entry->invisible_char;
- else
- invisible_char = ' '; /* just pick a char */
-
- ch_len = g_utf8_strlen (entry->text, entry->n_bytes);
- append_char (tmp_string, invisible_char, ch_len);
- cursor_index =
- g_utf8_offset_to_pointer (tmp_string->str, entry->current_pos) -
- tmp_string->str;
- g_string_insert (tmp_string, cursor_index, preedit_string);
- }
+ g_string_insert (tmp_string, cursor_index, preedit_string);
pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
{
PangoDirection pango_dir;
- if (entry->visible)
- pango_dir = pango_find_base_dir (entry->text, entry->n_bytes);
-
+ if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
+ pango_dir = pango_find_base_dir (display, n_bytes);
else
pango_dir = PANGO_DIRECTION_NEUTRAL;
if (pango_dir == PANGO_DIRECTION_NEUTRAL)
{
- if (GTK_WIDGET_HAS_FOCUS (widget))
+ if (gtk_widget_has_focus (widget))
{
GdkDisplay *display = gtk_widget_get_display (widget);
GdkKeymap *keymap = gdk_keymap_get_for_display (display);
pango_dir);
entry->resolved_dir = pango_dir;
-
- if (entry->visible)
- {
- pango_layout_set_text (layout, entry->text, entry->n_bytes);
- }
- else
- {
- GString *str = g_string_new (NULL);
- gunichar invisible_char;
- guint password_hint_timeout;
- GtkEntryPasswordHint *password_hint;
-
- g_object_get (gtk_widget_get_settings (widget),
- "gtk-entry-password-hint-timeout", &password_hint_timeout,
- NULL);
- if (entry->invisible_char != 0)
- invisible_char = entry->invisible_char;
- else
- invisible_char = ' '; /* just pick a char */
-
- password_hint = g_object_get_qdata (G_OBJECT (entry),
- quark_password_hint);
-
- if (password_hint && password_hint->password_hint_timeout_id)
- {
- g_source_remove (password_hint->password_hint_timeout_id);
- password_hint->password_hint_timeout_id = 0;
- }
-
- if (password_hint_timeout == 0 || password_hint == NULL ||
- (password_hint && password_hint->password_hint_length == 0))
- {
- append_char (str, invisible_char, entry->text_length);
- }
- else if (password_hint)
- {
- /* Draw hidden characters upto the inserted position,
- * then the real thing, pad up to full length
- */
- if (password_hint->password_hint_position > 1)
- append_char (str, invisible_char,
- password_hint->password_hint_position - 1);
-
- g_string_append_len (str, password_hint->password_hint,
- password_hint->password_hint_length);
-
- if (password_hint->password_hint_position < entry->text_length)
- append_char (str, invisible_char,
- entry->text_length -
- password_hint->password_hint_position);
-
- /* Now remove this last input character, don't need
- * it anymore
- */
- memset (password_hint->password_hint, 0, PASSWORD_HINT_MAX);
- password_hint->password_hint_length = 0;
-
- password_hint->password_hint_timeout_id =
- gdk_threads_add_timeout (password_hint_timeout,
- (GSourceFunc) gtk_entry_remove_password_hint,
- entry);
- }
-
- pango_layout_set_text (layout, str->str, str->len);
- g_string_free (str, TRUE);
- }
+ pango_layout_set_text (layout, display, n_bytes);
}
pango_layout_set_attributes (layout, tmp_attrs);
g_free (preedit_string);
+ g_free (display);
+
if (preedit_attrs)
pango_attr_list_unref (preedit_attrs);
}
static void
-gtk_entry_draw_text (GtkEntry *entry)
+draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
{
+ PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
GtkWidget *widget;
+ gint x, y;
+ gint start_pos, end_pos;
+
+ widget = GTK_WIDGET (entry);
+
+ cairo_save (cr);
+
+ get_layout_position (entry, &x, &y);
+
+ cairo_move_to (cr, x, y);
+ gdk_cairo_set_source_color (cr, default_color);
+ pango_cairo_show_layout (cr, layout);
+
+ if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
+ {
+ gint *ranges;
+ gint n_ranges, i;
+ PangoRectangle logical_rect;
+ GdkColor *selection_color, *text_color;
+ GtkBorder inner_border;
+
+ pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+ gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
+
+ if (gtk_widget_has_focus (widget))
+ {
+ selection_color = &widget->style->base [GTK_STATE_SELECTED];
+ text_color = &widget->style->text [GTK_STATE_SELECTED];
+ }
+ else
+ {
+ selection_color = &widget->style->base [GTK_STATE_ACTIVE];
+ text_color = &widget->style->text [GTK_STATE_ACTIVE];
+ }
+
+ _gtk_entry_effective_inner_border (entry, &inner_border);
+
+ for (i = 0; i < n_ranges; ++i)
+ cairo_rectangle (cr,
+ inner_border.left - entry->scroll_offset + ranges[2 * i],
+ y,
+ ranges[2 * i + 1],
+ logical_rect.height);
+
+ cairo_clip (cr);
+
+ gdk_cairo_set_source_color (cr, selection_color);
+ cairo_paint (cr);
+
+ cairo_move_to (cr, x, y);
+ gdk_cairo_set_source_color (cr, text_color);
+ pango_cairo_show_layout (cr, layout);
- if (!entry->visible && entry->invisible_char == 0)
+ g_free (ranges);
+ }
+ cairo_restore (cr);
+}
+
+static void
+gtk_entry_draw_text (GtkEntry *entry)
+{
+ GtkWidget *widget = GTK_WIDGET (entry);
+ cairo_t *cr;
+
+ /* Nothing to display at all */
+ if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
return;
- if (GTK_WIDGET_DRAWABLE (entry))
+ if (gtk_widget_is_drawable (widget))
{
- PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
- cairo_t *cr;
- gint x, y;
- gint start_pos, end_pos;
-
- widget = GTK_WIDGET (entry);
-
- get_layout_position (entry, &x, &y);
+ GdkColor text_color, bar_text_color;
+ gint pos_x, pos_y;
+ gint width, height;
+ gint progress_x, progress_y, progress_width, progress_height;
+ GtkStateType state;
- cr = gdk_cairo_create (entry->text_area);
+ state = GTK_STATE_SELECTED;
+ if (!gtk_widget_get_sensitive (widget))
+ state = GTK_STATE_INSENSITIVE;
+ text_color = widget->style->text[widget->state];
+ bar_text_color = widget->style->fg[state];
- cairo_move_to (cr, x, y);
- gdk_cairo_set_source_color (cr, &widget->style->text [widget->state]);
- pango_cairo_show_layout (cr, layout);
+ get_progress_area (widget,
+ &progress_x, &progress_y,
+ &progress_width, &progress_height);
- if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
- {
- gint *ranges;
- gint n_ranges, i;
- PangoRectangle logical_rect;
- GdkColor *selection_color, *text_color;
- GtkBorder inner_border;
+ cr = gdk_cairo_create (entry->text_area);
- pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
- gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
+ /* If the color is the same, or the progress area has a zero
+ * size, then we only need to draw once. */
+ if ((text_color.pixel == bar_text_color.pixel) ||
+ ((progress_width == 0) || (progress_height == 0)))
+ {
+ draw_text_with_color (entry, cr, &text_color);
+ }
+ else
+ {
+ gdk_drawable_get_size (entry->text_area, &width, &height);
- if (GTK_WIDGET_HAS_FOCUS (entry))
- {
- selection_color = &widget->style->base [GTK_STATE_SELECTED];
- text_color = &widget->style->text [GTK_STATE_SELECTED];
- }
- else
- {
- selection_color = &widget->style->base [GTK_STATE_ACTIVE];
- text_color = &widget->style->text [GTK_STATE_ACTIVE];
- }
+ cairo_rectangle (cr, 0, 0, width, height);
+ cairo_clip (cr);
+ cairo_save (cr);
- _gtk_entry_effective_inner_border (entry, &inner_border);
+ cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+ cairo_rectangle (cr, 0, 0, width, height);
- for (i = 0; i < n_ranges; ++i)
- cairo_rectangle (cr,
- inner_border.left - entry->scroll_offset + ranges[2 * i],
- y,
- ranges[2 * i + 1],
- logical_rect.height);
+ gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
+ progress_x -= pos_x;
+ progress_y -= pos_y;
- cairo_clip (cr);
-
- gdk_cairo_set_source_color (cr, selection_color);
- cairo_paint (cr);
+ cairo_rectangle (cr, progress_x, progress_y,
+ progress_width, progress_height);
+ cairo_clip (cr);
+ cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
+
+ draw_text_with_color (entry, cr, &text_color);
+ cairo_restore (cr);
- cairo_move_to (cr, x, y);
- gdk_cairo_set_source_color (cr, text_color);
- pango_cairo_show_layout (cr, layout);
-
- g_free (ranges);
- }
+ cairo_rectangle (cr, progress_x, progress_y,
+ progress_width, progress_height);
+ cairo_clip (cr);
+
+ draw_text_with_color (entry, cr, &bar_text_color);
+ }
cairo_destroy (cr);
}
gtk_entry_draw_cursor (GtkEntry *entry,
CursorType type)
{
+ GtkWidget *widget = GTK_WIDGET (entry);
GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
- if (GTK_WIDGET_DRAWABLE (entry))
+ if (gtk_widget_is_drawable (widget))
{
- GtkWidget *widget = GTK_WIDGET (entry);
GdkRectangle cursor_location;
gboolean split_cursor;
PangoRectangle cursor_rect;
static void
gtk_entry_queue_draw (GtkEntry *entry)
{
- if (GTK_WIDGET_DRAWABLE (entry))
+ if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
}
}
}
+/**
+ * gtk_entry_reset_im_context:
+ * @entry: a #GtkEntry
+ *
+ * Reset the input method context of the entry if needed.
+ *
+ * This can be necessary in the case where modifying the buffer
+ * would confuse on-going input method behavior.
+ *
+ * Since: 2.22
+ */
+void
+gtk_entry_reset_im_context (GtkEntry *entry)
+{
+ g_return_if_fail (GTK_IS_ENTRY (entry));
+
+ _gtk_entry_reset_im_context (entry);
+}
+
+/**
+ * gtk_entry_im_context_filter_keypress:
+ * @entry: a #GtkEntry
+ * @event: the key event
+ *
+ * Allow the #GtkEntry input method to internally handle key press
+ * and release events. If this function returns %TRUE, then no further
+ * processing should be done for this key event. See
+ * gtk_im_context_filter_keypress().
+ *
+ * Note that you are expected to call this function from your handler
+ * when overriding key event handling. This is needed in the case when
+ * you need to insert your own key handling between the input method
+ * and the default key event handling of the #GtkEntry.
+ * See gtk_text_view_reset_im_context() for an example of use.
+ *
+ * Return value: %TRUE if the input method handled the key event.
+ *
+ * Since: 2.22
+ */
+gboolean
+gtk_entry_im_context_filter_keypress (GtkEntry *entry,
+ GdkEventKey *event)
+{
+ g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
+
+ return gtk_im_context_filter_keypress (entry->im_context, event);
+}
+
+
static gint
gtk_entry_find_position (GtkEntry *entry,
gint x)
gint *strong_x,
gint *weak_x)
{
- if (!entry->visible && !entry->invisible_char)
+ DisplayMode mode = gtk_entry_get_display_mode (entry);
+
+ /* Nothing to display at all, so no cursor is relevant */
+ if (mode == DISPLAY_BLANK)
{
if (strong_x)
*strong_x = 0;
if (entry->dnd_position > entry->current_pos)
{
- if (entry->visible)
+ if (mode == DISPLAY_NORMAL)
index += entry->preedit_length;
else
{
- gint preedit_len_chars = g_utf8_strlen (text, -1) - entry->text_length;
+ gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
}
}
PangoLayoutLine *line;
PangoRectangle logical_rect;
- if (!GTK_WIDGET_REALIZED (entry))
+ if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
return;
_gtk_entry_effective_inner_border (entry, &inner_border);
gint count)
{
gint new_pos = start;
+ guint length;
+
+ length = gtk_entry_buffer_get_length (get_buffer (entry));
/* Prevent any leak of information */
- if (!entry->visible)
+ if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
{
- new_pos = CLAMP (start + count, 0, entry->text_length);
+ new_pos = CLAMP (start + count, 0, length);
}
- else if (entry->text)
+ else
{
PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
PangoLogAttr *log_attrs;
pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
- while (count > 0 && new_pos < entry->text_length)
+ while (count > 0 && new_pos < length)
{
do
new_pos++;
- while (new_pos < entry->text_length && !log_attrs[new_pos].is_cursor_position);
+ while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
count--;
}
gboolean allow_whitespace)
{
gint new_pos = start;
+ guint length;
+
+ length = gtk_entry_buffer_get_length (get_buffer (entry));
/* Prevent any leak of information */
- if (!entry->visible)
+ if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
{
- new_pos = entry->text_length;
+ new_pos = length;
}
- else if (entry->text && (new_pos < entry->text_length))
+ else if (new_pos < length)
{
PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
PangoLogAttr *log_attrs;
gint new_pos = start;
/* Prevent any leak of information */
- if (!entry->visible)
+ if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
{
new_pos = 0;
}
- else if (entry->text && start > 0)
+ else if (start > 0)
{
PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
PangoLogAttr *log_attrs;
gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
}
-/*
- * Like gtk_editable_get_chars, but handle not-visible entries
- * correctly.
- */
-static char *
-gtk_entry_get_public_chars (GtkEntry *entry,
- gint start,
- gint end)
-{
- if (end < 0)
- end = entry->text_length;
-
- if (entry->visible)
- return gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
- else if (!entry->invisible_char)
- return g_strdup ("");
- else
- {
- GString *str = g_string_new (NULL);
- append_char (str, entry->invisible_char, end - start);
- return g_string_free (str, FALSE);
- }
-}
-
static gint
truncate_multiline (const gchar *text)
{
length = truncate_multiline (text);
/* only complete if the selection is at the end */
- popup_completion = (entry->text_length == MAX (entry->current_pos, entry->selection_bound));
+ popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
+ MAX (entry->current_pos, entry->selection_bound));
if (completion)
{
- if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
+ if (gtk_widget_get_mapped (completion->priv->popup_window))
_gtk_entry_completion_popdown (completion);
if (!popup_completion && completion->priv->changed_id > 0)
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
{
- gchar *str = gtk_entry_get_public_chars (entry, start, end);
+ gchar *str = gtk_entry_get_display_text (entry, start, end);
gtk_selection_data_set_text (selection_data, str, -1);
g_free (str);
}
gint start, end;
gint n_targets;
- if (!GTK_WIDGET_REALIZED (entry))
+ if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
return;
list = gtk_target_list_new (NULL, 0);
{
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
EntryIconInfo *icon_info = priv->icons[icon_pos];
- GdkScreen *screen;
+ GtkIconInfo *info;
GtkIconTheme *icon_theme;
GtkSettings *settings;
+ GtkStateType state;
+ GtkWidget *widget;
+ GdkScreen *screen;
gint width, height;
- GtkIconInfo *info;
if (!icon_info || icon_info->pixbuf)
return;
+ widget = GTK_WIDGET (entry);
+
switch (icon_info->storage_type)
{
case GTK_IMAGE_EMPTY:
case GTK_IMAGE_PIXBUF:
break;
case GTK_IMAGE_STOCK:
- icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
+ state = gtk_widget_get_state (widget);
+ gtk_widget_set_state (widget, GTK_STATE_NORMAL);
+ icon_info->pixbuf = gtk_widget_render_icon (widget,
icon_info->stock_id,
GTK_ICON_SIZE_MENU,
NULL);
+ if (!icon_info->pixbuf)
+ icon_info->pixbuf = gtk_widget_render_icon (widget,
+ GTK_STOCK_MISSING_IMAGE,
+ GTK_ICON_SIZE_MENU,
+ NULL);
+ gtk_widget_set_state (widget, state);
break;
case GTK_IMAGE_ICON_NAME:
- screen = gtk_widget_get_screen (GTK_WIDGET (entry));
+ screen = gtk_widget_get_screen (widget);
if (screen)
{
icon_theme = gtk_icon_theme_get_for_screen (screen);
0, NULL);
if (icon_info->pixbuf == NULL)
- icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
- GTK_STOCK_MISSING_IMAGE,
- GTK_ICON_SIZE_MENU,
- NULL);
+ {
+ state = gtk_widget_get_state (widget);
+ gtk_widget_set_state (widget, GTK_STATE_NORMAL);
+ icon_info->pixbuf = gtk_widget_render_icon (widget,
+ GTK_STOCK_MISSING_IMAGE,
+ GTK_ICON_SIZE_MENU,
+ NULL);
+ gtk_widget_set_state (widget, state);
+ }
}
break;
case GTK_IMAGE_GICON:
- screen = gtk_widget_get_screen (GTK_WIDGET (entry));
+ screen = gtk_widget_get_screen (widget);
if (screen)
{
icon_theme = gtk_icon_theme_get_for_screen (screen);
}
if (icon_info->pixbuf == NULL)
- icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
- GTK_STOCK_MISSING_IMAGE,
- GTK_ICON_SIZE_MENU,
- NULL);
+ {
+ state = gtk_widget_get_state (widget);
+ gtk_widget_set_state (widget, GTK_STATE_NORMAL);
+ icon_info->pixbuf = gtk_widget_render_icon (widget,
+ GTK_STOCK_MISSING_IMAGE,
+ GTK_ICON_SIZE_MENU,
+ NULL);
+ gtk_widget_set_state (widget, state);
+ }
}
break;
break;
}
- if (icon_info->pixbuf != NULL)
+ if (icon_info->pixbuf != NULL && icon_info->window != NULL)
gdk_window_show_unraised (icon_info->window);
}
}
/**
- * gtk_entry_new_with_max_length:
- * @max: the maximum length of the entry, or 0 for no maximum.
- * (other than the maximum length of entries.) The value passed in will
- * be clamped to the range 0-65536.
+ * gtk_entry_new_with_buffer:
+ * @buffer: The buffer to use for the new #GtkEntry.
+ *
+ * Creates a new entry with the specified text buffer.
*
- * Creates a new #GtkEntry widget with the given maximum length.
- *
* Return value: a new #GtkEntry
*
- * Deprecated: Use gtk_entry_set_max_length() instead.
- **/
+ * Since: 2.18
+ */
GtkWidget*
-gtk_entry_new_with_max_length (gint max)
+gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
{
- GtkEntry *entry;
+ g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
+ return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
+}
- max = CLAMP (max, 0, MAX_SIZE);
+static GtkEntryBuffer*
+get_buffer (GtkEntry *entry)
+{
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
- entry = g_object_new (GTK_TYPE_ENTRY, NULL);
- entry->text_max_length = max;
+ if (priv->buffer == NULL)
+ {
+ GtkEntryBuffer *buffer;
+ buffer = gtk_entry_buffer_new (NULL, 0);
+ gtk_entry_set_buffer (entry, buffer);
+ g_object_unref (buffer);
+ }
- return GTK_WIDGET (entry);
+ return priv->buffer;
}
/**
- * gtk_entry_set_text:
+ * gtk_entry_get_buffer:
* @entry: a #GtkEntry
- * @text: the new text
*
- * Sets the text in the widget to the given
- * value, replacing the current contents.
+ * Get the #GtkEntryBuffer object which holds the text for
+ * this widget.
+ *
+ * Since: 2.18
+ *
+ * Returns: A #GtkEntryBuffer object.
*/
-void
-gtk_entry_set_text (GtkEntry *entry,
- const gchar *text)
+GtkEntryBuffer*
+gtk_entry_get_buffer (GtkEntry *entry)
{
- gint tmp_pos;
- GtkEntryCompletion *completion;
-
- g_return_if_fail (GTK_IS_ENTRY (entry));
- g_return_if_fail (text != NULL);
-
- /* Actually setting the text will affect the cursor and selection;
- * if the contents don't actually change, this will look odd to the user.
- */
- if (strcmp (entry->text, text) == 0)
- return;
-
- completion = gtk_entry_get_completion (entry);
- if (completion && completion->priv->changed_id > 0)
- g_signal_handler_block (entry, completion->priv->changed_id);
-
- begin_change (entry);
- g_object_freeze_notify (G_OBJECT (entry));
- gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
-
- tmp_pos = 0;
- gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
- g_object_thaw_notify (G_OBJECT (entry));
- end_change (entry);
+ g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
- if (completion && completion->priv->changed_id > 0)
- g_signal_handler_unblock (entry, completion->priv->changed_id);
+ return get_buffer (entry);
}
/**
- * gtk_entry_append_text:
+ * gtk_entry_set_buffer:
* @entry: a #GtkEntry
- * @text: the text to append
+ * @buffer: a #GtkEntryBuffer
*
- * Appends the given text to the contents of the widget.
+ * Set the #GtkEntryBuffer object which holds the text for
+ * this widget.
*
- * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
+ * Since: 2.18
*/
void
-gtk_entry_append_text (GtkEntry *entry,
- const gchar *text)
+gtk_entry_set_buffer (GtkEntry *entry,
+ GtkEntryBuffer *buffer)
{
- gint tmp_pos;
+ GtkEntryPrivate *priv;
+ GObject *obj;
g_return_if_fail (GTK_IS_ENTRY (entry));
- g_return_if_fail (text != NULL);
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
+
+ if (buffer)
+ {
+ g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
+ g_object_ref (buffer);
+ }
+
+ if (priv->buffer)
+ {
+ buffer_disconnect_signals (entry);
+ g_object_unref (priv->buffer);
+
+ /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
+ entry->text = NULL;
+ entry->text_length = 0;
+ entry->text_max_length = 0;
+ }
+
+ priv->buffer = buffer;
- tmp_pos = entry->text_length;
- gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
+ if (priv->buffer)
+ {
+ buffer_connect_signals (entry);
+
+ /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
+ entry->text = (char*)gtk_entry_buffer_get_text (priv->buffer);
+ entry->text_length = gtk_entry_buffer_get_length (priv->buffer);
+ entry->text_max_length = gtk_entry_buffer_get_max_length (priv->buffer);
+ }
+
+ obj = G_OBJECT (entry);
+ g_object_freeze_notify (obj);
+ g_object_notify (obj, "buffer");
+ g_object_notify (obj, "text");
+ g_object_notify (obj, "text-length");
+ g_object_notify (obj, "max-length");
+ g_object_notify (obj, "visibility");
+ g_object_notify (obj, "invisible-char");
+ g_object_notify (obj, "invisible-char-set");
+ g_object_thaw_notify (obj);
+
+ gtk_editable_set_position (GTK_EDITABLE (entry), 0);
+ gtk_entry_recompute (entry);
}
/**
- * gtk_entry_prepend_text:
+ * gtk_entry_get_text_window:
* @entry: a #GtkEntry
- * @text: the text to prepend
*
- * Prepends the given text to the contents of the widget.
+ * Returns the #GdkWindow which contains the text. This function is
+ * useful when drawing something to the entry in an expose-event
+ * callback because it enables the callback to distinguish between
+ * the text window and entry's icon windows.
*
- * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
- */
-void
-gtk_entry_prepend_text (GtkEntry *entry,
- const gchar *text)
+ * See also gtk_entry_get_icon_window().
+ *
+ * Return value: the entry's text window.
+ *
+ * Since: 2.20
+ **/
+GdkWindow *
+gtk_entry_get_text_window (GtkEntry *entry)
{
- gint tmp_pos;
-
- g_return_if_fail (GTK_IS_ENTRY (entry));
- g_return_if_fail (text != NULL);
+ g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
- tmp_pos = 0;
- gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
+ return entry->text_area;
}
+
/**
- * gtk_entry_set_position:
+ * gtk_entry_set_text:
* @entry: a #GtkEntry
- * @position: the position of the cursor. The cursor is displayed
- * before the character with the given (base 0) index in the widget.
- * The value must be less than or equal to the number of characters
- * in the widget. A value of -1 indicates that the position should
- * be set after the last character in the entry. Note that this
- * position is in characters, not in bytes.
+ * @text: the new text
*
- * Sets the cursor position in an entry to the given value.
+ * Sets the text in the widget to the given
+ * value, replacing the current contents.
*
- * Deprecated: 2.0: Use gtk_editable_set_position() instead.
+ * See gtk_entry_buffer_set_text().
*/
void
-gtk_entry_set_position (GtkEntry *entry,
- gint position)
+gtk_entry_set_text (GtkEntry *entry,
+ const gchar *text)
{
+ gint tmp_pos;
+ GtkEntryCompletion *completion;
+ GtkEntryPrivate *priv;
+
g_return_if_fail (GTK_IS_ENTRY (entry));
+ g_return_if_fail (text != NULL);
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
+
+ /* Actually setting the text will affect the cursor and selection;
+ * if the contents don't actually change, this will look odd to the user.
+ */
+ if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
+ return;
- gtk_editable_set_position (GTK_EDITABLE (entry), position);
+ completion = gtk_entry_get_completion (entry);
+ if (completion && completion->priv->changed_id > 0)
+ g_signal_handler_block (entry, completion->priv->changed_id);
+
+ begin_change (entry);
+ g_object_freeze_notify (G_OBJECT (entry));
+ gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
+ tmp_pos = 0;
+ gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
+ g_object_thaw_notify (G_OBJECT (entry));
+ end_change (entry);
+
+ if (completion && completion->priv->changed_id > 0)
+ g_signal_handler_unblock (entry, completion->priv->changed_id);
}
/**
gtk_entry_recompute (entry);
}
-/**
- * gtk_entry_set_editable:
- * @entry: a #GtkEntry
- * @editable: %TRUE if the user is allowed to edit the text
- * in the widget
- *
- * Determines if the user can edit the text in the editable
- * widget or not.
- *
- * Deprecated: 2.0: Use gtk_editable_set_editable() instead.
- */
-void
-gtk_entry_set_editable (GtkEntry *entry,
- gboolean editable)
-{
- g_return_if_fail (GTK_IS_ENTRY (entry));
-
- gtk_editable_set_editable (GTK_EDITABLE (entry), editable);
-}
-
/**
* gtk_entry_set_overwrite_mode:
* @entry: a #GtkEntry
* Retrieves the contents of the entry widget.
* See also gtk_editable_get_chars().
*
+ * This is equivalent to:
+ *
+ * <informalexample><programlisting>
+ * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
+ * </programlisting></informalexample>
+ *
* Return value: a pointer to the contents of the widget as a
* string. This string points to internally allocated
* storage in the widget and must not be freed, modified or
gtk_entry_get_text (GtkEntry *entry)
{
g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
-
- return entry->text;
-}
-
-/**
- * gtk_entry_select_region:
- * @entry: a #GtkEntry
- * @start: the starting position
- * @end: the end position
- *
- * Selects a region of text. The characters that are selected are
- * those characters at positions from @start_pos up to, but not
- * including @end_pos. If @end_pos is negative, then the the characters
- * selected will be those characters from @start_pos to the end of
- * the text.
- *
- * Deprecated: 2.0: Use gtk_editable_select_region() instead.
- */
-void
-gtk_entry_select_region (GtkEntry *entry,
- gint start,
- gint end)
-{
- gtk_editable_select_region (GTK_EDITABLE (entry), start, end);
+ return gtk_entry_buffer_get_text (get_buffer (entry));
}
/**
* Sets the maximum allowed length of the contents of the widget. If
* the current contents are longer than the given length, then they
* will be truncated to fit.
+ *
+ * This is equivalent to:
+ *
+ * <informalexample><programlisting>
+ * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
+ * </programlisting></informalexample>
**/
void
gtk_entry_set_max_length (GtkEntry *entry,
gint max)
{
g_return_if_fail (GTK_IS_ENTRY (entry));
-
- max = CLAMP (max, 0, MAX_SIZE);
-
- if (max > 0 && entry->text_length > max)
- gtk_editable_delete_text (GTK_EDITABLE (entry), max, -1);
-
- entry->text_max_length = max;
- g_object_notify (G_OBJECT (entry), "max-length");
+ gtk_entry_buffer_set_max_length (get_buffer (entry), max);
}
/**
* Retrieves the maximum allowed length of the text in
* @entry. See gtk_entry_set_max_length().
*
+ * This is equivalent to:
+ *
+ * <informalexample><programlisting>
+ * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
+ * </programlisting></informalexample>
+ *
* Return value: the maximum allowed number of characters
* in #GtkEntry, or 0 if there is no maximum.
**/
gtk_entry_get_max_length (GtkEntry *entry)
{
g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
-
- return entry->text_max_length;
+ return gtk_entry_buffer_get_max_length (get_buffer (entry));
}
/**
* Retrieves the current length of the text in
* @entry.
*
+ * This is equivalent to:
+ *
+ * <informalexample><programlisting>
+ * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
+ * </programlisting></informalexample>
+ *
* Return value: the current number of characters
* in #GtkEntry, or 0 if there are none.
*
gtk_entry_get_text_length (GtkEntry *entry)
{
g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
-
- return entry->text_length;
+ return gtk_entry_buffer_get_length (get_buffer (entry));
}
/**
/**
* gtk_entry_set_inner_border:
* @entry: a #GtkEntry
- * @border: a #GtkBorder, or %NULL
+ * @border: (allow-none): a #GtkBorder, or %NULL
*
* Sets %entry's inner-border property to %border, or clears it if %NULL
* is passed. The inner-border is the area around the entry's text, but
* This function returns the entry's #GtkEntry:inner-border property. See
* gtk_entry_set_inner_border() for more information.
*
- * Return value: the entry's #GtkBorder, or %NULL if none was set.
+ * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
*
* Since: 2.10
**/
* gtk_entry_layout_index_to_text_index() and
* gtk_entry_text_index_to_layout_index() are needed to convert byte
* indices in the layout to byte indices in the entry contents.
- *
- * Return value: the #PangoLayout for this entry
+ *
+ * Return value: (transfer none): the #PangoLayout for this entry
**/
PangoLayout*
gtk_entry_get_layout (GtkEntry *entry)
/**
* gtk_entry_get_layout_offsets:
* @entry: a #GtkEntry
- * @x: location to store X offset of layout, or %NULL
- * @y: location to store Y offset of layout, or %NULL
+ * @x: (allow-none): location to store X offset of layout, or %NULL
+ * @y: (allow-none): location to store Y offset of layout, or %NULL
*
*
* Obtains the position of the #PangoLayout used to render text
* gtk_entry_set_icon_from_pixbuf:
* @entry: a #GtkEntry
* @icon_pos: Icon position
- * @pixbuf: A #GdkPixbuf, or %NULL
+ * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
*
* Sets the icon shown in the specified position using a pixbuf.
*
g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
}
+
+ if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
+ gdk_window_show_unraised (icon_info->window);
}
gtk_entry_ensure_pixbuf (entry, icon_pos);
- if (GTK_WIDGET_VISIBLE (entry))
+ if (gtk_widget_get_visible (GTK_WIDGET (entry)))
gtk_widget_queue_resize (GTK_WIDGET (entry));
g_object_thaw_notify (G_OBJECT (entry));
* gtk_entry_set_icon_from_stock:
* @entry: A #GtkEntry
* @icon_pos: Icon position
- * @stock_id: The name of the stock item, or %NULL
+ * @stock_id: (allow-none): The name of the stock item, or %NULL
*
* Sets the icon shown in the entry at the specified position from
* a stock image.
g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
}
+
+ if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
+ gdk_window_show_unraised (icon_info->window);
}
gtk_entry_ensure_pixbuf (entry, icon_pos);
- if (GTK_WIDGET_VISIBLE (entry))
+ if (gtk_widget_get_visible (GTK_WIDGET (entry)))
gtk_widget_queue_resize (GTK_WIDGET (entry));
g_object_thaw_notify (G_OBJECT (entry));
* gtk_entry_set_icon_from_icon_name:
* @entry: A #GtkEntry
* @icon_pos: The position at which to set the icon
- * @icon_name: An icon name, or %NULL
+ * @icon_name: (allow-none): An icon name, or %NULL
*
* Sets the icon shown in the entry at the specified position
* from the current icon theme.
g_object_notify (G_OBJECT (entry), "secondary-icon-name");
g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
}
+
+ if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
+ gdk_window_show_unraised (icon_info->window);
}
gtk_entry_ensure_pixbuf (entry, icon_pos);
- if (GTK_WIDGET_VISIBLE (entry))
+ if (gtk_widget_get_visible (GTK_WIDGET (entry)))
gtk_widget_queue_resize (GTK_WIDGET (entry));
g_object_thaw_notify (G_OBJECT (entry));
* gtk_entry_set_icon_from_gicon:
* @entry: A #GtkEntry
* @icon_pos: The position at which to set the icon
- * @icon: The icon to set, or %NULL
+ * @icon: (allow-none): The icon to set, or %NULL
*
* Sets the icon shown in the entry at the specified position
* from the current icon theme.
g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
}
+
+ if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
+ gdk_window_show_unraised (icon_info->window);
}
gtk_entry_ensure_pixbuf (entry, icon_pos);
- if (GTK_WIDGET_VISIBLE (entry))
+ if (gtk_widget_get_visible (GTK_WIDGET (entry)))
gtk_widget_queue_resize (GTK_WIDGET (entry));
g_object_thaw_notify (G_OBJECT (entry));
{
icon_info->nonactivatable = !activatable;
- if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
+ if (gtk_widget_get_realized (GTK_WIDGET (entry)))
update_cursors (GTK_WIDGET (entry));
g_object_notify (G_OBJECT (entry),
{
icon_info->insensitive = !sensitive;
- if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
+ icon_info->pressed = FALSE;
+ icon_info->prelight = FALSE;
+
+ if (gtk_widget_get_realized (GTK_WIDGET (entry)))
update_cursors (GTK_WIDGET (entry));
+ gtk_widget_queue_draw (GTK_WIDGET (entry));
+
g_object_notify (G_OBJECT (entry),
icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
}
* #GtkWidget::drag-begin signal to set a different icon. Note that you
* have to use g_signal_connect_after() to ensure that your signal handler
* gets executed after the default handler.
+ *
+ * Since: 2.16
*/
void
gtk_entry_set_icon_drag_source (GtkEntry *entry,
*
* Returns: index of the icon which is the source of the current
* DND operation, or -1.
+ *
+ * Since: 2.16
*/
gint
gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
return -1;
}
+/**
+ * gtk_entry_get_icon_window:
+ * @entry: A #GtkEntry
+ * @icon_pos: Icon position
+ *
+ * Returns the #GdkWindow which contains the entry's icon at
+ * @icon_pos. This function is useful when drawing something to the
+ * entry in an expose-event callback because it enables the callback
+ * to distinguish between the text window and entry's icon windows.
+ *
+ * See also gtk_entry_get_text_window().
+ *
+ * Return value: the entry's icon window at @icon_pos.
+ *
+ * Since: 2.20
+ */
+GdkWindow *
+gtk_entry_get_icon_window (GtkEntry *entry,
+ GtkEntryIconPosition icon_pos)
+{
+ GtkEntryPrivate *priv;
+ EntryIconInfo *icon_info;
+
+ g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
+
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
+
+ icon_info = priv->icons[icon_pos];
+
+ if (icon_info)
+ return icon_info->window;
+
+ return NULL;
+}
+
static void
ensure_has_tooltip (GtkEntry *entry)
{
* gtk_entry_set_icon_tooltip_text:
* @entry: a #GtkEntry
* @icon_pos: the icon position
- * @tooltip: the contents of the tooltip for the icon, or %NULL
+ * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
*
* Sets @tooltip as the contents of the tooltip for the icon
* at the specified position.
{
GtkEntryPrivate *priv;
EntryIconInfo *icon_info;
- gchar *text = NULL;
g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
* gtk_entry_set_icon_tooltip_markup:
* @entry: a #GtkEntry
* @icon_pos: the icon position
- * @tooltip: the contents of the tooltip for the icon, or %NULL
+ * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
*
* Sets @tooltip as the contents of the tooltip for the icon at
* the specified position. @tooltip is assumed to be marked up with
GtkBorder inner_border;
gint monitor_num, strong_x, height;
- g_return_if_fail (GTK_WIDGET_REALIZED (entry));
+ g_return_if_fail (gtk_widget_get_realized (widget));
gdk_window_get_origin (entry->text_area, x, y);
PopupInfo *info = user_data;
GtkEntry *entry = info->entry;
- if (GTK_WIDGET_REALIZED (entry))
+ if (gtk_widget_get_realized (GTK_WIDGET (entry)))
{
+ DisplayMode mode;
gboolean clipboard_contains_text;
GtkWidget *menuitem;
GtkWidget *submenu;
GTK_WIDGET (entry),
popup_menu_detach);
+ mode = gtk_entry_get_display_mode (entry);
append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
- entry->editable && entry->visible && entry->current_pos != entry->selection_bound);
+ entry->editable && mode == DISPLAY_NORMAL &&
+ entry->current_pos != entry->selection_bound);
+
append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
- entry->visible && entry->current_pos != entry->selection_bound);
+ mode == DISPLAY_NORMAL &&
+ entry->current_pos != entry->selection_bound);
+
append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
entry->editable && clipboard_contains_text);
-
+
menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
g_signal_connect_swapped (menuitem, "activate",
if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
{
- gchar *str = gtk_entry_get_public_chars (GTK_ENTRY (widget), sel_start, sel_end);
+ gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
gtk_selection_data_set_text (selection_data, str, -1);
static gboolean
cursor_blinks (GtkEntry *entry)
{
- if (GTK_WIDGET_HAS_FOCUS (entry) &&
+ if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
entry->editable &&
entry->selection_bound == entry->current_pos)
{
static void
show_cursor (GtkEntry *entry)
{
+ GtkWidget *widget;
+
if (!entry->cursor_visible)
{
entry->cursor_visible = TRUE;
- if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
- gtk_widget_queue_draw (GTK_WIDGET (entry));
+ widget = GTK_WIDGET (entry);
+ if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
+ gtk_widget_queue_draw (widget);
}
}
static void
hide_cursor (GtkEntry *entry)
{
+ GtkWidget *widget;
+
if (entry->cursor_visible)
{
entry->cursor_visible = FALSE;
- if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
- gtk_widget_queue_draw (GTK_WIDGET (entry));
+ widget = GTK_WIDGET (entry);
+ if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
+ gtk_widget_queue_draw (widget);
}
}
entry = GTK_ENTRY (data);
priv = GTK_ENTRY_GET_PRIVATE (entry);
- if (!GTK_WIDGET_HAS_FOCUS (entry))
+ if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
{
g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
"connect a handler to this signal, it must return\n"
gtk_entry_completion_timeout (gpointer data)
{
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
completion->priv->completion_timeout = 0;
g_object_get (completion, "popup-single-match", &popup_single, NULL);
if ((matches > (popup_single ? 0: 1)) || actions > 0)
{
- if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
+ if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_resize_popup (completion);
else
- _gtk_entry_completion_popup (completion);
+ _gtk_entry_completion_popup (completion, priv->completion_device);
}
else
_gtk_entry_completion_popdown (completion);
}
- else if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
+ else if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_popdown (completion);
return FALSE;
gint matches, actions = 0;
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
- if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
+ if (!gtk_widget_get_mapped (completion->priv->popup_window))
return FALSE;
matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
{
GtkTreeIter iter;
+ GtkTreeIter child_iter;
GtkTreeModel *model = NULL;
GtkTreeSelection *sel;
gboolean entry_set;
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
if (!gtk_tree_selection_get_selected (sel, &model, &iter))
return FALSE;
+
+ gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
+ model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
if (completion->priv->completion_prefix == NULL)
completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
g_signal_emit_by_name (completion, "cursor-on-match", model,
- &iter, &entry_set);
+ &child_iter, &entry_set);
}
}
else if (completion->priv->current_selected - matches >= 0)
event->keyval == GDK_KP_Enter ||
event->keyval == GDK_Return)
{
+ GtkTreeIter iter;
+ GtkTreeModel *model = NULL;
+ GtkTreeSelection *sel;
gboolean retval = TRUE;
_gtk_entry_reset_im_context (GTK_ENTRY (widget));
if (completion->priv->current_selected < matches)
{
- GtkTreeIter iter;
- GtkTreeModel *model = NULL;
- GtkTreeSelection *sel;
gboolean entry_set;
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
}
else if (completion->priv->current_selected - matches >= 0)
{
- GtkTreePath *path;
-
- _gtk_entry_reset_im_context (GTK_ENTRY (widget));
-
- path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
+ sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
+ if (gtk_tree_selection_get_selected (sel, &model, &iter))
+ {
+ GtkTreePath *path;
- g_signal_emit_by_name (completion, "action-activated",
- gtk_tree_path_get_indices (path)[0]);
- gtk_tree_path_free (path);
+ path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
+ g_signal_emit_by_name (completion, "action-activated",
+ gtk_tree_path_get_indices (path)[0]);
+ gtk_tree_path_free (path);
+ }
+ else
+ retval = FALSE;
}
g_free (completion->priv->completion_prefix);
gtk_entry_completion_changed (GtkWidget *entry,
gpointer user_data)
{
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
+ GdkDevice *device;
/* (re)install completion timeout */
if (completion->priv->completion_timeout)
if (completion->priv->minimum_key_length > 0 &&
strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
{
- if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
+ if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_popdown (completion);
return;
}
+ device = gtk_get_current_event_device ();
+
+ if (device && device->source == GDK_SOURCE_KEYBOARD)
+ device = gdk_device_get_associated_device (device);
+
+ if (device)
+ priv->completion_device = device;
+
completion->priv->completion_timeout =
gdk_threads_add_timeout (COMPLETION_TIMEOUT,
gtk_entry_completion_timeout,
if (completion->priv->has_completion)
gtk_editable_set_position (GTK_EDITABLE (entry),
- entry->text_length);
+ gtk_entry_buffer_get_length (get_buffer (entry)));
return FALSE;
}
/**
* gtk_entry_set_completion:
* @entry: A #GtkEntry
- * @completion: The #GtkEntryCompletion or %NULL
+ * @completion: (allow-none): The #GtkEntryCompletion or %NULL
*
* Sets @completion to be the auxiliary completion object to use with @entry.
* All further configuration of the completion mechanism is done on
old->priv->completion_timeout = 0;
}
- if (GTK_WIDGET_MAPPED (old->priv->popup_window))
+ if (gtk_widget_get_mapped (old->priv->popup_window))
_gtk_entry_completion_popdown (old);
disconnect_completion_signals (entry, old);
* Retrieves the horizontal cursor adjustment for the entry.
* See gtk_entry_set_cursor_hadjustment().
*
- * Return value: the horizontal cursor adjustment, or %NULL
+ * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
* if none has been set.
- *
+ *
* Since: 2.12
*/
GtkAdjustment*
gtk_entry_set_progress_fraction (GtkEntry *entry,
gdouble fraction)
{
+ GtkWidget *widget;
GtkEntryPrivate *private;
gdouble old_fraction;
+ gint x, y, width, height;
+ gint old_x, old_y, old_width, old_height;
g_return_if_fail (GTK_IS_ENTRY (entry));
+ widget = GTK_WIDGET (entry);
private = GTK_ENTRY_GET_PRIVATE (entry);
if (private->progress_pulse_mode)
else
old_fraction = private->progress_fraction;
+ if (gtk_widget_is_drawable (widget))
+ get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
+
fraction = CLAMP (fraction, 0.0, 1.0);
private->progress_fraction = fraction;
private->progress_pulse_mode = FALSE;
private->progress_pulse_current = 0.0;
- if (fabs (fraction - old_fraction) > 0.0001)
- gtk_entry_queue_draw (entry);
+ if (gtk_widget_is_drawable (widget))
+ {
+ get_progress_area (widget, &x, &y, &width, &height);
+
+ if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
+ gtk_widget_queue_draw (widget);
+ }
if (fraction != old_fraction)
g_object_notify (G_OBJECT (entry), "progress-fraction");
{
private->progress_pulse_fraction = fraction;
- gtk_entry_queue_draw (entry);
+ gtk_widget_queue_draw (GTK_WIDGET (entry));
g_object_notify (G_OBJECT (entry), "progress-pulse-step");
}
private->progress_pulse_current = 0.0;
}
- gtk_entry_queue_draw (entry);
+ gtk_widget_queue_draw (GTK_WIDGET (entry));
}
/* Caps Lock warning for password entries */
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
char *text = NULL;
- if (!entry->visible && priv->caps_lock_warning)
+ if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
{
- if (gdk_keymap_get_caps_lock_state (keymap))
- text = _("You have the Caps Lock key on");
+ if (gdk_keymap_get_num_lock_state (keymap)
+ && gdk_keymap_get_caps_lock_state (keymap))
+ text = _("Caps Lock and Num Lock are on");
+ else if (gdk_keymap_get_num_lock_state (keymap))
+ text = _("Num Lock is on");
+ else if (gdk_keymap_get_caps_lock_state (keymap))
+ text = _("Caps Lock is on");
}
if (text)