1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4 * Moonlight List (moonlight-list@lists.ximian.com)
6 * Copyright 2007 Novell, Inc. (http://www.novell.com)
8 * See the LICENSE file included with the distribution for details.
15 DependencyObject
*object
;
16 GList
*properties_list
;
20 DependencyProperty
*property
;
44 property_indexer_compare_func (property_indexer
*a
, property_indexer
*b
)
46 if (a
->property
== b
->property
)
53 value_indexer_compare_func (value_indexer
*a
, value_indexer
*b
)
55 if (a
->precedence
< b
->precedence
)
57 else if (a
->precedence
> b
->precedence
)
64 Applier::AddPropertyChange (DependencyObject
*object
, DependencyProperty
*property
, Value
*v
, int precedence
)
67 g_warning ("Applier::AddPropertyChange is being called during shutdown");
72 if (precedence
== APPLIER_PRECEDENCE_INSTANT
) {
73 object
->SetValue (property
, *v
);
78 value_indexer
*v_indexer
= NULL
;
79 property_indexer
*p_indexer
= NULL
;
80 object_indexer
*o_indexer
= NULL
;
83 objects
= g_hash_table_new (g_direct_hash
, g_direct_equal
);
85 o_indexer
= (object_indexer
*) g_hash_table_lookup (objects
, object
);
87 if (o_indexer
== NULL
) {
88 o_indexer
= g_new (object_indexer
, 1);
89 o_indexer
->object
= object
;
91 o_indexer
->properties_list
= NULL
;
92 g_hash_table_insert (objects
, object
, o_indexer
);
95 GList
*list_item
= g_list_find_custom (o_indexer
->properties_list
, property
, (GCompareFunc
) property_indexer_compare_func
);
97 if (list_item
!= NULL
)
98 p_indexer
= (property_indexer
*) list_item
->data
;
100 if (p_indexer
== NULL
) {
101 p_indexer
= g_new (property_indexer
, 1);
102 p_indexer
->property
= property
;
103 p_indexer
->values_list
= NULL
;
104 o_indexer
->properties_list
= g_list_append (o_indexer
->properties_list
, p_indexer
);
107 v_indexer
= g_new (value_indexer
, 1);
108 v_indexer
->precedence
= precedence
;
111 p_indexer
->values_list
= g_list_insert_sorted (p_indexer
->values_list
, v_indexer
, (GCompareFunc
) value_indexer_compare_func
);
115 destroy_value_func (value_indexer
*v_indexer
, gpointer unused
)
117 g_return_if_fail (v_indexer
!= NULL
);
118 g_return_if_fail (v_indexer
->v
!= NULL
);
126 destroy_property_func (property_indexer
*p_indexer
, gpointer unused
)
128 g_return_if_fail (p_indexer
!= NULL
);
129 g_return_if_fail (p_indexer
->values_list
!= NULL
);
131 g_list_foreach (p_indexer
->values_list
, (GFunc
) destroy_value_func
, NULL
);
132 g_list_free (p_indexer
->values_list
);
133 p_indexer
->property
= NULL
;
134 p_indexer
->values_list
= NULL
;
139 destroy_object_func (DependencyObject
*object
, object_indexer
*o_indexer
, gpointer unused
)
141 g_return_if_fail (object
!= NULL
);
142 g_return_if_fail (o_indexer
!= NULL
);
144 g_list_foreach (o_indexer
->properties_list
, (GFunc
) destroy_property_func
, NULL
);
145 g_list_free (o_indexer
->properties_list
);
151 apply_property_func (property_indexer
*p_indexer
, DependencyObject
*object
)
153 g_return_if_fail (p_indexer
->property
!= NULL
);
154 g_return_if_fail (p_indexer
->values_list
!= NULL
);
156 value_indexer
*v_indexer
= (value_indexer
*) p_indexer
->values_list
->data
;
157 object
->SetValue (p_indexer
->property
, *v_indexer
->v
);
161 apply_object_func (DependencyObject
*object
, object_indexer
*o_indexer
, gpointer unused
)
163 g_return_if_fail (o_indexer
!= NULL
);
165 g_list_foreach (o_indexer
->properties_list
, (GFunc
) apply_property_func
, object
);
172 g_hash_table_foreach (objects
, (GHFunc
) apply_object_func
, NULL
);
179 g_hash_table_foreach (objects
, (GHFunc
) destroy_object_func
, NULL
);
180 g_hash_table_destroy (objects
);