Merge branch 'wip/otte/for-master' into 'master'

Wip/otte/for master

See merge request GNOME/gtk!2193
This commit is contained in:
Matthias Clasen 2020-07-05 16:06:16 +00:00
commit d65214fa4e
44 changed files with 438 additions and 382 deletions

View File

@ -188,7 +188,7 @@ constraint_view_init (ConstraintView *self)
g_list_store_append (list, children);
g_list_store_append (list, guides);
g_list_store_append (list, constraints);
self->model = G_LIST_MODEL (gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (list)));
self->model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (list)));
g_object_unref (children);
g_object_unref (guides);
g_object_unref (constraints);

View File

@ -348,6 +348,7 @@ GtkBitset
gtk_bitset_ref
gtk_bitset_unref
gtk_bitset_new_empty
gtk_bitset_new_range
gtk_bitset_copy
<SUBSECTION>
gtk_bitset_contains
@ -422,6 +423,7 @@ gtk_selection_model_get_type
GtkNoSelection
gtk_no_selection_new
gtk_no_selection_get_model
gtk_no_selection_set_model
<SUBSECTION Private>
gtk_no_selection_get_type
</SECTION>
@ -433,6 +435,7 @@ GtkSingleSelection
GTK_INVALID_LIST_POSITION
gtk_single_selection_new
gtk_single_selection_get_model
gtk_single_selection_set_model
gtk_single_selection_get_selected
gtk_single_selection_set_selected
gtk_single_selection_get_selected_item
@ -450,6 +453,7 @@ gtk_single_selection_get_type
GtkMultiSelection
gtk_multi_selection_new
gtk_multi_selection_get_model
gtk_multi_selection_set_model
<SUBSECTION Private>
gtk_multi_selection_get_type
</SECTION>
@ -1539,7 +1543,6 @@ gtk_custom_filter_get_type
<TITLE>GtkFilterListModel</TITLE>
GtkFilterListModel
gtk_filter_list_model_new
gtk_filter_list_model_new_for_type
gtk_filter_list_model_set_model
gtk_filter_list_model_get_model
gtk_filter_list_model_set_filter
@ -2698,7 +2701,6 @@ gtk_size_group_get_type
<TITLE>GtkSliceListModel</TITLE>
GtkSliceListModel
gtk_slice_list_model_new
gtk_slice_list_model_new_for_type
gtk_slice_list_model_set_model
gtk_slice_list_model_get_model
gtk_slice_list_model_set_offset
@ -2830,7 +2832,6 @@ gtk_tree_list_row_sorter_get_type
<TITLE>GtkSortListModel</TITLE>
GtkSortListModel
gtk_sort_list_model_new
gtk_sort_list_model_new_for_type
gtk_sort_list_model_set_sorter
gtk_sort_list_model_get_sorter
gtk_sort_list_model_set_model
@ -7610,7 +7611,9 @@ gtk_string_list_take
gtk_string_list_remove
gtk_string_list_splice
gtk_string_list_get_string
<SUBSECTION>
GtkStringObject
gtk_string_object_new
gtk_string_object_get_string
</SECTION>

View File

@ -295,7 +295,6 @@ gtk_cell_accessible_action_do_action (AtkAction *action,
GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action);
GtkCellAccessibleParent *parent;
cell = GTK_CELL_ACCESSIBLE (action);
if (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)) == NULL)
return FALSE;

View File

@ -65,7 +65,7 @@ static gunichar
gtk_password_entry_accessible_get_character_at_offset (AtkText *atk_text,
gint offset)
{
GtkText *text = get_text_widget (GTK_ACCESSIBLE (atk_text));
GtkText *text;
char *contents, *index;
gunichar result;

View File

@ -268,7 +268,7 @@ gtk_bitset_get_nth (const GtkBitset *self,
*
* Creates a new empty bitset.
*
* Returns: A new empty bitset.
* Returns: A new empty bitset
**/
GtkBitset *
gtk_bitset_new_empty (void)
@ -284,6 +284,28 @@ gtk_bitset_new_empty (void)
return self;
}
/**
* gtk_bitset_new_range:
* @start: first value to add
* @n_items: number of consecutive values to add
*
* Creates a bitset with the given range set.
*
* Returns: A new bitset
**/
GtkBitset *
gtk_bitset_new_range (guint start,
guint n_items)
{
GtkBitset *self;
self = gtk_bitset_new_empty ();
gtk_bitset_add_range (self, start, n_items);
return self;
}
/**
* gtk_bitset_copy:
* @self: a #GtkBitset

View File

@ -65,6 +65,9 @@ GDK_AVAILABLE_IN_ALL
GtkBitset * gtk_bitset_new_empty (void);
GDK_AVAILABLE_IN_ALL
GtkBitset * gtk_bitset_copy (const GtkBitset *self);
GDK_AVAILABLE_IN_ALL
GtkBitset * gtk_bitset_new_range (guint start,
guint n_items);
GDK_AVAILABLE_IN_ALL
void gtk_bitset_remove_all (GtkBitset *self);

View File

@ -321,7 +321,7 @@ gtk_custom_paper_unix_dialog_init (GtkCustomPaperUnixDialog *dialog)
g_list_store_append (printer_list_list, printer_list);
g_object_unref (printer_list);
full_list = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PRINTER, G_LIST_MODEL (printer_list_list)));
full_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (printer_list_list)));
g_object_unref (printer_list_list);
filter = gtk_custom_filter_new (match_func, NULL, NULL);

View File

@ -943,7 +943,7 @@ gtk_drop_down_set_from_strings (GtkDropDown *self,
set_default_factory (self);
model = G_LIST_MODEL (gtk_string_list_new ((const char **)texts));
model = G_LIST_MODEL (gtk_string_list_new (texts));
gtk_drop_down_set_model (self, model);
g_object_unref (model);
}

View File

@ -40,7 +40,6 @@
enum {
PROP_0,
PROP_FILTER,
PROP_ITEM_TYPE,
PROP_MODEL,
NUM_PROPERTIES
};
@ -63,7 +62,6 @@ struct _GtkFilterListModel
{
GObject parent_instance;
GType item_type;
GListModel *model;
GtkFilter *filter;
GtkFilterMatch strictness;
@ -194,9 +192,7 @@ gtk_filter_list_model_get_nth (GtkRbTree *tree,
static GType
gtk_filter_list_model_get_item_type (GListModel *list)
{
GtkFilterListModel *self = GTK_FILTER_LIST_MODEL (list);
return self->item_type;
return G_TYPE_OBJECT;
}
static guint
@ -364,10 +360,6 @@ gtk_filter_list_model_set_property (GObject *object,
gtk_filter_list_model_set_filter (self, g_value_get_object (value));
break;
case PROP_ITEM_TYPE:
self->item_type = g_value_get_gtype (value);
break;
case PROP_MODEL:
gtk_filter_list_model_set_model (self, g_value_get_object (value));
break;
@ -392,10 +384,6 @@ gtk_filter_list_model_get_property (GObject *object,
g_value_set_object (value, self->filter);
break;
case PROP_ITEM_TYPE:
g_value_set_gtype (value, self->item_type);
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
@ -662,18 +650,6 @@ gtk_filter_list_model_class_init (GtkFilterListModelClass *class)
GTK_TYPE_FILTER,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkFilterListModel:item-type:
*
* The #GType for elements of this object
*/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type",
P_("Item type"),
P_("The type of elements of this object"),
G_TYPE_OBJECT,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkFilterListModel:model:
*
@ -697,7 +673,7 @@ gtk_filter_list_model_init (GtkFilterListModel *self)
/**
* gtk_filter_list_model_new:
* @model: the model to sort
* @model: (allow-none): the model to sort
* @filter: (allow-none): filter or %NULL to not filter items
*
* Creates a new #GtkFilterListModel that will filter @model using the given
@ -711,10 +687,10 @@ gtk_filter_list_model_new (GListModel *model,
{
GtkFilterListModel *result;
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
g_return_val_if_fail (filter == NULL || GTK_IS_FILTER (filter), NULL);
result = g_object_new (GTK_TYPE_FILTER_LIST_MODEL,
"item-type", g_list_model_get_item_type (model),
"model", model,
"filter", filter,
NULL);
@ -722,26 +698,6 @@ gtk_filter_list_model_new (GListModel *model,
return result;
}
/**
* gtk_filter_list_model_new_for_type:
* @item_type: the type of the items that will be returned
*
* Creates a new empty filter list model set up to return items of type @item_type.
* It is up to the application to set a proper filter and model to ensure
* the item type is matched.
*
* Returns: a new #GtkFilterListModel
**/
GtkFilterListModel *
gtk_filter_list_model_new_for_type (GType item_type)
{
g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
return g_object_new (GTK_TYPE_FILTER_LIST_MODEL,
"item-type", item_type,
NULL);
}
/**
* gtk_filter_list_model_set_filter:
* @self: a #GtkFilterListModel

View File

@ -39,8 +39,6 @@ G_DECLARE_FINAL_TYPE (GtkFilterListModel, gtk_filter_list_model, GTK, FILTER_LIS
GDK_AVAILABLE_IN_ALL
GtkFilterListModel * gtk_filter_list_model_new (GListModel *model,
GtkFilter *filter);
GDK_AVAILABLE_IN_ALL
GtkFilterListModel * gtk_filter_list_model_new_for_type (GType item_type);
GDK_AVAILABLE_IN_ALL
void gtk_filter_list_model_set_filter (GtkFilterListModel *self,

View File

@ -40,7 +40,6 @@
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_MODEL,
NUM_PROPERTIES
};
@ -64,7 +63,6 @@ struct _GtkFlattenListModel
{
GObject parent_instance;
GType item_type;
GListModel *model;
GtkRbTree *items; /* NULL if model == NULL */
};
@ -157,9 +155,7 @@ gtk_flatten_list_model_get_nth_model (GtkRbTree *tree,
static GType
gtk_flatten_list_model_get_item_type (GListModel *list)
{
GtkFlattenListModel *self = GTK_FLATTEN_LIST_MODEL (list);
return self->item_type;
return G_TYPE_OBJECT;
}
static guint
@ -299,7 +295,6 @@ gtk_flatten_list_model_add_items (GtkFlattenListModel *self,
{
node = gtk_rb_tree_insert_before (self->items, after);
node->model = g_list_model_get_item (self->model, position + i);
g_warn_if_fail (g_type_is_a (g_list_model_get_item_type (node->model), self->item_type));
g_signal_connect (node->model,
"items-changed",
G_CALLBACK (gtk_flatten_list_model_items_changed_cb),
@ -321,10 +316,6 @@ gtk_flatten_list_model_set_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
self->item_type = g_value_get_gtype (value);
break;
case PROP_MODEL:
gtk_flatten_list_model_set_model (self, g_value_get_object (value));
break;
@ -345,10 +336,6 @@ gtk_flatten_list_model_get_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, self->item_type);
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
@ -416,18 +403,6 @@ gtk_flatten_list_model_class_init (GtkFlattenListModelClass *class)
gobject_class->get_property = gtk_flatten_list_model_get_property;
gobject_class->dispose = gtk_flatten_list_model_dispose;
/**
* GtkFlattenListModel:item-type:
*
* The #GType for elements of this object
*/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type",
P_("Item type"),
P_("The type of elements of this object"),
G_TYPE_OBJECT,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkFlattenListModel:model:
*
@ -450,26 +425,20 @@ gtk_flatten_list_model_init (GtkFlattenListModel *self)
/**
* gtk_flatten_list_model_new:
* @item_type: The type of items in the to-be-flattened models
* @model: (nullable) (transfer none): the item to be flattened
* @model: (nullable) (transfer none): the model to be flattened
*
* Creates a new #GtkFlattenListModel that flattens @list. The
* models returned by @model must conform to the given @item_type,
* either by having an identical type or a subtype.
* Creates a new #GtkFlattenListModel that flattens @list.
*
* Returns: a new #GtkFlattenListModel
**/
GtkFlattenListModel *
gtk_flatten_list_model_new (GType item_type,
GListModel *model)
gtk_flatten_list_model_new (GListModel *model)
{
GtkFlattenListModel *result;
g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
result = g_object_new (GTK_TYPE_FLATTEN_LIST_MODEL,
"item-type", item_type,
"model", model,
NULL);
@ -481,8 +450,7 @@ gtk_flatten_list_model_new (GType item_type,
* @self: a #GtkFlattenListModel
* @model: (nullable) (transfer none): the new model or %NULL
*
* Sets a new model to be flattened. The model must contain items of
* #GListModel that conform to the item type of @self.
* Sets a new model to be flattened.
**/
void
gtk_flatten_list_model_set_model (GtkFlattenListModel *self,
@ -492,10 +460,6 @@ gtk_flatten_list_model_set_model (GtkFlattenListModel *self,
g_return_if_fail (GTK_IS_FLATTEN_LIST_MODEL (self));
g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
if (model)
{
g_return_if_fail (g_type_is_a (g_list_model_get_item_type (model), G_TYPE_LIST_MODEL));
}
if (self->model == model)
return;

View File

@ -36,8 +36,7 @@ GDK_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (GtkFlattenListModel, gtk_flatten_list_model, GTK, FLATTEN_LIST_MODEL, GObject)
GDK_AVAILABLE_IN_ALL
GtkFlattenListModel * gtk_flatten_list_model_new (GType item_type,
GListModel *model);
GtkFlattenListModel * gtk_flatten_list_model_new (GListModel *model);
GDK_AVAILABLE_IN_ALL
void gtk_flatten_list_model_set_model (GtkFlattenListModel *self,

View File

@ -784,7 +784,7 @@ update_fontlist (GtkFontChooserWidget *self)
if ((self->level & GTK_FONT_CHOOSER_LEVEL_STYLE) == 0)
model = g_object_ref (G_LIST_MODEL (fontmap));
else
model = G_LIST_MODEL (gtk_flatten_list_model_new (PANGO_TYPE_FONT_FACE, G_LIST_MODEL (fontmap)));
model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (fontmap)));
gtk_filter_list_model_set_model (self->filter_model, model);
g_object_unref (model);
}

View File

@ -63,7 +63,6 @@
enum {
PROP_0,
PROP_HAS_MAP,
PROP_ITEM_TYPE,
PROP_MODEL,
NUM_PROPERTIES
};
@ -86,7 +85,6 @@ struct _GtkMapListModel
{
GObject parent_instance;
GType item_type;
GListModel *model;
GtkMapListModelMapFunc map_func;
gpointer user_data;
@ -145,9 +143,7 @@ gtk_map_list_model_get_nth (GtkRbTree *tree,
static GType
gtk_map_list_model_get_item_type (GListModel *list)
{
GtkMapListModel *self = GTK_MAP_LIST_MODEL (list);
return self->item_type;
return G_TYPE_OBJECT;
}
static guint
@ -199,11 +195,6 @@ gtk_map_list_model_get_item (GListModel *list,
}
node->item = self->map_func (g_list_model_get_item (self->model, position), self->user_data);
if (!G_TYPE_CHECK_INSTANCE_TYPE (node->item, self->item_type))
{
g_critical ("Map function returned a %s, but it is not a subtype of the model's type %s",
G_OBJECT_TYPE_NAME (node->item), g_type_name (self->item_type));
}
g_object_add_weak_pointer (node->item, &node->item);
return node->item;
@ -293,10 +284,6 @@ gtk_map_list_model_set_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
self->item_type = g_value_get_gtype (value);
break;
case PROP_MODEL:
gtk_map_list_model_set_model (self, g_value_get_object (value));
break;
@ -321,10 +308,6 @@ gtk_map_list_model_get_property (GObject *object,
g_value_set_boolean (value, self->items != NULL);
break;
case PROP_ITEM_TYPE:
g_value_set_gtype (value, self->item_type);
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
@ -382,18 +365,6 @@ gtk_map_list_model_class_init (GtkMapListModelClass *class)
FALSE,
GTK_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkMapListModel:item-type:
*
* The #GType for elements of this object
*/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type",
P_("Item type"),
P_("The type of elements of this object"),
G_TYPE_OBJECT,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkMapListModel:model:
*
@ -441,7 +412,6 @@ gtk_map_list_model_augment (GtkRbTree *map,
/**
* gtk_map_list_model_new:
* @item_type: the #GType to use as the model's item type
* @model: (allow-none): The model to map or %NULL for none
* @map_func: (allow-none): map function or %NULL to not map items
* @user_data: (closure): user data passed to @map_func
@ -452,19 +422,16 @@ gtk_map_list_model_augment (GtkRbTree *map,
* Returns: a new #GtkMapListModel
**/
GtkMapListModel *
gtk_map_list_model_new (GType item_type,
GListModel *model,
gtk_map_list_model_new (GListModel *model,
GtkMapListModelMapFunc map_func,
gpointer user_data,
GDestroyNotify user_destroy)
{
GtkMapListModel *result;
g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
result = g_object_new (GTK_TYPE_MAP_LIST_MODEL,
"item-type", item_type,
"model", model,
NULL);

View File

@ -53,8 +53,7 @@ G_DECLARE_FINAL_TYPE (GtkMapListModel, gtk_map_list_model, GTK, MAP_LIST_MODEL,
typedef gpointer (* GtkMapListModelMapFunc) (gpointer item, gpointer user_data);
GDK_AVAILABLE_IN_ALL
GtkMapListModel * gtk_map_list_model_new (GType item_type,
GListModel *model,
GtkMapListModel * gtk_map_list_model_new (GListModel *model,
GtkMapListModelMapFunc map_func,
gpointer user_data,
GDestroyNotify user_destroy);

View File

@ -62,9 +62,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, };
static GType
gtk_multi_selection_get_item_type (GListModel *list)
{
GtkMultiSelection *self = GTK_MULTI_SELECTION (list);
return g_list_model_get_item_type (self->model);
return G_TYPE_OBJECT;
}
static guint
@ -72,6 +70,9 @@ gtk_multi_selection_get_n_items (GListModel *list)
{
GtkMultiSelection *self = GTK_MULTI_SELECTION (list);
if (self->model == NULL)
return 0;
return g_list_model_get_n_items (self->model);
}
@ -81,6 +82,9 @@ gtk_multi_selection_get_item (GListModel *list,
{
GtkMultiSelection *self = GTK_MULTI_SELECTION (list);
if (self->model == NULL)
return NULL;
return g_list_model_get_item (self->model, position);
}
@ -174,7 +178,7 @@ gtk_multi_selection_set_selection (GtkSelectionModel *model,
max = gtk_bitset_get_maximum (changes);
/* sanity check */
n_items = g_list_model_get_n_items (self->model);
n_items = self->model ? g_list_model_get_n_items (self->model) : 0;
if (max >= n_items)
{
gtk_bitset_remove_range_closed (changes, n_items, max);
@ -291,12 +295,7 @@ gtk_multi_selection_set_property (GObject *object,
switch (prop_id)
{
case PROP_MODEL:
self->model = g_value_dup_object (value);
g_warn_if_fail (self->model != NULL);
g_signal_connect (self->model,
"items-changed",
G_CALLBACK (gtk_multi_selection_items_changed_cb),
self);
gtk_multi_selection_set_model (self, g_value_get_object (value));
break;
default:
@ -357,7 +356,7 @@ gtk_multi_selection_class_init (GtkMultiSelectionClass *klass)
P_("Model"),
P_("List managed by this selection"),
G_TYPE_LIST_MODEL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
@ -402,3 +401,49 @@ gtk_multi_selection_get_model (GtkMultiSelection *self)
return self->model;
}
/**
* gtk_multi_selection_set_model:
* @self: a #GtkMultiSelection
* @model: (allow-none): A #GListModel to wrap
*
* Sets the model that @self should wrap. If @model is %NULL, @self
* will be empty.
**/
void
gtk_multi_selection_set_model (GtkMultiSelection *self,
GListModel *model)
{
guint n_items_before;
g_return_if_fail (GTK_IS_MULTI_SELECTION (self));
g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
if (self->model == model)
return;
n_items_before = self->model ? g_list_model_get_n_items (self->model) : 0;
gtk_multi_selection_clear_model (self);
if (model)
{
self->model = g_object_ref (model);
g_signal_connect (self->model,
"items-changed",
G_CALLBACK (gtk_multi_selection_items_changed_cb),
self);
gtk_multi_selection_items_changed_cb (self->model,
0,
n_items_before,
g_list_model_get_n_items (model),
self);
}
else
{
gtk_bitset_remove_all (self->selected);
g_hash_table_remove_all (self->items);
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items_before, 0);
}
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}

View File

@ -35,6 +35,9 @@ GListModel * gtk_multi_selection_new (GListModel *mo
GDK_AVAILABLE_IN_ALL
GListModel * gtk_multi_selection_get_model (GtkMultiSelection *self);
GDK_AVAILABLE_IN_ALL
void gtk_multi_selection_set_model (GtkMultiSelection *self,
GListModel *model);
G_END_DECLS

View File

@ -60,9 +60,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, };
static GType
gtk_no_selection_get_item_type (GListModel *list)
{
GtkNoSelection *self = GTK_NO_SELECTION (list);
return g_list_model_get_item_type (self->model);
return G_TYPE_OBJECT;
}
static guint
@ -70,6 +68,9 @@ gtk_no_selection_get_n_items (GListModel *list)
{
GtkNoSelection *self = GTK_NO_SELECTION (list);
if (self->model == NULL)
return 0;
return g_list_model_get_n_items (self->model);
}
@ -79,6 +80,9 @@ gtk_no_selection_get_item (GListModel *list,
{
GtkNoSelection *self = GTK_NO_SELECTION (list);
if (self->model == NULL)
return NULL;
return g_list_model_get_item (self->model, position);
}
@ -142,10 +146,7 @@ gtk_no_selection_set_property (GObject *object,
switch (prop_id)
{
case PROP_MODEL:
gtk_no_selection_clear_model (self);
self->model = g_value_dup_object (value);
g_signal_connect_swapped (self->model, "items-changed",
G_CALLBACK (g_list_model_items_changed), self);
gtk_no_selection_set_model (self, g_value_get_object (value));
break;
default:
@ -203,7 +204,7 @@ gtk_no_selection_class_init (GtkNoSelectionClass *klass)
P_("The model"),
P_("The model being managed"),
G_TYPE_LIST_MODEL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
@ -247,3 +248,40 @@ gtk_no_selection_get_model (GtkNoSelection *self)
return self->model;
}
/**
* gtk_no_selection_set_model:
* @self: a #GtkNoSelection
* @model: (allow-none): A #GListModel to wrap
*
* Sets the model that @self should wrap. If @model is %NULL, this
* model will be empty.
**/
void
gtk_no_selection_set_model (GtkNoSelection *self,
GListModel *model)
{
guint n_items_before;
g_return_if_fail (GTK_IS_NO_SELECTION (self));
g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
if (self->model == model)
return;
n_items_before = self->model ? g_list_model_get_n_items (self->model) : 0;
gtk_no_selection_clear_model (self);
if (model)
{
self->model = g_object_ref (model);
g_signal_connect_swapped (self->model, "items-changed",
G_CALLBACK (g_list_model_items_changed), self);
}
g_list_model_items_changed (G_LIST_MODEL (self),
0,
n_items_before,
model ? g_list_model_get_n_items (self->model) : 0);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}

View File

@ -34,6 +34,9 @@ GtkNoSelection * gtk_no_selection_new (GListModel
GDK_AVAILABLE_IN_ALL
GListModel * gtk_no_selection_get_model (GtkNoSelection *self);
GDK_AVAILABLE_IN_ALL
void gtk_no_selection_set_model (GtkNoSelection *self,
GListModel *model);
G_END_DECLS

View File

@ -306,7 +306,7 @@ gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog)
g_list_store_append (store, dialog->page_setup_list);
g_list_store_append (store, dialog->custom_paper_list);
g_list_store_append (store, dialog->manage_papers_list);
paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PAGE_SETUP, G_LIST_MODEL (store)));
paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (store)));
gtk_drop_down_set_model (GTK_DROP_DOWN (dialog->paper_size_combo), paper_size_list);
g_object_unref (store);
g_object_unref (paper_size_list);
@ -321,7 +321,7 @@ gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog)
g_list_store_append (printer_list_list, printer_list);
g_object_unref (printer_list);
full_list = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PRINTER, G_LIST_MODEL (printer_list_list)));
full_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (printer_list_list)));
filter = gtk_custom_filter_new (match_func, NULL, NULL);
dialog->printer_list = G_LIST_MODEL (gtk_filter_list_model_new (full_list, filter));

View File

@ -806,7 +806,7 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
g_list_store_append (store, dialog->page_setup_list);
g_list_store_append (store, dialog->custom_paper_list);
g_list_store_append (store, dialog->manage_papers_list);
paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PAGE_SETUP, G_LIST_MODEL (store)));
paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (store)));
gtk_drop_down_set_model (GTK_DROP_DOWN (dialog->paper_size_combo), paper_size_list);
g_object_unref (store);
g_object_unref (paper_size_list);
@ -1056,7 +1056,7 @@ load_print_backends (GtkPrintUnixDialog *dialog)
g_list_store_append (lists, gtk_print_backend_get_printers (backend));
}
model = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PRINTER, G_LIST_MODEL (lists)));
model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (lists)));
g_object_unref (lists);

View File

@ -110,7 +110,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, };
static GType
gtk_shortcut_controller_list_model_get_item_type (GListModel *list)
{
return GTK_TYPE_SHORTCUT;
return G_TYPE_OBJECT;
}
static guint
@ -198,12 +198,6 @@ gtk_shortcut_controller_set_property (GObject *object,
case PROP_MODEL:
{
GListModel *model = g_value_get_object (value);
if (model && g_list_model_get_item_type (model) != GTK_TYPE_SHORTCUT)
{
g_warning ("Setting a model with type '%s' on a shortcut controller that requires 'GtkShortcut'",
g_type_name (g_list_model_get_item_type (model)));
model = NULL;
}
if (model == NULL)
{
self->shortcuts = G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT));
@ -309,6 +303,11 @@ gtk_shortcut_controller_run_controllers (GtkEventController *controller,
index = (self->last_activated + 1 + i) % g_list_model_get_n_items (self->shortcuts);
shortcut = g_list_model_get_item (self->shortcuts, index);
if (!GTK_IS_SHORTCUT (shortcut))
{
g_object_unref (shortcut);
continue;
}
switch (gtk_shortcut_trigger_trigger (gtk_shortcut_get_trigger (shortcut), event, enable_mnemonics))
{
@ -484,6 +483,7 @@ gtk_shortcut_controller_set_widget (GtkEventController *controller,
for (i = 0, p = g_list_model_get_n_items (G_LIST_MODEL (controller)); i < p; i++)
{
GtkShortcut *shortcut = g_list_model_get_item (G_LIST_MODEL (controller), i);
if (GTK_IS_SHORTCUT (shortcut))
update_accel (shortcut, widget, TRUE);
g_object_unref (shortcut);
}
@ -506,6 +506,7 @@ gtk_shortcut_controller_unset_widget (GtkEventController *controller)
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (controller)); i++)
{
GtkShortcut *shortcut = g_list_model_get_item (G_LIST_MODEL (controller), i);
if (GTK_IS_SHORTCUT (shortcut))
update_accel (shortcut, widget, FALSE);
g_object_unref (shortcut);
}
@ -697,7 +698,6 @@ GtkEventController *
gtk_shortcut_controller_new_for_model (GListModel *model)
{
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
g_return_val_if_fail (g_list_model_get_item_type (model) == GTK_TYPE_SHORTCUT, NULL);
return g_object_new (GTK_TYPE_SHORTCUT_CONTROLLER,
"model", model,

View File

@ -49,7 +49,7 @@ gtk_shortcut_manager_create_controllers (GtkWidget *widget)
GtkEventController *controller;
store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER);
model = gtk_flatten_list_model_new (GTK_TYPE_SHORTCUT, G_LIST_MODEL (store));
model = gtk_flatten_list_model_new (G_LIST_MODEL (store));
g_object_unref (store);
g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-bubble", model, g_object_unref);
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
@ -57,7 +57,7 @@ gtk_shortcut_manager_create_controllers (GtkWidget *widget)
gtk_widget_add_controller (widget, controller);
store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER);
model = gtk_flatten_list_model_new (GTK_TYPE_SHORTCUT, G_LIST_MODEL (store));
model = gtk_flatten_list_model_new (G_LIST_MODEL (store));
g_object_unref (store);
g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-capture", model, g_object_unref);
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));

View File

@ -72,9 +72,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, };
static GType
gtk_single_selection_get_item_type (GListModel *list)
{
GtkSingleSelection *self = GTK_SINGLE_SELECTION (list);
return g_list_model_get_item_type (self->model);
return G_TYPE_OBJECT;
}
static guint
@ -82,6 +80,9 @@ gtk_single_selection_get_n_items (GListModel *list)
{
GtkSingleSelection *self = GTK_SINGLE_SELECTION (list);
if (self->model == NULL)
return 0;
return g_list_model_get_n_items (self->model);
}
@ -91,6 +92,9 @@ gtk_single_selection_get_item (GListModel *list,
{
GtkSingleSelection *self = GTK_SINGLE_SELECTION (list);
if (self->model == NULL)
return NULL;
return g_list_model_get_item (self->model, position);
}
@ -307,12 +311,7 @@ gtk_single_selection_set_property (GObject *object,
break;
case PROP_MODEL:
gtk_single_selection_clear_model (self);
self->model = g_value_dup_object (value);
g_signal_connect (self->model, "items-changed",
G_CALLBACK (gtk_single_selection_items_changed_cb), self);
if (self->autoselect)
gtk_single_selection_set_selected (self, 0);
gtk_single_selection_set_model (self, g_value_get_object (value));
break;
case PROP_SELECTED:
@ -440,7 +439,7 @@ gtk_single_selection_class_init (GtkSingleSelectionClass *klass)
P_("The model"),
P_("The model being managed"),
G_TYPE_LIST_MODEL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
@ -486,6 +485,62 @@ gtk_single_selection_get_model (GtkSingleSelection *self)
return self->model;
}
/**
* gtk_single_selection_set_model:
* @self: a #GtkSingleSelection
* @model: (allow-none): A #GListModel to wrap
*
* Sets the model that @self should wrap. If @model is %NULL, @self
* will be empty.
**/
void
gtk_single_selection_set_model (GtkSingleSelection *self,
GListModel *model)
{
guint n_items_before;
g_return_if_fail (GTK_IS_SINGLE_SELECTION (self));
g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
if (self->model == model)
return;
g_object_freeze_notify (G_OBJECT (self));
n_items_before = self->model ? g_list_model_get_n_items (self->model) : 0;
gtk_single_selection_clear_model (self);
if (model)
{
self->model = g_object_ref (model);
g_signal_connect (self->model, "items-changed",
G_CALLBACK (gtk_single_selection_items_changed_cb), self);
gtk_single_selection_items_changed_cb (self->model,
0,
n_items_before,
g_list_model_get_n_items (model),
self);
}
else
{
if (self->selected != GTK_INVALID_LIST_POSITION)
{
self->selected = GTK_INVALID_LIST_POSITION;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED]);
}
if (self->selected_item)
{
g_clear_object (&self->selected_item);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_ITEM]);
}
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items_before, 0);
}
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
g_object_thaw_notify (G_OBJECT (self));
}
/**
* gtk_single_selection_get_selected:
* @self: a #GtkSingleSelection

View File

@ -35,6 +35,9 @@ GtkSingleSelection * gtk_single_selection_new (GListModel
GDK_AVAILABLE_IN_ALL
GListModel * gtk_single_selection_get_model (GtkSingleSelection *self);
GDK_AVAILABLE_IN_ALL
void gtk_single_selection_set_model (GtkSingleSelection *self,
GListModel *model);
GDK_AVAILABLE_IN_ALL
guint gtk_single_selection_get_selected (GtkSingleSelection *self);
GDK_AVAILABLE_IN_ALL
void gtk_single_selection_set_selected (GtkSingleSelection *self,

View File

@ -41,7 +41,6 @@
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_MODEL,
PROP_OFFSET,
PROP_SIZE,
@ -52,7 +51,6 @@ struct _GtkSliceListModel
{
GObject parent_instance;
GType item_type;
GListModel *model;
guint offset;
guint size;
@ -70,9 +68,7 @@ static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
static GType
gtk_slice_list_model_get_item_type (GListModel *list)
{
GtkSliceListModel *self = GTK_SLICE_LIST_MODEL (list);
return self->item_type;
return G_TYPE_OBJECT;
}
static guint
@ -182,10 +178,6 @@ gtk_slice_list_model_set_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
self->item_type = g_value_get_gtype (value);
break;
case PROP_MODEL:
gtk_slice_list_model_set_model (self, g_value_get_object (value));
break;
@ -214,10 +206,6 @@ gtk_slice_list_model_get_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, self->item_type);
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
@ -265,18 +253,6 @@ gtk_slice_list_model_class_init (GtkSliceListModelClass *class)
gobject_class->get_property = gtk_slice_list_model_get_property;
gobject_class->dispose = gtk_slice_list_model_dispose;
/**
* GtkSliceListModel:item-type:
*
* The #GType for elements of this object
*/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type",
P_("Item type"),
P_("The type of elements of this object"),
G_TYPE_OBJECT,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkSliceListModel:model:
*
@ -324,7 +300,7 @@ gtk_slice_list_model_init (GtkSliceListModel *self)
/**
* gtk_slice_list_model_new:
* @model: (transfer none): The model to use
* @model: (transfer none) (allow-none): The model to use
* @offset: the offset of the slice
* @size: maximum size of the slice
*
@ -338,35 +314,15 @@ gtk_slice_list_model_new (GListModel *model,
guint offset,
guint size)
{
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
return g_object_new (GTK_TYPE_SLICE_LIST_MODEL,
"item-type", g_list_model_get_item_type (model),
"model", model,
"offset", offset,
"size", size,
NULL);
}
/**
* gtk_slice_list_model_new_for_type:
* @item_type: the type of items
*
* Creates a new empty #GtkSliceListModel for the given @item_type that
* can be set up later.
*
* Returns: a new empty #GtkSliceListModel
**/
GtkSliceListModel *
gtk_slice_list_model_new_for_type (GType item_type)
{
g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
return g_object_new (GTK_TYPE_SLICE_LIST_MODEL,
"item-type", item_type,
NULL);
}
/**
* gtk_slice_list_model_set_model:
* @self: a #GtkSliceListModel

View File

@ -40,8 +40,6 @@ GDK_AVAILABLE_IN_ALL
GtkSliceListModel * gtk_slice_list_model_new (GListModel *model,
guint offset,
guint size);
GDK_AVAILABLE_IN_ALL
GtkSliceListModel * gtk_slice_list_model_new_for_type (GType item_type);
GDK_AVAILABLE_IN_ALL
void gtk_slice_list_model_set_model (GtkSliceListModel *self,

View File

@ -42,7 +42,6 @@
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_MODEL,
PROP_SORTER,
NUM_PROPERTIES
@ -54,7 +53,6 @@ struct _GtkSortListModel
{
GObject parent_instance;
GType item_type;
GListModel *model;
GtkSorter *sorter;
@ -89,9 +87,7 @@ gtk_sort_list_entry_free (gpointer data)
static GType
gtk_sort_list_model_get_item_type (GListModel *list)
{
GtkSortListModel *self = GTK_SORT_LIST_MODEL (list);
return self->item_type;
return G_TYPE_OBJECT;
}
static guint
@ -262,10 +258,6 @@ gtk_sort_list_model_set_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
self->item_type = g_value_get_gtype (value);
break;
case PROP_MODEL:
gtk_sort_list_model_set_model (self, g_value_get_object (value));
break;
@ -290,10 +282,6 @@ gtk_sort_list_model_get_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, self->item_type);
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
@ -405,18 +393,6 @@ gtk_sort_list_model_class_init (GtkSortListModelClass *class)
GTK_TYPE_SORTER,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkSortListModel:item-type:
*
* The #GType for items of this model
*/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type",
P_("Item type"),
P_("The type of items of this list"),
G_TYPE_OBJECT,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkSortListModel:model:
*
@ -439,7 +415,7 @@ gtk_sort_list_model_init (GtkSortListModel *self)
/**
* gtk_sort_list_model_new:
* @model: the model to sort
* @model: (allow-none): the model to sort
* @sorter: (allow-none): the #GtkSorter to sort @model with
*
* Creates a new sort list model that uses the @sorter to sort @model.
@ -452,11 +428,10 @@ gtk_sort_list_model_new (GListModel *model,
{
GtkSortListModel *result;
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
g_return_val_if_fail (sorter == NULL || GTK_IS_SORTER (sorter), NULL);
result = g_object_new (GTK_TYPE_SORT_LIST_MODEL,
"item-type", g_list_model_get_item_type (model),
"model", model,
"sorter", sorter,
NULL);
@ -464,26 +439,6 @@ gtk_sort_list_model_new (GListModel *model,
return result;
}
/**
* gtk_sort_list_model_new_for_type:
* @item_type: the type of the items that will be returned
*
* Creates a new empty sort list model set up to return items of type @item_type.
* It is up to the application to set a proper sort function and model to ensure
* the item type is matched.
*
* Returns: a new #GtkSortListModel
**/
GtkSortListModel *
gtk_sort_list_model_new_for_type (GType item_type)
{
g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
return g_object_new (GTK_TYPE_SORT_LIST_MODEL,
"item-type", item_type,
NULL);
}
/**
* gtk_sort_list_model_set_model:
* @self: a #GtkSortListModel
@ -500,10 +455,6 @@ gtk_sort_list_model_set_model (GtkSortListModel *self,
g_return_if_fail (GTK_IS_SORT_LIST_MODEL (self));
g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
if (model)
{
g_return_if_fail (g_type_is_a (g_list_model_get_item_type (model), self->item_type));
}
if (self->model == model)
return;

View File

@ -40,9 +40,6 @@ G_DECLARE_FINAL_TYPE (GtkSortListModel, gtk_sort_list_model, GTK, SORT_LIST_MODE
GDK_AVAILABLE_IN_ALL
GtkSortListModel * gtk_sort_list_model_new (GListModel *model,
GtkSorter *sorter);
GDK_AVAILABLE_IN_ALL
GtkSortListModel * gtk_sort_list_model_new_for_type (GType item_type);
GDK_AVAILABLE_IN_ALL
void gtk_sort_list_model_set_sorter (GtkSortListModel *self,
GtkSorter *sorter);

View File

@ -110,9 +110,9 @@ gtk_string_filter_match (GtkFilter *filter,
!gtk_expression_evaluate (self->expression, item, &value))
return FALSE;
s = g_value_get_string (&value);
if (s == NULL)
return FALSE;
prepared = gtk_string_filter_prepare (self, s);
if (prepared == NULL)
return FALSE;
switch (self->match_mode)
{

View File

@ -138,20 +138,13 @@ gtk_string_object_class_init (GtkStringObjectClass *class)
pspec = g_param_spec_string ("string", "String", "String",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_STRING, pspec);
}
static GtkStringObject *
gtk_string_object_new (const char *string)
{
return g_object_new (GTK_TYPE_STRING_OBJECT, "string", string, NULL);
}
static GtkStringObject *
gtk_string_object_new_take (char *string)
{
@ -163,6 +156,20 @@ gtk_string_object_new_take (char *string)
return obj;
}
/**
* gtk_string_object_new:
* @string: (non-nullable): The string to wrap
*
* Wraps a string in an object for use with #GListModel
*
* Returns: a new #GtkStringObject
**/
GtkStringObject *
gtk_string_object_new (const char *string)
{
return gtk_string_object_new_take (g_strdup (string));
}
/**
* gtk_string_object_get_string:
* @self: a #GtkStringObject
@ -432,15 +439,13 @@ gtk_string_list_init (GtkStringList *self)
* Returns: a new #GtkStringList
*/
GtkStringList *
gtk_string_list_new (const char **strings)
gtk_string_list_new (const char * const *strings)
{
GtkStringList *self;
guint i;
self = g_object_new (GTK_TYPE_STRING_LIST, NULL);
for (i = 0; strings[i]; i++)
g_sequence_append (self->items, gtk_string_object_new (strings[i]));
gtk_string_list_splice (self, 0, 0, strings);
return self;
}
@ -450,11 +455,10 @@ gtk_string_list_new (const char **strings)
* @self: a #GtkStringList
* @position: the position at which to make the change
* @n_removals: the number of strings to remove
* @additions: (array length=n_additions): the strings to add
* @n_additions: the number of items to add
* @additions: (array zero-terminated=1) (nullable): The strings to add
*
* Changes @self by removing @n_removals strings and adding @n_additions
* strings to it.
* Changes @self by removing @n_removals strings and adding @additions
* to it.
*
* This function is more efficient than gtk_string_list_insert() and
* gtk_string_list_remove(), because it only emits
@ -470,11 +474,10 @@ void
gtk_string_list_splice (GtkStringList *self,
guint position,
guint n_removals,
const char **additions,
guint n_additions)
const char * const *additions)
{
GSequenceIter *it;
guint n_items;
guint add, n_items;
g_return_if_fail (GTK_IS_STRING_LIST (self));
g_return_if_fail (position + n_removals >= position); /* overflow */
@ -494,17 +497,18 @@ gtk_string_list_splice (GtkStringList *self,
it = end;
}
if (n_additions)
if (additions)
{
gint i;
for (i = 0; i < n_additions; i++)
for (add = 0; additions[add]; add++)
{
g_sequence_insert_before (it, gtk_string_object_new (additions[i]));
g_sequence_insert_before (it, gtk_string_object_new (additions[add]));
}
}
else
add = 0;
g_list_model_items_changed (G_LIST_MODEL (self), position, n_removals, n_additions);
if (n_removals || add)
g_list_model_items_changed (G_LIST_MODEL (self), position, n_removals, add);
}
/**
@ -589,8 +593,8 @@ gtk_string_list_remove (GtkStringList *self,
* @self: a #GtkStringList
* @position: the position to get the string for
*
* Gets the string that is at @position in @self. @position
* must be smaller than the current length of the list.
* Gets the string that is at @position in @self. If @self
* does not contain @position items, %NULL is returned.
*
* This function returns the const char *. To get the
* object wrapping it, use g_list_model_get_item().

View File

@ -36,6 +36,8 @@ G_BEGIN_DECLS
GDK_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (GtkStringObject, gtk_string_object, GTK, STRING_OBJECT, GObject)
GDK_AVAILABLE_IN_ALL
GtkStringObject * gtk_string_object_new (const char *string);
GDK_AVAILABLE_IN_ALL
const char * gtk_string_object_get_string (GtkStringObject *self);
@ -45,7 +47,7 @@ GDK_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (GtkStringList, gtk_string_list, GTK, STRING_LIST, GObject)
GDK_AVAILABLE_IN_ALL
GtkStringList * gtk_string_list_new (const char **strings);
GtkStringList * gtk_string_list_new (const char * const *strings);
GDK_AVAILABLE_IN_ALL
void gtk_string_list_append (GtkStringList *self,
@ -63,8 +65,7 @@ GDK_AVAILABLE_IN_ALL
void gtk_string_list_splice (GtkStringList *self,
guint position,
guint n_removals,
const char **additions,
guint n_additions);
const char * const *additions);
GDK_AVAILABLE_IN_ALL
const char * gtk_string_list_get_string (GtkStringList *self,

View File

@ -533,16 +533,6 @@ gtk_tree_list_model_expand_node (GtkTreeListModel *self,
if (model == NULL)
return 0;
if (!g_type_is_a (g_list_model_get_item_type (model), g_list_model_get_item_type (self->root_node.model)))
{
g_critical ("The GtkTreeListModelCreateModelFunc for %p returned a model with item type \"%s\" "
"but \"%s\" is required.",
self,
g_type_name (g_list_model_get_item_type (model)),
g_type_name (g_list_model_get_item_type (self->root_node.model)));
return 0;
}
gtk_tree_list_model_init_node (self, node, model);
tree_node_mark_dirty (node);
@ -576,7 +566,7 @@ gtk_tree_list_model_get_item_type (GListModel *list)
GtkTreeListModel *self = GTK_TREE_LIST_MODEL (list);
if (self->passthrough)
return g_list_model_get_item_type (self->root_node.model);
return G_TYPE_OBJECT;
else
return GTK_TYPE_TREE_LIST_ROW;
}

View File

@ -245,10 +245,10 @@ gtk_inspector_controllers_set_object (GtkInspectorControllers *self,
self->model = gtk_property_lookup_list_model_new (GTK_TYPE_WIDGET, "parent");
gtk_property_lookup_list_model_set_object (self->model, object);
map_model = gtk_map_list_model_new (G_TYPE_LIST_MODEL, G_LIST_MODEL (self->model), map_to_controllers, NULL, NULL);
map_model = gtk_map_list_model_new (G_LIST_MODEL (self->model), map_to_controllers, NULL, NULL);
g_object_unref (self->model);
flatten_model = gtk_flatten_list_model_new (GTK_TYPE_EVENT_CONTROLLER, G_LIST_MODEL (map_model));
flatten_model = gtk_flatten_list_model_new (G_LIST_MODEL (map_model));
sorter = gtk_custom_sorter_new (compare_controllers, NULL, NULL);
sort_model = gtk_sort_list_model_new (G_LIST_MODEL (flatten_model), sorter);

View File

@ -130,7 +130,7 @@ object_tree_widget_get_children (GObject *object)
g_list_store_append (list, sublist);
g_object_unref (sublist);
flatten = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (list));
flatten = gtk_flatten_list_model_new (G_LIST_MODEL (list));
g_object_unref (list);
return G_LIST_MODEL (flatten);
@ -225,7 +225,7 @@ list_model_for_properties (GObject *object,
g_object_unref (tmp);
}
result = G_LIST_MODEL (gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (concat)));
result = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (concat)));
g_object_unref (concat);
return result;
}
@ -330,7 +330,7 @@ object_tree_tree_view_get_children (GObject *object)
g_object_unref (selection);
g_list_store_append (result_list, columns);
g_object_unref (columns);
result = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (result_list));
result = gtk_flatten_list_model_new (G_LIST_MODEL (result_list));
g_object_unref (result_list);
return G_LIST_MODEL (result);
@ -353,7 +353,7 @@ object_tree_column_view_get_children (GObject *object)
g_list_store_append (result_list, sublist);
g_object_unref (sublist);
result = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (result_list));
result = gtk_flatten_list_model_new (G_LIST_MODEL (result_list));
g_object_unref (result_list);
return G_LIST_MODEL (result);
@ -640,7 +640,7 @@ object_get_children (GObject *object)
if (result_list)
{
result = G_LIST_MODEL (gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (result_list)));
result = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
g_object_unref (result_list);
}
@ -1179,7 +1179,7 @@ create_root_model (GdkDisplay *display)
g_list_store_append (list, special);
g_object_unref (special);
filter = gtk_filter_list_model_new_for_type (G_TYPE_OBJECT);
filter = gtk_filter_list_model_new (NULL, NULL);
custom_filter = gtk_custom_filter_new (toplevel_filter_func,
display, NULL);
gtk_filter_list_model_set_filter (filter, custom_filter);
@ -1187,7 +1187,7 @@ create_root_model (GdkDisplay *display)
g_list_store_append (list, filter);
g_object_unref (filter);
flatten = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (list));
flatten = gtk_flatten_list_model_new (G_LIST_MODEL (list));
g_object_unref (list);
return G_LIST_MODEL (flatten);
}

View File

@ -621,7 +621,7 @@ main (int argc, char *argv[])
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_widget), NULL);
listview = gtk_grid_view_new_with_factory (factory);
listview = gtk_list_view_new_with_factory (factory);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
if (argc > 1)
@ -645,7 +645,7 @@ main (int argc, char *argv[])
selectionmodel = file_info_selection_new (G_LIST_MODEL (filter));
g_object_unref (filter);
gtk_grid_view_set_model (GTK_GRID_VIEW (listview), G_LIST_MODEL (selectionmodel));
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selectionmodel));
statusbar = gtk_statusbar_new ();
gtk_widget_add_tick_callback (statusbar, (GtkTickCallback) update_statusbar, NULL, NULL);

View File

@ -492,7 +492,7 @@ test_bind_child (void)
"filter");
filter = gtk_string_filter_new ();
child = gtk_filter_list_model_new_for_type (G_TYPE_OBJECT);
child = gtk_filter_list_model_new (NULL, NULL);
gtk_filter_list_model_set_filter (child, filter);
target = gtk_filter_list_model_new (G_LIST_MODEL (child), NULL);
g_object_unref (child);

View File

@ -210,7 +210,7 @@ new_model (GListStore *store)
GtkFlattenListModel *result;
GString *changes;
result = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (store));
result = gtk_flatten_list_model_new (G_LIST_MODEL (store));
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);

View File

@ -196,7 +196,7 @@ new_model (GListStore *store)
GtkMapListModel *result;
GString *changes;
result = gtk_map_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (store), map_multiply, GUINT_TO_POINTER (2), NULL);
result = gtk_map_list_model_new (G_LIST_MODEL (store), map_multiply, GUINT_TO_POINTER (2), NULL);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);

View File

@ -613,6 +613,59 @@ test_selection_filter (void)
g_object_unref (store);
g_object_unref (selection);
}
static void
test_set_model (void)
{
GtkSelectionModel *selection;
GListStore *store;
GListModel *m1, *m2;
gboolean ret;
store = new_store (1, 5, 1);
m1 = G_LIST_MODEL (store);
m2 = G_LIST_MODEL (gtk_slice_list_model_new (m1, 0, 3));
selection = new_model (store);
assert_selection (selection, "");
assert_selection_changes (selection, "");
ret = gtk_selection_model_select_range (selection, 1, 3, FALSE);
g_assert_true (ret);
assert_selection (selection, "2 3 4");
assert_selection_changes (selection, "1:3");
/* we retain the selected item across model changes */
gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), m2);
assert_changes (selection, "0-5+3");
assert_selection (selection, "2 3");
assert_selection_changes (selection, "");
gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), NULL);
assert_changes (selection, "0-3");
assert_selection (selection, "");
assert_selection_changes (selection, "");
gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), m2);
assert_changes (selection, "0+3");
assert_selection (selection, "");
assert_selection_changes (selection, "");
ret = gtk_selection_model_select_all (selection);
g_assert_true (ret);
assert_selection (selection, "1 2 3");
assert_selection_changes (selection, "0:3");
/* we retain no selected item across model changes */
gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), m1);
assert_changes (selection, "0-3+5");
assert_selection (selection, "1 2 3");
assert_selection_changes (selection, "");
g_object_unref (m2);
g_object_unref (m1);
g_object_unref (selection);
}
int
main (int argc, char *argv[])
{
@ -633,6 +686,7 @@ main (int argc, char *argv[])
g_test_add_func ("/multiselection/readd", test_readd);
g_test_add_func ("/multiselection/set_selection", test_set_selection);
g_test_add_func ("/multiselection/selection-filter", test_selection_filter);
g_test_add_func ("/multiselection/set-model", test_set_model);
return g_test_run ();
}

View File

@ -644,6 +644,57 @@ test_query_range (void)
g_object_unref (selection);
}
static void
test_set_model (void)
{
GtkSelectionModel *selection;
GListStore *store;
GListModel *m1, *m2;
store = new_store (1, 5, 1);
m1 = G_LIST_MODEL (store);
m2 = G_LIST_MODEL (gtk_slice_list_model_new (m1, 0, 3));
selection = new_model (store, TRUE, TRUE);
assert_selection (selection, "1");
assert_selection_changes (selection, "");
/* we retain the selected item across model changes */
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m2);
assert_changes (selection, "0-5+3");
assert_selection (selection, "1");
assert_selection_changes (selection, "");
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), NULL);
assert_changes (selection, "0-3");
assert_selection (selection, "");
assert_selection_changes (selection, "");
gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (selection), FALSE);
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m2);
assert_changes (selection, "0+3");
assert_selection (selection, "");
assert_selection_changes (selection, "");
/* we retain no selected item across model changes */
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m1);
assert_changes (selection, "0-3+5");
assert_selection (selection, "");
assert_selection_changes (selection, "");
gtk_single_selection_set_selected (GTK_SINGLE_SELECTION (selection), 4);
assert_selection (selection, "5");
assert_selection_changes (selection, "4:1");
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m2);
assert_changes (selection, "0-5+3");
assert_selection (selection, "");
assert_selection_changes (selection, "");
g_object_unref (m2);
g_object_unref (m1);
g_object_unref (selection);
}
int
main (int argc, char *argv[])
{
@ -662,6 +713,7 @@ main (int argc, char *argv[])
g_test_add_func ("/singleselection/persistence", test_persistence);
g_test_add_func ("/singleselection/query-range", test_query_range);
g_test_add_func ("/singleselection/changes", test_changes);
g_test_add_func ("/singleselection/set-model", test_set_model);
return g_test_run ();
}

View File

@ -191,11 +191,7 @@ new_model (GListStore *store, guint offset, guint size)
GtkSliceListModel *result;
GString *changes;
result = gtk_slice_list_model_new_for_type (G_TYPE_OBJECT);
if (store)
gtk_slice_list_model_set_model (result, G_LIST_MODEL (store));
gtk_slice_list_model_set_offset (result, offset);
gtk_slice_list_model_set_size (result, size);
result = gtk_slice_list_model_new (G_LIST_MODEL (store), offset, size);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);

View File

@ -203,7 +203,7 @@ new_model (gpointer model)
g_object_unref (sorter);
}
else
result = gtk_sort_list_model_new_for_type (G_TYPE_OBJECT);
result = gtk_sort_list_model_new (NULL, NULL);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);

View File

@ -184,7 +184,7 @@ test_splice (void)
assert_model (list, "a b c d e");
gtk_string_list_splice (list, 2, 2, (const char *[]){ "x", "y", "z" }, 3);
gtk_string_list_splice (list, 2, 2, (const char *[]){ "x", "y", "z", NULL });
assert_model (list, "a b x y z e");
assert_changes (list, "2-2+3");