Class Notebook

All Implemented Interfaces:
PointerInterface

public class Notebook extends Widget
`GtkNotebook` is a container whose children are pages switched
between using tabs.

![An example GtkNotebook](notebook.png)

There are many configuration options for `GtkNotebook`. Among
other things, you can choose on which edge the tabs appear
(see [method@Gtk.Notebook.set_tab_pos]), whether, if there are
too many tabs to fit the notebook should be made bigger or scrolling
arrows added (see [method@Gtk.Notebook.set_scrollable]), and whether
there will be a popup menu allowing the users to switch pages.
(see [method@Gtk.Notebook.popup_enable]).

# GtkNotebook as GtkBuildable

The `GtkNotebook` implementation of the `GtkBuildable` interface
supports placing children into tabs by specifying “tab” as the
“type” attribute of a <child> element. Note that the content
of the tab must be created before the tab can be filled.
A tab child can be specified without specifying a <child>
type attribute.

To add a child widget in the notebooks action area, specify
"action-start" or “action-end” as the “type” attribute of the
<child> element.

An example of a UI definition fragment with `GtkNotebook`:

```xml
<object class="GtkNotebook">
<child>
<object class="GtkLabel" id="notebook-content">
<property name="label">Content</property>
</object>
</child>
<child type="tab">
<object class="GtkLabel" id="notebook-tab">
<property name="label">Tab</property>
</object>
</child>
</object>
```

# CSS nodes

```
notebook
├── header.top
│ ├── [<action widget>]
│ ├── tabs
│ │ ├── [arrow]
│ │ ├── tab
│ │ │ ╰── <tab label>
┊ ┊ ┊
│ │ ├── tab[.reorderable-page]
│ │ │ ╰── <tab label>
│ │ ╰── [arrow]
│ ╰── [<action widget>]

╰── stack
├── <child>

╰── <child>
```

`GtkNotebook` has a main CSS node with name `notebook`, a subnode
with name `header` and below that a subnode with name `tabs` which
contains one subnode per tab with name `tab`.

If action widgets are present, their CSS nodes are placed next
to the `tabs` node. If the notebook is scrollable, CSS nodes with
name `arrow` are placed as first and last child of the `tabs` node.

The main node gets the `.frame` style class when the notebook
has a border (see [method@Gtk.Notebook.set_show_border]).

The header node gets one of the style class `.top`, `.bottom`,
`.left` or `.right`, depending on where the tabs are placed. For
reorderable pages, the tab node gets the `.reorderable-page` class.

A `tab` node gets the `.dnd` style class while it is moved with drag-and-drop.

The nodes are always arranged from left-to-right, regardless of text direction.

# Accessibility

`GtkNotebook` uses the following roles:

- %GTK_ACCESSIBLE_ROLE_GROUP for the notebook widget
- %GTK_ACCESSIBLE_ROLE_TAB_LIST for the list of tabs
- %GTK_ACCESSIBLE_ROLE_TAB role for each tab
- %GTK_ACCESSIBLE_ROLE_TAB_PANEL for each page

https://docs.gtk.org/gtk4/class.Notebook.html

  • Field Details

  • Constructor Details

    • Notebook

      public Notebook(PointerContainer pointer)
    • Notebook

      public Notebook()
      Creates a new `GtkNotebook` widget with no pages.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • appendPage

      public int appendPage(@Nonnull Widget child, @Nullable Widget tab_label)
      Appends a page to @notebook.
      Parameters:
      child - the `GtkWidget` to use as the contents of the page
      tab_label - the `GtkWidget` to be used as the label for the page, or %NULL to use the default label, “page N”
      Returns:
      the index (starting from 0) of the appended page in the notebook, or -1 if function fails
    • appendPageMenu

      public int appendPageMenu(@Nonnull Widget child, @Nullable Widget tab_label, @Nullable Widget menu_label)
      Appends a page to @notebook, specifying the widget to use as the
      label in the popup menu.
      Parameters:
      child - the `GtkWidget` to use as the contents of the page
      tab_label - the `GtkWidget` to be used as the label for the page, or %NULL to use the default label, “page N”
      menu_label - the widget to use as a label for the page-switch menu, if that is enabled. If %NULL, and @tab_label is a `GtkLabel` or %NULL, then the menu label will be a newly created label with the same text as @tab_label; if @tab_label is not a `GtkLabel`, @menu_label must be specified if the page-switch menu is to be used.
      Returns:
      the index (starting from 0) of the appended page in the notebook, or -1 if function fails
    • detachTab

      public void detachTab(@Nonnull Widget child)
      Removes the child from the notebook.

      This function is very similar to [method@Gtk.Notebook.remove_page],
      but additionally informs the notebook that the removal
      is happening as part of a tab DND operation, which should
      not be cancelled.
      Parameters:
      child - a child
    • getActionWidget

      public Widget getActionWidget(int pack_type)
      Gets one of the action widgets.

      See [method@Gtk.Notebook.set_action_widget].
      Parameters:
      pack_type - pack type of the action widget to receive
      Returns:
      The action widget with the given @pack_type or %NULL when this action widget has not been set
    • getCurrentPage

      public int getCurrentPage()
      Returns the page number of the current page.
      Returns:
      the index (starting from 0) of the current page in the notebook. If the notebook has no pages, then -1 will be returned.
    • getGroupName

      public Str getGroupName()
      Gets the current group name for @notebook.
      Returns:
      the group name, or %NULL if none is set
    • getMenuLabel

      public Widget getMenuLabel(@Nonnull Widget child)
      Retrieves the menu label widget of the page containing @child.
      Parameters:
      child - a widget contained in a page of @notebook
      Returns:
      the menu label, or %NULL if the notebook page does not have a menu label other than the default (the tab label).
    • getMenuLabelText

      public Str getMenuLabelText(@Nonnull Widget child)
      Retrieves the text of the menu label for the page containing
      @child.
      Parameters:
      child - the child widget of a page of the notebook.
      Returns:
      the text of the tab label, or %NULL if the widget does not have a menu label other than the default menu label, or the menu label widget is not a `GtkLabel`. The string is owned by the widget and must not be freed.
    • getNPages

      public int getNPages()
      Gets the number of pages in a notebook.
      Returns:
      the number of pages in the notebook
    • getNthPage

      public Widget getNthPage(int page_num)
      Returns the child widget contained in page number @page_num.
      Parameters:
      page_num - the index of a page in the notebook, or -1 to get the last page
      Returns:
      the child widget, or %NULL if @page_num is out of bounds
    • getPage

      public NotebookPage getPage(@Nonnull Widget child)
      Returns the `GtkNotebookPage` for @child.
      Parameters:
      child - a child of @notebook
      Returns:
      the `GtkNotebookPage` for @child
    • getPages

      public ListModel getPages()
      Returns a `GListModel` that contains the pages of the notebook.

      This can be used to keep an up-to-date view. The model also
      implements [iface@Gtk.SelectionModel] and can be used to track
      and modify the visible page.
      Returns:
      a `GListModel` for the notebook's children
    • getScrollable

      public boolean getScrollable()
      Returns whether the tab label area has arrows for scrolling.
      Returns:
      %TRUE if arrows for scrolling are present
    • getShowBorder

      public boolean getShowBorder()
      Returns whether a bevel will be drawn around the notebook pages.
      Returns:
      %TRUE if the bevel is drawn
    • getShowTabs

      public boolean getShowTabs()
      Returns whether the tabs of the notebook are shown.
      Returns:
      %TRUE if the tabs are shown
    • getTabDetachable

      public boolean getTabDetachable(@Nonnull Widget child)
      Returns whether the tab contents can be detached from @notebook.
      Parameters:
      child - a child `GtkWidget`
      Returns:
      %TRUE if the tab is detachable.
    • getTabLabel

      public Widget getTabLabel(@Nonnull Widget child)
      Returns the tab label widget for the page @child.

      %NULL is returned if @child is not in @notebook or
      if no tab label has specifically been set for @child.
      Parameters:
      child - the page
      Returns:
      the tab label
    • getTabLabelText

      public Str getTabLabelText(@Nonnull Widget child)
      Retrieves the text of the tab label for the page containing
      @child.
      Parameters:
      child - a widget contained in a page of @notebook
      Returns:
      the text of the tab label, or %NULL if the tab label idget is not a `GtkLabel`. The string is owned by the widget and must not be freed.
    • getTabPos

      public int getTabPos()
      Gets the edge at which the tabs are drawn.
      Returns:
      the edge at which the tabs are drawn
    • getTabReorderable

      public boolean getTabReorderable(@Nonnull Widget child)
      Gets whether the tab can be reordered via drag and drop or not.
      Parameters:
      child - a child `GtkWidget`
      Returns:
      %TRUE if the tab is reorderable.
    • insertPage

      public int insertPage(@Nonnull Widget child, @Nullable Widget tab_label, int position)
      Insert a page into @notebook at the given position.
      Parameters:
      child - the `GtkWidget` to use as the contents of the page
      tab_label - the `GtkWidget` to be used as the label for the page, or %NULL to use the default label, “page N”
      position - the index (starting at 0) at which to insert the page, or -1 to append the page after all other pages
      Returns:
      the index (starting from 0) of the inserted page in the notebook, or -1 if function fails
    • insertPageMenu

      public int insertPageMenu(@Nonnull Widget child, @Nullable Widget tab_label, @Nullable Widget menu_label, int position)
      Insert a page into @notebook at the given position, specifying
      the widget to use as the label in the popup menu.
      Parameters:
      child - the `GtkWidget` to use as the contents of the page
      tab_label - the `GtkWidget` to be used as the label for the page, or %NULL to use the default label, “page N”
      menu_label - the widget to use as a label for the page-switch menu, if that is enabled. If %NULL, and @tab_label is a `GtkLabel` or %NULL, then the menu label will be a newly created label with the same text as @tab_label; if @tab_label is not a `GtkLabel`, @menu_label must be specified if the page-switch menu is to be used.
      position - the index (starting at 0) at which to insert the page, or -1 to append the page after all other pages.
      Returns:
      the index (starting from 0) of the inserted page in the notebook
    • nextPage

      public void nextPage()
      Switches to the next page.

      Nothing happens if the current page is the last page.
    • pageNum

      public int pageNum(@Nonnull Widget child)
      Finds the index of the page which contains the given child
      widget.
      Parameters:
      child - a `GtkWidget`
      Returns:
      the index of the page containing @child, or -1 if @child is not in the notebook
    • popupDisable

      public void popupDisable()
      Disables the popup menu.
    • popupEnable

      public void popupEnable()
      Enables the popup menu.

      If the user clicks with the right mouse button on the tab labels,
      a menu with all the pages will be popped up.
    • prependPage

      public int prependPage(@Nonnull Widget child, @Nullable Widget tab_label)
      Prepends a page to @notebook.
      Parameters:
      child - the `GtkWidget` to use as the contents of the page
      tab_label - the `GtkWidget` to be used as the label for the page, or %NULL to use the default label, “page N”
      Returns:
      the index (starting from 0) of the prepended page in the notebook, or -1 if function fails
    • prependPageMenu

      public int prependPageMenu(@Nonnull Widget child, @Nullable Widget tab_label, @Nullable Widget menu_label)
      Prepends a page to @notebook, specifying the widget to use as the
      label in the popup menu.
      Parameters:
      child - the `GtkWidget` to use as the contents of the page
      tab_label - the `GtkWidget` to be used as the label for the page, or %NULL to use the default label, “page N”
      menu_label - the widget to use as a label for the page-switch menu, if that is enabled. If %NULL, and @tab_label is a `GtkLabel` or %NULL, then the menu label will be a newly created label with the same text as @tab_label; if @tab_label is not a `GtkLabel`, @menu_label must be specified if the page-switch menu is to be used.
      Returns:
      the index (starting from 0) of the prepended page in the notebook, or -1 if function fails
    • prevPage

      public void prevPage()
      Switches to the previous page.

      Nothing happens if the current page is the first page.
    • removePage

      public void removePage(int page_num)
      Removes a page from the notebook given its index
      in the notebook.
      Parameters:
      page_num - the index of a notebook page, starting from 0. If -1, the last page will be removed.
    • reorderChild

      public void reorderChild(@Nonnull Widget child, int position)
      Reorders the page containing @child, so that it appears in position
      @position.

      If @position is greater than or equal to the number of children in
      the list or negative, @child will be moved to the end of the list.
      Parameters:
      child - the child to move
      position - the new position, or -1 to move to the end
    • setActionWidget

      public void setActionWidget(@Nonnull Widget widget, int pack_type)
      Sets @widget as one of the action widgets.

      Depending on the pack type the widget will be placed before
      or after the tabs. You can use a `GtkBox` if you need to pack
      more than one widget on the same side.
      Parameters:
      widget - a `GtkWidget`
      pack_type - pack type of the action widget
    • setCurrentPage

      public void setCurrentPage(int page_num)
      Switches to the page number @page_num.

      Note that due to historical reasons, GtkNotebook refuses
      to switch to a page unless the child widget is visible.
      Therefore, it is recommended to show child widgets before
      adding them to a notebook.
      Parameters:
      page_num - index of the page to switch to, starting from 0. If negative, the last page will be used. If greater than the number of pages in the notebook, nothing will be done.
    • setGroupName

      public void setGroupName(@Nullable Str group_name)
      Sets a group name for @notebook.

      Notebooks with the same name will be able to exchange tabs
      via drag and drop. A notebook with a %NULL group name will
      not be able to exchange tabs with any other notebook.
      Parameters:
      group_name - the name of the notebook group, or %NULL to unset it
    • setGroupName

      public void setGroupName(String group_name)
      Sets a group name for @notebook.

      Notebooks with the same name will be able to exchange tabs
      via drag and drop. A notebook with a %NULL group name will
      not be able to exchange tabs with any other notebook.
      Parameters:
      group_name - the name of the notebook group, or %NULL to unset it
    • setMenuLabel

      public void setMenuLabel(@Nonnull Widget child, @Nullable Widget menu_label)
      Changes the menu label for the page containing @child.
      Parameters:
      child - the child widget
      menu_label - the menu label, or %NULL for default
    • setMenuLabelText

      public void setMenuLabelText(@Nonnull Widget child, @Nonnull Str menu_text)
      Creates a new label and sets it as the menu label of @child.
      Parameters:
      child - the child widget
      menu_text - the label text
    • setMenuLabelText

      public void setMenuLabelText(@Nonnull Widget child, String menu_text)
      Creates a new label and sets it as the menu label of @child.
      Parameters:
      child - the child widget
      menu_text - the label text
    • setScrollable

      public void setScrollable(boolean scrollable)
      Sets whether the tab label area will have arrows for
      scrolling if there are too many tabs to fit in the area.
      Parameters:
      scrollable - %TRUE if scroll arrows should be added
    • setShowBorder

      public void setShowBorder(boolean show_border)
      Sets whether a bevel will be drawn around the notebook pages.

      This only has a visual effect when the tabs are not shown.
      Parameters:
      show_border - %TRUE if a bevel should be drawn around the notebook
    • setShowTabs

      public void setShowTabs(boolean show_tabs)
      Sets whether to show the tabs for the notebook or not.
      Parameters:
      show_tabs - %TRUE if the tabs should be shown
    • setTabDetachable

      public void setTabDetachable(@Nonnull Widget child, boolean detachable)
      Sets whether the tab can be detached from @notebook to another
      notebook or widget.

      Note that two notebooks must share a common group identificator
      (see [method@Gtk.Notebook.set_group_name]) to allow automatic tabs
      interchange between them.

      If you want a widget to interact with a notebook through DnD
      (i.e.: accept dragged tabs from it) it must be set as a drop
      destination and accept the target “GTK_NOTEBOOK_TAB”. The notebook
      will fill the selection with a GtkWidget** pointing to the child
      widget that corresponds to the dropped tab.

      Note that you should use [method@Gtk.Notebook.detach_tab] instead
      of [method@Gtk.Notebook.remove_page] if you want to remove the tab
      from the source notebook as part of accepting a drop. Otherwise,
      the source notebook will think that the dragged tab was removed
      from underneath the ongoing drag operation, and will initiate a
      drag cancel animation.

      ```c
      static void
      on_drag_data_received (GtkWidget *widget,
      GdkDrop *drop,
      GtkSelectionData *data,
      guint time,
      gpointer user_data)
      {
      GtkDrag *drag;
      GtkWidget *notebook;
      GtkWidget **child;

      drag = gtk_drop_get_drag (drop);
      notebook = g_object_get_data (drag, "gtk-notebook-drag-origin");
      child = (void*) gtk_selection_data_get_data (data);

      // process_widget (*child);

      gtk_notebook_detach_tab (GTK_NOTEBOOK (notebook), *child);
      }
      ```

      If you want a notebook to accept drags from other widgets,
      you will have to set your own DnD code to do it.
      Parameters:
      child - a child `GtkWidget`
      detachable - whether the tab is detachable or not
    • setTabLabel

      public void setTabLabel(@Nonnull Widget child, @Nullable Widget tab_label)
      Changes the tab label for @child.

      If %NULL is specified for @tab_label, then the page will
      have the label “page N”.
      Parameters:
      child - the page
      tab_label - the tab label widget to use, or %NULL for default tab label
    • setTabLabelText

      public void setTabLabelText(@Nonnull Widget child, @Nonnull Str tab_text)
      Creates a new label and sets it as the tab label for the page
      containing @child.
      Parameters:
      child - the page
      tab_text - the label text
    • setTabLabelText

      public void setTabLabelText(@Nonnull Widget child, String tab_text)
      Creates a new label and sets it as the tab label for the page
      containing @child.
      Parameters:
      child - the page
      tab_text - the label text
    • setTabPos

      public void setTabPos(int pos)
      Sets the edge at which the tabs are drawn.
      Parameters:
      pos - the edge to draw the tabs at
    • setTabReorderable

      public void setTabReorderable(@Nonnull Widget child, boolean reorderable)
      Sets whether the notebook tab can be reordered
      via drag and drop or not.
      Parameters:
      child - a child `GtkWidget`
      reorderable - whether the tab is reorderable or not
    • onChangeCurrentPage

      public SignalHandler onChangeCurrentPage(Notebook.OnChangeCurrentPage signal)
      Connect to signal "change-current-page".
      See Notebook.OnChangeCurrentPage.onChangeCurrentPage(int) for signal description.
      Field SIGNAL_ON_CHANGE_CURRENT_PAGE contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onCreateWindow

      public SignalHandler onCreateWindow(Notebook.OnCreateWindow signal)
      Connect to signal "create-window".
      See Notebook.OnCreateWindow.onCreateWindow(ch.bailu.gtk.gtk.Widget) for signal description.
      Field SIGNAL_ON_CREATE_WINDOW contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onFocusTab

      public SignalHandler onFocusTab(Notebook.OnFocusTab signal)
      Connect to signal "focus-tab".
      See Notebook.OnFocusTab.onFocusTab(int) for signal description.
      Field SIGNAL_ON_FOCUS_TAB contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onMoveFocusOut

      public SignalHandler onMoveFocusOut(Notebook.OnMoveFocusOut signal)
      Connect to signal "move-focus-out".
      See Notebook.OnMoveFocusOut.onMoveFocusOut(int) for signal description.
      Field SIGNAL_ON_MOVE_FOCUS_OUT contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onPageAdded

      public SignalHandler onPageAdded(Notebook.OnPageAdded signal)
      Connect to signal "page-added".
      See Notebook.OnPageAdded.onPageAdded(ch.bailu.gtk.gtk.Widget, int) for signal description.
      Field SIGNAL_ON_PAGE_ADDED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onPageRemoved

      public SignalHandler onPageRemoved(Notebook.OnPageRemoved signal)
      Connect to signal "page-removed".
      See Notebook.OnPageRemoved.onPageRemoved(ch.bailu.gtk.gtk.Widget, int) for signal description.
      Field SIGNAL_ON_PAGE_REMOVED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onPageReordered

      public SignalHandler onPageReordered(Notebook.OnPageReordered signal)
      Connect to signal "page-reordered".
      See Notebook.OnPageReordered.onPageReordered(ch.bailu.gtk.gtk.Widget, int) for signal description.
      Field SIGNAL_ON_PAGE_REORDERED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onReorderTab

      public SignalHandler onReorderTab(Notebook.OnReorderTab signal)
      Connect to signal "reorder-tab".
      See Notebook.OnReorderTab.onReorderTab(int, boolean) for signal description.
      Field SIGNAL_ON_REORDER_TAB contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onSelectPage

      public SignalHandler onSelectPage(Notebook.OnSelectPage signal)
      Connect to signal "select-page".
      See Notebook.OnSelectPage.onSelectPage(boolean) for signal description.
      Field SIGNAL_ON_SELECT_PAGE contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onSwitchPage

      public SignalHandler onSwitchPage(Notebook.OnSwitchPage signal)
      Connect to signal "switch-page".
      See Notebook.OnSwitchPage.onSwitchPage(ch.bailu.gtk.gtk.Widget, int) for signal description.
      Field SIGNAL_ON_SWITCH_PAGE contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class Widget
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class Widget
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class Widget
      Returns:
      ConstraintTarget
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()