2015-12-12 01:02:04 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2015 Benjamin Otte <otte@gnome.org>
|
|
|
|
*
|
|
|
|
* 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 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkcssstylechangeprivate.h"
|
|
|
|
|
|
|
|
#include "gtkcssstylepropertyprivate.h"
|
|
|
|
|
2020-01-28 17:13:37 +00:00
|
|
|
static void
|
|
|
|
compute_change (GtkCssStyleChange *change)
|
|
|
|
{
|
2020-02-02 15:34:45 +00:00
|
|
|
gboolean color_changed = FALSE;
|
|
|
|
|
2020-01-28 17:13:37 +00:00
|
|
|
if (change->old_style->core != change->new_style->core)
|
2020-02-02 15:34:45 +00:00
|
|
|
{
|
|
|
|
gtk_css_core_values_compute_changes_and_affects (change->old_style,
|
|
|
|
change->new_style,
|
|
|
|
&change->changes,
|
|
|
|
&change->affects);
|
|
|
|
color_changed = _gtk_bitmask_get (change->changes, GTK_CSS_PROPERTY_COLOR);
|
|
|
|
}
|
|
|
|
|
2020-01-28 17:13:37 +00:00
|
|
|
if (change->old_style->background != change->new_style->background)
|
|
|
|
gtk_css_background_values_compute_changes_and_affects (change->old_style,
|
|
|
|
change->new_style,
|
|
|
|
&change->changes,
|
|
|
|
&change->affects);
|
2020-02-02 15:34:45 +00:00
|
|
|
|
|
|
|
if (change->old_style->border != change->new_style->border ||
|
|
|
|
(color_changed && (change->old_style->border->border_top_color == NULL ||
|
|
|
|
change->old_style->border->border_right_color == NULL ||
|
|
|
|
change->old_style->border->border_bottom_color == NULL ||
|
|
|
|
change->old_style->border->border_left_color == NULL)))
|
2020-01-28 17:13:37 +00:00
|
|
|
gtk_css_border_values_compute_changes_and_affects (change->old_style,
|
|
|
|
change->new_style,
|
|
|
|
&change->changes,
|
|
|
|
&change->affects);
|
2020-02-02 15:34:45 +00:00
|
|
|
|
2020-01-28 17:13:37 +00:00
|
|
|
if (change->old_style->icon != change->new_style->icon)
|
|
|
|
gtk_css_icon_values_compute_changes_and_affects (change->old_style,
|
|
|
|
change->new_style,
|
|
|
|
&change->changes,
|
|
|
|
&change->affects);
|
2020-02-02 15:34:45 +00:00
|
|
|
|
|
|
|
if (change->old_style->outline != change->new_style->outline ||
|
|
|
|
(color_changed && change->old_style->outline->outline_color == NULL))
|
2020-01-28 17:13:37 +00:00
|
|
|
gtk_css_outline_values_compute_changes_and_affects (change->old_style,
|
|
|
|
change->new_style,
|
|
|
|
&change->changes,
|
|
|
|
&change->affects);
|
2020-02-02 15:34:45 +00:00
|
|
|
|
|
|
|
if (change->old_style->font != change->new_style->font ||
|
|
|
|
(color_changed && (change->old_style->font->caret_color == NULL ||
|
|
|
|
change->old_style->font->secondary_caret_color == NULL)))
|
2020-01-28 17:13:37 +00:00
|
|
|
gtk_css_font_values_compute_changes_and_affects (change->old_style,
|
|
|
|
change->new_style,
|
|
|
|
&change->changes,
|
|
|
|
&change->affects);
|
2020-02-02 15:34:45 +00:00
|
|
|
|
|
|
|
if (change->old_style->font_variant != change->new_style->font_variant ||
|
|
|
|
(color_changed && change->old_style->font_variant->text_decoration_color == NULL))
|
2020-01-28 17:13:37 +00:00
|
|
|
gtk_css_font_variant_values_compute_changes_and_affects (change->old_style,
|
|
|
|
change->new_style,
|
|
|
|
&change->changes,
|
|
|
|
&change->affects);
|
2020-02-02 15:34:45 +00:00
|
|
|
|
2020-01-28 17:13:37 +00:00
|
|
|
if (change->old_style->animation != change->new_style->animation)
|
|
|
|
gtk_css_animation_values_compute_changes_and_affects (change->old_style,
|
|
|
|
change->new_style,
|
|
|
|
&change->changes,
|
|
|
|
&change->affects);
|
2020-02-02 15:34:45 +00:00
|
|
|
|
2020-01-28 17:13:37 +00:00
|
|
|
if (change->old_style->transition != change->new_style->transition)
|
|
|
|
gtk_css_transition_values_compute_changes_and_affects (change->old_style,
|
|
|
|
change->new_style,
|
|
|
|
&change->changes,
|
|
|
|
&change->affects);
|
2020-02-02 15:34:45 +00:00
|
|
|
|
2020-01-28 17:13:37 +00:00
|
|
|
if (change->old_style->size != change->new_style->size)
|
|
|
|
gtk_css_size_values_compute_changes_and_affects (change->old_style,
|
|
|
|
change->new_style,
|
|
|
|
&change->changes,
|
|
|
|
&change->affects);
|
2020-02-02 15:34:45 +00:00
|
|
|
|
2020-01-28 17:13:37 +00:00
|
|
|
if (change->old_style->other != change->new_style->other)
|
|
|
|
gtk_css_other_values_compute_changes_and_affects (change->old_style,
|
|
|
|
change->new_style,
|
|
|
|
&change->changes,
|
|
|
|
&change->affects);
|
|
|
|
}
|
|
|
|
|
2015-12-12 01:02:04 +00:00
|
|
|
void
|
|
|
|
gtk_css_style_change_init (GtkCssStyleChange *change,
|
|
|
|
GtkCssStyle *old_style,
|
|
|
|
GtkCssStyle *new_style)
|
|
|
|
{
|
|
|
|
change->old_style = g_object_ref (old_style);
|
|
|
|
change->new_style = g_object_ref (new_style);
|
|
|
|
|
|
|
|
change->affects = 0;
|
2015-12-13 03:08:44 +00:00
|
|
|
change->changes = _gtk_bitmask_new ();
|
2016-01-16 22:15:11 +00:00
|
|
|
|
2020-01-28 17:13:37 +00:00
|
|
|
if (old_style != new_style)
|
|
|
|
compute_change (change);
|
2015-12-12 01:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_css_style_change_finish (GtkCssStyleChange *change)
|
|
|
|
{
|
|
|
|
g_object_unref (change->old_style);
|
|
|
|
g_object_unref (change->new_style);
|
2015-12-13 03:08:44 +00:00
|
|
|
_gtk_bitmask_free (change->changes);
|
2015-12-12 01:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkCssStyle *
|
|
|
|
gtk_css_style_change_get_old_style (GtkCssStyleChange *change)
|
|
|
|
{
|
|
|
|
return change->old_style;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkCssStyle *
|
|
|
|
gtk_css_style_change_get_new_style (GtkCssStyleChange *change)
|
|
|
|
{
|
|
|
|
return change->new_style;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gtk_css_style_change_has_change (GtkCssStyleChange *change)
|
|
|
|
{
|
2020-01-28 17:13:37 +00:00
|
|
|
return !_gtk_bitmask_is_empty (change->changes);
|
2015-12-12 01:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gtk_css_style_change_affects (GtkCssStyleChange *change,
|
|
|
|
GtkCssAffects affects)
|
|
|
|
{
|
2020-01-28 17:13:37 +00:00
|
|
|
return (change->affects & affects) != 0;
|
2015-12-12 01:02:04 +00:00
|
|
|
}
|
|
|
|
|
2015-12-13 03:08:44 +00:00
|
|
|
gboolean
|
|
|
|
gtk_css_style_change_changes_property (GtkCssStyleChange *change,
|
|
|
|
guint id)
|
|
|
|
{
|
|
|
|
return _gtk_bitmask_get (change->changes, id);
|
|
|
|
}
|
|
|
|
|
2016-02-05 09:28:13 +00:00
|
|
|
void
|
|
|
|
gtk_css_style_change_print (GtkCssStyleChange *change,
|
|
|
|
GString *string)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
GtkCssStyle *old = gtk_css_style_change_get_old_style (change);
|
|
|
|
GtkCssStyle *new = gtk_css_style_change_get_new_style (change);
|
|
|
|
|
|
|
|
for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i ++)
|
|
|
|
{
|
|
|
|
if (gtk_css_style_change_changes_property (change, i))
|
|
|
|
{
|
|
|
|
GtkCssStyleProperty *prop;
|
|
|
|
GtkCssValue *value;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
prop = _gtk_css_style_property_lookup_by_id (i);
|
|
|
|
name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop));
|
|
|
|
|
|
|
|
g_string_append_printf (string, "%s: ", name);
|
2017-07-22 07:22:56 +00:00
|
|
|
value = gtk_css_style_get_value (old, i);
|
2016-02-05 09:28:13 +00:00
|
|
|
_gtk_css_value_print (value, string);
|
|
|
|
g_string_append (string, "\n");
|
|
|
|
|
|
|
|
g_string_append_printf (string, "%s: ", name);
|
|
|
|
value = gtk_css_style_get_value (new, i);
|
|
|
|
_gtk_css_value_print (value, string);
|
|
|
|
g_string_append (string, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
gtk_css_style_change_to_string (GtkCssStyleChange *change)
|
|
|
|
{
|
|
|
|
GString *string = g_string_new ("");
|
|
|
|
|
|
|
|
gtk_css_style_change_print (change, string);
|
|
|
|
|
|
|
|
return g_string_free (string, FALSE);
|
|
|
|
}
|