Bug 562506 - Use gtk_icon_theme_add_builtin_icon and gtk_window_set_icon_name for nsWindow::SetIcon with the GTK widget. r=karlt

--HG--
extra : rebase_source : d6f513b35dd4c1bc9fcd7d7609ccbe2bc4940c9e
This commit is contained in:
Jean-Alexandre Anglès d'Auriac 2011-12-14 11:22:15 +01:00
parent d1daf89bc9
commit 8d7ccfe650
2 changed files with 44 additions and 46 deletions

View File

@ -203,6 +203,8 @@ static void key_event_to_context_menu_event(nsMouseEvent &aEvent,
static int is_parent_ungrab_enter(GdkEventCrossing *aEvent);
static int is_parent_grab_leave(GdkEventCrossing *aEvent);
static void GetBrandName(nsXPIDLString& brandName);
/* callbacks from widgets */
#if defined(MOZ_WIDGET_GTK2)
static gboolean expose_event_cb (GtkWidget *widget,
@ -1846,39 +1848,63 @@ nsWindow::SetIcon(const nsAString& aIconSpec)
if (!mShell)
return NS_OK;
nsCAutoString iconName;
if (aIconSpec.EqualsLiteral("default")) {
nsXPIDLString brandName;
GetBrandName(brandName);
AppendUTF16toUTF8(brandName, iconName);
ToLowerCase(iconName);
} else {
AppendUTF16toUTF8(aIconSpec, iconName);
}
nsCOMPtr<nsILocalFile> iconFile;
nsCAutoString path;
nsTArray<nsCString> iconList;
// Look for icons with the following suffixes appended to the base name.
// The last two entries (for the old XPM format) will be ignored unless
// no icons are found using the other suffixes. XPM icons are depricated.
bool foundIcon = gtk_icon_theme_has_icon(gtk_icon_theme_get_default(),
iconName.get());
const char extensions[6][7] = { ".png", "16.png", "32.png", "48.png",
if (!foundIcon) {
// Look for icons with the following suffixes appended to the base name
// The last two entries (for the old XPM format) will be ignored unless
// no icons are found using other suffixes. XPM icons are deprecated.
const char extensions[6][7] = { ".png", "16.png", "32.png", "48.png",
".xpm", "16.xpm" };
for (PRUint32 i = 0; i < ArrayLength(extensions); i++) {
// Don't bother looking for XPM versions if we found a PNG.
if (i == ArrayLength(extensions) - 2 && iconList.Length())
break;
for (PRUint32 i = 0; i < ArrayLength(extensions); i++) {
// Don't bother looking for XPM versions if we found a PNG.
if (i == ArrayLength(extensions) - 2 && foundIcon)
break;
nsAutoString extension;
extension.AppendASCII(extensions[i]);
nsAutoString extension;
extension.AppendASCII(extensions[i]);
ResolveIconName(aIconSpec, extension, getter_AddRefs(iconFile));
if (iconFile) {
iconFile->GetNativePath(path);
iconList.AppendElement(path);
ResolveIconName(aIconSpec, extension, getter_AddRefs(iconFile));
if (iconFile) {
iconFile->GetNativePath(path);
GdkPixbuf *icon = gdk_pixbuf_new_from_file(path.get(), NULL);
if (icon){
gtk_icon_theme_add_builtin_icon(iconName.get(),
gdk_pixbuf_get_height(icon),
icon);
g_object_unref(icon);
foundIcon = true;
}
}
}
}
// leave the default icon intact if no matching icons were found
if (iconList.Length() == 0)
return NS_OK;
if (foundIcon) {
gtk_window_set_icon_name(GTK_WINDOW(mShell), iconName.get());
}
return SetWindowIconList(iconList);
return NS_OK;
}
nsIntPoint
nsWindow::WidgetToScreenOffset()
{
@ -5145,33 +5171,6 @@ nsWindow::SetupPluginPort(void)
return (void *)window;
}
nsresult
nsWindow::SetWindowIconList(const nsTArray<nsCString> &aIconList)
{
GList *list = NULL;
for (PRUint32 i = 0; i < aIconList.Length(); ++i) {
const char *path = aIconList[i].get();
LOG(("window [%p] Loading icon from %s\n", (void *)this, path));
GdkPixbuf *icon = gdk_pixbuf_new_from_file(path, NULL);
if (!icon)
continue;
list = g_list_append(list, icon);
}
if (!list)
return NS_ERROR_FAILURE;
gtk_window_set_icon_list(GTK_WINDOW(mShell), list);
g_list_foreach(list, (GFunc) g_object_unref, NULL);
g_list_free(list);
return NS_OK;
}
void
nsWindow::SetDefaultIcon(void)
{

View File

@ -385,7 +385,6 @@ private:
nsWindow *GetContainerWindow();
void SetUrgencyHint(GtkWidget *top_window, bool state);
void *SetupPluginPort(void);
nsresult SetWindowIconList(const nsTArray<nsCString> &aIconList);
void SetDefaultIcon(void);
void InitButtonEvent(nsMouseEvent &aEvent, GdkEventButton *aGdkEvent);
bool DispatchCommandEvent(nsIAtom* aCommand);