Package ch.bailu.gtk.gtk
Class PopoverMenu
- All Implemented Interfaces:
PointerInterface
`GtkPopoverMenu` is a subclass of `GtkPopover` that implements menu
behavior.
![An example GtkPopoverMenu](menu.png)
`GtkPopoverMenu` treats its children like menus and allows switching
between them. It can open submenus as traditional, nested submenus,
or in a more touch-friendly sliding fashion.
`GtkPopoverMenu` is meant to be used primarily with menu models,
using [ctor@Gtk.PopoverMenu.new_from_model]. If you need to put
other widgets such as a `GtkSpinButton` or a `GtkSwitch` into a popover,
you can use [method@Gtk.PopoverMenu.add_child].
For more dialog-like behavior, use a plain `GtkPopover`.
## Menu models
The XML format understood by `GtkBuilder` for `GMenuModel` consists
of a toplevel `<menu>` element, which contains one or more `<item>`
elements. Each `<item>` element contains `<attribute>` and `<link>`
elements with a mandatory name attribute. `<link>` elements have the
same content model as `<menu>`. Instead of `<link name="submenu">`
or `<link name="section">`, you can use `<submenu>` or `<section>`
elements.
```xml
<menu id='app-menu'>
<section>
<item>
<attribute name='label' translatable='yes'>_New Window</attribute>
<attribute name='action'>app.new</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_About Sunny</attribute>
<attribute name='action'>app.about</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Quit</attribute>
<attribute name='action'>app.quit</attribute>
</item>
</section>
</menu>
```
Attribute values can be translated using gettext, like other `GtkBuilder`
content. `<attribute>` elements can be marked for translation with a
`translatable="yes"` attribute. It is also possible to specify message
context and translator comments, using the context and comments attributes.
To make use of this, the `GtkBuilder` must have been given the gettext
domain to use.
The following attributes are used when constructing menu items:
- "label": a user-visible string to display
- "use-markup": whether the text in the menu item includes [Pango markup](https://docs.gtk.org/Pango/pango_markup.html)
- "action": the prefixed name of the action to trigger
- "target": the parameter to use when activating the action
- "icon" and "verb-icon": names of icons that may be displayed
- "submenu-action": name of an action that may be used to track
whether a submenu is open
- "hidden-when": a string used to determine when the item will be hidden.
Possible values include "action-disabled", "action-missing", "macos-menubar".
This is mainly useful for exported menus, see [method@Gtk.Application.set_menubar].
- "custom": a string used to match against the ID of a custom child added with
[method@Gtk.PopoverMenu.add_child], [method@Gtk.PopoverMenuBar.add_child],
or in the ui file with `<child type="ID">`.
The following attributes are used when constructing sections:
- "label": a user-visible string to use as section heading
- "display-hint": a string used to determine special formatting for the section.
Possible values include "horizontal-buttons", "circular-buttons" and
"inline-buttons". They all indicate that section should be
displayed as a horizontal row of buttons.
- "text-direction": a string used to determine the `GtkTextDirection` to use
when "display-hint" is set to "horizontal-buttons". Possible values
include "rtl", "ltr", and "none".
The following attributes are used when constructing submenus:
- "label": a user-visible string to display
- "icon": icon name to display
Menu items will also show accelerators, which are usually associated
with actions via [method@Gtk.Application.set_accels_for_action],
[id@gtk_widget_class_add_binding_action] or
[method@Gtk.ShortcutController.add_shortcut].
# CSS Nodes
`GtkPopoverMenu` is just a subclass of `GtkPopover` that adds custom content
to it, therefore it has the same CSS nodes. It is one of the cases that add
a .menu style class to the popover's main node.
# Accessibility
`GtkPopoverMenu` uses the %GTK_ACCESSIBLE_ROLE_MENU role, and its
items use the %GTK_ACCESSIBLE_ROLE_MENU_ITEM,
%GTK_ACCESSIBLE_ROLE_MENU_ITEM_CHECKBOX or
%GTK_ACCESSIBLE_ROLE_MENU_ITEM_RADIO roles, depending on the
action they are connected to.
behavior.
![An example GtkPopoverMenu](menu.png)
`GtkPopoverMenu` treats its children like menus and allows switching
between them. It can open submenus as traditional, nested submenus,
or in a more touch-friendly sliding fashion.
`GtkPopoverMenu` is meant to be used primarily with menu models,
using [ctor@Gtk.PopoverMenu.new_from_model]. If you need to put
other widgets such as a `GtkSpinButton` or a `GtkSwitch` into a popover,
you can use [method@Gtk.PopoverMenu.add_child].
For more dialog-like behavior, use a plain `GtkPopover`.
## Menu models
The XML format understood by `GtkBuilder` for `GMenuModel` consists
of a toplevel `<menu>` element, which contains one or more `<item>`
elements. Each `<item>` element contains `<attribute>` and `<link>`
elements with a mandatory name attribute. `<link>` elements have the
same content model as `<menu>`. Instead of `<link name="submenu">`
or `<link name="section">`, you can use `<submenu>` or `<section>`
elements.
```xml
<menu id='app-menu'>
<section>
<item>
<attribute name='label' translatable='yes'>_New Window</attribute>
<attribute name='action'>app.new</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_About Sunny</attribute>
<attribute name='action'>app.about</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Quit</attribute>
<attribute name='action'>app.quit</attribute>
</item>
</section>
</menu>
```
Attribute values can be translated using gettext, like other `GtkBuilder`
content. `<attribute>` elements can be marked for translation with a
`translatable="yes"` attribute. It is also possible to specify message
context and translator comments, using the context and comments attributes.
To make use of this, the `GtkBuilder` must have been given the gettext
domain to use.
The following attributes are used when constructing menu items:
- "label": a user-visible string to display
- "use-markup": whether the text in the menu item includes [Pango markup](https://docs.gtk.org/Pango/pango_markup.html)
- "action": the prefixed name of the action to trigger
- "target": the parameter to use when activating the action
- "icon" and "verb-icon": names of icons that may be displayed
- "submenu-action": name of an action that may be used to track
whether a submenu is open
- "hidden-when": a string used to determine when the item will be hidden.
Possible values include "action-disabled", "action-missing", "macos-menubar".
This is mainly useful for exported menus, see [method@Gtk.Application.set_menubar].
- "custom": a string used to match against the ID of a custom child added with
[method@Gtk.PopoverMenu.add_child], [method@Gtk.PopoverMenuBar.add_child],
or in the ui file with `<child type="ID">`.
The following attributes are used when constructing sections:
- "label": a user-visible string to use as section heading
- "display-hint": a string used to determine special formatting for the section.
Possible values include "horizontal-buttons", "circular-buttons" and
"inline-buttons". They all indicate that section should be
displayed as a horizontal row of buttons.
- "text-direction": a string used to determine the `GtkTextDirection` to use
when "display-hint" is set to "horizontal-buttons". Possible values
include "rtl", "ltr", and "none".
The following attributes are used when constructing submenus:
- "label": a user-visible string to display
- "icon": icon name to display
Menu items will also show accelerators, which are usually associated
with actions via [method@Gtk.Application.set_accels_for_action],
[id@gtk_widget_class_add_binding_action] or
[method@Gtk.ShortcutController.add_shortcut].
# CSS Nodes
`GtkPopoverMenu` is just a subclass of `GtkPopover` that adds custom content
to it, therefore it has the same CSS nodes. It is one of the cases that add
a .menu style class to the popover's main node.
# Accessibility
`GtkPopoverMenu` uses the %GTK_ACCESSIBLE_ROLE_MENU role, and its
items use the %GTK_ACCESSIBLE_ROLE_MENU_ITEM,
%GTK_ACCESSIBLE_ROLE_MENU_ITEM_CHECKBOX or
%GTK_ACCESSIBLE_ROLE_MENU_ITEM_RADIO roles, depending on the
action they are connected to.
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.bailu.gtk.gtk.Popover
Popover.OnActivateDefault, Popover.OnClosed
Nested classes/interfaces inherited from class ch.bailu.gtk.gtk.Widget
Widget.OnDestroy, Widget.OnDestroyNotify, Widget.OnDirectionChanged, Widget.OnHide, Widget.OnKeynavFailed, Widget.OnMap, Widget.OnMnemonicActivate, Widget.OnMoveFocus, Widget.OnQueryTooltip, Widget.OnRealize, Widget.OnShow, Widget.OnStateFlagsChanged, Widget.OnTickCallback, Widget.OnUnmap, Widget.OnUnrealize
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gtk.Popover
SIGNAL_ON_ACTIVATE_DEFAULT, SIGNAL_ON_CLOSED
Fields inherited from class ch.bailu.gtk.gtk.Widget
SIGNAL_ON_DESTROY, SIGNAL_ON_DIRECTION_CHANGED, SIGNAL_ON_HIDE, SIGNAL_ON_KEYNAV_FAILED, SIGNAL_ON_MAP, SIGNAL_ON_MNEMONIC_ACTIVATE, SIGNAL_ON_MOVE_FOCUS, SIGNAL_ON_QUERY_TOOLTIP, SIGNAL_ON_REALIZE, SIGNAL_ON_SHOW, SIGNAL_ON_STATE_FLAGS_CHANGED, SIGNAL_ON_UNMAP, SIGNAL_ON_UNREALIZE
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds a custom widget to a generated menu.boolean
Adds a custom widget to a generated menu.Implements interfaceAccessible
.Implements interfaceBuildable
.Implements interfaceConstraintTarget
.asNative()
Implements interfaceNative
.Implements interfaceShortcutManager
.static ClassHandler
static int
Returns the menu model used to populate the popover.static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
static PopoverMenu
newFromModelFullPopoverMenu
(MenuModel model, int flags) Creates a `GtkPopoverMenu` and populates it according to @model.static PopoverMenu
newFromModelPopoverMenu
(MenuModel model) Creates a `GtkPopoverMenu` and populates it according to @model.boolean
removeChild
(Widget child) Removes a widget that has previously been added with
gtk_popover_menu_add_child().void
setMenuModel
(MenuModel model) Sets a new menu model on @popover.Methods inherited from class ch.bailu.gtk.gtk.Popover
getAutohide, getCascadePopdown, getChild, getHasArrow, getMnemonicsVisible, getOffset, getPointingTo, getPosition, onActivateDefault, onClosed, popdown, popup, present, setAutohide, setCascadePopdown, setChild, setDefaultWidget, setHasArrow, setMnemonicsVisible, setOffset, setPointingTo, setPosition
Methods inherited from class ch.bailu.gtk.gtk.Widget
actionSetEnabled, actionSetEnabled, activate, activateAction, activateAction, activateActionVariant, activateActionVariant, activateDefault, addController, addCssClass, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, createPangoLayout, disposeTemplate, dragCheckThreshold, errorBell, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getCanFocus, getCanTarget, getChildVisible, getClipboard, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeCssClass, removeMnemonicLabel, removeTickCallback, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setTooltipMarkup, setTooltipMarkup, setTooltipText, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, snapshotChild, triggerTooltipQuery, unmap, unparent, unrealize, unsetStateFlags
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Constructor Details
-
PopoverMenu
-
-
Method Details
-
getClassHandler
-
newFromModelPopoverMenu
Creates a `GtkPopoverMenu` and populates it according to @model.
The created buttons are connected to actions found in the
`GtkApplicationWindow` to which the popover belongs - typically
by means of being attached to a widget that is contained within
the `GtkApplicationWindow`s widget hierarchy.
Actions can also be added using [method@Gtk.Widget.insert_action_group]
on the menus attach widget or on any of its parent widgets.
This function creates menus with sliding submenus.
See [ctor@Gtk.PopoverMenu.new_from_model_full] for a way
to control this.- Parameters:
model
- a `GMenuModel`- Returns:
- the new `GtkPopoverMenu`
-
newFromModelFullPopoverMenu
Creates a `GtkPopoverMenu` and populates it according to @model.
The created buttons are connected to actions found in the
action groups that are accessible from the parent widget.
This includes the `GtkApplicationWindow` to which the popover
belongs. Actions can also be added using [method@Gtk.Widget.insert_action_group]
on the parent widget or on any of its parent widgets.
The only flag that is supported currently is
%GTK_POPOVER_MENU_NESTED, which makes GTK create traditional,
nested submenus instead of the default sliding submenus.- Parameters:
model
- a `GMenuModel`flags
- flags that affect how the menu is created- Returns:
- the new `GtkPopoverMenu`
-
addChild
Adds a custom widget to a generated menu.
For this to work, the menu model of @popover must have
an item with a `custom` attribute that matches @id.- Parameters:
child
- the `GtkWidget` to addid
- the ID to insert @child at- Returns:
- %TRUE if @id was found and the widget added
-
addChild
Adds a custom widget to a generated menu.
For this to work, the menu model of @popover must have
an item with a `custom` attribute that matches @id.- Parameters:
child
- the `GtkWidget` to addid
- the ID to insert @child at- Returns:
- %TRUE if @id was found and the widget added
-
getMenuModel
Returns the menu model used to populate the popover.- Returns:
- the menu model of @popover
-
removeChild
Removes a widget that has previously been added with
gtk_popover_menu_add_child().- Parameters:
child
- the `GtkWidget` to remove- Returns:
- %TRUE if the widget was removed
-
setMenuModel
Sets a new menu model on @popover.
The existing contents of @popover are removed, and
the @popover is populated with new contents according
to @model.- Parameters:
model
- a `GMenuModel`
-
asAccessible
Implements interfaceAccessible
. Call this to get access to interface functions.- Overrides:
asAccessible
in classPopover
- Returns:
Accessible
-
asBuildable
Implements interfaceBuildable
. Call this to get access to interface functions.- Overrides:
asBuildable
in classPopover
- Returns:
Buildable
-
asConstraintTarget
Implements interfaceConstraintTarget
. Call this to get access to interface functions.- Overrides:
asConstraintTarget
in classPopover
- Returns:
ConstraintTarget
-
asNative
Implements interfaceNative
. Call this to get access to interface functions. -
asShortcutManager
Implements interfaceShortcutManager
. Call this to get access to interface functions.- Overrides:
asShortcutManager
in classPopover
- Returns:
ShortcutManager
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-