2008-01-05 05:24:38 +00:00
|
|
|
/*
|
2010-05-02 10:47:51 +00:00
|
|
|
Copyright (C) 2007-2010 Christian Dywan <christian@twotoasts.de>
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
See the file COPYING for the full license text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "katze-throbber.h"
|
|
|
|
|
2008-08-05 03:03:05 +00:00
|
|
|
#include "katze-utils.h"
|
|
|
|
|
2008-03-22 02:38:23 +00:00
|
|
|
#include <glib/gi18n.h>
|
2008-10-30 21:17:19 +00:00
|
|
|
#include <math.h>
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2010-05-02 10:47:51 +00:00
|
|
|
#define HAVE_SPINNER GTK_CHECK_VERSION (2, 20, 0)
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
struct _KatzeThrobber
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
2010-05-02 10:47:51 +00:00
|
|
|
#if HAVE_SPINNER
|
|
|
|
GtkSpinner parent_instance;
|
|
|
|
#else
|
2008-06-12 21:44:34 +00:00
|
|
|
GtkMisc parent_instance;
|
2010-05-02 10:47:51 +00:00
|
|
|
#endif
|
2008-06-12 21:44:34 +00:00
|
|
|
|
2008-01-05 05:24:38 +00:00
|
|
|
GtkIconSize icon_size;
|
|
|
|
gchar* icon_name;
|
|
|
|
GdkPixbuf* pixbuf;
|
|
|
|
gchar* stock_id;
|
|
|
|
gboolean animated;
|
|
|
|
gchar* static_icon_name;
|
|
|
|
GdkPixbuf* static_pixbuf;
|
|
|
|
gchar* static_stock_id;
|
|
|
|
|
|
|
|
gint index;
|
|
|
|
gint timer_id;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
};
|
|
|
|
|
2010-05-02 10:47:51 +00:00
|
|
|
struct _KatzeThrobberClass
|
|
|
|
{
|
|
|
|
#if HAVE_SPINNER
|
|
|
|
GtkSpinnerClass parent_class;
|
|
|
|
#else
|
|
|
|
GtkMiscClass parent_class;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#if HAVE_SPINNER
|
|
|
|
G_DEFINE_TYPE (KatzeThrobber, katze_throbber, GTK_TYPE_SPINNER);
|
|
|
|
#else
|
2009-01-15 02:26:15 +00:00
|
|
|
G_DEFINE_TYPE (KatzeThrobber, katze_throbber, GTK_TYPE_MISC);
|
2010-05-02 10:47:51 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_ICON_SIZE,
|
|
|
|
PROP_ICON_NAME,
|
|
|
|
PROP_PIXBUF,
|
|
|
|
PROP_ANIMATED,
|
|
|
|
PROP_STATIC_ICON_NAME,
|
|
|
|
PROP_STATIC_PIXBUF,
|
|
|
|
PROP_STATIC_STOCK_ID
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2008-10-15 01:32:11 +00:00
|
|
|
katze_throbber_dispose (GObject* object);
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_set_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue* value,
|
|
|
|
GParamSpec* pspec);
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_get_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue* value,
|
|
|
|
GParamSpec* pspec);
|
|
|
|
|
|
|
|
static void
|
2011-10-01 13:12:04 +00:00
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
katze_throbber_destroy (GtkWidget* object);
|
|
|
|
#else
|
2008-01-05 05:24:38 +00:00
|
|
|
katze_throbber_destroy (GtkObject* object);
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_realize (GtkWidget* widget);
|
|
|
|
|
2011-10-01 13:12:04 +00:00
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
static void
|
|
|
|
katze_throbber_get_preferred_height (GtkWidget *widget,
|
2012-02-29 21:41:59 +00:00
|
|
|
gint *minimal_height,
|
|
|
|
gint *natural_height);
|
2011-10-01 13:12:04 +00:00
|
|
|
static void
|
|
|
|
katze_throbber_get_preferred_width (GtkWidget *widget,
|
2012-02-29 21:41:59 +00:00
|
|
|
gint *minimal_width,
|
|
|
|
gint *natural_width);
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
static void
|
|
|
|
katze_throbber_unrealize (GtkWidget* widget);
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_map (GtkWidget* widget);
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_unmap (GtkWidget* widget);
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_style_set (GtkWidget* widget,
|
|
|
|
GtkStyle* style);
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_screen_changed (GtkWidget* widget,
|
|
|
|
GdkScreen* screen_prev);
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_size_request (GtkWidget* widget,
|
|
|
|
GtkRequisition* requisition);
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
katze_throbber_expose_event (GtkWidget* widget,
|
2011-10-01 13:12:04 +00:00
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
cairo_t* cr);
|
|
|
|
#else
|
2008-01-05 05:24:38 +00:00
|
|
|
GdkEventExpose* event);
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
icon_theme_changed (KatzeThrobber* throbber);
|
|
|
|
|
2010-05-02 10:47:51 +00:00
|
|
|
#if !HAVE_SPINNER
|
2008-01-05 05:24:38 +00:00
|
|
|
static gboolean
|
|
|
|
katze_throbber_timeout (KatzeThrobber* throbber);
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_timeout_destroy (KatzeThrobber* throbber);
|
2010-05-02 10:47:51 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_class_init (KatzeThrobberClass* class)
|
|
|
|
{
|
2010-01-29 20:10:05 +00:00
|
|
|
GObjectClass* gobject_class;
|
2011-10-01 13:12:04 +00:00
|
|
|
#if !GTK_CHECK_VERSION (3, 0, 0)
|
2010-01-29 20:10:05 +00:00
|
|
|
GtkObjectClass* object_class;
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2010-01-29 20:10:05 +00:00
|
|
|
GtkWidgetClass* widget_class;
|
|
|
|
GParamFlags flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (class);
|
2008-01-05 05:24:38 +00:00
|
|
|
gobject_class->dispose = katze_throbber_dispose;
|
|
|
|
gobject_class->set_property = katze_throbber_set_property;
|
|
|
|
gobject_class->get_property = katze_throbber_get_property;
|
|
|
|
|
2011-10-01 13:12:04 +00:00
|
|
|
widget_class = GTK_WIDGET_CLASS (class);
|
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
widget_class->destroy = katze_throbber_destroy;
|
|
|
|
#else
|
2010-01-29 20:10:05 +00:00
|
|
|
object_class = GTK_OBJECT_CLASS (class);
|
2008-01-05 05:24:38 +00:00
|
|
|
object_class->destroy = katze_throbber_destroy;
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
widget_class->realize = katze_throbber_realize;
|
|
|
|
widget_class->unrealize = katze_throbber_unrealize;
|
|
|
|
widget_class->map = katze_throbber_map;
|
|
|
|
widget_class->unmap = katze_throbber_unmap;
|
|
|
|
widget_class->style_set = katze_throbber_style_set;
|
|
|
|
widget_class->screen_changed = katze_throbber_screen_changed;
|
2011-10-01 13:12:04 +00:00
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
widget_class->get_preferred_width= katze_throbber_get_preferred_width;
|
|
|
|
widget_class->get_preferred_height= katze_throbber_get_preferred_height;
|
|
|
|
#else
|
2008-01-05 05:24:38 +00:00
|
|
|
widget_class->size_request = katze_throbber_size_request;
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
widget_class->draw = katze_throbber_expose_event;
|
|
|
|
#else
|
2008-01-05 05:24:38 +00:00
|
|
|
widget_class->expose_event = katze_throbber_expose_event;
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ICON_SIZE,
|
|
|
|
g_param_spec_int (
|
|
|
|
"icon-size",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Icon size",
|
|
|
|
"Symbolic size to use for the animation",
|
2008-01-05 05:24:38 +00:00
|
|
|
0, G_MAXINT, GTK_ICON_SIZE_MENU,
|
|
|
|
flags));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ICON_NAME,
|
|
|
|
g_param_spec_string (
|
|
|
|
"icon-name",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Icon Name",
|
|
|
|
"The name of an icon containing animation frames",
|
2008-01-05 05:24:38 +00:00
|
|
|
"process-working",
|
|
|
|
flags));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_PIXBUF,
|
|
|
|
g_param_spec_object (
|
|
|
|
"pixbuf",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Pixbuf",
|
|
|
|
"A GdkPixbuf containing animation frames",
|
2008-01-05 05:24:38 +00:00
|
|
|
GDK_TYPE_PIXBUF,
|
2008-04-13 09:29:21 +00:00
|
|
|
G_PARAM_READWRITE));
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ANIMATED,
|
|
|
|
g_param_spec_boolean (
|
|
|
|
"animated",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Animated",
|
|
|
|
"Whether the throbber should be animated",
|
2008-01-05 05:24:38 +00:00
|
|
|
FALSE,
|
|
|
|
flags));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_STATIC_ICON_NAME,
|
|
|
|
g_param_spec_string (
|
|
|
|
"static-icon-name",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Static Icon Name",
|
|
|
|
"The name of an icon to be used as the static image",
|
2008-01-05 05:24:38 +00:00
|
|
|
NULL,
|
|
|
|
flags));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_PIXBUF,
|
|
|
|
g_param_spec_object (
|
|
|
|
"static-pixbuf",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Static Pixbuf",
|
|
|
|
"A GdkPixbuf to be used as the static image",
|
2008-01-05 05:24:38 +00:00
|
|
|
GDK_TYPE_PIXBUF,
|
2008-04-13 09:29:21 +00:00
|
|
|
G_PARAM_READWRITE));
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_STATIC_STOCK_ID,
|
|
|
|
g_param_spec_string (
|
|
|
|
"static-stock-id",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Static Stock ID",
|
|
|
|
"The stock ID of an icon to be used as the static image",
|
2008-01-05 05:24:38 +00:00
|
|
|
NULL,
|
|
|
|
flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_init (KatzeThrobber *throbber)
|
|
|
|
{
|
2010-02-19 16:05:54 +00:00
|
|
|
gtk_widget_set_has_window (GTK_WIDGET (throbber), FALSE);
|
2010-05-02 10:47:51 +00:00
|
|
|
#if !HAVE_SPINNER
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (throbber), 0.0, 0.5);
|
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
throbber->timer_id = -1;
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-04-13 09:29:21 +00:00
|
|
|
katze_throbber_dispose (GObject* object)
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
|
|
|
KatzeThrobber* throbber = KATZE_THROBBER (object);
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
if (G_UNLIKELY (throbber->timer_id >= 0))
|
|
|
|
g_source_remove (throbber->timer_id);
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
(*G_OBJECT_CLASS (katze_throbber_parent_class)->dispose) (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-10-01 13:12:04 +00:00
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
katze_throbber_destroy (GtkWidget* object)
|
|
|
|
#else
|
2008-04-13 09:29:21 +00:00
|
|
|
katze_throbber_destroy (GtkObject* object)
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
|
|
|
KatzeThrobber* throbber = KATZE_THROBBER (object);
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
katze_assign (throbber->icon_name, NULL);
|
|
|
|
katze_object_assign (throbber->pixbuf, NULL);
|
|
|
|
katze_assign (throbber->static_icon_name, NULL);
|
|
|
|
katze_object_assign (throbber->static_pixbuf, NULL);
|
|
|
|
katze_assign (throbber->static_stock_id, NULL);
|
2011-10-01 13:12:04 +00:00
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
GTK_WIDGET_CLASS (katze_throbber_parent_class)->destroy (object);
|
|
|
|
#else
|
2008-01-05 05:24:38 +00:00
|
|
|
GTK_OBJECT_CLASS (katze_throbber_parent_class)->destroy (object);
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_set_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue* value,
|
|
|
|
GParamSpec* pspec)
|
|
|
|
{
|
|
|
|
KatzeThrobber* throbber = KATZE_THROBBER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_ICON_SIZE:
|
|
|
|
katze_throbber_set_icon_size (throbber, g_value_get_int (value));
|
|
|
|
break;
|
|
|
|
case PROP_ICON_NAME:
|
|
|
|
katze_throbber_set_icon_name (throbber, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
case PROP_PIXBUF:
|
|
|
|
katze_throbber_set_pixbuf (throbber, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
case PROP_ANIMATED:
|
|
|
|
katze_throbber_set_animated (throbber, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
case PROP_STATIC_ICON_NAME:
|
|
|
|
katze_throbber_set_static_icon_name (throbber, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
case PROP_STATIC_PIXBUF:
|
|
|
|
katze_throbber_set_static_pixbuf (throbber, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
case PROP_STATIC_STOCK_ID:
|
|
|
|
katze_throbber_set_static_stock_id (throbber, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-08-02 02:21:38 +00:00
|
|
|
katze_throbber_get_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue* value,
|
|
|
|
GParamSpec* pspec)
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
|
|
|
KatzeThrobber* throbber = KATZE_THROBBER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_ICON_SIZE:
|
|
|
|
g_value_set_int (value, katze_throbber_get_icon_size (throbber));
|
|
|
|
break;
|
|
|
|
case PROP_ICON_NAME:
|
|
|
|
g_value_set_string (value, katze_throbber_get_icon_name (throbber));
|
|
|
|
break;
|
|
|
|
case PROP_PIXBUF:
|
|
|
|
g_value_set_object (value, katze_throbber_get_pixbuf (throbber));
|
|
|
|
break;
|
|
|
|
case PROP_ANIMATED:
|
|
|
|
g_value_set_boolean (value, katze_throbber_get_animated (throbber));
|
|
|
|
break;
|
|
|
|
case PROP_STATIC_ICON_NAME:
|
|
|
|
g_value_set_string (value, katze_throbber_get_static_icon_name (throbber));
|
|
|
|
break;
|
|
|
|
case PROP_STATIC_PIXBUF:
|
|
|
|
g_value_set_object (value, katze_throbber_get_static_pixbuf (throbber));
|
|
|
|
break;
|
|
|
|
case PROP_STATIC_STOCK_ID:
|
|
|
|
g_value_set_string (value, katze_throbber_get_static_stock_id (throbber));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_new:
|
|
|
|
*
|
|
|
|
* Creates a new throbber widget.
|
|
|
|
*
|
|
|
|
* Return value: a new #KatzeThrobber
|
|
|
|
**/
|
|
|
|
GtkWidget*
|
|
|
|
katze_throbber_new (void)
|
|
|
|
{
|
|
|
|
KatzeThrobber* throbber = g_object_new (KATZE_TYPE_THROBBER,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return GTK_WIDGET (throbber);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_set_icon_size:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
* @icon_size: the new icon size
|
|
|
|
*
|
|
|
|
* Sets the desired size of the throbber image. The animation and static image
|
|
|
|
* will be displayed in this size. If a pixbuf is used for the animation every
|
|
|
|
* single frame is assumed to have this size.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
katze_throbber_set_icon_size (KatzeThrobber* throbber,
|
|
|
|
GtkIconSize icon_size)
|
|
|
|
{
|
2008-08-02 02:21:38 +00:00
|
|
|
GtkSettings* gtk_settings;
|
|
|
|
|
2008-01-05 05:24:38 +00:00
|
|
|
g_return_if_fail (KATZE_IS_THROBBER (throbber));
|
2008-08-02 02:21:38 +00:00
|
|
|
gtk_settings = gtk_widget_get_settings (GTK_WIDGET (throbber));
|
|
|
|
g_return_if_fail (gtk_icon_size_lookup_for_settings (gtk_settings,
|
|
|
|
icon_size,
|
|
|
|
&throbber->width,
|
|
|
|
&throbber->height));
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
throbber->icon_size = icon_size;
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (throbber), "icon-size");
|
2008-08-02 02:21:38 +00:00
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (throbber));
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_set_icon_name:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
* @icon_name: an icon name or %NULL
|
|
|
|
*
|
|
|
|
* Sets the name of an icon that should provide the animation frames.
|
|
|
|
*
|
|
|
|
* The pixbuf is automatically invalidated.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
katze_throbber_set_icon_name (KatzeThrobber* throbber,
|
|
|
|
const gchar* icon_name)
|
|
|
|
{
|
|
|
|
g_return_if_fail (KATZE_IS_THROBBER (throbber));
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
katze_assign (throbber->icon_name, g_strdup (icon_name));
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
if (icon_name)
|
|
|
|
icon_theme_changed (throbber);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (throbber), "icon-name");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_set_pixbuf:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
* @pixbuf: a #GdkPixbuf or %NULL
|
|
|
|
*
|
|
|
|
* Sets the pixbuf that should provide the animation frames. Every frame
|
|
|
|
* is assumed to have the icon size of the throbber, which can be specified
|
|
|
|
* with katze_throbber_set_icon_size ().
|
|
|
|
*
|
|
|
|
* The icon name is automatically invalidated.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
katze_throbber_set_pixbuf (KatzeThrobber* throbber,
|
2008-01-20 17:05:16 +00:00
|
|
|
GdkPixbuf* pixbuf)
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (KATZE_IS_THROBBER (throbber));
|
2008-08-02 02:21:38 +00:00
|
|
|
g_return_if_fail (!pixbuf || GDK_IS_PIXBUF (pixbuf));
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
katze_object_assign (throbber->pixbuf, pixbuf);
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_freeze_notify (G_OBJECT (throbber));
|
|
|
|
|
2008-01-05 05:24:38 +00:00
|
|
|
if (pixbuf)
|
|
|
|
{
|
|
|
|
g_object_ref (pixbuf);
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
katze_assign (throbber->icon_name, NULL);
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_notify (G_OBJECT (throbber), "icon-name");
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (throbber));
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (throbber), "pixbuf");
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_thaw_notify (G_OBJECT (throbber));
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_set_animated:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
* @animated: %TRUE to animate the throbber
|
|
|
|
*
|
|
|
|
* Sets the animation state of the throbber.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
katze_throbber_set_animated (KatzeThrobber* throbber,
|
|
|
|
gboolean animated)
|
|
|
|
{
|
|
|
|
g_return_if_fail (KATZE_IS_THROBBER (throbber));
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
if (G_UNLIKELY (throbber->animated == animated))
|
2008-01-05 05:24:38 +00:00
|
|
|
return;
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
throbber->animated = animated;
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2010-05-02 10:47:51 +00:00
|
|
|
#if HAVE_SPINNER
|
|
|
|
g_object_set (throbber, "active", animated, NULL);
|
|
|
|
#else
|
2008-06-12 21:44:34 +00:00
|
|
|
if (animated && (throbber->timer_id < 0))
|
|
|
|
throbber->timer_id = g_timeout_add_full (
|
2008-01-05 05:24:38 +00:00
|
|
|
G_PRIORITY_LOW, 50,
|
|
|
|
(GSourceFunc)katze_throbber_timeout,
|
|
|
|
throbber,
|
|
|
|
(GDestroyNotify)katze_throbber_timeout_destroy);
|
2010-05-02 10:47:51 +00:00
|
|
|
#endif
|
2012-02-11 03:19:23 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (throbber));
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (throbber), "animated");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_set_static_icon_name:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
* @icon_name: an icon name or %NULL
|
|
|
|
*
|
|
|
|
* Sets the name of an icon that should provide the static image.
|
|
|
|
*
|
|
|
|
* The static pixbuf and stock ID are automatically invalidated.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
katze_throbber_set_static_icon_name (KatzeThrobber* throbber,
|
|
|
|
const gchar* icon_name)
|
|
|
|
{
|
|
|
|
g_return_if_fail (KATZE_IS_THROBBER (throbber));
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
katze_assign (throbber->static_icon_name, g_strdup (icon_name));
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_freeze_notify (G_OBJECT (throbber));
|
|
|
|
|
2008-01-05 05:24:38 +00:00
|
|
|
if (icon_name)
|
|
|
|
{
|
2008-06-12 21:44:34 +00:00
|
|
|
katze_assign (throbber->static_stock_id, NULL);
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
icon_theme_changed (throbber);
|
2008-08-02 02:21:38 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (throbber), "static-pixbuf");
|
|
|
|
g_object_notify (G_OBJECT (throbber), "static-stock-id");
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (throbber), "static-icon-name");
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_thaw_notify (G_OBJECT (throbber));
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_set_static_pixbuf:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
* @pixbuf: a #GdkPixbuf or %NULL
|
|
|
|
*
|
|
|
|
* Sets the pixbuf that should provide the static image. The pixbuf is
|
|
|
|
* assumed to have the icon size of the throbber, which can be specified
|
|
|
|
* with katze_throbber_set_icon_size ().
|
|
|
|
*
|
|
|
|
* The static icon name and stock ID are automatically invalidated.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
katze_throbber_set_static_pixbuf (KatzeThrobber* throbber,
|
2008-01-20 17:05:16 +00:00
|
|
|
GdkPixbuf* pixbuf)
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (KATZE_IS_THROBBER (throbber));
|
|
|
|
g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
katze_object_assign (throbber->static_pixbuf, pixbuf);
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_freeze_notify (G_OBJECT (throbber));
|
|
|
|
|
2008-01-05 05:24:38 +00:00
|
|
|
if (pixbuf)
|
|
|
|
{
|
|
|
|
g_object_ref (pixbuf);
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
katze_assign (throbber->static_icon_name, NULL);
|
|
|
|
katze_assign (throbber->static_stock_id, NULL);
|
2008-08-02 02:21:38 +00:00
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (throbber));
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (throbber), "static-icon-name");
|
|
|
|
g_object_notify (G_OBJECT (throbber), "static-stock-id");
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (throbber), "static-pixbuf");
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_thaw_notify (G_OBJECT (throbber));
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_set_static_stock_id:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
* @stock_id: a stock ID or %NULL
|
|
|
|
*
|
|
|
|
* Sets the stock ID of an icon that should provide the static image.
|
|
|
|
*
|
2008-08-02 02:21:38 +00:00
|
|
|
* The static icon name and pixbuf are automatically invalidated.
|
2008-01-05 05:24:38 +00:00
|
|
|
**/
|
|
|
|
void
|
2008-08-02 02:21:38 +00:00
|
|
|
katze_throbber_set_static_stock_id (KatzeThrobber* throbber,
|
|
|
|
const gchar* stock_id)
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (KATZE_IS_THROBBER (throbber));
|
|
|
|
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_freeze_notify (G_OBJECT (throbber));
|
|
|
|
|
2008-01-05 05:24:38 +00:00
|
|
|
if (stock_id)
|
|
|
|
{
|
|
|
|
GtkStockItem stock_item;
|
|
|
|
g_return_if_fail (gtk_stock_lookup (stock_id, &stock_item));
|
2008-08-02 02:21:38 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (throbber), "static-icon-name");
|
|
|
|
g_object_notify (G_OBJECT (throbber), "static-pixbuf");
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
katze_assign (throbber->static_stock_id, g_strdup (stock_id));
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
if (stock_id)
|
|
|
|
icon_theme_changed (throbber);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (throbber), "static-stock-id");
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_thaw_notify (G_OBJECT (throbber));
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_get_icon_size:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
*
|
|
|
|
* Retrieves the size of the throbber.
|
|
|
|
*
|
|
|
|
* Return value: the size of the throbber
|
|
|
|
**/
|
|
|
|
GtkIconSize
|
|
|
|
katze_throbber_get_icon_size (KatzeThrobber* throbber)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (KATZE_IS_THROBBER (throbber), GTK_ICON_SIZE_INVALID);
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
return throbber->icon_size;
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_get_icon_name:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
*
|
|
|
|
* Retrieves the name of the icon providing the animation frames.
|
|
|
|
*
|
|
|
|
* Return value: the name of the icon providing the animation frames, or %NULL
|
|
|
|
**/
|
|
|
|
const gchar*
|
|
|
|
katze_throbber_get_icon_name (KatzeThrobber* throbber)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (KATZE_IS_THROBBER (throbber), NULL);
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
return throbber->icon_name;
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_get_pixbuf:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
*
|
|
|
|
* Retrieves the #GdkPixbuf providing the animation frames if an icon name
|
|
|
|
* or pixbuf is available. The caller of this function does not own a
|
|
|
|
* reference to the returned pixbuf.
|
|
|
|
*
|
|
|
|
* Return value: the pixbuf providing the animation frames, or %NULL
|
|
|
|
**/
|
|
|
|
GdkPixbuf*
|
|
|
|
katze_throbber_get_pixbuf (KatzeThrobber* throbber)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (KATZE_IS_THROBBER (throbber), NULL);
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
return throbber->pixbuf;
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_get_animated:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
*
|
|
|
|
* Retrieves the status of the animation, whcih can be animated or static.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the throbber is animated
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
katze_throbber_get_animated (KatzeThrobber* throbber)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (KATZE_IS_THROBBER (throbber), FALSE);
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
return throbber->animated;
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_get_static_icon_name:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
*
|
|
|
|
* Retrieves the name of the icon providing the static image, if an icon name
|
|
|
|
* for the static image was specified.
|
|
|
|
*
|
|
|
|
* Return value: the name of the icon providing the static image, or %NULL
|
|
|
|
**/
|
|
|
|
const gchar*
|
|
|
|
katze_throbber_get_static_icon_name (KatzeThrobber* throbber)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (KATZE_IS_THROBBER (throbber), NULL);
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
return throbber->static_icon_name;
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_get_static pixbuf:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
*
|
|
|
|
* Retrieves the #GdkPixbuf providing the static image, if an icon name, a
|
|
|
|
* pixbuf or a stock ID for the static image was specified. The caller of this
|
|
|
|
* function does not own a reference to the returned pixbuf.
|
|
|
|
*
|
|
|
|
* Return value: the pixbuf providing the static image, or %NULL
|
|
|
|
**/
|
|
|
|
GdkPixbuf*
|
|
|
|
katze_throbber_get_static_pixbuf (KatzeThrobber* throbber)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (KATZE_IS_THROBBER (throbber), NULL);
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
return throbber->static_pixbuf;
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* katze_throbber_get_static_stock_id:
|
|
|
|
* @throbber: a #KatzeThrobber
|
|
|
|
*
|
|
|
|
* Retrieves the stock ID of the icon providing the static image, if a
|
|
|
|
* stock ID for the static image was specified.
|
|
|
|
*
|
|
|
|
* Return value: the stock ID of the icon providing the static image, or %NULL
|
|
|
|
**/
|
|
|
|
const gchar*
|
|
|
|
katze_throbber_get_static_stock_id (KatzeThrobber* throbber)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (KATZE_IS_THROBBER (throbber), NULL);
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
return throbber->static_stock_id;
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_realize (GtkWidget* widget)
|
|
|
|
{
|
|
|
|
(*GTK_WIDGET_CLASS (katze_throbber_parent_class)->realize) (widget);
|
|
|
|
|
|
|
|
icon_theme_changed (KATZE_THROBBER (widget));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_unrealize (GtkWidget* widget)
|
|
|
|
{
|
|
|
|
if (GTK_WIDGET_CLASS (katze_throbber_parent_class)->unrealize)
|
|
|
|
GTK_WIDGET_CLASS (katze_throbber_parent_class)->unrealize (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pixbuf_assign_icon (GdkPixbuf** pixbuf,
|
|
|
|
const gchar* icon_name,
|
|
|
|
KatzeThrobber* throbber)
|
|
|
|
{
|
2008-08-02 02:21:38 +00:00
|
|
|
GdkScreen* screen;
|
|
|
|
GtkIconTheme* icon_theme;
|
|
|
|
|
2008-01-05 05:24:38 +00:00
|
|
|
if (*pixbuf)
|
|
|
|
g_object_unref (*pixbuf);
|
|
|
|
|
2008-08-02 02:21:38 +00:00
|
|
|
screen = gtk_widget_get_screen (GTK_WIDGET (throbber));
|
|
|
|
icon_theme = gtk_icon_theme_get_for_screen (screen);
|
2008-01-05 05:24:38 +00:00
|
|
|
*pixbuf = gtk_icon_theme_load_icon (icon_theme,
|
|
|
|
icon_name,
|
2008-06-12 21:44:34 +00:00
|
|
|
MAX (throbber->width, throbber->height),
|
2008-01-05 05:24:38 +00:00
|
|
|
(GtkIconLookupFlags) 0,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
icon_theme_changed (KatzeThrobber* throbber)
|
|
|
|
{
|
2008-06-12 21:44:34 +00:00
|
|
|
if (throbber->icon_name)
|
2008-08-02 02:21:38 +00:00
|
|
|
pixbuf_assign_icon (&throbber->pixbuf,
|
|
|
|
throbber->icon_name, throbber);
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
if (throbber->static_icon_name)
|
2008-08-02 02:21:38 +00:00
|
|
|
pixbuf_assign_icon (&throbber->static_pixbuf,
|
|
|
|
throbber->static_icon_name, throbber);
|
2008-06-12 21:44:34 +00:00
|
|
|
else if (throbber->static_stock_id)
|
2008-08-02 02:21:38 +00:00
|
|
|
katze_object_assign (throbber->static_pixbuf,
|
|
|
|
gtk_widget_render_icon (GTK_WIDGET (throbber),
|
|
|
|
throbber->static_stock_id,
|
|
|
|
throbber->icon_size,
|
|
|
|
NULL));
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_freeze_notify (G_OBJECT (throbber));
|
|
|
|
g_object_notify (G_OBJECT (throbber), "pixbuf");
|
|
|
|
g_object_notify (G_OBJECT (throbber), "static-pixbuf");
|
|
|
|
g_object_thaw_notify (G_OBJECT (throbber));
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (throbber));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_map (GtkWidget* widget)
|
|
|
|
{
|
|
|
|
(*GTK_WIDGET_CLASS (katze_throbber_parent_class)->map) (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_unmap (GtkWidget* widget)
|
|
|
|
{
|
|
|
|
if (GTK_WIDGET_CLASS (katze_throbber_parent_class)->unmap)
|
|
|
|
GTK_WIDGET_CLASS (katze_throbber_parent_class)->unmap (widget);
|
|
|
|
}
|
|
|
|
|
2010-05-02 10:47:51 +00:00
|
|
|
#if !HAVE_SPINNER
|
2008-01-05 05:24:38 +00:00
|
|
|
static gboolean
|
|
|
|
katze_throbber_timeout (KatzeThrobber* throbber)
|
|
|
|
{
|
2008-06-12 21:44:34 +00:00
|
|
|
throbber->index++;
|
2008-01-05 05:24:38 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (throbber));
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
return throbber->animated;
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_timeout_destroy (KatzeThrobber* throbber)
|
|
|
|
{
|
2008-06-12 21:44:34 +00:00
|
|
|
throbber->index = 0;
|
|
|
|
throbber->timer_id = -1;
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
2010-05-02 10:47:51 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_style_set (GtkWidget* widget,
|
2008-01-20 17:05:16 +00:00
|
|
|
GtkStyle* prev_style)
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
|
|
|
if (GTK_WIDGET_CLASS (katze_throbber_parent_class)->style_set)
|
|
|
|
GTK_WIDGET_CLASS (katze_throbber_parent_class)->style_set (widget,
|
|
|
|
prev_style);
|
|
|
|
|
|
|
|
icon_theme_changed (KATZE_THROBBER (widget));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_screen_changed (GtkWidget* widget,
|
2008-01-20 17:05:16 +00:00
|
|
|
GdkScreen* prev_screen)
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
|
|
|
if (GTK_WIDGET_CLASS (katze_throbber_parent_class)->screen_changed)
|
|
|
|
GTK_WIDGET_CLASS (katze_throbber_parent_class)->screen_changed (
|
|
|
|
widget,
|
|
|
|
prev_screen);
|
|
|
|
|
|
|
|
icon_theme_changed (KATZE_THROBBER (widget));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_size_request (GtkWidget* widget,
|
|
|
|
GtkRequisition* requisition)
|
|
|
|
{
|
2008-06-12 21:44:34 +00:00
|
|
|
KatzeThrobber* throbber = KATZE_THROBBER (widget);
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
requisition->width = throbber->width;
|
|
|
|
requisition->height = throbber->height;
|
2011-10-01 13:12:04 +00:00
|
|
|
#if !GTK_CHECK_VERSION (3, 0, 0)
|
2008-01-05 05:24:38 +00:00
|
|
|
GTK_WIDGET_CLASS (katze_throbber_parent_class)->size_request (widget,
|
|
|
|
requisition);
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
static void
|
|
|
|
katze_throbber_get_preferred_height (GtkWidget *widget,
|
2012-02-29 21:41:59 +00:00
|
|
|
gint *minimal_height,
|
|
|
|
gint *natural_height)
|
2011-10-01 13:12:04 +00:00
|
|
|
{
|
|
|
|
GtkRequisition requisition;
|
|
|
|
|
|
|
|
katze_throbber_size_request (widget, &requisition);
|
|
|
|
|
2012-02-29 21:41:59 +00:00
|
|
|
*minimal_height = *natural_height = requisition.width;
|
2011-10-01 13:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
katze_throbber_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimal_width,
|
|
|
|
gint *natural_width)
|
|
|
|
{
|
|
|
|
GtkRequisition requisition;
|
|
|
|
|
|
|
|
katze_throbber_size_request (widget, &requisition);
|
|
|
|
|
|
|
|
*minimal_width = *natural_width = requisition.width;
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-10-30 21:17:19 +00:00
|
|
|
static void
|
|
|
|
katze_throbber_aligned_coords (GtkWidget* widget,
|
|
|
|
gint* ax,
|
|
|
|
gint* ay)
|
|
|
|
{
|
|
|
|
gfloat xalign, yalign;
|
|
|
|
gint xpad, ypad;
|
2010-02-19 15:39:14 +00:00
|
|
|
GtkAllocation allocation;
|
|
|
|
GtkRequisition requisition;
|
2008-10-30 21:17:19 +00:00
|
|
|
|
2010-05-02 10:47:51 +00:00
|
|
|
#if HAVE_SPINNER
|
|
|
|
xalign = 0.0;
|
|
|
|
yalign = 0.5;
|
|
|
|
xpad = ypad = 0.0;
|
|
|
|
#else
|
2008-10-30 21:17:19 +00:00
|
|
|
gtk_misc_get_alignment (GTK_MISC (widget), &xalign, &yalign);
|
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
2008-11-16 00:04:12 +00:00
|
|
|
xalign = 1.0f - xalign;
|
2008-10-30 21:17:19 +00:00
|
|
|
gtk_misc_get_padding (GTK_MISC (widget), &xpad, &ypad);
|
2010-05-02 10:47:51 +00:00
|
|
|
#endif
|
2008-10-30 21:17:19 +00:00
|
|
|
|
2011-12-14 01:14:54 +00:00
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
allocation.width = gtk_widget_get_allocated_width (widget);
|
|
|
|
allocation.height = gtk_widget_get_allocated_height (widget);
|
|
|
|
gtk_widget_get_preferred_size (widget, &requisition, NULL);
|
|
|
|
#else
|
2010-02-19 15:39:14 +00:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
gtk_widget_size_request (widget, &requisition);
|
2011-12-14 01:14:54 +00:00
|
|
|
#endif
|
2010-02-19 15:39:14 +00:00
|
|
|
*ax = floor (allocation.x + xpad
|
|
|
|
+ ((allocation.width - requisition.width) * xalign));
|
|
|
|
*ay = floor (allocation.y + ypad
|
|
|
|
+ ((allocation.height - requisition.height) * yalign));
|
2008-10-30 21:17:19 +00:00
|
|
|
}
|
|
|
|
|
2008-01-05 05:24:38 +00:00
|
|
|
static gboolean
|
|
|
|
katze_throbber_expose_event (GtkWidget* widget,
|
2011-10-01 13:12:04 +00:00
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
cairo_t* cr)
|
|
|
|
#else
|
2008-01-05 05:24:38 +00:00
|
|
|
GdkEventExpose* event)
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
2008-06-12 21:44:34 +00:00
|
|
|
KatzeThrobber* throbber = KATZE_THROBBER (widget);
|
2010-11-01 02:18:00 +00:00
|
|
|
gint ax, ay;
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
if (G_UNLIKELY (!throbber->width || !throbber->height))
|
2008-01-05 05:24:38 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
if (G_UNLIKELY (!throbber->pixbuf && !throbber->static_pixbuf))
|
|
|
|
if (throbber->animated && !throbber->pixbuf && !throbber->icon_name)
|
2008-01-05 05:24:38 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2008-08-02 02:21:38 +00:00
|
|
|
if (!throbber->animated && (throbber->static_pixbuf
|
|
|
|
|| throbber->static_icon_name || throbber->static_stock_id))
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
2011-10-01 13:12:04 +00:00
|
|
|
#if !GTK_CHECK_VERSION (3, 0, 0)
|
2010-10-14 18:59:47 +00:00
|
|
|
cairo_t* cr;
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2008-06-12 21:44:34 +00:00
|
|
|
if (G_UNLIKELY (!throbber->static_pixbuf && throbber->static_icon_name))
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
|
|
|
icon_theme_changed (KATZE_THROBBER (widget));
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
if (!throbber->static_pixbuf)
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
2008-08-02 02:21:38 +00:00
|
|
|
g_warning (_("Named icon '%s' couldn't be loaded"),
|
2008-06-12 21:44:34 +00:00
|
|
|
throbber->static_icon_name);
|
|
|
|
katze_assign (throbber->static_icon_name, NULL);
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_notify (G_OBJECT (throbber), "static-icon-name");
|
2008-01-05 05:24:38 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-06-12 21:44:34 +00:00
|
|
|
else if (G_UNLIKELY (!throbber->static_pixbuf && throbber->static_stock_id))
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
|
|
|
icon_theme_changed (KATZE_THROBBER (widget));
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
if (!throbber->static_pixbuf)
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
2008-08-02 02:21:38 +00:00
|
|
|
g_warning (_("Stock icon '%s' couldn't be loaded"),
|
2008-06-12 21:44:34 +00:00
|
|
|
throbber->static_stock_id);
|
|
|
|
katze_assign (throbber->static_stock_id, NULL);
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_notify (G_OBJECT (throbber), "static-stock-id");
|
2008-01-05 05:24:38 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-30 21:17:19 +00:00
|
|
|
katze_throbber_aligned_coords (widget, &ax, &ay);
|
|
|
|
|
2011-10-01 13:12:04 +00:00
|
|
|
#if !GTK_CHECK_VERSION (3, 0, 0)
|
2010-10-14 18:59:47 +00:00
|
|
|
cr = gdk_cairo_create (gtk_widget_get_window (widget));
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2010-10-14 18:59:47 +00:00
|
|
|
gdk_cairo_set_source_pixbuf (cr, throbber->static_pixbuf, ax, ay);
|
|
|
|
cairo_paint (cr);
|
2011-10-01 13:12:04 +00:00
|
|
|
#if !GTK_CHECK_VERSION (3, 0, 0)
|
2010-10-14 18:59:47 +00:00
|
|
|
cairo_destroy (cr);
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-14 18:59:47 +00:00
|
|
|
#if HAVE_SPINNER
|
|
|
|
if (throbber->animated)
|
2011-10-01 13:12:04 +00:00
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
return GTK_WIDGET_CLASS (katze_throbber_parent_class)->draw (widget, cr);
|
|
|
|
#else
|
2010-10-14 18:59:47 +00:00
|
|
|
return GTK_WIDGET_CLASS (katze_throbber_parent_class)->expose_event (widget, event);
|
2011-10-01 13:12:04 +00:00
|
|
|
#endif
|
2010-10-14 18:59:47 +00:00
|
|
|
#else
|
2010-01-29 20:10:05 +00:00
|
|
|
gint cols, rows;
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
if (G_UNLIKELY (throbber->icon_name && !throbber->pixbuf))
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
|
|
|
icon_theme_changed (KATZE_THROBBER (widget));
|
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
if (!throbber->pixbuf)
|
2008-01-05 05:24:38 +00:00
|
|
|
{
|
2008-10-21 22:46:53 +00:00
|
|
|
/* Fallback to a stock icon */
|
|
|
|
katze_assign (throbber->icon_name, g_strdup (GTK_STOCK_EXECUTE));
|
2008-08-02 02:21:38 +00:00
|
|
|
g_object_notify (G_OBJECT (throbber), "icon-name");
|
2008-01-05 05:24:38 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-29 20:10:05 +00:00
|
|
|
cols = gdk_pixbuf_get_width (throbber->pixbuf) / throbber->width;
|
|
|
|
rows = gdk_pixbuf_get_height (throbber->pixbuf) / throbber->height;
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-10-21 22:46:53 +00:00
|
|
|
if (G_UNLIKELY (cols == 1 && cols == rows))
|
|
|
|
{
|
2008-10-30 21:17:19 +00:00
|
|
|
katze_throbber_aligned_coords (widget, &ax, &ay);
|
|
|
|
|
|
|
|
if (throbber->animated)
|
|
|
|
gdk_draw_pixbuf (event->window, NULL, throbber->pixbuf,
|
|
|
|
0, 0, ax, ay,
|
|
|
|
throbber->width, throbber->height,
|
|
|
|
GDK_RGB_DITHER_NONE, 0, 0);
|
2008-10-21 22:46:53 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-01-05 05:24:38 +00:00
|
|
|
if (G_LIKELY (cols > 0 && rows > 0))
|
|
|
|
{
|
2009-01-09 21:54:40 +00:00
|
|
|
gint idx;
|
2008-10-30 21:17:19 +00:00
|
|
|
guint x, y;
|
|
|
|
|
|
|
|
katze_throbber_aligned_coords (widget, &ax, &ay);
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2009-01-09 21:54:40 +00:00
|
|
|
idx = throbber->index % (cols * rows);
|
2008-06-12 21:44:34 +00:00
|
|
|
if (G_LIKELY (throbber->timer_id >= 0))
|
2009-01-09 21:54:40 +00:00
|
|
|
idx = MAX (idx, 1);
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2009-01-09 21:54:40 +00:00
|
|
|
x = (idx % cols) * throbber->width;
|
|
|
|
y = (idx / cols) * throbber->height;
|
2008-01-05 05:24:38 +00:00
|
|
|
|
2008-06-12 21:44:34 +00:00
|
|
|
gdk_draw_pixbuf (event->window, NULL, throbber->pixbuf,
|
2008-10-30 21:17:19 +00:00
|
|
|
x, y, ax, ay,
|
2008-06-12 21:44:34 +00:00
|
|
|
throbber->width, throbber->height,
|
2008-01-05 05:24:38 +00:00
|
|
|
GDK_RGB_DITHER_NONE, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-02 02:21:38 +00:00
|
|
|
g_warning (_("Animation frames are broken"));
|
2008-06-12 21:44:34 +00:00
|
|
|
katze_assign (throbber->icon_name, NULL);
|
|
|
|
katze_object_assign (throbber->pixbuf, NULL);
|
2008-08-02 02:21:38 +00:00
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (throbber));
|
|
|
|
g_object_notify (G_OBJECT (throbber), "icon-name");
|
|
|
|
g_object_notify (G_OBJECT (throbber), "pixbuf");
|
|
|
|
g_object_thaw_notify (G_OBJECT (throbber));
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
2010-10-14 18:59:47 +00:00
|
|
|
#endif
|
2008-01-05 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|