Class Widget

java.lang.Object
org.eclipse.swt.widgets.Widget
Direct Known Subclasses:
Caret, Control, DragSource, DropTarget, IME, Item, Menu, ScrollBar, TaskBar, ToolTip, Tracker, Tray

public abstract class Widget extends Object
This class is the abstract superclass of all user interface objects. Widgets are created, disposed and issue notification to listeners when events occur which affect them.
Styles:
(none)
Events:
Dispose

IMPORTANT: This class is intended to be subclassed only within the SWT implementation. However, it has not been marked final to allow those outside of the SWT development team to implement patched versions of the class in order to get around specific limitations in advance of when those limitations can be addressed by the team. Any class built using subclassing to access the internals of this class will likely fail to compile or run between releases and may be strongly platform specific. Subclassing should not be attempted without an intimate and detailed understanding of the workings of the hierarchy. No support is provided for user-written classes which are implemented as subclasses of this class.

See Also:
  • Field Details

  • Constructor Details

    • Widget

      Widget()
      Prevents uninitialized instances from being created outside the package.
    • Widget

      public Widget(Widget parent, int style)
      Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

      The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

      Parameters:
      parent - a widget which will be the parent of the new instance (cannot be null)
      style - the style of widget to construct
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the parent is null
      • ERROR_INVALID_ARGUMENT - if the parent is disposed
      SWTException -
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
      • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
      See Also:
  • Method Details

    • _addListener

      void _addListener(int eventType, Listener listener)
    • addListener

      public void addListener(int eventType, Listener listener)
      Adds the listener to the collection of listeners who will be notified when an event of the given type occurs. When the event does occur in the widget, the listener is notified by sending it the handleEvent() message. The event type is one of the event constants defined in class SWT.
      Parameters:
      eventType - the type of event to listen for
      listener - the listener which should be notified when the event occurs
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • addTypedListener

      protected void addTypedListener(EventListener listener, int... eventTypes)
      Adds the typed listener to the collection of listeners who will be notified when an event of the given types occurs. When the event does occur in the widget, the listener is notified by calling the type's handling methods. The event type is one of the event constants defined in class SWT and must correspond to the listeners type. If for example a SelectionListener is passed the eventTypes can be SWT.Selection or SWT.DefaultSelection.
      Parameters:
      listener - the listener which should be notified when the event occurs
      eventTypes - the types of event to listen for
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.126
      See Also:
    • addDisposeListener

      public void addDisposeListener(DisposeListener listener)
      Adds the listener to the collection of listeners who will be notified when the widget is disposed. When the widget is disposed, the listener is notified by sending it the widgetDisposed() message.
      Parameters:
      listener - the listener which should be notified when the receiver is disposed
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • paintWindow

      long paintWindow()
    • paintSurface

      long paintSurface()
    • cssHandle

      long cssHandle()
    • checkBits

      static int checkBits(int style, int int0, int int1, int int2, int int3, int int4, int int5)
    • cellDataProc

      long cellDataProc(long tree_column, long cell, long tree_model, long iter, long data)
    • checkOpen

      void checkOpen()
    • checkOrientation

      void checkOrientation(Widget parent)
    • checkParent

      void checkParent(Widget parent)
      Throws an exception if the specified widget can not be used as a parent for the receiver.
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the parent is null
      • ERROR_INVALID_ARGUMENT - if the parent is disposed
      SWTException -
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
    • checkSubclass

      protected void checkSubclass()
      Checks that this class can be subclassed.

      The SWT class library is intended to be subclassed only at specific, controlled points (most notably, Composite and Canvas when implementing new widgets). This method enforces this rule unless it is overridden.

      IMPORTANT: By providing an implementation of this method that allows a subclass of a class which does not normally allow subclassing to be created, the implementer agrees to be fully responsible for the fact that any such subclass will likely fail between SWT releases and will be strongly platform specific. No support is provided for user-written classes which are implemented in this fashion.

      The ability to subclass outside of the allowed SWT classes is intended purely to enable those not on the SWT development team to implement patches in order to get around specific limitations in advance of when those limitations can be addressed by the team. Subclassing should not be attempted without an intimate and detailed understanding of the hierarchy.

      Throws:
      SWTException -
      • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
    • checkWidget

      protected void checkWidget()
      Throws an SWTException if the receiver can not be accessed by the caller. This may include both checks on the state of the receiver and more generally on the entire execution context. This method should be called by widget implementors to enforce the standard SWT invariants.

      Currently, it is an error to invoke any method (other than isDisposed()) on a widget that has had its dispose() method called. It is also an error to call widget methods from any thread that is different from the thread that created the widget.

      In future releases of SWT, there may be more or fewer error checks and exceptions may be thrown for different reasons.

      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • createHandle

      void createHandle(int index)
    • createWidget

      void createWidget(int index)
    • deregister

      void deregister()
    • destroyWidget

      void destroyWidget()
    • dispose

      public void dispose()
      Disposes of the operating system resources associated with the receiver and all its descendants. After this method has been invoked, the receiver and all descendants will answer true when sent the message isDisposed(). Any internal connections between the widgets in the tree will have been removed to facilitate garbage collection. This method does nothing if the widget is already disposed.

      NOTE: This method is not called recursively on the descendants of the receiver. This means that, widget implementers can not detect when a widget is being disposed of by re-implementing this method, but should instead listen for the Dispose event.

      Throws:
      SWTException -
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • dpiChanged

      long dpiChanged(long object, long arg0)
    • error

      void error(int code)
    • getData

      public Object getData()
      Returns the application defined widget data associated with the receiver, or null if it has not been set. The widget data is a single, unnamed field that is stored with every widget.

      Applications may put arbitrary objects in this field. If the object stored in the widget data needs to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.

      Returns:
      the widget data
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - when the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread
      See Also:
    • getData

      public Object getData(String key)
      Returns the application defined property of the receiver with the specified name, or null if it has not been set.

      Applications may have associated arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.

      Parameters:
      key - the name of the property
      Returns:
      the value of the property or null if it has not been set
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the key is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • getDisplay

      public Display getDisplay()
      Returns the Display that is associated with the receiver.

      A widget's display is either provided when it is created (for example, top level Shells) or is the same as its parent's display.

      Returns:
      the receiver's display
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • getListeners

      public Listener[] getListeners(int eventType)
      Returns an array of listeners who will be notified when an event of the given type occurs. The event type is one of the event constants defined in class SWT.
      Parameters:
      eventType - the type of event to listen for
      Returns:
      an array of listeners that will be notified when the event occurs
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.4
      See Also:
    • getTypedListeners

      public <L extends EventListener> Stream<L> getTypedListeners(int eventType, Class<L> listenerType)
      Returns the typed listeners who will be notified when an event of the given type occurs. The event type is one of the event constants defined in class SWT and the specified listener-type must correspond to that event. If for example the eventType is SWT.Selection, the listeners type should be SelectionListener.
      Parameters:
      eventType - the type of event to listen for
      Returns:
      a stream of typed listeners that will be notified when the event occurs
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.126
      See Also:
    • getName

      String getName()
    • getNameText

      String getNameText()
    • getStyle

      public int getStyle()
      Returns the receiver's style information.

      Note that the value which is returned by this method may not match the value which was provided to the constructor when the receiver was created. This can occur when the underlying operating system does not support a particular combination of requested styles. For example, if the platform widget used to implement a particular SWT widget always has scroll bars, the result of calling this method would always have the SWT.H_SCROLL and SWT.V_SCROLL bits set.

      Returns:
      the style bits
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • gtk_activate

      long gtk_activate(long widget)
    • gtk_adjustment_get

      void gtk_adjustment_get(long adjustmentHandle, GtkAdjustment adjustment)
    • gtk_button_press_event

      long gtk_button_press_event(long widget, long event)
    • gtk_button_release_event

      long gtk_button_release_event(long widget, long event)
    • gtk_gesture_press_event

      int gtk_gesture_press_event(long gesture, int n_press, double x, double y, long event)
      Parameters:
      gesture - the corresponding controller responsible for capturing the event
      n_press - how many touch/button presses happened with this one
      x - the x coordinate, in widget allocation coordinates
      y - the y coordinate, in widget allocation coordinates
      event - the GdkEvent captured
    • gtk_gesture_release_event

      int gtk_gesture_release_event(long gesture, int n_press, double x, double y, long event)
      Parameters:
      gesture - the corresponding controller responsible for capturing the event
      n_press - how many touch/button presses happened with this one
      x - the x coordinate, in widget allocation coordinates
      y - the y coordinate, in widget allocation coordinates
      event - the GdkEvent captured
    • gtk4_motion_event

      void gtk4_motion_event(long controller, double x, double y, long event)
      Parameters:
      controller - the corresponding controller responsible for capturing the event
      x - the x coordinate
      y - the y coordinate
      event - the GdkEvent captured
    • gtk4_key_press_event

      boolean gtk4_key_press_event(long controller, int keyval, int keycode, int state, long event)
      Parameters:
      controller - the corresponding controller responsible for capturing the event
      keyval - the pressed key
      keycode - raw code of the pressed key
      state - the bitmask, representing the state of the modifier keys and pointer buttons
      event - the GdkEvent captured
      Returns:
      TRUE if the event has been fully/properly handled, otherwise FALSE
    • gtk4_key_release_event

      void gtk4_key_release_event(long controller, int keyval, int keycode, int state, long event)
      Parameters:
      controller - the corresponding controller responsible for capturing the event
      keyval - the released key
      keycode - raw code of the released key
      state - the bitmask, representing the state of the modifier keys and pointer buttons
      event - the GdkEvent captured
    • gtk4_focus_enter_event

      void gtk4_focus_enter_event(long controller, long event)
      Parameters:
      controller - the corresponding controller responsible for capturing the event
      event - the GdkEvent captured
    • gtk4_focus_window_event

      void gtk4_focus_window_event(long handle, long event)
      Parameters:
      handle - the handle of the window that caused the event
      event - the type of event, should be FocusIn or FocusOut
    • gtk4_focus_leave_event

      void gtk4_focus_leave_event(long controller, long event)
      Parameters:
      controller - the corresponding controller responsible for capturing the event
      event - the GdkEvent captured
    • gtk4_enter_event

      void gtk4_enter_event(long controller, double x, double y, long event)
      Parameters:
      controller - the corresponding controller responsible for capturing the event
      x - x coordinate of pointer location
      y - y coordinate of pointer location
      event - the GdkEvent captured
    • gtk4_leave_event

      void gtk4_leave_event(long controller, long event)
      Parameters:
      controller - the corresponding controller responsible for capturing the event
      event - the GdkEvent captured
    • gtk4_scroll_event

      boolean gtk4_scroll_event(long controller, double dx, double dy, long event)
      Parameters:
      controller - the corresponding controller responsible for capturing the event
      dx - x delta
      dy - y delta
      event - the GdkEvent captured
      Returns:
      TRUE if the scroll event was handled, FALSE otherwise
    • gtk_changed

      long gtk_changed(long widget)
    • gtk_change_value

      boolean gtk_change_value(long widget, int scroll, double value, long user_data)
    • gtk_clicked

      long gtk_clicked(long widget)
    • gtk_close_request

      long gtk_close_request(long widget)
    • gtk_commit

      long gtk_commit(long imcontext, long text)
    • gtk_configure_event

      long gtk_configure_event(long widget, long event)
    • gtk_create_menu_proxy

      long gtk_create_menu_proxy(long widget)
    • gtk_day_selected

      long gtk_day_selected(long widget)
    • gtk_day_selected_double_click

      long gtk_day_selected_double_click(long widget)
    • gtk_delete_event

      long gtk_delete_event(long widget, long event)
    • gtk_delete_range

      long gtk_delete_range(long widget, long iter1, long iter2)
    • gtk_delete_text

      long gtk_delete_text(long widget, long start_pos, long end_pos)
    • gtk_enter_notify_event

      long gtk_enter_notify_event(long widget, long event)
    • gtk3_event_after

      long gtk3_event_after(long widget, long event)
    • gtk_expand_collapse_cursor_row

      long gtk_expand_collapse_cursor_row(long widget, long logical, long expand, long open_all)
    • gtk_draw

      long gtk_draw(long widget, long cairo)
    • gtk4_draw

      void gtk4_draw(long widget, long cairo, Rectangle bounds)
    • gtk_focus

      long gtk_focus(long widget, long event)
    • gtk_focus_in_event

      long gtk_focus_in_event(long widget, long event)
    • gtk_focus_out_event

      long gtk_focus_out_event(long widget, long event)
    • gtk_grab_focus

      long gtk_grab_focus(long widget)
    • gtk_hide

      long gtk_hide(long widget)
    • gtk_icon_release

      long gtk_icon_release(long widget, long icon_pos, long event)
    • gtk_input

      long gtk_input(long widget, long arg1)
    • gtk_insert_text

      long gtk_insert_text(long widget, long new_text, long new_text_length, long position)
    • gtk3_key_press_event

      long gtk3_key_press_event(long widget, long event)
    • gtk3_key_release_event

      long gtk3_key_release_event(long widget, long event)
    • gtk_leave_notify_event

      long gtk_leave_notify_event(long widget, long event)
    • gtk_map

      long gtk_map(long widget)
    • gtk_map_event

      long gtk_map_event(long widget, long event)
    • gtk_menu_popped_up

      long gtk_menu_popped_up(long widget, long flipped_rect, long final_rect, long flipped_x, long flipped_y)

      GTK3.22+ has API which allows clients of GTK to connect a menu to the "popped-up" signal. This callback is triggered after the menu is popped up/shown to the user, and provides information about the actual position and size of the menu, as shown to the user.

      SWT clients can enable this functionality by launching their application with the SWT_MENU_LOCATION_DEBUGGING environment variable set to 1. If enabled, the previously mentioned positioning and size information will be printed to the console. The information comes from GTK internals and is stored in the method parameters.

      Parameters:
      widget - the memory address of the menu which was popped up
      flipped_rect - a pointer to the GdkRectangle containing the flipped location and size of the menu
      final_rect - a pointer to the GdkRectangle containing the final (after all internal adjustments) location and size of the menu
      flipped_x - a boolean flag indicating whether the menu has been inverted along the X-axis
      flipped_y - a boolean flag indicating whether the menu has been inverted along the Y-axis
    • gtk_mnemonic_activate

      long gtk_mnemonic_activate(long widget, long arg1)
    • gtk_month_changed

      long gtk_month_changed(long widget)
    • gtk_motion_notify_event

      long gtk_motion_notify_event(long widget, long event)
    • gtk_move_focus

      long gtk_move_focus(long widget, long event)
    • gtk_output

      long gtk_output(long widget)
    • gtk_populate_popup

      long gtk_populate_popup(long widget, long menu)
    • gtk3_popup_menu

      long gtk3_popup_menu(long widget)
    • gtk_preedit_changed

      long gtk_preedit_changed(long imcontext)
    • gtk_realize

      long gtk_realize(long widget)
    • gtk_row_activated

      long gtk_row_activated(long tree, long path, long column)
    • gtk_row_has_child_toggled

      long gtk_row_has_child_toggled(long model, long path, long iter)
    • gtk_scroll_child

      long gtk_scroll_child(long widget, long scrollType, long horizontal)
    • gtk_scroll_event

      long gtk_scroll_event(long widget, long event)
    • gtk_select

      long gtk_select(long item)
    • gtk_selection_done

      long gtk_selection_done(long menushell)
    • gtk_show

      long gtk_show(long widget)
    • gtk3_show_help

      long gtk3_show_help(long widget, long helpType)
    • gtk_size_allocate

      long gtk_size_allocate(long widget, long allocation)
    • gtk_status_icon_popup_menu

      long gtk_status_icon_popup_menu(long handle, long button, long activate_time)
    • gtk_start_interactive_search

      long gtk_start_interactive_search(long widget)
    • gtk_style_updated

      long gtk_style_updated(long widget)
    • gtk_switch_page

      long gtk_switch_page(long notebook, long page, int page_num)
    • gtk_test_collapse_row

      long gtk_test_collapse_row(long tree, long iter, long path)
    • gtk_test_expand_row

      long gtk_test_expand_row(long tree, long iter, long path)
    • gtk_text_buffer_insert_text

      long gtk_text_buffer_insert_text(long widget, long iter, long text, long length)
    • gtk_timer

      long gtk_timer()
    • gtk_toggled

      long gtk_toggled(long renderer, long pathStr)
    • gtk_tree_view_column_cell_get_position

      boolean gtk_tree_view_column_cell_get_position(long column, long cell_renderer, int[] start_pos, int[] width)
    • gtk_unmap

      long gtk_unmap(long widget)
    • gtk_unmap_event

      long gtk_unmap_event(long widget, long event)
    • gtk_unrealize

      long gtk_unrealize(long widget)
    • gtk_value_changed

      long gtk_value_changed(long range)
    • gtk_window_state_event

      long gtk_window_state_event(long widget, long event)
    • fontHeight

      int fontHeight(long font, long widgetHandle)
    • filterProc

      long filterProc(long xEvent, long gdkEvent, long data2)
    • filters

      boolean filters(int eventType)
    • fixMnemonic

      char[] fixMnemonic(String string)
    • fixMnemonic

      char[] fixMnemonic(String string, boolean replace)
    • fixMnemonic

      char[] fixMnemonic(String string, boolean replace, boolean removeAppended)
    • isActive

      boolean isActive()
    • isAutoDirection

      public boolean isAutoDirection()
      Returns true if the widget has auto text direction, and false otherwise.
      Returns:
      true when the widget has auto direction and false otherwise
      Since:
      3.105
      See Also:
    • isDisposed

      public boolean isDisposed()
      Returns true if the widget has been disposed, and false otherwise.

      This method gets the dispose state for the widget. When a widget has been disposed, it is an error to invoke any other method (except dispose()) using the widget.

      Returns:
      true when the widget is disposed and false otherwise
    • isListening

      public boolean isListening(int eventType)
      Returns true if there are any listeners for the specified event type associated with the receiver, and false otherwise. The event type is one of the event constants defined in class SWT.
      Parameters:
      eventType - the type of event
      Returns:
      true if the event is hooked
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • isValidThread

      boolean isValidThread()
    • isValidSubclass

      boolean isValidSubclass()
    • hookEvents

      void hookEvents()
    • hooks

      boolean hooks(int eventType)
    • hoverProc

      long hoverProc(long widget)
    • mnemonicHit

      boolean mnemonicHit(long mnemonicHandle, char key)
    • mnemonicMatch

      boolean mnemonicMatch(long mnemonicHandle, char key)
    • notifyListeners

      public void notifyListeners(int eventType, Event event)
      Notifies all of the receiver's listeners for events of the given type that one such event has occurred by invoking their handleEvent() method. The event type is one of the event constants defined in class SWT.
      Parameters:
      eventType - the type of event which has occurred
      event - the event data
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • postEvent

      void postEvent(int eventType)
    • postEvent

      void postEvent(int eventType, Event event)
    • register

      void register()
    • release

      void release(boolean destroy)
    • releaseChildren

      void releaseChildren(boolean destroy)
    • releaseHandle

      void releaseHandle()
    • releaseParent

      void releaseParent()
    • releaseWidget

      void releaseWidget()
    • removeListener

      public void removeListener(int eventType, Listener listener)
      Removes the listener from the collection of listeners who will be notified when an event of the given type occurs. The event type is one of the event constants defined in class SWT.
      Parameters:
      eventType - the type of event to listen for
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • removeListener

      @Deprecated(forRemoval=true, since="2025-03") protected void removeListener(int eventType, SWTEventListener listener)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Removes the listener from the collection of listeners who will be notified when an event of the given type occurs.

      IMPORTANT: This method is not part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It should never be referenced from application code.

      Parameters:
      eventType - the type of event to listen for
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • removeListener

      protected void removeListener(int eventType, EventListener listener)
      Removes the listener from the collection of listeners who will be notified when an event of the given type occurs.

      IMPORTANT: This method is not part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It should never be referenced from application code.

      Parameters:
      eventType - the type of event to listen for
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • removeTypedListener

      protected void removeTypedListener(int eventType, EventListener listener)
      Removes the listener from the collection of listeners who will be notified when an event of the given type occurs.

      IMPORTANT: This method is not part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It should never be referenced from application code.

      Parameters:
      eventType - the type of event to listen for
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • rendererGetPreferredWidthProc

      long rendererGetPreferredWidthProc(long cell, long handle, long minimun_size, long natural_size)
    • rendererRenderProc

      long rendererRenderProc(long cell, long cr, long handle, long background_area, long cell_area, long flags)
    • rendererSnapshotProc

      long rendererSnapshotProc(long cell, long snapshot, long handle, long background_area, long cell_area, long flags)
    • reskin

      public void reskin(int flags)
      Marks the widget to be skinned.

      The skin event is sent to the receiver's display when appropriate (usually before the next event is handled). Widgets are automatically marked for skinning upon creation as well as when its skin id or class changes. The skin id and/or class can be changed by calling Display.setData(String, Object) with the keys SWT.SKIN_ID and/or SWT.SKIN_CLASS. Once the skin event is sent to a widget, it will not be sent again unless reskin(int) is called on the widget or on an ancestor while specifying the SWT.ALL flag.

      The parameter flags may be either:

      SWT.ALL
      all children in the receiver's widget tree should be skinned
      SWT.NONE
      only the receiver should be skinned
      Parameters:
      flags - the flags specifying how to reskin
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.6
    • reskinChildren

      void reskinChildren(int flags)
    • reskinWidget

      void reskinWidget()
    • removeDisposeListener

      public void removeDisposeListener(DisposeListener listener)
      Removes the listener from the collection of listeners who will be notified when the widget is disposed.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • sendEvent

      void sendEvent(Event event)
    • sendEvent

      void sendEvent(int eventType)
    • sendEvent

      void sendEvent(int eventType, Event event)
    • sendEvent

      void sendEvent(int eventType, Event event, boolean send)
    • sendKeyEvent

      boolean sendKeyEvent(int type, long event)
    • sendIMKeyEvent

      char[] sendIMKeyEvent(int type, long event, char[] chars)
    • sendSelectionEvent

      void sendSelectionEvent(int eventType)
    • sendSelectionEvent

      void sendSelectionEvent(int eventType, Event event, boolean send)
    • setData

      public void setData(Object data)
      Sets the application defined widget data associated with the receiver to be the argument. The widget data is a single, unnamed field that is stored with every widget.

      Applications may put arbitrary objects in this field. If the object stored in the widget data needs to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.

      Parameters:
      data - the widget data
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - when the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread
      See Also:
    • setData

      public void setData(String key, Object value)
      Sets the application defined property of the receiver with the specified name to the given value.

      Applications may associate arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.

      Parameters:
      key - the name of the property
      value - the new value for the property
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the key is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • setFontDescription

      void setFontDescription(long widget, long fontDescription)
      Parameters:
      fontDescription - Font description in the form of PangoFontDescription*. This pointer will never be used by GTK after calling this function, so it's safe to free it as soon as the function completes.
    • convertPangoFontDescriptionToCss

      String convertPangoFontDescriptionToCss(long fontDescription)
    • setButtonState

      void setButtonState(Event event, int eventButton)
    • setInputState

      boolean setInputState(Event event, int state)
    • setKeyState

      boolean setKeyState(Event javaEvent, long event)
      On Linux, the most common way to handle keyboard input is XKB. The rest of the description explains XKB and related GTK stuff. XKB uses the following definitions:
      • "group" - that's how they call keyboard layouts
      • "keycode" - id of a physical key on a keyboard. For example, AB01 refers to 2nd row from the bottom (B), 1st key (01)
      • "level" - Can be seen as a number that describes modifiers pressed together with the key. For example, in English US, pressing A would result in level 0, and pressing Shift+A would result in level 1. The other common levels are used for AltGr and Shift+AltGr, but a keyboard layout could have even more exotic levels.
      • "modifiers" - a combination of modifier keys. Keyboard layouts could define their own modifiers.
      • "keyval" - Can be seen as a final calculation of what was produced by a key press (by taking keycode, group, level, and other modifiers such as dead keys into account).
      Some examples:
      LayoutKey rowKey colKeycodeModifiersKeyvalCharacter
      English US 110FK09F9
      English US 35AD04rr
      English US 35AD04ShiftRR
      English US 36AD05tt
      English Dvorak35AD04pp
      English Dvorak36AD05yy
      Bulgarian 35AD04Cyrillic_iи
      Bulgarian 36AD05Cyrillic_shaш

      XKB doesn't do two-step keyboard layout translation like Windows. For this reason, binding keyboard shortcuts across keyboard layouts quickly becomes ugly. Further, each major UI library (such as Qt or GTK) and many major softwares (such as Firefox, LibreOffice) has its own approach. Usually developed through trial, error and pain. The common approach is to search all installed keyboard layouts and find some that is latin. Then invoke keyboard shortcut using that layout. That is, if current layout is Bulgarian:
      • notice that current layout is not latin
      • search installed layouts to find a latin one
      • map pressed key to a latin char using that layout
      • invoke keyboard shortcut
      The details of how it's done differ across libraries and softwares. For example:
      • If currently pressed key produces latin keyval, some are happy with that and will not search for other layouts. Others do search anyway. This often results in multiple keys invoking the same shortcut (when there are multiple layouts with desired latin key in different positions). One example of affected software is 'gedit'.
      • When they do search, some search all layouts, others search only the previous layouts (and insist that latin layout is installed before non-latin), some search for a first match, some search for the "most latin" layout, etc.
      To my understanding, no matter which of these dark magics is chosen, this always results in ugly corner cases, band-aided with dirty workarounds which fix something while breaking something else. For an example of how other software deals with all that mess, see QXcbKeyboard::lookupLatinKeysym() in Qt.
    • setLocationState

      void setLocationState(Event event, long eventPtr)
    • setOrientation

      void setOrientation(boolean create)
    • setTabGroupFocus

      boolean setTabGroupFocus(boolean next)
    • setTabItemFocus

      boolean setTabItemFocus(boolean next)
    • shellMapProc

      long shellMapProc(long handle, long arg0, long user_data)
    • sizeAllocateProc

      long sizeAllocateProc(long handle, long arg0, long user_data)
    • sizeRequestProc

      long sizeRequestProc(long handle, long arg0, long user_data)
    • snapshotToDraw

      void snapshotToDraw(long handle, long snapshot)
      Converts an incoming snapshot into a gtk_draw() call, complete with a Cairo context.
      Parameters:
      handle - the widget receiving the snapshot
      snapshot - the actual GtkSnapshot
    • gtk_widget_get_window

      long gtk_widget_get_window(long widget)
    • gtk_widget_get_surface

      long gtk_widget_get_surface(long widget)
    • gdk_window_get_size

      void gdk_window_get_size(long drawable, int[] width, int[] height)
    • gdk_surface_get_size

      void gdk_surface_get_size(long surface, int[] width, int[] height)
    • gdk_event_free

      void gdk_event_free(long event)
      GTK4 does not hand out copies of events anymore, only references. Call gdk_event_free() on GTK3 and g_object_unref() on GTK4.
      Parameters:
      event - the event to be freed
    • gdk_event_get_surface_or_window

      long gdk_event_get_surface_or_window(long event)
      Wrapper function for gdk_event_get_surface() on GTK4, and gdk_event_get_window() on GTK3.
      Parameters:
      event - the event whose window or surface to fetch
      Returns:
      the GdkWindow or GdkSurface associated with the event
    • gdk_event_get_state

      int gdk_event_get_state(long event)
      Wrapper function for gdk_event_get_state()
      Parameters:
      event - pointer to the GdkEvent.
      Returns:
      the keymask to be used with constants like OS.GDK_SHIFT_MASK / OS.GDK_CONTROL_MASK / OS.GDK_MOD1_MASK etc..
    • gtk_box_new

      long gtk_box_new(int orientation, boolean homogeneous, int spacing)
    • gtk_box_set_child_packing

      void gtk_box_set_child_packing(long box, long child, boolean expand, boolean fill, int padding, int pack_type)
    • gtk_box_pack_end

      void gtk_box_pack_end(long box, long child, boolean expand, boolean fill, int padding)
    • gdk_pointer_grab

      int gdk_pointer_grab(long gdkResource, int grab_ownership, boolean owner_events, int event_mask, long confine_to, long cursor, int time_)
    • gdk_pointer_ungrab

      void gdk_pointer_ungrab(long gdkResource, int time_)
    • GdkSeatGrabPrepareFunc

      static long GdkSeatGrabPrepareFunc(long gdkSeat, long gdkResource, long userData_gdkResource)
    • toString

      public String toString()
      Returns a string containing a concise, human-readable description of the receiver.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the receiver
    • topHandle

      long topHandle()
    • timerProc

      long timerProc(long widget)
    • translateTraversal

      boolean translateTraversal(int event)
    • enterMotionProc

      void enterMotionProc(long controller, double x, double y, long user_data)
    • scrollProc

      boolean scrollProc(long controller, double dx, double dy, long user_data)
    • focusProc

      void focusProc(long controller, long user_data)
    • windowActiveProc

      void windowActiveProc(long handle, long user_data)
    • keyPressReleaseProc

      boolean keyPressReleaseProc(long controller, int keyval, int keycode, int state, long user_data)
    • gesturePressReleaseProc

      void gesturePressReleaseProc(long gesture, int n_press, double x, double y, long user_data)
    • leaveProc

      void leaveProc(long controller, long handle, long user_data)
    • notifyProc

      long notifyProc(long object, long arg0, long user_data)
    • notifyState

      long notifyState(long object, long argo0)
    • windowProc

      long windowProc(long handle, long user_data)
    • windowProc

      long windowProc(long handle, long arg0, long user_data)
    • windowProc

      long windowProc(long handle, long arg0, long arg1, long user_data)
    • windowProc

      long windowProc(long handle, long arg0, long arg1, long arg2, long user_data)
    • windowProc

      long windowProc(long handle, long arg0, long arg1, long arg2, long arg3, long user_data)
    • gtk_cell_renderer_get_preferred_size

      void gtk_cell_renderer_get_preferred_size(long cell, long widget, int[] width, int[] height)
    • gtk_widget_get_preferred_size

      void gtk_widget_get_preferred_size(long widget, GtkRequisition requisition)
    • gtk_container_get_border_width_or_margin

      int gtk_container_get_border_width_or_margin(long handle)
      Retrieves the amount of space around the outside of the container. On GTK3: this is done using gtk_container_get_border_width. On GTK4: this is done by returning the max margin on any side.
      Returns:
      amount of space around the outside of the container.
    • gtk_container_set_border_width

      void gtk_container_set_border_width(long handle, int border_width)
      Sets the border width of the container to all sides of the container.
    • setToolTipText

      void setToolTipText(long tipWidget, String string)
    • gtk_widget_size_allocate

      void gtk_widget_size_allocate(long widget, GtkAllocation allocation, int baseline)
    • notifyCreationTracker

      void notifyCreationTracker()
    • notifyDisposalTracker

      void notifyDisposalTracker()
    • gtk_widget_hide

      void gtk_widget_hide(long widget)
    • gtk_widget_show

      void gtk_widget_show(long widget)