diff options
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtklistitemmanager.c | 23 | ||||
-rw-r--r-- | gtk/gtknotebook.c | 54 |
2 files changed, 62 insertions, 15 deletions
diff --git a/gtk/gtklistitemmanager.c b/gtk/gtklistitemmanager.c index 2ca7f9eaf8..8fc0476370 100644 --- a/gtk/gtklistitemmanager.c +++ b/gtk/gtklistitemmanager.c @@ -597,7 +597,7 @@ gtk_list_tile_get_position (GtkListItemManager *self, } else { - pos = 0; + pos = 0; } for (parent = gtk_rb_tree_node_get_parent (tile); @@ -715,6 +715,7 @@ static void gtk_list_tile_set_type (GtkListTile *tile, GtkListTileType type) { + g_assert (tile != NULL); if (tile->type == type) return; @@ -845,7 +846,8 @@ gtk_list_item_manager_remove_items (GtkListItemManager *self, if (offset) tile = gtk_list_item_manager_ensure_split (self, tile, offset); header = gtk_list_tile_get_previous_skip (tile); - if (header->type != GTK_LIST_TILE_HEADER && header->type != GTK_LIST_TILE_UNMATCHED_HEADER) + if (header != NULL && + (header->type != GTK_LIST_TILE_HEADER && header->type != GTK_LIST_TILE_UNMATCHED_HEADER)) header = NULL; while (n_items > 0) @@ -911,7 +913,7 @@ gtk_list_item_manager_add_items (GtkListItemManager *self, GtkListItemChange *change, guint position, guint n_items) -{ +{ GtkListTile *tile; guint offset; gboolean has_sections; @@ -952,7 +954,7 @@ gtk_list_item_manager_add_items (GtkListItemManager *self, } if (offset) tile = gtk_list_item_manager_ensure_split (self, tile, offset); - + tile = gtk_rb_tree_insert_before (self->items, tile); tile->type = GTK_LIST_TILE_ITEM; tile->n_items = n_items; @@ -962,7 +964,7 @@ gtk_list_item_manager_add_items (GtkListItemManager *self, { GtkListTile *section = gtk_list_tile_get_previous_skip (tile); - if (section->type == GTK_LIST_TILE_HEADER) + if (section != NULL && section->type == GTK_LIST_TILE_HEADER) { gtk_list_item_change_clear_header (change, §ion->widget); gtk_list_tile_set_type (section, @@ -1207,7 +1209,7 @@ gtk_list_item_manager_insert_section (GtkListItemManager *self, { GtkListTile *tile, *footer, *header; guint offset; - + tile = gtk_list_item_manager_get_nth (self, pos, &offset); if (tile == NULL) { @@ -1225,7 +1227,8 @@ gtk_list_item_manager_insert_section (GtkListItemManager *self, tile = gtk_list_item_manager_ensure_split (self, tile, offset); header = gtk_list_tile_get_previous_skip (tile); - if (header->type == GTK_LIST_TILE_HEADER || header->type == GTK_LIST_TILE_UNMATCHED_HEADER) + if (header != NULL && + (header->type == GTK_LIST_TILE_HEADER || header->type == GTK_LIST_TILE_UNMATCHED_HEADER)) { if (header_type == GTK_LIST_TILE_HEADER) gtk_list_tile_set_type (header, header_type); @@ -1257,7 +1260,7 @@ gtk_list_tile_find_widget_before (GtkListTile *tile) for (other = gtk_rb_tree_node_get_previous (tile); other; other = gtk_rb_tree_node_get_previous (other)) - { + { if (other->widget) return other->widget; } @@ -1460,7 +1463,7 @@ gtk_list_item_manager_model_items_changed_cb (GListModel *model, GtkListTile *tile, *new_tile; GtkWidget *insert_after; guint i, offset; - + tile = gtk_list_item_manager_get_nth (self, position, &offset); for (new_tile = tile ? gtk_rb_tree_node_get_previous (tile) : gtk_rb_tree_get_last (self->items); new_tile && new_tile->widget == NULL; @@ -1576,7 +1579,7 @@ gtk_list_item_manager_model_items_changed_cb (GListModel *model, GtkListItemTracker *tracker = l->data; GtkListTile *tile; - if (tracker->widget != NULL || + if (tracker->widget != NULL || tracker->position == GTK_INVALID_LIST_POSITION) continue; diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index f0c84d8ed1..932701206d 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -46,6 +46,7 @@ #include "gtkorientable.h" #include "gtksizerequest.h" #include "gtkprivate.h" +#include "gtkselectionmodel.h" #include "gtkstack.h" #include "gtktypebuiltins.h" #include "gtkwidgetprivate.h" @@ -1172,7 +1173,7 @@ gtk_notebook_class_init (GtkNotebookClass *class) * * A selection model with the pages. */ - properties[PROP_PAGES] = + properties[PROP_PAGES] = g_param_spec_object ("pages", NULL, NULL, G_TYPE_LIST_MODEL, GTK_PARAM_READABLE); @@ -1358,7 +1359,7 @@ gtk_notebook_class_init (GtkNotebookClass *class) /** * GtkNotebook|menu.popup: * - * Opens the context menu. + * Opens the context menu. */ gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_notebook_popup_menu); @@ -1827,7 +1828,7 @@ gtk_notebook_reorder_tab (GtkNotebook *notebook, page_num = reorder_tab (notebook, child->next, notebook->focus_tab); else page_num = reorder_tab (notebook, child, notebook->focus_tab); - + gtk_notebook_child_reordered (notebook, notebook->focus_tab->data); for (element = notebook->children, i = 0; element; element = element->next, i++) { @@ -7131,7 +7132,7 @@ gtk_notebook_get_page (GtkNotebook *notebook, list = gtk_notebook_find_child (notebook, child); if (list != NULL) page = list->data; - + return page; } @@ -7197,8 +7198,51 @@ gtk_notebook_pages_list_model_init (GListModelInterface *iface) iface->get_n_items = gtk_notebook_pages_get_n_items; iface->get_item = gtk_notebook_pages_get_item; } + +static gboolean +gtk_notebook_pages_is_selected (GtkSelectionModel *model, + guint position) +{ + GtkNotebookPages *pages = GTK_NOTEBOOK_PAGES (model); + GtkNotebookPage *page; + + page = g_list_nth_data (pages->notebook->children, position); + if (page == NULL) + return FALSE; + + return page == pages->notebook->cur_page; +} + +static gboolean +gtk_notebook_pages_select_item (GtkSelectionModel *model, + guint position, + gboolean exclusive) +{ + GtkNotebookPages *pages = GTK_NOTEBOOK_PAGES (model); + GtkNotebookPage *page; + + page = g_list_nth_data (pages->notebook->children, position); + if (page == NULL) + return FALSE; + + if (page == pages->notebook->cur_page) + return FALSE; + + gtk_notebook_switch_page (pages->notebook, page); + + return TRUE; +} + +static void +gtk_notebook_pages_selection_model_init (GtkSelectionModelInterface *iface) +{ + iface->is_selected = gtk_notebook_pages_is_selected; + iface->select_item = gtk_notebook_pages_select_item; +} + G_DEFINE_TYPE_WITH_CODE (GtkNotebookPages, gtk_notebook_pages, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_notebook_pages_list_model_init)) + G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_notebook_pages_list_model_init) + G_IMPLEMENT_INTERFACE (GTK_TYPE_SELECTION_MODEL, gtk_notebook_pages_selection_model_init)) static void gtk_notebook_pages_init (GtkNotebookPages *pages) |