static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
static GQuark quark_inner_border = 0;
static GQuark quark_password_hint = 0;
+static GQuark quark_cursor_hadjustment = 0;
typedef struct _GtkEntryPrivate GtkEntryPrivate;
{
gfloat xalign;
gint insert_pos;
+ guint blink_time; /* time in msec the cursor has blinked since last user event */
+ guint interior_focus : 1;
+ guint real_changed : 1;
+ guint change_count : 8;
+
+ gint focus_width;
+ GtkShadowType shadow_type;
};
typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
PROP_SCROLL_OFFSET,
PROP_TEXT,
PROP_XALIGN,
- PROP_TRUNCATE_MULTILINE
+ PROP_TRUNCATE_MULTILINE,
+ PROP_SHADOW_TYPE
};
static guint signals[LAST_SIGNAL] = { 0 };
GtkRequisition *requisition);
static void gtk_entry_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static void gtk_entry_draw_frame (GtkWidget *widget);
+static void gtk_entry_draw_frame (GtkWidget *widget,
+ GdkRectangle *area);
static gint gtk_entry_expose (GtkWidget *widget,
GdkEventExpose *event);
static gint gtk_entry_button_press (GtkWidget *widget,
gboolean include_preedit);
static void gtk_entry_reset_layout (GtkEntry *entry);
static void gtk_entry_queue_draw (GtkEntry *entry);
-static void gtk_entry_reset_im_context (GtkEntry *entry);
static void gtk_entry_recompute (GtkEntry *entry);
static gint gtk_entry_find_position (GtkEntry *entry,
gint x);
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);
static void get_text_area_size (GtkEntry *entry,
gint *x,
gint *y,
gint *y,
gint *width,
gint *height);
-static void get_inner_border (GtkEntry *entry,
- GtkBorder *border);
+static void gtk_entry_move_adjustments (GtkEntry *entry);
/* Completion */
static gint gtk_entry_completion_timeout (gpointer data);
static void connect_completion_signals (GtkEntry *entry,
GtkEntryCompletion *completion);
+static void begin_change (GtkEntry *entry);
+static void end_change (GtkEntry *entry);
+static void emit_changed (GtkEntry *entry);
G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
+ quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
g_object_class_install_property (gobject_class,
PROP_CURSOR_POSITION,
FALSE,
GTK_PARAM_READWRITE));
+ /**
+ * GtkEntry:shadow-type:
+ *
+ * Which kind of shadow to draw around the entry when
+ * #GtkEntry:has-frame is set to %TRUE.
+ *
+ * Since: 2.12
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_SHADOW_TYPE,
+ g_param_spec_enum ("shadow-type",
+ P_("Shadow type"),
+ P_("Which kind of shadow to draw around the entry when has-frame is set"),
+ GTK_TYPE_SHADOW_TYPE,
+ GTK_SHADOW_IN,
+ GTK_PARAM_READWRITE));
+
signals[POPULATE_POPUP] =
g_signal_new (I_("populate_popup"),
G_OBJECT_CLASS_TYPE (gobject_class),
/**
* GtkEntry:inner-border:
*
- * Sets the text area's border between the text and the frame
+ * Sets the text area's border between the text and the frame.
*
* Since: 2.10
*/
/**
* GtkSettings:gtk-entry-password-hint-timeout:
*
- * How long to show the last inputted character in hidden
+ * How long to show the last input character in hidden
* entries. This value is in milliseconds. 0 disables showing the
* last char. 600 is a good value for enabling it.
*
*/
gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
P_("Password Hint Timeout"),
- P_("How long to show the last inputted character in hidden entries"),
+ P_("How long to show the last input character in hidden entries"),
0, G_MAXUINT, 0,
GTK_PARAM_READWRITE));
const GValue *value,
GParamSpec *pspec)
{
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
GtkEntry *entry = GTK_ENTRY (object);
switch (prop_id)
{
if (!new_value)
{
- gtk_entry_reset_im_context (entry);
+ _gtk_entry_reset_im_context (entry);
if (GTK_WIDGET_HAS_FOCUS (entry))
gtk_im_context_focus_out (entry->im_context);
entry->truncate_multiline = g_value_get_boolean (value);
break;
+ case PROP_SHADOW_TYPE:
+ priv->shadow_type = g_value_get_enum (value);
+ break;
+
case PROP_SCROLL_OFFSET:
case PROP_CURSOR_POSITION:
default:
GValue *value,
GParamSpec *pspec)
{
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
GtkEntry *entry = GTK_ENTRY (object);
switch (prop_id)
case PROP_TRUNCATE_MULTILINE:
g_value_set_boolean (value, entry->truncate_multiline);
break;
+ case PROP_SHADOW_TYPE:
+ g_value_set_enum (value, priv->shadow_type);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
entry->editing_canceled = FALSE;
entry->has_frame = TRUE;
entry->truncate_multiline = FALSE;
+ priv->shadow_type = GTK_SHADOW_IN;
priv->xalign = 0.0;
gtk_drag_dest_set (GTK_WIDGET (entry),
G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
}
+static void
+begin_change (GtkEntry *entry)
+{
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+
+ priv->change_count++;
+}
+
+static void
+end_change (GtkEntry *entry)
+{
+ GtkEditable *editable = GTK_EDITABLE (entry);
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+
+ g_return_if_fail (priv->change_count > 0);
+
+ priv->change_count--;
+
+ if (priv->change_count == 0)
+ {
+ if (priv->real_changed)
+ {
+ g_signal_emit_by_name (editable, "changed");
+ priv->real_changed = FALSE;
+ }
+ }
+}
+
+static void
+emit_changed (GtkEntry *entry)
+{
+ GtkEditable *editable = GTK_EDITABLE (entry);
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+
+ if (priv->change_count == 0)
+ g_signal_emit_by_name (editable, "changed");
+ else
+ priv->real_changed = TRUE;
+}
+
/*
* Overwrite a memory that might contain sensitive information.
*/
entry->n_bytes = 0;
entry->current_pos = entry->selection_bound = entry->text_length = 0;
- gtk_entry_reset_im_context (entry);
+ _gtk_entry_reset_im_context (entry);
gtk_entry_reset_layout (entry);
if (entry->blink_timeout)
gdk_window_set_user_data (widget->window, entry);
get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
-
- attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
- attributes_mask |= GDK_WA_CURSOR;
+
+ 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;
+ }
entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
+
gdk_window_set_user_data (entry->text_area, entry);
- gdk_cursor_unref (attributes.cursor);
+ if (attributes_mask & GDK_WA_CURSOR)
+ gdk_cursor_unref (attributes.cursor);
widget->style = gtk_style_attach (widget->style, widget->window);
gint *yborder)
{
GtkWidget *widget = GTK_WIDGET (entry);
- gint focus_width;
- gboolean interior_focus;
-
- gtk_widget_style_get (widget,
- "interior-focus", &interior_focus,
- "focus-line-width", &focus_width,
- NULL);
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
if (entry->has_frame)
{
*yborder = 0;
}
- if (!interior_focus)
+ if (!priv->interior_focus)
{
- *xborder += focus_width;
- *yborder += focus_width;
+ *xborder += priv->focus_width;
+ *yborder += priv->focus_width;
}
}
entry->descent = pango_font_metrics_get_descent (metrics);
_gtk_entry_get_borders (entry, &xborder, &yborder);
- get_inner_border (entry, &inner_border);
+ _gtk_entry_effective_inner_border (entry, &inner_border);
if (entry->width_chars < 0)
requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
gint *width,
gint *height)
{
+ gint frame_height;
gint xborder, yborder;
GtkRequisition requisition;
GtkWidget *widget = GTK_WIDGET (entry);
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
gtk_widget_get_child_requisition (widget, &requisition);
-
_gtk_entry_get_borders (entry, &xborder, &yborder);
+ if (GTK_WIDGET_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)
+ frame_height -= 2 * priv->focus_width;
+
if (x)
*x = xborder;
if (y)
- *y = yborder;
-
+ *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
+
if (width)
*width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
}
}
-static void
-get_inner_border (GtkEntry *entry,
- GtkBorder *border)
+void
+_gtk_entry_effective_inner_border (GtkEntry *entry,
+ GtkBorder *border)
{
GtkBorder *tmp_border;
if (tmp_border)
{
*border = *tmp_border;
- g_free (tmp_border);
+ gtk_border_free (tmp_border);
return;
}
}
static void
-gtk_entry_draw_frame (GtkWidget *widget)
+gtk_entry_draw_frame (GtkWidget *widget,
+ GdkRectangle *area)
{
- gint x = 0, y = 0;
- gint width, height;
- gboolean interior_focus;
- gint focus_width;
-
- gtk_widget_style_get (widget,
- "interior-focus", &interior_focus,
- "focus-line-width", &focus_width,
- NULL);
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+ gint x = 0, y = 0, width, height;
gdk_drawable_get_size (widget->window, &width, &height);
- if (GTK_WIDGET_HAS_FOCUS (widget) && !interior_focus)
+ if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
{
- x += focus_width;
- y += focus_width;
- width -= 2 * focus_width;
- height -= 2 * focus_width;
+ x += priv->focus_width;
+ y += priv->focus_width;
+ width -= 2 * priv->focus_width;
+ height -= 2 * priv->focus_width;
}
gtk_paint_shadow (widget->style, widget->window,
- GTK_STATE_NORMAL, GTK_SHADOW_IN,
- NULL, widget, "entry",
- x, y, width, height);
+ GTK_STATE_NORMAL, priv->shadow_type,
+ area, widget, "entry", x, y, width, height);
- if (GTK_WIDGET_HAS_FOCUS (widget) && !interior_focus)
+ if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
{
- x -= focus_width;
- y -= focus_width;
- width += 2 * focus_width;
- height += 2 * focus_width;
+ 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),
- NULL, widget, "entry",
+ area, widget, "entry",
0, 0, width, height);
}
}
GtkEntry *entry = GTK_ENTRY (widget);
if (widget->window == event->window)
- gtk_entry_draw_frame (widget);
+ gtk_entry_draw_frame (widget, &event->area);
else if (entry->text_area == event->window)
{
gint area_width, area_height;
gtk_paint_flat_box (widget->style, entry->text_area,
GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE,
- NULL, widget, "entry_bg",
+ &event->area, widget, "entry_bg",
0, 0, area_width, area_height);
-
- 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);
if (entry->dnd_position != -1)
gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
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);
}
return FALSE;
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
{
PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
- PangoLayoutLine *line = pango_layout_get_lines (layout)->data;
+ PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
const char *text = pango_layout_get_text (layout);
gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
(entry->button && event->button != entry->button))
return FALSE;
+ gtk_entry_reset_blink_time (entry);
+
entry->button = event->button;
if (!GTK_WIDGET_HAS_FOCUS (widget))
if (event->state & GDK_SHIFT_MASK)
{
- gtk_entry_reset_im_context (entry);
+ _gtk_entry_reset_im_context (entry);
if (!have_selection) /* select from the current position to the clicked position */
sel_start = sel_end = entry->current_pos;
if (tmp_pos > sel_start && tmp_pos < sel_end)
{
- /* Truncate current selection */
- gtk_entry_set_positions (entry, tmp_pos, -1);
+ /* Truncate current selection, but keep it as big as possible */
+ if (tmp_pos - sel_start > sel_end - tmp_pos)
+ gtk_entry_set_positions (entry, sel_start, tmp_pos);
+ else
+ gtk_entry_set_positions (entry, tmp_pos, sel_end);
}
else
{
*/
entry->in_drag = TRUE;
entry->drag_start_x = event->x + entry->scroll_offset;
- entry->drag_start_y = event->y + entry->scroll_offset;
+ entry->drag_start_y = event->y;
}
else
- gtk_editable_set_position (editable, tmp_pos);
+ gtk_editable_set_position (editable, tmp_pos);
break;
case GDK_2BUTTON_PRESS:
return TRUE;
}
- else if (event->button == 2 && event->type == GDK_BUTTON_PRESS && entry->editable)
+ else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
{
- priv->insert_pos = tmp_pos;
- gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
-
- return TRUE;
+ if (entry->editable)
+ {
+ priv->insert_pos = tmp_pos;
+ gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
+ return TRUE;
+ }
+ else
+ {
+ gtk_widget_error_bell (widget);
+ }
}
else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
{
if (entry->select_lines)
return TRUE;
- if (event->is_hint || (entry->text_area != event->window))
- gdk_window_get_pointer (entry->text_area, NULL, NULL, NULL);
+ gdk_event_request_motions (event);
if (entry->in_drag)
{
{
GtkEntry *entry = GTK_ENTRY (widget);
+ gtk_entry_reset_blink_time (entry);
gtk_entry_pend_cursor_blink (entry);
if (entry->editable)
completion->priv->completion_timeout = 0;
}
- gtk_entry_reset_im_context (entry);
+ _gtk_entry_reset_im_context (entry);
}
if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
*/
return TRUE;
+ if (!entry->editable && event->length)
+ gtk_widget_error_bell (widget);
+
return FALSE;
}
"direction_changed",
G_CALLBACK (gtk_entry_keymap_direction_changed), entry);
+ gtk_entry_reset_blink_time (entry);
gtk_entry_check_cursor_blink (entry);
return FALSE;
GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
- g_object_get (gtk_widget_get_settings (widget),
- "gtk-entry-select-on-focus",
- &select_on_focus,
- NULL);
+ if (entry->editable && !entry->in_click)
+ {
+ g_object_get (gtk_widget_get_settings (widget),
+ "gtk-entry-select-on-focus",
+ &select_on_focus,
+ NULL);
- if (select_on_focus && entry->editable && !entry->in_click)
- gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
+ if (select_on_focus)
+ gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
+ }
}
static void
GtkStateType previous_state)
{
GtkEntry *entry = GTK_ENTRY (widget);
+ GdkCursor *cursor;
if (GTK_WIDGET_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)]);
+
+ if (GTK_WIDGET_IS_SENSITIVE (widget))
+ cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
+ else
+ cursor = NULL;
+
+ gdk_window_set_cursor (entry->text_area, cursor);
+
+ if (cursor)
+ gdk_cursor_unref (cursor);
+
+ entry->mouse_cursor_obscured = FALSE;
}
if (!GTK_WIDGET_IS_SENSITIVE (widget))
}
static void
-gtk_entry_set_position_internal (GtkEntry *entry,
- gint position,
- gboolean reset_im)
+gtk_entry_real_set_position (GtkEditable *editable,
+ gint position)
{
+ GtkEntry *entry = GTK_ENTRY (editable);
+
if (position < 0 || position > entry->text_length)
position = entry->text_length;
if (position != entry->current_pos ||
position != entry->selection_bound)
{
- if (reset_im)
- gtk_entry_reset_im_context (entry);
+ _gtk_entry_reset_im_context (entry);
gtk_entry_set_positions (entry, position, position);
}
}
-static void
-gtk_entry_real_set_position (GtkEditable *editable,
- gint position)
-{
- gtk_entry_set_position_internal (GTK_ENTRY (editable), position, TRUE);
-}
-
static gint
gtk_entry_get_position (GtkEditable *editable)
{
if (end < 0)
end = entry->text_length;
- gtk_entry_reset_im_context (entry);
+ _gtk_entry_reset_im_context (entry);
gtk_entry_set_positions (entry,
MIN (end, entry->text_length),
GtkStyle *previous_style)
{
GtkEntry *entry = GTK_ENTRY (widget);
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+ gint focus_width;
+ gboolean interior_focus;
+
+ gtk_widget_style_get (widget,
+ "focus-line-width", &focus_width,
+ "interior-focus", &interior_focus,
+ NULL);
+ priv->focus_width = focus_width;
+ priv->interior_focus = interior_focus;
+
gtk_entry_recompute (entry);
if (previous_style && GTK_WIDGET_REALIZED (widget))
GtkEntry *entry = GTK_ENTRY (editable);
gint index;
gint n_chars;
- guint password_hint_timeout;
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)
{
- gdk_display_beep (gtk_widget_get_display (GTK_WIDGET (entry)));
+ 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 (entry->selection_bound > *position)
entry->selection_bound += n_chars;
- g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
- "gtk-entry-password-hint-timeout", &password_hint_timeout,
- NULL);
-
- if (password_hint_timeout > 0 && n_chars == 1 && !entry->visible &&
- (new_text_length < PASSWORD_HINT_MAX))
+ if (n_chars == 1 && !entry->visible && (new_text_length < PASSWORD_HINT_MAX))
{
- GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
- quark_password_hint);
+ guint password_hint_timeout;
+
+ g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
+ "gtk-entry-password-hint-timeout", &password_hint_timeout,
+ NULL);
- if (! password_hint)
+ if (password_hint_timeout > 0)
{
- password_hint = g_new0 (GtkEntryPasswordHint, 1);
- g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint,
- password_hint,
- (GDestroyNotify) gtk_entry_password_hint_free);
- }
+ GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
+ quark_password_hint);
+
+ if (!password_hint)
+ {
+ password_hint = g_new0 (GtkEntryPasswordHint, 1);
+ 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;
+ 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
{
gtk_entry_recompute (entry);
- g_signal_emit_by_name (editable, "changed");
+ emit_changed (entry);
g_object_notify (G_OBJECT (editable), "text");
}
gtk_entry_recompute (entry);
- g_signal_emit_by_name (editable, "changed");
+ emit_changed (entry);
g_object_notify (G_OBJECT (editable), "text");
}
}
{
gint new_pos = entry->current_pos;
- gtk_entry_reset_im_context (entry);
+ _gtk_entry_reset_im_context (entry);
if (entry->current_pos != entry->selection_bound && !extend_selection)
{
new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
else
new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
-
break;
}
case GTK_MOVEMENT_LOGICAL_POSITIONS:
break;
case GTK_MOVEMENT_VISUAL_POSITIONS:
new_pos = gtk_entry_move_visually (entry, new_pos, count);
+ if (entry->current_pos == new_pos)
+ {
+ if (!extend_selection)
+ {
+ if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
+ count > 0 ?
+ GTK_DIR_RIGHT : GTK_DIR_LEFT))
+ {
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
+
+ if (toplevel)
+ gtk_widget_child_focus (toplevel,
+ count > 0 ?
+ GTK_DIR_RIGHT : GTK_DIR_LEFT);
+ }
+ }
+ else
+ {
+ gtk_widget_error_bell (GTK_WIDGET (entry));
+ }
+ }
break;
case GTK_MOVEMENT_WORDS:
while (count > 0)
new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
count++;
}
+ if (entry->current_pos == new_pos)
+ gtk_widget_error_bell (GTK_WIDGET (entry));
break;
case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
case GTK_MOVEMENT_PARAGRAPH_ENDS:
case GTK_MOVEMENT_BUFFER_ENDS:
new_pos = count < 0 ? 0 : entry->text_length;
+ if (entry->current_pos == new_pos)
+ gtk_widget_error_bell (GTK_WIDGET (entry));
break;
case GTK_MOVEMENT_DISPLAY_LINES:
case GTK_MOVEMENT_PARAGRAPHS:
if (entry->editable)
{
- gtk_entry_reset_im_context (entry);
+ _gtk_entry_reset_im_context (entry);
gtk_editable_insert_text (editable, str, -1, &pos);
gtk_editable_set_position (editable, pos);
GtkEditable *editable = GTK_EDITABLE (entry);
gint start_pos = entry->current_pos;
gint end_pos = entry->current_pos;
+ gint old_n_bytes = entry->n_bytes;
- gtk_entry_reset_im_context (entry);
+ _gtk_entry_reset_im_context (entry);
if (!entry->editable)
- return;
+ {
+ gtk_widget_error_bell (GTK_WIDGET (entry));
+ return;
+ }
if (entry->selection_bound != entry->current_pos)
{
gtk_entry_delete_whitespace (entry);
break;
}
-
+
+ if (entry->n_bytes == old_n_bytes)
+ gtk_widget_error_bell (GTK_WIDGET (entry));
+
gtk_entry_pend_cursor_blink (entry);
}
GtkEditable *editable = GTK_EDITABLE (entry);
gint prev_pos;
- gtk_entry_reset_im_context (entry);
+ _gtk_entry_reset_im_context (entry);
if (!entry->editable || !entry->text)
- return;
+ {
+ gtk_widget_error_bell (GTK_WIDGET (entry));
+ return;
+ }
if (entry->selection_bound != entry->current_pos)
{
g_free (log_attrs);
}
+ else
+ {
+ gtk_widget_error_bell (GTK_WIDGET (entry));
+ }
gtk_entry_pend_cursor_blink (entry);
}
if (gtk_editable_get_selection_bounds (editable, &start, &end))
gtk_editable_delete_text (editable, start, end);
}
+ else
+ {
+ gtk_widget_error_bell (GTK_WIDGET (entry));
+ }
}
static void
{
if (entry->editable)
gtk_entry_paste (entry, GDK_NONE);
+ else
+ gtk_widget_error_bell (GTK_WIDGET (entry));
}
static void
gtk_entry_toggle_overwrite (GtkEntry *entry)
{
entry->overwrite_mode = !entry->overwrite_mode;
+ gtk_entry_pend_cursor_blink (entry);
+ gtk_widget_queue_draw (GTK_WIDGET (entry));
}
static void
{
GtkEditable *editable = GTK_EDITABLE (entry);
gint tmp_pos;
+ gboolean old_need_im_reset;
+
+ old_need_im_reset = entry->need_im_reset;
+ entry->need_im_reset = FALSE;
if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
gtk_editable_delete_selection (editable);
tmp_pos = entry->current_pos;
gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
- gtk_entry_set_position_internal (entry, tmp_pos, FALSE);
+ gtk_editable_set_position (editable, tmp_pos);
+
+ entry->need_im_reset = old_need_im_reset;
}
/* All changes to entry->current_pos and entry->selection_bound
g_object_thaw_notify (G_OBJECT (entry));
- if (changed)
- gtk_entry_recompute (entry);
+ if (changed)
+ {
+ gtk_entry_move_adjustments (entry);
+ gtk_entry_recompute (entry);
+ }
}
static void
{
GtkEntry *entry;
- GDK_THREADS_ENTER ();
-
entry = GTK_ENTRY (data);
entry->recompute_idle = 0;
update_im_cursor_location (entry);
}
- GDK_THREADS_LEAVE ();
-
return FALSE;
}
if (!entry->recompute_idle)
{
- entry->recompute_idle = g_idle_add_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
+ entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
recompute_idle_func, entry, NULL);
}
}
static gboolean
gtk_entry_remove_password_hint (gpointer data)
{
- GDK_THREADS_ENTER();
-
/* Force the string to be redrawn, but now without a visible character */
gtk_entry_recompute (GTK_ENTRY (data));
- GDK_THREADS_LEAVE();
-
return FALSE;
}
entry->text_length -
password_hint->password_hint_position);
- /* Now remove this last inputted character, don't need
+ /* 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 =
- g_timeout_add (password_hint_timeout,
+ gdk_threads_add_timeout (password_hint_timeout,
(GSourceFunc) gtk_entry_remove_password_hint,
entry);
}
pango_layout_set_attributes (layout, tmp_attrs);
- if (preedit_string)
- g_free (preedit_string);
+ g_free (preedit_string);
if (preedit_attrs)
pango_attr_list_unref (preedit_attrs);
layout = gtk_entry_ensure_layout (entry, TRUE);
get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
- get_inner_border (entry, &inner_border);
+ _gtk_entry_effective_inner_border (entry, &inner_border);
area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
- line = pango_layout_get_lines (layout)->data;
+ line = pango_layout_get_lines_readonly (layout)->data;
pango_layout_line_get_extents (line, NULL, &logical_rect);
/* Align primarily for locale's ascent/descent */
text_color = &widget->style->text [GTK_STATE_ACTIVE];
}
- get_inner_border (entry, &inner_border);
+ _gtk_entry_effective_inner_border (entry, &inner_border);
for (i = 0; i < n_ranges; ++i)
cairo_rectangle (cr,
GtkWidget *widget = GTK_WIDGET (entry);
GdkRectangle cursor_location;
gboolean split_cursor;
-
+ PangoRectangle cursor_rect;
GtkBorder inner_border;
gint xoffset;
- gint strong_x, weak_x;
gint text_area_height;
- PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
- PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
- gint x1 = 0;
- gint x2 = 0;
+ gint cursor_index;
+ gboolean block;
+ gboolean block_at_line_end;
- get_inner_border (entry, &inner_border);
+ _gtk_entry_effective_inner_border (entry, &inner_border);
xoffset = inner_border.left - entry->scroll_offset;
gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
-
- gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
- g_object_get (gtk_widget_get_settings (widget),
- "gtk-split-cursor", &split_cursor,
- NULL);
+ cursor_index = g_utf8_offset_to_pointer (entry->text, entry->current_pos + entry->preedit_cursor) - entry->text;
+ if (!entry->overwrite_mode)
+ block = FALSE;
+ else
+ block = _gtk_text_util_get_block_cursor_location (gtk_entry_ensure_layout (entry, TRUE),
+ cursor_index, &cursor_rect, &block_at_line_end);
+
+ if (!block)
+ {
+ gint strong_x, weak_x;
+ PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
+ PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
+ gint x1 = 0;
+ gint x2 = 0;
+
+ gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
+
+ g_object_get (gtk_widget_get_settings (widget),
+ "gtk-split-cursor", &split_cursor,
+ NULL);
- dir1 = entry->resolved_dir;
+ dir1 = entry->resolved_dir;
- if (split_cursor)
- {
- x1 = strong_x;
+ if (split_cursor)
+ {
+ x1 = strong_x;
- if (weak_x != strong_x)
- {
- dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
- x2 = weak_x;
- }
- }
- else
- {
- if (keymap_direction == entry->resolved_dir)
- x1 = strong_x;
- else
- x1 = weak_x;
- }
+ if (weak_x != strong_x)
+ {
+ dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
+ x2 = weak_x;
+ }
+ }
+ else
+ {
+ if (keymap_direction == entry->resolved_dir)
+ x1 = strong_x;
+ else
+ x1 = weak_x;
+ }
- cursor_location.x = xoffset + x1;
- cursor_location.y = inner_border.top;
- cursor_location.width = 0;
- cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
+ cursor_location.x = xoffset + x1;
+ cursor_location.y = inner_border.top;
+ cursor_location.width = 0;
+ cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
- draw_insertion_cursor (entry,
- &cursor_location, TRUE, dir1,
- dir2 != PANGO_DIRECTION_NEUTRAL);
+ draw_insertion_cursor (entry,
+ &cursor_location, TRUE, dir1,
+ dir2 != PANGO_DIRECTION_NEUTRAL);
- if (dir2 != PANGO_DIRECTION_NEUTRAL)
- {
- cursor_location.x = xoffset + x2;
- draw_insertion_cursor (entry,
- &cursor_location, FALSE, dir2,
- TRUE);
- }
+ if (dir2 != PANGO_DIRECTION_NEUTRAL)
+ {
+ cursor_location.x = xoffset + x2;
+ draw_insertion_cursor (entry,
+ &cursor_location, FALSE, dir2,
+ TRUE);
+ }
+ }
+ else /* overwrite_mode */
+ {
+ PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
+ GdkColor cursor_color;
+ GdkRectangle rect;
+ cairo_t *cr;
+ gint x, y;
+
+ get_layout_position (entry, &x, &y);
+
+ rect.x = PANGO_PIXELS (cursor_rect.x) + x;
+ rect.y = PANGO_PIXELS (cursor_rect.y) + y;
+ rect.width = PANGO_PIXELS (cursor_rect.width);
+ rect.height = PANGO_PIXELS (cursor_rect.height);
+
+ cr = gdk_cairo_create (entry->text_area);
+
+ _gtk_widget_get_cursor_color (widget, &cursor_color);
+ gdk_cairo_set_source_color (cr, &cursor_color);
+ gdk_cairo_rectangle (cr, &rect);
+ cairo_fill (cr);
+
+ if (!block_at_line_end)
+ {
+ gdk_cairo_rectangle (cr, &rect);
+ cairo_clip (cr);
+ cairo_move_to (cr, x, y);
+ gdk_cairo_set_source_color (cr, &widget->style->base[widget->state]);
+ pango_cairo_show_layout (cr, layout);
+ }
+
+ cairo_destroy (cr);
+ }
}
}
static void
gtk_entry_queue_draw (GtkEntry *entry)
{
- if (GTK_WIDGET_REALIZED (entry))
+ if (GTK_WIDGET_DRAWABLE (entry))
gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
}
-static void
-gtk_entry_reset_im_context (GtkEntry *entry)
+void
+_gtk_entry_reset_im_context (GtkEntry *entry)
{
if (entry->need_im_reset)
{
PangoLayoutLine *line;
gint index;
gint pos;
- gboolean trailing;
+ gint trailing;
const gchar *text;
gint cursor_index;
text = pango_layout_get_text (layout);
cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
- line = pango_layout_get_lines (layout)->data;
+ line = pango_layout_get_lines_readonly (layout)->data;
pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
if (index >= cursor_index && entry->preedit_length)
if (!GTK_WIDGET_REALIZED (entry))
return;
- get_inner_border (entry, &inner_border);
+ _gtk_entry_effective_inner_border (entry, &inner_border);
gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
text_area_width -= inner_border.left + inner_border.right;
text_area_width = 0;
layout = gtk_entry_ensure_layout (entry, TRUE);
- line = pango_layout_get_lines (layout)->data;
+ line = pango_layout_get_lines_readonly (layout)->data;
pango_layout_line_get_extents (line, NULL, &logical_rect);
g_object_notify (G_OBJECT (entry), "scroll-offset");
}
+static void
+gtk_entry_move_adjustments (GtkEntry *entry)
+{
+ PangoContext *context;
+ PangoFontMetrics *metrics;
+ gint x, layout_x, border_x, border_y;
+ gint char_width;
+ GtkAdjustment *adjustment;
+
+ adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
+ if (!adjustment)
+ return;
+
+ /* Cursor position, layout offset, border width, and widget allocation */
+ gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
+ get_layout_position (entry, &layout_x, NULL);
+ _gtk_entry_get_borders (entry, &border_x, &border_y);
+ x += entry->widget.allocation.x + layout_x + border_x;
+
+ /* Approximate width of a char, so user can see what is ahead/behind */
+ context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
+ metrics = pango_context_get_metrics (context,
+ entry->widget.style->font_desc,
+ pango_context_get_language (context));
+ char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
+
+ /* Scroll it */
+ gtk_adjustment_clamp_page (adjustment,
+ x - (char_width + 1), /* one char + one pixel before */
+ x + (char_width + 2)); /* one char + cursor + one pixel after */
+}
+
static gint
gtk_entry_move_visually (GtkEntry *entry,
gint start,
{
gint pos, start, end;
gint length = -1;
- GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
+ gboolean popup_completion;
+ GtkEntryCompletion *completion;
+
+ completion = gtk_entry_get_completion (entry);
if (entry->truncate_multiline)
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));
+
if (completion)
{
- g_signal_handler_block (entry, completion->priv->changed_id);
if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
_gtk_entry_completion_popdown (completion);
+
+ if (!popup_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));
if (gtk_editable_get_selection_bounds (editable, &start, &end))
gtk_editable_delete_text (editable, start, end);
pos = entry->current_pos;
gtk_editable_insert_text (editable, text, length, &pos);
gtk_editable_set_position (editable, pos);
+ g_object_thaw_notify (G_OBJECT (entry));
+ end_change (entry);
- if (completion)
+ if (completion &&
+ !popup_completion && completion->priv->changed_id > 0)
g_signal_handler_unblock (entry, completion->priv->changed_id);
}
return GTK_WIDGET (entry);
}
+/**
+ * gtk_entry_set_text:
+ * @entry: a #GtkEntry
+ * @text: the new text
+ *
+ * Sets the text in the widget to the given
+ * value, replacing the current contents.
+ */
void
gtk_entry_set_text (GtkEntry *entry,
const gchar *text)
return;
completion = gtk_entry_get_completion (entry);
- if (completion)
+ 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)
+ if (completion && completion->priv->changed_id > 0)
g_signal_handler_unblock (entry, completion->priv->changed_id);
}
+/**
+ * gtk_entry_append_text:
+ * @entry: a #GtkEntry
+ * @text: the text to append
+ *
+ * Appends the given text to the contents of the widget.
+ *
+ * Deprecated: gtk_entry_append_text() is deprecated and should not
+ * be used in newly-written code. Use gtk_editable_insert_text()
+ * instead.
+ */
void
gtk_entry_append_text (GtkEntry *entry,
const gchar *text)
gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
}
+/**
+ * gtk_entry_prepend_text:
+ * @entry: a #GtkEntry
+ * @text: the text to prepend
+ *
+ * Prepends the given text to the contents of the widget.
+ *
+ * Deprecated: gtk_entry_prepend_text() is deprecated and should not
+ * be used in newly-written code. Use gtk_editable_insert_text()
+ * instead.
+ */
void
gtk_entry_prepend_text (GtkEntry *entry,
const gchar *text)
gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
}
+/**
+ * gtk_entry_set_position:
+ * @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.
+ *
+ * Sets the cursor position in an entry to the given value.
+ *
+ * Deprecated: Use gtk_editable_set_position() instead.
+ */
void
gtk_entry_set_position (GtkEntry *entry,
gint position)
gtk_editable_set_position (GTK_EDITABLE (entry), position);
}
+/**
+ * gtk_entry_set_visibility:
+ * @entry: a #GtkEntry
+ * @visible: %TRUE if the contents of the entry are displayed
+ * as plaintext
+ *
+ * Sets whether the contents of the entry are visible or not.
+ * When visibility is set to %FALSE, characters are displayed
+ * as the invisible char, and will also appear that way when
+ * the text in the entry widget is copied elsewhere.
+ *
+ * The default invisible char is the asterisk '*', but it can
+ * be changed with gtk_entry_set_invisible_char().
+ */
void
gtk_entry_set_visibility (GtkEntry *entry,
gboolean visible)
* invisible char is an asterisk ('*'). If you set the invisible char
* to 0, then the user will get no feedback at all; there will be
* no text on the screen as they type.
- *
**/
void
gtk_entry_set_invisible_char (GtkEntry *entry,
* @entry: a #GtkEntry
*
* Retrieves the character displayed in place of the real characters
- * for entries with visisbility set to false. See gtk_entry_set_invisible_char().
+ * for entries with visibility set to false. See gtk_entry_set_invisible_char().
*
* Return value: the current invisible char, or 0, if the entry does not
* show invisible text at all.
return entry->invisible_char;
}
+/**
+ * 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: Use gtk_editable_set_editable() instead.
+ */
void
gtk_entry_set_editable (GtkEntry *entry,
gboolean editable)
* See also gtk_editable_get_chars().
*
* Return value: a pointer to the contents of the widget as a
- * string. This string points to internally allocated
+ * string. This string points to internally allocated
* storage in the widget and must not be freed, modified or
* stored.
**/
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: Use gtk_editable_select_region() instead.
+ */
void
gtk_entry_select_region (GtkEntry *entry,
gint start,
/**
* gtk_entry_set_max_length:
- * @entry: a #GtkEntry.
+ * @entry: a #GtkEntry
* @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.
*
* (For experts: if @setting is %TRUE, the entry calls
* gtk_window_activate_default() on the window containing the entry, in
- * the default handler for the "activate" signal.)
- *
+ * the default handler for the #GtkWidget::activate signal.)
**/
void
gtk_entry_set_activates_default (GtkEntry *entry,
* <emphasis>request</emphasis>, the size can still be affected by
* how you pack the widget into containers. If @n_chars is -1, the
* size reverts to the default entry size.
- *
**/
void
gtk_entry_set_width_chars (GtkEntry *entry,
* gtk_entry_get_inner_border:
* @entry: a #GtkEntry
*
- * This function returns the entry's inner-border property. See
+ * 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.
* 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.
- *
**/
void
gtk_entry_get_layout_offsets (GtkEntry *entry,
gtk_widget_size_request (entry->popup_menu, &menu_req);
gdk_drawable_get_size (entry->text_area, NULL, &height);
gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
- get_inner_border (entry, &inner_border);
+ _gtk_entry_effective_inner_border (entry, &inner_border);
*x += inner_border.left + strong_x - entry->scroll_offset;
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
else
{
/* Replacing selection */
+ begin_change (entry);
+ g_object_freeze_notify (G_OBJECT (entry));
gtk_editable_delete_text (editable, sel1, sel2);
gtk_editable_insert_text (editable, str, length, &sel1);
+ g_object_thaw_notify (G_OBJECT (entry));
+ end_change (entry);
}
- g_free (str);
gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
}
else
/* Drag and drop didn't happen! */
gtk_drag_finish (context, FALSE, FALSE, time);
}
+
+ g_free (str);
}
static void
* - the widget has focus
*/
-#define CURSOR_ON_MULTIPLIER 0.66
-#define CURSOR_OFF_MULTIPLIER 0.34
-#define CURSOR_PEND_MULTIPLIER 1.0
+#define CURSOR_ON_MULTIPLIER 2
+#define CURSOR_OFF_MULTIPLIER 1
+#define CURSOR_PEND_MULTIPLIER 3
+#define CURSOR_DIVIDER 3
static gboolean
cursor_blinks (GtkEntry *entry)
{
- GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
- gboolean blink;
-
if (GTK_WIDGET_HAS_FOCUS (entry) &&
entry->editable &&
entry->selection_bound == entry->current_pos)
{
+ GtkSettings *settings;
+ gboolean blink;
+
+ settings = gtk_widget_get_settings (GTK_WIDGET (entry));
g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
+
return blink;
}
else
return time;
}
+static gint
+get_cursor_blink_timeout (GtkEntry *entry)
+{
+ GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
+ gint timeout;
+
+ g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
+
+ return timeout;
+}
+
static void
show_cursor (GtkEntry *entry)
{
blink_cb (gpointer data)
{
GtkEntry *entry;
-
- GDK_THREADS_ENTER ();
+ GtkEntryPrivate *priv;
+ gint blink_timeout;
entry = GTK_ENTRY (data);
-
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
+
if (!GTK_WIDGET_HAS_FOCUS (entry))
{
g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
"connect a handler to this signal, it must return\n"
"FALSE so the entry gets the event as well");
+
+ gtk_entry_check_cursor_blink (entry);
+
+ return FALSE;
}
- g_assert (GTK_WIDGET_HAS_FOCUS (entry));
g_assert (entry->selection_bound == entry->current_pos);
-
- if (entry->cursor_visible)
+
+ blink_timeout = get_cursor_blink_timeout (entry);
+ if (priv->blink_time > 1000 * blink_timeout &&
+ blink_timeout < G_MAXINT/1000)
+ {
+ /* we've blinked enough without the user doing anything, stop blinking */
+ show_cursor (entry);
+ entry->blink_timeout = 0;
+ }
+ else if (entry->cursor_visible)
{
hide_cursor (entry);
- entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER,
+ entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
blink_cb,
entry);
}
else
{
show_cursor (entry);
- entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER,
+ priv->blink_time += get_cursor_time (entry);
+ entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
blink_cb,
entry);
}
- GDK_THREADS_LEAVE ();
-
/* Remove ourselves */
return FALSE;
}
static void
gtk_entry_check_cursor_blink (GtkEntry *entry)
{
+ GtkEntryPrivate *priv;
+
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
+
if (cursor_blinks (entry))
{
if (!entry->blink_timeout)
{
- entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER,
+ show_cursor (entry);
+ entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
blink_cb,
entry);
- show_cursor (entry);
}
}
else
if (entry->blink_timeout != 0)
g_source_remove (entry->blink_timeout);
- entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER,
+ entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
blink_cb,
entry);
show_cursor (entry);
}
}
+static void
+gtk_entry_reset_blink_time (GtkEntry *entry)
+{
+ GtkEntryPrivate *priv;
+
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
+
+ priv->blink_time = 0;
+}
+
+
/* completion */
static gint
gtk_entry_completion_timeout (gpointer data)
{
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
- GDK_THREADS_ENTER ();
-
completion->priv->completion_timeout = 0;
if (completion->priv->filter_model &&
else if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
_gtk_entry_completion_popdown (completion);
- GDK_THREADS_LEAVE ();
-
return FALSE;
}
{
gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
+
+ if (completion->priv->inline_selection &&
+ completion->priv->completion_prefix)
+ {
+ gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
+ completion->priv->completion_prefix);
+ gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+ }
}
else if (completion->priv->current_selected < matches)
{
path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
path, NULL, FALSE);
+
+ if (completion->priv->inline_selection)
+ {
+
+ GtkTreeIter 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;
+
+ 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);
+ }
}
else if (completion->priv->current_selected - matches >= 0)
{
path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
path, NULL, FALSE);
+
+ if (completion->priv->inline_selection &&
+ completion->priv->completion_prefix)
+ {
+ gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
+ completion->priv->completion_prefix);
+ gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+ }
}
gtk_tree_path_free (path);
return TRUE;
}
- else if (event->keyval == GDK_Escape)
+ else if (event->keyval == GDK_Escape ||
+ event->keyval == GDK_Left ||
+ event->keyval == GDK_KP_Left ||
+ event->keyval == GDK_Right ||
+ event->keyval == GDK_KP_Right)
{
+ gboolean retval = TRUE;
+
+ _gtk_entry_reset_im_context (GTK_ENTRY (widget));
_gtk_entry_completion_popdown (completion);
- return TRUE;
+ if (completion->priv->current_selected < 0)
+ {
+ retval = FALSE;
+ goto keypress_completion_out;
+ }
+ else if (completion->priv->inline_selection)
+ {
+ /* Escape rejects the tentative completion */
+ if (event->keyval == GDK_Escape)
+ {
+ if (completion->priv->completion_prefix)
+ gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
+ completion->priv->completion_prefix);
+ else
+ gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
+ }
+
+ /* Move the cursor to the end for Right/Esc, to the
+ beginning for Left */
+ if (event->keyval == GDK_Right ||
+ event->keyval == GDK_KP_Right ||
+ event->keyval == GDK_Escape)
+ gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+ else
+ gtk_editable_set_position (GTK_EDITABLE (widget), 0);
+ }
+
+keypress_completion_out:
+ if (completion->priv->inline_selection)
+ {
+ g_free (completion->priv->completion_prefix);
+ completion->priv->completion_prefix = NULL;
+ }
+
+ return retval;
}
else if (event->keyval == GDK_Tab ||
event->keyval == GDK_KP_Tab ||
event->keyval == GDK_ISO_Left_Tab)
{
- GtkWidget *entry;
GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
-
- _gtk_entry_completion_popdown (completion);
- entry = gtk_entry_completion_get_entry (completion);
+ _gtk_entry_reset_im_context (GTK_ENTRY (widget));
+ _gtk_entry_completion_popdown (completion);
- gtk_widget_child_focus (gtk_widget_get_toplevel (entry), dir);
+ g_free (completion->priv->completion_prefix);
+ completion->priv->completion_prefix = NULL;
+
+ gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
return TRUE;
}
event->keyval == GDK_KP_Enter ||
event->keyval == GDK_Return)
{
+ gboolean retval = TRUE;
+
+ _gtk_entry_reset_im_context (GTK_ENTRY (widget));
_gtk_entry_completion_popdown (completion);
if (completion->priv->current_selected < matches)
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;
-
- g_signal_handler_block (completion->priv->entry,
- completion->priv->changed_id);
- g_signal_emit_by_name (completion, "match_selected",
- model, &iter, &entry_set);
- g_signal_handler_unblock (completion->priv->entry,
- completion->priv->changed_id);
-
- if (!entry_set)
+ if (gtk_tree_selection_get_selected (sel, &model, &iter))
{
- gchar *str = NULL;
-
- gtk_tree_model_get (model, &iter,
- completion->priv->text_column, &str,
- -1);
-
g_signal_handler_block (widget, completion->priv->changed_id);
- gtk_entry_set_text (GTK_ENTRY (widget), str);
+ g_signal_emit_by_name (completion, "match_selected",
+ model, &iter, &entry_set);
g_signal_handler_unblock (widget, completion->priv->changed_id);
- /* move the cursor to the end */
- gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+ if (!entry_set)
+ {
+ gchar *str = NULL;
- g_free (str);
- }
+ gtk_tree_model_get (model, &iter,
+ completion->priv->text_column, &str,
+ -1);
- return TRUE;
+ gtk_entry_set_text (GTK_ENTRY (widget), str);
+
+ /* move the cursor to the end */
+ gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+
+ g_free (str);
+ }
+ }
+ else
+ retval = FALSE;
}
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);
g_signal_emit_by_name (completion, "action_activated",
gtk_tree_path_get_indices (path)[0]);
gtk_tree_path_free (path);
-
- return TRUE;
}
+
+ g_free (completion->priv->completion_prefix);
+ completion->priv->completion_prefix = NULL;
+
+ return retval;
}
return FALSE;
}
completion->priv->completion_timeout =
- g_timeout_add (COMPLETION_TIMEOUT,
+ gdk_threads_add_timeout (COMPLETION_TIMEOUT,
gtk_entry_completion_timeout,
completion);
}
G_CALLBACK (completion_changed), entry);
if (completion->priv->changed_id > 0 &&
g_signal_handler_is_connected (entry, completion->priv->changed_id))
- g_signal_handler_disconnect (entry, completion->priv->changed_id);
+ {
+ g_signal_handler_disconnect (entry, completion->priv->changed_id);
+ completion->priv->changed_id = 0;
+ }
g_signal_handlers_disconnect_by_func (entry,
G_CALLBACK (gtk_entry_completion_key_press), completion);
if (completion->priv->insert_text_id > 0 &&
g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
- g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
+ {
+ g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
+ completion->priv->insert_text_id = 0;
+ }
g_signal_handlers_disconnect_by_func (entry,
G_CALLBACK (completion_insert_text_callback), completion);
g_signal_handlers_disconnect_by_func (entry,
g_signal_connect (entry, "focus_out_event",
G_CALLBACK (accept_completion_callback), completion);
}
+
g_signal_connect (completion, "notify",
G_CALLBACK (completion_changed), entry);
}
/**
* gtk_entry_set_completion:
- * @entry: A #GtkEntry.
- * @completion: The #GtkEntryCompletion or %NULL.
+ * @entry: A #GtkEntry
+ * @completion: 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
/**
* gtk_entry_get_completion:
- * @entry: A #GtkEntry.
+ * @entry: A #GtkEntry
*
* Returns the auxiliary completion object currently in use by @entry.
*
return completion;
}
+/**
+ * gtk_entry_set_cursor_hadjustment:
+ * @entry: a #GtkEntry
+ * @adjustment: an adjustment which should be adjusted when the cursor
+ * is moved, or %NULL
+ *
+ * Hooks up an adjustment to the cursor position in an entry, so that when
+ * the cursor is moved, the adjustment is scrolled to show that position.
+ * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
+ * the adjustment.
+ *
+ * The adjustment has to be in pixel units and in the same coordinate system
+ * as the entry.
+ *
+ * Since: 2.12
+ */
+void
+gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
+ GtkAdjustment *adjustment)
+{
+ g_return_if_fail (GTK_IS_ENTRY (entry));
+ if (adjustment)
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+
+ if (adjustment)
+ g_object_ref (adjustment);
+
+ g_object_set_qdata_full (G_OBJECT (entry),
+ quark_cursor_hadjustment,
+ adjustment,
+ g_object_unref);
+}
+
+/**
+ * gtk_entry_get_cursor_hadjustment:
+ * @entry: a #GtkEntry
+ *
+ * Retrieves the horizontal cursor adjustment for the entry.
+ * See gtk_entry_set_cursor_hadjustment().
+ *
+ * Return value: the horizontal cursor adjustment, or %NULL
+ * if none has been set.
+ *
+ * Since: 2.12
+ */
+GtkAdjustment*
+gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
+{
+ g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
+
+ return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
+}
+
#define __GTK_ENTRY_C__
#include "gtkaliasdef.c"