[gtk/wip/otte/listview: 86/199] listlistmodel: Add gtk_list_list_model_item_moved()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 86/199] listlistmodel: Add gtk_list_list_model_item_moved()
- Date: Tue, 4 Feb 2020 18:37:33 +0000 (UTC)
commit 1093796a60d2a9b38d135218c56d924a6172925c
Author: Benjamin Otte <otte redhat com>
Date: Fri Sep 28 02:45:54 2018 +0200
listlistmodel: Add gtk_list_list_model_item_moved()
Use it to fix a case that just said g_warning ("oops").
Apparently I had forgotten the case where a container moved a child
in the widget tree.
gtk/gtklistlistmodel.c | 64 +++++++++++++++++++++++++++++++------------
gtk/gtklistlistmodelprivate.h | 3 ++
gtk/gtkwidget.c | 2 +-
3 files changed, 51 insertions(+), 18 deletions(-)
---
diff --git a/gtk/gtklistlistmodel.c b/gtk/gtklistlistmodel.c
index 3d10f49280..f01133978d 100644
--- a/gtk/gtklistlistmodel.c
+++ b/gtk/gtklistlistmodel.c
@@ -206,15 +206,12 @@ gtk_list_list_model_new_with_size (GType item_type,
return result;
}
-void
-gtk_list_list_model_item_added (GtkListListModel *self,
- gpointer item)
+static guint
+gtk_list_list_model_find (GtkListListModel *self,
+ gpointer item)
{
- gpointer x;
guint position;
-
- g_return_if_fail (GTK_IS_LIST_LIST_MODEL (self));
- g_return_if_fail (item != NULL);
+ gpointer x;
position = 0;
for (x = self->get_first (self->data);
@@ -222,7 +219,17 @@ gtk_list_list_model_item_added (GtkListListModel *self,
x = self->get_next (x, self->data))
position++;
- gtk_list_list_model_item_added_at (self, position);
+ return position;
+}
+
+void
+gtk_list_list_model_item_added (GtkListListModel *self,
+ gpointer item)
+{
+ g_return_if_fail (GTK_IS_LIST_LIST_MODEL (self));
+ g_return_if_fail (item != NULL);
+
+ gtk_list_list_model_item_added_at (self, gtk_list_list_model_find (self, item));
}
void
@@ -241,26 +248,49 @@ void
gtk_list_list_model_item_removed (GtkListListModel *self,
gpointer previous)
{
- gpointer x;
guint position;
g_return_if_fail (GTK_IS_LIST_LIST_MODEL (self));
if (previous == NULL)
+ position = 0;
+ else
+ position = 1 + gtk_list_list_model_find (self, previous);
+
+ gtk_list_list_model_item_removed_at (self, position);
+}
+
+void
+gtk_list_list_model_item_moved (GtkListListModel *self,
+ gpointer item,
+ gpointer previous_previous)
+{
+ guint position, previous_position;
+ guint min, max;
+
+ g_return_if_fail (GTK_IS_LIST_LIST_MODEL (self));
+ g_return_if_fail (item != previous_previous);
+
+ position = gtk_list_list_model_find (self, item);
+
+ if (previous_previous == NULL)
{
- position = 0;
+ previous_position = 0;
}
else
{
- position = 1;
-
- for (x = self->get_first (self->data);
- x != previous;
- x = self->get_next (x, self->data))
- position++;
+ previous_position = gtk_list_list_model_find (self, previous_previous);
+ if (position > previous_position)
+ previous_position++;
}
- gtk_list_list_model_item_removed_at (self, position);
+ /* item didn't move */
+ if (position == previous_position)
+ return;
+
+ min = MIN (position, previous_position);
+ max = MAX (position, previous_position) + 1;
+ g_list_model_items_changed (G_LIST_MODEL (self), min, max - min, max - min);
}
void
diff --git a/gtk/gtklistlistmodelprivate.h b/gtk/gtklistlistmodelprivate.h
index 3103b3c7c3..f0a5717238 100644
--- a/gtk/gtklistlistmodelprivate.h
+++ b/gtk/gtklistlistmodelprivate.h
@@ -64,6 +64,9 @@ void gtk_list_list_model_item_removed (GtkListListMode
gpointer previous);
void gtk_list_list_model_item_removed_at (GtkListListModel *self,
guint position);
+void gtk_list_list_model_item_moved (GtkListListModel *self,
+ gpointer item,
+ gpointer previous_previous);
void gtk_list_list_model_clear (GtkListListModel *self);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index d93b4b13a5..d374784258 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -6157,7 +6157,7 @@ gtk_widget_reposition_after (GtkWidget *widget,
if (parent->priv->children_observer)
{
if (prev_previous)
- g_warning ("oops");
+ gtk_list_list_model_item_moved (parent->priv->children_observer, widget, prev_previous);
else
gtk_list_list_model_item_added (parent->priv->children_observer, widget);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]