2008-01-09 Emmanuele Bassi <ebassi@openedhand.com>

* 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
This commit is contained in:
Emmanuele Bassi 2008-01-09 14:18:53 +00:00
parent a6c7ce7117
commit e85d5eab84
6 changed files with 191 additions and 124 deletions

View File

@ -1,3 +1,21 @@
2008-01-09 Emmanuele Bassi <ebassi@openedhand.com>
* 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 <ebassi@openedhand.com>
* clutter/clutter-label.c:

View File

@ -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)

View File

@ -50,6 +50,7 @@
#include <glib-object.h>
#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:
*
* <informalexample><programlisting>
* model = clutter_model_default_new (3,
* G_TYPE_INT, "Score",
* G_TYPE_STRING, "Team",
* GDK_TYPE_PIXBUF, "Logo");
* </programlisting></informalexample>
*
* 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;
}

View File

@ -0,0 +1,24 @@
#ifndef __CLUTTER_MODEL_PRIVATE_H__
#define __CLUTTER_MODEL_PRIVATE_H__
#include <glib.h>
#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__ */

View File

@ -127,7 +127,7 @@
#include <gobject/gvaluecollector.h>
#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:
*
* <informalexample><programlisting>
* model = clutter_model_default_new (3,
* G_TYPE_INT, "Score",
* G_TYPE_STRING, "Team",
* GDK_TYPE_PIXBUF, "Logo");
* </programlisting></informalexample>
*
* 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

View File

@ -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 \