Class PopoverMenu
- All Implemented Interfaces:
Proxy
,Accessible
,Buildable
,ConstraintTarget
,Native
,ShortcutManager
GtkPopoverMenu
is a subclass of GtkPopover
that implements menu
behavior.
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.
The property Gtk.PopoverMenu:flags
controls this appearance.
GtkPopoverMenu
is meant to be used primarily with menu models,
using fromModel(org.gnome.gio.MenuModel)
. If you need to put
other widgets such as a GtkSpinButton
or a GtkSwitch
into a popover,
you can use addChild(org.gnome.gtk.Widget, java.lang.String)
.
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.
<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
- "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
Application.setMenubar(org.gnome.gio.MenuModel)
. - "custom": a string used to match against the ID of a custom child added with
addChild(org.gnome.gtk.Widget, java.lang.String)
,PopoverMenuBar.addChild(org.gnome.gtk.Widget, java.lang.String)
, 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 Application.setAccelsForAction(java.lang.String, java.lang.String[])
,
WidgetClass#addBindingAction
or
ShortcutController.addShortcut(org.gnome.gtk.Shortcut)
.
Shortcuts and Gestures
GtkPopoverMenu
supports the following keyboard shortcuts:
Space
activates the default widget.
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 main popover
node.
Menu items have nodes with name button
and class .model
. If a section
display-hint is set, the section gets a node box
with class horizontal
plus a class with the same text as the display hint. Note that said box may
not be the direct ancestor of the item button
s. Thus, for example, to style
items in an inline-buttons
section, select .inline-buttons button.model
.
Other things that may be of interest to style in menus include label
nodes.
Accessibility
GtkPopoverMenu
uses the AccessibleRole.MENU
role, and its
items use the AccessibleRole.MENU_ITEM
,
AccessibleRole.MENU_ITEM_CHECKBOX
or
AccessibleRole.MENU_ITEM_RADIO
roles, depending on the
action they are connected to.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
PopoverMenu.Builder<B extends PopoverMenu.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.gnome.gtk.Popover
Popover.ActivateDefaultCallback, Popover.ClosedCallback, Popover.PopoverClass
Nested classes/interfaces inherited from class org.gnome.gtk.Widget
Widget.DestroyCallback, Widget.DirectionChangedCallback, Widget.HideCallback, Widget.KeynavFailedCallback, Widget.MapCallback, Widget.MnemonicActivateCallback, Widget.MoveFocusCallback, Widget.QueryTooltipCallback, Widget.RealizeCallback, Widget.ShowCallback, Widget.StateFlagsChangedCallback, Widget.UnmapCallback, Widget.UnrealizeCallback, Widget.WidgetClass, Widget.WidgetImpl
Nested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClass
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gtk.Accessible
Accessible.AccessibleImpl, Accessible.AccessibleInterface
Nested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.BuildableIface, Buildable.BuildableImpl
Nested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTargetImpl, ConstraintTarget.ConstraintTargetInterface
Nested classes/interfaces inherited from interface org.gnome.gtk.Native
Native.NativeImpl, Native.NativeInterface
Nested classes/interfaces inherited from interface org.gnome.gtk.ShortcutManager
ShortcutManager.ShortcutManagerImpl, ShortcutManager.ShortcutManagerInterface
-
Constructor Summary
ConstructorDescriptionPopoverMenu
(MemorySegment address) Create a PopoverMenu proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds a custom widget to a generated menu.protected PopoverMenu
asParent()
Returns this instance as if it were its parent type.static PopoverMenu.Builder
<? extends PopoverMenu.Builder> builder()
APopoverMenu.Builder
object constructs aPopoverMenu
with the specified properties.static PopoverMenu
Creates aGtkPopoverMenu
and populates it according tomodel
.static PopoverMenu
fromModelFull
(MenuModel model, Set<PopoverMenuFlags> flags) Creates aGtkPopoverMenu
and populates it according tomodel
.static Widget
fromModelFull
(MenuModel model, PopoverMenuFlags... flags) Creates aGtkPopoverMenu
and populates it according tomodel
.getFlags()
Returns the flags that this PopoverMenu uses to create/display a menu from its model.Returns the menu model used to populate the popover.static Type
getType()
Get the GType of the PopoverMenu classboolean
removeChild
(Widget child) Removes a widget that has previously been added withPopoverMenu#addChild()
void
setFlags
(Set<PopoverMenuFlags> flags) Sets the flags that this PopoverMenu uses to create/display a menu from its model.void
setFlags
(PopoverMenuFlags... flags) Sets the flags that this PopoverMenu uses to create/display a menu from its model.void
setMenuModel
(@Nullable MenuModel model) Sets a new menu model on this PopoverMenu.Methods inherited from class org.gnome.gtk.Popover
activateDefault, closed, emitActivateDefault, emitClosed, getAutohide, getCascadePopdown, getChild, getHasArrow, getMemoryLayout, getMnemonicsVisible, getOffset, getPointingTo, getPosition, onActivateDefault, onClosed, popdown, popup, present, setAutohide, setCascadePopdown, setChild, setDefaultWidget, setHasArrow, setMnemonicsVisible, setOffset, setPointingTo, setPosition
Methods inherited from class org.gnome.gtk.Widget
actionSetEnabled, activateActionIfExists, activateWidget, addController, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, cssChanged, directionChanged, disposeTemplate, dragCheckThreshold, emitDestroy, emitDirectionChanged, emitHide, emitKeynavFailed, emitMap, emitMnemonicActivate, emitMoveFocus, emitQueryTooltip, emitRealize, emitShow, emitStateFlagsChanged, emitUnmap, emitUnrealize, errorBell, focus, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getBaseline, getCanFocus, getCanTarget, getChildVisible, getClipboard, getColor, 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, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, moveFocus, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, pick, queryTooltip, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeMnemonicLabel, removeTickCallback, root, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setStateFlags, setTooltipMarkup, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, sizeAllocate, snapshot, snapshotChild, stateFlagsChanged, systemSettingChanged, translateCoordinates, triggerTooltipQuery, unmap, unparent, unrealize, unroot, unsetStateFlags, unsetStateFlags
Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.gnome.gtk.Accessible
announce, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updateProperty, updateRelation, updateState
Methods inherited from interface org.gnome.gtk.Buildable
getBuildableId
Methods inherited from interface org.gnome.gtk.Native
getRenderer, getSurface, getSurfaceTransform, realize, unrealize
-
Constructor Details
-
PopoverMenu
Create a PopoverMenu proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
fromModel
Creates aGtkPopoverMenu
and populates it according tomodel
.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 theGtkApplicationWindow
s widget hierarchy.Actions can also be added using
Widget.insertActionGroup(java.lang.String, org.gnome.gio.ActionGroup)
on the menus attach widget or on any of its parent widgets.This function creates menus with sliding submenus. See
fromModelFull(org.gnome.gio.MenuModel, java.util.Set<org.gnome.gtk.PopoverMenuFlags>)
for a way to control this.- Parameters:
model
- aGMenuModel
- Returns:
- the new
GtkPopoverMenu
-
fromModelFull
Creates aGtkPopoverMenu
and populates it according tomodel
.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 usingWidget.insertActionGroup(java.lang.String, org.gnome.gio.ActionGroup)
on the parent widget or on any of its parent widgets.- Parameters:
model
- aGMenuModel
flags
- flags that affect how the menu is created- Returns:
- the new
GtkPopoverMenu
-
fromModelFull
Creates aGtkPopoverMenu
and populates it according tomodel
.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 usingWidget.insertActionGroup(java.lang.String, org.gnome.gio.ActionGroup)
on the parent widget or on any of its parent widgets.- Parameters:
model
- aGMenuModel
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 this PopoverMenu must have an item with a
custom
attribute that matchesid
.- Parameters:
child
- theGtkWidget
to addid
- the ID to insertchild
at- Returns:
true
ifid
was found and the widget added
-
getFlags
Returns the flags that this PopoverMenu uses to create/display a menu from its model.- Returns:
- the
GtkPopoverMenuFlags
-
getMenuModel
Returns the menu model used to populate the popover.- Returns:
- the menu model of this PopoverMenu
-
removeChild
Removes a widget that has previously been added withPopoverMenu#addChild()
- Parameters:
child
- theGtkWidget
to remove- Returns:
true
if the widget was removed
-
setFlags
Sets the flags that this PopoverMenu uses to create/display a menu from its model.If a model is set and the flags change, contents are rebuilt, so if setting properties individually, set flags before model to avoid a redundant rebuild.
- Parameters:
flags
- a set ofGtkPopoverMenuFlags
-
setFlags
Sets the flags that this PopoverMenu uses to create/display a menu from its model.If a model is set and the flags change, contents are rebuilt, so if setting properties individually, set flags before model to avoid a redundant rebuild.
- Parameters:
flags
- a set ofGtkPopoverMenuFlags
-
setMenuModel
Sets a new menu model on this PopoverMenu.The existing contents of this PopoverMenu are removed, and the this PopoverMenu is populated with new contents according to
model
.- Parameters:
model
- aGMenuModel
-
builder
APopoverMenu.Builder
object constructs aPopoverMenu
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withPopoverMenu.Builder.build()
.
-