diff options
author | Owen Taylor <otaylor@redhat.com> | 2002-02-18 23:43:25 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2002-02-18 23:43:25 +0000 |
commit | c3940d4a07a6855998e1d991afeb92f3253bef56 (patch) | |
tree | 3732261e1dd8be747f7458d2f213d90d39fe6b16 /gtk/gtkfontsel.c | |
parent | 911700a37ec8ec3dd8fe94f883a32f4329624de0 (diff) | |
download | gdk-pixbuf-c3940d4a07a6855998e1d991afeb92f3253bef56.tar.gz |
Select the right item in the family list. (Reported by Mark Patton, Patch
Mon Feb 18 18:27:45 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkfontsel.c (gtk_font_selection_set_font_name): Select
the right item in the family list. (Reported by Mark Patton,
Patch from Satajyit Kanungo, #64240)
* gtk/gtkfontsel.c (gtk_font_selection_set_font_name): Update
the size and face entry lists as well, fix memory leak.
(Also #64240)
* gtk/gtkfontsel.c (gtk_font_selection_show_available_sizes):
Allow fractional sizes, unselect the selected row if none
matches.
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_focus): Fix
a bug where the scrolled window would always get focus
when focusing out of the child.
Diffstat (limited to 'gtk/gtkfontsel.c')
-rw-r--r-- | gtk/gtkfontsel.c | 92 |
1 files changed, 63 insertions, 29 deletions
diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontsel.c index 62f7b8665..05fb49415 100644 --- a/gtk/gtkfontsel.c +++ b/gtk/gtkfontsel.c @@ -824,7 +824,8 @@ gtk_font_selection_show_available_sizes (GtkFontSelection *fontsel, GtkListStore *model; GtkTreeSelection *selection; gchar buffer[128]; - + gchar *p; + model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->size_list))); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->size_list)); @@ -847,20 +848,44 @@ gtk_font_selection_show_available_sizes (GtkFontSelection *fontsel, else { GtkTreeIter iter; + gboolean found = FALSE; gtk_tree_model_get_iter_root (GTK_TREE_MODEL (model), &iter); - for (i = 0; i < G_N_ELEMENTS (font_sizes); i++) + for (i = 0; i < G_N_ELEMENTS (font_sizes) && !found; i++) { if (font_sizes[i] * PANGO_SCALE == fontsel->size) - set_cursor_to_iter (GTK_TREE_VIEW (fontsel->size_list), &iter); + { + set_cursor_to_iter (GTK_TREE_VIEW (fontsel->size_list), &iter); + found = TRUE; + } gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter); } - + + if (!found) + { + GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->size_list)); + gtk_tree_selection_unselect_all (selection); + } + } + + /* Set the entry to the new size, rounding to 1 digit, + * trimming of trailing 0's and a trailing period + */ + sprintf (buffer, "%.1f", fontsel->size / (1.0 * PANGO_SCALE)); + if (strchr (buffer, '.')) + { + p = buffer + strlen (buffer) - 1; + while (*p == '0') + p--; + if (*p == '.') + p--; + p[1] = '\0'; } - sprintf (buffer, "%i", fontsel->size / PANGO_SCALE); - gtk_entry_set_text (GTK_ENTRY (fontsel->size_entry), buffer); + /* Compare, to avoid moving the cursor unecessarily */ + if (strcmp (gtk_entry_get_text (GTK_ENTRY (fontsel->size_entry)), buffer) != 0) + gtk_entry_set_text (GTK_ENTRY (fontsel->size_entry), buffer); } static void @@ -869,6 +894,19 @@ gtk_font_selection_select_best_size (GtkFontSelection *fontsel) gtk_font_selection_load_font (fontsel); } +static void +gtk_font_selection_set_size (GtkFontSelection *fontsel, + gint new_size) +{ + if (fontsel->size != new_size) + { + fontsel->size = new_size; + + gtk_font_selection_show_available_sizes (fontsel, FALSE); + gtk_font_selection_load_font (fontsel); + } +} + /* If the user hits return in the font size entry, we change to the new font size. */ static void @@ -882,13 +920,9 @@ gtk_font_selection_size_activate (GtkWidget *w, fontsel = GTK_FONT_SELECTION (data); text = gtk_entry_get_text (GTK_ENTRY (fontsel->size_entry)); - new_size = atoi (text) * PANGO_SCALE; - - if (fontsel->size != new_size) - { - fontsel->size = new_size; - gtk_font_selection_load_font (fontsel); - } + new_size = MAX (0.1, atof (text) * PANGO_SCALE + 0.5); + + gtk_font_selection_set_size (fontsel, new_size); } /* This is called when a size is selected in the list. */ @@ -900,25 +934,13 @@ gtk_font_selection_select_size (GtkTreeSelection *selection, GtkTreeModel *model; GtkTreeIter iter; gint new_size; - gchar buffer[128]; fontsel = GTK_FONT_SELECTION (data); if (gtk_tree_selection_get_selected (selection, &model, &iter)) { gtk_tree_model_get (model, &iter, SIZE_COLUMN, &new_size, -1); - new_size *= PANGO_SCALE; - - if (fontsel->size != new_size) - { - /* If the size was selected by the user we set the selected_size. */ - fontsel->size = new_size; - - sprintf (buffer, "%i", fontsel->size / PANGO_SCALE); - gtk_entry_set_text (GTK_ENTRY (fontsel->size_entry), buffer); - - gtk_font_selection_load_font (fontsel); - } + gtk_font_selection_set_size (fontsel, new_size * PANGO_SCALE); } } @@ -1025,6 +1047,7 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel, PangoFontDescription *new_desc; GtkTreeModel *model; GtkTreeIter iter; + GtkTreeIter match_iter; gboolean valid; g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE); @@ -1056,6 +1079,7 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel, return FALSE; fontsel->family = new_family; + set_cursor_to_iter (GTK_TREE_VIEW (fontsel->family_list), &iter); gtk_font_selection_show_available_styles (fontsel); model = gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->face_list)); @@ -1073,26 +1097,36 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel, new_face = face; if (!fallback_face) - fallback_face = face; + { + fallback_face = face; + match_iter = iter; + } pango_font_description_free (tmp_desc); g_object_unref (face); if (new_face) - break; + { + match_iter = iter; + break; + } } if (!new_face) new_face = fallback_face; fontsel->face = new_face; - gtk_font_selection_select_best_size (fontsel); + set_cursor_to_iter (GTK_TREE_VIEW (fontsel->face_list), &match_iter); + gtk_font_selection_set_size (fontsel, pango_font_description_get_size (new_desc)); + g_object_freeze_notify (G_OBJECT (fontsel)); g_object_notify (G_OBJECT (fontsel), "font_name"); g_object_notify (G_OBJECT (fontsel), "font"); g_object_thaw_notify (G_OBJECT (fontsel)); + pango_font_description_free (new_desc); + return TRUE; } |