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"
|
2017-11-15 13:11:01 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
2020-01-28 14:03:42 +00:00
|
|
|
#include "gtkbuiltiniconprivate.h"
|
2015-12-21 22:46:44 +00:00
|
|
|
#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
|
|
|
|
2020-01-28 14:03:42 +00:00
|
|
|
/* GtkBuiltinIcon 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
|
|
|
|
2020-01-28 14:03:42 +00:00
|
|
|
struct _GtkBuiltinIcon
|
2018-02-01 14:29:01 +00:00
|
|
|
{
|
|
|
|
GtkWidget parent;
|
|
|
|
};
|
|
|
|
|
2020-01-28 14:03:42 +00:00
|
|
|
G_DEFINE_TYPE (GtkBuiltinIcon, gtk_builtin_icon, GTK_TYPE_WIDGET)
|
2015-12-21 22:46:44 +00:00
|
|
|
|
2016-11-15 15:39:07 +00:00
|
|
|
static void
|
2020-01-28 14:03:42 +00:00
|
|
|
gtk_builtin_icon_snapshot (GtkWidget *widget,
|
|
|
|
GtkSnapshot *snapshot)
|
2015-12-21 22:46:44 +00:00
|
|
|
{
|
2017-05-07 19:30:02 +00:00
|
|
|
GtkCssStyle *style = gtk_css_node_get_style (gtk_widget_get_css_node (widget));
|
2017-06-18 13:45:42 +00:00
|
|
|
int width, height;
|
2017-05-07 19:30:02 +00:00
|
|
|
|
2017-12-04 11:42:52 +00:00
|
|
|
width = gtk_widget_get_width (widget);
|
|
|
|
height = gtk_widget_get_height (widget);
|
2015-12-21 22:46:44 +00:00
|
|
|
|
2017-10-09 15:38:54 +00:00
|
|
|
if (width > 0 && height > 0)
|
2020-01-10 18:11:59 +00:00
|
|
|
gtk_css_style_snapshot_icon (style, snapshot, width, height);
|
2015-12-21 22:46:44 +00:00
|
|
|
}
|
|
|
|
|
2020-01-25 01:53:16 +00:00
|
|
|
static void
|
2020-02-05 01:46:13 +00:00
|
|
|
gtk_builtin_icon_css_changed (GtkWidget *widget,
|
|
|
|
GtkCssStyleChange *change)
|
2020-01-25 01:53:16 +00:00
|
|
|
{
|
2020-02-05 01:46:13 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_builtin_icon_parent_class)->css_changed (widget, change);
|
2020-01-25 01:53:16 +00:00
|
|
|
|
|
|
|
if (change == NULL ||
|
|
|
|
gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_ICON_SIZE))
|
|
|
|
{
|
|
|
|
gtk_widget_queue_resize (widget);
|
|
|
|
}
|
|
|
|
else if (gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_ICON_TEXTURE) ||
|
|
|
|
gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_ICON_REDRAW))
|
|
|
|
{
|
|
|
|
gtk_widget_queue_draw (widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 13:11:01 +00:00
|
|
|
static void
|
2020-01-28 14:03:42 +00:00
|
|
|
gtk_builtin_icon_measure (GtkWidget *widget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline)
|
2017-11-15 13:11:01 +00:00
|
|
|
{
|
|
|
|
GtkCssValue *icon_size;
|
|
|
|
|
|
|
|
icon_size = _gtk_style_context_peek_property (gtk_widget_get_style_context (widget), GTK_CSS_PROPERTY_ICON_SIZE);
|
|
|
|
*minimum = *natural = _gtk_css_number_value_get (icon_size, 100);
|
|
|
|
}
|
|
|
|
|
2015-12-21 22:46:44 +00:00
|
|
|
static void
|
2020-01-28 14:03:42 +00:00
|
|
|
gtk_builtin_icon_class_init (GtkBuiltinIconClass *klass)
|
2015-12-21 22:46:44 +00:00
|
|
|
{
|
|
|
|
GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2020-01-28 14:03:42 +00:00
|
|
|
wclass->snapshot = gtk_builtin_icon_snapshot;
|
|
|
|
wclass->measure = gtk_builtin_icon_measure;
|
2020-02-05 01:46:13 +00:00
|
|
|
wclass->css_changed = gtk_builtin_icon_css_changed;
|
2020-04-08 11:43:28 +00:00
|
|
|
wclass->grab_focus = gtk_widget_grab_focus_none;
|
|
|
|
wclass->focus = gtk_widget_focus_none;
|
2015-12-21 22:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-01-28 14:03:42 +00:00
|
|
|
gtk_builtin_icon_init (GtkBuiltinIcon *self)
|
2015-12-21 22:46:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
2020-01-28 14:03:42 +00:00
|
|
|
gtk_builtin_icon_new (const char *css_name)
|
2015-12-21 22:46:44 +00:00
|
|
|
{
|
2020-01-28 14:03:42 +00:00
|
|
|
return g_object_new (GTK_TYPE_BUILTIN_ICON,
|
2015-12-21 22:46:44 +00:00
|
|
|
"css-name", css_name,
|
|
|
|
NULL);
|
|
|
|
}
|
2017-05-11 05:48:00 +00:00
|
|
|
|
2017-06-15 19:14:25 +00:00
|
|
|
void
|
2020-01-28 14:03:42 +00:00
|
|
|
gtk_builtin_icon_set_css_name (GtkBuiltinIcon *self,
|
2020-01-30 11:27:15 +00:00
|
|
|
const char *css_name)
|
2017-06-15 19:14:25 +00:00
|
|
|
{
|
|
|
|
gtk_css_node_set_name (gtk_widget_get_css_node (GTK_WIDGET (self)),
|
2020-01-23 23:43:26 +00:00
|
|
|
g_quark_from_string (css_name));
|
2017-06-15 19:14:25 +00:00
|
|
|
}
|