2007-12-14 12:25:55 -05:00
|
|
|
|
/*
|
|
|
|
|
* Clutter.
|
|
|
|
|
*
|
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
|
*
|
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
|
* Neil Jagdish Patel <njp@o-hand.com>
|
|
|
|
|
* Emmanuele Bassi <ebassi@openedhand.com>
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006 OpenedHand
|
|
|
|
|
*
|
|
|
|
|
* 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
|
2010-03-01 07:56:10 -05:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
*
|
2007-12-14 12:25:55 -05:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-09 09:34:24 -05:00
|
|
|
|
* SECTION:clutter-list-model
|
|
|
|
|
* @short_description: List model implementation
|
2007-12-14 12:25:55 -05:00
|
|
|
|
*
|
2008-01-09 09:34:24 -05:00
|
|
|
|
* #ClutterListModel is a #ClutterModel implementation provided by
|
|
|
|
|
* Clutter. #ClutterListModel uses a #GSequence for storing the
|
2007-12-14 12:25:55 -05:00
|
|
|
|
* values for each row, so it's optimized for insertion and look up
|
|
|
|
|
* in sorted lists.
|
|
|
|
|
*
|
2008-01-09 09:34:24 -05:00
|
|
|
|
* #ClutterListModel is available since Clutter 0.6
|
2007-12-14 12:25:55 -05:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
|
|
|
|
|
#include "clutter-model.h"
|
2008-01-09 09:18:53 -05:00
|
|
|
|
#include "clutter-model-private.h"
|
2008-01-09 09:40:31 -05:00
|
|
|
|
#include "clutter-list-model.h"
|
2007-12-14 12:25:55 -05:00
|
|
|
|
#include "clutter-private.h"
|
|
|
|
|
#include "clutter-debug.h"
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
#define CLUTTER_TYPE_LIST_MODEL_ITER \
|
|
|
|
|
(clutter_list_model_iter_get_type())
|
|
|
|
|
#define CLUTTER_LIST_MODEL_ITER(obj) \
|
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
|
|
|
|
|
CLUTTER_TYPE_LIST_MODEL_ITER, \
|
|
|
|
|
ClutterListModelIter))
|
|
|
|
|
#define CLUTTER_IS_LIST_MODEL_ITER(obj) \
|
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj), \
|
|
|
|
|
CLUTTER_TYPE_LIST_MODEL_ITER))
|
|
|
|
|
#define CLUTTER_LIST_MODEL_ITER_CLASS(klass) \
|
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST ((klass), \
|
|
|
|
|
CLUTTER_TYPE_LIST_MODEL_ITER, \
|
|
|
|
|
ClutterListModelIterClass))
|
|
|
|
|
#define CLUTTER_IS_LIST_MODEL_ITER_CLASS(klass) \
|
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
|
|
|
|
|
CLUTTER_TYPE_LIST_MODEL_ITER))
|
|
|
|
|
#define CLUTTER_LIST_MODEL_ITER_GET_CLASS(obj) \
|
|
|
|
|
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
|
|
|
|
|
CLUTTER_TYPE_LIST_MODEL_ITER, \
|
|
|
|
|
ClutterListModelIterClass))
|
|
|
|
|
|
|
|
|
|
typedef struct _ClutterListModelIter ClutterListModelIter;
|
|
|
|
|
typedef struct _ClutterModelIterClass ClutterListModelIterClass;
|
|
|
|
|
|
2009-02-14 06:31:00 -05:00
|
|
|
|
#define CLUTTER_LIST_MODEL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_LIST_MODEL, ClutterListModelPrivate))
|
2008-01-09 09:34:24 -05:00
|
|
|
|
|
2009-02-14 06:31:00 -05:00
|
|
|
|
struct _ClutterListModelPrivate
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
|
|
|
|
GSequence *sequence;
|
2009-05-05 14:39:26 -04:00
|
|
|
|
|
|
|
|
|
ClutterModelIter *temp_iter;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
};
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
struct _ClutterListModelIter
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
|
|
|
|
ClutterModelIter parent_instance;
|
|
|
|
|
|
|
|
|
|
GSequenceIter *seq_iter;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-07 07:34:06 -05:00
|
|
|
|
GType clutter_list_model_iter_get_type (void);
|
|
|
|
|
|
2007-12-14 12:25:55 -05:00
|
|
|
|
/*
|
2008-01-09 09:34:24 -05:00
|
|
|
|
* ClutterListModel
|
2007-12-14 12:25:55 -05:00
|
|
|
|
*/
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
G_DEFINE_TYPE (ClutterListModelIter,
|
|
|
|
|
clutter_list_model_iter,
|
2007-12-14 12:25:55 -05:00
|
|
|
|
CLUTTER_TYPE_MODEL_ITER);
|
|
|
|
|
|
|
|
|
|
static void
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_iter_get_value (ClutterModelIter *iter,
|
|
|
|
|
guint column,
|
|
|
|
|
GValue *value)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModelIter *iter_default;
|
2012-02-06 09:37:49 -05:00
|
|
|
|
GValue *values;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
GValue *iter_value;
|
2012-03-17 12:38:06 -04:00
|
|
|
|
GValue real_value = G_VALUE_INIT;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
gboolean converted = FALSE;
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
iter_default = CLUTTER_LIST_MODEL_ITER (iter);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
g_assert (iter_default->seq_iter != NULL);
|
|
|
|
|
|
2012-02-06 09:37:49 -05:00
|
|
|
|
values = g_sequence_get (iter_default->seq_iter);
|
|
|
|
|
iter_value = &values[column];
|
2007-12-14 12:25:55 -05:00
|
|
|
|
g_assert (iter_value != NULL);
|
|
|
|
|
|
|
|
|
|
if (!g_type_is_a (G_VALUE_TYPE (value), G_VALUE_TYPE (iter_value)))
|
|
|
|
|
{
|
|
|
|
|
if (!g_value_type_compatible (G_VALUE_TYPE (value),
|
|
|
|
|
G_VALUE_TYPE (iter_value)) &&
|
|
|
|
|
!g_value_type_compatible (G_VALUE_TYPE (iter_value),
|
|
|
|
|
G_VALUE_TYPE (value)))
|
|
|
|
|
{
|
|
|
|
|
g_warning ("%s: Unable to convert from %s to %s",
|
|
|
|
|
G_STRLOC,
|
|
|
|
|
g_type_name (G_VALUE_TYPE (value)),
|
|
|
|
|
g_type_name (G_VALUE_TYPE (iter_value)));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-18 09:32:57 -05:00
|
|
|
|
if (!g_value_transform (iter_value, &real_value))
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
|
|
|
|
g_warning ("%s: Unable to make conversion from %s to %s",
|
|
|
|
|
G_STRLOC,
|
|
|
|
|
g_type_name (G_VALUE_TYPE (value)),
|
|
|
|
|
g_type_name (G_VALUE_TYPE (iter_value)));
|
|
|
|
|
g_value_unset (&real_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
converted = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (converted)
|
|
|
|
|
{
|
|
|
|
|
g_value_copy (&real_value, value);
|
|
|
|
|
g_value_unset (&real_value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
g_value_copy (iter_value, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_iter_set_value (ClutterModelIter *iter,
|
|
|
|
|
guint column,
|
|
|
|
|
const GValue *value)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModelIter *iter_default;
|
2012-02-06 09:37:49 -05:00
|
|
|
|
GValue *values;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
GValue *iter_value;
|
2012-03-17 12:38:06 -04:00
|
|
|
|
GValue real_value = G_VALUE_INIT;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
gboolean converted = FALSE;
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
iter_default = CLUTTER_LIST_MODEL_ITER (iter);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
g_assert (iter_default->seq_iter != NULL);
|
|
|
|
|
|
2012-02-06 09:37:49 -05:00
|
|
|
|
values = g_sequence_get (iter_default->seq_iter);
|
|
|
|
|
iter_value = &values[column];
|
2007-12-14 12:25:55 -05:00
|
|
|
|
g_assert (iter_value != NULL);
|
|
|
|
|
|
|
|
|
|
if (!g_type_is_a (G_VALUE_TYPE (value), G_VALUE_TYPE (iter_value)))
|
|
|
|
|
{
|
|
|
|
|
if (!g_value_type_compatible (G_VALUE_TYPE (value),
|
|
|
|
|
G_VALUE_TYPE (iter_value)) &&
|
|
|
|
|
!g_value_type_compatible (G_VALUE_TYPE (iter_value),
|
|
|
|
|
G_VALUE_TYPE (value)))
|
|
|
|
|
{
|
|
|
|
|
g_warning ("%s: Unable to convert from %s to %s\n",
|
|
|
|
|
G_STRLOC,
|
|
|
|
|
g_type_name (G_VALUE_TYPE (value)),
|
|
|
|
|
g_type_name (G_VALUE_TYPE (iter_value)));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!g_value_transform (value, &real_value))
|
|
|
|
|
{
|
|
|
|
|
g_warning ("%s: Unable to make conversion from %s to %s\n",
|
|
|
|
|
G_STRLOC,
|
|
|
|
|
g_type_name (G_VALUE_TYPE (value)),
|
|
|
|
|
g_type_name (G_VALUE_TYPE (iter_value)));
|
|
|
|
|
g_value_unset (&real_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
converted = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (converted)
|
|
|
|
|
{
|
|
|
|
|
g_value_copy (&real_value, iter_value);
|
|
|
|
|
g_value_unset (&real_value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
g_value_copy (value, iter_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_iter_is_first (ClutterModelIter *iter)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModelIter *iter_default;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
ClutterModel *model;
|
|
|
|
|
ClutterModelIter *temp_iter;
|
2009-02-14 06:31:00 -05:00
|
|
|
|
GSequence *sequence;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
GSequenceIter *begin, *end;
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
iter_default = CLUTTER_LIST_MODEL_ITER (iter);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
g_assert (iter_default->seq_iter != NULL);
|
|
|
|
|
|
|
|
|
|
model = clutter_model_iter_get_model (iter);
|
|
|
|
|
|
2009-02-14 06:31:00 -05:00
|
|
|
|
sequence = CLUTTER_LIST_MODEL (model)->priv->sequence;
|
|
|
|
|
|
|
|
|
|
begin = g_sequence_get_begin_iter (sequence);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
end = iter_default->seq_iter;
|
|
|
|
|
|
2009-05-05 14:39:26 -04:00
|
|
|
|
temp_iter = CLUTTER_LIST_MODEL (model)->priv->temp_iter;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
while (!g_sequence_iter_is_begin (begin))
|
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
CLUTTER_LIST_MODEL_ITER (temp_iter)->seq_iter = begin;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
if (clutter_model_filter_iter (model, temp_iter))
|
|
|
|
|
{
|
|
|
|
|
end = begin;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
begin = g_sequence_iter_next (begin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This is because the 'begin_iter' is always *before* the last valid
|
|
|
|
|
* iter, otherwise we'd have endless loops
|
|
|
|
|
*/
|
|
|
|
|
end = g_sequence_iter_prev (end);
|
|
|
|
|
|
|
|
|
|
return iter_default->seq_iter == end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_iter_is_last (ClutterModelIter *iter)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModelIter *iter_default;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
ClutterModelIter *temp_iter;
|
|
|
|
|
ClutterModel *model;
|
2009-02-14 06:31:00 -05:00
|
|
|
|
GSequence *sequence;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
GSequenceIter *begin, *end;
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
iter_default = CLUTTER_LIST_MODEL_ITER (iter);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
g_assert (iter_default->seq_iter != NULL);
|
|
|
|
|
|
|
|
|
|
if (g_sequence_iter_is_end (iter_default->seq_iter))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
model = clutter_model_iter_get_model (iter);
|
|
|
|
|
|
2009-02-14 06:31:00 -05:00
|
|
|
|
sequence = CLUTTER_LIST_MODEL (model)->priv->sequence;
|
|
|
|
|
|
|
|
|
|
begin = g_sequence_get_end_iter (sequence);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
begin = g_sequence_iter_prev (begin);
|
|
|
|
|
end = iter_default->seq_iter;
|
|
|
|
|
|
2009-05-05 14:39:26 -04:00
|
|
|
|
temp_iter = CLUTTER_LIST_MODEL (model)->priv->temp_iter;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
while (!g_sequence_iter_is_begin (begin))
|
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
CLUTTER_LIST_MODEL_ITER (temp_iter)->seq_iter = begin;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
if (clutter_model_filter_iter (model, temp_iter))
|
|
|
|
|
{
|
|
|
|
|
end = begin;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
begin = g_sequence_iter_prev (begin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This is because the 'end_iter' is always *after* the last valid iter.
|
|
|
|
|
* Otherwise we'd have endless loops
|
|
|
|
|
*/
|
|
|
|
|
end = g_sequence_iter_next (end);
|
|
|
|
|
|
|
|
|
|
return iter_default->seq_iter == end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ClutterModelIter *
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_iter_next (ClutterModelIter *iter)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModelIter *iter_default;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
ClutterModelIter *temp_iter;
|
|
|
|
|
ClutterModel *model = NULL;
|
|
|
|
|
GSequenceIter *filter_next;
|
|
|
|
|
guint row;
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
iter_default = CLUTTER_LIST_MODEL_ITER (iter);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
g_assert (iter_default->seq_iter != NULL);
|
|
|
|
|
|
|
|
|
|
model = clutter_model_iter_get_model (iter);
|
2009-04-29 10:26:05 -04:00
|
|
|
|
row = clutter_model_iter_get_row (iter);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
filter_next = g_sequence_iter_next (iter_default->seq_iter);
|
|
|
|
|
g_assert (filter_next != NULL);
|
|
|
|
|
|
2009-05-05 14:39:26 -04:00
|
|
|
|
temp_iter = CLUTTER_LIST_MODEL (model)->priv->temp_iter;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
while (!g_sequence_iter_is_end (filter_next))
|
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
CLUTTER_LIST_MODEL_ITER (temp_iter)->seq_iter = filter_next;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
if (clutter_model_filter_iter (model, temp_iter))
|
2009-04-29 10:26:05 -04:00
|
|
|
|
{
|
|
|
|
|
row += 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
filter_next = g_sequence_iter_next (filter_next);
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-29 10:26:05 -04:00
|
|
|
|
if (g_sequence_iter_is_end (filter_next))
|
|
|
|
|
row += 1;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
2007-12-15 08:02:06 -05:00
|
|
|
|
/* update the iterator and return it */
|
2012-02-09 13:40:03 -05:00
|
|
|
|
_clutter_model_iter_set_row (CLUTTER_MODEL_ITER (iter_default), row);
|
2007-12-15 08:02:06 -05:00
|
|
|
|
iter_default->seq_iter = filter_next;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
2007-12-15 08:02:06 -05:00
|
|
|
|
return CLUTTER_MODEL_ITER (iter_default);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ClutterModelIter *
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_iter_prev (ClutterModelIter *iter)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModelIter *iter_default;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
ClutterModelIter *temp_iter;
|
|
|
|
|
ClutterModel *model;
|
|
|
|
|
GSequenceIter *filter_prev;
|
|
|
|
|
guint row;
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
iter_default = CLUTTER_LIST_MODEL_ITER (iter);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
g_assert (iter_default->seq_iter != NULL);
|
|
|
|
|
|
|
|
|
|
model = clutter_model_iter_get_model (iter);
|
2009-04-29 10:26:05 -04:00
|
|
|
|
row = clutter_model_iter_get_row (iter);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
filter_prev = g_sequence_iter_prev (iter_default->seq_iter);
|
|
|
|
|
g_assert (filter_prev != NULL);
|
|
|
|
|
|
2009-05-05 14:39:26 -04:00
|
|
|
|
temp_iter = CLUTTER_LIST_MODEL (model)->priv->temp_iter;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
while (!g_sequence_iter_is_begin (filter_prev))
|
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
CLUTTER_LIST_MODEL_ITER (temp_iter)->seq_iter = filter_prev;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
if (clutter_model_filter_iter (model, temp_iter))
|
2009-04-29 10:26:05 -04:00
|
|
|
|
{
|
|
|
|
|
row -= 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
filter_prev = g_sequence_iter_prev (filter_prev);
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-29 10:26:05 -04:00
|
|
|
|
if (g_sequence_iter_is_begin (filter_prev))
|
|
|
|
|
row -= 1;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
2007-12-15 08:02:06 -05:00
|
|
|
|
/* update the iterator and return it */
|
2012-02-09 13:40:03 -05:00
|
|
|
|
_clutter_model_iter_set_row (CLUTTER_MODEL_ITER (iter_default), row);
|
2007-12-15 08:02:06 -05:00
|
|
|
|
iter_default->seq_iter = filter_prev;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
2007-12-15 08:02:06 -05:00
|
|
|
|
return CLUTTER_MODEL_ITER (iter_default);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
}
|
2008-03-19 14:33:33 -04:00
|
|
|
|
|
|
|
|
|
static ClutterModelIter *
|
|
|
|
|
clutter_list_model_iter_copy (ClutterModelIter *iter)
|
|
|
|
|
{
|
|
|
|
|
ClutterListModelIter *iter_default;
|
|
|
|
|
ClutterListModelIter *iter_copy;
|
|
|
|
|
ClutterModel *model;
|
|
|
|
|
guint row;
|
|
|
|
|
|
|
|
|
|
iter_default = CLUTTER_LIST_MODEL_ITER (iter);
|
|
|
|
|
|
|
|
|
|
model = clutter_model_iter_get_model (iter);
|
|
|
|
|
row = clutter_model_iter_get_row (iter) - 1;
|
|
|
|
|
|
|
|
|
|
iter_copy = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER,
|
|
|
|
|
"model", model,
|
|
|
|
|
"row", row,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
/* this is safe, because the seq_iter pointer on the passed
|
|
|
|
|
* iterator will be always be overwritten in ::next or ::prev
|
|
|
|
|
*/
|
|
|
|
|
iter_copy->seq_iter = iter_default->seq_iter;
|
|
|
|
|
|
|
|
|
|
return CLUTTER_MODEL_ITER (iter_copy);
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-14 12:25:55 -05:00
|
|
|
|
static void
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_iter_class_init (ClutterListModelIterClass *klass)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
|
|
|
|
ClutterModelIterClass *iter_class = CLUTTER_MODEL_ITER_CLASS (klass);
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
iter_class->get_value = clutter_list_model_iter_get_value;
|
|
|
|
|
iter_class->set_value = clutter_list_model_iter_set_value;
|
|
|
|
|
iter_class->is_first = clutter_list_model_iter_is_first;
|
|
|
|
|
iter_class->is_last = clutter_list_model_iter_is_last;
|
|
|
|
|
iter_class->next = clutter_list_model_iter_next;
|
|
|
|
|
iter_class->prev = clutter_list_model_iter_prev;
|
2008-03-19 14:33:33 -04:00
|
|
|
|
iter_class->copy = clutter_list_model_iter_copy;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_iter_init (ClutterListModelIter *iter)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
|
|
|
|
iter->seq_iter = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2008-01-09 09:34:24 -05:00
|
|
|
|
* ClutterListModel
|
2007-12-14 12:25:55 -05:00
|
|
|
|
*/
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
G_DEFINE_TYPE (ClutterListModel, clutter_list_model, CLUTTER_TYPE_MODEL);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
static ClutterModelIter *
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_get_iter_at_row (ClutterModel *model,
|
|
|
|
|
guint row)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModel *model_default = CLUTTER_LIST_MODEL (model);
|
2009-02-14 06:31:00 -05:00
|
|
|
|
GSequence *sequence = model_default->priv->sequence;
|
2010-12-02 09:27:36 -05:00
|
|
|
|
GSequenceIter *filter_next;
|
2009-04-29 10:26:05 -04:00
|
|
|
|
gint seq_length = g_sequence_get_length (sequence);
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModelIter *retval;
|
2010-12-02 09:27:36 -05:00
|
|
|
|
gint count = -1;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
2009-04-29 10:26:05 -04:00
|
|
|
|
if (row >= seq_length)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
return NULL;
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
retval = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER,
|
2007-12-14 12:25:55 -05:00
|
|
|
|
"model", model,
|
|
|
|
|
"row", row,
|
|
|
|
|
NULL);
|
2009-04-29 10:26:05 -04:00
|
|
|
|
|
|
|
|
|
/* short-circuit in case we don't have a filter in place */
|
|
|
|
|
if (!clutter_model_get_filter_set (model))
|
|
|
|
|
{
|
|
|
|
|
retval->seq_iter = g_sequence_get_iter_at_pos (sequence, row);
|
|
|
|
|
|
|
|
|
|
return CLUTTER_MODEL_ITER (retval);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-02 09:27:36 -05:00
|
|
|
|
filter_next = g_sequence_get_begin_iter (sequence);
|
|
|
|
|
g_assert (filter_next != NULL);
|
2009-05-08 05:57:56 -04:00
|
|
|
|
|
2010-12-02 09:27:36 -05:00
|
|
|
|
while (!g_sequence_iter_is_end (filter_next))
|
2009-04-29 10:26:05 -04:00
|
|
|
|
{
|
2010-12-02 09:27:36 -05:00
|
|
|
|
retval->seq_iter = filter_next;
|
2009-04-29 10:26:05 -04:00
|
|
|
|
|
2010-12-02 09:27:36 -05:00
|
|
|
|
if (clutter_model_filter_iter (model, CLUTTER_MODEL_ITER (retval)))
|
2009-04-29 10:26:05 -04:00
|
|
|
|
{
|
2010-12-02 09:27:36 -05:00
|
|
|
|
/* We've found a row that is valid under the filter */
|
|
|
|
|
count++;
|
|
|
|
|
if (count == row)
|
2009-04-29 10:26:05 -04:00
|
|
|
|
break;
|
|
|
|
|
}
|
2010-12-02 09:27:36 -05:00
|
|
|
|
|
|
|
|
|
filter_next = g_sequence_iter_next (filter_next);
|
2009-04-29 10:26:05 -04:00
|
|
|
|
}
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
2010-12-02 09:27:36 -05:00
|
|
|
|
if (count != row)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (retval);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2007-12-14 12:25:55 -05:00
|
|
|
|
return CLUTTER_MODEL_ITER (retval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ClutterModelIter *
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_insert_row (ClutterModel *model,
|
|
|
|
|
gint index_)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModel *model_default = CLUTTER_LIST_MODEL (model);
|
2009-02-14 06:31:00 -05:00
|
|
|
|
GSequence *sequence = model_default->priv->sequence;
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModelIter *retval;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
guint n_columns, i, pos;
|
2012-02-06 09:37:49 -05:00
|
|
|
|
GValue *values;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
GSequenceIter *seq_iter;
|
|
|
|
|
|
|
|
|
|
n_columns = clutter_model_get_n_columns (model);
|
2012-02-06 09:37:49 -05:00
|
|
|
|
values = g_new0 (GValue, n_columns);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_columns; i++)
|
2012-02-06 09:37:49 -05:00
|
|
|
|
g_value_init (&values[i], clutter_model_get_column_type (model, i));
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
if (index_ < 0)
|
|
|
|
|
{
|
2012-02-06 09:37:49 -05:00
|
|
|
|
seq_iter = g_sequence_append (sequence, values);
|
2009-04-29 10:26:05 -04:00
|
|
|
|
pos = g_sequence_get_length (sequence) - 1;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
}
|
|
|
|
|
else if (index_ == 0)
|
|
|
|
|
{
|
2012-02-06 09:37:49 -05:00
|
|
|
|
seq_iter = g_sequence_prepend (sequence, values);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
pos = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-02-14 06:31:00 -05:00
|
|
|
|
seq_iter = g_sequence_get_iter_at_pos (sequence, index_);
|
2012-02-06 09:37:49 -05:00
|
|
|
|
seq_iter = g_sequence_insert_before (seq_iter, values);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
pos = index_;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
retval = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER,
|
2007-12-14 12:25:55 -05:00
|
|
|
|
"model", model,
|
|
|
|
|
"row", pos,
|
|
|
|
|
NULL);
|
|
|
|
|
retval->seq_iter = seq_iter;
|
|
|
|
|
|
|
|
|
|
return CLUTTER_MODEL_ITER (retval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_remove_row (ClutterModel *model,
|
|
|
|
|
guint row)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModel *model_default = CLUTTER_LIST_MODEL (model);
|
2009-02-14 06:31:00 -05:00
|
|
|
|
GSequence *sequence = model_default->priv->sequence;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
GSequenceIter *seq_iter;
|
|
|
|
|
guint pos = 0;
|
|
|
|
|
|
2009-02-14 06:31:00 -05:00
|
|
|
|
seq_iter = g_sequence_get_begin_iter (sequence);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
while (!g_sequence_iter_is_end (seq_iter))
|
|
|
|
|
{
|
|
|
|
|
if (clutter_model_filter_row (model, pos))
|
|
|
|
|
{
|
|
|
|
|
if (pos == row)
|
|
|
|
|
{
|
|
|
|
|
ClutterModelIter *iter;
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
iter = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER,
|
2007-12-14 12:25:55 -05:00
|
|
|
|
"model", model,
|
|
|
|
|
"row", pos,
|
|
|
|
|
NULL);
|
2008-01-09 09:34:24 -05:00
|
|
|
|
CLUTTER_LIST_MODEL_ITER (iter)->seq_iter = seq_iter;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
2008-01-02 07:15:10 -05:00
|
|
|
|
/* the actual row is removed from the sequence inside
|
|
|
|
|
* the ::row-removed signal class handler, so that every
|
|
|
|
|
* handler connected to ::row-removed will still get
|
|
|
|
|
* a valid iterator, and every signal connected to
|
|
|
|
|
* ::row-removed with the AFTER flag will get an updated
|
|
|
|
|
* model
|
|
|
|
|
*/
|
2007-12-14 12:25:55 -05:00
|
|
|
|
g_signal_emit_by_name (model, "row-removed", iter);
|
|
|
|
|
|
|
|
|
|
g_object_unref (iter);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos += 1;
|
|
|
|
|
seq_iter = g_sequence_iter_next (seq_iter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
ClutterModel *model;
|
|
|
|
|
guint column;
|
|
|
|
|
ClutterModelSortFunc func;
|
|
|
|
|
gpointer data;
|
|
|
|
|
} SortClosure;
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
sort_model_default (gconstpointer a,
|
|
|
|
|
gconstpointer b,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
2012-02-06 09:37:49 -05:00
|
|
|
|
const GValue *row_a = a;
|
|
|
|
|
const GValue *row_b = b;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
SortClosure *clos = data;
|
|
|
|
|
|
|
|
|
|
return clos->func (clos->model,
|
2012-02-06 09:37:49 -05:00
|
|
|
|
&row_a[clos->column],
|
|
|
|
|
&row_b[clos->column],
|
2007-12-14 12:25:55 -05:00
|
|
|
|
clos->data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_resort (ClutterModel *model,
|
|
|
|
|
ClutterModelSortFunc func,
|
|
|
|
|
gpointer data)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
|
|
|
|
SortClosure sort_closure = { NULL, 0, NULL, NULL };
|
|
|
|
|
|
|
|
|
|
sort_closure.model = model;
|
|
|
|
|
sort_closure.column = clutter_model_get_sorting_column (model);
|
|
|
|
|
sort_closure.func = func;
|
|
|
|
|
sort_closure.data = data;
|
|
|
|
|
|
2009-02-14 06:31:00 -05:00
|
|
|
|
g_sequence_sort (CLUTTER_LIST_MODEL (model)->priv->sequence,
|
2007-12-14 12:25:55 -05:00
|
|
|
|
sort_model_default,
|
|
|
|
|
&sort_closure);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-10 13:13:03 -05:00
|
|
|
|
static guint
|
|
|
|
|
clutter_list_model_get_n_rows (ClutterModel *model)
|
|
|
|
|
{
|
|
|
|
|
ClutterListModel *list_model = CLUTTER_LIST_MODEL (model);
|
|
|
|
|
|
|
|
|
|
/* short-circuit in case we don't have a filter in place */
|
|
|
|
|
if (!clutter_model_get_filter_set (model))
|
|
|
|
|
return g_sequence_get_length (list_model->priv->sequence);
|
|
|
|
|
|
|
|
|
|
return CLUTTER_MODEL_CLASS (clutter_list_model_parent_class)->get_n_rows (model);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-02 07:15:10 -05:00
|
|
|
|
static void
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_row_removed (ClutterModel *model,
|
|
|
|
|
ClutterModelIter *iter)
|
2008-01-02 07:15:10 -05:00
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModelIter *iter_default;
|
2012-02-06 09:37:49 -05:00
|
|
|
|
guint i, n_columns;
|
|
|
|
|
GValue *values;
|
|
|
|
|
|
|
|
|
|
n_columns = clutter_model_get_n_columns (model);
|
2008-01-02 07:15:10 -05:00
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
iter_default = CLUTTER_LIST_MODEL_ITER (iter);
|
2008-01-02 07:15:10 -05:00
|
|
|
|
|
2012-02-06 09:37:49 -05:00
|
|
|
|
values = g_sequence_get (iter_default->seq_iter);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_columns; i++)
|
|
|
|
|
g_value_unset (&values[i]);
|
|
|
|
|
|
|
|
|
|
g_free (values);
|
2008-01-02 07:15:10 -05:00
|
|
|
|
|
|
|
|
|
g_sequence_remove (iter_default->seq_iter);
|
|
|
|
|
iter_default->seq_iter = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-14 12:25:55 -05:00
|
|
|
|
static void
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_finalize (GObject *gobject)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
2008-01-09 09:34:24 -05:00
|
|
|
|
ClutterListModel *model = CLUTTER_LIST_MODEL (gobject);
|
2009-02-14 06:31:00 -05:00
|
|
|
|
GSequence *sequence = model->priv->sequence;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
GSequenceIter *iter;
|
2012-02-06 09:37:49 -05:00
|
|
|
|
guint n_columns, i;
|
|
|
|
|
|
|
|
|
|
n_columns = clutter_model_get_n_columns (CLUTTER_MODEL (gobject));
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
2009-02-14 06:31:00 -05:00
|
|
|
|
iter = g_sequence_get_begin_iter (sequence);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
while (!g_sequence_iter_is_end (iter))
|
|
|
|
|
{
|
2012-02-06 09:37:49 -05:00
|
|
|
|
GValue *values = g_sequence_get (iter);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_columns; i++)
|
|
|
|
|
g_value_unset (&values[i]);
|
|
|
|
|
|
|
|
|
|
g_free (values);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
|
|
|
|
iter = g_sequence_iter_next (iter);
|
|
|
|
|
}
|
2009-02-14 06:31:00 -05:00
|
|
|
|
g_sequence_free (sequence);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
G_OBJECT_CLASS (clutter_list_model_parent_class)->finalize (gobject);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-05 14:39:26 -04:00
|
|
|
|
static void
|
|
|
|
|
clutter_list_model_dispose (GObject *gobject)
|
|
|
|
|
{
|
|
|
|
|
ClutterListModel *model = CLUTTER_LIST_MODEL (gobject);
|
|
|
|
|
|
|
|
|
|
if (model->priv->temp_iter)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (model->priv->temp_iter);
|
|
|
|
|
model->priv->temp_iter = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-09 20:09:42 -04:00
|
|
|
|
G_OBJECT_CLASS (clutter_list_model_parent_class)->dispose (gobject);
|
2009-05-05 14:39:26 -04:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-14 12:25:55 -05:00
|
|
|
|
static void
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_class_init (ClutterListModelClass *klass)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
ClutterModelClass *model_class = CLUTTER_MODEL_CLASS (klass);
|
|
|
|
|
|
2009-02-14 06:31:00 -05:00
|
|
|
|
g_type_class_add_private (klass, sizeof (ClutterListModelPrivate));
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
gobject_class->finalize = clutter_list_model_finalize;
|
2009-05-05 14:39:26 -04:00
|
|
|
|
gobject_class->dispose = clutter_list_model_dispose;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
model_class->get_iter_at_row = clutter_list_model_get_iter_at_row;
|
|
|
|
|
model_class->insert_row = clutter_list_model_insert_row;
|
|
|
|
|
model_class->remove_row = clutter_list_model_remove_row;
|
|
|
|
|
model_class->resort = clutter_list_model_resort;
|
2011-01-10 13:13:03 -05:00
|
|
|
|
model_class->get_n_rows = clutter_list_model_get_n_rows;
|
2008-01-02 07:15:10 -05:00
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
model_class->row_removed = clutter_list_model_row_removed;
|
2007-12-14 12:25:55 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_init (ClutterListModel *model)
|
2007-12-14 12:25:55 -05:00
|
|
|
|
{
|
2009-02-14 06:31:00 -05:00
|
|
|
|
model->priv = CLUTTER_LIST_MODEL_GET_PRIVATE (model);
|
|
|
|
|
|
|
|
|
|
model->priv->sequence = g_sequence_new (NULL);
|
2009-05-05 14:39:26 -04:00
|
|
|
|
model->priv->temp_iter = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER,
|
|
|
|
|
"model",
|
|
|
|
|
model,
|
|
|
|
|
NULL);
|
2007-12-14 12:25:55 -05:00
|
|
|
|
}
|
2008-01-09 09:18:53 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-01-09 09:34:24 -05:00
|
|
|
|
* clutter_list_model_new:
|
2008-01-09 09:18:53 -05:00
|
|
|
|
* @n_columns: number of columns in the model
|
2011-07-26 08:43:37 -04:00
|
|
|
|
* @...: @n_columns number of #GType and string pairs
|
2008-01-09 09:18:53 -05:00
|
|
|
|
*
|
|
|
|
|
* Creates a new default model with @n_columns columns with the types
|
|
|
|
|
* and names passed in.
|
|
|
|
|
*
|
|
|
|
|
* For example:
|
|
|
|
|
*
|
|
|
|
|
* <informalexample><programlisting>
|
2008-01-09 09:34:24 -05:00
|
|
|
|
* model = clutter_list_model_new (3,
|
|
|
|
|
* G_TYPE_INT, "Score",
|
|
|
|
|
* G_TYPE_STRING, "Team",
|
|
|
|
|
* GDK_TYPE_PIXBUF, "Logo");
|
2008-01-09 09:18:53 -05:00
|
|
|
|
* </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.
|
|
|
|
|
*
|
2008-01-09 09:34:24 -05:00
|
|
|
|
* Return value: a new #ClutterListModel
|
2008-01-09 09:18:53 -05:00
|
|
|
|
*
|
2012-08-27 04:48:36 -04:00
|
|
|
|
*
|
2008-01-09 09:18:53 -05:00
|
|
|
|
*/
|
|
|
|
|
ClutterModel *
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_new (guint n_columns,
|
|
|
|
|
...)
|
2008-01-09 09:18:53 -05:00
|
|
|
|
{
|
|
|
|
|
ClutterModel *model;
|
|
|
|
|
va_list args;
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (n_columns > 0, NULL);
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
model = g_object_new (CLUTTER_TYPE_LIST_MODEL, NULL);
|
2012-02-09 13:40:03 -05:00
|
|
|
|
_clutter_model_set_n_columns (model, n_columns, TRUE, TRUE);
|
2008-01-09 09:18:53 -05:00
|
|
|
|
|
|
|
|
|
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*);
|
|
|
|
|
|
2012-02-09 13:40:03 -05:00
|
|
|
|
if (!_clutter_model_check_type (type))
|
2008-01-09 09:18:53 -05:00
|
|
|
|
{
|
|
|
|
|
g_warning ("%s: Invalid type %s\n", G_STRLOC, g_type_name (type));
|
|
|
|
|
g_object_unref (model);
|
2012-11-30 21:35:58 -05:00
|
|
|
|
model = NULL;
|
|
|
|
|
goto out;
|
2008-01-09 09:18:53 -05:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-09 13:40:03 -05:00
|
|
|
|
_clutter_model_set_column_type (model, i, type);
|
|
|
|
|
_clutter_model_set_column_name (model, i, name);
|
2008-01-09 09:18:53 -05:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-30 21:35:58 -05:00
|
|
|
|
out:
|
2008-01-09 09:18:53 -05:00
|
|
|
|
va_end (args);
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-09 09:34:24 -05:00
|
|
|
|
* clutter_list_model_newv:
|
2008-01-09 09:18:53 -05:00
|
|
|
|
* @n_columns: number of columns in the model
|
2012-01-12 21:15:55 -05:00
|
|
|
|
* @types: (array length=n_columns): an array of #GType types for the columns, from first to last
|
|
|
|
|
* @names: (array length=n_columns): an array of names for the columns, from first to last
|
2008-01-09 09:18:53 -05:00
|
|
|
|
*
|
2008-01-09 09:34:24 -05:00
|
|
|
|
* Non-vararg version of clutter_list_model_new(). This function is
|
2008-01-09 09:18:53 -05:00
|
|
|
|
* useful for language bindings.
|
|
|
|
|
*
|
2010-09-08 11:41:47 -04:00
|
|
|
|
* Return value: (transfer full): a new default #ClutterModel
|
2008-01-09 09:18:53 -05:00
|
|
|
|
*
|
2012-08-27 04:48:36 -04:00
|
|
|
|
*
|
2008-01-09 09:18:53 -05:00
|
|
|
|
*/
|
|
|
|
|
ClutterModel *
|
2008-01-09 09:34:24 -05:00
|
|
|
|
clutter_list_model_newv (guint n_columns,
|
|
|
|
|
GType *types,
|
|
|
|
|
const gchar * const names[])
|
2008-01-09 09:18:53 -05:00
|
|
|
|
{
|
|
|
|
|
ClutterModel *model;
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (n_columns > 0, NULL);
|
|
|
|
|
|
2008-01-09 09:34:24 -05:00
|
|
|
|
model = g_object_new (CLUTTER_TYPE_LIST_MODEL, NULL);
|
2012-02-09 13:40:03 -05:00
|
|
|
|
_clutter_model_set_n_columns (model, n_columns, TRUE, TRUE);
|
2008-01-09 09:18:53 -05:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_columns; i++)
|
|
|
|
|
{
|
2012-02-09 13:40:03 -05:00
|
|
|
|
if (!_clutter_model_check_type (types[i]))
|
2008-01-09 09:18:53 -05:00
|
|
|
|
{
|
|
|
|
|
g_warning ("%s: Invalid type %s\n", G_STRLOC, g_type_name (types[i]));
|
|
|
|
|
g_object_unref (model);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-09 13:40:03 -05:00
|
|
|
|
_clutter_model_set_column_type (model, i, types[i]);
|
|
|
|
|
_clutter_model_set_column_name (model, i, names[i]);
|
2008-01-09 09:18:53 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return model;
|
|
|
|
|
}
|