[gtk+] GtkEntry: Focus the entry without selecting the text
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] GtkEntry: Focus the entry without selecting the text
- Date: Thu, 23 May 2013 18:53:45 +0000 (UTC)
commit ffbe7f6eb6de2933478a14fc9d734570d7820c21
Author: Bastien Nocera <hadess hadess net>
Date: Tue May 21 18:26:48 2013 +0200
GtkEntry: Focus the entry without selecting the text
Focusing the text entry without selecting all the text is needed in
some places (GtkTreeView, and some uses of GtkSearchEntry) so
create a private helper to avoid replicating the hacks.
https://bugzilla.gnome.org/show_bug.cgi?id=700787
gtk/gtkentry.c | 18 ++++++++++++++----
gtk/gtkentryprivate.h | 3 ++-
2 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 3fefc24..8a7d9e0 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -4725,6 +4725,15 @@ gtk_entry_focus_out (GtkWidget *widget,
return FALSE;
}
+void
+_gtk_entry_grab_focus (GtkEntry *entry,
+ gboolean select_all)
+{
+ GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (GTK_WIDGET (entry));
+ if (select_all)
+ gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
+}
+
static void
gtk_entry_grab_focus (GtkWidget *widget)
{
@@ -4732,8 +4741,6 @@ gtk_entry_grab_focus (GtkWidget *widget)
GtkEntryPrivate *priv = entry->priv;
gboolean select_on_focus;
- GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
-
if (priv->editable && !priv->in_click)
{
g_object_get (gtk_widget_get_settings (widget),
@@ -4741,8 +4748,11 @@ gtk_entry_grab_focus (GtkWidget *widget)
&select_on_focus,
NULL);
- if (select_on_focus)
- gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
+ _gtk_entry_grab_focus (entry, select_on_focus);
+ }
+ else
+ {
+ _gtk_entry_grab_focus (entry, FALSE);
}
}
diff --git a/gtk/gtkentryprivate.h b/gtk/gtkentryprivate.h
index 0cc825a..9d6f1e9 100644
--- a/gtk/gtkentryprivate.h
+++ b/gtk/gtkentryprivate.h
@@ -87,7 +87,8 @@ void _gtk_entry_get_borders (GtkEntry *entry,
GtkIMContext* _gtk_entry_get_im_context (GtkEntry *entry);
void _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
gboolean is_cell_renderer);
-
+void _gtk_entry_grab_focus (GtkEntry *entry,
+ gboolean select_all);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]