* 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, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#include "gtkcssshorthandpropertyprivate.h"
+#include "gtkcssarrayvalueprivate.h"
+#include "gtkcssinheritvalueprivate.h"
+#include "gtkcssinitialvalueprivate.h"
#include "gtkcssstylefuncsprivate.h"
-#include "gtkcsstypesprivate.h"
#include "gtkintl.h"
-#include "gtkprivatetypebuiltins.h"
enum {
PROP_0,
GtkStateFlags state,
const GValue *value)
{
- GParameter *parameters;
- guint i, n_parameters;
-
- parameters = property->unpack_func (value, &n_parameters);
+ GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
- for (i = 0; i < n_parameters; i++)
- {
- _gtk_style_property_assign (_gtk_style_property_lookup (parameters[i].name),
- props,
- state,
- ¶meters[i].value);
- g_value_unset (¶meters[i].value);
- }
- g_free (parameters);
+ shorthand->assign (shorthand, props, state, value);
}
static void
_gtk_css_shorthand_property_query (GtkStyleProperty *property,
- GtkStyleProperties *props,
- GtkStateFlags state,
- GtkStylePropertyContext *context,
- GValue *value)
+ GValue *value,
+ GtkStyleQueryFunc query_func,
+ gpointer query_data)
{
- property->pack_func (value, props, state, context);
+ GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
+
+ return shorthand->query (shorthand, value, query_func, query_data);
}
-static gboolean
+static GtkCssValue *
gtk_css_shorthand_property_parse_value (GtkStyleProperty *property,
- GValue *value,
- GtkCssParser *parser,
- GFile *base)
+ GtkCssParser *parser)
{
GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
- GValueArray *array;
+ GtkCssValue **data;
+ GtkCssValue *result;
guint i;
- array = g_value_array_new (shorthand->subproperties->len);
- for (i = 0; i < shorthand->subproperties->len; i++)
- g_value_array_append (array, NULL);
+ data = g_new0 (GtkCssValue *, shorthand->subproperties->len);
if (_gtk_css_parser_try (parser, "initial", TRUE))
{
*/
for (i = 0; i < shorthand->subproperties->len; i++)
{
- GValue *val = g_value_array_get_nth (array, i);
- g_value_init (val, GTK_TYPE_CSS_SPECIAL_VALUE);
- g_value_set_enum (val, GTK_CSS_INITIAL);
+ data[i] = _gtk_css_initial_value_new ();
}
}
else if (_gtk_css_parser_try (parser, "inherit", TRUE))
*/
for (i = 0; i < shorthand->subproperties->len; i++)
{
- GValue *val = g_value_array_get_nth (array, i);
- g_value_init (val, GTK_TYPE_CSS_SPECIAL_VALUE);
- g_value_set_enum (val, GTK_CSS_INHERIT);
+ data[i] = _gtk_css_inherit_value_new ();
}
}
- else if (!shorthand->parse (shorthand, array->values, parser, base))
+ else if (!shorthand->parse (shorthand, data, parser))
{
- g_value_array_free (array);
- return FALSE;
+ for (i = 0; i < shorthand->subproperties->len; i++)
+ {
+ if (data[i] != NULL)
+ _gtk_css_value_unref (data[i]);
+ }
+ g_free (data);
+ return NULL;
}
/* All values that aren't set by the parse func are set to their
* XXX: Is the default always initial or can it be inherit? */
for (i = 0; i < shorthand->subproperties->len; i++)
{
- GValue *val = g_value_array_get_nth (array, i);
- if (G_IS_VALUE (val))
- continue;
- g_value_init (val, GTK_TYPE_CSS_SPECIAL_VALUE);
- g_value_set_enum (val, GTK_CSS_INITIAL);
+ if (data[i] == NULL)
+ data[i] = _gtk_css_initial_value_new ();
}
- g_value_unset (value);
- g_value_init (value, G_TYPE_VALUE_ARRAY);
- g_value_set_boxed (value, array);
- return TRUE;
+ result = _gtk_css_array_value_new_from_array (data, shorthand->subproperties->len);
+ g_free (data);
+
+ return result;
}
static void
property_class->parse_value = gtk_css_shorthand_property_parse_value;
}
-/* XXX: This function is compat only, don't read it */
-static gboolean
-gtk_css_shorthand_property_parse (GtkCssShorthandProperty *shorthand,
- GValue *values,
- GtkCssParser *parser,
- GFile *base)
-{
- GtkStyleProperty *property = GTK_STYLE_PROPERTY (shorthand);
- GParameter *parameters;
- guint i, j, n_parameters;
-
- GValue val = G_VALUE_INIT;
-
- g_value_init (&val, _gtk_style_property_get_value_type (property));
- if (property->parse_func)
- {
- if (!(* property->parse_func) (parser, base, &val))
- {
- g_value_unset (&val);
- return FALSE;
- }
- }
- else if (!_gtk_css_style_parse_value (&val, parser, base))
- {
- g_value_unset (&val);
- return FALSE;
- }
-
- parameters = property->unpack_func (&val, &n_parameters);
- g_value_unset (&val);
-
- for (i = 0; i < shorthand->subproperties->len; i++)
- {
- for (j = 0; j < n_parameters; j++)
- {
- if (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, i))
- == _gtk_style_property_lookup (parameters[j].name))
- {
- g_value_init (&values[i], G_VALUE_TYPE (¶meters[j].value));
- g_value_copy (¶meters[j].value, &values[i]);
- g_value_unset (¶meters[j].value);
- break;
- }
- }
- g_assert (j < n_parameters);
- }
-
- g_free (parameters);
-
- return TRUE;
-}
-
static void
_gtk_css_shorthand_property_init (GtkCssShorthandProperty *shorthand)
{
shorthand->subproperties = g_ptr_array_new_with_free_func (g_object_unref);
-
- shorthand->parse = gtk_css_shorthand_property_parse;
}
GtkCssStyleProperty *