From e85d5eab8483bbd3bb15488d001af1bfc2c21743 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 9 Jan 2008 14:18:53 +0000 Subject: [PATCH] 2008-01-09 Emmanuele Bassi * clutter/clutter-model-default.c: (clutter_model_default_new), (clutter_model_default_newv): Move the constructors in the right file * clutter/clutter-model-private.h: Add a private header for the ClutterModel implementations * clutter/clutter-model.c: (clutter_model_check_type), (clutter_model_set_n_columns), (clutter_model_set_column_type): Mark as private to Clutter, not static to ClutterModel * clutter/Makefile.am: Add clutter-model-private.h --- ChangeLog | 18 +++++ clutter/Makefile.am | 1 + clutter/clutter-model-default.c | 107 ++++++++++++++++++++++++++ clutter/clutter-model-private.h | 24 ++++++ clutter/clutter-model.c | 164 ++++++++++------------------------------ doc/reference/Makefile.am | 1 + 6 files changed, 191 insertions(+), 124 deletions(-) create mode 100644 clutter/clutter-model-private.h diff --git a/ChangeLog b/ChangeLog index 7478ab8..5c67388 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,23 @@ 2008-01-09 Emmanuele Bassi + * clutter/clutter-model-default.c: + (clutter_model_default_new), + (clutter_model_default_newv): Move the constructors in the + right file + + * clutter/clutter-model-private.h: Add a private header for + the ClutterModel implementations + + * clutter/clutter-model.c: + (clutter_model_check_type), + (clutter_model_set_n_columns), + (clutter_model_set_column_type): Mark as private to Clutter, + not static to ClutterModel + + * clutter/Makefile.am: Add clutter-model-private.h + +2008-01-09 Emmanuele Bassi + * clutter/clutter-label.c: (clutter_label_ensure_layout): Fix the ClutterUnits to Pango scale conversion. diff --git a/clutter/Makefile.am b/clutter/Makefile.am index 0314215..11c9f9c 100644 --- a/clutter/Makefile.am +++ b/clutter/Makefile.am @@ -167,6 +167,7 @@ source_c = \ source_h_priv = \ clutter-debug.h \ clutter-keysyms-table.h \ + clutter-model-private.h \ clutter-private.h \ clutter-script-private.h \ $(NULL) diff --git a/clutter/clutter-model-default.c b/clutter/clutter-model-default.c index bbe7455..4185d2e 100644 --- a/clutter/clutter-model-default.c +++ b/clutter/clutter-model-default.c @@ -50,6 +50,7 @@ #include #include "clutter-model.h" +#include "clutter-model-private.h" #include "clutter-model-default.h" #include "clutter-private.h" #include "clutter-debug.h" @@ -658,3 +659,109 @@ clutter_model_default_init (ClutterModelDefault *model) { model->sequence = g_sequence_new (NULL); } + +/** + * clutter_model_default_new: + * @n_columns: number of columns in the model + * @Varargs: @n_columns number of #GType and string pairs + * + * Creates a new default model with @n_columns columns with the types + * and names passed in. + * + * For example: + * + * + * model = clutter_model_default_new (3, + * G_TYPE_INT, "Score", + * G_TYPE_STRING, "Team", + * GDK_TYPE_PIXBUF, "Logo"); + * + * + * will create a new #ClutterModel with three columns of type int, + * string and #GdkPixbuf respectively. + * + * Note that the name of the column can be set to %NULL, in which case + * the canonical name of the type held by the column will be used as + * the title. + * + * Return value: a new default #ClutterModel + * + * Since: 0.6 + */ +ClutterModel * +clutter_model_default_new (guint n_columns, + ...) +{ + ClutterModel *model; + va_list args; + gint i; + + g_return_val_if_fail (n_columns > 0, NULL); + + model = g_object_new (CLUTTER_TYPE_MODEL_DEFAULT, NULL); + clutter_model_set_n_columns (model, n_columns, TRUE, TRUE); + + va_start (args, n_columns); + + for (i = 0; i < n_columns; i++) + { + GType type = va_arg (args, GType); + const gchar *name = va_arg (args, gchar*); + + if (!clutter_model_check_type (type)) + { + g_warning ("%s: Invalid type %s\n", G_STRLOC, g_type_name (type)); + g_object_unref (model); + return NULL; + } + + clutter_model_set_column_type (model, i, type); + clutter_model_set_column_name (model, i, name); + } + + va_end (args); + + return model; +} + +/** + * clutter_model_default_newv: + * @n_columns: number of columns in the model + * @types: an array of #GType types for the columns, from first to last + * @names: an array of names for the columns, from first to last + * + * Non-vararg version of clutter_model_default_new(). This function is + * useful for language bindings. + * + * Return value: a new default #ClutterModel + * + * Since: 0.6 + */ +ClutterModel * +clutter_model_default_newv (guint n_columns, + GType *types, + const gchar * const names[]) +{ + ClutterModel *model; + gint i; + + g_return_val_if_fail (n_columns > 0, NULL); + + model = g_object_new (CLUTTER_TYPE_MODEL_DEFAULT, NULL); + clutter_model_set_n_columns (model, n_columns, TRUE, TRUE); + + for (i = 0; i < n_columns; i++) + { + if (!clutter_model_check_type (types[i])) + { + g_warning ("%s: Invalid type %s\n", G_STRLOC, g_type_name (types[i])); + g_object_unref (model); + return NULL; + } + + clutter_model_set_column_type (model, i, types[i]); + clutter_model_set_column_name (model, i, names[i]); + } + + return model; +} diff --git a/clutter/clutter-model-private.h b/clutter/clutter-model-private.h new file mode 100644 index 0000000..051ca15 --- /dev/null +++ b/clutter/clutter-model-private.h @@ -0,0 +1,24 @@ +#ifndef __CLUTTER_MODEL_PRIVATE_H__ +#define __CLUTTER_MODEL_PRIVATE_H__ + +#include +#include "clutter-model.h" + +G_BEGIN_DECLS + +void clutter_model_set_n_columns (ClutterModel *model, + gint n_columns, + gboolean set_types, + gboolean set_names); +gboolean clutter_model_check_type (GType gtype); + +void clutter_model_set_column_type (ClutterModel *model, + gint column, + GType gtype); +void clutter_model_set_column_name (ClutterModel *model, + gint column, + const gchar *name); + +G_END_DECLS + +#endif /* __CLUTTER_MODEL_PRIVATE_H__ */ diff --git a/clutter/clutter-model.c b/clutter/clutter-model.c index 262fea8..2c327b4 100644 --- a/clutter/clutter-model.c +++ b/clutter/clutter-model.c @@ -127,7 +127,7 @@ #include #include "clutter-model.h" -#include "clutter-model-default.h" +#include "clutter-model-private.h" #include "clutter-marshal.h" #include "clutter-private.h" @@ -381,8 +381,8 @@ clutter_model_init (ClutterModel *self) /* XXX - is this whitelist really necessary? we accept every fundamental * type. */ -static gboolean -clutter_model_check_type (type) +gboolean +clutter_model_check_type (GType gtype) { gint i = 0; static const GType type_list[] = @@ -407,12 +407,12 @@ clutter_model_check_type (type) G_TYPE_INVALID }; - if (! G_TYPE_IS_VALUE_TYPE (type)) + if (! G_TYPE_IS_VALUE_TYPE (gtype)) return FALSE; while (type_list[i] != G_TYPE_INVALID) { - if (g_type_is_a (type, type_list[i])) + if (g_type_is_a (gtype, type_list[i])) return TRUE; i++; } @@ -519,7 +519,20 @@ clutter_model_filter_iter (ClutterModel *model, return priv->filter_func (model, iter, priv->filter_data); } -static void +/* + * clutter_model_set_n_columns: + * @model: a #ClutterModel + * @n_columns: number of columns + * @set_types: set the columns type + * @set_names: set the columns name + * + * Sets the number of columns in @model to @n_columns. If @set_types + * or @set_names are %TRUE, initialises the columns type and name + * arrays as well. + * + * This function can only be called once. + */ +void clutter_model_set_n_columns (ClutterModel *model, gint n_columns, gboolean set_types, @@ -540,20 +553,36 @@ clutter_model_set_n_columns (ClutterModel *model, priv->column_types = g_new0 (GType, n_columns); if (set_names && !priv->column_names) - priv->column_names = g_new0 (gchar*, n_columns + 1); + priv->column_names = g_new0 (gchar*, n_columns); } -static inline void +/* + * clutter_model_set_column_type: + * @model: a #ClutterModel + * @column: column index + * @gtype: type of the column + * + * Sets the type of @column inside @model + */ +void clutter_model_set_column_type (ClutterModel *model, gint column, - GType type) + GType gtype) { ClutterModelPrivate *priv = model->priv; - priv->column_types[column] = type; + priv->column_types[column] = gtype; } -static inline void +/* + * clutter_model_set_column_name: + * @model: a #ClutterModel + * @column: column index + * @name: name of the column, or %NULL + * + * Sets the name of @column inside @model + */ +void clutter_model_set_column_name (ClutterModel *model, gint column, const gchar *name) @@ -563,119 +592,6 @@ clutter_model_set_column_name (ClutterModel *model, priv->column_names[column] = g_strdup (name); } -/* we implement the constructors of the default model here because - * we need the private accessors to the column names and types - * vectors inside ClutterModelPrivate, to avoid having them inside - * a private header; the ClutterModelDefault ctors are declared inside - * clutter-model-default.h - */ - -/** - * clutter_model_default_new: - * @n_columns: number of columns in the model - * @Varargs: @n_columns number of #GType and string pairs - * - * Creates a new default model with @n_columns columns with the types - * and names passed in. - * - * For example: - * - * - * model = clutter_model_default_new (3, - * G_TYPE_INT, "Score", - * G_TYPE_STRING, "Team", - * GDK_TYPE_PIXBUF, "Logo"); - * - * - * will create a new #ClutterModel with three columns of type int, - * string and #GdkPixbuf respectively. - * - * Note that the name of the column can be set to %NULL, in which case - * the canonical name of the type held by the column will be used as - * the title. - * - * Return value: a new default #ClutterModel - * - * Since: 0.6 - */ -ClutterModel * -clutter_model_default_new (guint n_columns, - ...) -{ - ClutterModel *model; - va_list args; - gint i; - - g_return_val_if_fail (n_columns > 0, NULL); - - model = g_object_new (CLUTTER_TYPE_MODEL_DEFAULT, NULL); - clutter_model_set_n_columns (model, n_columns, TRUE, TRUE); - - va_start (args, n_columns); - - for (i = 0; i < n_columns; i++) - { - GType type = va_arg (args, GType); - const gchar *name = va_arg (args, gchar*); - - if (!clutter_model_check_type (type)) - { - g_warning ("%s: Invalid type %s\n", G_STRLOC, g_type_name (type)); - g_object_unref (model); - return NULL; - } - - clutter_model_set_column_type (model, i, type); - clutter_model_set_column_name (model, i, name); - } - - va_end (args); - - return model; -} - -/** - * clutter_model_default_newv: - * @n_columns: number of columns in the model - * @types: an array of #GType types for the columns, from first to last - * @names: an array of names for the columns, from first to last - * - * Non-vararg version of clutter_model_default_new(). This function is - * useful for language bindings. - * - * Return value: a new default #ClutterModel - * - * Since: 0.6 - */ -ClutterModel * -clutter_model_default_newv (guint n_columns, - GType *types, - const gchar * const names[]) -{ - ClutterModel *model; - gint i; - - g_return_val_if_fail (n_columns > 0, NULL); - - model = g_object_new (CLUTTER_TYPE_MODEL_DEFAULT, NULL); - clutter_model_set_n_columns (model, n_columns, TRUE, TRUE); - - for (i = 0; i < n_columns; i++) - { - if (!clutter_model_check_type (types[i])) - { - g_warning ("%s: Invalid type %s\n", G_STRLOC, g_type_name (types[i])); - g_object_unref (model); - return NULL; - } - - clutter_model_set_column_type (model, i, types[i]); - clutter_model_set_column_name (model, i, names[i]); - } - - return model; -} - /** * clutter_model_set_types: * @model: a #ClutterModel diff --git a/doc/reference/Makefile.am b/doc/reference/Makefile.am index beda449..307a37e 100644 --- a/doc/reference/Makefile.am +++ b/doc/reference/Makefile.am @@ -57,6 +57,7 @@ IGNORE_HFILES=\ clutter-keysyms.h \ clutter-keysyms-table.h \ clutter-marshal.h \ + clutter-model-private.h \ clutter-private.h \ clutter-script-private.h \ stamp-clutter-enum-types.h \ -- 2.7.4