diff options
author | Benjamin Otte <otte@redhat.com> | 2019-10-24 02:14:34 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2019-10-28 10:49:02 +0100 |
commit | 2ba06352b18dc4c52578d0a1e9de760a5c6a4775 (patch) | |
tree | 0a4b418e7859535db17b75c8ccaf51d27a2b5cfa | |
parent | f41f288fe757a98c523b7df730abb92a35b5cc01 (diff) | |
download | gtk+-2ba06352b18dc4c52578d0a1e9de760a5c6a4775.tar.gz |
Remove gtk_selection_model_user_select_item() again
This reverts commit 6a164ab306dad9096bde736c907494c71086d3c4.
The function was awkward and we now have only one caller again, so we
can fold it back into it.
-rw-r--r-- | docs/reference/gtk/gtk4-sections.txt | 2 | ||||
-rw-r--r-- | gtk/gtklistbase.c | 69 | ||||
-rw-r--r-- | gtk/gtkselectionmodel.c | 87 | ||||
-rw-r--r-- | gtk/gtkselectionmodel.h | 5 |
4 files changed, 60 insertions, 103 deletions
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 432e51a4f3..4344e85f30 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -453,8 +453,6 @@ gtk_selection_model_select_all gtk_selection_model_unselect_all gtk_selection_model_query_range <SUBSECTION> -gtk_selection_model_user_select_item -<SUBSECTION> gtk_selection_model_selection_changed <SUBSECTION Standard> GTK_SELECTION_MODEL diff --git a/gtk/gtklistbase.c b/gtk/gtklistbase.c index 10185ba728..d030e2ee76 100644 --- a/gtk/gtklistbase.c +++ b/gtk/gtklistbase.c @@ -119,22 +119,73 @@ gtk_list_base_select_item (GtkListBase *self, { GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self); GtkSelectionModel *model; + gboolean success = FALSE; + guint n_items; model = gtk_list_item_manager_get_model (priv->item_manager); if (model == NULL) return; - if (gtk_selection_model_user_select_item (model, - pos, - modify, - extend ? gtk_list_item_tracker_get_position (priv->item_manager, priv->selected) - : GTK_INVALID_LIST_POSITION)) + n_items = g_list_model_get_n_items (G_LIST_MODEL (model)); + if (pos >= n_items) + return; + + if (extend) + { + guint extend_pos = gtk_list_item_tracker_get_position (priv->item_manager, priv->selected); + + if (extend_pos < n_items) + { + guint max = MAX (extend_pos, pos); + guint min = MIN (extend_pos, pos); + + if (modify) + { + if (gtk_selection_model_is_selected (model, extend_pos)) + { + success = gtk_selection_model_select_range (model, + min, + max - min + 1, + FALSE); + } + else + { + success = gtk_selection_model_unselect_range (model, + min, + max - min + 1); + } + } + else + { + success = gtk_selection_model_select_range (model, + min, + max - min + 1, + TRUE); + } + } + /* If there's no range to select or selecting ranges isn't supported + * by the model, fall through to normal setting. + */ + } + if (success) + return; + + if (modify) { - gtk_list_item_tracker_set_position (priv->item_manager, - priv->selected, - pos, - 0, 0); + if (gtk_selection_model_is_selected (model, pos)) + success = gtk_selection_model_unselect_item (model, pos); + else + success = gtk_selection_model_select_item (model, pos, FALSE); } + else + { + success = gtk_selection_model_select_item (model, pos, TRUE); + } + + gtk_list_item_tracker_set_position (priv->item_manager, + priv->selected, + pos, + 0, 0); } static void diff --git a/gtk/gtkselectionmodel.c b/gtk/gtkselectionmodel.c index c5853e87a7..7be454fd74 100644 --- a/gtk/gtkselectionmodel.c +++ b/gtk/gtkselectionmodel.c @@ -382,90 +382,3 @@ gtk_selection_model_selection_changed (GtkSelectionModel *model, g_signal_emit (model, signals[SELECTION_CHANGED], 0, position, n_items); } -/** - * gtk_selection_model_user_select_item: - * @self: a #GtkSelectionModel - * @pos: position selected by the user. If this position is invalid - * no selection will be done. - * @modify: %TRUE if the selection should be modified, %FALSE - * if a new selection should be done. This is usually set - * to %TRUE if the user keeps the <Shift> key pressed. - * @extend_pos: the position to extend the selection from or - * an invalid position like #GTK_INVALID_LIST_POSITION to not - * extend the selection. Selections are usually extended - * from the last selected position if the user presses the - * <Ctrl> key. The last selected position is stored by the - * widget - * - * Does a selection according to how GTK list widgets modify - * selections, both when clicking rows with the mouse or when using - * the keyboard. - * - * Returns: %TRUE if the last selected position for further calls - * to this function should be updated to @pos, %FALSE if the - * last selected position should not change. - **/ -gboolean -gtk_selection_model_user_select_item (GtkSelectionModel *self, - guint pos, - gboolean modify, - guint extend_pos) -{ - gboolean success = FALSE; - guint n_items; - - g_return_val_if_fail (GTK_IS_SELECTION_MODEL (self), FALSE); - - n_items = g_list_model_get_n_items (G_LIST_MODEL (self)); - if (pos >= n_items) - return FALSE; - - if (extend_pos < n_items) - { - guint max = MAX (extend_pos, pos); - guint min = MIN (extend_pos, pos); - if (modify) - { - if (gtk_selection_model_is_selected (self, extend_pos)) - { - success = gtk_selection_model_select_range (self, - min, - max - min + 1, - FALSE); - } - else - { - success = gtk_selection_model_unselect_range (self, - min, - max - min + 1); - } - } - else - { - success = gtk_selection_model_select_range (self, - min, - max - min + 1, - TRUE); - } - /* If there's no range to select or selecting ranges isn't supported - * by the model, fall through to normal setting. - */ - } - if (success) - return FALSE; - - if (modify) - { - if (gtk_selection_model_is_selected (self, pos)) - success = gtk_selection_model_unselect_item (self, pos); - else - success = gtk_selection_model_select_item (self, pos, FALSE); - } - else - { - success = gtk_selection_model_select_item (self, pos, TRUE); - } - - return success; -} - diff --git a/gtk/gtkselectionmodel.h b/gtk/gtkselectionmodel.h index 6f3dcb28e1..c982a918ad 100644 --- a/gtk/gtkselectionmodel.h +++ b/gtk/gtkselectionmodel.h @@ -130,11 +130,6 @@ void gtk_selection_model_query_range (GtkSelectionMod guint *n_items, gboolean *selected); -GDK_AVAILABLE_IN_ALL -gboolean gtk_selection_model_user_select_item (GtkSelectionModel *self, - guint pos, - gboolean modify, - guint extend_pos); /* for implementations only */ GDK_AVAILABLE_IN_ALL void gtk_selection_model_selection_changed (GtkSelectionModel *model, |