2015-12-21 22:46:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright © 2015 Endless Mobile, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that 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 along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: Cosimo Cecchi <cosimoc@gnome.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkcssnodeprivate.h"
|
|
|
|
#include "gtkiconprivate.h"
|
|
|
|
#include "gtkwidgetprivate.h"
|
2017-05-07 19:30:02 +00:00
|
|
|
#include "gtkrendericonprivate.h"
|
2017-05-20 12:08:42 +00:00
|
|
|
#include "gtksnapshot.h"
|
2015-12-21 22:46:44 +00:00
|
|
|
|
2017-05-07 19:30:02 +00:00
|
|
|
/* GtkIcon was a minimal widget wrapped around a GtkBuiltinIcon gadget,
|
2015-12-22 19:22:13 +00:00
|
|
|
* It should be used whenever builtin-icon functionality is desired
|
|
|
|
* but a widget is needed for other reasons.
|
|
|
|
*/
|
2015-12-21 22:46:44 +00:00
|
|
|
|
2017-05-07 19:30:02 +00:00
|
|
|
G_DEFINE_TYPE (GtkIcon, gtk_icon, GTK_TYPE_WIDGET)
|
2015-12-21 22:46:44 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_icon_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
2017-05-07 19:30:02 +00:00
|
|
|
gtk_widget_set_clip (widget, allocation);
|
2015-12-21 22:46:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 15:39:07 +00:00
|
|
|
static void
|
|
|
|
gtk_icon_snapshot (GtkWidget *widget,
|
|
|
|
GtkSnapshot *snapshot)
|
2015-12-21 22:46:44 +00:00
|
|
|
{
|
2017-05-11 05:48:00 +00:00
|
|
|
GtkIcon *self = GTK_ICON (widget);
|
2017-05-07 19:30:02 +00:00
|
|
|
GtkCssStyle *style = gtk_css_node_get_style (gtk_widget_get_css_node (widget));
|
2017-05-20 12:08:42 +00:00
|
|
|
GtkAllocation content_alloc;
|
2017-05-07 19:30:02 +00:00
|
|
|
|
2017-05-20 12:08:42 +00:00
|
|
|
gtk_widget_get_content_allocation (widget, &content_alloc);
|
2015-12-21 22:46:44 +00:00
|
|
|
|
2017-05-07 19:30:02 +00:00
|
|
|
gtk_css_style_snapshot_icon (style,
|
|
|
|
snapshot,
|
2017-05-20 12:08:42 +00:00
|
|
|
content_alloc.width, content_alloc.height,
|
2017-05-11 05:48:00 +00:00
|
|
|
self->image);
|
2015-12-21 22:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_icon_class_init (GtkIconClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
wclass->size_allocate = gtk_icon_size_allocate;
|
2016-11-15 15:39:07 +00:00
|
|
|
wclass->snapshot = gtk_icon_snapshot;
|
2015-12-21 22:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_icon_init (GtkIcon *self)
|
|
|
|
{
|
2017-05-07 19:30:02 +00:00
|
|
|
gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
|
2017-05-11 05:48:00 +00:00
|
|
|
self->image = GTK_CSS_IMAGE_BUILTIN_NONE;
|
2015-12-21 22:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gtk_icon_new (const char *css_name)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_ICON,
|
|
|
|
"css-name", css_name,
|
|
|
|
NULL);
|
|
|
|
}
|
2017-05-11 05:48:00 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gtk_icon_set_image (GtkIcon *self,
|
|
|
|
GtkCssImageBuiltinType image)
|
|
|
|
{
|
|
|
|
self->image = image;
|
|
|
|
}
|
2017-06-15 19:14:25 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gtk_icon_set_css_name (GtkIcon *self,
|
|
|
|
const char *css_name)
|
|
|
|
{
|
|
|
|
gtk_css_node_set_name (gtk_widget_get_css_node (GTK_WIDGET (self)),
|
|
|
|
g_intern_string (css_name));
|
|
|
|
}
|