When finding a matching non-scalable dir, keep going and look for a closer

2007-01-14  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtkicontheme.c (theme_lookup_icon): When finding a matching
        non-scalable dir, keep going and look for a closer match.
        (#395830, Luca Ferretti)


svn path=/trunk/; revision=17153
This commit is contained in:
Matthias Clasen 2007-01-15 02:56:33 +00:00 committed by Matthias Clasen
parent 6400dda3a0
commit 82ef0d0d2a
2 changed files with 60 additions and 29 deletions

View File

@ -1,3 +1,9 @@
2007-01-14 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkicontheme.c (theme_lookup_icon): When finding a matching
non-scalable dir, keep going and look for a closer match.
(#395830, Luca Ferretti)
2007-01-14 Christian Persch <chpe@svn.gnome.org> 2007-01-14 Christian Persch <chpe@svn.gnome.org>
* gtk/gtkclipboard.c: (gtk_clipboard_set_text), * gtk/gtkclipboard.c: (gtk_clipboard_set_text),

View File

@ -1873,12 +1873,13 @@ theme_lookup_icon (IconTheme *theme,
char *file; char *file;
int min_difference, difference; int min_difference, difference;
BuiltinIcon *closest_builtin = NULL; BuiltinIcon *closest_builtin = NULL;
gboolean smaller, has_larger; gboolean smaller, has_larger, match;
IconSuffix suffix; IconSuffix suffix;
min_difference = G_MAXINT; min_difference = G_MAXINT;
min_dir = NULL; min_dir = NULL;
has_larger = FALSE; has_larger = FALSE;
match = FALSE;
/* Builtin icons are logically part of the default theme and /* Builtin icons are logically part of the default theme and
* are searched before other subdirectories of the default theme. * are searched before other subdirectories of the default theme.
@ -1912,31 +1913,55 @@ theme_lookup_icon (IconTheme *theme,
if (difference == 0) if (difference == 0)
{ {
min_dir = dir; if (dir->type == ICON_THEME_DIR_SCALABLE)
break; {
/* don't pick scalable if we already found
* a matching non-scalable dir
*/
if (!match)
{
min_dir = dir;
break;
}
}
else
{
/* for a matching non-scalable dir keep
* going and look for a closer match
*/
difference = abs (size - dir->size);
if (!match || difference < min_difference)
{
match = TRUE;
min_difference = difference;
min_dir = dir;
}
if (difference == 0)
break;
}
}
if (!match)
{
if (!has_larger)
{
if (difference < min_difference || smaller)
{
min_difference = difference;
min_dir = dir;
has_larger = smaller;
}
}
else
{
if (difference < min_difference && smaller)
{
min_difference = difference;
min_dir = dir;
}
}
} }
}
if (!has_larger)
{
if (difference < min_difference || smaller)
{
min_difference = difference;
min_dir = dir;
closest_builtin = NULL;
has_larger = smaller;
}
}
else
{
if (difference < min_difference && smaller)
{
min_difference = difference;
min_dir = dir;
closest_builtin = NULL;
}
}
}
l = l->next; l = l->next;
@ -1947,9 +1972,6 @@ theme_lookup_icon (IconTheme *theme,
} }
} }
if (closest_builtin)
return icon_info_new_builtin (closest_builtin);
if (min_dir) if (min_dir)
{ {
GtkIconInfo *icon_info = icon_info_new (); GtkIconInfo *icon_info = icon_info_new ();
@ -2015,7 +2037,10 @@ theme_lookup_icon (IconTheme *theme,
return icon_info; return icon_info;
} }
if (closest_builtin)
return icon_info_new_builtin (closest_builtin);
return NULL; return NULL;
} }