Add gtk_window_set_icon_from_file(),

Mon Sep 30 14:28:58 2002  Owen Taylor  <otaylor@redhat.com>

        * gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(),
        gtk_window_set_default_icon_from_file() convenience
        functions (#75178, suggestion from Havoc Pennington)
This commit is contained in:
Owen Taylor 2002-09-30 18:58:27 +00:00 committed by Owen Taylor
parent 22e3d3b937
commit 41030b43c6
8 changed files with 133 additions and 1 deletions

View File

@ -1,3 +1,9 @@
Mon Sep 30 14:28:58 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(),
gtk_window_set_default_icon_from_file() convenience
functions (#75178, suggestion from Havoc Pennington)
2002-09-30 Daniel Elstner <daniel.elstner@gmx.net> 2002-09-30 Daniel Elstner <daniel.elstner@gmx.net>
* gtk/gtktextbuffer.c: Add construct-only property "tag_table" * gtk/gtktextbuffer.c: Add construct-only property "tag_table"

View File

@ -1,3 +1,9 @@
Mon Sep 30 14:28:58 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(),
gtk_window_set_default_icon_from_file() convenience
functions (#75178, suggestion from Havoc Pennington)
2002-09-30 Daniel Elstner <daniel.elstner@gmx.net> 2002-09-30 Daniel Elstner <daniel.elstner@gmx.net>
* gtk/gtktextbuffer.c: Add construct-only property "tag_table" * gtk/gtktextbuffer.c: Add construct-only property "tag_table"

View File

@ -1,3 +1,9 @@
Mon Sep 30 14:28:58 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(),
gtk_window_set_default_icon_from_file() convenience
functions (#75178, suggestion from Havoc Pennington)
2002-09-30 Daniel Elstner <daniel.elstner@gmx.net> 2002-09-30 Daniel Elstner <daniel.elstner@gmx.net>
* gtk/gtktextbuffer.c: Add construct-only property "tag_table" * gtk/gtktextbuffer.c: Add construct-only property "tag_table"

View File

@ -1,3 +1,9 @@
Mon Sep 30 14:28:58 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(),
gtk_window_set_default_icon_from_file() convenience
functions (#75178, suggestion from Havoc Pennington)
2002-09-30 Daniel Elstner <daniel.elstner@gmx.net> 2002-09-30 Daniel Elstner <daniel.elstner@gmx.net>
* gtk/gtktextbuffer.c: Add construct-only property "tag_table" * gtk/gtktextbuffer.c: Add construct-only property "tag_table"

View File

@ -1,3 +1,9 @@
Mon Sep 30 14:28:58 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(),
gtk_window_set_default_icon_from_file() convenience
functions (#75178, suggestion from Havoc Pennington)
2002-09-30 Daniel Elstner <daniel.elstner@gmx.net> 2002-09-30 Daniel Elstner <daniel.elstner@gmx.net>
* gtk/gtktextbuffer.c: Add construct-only property "tag_table" * gtk/gtktextbuffer.c: Add construct-only property "tag_table"

View File

@ -1,3 +1,9 @@
Mon Sep 30 14:28:58 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(),
gtk_window_set_default_icon_from_file() convenience
functions (#75178, suggestion from Havoc Pennington)
2002-09-30 Daniel Elstner <daniel.elstner@gmx.net> 2002-09-30 Daniel Elstner <daniel.elstner@gmx.net>
* gtk/gtktextbuffer.c: Add construct-only property "tag_table" * gtk/gtktextbuffer.c: Add construct-only property "tag_table"

View File

@ -2557,7 +2557,10 @@ gtk_window_set_icon (GtkWindow *window,
g_return_if_fail (icon == NULL || GDK_IS_PIXBUF (icon)); g_return_if_fail (icon == NULL || GDK_IS_PIXBUF (icon));
list = NULL; list = NULL;
list = g_list_append (list, icon);
if (icon)
list = g_list_append (list, icon);
gtk_window_set_icon_list (window, list); gtk_window_set_icon_list (window, list);
g_list_free (list); g_list_free (list);
} }
@ -2586,6 +2589,62 @@ gtk_window_get_icon (GtkWindow *window)
return NULL; return NULL;
} }
/* Load pixbuf, printing warning on failure if error == NULL
*/
static GdkPixbuf *
load_pixbuf_verbosely (const char *filename,
GError **err)
{
GError *local_err = NULL;
GdkPixbuf *pixbuf;
pixbuf = gdk_pixbuf_new_from_file (filename, &local_err);
if (!pixbuf)
{
if (err)
*err = local_err;
else
{
g_warning ("Error loading icon from file '%s':\n\t%s",
filename, local_err->message);
g_error_free (local_err);
}
}
return pixbuf;
}
/**
* gtk_window_set_icon_from_file:
* @window: a #GtkWindow
* @list: a list of #GdkPixbuf
* @err: location to store error, or %NULL.
*
* Sets the icon for @wi
* had gtk_window_set_icon_list() called on them as a single file.
* Warns on failure if @err is %NULL.
*
* Returns: %TRUE if setting the icon succeeded.
**/
gboolean
gtk_window_set_icon_from_file (GtkWindow *window,
const gchar *filename,
GError **err)
{
GdkPixbuf *pixbuf = load_pixbuf_verbosely (filename, err);
if (pixbuf)
{
gtk_window_set_icon (window, pixbuf);
g_object_unref (pixbuf);
return TRUE;
}
else
return FALSE;
}
/** /**
* gtk_window_set_default_icon_list: * gtk_window_set_default_icon_list:
* @list: a list of #GdkPixbuf * @list: a list of #GdkPixbuf
@ -2640,6 +2699,37 @@ gtk_window_set_default_icon_list (GList *list)
g_list_free (toplevels); g_list_free (toplevels);
} }
/**
* gtk_window_set_default_icon_from_file:
* @filename: location of icon file
* @err: location to store error, or %NULL.
*
* Sets an icon to be used as fallback for windows that haven't
* had gtk_window_set_icon_list() called on them from a file
* on disk. Warns on failure if @error is %NULL.
*
* Returns: %TRUE if setting the icon succeeded.
**/
gboolean
gtk_window_set_default_icon_from_file (const gchar *filename,
GError **err)
{
GdkPixbuf *pixbuf = load_pixbuf_verbosely (filename, err);
if (pixbuf)
{
GList *list = g_list_prepend (NULL, pixbuf);
gtk_window_set_default_icon_list (list);
g_list_free (list);
g_object_unref (pixbuf);
return TRUE;
}
else
return FALSE;
}
/** /**
* gtk_window_get_default_icon_list: * gtk_window_get_default_icon_list:
* *

View File

@ -246,9 +246,15 @@ void gtk_window_set_icon_list (GtkWindow *window,
GList* gtk_window_get_icon_list (GtkWindow *window); GList* gtk_window_get_icon_list (GtkWindow *window);
void gtk_window_set_icon (GtkWindow *window, void gtk_window_set_icon (GtkWindow *window,
GdkPixbuf *icon); GdkPixbuf *icon);
gboolean gtk_window_set_icon_from_file (GtkWindow *window,
const gchar *filename,
GError **err);
GdkPixbuf* gtk_window_get_icon (GtkWindow *window); GdkPixbuf* gtk_window_get_icon (GtkWindow *window);
void gtk_window_set_default_icon_list (GList *list); void gtk_window_set_default_icon_list (GList *list);
GList* gtk_window_get_default_icon_list (void); GList* gtk_window_get_default_icon_list (void);
gboolean gtk_window_set_default_icon_from_file (const gchar *filename,
GError **err);
/* If window is set modal, input will be grabbed when show and released when hide */ /* If window is set modal, input will be grabbed when show and released when hide */
void gtk_window_set_modal (GtkWindow *window, void gtk_window_set_modal (GtkWindow *window,