2010-10-30 23:57:59 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
/*
|
|
|
|
* st-icon.c: icon widget
|
|
|
|
*
|
|
|
|
* Copyright 2009, 2010 Intel Corporation.
|
2010-10-31 20:02:24 +00:00
|
|
|
* Copyright 2010 Red Hat, Inc.
|
2010-10-30 23:57:59 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU Lesser General Public License,
|
|
|
|
* version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2010-11-12 20:52:20 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-10-30 23:57:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:st-icon
|
|
|
|
* @short_description: a simple styled icon actor
|
|
|
|
*
|
|
|
|
* #StIcon is a simple styled texture actor that displays an image from
|
|
|
|
* a stylesheet.
|
|
|
|
*/
|
|
|
|
|
2010-10-31 20:02:24 +00:00
|
|
|
#include "st-enum-types.h"
|
2010-10-30 23:57:59 +00:00
|
|
|
#include "st-icon.h"
|
2010-10-31 20:02:24 +00:00
|
|
|
#include "st-texture-cache.h"
|
2014-02-16 03:43:35 +00:00
|
|
|
#include "st-theme-context.h"
|
2010-10-30 23:57:59 +00:00
|
|
|
#include "st-private.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
2010-09-26 15:18:26 +00:00
|
|
|
PROP_GICON,
|
2010-10-30 23:57:59 +00:00
|
|
|
PROP_ICON_NAME,
|
|
|
|
PROP_ICON_SIZE
|
|
|
|
};
|
|
|
|
|
2010-10-31 20:02:24 +00:00
|
|
|
G_DEFINE_TYPE (StIcon, st_icon, ST_TYPE_WIDGET)
|
2010-10-30 23:57:59 +00:00
|
|
|
|
|
|
|
#define ST_ICON_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), ST_TYPE_ICON, StIconPrivate))
|
|
|
|
|
|
|
|
struct _StIconPrivate
|
|
|
|
{
|
|
|
|
ClutterActor *icon_texture;
|
2010-11-30 15:19:27 +00:00
|
|
|
ClutterActor *pending_texture;
|
|
|
|
guint opacity_handler_id;
|
2010-10-30 23:57:59 +00:00
|
|
|
|
2010-09-26 15:18:26 +00:00
|
|
|
GIcon *gicon;
|
2010-10-31 20:02:24 +00:00
|
|
|
gint prop_icon_size; /* icon size set as property */
|
|
|
|
gint theme_icon_size; /* icon size from theme node */
|
|
|
|
gint icon_size; /* icon size we are using */
|
2010-11-23 12:48:23 +00:00
|
|
|
|
|
|
|
CoglHandle shadow_material;
|
|
|
|
float shadow_width;
|
|
|
|
float shadow_height;
|
2011-01-13 23:27:24 +00:00
|
|
|
StShadow *shadow_spec;
|
2010-10-30 23:57:59 +00:00
|
|
|
};
|
|
|
|
|
2010-11-02 20:15:53 +00:00
|
|
|
static void st_icon_update (StIcon *icon);
|
|
|
|
static gboolean st_icon_update_icon_size (StIcon *icon);
|
2010-10-30 23:57:59 +00:00
|
|
|
|
2010-10-31 20:02:24 +00:00
|
|
|
#define DEFAULT_ICON_SIZE 48
|
2010-10-30 23:57:59 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
st_icon_set_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
StIcon *icon = ST_ICON (gobject);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2010-09-26 15:18:26 +00:00
|
|
|
case PROP_GICON:
|
|
|
|
st_icon_set_gicon (icon, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2010-10-30 23:57:59 +00:00
|
|
|
case PROP_ICON_NAME:
|
|
|
|
st_icon_set_icon_name (icon, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ICON_SIZE:
|
|
|
|
st_icon_set_icon_size (icon, g_value_get_int (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_icon_get_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
StIcon *icon = ST_ICON (gobject);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2010-09-26 15:18:26 +00:00
|
|
|
case PROP_GICON:
|
|
|
|
g_value_set_object (value, icon->priv->gicon);
|
|
|
|
break;
|
|
|
|
|
2010-10-30 23:57:59 +00:00
|
|
|
case PROP_ICON_NAME:
|
|
|
|
g_value_set_string (value, st_icon_get_icon_name (icon));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ICON_SIZE:
|
|
|
|
g_value_set_int (value, st_icon_get_icon_size (icon));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_icon_dispose (GObject *gobject)
|
|
|
|
{
|
|
|
|
StIconPrivate *priv = ST_ICON (gobject)->priv;
|
|
|
|
|
|
|
|
if (priv->icon_texture)
|
|
|
|
{
|
|
|
|
clutter_actor_destroy (priv->icon_texture);
|
|
|
|
priv->icon_texture = NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-30 15:19:27 +00:00
|
|
|
if (priv->pending_texture)
|
|
|
|
{
|
|
|
|
clutter_actor_destroy (priv->pending_texture);
|
|
|
|
g_object_unref (priv->pending_texture);
|
2010-12-21 21:49:54 +00:00
|
|
|
priv->pending_texture = NULL;
|
2010-11-30 15:19:27 +00:00
|
|
|
}
|
|
|
|
|
2010-09-26 15:18:26 +00:00
|
|
|
if (priv->gicon)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->gicon);
|
|
|
|
priv->gicon = NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-23 12:48:23 +00:00
|
|
|
if (priv->shadow_material)
|
|
|
|
{
|
|
|
|
cogl_handle_unref (priv->shadow_material);
|
|
|
|
priv->shadow_material = COGL_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2011-01-13 23:27:24 +00:00
|
|
|
if (priv->shadow_spec)
|
|
|
|
{
|
|
|
|
st_shadow_unref (priv->shadow_spec);
|
|
|
|
priv->shadow_spec = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-30 23:57:59 +00:00
|
|
|
G_OBJECT_CLASS (st_icon_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_icon_paint (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
StIconPrivate *priv = ST_ICON (actor)->priv;
|
|
|
|
|
2012-02-13 21:41:29 +00:00
|
|
|
st_widget_paint_background (ST_WIDGET (actor));
|
2010-10-30 23:57:59 +00:00
|
|
|
|
|
|
|
if (priv->icon_texture)
|
2010-11-23 12:48:23 +00:00
|
|
|
{
|
|
|
|
if (priv->shadow_material)
|
|
|
|
{
|
|
|
|
ClutterActorBox allocation;
|
|
|
|
float width, height;
|
|
|
|
|
|
|
|
clutter_actor_get_allocation_box (priv->icon_texture, &allocation);
|
|
|
|
clutter_actor_box_get_size (&allocation, &width, &height);
|
|
|
|
|
2011-01-13 23:27:24 +00:00
|
|
|
_st_paint_shadow_with_opacity (priv->shadow_spec,
|
2010-11-23 12:48:23 +00:00
|
|
|
priv->shadow_material,
|
|
|
|
&allocation,
|
|
|
|
clutter_actor_get_paint_opacity (priv->icon_texture));
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_paint (priv->icon_texture);
|
|
|
|
}
|
2010-10-30 23:57:59 +00:00
|
|
|
}
|
|
|
|
|
2010-10-31 20:02:24 +00:00
|
|
|
static void
|
|
|
|
st_icon_style_changed (StWidget *widget)
|
|
|
|
{
|
|
|
|
StIcon *self = ST_ICON (widget);
|
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (widget);
|
|
|
|
StIconPrivate *priv = self->priv;
|
|
|
|
|
2011-01-13 23:27:24 +00:00
|
|
|
if (priv->shadow_spec)
|
|
|
|
{
|
|
|
|
st_shadow_unref (priv->shadow_spec);
|
|
|
|
priv->shadow_spec = NULL;
|
|
|
|
}
|
2012-07-12 00:26:11 +00:00
|
|
|
|
|
|
|
if (priv->shadow_material)
|
|
|
|
{
|
|
|
|
cogl_handle_unref (priv->shadow_material);
|
|
|
|
priv->shadow_material = COGL_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2011-01-13 23:27:24 +00:00
|
|
|
priv->shadow_spec = st_theme_node_get_shadow (theme_node, "icon-shadow");
|
|
|
|
|
2011-02-14 01:07:14 +00:00
|
|
|
if (priv->shadow_spec && priv->shadow_spec->inset)
|
|
|
|
{
|
|
|
|
g_warning ("The icon-shadow property does not support inset shadows");
|
|
|
|
st_shadow_unref (priv->shadow_spec);
|
|
|
|
priv->shadow_spec = NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-19 16:34:10 +00:00
|
|
|
priv->theme_icon_size = (int)(0.5 + st_theme_node_get_length (theme_node, "icon-size"));
|
2010-10-31 20:02:24 +00:00
|
|
|
st_icon_update_icon_size (self);
|
2010-11-02 20:15:53 +00:00
|
|
|
st_icon_update (self);
|
2010-10-31 20:02:24 +00:00
|
|
|
}
|
|
|
|
|
2010-10-30 23:57:59 +00:00
|
|
|
static void
|
|
|
|
st_icon_class_init (StIconClass *klass)
|
|
|
|
{
|
|
|
|
GParamSpec *pspec;
|
|
|
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
2010-10-31 20:02:24 +00:00
|
|
|
StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
|
2010-10-30 23:57:59 +00:00
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (StIconPrivate));
|
|
|
|
|
|
|
|
object_class->get_property = st_icon_get_property;
|
|
|
|
object_class->set_property = st_icon_set_property;
|
|
|
|
object_class->dispose = st_icon_dispose;
|
|
|
|
|
|
|
|
actor_class->paint = st_icon_paint;
|
|
|
|
|
2010-10-31 20:02:24 +00:00
|
|
|
widget_class->style_changed = st_icon_style_changed;
|
|
|
|
|
2010-09-26 15:18:26 +00:00
|
|
|
pspec = g_param_spec_object ("gicon",
|
|
|
|
"GIcon",
|
2012-08-26 13:36:45 +00:00
|
|
|
"The GIcon shown by this icon actor",
|
2010-09-26 15:18:26 +00:00
|
|
|
G_TYPE_ICON,
|
|
|
|
ST_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_GICON, pspec);
|
|
|
|
|
2010-10-30 23:57:59 +00:00
|
|
|
pspec = g_param_spec_string ("icon-name",
|
|
|
|
"Icon name",
|
|
|
|
"An icon name",
|
2014-06-26 19:45:55 +00:00
|
|
|
NULL, ST_PARAM_READWRITE);
|
2010-10-30 23:57:59 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_ICON_NAME, pspec);
|
|
|
|
|
|
|
|
pspec = g_param_spec_int ("icon-size",
|
|
|
|
"Icon size",
|
2010-10-31 20:02:24 +00:00
|
|
|
"The size if the icon, if positive. Otherwise the size will be derived from the current style",
|
|
|
|
-1, G_MAXINT, -1,
|
2010-10-30 23:57:59 +00:00
|
|
|
ST_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_ICON_SIZE, pspec);
|
|
|
|
}
|
|
|
|
|
2010-10-31 20:02:24 +00:00
|
|
|
static void
|
|
|
|
st_icon_init (StIcon *self)
|
|
|
|
{
|
2014-02-16 05:33:21 +00:00
|
|
|
ClutterLayoutManager *layout_manager;
|
|
|
|
|
2010-10-31 20:02:24 +00:00
|
|
|
self->priv = ST_ICON_GET_PRIVATE (self);
|
|
|
|
|
2014-02-16 05:33:21 +00:00
|
|
|
layout_manager = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
|
|
|
|
CLUTTER_BIN_ALIGNMENT_FILL);
|
|
|
|
clutter_actor_set_layout_manager (CLUTTER_ACTOR (self), layout_manager);
|
|
|
|
|
2010-10-31 20:02:24 +00:00
|
|
|
self->priv->icon_size = DEFAULT_ICON_SIZE;
|
|
|
|
self->priv->prop_icon_size = -1;
|
2010-11-23 12:48:23 +00:00
|
|
|
|
2010-12-09 17:01:27 +00:00
|
|
|
self->priv->shadow_material = COGL_INVALID_HANDLE;
|
2010-11-23 12:48:23 +00:00
|
|
|
self->priv->shadow_width = -1;
|
|
|
|
self->priv->shadow_height = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_icon_update_shadow_material (StIcon *icon)
|
|
|
|
{
|
|
|
|
StIconPrivate *priv = icon->priv;
|
|
|
|
|
|
|
|
if (priv->shadow_material)
|
|
|
|
{
|
|
|
|
cogl_handle_unref (priv->shadow_material);
|
|
|
|
priv->shadow_material = COGL_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2011-01-13 23:27:24 +00:00
|
|
|
if (priv->shadow_spec)
|
2010-11-23 12:48:23 +00:00
|
|
|
{
|
|
|
|
CoglHandle material;
|
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
clutter_texture_get_base_size (CLUTTER_TEXTURE (priv->icon_texture),
|
|
|
|
&width, &height);
|
2011-01-13 23:27:24 +00:00
|
|
|
|
|
|
|
material = _st_create_shadow_material_from_actor (priv->shadow_spec,
|
2010-11-23 12:48:23 +00:00
|
|
|
priv->icon_texture);
|
|
|
|
priv->shadow_material = material;
|
|
|
|
priv->shadow_width = width;
|
|
|
|
priv->shadow_height = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_pixbuf_changed (ClutterTexture *texture,
|
|
|
|
StIcon *icon)
|
|
|
|
{
|
|
|
|
st_icon_update_shadow_material (icon);
|
2010-10-31 20:02:24 +00:00
|
|
|
}
|
|
|
|
|
2010-10-30 23:57:59 +00:00
|
|
|
static void
|
2010-11-30 15:19:27 +00:00
|
|
|
st_icon_finish_update (StIcon *icon)
|
2010-10-30 23:57:59 +00:00
|
|
|
{
|
|
|
|
StIconPrivate *priv = icon->priv;
|
|
|
|
|
|
|
|
if (priv->icon_texture)
|
|
|
|
{
|
|
|
|
clutter_actor_destroy (priv->icon_texture);
|
|
|
|
priv->icon_texture = NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-30 15:19:27 +00:00
|
|
|
if (priv->pending_texture)
|
|
|
|
{
|
|
|
|
priv->icon_texture = priv->pending_texture;
|
|
|
|
priv->pending_texture = NULL;
|
2014-02-16 05:33:21 +00:00
|
|
|
clutter_actor_set_x_align (priv->icon_texture, CLUTTER_ACTOR_ALIGN_CENTER);
|
|
|
|
clutter_actor_set_y_align (priv->icon_texture, CLUTTER_ACTOR_ALIGN_CENTER);
|
2012-02-13 20:22:53 +00:00
|
|
|
clutter_actor_add_child (CLUTTER_ACTOR (icon), priv->icon_texture);
|
2010-11-30 15:19:27 +00:00
|
|
|
|
|
|
|
/* Remove the temporary ref we added */
|
|
|
|
g_object_unref (priv->icon_texture);
|
|
|
|
|
|
|
|
st_icon_update_shadow_material (icon);
|
|
|
|
|
|
|
|
/* "pixbuf-change" is actually a misnomer for "texture-changed" */
|
2013-03-27 16:54:41 +00:00
|
|
|
g_signal_connect_object (priv->icon_texture, "pixbuf-change",
|
|
|
|
G_CALLBACK (on_pixbuf_changed), icon, 0);
|
2010-11-30 15:19:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
opacity_changed_cb (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
StIcon *icon = user_data;
|
|
|
|
StIconPrivate *priv = icon->priv;
|
|
|
|
|
|
|
|
g_signal_handler_disconnect (priv->pending_texture, priv->opacity_handler_id);
|
|
|
|
priv->opacity_handler_id = 0;
|
|
|
|
|
|
|
|
st_icon_finish_update (icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_icon_update (StIcon *icon)
|
|
|
|
{
|
|
|
|
StIconPrivate *priv = icon->priv;
|
|
|
|
StThemeNode *theme_node;
|
|
|
|
StTextureCache *cache;
|
2014-02-16 03:43:35 +00:00
|
|
|
gint scale;
|
|
|
|
ClutterActor *stage;
|
|
|
|
StThemeContext *context;
|
2010-11-30 15:19:27 +00:00
|
|
|
|
|
|
|
if (priv->pending_texture)
|
|
|
|
{
|
|
|
|
clutter_actor_destroy (priv->pending_texture);
|
|
|
|
g_object_unref (priv->pending_texture);
|
|
|
|
priv->pending_texture = NULL;
|
|
|
|
priv->opacity_handler_id = 0;
|
|
|
|
}
|
|
|
|
|
2010-09-26 15:18:26 +00:00
|
|
|
theme_node = st_widget_peek_theme_node (ST_WIDGET (icon));
|
|
|
|
if (theme_node == NULL)
|
|
|
|
return;
|
|
|
|
|
2014-02-16 03:43:35 +00:00
|
|
|
stage = clutter_actor_get_stage (CLUTTER_ACTOR (icon));
|
|
|
|
context = st_theme_context_get_for_stage (CLUTTER_STAGE (stage));
|
|
|
|
g_object_get (context, "scale-factor", &scale, NULL);
|
|
|
|
|
2010-09-26 15:18:26 +00:00
|
|
|
cache = st_texture_cache_get_default ();
|
|
|
|
if (priv->gicon)
|
|
|
|
{
|
2010-11-30 15:19:27 +00:00
|
|
|
priv->pending_texture = st_texture_cache_load_gicon (cache,
|
2012-03-15 22:24:51 +00:00
|
|
|
theme_node,
|
2010-11-30 15:19:27 +00:00
|
|
|
priv->gicon,
|
2014-02-16 03:43:35 +00:00
|
|
|
priv->icon_size,
|
|
|
|
scale);
|
2010-09-26 15:18:26 +00:00
|
|
|
}
|
2010-11-30 15:19:27 +00:00
|
|
|
|
|
|
|
if (priv->pending_texture)
|
2010-11-23 12:48:23 +00:00
|
|
|
{
|
2010-11-30 15:19:27 +00:00
|
|
|
g_object_ref_sink (priv->pending_texture);
|
2010-11-23 12:48:23 +00:00
|
|
|
|
2010-11-30 15:19:27 +00:00
|
|
|
if (clutter_actor_get_opacity (priv->pending_texture) != 0 || priv->icon_texture == NULL)
|
|
|
|
{
|
|
|
|
/* This icon is ready for showing, or nothing else is already showing */
|
|
|
|
st_icon_finish_update (icon);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Will be shown when fully loaded */
|
2013-03-27 16:54:41 +00:00
|
|
|
priv->opacity_handler_id = g_signal_connect_object (priv->pending_texture, "notify::opacity", G_CALLBACK (opacity_changed_cb), icon, 0);
|
2010-11-30 15:19:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (priv->icon_texture)
|
|
|
|
{
|
|
|
|
clutter_actor_destroy (priv->icon_texture);
|
|
|
|
priv->icon_texture = NULL;
|
2010-11-23 12:48:23 +00:00
|
|
|
}
|
2010-10-30 23:57:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 20:15:53 +00:00
|
|
|
static gboolean
|
2010-10-31 20:02:24 +00:00
|
|
|
st_icon_update_icon_size (StIcon *icon)
|
2010-10-30 23:57:59 +00:00
|
|
|
{
|
2010-10-31 20:02:24 +00:00
|
|
|
StIconPrivate *priv = icon->priv;
|
|
|
|
int new_size;
|
2010-10-30 23:57:59 +00:00
|
|
|
|
2010-10-31 20:02:24 +00:00
|
|
|
if (priv->prop_icon_size > 0)
|
|
|
|
new_size = priv->prop_icon_size;
|
|
|
|
else if (priv->theme_icon_size > 0)
|
2014-02-16 03:43:35 +00:00
|
|
|
{
|
|
|
|
gint scale;
|
|
|
|
ClutterActor *stage;
|
|
|
|
StThemeContext *context;
|
|
|
|
|
|
|
|
/* The theme will give us an already-scaled size, so we
|
|
|
|
* undo it here, as priv->icon_size is in unscaled pixels.
|
|
|
|
*/
|
|
|
|
stage = clutter_actor_get_stage (CLUTTER_ACTOR (icon));
|
|
|
|
context = st_theme_context_get_for_stage (CLUTTER_STAGE (stage));
|
|
|
|
g_object_get (context, "scale-factor", &scale, NULL);
|
|
|
|
new_size = (gint) (priv->theme_icon_size / scale);
|
|
|
|
}
|
2010-10-31 20:02:24 +00:00
|
|
|
else
|
|
|
|
new_size = DEFAULT_ICON_SIZE;
|
2010-10-30 23:57:59 +00:00
|
|
|
|
2010-10-31 20:02:24 +00:00
|
|
|
if (new_size != priv->icon_size)
|
2010-10-30 23:57:59 +00:00
|
|
|
{
|
2010-11-02 21:11:28 +00:00
|
|
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (icon));
|
2010-10-31 20:02:24 +00:00
|
|
|
priv->icon_size = new_size;
|
2010-11-02 20:15:53 +00:00
|
|
|
return TRUE;
|
2010-10-30 23:57:59 +00:00
|
|
|
}
|
2010-11-02 20:15:53 +00:00
|
|
|
else
|
|
|
|
return FALSE;
|
2010-10-30 23:57:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_icon_new:
|
|
|
|
*
|
|
|
|
* Create a newly allocated #StIcon
|
|
|
|
*
|
|
|
|
* Returns: A newly allocated #StIcon
|
|
|
|
*/
|
|
|
|
ClutterActor *
|
|
|
|
st_icon_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (ST_TYPE_ICON, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
st_icon_get_icon_name (StIcon *icon)
|
|
|
|
{
|
2012-08-26 13:36:45 +00:00
|
|
|
StIconPrivate *priv;
|
|
|
|
|
2010-10-30 23:57:59 +00:00
|
|
|
g_return_val_if_fail (ST_IS_ICON (icon), NULL);
|
|
|
|
|
2012-08-26 13:36:45 +00:00
|
|
|
priv = icon->priv;
|
|
|
|
|
|
|
|
if (priv->gicon && G_IS_THEMED_ICON (priv->gicon))
|
|
|
|
return g_themed_icon_get_names (G_THEMED_ICON (priv->gicon)) [0];
|
|
|
|
else
|
|
|
|
return NULL;
|
2010-10-30 23:57:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
st_icon_set_icon_name (StIcon *icon,
|
|
|
|
const gchar *icon_name)
|
|
|
|
{
|
2013-03-02 20:50:47 +00:00
|
|
|
StIconPrivate *priv = icon->priv;
|
|
|
|
GIcon *gicon = NULL;
|
2010-10-30 23:57:59 +00:00
|
|
|
|
|
|
|
g_return_if_fail (ST_IS_ICON (icon));
|
|
|
|
|
2013-03-02 20:50:47 +00:00
|
|
|
if (icon_name)
|
|
|
|
gicon = g_themed_icon_new_with_default_fallbacks (icon_name);
|
|
|
|
|
|
|
|
if (g_icon_equal (priv->gicon, gicon)) /* do nothing */
|
|
|
|
{
|
2013-04-25 16:25:12 +00:00
|
|
|
if (gicon)
|
|
|
|
g_object_unref (gicon);
|
2013-03-02 20:50:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-10-30 23:57:59 +00:00
|
|
|
|
2010-09-26 15:18:26 +00:00
|
|
|
if (priv->gicon)
|
2012-08-26 13:36:45 +00:00
|
|
|
g_object_unref (priv->gicon);
|
|
|
|
|
2013-03-02 20:50:47 +00:00
|
|
|
g_object_freeze_notify (G_OBJECT (icon));
|
|
|
|
|
|
|
|
priv->gicon = gicon;
|
2010-10-30 23:57:59 +00:00
|
|
|
|
2012-08-26 13:36:45 +00:00
|
|
|
g_object_notify (G_OBJECT (icon), "gicon");
|
2010-10-30 23:57:59 +00:00
|
|
|
g_object_notify (G_OBJECT (icon), "icon-name");
|
2010-09-26 15:18:26 +00:00
|
|
|
|
2013-03-02 20:50:47 +00:00
|
|
|
g_object_thaw_notify (G_OBJECT (icon));
|
|
|
|
|
2010-09-26 15:18:26 +00:00
|
|
|
st_icon_update (icon);
|
2010-10-30 23:57:59 +00:00
|
|
|
}
|
|
|
|
|
2010-09-26 15:18:26 +00:00
|
|
|
/**
|
|
|
|
* st_icon_get_gicon:
|
|
|
|
* @icon: an icon
|
|
|
|
*
|
|
|
|
* Return value: (transfer none): the override GIcon, if set, or NULL
|
|
|
|
*/
|
|
|
|
GIcon *
|
|
|
|
st_icon_get_gicon (StIcon *icon)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (ST_IS_ICON (icon), NULL);
|
|
|
|
|
|
|
|
return icon->priv->gicon;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_icon_set_gicon:
|
|
|
|
* @icon: an icon
|
2014-05-28 19:54:02 +00:00
|
|
|
* @gicon: (nullable): a #GIcon to override :icon-name
|
2010-09-26 15:18:26 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
st_icon_set_gicon (StIcon *icon, GIcon *gicon)
|
|
|
|
{
|
|
|
|
g_return_if_fail (ST_IS_ICON (icon));
|
2012-08-26 13:36:45 +00:00
|
|
|
g_return_if_fail (gicon == NULL || G_IS_ICON (gicon));
|
2010-09-26 15:18:26 +00:00
|
|
|
|
2013-03-02 20:50:47 +00:00
|
|
|
if (g_icon_equal (icon->priv->gicon, gicon)) /* do nothing */
|
2010-09-26 15:18:26 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (icon->priv->gicon)
|
|
|
|
{
|
|
|
|
g_object_unref (icon->priv->gicon);
|
|
|
|
icon->priv->gicon = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gicon)
|
|
|
|
icon->priv->gicon = g_object_ref (gicon);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (icon), "gicon");
|
|
|
|
|
|
|
|
st_icon_update (icon);
|
|
|
|
}
|
|
|
|
|
2010-10-31 20:02:24 +00:00
|
|
|
/**
|
|
|
|
* st_icon_get_icon_size:
|
|
|
|
* @icon: an icon
|
|
|
|
*
|
|
|
|
* Gets the size explicit size on the icon. This is not necesariily
|
|
|
|
* the size that the icon will actually be displayed at.
|
|
|
|
*
|
|
|
|
* Return value: the size explicitly set, or -1 if no size has been set
|
|
|
|
*/
|
2010-10-30 23:57:59 +00:00
|
|
|
gint
|
|
|
|
st_icon_get_icon_size (StIcon *icon)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (ST_IS_ICON (icon), -1);
|
|
|
|
|
2010-10-31 20:02:24 +00:00
|
|
|
return icon->priv->prop_icon_size;
|
2010-10-30 23:57:59 +00:00
|
|
|
}
|
2010-10-31 20:02:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* st_icon_set_icon_size:
|
|
|
|
* @icon: an icon
|
|
|
|
* @size: if positive, the new size, otherwise the size will be
|
|
|
|
* derived from the current style
|
|
|
|
*
|
|
|
|
* Sets an explicit size for the icon.
|
|
|
|
*/
|
2010-10-30 23:57:59 +00:00
|
|
|
void
|
|
|
|
st_icon_set_icon_size (StIcon *icon,
|
|
|
|
gint size)
|
|
|
|
{
|
|
|
|
StIconPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (ST_IS_ICON (icon));
|
|
|
|
|
|
|
|
priv = icon->priv;
|
2010-10-31 20:02:24 +00:00
|
|
|
if (priv->prop_icon_size != size)
|
2010-10-30 23:57:59 +00:00
|
|
|
{
|
2010-10-31 20:02:24 +00:00
|
|
|
priv->prop_icon_size = size;
|
2010-11-02 20:15:53 +00:00
|
|
|
if (st_icon_update_icon_size (icon))
|
|
|
|
st_icon_update (icon);
|
2010-10-30 23:57:59 +00:00
|
|
|
g_object_notify (G_OBJECT (icon), "icon-size");
|
|
|
|
}
|
|
|
|
}
|