Gjsify LogoGjsify Logo

The #GtkMenuItem widget and the derived widgets are the only valid children for menus. Their function is to correctly handle highlighting, alignment, events and submenus.

As a GtkMenuItem derives from #GtkBin it can hold any valid child widget, although only a few are really useful.

By default, a GtkMenuItem sets a #GtkAccelLabel as its child. GtkMenuItem has direct functions to set the label and its mnemonic. For more advanced label settings, you can fetch the child widget from the GtkBin.

An example for setting markup and accelerator on a MenuItem:

GtkWidget *menu_item = gtk_menu_item_new_with_label ("Example Menu Item");

GtkWidget *child = gtk_bin_get_child (GTK_BIN (menu_item));
gtk_label_set_markup (GTK_LABEL (child), "<i>new label</i> with <b>markup</b>");
gtk_accel_label_set_accel (GTK_ACCEL_LABEL (child), GDK_KEY_1, 0);

GtkMenuItem as GtkBuildable

The GtkMenuItem implementation of the #GtkBuildable interface supports adding a submenu by specifying “submenu” as the “type” attribute of a <child> element.

An example of UI definition fragment with submenus:

|[



# CSS nodes

|[<!-- language="plain" -->
menuitem
├── <child>
╰── [arrow.right]

GtkMenuItem has a single CSS node with name menuitem. If the menuitem has a submenu, it gets another CSS node with name arrow, which has the .left or .right style class.

Hierarchy

Index

Constructors

Properties

Methods

Constructors

Properties

accel_path: string

Sets the accelerator path of the menu item, through which runtime changes of the menu item's accelerator caused by the user can be identified and saved to persistant storage.

action_name: string
action_target: GLib.Variant
app_paintable: boolean
bin: Gtk.Bin
border_width: number
can_default: boolean
can_focus: boolean
child: Gtk.Widget
composite_child: boolean
container: Gtk.Container
double_buffered: boolean

Whether the widget is double buffered.

events: Gdk.EventMask
expand: boolean

Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand

focus_on_click: boolean

Whether the widget should grab focus when it is clicked with the mouse.

This property is only relevant for widgets that can take focus.

Before 3.20, several widgets (GtkButton, GtkFileChooserButton, GtkComboBox) implemented this property individually.

g_type_instance: TypeInstance
halign: Gtk.Align

How to distribute horizontal space if widget gets extra space, see #GtkAlign

has_default: boolean
has_focus: boolean
has_tooltip: boolean

Enables or disables the emission of #GtkWidget::query-tooltip on widget. A value of %TRUE indicates that widget can have a tooltip, in this case the widget will be queried using #GtkWidget::query-tooltip to determine whether it will provide a tooltip or not.

Note that setting this property to %TRUE for the first time will change the event masks of the GdkWindows of this widget to include leave-notify and motion-notify events. This cannot and will not be undone when the property is set to %FALSE again.

height_request: number
hexpand: boolean

Whether to expand horizontally. See gtk_widget_set_hexpand().

hexpand_set: boolean

Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().

is_focus: boolean
label: string

The text for the child label.

margin: number

Sets all four sides' margin at once. If read, returns max margin on any side.

margin_bottom: number

Margin on bottom side of widget.

This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from gtk_widget_set_size_request() for example.

margin_end: number

Margin on end of widget, horizontally. This property supports left-to-right and right-to-left text directions.

This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from gtk_widget_set_size_request() for example.

margin_left: number

Margin on left side of widget.

This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from gtk_widget_set_size_request() for example.

margin_right: number

Margin on right side of widget.

This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from gtk_widget_set_size_request() for example.

margin_start: number

Margin on start of widget, horizontally. This property supports left-to-right and right-to-left text directions.

This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from gtk_widget_set_size_request() for example.

margin_top: number

Margin on top side of widget.

This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from gtk_widget_set_size_request() for example.

name: string
no_show_all: boolean
opacity: number

The requested opacity of the widget. See gtk_widget_set_opacity() for more details about window opacity.

Before 3.8 this was only available in GtkWindow

parent: Gtk.Container
parent_instance: InitiallyUnowned
receives_default: boolean
related_action: Gtk.Action

The action that this activatable will activate and receive updates from for various states and possibly appearance.

#GtkActivatable implementors need to handle the this property and call gtk_activatable_do_set_related_action() when it changes.

resize_mode: Gtk.ResizeMode
right_justified: boolean

Sets whether the menu item appears justified at the right side of a menu bar.

scale_factor: number

The scale factor of the widget. See gtk_widget_get_scale_factor() for more details about widget scaling.

sensitive: boolean
style: Gtk.Style

The style of the widget, which contains information about how it will look (colors, etc).

submenu: Gtk.Menu

The submenu attached to the menu item, or %NULL if it has none.

tooltip_markup: string

Sets the text of tooltip to be the given string, which is marked up with the [Pango text markup language][PangoMarkupFormat]. Also see gtk_tooltip_set_markup().

This is a convenience property which will take care of getting the tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip will automatically be set to %TRUE and there will be taken care of #GtkWidget::query-tooltip in the default signal handler.

Note that if both #GtkWidget:tooltip-text and #GtkWidget:tooltip-markup are set, the last one wins.

tooltip_text: string

Sets the text of tooltip to be the given string.

Also see gtk_tooltip_set_text().

This is a convenience property which will take care of getting the tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip will automatically be set to %TRUE and there will be taken care of #GtkWidget::query-tooltip in the default signal handler.

Note that if both #GtkWidget:tooltip-text and #GtkWidget:tooltip-markup are set, the last one wins.

use_action_appearance: boolean

Whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance.

See the #GtkAction documentation directly to find which properties should be ignored by the #GtkActivatable when this property is %FALSE.

#GtkActivatable implementors need to handle this property and call gtk_activatable_sync_action_properties() on the activatable widget when it changes.

use_underline: boolean

%TRUE if underlines in the text indicate mnemonics.

valign: Gtk.Align

How to distribute vertical space if widget gets extra space, see #GtkAlign

vexpand: boolean

Whether to expand vertically. See gtk_widget_set_vexpand().

vexpand_set: boolean

Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().

visible: boolean
widget: Gtk.Widget
width_request: number
window: Gdk.Window

The widget's window if it is realized, %NULL otherwise.

$gtype: GType<Gtk.MenuItem>
name: string

Methods

  • activate(): void
  • activate(): boolean
  • activate(...args: any[]): any
  • activate(...args: any[]): any
  • Emits the #GtkMenuItem::activate signal on the given item

    Returns void

  • For widgets that can be “activated” (buttons, menu items, etc.) this function activates them. Activation is what happens when you press Enter on a widget during key navigation. If widget isn't activatable, the function returns %FALSE.

    Returns boolean

  • Parameters

    • Rest ...args: any[]

    Returns any

  • Parameters

    • Rest ...args: any[]

    Returns any

  • Adds widget to container. Typically used for simple containers such as #GtkWindow, #GtkFrame, or #GtkButton; for more complicated layout containers such as #GtkBox or #GtkGrid, this function will pick default packing parameters that may not be correct. So consider functions such as gtk_box_pack_start() and gtk_grid_attach() as an alternative to gtk_container_add() in those cases. A widget may be added to only one container at a time; you can’t place the same widget inside two different containers.

    Note that some containers, such as #GtkScrolledWindow or #GtkListBox, may add intermediate children between the added widget and the container.

    Parameters

    • widget: Gtk.Widget

      a widget to be placed inside container

    Returns void

  • Installs an accelerator for this widget in accel_group that causes accel_signal to be emitted if the accelerator is activated. The accel_group needs to be added to the widget’s toplevel via gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION. Accelerators added through this function are not user changeable during runtime. If you want to support accelerators that can be changed by the user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or gtk_menu_item_set_accel_path() instead.

    Parameters

    • accel_signal: string

      widget signal to emit on accelerator activation

    • accel_group: Gtk.AccelGroup

      accel group for this widget, added to its toplevel

    • accel_key: number

      GDK keyval of the accelerator

    • accel_mods: Gdk.ModifierType

      modifier key combination of the accelerator

    • accel_flags: Gtk.AccelFlags

      flag accelerators, e.g. %GTK_ACCEL_VISIBLE

    Returns void

  • add_events(events: number): void
  • Adds the events in the bitfield events to the event mask for widget. See gtk_widget_set_events() and the [input handling overview][event-masks] for details.

    Parameters

    • events: number

      an event mask, see #GdkEventMask

    Returns void

  • Adds a widget to the list of mnemonic labels for this widget. (See gtk_widget_list_mnemonic_labels()). Note the list of mnemonic labels for the widget is cleared when the widget is destroyed, so the caller must make sure to update its internal state at this point as well, by using a connection to the #GtkWidget::destroy signal or a weak notifier.

    Parameters

    • label: Gtk.Widget

      a #GtkWidget that acts as a mnemonic label for widget

    Returns void

  • Queues an animation frame update and adds a callback to be called before each frame. Until the tick callback is removed, it will be called frequently (usually at the frame rate of the output device or as quickly as the application can be repainted, whichever is slower). For this reason, is most suitable for handling graphics that change every frame or every few frames. The tick callback does not automatically imply a relayout or repaint. If you want a repaint or relayout, and aren’t changing widget properties that would trigger that (for example, changing the text of a #GtkLabel), then you will have to call gtk_widget_queue_resize() or gtk_widget_queue_draw_area() yourself.

    gdk_frame_clock_get_frame_time() should generally be used for timing continuous animations and gdk_frame_timings_get_predicted_presentation_time() if you are trying to display isolated frames at particular times.

    This is a more convenient alternative to connecting directly to the #GdkFrameClock::update signal of #GdkFrameClock, since you don't have to worry about when a #GdkFrameClock is assigned to a widget.

    Parameters

    Returns number

  • Creates a binding between source_property on source and target_property on target.

    Whenever the source_property is changed the target_property is updated using the same value. For instance:

      g_object_bind_property (action, "active", widget, "sensitive", 0);
    

    Will result in the "sensitive" property of the widget #GObject instance to be updated with the same value of the "active" property of the action #GObject instance.

    If flags contains %G_BINDING_BIDIRECTIONAL then the binding will be mutual: if target_property on target changes then the source_property on source will be updated as well.

    The binding will automatically be removed when either the source or the target instances are finalized. To remove the binding without affecting the source and the target you can just call g_object_unref() on the returned #GBinding instance.

    Removing the binding by calling g_object_unref() on it must only be done if the binding, source and target are only used from a single thread and it is clear that both source and target outlive the binding. Especially it is not safe to rely on this if the binding, source or target can be finalized from different threads. Keep another reference to the binding and use g_binding_unbind() instead to be on the safe side.

    A #GObject can have multiple bindings.

    Parameters

    • source_property: string

      the property on source to bind

    • target: GObject.Object

      the target #GObject

    • target_property: string

      the property on target to bind

    • flags: BindingFlags

      flags to pass to #GBinding

    Returns Binding

  • Creates a binding between source_property on source and target_property on target, allowing you to set the transformation functions to be used by the binding.

    This function is the language bindings friendly version of g_object_bind_property_full(), using #GClosures instead of function pointers.

    Parameters

    • source_property: string

      the property on source to bind

    • target: GObject.Object

      the target #GObject

    • target_property: string

      the property on target to bind

    • flags: BindingFlags

      flags to pass to #GBinding

    • transform_to: TClosure<any, any>

      a #GClosure wrapping the transformation function from the source to the target, or %NULL to use the default

    • transform_from: TClosure<any, any>

      a #GClosure wrapping the transformation function from the target to the source, or %NULL to use the default

    Returns Binding

  • can_activate_accel(signal_id: number): boolean
  • Determines whether an accelerator that activates the signal identified by signal_id can currently be activated. This is done by emitting the #GtkWidget::can-activate-accel signal on widget; if the signal isn’t overridden by a handler or in a derived widget, then the default check is that the widget must be sensitive, and the widget and all its ancestors mapped.

    Parameters

    • signal_id: number

      the ID of a signal installed on widget

    Returns boolean

  • check_resize(): void
  • This function is used by custom widget implementations; if you're writing an app, you’d use gtk_widget_grab_focus() to move the focus to a particular widget, and gtk_container_set_focus_chain() to change the focus tab order. So you may want to investigate those functions instead.

    gtk_widget_child_focus() is called by containers as the user moves around the window using keyboard shortcuts. direction indicates what kind of motion is taking place (up, down, left, right, tab forward, tab backward). gtk_widget_child_focus() emits the #GtkWidget::focus signal; widgets override the default handler for this signal in order to implement appropriate focus behavior.

    The default ::focus handler for a widget should return %TRUE if moving in direction left the focus on a focusable location inside that widget, and %FALSE if moving in direction moved the focus outside the widget. If returning %TRUE, widgets normally call gtk_widget_grab_focus() to place the focus accordingly; if returning %FALSE, they don’t modify the current focus location.

    Parameters

    Returns boolean

  • child_get_property(child: Gtk.Widget, property_name: string, value: any): void
  • Gets the value of a child property for child and container.

    Parameters

    • child: Gtk.Widget

      a widget which is a child of container

    • property_name: string

      the name of the property to get

    • value: any

      a location to return the value

    Returns void

  • child_notify(...args: any[]): any
  • Emits a #GtkWidget::child-notify signal for the [child property][child-properties] child_property on widget.

    This is the analogue of g_object_notify() for child properties.

    Also see gtk_container_child_notify().

    Parameters

    • Rest ...args: any[]

    Returns any

  • Emits a #GtkWidget::child-notify signal for the [child property][child-properties] specified by pspec on the child.

    This is an analogue of g_object_notify_by_pspec() for child properties.

    Parameters

    • child: Gtk.Widget

      the child widget

    • pspec: ParamSpec

      the #GParamSpec of a child property instealled on the class of container

    Returns void

  • child_set_property(child: Gtk.Widget, property_name: string, value: any): void
  • Sets a child property for child and container.

    Parameters

    • child: Gtk.Widget

      a widget which is a child of container

    • property_name: string

      the name of the property to set

    • value: any

      the value to set the property to

    Returns void

  • child_type(): GType<unknown>
  • Returns the type of the children supported by the container.

    Note that this may return %G_TYPE_NONE to indicate that no more children can be added, e.g. for a #GtkPaned which already has two children.

    Returns GType<unknown>

  • class_path(): [number, string, string]
  • Same as gtk_widget_path(), but always uses the name of a widget’s type, never uses a custom name set with gtk_widget_set_name().

    Returns [number, string, string]

  • Computes whether a container should give this widget extra space when possible. Containers should check this, rather than looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().

    This function already checks whether the widget is visible, so visibility does not need to be checked separately. Non-visible widgets are not expanded.

    The computed expand value uses either the expand setting explicitly set on the widget itself, or, if none has been explicitly set, the widget may expand if some of its children do.

    Parameters

    Returns boolean

  • connect_after(sigName: "activate", callback: Gtk.MenuItem_ActivateSignalCallback): number
  • connect_after(sigName: "activate-item", callback: Gtk.MenuItem_ActivateItemSignalCallback): number
  • connect_after(sigName: "deselect", callback: MenuItem_DeselectSignalCallback): number
  • connect_after(sigName: "select", callback: MenuItem_SelectSignalCallback): number
  • connect_after(sigName: "toggle-size-allocate", callback: Gtk.MenuItem_ToggleSizeAllocateSignalCallback): number
  • connect_after(sigName: "toggle-size-request", callback: Gtk.MenuItem_ToggleSizeRequestSignalCallback): number
  • connect_after(sigName: "notify::accel-path", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::label", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::right-justified", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::submenu", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::use-underline", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::border-width", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::child", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::resize-mode", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::app-paintable", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::can-default", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::can-focus", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::composite-child", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::double-buffered", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::events", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::expand", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::focus-on-click", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::halign", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::has-default", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::has-focus", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::has-tooltip", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::height-request", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::hexpand", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::hexpand-set", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::is-focus", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::margin", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::margin-bottom", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::margin-end", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::margin-left", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::margin-right", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::margin-start", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::margin-top", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::name", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::no-show-all", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::opacity", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::parent", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::receives-default", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::scale-factor", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::sensitive", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::style", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::tooltip-markup", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::tooltip-text", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::valign", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::vexpand", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::vexpand-set", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::visible", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::width-request", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::window", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::action-name", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::action-target", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::related-action", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: "notify::use-action-appearance", callback: (($obj: Gtk.MenuItem, pspec: ParamSpec) => void)): number
  • connect_after(sigName: string, callback: ((...args: any[]) => void)): number
  • Constructs a child of buildable with the name name.

    #GtkBuilder calls this function if a “constructor” has been specified in the UI definition.

    Parameters

    • builder: Gtk.Builder

      #GtkBuilder used to construct this object

    • name: string

      name of child to construct

    Returns GObject.Object

  • Creates a new #PangoLayout with the appropriate font map, font description, and base direction for drawing text for this widget.

    If you keep a #PangoLayout created in this way around, you need to re-create it when the widget #PangoContext is replaced. This can be tracked by using the #GtkWidget::screen-changed signal on the widget.

    Parameters

    • text: string

      text to set on the layout (can be %NULL)

    Returns Pango.Layout

  • This is similar to gtk_buildable_parser_finished() but is called once for each custom tag handled by the buildable.

    Parameters

    • builder: Gtk.Builder

      a #GtkBuilder

    • child: GObject.Object

      child object or %NULL for non-child tags

    • tagname: string

      the name of the tag

    • data: object

      user data created in custom_tag_start

    Returns void

  • This is called at the end of each custom element handled by the buildable.

    Parameters

    • builder: Gtk.Builder

      #GtkBuilder used to construct this object

    • child: GObject.Object

      child object or %NULL for non-child tags

    • tagname: string

      name of tag

    • data: object

      user data that will be passed in to parser functions

    Returns void

  • deselect(): void
  • destroy(): void
  • Destroys a widget.

    When a widget is destroyed all references it holds on other objects will be released:

    • if the widget is inside a container, it will be removed from its parent
    • if the widget is a container, all its children will be destroyed, recursively
    • if the widget is a top level, it will be removed from the list of top level widgets that GTK+ maintains internally

    It's expected that all references held on the widget will also be released; you should connect to the #GtkWidget::destroy signal if you hold a reference to widget and you wish to remove it when this function is called. It is not necessary to do so if you are implementing a #GtkContainer, as you'll be able to use the #GtkContainerClass.remove() virtual function for that.

    It's important to notice that gtk_widget_destroy() will only cause the widget to be finalized if no additional references, acquired using g_object_ref(), are held on it. In case additional references are in place, the widget will be in an "inert" state after calling this function; widget will still point to valid memory, allowing you to release the references you hold, but you may not query the widget's own state.

    You should typically call this function on top level widgets, and rarely on child widgets.

    See also: gtk_container_remove()

    Returns void

  • This function sets *widget_pointer to %NULL if widget_pointer != %NULL. It’s intended to be used as a callback connected to the “destroy” signal of a widget. You connect gtk_widget_destroyed() as a signal handler, and pass the address of your widget variable as user data. Then when the widget is destroyed, the variable will be set to %NULL. Useful for example to avoid multiple copies of the same dialog.

    Parameters

    • widget_pointer: Gtk.Widget

      address of a variable that contains widget

    Returns Gtk.Widget

  • device_is_shadowed(device: Gdk.Device): boolean
  • Returns %TRUE if device has been shadowed by a GTK+ device grab on another widget, so it would stop sending events to widget. This may be used in the #GtkWidget::grab-notify signal to check for specific devices. See gtk_device_grab_add().

    Parameters

    Returns boolean

  • disconnect(id: number): void
  • do_set_related_action(action: Gtk.Action): void
  • This is a utility function for #GtkActivatable implementors.

    When implementing #GtkActivatable you must call this when handling changes of the #GtkActivatable:related-action, and you must also use this to break references in #GObject->dispose().

    This function adds a reference to the currently set related action for you, it also makes sure the #GtkActivatable->update() method is called when the related #GtkAction properties change and registers to the action’s proxy list.

    Be careful to call this before setting the local copy of the #GtkAction property, since this function uses gtk_activatable_get_related_action() to retrieve the previous action.

    Parameters

    Returns void

  • This function is equivalent to gtk_drag_begin_with_coordinates(), passing -1, -1 as coordinates.

    Parameters

    • targets: Gtk.TargetList

      The targets (data formats) in which the source can provide the data

    • actions: Gdk.DragAction

      A bitmask of the allowed drag actions for this drag

    • button: number

      The button the user clicked to start the drag

    • event: Gdk.Event

      The event that triggered the start of the drag, or %NULL if none can be obtained.

    Returns Gdk.DragContext

  • Initiates a drag on the source side. The function only needs to be used when the application is starting drags itself, and is not needed when gtk_drag_source_set() is used.

    The event is used to retrieve the timestamp that will be used internally to grab the pointer. If event is %NULL, then %GDK_CURRENT_TIME will be used. However, you should try to pass a real event in all cases, since that can be used to get information about the drag.

    Generally there are three cases when you want to start a drag by hand by calling this function:

    1. During a #GtkWidget::button-press-event handler, if you want to start a drag immediately when the user presses the mouse button. Pass the event that you have in your #GtkWidget::button-press-event handler.

    2. During a #GtkWidget::motion-notify-event handler, if you want to start a drag when the mouse moves past a certain threshold distance after a button-press. Pass the event that you have in your #GtkWidget::motion-notify-event handler.

    3. During a timeout handler, if you want to start a drag after the mouse button is held down for some time. Try to save the last event that you got from the mouse, using gdk_event_copy(), and pass it to this function (remember to free the event with gdk_event_free() when you are done). If you really cannot pass a real event, pass %NULL instead.

    Parameters

    • targets: Gtk.TargetList

      The targets (data formats) in which the source can provide the data

    • actions: Gdk.DragAction

      A bitmask of the allowed drag actions for this drag

    • button: number

      The button the user clicked to start the drag

    • event: Gdk.Event

      The event that triggered the start of the drag, or %NULL if none can be obtained.

    • x: number

      The initial x coordinate to start dragging from, in the coordinate space of widget. If -1 is passed, the coordinates are retrieved from event or the current pointer position

    • y: number

      The initial y coordinate to start dragging from, in the coordinate space of widget. If -1 is passed, the coordinates are retrieved from event or the current pointer position

    Returns Gdk.DragContext

  • drag_check_threshold(start_x: number, start_y: number, current_x: number, current_y: number): boolean
  • Checks to see if a mouse drag starting at (start_x, start_y) and ending at (current_x, current_y) has passed the GTK+ drag threshold, and thus should trigger the beginning of a drag-and-drop operation.

    Parameters

    • start_x: number

      X coordinate of start of drag

    • start_y: number

      Y coordinate of start of drag

    • current_x: number

      current X coordinate

    • current_y: number

      current Y coordinate

    Returns boolean

  • drag_dest_add_image_targets(): void
  • Add the image targets supported by #GtkSelectionData to the target list of the drag destination. The targets are added with info = 0. If you need another value, use gtk_target_list_add_image_targets() and gtk_drag_dest_set_target_list().

    Returns void

  • drag_dest_add_text_targets(): void
  • Add the text targets supported by #GtkSelectionData to the target list of the drag destination. The targets are added with info = 0. If you need another value, use gtk_target_list_add_text_targets() and gtk_drag_dest_set_target_list().

    Returns void

  • drag_dest_add_uri_targets(): void
  • Add the URI targets supported by #GtkSelectionData to the target list of the drag destination. The targets are added with info = 0. If you need another value, use gtk_target_list_add_uri_targets() and gtk_drag_dest_set_target_list().

    Returns void

  • Looks for a match between the supported targets of context and the dest_target_list, returning the first matching target, otherwise returning %GDK_NONE. dest_target_list should usually be the return value from gtk_drag_dest_get_target_list(), but some widgets may have different valid targets for different parts of the widget; in that case, they will have to implement a drag_motion handler that passes the correct target list to this function.

    Parameters

    • context: Gdk.DragContext

      drag context

    • target_list: Gtk.TargetList

      list of droppable targets, or %NULL to use gtk_drag_dest_get_target_list (widget).

    Returns Gdk.Atom

  • drag_dest_get_track_motion(): boolean
  • Sets a widget as a potential drop destination, and adds default behaviors.

    The default behaviors listed in flags have an effect similar to installing default handlers for the widget’s drag-and-drop signals (#GtkWidget::drag-motion, #GtkWidget::drag-drop, ...). They all exist for convenience. When passing #GTK_DEST_DEFAULT_ALL for instance it is sufficient to connect to the widget’s #GtkWidget::drag-data-received signal to get primitive, but consistent drag-and-drop support.

    Things become more complicated when you try to preview the dragged data, as described in the documentation for #GtkWidget::drag-motion. The default behaviors described by flags make some assumptions, that can conflict with your own signal handlers. For instance #GTK_DEST_DEFAULT_DROP causes invokations of gdk_drag_status() in the context of #GtkWidget::drag-motion, and invokations of gtk_drag_finish() in #GtkWidget::drag-data-received. Especially the later is dramatic, when your own #GtkWidget::drag-motion handler calls gtk_drag_get_data() to inspect the dragged data.

    There’s no way to set a default action here, you can use the #GtkWidget::drag-motion callback for that. Here’s an example which selects the action to use depending on whether the control key is pressed or not:

    static void
    drag_motion (GtkWidget *widget,
    GdkDragContext *context,
    gint x,
    gint y,
    guint time)
    {
    GdkModifierType mask;

    gdk_window_get_pointer (gtk_widget_get_window (widget),
    NULL, NULL, &mask);
    if (mask & GDK_CONTROL_MASK)
    gdk_drag_status (context, GDK_ACTION_COPY, time);
    else
    gdk_drag_status (context, GDK_ACTION_MOVE, time);
    }

    Parameters

    • flags: Gtk.DestDefaults

      which types of default drag behavior to use

    • targets: Gtk.TargetEntry[]

      a pointer to an array of #GtkTargetEntrys indicating the drop types that this widget will accept, or %NULL. Later you can access the list with gtk_drag_dest_get_target_list() and gtk_drag_dest_find_target().

    • actions: Gdk.DragAction

      a bitmask of possible actions for a drop onto this widget.

    Returns void

  • Sets this widget as a proxy for drops to another window.

    Parameters

    • proxy_window: Gdk.Window

      the window to which to forward drag events

    • protocol: Gdk.DragProtocol

      the drag protocol which the proxy_window accepts (You can use gdk_drag_get_protocol() to determine this)

    • use_coordinates: boolean

      If %TRUE, send the same coordinates to the destination, because it is an embedded subwindow.

    Returns void

  • drag_dest_set_track_motion(track_motion: boolean): void
  • Tells the widget to emit #GtkWidget::drag-motion and #GtkWidget::drag-leave events regardless of the targets and the %GTK_DEST_DEFAULT_MOTION flag.

    This may be used when a widget wants to do generic actions regardless of the targets that the source offers.

    Parameters

    • track_motion: boolean

      whether to accept all targets

    Returns void

  • drag_dest_unset(): void
  • Gets the data associated with a drag. When the data is received or the retrieval fails, GTK+ will emit a #GtkWidget::drag-data-received signal. Failure of the retrieval is indicated by the length field of the selection_data signal parameter being negative. However, when gtk_drag_get_data() is called implicitely because the %GTK_DEST_DEFAULT_DROP was set, then the widget will not receive notification of failed drops.

    Parameters

    • context: Gdk.DragContext

      the drag context

    • target: Gdk.Atom

      the target (form of the data) to retrieve

    • time_: number

      a timestamp for retrieving the data. This will generally be the time received in a #GtkWidget::drag-motion or #GtkWidget::drag-drop signal

    Returns void

  • drag_highlight(): void
  • Highlights a widget as a currently hovered drop target. To end the highlight, call gtk_drag_unhighlight(). GTK+ calls this automatically if %GTK_DEST_DEFAULT_HIGHLIGHT is set.

    Returns void

  • drag_source_add_image_targets(): void
  • Add the writable image targets supported by #GtkSelectionData to the target list of the drag source. The targets are added with info = 0. If you need another value, use gtk_target_list_add_image_targets() and gtk_drag_source_set_target_list().

    Returns void

  • drag_source_add_text_targets(): void
  • Add the text targets supported by #GtkSelectionData to the target list of the drag source. The targets are added with info = 0. If you need another value, use gtk_target_list_add_text_targets() and gtk_drag_source_set_target_list().

    Returns void

  • drag_source_add_uri_targets(): void
  • Add the URI targets supported by #GtkSelectionData to the target list of the drag source. The targets are added with info = 0. If you need another value, use gtk_target_list_add_uri_targets() and gtk_drag_source_set_target_list().

    Returns void

  • Sets up a widget so that GTK+ will start a drag operation when the user clicks and drags on the widget. The widget must have a window.

    Parameters

    • start_button_mask: Gdk.ModifierType

      the bitmask of buttons that can start the drag

    • targets: Gtk.TargetEntry[]

      the table of targets that the drag will support, may be %NULL

    • actions: Gdk.DragAction

      the bitmask of possible actions for a drag from this widget

    Returns void

  • drag_source_set_icon_gicon(icon: Gio.Icon): void
  • drag_source_set_icon_name(icon_name: string): void
  • drag_source_set_icon_pixbuf(pixbuf: Pixbuf): void
  • Sets the icon that will be used for drags from a particular widget from a #GdkPixbuf. GTK+ retains a reference for pixbuf and will release it when it is no longer needed.

    Parameters

    • pixbuf: Pixbuf

      the #GdkPixbuf for the drag icon

    Returns void

  • drag_source_set_icon_stock(stock_id: string): void
  • drag_source_unset(): void
  • drag_unhighlight(): void
  • Draws widget to cr. The top left corner of the widget will be drawn to the currently set origin point of cr.

    You should pass a cairo context as cr argument that is in an original state. Otherwise the resulting drawing is undefined. For example changing the operator using cairo_set_operator() or the line width using cairo_set_line_width() might have unwanted side effects. You may however change the context’s transform matrix - like with cairo_scale(), cairo_translate() or cairo_set_matrix() and clip region with cairo_clip() prior to calling this function. Also, it is fine to modify the context with cairo_save() and cairo_push_group() prior to calling this function.

    Note that special-purpose widgets may contain special code for rendering to the screen and might appear differently on screen and when rendered using gtk_widget_draw().

    Parameters

    Returns void

  • emit(sigName: "activate", ...args: any[]): void
  • emit(sigName: "activate-item", ...args: any[]): void
  • emit(sigName: "deselect", ...args: any[]): void
  • emit(sigName: "select", ...args: any[]): void
  • emit(sigName: "toggle-size-allocate", object: number, ...args: any[]): void
  • emit(sigName: "toggle-size-request", object: object, ...args: any[]): void
  • emit(sigName: "notify::accel-path", ...args: any[]): void
  • emit(sigName: "notify::label", ...args: any[]): void
  • emit(sigName: "notify::right-justified", ...args: any[]): void
  • emit(sigName: "notify::submenu", ...args: any[]): void
  • emit(sigName: "notify::use-underline", ...args: any[]): void
  • emit(sigName: "notify::border-width", ...args: any[]): void
  • emit(sigName: "notify::child", ...args: any[]): void
  • emit(sigName: "notify::resize-mode", ...args: any[]): void
  • emit(sigName: "notify::app-paintable", ...args: any[]): void
  • emit(sigName: "notify::can-default", ...args: any[]): void
  • emit(sigName: "notify::can-focus", ...args: any[]): void
  • emit(sigName: "notify::composite-child", ...args: any[]): void
  • emit(sigName: "notify::double-buffered", ...args: any[]): void
  • emit(sigName: "notify::events", ...args: any[]): void
  • emit(sigName: "notify::expand", ...args: any[]): void
  • emit(sigName: "notify::focus-on-click", ...args: any[]): void
  • emit(sigName: "notify::halign", ...args: any[]): void
  • emit(sigName: "notify::has-default", ...args: any[]): void
  • emit(sigName: "notify::has-focus", ...args: any[]): void
  • emit(sigName: "notify::has-tooltip", ...args: any[]): void
  • emit(sigName: "notify::height-request", ...args: any[]): void
  • emit(sigName: "notify::hexpand", ...args: any[]): void
  • emit(sigName: "notify::hexpand-set", ...args: any[]): void
  • emit(sigName: "notify::is-focus", ...args: any[]): void
  • emit(sigName: "notify::margin", ...args: any[]): void
  • emit(sigName: "notify::margin-bottom", ...args: any[]): void
  • emit(sigName: "notify::margin-end", ...args: any[]): void
  • emit(sigName: "notify::margin-left", ...args: any[]): void
  • emit(sigName: "notify::margin-right", ...args: any[]): void
  • emit(sigName: "notify::margin-start", ...args: any[]): void
  • emit(sigName: "notify::margin-top", ...args: any[]): void
  • emit(sigName: "notify::name", ...args: any[]): void
  • emit(sigName: "notify::no-show-all", ...args: any[]): void
  • emit(sigName: "notify::opacity", ...args: any[]): void
  • emit(sigName: "notify::parent", ...args: any[]): void
  • emit(sigName: "notify::receives-default", ...args: any[]): void
  • emit(sigName: "notify::scale-factor", ...args: any[]): void
  • emit(sigName: "notify::sensitive", ...args: any[]): void
  • emit(sigName: "notify::style", ...args: any[]): void
  • emit(sigName: "notify::tooltip-markup", ...args: any[]): void
  • emit(sigName: "notify::tooltip-text", ...args: any[]): void
  • emit(sigName: "notify::valign", ...args: any[]): void
  • emit(sigName: "notify::vexpand", ...args: any[]): void
  • emit(sigName: "notify::vexpand-set", ...args: any[]): void
  • emit(sigName: "notify::visible", ...args: any[]): void
  • emit(sigName: "notify::width-request", ...args: any[]): void
  • emit(sigName: "notify::window", ...args: any[]): void
  • emit(sigName: "notify::action-name", ...args: any[]): void
  • emit(sigName: "notify::action-target", ...args: any[]): void
  • emit(sigName: "notify::related-action", ...args: any[]): void
  • emit(sigName: "notify::use-action-appearance", ...args: any[]): void
  • emit(sigName: string, ...args: any[]): void
  • ensure_style(): void
  • Ensures that widget has a style (widget->style).

    Not a very useful function; most of the time, if you want the style, the widget is realized, and realized widgets are guaranteed to have a style already.

    Returns void

  • error_bell(): void
  • Notifies the user about an input-related error on this widget. If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls gdk_window_beep(), otherwise it does nothing.

    Note that the effect of gdk_window_beep() can be configured in many ways, depending on the windowing backend and the desktop environment or window manager that is used.

    Returns void

  • Rarely-used function. This function is used to emit the event signals on a widget (those signals should never be emitted without using this function to do so). If you want to synthesize an event though, don’t use this function; instead, use gtk_main_do_event() so the event will behave as if it were in the event queue. Don’t synthesize expose events; instead, use gdk_window_invalidate_rect() to invalidate a region of the window.

    Parameters

    Returns boolean

  • Invokes callback on each direct child of container, including children that are considered “internal” (implementation details of the container). “Internal” children generally weren’t added by the user of the container, but were added by the container implementation itself.

    Most applications should use gtk_container_foreach(), rather than gtk_container_forall().

    Parameters

    Returns void

  • force_floating(): void
  • This function is intended for #GObject implementations to re-enforce a [floating][floating-ref] object reference. Doing this is seldom required: all #GInitiallyUnowneds are created with a floating reference which usually just needs to be sunken by calling g_object_ref_sink().

    Returns void

  • Invokes callback on each non-internal child of container. See gtk_container_forall() for details on what constitutes an “internal” child. For all practical purposes, this function should iterate over precisely those child widgets that were added to the container by the application with explicit add() calls.

    It is permissible to remove the child from the callback handler.

    Most applications should use gtk_container_foreach(), rather than gtk_container_forall().

    Parameters

    Returns void

  • freeze_child_notify(): void
  • Stops emission of #GtkWidget::child-notify signals on widget. The signals are queued until gtk_widget_thaw_child_notify() is called on widget.

    This is the analogue of g_object_freeze_notify() for child properties.

    Returns void

  • freeze_notify(): void
  • Increases the freeze count on object. If the freeze count is non-zero, the emission of "notify" signals on object is stopped. The signals are queued until the freeze count is decreased to zero. Duplicate notifications are squashed so that at most one #GObject::notify signal is emitted for each property modified while the object is frozen.

    This is necessary for accessors that modify multiple properties to prevent premature notification while the object is still being modified.

    Returns void

  • get_accel_path(): string
  • Retrieve the accelerator path that was previously set on menu_item.

    See gtk_menu_item_set_accel_path() for details.

    Returns string

  • Returns the accessible object that describes the widget to an assistive technology.

    If accessibility support is not available, this #AtkObject instance may be a no-op. Likewise, if no class-specific #AtkObject implementation is available for the widget instance in question, it will inherit an #AtkObject implementation from the first ancestor class for which such an implementation is defined.

    The documentation of the ATK library contains more information about accessible objects and their uses.

    Returns Atk.Object

  • Retrieves the #GActionGroup that was registered using prefix. The resulting #GActionGroup may have been registered to widget or any #GtkWidget in its ancestry.

    If no action group was found matching prefix, then %NULL is returned.

    Parameters

    • prefix: string

      The “prefix” of the action group.

    Returns Gio.ActionGroup

  • get_action_name(): string
  • get_allocated_baseline(): number
  • Returns the baseline that has currently been allocated to widget. This function is intended to be used when implementing handlers for the #GtkWidget::draw function, and when allocating child widgets in #GtkWidget::size_allocate.

    Returns number

  • get_allocated_height(): number
  • Retrieves the widget’s allocated size.

    This function returns the last values passed to gtk_widget_size_allocate_with_baseline(). The value differs from the size returned in gtk_widget_get_allocation() in that functions like gtk_widget_set_halign() can adjust the allocation, but not the value returned by this function.

    If a widget is not visible, its allocated size is 0.

    Returns [Gdk.Rectangle, number]

  • get_allocated_width(): number
  • Returns the width that has currently been allocated to widget. This function is intended to be used when implementing handlers for the #GtkWidget::draw function.

    Returns number

  • Retrieves the widget’s allocation.

    Note, when implementing a #GtkContainer: a widget’s allocation will be its “adjusted” allocation, that is, the widget’s parent container typically calls gtk_widget_size_allocate() with an allocation, and that allocation is then adjusted (to handle margin and alignment for example) before assignment to the widget. gtk_widget_get_allocation() returns the adjusted allocation that was actually assigned to the widget. The adjusted allocation is guaranteed to be completely contained within the gtk_widget_size_allocate() allocation, however. So a #GtkContainer is guaranteed that its children stay inside the assigned bounds, but not that they have exactly the bounds the container assigned. There is no way to get the original allocation assigned by gtk_widget_size_allocate(), since it isn’t stored; if a container implementation needs that information it will have to track it itself.

    Returns Gdk.Rectangle

  • Gets the first ancestor of widget with type widget_type. For example, gtk_widget_get_ancestor (widget, GTK_TYPE_BOX) gets the first #GtkBox that’s an ancestor of widget. No reference will be added to the returned widget; it should not be unreferenced. See note about checking for a toplevel #GtkWindow in the docs for gtk_widget_get_toplevel().

    Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor() considers widget to be an ancestor of itself.

    Parameters

    • widget_type: GType<unknown>

      ancestor type

    Returns Gtk.Widget

  • get_app_paintable(): boolean
  • get_border_width(): number
  • get_can_default(): boolean
  • get_can_focus(): boolean
  • This function is only for use in widget implementations. Obtains widget->requisition, unless someone has forced a particular geometry on the widget (e.g. with gtk_widget_set_size_request()), in which case it returns that geometry instead of the widget's requisition.

    This function differs from gtk_widget_size_request() in that it retrieves the last size request value from widget->requisition, while gtk_widget_size_request() actually calls the "size_request" method on widget to compute the size request and fill in widget->requisition, and only then returns widget->requisition.

    Because this function does not call the “size_request” method, it can only be used when you know that widget->requisition is up-to-date, that is, gtk_widget_size_request() has been called since the last time a resize was queued. In general, only container implementations have this information; applications should use gtk_widget_size_request().

    Returns Gtk.Requisition

  • get_child_visible(): boolean
  • Gets the value set with gtk_widget_set_child_visible(). If you feel a need to use this function, your code probably needs reorganization.

    This function is only useful for container implementations and never should be called by an application.

    Returns boolean

  • Retrieves the widget’s clip area.

    The clip area is the area in which all of widget's drawing will happen. Other toolkits call it the bounding box.

    Historically, in GTK+ the clip area has been equal to the allocation retrieved via gtk_widget_get_allocation().

    Returns Gdk.Rectangle

  • Returns the clipboard object for the given selection to be used with widget. widget must have a #GdkDisplay associated with it, so must be attached to a toplevel window.

    Parameters

    • selection: Gdk.Atom

      a #GdkAtom which identifies the clipboard to use. %GDK_SELECTION_CLIPBOARD gives the default clipboard. Another common value is %GDK_SELECTION_PRIMARY, which gives the primary X selection.

    Returns Gtk.Clipboard

  • get_composite_name(): string
  • get_data(key?: string): object
  • Gets a named field from the objects table of associations (see g_object_set_data()).

    Parameters

    • Optional key: string

      name of the key for that association

    Returns object

  • get_device_enabled(device: Gdk.Device): boolean