summaryrefslogtreecommitdiff
path: root/gtk/gtkcssstylechange.c
blob: 50eac153e18c2a216968868898a78e4759aa5493 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* 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"

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->n_compared = 0;

  change->affects = 0;
  change->changes = _gtk_bitmask_new ();
}

void
gtk_css_style_change_finish (GtkCssStyleChange *change)
{
  g_object_unref (change->old_style);
  g_object_unref (change->new_style);
  _gtk_bitmask_free (change->changes);
}

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;
}

static gboolean
gtk_css_style_compare_next_value (GtkCssStyleChange *change)
{
  if (change->n_compared == GTK_CSS_PROPERTY_N_PROPERTIES)
    return FALSE;

  if (!_gtk_css_value_equal (gtk_css_style_get_value (change->old_style, change->n_compared),
                             gtk_css_style_get_value (change->new_style, change->n_compared)))
    {
      change->affects |= _gtk_css_style_property_get_affects (_gtk_css_style_property_lookup_by_id (change->n_compared));
      change->changes = _gtk_bitmask_set (change->changes, change->n_compared, TRUE);
    }

  change->n_compared++;

  return TRUE;
}

gboolean
gtk_css_style_change_has_change (GtkCssStyleChange *change)
{
  do {
    if (!_gtk_bitmask_is_empty (change->changes))
      return TRUE;
  } while (gtk_css_style_compare_next_value (change));

  return FALSE;
}

gboolean
gtk_css_style_change_affects (GtkCssStyleChange *change,
                              GtkCssAffects      affects)
{
  do {
    if (change->affects & affects)
      return TRUE;
  } while (gtk_css_style_compare_next_value (change));

  return FALSE;
}

gboolean
gtk_css_style_change_changes_property (GtkCssStyleChange *change,
                                       guint              id)
{
  while (change->n_compared <= id)
    gtk_css_style_compare_next_value (change);

  return _gtk_bitmask_get (change->changes, id);
}