gtk2/gtk2-bnc130159-bgo319483-async-selection-in-gtk-font-selection.diff

264 lines
8.3 KiB
Diff

diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontsel.c
index 317e336..bce5280 100644
--- a/gtk/gtkfontsel.c
+++ b/gtk/gtkfontsel.c
@@ -549,11 +549,24 @@ static void
gtk_font_selection_finalize (GObject *object)
{
GtkFontSelection *fontsel;
+ guint selection_timeout;
g_return_if_fail (GTK_IS_FONT_SELECTION (object));
fontsel = GTK_FONT_SELECTION (object);
+ selection_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (fontsel), "font-selection-timeout"));
+ if (selection_timeout)
+ g_source_remove (selection_timeout);
+
+ selection_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (fontsel), "style-selection-timeout"));
+ if (selection_timeout)
+ g_source_remove (selection_timeout);
+
+ selection_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (fontsel), "size-selection-timeout"));
+ if (selection_timeout)
+ g_source_remove (selection_timeout);
+
if (fontsel->font)
gdk_font_unref (fontsel->font);
@@ -568,9 +581,15 @@ gtk_font_selection_screen_changed (GtkWidget *widget,
if (gtk_widget_has_screen (GTK_WIDGET (fontsel)))
{
+ /* Disable selection timeout */
+ g_object_set_data (G_OBJECT (fontsel), "immediate-selection", GUINT_TO_POINTER (1));
+
gtk_font_selection_show_available_fonts (fontsel);
gtk_font_selection_show_available_sizes (fontsel, TRUE);
gtk_font_selection_show_available_styles (fontsel);
+
+ /* Enable selection timeout */
+ g_object_set_data (G_OBJECT (fontsel), "immediate-selection", GUINT_TO_POINTER (0));
}
}
@@ -632,10 +651,10 @@ gtk_font_selection_scroll_on_map (GtkWidget *widget,
}
/* This is called when a family is selected in the list. */
-static void
-gtk_font_selection_select_font (GtkTreeSelection *selection,
- gpointer data)
+static gboolean
+gtk_font_selection_real_select_font (gpointer data)
{
+ GtkTreeSelection *selection;
GtkFontSelection *fontsel;
GtkTreeModel *model;
GtkTreeIter iter;
@@ -643,7 +662,11 @@ gtk_font_selection_select_font (GtkTreeSelection *selection,
const gchar *family_name;
#endif
+ if (!g_object_get_data (G_OBJECT (data), "immediate-selection"))
+ GDK_THREADS_ENTER ();
+
fontsel = GTK_FONT_SELECTION (data);
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->family_list));
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
@@ -665,6 +688,40 @@ gtk_font_selection_select_font (GtkTreeSelection *selection,
g_object_unref (family);
}
+
+ g_object_set_data (G_OBJECT (fontsel), "font-selection-timeout", GUINT_TO_POINTER (0));
+
+ if (!g_object_get_data (G_OBJECT (fontsel), "immediate-selection"))
+ GDK_THREADS_LEAVE ();
+
+ /* Remove ourselves */
+ return FALSE;
+}
+
+static void
+gtk_font_selection_select_font (GtkTreeSelection *selection,
+ gpointer data)
+{
+ GtkFontSelection *fontsel;
+ guint selection_timeout = 0;
+ guint immediate_selection = 0;
+
+ fontsel = GTK_FONT_SELECTION (data);
+ selection_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (fontsel), "font-selection-timeout"));
+ immediate_selection = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (fontsel), "immediate-selection"));
+
+ if (selection_timeout)
+ g_source_remove (selection_timeout);
+
+ if (immediate_selection)
+ {
+ gtk_font_selection_real_select_font (data);
+ }
+ else
+ {
+ selection_timeout = g_timeout_add (200, gtk_font_selection_real_select_font, data);
+ g_object_set_data (G_OBJECT (fontsel), "font-selection-timeout", GUINT_TO_POINTER (selection_timeout));
+ }
}
static int
@@ -867,14 +924,20 @@ gtk_font_selection_select_best_style (GtkFontSelection *fontsel,
/* This is called when a style is selected in the list. */
-static void
-gtk_font_selection_select_style (GtkTreeSelection *selection,
- gpointer data)
+static gboolean
+gtk_font_selection_real_select_style (gpointer data)
{
- GtkFontSelection *fontsel = GTK_FONT_SELECTION (data);
+ GtkTreeSelection *selection;
+ GtkFontSelection *fontsel;
GtkTreeModel *model;
GtkTreeIter iter;
+ if (!g_object_get_data (G_OBJECT (data), "immediate-selection"))
+ GDK_THREADS_ENTER ();
+
+ fontsel = GTK_FONT_SELECTION (data);
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->face_list));
+
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
PangoFontFace *face;
@@ -887,6 +950,40 @@ gtk_font_selection_select_style (GtkTreeSelection *selection,
gtk_font_selection_show_available_sizes (fontsel, FALSE);
gtk_font_selection_select_best_size (fontsel);
+
+ g_object_set_data (G_OBJECT (fontsel), "style-selection-timeout", GUINT_TO_POINTER (0));
+
+ if (!g_object_get_data (G_OBJECT (fontsel), "immediate-selection"))
+ GDK_THREADS_LEAVE ();
+
+ /* Remove ourselves */
+ return FALSE;
+}
+
+static void
+gtk_font_selection_select_style (GtkTreeSelection *selection,
+ gpointer data)
+{
+ GtkFontSelection *fontsel;
+ guint selection_timeout = 0;
+ guint immediate_selection = 0;
+
+ fontsel = GTK_FONT_SELECTION (data);
+ selection_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (fontsel), "style-selection-timeout"));
+ immediate_selection = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (fontsel), "immediate-selection"));
+
+ if (selection_timeout)
+ g_source_remove (selection_timeout);
+
+ if (immediate_selection)
+ {
+ gtk_font_selection_real_select_style (data);
+ }
+ else
+ {
+ selection_timeout = g_timeout_add (200, gtk_font_selection_real_select_style, data);
+ g_object_set_data (G_OBJECT (fontsel), "style-selection-timeout", GUINT_TO_POINTER (selection_timeout));
+ }
}
static void
@@ -1019,22 +1116,60 @@ gtk_font_selection_size_focus_out (GtkWidget *w,
}
/* This is called when a size is selected in the list. */
-static void
-gtk_font_selection_select_size (GtkTreeSelection *selection,
- gpointer data)
+static gboolean
+gtk_font_selection_real_select_size (gpointer data)
{
+ GtkTreeSelection *selection;
GtkFontSelection *fontsel;
GtkTreeModel *model;
GtkTreeIter iter;
gint new_size;
+ if (!g_object_get_data (G_OBJECT (data), "immediate-selection"))
+ GDK_THREADS_ENTER ();
+
fontsel = GTK_FONT_SELECTION (data);
-
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->size_list));
+
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
gtk_tree_model_get (model, &iter, SIZE_COLUMN, &new_size, -1);
gtk_font_selection_set_size (fontsel, new_size * PANGO_SCALE);
}
+
+ g_object_set_data (G_OBJECT (fontsel), "size-selection-timeout", GUINT_TO_POINTER (0));
+
+ if (!g_object_get_data (G_OBJECT (fontsel), "immediate-selection"))
+ GDK_THREADS_LEAVE ();
+
+ /* Remove ourselves */
+ return FALSE;
+}
+
+static void
+gtk_font_selection_select_size (GtkTreeSelection *selection,
+ gpointer data)
+{
+ GtkFontSelection *fontsel;
+ guint selection_timeout = 0;
+ guint immediate_selection = 0;
+
+ fontsel = GTK_FONT_SELECTION (data);
+ selection_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (fontsel), "size-selection-timeout"));
+ immediate_selection = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (fontsel), "immediate-selection"));
+
+ if (selection_timeout)
+ g_source_remove (selection_timeout);
+
+ if (immediate_selection)
+ {
+ gtk_font_selection_real_select_size (data);
+ }
+ else
+ {
+ selection_timeout = g_timeout_add (200, gtk_font_selection_real_select_size, data);
+ g_object_set_data (G_OBJECT (fontsel), "size-selection-timeout", GUINT_TO_POINTER (selection_timeout));
+ }
}
static void
@@ -1218,6 +1353,9 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
if (!new_family)
return FALSE;
+ /* Disable selection timeout */
+ g_object_set_data (G_OBJECT (fontsel), "immediate-selection", GUINT_TO_POINTER (1));
+
fontsel->family = new_family;
set_cursor_to_iter (GTK_TREE_VIEW (fontsel->family_list), &iter);
gtk_font_selection_show_available_styles (fontsel);
@@ -1267,6 +1405,9 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
pango_font_description_free (new_desc);
+ /* Enable selection timeout */
+ g_object_set_data (G_OBJECT (fontsel), "immediate-selection", GUINT_TO_POINTER (0));
+
return TRUE;
}