mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-09 18:30:08 +00:00
Implement GtkSelectionModel for GtkNotebookPages
The documentation says that the model returned by gtk_notebook_get_pages() implements the GtkSelectionModel interface, but checking the history confirms this is a lie. Instead of fixing the documentation, we can easily make it true, and reduce the differences between GtkNotebook and GtkStack. Fixes: #5837
This commit is contained in:
parent
b2a3a5e226
commit
0bbe68db0b
@ -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"
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user