Gjsify LogoGjsify Logo

GtkWidget is the base class all widgets in GTK+ derive from. It manages the widget lifecycle, states and style.

Height-for-width Geometry Management # {#geometry-management}

GTK+ uses a height-for-width (and width-for-height) geometry management system. Height-for-width means that a widget can change how much vertical space it needs, depending on the amount of horizontal space that it is given (and similar for width-for-height). The most common example is a label that reflows to fill up the available width, wraps to fewer lines, and therefore needs less height.

Height-for-width geometry management is implemented in GTK+ by way of five virtual methods:

  • #GtkWidgetClass.get_request_mode()
  • #GtkWidgetClass.get_preferred_width()
  • #GtkWidgetClass.get_preferred_height()
  • #GtkWidgetClass.get_preferred_height_for_width()
  • #GtkWidgetClass.get_preferred_width_for_height()
  • #GtkWidgetClass.get_preferred_height_and_baseline_for_width()

There are some important things to keep in mind when implementing height-for-width and when using it in container implementations.

The geometry management system will query a widget hierarchy in only one orientation at a time. When widgets are initially queried for their minimum sizes it is generally done in two initial passes in the #GtkSizeRequestMode chosen by the toplevel.

For example, when queried in the normal %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode: First, the default minimum and natural width for each widget in the interface will be computed using gtk_widget_get_preferred_width(). Because the preferred widths for each container depend on the preferred widths of their children, this information propagates up the hierarchy, and finally a minimum and natural width is determined for the entire toplevel. Next, the toplevel will use the minimum width to query for the minimum height contextual to that width using gtk_widget_get_preferred_height_for_width(), which will also be a highly recursive operation. The minimum height for the minimum width is normally used to set the minimum size constraint on the toplevel (unless gtk_window_set_geometry_hints() is explicitly used instead).

After the toplevel window has initially requested its size in both dimensions it can go on to allocate itself a reasonable size (or a size previously specified with gtk_window_set_default_size()). During the recursive allocation process it’s important to note that request cycles will be recursively executed while container widgets allocate their children. Each container widget, once allocated a size, will go on to first share the space in one orientation among its children and then request each child's height for its target allocated width or its width for allocated height, depending. In this way a #GtkWidget will typically be requested its size a number of times before actually being allocated a size. The size a widget is finally allocated can of course differ from the size it has requested. For this reason, #GtkWidget caches a small number of results to avoid re-querying for the same sizes in one allocation cycle.

See [GtkContainer’s geometry management section][container-geometry-management] to learn more about how height-for-width allocations are performed by container widgets.

If a widget does move content around to intelligently use up the allocated size then it must support the request in both #GtkSizeRequestModes even if the widget in question only trades sizes in a single orientation.

For instance, a #GtkLabel that does height-for-width word wrapping will not expect to have #GtkWidgetClass.get_preferred_height() called because that call is specific to a width-for-height request. In this case the label must return the height required for its own minimum possible width. By following this rule any widget that handles height-for-width or width-for-height requests will always be allocated at least enough space to fit its own content.

Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height() it will do:

static void
foo_widget_get_preferred_height (GtkWidget *widget,
gint *min_height,
gint *nat_height)
{
if (i_am_in_height_for_width_mode)
{
gint min_width, nat_width;

GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget,
&min_width,
&nat_width);
GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width
(widget,
min_width,
min_height,
nat_height);
}
else
{
... some widgets do both. For instance, if a GtkLabel is
rotated to 90 degrees it will return the minimum and
natural height for the rotated label here.
}
}

And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return the minimum and natural width:

static void
foo_widget_get_preferred_width_for_height (GtkWidget *widget,
gint for_height,
gint *min_width,
gint *nat_width)
{
if (i_am_in_height_for_width_mode)
{
GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget,
min_width,
nat_width);
}
else
{
... again if a widget is sometimes operating in
width-for-height mode (like a rotated GtkLabel) it can go
ahead and do its real width for height calculation here.
}
}

Often a widget needs to get its own request during size request or allocation. For example, when computing height it may need to also compute width. Or when deciding how to use an allocation, the widget may need to know its natural size. In these cases, the widget should be careful to call its virtual methods directly, like this:

GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget,
&min,
&natural);

It will not work to use the wrapper functions, such as gtk_widget_get_preferred_width() inside your own size request implementation. These return a request adjusted by #GtkSizeGroup and by the #GtkWidgetClass.adjust_size_request() virtual method. If a widget used the wrappers inside its virtual method implementations, then the adjustments (such as widget margins) would be applied twice. GTK+ therefore does not allow this and will warn if you try to do it.

Of course if you are getting the size request for another widget, such as a child of a container, you must use the wrapper APIs. Otherwise, you would not properly consider widget margins, #GtkSizeGroup, and so forth.

Since 3.10 GTK+ also supports baseline vertical alignment of widgets. This means that widgets are positioned such that the typographical baseline of widgets in the same row are aligned. This happens if a widget supports baselines, has a vertical alignment of %GTK_ALIGN_BASELINE, and is inside a container that supports baselines and has a natural “row” that it aligns to the baseline, or a baseline assigned to it by the grandparent.

Baseline alignment support for a widget is done by the #GtkWidgetClass.get_preferred_height_and_baseline_for_width() virtual function. It allows you to report a baseline in combination with the minimum and natural height. If there is no baseline you can return -1 to indicate this. The default implementation of this virtual function calls into the #GtkWidgetClass.get_preferred_height() and #GtkWidgetClass.get_preferred_height_for_width(), so if baselines are not supported it doesn’t need to be implemented.

If a widget ends up baseline aligned it will be allocated all the space in the parent as if it was %GTK_ALIGN_FILL, but the selected baseline can be found via gtk_widget_get_allocated_baseline(). If this has a value other than -1 you need to align the widget such that the baseline appears at the position.

Style Properties

#GtkWidget introduces “style properties” - these are basically object properties that are stored not on the object, but in the style object associated to the widget. Style properties are set in [resource files][gtk3-Resource-Files]. This mechanism is used for configuring such things as the location of the scrollbar arrows through the theme, giving theme authors more control over the look of applications without the need to write a theme engine in C.

Use gtk_widget_class_install_style_property() to install style properties for a widget class, gtk_widget_class_find_style_property() or gtk_widget_class_list_style_properties() to get information about existing style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or gtk_widget_style_get_valist() to obtain the value of a style property.

GtkWidget as GtkBuildable

The GtkWidget implementation of the GtkBuildable interface supports a custom <accelerator> element, which has attributes named ”key”, ”modifiers” and ”signal” and allows to specify accelerators.

An example of a UI definition fragment specifying an accelerator:

|[



In addition to accelerators, GtkWidget also support a custom `<accessible>`
element, which supports actions and relations. Properties on the accessible
implementation of an object can be set by accessing the internal child
accessibleof a #GtkWidget.

An example of a UI definition fragment specifying an accessible:

|[<!-- language="xml" -->
<object class="GtkLabel" id="label1"/>
<property name="label">I am a Label for a Button</property>
</object>
<object class="GtkButton" id="button1">
<accessibility>
<action action_name="click" translatable="yes">Click the button.</action>
<relation target="label1" type="labelled-by"/>
</accessibility>
<child internal-child="accessible">
<object class="AtkObject" id="a11y-button1">
<property name="accessible-name">Clickable Button</property>
</object>
</child>
</object>

Finally, GtkWidget allows style information such as style classes to be associated with widgets, using the custom <style> element:

|[



# Building composite widgets from template XML ## {#composite-templates}

GtkWidget exposes some facilities to automate the procedure
of creating composite widgets using #GtkBuilder interface description
language.

To create composite widgets with #GtkBuilder XML, one must associate
the interface description with the widget class at class initialization
time using gtk_widget_class_set_template().

The interface description semantics expected in composite template descriptions
is slightly different from regular #GtkBuilder XML.

Unlike regular interface descriptions, gtk_widget_class_set_template() will
expect a `<template>` tag as a direct child of the toplevel `<interface>`
tag. The `<template>` tag must specify theclassattribute which must be
the type name of the widget. Optionally, theparentattribute may be
specified to specify the direct parent type of the widget type, this is
ignored by the GtkBuilder but required for Glade to introspect what kind
of properties and internal children exist for a given type when the actual
type does not exist.

The XML which is contained inside the `<template>` tag behaves as if it were
added to the `<object>` tag defining "widget" itself. You may set properties
on `widget` by inserting `<property>` tags into the `<template>` tag, and also
add `<child>` tags to add children and extend "widget" in the normal way you
would with `<object>` tags.

Additionally, `<object>` tags can also be added before and after the initial
`<template>` tag in the normal way, allowing one to define auxiliary objects
which might be referenced by other widgets declared as children of the
`<template>` tag.

An example of a GtkBuilder Template Definition:

|[<!-- language="xml" -->
<interface>
<template class="FooWidget" parent="GtkBox">
<property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
<property name="spacing">4</property>
<child>
<object class="GtkButton" id="hello_button">
<property name="label">Hello World</property>
<signal name="clicked" handler="hello_button_clicked" object="FooWidget" swapped="yes"/>
</object>
</child>
<child>
<object class="GtkButton" id="goodbye_button">
<property name="label">Goodbye World</property>
</object>
</child>
</template>
</interface>

Typically, you'll place the template fragment into a file that is bundled with your project, using #GResource. In order to load the template, you need to call gtk_widget_class_set_template_from_resource() from the class initialization of your #GtkWidget type:

static void
foo_widget_class_init (FooWidgetClass *klass)
{
// ...

gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
"/com/example/ui/foowidget.ui");
}

You will also need to call gtk_widget_init_template() from the instance initialization function:

static void
foo_widget_init (FooWidget *self)
{
// ...
gtk_widget_init_template (GTK_WIDGET (self));
}

You can access widgets defined in the template using the gtk_widget_get_template_child() function, but you will typically declare a pointer in the instance private data structure of your type using the same name as the widget in the template definition, and call gtk_widget_class_bind_template_child_private() with that name, e.g.

typedef struct {
GtkWidget *hello_button;
GtkWidget *goodbye_button;
} FooWidgetPrivate;

G_DEFINE_TYPE_WITH_PRIVATE (FooWidget, foo_widget, GTK_TYPE_BOX)

static void
foo_widget_class_init (FooWidgetClass *klass)
{
// ...
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
"/com/example/ui/foowidget.ui");
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass),
FooWidget, hello_button);
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass),
FooWidget, goodbye_button);
}

static void
foo_widget_init (FooWidget *widget)
{

}

You can also use gtk_widget_class_bind_template_callback() to connect a signal callback defined in the template with a function visible in the scope of the class, e.g.

// the signal handler has the instance and user data swapped
// because of the swapped="yes" attribute in the template XML
static void
hello_button_clicked (FooWidget *self,
GtkButton *button)
{
g_print ("Hello, world!\n");
}

static void
foo_widget_class_init (FooWidgetClass *klass)
{
// ...
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
"/com/example/ui/foowidget.ui");
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), hello_button_clicked);
}

Hierarchy

Index

Constructors

Properties

Methods

Constructors

Properties

app_paintable: boolean
can_default: boolean
can_focus: boolean
composite_child: boolean
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
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
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).

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.

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
width_request: number
window: Gdk.Window

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

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

Methods

  • activate(): boolean
  • 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

  • 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

  • Adds the device events in the bitfield events to the event mask for widget. See gtk_widget_set_device_events() for details.

    Parameters

    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

  • 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_notify(child_property: string): void
  • 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

    • child_property: string

      the name of a child property installed on the class of widget’s parent

    Returns void

  • 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

  • Creates a new #PangoContext with the appropriate font map, font options, font description, and base direction for drawing text for this widget. See also gtk_widget_get_pango_context().

    Returns Pango.Context

  • 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

  • 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
  • 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
  • Returns whether the widget has been configured to always emit #GtkWidget::drag-motion signals.

    Returns 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

  • Sets the target types that this widget can accept from drag-and-drop. The widget must first be made into a drag destination with gtk_drag_dest_set().

    Parameters

    • target_list: Gtk.TargetList

      list of droppable targets, or %NULL for none

    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
  • Clears information about a drop destination set with gtk_drag_dest_set(). The widget will no longer receive notification of drags.

    Returns 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
  • Sets the icon that will be used for drags from a particular source to icon. See the docs for #GtkIconTheme for more details.

    Parameters

    Returns void

  • drag_source_set_icon_name(icon_name: string): void
  • Sets the icon that will be used for drags from a particular source to a themed icon. See the docs for #GtkIconTheme for more details.

    Parameters

    • icon_name: string

      name of icon to use

    Returns 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
  • Sets the icon that will be used for drags from a particular source to a stock icon.

    Parameters

    • stock_id: string

      the ID of the stock icon to use

    Returns void

  • Changes the target types that this widget offers for drag-and-drop. The widget must first be made into a drag source with gtk_drag_source_set().

    Parameters

    • target_list: Gtk.TargetList

      list of draggable targets, or %NULL for none

    Returns 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: "accel-closures-changed", ...args: any[]): void
  • emit(sigName: "button-press-event", event: Gdk.EventButton, ...args: any[]): void
  • emit(sigName: "button-release-event", event: Gdk.EventButton, ...args: any[]): void
  • emit(sigName: "can-activate-accel", signal_id: number, ...args: any[]): void
  • emit(sigName: "child-notify", child_property: ParamSpec, ...args: any[]): void
  • emit(sigName: "composited-changed", ...args: any[]): void
  • emit(sigName: "configure-event", event: Gdk.EventConfigure, ...args: any[]): void
  • emit(sigName: "damage-event", event: Gdk.EventExpose, ...args: any[]): void
  • emit(sigName: "delete-event", event: Gdk.Event, ...args: any[]): void
  • emit(sigName: "destroy", ...args: any[]): void
  • emit(sigName: "destroy-event", event: Gdk.Event, ...args: any[]): void
  • emit(sigName: "direction-changed", previous_direction: Gtk.TextDirection, ...args: any[]): void
  • emit(sigName: "drag-begin", context: Gdk.DragContext, ...args: any[]): void
  • emit(sigName: "drag-data-delete", context: Gdk.DragContext, ...args: any[]): void
  • emit(sigName: "drag-data-get", context: Gdk.DragContext, data: Gtk.SelectionData, info: number, time: number, ...args: any[]): void
  • emit(sigName: "drag-data-received", context: Gdk.DragContext, x: number, y: number, data: Gtk.SelectionData, info: number, time: number, ...args: any[]): void
  • emit(sigName: "drag-drop", context: Gdk.DragContext, x: number, y: number, time: number, ...args: any[]): void
  • emit(sigName: "drag-end", context: Gdk.DragContext, ...args: any[]): void
  • emit(sigName: "drag-failed", context: Gdk.DragContext, result: Gtk.DragResult, ...args: any[]): void
  • emit(sigName: "drag-leave", context: Gdk.DragContext, time: number, ...args: any[]): void
  • emit(sigName: "drag-motion", context: Gdk.DragContext, x: number, y: number, time: number, ...args: any[]): void
  • emit(sigName: "draw", cr: cairo.Context, ...args: any[]): void
  • emit(sigName: "enter-notify-event", event: Gdk.EventCrossing, ...args: any[]): void
  • emit(sigName: "event", event: Gdk.Event, ...args: any[]): void
  • emit(sigName: "event-after", event: Gdk.Event, ...args: any[]): void
  • emit(sigName: "focus", direction: Gtk.DirectionType, ...args: any[]): void
  • emit(sigName: "focus-in-event", event: Gdk.EventFocus, ...args: any[]): void
  • emit(sigName: "focus-out-event", event: Gdk.EventFocus, ...args: any[]): void
  • emit(sigName: "grab-broken-event", event: Gdk.EventGrabBroken, ...args: any[]): void
  • emit(sigName: "grab-focus", ...args: any[]): void
  • emit(sigName: "grab-notify", was_grabbed: boolean, ...args: any[]): void
  • emit(sigName: "hide", ...args: any[]): void
  • emit(sigName: "hierarchy-changed", previous_toplevel: Gtk.Widget, ...args: any[]): void
  • emit(sigName: "key-press-event", event: Gdk.EventKey, ...args: any[]): void
  • emit(sigName: "key-release-event", event: Gdk.EventKey, ...args: any[]): void
  • emit(sigName: "keynav-failed", direction: Gtk.DirectionType, ...args: any[]): void
  • emit(sigName: "leave-notify-event", event: Gdk.EventCrossing, ...args: any[]): void
  • emit(sigName: "map", ...args: any[]): void
  • emit(sigName: "map-event", event: Gdk.EventAny, ...args: any[]): void
  • emit(sigName: "mnemonic-activate", group_cycling: boolean, ...args: any[]): void
  • emit(sigName: "motion-notify-event", event: Gdk.EventMotion, ...args: any[]): void
  • emit(sigName: "move-focus", direction: Gtk.DirectionType, ...args: any[]): void
  • emit(sigName: "parent-set", old_parent: Gtk.Widget, ...args: any[]): void
  • emit(sigName: "popup-menu", ...args: any[]): void
  • emit(sigName: "property-notify-event", event: Gdk.EventProperty, ...args: any[]): void
  • emit(sigName: "proximity-in-event", event: Gdk.EventProximity, ...args: any[]): void
  • emit(sigName: "proximity-out-event", event: Gdk.EventProximity, ...args: any[]): void
  • emit(sigName: "query-tooltip", x: number, y: number, keyboard_mode: boolean, tooltip: Gtk.Tooltip, ...args: any[]): void
  • emit(sigName: "realize", ...args: any[]): void
  • emit(sigName: "screen-changed", previous_screen: Gdk.Screen, ...args: any[]): void
  • emit(sigName: "scroll-event", event: Gdk.EventScroll, ...args: any[]): void
  • emit(sigName: "selection-clear-event", event: Gdk.EventSelection, ...args: any[]): void
  • emit(sigName: "selection-get", data: Gtk.SelectionData, info: number, time: number, ...args: any[]): void
  • emit(sigName: "selection-notify-event", event: Gdk.EventSelection, ...args: any[]): void
  • emit(sigName: "selection-received", data: Gtk.SelectionData, time: number, ...args: any[]): void
  • emit(sigName: "selection-request-event", event: Gdk.EventSelection, ...args: any[]): void
  • emit(sigName: "show", ...args: any[]): void
  • emit(sigName: "show-help", help_type: Gtk.WidgetHelpType, ...args: any[]): void
  • emit(sigName: "size-allocate", allocation: Gdk.Rectangle, ...args: any[]): void
  • emit(sigName: "state-changed", state: Gtk.StateType, ...args: any[]): void
  • emit(sigName: "state-flags-changed", flags: Gtk.StateFlags, ...args: any[]): void
  • emit(sigName: "style-set", previous_style: Gtk.Style, ...args: any[]): void
  • emit(sigName: "style-updated", ...args: any[]): void
  • emit(sigName: "touch-event", object: Gdk.Event, ...args: any[]): void
  • emit(sigName: "unmap", ...args: any[]): void
  • emit(sigName: "unmap-event", event: Gdk.EventAny, ...args: any[]): void
  • emit(sigName: "unrealize", ...args: any[]): void
  • emit(sigName: "visibility-notify-event", event: Gdk.EventVisibility, ...args: any[]): void
  • emit(sigName: "window-state-event", event: Gdk.EventWindowState, ...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: string, ...args: any[]): void