diff options
author | Matthias Clasen <mclasen@redhat.com> | 2023-05-16 21:28:29 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2023-05-16 21:28:29 +0000 |
commit | 0bbc6f89324e1caa0c8c1919f1b9d4133a59223b (patch) | |
tree | e944e538dd9f882f6de626ee24d7082f279875ab /gtk/gtknotebook.c | |
parent | 0434ad3bd9cc2e06d3d7103810aa4b801bb4e1c6 (diff) | |
parent | 1ad4c04b2a17dd84b3929a6c70b2712c31dff99b (diff) | |
download | gtk+-0bbc6f89324e1caa0c8c1919f1b9d4133a59223b.tar.gz |
Merge branch 'ebassi/issue-5837' into 'main'
Fix various compiler warnings with GCC 13
Closes #5837
See merge request GNOME/gtk!5977
Diffstat (limited to 'gtk/gtknotebook.c')
-rw-r--r-- | gtk/gtknotebook.c | 54 |
1 files changed, 49 insertions, 5 deletions
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) |