From f664d297f7bb009784868bf3fcf0b3e3bb9a646b Mon Sep 17 00:00:00 2001 From: Felipe Heidrich Date: Tue, 30 Jun 2009 22:00:12 +0000 Subject: *** empty log message *** --- .../gtk/org/eclipse/swt/widgets/Button.java | 836 ---- .../gtk/org/eclipse/swt/widgets/Canvas.java | 407 -- .../gtk/org/eclipse/swt/widgets/Caret.java | 515 --- .../gtk/org/eclipse/swt/widgets/ColorDialog.java | 182 - .../gtk/org/eclipse/swt/widgets/Combo.java | 2241 ---------- .../gtk/org/eclipse/swt/widgets/Composite.java | 1438 ------ .../gtk/org/eclipse/swt/widgets/Control.java | 4588 -------------------- .../gtk/org/eclipse/swt/widgets/DateTime.java | 1103 ----- .../gtk/org/eclipse/swt/widgets/Decorations.java | 752 ---- .../org/eclipse/swt/widgets/DirectoryDialog.java | 339 -- .../gtk/org/eclipse/swt/widgets/Display.java | 4212 ------------------ .../gtk/org/eclipse/swt/widgets/ExpandBar.java | 728 ---- .../gtk/org/eclipse/swt/widgets/ExpandItem.java | 631 --- .../gtk/org/eclipse/swt/widgets/FileDialog.java | 731 ---- .../gtk/org/eclipse/swt/widgets/FontDialog.java | 243 -- .../gtk/org/eclipse/swt/widgets/Group.java | 292 -- .../gtk/org/eclipse/swt/widgets/IME.java | 443 -- .../gtk/org/eclipse/swt/widgets/ImageList.java | 154 - .../gtk/org/eclipse/swt/widgets/Label.java | 589 --- .../gtk/org/eclipse/swt/widgets/Link.java | 740 ---- .../gtk/org/eclipse/swt/widgets/List.java | 1594 ------- .../gtk/org/eclipse/swt/widgets/Menu.java | 981 ----- .../gtk/org/eclipse/swt/widgets/MenuItem.java | 883 ---- .../gtk/org/eclipse/swt/widgets/MessageBox.java | 238 - .../gtk/org/eclipse/swt/widgets/ProgressBar.java | 302 -- .../gtk/org/eclipse/swt/widgets/Sash.java | 441 -- .../gtk/org/eclipse/swt/widgets/Scale.java | 377 -- .../gtk/org/eclipse/swt/widgets/ScrollBar.java | 768 ---- .../gtk/org/eclipse/swt/widgets/Scrollable.java | 384 -- .../gtk/org/eclipse/swt/widgets/Shell.java | 2195 ---------- .../gtk/org/eclipse/swt/widgets/Slider.java | 614 --- .../gtk/org/eclipse/swt/widgets/Spinner.java | 1203 ----- .../gtk/org/eclipse/swt/widgets/TabFolder.java | 733 ---- .../gtk/org/eclipse/swt/widgets/TabItem.java | 390 -- .../gtk/org/eclipse/swt/widgets/Table.java | 3543 --------------- .../gtk/org/eclipse/swt/widgets/TableColumn.java | 702 --- .../gtk/org/eclipse/swt/widgets/TableItem.java | 1324 ------ .../gtk/org/eclipse/swt/widgets/Text.java | 2152 --------- .../gtk/org/eclipse/swt/widgets/ToolBar.java | 551 --- .../gtk/org/eclipse/swt/widgets/ToolItem.java | 1091 ----- .../gtk/org/eclipse/swt/widgets/ToolTip.java | 818 ---- .../gtk/org/eclipse/swt/widgets/Tracker.java | 996 ----- .../gtk/org/eclipse/swt/widgets/TrayItem.java | 591 --- .../gtk/org/eclipse/swt/widgets/Tree.java | 3385 --------------- .../gtk/org/eclipse/swt/widgets/TreeColumn.java | 697 --- .../gtk/org/eclipse/swt/widgets/TreeItem.java | 1769 -------- .../gtk/org/eclipse/swt/widgets/Widget.java | 1617 ------- 47 files changed, 51503 deletions(-) delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java delete mode 100644 bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets') diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java deleted file mode 100644 index 41802dc836..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java +++ /dev/null @@ -1,836 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class represent a selectable user interface object that - * issues notification when pressed and released. - *
- *
Styles:
- *
ARROW, CHECK, PUSH, RADIO, TOGGLE, FLAT
- *
UP, DOWN, LEFT, RIGHT, CENTER
- *
Events:
- *
Selection
- *
- *

- * Note: Only one of the styles ARROW, CHECK, PUSH, RADIO, and TOGGLE - * may be specified. - *

- * Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified. - *

- * Note: Only one of the styles UP, DOWN, LEFT, and RIGHT may be specified - * when the ARROW style is specified. - *

- * IMPORTANT: This class is intended to be subclassed only - * within the SWT implementation. - *

- * - * @see Button snippets - * @see SWT Example: ControlExample - * @see Sample code and further information - * @noextend This class is not intended to be subclassed by clients. - */ -public class Button extends Control { - int /*long*/ boxHandle, labelHandle, imageHandle, arrowHandle, groupHandle; - boolean selected, grayed; - ImageList imageList; - Image image; - String text; - -/** - * 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. - *

- * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException - * @exception SWTException - * - * @see SWT#ARROW - * @see SWT#CHECK - * @see SWT#PUSH - * @see SWT#RADIO - * @see SWT#TOGGLE - * @see SWT#FLAT - * @see SWT#UP - * @see SWT#DOWN - * @see SWT#LEFT - * @see SWT#RIGHT - * @see SWT#CENTER - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Button (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -static int checkStyle (int style) { - style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0); - if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) { - return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0); - } - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0); - } - if ((style & SWT.ARROW) != 0) { - style |= SWT.NO_FOCUS; - return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0); - } - return style; -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected by the user, by sending - * it one of the messages defined in the SelectionListener - * interface. - *

- * widgetSelected is called when the control is selected by the user. - * widgetDefaultSelected is not called. - *

- * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException - * @exception SWTException - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener (SelectionListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Selection,typedListener); - addListener (SWT.DefaultSelection,typedListener); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; - if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - /* - * Feature in GTK, GtkCheckButton and GtkRadioButton allocate - * only the minimum size necessary for its child. This causes the child - * alignment to fail. The fix is to set the child size to the size - * of the button. - */ - forceResize (); - int [] reqWidth = null, reqHeight = null; - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - reqWidth = new int [1]; - reqHeight = new int [1]; - OS.gtk_widget_get_size_request (boxHandle, reqWidth, reqHeight); - OS.gtk_widget_set_size_request (boxHandle, -1, -1); - } - Point size = computeNativeSize (handle, wHint, hHint, changed); - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - OS.gtk_widget_set_size_request (boxHandle, reqWidth [0], reqHeight [0]); - } - if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) { - if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_CAN_DEFAULT) != 0) { - int /*long*/ [] buffer = new int /*long*/ [1]; - GtkBorder border = new GtkBorder (); - OS.gtk_widget_style_get (handle, OS.default_border, buffer, 0); - if (buffer[0] != 0) { - OS.memmove (border, buffer[0], GtkBorder.sizeof); - } else { - /* Use the GTK+ default value of 1 for each. */ - border.left = border.right = border.top = border.bottom = 1; - } - if (wHint != SWT.DEFAULT) size.x += border.left + border.right; - if (hHint != SWT.DEFAULT) size.y += border.top + border.bottom; - } - } - return size; -} - -void createHandle (int index) { - state |= HANDLE; - if ((style & (SWT.PUSH | SWT.TOGGLE)) == 0) state |= THEME_BACKGROUND; - int bits = SWT.ARROW | SWT.TOGGLE | SWT.CHECK | SWT.RADIO | SWT.PUSH; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - switch (style & bits) { - case SWT.ARROW: - int arrow_type = OS.GTK_ARROW_UP; - if ((style & SWT.UP) != 0) arrow_type = OS.GTK_ARROW_UP; - if ((style & SWT.DOWN) != 0) arrow_type = OS.GTK_ARROW_DOWN; - if ((style & SWT.LEFT) != 0) arrow_type = OS.GTK_ARROW_LEFT; - if ((style & SWT.RIGHT) != 0) arrow_type = OS.GTK_ARROW_RIGHT; - handle = OS.gtk_button_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - arrowHandle = OS.gtk_arrow_new (arrow_type, OS.GTK_SHADOW_OUT); - if (arrowHandle == 0) error (SWT.ERROR_NO_HANDLES); - break; - case SWT.TOGGLE: - handle = OS.gtk_toggle_button_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - break; - case SWT.CHECK: - handle = OS.gtk_check_button_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - break; - case SWT.RADIO: - /* - * Feature in GTK. In GTK, radio button must always be part of - * a radio button group. In a GTK radio group, one button is always - * selected. This means that it is not possible to have a single - * radio button that is unselected. This is necessary to allow - * applications to implement their own radio behavior or use radio - * buttons outside of radio groups. The fix is to create a hidden - * radio button for each radio button we create and add them - * to the same group. This allows the visible button to be - * unselected. - */ - groupHandle = OS.gtk_radio_button_new (0); - if (groupHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.g_object_ref (groupHandle); - OS.gtk_object_sink (groupHandle); - handle = OS.gtk_radio_button_new (OS.gtk_radio_button_get_group (groupHandle)); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - break; - case SWT.PUSH: - default: - handle = OS.gtk_button_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_CAN_DEFAULT); - break; - } - if ((style & SWT.ARROW) != 0) { - OS.gtk_container_add (handle, arrowHandle); - } else { - boxHandle = OS.gtk_hbox_new (false, 4); - if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); - labelHandle = OS.gtk_label_new_with_mnemonic (null); - if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); - imageHandle = OS.gtk_image_new (); - if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (handle, boxHandle); - OS.gtk_container_add (boxHandle, imageHandle); - OS.gtk_container_add (boxHandle, labelHandle); - } - OS.gtk_container_add (fixedHandle, handle); - - if ((style & SWT.ARROW) != 0) return; - _setAlignment (style & (SWT.LEFT | SWT.CENTER | SWT.RIGHT)); -} - -void createWidget (int index) { - super.createWidget (index); - text = ""; -} - -void deregister () { - super.deregister (); - if (boxHandle != 0) display.removeWidget (boxHandle); - if (labelHandle != 0) display.removeWidget (labelHandle); - if (imageHandle != 0) display.removeWidget (imageHandle); - if (arrowHandle != 0) display.removeWidget (arrowHandle); -} - -int /*long*/ fontHandle () { - if (labelHandle != 0) return labelHandle; - return super.fontHandle (); -} - -/** - * Returns a value which describes the position of the - * text or image in the receiver. The value will be one of - * LEFT, RIGHT or CENTER - * unless the receiver is an ARROW button, in - * which case, the alignment will indicate the direction of - * the arrow (one of LEFT, RIGHT, - * UP or DOWN). - * - * @return the alignment - * - * @exception SWTException - */ -public int getAlignment () { - checkWidget (); - if ((style & SWT.ARROW) != 0) { - if ((style & SWT.UP) != 0) return SWT.UP; - if ((style & SWT.DOWN) != 0) return SWT.DOWN; - if ((style & SWT.LEFT) != 0) return SWT.LEFT; - if ((style & SWT.RIGHT) != 0) return SWT.RIGHT; - return SWT.UP; - } - if ((style & SWT.LEFT) != 0) return SWT.LEFT; - if ((style & SWT.CENTER) != 0) return SWT.CENTER; - if ((style & SWT.RIGHT) != 0) return SWT.RIGHT; - return SWT.LEFT; -} - -/** - * Returns true if the receiver is grayed, - * and false otherwise. When the widget does not have - * the CHECK style, return false. - * - * @return the grayed state of the checkbox - * - * @exception SWTException - * - * @since 3.4 - */ -public boolean getGrayed () { - checkWidget(); - if ((style & SWT.CHECK) == 0) return false; - return grayed; -} - -/** - * Returns the receiver's image if it has one, or null - * if it does not. - * - * @return the receiver's image - * - * @exception SWTException - */ -public Image getImage () { - checkWidget (); - return image; -} - -String getNameText () { - return getText (); -} - -/** - * Returns true if the receiver is selected, - * and false otherwise. - *

- * When the receiver is of type CHECK or RADIO, - * it is selected when it is checked. When it is of type TOGGLE, - * it is selected when it is pushed in. If the receiver is of any other type, - * this method returns false. - * - * @return the selection state - * - * @exception SWTException

- */ -public boolean getSelection () { - checkWidget (); - if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false; - return OS.gtk_toggle_button_get_active (handle); -} - -/** - * Returns the receiver's text, which will be an empty - * string if it has never been set or if the receiver is - * an ARROW button. - * - * @return the receiver's text - * - * @exception SWTException - */ -public String getText () { - checkWidget(); - if ((style & SWT.ARROW) != 0) return ""; - return text; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_button_press_event (widget, event); - if (result != 0) return result; - if ((style & SWT.RADIO) != 0) selected = getSelection (); - return result; -} - -int /*long*/ gtk_clicked (int /*long*/ widget) { - if ((style & SWT.RADIO) != 0) { - if ((parent.getStyle () & SWT.NO_RADIO_GROUP) != 0) { - setSelection (!selected); - } else { - selectRadio (); - } - } else { - if ((style & SWT.CHECK) != 0) { - if (grayed) { - if (OS.gtk_toggle_button_get_active (handle)) { - OS.gtk_toggle_button_set_inconsistent (handle, true); - } else { - OS.gtk_toggle_button_set_inconsistent (handle, false); - } - } - } - } - postEvent (SWT.Selection); - return 0; -} - -int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_focus_in_event (widget, event); - // widget could be disposed at this point - if (handle == 0) return 0; - if ((style & SWT.PUSH) != 0 && OS.GTK_WIDGET_HAS_DEFAULT (handle)) { - Decorations menuShell = menuShell (); - menuShell.defaultButton = this; - } - return result; -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_focus_out_event (widget, event); - // widget could be disposed at this point - if (handle == 0) return 0; - if ((style & SWT.PUSH) != 0 && !OS.GTK_WIDGET_HAS_DEFAULT (handle)) { - Decorations menuShell = menuShell (); - if (menuShell.defaultButton == this) { - menuShell.defaultButton = null; - } - } - return result; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_key_press_event (widget, event); - if (result != 0) return result; - if ((style & SWT.RADIO) != 0) selected = getSelection (); - return result; -} - -void hookEvents () { - super.hookEvents(); - OS.g_signal_connect_closure (handle, OS.clicked, display.closures [CLICKED], false); - if (labelHandle != 0) { - OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); - } -} - -boolean isDescribedByLabel () { - return false; -} - -boolean mnemonicHit (char key) { - if (labelHandle == 0) return false; - boolean result = super.mnemonicHit (labelHandle, key); - if (result) setFocus (); - return result; -} - -boolean mnemonicMatch (char key) { - if (labelHandle == 0) return false; - return mnemonicMatch (labelHandle, key); -} - -void register () { - super.register (); - if (boxHandle != 0) display.addWidget (boxHandle, this); - if (labelHandle != 0) display.addWidget (labelHandle, this); - if (imageHandle != 0) display.addWidget (imageHandle, this); - if (arrowHandle != 0) display.addWidget (arrowHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - boxHandle = imageHandle = labelHandle = arrowHandle = 0; -} - -void releaseWidget () { - super.releaseWidget (); - if (groupHandle != 0) OS.g_object_unref (groupHandle); - groupHandle = 0; - if (imageList != null) imageList.dispose (); - imageList = null; - image = null; - text = null; -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected by the user. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException - * @exception SWTException - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener (SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Selection, listener); - eventTable.unhook (SWT.DefaultSelection,listener); -} - -void resizeHandle (int width, int height) { - super.resizeHandle (width, height); - /* - * Feature in GTK, GtkCheckButton and GtkRadioButton allocate - * only the minimum size necessary for its child. This causes the child - * alignment to fail. The fix is to set the child size to the size - * of the button. - */ - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - OS.gtk_widget_set_size_request (boxHandle, width, -1); - } -} - -void selectRadio () { - /* - * This code is intentionally commented. When two groups - * of radio buttons with the same parent are separated by - * another control, the correct behavior should be that - * the two groups act independently. This is consistent - * with radio tool and menu items. The commented code - * implements this behavior. - */ -// int index = 0; -// Control [] children = parent._getChildren (); -// while (index < children.length && children [index] != this) index++; -// int i = index - 1; -// while (i >= 0 && children [i].setRadioSelection (false)) --i; -// int j = index + 1; -// while (j < children.length && children [j].setRadioSelection (false)) j++; -// setSelection (true); - Control [] children = parent._getChildren (); - for (int i=0; iLEFT, RIGHT or CENTER - * unless the receiver is an ARROW button, in - * which case, the argument indicates the direction of - * the arrow (one of LEFT, RIGHT, - * UP or DOWN). - * - * @param alignment the new alignment - * - * @exception SWTException - */ -public void setAlignment (int alignment) { - checkWidget (); - _setAlignment (alignment); -} - -void _setAlignment (int alignment) { - if ((style & SWT.ARROW) != 0) { - if ((style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) == 0) return; - style &= ~(SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT); - style |= alignment & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT); - int arrow_type = OS.GTK_ARROW_UP; - boolean isRTL = (style & SWT.RIGHT_TO_LEFT) != 0; - switch (alignment) { - case SWT.UP: arrow_type = OS.GTK_ARROW_UP; break; - case SWT.DOWN: arrow_type = OS.GTK_ARROW_DOWN; break; - case SWT.LEFT: arrow_type = isRTL ? OS.GTK_ARROW_RIGHT : OS.GTK_ARROW_LEFT; break; - case SWT.RIGHT: arrow_type = isRTL ? OS.GTK_ARROW_LEFT : OS.GTK_ARROW_RIGHT; break; - } - OS.gtk_arrow_set (arrowHandle, arrow_type, OS.GTK_SHADOW_OUT); - return; - } - if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return; - style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER); - style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); - /* Alignment not honoured when image and text are visible */ - boolean bothVisible = OS.GTK_WIDGET_VISIBLE (labelHandle) && OS.GTK_WIDGET_VISIBLE (imageHandle); - if (bothVisible) { - if ((style & (SWT.RADIO | SWT.CHECK)) != 0) alignment = SWT.LEFT; - if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) alignment = SWT.CENTER; - } - if ((alignment & SWT.LEFT) != 0) { - if (bothVisible) { - OS.gtk_box_set_child_packing (boxHandle, labelHandle, false, false, 0, OS.GTK_PACK_START); - OS.gtk_box_set_child_packing (boxHandle, imageHandle, false, false, 0, OS.GTK_PACK_START); - } - OS.gtk_misc_set_alignment (labelHandle, 0.0f, 0.5f); - OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_LEFT); - OS.gtk_misc_set_alignment (imageHandle, 0.0f, 0.5f); - return; - } - if ((alignment & SWT.CENTER) != 0) { - if (bothVisible) { - OS.gtk_box_set_child_packing (boxHandle, labelHandle, true, true, 0, OS.GTK_PACK_END); - OS.gtk_box_set_child_packing (boxHandle, imageHandle, true, true, 0, OS.GTK_PACK_START); - OS.gtk_misc_set_alignment (labelHandle, 0f, 0.5f); - OS.gtk_misc_set_alignment (imageHandle, 1f, 0.5f); - } else { - OS.gtk_misc_set_alignment (labelHandle, 0.5f, 0.5f); - OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_CENTER); - OS.gtk_misc_set_alignment (imageHandle, 0.5f, 0.5f); - } - return; - } - if ((alignment & SWT.RIGHT) != 0) { - if (bothVisible) { - OS.gtk_box_set_child_packing (boxHandle, labelHandle, false, false, 0, OS.GTK_PACK_END); - OS.gtk_box_set_child_packing (boxHandle, imageHandle, false, false, 0, OS.GTK_PACK_END); - } - OS.gtk_misc_set_alignment (labelHandle, 1.0f, 0.5f); - OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_RIGHT); - OS.gtk_misc_set_alignment (imageHandle, 1.0f, 0.5f); - return; - } -} - -void setBackgroundColor (GdkColor color) { - super.setBackgroundColor (color); - setBackgroundColor(fixedHandle, color); - if (labelHandle != 0) setBackgroundColor(labelHandle, color); - if (imageHandle != 0) setBackgroundColor(imageHandle, color); -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - if (labelHandle != 0) OS.gtk_widget_modify_font (labelHandle, font); - if (imageHandle != 0) OS.gtk_widget_modify_font (imageHandle, font); -} - -boolean setRadioSelection (boolean value) { - if ((style & SWT.RADIO) == 0) return false; - if (getSelection () != value) { - setSelection (value); - postEvent (SWT.Selection); - } - return true; -} - -void setForegroundColor (GdkColor color) { - super.setForegroundColor (color); - setForegroundColor (fixedHandle, color); - if (labelHandle != 0) setForegroundColor (labelHandle, color); - if (imageHandle != 0) setForegroundColor (imageHandle, color); -} - -/** - * Sets the grayed state of the receiver. This state change - * only applies if the control was created with the SWT.CHECK - * style. - * - * @param grayed the new grayed state - * - * @exception SWTException - * - * @since 3.4 - */ -public void setGrayed (boolean grayed) { - checkWidget(); - if ((style & SWT.CHECK) == 0) return; - this.grayed = grayed; - if (grayed && OS.gtk_toggle_button_get_active (handle)) { - OS.gtk_toggle_button_set_inconsistent (handle, true); - } else { - OS.gtk_toggle_button_set_inconsistent (handle, false); - } -} - -/** - * Sets the receiver's image to the argument, which may be - * null indicating that no image should be displayed. - *

- * Note that a Button can display an image and text simultaneously - * on Windows (starting with XP), GTK+ and OSX. On other platforms, - * a Button that has an image and text set into it will display the - * image or text that was set most recently. - *

- * @param image the image to display on the receiver (may be null) - * - * @exception IllegalArgumentException - * @exception SWTException - */ -public void setImage (Image image) { - checkWidget (); - if ((style & SWT.ARROW) != 0) return; - if (imageList != null) imageList.dispose (); - imageList = null; - if (image != null) { - if (image.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - imageList = new ImageList (); - int imageIndex = imageList.add (image); - int /*long*/ pixbuf = imageList.getPixbuf (imageIndex); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); - if (text.length () == 0) OS.gtk_widget_hide (labelHandle); - OS.gtk_widget_show (imageHandle); - } else { - OS.gtk_image_set_from_pixbuf (imageHandle, 0); - OS.gtk_widget_show (labelHandle); - OS.gtk_widget_hide (imageHandle); - } - this.image = image; - _setAlignment (style); -} - -void setOrientation () { - super.setOrientation (); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - if (boxHandle != 0) OS.gtk_widget_set_direction (boxHandle, OS.GTK_TEXT_DIR_RTL); - if (labelHandle != 0) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL); - if (imageHandle != 0) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL); - if (arrowHandle != 0) { - switch (style & (SWT.LEFT | SWT.RIGHT)) { - case SWT.LEFT: OS.gtk_arrow_set (arrowHandle, OS.GTK_ARROW_RIGHT, OS.GTK_SHADOW_OUT); break; - case SWT.RIGHT: OS.gtk_arrow_set (arrowHandle, OS.GTK_ARROW_LEFT, OS.GTK_SHADOW_OUT); break; - } - } - } -} - -/** - * Sets the selection state of the receiver, if it is of type CHECK, - * RADIO, or TOGGLE. - * - *

- * When the receiver is of type CHECK or RADIO, - * it is selected when it is checked. When it is of type TOGGLE, - * it is selected when it is pushed in. - * - * @param selected the new selection state - * - * @exception SWTException

- */ -public void setSelection (boolean selected) { - checkWidget(); - if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); - OS.gtk_toggle_button_set_active (handle, selected); - if ((style & SWT.CHECK) != 0) { - if (selected && grayed) { - OS.gtk_toggle_button_set_inconsistent (handle, true); - } else { - OS.gtk_toggle_button_set_inconsistent (handle, false); - } - } - if ((style & SWT.RADIO) != 0) OS.gtk_toggle_button_set_active (groupHandle, !selected); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); -} - -/** - * Sets the receiver's text. - *

- * This method sets the button label. The label may include - * the mnemonic character but must not contain line delimiters. - *

- *

- * Mnemonics are indicated by an '&' that causes the next - * character to be the mnemonic. When the user presses a - * key sequence that matches the mnemonic, a selection - * event occurs. On most platforms, the mnemonic appears - * underlined but may be emphasized in a platform specific - * manner. The mnemonic indicator character '&' can be - * escaped by doubling it in the string, causing a single - * '&' to be displayed. - *

- * Note that a Button can display an image and text simultaneously - * on Windows (starting with XP), GTK+ and OSX. On other platforms, - * a Button that has an image and text set into it will display the - * image or text that was set most recently. - *

- * @param string the new text - * - * @exception IllegalArgumentException - * @exception SWTException - */ -public void setText (String string) { - checkWidget (); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.ARROW) != 0) return; - text = string; - char [] chars = fixMnemonic (string); - byte [] buffer = Converter.wcsToMbcs (null, chars, true); - OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer); - if (image == null) OS.gtk_widget_hide (imageHandle); - OS.gtk_widget_show (labelHandle); - _setAlignment (style); -} - -void showWidget () { - super.showWidget (); - if (boxHandle != 0) OS.gtk_widget_show (boxHandle); - if (labelHandle != 0) OS.gtk_widget_show (labelHandle); - if (arrowHandle != 0) OS.gtk_widget_show (arrowHandle); -} - -int traversalCode (int key, GdkEventKey event) { - int code = super.traversalCode (key, event); - if ((style & SWT.ARROW) != 0) code &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS); - if ((style & SWT.RADIO) != 0) code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS; - return code; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java deleted file mode 100644 index ea6a1495d8..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java +++ /dev/null @@ -1,407 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.*; - -/** - * Instances of this class provide a surface for drawing - * arbitrary graphics. - *
- *
Styles:
- *
(none)
- *
Events:
- *
(none)
- *
- *

- * This class may be subclassed by custom control implementors - * who are building controls that are not constructed - * from aggregates of other controls. That is, they are either - * painted using SWT graphics calls or are handled by native - * methods. - *

- * - * @see Composite - * @see Canvas snippets - * @see SWT Example: ControlExample - * @see Sample code and further information - */ -public class Canvas extends Composite { - Caret caret; - IME ime; - -Canvas () {} - -/** - * 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. - *

- * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException - * @exception SWTException - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Canvas (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -/** - * Fills the interior of the rectangle specified by the arguments, - * with the receiver's background. - * - * @param gc the gc where the rectangle is to be filled - * @param x the x coordinate of the rectangle to be filled - * @param y the y coordinate of the rectangle to be filled - * @param width the width of the rectangle to be filled - * @param height the height of the rectangle to be filled - * - * @exception IllegalArgumentException - * @exception SWTException - * - * @since 3.2 - */ -public void drawBackground (GC gc, int x, int y, int width, int height) { - checkWidget (); - if (gc == null) error (SWT.ERROR_NULL_ARGUMENT); - if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - super.drawBackground (gc, x, y, width, height); -} - -/** - * Returns the caret. - *

- * The caret for the control is automatically hidden - * and shown when the control is painted or resized, - * when focus is gained or lost and when an the control - * is scrolled. To avoid drawing on top of the caret, - * the programmer must hide and show the caret when - * drawing in the window any other time. - *

- * - * @return the caret for the receiver, may be null - * - * @exception SWTException - */ -public Caret getCaret () { - checkWidget(); - return caret; -} - -Point getIMCaretPos () { - if (caret == null) return super.getIMCaretPos (); - return new Point (caret.x, caret.y); -} - -/** - * Returns the IME. - * - * @return the IME - * - * @exception SWTException - * - * @since 3.4 - */ -public IME getIME () { - checkWidget (); - return ime; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - if (ime != null) { - int /*long*/ result = ime.gtk_button_press_event (widget, event); - if (result != 0) return result; - } - return super.gtk_button_press_event (widget, event); -} - -int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ text) { - if (ime != null) { - int /*long*/ result = ime.gtk_commit (imcontext, text); - if (result != 0) return result; - } - return super.gtk_commit (imcontext, text); -} - -int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ event) { - if ((state & OBSCURED) != 0) return 0; - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - int /*long*/ result = super.gtk_expose_event (widget, event); - if (isFocus) caret.setFocus (); - return result; -} - -int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_focus_in_event (widget, event); - if (caret != null) caret.setFocus (); - return result; -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_focus_out_event (widget, event); - if (caret != null) caret.killFocus (); - return result; -} - -int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) { - if (ime != null) { - int /*long*/ result = ime.gtk_preedit_changed (imcontext); - if (result != 0) return result; - } - return super.gtk_preedit_changed (imcontext); -} - -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean all, boolean trim) { - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - super.redrawWidget (x, y, width, height, redrawAll, all, trim); - if (isFocus) caret.setFocus (); -} - -void releaseChildren (boolean destroy) { - if (caret != null) { - caret.release (false); - caret = null; - } - if (ime != null) { - ime.release (false); - ime = null; - } - super.releaseChildren (destroy); -} - -/** - * Scrolls a rectangular area of the receiver by first copying - * the source area to the destination and then causing the area - * of the source which is not covered by the destination to - * be repainted. Children that intersect the rectangle are - * optionally moved during the operation. In addition, outstanding - * paint events are flushed before the source area is copied to - * ensure that the contents of the canvas are drawn correctly. - * - * @param destX the x coordinate of the destination - * @param destY the y coordinate of the destination - * @param x the x coordinate of the source - * @param y the y coordinate of the source - * @param width the width of the area - * @param height the height of the area - * @param all trueif children should be scrolled, and false otherwise - * - * @exception SWTException - */ -public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) { - checkWidget(); - if (width <= 0 || height <= 0) return; - if ((style & SWT.MIRRORED) != 0) { - int clientWidth = getClientWidth (); - x = clientWidth - width - x; - destX = clientWidth - width - destX; - } - int deltaX = destX - x, deltaY = destY - y; - if (deltaX == 0 && deltaY == 0) return; - if (!isVisible ()) return; - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - int /*long*/ window = paintWindow (); - int /*long*/ visibleRegion = OS.gdk_drawable_get_visible_region (window); - GdkRectangle srcRect = new GdkRectangle (); - srcRect.x = x; - srcRect.y = y; - srcRect.width = width; - srcRect.height = height; - int /*long*/ copyRegion = OS.gdk_region_rectangle (srcRect); - OS.gdk_region_intersect(copyRegion, visibleRegion); - int /*long*/ invalidateRegion = OS.gdk_region_rectangle (srcRect); - OS.gdk_region_subtract (invalidateRegion, visibleRegion); - OS.gdk_region_offset (invalidateRegion, deltaX, deltaY); - GdkRectangle copyRect = new GdkRectangle(); - OS.gdk_region_get_clipbox (copyRegion, copyRect); - if (copyRect.width != 0 && copyRect.height != 0) { - update (); - } - Control control = findBackgroundControl (); - if (control == null) control = this; - if (control.backgroundImage != null) { - redrawWidget (x, y, width, height, false, false, false); - redrawWidget (destX, destY, width, height, false, false, false); - } else { -// GC gc = new GC (this); -// gc.copyArea (x, y, width, height, destX, destY); -// gc.dispose (); - int /*long*/ gdkGC = OS.gdk_gc_new (window); - OS.gdk_gc_set_exposures (gdkGC, true); - OS.gdk_draw_drawable (window, gdkGC, window, copyRect.x, copyRect.y, copyRect.x + deltaX, copyRect.y + deltaY, copyRect.width, copyRect.height); - OS.g_object_unref (gdkGC); - boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY); - if (disjoint) { - GdkRectangle rect = new GdkRectangle (); - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; - OS.gdk_region_union_with_rect (invalidateRegion, rect); - } else { - GdkRectangle rect = new GdkRectangle (); - if (deltaX != 0) { - int newX = destX - deltaX; - if (deltaX < 0) newX = destX + width; - rect.x = newX; - rect.y = y; - rect.width = Math.abs(deltaX); - rect.height = height; - OS.gdk_region_union_with_rect (invalidateRegion, rect); - } - if (deltaY != 0) { - int newY = destY - deltaY; - if (deltaY < 0) newY = destY + height; - rect.x = x; - rect.y = newY; - rect.width = width; - rect.height = Math.abs(deltaY); - OS.gdk_region_union_with_rect (invalidateRegion, rect); - } - } - OS.gdk_window_invalidate_region(window, invalidateRegion, all); - OS.gdk_region_destroy (visibleRegion); - OS.gdk_region_destroy (copyRegion); - OS.gdk_region_destroy (invalidateRegion); - } - if (all) { - Control [] children = _getChildren (); - for (int i=0; i= Math.max (x, rect.x) && - Math.min(y + height, rect.y + rect.height) >= Math.max (y, rect.y)) { - child.setLocation (rect.x + deltaX, rect.y + deltaY); - } - } - } - if (isFocus) caret.setFocus (); -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - int result = super.setBounds (x, y, width, height, move, resize); - if (isFocus) caret.setFocus (); - return result; -} - -/** - * Sets the receiver's caret. - *

- * The caret for the control is automatically hidden - * and shown when the control is painted or resized, - * when focus is gained or lost and when an the control - * is scrolled. To avoid drawing on top of the caret, - * the programmer must hide and show the caret when - * drawing in the window any other time. - *

- * @param caret the new caret for the receiver, may be null - * - * @exception IllegalArgumentException
    - *
  • ERROR_INVALID_ARGUMENT - if the caret has been disposed
  • - *
- * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public void setCaret (Caret caret) { - checkWidget(); - Caret newCaret = caret; - Caret oldCaret = this.caret; - this.caret = newCaret; - if (hasFocus ()) { - if (oldCaret != null) oldCaret.killFocus (); - if (newCaret != null) { - if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - newCaret.setFocus (); - } - } -} - -public void setFont (Font font) { - checkWidget(); - if (caret != null) caret.setFont (font); - super.setFont (font); -} - -/** - * Sets the receiver's IME. - * - * @param ime the new IME for the receiver, may be null - * - * @exception IllegalArgumentException
    - *
  • ERROR_INVALID_ARGUMENT - if the IME has been disposed
  • - *
- * @exception 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 - */ -public void setIME (IME ime) { - checkWidget (); - if (ime != null && ime.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - this.ime = ime; -} - -void updateCaret () { - int /*long*/ imHandle = imHandle (); - if (imHandle == 0) return; - GdkRectangle rect = new GdkRectangle (); - rect.x = caret.x; - rect.y = caret.y; - rect.width = caret.width; - rect.height = caret.height; - OS.gtk_im_context_set_cursor_location (imHandle, rect); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java deleted file mode 100644 index 8bfa82fd71..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java +++ /dev/null @@ -1,515 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class provide an i-beam that is typically used - * as the insertion point for text. - *
- *
Styles:
- *
(none)
- *
Events:
- *
(none)
- *
- *

- * IMPORTANT: This class is intended to be subclassed only - * within the SWT implementation. - *

- * - * @see Caret snippets - * @see SWT Example: ControlExample, Canvas tab - * @see Sample code and further information - * @noextend This class is not intended to be subclassed by clients. - */ -public class Caret extends Widget { - Canvas parent; - int x, y, width, height; - boolean isVisible, isShowing; - int blinkRate; - Image image; - Font font; - - static final int DEFAULT_WIDTH = 1; - -/** - * 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. - *

- * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the parent is null
  • - *
- * @exception 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 SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Caret (Canvas parent, int style) { - super (parent, style); - this.parent = parent; - createWidget (0); -} - -boolean blinkCaret () { - if (!isVisible) return true; - if (!isShowing) return showCaret (); - if (blinkRate == 0) return true; - return hideCaret (); -} - -void createWidget (int index) { - super.createWidget (index); - blinkRate = display.getCaretBlinkTime (); - isVisible = true; - if (parent.getCaret () == null) { - parent.setCaret (this); - } -} - -boolean drawCaret () { - if (parent == null) return false; - if (parent.isDisposed ()) return false; - int /*long*/ window = parent.paintWindow (); - int /*long*/ gc = OS.gdk_gc_new (window); - GdkColor color = new GdkColor (); - color.red = (short) 0xffff; - color.green = (short) 0xffff; - color.blue = (short) 0xffff; - int /*long*/ colormap = OS.gdk_colormap_get_system (); - OS.gdk_colormap_alloc_color (colormap, color, true, true); - OS.gdk_gc_set_foreground (gc, color); - OS.gdk_gc_set_function (gc, OS.GDK_XOR); - if (image != null && !image.isDisposed() && image.mask == 0) { - int[] width = new int[1]; int[] height = new int[1]; - OS.gdk_drawable_get_size(image.pixmap, width, height); - int nX = x; - if ((parent.style & SWT.MIRRORED) != 0) nX = parent.getClientWidth () - width[0] - nX; - OS.gdk_draw_drawable(window, gc, image.pixmap, 0, 0, nX, y, width[0], height[0]); - } else { - int nWidth = width, nHeight = height; - if (nWidth <= 0) nWidth = DEFAULT_WIDTH; - int nX = x; - if ((parent.style & SWT.MIRRORED) != 0) nX = parent.getClientWidth () - nWidth - nX; - OS.gdk_draw_rectangle (window, gc, 1, nX, y, nWidth, nHeight); - } - OS.g_object_unref (gc); - OS.gdk_colormap_free_colors (colormap, color, 1); - return true; -} - -/** - * Returns a rectangle describing the receiver's size and location - * relative to its parent (or its display if its parent is null). - * - * @return the receiver's bounding rectangle - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public Rectangle getBounds () { - checkWidget(); - if (image != null) { - Rectangle rect = image.getBounds (); - return new Rectangle (x, y, rect.width, rect.height); - } else { - if (width == 0) { - return new Rectangle (x, y, DEFAULT_WIDTH, height); - } - } - return new Rectangle (x, y, width, height); -} - -/** - * Returns the font that the receiver will use to paint textual information. - * - * @return the receiver's font - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public Font getFont () { - checkWidget(); - if (font != null) return font; - return parent.getFont (); -} - -/** - * Returns the image that the receiver will use to paint the caret. - * - * @return the receiver's image - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public Image getImage () { - checkWidget(); - return image; -} - -/** - * Returns a point describing the receiver's location relative - * to its parent (or its display if its parent is null). - * - * @return the receiver's location - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public Point getLocation () { - checkWidget(); - return new Point (x, y); -} - -/** - * Returns the receiver's parent, which must be a Canvas. - * - * @return the receiver's parent - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public Canvas getParent () { - checkWidget(); - return parent; -} - -/** - * Returns a point describing the receiver's size. - * - * @return the receiver's size - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public Point getSize () { - checkWidget(); - if (image != null) { - Rectangle rect = image.getBounds (); - return new Point (rect.width, rect.height); - } else { - if (width == 0) { - return new Point (DEFAULT_WIDTH, height); - } - } - return new Point (width, height); -} - -/** - * Returns true if the receiver is visible, and - * false otherwise. - *

- * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, this method - * may still indicate that it is considered visible even though - * it may not actually be showing. - *

- * - * @return the receiver's visibility state - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public boolean getVisible () { - checkWidget(); - return isVisible; -} - -boolean hideCaret () { - if (!isShowing) return true; - isShowing = false; - return drawCaret (); -} - -/** - * Returns true if the receiver is visible and all - * of the receiver's ancestors are visible and false - * otherwise. - * - * @return the receiver's visibility state - * - * @exception 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 #getVisible - */ -public boolean isVisible () { - checkWidget(); - return isVisible && parent.isVisible () && parent.hasFocus (); -} - -boolean isFocusCaret () { - return this == display.currentCaret; -} - -void killFocus () { - if (display.currentCaret != this) return; - display.setCurrentCaret (null); - if (isVisible) hideCaret (); -} - -void releaseParent () { - super.releaseParent (); - if (this == parent.getCaret ()) parent.setCaret (null); -} - -void releaseWidget () { - super.releaseWidget (); - if (display.currentCaret == this) { - hideCaret (); - display.setCurrentCaret (null); - } - parent = null; - image = null; -} - -/** - * Sets the receiver's size and location to the rectangular - * area specified by the arguments. The x and - * y arguments are relative to the receiver's - * parent (or its display if its parent is null). - * - * @param x the new x coordinate for the receiver - * @param y the new y coordinate for the receiver - * @param width the new width for the receiver - * @param height the new height for the receiver - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public void setBounds (int x, int y, int width, int height) { - checkWidget(); - if (this.x == x && this.y == y && this.width == width && this.height == height) return; - boolean isFocus = isFocusCaret (); - if (isFocus && isVisible) hideCaret (); - this.x = x; this.y = y; - this.width = width; this.height = height; - parent.updateCaret (); - if (isFocus && isVisible) showCaret (); -} - -/** - * Sets the receiver's size and location to the rectangular - * area specified by the argument. The x and - * y fields of the rectangle are relative to - * the receiver's parent (or its display if its parent is null). - * - * @param rect the new bounds for the receiver - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public void setBounds (Rectangle rect) { - checkWidget(); - if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); - setBounds (rect.x, rect.y, rect.width, rect.height); -} - -void setFocus () { - if (display.currentCaret == this) return; - display.setCurrentCaret (this); - if (isVisible) showCaret (); -} - -/** - * Sets the font that the receiver will use to paint textual information - * to the font specified by the argument, or to the default font for that - * kind of control if the argument is null. - * - * @param font the new font (or null) - * - * @exception IllegalArgumentException
    - *
  • ERROR_INVALID_ARGUMENT - if the font has been disposed
  • - *
- * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public void setFont (Font font) { - checkWidget(); - if (font != null && font.isDisposed ()) { - error (SWT.ERROR_INVALID_ARGUMENT); - } - this.font = font; -} - -/** - * Sets the image that the receiver will use to paint the caret - * to the image specified by the argument, or to the default - * which is a filled rectangle if the argument is null - * - * @param image the new image (or null) - * - * @exception IllegalArgumentException
    - *
  • ERROR_INVALID_ARGUMENT - if the image has been disposed
  • - *
- * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public void setImage (Image image) { - checkWidget(); - if (image != null && image.isDisposed ()) { - error (SWT.ERROR_INVALID_ARGUMENT); - } - boolean isFocus = isFocusCaret (); - if (isFocus && isVisible) hideCaret (); - this.image = image; - if (isFocus && isVisible) showCaret (); -} - -/** - * Sets the receiver's location to the point specified by - * the arguments which are relative to the receiver's - * parent (or its display if its parent is null). - * - * @param x the new x coordinate for the receiver - * @param y the new y coordinate for the receiver - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public void setLocation (int x, int y) { - checkWidget(); - setBounds (x, y, width, height); -} - -/** - * Sets the receiver's location to the point specified by - * the argument which is relative to the receiver's - * parent (or its display if its parent is null). - * - * @param location the new location for the receiver - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public void setLocation (Point location) { - checkWidget(); - if (location == null) error (SWT.ERROR_NULL_ARGUMENT); - setLocation (location.x, location.y); -} - -/** - * Sets the receiver's size to the point specified by the arguments. - * - * @param width the new width for the receiver - * @param height the new height for the receiver - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public void setSize (int width, int height) { - checkWidget(); - setBounds (x, y, width, height); -} - -/** - * Sets the receiver's size to the point specified by the argument. - * - * @param size the new extent for the receiver - * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the point is null
  • - *
- * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public void setSize (Point size) { - checkWidget(); - if (size == null) error (SWT.ERROR_NULL_ARGUMENT); - setSize (size.x, size.y); -} - -/** - * Marks the receiver as visible if the argument is true, - * and marks it invisible otherwise. - *

- * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, marking - * it visible may not actually cause it to be displayed. - *

- * - * @param visible the new visibility state - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public void setVisible (boolean visible) { - checkWidget(); - if (visible == isVisible) return; - isVisible = visible; - if (!isFocusCaret ()) return; - if (isVisible) { - showCaret (); - } else { - hideCaret (); - } -} - -boolean showCaret () { - if (isShowing) return true; - isShowing = true; - return drawCaret (); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java deleted file mode 100644 index 257f07af33..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class allow the user to select a color - * from a predefined set of available colors. - *
- *
Styles:
- *
(none)
- *
Events:
- *
(none)
- *
- *

- * IMPORTANT: This class is intended to be subclassed only - * within the SWT implementation. - *

- * - * @see SWT Example: ControlExample, Dialog tab - * @see Sample code and further information - * @noextend This class is not intended to be subclassed by clients. - */ -public class ColorDialog extends Dialog { - RGB rgb; -/** - * Constructs a new instance of this class given only its parent. - * - * @param parent a composite control which will be the parent of the new instance - * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the parent is null
  • - *
- * @exception 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 SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ColorDialog (Shell parent) { - this (parent, SWT.APPLICATION_MODAL); -} -/** - * 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. - *

- * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the parent is null
  • - *
- * @exception 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 SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ColorDialog (Shell parent, int style) { - super (parent, checkStyle (parent, style)); - checkSubclass (); -} - -/** - * Returns the currently selected color in the receiver. - * - * @return the RGB value for the selected color, may be null - * - * @see PaletteData#getRGBs - */ -public RGB getRGB () { - return rgb; -} -/** - * Makes the receiver visible and brings it to the front - * of the display. - * - * @return the selected color, or null if the dialog was - * cancelled, no color was selected, or an error - * occurred - * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- */ -public RGB open () { - byte [] buffer = Converter.wcsToMbcs (null, title, true); - int /*long*/ handle = OS.gtk_color_selection_dialog_new (buffer); - Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - if (parent != null) { - int /*long*/ shellHandle = parent.topHandle (); - OS.gtk_window_set_transient_for (handle, shellHandle); - int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle); - if (pixbufs != 0) { - OS.gtk_window_set_icon_list (handle, pixbufs); - OS.g_list_free (pixbufs); - } - } - OS.gtk_window_set_modal (handle, true); - GtkColorSelectionDialog dialog = new GtkColorSelectionDialog (); - OS.memmove (dialog, handle); - GdkColor color = new GdkColor(); - if (rgb != null) { - color.red = (short)((rgb.red & 0xFF) | ((rgb.red & 0xFF) << 8)); - color.green = (short)((rgb.green & 0xFF) | ((rgb.green & 0xFF) << 8)); - color.blue = (short)((rgb.blue & 0xFF) | ((rgb.blue & 0xFF) << 8)); - OS.gtk_color_selection_set_current_color (dialog.colorsel, color); - } - OS.gtk_color_selection_set_has_palette (dialog.colorsel, true); - display.addIdleProc (); - Dialog oldModal = null; - if (OS.gtk_window_get_modal (handle)) { - oldModal = display.getModalDialog (); - display.setModalDialog (this); - } - int signalId = 0; - int /*long*/ hookId = 0; - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET()); - hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0); - } - int response = OS.gtk_dialog_run (handle); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.g_signal_remove_emission_hook (signalId, hookId); - } - if (OS.gtk_window_get_modal (handle)) { - display.setModalDialog (oldModal); - } - boolean success = response == OS.GTK_RESPONSE_OK; - if (success) { - OS.gtk_color_selection_get_current_color (dialog.colorsel, color); - int red = (color.red >> 8) & 0xFF; - int green = (color.green >> 8) & 0xFF; - int blue = (color.blue >> 8) & 0xFF; - rgb = new RGB (red, green, blue); - } - display.removeIdleProc (); - OS.gtk_widget_destroy (handle); - if (!success) return null; - return rgb; -} -/** - * Sets the receiver's selected color to be the argument. - * - * @param rgb the new RGB value for the selected color, may be - * null to let the platform select a default when - * open() is called - * @see PaletteData#getRGBs - */ -public void setRGB (RGB rgb) { - this.rgb = rgb; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java deleted file mode 100644 index 6e526d3b05..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java +++ /dev/null @@ -1,2241 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class are controls that allow the user - * to choose an item from a list of items, or optionally - * enter a new value by typing it into an editable text - * field. Often, Combos are used in the same place - * where a single selection List widget could - * be used but space is limited. A Combo takes - * less space than a List widget and shows - * similar information. - *

- * Note: Since Combos can contain both a list - * and an editable text field, it is possible to confuse methods - * which access one versus the other (compare for example, - * clearSelection() and deselectAll()). - * The API documentation is careful to indicate either "the - * receiver's list" or the "the receiver's text field" to - * distinguish between the two cases. - *

- * Note that although this class is a subclass of Composite, - * it does not make sense to add children to it, or set a layout on it. - *

- *
- *
Styles:
- *
DROP_DOWN, READ_ONLY, SIMPLE
- *
Events:
- *
DefaultSelection, Modify, Selection, Verify
- *
- *

- * Note: Only one of the styles DROP_DOWN and SIMPLE may be specified. - *

- * IMPORTANT: This class is not intended to be subclassed. - *

- * - * @see List - * @see Combo snippets - * @see SWT Example: ControlExample - * @see Sample code and further information - * @noextend This class is not intended to be subclassed by clients. - */ -public class Combo extends Composite { - int /*long*/ buttonHandle, entryHandle, listHandle, textRenderer, cellHandle, popupHandle; - int lastEventTime, visibleCount = 5; - int /*long*/ gdkEventKey = 0; - int fixStart = -1, fixEnd = -1; - String [] items = new String [0]; - boolean ignoreSelect, lockText; - - /** - * the operating system limit for the number of characters - * that the text field in an instance of this class can hold - */ - public final static int LIMIT; - - /* - * These values can be different on different platforms. - * Therefore they are not initialized in the declaration - * to stop the compiler from inlining. - */ - static { - LIMIT = 0xFFFF; - } - -/** - * 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. - *

- * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the parent is null
  • - *
- * @exception 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 SWT#DROP_DOWN - * @see SWT#READ_ONLY - * @see SWT#SIMPLE - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Combo (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -/** - * Adds the argument to the end of the receiver's list. - * - * @param string the new item - * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the string is null
  • - *
- * @exception 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 #add(String,int) - */ -public void add (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - add (string, items.length); -} - -/** - * Adds the argument to the receiver's list at the given - * zero-relative index. - *

- * Note: To add an item at the end of the list, use the - * result of calling getItemCount() as the - * index or use add(String). - *

- * - * @param string the new item - * @param index the index for the item - * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the string is null
  • - *
  • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)
  • - *
- * @exception 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 #add(String) - */ -public void add (String string, int index) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (!(0 <= index && index <= items.length)) { - error (SWT.ERROR_INVALID_RANGE); - } - String [] newItems = new String [items.length + 1]; - System.arraycopy (items, 0, newItems, 0, index); - newItems [index] = string; - System.arraycopy (items, index, newItems, index + 1, items.length - index); - items = newItems; - byte [] buffer = Converter.wcsToMbcs (null, string, true); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.gtk_combo_box_insert_text (handle, index, buffer); - if ((style & SWT.RIGHT_TO_LEFT) != 0 && popupHandle != 0) { - OS.gtk_container_forall (popupHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - } else { - /* - * Feature in GTK. When the list is empty and the first item - * is added, the combo box selects that item replacing the - * text in the entry field. The fix is to avoid this by - * stopping the "delete" and "insert_text" signal emission. - */ - ignoreSelect = lockText = true; - int /*long*/ item = OS.gtk_list_item_new_with_label (buffer); - int /*long*/ label = OS.gtk_bin_get_child (item); - setForegroundColor (label, getForegroundColor ()); - OS.gtk_widget_modify_font (label, getFontDescription ()); - OS.gtk_widget_set_direction (label, OS.gtk_widget_get_direction (handle)); - OS.gtk_widget_show (item); - int /*long*/ items = OS.g_list_append (0, item); - OS.gtk_list_insert_items (listHandle, items, index); - ignoreSelect = lockText = false; - } -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's text is modified, by sending - * it one of the messages defined in the ModifyListener - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the listener is null
  • - *
- * @exception 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 ModifyListener - * @see #removeModifyListener - */ -public void addModifyListener (ModifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Modify, typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the user changes the receiver's selection, by sending - * it one of the messages defined in the SelectionListener - * interface. - *

- * widgetSelected is called when the user changes the combo's list selection. - * widgetDefaultSelected is typically called when ENTER is pressed the combo's text area. - *

- * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the listener is null
  • - *
- * @exception 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 SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Selection,typedListener); - addListener (SWT.DefaultSelection,typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's text is verified, by sending - * it one of the messages defined in the VerifyListener - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the listener is null
  • - *
- * @exception 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 VerifyListener - * @see #removeVerifyListener - * - * @since 3.1 - */ -public void addVerifyListener (VerifyListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Verify, typedListener); -} - -static int checkStyle (int style) { - /* - * Feature in Windows. It is not possible to create - * a combo box that has a border using Windows style - * bits. All combo boxes draw their own border and - * do not use the standard Windows border styles. - * Therefore, no matter what style bits are specified, - * clear the BORDER bits so that the SWT style will - * match the Windows widget. - * - * The Windows behavior is currently implemented on - * all platforms. - */ - style &= ~SWT.BORDER; - - /* - * Even though it is legal to create this widget - * with scroll bars, they serve no useful purpose - * because they do not automatically scroll the - * widget's client area. The fix is to clear - * the SWT style. - */ - style &= ~(SWT.H_SCROLL | SWT.V_SCROLL); - style = checkBits (style, SWT.DROP_DOWN, SWT.SIMPLE, 0, 0, 0, 0); - if ((style & SWT.SIMPLE) != 0) return style & ~SWT.READ_ONLY; - return style; -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -/** - * Sets the selection in the receiver's text field to an empty - * selection starting just before the first character. If the - * text field is editable, this has the effect of placing the - * i-beam at the start of the text. - *

- * Note: To clear the selected items in the receiver's list, - * use deselectAll(). - *

- * - * @exception 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 #deselectAll - */ -public void clearSelection () { - checkWidget(); - if (entryHandle != 0) { - int position = OS.gtk_editable_get_position (entryHandle); - OS.gtk_editable_select_region (entryHandle, position, position); - } -} - -void clearText () { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if ((style & SWT.READ_ONLY) != 0) { - int index = OS.gtk_combo_box_get_active (handle); - if (index != -1) { - int /*long*/ modelHandle = OS.gtk_combo_box_get_model (handle); - int /*long*/ [] ptr = new int /*long*/ [1]; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - OS.gtk_tree_model_get (modelHandle, iter, 0, ptr, -1); - OS.g_free (iter); - if (ptr [0] != 0 && OS.strlen (ptr [0]) > 0) postEvent (SWT.Modify); - OS.g_free (ptr [0]); - } - } else { - OS.gtk_entry_set_text (entryHandle, new byte[1]); - } - OS.gtk_combo_box_set_active (handle, -1); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - return computeNativeSize (handle, wHint, hHint, changed); - } - if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; - if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - int[] w = new int [1], h = new int [1]; - OS.gtk_widget_realize (entryHandle); - int /*long*/ layout = OS.gtk_entry_get_layout (entryHandle); - OS.pango_layout_get_size (layout, w, h); - int xborder = Display.INNER_BORDER, yborder = Display.INNER_BORDER; - int /*long*/ style = OS.gtk_widget_get_style (entryHandle); - xborder += OS.gtk_style_get_xthickness (style); - yborder += OS.gtk_style_get_ythickness (style); - int [] property = new int [1]; - OS.gtk_widget_style_get (entryHandle, OS.interior_focus, property, 0); - if (property [0] == 0) { - OS.gtk_widget_style_get (entryHandle, OS.focus_line_width, property, 0); - xborder += property [0]; - yborder += property [0]; - } - int width = OS.PANGO_PIXELS (w [0]) + xborder * 2; - int height = OS.PANGO_PIXELS (h [0]) + yborder * 2; - - GtkRequisition arrowRequesition = new GtkRequisition (); - OS.gtk_widget_size_request (buttonHandle, arrowRequesition); - GtkRequisition listRequesition = new GtkRequisition (); - int /*long*/ listParent = OS.gtk_widget_get_parent (listHandle); - OS.gtk_widget_size_request (listParent != 0 ? listParent : listHandle, listRequesition); - - width = Math.max (listRequesition.width, width) + arrowRequesition.width + 4; - width = wHint == SWT.DEFAULT ? width : wHint; - height = hHint == SWT.DEFAULT ? height : hHint; - return new Point (width, height); -} - -/** - * Copies the selected text. - *

- * The current selection is copied to the clipboard. - *

- * - * @exception 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 2.1 - */ -public void copy () { - checkWidget (); - if (entryHandle != 0) OS.gtk_editable_copy_clipboard (entryHandle); -} - -void createHandle (int index) { - state |= HANDLE | MENU; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - int /*long*/ oldList = OS.gtk_window_list_toplevels (); - if ((style & SWT.READ_ONLY) != 0) { - handle = OS.gtk_combo_box_new_text (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - cellHandle = OS.gtk_bin_get_child (handle); - if (cellHandle == 0) error (SWT.ERROR_NO_HANDLES); - } else { - handle = OS.gtk_combo_box_entry_new_text (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - entryHandle = OS.gtk_bin_get_child (handle); - if (entryHandle == 0) error (SWT.ERROR_NO_HANDLES); - } - popupHandle = findPopupHandle (oldList); - OS.gtk_container_add (fixedHandle, handle); - textRenderer = OS.gtk_cell_renderer_text_new (); - if (textRenderer == 0) error (SWT.ERROR_NO_HANDLES); - /* - * Feature in GTK. In order to make a read only combo box the same - * height as an editable combo box the ypad must be set to 0. In - * versions 2.4.x of GTK, a pad of 0 will clip some letters. The - * fix is to set the pad to 1. - */ - int pad = 0; - if (OS.GTK_VERSION < OS.VERSION(2, 6, 0)) pad = 1; - OS.g_object_set (textRenderer, OS.ypad, pad, 0); - /* - * Feature in GTK. In version 2.4.9 of GTK, a warning is issued - * when a call to gtk_cell_layout_clear() is made. The fix is to hide - * the warning. - */ - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.gtk_cell_layout_clear (handle); - display.setWarnings (warnings); - OS.gtk_cell_layout_pack_start (handle, textRenderer, true); - OS.gtk_cell_layout_set_attributes (handle, textRenderer, OS.text, 0, 0); - - /* - * Feature in GTK. There is no API to query the button - * handle from a combo box although it is possible to get the - * text field. The button handle is needed to hook events. The - * fix is to walk the combo tree and find the first child that is - * an instance of button. - */ - OS.gtk_container_forall (handle, display.allChildrenProc, 0); - if (display.allChildren != 0) { - int /*long*/ list = display.allChildren; - while (list != 0) { - int /*long*/ widget = OS.g_list_data (list); - if (OS.GTK_IS_BUTTON (widget)) { - buttonHandle = widget; - break; - } - list = OS.g_list_next (list); - } - OS.g_list_free (display.allChildren); - display.allChildren = 0; - } - /* - * Feature in GTK. By default, read only combo boxes - * process the RETURN key rather than allowing the - * default button to process the key. The fix is to - * clear the GTK_RECEIVES_DEFAULT flag. - */ - if ((style & SWT.READ_ONLY) != 0 && buttonHandle != 0) { - OS.GTK_WIDGET_UNSET_FLAGS (buttonHandle, OS.GTK_RECEIVES_DEFAULT); - } - } else { - handle = OS.gtk_combo_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, handle); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle); - entryHandle = combo.entry; - listHandle = combo.list; - - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - int /*long*/ parentHandle = 0; - int /*long*/ temp = listHandle; - while ((temp = OS.gtk_widget_get_parent(temp)) != 0) { - parentHandle = temp; - } - popupHandle = parentHandle; - if (popupHandle != 0) { - int /*long*/ modalGroup = getShell().modalGroup; - if (modalGroup != 0) { - OS.gtk_window_group_add_window (modalGroup, popupHandle); - } - } - } - /* - * Feature in GTK. There is no API to query the arrow - * handle from a combo box although it is possible to - * get the list and text field. The arrow handle is needed - * to hook events. The fix is to find the first child that is - * not the entry or list and assume this is the arrow handle. - */ - int /*long*/ list = OS.gtk_container_get_children (handle); - if (list != 0) { - int i = 0, count = OS.g_list_length (list); - while (i - * The current selection is first copied to the - * clipboard and then deleted from the widget. - *

- * - * @exception 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 2.1 - */ -public void cut () { - checkWidget (); - if (entryHandle != 0) OS.gtk_editable_cut_clipboard (entryHandle); -} - -void deregister () { - super.deregister (); - if (buttonHandle != 0) display.removeWidget (buttonHandle); - if (entryHandle != 0) display.removeWidget (entryHandle); - if (listHandle != 0) display.removeWidget (listHandle); - int /*long*/ imContext = imContext (); - if (imContext != 0) display.removeWidget (imContext); -} - -boolean filterKey (int keyval, int /*long*/ event) { - int time = OS.gdk_event_get_time (event); - if (time != lastEventTime) { - lastEventTime = time; - int /*long*/ imContext = imContext (); - if (imContext != 0) { - return OS.gtk_im_context_filter_keypress (imContext, event); - } - } - gdkEventKey = event; - return false; -} - -int /*long*/ findPopupHandle (int /*long*/ oldList) { - int /*long*/ hdl = 0; - int /*long*/ currentList = OS.gtk_window_list_toplevels(); - int /*long*/ oldFromList = oldList; - int /*long*/ newFromList = currentList; - boolean isFound; - while (newFromList != 0) { - int /*long*/ newToplevel = OS.g_list_data(newFromList); - isFound = false; - oldFromList = oldList; - while (oldFromList != 0) { - int /*long*/ oldToplevel = OS.g_list_data(oldFromList); - if (newToplevel == oldToplevel) { - isFound = true; - break; - } - oldFromList = OS.g_list_next(oldFromList); - } - if (!isFound) { - hdl = newToplevel; - break; - } - newFromList = OS.g_list_next(newFromList); - } - OS.g_list_free(oldList); - OS.g_list_free(currentList); - return hdl; -} - -void fixModal (int /*long*/ group, int /*long*/ modalGroup) { - if (popupHandle != 0) { - if (group != 0) { - OS.gtk_window_group_add_window (group, popupHandle); - } else { - if (modalGroup != 0) { - OS.gtk_window_group_remove_window (modalGroup, popupHandle); - } - } - } -} - -void fixIM () { - /* - * The IM filter has to be called one time for each key press event. - * When the IM is open the key events are duplicated. The first event - * is filtered by SWT and the second event is filtered by GTK. In some - * cases the GTK handler does not run (the widget is destroyed, the - * application code consumes the event, etc), for these cases the IM - * filter has to be called by SWT. - */ - if (gdkEventKey != 0 && gdkEventKey != -1) { - int /*long*/ imContext = imContext (); - if (imContext != 0) { - OS.gtk_im_context_filter_keypress (imContext, gdkEventKey); - gdkEventKey = -1; - return; - } - } - gdkEventKey = 0; -} - -int /*long*/ fontHandle () { - if (entryHandle != 0) return entryHandle; - return super.fontHandle (); -} - -int /*long*/ focusHandle () { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if ((style & SWT.READ_ONLY) != 0 && buttonHandle != 0) return buttonHandle; - } - if (entryHandle != 0) return entryHandle; - return super.focusHandle (); -} - -boolean hasFocus () { - if (super.hasFocus ()) return true; - if (entryHandle != 0 && OS.GTK_WIDGET_HAS_FOCUS (entryHandle)) return true; - if (listHandle != 0 && OS.GTK_WIDGET_HAS_FOCUS (listHandle)) return true; - return false; -} - -void hookEvents () { - super.hookEvents (); - if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) { - OS.g_signal_connect_closure (handle, OS.changed, display.closures [CHANGED], true); - } - - if (entryHandle != 0) { - OS.g_signal_connect_closure (entryHandle, OS.changed, display.closures [CHANGED], true); - OS.g_signal_connect_closure (entryHandle, OS.insert_text, display.closures [INSERT_TEXT], false); - OS.g_signal_connect_closure (entryHandle, OS.delete_text, display.closures [DELETE_TEXT], false); - OS.g_signal_connect_closure (entryHandle, OS.activate, display.closures [ACTIVATE], false); - OS.g_signal_connect_closure (entryHandle, OS.populate_popup, display.closures [POPULATE_POPUP], false); - } - int eventMask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_PRESS_MASK | - OS.GDK_BUTTON_RELEASE_MASK; - int /*long*/ [] handles = new int /*long*/ [] {buttonHandle, entryHandle, listHandle}; - for (int i=0; i - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - * - */ -public void deselect (int index) { - checkWidget(); - if (index < 0 || index >= items.length) return; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (OS.gtk_combo_box_get_active (handle) == index) { - clearText (); - } - } else { - ignoreSelect = true; - int /*long*/ children = OS.gtk_container_get_children (listHandle); - int /*long*/ item = OS.g_list_nth_data (children, index); - boolean selected = OS.GTK_WIDGET_STATE (item) == OS.GTK_STATE_SELECTED; - if (selected) { - OS.gtk_list_unselect_all (listHandle); - OS.gtk_entry_set_text (entryHandle, new byte[1]); - } - OS.g_list_free (children); - ignoreSelect = false; - } -} - -/** - * Deselects all selected items in the receiver's list. - *

    - * Note: To clear the selection in the receiver's text field, - * use clearSelection(). - *

    - * - * @exception 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 #clearSelection - */ -public void deselectAll () { - checkWidget(); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - clearText (); - } else { - ignoreSelect = true; - OS.gtk_list_unselect_all (listHandle); - OS.gtk_entry_set_text (entryHandle, new byte[1]); - ignoreSelect = false; - } -} - -boolean dragDetect(int x, int y, boolean filter, boolean[] consume) { - if (filter && entryHandle != 0) { - int [] index = new int [1]; - int [] trailing = new int [1]; - int /*long*/ layout = OS.gtk_entry_get_layout (entryHandle); - OS.pango_layout_xy_to_index (layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, trailing); - int /*long*/ ptr = OS.pango_layout_get_text (layout); - int position = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]) + trailing[0]; - Point selection = getSelection (); - if (selection.x <= position && position < selection.y) { - if (super.dragDetect (x, y, filter, consume)) { - if (consume != null) consume [0] = true; - return true; - } - } - return false; - } - return super.dragDetect (x, y, filter, consume); -} - -int /*long*/ enterExitHandle () { - return fixedHandle; -} - -int /*long*/ eventWindow () { - return paintWindow (); -} - -GdkColor getBackgroundColor () { - return getBaseColor (); -} - -GdkColor getForegroundColor () { - return getTextColor (); -} - -/** - * Returns the item at the given, zero-relative index in the - * receiver's list. Throws an exception if the index is out - * of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public String getItem (int index) { - checkWidget(); - if (!(0 <= index && index < items.length)) { - error (SWT.ERROR_INVALID_RANGE); - } - return items [index]; -} - -/** - * Returns the number of items contained in the receiver's list. - * - * @return the number of items - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int getItemCount () { - checkWidget(); - return items.length; -} - -/** - * Returns the height of the area which would be used to - * display one of the items in the receiver's list. - * - * @return the height of one item - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int getItemHeight () { - checkWidget(); - return fontHeight (getFontDescription (), listHandle != 0 ? listHandle : handle); -} - -/** - * Returns a (possibly empty) array of Strings which are - * the items in the receiver's list. - *

    - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - *

    - * - * @return the items in the receiver's list - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public String [] getItems () { - checkWidget(); - String [] result = new String [items.length]; - System.arraycopy (items, 0, result, 0, items.length); - return result; -} - -/** - * Returns true if the receiver's list is visible, - * and false otherwise. - *

    - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, this method - * may still indicate that it is considered visible even though - * it may not actually be showing. - *

    - * - * @return the receiver's list's visibility state - * - * @exception 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 - */ -public boolean getListVisible () { - checkWidget (); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - return popupHandle != 0 && OS.GTK_WIDGET_VISIBLE (popupHandle); - } - return false; -} - -String getNameText () { - return getText (); -} - -/** - * Returns the orientation of the receiver. - * - * @return the orientation style - * - * @exception 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 2.1.2 - */ -public int getOrientation () { - checkWidget(); - return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); -} - -/** - * Returns a Point whose x coordinate is the - * character position representing the start of the selection - * in the receiver's text field, and whose y coordinate is the - * character position representing the end of the selection. - * An "empty" selection is indicated by the x and y coordinates - * having the same value. - *

    - * Indexing is zero based. The range of a selection is from - * 0..N where N is the number of characters in the widget. - *

    - * - * @return a point representing the selection start and end - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Point getSelection () { - checkWidget (); - if ((style & SWT.READ_ONLY) != 0) { - int length = 0; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - int index = OS.gtk_combo_box_get_active (handle); - if (index != -1) length = getItem (index).length (); - } else { - int /*long*/ str = OS.gtk_entry_get_text (entryHandle); - if (str != 0) length = (int)/*64*/OS.g_utf8_strlen (str, -1); - } - return new Point (0, length); - } - int [] start = new int [1]; - int [] end = new int [1]; - if (entryHandle != 0) { - OS.gtk_editable_get_selection_bounds (entryHandle, start, end); - } - return new Point(start [0], end [0]); -} - -/** - * Returns the zero-relative index of the item which is currently - * selected in the receiver's list, or -1 if no item is selected. - * - * @return the index of the selected item - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int getSelectionIndex () { - checkWidget(); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - return OS.gtk_combo_box_get_active (handle); - } - int index = 0, result = -1; - int /*long*/ children = OS.gtk_container_get_children (listHandle); - int /*long*/ temp = children; - while (temp != 0) { - int /*long*/ item = OS.g_list_data (temp); - if (OS.GTK_WIDGET_STATE (item) == OS.GTK_STATE_SELECTED) { - result = index; - break; - } - index++; - temp = OS.g_list_next (temp); - } - OS.g_list_free (children); - return result; -} - -/** - * Returns a string containing a copy of the contents of the - * receiver's text field, or an empty string if there are no - * contents. - * - * @return the receiver's text - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public String getText () { - checkWidget(); - if (entryHandle != 0) { - int /*long*/ str = OS.gtk_entry_get_text (entryHandle); - if (str == 0) return ""; - int length = OS.strlen (str); - byte [] buffer = new byte [length]; - OS.memmove (buffer, str, length); - return new String (Converter.mbcsToWcs (null, buffer)); - } else { - int index = OS.gtk_combo_box_get_active (handle); - return index != -1 ? getItem (index) : ""; - } -} - -String getText (int start, int stop) { - /* - * NOTE: The current implementation uses substring () - * which can reference a potentially large character - * array. - */ - return getText ().substring (start, stop - 1); -} - -/** - * Returns the height of the receivers's text field. - * - * @return the text height - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int getTextHeight () { - checkWidget(); - GtkRequisition requisition = new GtkRequisition (); - gtk_widget_size_request (handle, requisition); - return OS.GTK_WIDGET_REQUISITION_HEIGHT (handle); -} - -/** - * Returns the maximum number of characters that the receiver's - * text field is capable of holding. If this has not been changed - * by setTextLimit(), it will be the constant - * Combo.LIMIT. - * - * @return the text limit - * - * @exception 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 #LIMIT - */ -public int getTextLimit () { - checkWidget(); - int limit = entryHandle != 0 ? OS.gtk_entry_get_max_length (entryHandle) : 0; - return limit == 0 ? LIMIT : limit; -} - -/** - * Gets the number of items that are visible in the drop - * down portion of the receiver's list. - *

    - * Note: This operation is a hint and is not supported on - * platforms that do not have this concept. - *

    - * - * @return the number of items that are visible - * - * @exception 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.0 - */ -public int getVisibleItemCount () { - checkWidget (); - return visibleCount; -} - -int /*long*/ gtk_activate (int /*long*/ widget) { - postEvent (SWT.DefaultSelection); - return 0; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - /* - * Feature in GTK. Depending on where the user clicks, GTK prevents - * the left mouse button event from being propagated. The fix is to - * send the mouse event from the event_after handler. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - if (gdkEvent.type == OS.GDK_BUTTON_PRESS && gdkEvent.button == 1 && (style & SWT.READ_ONLY) != 0) { - return gtk_button_press_event(widget, event, false); - } - } - return super.gtk_button_press_event (widget, event); -} - -int /*long*/ gtk_changed (int /*long*/ widget) { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (widget == handle) { - if (entryHandle == 0) { - sendEvent(SWT.Modify); - if (isDisposed ()) return 0; - } - /* - * Feature in GTK. GTK emits a changed signal whenever - * the contents of a combo box are altered by typing or - * by selecting an item in the list, but the event should - * only be sent when the list is selected. The fix is to - * only send out a selection event when there is a selected - * item. - * - * NOTE: This code relies on GTK clearing the selected - * item and not matching the item as the user types. - */ - int index = OS.gtk_combo_box_get_active (handle); - if (index != -1) postEvent (SWT.Selection); - return 0; - } - } else { - if (!ignoreSelect) { - int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle); - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - String text = new String (Converter.mbcsToWcs (null, buffer)); - for (int i = 0; i < items.length; i++) { - if (items [i].equals (text)) { - postEvent (SWT.Selection); - break; - } - } - } - } - /* - * Feature in GTK. When the user types, GTK positions - * the caret after sending the changed signal. This - * means that application code that attempts to position - * the caret during a changed signal will fail. The fix - * is to post the modify event when the user is typing. - */ - boolean keyPress = false; - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - switch (gdkEvent.type) { - case OS.GDK_KEY_PRESS: - keyPress = true; - break; - } - OS.gdk_event_free (eventPtr); - } - if (keyPress) { - postEvent (SWT.Modify); - } else { - sendEvent (SWT.Modify); - } - return 0; -} - -int /*long*/ gtk_commit (int /*long*/ imContext, int /*long*/ text) { - if (text == 0) return 0; - if (!OS.gtk_editable_get_editable (entryHandle)) return 0; - int length = OS.strlen (text); - if (length == 0) return 0; - byte [] buffer = new byte [length]; - OS.memmove (buffer, text, length); - char [] chars = Converter.mbcsToWcs (null, buffer); - char [] newChars = sendIMKeyEvent (SWT.KeyDown, null, chars); - if (newChars == null) return 0; - /* - * Feature in GTK. For a GtkEntry, during the insert-text signal, - * GTK allows the programmer to change only the caret location, - * not the selection. If the programmer changes the selection, - * the new selection is lost. The fix is to detect a selection - * change and set it after the insert-text signal has completed. - */ - fixStart = fixEnd = -1; - OS.g_signal_handlers_block_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT); - int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ()); - int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID; - OS.g_signal_handlers_unblock_matched (imContext, mask, id, 0, 0, 0, entryHandle); - if (newChars == chars) { - OS.g_signal_emit_by_name (imContext, OS.commit, text); - } else { - buffer = Converter.wcsToMbcs (null, newChars, true); - OS.g_signal_emit_by_name (imContext, OS.commit, buffer); - } - OS.g_signal_handlers_unblock_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT); - OS.g_signal_handlers_block_matched (imContext, mask, id, 0, 0, 0, entryHandle); - if (fixStart != -1 && fixEnd != -1) { - OS.gtk_editable_set_position (entryHandle, fixStart); - OS.gtk_editable_select_region (entryHandle, fixStart, fixEnd); - } - fixStart = fixEnd = -1; - return 0; -} - -int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) { - if (lockText) { - OS.gtk_list_unselect_item (listHandle, 0); - OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text); - return 0; - } - if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0; - String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos); - if (newText == null) { - OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text); - } else { - if (newText.length () > 0) { - int [] pos = new int [1]; - pos [0] = (int)/*64*/end_pos; - byte [] buffer = Converter.wcsToMbcs (null, newText, false); - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.gtk_editable_insert_text (entryHandle, buffer, buffer.length, pos); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_editable_set_position (entryHandle, pos [0]); - } - } - return 0; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { - /* - * Feature in GTK. Depending on where the user clicks, GTK prevents - * the left mouse button event from being propagated. The fix is to - * send the mouse event from the event_after handler. - * - * Feature in GTK. When the user clicks anywhere in an editable - * combo box, a single focus event should be issued, despite the - * fact that focus might switch between the drop down button and - * the text field. The fix is to use gtk_combo_box_set_focus_on_click () - * to eat all focus events while focus is in the combo box. When the - * user clicks on the drop down button focus is assigned to the text - * field. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - GdkEvent event = new GdkEvent (); - OS.memmove (event, gdkEvent, GdkEvent.sizeof); - switch (event.type) { - case OS.GDK_BUTTON_PRESS: { - GdkEventButton gdkEventButton = new GdkEventButton (); - OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof); - if (gdkEventButton.button == 1) { - if ((style & SWT.READ_ONLY) != 0 && !sendMouseEvent (SWT.MouseDown, gdkEventButton.button, display.clickCount, 0, false, gdkEventButton.time, gdkEventButton.x_root, gdkEventButton.y_root, false, gdkEventButton.state)) { - return 1; - } - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) { - if ((style & SWT.READ_ONLY) == 0 && widget == buttonHandle) { - OS.gtk_widget_grab_focus (entryHandle); - } - } - } - break; - } - case OS.GDK_FOCUS_CHANGE: { - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) { - if ((style & SWT.READ_ONLY) == 0) { - GdkEventFocus gdkEventFocus = new GdkEventFocus (); - OS.memmove (gdkEventFocus, gdkEvent, GdkEventFocus.sizeof); - if (gdkEventFocus.in != 0) { - OS.gtk_combo_box_set_focus_on_click (handle, false); - } else { - OS.gtk_combo_box_set_focus_on_click (handle, true); - } - } - } - break; - } - } - } - return super.gtk_event_after(widget, gdkEvent); -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - fixIM (); - return super.gtk_focus_out_event (widget, event); -} - -int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*long*/ new_text_length, int /*long*/ position) { - if (lockText) { - OS.gtk_list_unselect_item (listHandle, 0); - OS.g_signal_stop_emission_by_name (entryHandle, OS.insert_text); - return 0; - } - if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0; - if (new_text == 0 || new_text_length == 0) return 0; - byte [] buffer = new byte [(int)/*64*/new_text_length]; - OS.memmove (buffer, new_text, buffer.length); - String oldText = new String (Converter.mbcsToWcs (null, buffer)); - int [] pos = new int [1]; - OS.memmove (pos, position, 4); - if (pos [0] == -1) { - int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle); - pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1); - } - String newText = verifyText (oldText, pos [0], pos [0]); - if (newText != oldText) { - int [] newStart = new int [1], newEnd = new int [1]; - OS.gtk_editable_get_selection_bounds (entryHandle, newStart, newEnd); - if (newText != null) { - if (newStart [0] != newEnd [0]) { - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_editable_delete_selection (entryHandle); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } - byte [] buffer3 = Converter.wcsToMbcs (null, newText, false); - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.gtk_editable_insert_text (entryHandle, buffer3, buffer3.length, pos); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - newStart [0] = newEnd [0] = pos [0]; - } - pos [0] = newEnd [0]; - if (newStart [0] != newEnd [0]) { - fixStart = newStart [0]; - fixEnd = newEnd [0]; - } - OS.memmove (position, pos, 4); - OS.g_signal_stop_emission_by_name (entryHandle, OS.insert_text); - } - return 0; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_key_press_event (widget, event); - if (result != 0) fixIM (); - if (gdkEventKey == -1) result = 1; - gdkEventKey = 0; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0) && (style & SWT.READ_ONLY) == 0) { - GdkEventKey keyEvent = new GdkEventKey (); - OS.memmove (keyEvent, event, GdkEventKey.sizeof); - int oldIndex = OS.gtk_combo_box_get_active (handle); - int newIndex = oldIndex; - int key = keyEvent.keyval; - switch (key) { - case OS.GDK_Down: - case OS.GDK_KP_Down: - if (oldIndex != (items.length - 1)) { - newIndex = oldIndex + 1; - } - break; - case OS.GDK_Up: - case OS.GDK_KP_Up: - if (oldIndex != -1 && oldIndex != 0) { - newIndex = oldIndex - 1; - } - break; - /* - * Feature in GTK. In gtk_combo_box, the PageUp and PageDown keys - * go the first and last items in the list rather than scrolling - * a page at a time. The fix is to emulate this behavior for - * gtk_combo_box_entry. - */ - case OS.GDK_Page_Up: - case OS.GDK_KP_Page_Up: - newIndex = 0; - break; - case OS.GDK_Page_Down: - case OS.GDK_KP_Page_Down: - newIndex = items.length - 1; - break; - } - if (newIndex != oldIndex) { - OS.gtk_combo_box_set_active (handle, newIndex); - return 1; - } - } - return result; -} - -int /*long*/ gtk_populate_popup (int /*long*/ widget, int /*long*/ menu) { - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.gtk_widget_set_direction (menu, OS.GTK_TEXT_DIR_RTL); - OS.gtk_container_forall (menu, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - return 0; -} - -/** - * Searches the receiver's list starting at the first item - * (index 0) until an item is found that is equal to the - * argument, and returns the index of that item. If no item - * is found, returns -1. - * - * @param string the search item - * @return the index of the item - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the string is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int indexOf (String string) { - checkWidget(); - return indexOf (string, 0); -} - -/** - * Searches the receiver's list starting at the given, - * zero-relative index until an item is found that is equal - * to the argument, and returns the index of that item. If - * no item is found or the starting index is out of range, - * returns -1. - * - * @param string the search item - * @param start the zero-relative index at which to begin the search - * @return the index of the item - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the string is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int indexOf (String string, int start) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (!(0 <= start && start < items.length)) return -1; - for (int i=start; i= OS.VERSION (2, 4, 0)) { - if (buttonHandle != 0 && widget == buttonHandle) return true; - if (entryHandle != 0 && widget == entryHandle) return true; - } - return super.isFocusHandle (widget); -} - -int /*long*/ paintWindow () { - int /*long*/ childHandle = entryHandle != 0 ? entryHandle : handle; - OS.gtk_widget_realize (childHandle); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (childHandle); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if ((style & SWT.READ_ONLY) != 0) return window; - } - int /*long*/ children = OS.gdk_window_get_children (window); - if (children != 0) window = OS.g_list_data (children); - OS.g_list_free (children); - return window; -} - -/** - * Pastes text from clipboard. - *

    - * The selected text is deleted from the widget - * and new text inserted from the clipboard. - *

    - * - * @exception 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 2.1 - */ -public void paste () { - checkWidget (); - if (entryHandle != 0) OS.gtk_editable_paste_clipboard (entryHandle); -} - -int /*long*/ parentingHandle() { - return fixedHandle; -} - -void register () { - super.register (); - if (buttonHandle != 0) display.addWidget (buttonHandle, this); - if (entryHandle != 0) display.addWidget (entryHandle, this); - if (listHandle != 0) display.addWidget (listHandle, this); - int /*long*/ imContext = imContext (); - if (imContext != 0) display.addWidget (imContext, this); -} - -void releaseHandle () { - super.releaseHandle (); - buttonHandle = entryHandle = listHandle = 0; -} - -void releaseWidget () { - super.releaseWidget (); - textRenderer = 0; - fixIM (); -} - -/** - * Removes the item from the receiver's list at the given - * zero-relative index. - * - * @param index the index for the item - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void remove (int index) { - checkWidget(); - if (!(0 <= index && index < items.length)) { - error (SWT.ERROR_INVALID_RANGE); - } - String [] oldItems = items; - String [] newItems = new String [oldItems.length - 1]; - System.arraycopy (oldItems, 0, newItems, 0, index); - System.arraycopy (oldItems, index + 1, newItems, index, oldItems.length - index - 1); - items = newItems; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (OS.gtk_combo_box_get_active (handle) == index) clearText (); - OS.gtk_combo_box_remove_text (handle, index); - } else { - ignoreSelect = true; - int /*long*/ children = OS.gtk_container_get_children (listHandle); - int /*long*/ item = OS.g_list_nth_data (children, index); - boolean selected = OS.GTK_WIDGET_STATE (item) == OS.GTK_STATE_SELECTED; - int /*long*/ items = OS.g_list_append (0, item); - OS.gtk_list_remove_items (listHandle, items); - OS.g_list_free (items); - OS.g_list_free (children); - if (selected) { - OS.gtk_entry_set_text (entryHandle, new byte[1]); - } - ignoreSelect = false; - } -} - -/** - * Removes the items from the receiver's list which are - * between the given zero-relative start and end - * indices (inclusive). - * - * @param start the start of the range - * @param end the end of the range - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void remove (int start, int end) { - checkWidget(); - if (start > end) return; - if (!(0 <= start && start <= end && end < items.length)) { - error (SWT.ERROR_INVALID_RANGE); - } - String [] oldItems = items; - String [] newItems = new String [oldItems.length - (end - start + 1)]; - System.arraycopy (oldItems, 0, newItems, 0, start); - System.arraycopy (oldItems, end + 1, newItems, start, oldItems.length - end - 1); - items = newItems; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - int index = OS.gtk_combo_box_get_active (handle); - if (start <= index && index <= end) clearText(); - for (int i = end; i >= start; i--) { - OS.gtk_combo_box_remove_text (handle, i); - } - } else { - boolean selected = false; - ignoreSelect = true; - int /*long*/ items = 0; - int /*long*/ children = OS.gtk_container_get_children (listHandle); - for (int i = start; i <= end; i++) { - int /*long*/ item = OS.g_list_nth_data (children, i); - selected |= OS.GTK_WIDGET_STATE (item) == OS.GTK_STATE_SELECTED; - items = OS.g_list_append (items, item); - } - OS.gtk_list_remove_items (listHandle, items); - OS.g_list_free (items); - OS.g_list_free (children); - if (selected) { - OS.gtk_entry_set_text (entryHandle, new byte[1]); - } - ignoreSelect = false; - } -} - -/** - * Searches the receiver's list starting at the first item - * until an item is found that is equal to the argument, - * and removes that item from the list. - * - * @param string the item to remove - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the string is null
    • - *
    • ERROR_INVALID_ARGUMENT - if the string is not found in the list
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void remove (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - int index = indexOf (string, 0); - if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT); - remove (index); -} - -/** - * Removes all of the items from the receiver's list and clear the - * contents of receiver's text field. - *

    - * @exception SWTException

      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void removeAll () { - checkWidget(); - int count = items.length; - items = new String[0]; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - clearText (); - for (int i = count - 1; i >= 0; i--) { - OS.gtk_combo_box_remove_text (handle, i); - } - } else { - ignoreSelect = true; - OS.gtk_list_clear_items (listHandle, 0, -1); - OS.gtk_entry_set_text (entryHandle, new byte[1]); - ignoreSelect = false; - } -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's text is modified. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 ModifyListener - * @see #addModifyListener - */ -public void removeModifyListener (ModifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Modify, listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the user changes the receiver's selection. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener (SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Selection, listener); - eventTable.unhook (SWT.DefaultSelection,listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is verified. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 VerifyListener - * @see #addVerifyListener - * - * @since 3.1 - */ -public void removeVerifyListener (VerifyListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Verify, listener); -} - -/** - * Selects the item at the given zero-relative index in the receiver's - * list. If the item at the index was already selected, it remains - * selected. Indices that are out of range are ignored. - * - * @param index the index of the item to select - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void select (int index) { - checkWidget(); - if (index < 0 || index >= items.length) return; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_combo_box_set_active (handle, index); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if ((style & SWT.READ_ONLY) != 0) { - /* - * Feature in GTK. Read Only combo boxes do not get a chance to send out a - * Modify event in the gtk_changed callback. The fix is to send a Modify event - * here. - */ - sendEvent (SWT.Modify); - } - } else { - ignoreSelect = true; - OS.gtk_list_select_item (listHandle, index); - ignoreSelect = false; - } -} - -void setBackgroundColor (GdkColor color) { - super.setBackgroundColor (color); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (entryHandle != 0) OS.gtk_widget_modify_base (entryHandle, 0, color); - OS.g_object_set (textRenderer, OS.background_gdk, color, 0); - } else { - OS.gtk_widget_modify_base (entryHandle, 0, color); - if (listHandle != 0) OS.gtk_widget_modify_base (listHandle, 0, color); - } -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int newHeight = height; - if (resize) newHeight = Math.max (getTextHeight (), height); - return super.setBounds (x, y, width, newHeight, move, resize); -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (entryHandle != 0) OS.gtk_widget_modify_font (entryHandle, font); - OS.g_object_set (textRenderer, OS.font_desc, font, 0); - if ((style & SWT.READ_ONLY) != 0) { - /* - * Bug in GTK. Setting the font can leave the combo box with an - * invalid minimum size. The fix is to temporarily change the - * selected item to force the combo box to resize. - */ - int index = OS.gtk_combo_box_get_active (handle); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_combo_box_set_active (handle, -1); - OS.gtk_combo_box_set_active (handle, index); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } - } else { - OS.gtk_widget_modify_font (entryHandle, font); - if (listHandle != 0) { - OS.gtk_widget_modify_font (listHandle, font); - int /*long*/ itemsList = OS.gtk_container_get_children (listHandle); - if (itemsList != 0) { - int count = OS.g_list_length (itemsList); - for (int i=count - 1; i>=0; i--) { - int /*long*/ widget = OS.gtk_bin_get_child (OS.g_list_nth_data (itemsList, i)); - OS.gtk_widget_modify_font (widget, font); - } - OS.g_list_free (itemsList); - } - } - } -} - -void setForegroundColor (GdkColor color) { - super.setForegroundColor (color); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (entryHandle != 0) setForegroundColor (entryHandle, color); - OS.g_object_set (textRenderer, OS.foreground_gdk, color, 0); - } else { - setForegroundColor (entryHandle, color); - if (listHandle != 0) { - setForegroundColor (listHandle, color); - int /*long*/ itemsList = OS.gtk_container_get_children (listHandle); - if (itemsList != 0) { - int count = OS.g_list_length (itemsList); - for (int i=count - 1; i>=0; i--) { - int /*long*/ widget = OS.gtk_bin_get_child (OS.g_list_nth_data (itemsList, i)); - setForegroundColor (widget, color); - } - OS.g_list_free (itemsList); - } - } - } -} - -/** - * Sets the text of the item in the receiver's list at the given - * zero-relative index to the string argument. - * - * @param index the index for the item - * @param string the new text for the item - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
    • - *
    • ERROR_NULL_ARGUMENT - if the string is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setItem (int index, String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (!(0 <= index && index < items.length)) { - error (SWT.ERROR_INVALID_ARGUMENT); - } - items [index] = string; - byte [] buffer = Converter.wcsToMbcs (null, string, true); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.gtk_combo_box_remove_text (handle, index); - OS.gtk_combo_box_insert_text (handle, index, buffer); - if ((style & SWT.RIGHT_TO_LEFT) != 0 && popupHandle != 0) { - OS.gtk_container_forall (popupHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - } else { - ignoreSelect = true; - int /*long*/ children = OS.gtk_container_get_children (listHandle); - int /*long*/ item = OS.g_list_nth_data (children, index); - int /*long*/ label = OS.gtk_bin_get_child (item); - OS.gtk_label_set_text (label, buffer); - OS.g_list_free (children); - ignoreSelect = false; - } -} - -/** - * Sets the receiver's list to be the given array of items. - * - * @param items the array of items - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the items array is null
    • - *
    • ERROR_INVALID_ARGUMENT - if an item in the items array is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setItems (String [] items) { - checkWidget(); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - for (int i=0; i= OS.VERSION (2, 4, 0)) { - clearText (); - for (int i = count - 1; i >= 0; i--) { - OS.gtk_combo_box_remove_text (handle, i); - } - for (int i = 0; i < items.length; i++) { - String string = items [i]; - byte [] buffer = Converter.wcsToMbcs (null, string, true); - OS.gtk_combo_box_insert_text (handle, i, buffer); - if ((style & SWT.RIGHT_TO_LEFT) != 0 && popupHandle != 0) { - OS.gtk_container_forall (popupHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - } - } else { - lockText = ignoreSelect = true; - OS.gtk_list_clear_items (listHandle, 0, -1); - int /*long*/ font = getFontDescription (); - GdkColor color = getForegroundColor (); - int direction = OS.gtk_widget_get_direction (handle); - int i = 0; - while (i < items.length) { - String string = items [i]; - byte [] buffer = Converter.wcsToMbcs (null, string, true); - int /*long*/ item = OS.gtk_list_item_new_with_label (buffer); - int /*long*/ label = OS.gtk_bin_get_child (item); - setForegroundColor (label, color); - OS.gtk_widget_modify_font (label, font); - OS.gtk_widget_set_direction (label, direction); - OS.gtk_container_add (listHandle, item); - OS.gtk_widget_show (item); - i++; - } - lockText = ignoreSelect = false; - OS.gtk_entry_set_text (entryHandle, new byte[1]); - } -} - -/** - * Marks the receiver's list as visible if the argument is true, - * and marks it invisible otherwise. - *

    - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, marking - * it visible may not actually cause it to be displayed. - *

    - * - * @param visible the new visibility state - * - * @exception 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 - */ -public void setListVisible (boolean visible) { - checkWidget (); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (visible) { - OS.gtk_combo_box_popup (handle); - } else { - OS.gtk_combo_box_popdown (handle); - } - } -} - -void setOrientation() { - super.setOrientation(); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - if (listHandle != 0) OS.gtk_widget_set_direction (listHandle, OS.GTK_TEXT_DIR_RTL); - if (entryHandle != 0) OS.gtk_widget_set_direction (entryHandle, OS.GTK_TEXT_DIR_RTL); - if (cellHandle != 0) OS.gtk_widget_set_direction (cellHandle, OS.GTK_TEXT_DIR_RTL); - } -} - -/** - * Sets the orientation of the receiver, which must be one - * of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT. - *

    - * - * @param orientation new orientation style - * - * @exception 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 2.1.2 - */ -public void setOrientation (int orientation) { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - checkWidget(); - int flags = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT; - if ((orientation & flags) == 0 || (orientation & flags) == flags) return; - style &= ~flags; - style |= orientation & flags; - int dir = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? OS.GTK_TEXT_DIR_RTL : OS.GTK_TEXT_DIR_LTR; - OS.gtk_widget_set_direction (fixedHandle, dir); - OS.gtk_widget_set_direction (handle, dir); - if (entryHandle != 0) OS.gtk_widget_set_direction (entryHandle, dir); - if (listHandle != 0) { - OS.gtk_widget_set_direction (listHandle, dir); - int /*long*/ itemsList = OS.gtk_container_get_children (listHandle); - if (itemsList != 0) { - int count = OS.g_list_length (itemsList); - for (int i=count - 1; i>=0; i--) { - int /*long*/ widget = OS.gtk_bin_get_child (OS.g_list_nth_data (itemsList, i)); - OS.gtk_widget_set_direction (widget, dir); - } - OS.g_list_free (itemsList); - } - } - if (cellHandle != 0) OS.gtk_widget_set_direction (cellHandle, dir); - if (popupHandle != 0) OS.gtk_container_forall (popupHandle, display.setDirectionProc, dir); - } -} - -/** - * Sets the selection in the receiver's text field to the - * range specified by the argument whose x coordinate is the - * start of the selection and whose y coordinate is the end - * of the selection. - * - * @param selection a point representing the new selection start and end - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the point is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setSelection (Point selection) { - checkWidget(); - if (selection == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.READ_ONLY) != 0) return; - if (entryHandle != 0) { - OS.gtk_editable_set_position (entryHandle, selection.x); - OS.gtk_editable_select_region (entryHandle, selection.x, selection.y); - } -} - -/** - * Sets the contents of the receiver's text field to the - * given string. - *

    - * This call is ignored when the receiver is read only and - * the given string is not in the receiver's list. - *

    - *

    - * Note: The text field in a Combo is typically - * only capable of displaying a single line of text. Thus, - * setting the text to a string containing line breaks or - * other special characters will probably cause it to - * display incorrectly. - *

    - * - * @param string the new text - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the string is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.READ_ONLY) != 0) { - int index = indexOf (string); - if (index == -1) return; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_combo_box_set_active (handle, index); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - /* - * Feature in GTK. Read Only combo boxes do not get a chance to send out a - * Modify event in the gtk_changed callback. The fix is to send a Modify event - * here. - */ - sendEvent (SWT.Modify); - return; - } - } - /* - * Feature in gtk. When text is set in gtk, separate events are fired for the deletion and - * insertion of the text. This is not wrong, but is inconsistent with other platforms. The - * fix is to block the firing of these events and fire them ourselves in a consistent manner. - */ - if (hooks (SWT.Verify) || filters (SWT.Verify)) { - int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle); - string = verifyText (string, 0, (int)/*64*/OS.g_utf8_strlen (ptr, -1)); - if (string == null) return; - } - byte [] buffer = Converter.wcsToMbcs (null, string, true); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.gtk_entry_set_text (entryHandle, buffer); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - sendEvent (SWT.Modify); -} - -/** - * Sets the maximum number of characters that the receiver's - * text field is capable of holding to be the argument. - *

    - * To reset this value to the default, use setTextLimit(Combo.LIMIT). - * Specifying a limit value larger than Combo.LIMIT sets the - * receiver's limit to Combo.LIMIT. - *

    - * @param limit new text limit - * - * @exception IllegalArgumentException
      - *
    • ERROR_CANNOT_BE_ZERO - if the limit is zero
    • - *
    - * @exception 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 #LIMIT - */ -public void setTextLimit (int limit) { - checkWidget(); - if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); - if (entryHandle != 0) OS.gtk_entry_set_max_length (entryHandle, limit); -} - -void setToolTipText (Shell shell, String newString) { - if (entryHandle != 0) shell.setToolTipText (entryHandle, newString); - if (buttonHandle != 0) shell.setToolTipText (buttonHandle, newString); -} - -/** - * Sets the number of items that are visible in the drop - * down portion of the receiver's list. - *

    - * Note: This operation is a hint and is not supported on - * platforms that do not have this concept. - *

    - * - * @param count the new number of items to be visible - * - * @exception 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.0 - */ -public void setVisibleItemCount (int count) { - checkWidget (); - if (count < 0) return; - visibleCount = count; -} - -boolean checkSubwindow () { - return false; -} - -boolean translateTraversal (GdkEventKey keyEvent) { - int key = keyEvent.keyval; - switch (key) { - case OS.GDK_KP_Enter: - case OS.GDK_Return: { - int /*long*/ imContext = imContext (); - if (imContext != 0) { - int /*long*/ [] preeditString = new int /*long*/ [1]; - OS.gtk_im_context_get_preedit_string (imContext, preeditString, null, null); - if (preeditString [0] != 0) { - int length = OS.strlen (preeditString [0]); - OS.g_free (preeditString [0]); - if (length != 0) return false; - } - } - } - } - return super.translateTraversal (keyEvent); -} - -String verifyText (String string, int start, int end) { - if (string.length () == 0 && start == end) return null; - Event event = new Event (); - event.text = string; - event.start = start; - event.end = end; - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - switch (gdkEvent.type) { - case OS.GDK_KEY_PRESS: - setKeyState (event, gdkEvent); - break; - } - OS.gdk_event_free (eventPtr); - } - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the verify - * event. If this happens, answer null to cancel - * the operation. - */ - sendEvent (SWT.Verify, event); - if (!event.doit || isDisposed ()) return null; - return event.text; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java deleted file mode 100644 index 62cda3117c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java +++ /dev/null @@ -1,1438 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.cairo.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class are controls which are capable - * of containing other controls. - *
    - *
    Styles:
    - *
    NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP, EMBEDDED, DOUBLE_BUFFERED
    - *
    Events:
    - *
    (none)
    - *
    - *

    - * Note: The NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, - * and NO_REDRAW_RESIZE styles are intended for use with Canvas. - * They can be used with Composite if you are drawing your own, but their - * behavior is undefined if they are used with subclasses of Composite other - * than Canvas. - *

    - * Note: The CENTER style, although undefined for composites, has the - * same value as EMBEDDED which is used to embed widgets from other - * widget toolkits into SWT. On some operating systems (GTK, Motif), this may cause - * the children of this composite to be obscured. - *

    - * This class may be subclassed by custom control implementors - * who are building controls that are constructed from aggregates - * of other controls. - *

    - * - * @see Canvas - * @see Composite snippets - * @see Sample code and further information - */ -public class Composite extends Scrollable { - public int /*long*/ embeddedHandle; - int /*long*/ imHandle, socketHandle; - Layout layout; - Control[] tabList; - int layoutCount, backgroundMode; - - static final String NO_INPUT_METHOD = "org.eclipse.swt.internal.gtk.noInputMethod"; //$NON-NLS-1$ - -Composite () { - /* Do nothing */ -} - -/** - * 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. - *

    - * - * @param parent a widget which will be the parent of the new instance (cannot be null) - * @param style the style of widget to construct - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the parent is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
    • - *
    - * - * @see SWT#NO_BACKGROUND - * @see SWT#NO_FOCUS - * @see SWT#NO_MERGE_PAINTS - * @see SWT#NO_REDRAW_RESIZE - * @see SWT#NO_RADIO_GROUP - * @see SWT#EMBEDDED - * @see SWT#DOUBLE_BUFFERED - * @see Widget#getStyle - */ -public Composite (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -static int checkStyle (int style) { - style &= ~SWT.TRANSPARENT; - return style; -} - -Control [] _getChildren () { - int /*long*/ parentHandle = parentingHandle (); - int /*long*/ list = OS.gtk_container_get_children (parentHandle); - if (list == 0) return new Control [0]; - int count = OS.g_list_length (list); - Control [] children = new Control [count]; - int i = 0; - int /*long*/ temp = list; - while (temp != 0) { - int /*long*/ handle = OS.g_list_data (temp); - if (handle != 0) { - Widget widget = display.getWidget (handle); - if (widget != null && widget != this) { - if (widget instanceof Control) { - children [i++] = (Control) widget; - } - } - } - temp = OS.g_list_next (temp); - } - OS.g_list_free (list); - if (i == count) return children; - Control [] newChildren = new Control [i]; - System.arraycopy (children, 0, newChildren, 0, i); - return newChildren; -} - -Control [] _getTabList () { - if (tabList == null) return tabList; - int count = 0; - for (int i=0; i - *
  • ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed
  • - *
  • ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver
  • - * - * @exception 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.1 - */ -public void changed (Control[] changed) { - checkWidget (); - if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT); - for (int i=0; i 0 ? this : parent.findDeferredControl (); -} - -Menu [] findMenus (Control control) { - if (control == this) return new Menu [0]; - Menu result [] = super.findMenus (control); - Control [] children = _getChildren (); - for (int i=0; iSWT: - * INHERIT_NONE, INHERIT_DEFAULT, - * INHERTIT_FORCE. - * - * @return the background mode - * - * @exception 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 SWT - * - * @since 3.2 - */ -public int getBackgroundMode () { - checkWidget (); - return backgroundMode; -} - -/** - * Returns a (possibly empty) array containing the receiver's children. - * Children are returned in the order that they are drawn. The topmost - * control appears at the beginning of the array. Subsequent controls - * draw beneath this control and appear later in the array. - *

    - * Note: This is not the actual structure used by the receiver - * to maintain its list of children, so modifying the array will - * not affect the receiver. - *

    - * - * @return an array of children - * - * @see Control#moveAbove - * @see Control#moveBelow - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Control [] getChildren () { - checkWidget(); - return _getChildren (); -} - -int getChildrenCount () { - /* - * NOTE: The current implementation will count - * non-registered children. - */ - int /*long*/ list = OS.gtk_container_get_children (handle); - if (list == 0) return 0; - int count = OS.g_list_length (list); - OS.g_list_free (list); - return count; -} - -public Rectangle getClientArea () { - checkWidget(); - if ((state & CANVAS) != 0) { - if ((state & ZERO_WIDTH) != 0 && (state & ZERO_HEIGHT) != 0) { - return new Rectangle (0, 0, 0, 0); - } - forceResize (); - int /*long*/ clientHandle = clientHandle (); - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle); - int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (clientHandle); - return new Rectangle (0, 0, width, height); - } - return super.getClientArea(); -} - -int getClientWidth() { - return (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle ()); -} - -/** - * Returns layout which is associated with the receiver, or - * null if one has not been set. - * - * @return the receiver's layout or null - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Layout getLayout () { - checkWidget(); - return layout; -} - -/** - * Returns true if the receiver has deferred - * the performing of layout, and false otherwise. - * - * @return the receiver's deferred layout state - * - * @exception 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 #setLayoutDeferred(boolean) - * @see #isLayoutDeferred() - * - * @since 3.1 - */ -public boolean getLayoutDeferred () { - checkWidget (); - return layoutCount > 0 ; -} - -/** - * Gets the (possibly empty) tabbing order for the control. - * - * @return tabList the ordered list of controls representing the tab order - * - * @exception 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 #setTabList - */ -public Control [] getTabList () { - checkWidget (); - Control [] tabList = _getTabList (); - if (tabList == null) { - int count = 0; - Control [] list =_getChildren (); - for (int i=0; itrue if the receiver or any ancestor - * up to and including the receiver's nearest ancestor shell - * has deferred the performing of layouts. Otherwise, false - * is returned. - * - * @return the receiver's deferred layout state - * - * @exception 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 #setLayoutDeferred(boolean) - * @see #getLayoutDeferred() - * - * @since 3.1 - */ -public boolean isLayoutDeferred () { - checkWidget (); - return findDeferredControl () != null; -} - -boolean isTabGroup() { - if ((state & CANVAS) != 0) return true; - return super.isTabGroup(); -} - -/** - * If the receiver has a layout, asks the layout to lay out - * (that is, set the size and location of) the receiver's children. - * If the receiver does not have a layout, do nothing. - *

    - * This is equivalent to calling layout(true). - *

    - *

    - * Note: Layout is different from painting. If a child is - * moved or resized such that an area in the parent is - * exposed, then the parent will paint. If no child is - * affected, the parent will not paint. - *

    - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void layout () { - checkWidget (); - layout (true); -} - -/** - * If the receiver has a layout, asks the layout to lay out - * (that is, set the size and location of) the receiver's children. - * If the argument is true the layout must not rely - * on any information it has cached about the immediate children. If it - * is false the layout may (potentially) optimize the - * work it is doing by assuming that none of the receiver's - * children has changed state since the last layout. - * If the receiver does not have a layout, do nothing. - *

    - * If a child is resized as a result of a call to layout, the - * resize event will invoke the layout of the child. The layout - * will cascade down through all child widgets in the receiver's widget - * tree until a child is encountered that does not resize. Note that - * a layout due to a resize will not flush any cached information - * (same as layout(false)). - *

    - *

    - * Note: Layout is different from painting. If a child is - * moved or resized such that an area in the parent is - * exposed, then the parent will paint. If no child is - * affected, the parent will not paint. - *

    - * - * @param changed true if the layout must flush its caches, and false otherwise - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void layout (boolean changed) { - checkWidget (); - if (layout == null) return; - layout (changed, false); -} - -/** - * If the receiver has a layout, asks the layout to lay out - * (that is, set the size and location of) the receiver's children. - * If the changed argument is true the layout must not rely - * on any information it has cached about its children. If it - * is false the layout may (potentially) optimize the - * work it is doing by assuming that none of the receiver's - * children has changed state since the last layout. - * If the all argument is true the layout will cascade down - * through all child widgets in the receiver's widget tree, regardless of - * whether the child has changed size. The changed argument is applied to - * all layouts. If the all argument is false, the layout will - * not cascade down through all child widgets in the receiver's widget - * tree. However, if a child is resized as a result of a call to layout, the - * resize event will invoke the layout of the child. Note that - * a layout due to a resize will not flush any cached information - * (same as layout(false)). - *

    - *

    - * Note: Layout is different from painting. If a child is - * moved or resized such that an area in the parent is - * exposed, then the parent will paint. If no child is - * affected, the parent will not paint. - *

    - * - * @param changed true if the layout must flush its caches, and false otherwise - * @param all true if all children in the receiver's widget tree should be laid out, and false otherwise - * - * @exception 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.1 - */ -public void layout (boolean changed, boolean all) { - checkWidget (); - if (layout == null && !all) return; - markLayout (changed, all); - updateLayout (all); -} - -/** - * Forces a lay out (that is, sets the size and location) of all widgets that - * are in the parent hierarchy of the changed control up to and including the - * receiver. The layouts in the hierarchy must not rely on any information - * cached about the changed control or any of its ancestors. The layout may - * (potentially) optimize the work it is doing by assuming that none of the - * peers of the changed control have changed state since the last layout. - * If an ancestor does not have a layout, skip it. - *

    - * Note: Layout is different from painting. If a child is - * moved or resized such that an area in the parent is - * exposed, then the parent will paint. If no child is - * affected, the parent will not paint. - *

    - * - * @param changed a control that has had a state change which requires a recalculation of its size - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed
    • - *
    • ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver
    • - *
    - * @exception 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.1 - */ -public void layout (Control [] changed) { - checkWidget (); - if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT); - for (int i=0; i=0; i--) { - update [i].updateLayout (false); - } -} - -void markLayout (boolean changed, boolean all) { - if (layout != null) { - state |= LAYOUT_NEEDED; - if (changed) state |= LAYOUT_CHANGED; - } - if (all) { - Control [] children = _getChildren (); - for (int i=0; i=0; --i) { - Control child = children [i]; - if (child.getVisible ()) { - Point location = child.getLocation (); - child.printWidget (gc, drawable, depth, x + location.x, y + location.y); - } - } - gc.setClipping (oldClip); - oldClip.dispose (); - newClip.dispose (); -} - -void redrawChildren () { - super.redrawChildren (); - Control [] children = _getChildren (); - for (int i = 0; i < children.length; i++) { - Control child = children [i]; - if ((child.state & PARENT_BACKGROUND) != 0) { - child.redrawWidget (0, 0, 0, 0, true, false, true); - child.redrawChildren (); - } - } -} - -void register () { - super.register (); - if (socketHandle != 0) display.addWidget (socketHandle, this); -} - -void releaseChildren (boolean destroy) { - Control [] children = _getChildren (); - for (int i=0; iSWT: - * INHERIT_NONE, INHERIT_DEFAULT, - * INHERIT_FORCE. - * - * @param mode the new background mode - * - * @exception 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 SWT - * - * @since 3.2 - */ -public void setBackgroundMode (int mode) { - checkWidget (); - backgroundMode = mode; - Control[] children = _getChildren (); - for (int i = 0; i < children.length; i++) { - children [i].updateBackgroundMode (); - } -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int result = super.setBounds (x, y, width, height, move, resize); - if ((result & RESIZED) != 0 && layout != null) { - markLayout (false, false); - updateLayout (false); - } - return result; -} - -public boolean setFocus () { - checkWidget(); - Control [] children = _getChildren (); - for (int i=0; i - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - * - */ -public void setLayout (Layout layout) { - checkWidget(); - this.layout = layout; -} - -/** - * If the argument is true, causes subsequent layout - * operations in the receiver or any of its children to be ignored. - * No layout of any kind can occur in the receiver or any of its - * children until the flag is set to false. - * Layout operations that occurred while the flag was - * true are remembered and when the flag is set to - * false, the layout operations are performed in an - * optimized manner. Nested calls to this method are stacked. - * - * @param defer the new defer state - * - * @exception 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 #layout(boolean) - * @see #layout(Control[]) - * - * @since 3.1 - */ -public void setLayoutDeferred (boolean defer) { - if (!defer) { - if (--layoutCount == 0) { - if ((state & LAYOUT_CHILD) != 0 || (state & LAYOUT_NEEDED) != 0) { - updateLayout (true); - } - } - } else { - layoutCount++; - } -} - -boolean setScrollBarVisible (ScrollBar bar, boolean visible) { - boolean changed = super.setScrollBarVisible (bar, visible); - if (changed && layout != null) { - markLayout (false, false); - updateLayout (false); - } - return changed; -} - -boolean setTabGroupFocus (boolean next) { - if (isTabItem ()) return setTabItemFocus (next); - boolean takeFocus = (style & SWT.NO_FOCUS) == 0; - if ((state & CANVAS) != 0) takeFocus = hooksKeys (); - if (socketHandle != 0) takeFocus = true; - if (takeFocus && setTabItemFocus (next)) return true; - Control [] children = _getChildren (); - for (int i=0; i - *
  • ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed
  • - *
  • ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree
  • - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setTabList (Control [] tabList) { - checkWidget (); - if (tabList != null) { - for (int i=0; i - *
    - *
    Styles: - *
    BORDER
    - *
    LEFT_TO_RIGHT, RIGHT_TO_LEFT
    - *
    Events: - *
    DragDetect, FocusIn, FocusOut, Help, KeyDown, KeyUp, MenuDetect, MouseDoubleClick, MouseDown, MouseEnter, - * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse
    - *
    - *

    - * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified. - *

    - * IMPORTANT: This class is intended to be subclassed only - * within the SWT implementation. - *

    - * - * @see Control snippets - * @see SWT Example: ControlExample - * @see Sample code and further information - * @noextend This class is not intended to be subclassed by clients. - */ -public abstract class Control extends Widget implements Drawable { - int /*long*/ fixedHandle; - int /*long*/ redrawWindow, enableWindow; - int drawCount; - Composite parent; - Cursor cursor; - Menu menu; - Image backgroundImage; - Font font; - Region region; - String toolTipText; - Object layoutData; - Accessible accessible; - - static final String IS_ACTIVE = "org.eclipse.swt.internal.control.isactive"; //$NON-NLS-1$ - -Control () { -} - -/** - * 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. - *

    - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the parent is null
    • - *
    - * @exception 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 SWT#BORDER - * @see SWT#LEFT_TO_RIGHT - * @see SWT#RIGHT_TO_LEFT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Control (Composite parent, int style) { - super (parent, style); - this.parent = parent; - createWidget (0); -} - -Font defaultFont () { - return display.getSystemFont (); -} - -void deregister () { - super.deregister (); - if (fixedHandle != 0) display.removeWidget (fixedHandle); - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) display.removeWidget (imHandle); -} - -boolean drawGripper (int x, int y, int width, int height, boolean vertical) { - int /*long*/ paintHandle = paintHandle (); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle); - if (window == 0) return false; - int orientation = vertical ? OS.GTK_ORIENTATION_HORIZONTAL : OS.GTK_ORIENTATION_VERTICAL; - if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - width - x; - OS.gtk_paint_handle (OS.gtk_widget_get_style (paintHandle), window, OS.GTK_STATE_NORMAL, OS.GTK_SHADOW_OUT, null, paintHandle, new byte [1], x, y, width, height, orientation); - return true; -} - -void enableWidget (boolean enabled) { - OS.gtk_widget_set_sensitive (handle, enabled); -} - -int /*long*/ enterExitHandle () { - return eventHandle (); -} - -int /*long*/ eventHandle () { - return handle; -} - -int /*long*/ eventWindow () { - int /*long*/ eventHandle = eventHandle (); - OS.gtk_widget_realize (eventHandle); - return OS.GTK_WIDGET_WINDOW (eventHandle); -} - -void fixFocus (Control focusControl) { - Shell shell = getShell (); - Control control = this; - while (control != shell && (control = control.parent) != null) { - if (control.setFocus ()) return; - } - shell.setSavedFocus (focusControl); - int /*long*/ focusHandle = shell.vboxHandle; - OS.GTK_WIDGET_SET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS); - OS.gtk_widget_grab_focus (focusHandle); - OS.GTK_WIDGET_UNSET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS); -} - -void fixStyle () { - if (fixedHandle != 0) fixStyle (fixedHandle); -} - -void fixStyle (int /*long*/ handle) { - /* - * Feature in GTK. Some GTK themes apply a different background to - * the contents of a GtkNotebook. However, in an SWT TabFolder, the - * children are not parented below the GtkNotebook widget, and usually - * have their own GtkFixed. The fix is to look up the correct style - * for a child of a GtkNotebook and apply its background to any GtkFixed - * widgets that are direct children of an SWT TabFolder. - * - * Note that this has to be when the theme settings changes and that it - * should not override the application background. - */ - if ((state & BACKGROUND) != 0) return; - if ((state & THEME_BACKGROUND) == 0) return; - int /*long*/ childStyle = parent.childStyle (); - if (childStyle != 0) { - GdkColor color = new GdkColor(); - OS.gtk_style_get_bg (childStyle, 0, color); - setBackgroundColor (color); - } -} - -int /*long*/ focusHandle () { - return handle; -} - -int /*long*/ fontHandle () { - return handle; -} - -boolean hasFocus () { - return this == display.getFocusControl(); -} - -void hookEvents () { - /* Connect the keyboard signals */ - int /*long*/ focusHandle = focusHandle (); - int focusMask = OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK | OS.GDK_FOCUS_CHANGE_MASK; - OS.gtk_widget_add_events (focusHandle, focusMask); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [POPUP_MENU], 0, display.closures [POPUP_MENU], false); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [SHOW_HELP], 0, display.closures [SHOW_HELP], false); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [KEY_PRESS_EVENT], 0, display.closures [KEY_PRESS_EVENT], false); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [KEY_RELEASE_EVENT], 0, display.closures [KEY_RELEASE_EVENT], false); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [FOCUS], 0, display.closures [FOCUS], false); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [FOCUS_IN_EVENT], 0, display.closures [FOCUS_IN_EVENT], false); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false); - - /* Connect the mouse signals */ - int /*long*/ eventHandle = eventHandle (); - int eventMask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK; - OS.gtk_widget_add_events (eventHandle, eventMask); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT], false); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT], false); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [SCROLL_EVENT], 0, display.closures [SCROLL_EVENT], false); - - /* Connect enter/exit signals */ - int /*long*/ enterExitHandle = enterExitHandle (); - int enterExitMask = OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK; - OS.gtk_widget_add_events (enterExitHandle, enterExitMask); - OS.g_signal_connect_closure_by_id (enterExitHandle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); - OS.g_signal_connect_closure_by_id (enterExitHandle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_NOTIFY_EVENT], false); - - /* - * Feature in GTK. Events such as mouse move are propagate up - * the widget hierarchy and are seen by the parent. This is the - * correct GTK behavior but not correct for SWT. The fix is to - * hook a signal after and stop the propagation using a negative - * event number to distinguish this case. - * - * The signal is hooked to the fixedHandle to catch events sent to - * lightweight widgets. - */ - int /*long*/ blockHandle = fixedHandle != 0 ? fixedHandle : eventHandle; - OS.g_signal_connect_closure_by_id (blockHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT_INVERSE], true); - OS.g_signal_connect_closure_by_id (blockHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT_INVERSE], true); - OS.g_signal_connect_closure_by_id (blockHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT_INVERSE], true); - - /* Connect the event_after signal for both key and mouse */ - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false); - if (focusHandle != eventHandle) { - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false); - } - - /* Connect the paint signal */ - int /*long*/ paintHandle = paintHandle (); - int paintMask = OS.GDK_EXPOSURE_MASK | OS.GDK_VISIBILITY_NOTIFY_MASK; - OS.gtk_widget_add_events (paintHandle, paintMask); - OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures [EXPOSE_EVENT_INVERSE], false); - OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [VISIBILITY_NOTIFY_EVENT], 0, display.closures [VISIBILITY_NOTIFY_EVENT], false); - OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures [EXPOSE_EVENT], true); - - /* Connect the Input Method signals */ - OS.g_signal_connect_closure_by_id (handle, display.signalIds [REALIZE], 0, display.closures [REALIZE], true); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [UNREALIZE], 0, display.closures [UNREALIZE], false); - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - OS.g_signal_connect_closure (imHandle, OS.commit, display.closures [COMMIT], false); - OS.g_signal_connect_closure (imHandle, OS.preedit_changed, display.closures [PREEDIT_CHANGED], false); - } - - OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [STYLE_SET], 0, display.closures [STYLE_SET], false); - - int /*long*/ topHandle = topHandle (); - OS.g_signal_connect_closure_by_id (topHandle, display.signalIds [MAP], 0, display.closures [MAP], true); -} - -int /*long*/ hoverProc (int /*long*/ widget) { - int [] x = new int [1], y = new int [1], mask = new int [1]; - OS.gdk_window_get_pointer (0, x, y, mask); - sendMouseEvent (SWT.MouseHover, 0, /*time*/0, x [0], y [0], false, mask [0]); - /* Always return zero in order to cancel the hover timer */ - return 0; -} - -int /*long*/ topHandle() { - if (fixedHandle != 0) return fixedHandle; - return super.topHandle (); -} - -int /*long*/ paintHandle () { - int /*long*/ topHandle = topHandle (); - int /*long*/ paintHandle = handle; - while (paintHandle != topHandle) { - if ((OS.GTK_WIDGET_FLAGS (paintHandle) & OS.GTK_NO_WINDOW) == 0) break; - paintHandle = OS.gtk_widget_get_parent (paintHandle); - } - return paintHandle; -} - -int /*long*/ paintWindow () { - int /*long*/ paintHandle = paintHandle (); - OS.gtk_widget_realize (paintHandle); - return OS.GTK_WIDGET_WINDOW (paintHandle); -} - -/** - * Prints the receiver and all children. - * - * @param gc the gc where the drawing occurs - * @return true if the operation was successful and false otherwise - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the gc is null
    • - *
    • ERROR_INVALID_ARGUMENT - if the gc has been disposed
    • - *
    - * @exception 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 - */ -public boolean print (GC gc) { - checkWidget (); - if (gc == null) error (SWT.ERROR_NULL_ARGUMENT); - if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - int /*long*/ topHandle = topHandle (); - OS.gtk_widget_realize (topHandle); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle); - GCData data = gc.getGCData (); - OS.gdk_window_process_updates (window, true); - printWidget (gc, data.drawable, OS.gdk_drawable_get_depth (data.drawable), 0, 0); - return true; -} - -void printWidget (GC gc, int /*long*/ drawable, int depth, int x, int y) { - boolean obscured = (state & OBSCURED) != 0; - state &= ~OBSCURED; - int /*long*/ topHandle = topHandle (); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle); - printWindow (true, this, gc, drawable, depth, window, x, y); - if (obscured) state |= OBSCURED; -} - -void printWindow (boolean first, Control control, GC gc, int /*long*/ drawable, int depth, int /*long*/ window, int x, int y) { - if (OS.gdk_drawable_get_depth (window) != depth) return; - GdkRectangle rect = new GdkRectangle (); - int [] width = new int [1], height = new int [1]; - OS.gdk_drawable_get_size (window, width, height); - rect.width = width [0]; - rect.height = height [0]; - OS.gdk_window_begin_paint_rect (window, rect); - int /*long*/ [] real_drawable = new int /*long*/ [1]; - int [] x_offset = new int [1], y_offset = new int [1]; - OS.gdk_window_get_internal_paint_info (window, real_drawable, x_offset, y_offset); - int /*long*/ [] userData = new int /*long*/ [1]; - OS.gdk_window_get_user_data (window, userData); - if (userData [0] != 0) { - int /*long*/ eventPtr = OS.gdk_event_new (OS.GDK_EXPOSE); - GdkEventExpose event = new GdkEventExpose (); - event.type = OS.GDK_EXPOSE; - event.window = OS.g_object_ref (window); - event.area_width = rect.width; - event.area_height = rect.height; - event.region = OS.gdk_region_rectangle (rect); - OS.memmove (eventPtr, event, GdkEventExpose.sizeof); - OS.gtk_widget_send_expose (userData [0], eventPtr); - OS.gdk_event_free (eventPtr); - } - int srcX = x_offset [0], srcY = y_offset [0]; - int destX = x, destY = y, destWidth = width [0], destHeight = height [0]; - if (!first) { - int [] cX = new int [1], cY = new int [1]; - OS.gdk_window_get_position (window, cX, cY); - int /*long*/ parentWindow = OS.gdk_window_get_parent (window); - int [] pW = new int [1], pH = new int [1]; - OS.gdk_drawable_get_size (parentWindow, pW, pH); - srcX = x_offset [0] - cX [0]; - srcY = y_offset [0] - cY [0]; - destX = x - cX [0]; - destY = y - cY [0]; - destWidth = Math.min (cX [0] + width [0], pW [0]); - destHeight = Math.min (cY [0] + height [0], pH [0]); - } - GCData gcData = gc.getGCData(); - int /*long*/ cairo = gcData.cairo; - if (cairo != 0) { - int /*long*/ xDisplay = OS.GDK_DISPLAY(); - int /*long*/ xVisual = OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system()); - int /*long*/ xDrawable = OS.GDK_PIXMAP_XID(real_drawable [0]); - int /*long*/ surface = Cairo.cairo_xlib_surface_create(xDisplay, xDrawable, xVisual, width [0], height [0]); - if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); - Cairo.cairo_save(cairo); - Cairo.cairo_rectangle(cairo, destX , destY, destWidth, destHeight); - Cairo.cairo_clip(cairo); - Cairo.cairo_translate(cairo, destX, destY); - int /*long*/ pattern = Cairo.cairo_pattern_create_for_surface(surface); - if (pattern == 0) SWT.error(SWT.ERROR_NO_HANDLES); - Cairo.cairo_pattern_set_filter(pattern, Cairo.CAIRO_FILTER_BEST); - Cairo.cairo_set_source(cairo, pattern); - if (gcData.alpha != 0xFF) { - Cairo.cairo_paint_with_alpha(cairo, gcData.alpha / (float)0xFF); - } else { - Cairo.cairo_paint(cairo); - } - Cairo.cairo_restore(cairo); - Cairo.cairo_pattern_destroy(pattern); - Cairo.cairo_surface_destroy(surface); - } else { - OS.gdk_draw_drawable (drawable, gc.handle, real_drawable [0], srcX, srcY, destX, destY, destWidth, destHeight); - } - OS.gdk_window_end_paint (window); - int /*long*/ children = OS.gdk_window_get_children (window); - if (children != 0) { - int /*long*/ windows = children; - while (windows != 0) { - int /*long*/ child = OS.g_list_data (windows); - if (OS.gdk_window_is_visible (child)) { - int /*long*/ [] data = new int /*long*/ [1]; - OS.gdk_window_get_user_data (child, data); - if (data [0] != 0) { - Widget widget = display.findWidget (data [0]); - if (widget == null || widget == control) { - int [] x_pos = new int [1], y_pos = new int [1]; - OS.gdk_window_get_position (child, x_pos, y_pos); - printWindow (false, control, gc, drawable, depth, child, x + x_pos [0], y + y_pos [0]); - } - } - } - windows = OS.g_list_next (windows); - } - OS.g_list_free (children); - } -} - -/** - * Returns the preferred size of the receiver. - *

    - * The preferred size of a control is the size that it would - * best be displayed at. The width hint and height hint arguments - * allow the caller to ask a control questions such as "Given a particular - * width, how high does the control need to be to show all of the contents?" - * To indicate that the caller does not wish to constrain a particular - * dimension, the constant SWT.DEFAULT is passed for the hint. - *

    - * - * @param wHint the width hint (can be SWT.DEFAULT) - * @param hHint the height hint (can be SWT.DEFAULT) - * @return the preferred size of the control - * - * @exception 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 Layout - * @see #getBorderWidth - * @see #getBounds - * @see #getSize - * @see #pack(boolean) - * @see "computeTrim, getClientArea for controls that implement them" - */ -public Point computeSize (int wHint, int hHint) { - return computeSize (wHint, hHint, true); -} - -Widget computeTabGroup () { - if (isTabGroup()) return this; - return parent.computeTabGroup (); -} - -Widget[] computeTabList() { - if (isTabGroup()) { - if (getVisible() && getEnabled()) { - return new Widget[] {this}; - } - } - return new Widget[0]; -} - -Control computeTabRoot () { - Control[] tabList = parent._getTabList(); - if (tabList != null) { - int index = 0; - while (index < tabList.length) { - if (tabList [index] == this) break; - index++; - } - if (index == tabList.length) { - if (isTabGroup ()) return this; - } - } - return parent.computeTabRoot (); -} - -void checkBuffered () { - style |= SWT.DOUBLE_BUFFERED; -} - -void checkBackground () { - Shell shell = getShell (); - if (this == shell) return; - state &= ~PARENT_BACKGROUND; - Composite composite = parent; - do { - int mode = composite.backgroundMode; - if (mode != SWT.INHERIT_NONE) { - if (mode == SWT.INHERIT_DEFAULT) { - Control control = this; - do { - if ((control.state & THEME_BACKGROUND) == 0) { - return; - } - control = control.parent; - } while (control != composite); - } - state |= PARENT_BACKGROUND; - return; - } - if (composite == shell) break; - composite = composite.parent; - } while (true); -} - -void checkBorder () { - if (getBorderWidth () == 0) style &= ~SWT.BORDER; -} - -void checkMirrored () { - if ((style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.MIRRORED; -} - -int /*long*/ childStyle () { - return parent.childStyle (); -} - -void createWidget (int index) { - state |= DRAG_DETECT; - checkOrientation (parent); - super.createWidget (index); - checkBackground (); - if ((state & PARENT_BACKGROUND) != 0) setBackground (); - checkBuffered (); - showWidget (); - setInitialBounds (); - setZOrder (null, false, false); - setRelations (); - checkMirrored (); - checkBorder (); -} - -/** - * Returns the preferred size of the receiver. - *

    - * The preferred size of a control is the size that it would - * best be displayed at. The width hint and height hint arguments - * allow the caller to ask a control questions such as "Given a particular - * width, how high does the control need to be to show all of the contents?" - * To indicate that the caller does not wish to constrain a particular - * dimension, the constant SWT.DEFAULT is passed for the hint. - *

    - * If the changed flag is true, it indicates that the receiver's - * contents have changed, therefore any caches that a layout manager - * containing the control may have been keeping need to be flushed. When the - * control is resized, the changed flag will be false, so layout - * manager caches can be retained. - *

    - * - * @param wHint the width hint (can be SWT.DEFAULT) - * @param hHint the height hint (can be SWT.DEFAULT) - * @param changed true if the control's contents have changed, and false otherwise - * @return the preferred size of the control. - * - * @exception 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 Layout - * @see #getBorderWidth - * @see #getBounds - * @see #getSize - * @see #pack(boolean) - * @see "computeTrim, getClientArea for controls that implement them" - */ -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; - if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - return computeNativeSize (handle, wHint, hHint, changed); -} - -Point computeNativeSize (int /*long*/ h, int wHint, int hHint, boolean changed) { - int width = wHint, height = hHint; - if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) { - GtkRequisition requisition = new GtkRequisition (); - gtk_widget_size_request (h, requisition); - width = OS.GTK_WIDGET_REQUISITION_WIDTH (h); - height = OS.GTK_WIDGET_REQUISITION_HEIGHT (h); - } else if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { - int [] reqWidth = new int [1], reqHeight = new int [1]; - OS.gtk_widget_get_size_request (h, reqWidth, reqHeight); - OS.gtk_widget_set_size_request (h, wHint, hHint); - GtkRequisition requisition = new GtkRequisition (); - gtk_widget_size_request (h, requisition); - OS.gtk_widget_set_size_request (h, reqWidth [0], reqHeight [0]); - width = wHint == SWT.DEFAULT ? requisition.width : wHint; - height = hHint == SWT.DEFAULT ? requisition.height : hHint; - } - return new Point (width, height); -} - -void forceResize () { - /* - * Force size allocation on all children of this widget's - * topHandle. Note that all calls to gtk_widget_size_allocate() - * must be preceded by a call to gtk_widget_size_request(). - */ - int /*long*/ topHandle = topHandle (); - GtkRequisition requisition = new GtkRequisition (); - gtk_widget_size_request (topHandle, requisition); - GtkAllocation allocation = new GtkAllocation (); - allocation.x = OS.GTK_WIDGET_X (topHandle); - allocation.y = OS.GTK_WIDGET_Y (topHandle); - allocation.width = OS.GTK_WIDGET_WIDTH (topHandle); - allocation.height = OS.GTK_WIDGET_HEIGHT (topHandle); - OS.gtk_widget_size_allocate (topHandle, allocation); -} - -/** - * Returns the accessible object for the receiver. - * If this is the first time this object is requested, - * then the object is created and returned. - * - * @return the accessible object - * - * @exception 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 Accessible#addAccessibleListener - * @see Accessible#addAccessibleControlListener - * - * @since 2.0 - */ -public Accessible getAccessible () { - checkWidget (); - if (accessible == null) { - accessible = Accessible.internal_new_Accessible (this); - } - return accessible; -} - -/** - * Returns a rectangle describing the receiver's size and location - * relative to its parent (or its display if its parent is null), - * unless the receiver is a shell. In this case, the location is - * relative to the display. - * - * @return the receiver's bounding rectangle - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Rectangle getBounds () { - checkWidget(); - int /*long*/ topHandle = topHandle (); - int x = OS.GTK_WIDGET_X (topHandle); - int y = OS.GTK_WIDGET_Y (topHandle); - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle); - if ((parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - width - x; - return new Rectangle (x, y, width, height); -} - -/** - * Sets the receiver's size and location to the rectangular - * area specified by the argument. The x and - * y fields of the rectangle are relative to - * the receiver's parent (or its display if its parent is null). - *

    - * Note: Attempting to set the width or height of the - * receiver to a negative number will cause that - * value to be set to zero instead. - *

    - * - * @param rect the new bounds for the receiver - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setBounds (Rectangle rect) { - checkWidget (); - if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); - setBounds (rect.x, rect.y, Math.max (0, rect.width), Math.max (0, rect.height), true, true); -} - -/** - * Sets the receiver's size and location to the rectangular - * area specified by the arguments. The x and - * y arguments are relative to the receiver's - * parent (or its display if its parent is null), unless - * the receiver is a shell. In this case, the x - * and y arguments are relative to the display. - *

    - * Note: Attempting to set the width or height of the - * receiver to a negative number will cause that - * value to be set to zero instead. - *

    - * - * @param x the new x coordinate for the receiver - * @param y the new y coordinate for the receiver - * @param width the new width for the receiver - * @param height the new height for the receiver - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setBounds (int x, int y, int width, int height) { - checkWidget(); - setBounds (x, y, Math.max (0, width), Math.max (0, height), true, true); -} - -void markLayout (boolean changed, boolean all) { - /* Do nothing */ -} - -void modifyStyle (int /*long*/ handle, int /*long*/ style) { - super.modifyStyle(handle, style); - /* - * Bug in GTK. When changing the style of a control that - * has had a region set on it, the region is lost. The - * fix is to set the region again. - */ - if (region != null) OS.gdk_window_shape_combine_region (OS.GTK_WIDGET_WINDOW (topHandle ()), region.handle, 0, 0); -} - -void moveHandle (int x, int y) { - int /*long*/ topHandle = topHandle (); - int /*long*/ parentHandle = parent.parentingHandle (); - /* - * Feature in GTK. Calling gtk_fixed_move() to move a child causes - * the whole parent to redraw. This is a performance problem. The - * fix is temporarily make the parent not visible during the move. - * - * NOTE: Because every widget in SWT has an X window, the new and - * old bounds of the child are correctly redrawn. - */ - int flags = OS.GTK_WIDGET_FLAGS (parentHandle); - OS.GTK_WIDGET_UNSET_FLAGS (parentHandle, OS.GTK_VISIBLE); - OS.gtk_fixed_move (parentHandle, topHandle, x, y); - if ((flags & OS.GTK_VISIBLE) != 0) { - OS.GTK_WIDGET_SET_FLAGS (parentHandle, OS.GTK_VISIBLE); - } -} - -void resizeHandle (int width, int height) { - int /*long*/ topHandle = topHandle (); - OS.gtk_widget_set_size_request (topHandle, width, height); - if (topHandle != handle) OS.gtk_widget_set_size_request (handle, width, height); -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int /*long*/ topHandle = topHandle (); - boolean sendMove = move; - if ((parent.style & SWT.MIRRORED) != 0) { - int clientWidth = parent.getClientWidth (); - int oldWidth = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - int oldX = clientWidth - oldWidth - OS.GTK_WIDGET_X (topHandle); - if (move) { - sendMove &= x != oldX; - x = clientWidth - (resize ? width : oldWidth) - x; - } else { - move = true; - x = clientWidth - (resize ? width : oldWidth) - oldX; - y = OS.GTK_WIDGET_Y (topHandle); - } - } - boolean sameOrigin = true, sameExtent = true; - if (move) { - int oldX = OS.GTK_WIDGET_X (topHandle); - int oldY = OS.GTK_WIDGET_Y (topHandle); - sameOrigin = x == oldX && y == oldY; - if (!sameOrigin) { - if (enableWindow != 0) { - OS.gdk_window_move (enableWindow, x, y); - } - moveHandle (x, y); - } - } - int clientWidth = 0; - if (resize) { - int oldWidth = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - int oldHeight = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle); - sameExtent = width == oldWidth && height == oldHeight; - if (!sameExtent && (style & SWT.MIRRORED) != 0) clientWidth = getClientWidth (); - if (!sameExtent && !(width == 0 && height == 0)) { - int newWidth = Math.max (1, width); - int newHeight = Math.max (1, height); - if (redrawWindow != 0) { - OS.gdk_window_resize (redrawWindow, newWidth, newHeight); - } - if (enableWindow != 0) { - OS.gdk_window_resize (enableWindow, newWidth, newHeight); - } - resizeHandle (newWidth, newHeight); - } - } - if (!sameOrigin || !sameExtent) { - /* - * Cause a size allocation this widget's topHandle. Note that - * all calls to gtk_widget_size_allocate() must be preceded by - * a call to gtk_widget_size_request(). - */ - GtkRequisition requisition = new GtkRequisition (); - gtk_widget_size_request (topHandle, requisition); - GtkAllocation allocation = new GtkAllocation (); - if (move) { - allocation.x = x; - allocation.y = y; - } else { - allocation.x = OS.GTK_WIDGET_X (topHandle); - allocation.y = OS.GTK_WIDGET_Y (topHandle); - } - if (resize) { - allocation.width = width; - allocation.height = height; - } else { - allocation.width = OS.GTK_WIDGET_WIDTH (topHandle); - allocation.height = OS.GTK_WIDGET_HEIGHT (topHandle); - } - OS.gtk_widget_size_allocate (topHandle, allocation); - } - /* - * Bug in GTK. Widgets cannot be sized smaller than 1x1. - * The fix is to hide zero-sized widgets and show them again - * when they are resized larger. - */ - if (!sameExtent) { - state = (width == 0) ? state | ZERO_WIDTH : state & ~ZERO_WIDTH; - state = (height == 0) ? state | ZERO_HEIGHT : state & ~ZERO_HEIGHT; - if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) != 0) { - if (enableWindow != 0) { - OS.gdk_window_hide (enableWindow); - } - OS.gtk_widget_hide (topHandle); - } else { - if ((state & HIDDEN) == 0) { - if (enableWindow != 0) { - OS.gdk_window_show_unraised (enableWindow); - } - OS.gtk_widget_show (topHandle); - } - } - if ((style & SWT.MIRRORED) != 0) moveChildren (clientWidth); - } - int result = 0; - if (move && !sameOrigin) { - Control control = findBackgroundControl (); - if (control != null && control.backgroundImage != null) { - if (isVisible ()) redrawWidget (0, 0, 0, 0, true, true, true); - } - if (sendMove) sendEvent (SWT.Move); - result |= MOVED; - } - if (resize && !sameExtent) { - sendEvent (SWT.Resize); - result |= RESIZED; - } - return result; -} - -/** - * Returns a point describing the receiver's location relative - * to its parent (or its display if its parent is null), unless - * the receiver is a shell. In this case, the point is - * relative to the display. - * - * @return the receiver's location - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Point getLocation () { - checkWidget(); - int /*long*/ topHandle = topHandle (); - int x = OS.GTK_WIDGET_X (topHandle); - int y = OS.GTK_WIDGET_Y (topHandle); - if ((parent.style & SWT.MIRRORED) != 0) { - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - x = parent.getClientWidth () - width - x; - } - return new Point (x, y); -} - -/** - * Sets the receiver's location to the point specified by - * the arguments which are relative to the receiver's - * parent (or its display if its parent is null), unless - * the receiver is a shell. In this case, the point is - * relative to the display. - * - * @param location the new location for the receiver - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setLocation (Point location) { - checkWidget (); - if (location == null) error (SWT.ERROR_NULL_ARGUMENT); - setBounds (location.x, location.y, 0, 0, true, false); -} - -/** - * Sets the receiver's location to the point specified by - * the arguments which are relative to the receiver's - * parent (or its display if its parent is null), unless - * the receiver is a shell. In this case, the point is - * relative to the display. - * - * @param x the new x coordinate for the receiver - * @param y the new y coordinate for the receiver - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setLocation(int x, int y) { - checkWidget(); - setBounds (x, y, 0, 0, true, false); -} - -/** - * Returns a point describing the receiver's size. The - * x coordinate of the result is the width of the receiver. - * The y coordinate of the result is the height of the - * receiver. - * - * @return the receiver's size - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Point getSize () { - checkWidget(); - int /*long*/ topHandle = topHandle (); - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle); - return new Point (width, height); -} - -/** - * Sets the receiver's size to the point specified by the argument. - *

    - * Note: Attempting to set the width or height of the - * receiver to a negative number will cause them to be - * set to zero instead. - *

    - * - * @param size the new size for the receiver - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the point is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setSize (Point size) { - checkWidget (); - if (size == null) error (SWT.ERROR_NULL_ARGUMENT); - setBounds (0, 0, Math.max (0, size.x), Math.max (0, size.y), false, true); -} - -/** - * Sets the shape of the control to the region specified - * by the argument. When the argument is null, the - * default shape of the control is restored. - * - * @param region the region that defines the shape of the control (or null) - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the region has been disposed
    • - *
    - * @exception 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 - */ -public void setRegion (Region region) { - checkWidget (); - if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle ()); - int /*long*/ shape_region = (region == null) ? 0 : region.handle; - OS.gdk_window_shape_combine_region (window, shape_region, 0, 0); - this.region = region; -} - -void setRelations () { - int /*long*/ parentHandle = parent.parentingHandle (); - int /*long*/ list = OS.gtk_container_get_children (parentHandle); - if (list == 0) return; - int count = OS.g_list_length (list); - if (count > 1) { - /* - * the receiver is the last item in the list, so its predecessor will - * be the second-last item in the list - */ - int /*long*/ handle = OS.g_list_nth_data (list, count - 2); - if (handle != 0) { - Widget widget = display.getWidget (handle); - if (widget != null && widget != this) { - if (widget instanceof Control) { - Control sibling = (Control)widget; - sibling.addRelation (this); - } - } - } - } - OS.g_list_free (list); -} - -/** - * Sets the receiver's size to the point specified by the arguments. - *

    - * Note: Attempting to set the width or height of the - * receiver to a negative number will cause that - * value to be set to zero instead. - *

    - * - * @param width the new width for the receiver - * @param height the new height for the receiver - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setSize (int width, int height) { - checkWidget(); - setBounds (0, 0, Math.max (0, width), Math.max (0, height), false, true); -} - - -boolean isActive () { - return getShell ().getModalShell () == null && display.getModalDialog () == null; -} - -/* - * Answers a boolean indicating whether a Label that precedes the receiver in - * a layout should be read by screen readers as the recevier's label. - */ -boolean isDescribedByLabel () { - return true; -} - -boolean isFocusHandle (int /*long*/ widget) { - return widget == focusHandle (); -} - -/** - * Moves the receiver above the specified control in the - * drawing order. If the argument is null, then the receiver - * is moved to the top of the drawing order. The control at - * the top of the drawing order will not be covered by other - * controls even if they occupy intersecting areas. - * - * @param control the sibling control (or null) - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the control has been disposed
    • - *
    - * @exception 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 Control#moveBelow - * @see Composite#getChildren - */ -public void moveAbove (Control control) { - checkWidget(); - if (control != null) { - if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - if (parent != control.parent) return; - } - setZOrder (control, true, true); -} - -/** - * Moves the receiver below the specified control in the - * drawing order. If the argument is null, then the receiver - * is moved to the bottom of the drawing order. The control at - * the bottom of the drawing order will be covered by all other - * controls which occupy intersecting areas. - * - * @param control the sibling control (or null) - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the control has been disposed
    • - *
    - * @exception 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 Control#moveAbove - * @see Composite#getChildren - */ -public void moveBelow (Control control) { - checkWidget(); - if (control != null) { - if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT); - if (parent != control.parent) return; - } - setZOrder (control, false, true); -} - -void moveChildren (int oldWidth) { -} - -/** - * Causes the receiver to be resized to its preferred size. - * For a composite, this involves computing the preferred size - * from its layout, if there is one. - * - * @exception 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 #computeSize(int, int, boolean) - */ -public void pack () { - pack (true); -} - -/** - * Causes the receiver to be resized to its preferred size. - * For a composite, this involves computing the preferred size - * from its layout, if there is one. - *

    - * If the changed flag is true, it indicates that the receiver's - * contents have changed, therefore any caches that a layout manager - * containing the control may have been keeping need to be flushed. When the - * control is resized, the changed flag will be false, so layout - * manager caches can be retained. - *

    - * - * @param changed whether or not the receiver's contents have changed - * - * @exception 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 #computeSize(int, int, boolean) - */ -public void pack (boolean changed) { - setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed)); -} - -/** - * Sets the layout data associated with the receiver to the argument. - * - * @param layoutData the new layout data for the receiver. - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setLayoutData (Object layoutData) { - checkWidget(); - this.layoutData = layoutData; -} - -/** - * Returns a point which is the result of converting the - * argument, which is specified in display relative coordinates, - * to coordinates relative to the receiver. - *

    - * @param x the x coordinate to be translated - * @param y the y coordinate to be translated - * @return the translated coordinates - * - * @exception 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 2.1 - */ -public Point toControl (int x, int y) { - checkWidget (); - int /*long*/ window = eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - x -= origin_x [0]; - y -= origin_y [0]; - if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x; - return new Point (x, y); -} - -/** - * Returns a point which is the result of converting the - * argument, which is specified in display relative coordinates, - * to coordinates relative to the receiver. - *

    - * @param point the point to be translated (must not be null) - * @return the translated coordinates - * - * @exception IllegalArgumentException

      - *
    • ERROR_NULL_ARGUMENT - if the point is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Point toControl (Point point) { - checkWidget (); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - return toControl (point.x, point.y); -} - -/** - * Returns a point which is the result of converting the - * argument, which is specified in coordinates relative to - * the receiver, to display relative coordinates. - *

    - * @param x the x coordinate to be translated - * @param y the y coordinate to be translated - * @return the translated coordinates - * - * @exception 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 2.1 - */ -public Point toDisplay (int x, int y) { - checkWidget(); - int /*long*/ window = eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x; - x += origin_x [0]; - y += origin_y [0]; - return new Point (x, y); -} - -/** - * Returns a point which is the result of converting the - * argument, which is specified in coordinates relative to - * the receiver, to display relative coordinates. - *

    - * @param point the point to be translated (must not be null) - * @return the translated coordinates - * - * @exception IllegalArgumentException

      - *
    • ERROR_NULL_ARGUMENT - if the point is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Point toDisplay (Point point) { - checkWidget(); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - return toDisplay (point.x, point.y); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is moved or resized, by sending - * it one of the messages defined in the ControlListener - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 ControlListener - * @see #removeControlListener - */ -public void addControlListener(ControlListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Resize,typedListener); - addListener (SWT.Move,typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when a drag gesture occurs, by sending it - * one of the messages defined in the DragDetectListener - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 DragDetectListener - * @see #removeDragDetectListener - * - * @since 3.3 - */ -public void addDragDetectListener (DragDetectListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.DragDetect,typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the control gains or loses focus, by sending - * it one of the messages defined in the FocusListener - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 FocusListener - * @see #removeFocusListener - */ -public void addFocusListener(FocusListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.FocusIn,typedListener); - addListener(SWT.FocusOut,typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when help events are generated for the control, - * by sending it one of the messages defined in the - * HelpListener interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 HelpListener - * @see #removeHelpListener - */ -public void addHelpListener (HelpListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Help, typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when keys are pressed and released on the system keyboard, by sending - * it one of the messages defined in the KeyListener - * interface. - *

    - * When a key listener is added to a control, the control - * will take part in widget traversal. By default, all - * traversal keys (such as the tab key and so on) are - * delivered to the control. In order for a control to take - * part in traversal, it should listen for traversal events. - * Otherwise, the user can traverse into a control but not - * out. Note that native controls such as table and tree - * implement key traversal in the operating system. It is - * not necessary to add traversal listeners for these controls, - * unless you want to override the default traversal. - *

    - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 KeyListener - * @see #removeKeyListener - */ -public void addKeyListener(KeyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.KeyUp,typedListener); - addListener(SWT.KeyDown,typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the platform-specific context menu trigger - * has occurred, by sending it one of the messages defined in - * the MenuDetectListener interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 MenuDetectListener - * @see #removeMenuDetectListener - * - * @since 3.3 - */ -public void addMenuDetectListener (MenuDetectListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.MenuDetect, typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when mouse buttons are pressed and released, by sending - * it one of the messages defined in the MouseListener - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 MouseListener - * @see #removeMouseListener - */ -public void addMouseListener(MouseListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.MouseDown,typedListener); - addListener(SWT.MouseUp,typedListener); - addListener(SWT.MouseDoubleClick,typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the mouse moves, by sending it one of the - * messages defined in the MouseMoveListener - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 MouseMoveListener - * @see #removeMouseMoveListener - */ -public void addMouseMoveListener(MouseMoveListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.MouseMove,typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the mouse passes or hovers over controls, by sending - * it one of the messages defined in the MouseTrackListener - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 MouseTrackListener - * @see #removeMouseTrackListener - */ -public void addMouseTrackListener (MouseTrackListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.MouseEnter,typedListener); - addListener (SWT.MouseExit,typedListener); - addListener (SWT.MouseHover,typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the mouse wheel is scrolled, by sending - * it one of the messages defined in the - * MouseWheelListener interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 MouseWheelListener - * @see #removeMouseWheelListener - * - * @since 3.3 - */ -public void addMouseWheelListener (MouseWheelListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.MouseWheel, typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver needs to be painted, by sending it - * one of the messages defined in the PaintListener - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 PaintListener - * @see #removePaintListener - */ -public void addPaintListener(PaintListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.Paint,typedListener); -} - -void addRelation (Control control) { -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when traversal events occur, by sending it - * one of the messages defined in the TraverseListener - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 TraverseListener - * @see #removeTraverseListener - */ -public void addTraverseListener (TraverseListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Traverse,typedListener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is moved or resized. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 ControlListener - * @see #addControlListener - */ -public void removeControlListener (ControlListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Move, listener); - eventTable.unhook (SWT.Resize, listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when a drag gesture occurs. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 DragDetectListener - * @see #addDragDetectListener - * - * @since 3.3 - */ -public void removeDragDetectListener(DragDetectListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.DragDetect, listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the control gains or loses focus. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 FocusListener - * @see #addFocusListener - */ -public void removeFocusListener(FocusListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.FocusIn, listener); - eventTable.unhook (SWT.FocusOut, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the help events are generated for the control. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 HelpListener - * @see #addHelpListener - */ -public void removeHelpListener (HelpListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Help, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when keys are pressed and released on the system keyboard. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 KeyListener - * @see #addKeyListener - */ -public void removeKeyListener(KeyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.KeyUp, listener); - eventTable.unhook (SWT.KeyDown, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the platform-specific context menu trigger has - * occurred. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 MenuDetectListener - * @see #addMenuDetectListener - * - * @since 3.3 - */ -public void removeMenuDetectListener (MenuDetectListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.MenuDetect, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when mouse buttons are pressed and released. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 MouseListener - * @see #addMouseListener - */ -public void removeMouseListener (MouseListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.MouseDown, listener); - eventTable.unhook (SWT.MouseUp, listener); - eventTable.unhook (SWT.MouseDoubleClick, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the mouse moves. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 MouseMoveListener - * @see #addMouseMoveListener - */ -public void removeMouseMoveListener(MouseMoveListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.MouseMove, listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the mouse passes or hovers over controls. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 MouseTrackListener - * @see #addMouseTrackListener - */ -public void removeMouseTrackListener(MouseTrackListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.MouseEnter, listener); - eventTable.unhook (SWT.MouseExit, listener); - eventTable.unhook (SWT.MouseHover, listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the mouse wheel is scrolled. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 MouseWheelListener - * @see #addMouseWheelListener - * - * @since 3.3 - */ -public void removeMouseWheelListener (MouseWheelListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.MouseWheel, listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver needs to be painted. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 PaintListener - * @see #addPaintListener - */ -public void removePaintListener(PaintListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Paint, listener); -} - -/* - * Remove "Labelled by" relations from the receiver. - */ -void removeRelation () { - if (!isDescribedByLabel ()) return; /* there will not be any */ - int /*long*/ accessible = OS.gtk_widget_get_accessible (handle); - if (accessible == 0) return; - int /*long*/ set = ATK.atk_object_ref_relation_set (accessible); - int count = ATK.atk_relation_set_get_n_relations (set); - for (int i = 0; i < count; i++) { - int /*long*/ relation = ATK.atk_relation_set_get_relation (set, 0); - ATK.atk_relation_set_remove (set, relation); - } - OS.g_object_unref (set); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when traversal events occur. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 TraverseListener - * @see #addTraverseListener - */ -public void removeTraverseListener(TraverseListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Traverse, listener); -} - -/** - * Detects a drag and drop gesture. This method is used - * to detect a drag gesture when called from within a mouse - * down listener. - * - *

    By default, a drag is detected when the gesture - * occurs anywhere within the client area of a control. - * Some controls, such as tables and trees, override this - * behavior. In addition to the operating system specific - * drag gesture, they require the mouse to be inside an - * item. Custom widget writers can use setDragDetect - * to disable the default detection, listen for mouse down, - * and then call dragDetect() from within the - * listener to conditionally detect a drag. - *

    - * - * @param event the mouse down event - * - * @return true if the gesture occurred, and false otherwise. - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT when the event is null
    • - *
    - * @exception 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 DragDetectListener - * @see #addDragDetectListener - * - * @see #getDragDetect - * @see #setDragDetect - * - * @since 3.3 - */ -public boolean dragDetect (Event event) { - checkWidget (); - if (event == null) error (SWT.ERROR_NULL_ARGUMENT); - return dragDetect (event.button, event.count, event.stateMask, event.x, event.y); -} - -/** - * Detects a drag and drop gesture. This method is used - * to detect a drag gesture when called from within a mouse - * down listener. - * - *

    By default, a drag is detected when the gesture - * occurs anywhere within the client area of a control. - * Some controls, such as tables and trees, override this - * behavior. In addition to the operating system specific - * drag gesture, they require the mouse to be inside an - * item. Custom widget writers can use setDragDetect - * to disable the default detection, listen for mouse down, - * and then call dragDetect() from within the - * listener to conditionally detect a drag. - *

    - * - * @param event the mouse down event - * - * @return true if the gesture occurred, and false otherwise. - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT when the event is null
    • - *
    - * @exception 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 DragDetectListener - * @see #addDragDetectListener - * - * @see #getDragDetect - * @see #setDragDetect - * - * @since 3.3 - */ -public boolean dragDetect (MouseEvent event) { - checkWidget (); - if (event == null) error (SWT.ERROR_NULL_ARGUMENT); - return dragDetect (event.button, event.count, event.stateMask, event.x, event.y); -} - -boolean dragDetect (int button, int count, int stateMask, int x, int y) { - if (button != 1 || count != 1) return false; - if (!dragDetect (x, y, false, null)) return false; - return sendDragEvent (button, stateMask, x, y, true); -} - -boolean dragDetect (int x, int y, boolean filter, boolean [] consume) { - boolean quit = false, dragging = false; - while (!quit) { - int /*long*/ eventPtr = 0; - /* - * There should be an event on the queue already, but - * in cases where there isn't one, stop trying after - * half a second. - */ - long timeout = System.currentTimeMillis() + 500; - while (System.currentTimeMillis() < timeout) { - eventPtr = OS.gdk_event_get (); - if (eventPtr != 0) { - break; - } else { - try {Thread.sleep(50);} catch (Exception ex) {} - } - } - if (eventPtr == 0) return false; - switch (OS.GDK_EVENT_TYPE (eventPtr)) { - case OS.GDK_MOTION_NOTIFY: { - GdkEventMotion gdkMotionEvent = new GdkEventMotion (); - OS.memmove (gdkMotionEvent, eventPtr, GdkEventMotion.sizeof); - if ((gdkMotionEvent.state & OS.GDK_BUTTON1_MASK) != 0) { - if (OS.gtk_drag_check_threshold (handle, x, y, (int) gdkMotionEvent.x, (int) gdkMotionEvent.y)) { - dragging = true; - quit = true; - } - } else { - quit = true; - } - int [] newX = new int [1], newY = new int [1]; - OS.gdk_window_get_pointer (gdkMotionEvent.window, newX, newY, null); - break; - } - case OS.GDK_KEY_PRESS: - case OS.GDK_KEY_RELEASE: { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - if (gdkEvent.keyval == OS.GDK_Escape) quit = true; - break; - } - case OS.GDK_BUTTON_RELEASE: - case OS.GDK_BUTTON_PRESS: - case OS.GDK_2BUTTON_PRESS: - case OS.GDK_3BUTTON_PRESS: { - OS.gdk_event_put (eventPtr); - quit = true; - break; - } - default: - OS.gtk_main_do_event (eventPtr); - } - OS.gdk_event_free (eventPtr); - } - return dragging; -} - -boolean filterKey (int keyval, int /*long*/ event) { - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - return OS.gtk_im_context_filter_keypress (imHandle, event); - } - return false; -} - -Control findBackgroundControl () { - if ((state & BACKGROUND) != 0 || backgroundImage != null) return this; - return (state & PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null; -} - -Menu [] findMenus (Control control) { - if (menu != null && this != control) return new Menu [] {menu}; - return new Menu [0]; -} - -void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) { - oldShell.fixShell (newShell, this); - oldDecorations.fixDecorations (newDecorations, this, menus); -} - -int /*long*/ fixedMapProc (int /*long*/ widget) { - OS.GTK_WIDGET_SET_FLAGS (widget, OS.GTK_MAPPED); - int /*long*/ widgetList = OS.gtk_container_get_children (widget); - if (widgetList != 0) { - int /*long*/ widgets = widgetList; - while (widgets != 0) { - int /*long*/ child = OS.g_list_data (widgets); - if (OS.GTK_WIDGET_VISIBLE (child) && OS.gtk_widget_get_child_visible (child) && !OS.GTK_WIDGET_MAPPED (child)) { - OS.gtk_widget_map (child); - } - widgets = OS.g_list_next (widgets); - } - OS.g_list_free (widgetList); - } - if ((OS.GTK_WIDGET_FLAGS (widget) & OS.GTK_NO_WINDOW) == 0) { - OS.gdk_window_show_unraised (OS.GTK_WIDGET_WINDOW (widget)); - } - return 0; -} - -void fixModal(int /*long*/ group, int /*long*/ modalGroup) { -} - -/** - * Forces the receiver to have the keyboard focus, causing - * all keyboard events to be delivered to it. - * - * @return true if the control got focus, and false if it was unable to. - * - * @exception 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 #setFocus - */ -public boolean forceFocus () { - checkWidget(); - if (display.focusEvent == SWT.FocusOut) return false; - Shell shell = getShell (); - shell.setSavedFocus (this); - if (!isEnabled () || !isVisible ()) return false; - shell.bringToTop (false); - return forceFocus (focusHandle ()); -} - -boolean forceFocus (int /*long*/ focusHandle) { - if (OS.GTK_WIDGET_HAS_FOCUS (focusHandle)) return true; - /* When the control is zero sized it must be realized */ - OS.gtk_widget_realize (focusHandle); - OS.gtk_widget_grab_focus (focusHandle); - Shell shell = getShell (); - int /*long*/ shellHandle = shell.shellHandle; - int /*long*/ handle = OS.gtk_window_get_focus (shellHandle); - while (handle != 0) { - if (handle == focusHandle) { - /* Cancel any previous ignoreFocus requests */ - display.ignoreFocus = false; - return true; - } - Widget widget = display.getWidget (handle); - if (widget != null && widget instanceof Control) { - return widget == this; - } - handle = OS.gtk_widget_get_parent (handle); - } - return false; -} - -/** - * Returns the receiver's background color. - *

    - * Note: This operation is a hint and may be overridden by the platform. - * For example, on some versions of Windows the background of a TabFolder, - * is a gradient rather than a solid color. - *

    - * @return the background color - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Color getBackground () { - checkWidget(); - Control control = findBackgroundControl (); - if (control == null) control = this; - return Color.gtk_new (display, control.getBackgroundColor ()); -} - -GdkColor getBackgroundColor () { - return getBgColor (); -} - -/** - * Returns the receiver's background image. - * - * @return the background image - * - * @exception 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.2 - */ -public Image getBackgroundImage () { - checkWidget (); - Control control = findBackgroundControl (); - if (control == null) control = this; - return control.backgroundImage; -} - -GdkColor getBgColor () { - int /*long*/ fontHandle = fontHandle (); - OS.gtk_widget_realize (fontHandle); - GdkColor color = new GdkColor (); - OS.gtk_style_get_bg (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color); - return color; -} - -GdkColor getBaseColor () { - int /*long*/ fontHandle = fontHandle (); - OS.gtk_widget_realize (fontHandle); - GdkColor color = new GdkColor (); - OS.gtk_style_get_base (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color); - return color; -} - -/** - * Returns the receiver's border width. - * - * @return the border width - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int getBorderWidth () { - checkWidget(); - return 0; -} - -int getClientWidth () { - return 0; -} - -/** - * Returns the receiver's cursor, or null if it has not been set. - *

    - * When the mouse pointer passes over a control its appearance - * is changed to match the control's cursor. - *

    - * - * @return the receiver's cursor or null - * - * @exception 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.3 - */ -public Cursor getCursor () { - checkWidget (); - return cursor; -} - -public Object getData(String key) { - if (key.equals(IS_ACTIVE)) return new Boolean(isActive ()); - return super.getData(key); -} - -/** - * Returns true if the receiver is detecting - * drag gestures, and false otherwise. - * - * @return the receiver's drag detect state - * - * @exception 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.3 - */ -public boolean getDragDetect () { - checkWidget (); - return (state & DRAG_DETECT) != 0; -} - -/** - * Returns true if the receiver is enabled, and - * false otherwise. A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception 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 #isEnabled - */ -public boolean getEnabled () { - checkWidget (); - return (state & DISABLED) == 0; -} - -/** - * Returns the font that the receiver will use to paint textual information. - * - * @return the receiver's font - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Font getFont () { - checkWidget(); - return font != null ? font : defaultFont (); -} - -int /*long*/ getFontDescription () { - int /*long*/ fontHandle = fontHandle (); - OS.gtk_widget_realize (fontHandle); - return OS.gtk_style_get_font_desc (OS.gtk_widget_get_style (fontHandle)); -} - -/** - * Returns the foreground color that the receiver will use to draw. - * - * @return the receiver's foreground color - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Color getForeground () { - checkWidget(); - return Color.gtk_new (display, getForegroundColor ()); -} - -GdkColor getForegroundColor () { - return getFgColor (); -} - -GdkColor getFgColor () { - int /*long*/ fontHandle = fontHandle (); - OS.gtk_widget_realize (fontHandle); - GdkColor color = new GdkColor (); - OS.gtk_style_get_fg (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color); - return color; -} - -Point getIMCaretPos () { - return new Point (0, 0); -} - -GdkColor getTextColor () { - int /*long*/ fontHandle = fontHandle (); - OS.gtk_widget_realize (fontHandle); - GdkColor color = new GdkColor (); - OS.gtk_style_get_text (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color); - return color; -} - -/** - * Returns layout data which is associated with the receiver. - * - * @return the receiver's layout data - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Object getLayoutData () { - checkWidget(); - return layoutData; -} - -/** - * Returns the receiver's pop up menu if it has one, or null - * if it does not. All controls may optionally have a pop up - * menu that is displayed when the user requests one for - * the control. The sequence of key strokes, button presses - * and/or button releases that are used to request a pop up - * menu is platform specific. - * - * @return the receiver's menu - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Menu getMenu () { - checkWidget(); - return menu; -} - -/** - * Returns the receiver's monitor. - * - * @return the receiver's monitor - * - * @since 3.0 - */ -public Monitor getMonitor () { - checkWidget(); - Monitor monitor = null; - int /*long*/ screen = OS.gdk_screen_get_default (); - if (screen != 0) { - int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, paintWindow ()); - GdkRectangle dest = new GdkRectangle (); - OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest); - monitor = new Monitor (); - monitor.handle = monitorNumber; - monitor.x = dest.x; - monitor.y = dest.y; - monitor.width = dest.width; - monitor.height = dest.height; - Rectangle workArea = null; - if (monitorNumber == 0) workArea = display.getWorkArea (); - if (workArea != null) { - monitor.clientX = workArea.x; - monitor.clientY = workArea.y; - monitor.clientWidth = workArea.width; - monitor.clientHeight = workArea.height; - } else { - monitor.clientX = monitor.x; - monitor.clientY = monitor.y; - monitor.clientWidth = monitor.width; - monitor.clientHeight = monitor.height; - } - } else { - monitor = display.getPrimaryMonitor (); - } - return monitor; -} - -/** - * Returns the receiver's parent, which must be a Composite - * or null when the receiver is a shell that was created with null or - * a display for a parent. - * - * @return the receiver's parent - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Composite getParent () { - checkWidget(); - return parent; -} - -Control [] getPath () { - int count = 0; - Shell shell = getShell (); - Control control = this; - while (control != shell) { - count++; - control = control.parent; - } - control = this; - Control [] result = new Control [count]; - while (control != shell) { - result [--count] = control; - control = control.parent; - } - return result; -} - -/** - * Returns the region that defines the shape of the control, - * or null if the control has the default shape. - * - * @return the region that defines the shape of the shell (or null) - * - * @exception 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 - */ -public Region getRegion () { - checkWidget (); - return region; -} - -/** - * Returns the receiver's shell. For all controls other than - * shells, this simply returns the control's nearest ancestor - * shell. Shells return themselves, even if they are children - * of other shells. - * - * @return the receiver's shell - * - * @exception 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 #getParent - */ -public Shell getShell() { - checkWidget(); - return _getShell(); -} - -Shell _getShell() { - return parent._getShell(); -} - -/** - * Returns the receiver's tool tip text, or null if it has - * not been set. - * - * @return the receiver's tool tip text - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public String getToolTipText () { - checkWidget(); - return toolTipText; -} -/** - * Returns true if the receiver is visible, and - * false otherwise. - *

    - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, this method - * may still indicate that it is considered visible even though - * it may not actually be showing. - *

    - * - * @return the receiver's visibility state - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public boolean getVisible () { - checkWidget(); - return (state & HIDDEN) == 0; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - return gtk_button_press_event (widget, event, true); -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event, boolean sendMouseDown) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - if (gdkEvent.type == OS.GDK_3BUTTON_PRESS) return 0; - - /* - * When a shell is created with SWT.ON_TOP and SWT.NO_FOCUS, - * do not activate the shell when the user clicks on the - * the client area or on the border or a control within the - * shell that does not take focus. - */ - Shell shell = _getShell (); - if (((shell.style & SWT.ON_TOP) != 0) && (((shell.style & SWT.NO_FOCUS) == 0) || ((style & SWT.NO_FOCUS) == 0))) { - shell.forceActive(); - } - int /*long*/ result = 0; - if (gdkEvent.type == OS.GDK_BUTTON_PRESS) { - display.clickCount = 1; - int /*long*/ nextEvent = OS.gdk_event_peek (); - if (nextEvent != 0) { - int eventType = OS.GDK_EVENT_TYPE (nextEvent); - if (eventType == OS.GDK_2BUTTON_PRESS) display.clickCount = 2; - if (eventType == OS.GDK_3BUTTON_PRESS) display.clickCount = 3; - OS.gdk_event_free (nextEvent); - } - boolean dragging = false; - if ((state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect)) { - if (gdkEvent.button == 1) { - boolean [] consume = new boolean [1]; - if (dragDetect ((int) gdkEvent.x, (int) gdkEvent.y, true, consume)) { - dragging = true; - if (consume [0]) result = 1; - } - if (isDisposed ()) return 1; - } - } - if (sendMouseDown && !sendMouseEvent (SWT.MouseDown, gdkEvent.button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state)) { - result = 1; - } - if (isDisposed ()) return 1; - if (dragging) { - sendDragEvent (gdkEvent.button, gdkEvent.state, (int) gdkEvent.x, (int) gdkEvent.y, false); - if (isDisposed ()) return 1; - } - /* - * Pop up the context menu in the button press event for widgets - * that have default operating system menus in order to stop the - * operating system from displaying the menu if necessary. - */ - if ((state & MENU) != 0) { - if (gdkEvent.button == 3) { - if (showMenu ((int)gdkEvent.x_root, (int)gdkEvent.y_root)) { - result = 1; - } - } - } - } else { - display.clickCount = 2; - result = sendMouseEvent (SWT.MouseDoubleClick, gdkEvent.button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - if (isDisposed ()) return 1; - } - if (!shell.isDisposed ()) shell.setActiveControl (this); - return result; -} - -int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - /* - * Feature in GTK. When button 4, 5, 6, or 7 is released, GTK - * does not deliver a corresponding GTK event. Button 6 and 7 - * are mapped to buttons 4 and 5 in SWT. The fix is to change - * the button number of the event to a negative number so that - * it gets dispatched by GTK. SWT has been modified to look - * for negative button numbers. - */ - int button = gdkEvent.button; - switch (button) { - case -6: button = 4; break; - case -7: button = 5; break; - } - return sendMouseEvent (SWT.MouseUp, button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; -} - -int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ text) { - if (text == 0) return 0; - int length = OS.strlen (text); - if (length == 0) return 0; - byte [] buffer = new byte [length]; - OS.memmove (buffer, text, length); - char [] chars = Converter.mbcsToWcs (null, buffer); - sendIMKeyEvent (SWT.KeyDown, null, chars); - return 0; -} - -int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) { - if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) { - /* - * Feature in GTK. Children of a shell will inherit and display the shell's - * tooltip if they do not have a tooltip of their own. The fix is to use the - * new tooltip API in GTK 2.12 to null the shell's tooltip when the control - * being entered does not have any tooltip text set. - */ - byte [] buffer = null; - if (toolTipText != null && toolTipText.length() != 0) { - char [] chars = fixMnemonic (toolTipText, false); - buffer = Converter.wcsToMbcs (null, chars, true); - } - int /*long*/ toolHandle = getShell().handle; - OS.gtk_widget_set_tooltip_text (toolHandle, buffer); - } - if (display.currentControl == this) return 0; - GdkEventCrossing gdkEvent = new GdkEventCrossing (); - OS.memmove (gdkEvent, event, GdkEventCrossing.sizeof); - /* - * It is possible to send out too many enter/exit events if entering a - * control through a subwindow. The fix is to return without sending any - * events if the GdkEventCrossing subwindow field is set and the control - * requests to check the field. - */ - if (gdkEvent.subwindow != 0 && checkSubwindow ()) return 0; - if (gdkEvent.mode != OS.GDK_CROSSING_NORMAL && gdkEvent.mode != OS.GDK_CROSSING_UNGRAB) return 0; - if ((gdkEvent.state & (OS.GDK_BUTTON1_MASK | OS.GDK_BUTTON2_MASK | OS.GDK_BUTTON3_MASK)) != 0) return 0; - if (display.currentControl != null && !display.currentControl.isDisposed ()) { - display.removeMouseHoverTimeout (display.currentControl.handle); - display.currentControl.sendMouseEvent (SWT.MouseExit, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state); - } - if (!isDisposed ()) { - display.currentControl = this; - return sendMouseEvent (SWT.MouseEnter, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - } - return 0; -} - -boolean checkSubwindow () { - return false; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { - GdkEvent event = new GdkEvent (); - OS.memmove (event, gdkEvent, GdkEvent.sizeof); - switch (event.type) { - case OS.GDK_BUTTON_PRESS: { - if (widget != eventHandle ()) break; - /* - * Pop up the context menu in the event_after signal to allow - * the widget to process the button press. This allows widgets - * such as GtkTreeView to select items before a menu is shown. - */ - if ((state & MENU) == 0) { - GdkEventButton gdkEventButton = new GdkEventButton (); - OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof); - if (gdkEventButton.button == 3) { - showMenu ((int) gdkEventButton.x_root, (int) gdkEventButton.y_root); - } - } - break; - } - case OS.GDK_FOCUS_CHANGE: { - if (!isFocusHandle (widget)) break; - GdkEventFocus gdkEventFocus = new GdkEventFocus (); - OS.memmove (gdkEventFocus, gdkEvent, GdkEventFocus.sizeof); - - /* - * Feature in GTK. The GTK combo box popup under some window managers - * is implemented as a GTK_MENU. When it pops up, it causes the combo - * box to lose focus when focus is received for the menu. The - * fix is to check the current grab handle and see if it is a GTK_MENU - * and ignore the focus event when the menu is both shown and hidden. - * - * NOTE: This code runs for all menus. - */ - Display display = this.display; - if (gdkEventFocus.in != 0) { - if (display.ignoreFocus) { - display.ignoreFocus = false; - break; - } - } else { - display.ignoreFocus = false; - int /*long*/ grabHandle = OS.gtk_grab_get_current (); - if (grabHandle != 0) { - if (OS.G_OBJECT_TYPE (grabHandle) == OS.GTK_TYPE_MENU ()) { - display.ignoreFocus = true; - break; - } - } - } - - sendFocusEvent (gdkEventFocus.in != 0 ? SWT.FocusIn : SWT.FocusOut); - break; - } - } - return 0; -} - -int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) { - if ((state & OBSCURED) != 0) return 0; - if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0; - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove(gdkEvent, eventPtr, GdkEventExpose.sizeof); - Event event = new Event (); - event.count = gdkEvent.count; - event.x = gdkEvent.area_x; - event.y = gdkEvent.area_y; - event.width = gdkEvent.area_width; - event.height = gdkEvent.area_height; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; - GCData data = new GCData (); - data.damageRgn = gdkEvent.region; - GC gc = event.gc = GC.gtk_new (this, data); - OS.gdk_gc_set_clip_region (gc.handle, gdkEvent.region); - sendEvent (SWT.Paint, event); - gc.dispose (); - event.gc = null; - return 0; -} - -int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ directionType) { - /* Stop GTK traversal for every widget */ - return 1; -} - -int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) { - // widget could be disposed at this point - if (handle != 0) { - Control oldControl = display.imControl; - if (oldControl != this) { - if (oldControl != null && !oldControl.isDisposed ()) { - int /*long*/ oldIMHandle = oldControl.imHandle (); - if (oldIMHandle != 0) OS.gtk_im_context_reset (oldIMHandle); - } - } - if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) { - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) OS.gtk_im_context_focus_in (imHandle); - } - } - return 0; -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - // widget could be disposed at this point - if (handle != 0) { - if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) { - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - OS.gtk_im_context_focus_out (imHandle); - } - } - } - return 0; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - if (!hasFocus ()) return 0; - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, event, GdkEventKey.sizeof); - - if (translateMnemonic (gdkEvent.keyval, gdkEvent)) return 1; - // widget could be disposed at this point - if (isDisposed ()) return 0; - - if (filterKey (gdkEvent.keyval, event)) return 1; - // widget could be disposed at this point - if (isDisposed ()) return 0; - - if (translateTraversal (gdkEvent)) return 1; - // widget could be disposed at this point - if (isDisposed ()) return 0; - return super.gtk_key_press_event (widget, event); -} - -int /*long*/ gtk_key_release_event (int /*long*/ widget, int /*long*/ event) { - if (!hasFocus ()) return 0; - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - if (OS.gtk_im_context_filter_keypress (imHandle, event)) return 1; - } - return super.gtk_key_release_event (widget, event); -} - -int /*long*/ gtk_leave_notify_event (int /*long*/ widget, int /*long*/ event) { - if (display.currentControl != this) return 0; - display.removeMouseHoverTimeout (handle); - int result = 0; - if (sendLeaveNotify () || display.getCursorControl () == null) { - GdkEventCrossing gdkEvent = new GdkEventCrossing (); - OS.memmove (gdkEvent, event, GdkEventCrossing.sizeof); - if (gdkEvent.mode != OS.GDK_CROSSING_NORMAL && gdkEvent.mode != OS.GDK_CROSSING_UNGRAB) return 0; - if ((gdkEvent.state & (OS.GDK_BUTTON1_MASK | OS.GDK_BUTTON2_MASK | OS.GDK_BUTTON3_MASK)) != 0) return 0; - result = sendMouseEvent (SWT.MouseExit, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - display.currentControl = null; - } - return result; -} - -int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) { - int result = 0; - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEventKey keyEvent = new GdkEventKey (); - OS.memmove (keyEvent, eventPtr, GdkEventKey.sizeof); - if (keyEvent.type == OS.GDK_KEY_PRESS) { - Control focusControl = display.getFocusControl (); - int /*long*/ focusHandle = focusControl != null ? focusControl.focusHandle () : 0; - if (focusHandle != 0) { - display.mnemonicControl = this; - OS.gtk_widget_event (focusHandle, eventPtr); - display.mnemonicControl = null; - } - result = 1; - } - OS.gdk_event_free (eventPtr); - } - return result; -} - -int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ event) { - GdkEventMotion gdkEvent = new GdkEventMotion (); - OS.memmove (gdkEvent, event, GdkEventMotion.sizeof); - if (this == display.currentControl && (hooks (SWT.MouseHover) || filters (SWT.MouseHover))) { - display.addMouseHoverTimeout (handle); - } - double x = gdkEvent.x_root, y = gdkEvent.y_root; - int state = gdkEvent.state; - if (gdkEvent.is_hint != 0) { - int [] pointer_x = new int [1], pointer_y = new int [1], mask = new int [1]; - int /*long*/ window = eventWindow (); - OS.gdk_window_get_pointer (window, pointer_x, pointer_y, mask); - x = pointer_x [0]; - y = pointer_y [0]; - state = mask [0]; - } - int result = sendMouseEvent (SWT.MouseMove, 0, gdkEvent.time, x, y, gdkEvent.is_hint != 0, state) ? 0 : 1; - return result; -} - -int /*long*/ gtk_popup_menu (int /*long*/ widget) { - if (!hasFocus()) return 0; - int [] x = new int [1], y = new int [1]; - OS.gdk_window_get_pointer (0, x, y, null); - return showMenu (x [0], y [0]) ? 1 : 0; -} - -int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) { - display.showIMWindow (this); - return 0; -} - -int /*long*/ gtk_realize (int /*long*/ widget) { - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ()); - OS.gtk_im_context_set_client_window (imHandle, window); - } - if (backgroundImage != null) { - int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ()); - if (window != 0) OS.gdk_window_set_back_pixmap (window, backgroundImage.pixmap, false); - } - return 0; -} - -int /*long*/ gtk_scroll_event (int /*long*/ widget, int /*long*/ eventPtr) { - GdkEventScroll gdkEvent = new GdkEventScroll (); - OS.memmove (gdkEvent, eventPtr, GdkEventScroll.sizeof); - switch (gdkEvent.direction) { - case OS.GDK_SCROLL_UP: - return sendMouseEvent (SWT.MouseWheel, 0, 3, SWT.SCROLL_LINE, true, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - case OS.GDK_SCROLL_DOWN: - return sendMouseEvent (SWT.MouseWheel, 0, -3, SWT.SCROLL_LINE, true, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - case OS.GDK_SCROLL_LEFT: - return sendMouseEvent (SWT.MouseDown, 4, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - case OS.GDK_SCROLL_RIGHT: - return sendMouseEvent (SWT.MouseDown, 5, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - } - return 0; -} - -int /*long*/ gtk_show_help (int /*long*/ widget, int /*long*/ helpType) { - if (!hasFocus ()) return 0; - return sendHelpEvent (helpType) ? 1 : 0; -} - -int /*long*/ gtk_style_set (int /*long*/ widget, int /*long*/ previousStyle) { - if (backgroundImage != null) { - setBackgroundPixmap (backgroundImage.pixmap); - } - return 0; -} - -int /*long*/ gtk_unrealize (int /*long*/ widget) { - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) OS.gtk_im_context_set_client_window (imHandle, 0); - return 0; -} - -int /*long*/ gtk_visibility_notify_event (int /*long*/ widget, int /*long*/ event) { - GdkEventVisibility gdkEvent = new GdkEventVisibility (); - OS.memmove (gdkEvent, event, GdkEventVisibility.sizeof); - int /*long*/ paintWindow = paintWindow(); - int /*long*/ window = gdkEvent.window; - if (window == paintWindow) { - if (gdkEvent.state == OS.GDK_VISIBILITY_FULLY_OBSCURED) { - state |= OBSCURED; - } else { - if ((state & OBSCURED) != 0) { - int [] width = new int [1], height = new int [1]; - OS.gdk_drawable_get_size (window, width, height); - GdkRectangle rect = new GdkRectangle (); - rect.width = width [0]; - rect.height = height [0]; - OS.gdk_window_invalidate_rect (window, rect, false); - } - state &= ~OBSCURED; - } - } - return 0; -} - -void gtk_widget_size_request (int /*long*/ widget, GtkRequisition requisition) { - OS.gtk_widget_size_request (widget, requisition); -} - -/** - * Invokes platform specific functionality to allocate a new GC handle. - *

    - * IMPORTANT: This method is not part of the public - * API for Control. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - *

    - * - * @param data the platform specific GC data - * @return the platform specific GC handle - */ -public int /*long*/ internal_new_GC (GCData data) { - checkWidget (); - int /*long*/ window = paintWindow (); - if (window == 0) SWT.error (SWT.ERROR_NO_HANDLES); - int /*long*/ gdkGC = OS.gdk_gc_new (window); - if (gdkGC == 0) error (SWT.ERROR_NO_HANDLES); - if (data != null) { - int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; - if ((data.style & mask) == 0) { - data.style |= style & (mask | SWT.MIRRORED); - } else { - if ((data.style & SWT.RIGHT_TO_LEFT) != 0) { - data.style |= SWT.MIRRORED; - } - } - data.drawable = window; - data.device = display; - data.foreground = getForegroundColor (); - Control control = findBackgroundControl (); - if (control == null) control = this; - data.background = control.getBackgroundColor (); - data.font = font != null ? font : defaultFont (); - } - return gdkGC; -} - -int /*long*/ imHandle () { - return 0; -} - -/** - * Invokes platform specific functionality to dispose a GC handle. - *

    - * IMPORTANT: This method is not part of the public - * API for Control. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - *

    - * - * @param hDC the platform specific GC handle - * @param data the platform specific GC data - */ -public void internal_dispose_GC (int /*long*/ gdkGC, GCData data) { - checkWidget (); - OS.g_object_unref (gdkGC); -} - -/** - * Returns true if the underlying operating - * system supports this reparenting, otherwise false - * - * @return true if the widget can be reparented, otherwise false - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public boolean isReparentable () { - checkWidget(); - return true; -} -boolean isShowing () { - /* - * This is not complete. Need to check if the - * widget is obscurred by a parent or sibling. - */ - if (!isVisible ()) return false; - Control control = this; - while (control != null) { - Point size = control.getSize (); - if (size.x == 0 || size.y == 0) { - return false; - } - control = control.parent; - } - return true; -} -boolean isTabGroup () { - Control [] tabList = parent._getTabList (); - if (tabList != null) { - for (int i=0; itrue if the receiver is enabled and all - * ancestors up to and including the receiver's nearest ancestor - * shell are enabled. Otherwise, false is returned. - * A disabled control is typically not selectable from the user - * interface and draws with an inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception 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 #getEnabled - */ -public boolean isEnabled () { - checkWidget (); - return getEnabled () && parent.isEnabled (); -} - -boolean isFocusAncestor (Control control) { - while (control != null && control != this && !(control instanceof Shell)) { - control = control.parent; - } - return control == this; -} - -/** - * Returns true if the receiver has the user-interface - * focus, and false otherwise. - * - * @return the receiver's focus state - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public boolean isFocusControl () { - checkWidget(); - Control focusControl = display.focusControl; - if (focusControl != null && !focusControl.isDisposed ()) { - return this == focusControl; - } - return hasFocus (); -} - -/** - * Returns true if the receiver is visible and all - * ancestors up to and including the receiver's nearest ancestor - * shell are visible. Otherwise, false is returned. - * - * @return the receiver's visibility state - * - * @exception 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 #getVisible - */ -public boolean isVisible () { - checkWidget(); - return getVisible () && parent.isVisible (); -} - -Decorations menuShell () { - return parent.menuShell (); -} - -boolean mnemonicHit (char key) { - return false; -} - -boolean mnemonicMatch (char key) { - return false; -} - -void register () { - super.register (); - if (fixedHandle != 0) display.addWidget (fixedHandle, this); - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) display.addWidget (imHandle, this); -} - -/** - * Causes the entire bounds of the receiver to be marked - * as needing to be redrawn. The next time a paint request - * is processed, the control will be completely painted, - * including the background. - * - * @exception 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 #update() - * @see PaintListener - * @see SWT#Paint - * @see SWT#NO_BACKGROUND - * @see SWT#NO_REDRAW_RESIZE - * @see SWT#NO_MERGE_PAINTS - * @see SWT#DOUBLE_BUFFERED - */ -public void redraw () { - checkWidget(); - redraw (false); -} - -void redraw (boolean all) { -// checkWidget(); - if (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return; - redrawWidget (0, 0, 0, 0, true, all, false); -} - -/** - * Causes the rectangular area of the receiver specified by - * the arguments to be marked as needing to be redrawn. - * The next time a paint request is processed, that area of - * the receiver will be painted, including the background. - * If the all flag is true, any - * children of the receiver which intersect with the specified - * area will also paint their intersecting areas. If the - * all flag is false, the children - * will not be painted. - * - * @param x the x coordinate of the area to draw - * @param y the y coordinate of the area to draw - * @param width the width of the area to draw - * @param height the height of the area to draw - * @param all true if children should redraw, and false otherwise - * - * @exception 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 #update() - * @see PaintListener - * @see SWT#Paint - * @see SWT#NO_BACKGROUND - * @see SWT#NO_REDRAW_RESIZE - * @see SWT#NO_MERGE_PAINTS - * @see SWT#DOUBLE_BUFFERED - */ -public void redraw (int x, int y, int width, int height, boolean all) { - checkWidget(); - if (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return; - if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - width - x; - redrawWidget (x, y, width, height, false, all, false); -} - -void redrawChildren () { -} - -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean all, boolean trim) { - if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) == 0) return; - int /*long*/ window = paintWindow (); - GdkRectangle rect = new GdkRectangle (); - if (redrawAll) { - int [] w = new int [1], h = new int [1]; - OS.gdk_drawable_get_size (window, w, h); - rect.width = w [0]; - rect.height = h [0]; - } else { - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; - } - OS.gdk_window_invalidate_rect (window, rect, all); -} - -void release (boolean destroy) { - Control next = null, previous = null; - if (destroy && parent != null) { - Control[] children = parent._getChildren (); - int index = 0; - while (index < children.length) { - if (children [index] == this) break; - index++; - } - if (0 < index && (index + 1) < children.length) { - next = children [index + 1]; - previous = children [index - 1]; - } - } - super.release (destroy); - if (destroy) { - if (previous != null) previous.addRelation (next); - } -} - -void releaseHandle () { - super.releaseHandle (); - fixedHandle = 0; - parent = null; -} - -void releaseParent () { - parent.removeControl (this); -} - -void releaseWidget () { - super.releaseWidget (); - if (display.currentControl == this) display.currentControl = null; - display.removeMouseHoverTimeout (handle); - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - OS.gtk_im_context_reset (imHandle); - OS.gtk_im_context_set_client_window (imHandle, 0); - } - if (enableWindow != 0) { - OS.gdk_window_set_user_data (enableWindow, 0); - OS.gdk_window_destroy (enableWindow); - enableWindow = 0; - } - redrawWindow = 0; - if (menu != null && !menu.isDisposed ()) { - menu.dispose (); - } - menu = null; - cursor = null; - toolTipText = null; - layoutData = null; - accessible = null; - region = null; -} - -boolean sendDragEvent (int button, int stateMask, int x, int y, boolean isStateMask) { - Event event = new Event (); - event.button = button; - event.x = x; - event.y = y; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.x; - if (isStateMask) { - event.stateMask = stateMask; - } else { - setInputState (event, stateMask); - } - postEvent (SWT.DragDetect, event); - if (isDisposed ()) return false; - return event.doit; -} - -void sendFocusEvent (int type) { - Shell shell = _getShell (); - Display display = this.display; - display.focusControl = this; - display.focusEvent = type; - sendEvent (type); - display.focusControl = null; - display.focusEvent = SWT.None; - /* - * It is possible that the shell may be - * disposed at this point. If this happens - * don't send the activate and deactivate - * events. - */ - if (!shell.isDisposed ()) { - switch (type) { - case SWT.FocusIn: - shell.setActiveControl (this); - break; - case SWT.FocusOut: - if (shell != display.activeShell) { - shell.setActiveControl (null); - } - break; - } - } -} - -boolean sendHelpEvent (int /*long*/ helpType) { - Control control = this; - while (control != null) { - if (control.hooks (SWT.Help)) { - control.postEvent (SWT.Help); - return true; - } - control = control.parent; - } - return false; -} - -boolean sendLeaveNotify() { - return false; -} - -boolean sendMouseEvent (int type, int button, int time, double x, double y, boolean is_hint, int state) { - return sendMouseEvent (type, button, 0, 0, false, time, x, y, is_hint, state); -} - -boolean sendMouseEvent (int type, int button, int count, int detail, boolean send, int time, double x, double y, boolean is_hint, int state) { - if (!hooks (type) && !filters (type)) return true; - Event event = new Event (); - event.time = time; - event.button = button; - event.detail = detail; - event.count = count; - if (is_hint) { - event.x = (int)x; - event.y = (int)y; - } else { - int /*long*/ window = eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - event.x = (int)x - origin_x [0]; - event.y = (int)y - origin_y [0]; - } - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.x; - setInputState (event, state); - if (send) { - sendEvent (type, event); - if (isDisposed ()) return false; - } else { - postEvent (type, event); - } - return event.doit; -} - -void setBackground () { - if ((state & PARENT_BACKGROUND) != 0 && (state & BACKGROUND) == 0 && backgroundImage == null) { - setParentBackground (); - } else { - setWidgetBackground (); - } - redrawWidget (0, 0, 0, 0, true, false, false); -} - -/** - * Sets the receiver's background color to the color specified - * by the argument, or to the default system color for the control - * if the argument is null. - *

    - * Note: This operation is a hint and may be overridden by the platform. - * For example, on Windows the background of a Button cannot be changed. - *

    - * @param color the new color (or null) - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the argument has been disposed
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setBackground (Color color) { - checkWidget(); - if (((state & BACKGROUND) == 0) && color == null) return; - GdkColor gdkColor = null; - if (color != null) { - if (color.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - gdkColor = color.handle; - } - boolean set = false; - if (gdkColor == null) { - int /*long*/ style = OS.gtk_widget_get_modifier_style (handle); - set = (OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL) & OS.GTK_RC_BG) != 0; - } else { - GdkColor oldColor = getBackgroundColor (); - set = oldColor.pixel != gdkColor.pixel; - } - if (set) { - if (color == null) { - state &= ~BACKGROUND; - } else { - state |= BACKGROUND; - } - setBackgroundColor (gdkColor); - redrawChildren (); - } -} - -void setBackgroundColor (int /*long*/ handle, GdkColor color) { - int index = OS.GTK_STATE_NORMAL; - int /*long*/ style = OS.gtk_widget_get_modifier_style (handle); - int /*long*/ ptr = OS.gtk_rc_style_get_bg_pixmap_name (style, index); - if (ptr != 0) OS.g_free (ptr); - String name = color == null ? "" : ""; - byte[] buffer = Converter.wcsToMbcs (null, name, true); - ptr = OS.g_malloc (buffer.length); - OS.memmove (ptr, buffer, buffer.length); - OS.gtk_rc_style_set_bg_pixmap_name (style, index, ptr); - OS.gtk_rc_style_set_bg (style, index, color); - int flags = OS.gtk_rc_style_get_color_flags (style, index); - flags = (color == null) ? flags & ~OS.GTK_RC_BG : flags | OS.GTK_RC_BG; - OS.gtk_rc_style_set_color_flags (style, index, flags); - modifyStyle (handle, style); -} - -void setBackgroundColor (GdkColor color) { - setBackgroundColor (handle, color); -} - -/** - * Sets the receiver's background image to the image specified - * by the argument, or to the default system color for the control - * if the argument is null. The background image is tiled to fill - * the available space. - *

    - * Note: This operation is a hint and may be overridden by the platform. - * For example, on Windows the background of a Button cannot be changed. - *

    - * @param image the new image (or null) - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the argument has been disposed
    • - *
    • ERROR_INVALID_ARGUMENT - if the argument is not a bitmap
    • - *
    - * @exception 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.2 - */ -public void setBackgroundImage (Image image) { - checkWidget (); - if (image != null && image.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (image == backgroundImage) return; - this.backgroundImage = image; - if (backgroundImage != null) { - setBackgroundPixmap (backgroundImage.pixmap); - redrawWidget (0, 0, 0, 0, true, false, false); - } else { - setWidgetBackground (); - } - redrawChildren (); -} - -void setBackgroundPixmap (int /*long*/ pixmap) { - int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ()); - if (window != 0) OS.gdk_window_set_back_pixmap (window, backgroundImage.pixmap, false); -} - -/** - * If the argument is true, causes the receiver to have - * all mouse events delivered to it until the method is called with - * false as the argument. Note that on some platforms, - * a mouse button must currently be down for capture to be assigned. - * - * @param capture true to capture the mouse, and false to release it - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setCapture (boolean capture) { - checkWidget(); - /* FIXME !!!!! */ - /* - if (capture) { - OS.gtk_widget_grab_focus (handle); - } else { - OS.gtk_widget_grab_default (handle); - } - */ -} -/** - * Sets the receiver's cursor to the cursor specified by the - * argument, or to the default cursor for that kind of control - * if the argument is null. - *

    - * When the mouse pointer passes over a control its appearance - * is changed to match the control's cursor. - *

    - * - * @param cursor the new cursor (or null) - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the argument has been disposed
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setCursor (Cursor cursor) { - checkWidget(); - if (cursor != null && cursor.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - this.cursor = cursor; - setCursor (cursor != null ? cursor.handle : 0); -} - -void setCursor (int /*long*/ cursor) { - int /*long*/ window = eventWindow (); - if (window != 0) { - OS.gdk_window_set_cursor (window, cursor); - if (!OS.GDK_WINDOWING_X11 ()) { - OS.gdk_flush (); - } else { - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - OS.XFlush (xDisplay); - } - } -} - -/** - * Sets the receiver's drag detect state. If the argument is - * true, the receiver will detect drag gestures, - * otherwise these gestures will be ignored. - * - * @param dragDetect the new drag detect state - * - * @exception 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.3 - */ -public void setDragDetect (boolean dragDetect) { - checkWidget (); - if (dragDetect) { - state |= DRAG_DETECT; - } else { - state &= ~DRAG_DETECT; - } -} - -/** - * Enables the receiver if the argument is true, - * and disables it otherwise. A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @param enabled the new enabled state - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setEnabled (boolean enabled) { - checkWidget(); - if (((state & DISABLED) == 0) == enabled) return; - Control control = null; - boolean fixFocus = false; - if (!enabled) { - if (display.focusEvent != SWT.FocusOut) { - control = display.getFocusControl (); - fixFocus = isFocusAncestor (control); - } - } - if (enabled) { - state &= ~DISABLED; - } else { - state |= DISABLED; - } - enableWidget (enabled); - if (isDisposed ()) return; - if (enabled) { - if (enableWindow != 0) { - OS.gdk_window_set_user_data (enableWindow, 0); - OS.gdk_window_destroy (enableWindow); - enableWindow = 0; - } - } else { - OS.gtk_widget_realize (handle); - int /*long*/ parentHandle = parent.eventHandle (); - int /*long*/ window = parent.eventWindow (); - int /*long*/ topHandle = topHandle (); - GdkWindowAttr attributes = new GdkWindowAttr (); - attributes.x = OS.GTK_WIDGET_X (topHandle); - attributes.y = OS.GTK_WIDGET_Y (topHandle); - attributes.width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - attributes.height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle); - attributes.event_mask = (0xFFFFFFFF & ~OS.ExposureMask); - attributes.wclass = OS.GDK_INPUT_ONLY; - attributes.window_type = OS.GDK_WINDOW_CHILD; - enableWindow = OS.gdk_window_new (window, attributes, OS.GDK_WA_X | OS.GDK_WA_Y); - if (enableWindow != 0) { - OS.gdk_window_set_user_data (enableWindow, parentHandle); - if (!OS.GDK_WINDOWING_X11 ()) { - OS.gdk_window_raise (enableWindow); - } else { - int /*long*/ topWindow = OS.GTK_WIDGET_WINDOW (topHandle); - int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay (topWindow); - int /*long*/ xWindow = OS.gdk_x11_drawable_get_xid (enableWindow); - int xScreen = OS.XDefaultScreen (xDisplay); - int flags = OS.CWStackMode | OS.CWSibling; - XWindowChanges changes = new XWindowChanges (); - changes.sibling = OS.gdk_x11_drawable_get_xid (topWindow); - changes.stack_mode = OS.Above; - OS.XReconfigureWMWindow (xDisplay, xWindow, xScreen, flags, changes); - } - if (OS.GTK_WIDGET_VISIBLE (topHandle)) OS.gdk_window_show_unraised (enableWindow); - } - } - if (fixFocus) fixFocus (control); -} - -/** - * Causes the receiver to have the keyboard focus, - * such that all keyboard events will be delivered to it. Focus - * reassignment will respect applicable platform constraints. - * - * @return true if the control got focus, and false if it was unable to. - * - * @exception 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 #forceFocus - */ -public boolean setFocus () { - checkWidget(); - if ((style & SWT.NO_FOCUS) != 0) return false; - return forceFocus (); -} - -/** - * Sets the font that the receiver will use to paint textual information - * to the font specified by the argument, or to the default font for that - * kind of control if the argument is null. - * - * @param font the new font (or null) - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the argument has been disposed
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setFont (Font font) { - checkWidget(); - if (((state & FONT) == 0) && font == null) return; - this.font = font; - int /*long*/ fontDesc; - if (font == null) { - fontDesc = defaultFont ().handle; - } else { - if (font.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - fontDesc = font.handle; - } - if (font == null) { - state &= ~FONT; - } else { - state |= FONT; - } - setFontDescription (fontDesc); -} - -void setFontDescription (int /*long*/ font) { - OS.gtk_widget_modify_font (handle, font); -} - -/** - * Sets the receiver's foreground color to the color specified - * by the argument, or to the default system color for the control - * if the argument is null. - *

    - * Note: This operation is a hint and may be overridden by the platform. - *

    - * @param color the new color (or null) - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the argument has been disposed
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setForeground (Color color) { - checkWidget(); - if (((state & FOREGROUND) == 0) && color == null) return; - GdkColor gdkColor = null; - if (color != null) { - if (color.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - gdkColor = color.handle; - } - boolean set = false; - if (gdkColor == null) { - int /*long*/ style = OS.gtk_widget_get_modifier_style (handle); - set = (OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL) & OS.GTK_RC_FG) != 0; - } else { - GdkColor oldColor = getForegroundColor (); - set = oldColor.pixel != gdkColor.pixel; - } - if (set) { - if (color == null) { - state &= ~FOREGROUND; - } else { - state |= FOREGROUND; - } - setForegroundColor (gdkColor); - } -} - -void setForegroundColor (GdkColor color) { - setForegroundColor (handle, color); -} - -void setInitialBounds () { - if ((state & ZERO_WIDTH) != 0 && (state & ZERO_HEIGHT) != 0) { - /* - * Feature in GTK. On creation, each widget's allocation is - * initialized to a position of (-1, -1) until the widget is - * first sized. The fix is to set the value to (0, 0) as - * expected by SWT. - */ - int /*long*/ topHandle = topHandle (); - if ((parent.style & SWT.MIRRORED) != 0) { - OS.GTK_WIDGET_SET_X (topHandle, parent.getClientWidth ()); - } else { - OS.GTK_WIDGET_SET_X (topHandle, 0); - } - OS.GTK_WIDGET_SET_Y (topHandle, 0); - } else { - resizeHandle (1, 1); - forceResize (); - } -} - -/** - * Sets the receiver's pop up menu to the argument. - * All controls may optionally have a pop up - * menu that is displayed when the user requests one for - * the control. The sequence of key strokes, button presses - * and/or button releases that are used to request a pop up - * menu is platform specific. - *

    - * Note: Disposing of a control that has a pop up menu will - * dispose of the menu. To avoid this behavior, set the - * menu to null before the control is disposed. - *

    - * - * @param menu the new pop up menu - * - * @exception IllegalArgumentException
      - *
    • ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu
    • - *
    • ERROR_INVALID_PARENT - if the menu is not in the same widget tree
    • - *
    • ERROR_INVALID_ARGUMENT - if the menu has been disposed
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setMenu (Menu menu) { - checkWidget(); - if (menu != null) { - if ((menu.style & SWT.POP_UP) == 0) { - error (SWT.ERROR_MENU_NOT_POP_UP); - } - if (menu.parent != menuShell ()) { - error (SWT.ERROR_INVALID_PARENT); - } - } - this.menu = menu; -} - -void setOrientation () { - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - if (handle != 0) OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL); - if (fixedHandle != 0) OS.gtk_widget_set_direction (fixedHandle, OS.GTK_TEXT_DIR_RTL); - } -} - -/** - * Changes the parent of the widget to be the one provided if - * the underlying operating system supports this feature. - * Returns true if the parent is successfully changed. - * - * @param parent the new parent for the control. - * @return true if the parent is changed and false otherwise. - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the argument has been disposed
    • - *
    • ERROR_NULL_ARGUMENT - if the parent is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public boolean setParent (Composite parent) { - checkWidget (); - if (parent == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - if (parent.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); - if (this.parent == parent) return true; - if (!isReparentable ()) return false; - int /*long*/ topHandle = topHandle (); - int x = OS.GTK_WIDGET_X (topHandle); - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - if ((this.parent.style & SWT.MIRRORED) != 0) { - x = this.parent.getClientWidth () - width - x; - } - if ((parent.style & SWT.MIRRORED) != 0) { - x = parent.getClientWidth () - width - x; - } - int y = OS.GTK_WIDGET_Y (topHandle); - releaseParent (); - Shell newShell = parent.getShell (), oldShell = getShell (); - Decorations newDecorations = parent.menuShell (), oldDecorations = menuShell (); - Menu [] menus = oldShell.findMenus (this); - if (oldShell != newShell || oldDecorations != newDecorations) { - fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus); - newDecorations.fixAccelGroup (); - oldDecorations.fixAccelGroup (); - } - int /*long*/ newParent = parent.parentingHandle(); - OS.gtk_widget_reparent (topHandle, newParent); - OS.gtk_fixed_move (newParent, topHandle, x, y); - this.parent = parent; - setZOrder (null, false, true); - return true; -} - -void setParentBackground () { - setBackgroundColor (handle, null); - if (fixedHandle != 0) setBackgroundColor (fixedHandle, null); -} - -void setParentWindow (int /*long*/ widget) { -} - -boolean setRadioSelection (boolean value) { - return false; -} - -/** - * If the argument is false, causes subsequent drawing - * operations in the receiver to be ignored. No drawing of any kind - * can occur in the receiver until the flag is set to true. - * Graphics operations that occurred while the flag was - * false are lost. When the flag is set to true, - * the entire widget is marked as needing to be redrawn. Nested calls - * to this method are stacked. - *

    - * Note: This operation is a hint and may not be supported on some - * platforms or for some widgets. - *

    - * - * @param redraw the new redraw state - * - * @exception 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 #redraw(int, int, int, int, boolean) - * @see #update() - */ -public void setRedraw (boolean redraw) { - checkWidget(); - if (redraw) { - if (--drawCount == 0) { - if (redrawWindow != 0) { - int /*long*/ window = paintWindow (); - /* Explicitly hiding the window avoids flicker on GTK+ >= 2.6 */ - OS.gdk_window_hide (redrawWindow); - OS.gdk_window_destroy (redrawWindow); - OS.gdk_window_set_events (window, OS.gtk_widget_get_events (paintHandle ())); - redrawWindow = 0; - } - } - } else { - if (drawCount++ == 0) { - if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) != 0) { - int /*long*/ window = paintWindow (); - Rectangle rect = getBounds (); - GdkWindowAttr attributes = new GdkWindowAttr (); - attributes.width = rect.width; - attributes.height = rect.height; - attributes.event_mask = OS.GDK_EXPOSURE_MASK; - attributes.window_type = OS.GDK_WINDOW_CHILD; - redrawWindow = OS.gdk_window_new (window, attributes, 0); - if (redrawWindow != 0) { - int mouseMask = OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK | - OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK | - OS.GDK_POINTER_MOTION_MASK | OS.GDK_POINTER_MOTION_HINT_MASK | - OS.GDK_BUTTON_MOTION_MASK | OS.GDK_BUTTON1_MOTION_MASK | - OS.GDK_BUTTON2_MOTION_MASK | OS.GDK_BUTTON3_MOTION_MASK; - OS.gdk_window_set_events (window, OS.gdk_window_get_events (window) & ~mouseMask); - OS.gdk_window_set_back_pixmap (redrawWindow, 0, false); - OS.gdk_window_show (redrawWindow); - } - } - } - } -} - -boolean setTabItemFocus (boolean next) { - if (!isShowing ()) return false; - return forceFocus (); -} - -/** - * Sets the receiver's tool tip text to the argument, which - * may be null indicating that the default tool tip for the - * control will be shown. For a control that has a default - * tool tip, such as the Tree control on Windows, setting - * the tool tip text to an empty string replaces the default, - * causing no tool tip text to be shown. - *

    - * The mnemonic indicator (character '&') is not displayed in a tool tip. - * To display a single '&' in the tool tip, the character '&' can be - * escaped by doubling it in the string. - *

    - * - * @param string the new tool tip text (or null) - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setToolTipText (String string) { - checkWidget(); - setToolTipText (_getShell (), string); - toolTipText = string; -} - -void setToolTipText (Shell shell, String newString) { - if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) { - /* - * Feature in GTK. In order to prevent children widgets - * from inheriting their parent's tooltip, the tooltip is - * a set on a shell only. In order to force the shell tooltip - * to update when a new tip string is set, the existing string - * in the tooltip is set to null, followed by running a query. - * The real tip text can then be set. - * - * Note that this will only run if the control for which the - * tooltip is being set is the current control (i.e. the control - * under the pointer). - */ - if (display.currentControl == this) { - shell.setToolTipText (shell.handle, eventHandle (), newString); - } - } else { - shell.setToolTipText (eventHandle (), newString); - } -} - -/** - * Marks the receiver as visible if the argument is true, - * and marks it invisible otherwise. - *

    - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, marking - * it visible may not actually cause it to be displayed. - *

    - * - * @param visible the new visibility state - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setVisible (boolean visible) { - checkWidget(); - if (((state & HIDDEN) == 0) == visible) return; - int /*long*/ topHandle = topHandle(); - if (visible) { - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the show - * event. If this happens, just return. - */ - sendEvent (SWT.Show); - if (isDisposed ()) return; - state &= ~HIDDEN; - if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) == 0) { - if (enableWindow != 0) OS.gdk_window_show_unraised (enableWindow); - OS.gtk_widget_show (topHandle); - } - } else { - /* - * Bug in GTK. Invoking gtk_widget_hide() on a widget that has - * focus causes a focus_out_event to be sent. If the client disposes - * the widget inside the event, GTK GP's. The fix is to reassign focus - * before hiding the widget. - * - * NOTE: In order to stop the same widget from taking focus, - * temporarily clear and set the GTK_VISIBLE flag. - */ - Control control = null; - boolean fixFocus = false; - if (display.focusEvent != SWT.FocusOut) { - control = display.getFocusControl (); - fixFocus = isFocusAncestor (control); - } - state |= HIDDEN; - if (fixFocus) { - OS.GTK_WIDGET_UNSET_FLAGS (topHandle, OS.GTK_VISIBLE); - fixFocus (control); - if (isDisposed ()) return; - OS.GTK_WIDGET_SET_FLAGS (topHandle, OS.GTK_VISIBLE); - } - OS.gtk_widget_hide (topHandle); - if (isDisposed ()) return; - if (enableWindow != 0) OS.gdk_window_hide (enableWindow); - sendEvent (SWT.Hide); - } -} - -void setZOrder (Control sibling, boolean above, boolean fixRelations) { - setZOrder (sibling, above, fixRelations, true); -} - -void setZOrder (Control sibling, boolean above, boolean fixRelations, boolean fixChildren) { - int index = 0, siblingIndex = 0, oldNextIndex = -1; - Control[] children = null; - if (fixRelations) { - /* determine the receiver's and sibling's indexes in the parent */ - children = parent._getChildren (); - while (index < children.length) { - if (children [index] == this) break; - index++; - } - if (sibling != null) { - while (siblingIndex < children.length) { - if (children [siblingIndex] == sibling) break; - siblingIndex++; - } - } - /* remove "Labelled by" relationships that will no longer be valid */ - removeRelation (); - if (index + 1 < children.length) { - oldNextIndex = index + 1; - children [oldNextIndex].removeRelation (); - } - if (sibling != null) { - if (above) { - sibling.removeRelation (); - } else { - if (siblingIndex + 1 < children.length) { - children [siblingIndex + 1].removeRelation (); - } - } - } - } - - int /*long*/ topHandle = topHandle (); - int /*long*/ siblingHandle = sibling != null ? sibling.topHandle () : 0; - int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle); - if (window != 0) { - int /*long*/ siblingWindow = 0; - if (sibling != null) { - if (above && sibling.enableWindow != 0) { - siblingWindow = enableWindow; - } else { - siblingWindow = OS.GTK_WIDGET_WINDOW (siblingHandle); - } - } - int /*long*/ redrawWindow = fixChildren ? parent.redrawWindow : 0; - if (!OS.GDK_WINDOWING_X11 () || (siblingWindow == 0 && (!above || redrawWindow == 0))) { - if (above) { - OS.gdk_window_raise (window); - if (redrawWindow != 0) OS.gdk_window_raise (redrawWindow); - if (enableWindow != 0) OS.gdk_window_raise (enableWindow); - } else { - if (enableWindow != 0) OS.gdk_window_lower (enableWindow); - OS.gdk_window_lower (window); - } - } else { - XWindowChanges changes = new XWindowChanges (); - changes.sibling = OS.gdk_x11_drawable_get_xid (siblingWindow != 0 ? siblingWindow : redrawWindow); - changes.stack_mode = above ? OS.Above : OS.Below; - if (redrawWindow != 0 && siblingWindow == 0) changes.stack_mode = OS.Below; - int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay (window); - int /*long*/ xWindow = OS.gdk_x11_drawable_get_xid (window); - int xScreen = OS.XDefaultScreen (xDisplay); - int flags = OS.CWStackMode | OS.CWSibling; - /* - * Feature in X. If the receiver is a top level, XConfigureWindow () - * will fail (with a BadMatch error) for top level shells because top - * level shells are reparented by the window manager and do not share - * the same X window parent. This is the correct behavior but it is - * unexpected. The fix is to use XReconfigureWMWindow () instead. - * When the receiver is not a top level shell, XReconfigureWMWindow () - * behaves the same as XConfigureWindow (). - */ - OS.XReconfigureWMWindow (xDisplay, xWindow, xScreen, flags, changes); - if (enableWindow != 0) { - changes.sibling = OS.gdk_x11_drawable_get_xid (window); - changes.stack_mode = OS.Above; - xWindow = OS.gdk_x11_drawable_get_xid (enableWindow); - OS.XReconfigureWMWindow (xDisplay, xWindow, xScreen, flags, changes); - } - } - } - if (fixChildren) { - if (above) { - parent.moveAbove (topHandle, siblingHandle); - } else { - parent.moveBelow (topHandle, siblingHandle); - } - } - /* Make sure that the parent internal windows are on the bottom of the stack */ - if (!above && fixChildren) parent.fixZOrder (); - - if (fixRelations) { - /* determine the receiver's new index in the parent */ - if (sibling != null) { - if (above) { - index = siblingIndex - (index < siblingIndex ? 1 : 0); - } else { - index = siblingIndex + (siblingIndex < index ? 1 : 0); - } - } else { - if (above) { - index = 0; - } else { - index = children.length - 1; - } - } - - /* add new "Labelled by" relations as needed */ - children = parent._getChildren (); - if (0 < index) { - children [index - 1].addRelation (this); - } - if (index + 1 < children.length) { - addRelation (children [index + 1]); - } - if (oldNextIndex != -1) { - if (oldNextIndex <= index) oldNextIndex--; - /* the last two conditions below ensure that duplicate relations are not hooked */ - if (0 < oldNextIndex && oldNextIndex != index && oldNextIndex != index + 1) { - children [oldNextIndex - 1].addRelation (children [oldNextIndex]); - } - } - } -} - -void setWidgetBackground () { - if (fixedHandle != 0) { - int /*long*/ style = OS.gtk_widget_get_modifier_style (fixedHandle); - modifyStyle (fixedHandle, style); - } - int /*long*/ style = OS.gtk_widget_get_modifier_style (handle); - modifyStyle (handle, style); -} - -boolean showMenu (int x, int y) { - Event event = new Event (); - event.x = x; - event.y = y; - sendEvent (SWT.MenuDetect, event); - //widget could be disposed at this point - if (isDisposed ()) return false; - if (event.doit) { - if (menu != null && !menu.isDisposed ()) { - boolean hooksKeys = hooks (SWT.KeyDown) || hooks (SWT.KeyUp); - menu.createIMMenu (hooksKeys ? imHandle() : 0); - if (event.x != x || event.y != y) { - menu.setLocation (event.x, event.y); - } - menu.setVisible (true); - return true; - } - } - return false; -} - -void showWidget () { - // Comment this line to disable zero-sized widgets - state |= ZERO_WIDTH | ZERO_HEIGHT; - int /*long*/ topHandle = topHandle (); - int /*long*/ parentHandle = parent.parentingHandle (); - parent.setParentWindow (topHandle); - OS.gtk_container_add (parentHandle, topHandle); - if (handle != 0 && handle != topHandle) OS.gtk_widget_show (handle); - if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) == 0) { - if (fixedHandle != 0) OS.gtk_widget_show (fixedHandle); - } - if (fixedHandle != 0) fixStyle (fixedHandle); -} - -void sort (int [] items) { - /* Shell Sort from K&R, pg 108 */ - int length = items.length; - for (int gap=length/2; gap>0; gap/=2) { - for (int i=gap; i=0; j-=gap) { - if (items [j] <= items [j + gap]) { - int swap = items [j]; - items [j] = items [j + gap]; - items [j + gap] = swap; - } - } - } - } -} - -/** - * Based on the argument, perform one of the expected platform - * traversal action. The argument should be one of the constants: - * SWT.TRAVERSE_ESCAPE, SWT.TRAVERSE_RETURN, - * SWT.TRAVERSE_TAB_NEXT, SWT.TRAVERSE_TAB_PREVIOUS, - * SWT.TRAVERSE_ARROW_NEXT and SWT.TRAVERSE_ARROW_PREVIOUS. - * - * @param traversal the type of traversal - * @return true if the traversal succeeded - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public boolean traverse (int traversal) { - checkWidget (); - Event event = new Event (); - event.doit = true; - event.detail = traversal; - return traverse (event); -} - -boolean translateMnemonic (Event event, Control control) { - if (control == this) return false; - if (!isVisible () || !isEnabled ()) return false; - event.doit = this == display.mnemonicControl || mnemonicMatch (event.character); - return traverse (event); -} - -boolean translateMnemonic (int keyval, GdkEventKey gdkEvent) { - int key = OS.gdk_keyval_to_unicode (keyval); - if (key < 0x20) return false; - if (gdkEvent.state == 0) { - int code = traversalCode (keyval, gdkEvent); - if ((code & SWT.TRAVERSE_MNEMONIC) == 0) return false; - } else { - Shell shell = _getShell (); - int mask = OS.GDK_CONTROL_MASK | OS.GDK_SHIFT_MASK | OS.GDK_MOD1_MASK; - if ((gdkEvent.state & mask) != OS.gtk_window_get_mnemonic_modifier (shell.shellHandle)) return false; - } - Decorations shell = menuShell (); - if (shell.isVisible () && shell.isEnabled ()) { - Event event = new Event (); - event.detail = SWT.TRAVERSE_MNEMONIC; - if (setKeyState (event, gdkEvent)) { - return translateMnemonic (event, null) || shell.translateMnemonic (event, this); - } - } - return false; -} - -boolean translateTraversal (GdkEventKey keyEvent) { - int detail = SWT.TRAVERSE_NONE; - int key = keyEvent.keyval; - int code = traversalCode (key, keyEvent); - boolean all = false; - switch (key) { - case OS.GDK_Escape: { - all = true; - detail = SWT.TRAVERSE_ESCAPE; - break; - } - case OS.GDK_KP_Enter: - case OS.GDK_Return: { - all = true; - detail = SWT.TRAVERSE_RETURN; - break; - } - case OS.GDK_ISO_Left_Tab: - case OS.GDK_Tab: { - boolean next = (keyEvent.state & OS.GDK_SHIFT_MASK) == 0; - detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS; - break; - } - case OS.GDK_Up: - case OS.GDK_Left: - case OS.GDK_Down: - case OS.GDK_Right: { - boolean next = key == OS.GDK_Down || key == OS.GDK_Right; - if (parent != null && (parent.style & SWT.MIRRORED) != 0) { - if (key == OS.GDK_Left || key == OS.GDK_Right) next = !next; - } - detail = next ? SWT.TRAVERSE_ARROW_NEXT : SWT.TRAVERSE_ARROW_PREVIOUS; - break; - } - case OS.GDK_Page_Up: - case OS.GDK_Page_Down: { - all = true; - if ((keyEvent.state & OS.GDK_CONTROL_MASK) == 0) return false; - detail = key == OS.GDK_Page_Down ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS; - break; - } - default: - return false; - } - Event event = new Event (); - event.doit = (code & detail) != 0; - event.detail = detail; - event.time = keyEvent.time; - if (!setKeyState (event, keyEvent)) return false; - Shell shell = getShell (); - Control control = this; - do { - if (control.traverse (event)) return true; - if (!event.doit && control.hooks (SWT.Traverse)) return false; - if (control == shell) return false; - control = control.parent; - } while (all && control != null); - return false; -} - -int traversalCode (int key, GdkEventKey event) { - int code = SWT.TRAVERSE_RETURN | SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_PAGE_NEXT | SWT.TRAVERSE_PAGE_PREVIOUS; - Shell shell = getShell (); - if (shell.parent != null) code |= SWT.TRAVERSE_ESCAPE; - return code; -} - -boolean traverse (Event event) { - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the traverse - * event. If this happens, return true to stop further - * event processing. - */ - sendEvent (SWT.Traverse, event); - if (isDisposed ()) return true; - if (!event.doit) return false; - switch (event.detail) { - case SWT.TRAVERSE_NONE: return true; - case SWT.TRAVERSE_ESCAPE: return traverseEscape (); - case SWT.TRAVERSE_RETURN: return traverseReturn (); - case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true); - case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false); - case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true); - case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false); - case SWT.TRAVERSE_MNEMONIC: return traverseMnemonic (event.character); - case SWT.TRAVERSE_PAGE_NEXT: return traversePage (true); - case SWT.TRAVERSE_PAGE_PREVIOUS: return traversePage (false); - } - return false; -} - -boolean traverseEscape () { - return false; -} - -boolean traverseGroup (boolean next) { - Control root = computeTabRoot (); - Widget group = computeTabGroup (); - Widget [] list = root.computeTabList (); - int length = list.length; - int index = 0; - while (index < length) { - if (list [index] == group) break; - index++; - } - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in focus in - * or out events. Ensure that a disposed widget is - * not accessed. - */ - if (index == length) return false; - int start = index, offset = (next) ? 1 : -1; - while ((index = ((index + offset + length) % length)) != start) { - Widget widget = list [index]; - if (!widget.isDisposed () && widget.setTabGroupFocus (next)) { - return true; - } - } - if (group.isDisposed ()) return false; - return group.setTabGroupFocus (next); -} - -boolean traverseItem (boolean next) { - Control [] children = parent._getChildren (); - int length = children.length; - int index = 0; - while (index < length) { - if (children [index] == this) break; - index++; - } - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in focus in - * or out events. Ensure that a disposed widget is - * not accessed. - */ - if (index == length) return false; - int start = index, offset = (next) ? 1 : -1; - while ((index = (index + offset + length) % length) != start) { - Control child = children [index]; - if (!child.isDisposed () && child.isTabItem ()) { - if (child.setTabItemFocus (next)) return true; - } - } - return false; -} - -boolean traverseReturn () { - return false; -} - -boolean traversePage (boolean next) { - return false; -} - -boolean traverseMnemonic (char key) { - return mnemonicHit (key); -} - -/** - * Forces all outstanding paint requests for the widget - * to be processed before this method returns. If there - * are no outstanding paint request, this method does - * nothing. - *

    - * Note: This method does not cause a redraw. - *

    - * - * @exception 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 #redraw() - * @see #redraw(int, int, int, int, boolean) - * @see PaintListener - * @see SWT#Paint - */ -public void update () { - checkWidget (); - update (false, true); -} - -void update (boolean all, boolean flush) { -// checkWidget(); - if (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return; - if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) == 0) return; - int /*long*/ window = paintWindow (); - if (flush) display.flushExposes (window, all); - OS.gdk_window_process_updates (window, all); - OS.gdk_flush (); -} - -void updateBackgroundMode () { - int oldState = state & PARENT_BACKGROUND; - checkBackground (); - if (oldState != (state & PARENT_BACKGROUND)) { - setBackground (); - } -} - -void updateLayout (boolean all) { - /* Do nothing */ -} - -int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - switch ((int)/*64*/user_data) { - case EXPOSE_EVENT_INVERSE: { - if ((OS.GTK_VERSION < OS.VERSION (2, 8, 0)) && ((state & OBSCURED) == 0)) { - Control control = findBackgroundControl (); - if (control != null && control.backgroundImage != null) { - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, arg0, GdkEventExpose.sizeof); - int /*long*/ paintWindow = paintWindow(); - int /*long*/ window = gdkEvent.window; - if (window != paintWindow) break; - int /*long*/ gdkGC = OS.gdk_gc_new (window); - OS.gdk_gc_set_clip_region (gdkGC, gdkEvent.region); - int[] dest_x = new int[1], dest_y = new int[1]; - OS.gtk_widget_translate_coordinates (paintHandle (), control.paintHandle (), 0, 0, dest_x, dest_y); - OS.gdk_gc_set_fill (gdkGC, OS.GDK_TILED); - OS.gdk_gc_set_ts_origin (gdkGC, -dest_x [0], -dest_y [0]); - OS.gdk_gc_set_tile (gdkGC, control.backgroundImage.pixmap); - OS.gdk_draw_rectangle (window, gdkGC, 1, gdkEvent.area_x, gdkEvent.area_y, gdkEvent.area_width, gdkEvent.area_height); - OS.g_object_unref (gdkGC); - } - } - break; - } - } - return super.windowProc (handle, arg0, user_data); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java deleted file mode 100644 index 11248e326d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java +++ /dev/null @@ -1,1103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - -import java.text.DateFormatSymbols; -import java.util.Calendar; - -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.gtk.OS; - -/** - * Instances of this class are selectable user interface - * objects that allow the user to enter and modify date - * or time values. - *

    - * Note that although this class is a subclass of Composite, - * it does not make sense to add children to it, or set a layout on it. - *

    - *
    - *
    Styles:
    - *
    DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG, DROP_DOWN
    - *
    Events:
    - *
    DefaultSelection, Selection
    - *
    - *

    - * Note: Only one of the styles DATE, TIME, or CALENDAR may be specified, - * and only one of the styles SHORT, MEDIUM, or LONG may be specified. - * The DROP_DOWN style is a HINT, and it is only valid with the DATE style. - *

    - * IMPORTANT: This class is not intended to be subclassed. - *

    - * - * @see DateTime snippets - * @see SWT Example: ControlExample - * @see Sample code and further information - * - * @since 3.3 - * @noextend This class is not intended to be subclassed by clients. - */ -public class DateTime extends Composite { - int day, month, year, hours, minutes, seconds; - - static final int MIN_YEAR = 1752; // Gregorian switchover in North America: September 19, 1752 - static final int MAX_YEAR = 9999; - - /* Emulated DATE and TIME variables */ - Calendar calendar; - DateFormatSymbols formatSymbols; - Button down, up; - Text text; - String format; - Point[] fieldIndices; - int[] fieldNames; - int fieldCount, currentField = 0, characterCount = 0; - boolean ignoreVerify = false; - static final String DEFAULT_SHORT_DATE_FORMAT = "MM/YYYY"; - static final String DEFAULT_MEDIUM_DATE_FORMAT = "MM/DD/YYYY"; - static final String DEFAULT_LONG_DATE_FORMAT = "MM/DD/YYYY"; - static final String DEFAULT_SHORT_TIME_FORMAT = "HH:MM AM"; - static final String DEFAULT_MEDIUM_TIME_FORMAT = "HH:MM:SS AM"; - static final String DEFAULT_LONG_TIME_FORMAT = "HH:MM:SS AM"; - -/** - * 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. - *

    - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the parent is null
    • - *
    - * @exception 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 SWT#DATE - * @see SWT#TIME - * @see SWT#CALENDAR - * @see SWT#SHORT - * @see SWT#MEDIUM - * @see SWT#LONG - * @see SWT#DROP_DOWN - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public DateTime (Composite parent, int style) { - super (parent, checkStyle (style)); - if ((this.style & SWT.CALENDAR) == 0) { - /* SWT.DATE and SWT.TIME */ - calendar = Calendar.getInstance(); - formatSymbols = new DateFormatSymbols(); - text = new Text(this, SWT.SINGLE); - /* disable the native drag and drop for the date/time text field */ - OS.gtk_drag_dest_unset(text.handle); - if ((this.style & SWT.DATE) != 0) { - setFormat((this.style & SWT.SHORT) != 0 ? DEFAULT_SHORT_DATE_FORMAT : (this.style & SWT.LONG) != 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT); - } else { // SWT.TIME - setFormat((this.style & SWT.SHORT) != 0 ? DEFAULT_SHORT_TIME_FORMAT : (this.style & SWT.LONG) != 0 ? DEFAULT_LONG_TIME_FORMAT : DEFAULT_MEDIUM_TIME_FORMAT); - } - text.setText(getFormattedString(this.style)); - Listener listener = new Listener() { - public void handleEvent(Event event) { - switch(event.type) { - case SWT.KeyDown: onKeyDown(event); break; - case SWT.FocusIn: onFocusIn(event); break; - case SWT.FocusOut: onFocusOut(event); break; - case SWT.MouseDown: onMouseClick(event); break; - case SWT.MouseUp: onMouseClick(event); break; - case SWT.Verify: onVerify(event); break; - } - } - }; - text.addListener(SWT.KeyDown, listener); - text.addListener(SWT.FocusIn, listener); - text.addListener(SWT.FocusOut, listener); - text.addListener(SWT.MouseDown, listener); - text.addListener(SWT.MouseUp, listener); - text.addListener(SWT.Verify, listener); - up = new Button(this, SWT.ARROW | SWT.UP); - //up.setToolTipText(SWT.getMessage ("SWT_Up")); //$NON-NLS-1$ - down = new Button(this, SWT.ARROW | SWT.DOWN); - //down.setToolTipText(SWT.getMessage ("SWT_Down")); //$NON-NLS-1$ - up.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - incrementField(+1); - text.setFocus(); - } - }); - down.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - incrementField(-1); - text.setFocus(); - } - }); - addListener(SWT.Resize, new Listener() { - public void handleEvent(Event event) { - onResize(event); - } - }); - } -} - -static int checkStyle (int style) { - /* - * Even though it is legal to create this widget - * with scroll bars, they serve no useful purpose - * because they do not automatically scroll the - * widget's client area. The fix is to clear - * the SWT style. - */ - style &= ~(SWT.H_SCROLL | SWT.V_SCROLL); - style = checkBits (style, SWT.DATE, SWT.TIME, SWT.CALENDAR, 0, 0, 0); - return checkBits (style, SWT.MEDIUM, SWT.SHORT, SWT.LONG, 0, 0, 0); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected by the user, by sending - * it one of the messages defined in the SelectionListener - * interface. - *

    - * widgetSelected is called when the user changes the control's value. - * widgetDefaultSelected is typically called when ENTER is pressed. - *

    - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener (SelectionListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Selection, typedListener); - addListener (SWT.DefaultSelection, typedListener); -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - int width = 0, height = 0; - if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { - if ((style & SWT.CALENDAR) != 0) { - // TODO: CALENDAR computeSize - width = 300; - height = 200; - } else { - /* SWT.DATE and SWT.TIME */ - GC gc = new GC(text); - Point textSize = gc.stringExtent(getComputeSizeString(style)); - gc.dispose(); - Rectangle trim = text.computeTrim(0, 0, textSize.x, textSize.y); - Point buttonSize = up.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed); - width = trim.width + buttonSize.x; - height = Math.max(trim.height, buttonSize.y); - } - } - if (width == 0) width = DEFAULT_WIDTH; - if (height == 0) height = DEFAULT_HEIGHT; - if (wHint != SWT.DEFAULT) width = wHint; - if (hHint != SWT.DEFAULT) height = hHint; - int border = getBorderWidth (); - width += border * 2; height += border * 2; - return new Point (width, height); -} - -void createHandle (int index) { - if ((style & SWT.CALENDAR) != 0) { - state |= HANDLE; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - handle = OS.gtk_calendar_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, handle); - if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) { - OS.gtk_calendar_set_display_options(handle, OS.GTK_CALENDAR_SHOW_HEADING | OS.GTK_CALENDAR_SHOW_DAY_NAMES); - } else { - OS.gtk_calendar_display_options(handle, OS.GTK_CALENDAR_SHOW_HEADING | OS.GTK_CALENDAR_SHOW_DAY_NAMES); - } - } else { - super.createHandle(index); - } -} - -boolean checkSubwindow () { - return false; -} - -void createWidget (int index) { - super.createWidget (index); - if ((style & SWT.CALENDAR) != 0) { - getDate(); - } -} - -void commitCurrentField() { - if (characterCount > 0) { - characterCount = 0; - int fieldName = fieldNames[currentField]; - int start = fieldIndices[currentField].x; - int end = fieldIndices[currentField].y; - String value = text.getText(start, end - 1); - int s = value.lastIndexOf(' '); - if (s != -1) value = value.substring(s + 1); - int newValue = unformattedIntValue(fieldName, value, characterCount == 0, calendar.getActualMaximum(fieldName)); - if (newValue != -1) setTextField(fieldName, newValue, true, true); - } -} - -String formattedStringValue(int fieldName, int value, boolean adjust) { - if (fieldName == Calendar.AM_PM) { - String[] ampm = formatSymbols.getAmPmStrings(); - return ampm[value]; - } - if (adjust) { - if (fieldName == Calendar.HOUR && value == 0) { - return String.valueOf(12); - } - if (fieldName == Calendar.MONTH) { - return String.valueOf(value + 1); - } - } - return String.valueOf(value); -} - -String getComputeSizeString(int style) { - if ((style & SWT.DATE) != 0) { - return (style & SWT.SHORT) != 0 ? DEFAULT_SHORT_DATE_FORMAT : (style & SWT.LONG) != 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT; - } - // SWT.TIME - return (style & SWT.SHORT) != 0 ? DEFAULT_SHORT_TIME_FORMAT : (style & SWT.LONG) != 0 ? DEFAULT_LONG_TIME_FORMAT : DEFAULT_MEDIUM_TIME_FORMAT; -} - -int getFieldIndex(int fieldName) { - for (int i = 0; i < fieldCount; i++) { - if (fieldNames[i] == fieldName) { - return i; - } - } - return -1; -} - -String getFormattedString(int style) { - if ((style & SWT.TIME) != 0) { - String[] ampm = formatSymbols.getAmPmStrings(); - int h = calendar.get(Calendar.HOUR); if (h == 0) h = 12; - int m = calendar.get(Calendar.MINUTE); - int s = calendar.get(Calendar.SECOND); - int a = calendar.get(Calendar.AM_PM); - if ((style & SWT.SHORT) != 0) return "" + (h < 10 ? " " : "") + h + ":" + (m < 10 ? "0" : "") + m + " " + ampm[a]; - return "" + (h < 10 ? " " : "") + h + ":" + (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s + " " + ampm[a]; - } - /* SWT.DATE */ - int y = calendar.get(Calendar.YEAR); - int m = calendar.get(Calendar.MONTH) + 1; - int d = calendar.get(Calendar.DAY_OF_MONTH); - if ((style & SWT.SHORT) != 0) return "" + (m < 10 ? " " : "") + m + "/" + y; - return "" + (m < 10 ? " " : "") + m + "/" + (d < 10 ? " " : "") + d + "/" + y; -} - -void getDate() { - int [] y = new int [1]; - int [] m = new int [1]; - int [] d = new int [1]; - OS.gtk_calendar_get_date(handle, y, m, d); - year = y[0]; - month = m[0]; - day = d[0]; -} - -/** - * Returns the receiver's date, or day of the month. - *

    - * The first day of the month is 1, and the last day depends on the month and year. - *

    - * - * @return a positive integer beginning with 1 - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int getDay () { - checkWidget (); - if ((style & SWT.CALENDAR) != 0) { - getDate(); - return day; - } else { - return calendar.get(Calendar.DAY_OF_MONTH); - } -} - -/** - * Returns the receiver's hours. - *

    - * Hours is an integer between 0 and 23. - *

    - * - * @return an integer between 0 and 23 - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int getHours () { - checkWidget (); - if ((style & SWT.CALENDAR) != 0) { - return hours; - } else { - return calendar.get(Calendar.HOUR_OF_DAY); - } -} - -/** - * Returns the receiver's minutes. - *

    - * Minutes is an integer between 0 and 59. - *

    - * - * @return an integer between 0 and 59 - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int getMinutes () { - checkWidget (); - if ((style & SWT.CALENDAR) != 0) { - return minutes; - } else { - return calendar.get(Calendar.MINUTE); - } -} - -/** - * Returns the receiver's month. - *

    - * The first month of the year is 0, and the last month is 11. - *

    - * - * @return an integer between 0 and 11 - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int getMonth () { - checkWidget (); - if ((style & SWT.CALENDAR) != 0) { - getDate(); - return month; - } else { - return calendar.get(Calendar.MONTH); - } -} - -String getNameText() { - return (style & SWT.TIME) != 0 ? getHours() + ":" + getMinutes() + ":" + getSeconds() - : (getMonth() + 1) + "/" + getDay() + "/" + getYear(); -} - -/** - * Returns the receiver's seconds. - *

    - * Seconds is an integer between 0 and 59. - *

    - * - * @return an integer between 0 and 59 - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int getSeconds () { - checkWidget (); - if ((style & SWT.CALENDAR) != 0) { - return seconds; - } else { - return calendar.get(Calendar.SECOND); - } -} - -/** - * Returns the receiver's year. - *

    - * The first year is 1752 and the last year is 9999. - *

    - * - * @return an integer between 1752 and 9999 - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public int getYear () { - checkWidget (); - if ((style & SWT.CALENDAR) != 0) { - getDate(); - return year; - } else { - return calendar.get(Calendar.YEAR); - } -} - -int /*long*/ gtk_day_selected (int /*long*/ widget) { - sendSelectionEvent (); - return 0; -} - -int /*long*/ gtk_day_selected_double_click (int /*long*/ widget) { - postEvent(SWT.DefaultSelection); - return 0; -} - -int /*long*/ gtk_month_changed (int /*long*/ widget) { - sendSelectionEvent (); - return 0; -} - -void hookEvents () { - super.hookEvents(); - if ((style & SWT.CALENDAR) != 0) { - OS.g_signal_connect_closure (handle, OS.day_selected, display.closures [DAY_SELECTED], false); - OS.g_signal_connect_closure (handle, OS.day_selected_double_click, display.closures [DAY_SELECTED_DOUBLE_CLICK], false); - OS.g_signal_connect_closure (handle, OS.month_changed, display.closures [MONTH_CHANGED], false); - } -} - -boolean isValidTime(int fieldName, int value) { - Calendar validCalendar; - if ((style & SWT.CALENDAR) != 0) { - validCalendar = Calendar.getInstance(); - } else { - validCalendar = calendar; - } - int min = validCalendar.getActualMinimum(fieldName); - int max = validCalendar.getActualMaximum(fieldName); - return value >= min && value <= max; -} - -boolean isValidDate(int year, int month, int day) { - if (year < MIN_YEAR || year > MAX_YEAR) return false; - Calendar valid = Calendar.getInstance(); - valid.set(year, month, day); - return valid.get(Calendar.YEAR) == year - && valid.get(Calendar.MONTH) == month - && valid.get(Calendar.DAY_OF_MONTH) == day; -} - -void incrementField(int amount) { - int fieldName = fieldNames[currentField]; - int value = calendar.get(fieldName); - if (fieldName == Calendar.HOUR) { - int max = calendar.getMaximum(Calendar.HOUR); - int min = calendar.getMinimum(Calendar.HOUR); - if ((value == max && amount == 1) || (value == min && amount == -1)) { - int temp = currentField; - currentField = getFieldIndex(Calendar.AM_PM); - setTextField(Calendar.AM_PM, (calendar.get(Calendar.AM_PM) + 1) % 2, true, true); - currentField = temp; - } - } - setTextField(fieldName, value + amount, true, true); -} - -void onKeyDown(Event event) { - int fieldName; - switch (event.keyCode) { - case SWT.ARROW_RIGHT: - case SWT.KEYPAD_DIVIDE: - // a right arrow or a valid separator navigates to the field on the right, with wraping - selectField((currentField + 1) % fieldCount); - break; - case SWT.ARROW_LEFT: - // navigate to the field on the left, with wrapping - int index = currentField - 1; - selectField(index < 0 ? fieldCount - 1 : index); - break; - case SWT.ARROW_UP: - case SWT.KEYPAD_ADD: - // set the value of the current field to value + 1, with wrapping - commitCurrentField(); - incrementField(+1); - break; - case SWT.ARROW_DOWN: - case SWT.KEYPAD_SUBTRACT: - // set the value of the current field to value - 1, with wrapping - commitCurrentField(); - incrementField(-1); - break; - case SWT.HOME: - // set the value of the current field to its minimum - fieldName = fieldNames[currentField]; - setTextField(fieldName, calendar.getActualMinimum(fieldName), true, true); - break; - case SWT.END: - // set the value of the current field to its maximum - fieldName = fieldNames[currentField]; - setTextField(fieldName, calendar.getActualMaximum(fieldName), true, true); - break; - case SWT.CR: - postEvent(SWT.DefaultSelection); - break; - default: - switch (event.character) { - case '/': - case ':': - case '-': - case '.': - // a valid separator navigates to the field on the right, with wraping - selectField((currentField + 1) % fieldCount); - break; - } - } -} - -void onFocusIn(Event event) { - selectField(currentField); -} - -void onFocusOut(Event event) { - commitCurrentField(); -} - -void onMouseClick(Event event) { - if (event.button != 1) return; - Point sel = text.getSelection(); - for (int i = 0; i < fieldCount; i++) { - if (fieldIndices[i].x <= sel.x && sel.x <= fieldIndices[i].y) { - selectField(i); - break; - } - } -} - -void onResize(Event event) { - Rectangle rect = getClientArea (); - int width = rect.width; - int height = rect.height; - Point buttonSize = up.computeSize(SWT.DEFAULT, height); - int buttonHeight = buttonSize.y / 2; - text.setBounds(0, 0, width - buttonSize.x, height); - up.setBounds(width - buttonSize.x, 0, buttonSize.x, buttonHeight); - down.setBounds(width - buttonSize.x, buttonHeight, buttonSize.x, buttonHeight); -} - -void onVerify(Event event) { - if (ignoreVerify) return; - event.doit = false; - int fieldName = fieldNames[currentField]; - int start = fieldIndices[currentField].x; - int end = fieldIndices[currentField].y; - int length = end - start; - String newText = event.text; - if (fieldName == Calendar.AM_PM) { - String[] ampm = formatSymbols.getAmPmStrings(); - if (newText.equalsIgnoreCase(ampm[Calendar.AM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.AM])) { - setTextField(fieldName, Calendar.AM, true, false); - } else if (newText.equalsIgnoreCase(ampm[Calendar.PM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.PM])) { - setTextField(fieldName, Calendar.PM, true, false); - } - return; - } - if (characterCount > 0) { - try { - Integer.parseInt(newText); - } catch (NumberFormatException ex) { - return; - } - String value = text.getText(start, end - 1); - int s = value.lastIndexOf(' '); - if (s != -1) value = value.substring(s + 1); - newText = "" + value + newText; - } - int newTextLength = newText.length(); - boolean first = characterCount == 0; - characterCount = (newTextLength < length) ? newTextLength : 0; - int max = calendar.getActualMaximum(fieldName); - int min = calendar.getActualMinimum(fieldName); - int newValue = unformattedIntValue(fieldName, newText, characterCount == 0, max); - if (newValue == -1) { - characterCount = 0; - return; - } - if (first && newValue == 0 && length > 1) { - setTextField(fieldName, newValue, false, false); - } else if (min <= newValue && newValue <= max) { - setTextField(fieldName, newValue, characterCount == 0, characterCount == 0); - } else { - if (newTextLength >= length) { - newText = newText.substring(newTextLength - length + 1); - newValue = unformattedIntValue(fieldName, newText, characterCount == 0, max); - if (newValue != -1) { - characterCount = length - 1; - if (min <= newValue && newValue <= max) { - setTextField(fieldName, newValue, characterCount == 0, true); - } - } - } - } -} - -void releaseWidget () { - super.releaseWidget(); - //TODO: need to do anything here? -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected by the user. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception 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 SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener (SelectionListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Selection, listener); - eventTable.unhook (SWT.DefaultSelection, listener); -} - -void selectField(int index) { - if (index != currentField) { - commitCurrentField(); - } - final int start = fieldIndices[index].x; - final int end = fieldIndices[index].y; - Point pt = text.getSelection(); - if (index == currentField && start == pt.x && end == pt.y) return; - currentField = index; - display.asyncExec(new Runnable() { - public void run() { - if (!text.isDisposed()) { - String value = text.getText(start, end - 1); - int s = value.lastIndexOf(' '); - if (s == -1) s = start; - else s = start + s + 1; - text.setSelection(s, end); - } - } - }); -} - -void sendSelectionEvent () { - int [] y = new int [1]; - int [] m = new int [1]; - int [] d = new int [1]; - OS.gtk_calendar_get_date(handle, y, m, d); - //TODO: hours, minutes, seconds? - if (d[0] != day || - m[0] != month || - y[0] != year) { - year = y[0]; - month = m[0]; - day = d[0]; - postEvent (SWT.Selection); - } -} - -public void setBackground(Color color) { - checkWidget(); - super.setBackground(color); - if (text != null) text.setBackground(color); -} - -public void setFont(Font font) { - checkWidget(); - super.setFont(font); - if (text != null) text.setFont(font); - redraw(); -} - -public void setForeground(Color color) { - checkWidget(); - super.setForeground(color); - if (text != null) text.setForeground(color); -} - -/*public*/ void setFormat(String string) { - checkWidget(); - // TODO: this needs to be locale sensitive - fieldCount = (style & SWT.DATE) != 0 ? ((style & SWT.SHORT) != 0 ? 2 : 3) : ((style & SWT.SHORT) != 0 ? 3 : 4); - fieldIndices = new Point[fieldCount]; - fieldNames = new int[fieldCount]; - if ((style & SWT.DATE) != 0) { - fieldNames[0] = Calendar.MONTH; - fieldIndices[0] = new Point(0, 2); - if ((style & SWT.SHORT) != 0) { - fieldNames[1] = Calendar.YEAR; - fieldIndices[1] = new Point(3, 7); - } else { - fieldNames[1] = Calendar.DAY_OF_MONTH; - fieldIndices[1] = new Point(3, 5); - fieldNames[2] = Calendar.YEAR; - fieldIndices[2] = new Point(6, 10); - } - } else { /* SWT.TIME */ - fieldNames[0] = Calendar.HOUR; - fieldIndices[0] = new Point(0, 2); - fieldNames[1] = Calendar.MINUTE; - fieldIndices[1] = new Point(3, 5); - if ((style & SWT.SHORT) != 0) { - fieldNames[2] = Calendar.AM_PM; - fieldIndices[2] = new Point(6, 8); - } else { - fieldNames[2] = Calendar.SECOND; - fieldIndices[2] = new Point(6, 8); - fieldNames[3] = Calendar.AM_PM; - fieldIndices[3] = new Point(9, 11); - } - } -} - -void setField(int fieldName, int value) { - if (calendar.get(fieldName) == value) return; - if (fieldName == Calendar.AM_PM) { - calendar.roll(Calendar.HOUR_OF_DAY, 12); // TODO: needs more work for setFormat and locale - } - calendar.set(fieldName, value); - postEvent(SWT.Selection); -} - -void setTextField(int fieldName, int value, boolean commit, boolean adjust) { - if (commit) { - int max = calendar.getActualMaximum(fieldName); - int min = calendar.getActualMinimum(fieldName); - if (fieldName == Calendar.YEAR) { - max = MAX_YEAR; - min = MIN_YEAR; - /* Special case: convert 1 or 2-digit years into reasonable 4-digit years. */ - int currentYear = Calendar.getInstance().get(Calendar.YEAR); - int currentCentury = (currentYear / 100) * 100; - if (value < (currentYear + 30) % 100) value += currentCentury; - else if (value < 100) value += currentCentury - 100; - } - if (value > max) value = min; // wrap - if (value < min) value = max; // wrap - } - int start = fieldIndices[currentField].x; - int end = fieldIndices[currentField].y; - text.setSelection(start, end); - String newValue = formattedStringValue(fieldName, value, adjust); - StringBuffer buffer = new StringBuffer(newValue); - /* Convert leading 0's into spaces. */ - int prependCount = end - start - buffer.length(); - for (int i = 0; i < prependCount; i++) { - switch (fieldName) { - case Calendar.MINUTE: - case Calendar.SECOND: - buffer.insert(0, 0); - break; - default: - buffer.insert(0, ' '); - break; - } - } - newValue = buffer.toString(); - ignoreVerify = true; - text.insert(newValue); - ignoreVerify = false; - selectField(currentField); - if (commit) setField(fieldName, value); -} - -/** - * Sets the receiver's year, month, and day in a single operation. - *

    - * This is the recommended way to set the date, because setting the year, - * month, and day separately may result in invalid intermediate dates. - *

    - * - * @param year an integer between 1752 and 9999 - * @param month an integer between 0 and 11 - * @param day a positive integer beginning with 1 - * - * @exception 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 - */ -public void setDate (int year, int month, int day) { - checkWidget (); - if (!isValidDate(year, month, day)) return; - if ((style & SWT.CALENDAR) != 0) { - this.year = year; - this.month = month; - this.day = day; - OS.gtk_calendar_select_month(handle, month, year); - OS.gtk_calendar_select_day(handle, day); - } else { - calendar.set(year, month, day); - updateControl(); - } -} - -/** - * Sets the receiver's date, or day of the month, to the specified day. - *

    - * The first day of the month is 1, and the last day depends on the month and year. - * If the specified day is not valid for the receiver's month and year, then it is ignored. - *

    - * - * @param day a positive integer beginning with 1 - * - * @exception 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 #setDate - */ -public void setDay (int day) { - checkWidget (); - if (!isValidDate(getYear(), getMonth(), day)) return; - if ((style & SWT.CALENDAR) != 0) { - this.day = day; - OS.gtk_calendar_select_day(handle, day); - } else { - calendar.set(Calendar.DAY_OF_MONTH, day); - updateControl(); - } -} - -/** - * Sets the receiver's hours. - *

    - * Hours is an integer between 0 and 23. - *

    - * - * @param hours an integer between 0 and 23 - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setHours (int hours) { - checkWidget (); - if (!isValidTime(Calendar.HOUR_OF_DAY, hours)) return; - if ((style & SWT.CALENDAR) != 0) { - this.hours = hours; - } else { - calendar.set(Calendar.HOUR_OF_DAY, hours); - updateControl(); - } -} - -/** - * Sets the receiver's minutes. - *

    - * Minutes is an integer between 0 and 59. - *

    - * - * @param minutes an integer between 0 and 59 - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setMinutes (int minutes) { - checkWidget (); - if (!isValidTime(Calendar.MINUTE, minutes)) return; - if ((style & SWT.CALENDAR) != 0) { - this.minutes = minutes; - } else { - calendar.set(Calendar.MINUTE, minutes); - updateControl(); - } -} - -/** - * Sets the receiver's month. - *

    - * The first month of the year is 0, and the last month is 11. - * If the specified month is not valid for the receiver's day and year, then it is ignored. - *

    - * - * @param month an integer between 0 and 11 - * - * @exception 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 #setDate - */ -public void setMonth (int month) { - checkWidget (); - if (!isValidDate(getYear(), month, getDay())) return; - if ((style & SWT.CALENDAR) != 0) { - this.month = month; - OS.gtk_calendar_select_month(handle, month, year); - } else { - calendar.set(Calendar.MONTH, month); - updateControl(); - } -} - -/** - * Sets the receiver's seconds. - *

    - * Seconds is an integer between 0 and 59. - *

    - * - * @param seconds an integer between 0 and 59 - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setSeconds (int seconds) { - checkWidget (); - if (!isValidTime(Calendar.SECOND, seconds)) return; - if ((style & SWT.CALENDAR) != 0) { - this.seconds = seconds; - } else { - calendar.set(Calendar.SECOND, seconds); - updateControl(); - } -} - -/** - * Sets the receiver's hours, minutes, and seconds in a single operation. - * - * @param hours an integer between 0 and 23 - * @param minutes an integer between 0 and 59 - * @param seconds an integer between 0 and 59 - * - * @exception 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 - */ -public void setTime (int hours, int minutes, int seconds) { - checkWidget (); - if (!isValidTime(Calendar.HOUR_OF_DAY, hours)) return; - if (!isValidTime(Calendar.MINUTE, minutes)) return; - if (!isValidTime(Calendar.SECOND, seconds)) return; - if ((style & SWT.CALENDAR) != 0) { - this.hours = hours; - this.minutes = minutes; - this.seconds = seconds; - } else { - calendar.set(Calendar.HOUR_OF_DAY, hours); - calendar.set(Calendar.MINUTE, minutes); - calendar.set(Calendar.SECOND, seconds); - updateControl(); - } -} - -/** - * Sets the receiver's year. - *

    - * The first year is 1752 and the last year is 9999. - * If the specified year is not valid for the receiver's day and month, then it is ignored. - *

    - * - * @param year an integer between 1752 and 9999 - * - * @exception 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 #setDate - */ -public void setYear (int year) { - checkWidget (); - if (!isValidDate(year, getMonth(), getDay())) return; - if ((style & SWT.CALENDAR) != 0) { - this.year = year; - OS.gtk_calendar_select_month(handle, month, year); - } else { - calendar.set(Calendar.YEAR, year); - updateControl(); - } -} - -int unformattedIntValue(int fieldName, String newText, boolean adjust, int max) { - int newValue; - try { - newValue = Integer.parseInt(newText); - } catch (NumberFormatException ex) { - return -1; - } - if (fieldName == Calendar.MONTH && adjust) { - newValue--; - if (newValue == -1) newValue = max; - } - if (fieldName == Calendar.HOUR && adjust) { - if (newValue == 12) newValue = 0; // TODO: needs more work for setFormat and locale - } - return newValue; -} - -public void updateControl() { - if (text != null) { - String string = getFormattedString(style); - ignoreVerify = true; - text.setText(string); - ignoreVerify = false; - } - redraw(); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java deleted file mode 100644 index 38ed5a2f6a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java +++ /dev/null @@ -1,752 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class provide the appearance and - * behavior of Shells, but are not top - * level shells or dialogs. Class Shell - * shares a significant amount of code with this class, - * and is a subclass. - *

    - * IMPORTANT: This class was intended to be abstract and - * should never be referenced or instantiated. - * Instead, the class Shell should be used. - *

    - *

    - * Instances are always displayed in one of the maximized, - * minimized or normal states: - *

      - *
    • - * When an instance is marked as maximized, the - * window manager will typically resize it to fill the - * entire visible area of the display, and the instance - * is usually put in a state where it can not be resized - * (even if it has style RESIZE) until it is - * no longer maximized. - *
    • - * When an instance is in the normal state (neither - * maximized or minimized), its appearance is controlled by - * the style constants which were specified when it was created - * and the restrictions of the window manager (see below). - *
    • - * When an instance has been marked as minimized, - * its contents (client area) will usually not be visible, - * and depending on the window manager, it may be - * "iconified" (that is, replaced on the desktop by a small - * simplified representation of itself), relocated to a - * distinguished area of the screen, or hidden. Combinations - * of these changes are also possible. - *
    • - *
    - *

    - * Note: The styles supported by this class must be treated - * as HINTs, since the window manager for the - * desktop on which the instance is visible has ultimate - * control over the appearance and behavior of decorations. - * For example, some window managers only support resizable - * windows and will always assume the RESIZE style, even if - * it is not set. - *
    - *
    Styles:
    - *
    BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL
    - *
    Events:
    - *
    (none)
    - *
    - * Class SWT provides two "convenience constants" - * for the most commonly required style combinations: - *
    - *
    SHELL_TRIM
    - *
    - * the result of combining the constants which are required - * to produce a typical application top level shell: (that - * is, CLOSE | TITLE | MIN | MAX | RESIZE) - *
    - *
    DIALOG_TRIM
    - *
    - * the result of combining the constants which are required - * to produce a typical application dialog shell: (that - * is, TITLE | CLOSE | BORDER) - *
    - *
    - *

    - * IMPORTANT: This class is intended to be subclassed only - * within the SWT implementation. - *

    - * - * @see #getMinimized - * @see #getMaximized - * @see Shell - * @see SWT - * @see Sample code and further information - * @noextend This class is not intended to be subclassed by clients. - */ -public class Decorations extends Canvas { - String text; - Image image; - Image [] images = new Image [0]; - boolean minimized, maximized; - Menu menuBar; - Menu [] menus; - Control savedFocus; - Button defaultButton, saveDefault; - int /*long*/ accelGroup, vboxHandle; - -Decorations () { - /* Do nothing */ -} - -/** - * 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. - *

    - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the parent is null
    • - *
    - * @exception 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 SWT#BORDER - * @see SWT#CLOSE - * @see SWT#MIN - * @see SWT#MAX - * @see SWT#RESIZE - * @see SWT#TITLE - * @see SWT#NO_TRIM - * @see SWT#SHELL_TRIM - * @see SWT#DIALOG_TRIM - * @see SWT#ON_TOP - * @see SWT#TOOL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Decorations (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -static int checkStyle (int style) { - if ((style & SWT.NO_TRIM) != 0) { - style &= ~(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.BORDER); - } - if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) { - style |= SWT.TITLE; - } - return style; -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -void _setImages (Image [] images) { - if (images != null && images.length > 1) { - Image [] bestImages = new Image [images.length]; - System.arraycopy (images, 0, bestImages, 0, images.length); - sort (bestImages); - images = bestImages; - } - int /*long*/ pixbufs = 0; - if (images != null) { - for (int i = 0; i < images.length; i++) { - Image image = images [i]; - int /*long*/ pixbuf = Display.createPixbuf (image); - pixbufs = OS.g_list_append (pixbufs, pixbuf); - } - } - OS.gtk_window_set_icon_list (topHandle (), pixbufs); - int /*long*/ [] data = new int /*long*/ [1]; - int /*long*/ temp = pixbufs; - while (temp != 0) { - OS.memmove (data, temp, OS.PTR_SIZEOF); - OS.g_object_unref (data [0]); - temp = OS.g_list_next (temp); - } - if (pixbufs != 0) OS.g_list_free (pixbufs); -} - -void addMenu (Menu menu) { - if (menus == null) menus = new Menu [4]; - for (int i=0; i data2.width || data1.height > data2.height ? -1 : 1; -} - -Widget computeTabGroup () { - return this; -} - -Control computeTabRoot () { - return this; -} - -void createAccelGroup () { - if (accelGroup != 0) return; - accelGroup = OS.gtk_accel_group_new (); - if (accelGroup == 0) SWT.error (SWT.ERROR_NO_HANDLES); - //FIXME - what should we do for Decorations - int /*long*/ shellHandle = topHandle (); - OS.gtk_window_add_accel_group (shellHandle, accelGroup); -} - -void createWidget (int index) { - super.createWidget (index); - text = ""; -} - -void destroyAccelGroup () { - if (accelGroup == 0) return; - int /*long*/ shellHandle = topHandle (); - OS.gtk_window_remove_accel_group (shellHandle, accelGroup); - //TEMPORARY CODE -// OS.g_object_unref (accelGroup); - accelGroup = 0; -} - -void fixAccelGroup () { - if (menuBar == null) return; - destroyAccelGroup (); - createAccelGroup (); - menuBar.addAccelerators (accelGroup); -} - -void fixDecorations (Decorations newDecorations, Control control, Menu [] menus) { - if (this == newDecorations) return; - if (control == savedFocus) savedFocus = null; - if (control == defaultButton) defaultButton = null; - if (control == saveDefault) saveDefault = null; - if (menus == null) return; - Menu menu = control.menu; - if (menu != null) { - int index = 0; - while (index - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - * - * - * @see #setDefaultButton(Button) - */ -public Button getDefaultButton () { - checkWidget(); - return defaultButton != null ? defaultButton : saveDefault; -} - -/** - * Returns the receiver's image if it had previously been - * set using setImage(). The image is typically - * displayed by the window manager when the instance is - * marked as iconified, and may also be displayed somewhere - * in the trim when the instance is in normal or maximized - * states. - *

    - * Note: This method will return null if called before - * setImage() is called. It does not provide - * access to a window manager provided, "default" image - * even if one exists. - *

    - * - * @return the image - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Image getImage () { - checkWidget (); - return image; -} - -/** - * Returns the receiver's images if they had previously been - * set using setImages(). Images are typically - * displayed by the window manager when the instance is - * marked as iconified, and may also be displayed somewhere - * in the trim when the instance is in normal or maximized - * states. Depending where the icon is displayed, the platform - * chooses the icon with the "best" attributes. It is expected - * that the array will contain the same icon rendered at different - * sizes, with different depth and transparency attributes. - * - *

    - * Note: This method will return an empty array if called before - * setImages() is called. It does not provide - * access to a window manager provided, "default" image - * even if one exists. - *

    - * - * @return the images - * - * @exception 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.0 - */ -public Image [] getImages () { - checkWidget (); - if (images == null) return new Image [0]; - Image [] result = new Image [images.length]; - System.arraycopy (images, 0, result, 0, images.length); - return result; -} - -/** - * Returns true if the receiver is currently - * maximized, and false otherwise. - *

    - * - * @return the maximized state - * - * @exception 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 #setMaximized - */ -public boolean getMaximized () { - checkWidget(); - return maximized; -} - -/** - * Returns the receiver's menu bar if one had previously - * been set, otherwise returns null. - * - * @return the menu bar or null - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Menu getMenuBar () { - checkWidget(); - return menuBar; -} - -/** - * Returns true if the receiver is currently - * minimized, and false otherwise. - *

    - * - * @return the minimized state - * - * @exception 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 #setMinimized - */ -public boolean getMinimized () { - checkWidget(); - return minimized; -} - -String getNameText () { - return getText (); -} - -/** - * Returns the receiver's text, which is the string that the - * window manager will typically display as the receiver's - * title. If the text has not previously been set, - * returns an empty string. - * - * @return the text - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public String getText () { - checkWidget(); - return text; -} - -public boolean isReparentable () { - checkWidget (); - return false; -} - -boolean isTabGroup () { - return true; -} - -boolean isTabItem () { - return false; -} - -Decorations menuShell () { - return this; -} - -void removeMenu (Menu menu) { - if (menus == null) return; - for (int i=0; isaved default button). If no default button had - * previously been set, or the saved default button was - * disposed, the receiver's default button will be set to - * null. - *

    - * The default button is the button that is selected when - * the receiver is active and the user presses ENTER. - *

    - * - * @param button the new default button - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the button has been disposed
    • - *
    • ERROR_INVALID_PARENT - if the control is not in the same widget tree
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setDefaultButton (Button button) { - checkWidget(); - int /*long*/ buttonHandle = 0; - if (button != null) { - if (button.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - if (button.menuShell () != this) error (SWT.ERROR_INVALID_PARENT); - buttonHandle = button.handle; - } - saveDefault = defaultButton = button; - OS.gtk_window_set_default (topHandle (), buttonHandle); -} - -/** - * Sets the receiver's image to the argument, which may - * be null. The image is typically displayed by the window - * manager when the instance is marked as iconified, and - * may also be displayed somewhere in the trim when the - * instance is in normal or maximized states. - * - * @param image the new image (or null) - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the image has been disposed
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setImage (Image image) { - checkWidget (); - this.image = image; - _setImages (image != null ? new Image [] {image} : null); -} - -/** - * Sets the receiver's images to the argument, which may - * be an empty array. Images are typically displayed by the - * window manager when the instance is marked as iconified, - * and may also be displayed somewhere in the trim when the - * instance is in normal or maximized states. Depending where - * the icon is displayed, the platform chooses the icon with - * the "best" attributes. It is expected that the array will - * contain the same icon rendered at different sizes, with - * different depth and transparency attributes. - * - * @param images the new image array - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the array of images is null
    • - *
    • ERROR_INVALID_ARGUMENT - if one of the images is null or has been disposed
    • - *
    - * @exception 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.0 - */ -public void setImages (Image [] images) { - checkWidget (); - if (images == null) error (SWT.ERROR_INVALID_ARGUMENT); - for (int i = 0; i < images.length; i++) { - if (images [i] == null || images [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - } - this.images = images; - _setImages (images); -} - -/** - * Sets the maximized state of the receiver. - * If the argument is true causes the receiver - * to switch to the maximized state, and if the argument is - * false and the receiver was previously maximized, - * causes the receiver to switch back to either the minimized - * or normal states. - *

    - * Note: The result of intermixing calls to setMaximized(true) - * and setMinimized(true) will vary by platform. Typically, - * the behavior will match the platform user's expectations, but not - * always. This should be avoided if possible. - *

    - * - * @param maximized the new maximized state - * - * @exception 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 #setMinimized - */ -public void setMaximized (boolean maximized) { - checkWidget(); - this.maximized = maximized; -} - -/** - * Sets the receiver's menu bar to the argument, which - * may be null. - * - * @param menu the new menu bar - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the menu has been disposed
    • - *
    • ERROR_INVALID_PARENT - if the menu is not in the same widget tree
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setMenuBar (Menu menu) { - checkWidget(); - if (menuBar == menu) return; - if (menu != null) { - if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR); - if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT); - } - menuBar = menu; -} - -/** - * Sets the minimized stated of the receiver. - * If the argument is true causes the receiver - * to switch to the minimized state, and if the argument is - * false and the receiver was previously minimized, - * causes the receiver to switch back to either the maximized - * or normal states. - *

    - * Note: The result of intermixing calls to setMaximized(true) - * and setMinimized(true) will vary by platform. Typically, - * the behavior will match the platform user's expectations, but not - * always. This should be avoided if possible. - *

    - * - * @param minimized the new maximized state - * - * @exception 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 #setMaximized - */ -public void setMinimized (boolean minimized) { - checkWidget(); - this.minimized = minimized; -} - -void setSavedFocus (Control control) { - if (this == control) return; - savedFocus = control; -} - -/** - * Sets the receiver's text, which is the string that the - * window manager will typically display as the receiver's - * title, to the argument, which must not be null. - * - * @param string the new text - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the text is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - text = string; -} - -void sort (Image [] images) { - /* Shell Sort from K&R, pg 108 */ - int length = images.length; - if (length <= 1) return; - ImageData [] datas = new ImageData [length]; - for (int i = 0; i < length; i++) { - datas [i] = images [i].getImageData (); - } - for (int gap=length/2; gap>0; gap/=2) { - for (int i=gap; i=0; j-=gap) { - if (compare (datas [j], datas [j + gap]) >= 0) { - Image swap = images [j]; - images [j] = images [j + gap]; - images [j + gap] = swap; - ImageData swapData = datas [j]; - datas [j] = datas [j + gap]; - datas [j + gap] = swapData; - } - } - } - } -} - -boolean traverseItem (boolean next) { - return false; -} - -boolean traverseReturn () { - Button button = defaultButton != null ? defaultButton: saveDefault; - if (button == null || button.isDisposed ()) return false; - /* - * Bug in GTK. When a default button that is disabled is - * activated using the Enter key, GTK GP's. The fix is to - * detect this case and stop GTK from processing the Enter - * key. - */ - if (!button.isVisible () || !button.isEnabled ()) return true; - int /*long*/ shellHandle = _getShell ().topHandle (); - return OS.gtk_window_activate_default (shellHandle); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java deleted file mode 100644 index 8b31222fad..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java +++ /dev/null @@ -1,339 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; - -/** - * Instances of this class allow the user to navigate - * the file system and select a directory. - *
    - *
    Styles:
    - *
    (none)
    - *
    Events:
    - *
    (none)
    - *
    - *

    - * IMPORTANT: This class is intended to be subclassed only - * within the SWT implementation. - *

    - * - * @see DirectoryDialog snippets - * @see SWT Example: ControlExample, Dialog tab - * @see Sample code and further information - * @noextend This class is not intended to be subclassed by clients. - */ -public class DirectoryDialog extends Dialog { - String message = "", filterPath = ""; - static final String SEPARATOR = System.getProperty ("file.separator"); - -/** - * Constructs a new instance of this class given only its parent. - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the parent is null
    • - *
    - * @exception 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
    • - *
    - */ -public DirectoryDialog (Shell parent) { - this (parent, SWT.APPLICATION_MODAL); -} -/** - * 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. - *

    - * - * @param parent a shell which will be the parent of the new instance - * @param style the style of dialog to construct - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the parent is null
    • - *
    - * @exception 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
    • - *
    - */ -public DirectoryDialog (Shell parent, int style) { - super (parent, checkStyle (parent, style)); - checkSubclass (); -} -/** - * Returns the path which the dialog will use to filter - * the directories it shows. - * - * @return the filter path - * - * @see #setFilterPath - */ -public String getFilterPath () { - return filterPath; -} -/** - * Returns the dialog's message, which is a description of - * the purpose for which it was opened. This message will be - * visible on the dialog while it is open. - * - * @return the message - */ -public String getMessage () { - return message; -} -/** - * Makes the dialog visible and brings it to the front - * of the display. - * - * @return a string describing the absolute path of the selected directory, - * or null if the dialog was cancelled or an error occurred - * - * @exception SWTException
      - *
    • ERROR_WIDGET_DISPOSED - if the dialog has been disposed
    • - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog
    • - *
    - */ -public String open () { - boolean useChooserDialog = OS.GTK_VERSION >= OS.VERSION (2, 4, 10); - if (useChooserDialog) { - return openChooserDialog (); - } else { - return openClassicDialog (); - } -} -String openChooserDialog () { - byte [] titleBytes = Converter.wcsToMbcs (null, title, true); - int /*long*/ shellHandle = parent.topHandle (); - Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - int /*long*/ handle = 0; - if (display.getDismissalAlignment() == SWT.RIGHT) { - handle = OS.gtk_file_chooser_dialog_new (titleBytes, shellHandle, OS.GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, OS.GTK_STOCK_CANCEL (), OS.GTK_RESPONSE_CANCEL, OS.GTK_STOCK_OK (), OS.GTK_RESPONSE_OK, 0); - } else { - handle = OS.gtk_file_chooser_dialog_new (titleBytes, shellHandle, OS.GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, OS.GTK_STOCK_OK (), OS.GTK_RESPONSE_OK, OS.GTK_STOCK_CANCEL (), OS.GTK_RESPONSE_CANCEL, 0); - } - OS.gtk_window_set_modal (handle, true); - int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle); - if (pixbufs != 0) { - OS.gtk_window_set_icon_list (handle, pixbufs); - OS.g_list_free (pixbufs); - } - if (filterPath != null && filterPath.length () > 0) { - StringBuffer stringBuffer = new StringBuffer (); - /* filename must be a full path */ - if (!filterPath.startsWith (SEPARATOR)) { - stringBuffer.append (SEPARATOR); - } - stringBuffer.append (filterPath); - byte [] buffer = Converter.wcsToMbcs (null, stringBuffer.toString (), true); - /* - * Bug in GTK. GtkFileChooser may crash on GTK versions 2.4.10 to 2.6 - * when setting a file name that is not a true canonical path. - * The fix is to use the canonical path. - */ - int /*long*/ ptr = OS.realpath (buffer, null); - if (ptr != 0) { - OS.gtk_file_chooser_set_current_folder (handle, ptr); - OS.g_free (ptr); - } - } - if (message.length () > 0) { - byte [] buffer = Converter.wcsToMbcs (null, message, true); - int /*long*/ box = OS.gtk_hbox_new (false, 0); - if (box == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ label = OS.gtk_label_new (buffer); - if (label == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (box, label); - OS.gtk_widget_show (label); - OS.gtk_label_set_line_wrap (label, true); - OS.gtk_label_set_justify (label, OS.GTK_JUSTIFY_CENTER); - OS.gtk_file_chooser_set_extra_widget (handle, box); - } - String answer = null; - display.addIdleProc (); - Dialog oldModal = null; - if (OS.gtk_window_get_modal (handle)) { - oldModal = display.getModalDialog (); - display.setModalDialog (this); - } - int signalId = 0; - int /*long*/ hookId = 0; - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET()); - hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0); - } - int response = OS.gtk_dialog_run (handle); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.g_signal_remove_emission_hook (signalId, hookId); - } - if (OS.gtk_window_get_modal (handle)) { - display.setModalDialog (oldModal); - } - if (response == OS.GTK_RESPONSE_OK) { - int /*long*/ path = OS.gtk_file_chooser_get_filename (handle); - if (path != 0) { - int /*long*/ utf8Ptr = OS.g_filename_to_utf8 (path, -1, null, null, null); - OS.g_free (path); - if (utf8Ptr != 0) { - int /*long*/ [] items_written = new int /*long*/ [1]; - int /*long*/ utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null); - OS.g_free (utf8Ptr); - if (utf16Ptr != 0) { - int clength = (int)/*64*/items_written [0]; - char [] chars = new char [clength]; - OS.memmove (chars, utf16Ptr, clength * 2); - OS.g_free (utf16Ptr); - answer = new String (chars); - filterPath = answer; - } - } - } - } - display.removeIdleProc (); - OS.gtk_widget_destroy (handle); - return answer; -} -String openClassicDialog () { - byte [] titleBytes = Converter.wcsToMbcs (null, title, true); - int /*long*/ handle = OS.gtk_file_selection_new (titleBytes); - if (parent != null) { - int /*long*/ shellHandle = parent.topHandle (); - OS.gtk_window_set_transient_for (handle, shellHandle); - int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle); - if (pixbufs != 0) { - OS.gtk_window_set_icon_list (handle, pixbufs); - OS.g_list_free (pixbufs); - } - } - OS.gtk_window_set_modal (handle, true); - String answer = null; - if (filterPath != null) { - String path = filterPath; - if (path.length () > 0 && !path.endsWith (SEPARATOR)) { - path += SEPARATOR; - } - int length = path.length (); - char [] buffer = new char [length + 1]; - path.getChars (0, length, buffer, 0); - int /*long*/ utf8Ptr = OS.g_utf16_to_utf8 (buffer, -1, null, null, null); - int /*long*/ fileNamePtr = OS.g_filename_from_utf8 (utf8Ptr, -1, null, null, null); - OS.gtk_file_selection_set_filename (handle, fileNamePtr); - OS.g_free (utf8Ptr); - OS.g_free (fileNamePtr); - } - GtkFileSelection selection = new GtkFileSelection (); - OS.memmove (selection, handle); - OS.gtk_file_selection_hide_fileop_buttons (handle); - int /*long*/ fileListParent = OS.gtk_widget_get_parent (selection.file_list); - OS.gtk_widget_hide (selection.file_list); - OS.gtk_widget_hide (fileListParent); - if (message.length () > 0) { - byte [] buffer = Converter.wcsToMbcs (null, message, true); - int /*long*/ labelHandle = OS.gtk_label_new (buffer); - OS.gtk_label_set_line_wrap (labelHandle, true); - OS.gtk_misc_set_alignment (labelHandle, 0.0f, 0.0f); - OS.gtk_container_add (selection.main_vbox, labelHandle); - OS.gtk_box_set_child_packing ( - selection.main_vbox, labelHandle, false, false, 0, OS.GTK_PACK_START); - OS.gtk_widget_show (labelHandle); - } - Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - display.addIdleProc (); - Dialog oldModal = null; - if (OS.gtk_window_get_modal (handle)) { - oldModal = display.getModalDialog (); - display.setModalDialog (this); - } - int signalId = 0; - int /*long*/ hookId = 0; - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET()); - hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0); - } - int response = OS.gtk_dialog_run (handle); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.g_signal_remove_emission_hook (signalId, hookId); - } - if (OS.gtk_window_get_modal (handle)) { - display.setModalDialog (oldModal); - } - if (response == OS.GTK_RESPONSE_OK) { - int /*long*/ fileNamePtr = OS.gtk_file_selection_get_filename (handle); - int /*long*/ utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, null, null); - if (utf8Ptr != 0) { - int /*long*/ [] items_written = new int /*long*/ [1]; - int /*long*/ utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null); - if (utf16Ptr != 0) { - int length = (int)/*64*/items_written [0]; - char [] buffer = new char [length]; - OS.memmove (buffer, utf16Ptr, length * 2); - String osAnswer = new String (buffer); - if (osAnswer != null) { - /* remove trailing separator, unless root directory */ - if (!osAnswer.equals (SEPARATOR) && osAnswer.endsWith (SEPARATOR)) { - osAnswer = osAnswer.substring (0, osAnswer.length () - 1); - } - answer = filterPath = osAnswer; - } - OS.g_free (utf16Ptr); - } - OS.g_free (utf8Ptr); - } - } - display.removeIdleProc (); - OS.gtk_widget_destroy (handle); - return answer; -} -/** - * Sets the path that the dialog will use to filter - * the directories it shows to the argument, which may - * be null. If the string is null, then the operating - * system's default filter path will be used. - *

    - * Note that the path string is platform dependent. - * For convenience, either '/' or '\' can be used - * as a path separator. - *

    - * - * @param string the filter path - */ -public void setFilterPath (String string) { - filterPath = string; -} -/** - * Sets the dialog's message, which is a description of - * the purpose for which it was opened. This message will be - * visible on the dialog while it is open. - * - * @param string the message - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the string is null
    • - *
    - */ -public void setMessage (String string) { - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - message = string; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java deleted file mode 100644 index 0e1945fe3e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ /dev/null @@ -1,4212 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class are responsible for managing the - * connection between SWT and the underlying operating - * system. Their most important function is to implement - * the SWT event loop in terms of the platform event model. - * They also provide various methods for accessing information - * about the operating system, and have overall control over - * the operating system resources which SWT allocates. - *

    - * Applications which are built with SWT will almost always - * require only a single display. In particular, some platforms - * which SWT supports will not allow more than one active - * display. In other words, some platforms do not support - * creating a new display if one already exists that has not been - * sent the dispose() message. - *

    - * In SWT, the thread which creates a Display - * instance is distinguished as the user-interface thread - * for that display. - *

    - * The user-interface thread for a particular display has the - * following special attributes: - *
      - *
    • - * The event loop for that display must be run from the thread. - *
    • - *
    • - * Some SWT API methods (notably, most of the public methods in - * Widget and its subclasses), may only be called - * from the thread. (To support multi-threaded user-interface - * applications, class Display provides inter-thread - * communication methods which allow threads other than the - * user-interface thread to request that it perform operations - * on their behalf.) - *
    • - *
    • - * The thread is not allowed to construct other - * Displays until that display has been disposed. - * (Note that, this is in addition to the restriction mentioned - * above concerning platform support for multiple displays. Thus, - * the only way to have multiple simultaneously active displays, - * even on platforms which support it, is to have multiple threads.) - *
    • - *
    - * Enforcing these attributes allows SWT to be implemented directly - * on the underlying operating system's event model. This has - * numerous benefits including smaller footprint, better use of - * resources, safer memory management, clearer program logic, - * better performance, and fewer overall operating system threads - * required. The down side however, is that care must be taken - * (only) when constructing multi-threaded applications to use the - * inter-thread communication mechanisms which this class provides - * when required. - *

    - * All SWT API methods which may only be called from the user-interface - * thread are distinguished in their documentation by indicating that - * they throw the "ERROR_THREAD_INVALID_ACCESS" - * SWT exception. - *

    - *
    - *
    Styles:
    - *
    (none)
    - *
    Events:
    - *
    Close, Dispose, Settings
    - *
    - *

    - * IMPORTANT: This class is not intended to be subclassed. - *

    - * @see #syncExec - * @see #asyncExec - * @see #wake - * @see #readAndDispatch - * @see #sleep - * @see Device#dispose - * @see Display snippets - * @see Sample code and further information - * @noextend This class is not intended to be subclassed by clients. - */ -public class Display extends Device { - - /* Events Dispatching and Callback */ - int gdkEventCount; - int /*long*/ [] gdkEvents; - Widget [] gdkEventWidgets; - int [] dispatchEvents; - Event [] eventQueue; - int /*long*/ fds; - int allocated_nfds; - boolean wake; - int [] max_priority = new int [1], timeout = new int [1]; - Callback eventCallback, filterCallback; - int /*long*/ eventProc, filterProc, windowProc2, windowProc3, windowProc4, windowProc5; - Callback windowCallback2, windowCallback3, windowCallback4, windowCallback5; - EventTable eventTable, filterTable; - static String APP_NAME = "SWT"; //$NON-NLS-1$ - static final String DISPATCH_EVENT_KEY = "org.eclipse.swt.internal.gtk.dispatchEvent"; //$NON-NLS-1$ - static final String ADD_WIDGET_KEY = "org.eclipse.swt.internal.addWidget"; //$NON-NLS-1$ - int /*long*/ [] closures; - int [] signalIds; - int /*long*/ shellMapProcClosure; - - /* Widget Table */ - int [] indexTable; - int freeSlot; - int /*long*/ lastHandle; - Widget lastWidget; - Widget [] widgetTable; - final static int GROW_SIZE = 1024; - static final int SWT_OBJECT_INDEX; - static final int SWT_OBJECT_INDEX1; - static final int SWT_OBJECT_INDEX2; - static { - byte [] buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX", true); //$NON-NLS-1$ - SWT_OBJECT_INDEX = OS.g_quark_from_string (buffer); - buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX1", true); //$NON-NLS-1$ - SWT_OBJECT_INDEX1 = OS.g_quark_from_string (buffer); - buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX2", true); //$NON-NLS-1$ - SWT_OBJECT_INDEX2 = OS.g_quark_from_string (buffer); - } - - /* Modality */ - Shell [] modalShells; - Dialog modalDialog; - static final String GET_MODAL_DIALOG = "org.eclipse.swt.internal.gtk.getModalDialog"; //$NON-NLS-1$ - static final String SET_MODAL_DIALOG = "org.eclipse.swt.internal.gtk.setModalDialog"; //$NON-NLS-1$ - - /* Focus */ - int focusEvent; - Control focusControl; - Shell activeShell; - boolean activePending; - boolean ignoreActivate, ignoreFocus; - - /* Input method resources */ - Control imControl; - int /*long*/ preeditWindow, preeditLabel; - - /* Sync/Async Widget Communication */ - Synchronizer synchronizer = new Synchronizer (this); - Thread thread; - - /* Display Shutdown */ - Runnable [] disposeList; - - /* System Tray */ - Tray tray; - - /* Timers */ - int [] timerIds; - Runnable [] timerList; - Callback timerCallback; - int /*long*/ timerProc; - Callback windowTimerCallback; - int /*long*/ windowTimerProc; - - /* Caret */ - Caret currentCaret; - Callback caretCallback; - int caretId; - int /*long*/ caretProc; - - /* Mnemonics */ - Control mnemonicControl; - - /* Mouse hover */ - int mouseHoverId; - int /*long*/ mouseHoverHandle, mouseHoverProc; - Callback mouseHoverCallback; - - /* Menu position callback */ - int /*long*/ menuPositionProc; - Callback menuPositionCallback; - - /* Tooltip size allocate callback */ - int /*long*/ sizeAllocateProc; - Callback sizeAllocateCallback; - int /*long*/ sizeRequestProc; - Callback sizeRequestCallback; - - /* Shell map callback */ - int /*long*/ shellMapProc; - Callback shellMapCallback; - - /* Idle proc callback */ - int /*long*/ idleProc; - int idleHandle; - Callback idleCallback; - static final String ADD_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk.addIdleProc"; //$NON-NLS-1$ - static final String REMOVE_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk.removeIdleProc"; //$NON-NLS-1$ - Object idleLock = new Object(); - boolean idleNeeded; - - /* GtkTreeView callbacks */ - int[] treeSelection; - int treeSelectionLength; - int /*long*/ treeSelectionProc; - Callback treeSelectionCallback; - int /*long*/ cellDataProc; - Callback cellDataCallback; - - /* Set direction callback */ - int /*long*/ setDirectionProc; - Callback setDirectionCallback; - static final String GET_DIRECTION_PROC_KEY = "org.eclipse.swt.internal.gtk.getDirectionProc"; //$NON-NLS-1$ - - /* Set emissionProc callback */ - int /*long*/ emissionProc; - Callback emissionProcCallback; - static final String GET_EMISSION_PROC_KEY = "org.eclipse.swt.internal.gtk.getEmissionProc"; //$NON-NLS-1$ - - /* Get all children callback */ - int /*long*/ allChildrenProc, allChildren; - Callback allChildrenCallback; - - /* Settings callbacks */ - int /*long*/ styleSetProc; - Callback styleSetCallback; - int /*long*/ shellHandle; - boolean settingsChanged, runSettings; - - /* Entry focus behaviour */ - boolean entrySelectOnFocus; - - /* Enter/Exit events */ - Control currentControl; - - /* Flush exposes */ - int /*long*/ checkIfEventProc; - Callback checkIfEventCallback; - int /*long*/ flushWindow; - boolean flushAll; - GdkRectangle flushRect = new GdkRectangle (); - XExposeEvent exposeEvent = new XExposeEvent (); - XVisibilityEvent visibilityEvent = new XVisibilityEvent (); - int /*long*/ [] flushData = new int /*long*/ [1]; - - /* System Resources */ - Font systemFont; - Image errorImage, infoImage, questionImage, warningImage; - Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1]; - Resource [] resources; - static final int RESOURCE_SIZE = 1 + 4 + SWT.CURSOR_HAND + 1; - - /* Colors */ - GdkColor COLOR_WIDGET_DARK_SHADOW, COLOR_WIDGET_NORMAL_SHADOW, COLOR_WIDGET_LIGHT_SHADOW; - GdkColor COLOR_WIDGET_HIGHLIGHT_SHADOW, COLOR_WIDGET_BACKGROUND, COLOR_WIDGET_FOREGROUND, COLOR_WIDGET_BORDER; - GdkColor COLOR_LIST_FOREGROUND, COLOR_LIST_BACKGROUND, COLOR_LIST_SELECTION, COLOR_LIST_SELECTION_TEXT; - GdkColor COLOR_INFO_BACKGROUND, COLOR_INFO_FOREGROUND; - GdkColor COLOR_TITLE_FOREGROUND, COLOR_TITLE_BACKGROUND, COLOR_TITLE_BACKGROUND_GRADIENT; - GdkColor COLOR_TITLE_INACTIVE_FOREGROUND, COLOR_TITLE_INACTIVE_BACKGROUND, COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT; - - /* Popup Menus */ - Menu [] popups; - - /* Click count*/ - int clickCount = 1; - - /* Entry inner border */ - static final int INNER_BORDER = 2; - - /* Timestamp of the Last Received Events */ - int lastEventTime, lastUserEventTime; - - /* Pango layout constructor */ - int /*long*/ pangoLayoutNewProc, pangoLayoutNewDefaultProc; - Callback pangoLayoutNewCallback; - - /* Fixed Subclass */ - static int /*long*/ fixed_type; - static int /*long*/ fixed_info_ptr; - static Callback fixedClassInitCallback, fixedMapCallback, fixedSizeAllocateCallback; - static int /*long*/ fixedClassInitProc, fixedMapProc, fixedSizeAllocateProc, oldFixedSizeAllocateProc; - - /* Renderer Subclass */ - static int /*long*/ text_renderer_type, pixbuf_renderer_type, toggle_renderer_type; - static int /*long*/ text_renderer_info_ptr, pixbuf_renderer_info_ptr, toggle_renderer_info_ptr; - static Callback rendererClassInitCallback, rendererRenderCallback, rendererGetSizeCallback; - static int /*long*/ rendererClassInitProc, rendererRenderProc, rendererGetSizeProc; - - /* Key Mappings */ - static final int [] [] KeyTable = { - - /* Keyboard and Mouse Masks */ - {OS.GDK_Alt_L, SWT.ALT}, - {OS.GDK_Alt_R, SWT.ALT}, - {OS.GDK_Meta_L, SWT.ALT}, - {OS.GDK_Meta_R, SWT.ALT}, - {OS.GDK_Shift_L, SWT.SHIFT}, - {OS.GDK_Shift_R, SWT.SHIFT}, - {OS.GDK_Control_L, SWT.CONTROL}, - {OS.GDK_Control_R, SWT.CONTROL}, -// {OS.GDK_????, SWT.COMMAND}, -// {OS.GDK_????, SWT.COMMAND}, - - /* Non-Numeric Keypad Keys */ - {OS.GDK_Up, SWT.ARROW_UP}, - {OS.GDK_KP_Up, SWT.ARROW_UP}, - {OS.GDK_Down, SWT.ARROW_DOWN}, - {OS.GDK_KP_Down, SWT.ARROW_DOWN}, - {OS.GDK_Left, SWT.ARROW_LEFT}, - {OS.GDK_KP_Left, SWT.ARROW_LEFT}, - {OS.GDK_Right, SWT.ARROW_RIGHT}, - {OS.GDK_KP_Right, SWT.ARROW_RIGHT}, - {OS.GDK_Page_Up, SWT.PAGE_UP}, - {OS.GDK_KP_Page_Up, SWT.PAGE_UP}, - {OS.GDK_Page_Down, SWT.PAGE_DOWN}, - {OS.GDK_KP_Page_Down, SWT.PAGE_DOWN}, - {OS.GDK_Home, SWT.HOME}, - {OS.GDK_KP_Home, SWT.HOME}, - {OS.GDK_End, SWT.END}, - {OS.GDK_KP_End, SWT.END}, - {OS.GDK_Insert, SWT.INSERT}, - {OS.GDK_KP_Insert, SWT.INSERT}, - - /* Virtual and Ascii Keys */ - {OS.GDK_BackSpace, SWT.BS}, - {OS.GDK_Return, SWT.CR}, - {OS.GDK_Delete, SWT.DEL}, - {OS.GDK_KP_Delete, SWT.DEL}, - {OS.GDK_Escape, SWT.ESC}, - {OS.GDK_Linefeed, SWT.LF}, - {OS.GDK_Tab, SWT.TAB}, - {OS.GDK_ISO_Left_Tab, SWT.TAB}, - - /* Functions Keys */ - {OS.GDK_F1, SWT.F1}, - {OS.GDK_F2, SWT.F2}, - {OS.GDK_F3, SWT.F3}, - {OS.GDK_F4, SWT.F4}, - {OS.GDK_F5, SWT.F5}, - {OS.GDK_F6, SWT.F6}, - {OS.GDK_F7, SWT.F7}, - {OS.GDK_F8, SWT.F8}, - {OS.GDK_F9, SWT.F9}, - {OS.GDK_F10, SWT.F10}, - {OS.GDK_F11, SWT.F11}, - {OS.GDK_F12, SWT.F12}, - {OS.GDK_F13, SWT.F13}, - {OS.GDK_F14, SWT.F14}, - {OS.GDK_F15, SWT.F15}, - - /* Numeric Keypad Keys */ - {OS.GDK_KP_Multiply, SWT.KEYPAD_MULTIPLY}, - {OS.GDK_KP_Add, SWT.KEYPAD_ADD}, - {OS.GDK_KP_Enter, SWT.KEYPAD_CR}, - {OS.GDK_KP_Subtract, SWT.KEYPAD_SUBTRACT}, - {OS.GDK_KP_Decimal, SWT.KEYPAD_DECIMAL}, - {OS.GDK_KP_Divide, SWT.KEYPAD_DIVIDE}, - {OS.GDK_KP_0, SWT.KEYPAD_0}, - {OS.GDK_KP_1, SWT.KEYPAD_1}, - {OS.GDK_KP_2, SWT.KEYPAD_2}, - {OS.GDK_KP_3, SWT.KEYPAD_3}, - {OS.GDK_KP_4, SWT.KEYPAD_4}, - {OS.GDK_KP_5, SWT.KEYPAD_5}, - {OS.GDK_KP_6, SWT.KEYPAD_6}, - {OS.GDK_KP_7, SWT.KEYPAD_7}, - {OS.GDK_KP_8, SWT.KEYPAD_8}, - {OS.GDK_KP_9, SWT.KEYPAD_9}, - {OS.GDK_KP_Equal, SWT.KEYPAD_EQUAL}, - - /* Other keys */ - {OS.GDK_Caps_Lock, SWT.CAPS_LOCK}, - {OS.GDK_Num_Lock, SWT.NUM_LOCK}, - {OS.GDK_Scroll_Lock, SWT.SCROLL_LOCK}, - {OS.GDK_Pause, SWT.PAUSE}, - {OS.GDK_Break, SWT.BREAK}, - {OS.GDK_Print, SWT.PRINT_SCREEN}, - {OS.GDK_Help, SWT.HELP}, - - }; - - /* Multiple Displays. */ - static Display Default; - static Display [] Displays = new Display [4]; - - /* Package name */ - static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$ - /* This code is intentionally commented. - * ".class" can not be used on CLDC. - */ -// static { -// String name = Display.class.getName (); -// int index = name.lastIndexOf ('.'); -// PACKAGE_NAME = name.substring (0, index + 1); -// } - - /* GTK Version */ - static final int MAJOR = 2; - static final int MINOR = 2; - static final int MICRO = 0; - - /* Display Data */ - Object data; - String [] keys; - Object [] values; - - /* Initial Guesses for Shell Trimmings. */ - int borderTrimWidth = 4, borderTrimHeight = 4; - int resizeTrimWidth = 6, resizeTrimHeight = 6; - int titleBorderTrimWidth = 5, titleBorderTrimHeight = 28; - int titleResizeTrimWidth = 6, titleResizeTrimHeight = 29; - int titleTrimWidth = 0, titleTrimHeight = 23; - boolean ignoreTrim; - - /* Window Manager */ - String windowManager; - - /* - * TEMPORARY CODE. Install the runnable that - * gets the current display. This code will - * be removed in the future. - */ - static { - DeviceFinder = new Runnable () { - public void run () { - Device device = getCurrent (); - if (device == null) { - device = getDefault (); - } - setDevice (device); - } - }; - } - -/* -* TEMPORARY CODE. -*/ -static void setDevice (Device device) { - CurrentDevice = device; -} - -/** - * Constructs a new instance of this class. - *

    - * Note: The resulting display is marked as the current - * display. If this is the first display which has been - * constructed since the application started, it is also - * marked as the default display. - *

    - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if called from a thread that already created an existing display
    • - *
    • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
    • - *
    - * - * @see #getCurrent - * @see #getDefault - * @see Widget#checkSubclass - * @see Shell - */ -public Display () { - this (null); -} - -/** - * Constructs a new instance of this class using the parameter. - * - * @param data the device data - */ -public Display (DeviceData data) { - super (data); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when an event of the given type occurs anywhere - * in a widget. The event type is one of the event constants - * defined in class SWT. When the event does occur, - * the listener is notified by sending it the handleEvent() - * message. - *

    - * Setting the type of an event to SWT.None from - * within the handleEvent() method can be used to - * change the event type and stop subsequent Java listeners - * from running. Because event filters run before other listeners, - * event filters can both block other listeners and set arbitrary - * fields within an event. For this reason, event filters are both - * powerful and dangerous. They should generally be avoided for - * performance, debugging and code maintenance reasons. - *

    - * - * @param eventType the type of event to listen for - * @param listener the listener which should be notified when the event occurs - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @see Listener - * @see SWT - * @see #removeFilter - * @see #removeListener - * - * @since 3.0 - */ -public void addFilter (int eventType, Listener listener) { - checkDevice (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (filterTable == null) filterTable = new EventTable (); - filterTable.hook (eventType, listener); -} - -void addGdkEvent (int /*long*/ event) { - if (gdkEvents == null) { - int length = GROW_SIZE; - gdkEvents = new int /*long*/ [length]; - gdkEventWidgets = new Widget [length]; - gdkEventCount = 0; - } - if (gdkEventCount == gdkEvents.length) { - int length = gdkEventCount + GROW_SIZE; - int /*long*/ [] newEvents = new int /*long*/ [length]; - System.arraycopy (gdkEvents, 0, newEvents, 0, gdkEventCount); - gdkEvents = newEvents; - Widget [] newWidgets = new Widget [length]; - System.arraycopy (gdkEventWidgets, 0, newWidgets, 0, gdkEventCount); - gdkEventWidgets = newWidgets; - } - Widget widget = null; - int /*long*/ handle = OS.gtk_get_event_widget (event); - if (handle != 0) { - do { - widget = getWidget (handle); - } while (widget == null && (handle = OS.gtk_widget_get_parent (handle)) != 0); - } - gdkEvents [gdkEventCount] = event; - gdkEventWidgets [gdkEventCount] = widget; - gdkEventCount++; -} - -void addIdleProc() { - synchronized (idleLock){ - this.idleNeeded = true; - if (idleHandle == 0) { - idleHandle = OS.g_idle_add (idleProc, 0); - } - } -} - -/** - * Adds the listener to 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. - * When the event does occur in the display, the listener is notified by - * sending it the handleEvent() message. - * - * @param eventType the type of event to listen for - * @param listener the listener which should be notified when the event occurs - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the listener is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @see Listener - * @see SWT - * @see #removeListener - * - * @since 2.0 - */ -public void addListener (int eventType, Listener listener) { - checkDevice (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) eventTable = new EventTable (); - eventTable.hook (eventType, listener); -} - -int /*long*/ allChildrenProc (int /*long*/ widget, int /*long*/ recurse) { - allChildren = OS.g_list_append (allChildren, widget); - if (recurse != 0 && OS.GTK_IS_CONTAINER (widget)) { - OS.gtk_container_forall (widget, allChildrenProc, recurse); - } - return 0; -} - -void addMouseHoverTimeout (int /*long*/ handle) { - if (mouseHoverId != 0) OS.gtk_timeout_remove (mouseHoverId); - mouseHoverId = OS.gtk_timeout_add (400, mouseHoverProc, handle); - mouseHoverHandle = handle; -} - -void addPopup (Menu menu) { - if (popups == null) popups = new Menu [4]; - int length = popups.length; - for (int i=0; irun() method of the runnable to - * be invoked by the user-interface thread at the next - * reasonable opportunity. The caller of this method continues - * to run in parallel, and is not notified when the - * runnable has completed. Specifying null as the - * runnable simply wakes the user-interface thread when run. - *

    - * Note that at the time the runnable is invoked, widgets - * that have the receiver as their display may have been - * disposed. Therefore, it is necessary to check for this - * case inside the runnable before accessing the widget. - *

    - * - * @param runnable code to run on the user-interface thread or null - * - * @exception SWTException
      - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @see #syncExec - */ -public void asyncExec (Runnable runnable) { - synchronized (Device.class) { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - synchronized (idleLock) { - if (idleNeeded && idleHandle == 0) { - //NOTE: calling unlocked function in OS - idleHandle = OS._g_idle_add (idleProc, 0); - } - } - synchronizer.asyncExec (runnable); - } -} - -/** - * Causes the system hardware to emit a short sound - * (if it supports this capability). - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public void beep () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - OS.gdk_beep(); - if (!OS.GDK_WINDOWING_X11 ()) { - OS.gdk_flush (); - } else { - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - OS.XFlush (xDisplay); - } -} - -int /*long*/ cellDataProc (int /*long*/ tree_column, int /*long*/ cell, int /*long*/ tree_model, int /*long*/ iter, int /*long*/ data) { - Widget widget = getWidget (data); - if (widget == null) return 0; - return widget.cellDataProc (tree_column, cell, tree_model, iter, data); -} - -protected void checkDevice () { - if (thread == null) error (SWT.ERROR_WIDGET_DISPOSED); - if (thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); -} - -static void checkDisplay (Thread thread, boolean multiple) { - synchronized (Device.class) { - for (int i=0; i - * IMPORTANT: See the comment in Widget.checkSubclass(). - *

    - * - * @exception SWTException
      - *
    • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
    • - *
    - * - * @see Widget#checkSubclass - */ -protected void checkSubclass () { - if (!isValidClass (getClass ())) error (SWT.ERROR_INVALID_SUBCLASS); -} - -void clearModal (Shell shell) { - if (modalShells == null) return; - int index = 0, length = modalShells.length; - while (index < length) { - if (modalShells [index] == shell) break; - if (modalShells [index] == null) return; - index++; - } - if (index == length) return; - System.arraycopy (modalShells, index + 1, modalShells, index, --length - index); - modalShells [length] = null; - if (index == 0 && modalShells [0] == null) modalShells = null; - Shell [] shells = getShells (); - for (int i=0; i - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
  • - * - * - * @see Device#dispose - * - * @since 2.0 - */ -public void close () { - checkDevice (); - Event event = new Event (); - sendEvent (SWT.Close, event); - if (event.doit) dispose (); -} - -/** - * Creates the device in the operating system. If the device - * does not have a handle, this method may do nothing depending - * on the device. - *

    - * This method is called before init. - *

    - * - * @param data the DeviceData which describes the receiver - * - * @see #init - */ -protected void create (DeviceData data) { - checkSubclass (); - checkDisplay(thread = Thread.currentThread (), false); - createDisplay (data); - register (this); - if (Default == null) Default = this; -} - -void createDisplay (DeviceData data) { - /* Required for g_main_context_wakeup */ - if (!OS.g_thread_supported ()) { - OS.g_thread_init (0); - } - OS.gtk_set_locale(); - if (!OS.gtk_init_check (new int /*long*/ [] {0}, null)) { - SWT.error (SWT.ERROR_NO_HANDLES, null, " [gtk_init_check() failed]"); //$NON-NLS-1$ - } - if (OS.GDK_WINDOWING_X11 ()) xDisplay = OS.GDK_DISPLAY (); - int /*long*/ ptr = OS.gtk_check_version (MAJOR, MINOR, MICRO); - if (ptr != 0) { - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - System.out.println ("***WARNING: " + new String (Converter.mbcsToWcs (null, buffer))); //$NON-NLS-1$ - System.out.println ("***WARNING: SWT requires GTK " + MAJOR+ "." + MINOR + "." + MICRO); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - int major = OS.gtk_major_version (), minor = OS.gtk_minor_version (), micro = OS.gtk_micro_version (); - System.out.println ("***WARNING: Detected: " + major + "." + minor + "." + micro); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - if (fixed_type == 0) { - byte [] type_name = Converter.wcsToMbcs (null, "SwtFixed", true); //$NON-NLS-1$ - fixedClassInitCallback = new Callback (getClass (), "fixedClassInitProc", 2); //$NON-NLS-1$ - fixedClassInitProc = fixedClassInitCallback.getAddress (); - if (fixedClassInitProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - fixedMapCallback = new Callback (getClass (), "fixedMapProc", 1); //$NON-NLS-1$ - fixedMapProc = fixedMapCallback.getAddress (); - if (fixedMapProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - fixedSizeAllocateCallback = new Callback (getClass (), "fixedSizeAllocateProc", 2); //$NON-NLS-1$ - fixedSizeAllocateProc = fixedSizeAllocateCallback.getAddress (); - if (fixedSizeAllocateProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - GTypeInfo fixed_info = new GTypeInfo (); - fixed_info.class_size = (short) OS.GtkFixedClass_sizeof (); - fixed_info.class_init = fixedClassInitProc; - fixed_info.instance_size = (short) OS.GtkFixed_sizeof (); - fixed_info_ptr = OS.g_malloc (GTypeInfo.sizeof); - OS.memmove (fixed_info_ptr, fixed_info, GTypeInfo.sizeof); - fixed_type = OS.g_type_register_static (OS.GTK_TYPE_FIXED (), type_name, fixed_info_ptr, 0); - } - if (rendererClassInitProc == 0) { - rendererClassInitCallback = new Callback (getClass (), "rendererClassInitProc", 2); //$NON-NLS-1$ - rendererClassInitProc = rendererClassInitCallback.getAddress (); - if (rendererClassInitProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - } - if (rendererRenderProc == 0) { - rendererRenderCallback = new Callback (getClass (), "rendererRenderProc", 7); //$NON-NLS-1$ - rendererRenderProc = rendererRenderCallback.getAddress (); - if (rendererRenderProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - } - if (rendererGetSizeProc == 0) { - rendererGetSizeCallback = new Callback (getClass (), "rendererGetSizeProc", 7); //$NON-NLS-1$ - rendererGetSizeProc = rendererGetSizeCallback.getAddress (); - if (rendererGetSizeProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - } - if (text_renderer_type == 0) { - GTypeInfo renderer_info = new GTypeInfo (); - renderer_info.class_size = (short) OS.GtkCellRendererTextClass_sizeof (); - renderer_info.class_init = rendererClassInitProc; - renderer_info.instance_size = (short) OS.GtkCellRendererText_sizeof (); - text_renderer_info_ptr = OS.g_malloc (GTypeInfo.sizeof); - OS.memmove (text_renderer_info_ptr, renderer_info, GTypeInfo.sizeof); - byte [] type_name = Converter.wcsToMbcs (null, "SwtTextRenderer", true); //$NON-NLS-1$ - text_renderer_type = OS.g_type_register_static (OS.GTK_TYPE_CELL_RENDERER_TEXT (), type_name, text_renderer_info_ptr, 0); - } - if (pixbuf_renderer_type == 0) { - GTypeInfo renderer_info = new GTypeInfo (); - renderer_info.class_size = (short) OS.GtkCellRendererPixbufClass_sizeof (); - renderer_info.class_init = rendererClassInitProc; - renderer_info.instance_size = (short) OS.GtkCellRendererPixbuf_sizeof (); - pixbuf_renderer_info_ptr = OS.g_malloc (GTypeInfo.sizeof); - OS.memmove (pixbuf_renderer_info_ptr, renderer_info, GTypeInfo.sizeof); - byte [] type_name = Converter.wcsToMbcs (null, "SwtPixbufRenderer", true); //$NON-NLS-1$ - pixbuf_renderer_type = OS.g_type_register_static (OS.GTK_TYPE_CELL_RENDERER_PIXBUF (), type_name, pixbuf_renderer_info_ptr, 0); - } - if (toggle_renderer_type == 0) { - GTypeInfo renderer_info = new GTypeInfo (); - renderer_info.class_size = (short) OS.GtkCellRendererToggleClass_sizeof (); - renderer_info.class_init = rendererClassInitProc; - renderer_info.instance_size = (short) OS.GtkCellRendererToggle_sizeof (); - toggle_renderer_info_ptr = OS.g_malloc (GTypeInfo.sizeof); - OS.memmove (toggle_renderer_info_ptr, renderer_info, GTypeInfo.sizeof); - byte [] type_name = Converter.wcsToMbcs (null, "SwtToggleRenderer", true); //$NON-NLS-1$ - toggle_renderer_type = OS.g_type_register_static (OS.GTK_TYPE_CELL_RENDERER_TOGGLE (), type_name, toggle_renderer_info_ptr, 0); - } - - OS.gtk_widget_set_default_direction (OS.GTK_TEXT_DIR_LTR); - OS.gdk_rgb_init (); - byte [] buffer = Converter.wcsToMbcs (null, APP_NAME, true); - OS.g_set_prgname (buffer); - OS.gdk_set_program_class (buffer); - byte [] flatStyle = Converter.wcsToMbcs (null, "style \"swt-flat\" { GtkToolbar::shadow-type = none } widget \"*.swt-toolbar-flat\" style : highest \"swt-flat\"", true); //$NON-NLS-1$ - OS.gtk_rc_parse_string (flatStyle); - - /* Initialize the hidden shell */ - shellHandle = OS.gtk_window_new (OS.GTK_WINDOW_TOPLEVEL); - if (shellHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gtk_widget_realize (shellHandle); - - /* Initialize the filter and event callback */ - eventCallback = new Callback (this, "eventProc", 2); //$NON-NLS-1$ - eventProc = eventCallback.getAddress (); - if (eventProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - OS.gdk_event_handler_set (eventProc, 0, 0); - filterCallback = new Callback (this, "filterProc", 3); //$NON-NLS-1$ - filterProc = filterCallback.getAddress (); - if (filterProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - OS.gdk_window_add_filter (0, filterProc, 0); -} - -Image createImage (String name) { - int /*long*/ style = OS.gtk_widget_get_default_style (); - byte[] buffer = Converter.wcsToMbcs (null, name, true); - int /*long*/ pixbuf = OS.gtk_icon_set_render_icon ( - OS.gtk_icon_factory_lookup_default (buffer), style, - OS.GTK_TEXT_DIR_NONE, OS.GTK_STATE_NORMAL, OS.GTK_ICON_SIZE_DIALOG, 0, 0); - if (pixbuf == 0) return null; - int width = OS.gdk_pixbuf_get_width (pixbuf); - int height = OS.gdk_pixbuf_get_height (pixbuf); - int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); - boolean hasAlpha = OS.gdk_pixbuf_get_has_alpha (pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); - byte [] data = new byte [stride * height]; - OS.memmove (data, pixels, data.length); - OS.g_object_unref (pixbuf); - ImageData imageData = null; - if (hasAlpha) { - PaletteData palette = new PaletteData (0xFF000000, 0xFF0000, 0xFF00); - imageData = new ImageData (width, height, 32, palette); - byte [] alpha = new byte [stride * height]; - for (int y=0; y - * This method is called after release. - *

    - * @see Device#dispose - * @see #release - */ -protected void destroy () { - if (this == Default) Default = null; - deregister (this); - destroyDisplay (); -} - -void destroyDisplay () { -} - -int /*long*/ emissionProc (int /*long*/ ihint, int /*long*/ n_param_values, int /*long*/ param_values, int /*long*/ data) { - if (OS.gtk_widget_get_toplevel (OS.g_value_peek_pointer(param_values)) == data) { - OS.gtk_widget_set_direction (OS.g_value_peek_pointer(param_values), OS.GTK_TEXT_DIR_RTL); - } - return 1; -} - -/** - * Returns the display which the given thread is the - * user-interface thread for, or null if the given thread - * is not a user-interface thread for any display. Specifying - * null as the thread will return null - * for the display. - * - * @param thread the user-interface thread - * @return the display for the given thread - */ -public static Display findDisplay (Thread thread) { - synchronized (Device.class) { - for (int i=0; irun() method of the runnable to - * be invoked by the user-interface thread just before the - * receiver is disposed. Specifying a null runnable - * is ignored. - * - * @param runnable code to run at dispose time. - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public void disposeExec (Runnable runnable) { - checkDevice (); - if (disposeList == null) disposeList = new Runnable [4]; - for (int i=0; iSWTError.error to handle the error. - * - * @param code the descriptive error code - * - * @see SWTError#error - */ -void error (int code) { - SWT.error (code); -} - -int /*long*/ eventProc (int /*long*/ event, int /*long*/ data) { - /* - * Use gdk_event_get_time() rather than event.time or - * gtk_get_current_event_time(). If the event does not - * have a time stamp, then the field will contain garbage. - * Note that calling gtk_get_current_event_time() from - * outside of gtk_main_do_event() seems to always - * return zero. - */ - int time = OS.gdk_event_get_time (event); - if (time != 0) lastEventTime = time; - - int eventType = OS.GDK_EVENT_TYPE (event); - switch (eventType) { - case OS.GDK_BUTTON_PRESS: - case OS.GDK_KEY_PRESS: - lastUserEventTime = time; - } - boolean dispatch = true; - if (dispatchEvents != null) { - dispatch = false; - for (int i = 0; i < dispatchEvents.length; i++) { - if (eventType == dispatchEvents [i]) { - dispatch = true; - break; - } - } - } - if (!dispatch) { - addGdkEvent (OS.gdk_event_copy (event)); - return 0; - } - OS.gtk_main_do_event (event); - if (dispatchEvents == null) putGdkEvents (); - return 0; -} - -/** - * Given the operating system handle for a widget, returns - * the instance of the Widget subclass which - * represents it in the currently running application, if - * such exists, or null if no matching widget can be found. - *

    - * IMPORTANT: This method should not be called from - * application code. The arguments are platform-specific. - *

    - * - * @param handle the handle for the widget - * @return the SWT widget that the handle represents - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public Widget findWidget (int /*long*/ handle) { - checkDevice (); - return getWidget (handle); -} - -/** - * Given the operating system handle for a widget, - * and widget-specific id, returns the instance of - * the Widget subclass which represents - * the handle/id pair in the currently running application, - * if such exists, or null if no matching widget can be found. - *

    - * IMPORTANT: This method should not be called from - * application code. The arguments are platform-specific. - *

    - * - * @param handle the handle for the widget - * @param id the id for the subwidget (usually an item) - * @return the SWT widget that the handle/id pair represents - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @since 3.1 - */ -public Widget findWidget (int /*long*/ handle, int /*long*/ id) { - checkDevice (); - return null; -} - -/** - * Given a widget and a widget-specific id, returns the - * instance of the Widget subclass which represents - * the widget/id pair in the currently running application, - * if such exists, or null if no matching widget can be found. - * - * @param widget the widget - * @param id the id for the subwidget (usually an item) - * @return the SWT subwidget (usually an item) that the widget/id pair represents - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @since 3.3 - */ -public Widget findWidget (Widget widget, int /*long*/ id) { - checkDevice (); - return null; -} - -static int /*long*/ fixedClassInitProc (int /*long*/ g_class, int /*long*/ class_data) { - GtkWidgetClass klass = new GtkWidgetClass (); - OS.memmove (klass, g_class); - klass.map = fixedMapProc; - oldFixedSizeAllocateProc = klass.size_allocate; - klass.size_allocate = fixedSizeAllocateProc; - OS.memmove (g_class, klass); - return 0; -} - -static int /*long*/ fixedMapProc (int /*long*/ handle) { - Display display = getCurrent (); - Widget widget = display.getWidget (handle); - if (widget != null) return widget.fixedMapProc (handle); - return 0; -} - -static int /*long*/ fixedSizeAllocateProc (int /*long*/ handle, int /*long*/ allocation) { - Display display = getCurrent (); - Widget widget = display.getWidget (handle); - if (widget != null) return widget.fixedSizeAllocateProc (handle, allocation); - return OS.Call (oldFixedSizeAllocateProc, handle, allocation); -} - -static int /*long*/ rendererClassInitProc (int /*long*/ g_class, int /*long*/ class_data) { - GtkCellRendererClass klass = new GtkCellRendererClass (); - OS.memmove (klass, g_class); - klass.render = rendererRenderProc; - klass.get_size = rendererGetSizeProc; - OS.memmove (g_class, klass); - return 0; -} - -static int /*long*/ rendererGetSizeProc (int /*long*/ cell, int /*long*/ handle, int /*long*/ cell_area, int /*long*/ x_offset, int /*long*/ y_offset, int /*long*/ width, int /*long*/ height) { - Display display = getCurrent (); - Widget widget = display.getWidget (handle); - if (widget != null) return widget.rendererGetSizeProc (cell, handle, cell_area, x_offset, y_offset, width, height); - return 0; -} - -static int /*long*/ rendererRenderProc (int /*long*/ cell, int /*long*/ window, int /*long*/ handle, int /*long*/ background_area, int /*long*/ cell_area, int /*long*/ expose_area, int /*long*/ flags) { - Display display = getCurrent (); - Widget widget = display.getWidget (handle); - if (widget != null) return widget.rendererRenderProc (cell, window, handle, background_area, cell_area, expose_area, flags); - return 0; -} - -void flushExposes (int /*long*/ window, boolean all) { - OS.gdk_flush (); - OS.gdk_flush (); - if (OS.GDK_WINDOWING_X11 ()) { - this.flushWindow = window; - this.flushAll = all; - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - int /*long*/ xEvent = OS.g_malloc (XEvent.sizeof); - OS.XCheckIfEvent (xDisplay, xEvent, checkIfEventProc, 0); - OS.g_free (xEvent); - this.flushWindow = 0; - } -} - -/** - * Returns the currently active Shell, or null - * if no shell belonging to the currently running application - * is active. - * - * @return the active shell or null - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public Shell getActiveShell () { - checkDevice (); - return activeShell; -} - -/** - * Returns a rectangle describing the receiver's size and location. Note that - * on multi-monitor systems the origin can be negative. - * - * @return the bounding rectangle - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public Rectangle getBounds () { - checkDevice (); - return new Rectangle (0, 0, OS.gdk_screen_width (), OS.gdk_screen_height ()); -} - -/** - * Returns the display which the currently running thread is - * the user-interface thread for, or null if the currently - * running thread is not a user-interface thread for any display. - * - * @return the current display - */ -public static Display getCurrent () { - return findDisplay (Thread.currentThread ()); -} - -int getCaretBlinkTime () { -// checkDevice (); - int /*long*/ settings = OS.gtk_settings_get_default (); - if (settings == 0) return 500; - int [] buffer = new int [1]; - OS.g_object_get (settings, OS.gtk_cursor_blink, buffer, 0); - if (buffer [0] == 0) return 0; - OS.g_object_get (settings, OS.gtk_cursor_blink_time, buffer, 0); - if (buffer [0] == 0) return 500; - /* - * By experimentation, GTK application don't use the whole - * blink cycle time. Instead, they divide up the time, using - * an effective blink rate of about 1/2 the total time. - */ - return buffer [0] / 2; -} - -/** - * Returns the control which the on-screen pointer is currently - * over top of, or null if it is not currently over one of the - * controls built by the currently running application. - * - * @return the control under the cursor - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public Control getCursorControl () { - checkDevice(); - int[] x = new int[1], y = new int[1]; - int /*long*/ handle = 0; - int /*long*/ [] user_data = new int /*long*/ [1]; - int /*long*/ window = OS.gdk_window_at_pointer (x,y); - if (window != 0) { - OS.gdk_window_get_user_data (window, user_data); - handle = user_data [0]; - } else { - /* - * Feature in GTK. gdk_window_at_pointer() will not return a window - * if the pointer is over a foreign embedded window. The fix is to use - * XQueryPointer to find the containing GDK window. - */ - if (!OS.GDK_WINDOWING_X11 ()) return null; - OS.gdk_error_trap_push (); - int[] unusedInt = new int[1]; - int /*long*/[] unusedPtr = new int /*long*/[1], buffer = new int /*long*/[1]; - int /*long*/ xWindow, xParent = OS.XDefaultRootWindow (xDisplay); - do { - if (OS.XQueryPointer (xDisplay, xParent, unusedPtr, buffer, unusedInt, unusedInt, unusedInt, unusedInt, unusedInt) == 0) { - handle = 0; - break; - } - if ((xWindow = buffer [0]) != 0) { - xParent = xWindow; - int /*long*/ gdkWindow = OS.gdk_window_lookup (xWindow); - if (gdkWindow != 0) { - OS.gdk_window_get_user_data (gdkWindow, user_data); - if (user_data[0] != 0) handle = user_data[0]; - } - } - } while (xWindow != 0); - OS.gdk_error_trap_pop (); - } - if (handle == 0) return null; - do { - Widget widget = getWidget (handle); - if (widget != null && widget instanceof Control) { - Control control = (Control) widget; - if (control.isEnabled ()) return control; - } - } while ((handle = OS.gtk_widget_get_parent (handle)) != 0); - return null; -} - -static GtkBorder getEntryInnerBorder (int /*long*/ handle) { - GtkBorder gtkBorder = new GtkBorder(); - if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - int /*long*/ border = OS.gtk_entry_get_inner_border (handle); - if (border != 0) { - OS.memmove (gtkBorder, border, GtkBorder.sizeof); - return gtkBorder; - } - int /*long*/ [] borderPtr = new int /*long*/ [1]; - OS.gtk_widget_style_get (handle, OS.inner_border, borderPtr,0); - if (borderPtr[0] != 0) { - OS.memmove (gtkBorder, borderPtr[0], GtkBorder.sizeof); - OS.gtk_border_free(borderPtr[0]); - return gtkBorder; - } - } - gtkBorder.left = INNER_BORDER; - gtkBorder.top = INNER_BORDER; - gtkBorder.right = INNER_BORDER; - gtkBorder.bottom = INNER_BORDER; - return gtkBorder; -} - -boolean filterEvent (Event event) { - if (filterTable != null) filterTable.sendEvent (event); - return false; -} - -boolean filters (int eventType) { - if (filterTable == null) return false; - return filterTable.hooks (eventType); -} - -int /*long*/ filterProc (int /*long*/ xEvent, int /*long*/ gdkEvent, int /*long*/ data) { - if (data == 0) { - /* - * Feature in GTK. When button 4, 5, 6, or 7 is released, GTK - * does not deliver a corresponding GTK event. Button 6 and 7 - * are mapped to buttons 4 and 5 in SWT. The fix is to change - * the button number of the event to a negative number so that - * it gets dispatched by GTK. SWT has been modified to look - * for negative button numbers. - */ - XButtonEvent mouseEvent = new XButtonEvent (); - OS.memmove (mouseEvent, xEvent, 4); - if (mouseEvent.type == OS.ButtonRelease) { - OS.memmove (mouseEvent, xEvent, XButtonEvent.sizeof); - switch (mouseEvent.button) { - case 6: - case 7: - mouseEvent.button = -mouseEvent.button; - OS.memmove (xEvent, mouseEvent, XButtonEvent.sizeof); - break; - } - } - } - Widget widget = getWidget (data); - if (widget == null) return 0; - return widget.filterProc (xEvent, gdkEvent, data); -} - -/** - * Returns the location of the on-screen pointer relative - * to the top left corner of the screen. - * - * @return the cursor location - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public Point getCursorLocation () { - checkDevice (); - int [] x = new int [1], y = new int [1]; - OS.gdk_window_get_pointer (0, x, y, null); - return new Point (x [0], y [0]); -} - -/** - * Returns an array containing the recommended cursor sizes. - * - * @return the array of cursor sizes - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @since 3.0 - */ -public Point [] getCursorSizes () { - checkDevice (); - return new Point [] {new Point (16, 16), new Point (32, 32)}; -} - -/** - * 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 display is disposed - * of, it is the application's responsibility to provide a - * disposeExec() handler which does so. - *

    - * - * @param key the name of the property - * @return the value of the property or null if it has not been set - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the key is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @see #setData(String, Object) - * @see #disposeExec(Runnable) - */ -public Object getData (String key) { - checkDevice (); - if (key == null) error (SWT.ERROR_NULL_ARGUMENT); - if (key.equals (DISPATCH_EVENT_KEY)) { - return dispatchEvents; - } - if (key.equals (GET_MODAL_DIALOG)) { - return modalDialog; - } - if (key.equals (GET_DIRECTION_PROC_KEY)) { - return new LONG (setDirectionProc); - } - if (key.equals (GET_EMISSION_PROC_KEY)) { - return new LONG (emissionProc); - } - if (keys == null) return null; - for (int i=0; idisplay specific data is a single, - * unnamed field that is stored with every display. - *

    - * Applications may put arbitrary objects in this field. If - * the object stored in the display specific data needs to - * be notified when the display is disposed of, it is the - * application's responsibility to provide a - * disposeExec() handler which does so. - *

    - * - * @return the display specific data - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @see #setData(Object) - * @see #disposeExec(Runnable) - */ -public Object getData () { - checkDevice (); - return data; -} - -/** - * Returns a point whose x coordinate is the horizontal - * dots per inch of the display, and whose y coordinate - * is the vertical dots per inch of the display. - * - * @return the horizontal and vertical DPI - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    - */ -public Point getDPI () { - checkDevice (); - int widthMM = OS.gdk_screen_width_mm (); - int width = OS.gdk_screen_width (); - int dpi = Compatibility.round (254 * width, widthMM * 10); - return new Point (dpi, dpi); -} - -int /*long*/ gtk_fixed_get_type () { - return fixed_type; -} - -int /*long*/ gtk_cell_renderer_text_get_type () { - return text_renderer_type; -} - -int /*long*/ gtk_cell_renderer_pixbuf_get_type () { - return pixbuf_renderer_type; -} - -int /*long*/ gtk_cell_renderer_toggle_get_type () { - return toggle_renderer_type; -} - -/** - * Returns the default display. One is created (making the - * thread that invokes this method its user-interface thread) - * if it did not already exist. - * - * @return the default display - */ -public static Display getDefault () { - synchronized (Device.class) { - if (Default == null) Default = new Display (); - return Default; - } -} - -static boolean isValidClass (Class clazz) { - String name = clazz.getName (); - int index = name.lastIndexOf ('.'); - return name.substring (0, index + 1).equals (PACKAGE_PREFIX); -} - -/** - * Returns the button dismissal alignment, one of LEFT or RIGHT. - * The button dismissal alignment is the ordering that should be used when positioning the - * default dismissal button for a dialog. For example, in a dialog that contains an OK and - * CANCEL button, on platforms where the button dismissal alignment is LEFT, the - * button ordering should be OK/CANCEL. When button dismissal alignment is RIGHT, - * the button ordering should be CANCEL/OK. - * - * @return the button dismissal order - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @since 2.1 - */ -public int getDismissalAlignment () { - checkDevice (); - int [] buffer = new int [1]; - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) { - int /*long*/ settings = OS.gtk_settings_get_default (); - OS.g_object_get (settings, OS.gtk_alternative_button_order, buffer, 0); - } - return buffer [0] == 1 ? SWT.LEFT : SWT.RIGHT; -} - -/** - * Returns the longest duration, in milliseconds, between - * two mouse button clicks that will be considered a - * double click by the underlying operating system. - * - * @return the double click time - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public int getDoubleClickTime () { - checkDevice (); - int /*long*/ settings = OS.gtk_settings_get_default (); - int [] buffer = new int [1]; - OS.g_object_get (settings, OS.gtk_double_click_time, buffer, 0); - return buffer [0]; -} - -/** - * Returns the control which currently has keyboard focus, - * or null if keyboard events are not currently going to - * any of the controls built by the currently running - * application. - * - * @return the control under the cursor - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public Control getFocusControl () { - checkDevice (); - if (focusControl != null && !focusControl.isDisposed ()) { - return focusControl; - } - if (activeShell == null) return null; - int /*long*/ shellHandle = activeShell.shellHandle; - int /*long*/ handle = OS.gtk_window_get_focus (shellHandle); - if (handle == 0) return null; - do { - Widget widget = getWidget (handle); - if (widget != null && widget instanceof Control) { - Control control = (Control) widget; - return control.isEnabled () ? control : null; - } - } while ((handle = OS.gtk_widget_get_parent (handle)) != 0); - return null; -} - -/** - * Returns true when the high contrast mode is enabled. - * Otherwise, false is returned. - *

    - * Note: This operation is a hint and is not supported on - * platforms that do not have this concept. - *

    - * - * @return the high contrast mode - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @since 3.0 - */ -public boolean getHighContrast () { - checkDevice (); - return false; -} - -public int getDepth () { - checkDevice (); - GdkVisual visual = new GdkVisual (); - OS.memmove (visual, OS.gdk_visual_get_system()); - return visual.depth; -} - -/** - * Returns the maximum allowed depth of icons on this display, in bits per pixel. - * On some platforms, this may be different than the actual depth of the display. - * - * @return the maximum icon depth - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @see Device#getDepth - */ -public int getIconDepth () { - checkDevice (); - return getDepth (); -} - -/** - * Returns an array containing the recommended icon sizes. - * - * @return the array of icon sizes - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @see Decorations#setImages(Image[]) - * - * @since 3.0 - */ -public Point [] getIconSizes () { - checkDevice (); - return new Point [] {new Point (16, 16), new Point (32, 32)}; -} - -int getLastEventTime () { - return lastEventTime; -} - -int getMessageCount () { - return synchronizer.getMessageCount (); -} - -Dialog getModalDialog () { - return modalDialog; -} - -/** - * Returns the work area, an EWMH property to store the size - * and position of the screen not covered by dock and panel - * windows. See http://freedesktop.org/Standards/wm-spec. - */ -Rectangle getWorkArea() { - byte[] name = Converter.wcsToMbcs (null, "_NET_WORKAREA", true); //$NON-NLS-1$ - int /*long*/ atom = OS.gdk_atom_intern (name, true); - if (atom == OS.GDK_NONE) return null; - int /*long*/[] actualType = new int /*long*/[1]; - int[] actualFormat = new int[1]; - int[] actualLength = new int[1]; - int /*long*/[] data = new int /*long*/[1]; - if (!OS.gdk_property_get (OS.GDK_ROOT_PARENT (), atom, OS.GDK_NONE, 0, 16, 0, actualType, actualFormat, actualLength, data)) { - return null; - } - Rectangle result = null; - if (data [0] != 0) { - if (actualLength [0] == 16) { - int values [] = new int [4]; - OS.memmove (values, data[0], 16); - result = new Rectangle (values [0],values [1],values [2],values [3]); - } else if (actualLength [0] == 32) { - long values [] = new long [4]; - OS.memmove (values, data[0], 32); - result = new Rectangle ((int)values [0],(int)values [1],(int)values [2],(int)values [3]); - } - OS.g_free (data [0]); - } - return result; -} - -/** - * Returns an array of monitors attached to the device. - * - * @return the array of monitors - * - * @since 3.0 - */ -public Monitor [] getMonitors () { - checkDevice (); - Monitor [] monitors = null; - Rectangle workArea = getWorkArea(); - int /*long*/ screen = OS.gdk_screen_get_default (); - if (screen != 0) { - int monitorCount = OS.gdk_screen_get_n_monitors (screen); - if (monitorCount > 0) { - monitors = new Monitor [monitorCount]; - GdkRectangle dest = new GdkRectangle (); - for (int i = 0; i < monitorCount; i++) { - OS.gdk_screen_get_monitor_geometry (screen, i, dest); - Monitor monitor = new Monitor (); - monitor.handle = i; - monitor.x = dest.x; - monitor.y = dest.y; - monitor.width = dest.width; - monitor.height = dest.height; - if (i == 0 && workArea != null) { - monitor.clientX = workArea.x; - monitor.clientY = workArea.y; - monitor.clientWidth = workArea.width; - monitor.clientHeight = workArea.height; - } else { - monitor.clientX = monitor.x; - monitor.clientY = monitor.y; - monitor.clientWidth = monitor.width; - monitor.clientHeight = monitor.height; - } - monitors [i] = monitor; - } - } - } - if (monitors == null) { - /* No multimonitor support detected, default to one monitor */ - Monitor monitor = new Monitor (); - Rectangle bounds = getBounds (); - monitor.x = bounds.x; - monitor.y = bounds.y; - monitor.width = bounds.width; - monitor.height = bounds.height; - if (workArea != null) { - monitor.clientX = workArea.x; - monitor.clientY = workArea.y; - monitor.clientWidth = workArea.width; - monitor.clientHeight = workArea.height; - } else { - monitor.clientX = monitor.x; - monitor.clientY = monitor.y; - monitor.clientWidth = monitor.width; - monitor.clientHeight = monitor.height; - } - monitors = new Monitor [] { monitor }; - } - return monitors; -} - -/** - * Returns the primary monitor for that device. - * - * @return the primary monitor - * - * @since 3.0 - */ -public Monitor getPrimaryMonitor () { - checkDevice (); - Monitor [] monitors = getMonitors (); - return monitors [0]; -} - -/** - * Returns a (possibly empty) array containing all shells which have - * not been disposed and have the receiver as their display. - * - * @return the receiver's shells - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public Shell [] getShells () { - checkDevice (); - int index = 0; - Shell [] result = new Shell [16]; - for (int i = 0; i < widgetTable.length; i++) { - Widget widget = widgetTable [i]; - if (widget != null && widget instanceof Shell) { - int j = 0; - while (j < index) { - if (result [j] == widget) break; - j++; - } - if (j == index) { - if (index == result.length) { - Shell [] newResult = new Shell [index + 16]; - System.arraycopy (result, 0, newResult, 0, index); - result = newResult; - } - result [index++] = (Shell) widget; - } - } - } - if (index == result.length) return result; - Shell [] newResult = new Shell [index]; - System.arraycopy (result, 0, newResult, 0, index); - return newResult; -} - -/** - * Gets the synchronizer used by the display. - * - * @return the receiver's synchronizer - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @since 3.4 - */ -public Synchronizer getSynchronizer () { - checkDevice (); - return synchronizer; -} - -/** - * Returns the thread that has invoked syncExec - * or null if no such runnable is currently being invoked by - * the user-interface thread. - *

    - * Note: If a runnable invoked by asyncExec is currently - * running, this method will return null. - *

    - * - * @return the receiver's sync-interface thread - * - * @exception SWTException
      - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public Thread getSyncThread () { - synchronized (Device.class) { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - return synchronizer.syncThread; - } -} - -/** - * Returns the matching standard color for the given - * constant, which should be one of the color constants - * specified in class SWT. Any value other - * than one of the SWT color constants which is passed - * in will result in the color black. This color should - * not be free'd because it was allocated by the system, - * not the application. - * - * @param id the color constant - * @return the matching color - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @see SWT - */ -public Color getSystemColor (int id) { - checkDevice (); - GdkColor gdkColor = null; - switch (id) { - case SWT.COLOR_INFO_FOREGROUND: gdkColor = COLOR_INFO_FOREGROUND; break; - case SWT.COLOR_INFO_BACKGROUND: gdkColor = COLOR_INFO_BACKGROUND; break; - case SWT.COLOR_TITLE_FOREGROUND: gdkColor = COLOR_TITLE_FOREGROUND; break; - case SWT.COLOR_TITLE_BACKGROUND: gdkColor = COLOR_TITLE_BACKGROUND; break; - case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: gdkColor = COLOR_TITLE_BACKGROUND_GRADIENT; break; - case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: gdkColor = COLOR_TITLE_INACTIVE_FOREGROUND; break; - case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: gdkColor = COLOR_TITLE_INACTIVE_BACKGROUND; break; - case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: gdkColor = COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT; break; - case SWT.COLOR_WIDGET_DARK_SHADOW: gdkColor = COLOR_WIDGET_DARK_SHADOW; break; - case SWT.COLOR_WIDGET_NORMAL_SHADOW: gdkColor = COLOR_WIDGET_NORMAL_SHADOW; break; - case SWT.COLOR_WIDGET_LIGHT_SHADOW: gdkColor = COLOR_WIDGET_LIGHT_SHADOW; break; - case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: gdkColor = COLOR_WIDGET_HIGHLIGHT_SHADOW; break; - case SWT.COLOR_WIDGET_BACKGROUND: gdkColor = COLOR_WIDGET_BACKGROUND; break; - case SWT.COLOR_WIDGET_FOREGROUND: gdkColor = COLOR_WIDGET_FOREGROUND; break; - case SWT.COLOR_WIDGET_BORDER: gdkColor = COLOR_WIDGET_BORDER; break; - case SWT.COLOR_LIST_FOREGROUND: gdkColor = COLOR_LIST_FOREGROUND; break; - case SWT.COLOR_LIST_BACKGROUND: gdkColor = COLOR_LIST_BACKGROUND; break; - case SWT.COLOR_LIST_SELECTION: gdkColor = COLOR_LIST_SELECTION; break; - case SWT.COLOR_LIST_SELECTION_TEXT: gdkColor = COLOR_LIST_SELECTION_TEXT; break; - default: - return super.getSystemColor (id); - } - if (gdkColor == null) return super.getSystemColor (SWT.COLOR_BLACK); - return Color.gtk_new (this, gdkColor); -} - -/** - * Returns the matching standard platform cursor for the given - * constant, which should be one of the cursor constants - * specified in class SWT. This cursor should - * not be free'd because it was allocated by the system, - * not the application. A value of null will - * be returned if the supplied constant is not an SWT cursor - * constant. - * - * @param id the SWT cursor constant - * @return the corresponding cursor or null - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @see SWT#CURSOR_ARROW - * @see SWT#CURSOR_WAIT - * @see SWT#CURSOR_CROSS - * @see SWT#CURSOR_APPSTARTING - * @see SWT#CURSOR_HELP - * @see SWT#CURSOR_SIZEALL - * @see SWT#CURSOR_SIZENESW - * @see SWT#CURSOR_SIZENS - * @see SWT#CURSOR_SIZENWSE - * @see SWT#CURSOR_SIZEWE - * @see SWT#CURSOR_SIZEN - * @see SWT#CURSOR_SIZES - * @see SWT#CURSOR_SIZEE - * @see SWT#CURSOR_SIZEW - * @see SWT#CURSOR_SIZENE - * @see SWT#CURSOR_SIZESE - * @see SWT#CURSOR_SIZESW - * @see SWT#CURSOR_SIZENW - * @see SWT#CURSOR_UPARROW - * @see SWT#CURSOR_IBEAM - * @see SWT#CURSOR_NO - * @see SWT#CURSOR_HAND - * - * @since 3.0 - */ -public Cursor getSystemCursor (int id) { - checkDevice (); - if (!(0 <= id && id < cursors.length)) return null; - if (cursors [id] == null) { - cursors [id] = new Cursor (this, id); - } - return cursors [id]; -} - -/** - * Returns the matching standard platform image for the given - * constant, which should be one of the icon constants - * specified in class SWT. This image should - * not be free'd because it was allocated by the system, - * not the application. A value of null will - * be returned either if the supplied constant is not an - * SWT icon constant or if the platform does not define an - * image that corresponds to the constant. - * - * @param id the SWT icon constant - * @return the corresponding image or null - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @see SWT#ICON_ERROR - * @see SWT#ICON_INFORMATION - * @see SWT#ICON_QUESTION - * @see SWT#ICON_WARNING - * @see SWT#ICON_WORKING - * - * @since 3.0 - */ -public Image getSystemImage (int id) { - checkDevice (); - switch (id) { - case SWT.ICON_ERROR: - if (errorImage == null) { - errorImage = createImage ("gtk-dialog-error"); //$NON-NLS-1$ - } - return errorImage; - case SWT.ICON_INFORMATION: - case SWT.ICON_WORKING: - if (infoImage == null) { - infoImage = createImage ("gtk-dialog-info"); //$NON-NLS-1$ - } - return infoImage; - case SWT.ICON_QUESTION: - if (questionImage == null) { - questionImage = createImage ("gtk-dialog-question"); //$NON-NLS-1$ - } - return questionImage; - case SWT.ICON_WARNING: - if (warningImage == null) { - warningImage = createImage ("gtk-dialog-warning"); //$NON-NLS-1$ - } - return warningImage; - } - return null; -} - -void initializeSystemColors () { - GdkColor gdkColor; - - /* Get Tooltip resources */ - int /*long*/ tooltipShellHandle = OS.gtk_window_new (OS.GTK_WINDOW_POPUP); - if (tooltipShellHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - byte[] gtk_tooltips = Converter.wcsToMbcs (null, "gtk-tooltips", true); //$NON-NLS-1$ - OS.gtk_widget_set_name (tooltipShellHandle, gtk_tooltips); - OS.gtk_widget_realize (tooltipShellHandle); - int /*long*/ tooltipStyle = OS.gtk_widget_get_style (tooltipShellHandle); - gdkColor = new GdkColor(); - OS.gtk_style_get_fg (tooltipStyle, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_INFO_FOREGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_bg (tooltipStyle, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_INFO_BACKGROUND = gdkColor; - OS.gtk_widget_destroy (tooltipShellHandle); - - /* Get Shell resources */ - int /*long*/ style = OS.gtk_widget_get_style (shellHandle); - gdkColor = new GdkColor(); - OS.gtk_style_get_black (style, gdkColor); - COLOR_WIDGET_DARK_SHADOW = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_dark (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_WIDGET_NORMAL_SHADOW = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_bg (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_WIDGET_LIGHT_SHADOW = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_light (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_WIDGET_HIGHLIGHT_SHADOW = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_fg (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_WIDGET_FOREGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_bg (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_WIDGET_BACKGROUND = gdkColor; - //gdkColor = new GdkColor(); - //OS.gtk_style_get_text (style, OS.GTK_STATE_NORMAL, gdkColor); - //COLOR_TEXT_FOREGROUND = gdkColor; - //gdkColor = new GdkColor(); - //OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, gdkColor); - //COLOR_TEXT_BACKGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_text (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_LIST_FOREGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_LIST_BACKGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_text (style, OS.GTK_STATE_SELECTED, gdkColor); - COLOR_LIST_SELECTION_TEXT = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_base (style, OS.GTK_STATE_SELECTED, gdkColor); - COLOR_LIST_SELECTION = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_bg (style, OS.GTK_STATE_SELECTED, gdkColor); - COLOR_TITLE_BACKGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_fg (style, OS.GTK_STATE_SELECTED, gdkColor); - COLOR_TITLE_FOREGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_light (style, OS.GTK_STATE_SELECTED, gdkColor); - COLOR_TITLE_BACKGROUND_GRADIENT = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_bg (style, OS.GTK_STATE_INSENSITIVE, gdkColor); - COLOR_TITLE_INACTIVE_BACKGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_fg (style, OS.GTK_STATE_INSENSITIVE, gdkColor); - COLOR_TITLE_INACTIVE_FOREGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_light (style, OS.GTK_STATE_INSENSITIVE, gdkColor); - COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = gdkColor; -} - -/** - * Returns a reasonable font for applications to use. - * On some platforms, this will match the "default font" - * or "system font" if such can be found. This font - * should not be free'd because it was allocated by the - * system, not the application. - *

    - * Typically, applications which want the default look - * should simply not set the font on the widgets they - * create. Widgets are always created with the correct - * default font for the class of user-interface component - * they represent. - *

    - * - * @return a font - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public Font getSystemFont () { - checkDevice (); - if (systemFont != null) return systemFont; - int /*long*/ style = OS.gtk_widget_get_style (shellHandle); - int /*long*/ defaultFont = OS.pango_font_description_copy (OS.gtk_style_get_font_desc (style)); - return systemFont = Font.gtk_new (this, defaultFont); -} - -/** - * Returns the single instance of the system tray or null - * when there is no system tray available for the platform. - * - * @return the system tray or null - * - * @exception SWTException
      - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @since 3.0 - */ -public Tray getSystemTray () { - checkDevice (); - if (tray != null) return tray; - return tray = new Tray (this, SWT.NONE); -} - -/** - * Returns the user-interface thread for the receiver. - * - * @return the receiver's user-interface thread - * - * @exception SWTException
      - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - */ -public Thread getThread () { - synchronized (Device.class) { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - return thread; - } -} - -Widget getWidget (int /*long*/ handle) { - if (handle == 0) return null; - if (lastWidget != null && lastHandle == handle) return lastWidget; - int /*long*/ index = OS.g_object_get_qdata (handle, SWT_OBJECT_INDEX) - 1; - if (0 <= index && index < widgetTable.length) { - lastHandle = handle; - return lastWidget = widgetTable [(int)/*64*/index]; - } - return null; -} - -int /*long*/ idleProc (int /*long*/ data) { - boolean result = runAsyncMessages (false); - if (!result) { - synchronized (idleLock) { - idleHandle = 0; - } - } - return result ? 1 : 0; -} - -/** - * Initializes any internal resources needed by the - * device. - *

    - * This method is called after create. - *

    - * - * @see #create - */ -protected void init () { - super.init (); - initializeCallbacks (); - initializeSubclasses (); - initializeSystemColors (); - initializeSystemSettings (); - initializeWidgetTable (); - initializeWindowManager (); -} - -void initializeCallbacks () { - closures = new int /*long*/ [Widget.LAST_SIGNAL]; - signalIds = new int [Widget.LAST_SIGNAL]; - - /* Cache signals for GtkWidget */ - signalIds [Widget.BUTTON_PRESS_EVENT] = OS.g_signal_lookup (OS.button_press_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.BUTTON_RELEASE_EVENT] = OS.g_signal_lookup (OS.button_release_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.CONFIGURE_EVENT] = OS.g_signal_lookup (OS.configure_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.DELETE_EVENT] = OS.g_signal_lookup (OS.delete_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.ENTER_NOTIFY_EVENT] = OS.g_signal_lookup (OS.enter_notify_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.EVENT] = OS.g_signal_lookup (OS.event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.EVENT_AFTER] = OS.g_signal_lookup (OS.event_after, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.EXPOSE_EVENT] = OS.g_signal_lookup (OS.expose_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.FOCUS] = OS.g_signal_lookup (OS.focus, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.FOCUS_IN_EVENT] = OS.g_signal_lookup (OS.focus_in_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.FOCUS_OUT_EVENT] = OS.g_signal_lookup (OS.focus_out_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.GRAB_FOCUS] = OS.g_signal_lookup (OS.grab_focus, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.HIDE] = OS.g_signal_lookup (OS.hide, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.KEY_PRESS_EVENT] = OS.g_signal_lookup (OS.key_press_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.KEY_RELEASE_EVENT] = OS.g_signal_lookup (OS.key_release_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.LEAVE_NOTIFY_EVENT] = OS.g_signal_lookup (OS.leave_notify_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.MAP] = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.MAP_EVENT] = OS.g_signal_lookup (OS.map_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.MNEMONIC_ACTIVATE] = OS.g_signal_lookup (OS.mnemonic_activate, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.MOTION_NOTIFY_EVENT] = OS.g_signal_lookup (OS.motion_notify_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.POPUP_MENU] = OS.g_signal_lookup (OS.popup_menu, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.REALIZE] = OS.g_signal_lookup (OS.realize, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.SCROLL_EVENT] = OS.g_signal_lookup (OS.scroll_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.SHOW] = OS.g_signal_lookup (OS.show, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.SHOW_HELP] = OS.g_signal_lookup (OS.show_help, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.SIZE_ALLOCATE] = OS.g_signal_lookup (OS.size_allocate, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.STYLE_SET] = OS.g_signal_lookup (OS.style_set, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.UNMAP] = OS.g_signal_lookup (OS.unmap, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.UNMAP_EVENT] = OS.g_signal_lookup (OS.unmap_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.UNREALIZE] = OS.g_signal_lookup (OS.realize, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.VISIBILITY_NOTIFY_EVENT] = OS.g_signal_lookup (OS.visibility_notify_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.WINDOW_STATE_EVENT] = OS.g_signal_lookup (OS.window_state_event, OS.GTK_TYPE_WIDGET ()); - - windowCallback2 = new Callback (this, "windowProc", 2); //$NON-NLS-1$ - windowProc2 = windowCallback2.getAddress (); - if (windowProc2 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - closures [Widget.ACTIVATE] = OS.g_cclosure_new (windowProc2, Widget.ACTIVATE, 0); - closures [Widget.ACTIVATE_INVERSE] = OS.g_cclosure_new (windowProc2, Widget.ACTIVATE_INVERSE, 0); - closures [Widget.CHANGED] = OS.g_cclosure_new (windowProc2, Widget.CHANGED, 0); - closures [Widget.CLICKED] = OS.g_cclosure_new (windowProc2, Widget.CLICKED, 0); - closures [Widget.DAY_SELECTED] = OS.g_cclosure_new (windowProc2, Widget.DAY_SELECTED, 0); - closures [Widget.DAY_SELECTED_DOUBLE_CLICK] = OS.g_cclosure_new (windowProc2, Widget.DAY_SELECTED_DOUBLE_CLICK, 0); - closures [Widget.HIDE] = OS.g_cclosure_new (windowProc2, Widget.HIDE, 0); - closures [Widget.GRAB_FOCUS] = OS.g_cclosure_new (windowProc2, Widget.GRAB_FOCUS, 0); - closures [Widget.MAP] = OS.g_cclosure_new (windowProc2, Widget.MAP, 0); - closures [Widget.MONTH_CHANGED] = OS.g_cclosure_new (windowProc2, Widget.MONTH_CHANGED, 0); - closures [Widget.OUTPUT] = OS.g_cclosure_new (windowProc2, Widget.OUTPUT, 0); - closures [Widget.POPUP_MENU] = OS.g_cclosure_new (windowProc2, Widget.POPUP_MENU, 0); - closures [Widget.PREEDIT_CHANGED] = OS.g_cclosure_new (windowProc2, Widget.PREEDIT_CHANGED, 0); - closures [Widget.REALIZE] = OS.g_cclosure_new (windowProc2, Widget.REALIZE, 0); - closures [Widget.SELECT] = OS.g_cclosure_new (windowProc2, Widget.SELECT, 0); - closures [Widget.SHOW] = OS.g_cclosure_new (windowProc2, Widget.SHOW, 0); - closures [Widget.VALUE_CHANGED] = OS.g_cclosure_new (windowProc2, Widget.VALUE_CHANGED, 0); - closures [Widget.UNMAP] = OS.g_cclosure_new (windowProc2, Widget.UNMAP, 0); - closures [Widget.UNREALIZE] = OS.g_cclosure_new (windowProc2, Widget.UNREALIZE, 0); - - windowCallback3 = new Callback (this, "windowProc", 3); //$NON-NLS-1$ - windowProc3 = windowCallback3.getAddress (); - if (windowProc3 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - closures [Widget.BUTTON_PRESS_EVENT] = OS.g_cclosure_new (windowProc3, Widget.BUTTON_PRESS_EVENT, 0); - closures [Widget.BUTTON_PRESS_EVENT_INVERSE] = OS.g_cclosure_new (windowProc3, Widget.BUTTON_PRESS_EVENT_INVERSE, 0); - closures [Widget.BUTTON_RELEASE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.BUTTON_RELEASE_EVENT, 0); - closures [Widget.BUTTON_RELEASE_EVENT_INVERSE] = OS.g_cclosure_new (windowProc3, Widget.BUTTON_RELEASE_EVENT_INVERSE, 0); - closures [Widget.COMMIT] = OS.g_cclosure_new (windowProc3, Widget.COMMIT, 0); - closures [Widget.CONFIGURE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.CONFIGURE_EVENT, 0); - closures [Widget.DELETE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.DELETE_EVENT, 0); - closures [Widget.ENTER_NOTIFY_EVENT] = OS.g_cclosure_new (windowProc3, Widget.ENTER_NOTIFY_EVENT, 0); - closures [Widget.EVENT] = OS.g_cclosure_new (windowProc3, Widget.EVENT, 0); - closures [Widget.EVENT_AFTER] = OS.g_cclosure_new (windowProc3, Widget.EVENT_AFTER, 0); - closures [Widget.EXPOSE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.EXPOSE_EVENT, 0); - closures [Widget.EXPOSE_EVENT_INVERSE] = OS.g_cclosure_new (windowProc3, Widget.EXPOSE_EVENT_INVERSE, 0); - closures [Widget.FOCUS] = OS.g_cclosure_new (windowProc3, Widget.FOCUS, 0); - closures [Widget.FOCUS_IN_EVENT] = OS.g_cclosure_new (windowProc3, Widget.FOCUS_IN_EVENT, 0); - closures [Widget.FOCUS_OUT_EVENT] = OS.g_cclosure_new (windowProc3, Widget.FOCUS_OUT_EVENT, 0); - closures [Widget.KEY_PRESS_EVENT] = OS.g_cclosure_new (windowProc3, Widget.KEY_PRESS_EVENT, 0); - closures [Widget.KEY_RELEASE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.KEY_RELEASE_EVENT, 0); - closures [Widget.INPUT] = OS.g_cclosure_new (windowProc3, Widget.INPUT, 0); - closures [Widget.LEAVE_NOTIFY_EVENT] = OS.g_cclosure_new (windowProc3, Widget.LEAVE_NOTIFY_EVENT, 0); - closures [Widget.MAP_EVENT] = OS.g_cclosure_new (windowProc3, Widget.MAP_EVENT, 0); - closures [Widget.MNEMONIC_ACTIVATE] = OS.g_cclosure_new (windowProc3, Widget.MNEMONIC_ACTIVATE, 0); - closures [Widget.MOTION_NOTIFY_EVENT] = OS.g_cclosure_new (windowProc3, Widget.MOTION_NOTIFY_EVENT, 0); - closures [Widget.MOTION_NOTIFY_EVENT_INVERSE] = OS.g_cclosure_new (windowProc3, Widget.MOTION_NOTIFY_EVENT_INVERSE, 0); - closures [Widget.MOVE_FOCUS] = OS.g_cclosure_new (windowProc3, Widget.MOVE_FOCUS, 0); - closures [Widget.POPULATE_POPUP] = OS.g_cclosure_new (windowProc3, Widget.POPULATE_POPUP, 0); - closures [Widget.SCROLL_EVENT] = OS.g_cclosure_new (windowProc3, Widget.SCROLL_EVENT, 0); - closures [Widget.SHOW_HELP] = OS.g_cclosure_new (windowProc3, Widget.SHOW_HELP, 0); - closures [Widget.SIZE_ALLOCATE] = OS.g_cclosure_new (windowProc3, Widget.SIZE_ALLOCATE, 0); - closures [Widget.STYLE_SET] = OS.g_cclosure_new (windowProc3, Widget.STYLE_SET, 0); - closures [Widget.TOGGLED] = OS.g_cclosure_new (windowProc3, Widget.TOGGLED, 0); - closures [Widget.UNMAP_EVENT] = OS.g_cclosure_new (windowProc3, Widget.UNMAP_EVENT, 0); - closures [Widget.VISIBILITY_NOTIFY_EVENT] = OS.g_cclosure_new (windowProc3, Widget.VISIBILITY_NOTIFY_EVENT, 0); - closures [Widget.WINDOW_STATE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.WINDOW_STATE_EVENT, 0); - closures [Widget.ROW_DELETED] = OS.g_cclosure_new (windowProc3, Widget.ROW_DELETED, 0); - - windowCallback4 = new Callback (this, "windowProc", 4); //$NON-NLS-1$ - windowProc4 = windowCallback4.getAddress (); - if (windowProc4 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - closures [Widget.DELETE_RANGE] = OS.g_cclosure_new (windowProc4, Widget.DELETE_RANGE, 0); - closures [Widget.DELETE_TEXT] = OS.g_cclosure_new (windowProc4, Widget.DELETE_TEXT, 0); - closures [Widget.ROW_ACTIVATED] = OS.g_cclosure_new (windowProc4, Widget.ROW_ACTIVATED, 0); - closures [Widget.SCROLL_CHILD] = OS.g_cclosure_new (windowProc4, Widget.SCROLL_CHILD, 0); - closures [Widget.STATUS_ICON_POPUP_MENU] = OS.g_cclosure_new (windowProc4, Widget.STATUS_ICON_POPUP_MENU, 0); - closures [Widget.SWITCH_PAGE] = OS.g_cclosure_new (windowProc4, Widget.SWITCH_PAGE, 0); - closures [Widget.TEST_COLLAPSE_ROW] = OS.g_cclosure_new (windowProc4, Widget.TEST_COLLAPSE_ROW, 0); - closures [Widget.TEST_EXPAND_ROW] = OS.g_cclosure_new (windowProc4, Widget.TEST_EXPAND_ROW, 0); - closures [Widget.ROW_INSERTED] = OS.g_cclosure_new (windowProc4, Widget.ROW_INSERTED, 0); - - windowCallback5 = new Callback (this, "windowProc", 5); //$NON-NLS-1$ - windowProc5 = windowCallback5.getAddress (); - if (windowProc5 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - closures [Widget.CHANGE_VALUE] = OS.g_cclosure_new (windowProc5, Widget.CHANGE_VALUE, 0); - closures [Widget.EXPAND_COLLAPSE_CURSOR_ROW] = OS.g_cclosure_new (windowProc5, Widget.EXPAND_COLLAPSE_CURSOR_ROW, 0); - closures [Widget.INSERT_TEXT] = OS.g_cclosure_new (windowProc5, Widget.INSERT_TEXT, 0); - closures [Widget.TEXT_BUFFER_INSERT_TEXT] = OS.g_cclosure_new (windowProc5, Widget.TEXT_BUFFER_INSERT_TEXT, 0); - - for (int i = 0; i < Widget.LAST_SIGNAL; i++) { - if (closures [i] != 0) OS.g_closure_ref (closures [i]); - } - - timerCallback = new Callback (this, "timerProc", 1); //$NON-NLS-1$ - timerProc = timerCallback.getAddress (); - if (timerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - windowTimerCallback = new Callback (this, "windowTimerProc", 1); //$NON-NLS-1$ - windowTimerProc = windowTimerCallback.getAddress (); - if (windowTimerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - mouseHoverCallback = new Callback (this, "mouseHoverProc", 1); //$NON-NLS-1$ - mouseHoverProc = mouseHoverCallback.getAddress (); - if (mouseHoverProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - caretCallback = new Callback(this, "caretProc", 1); //$NON-NLS-1$ - caretProc = caretCallback.getAddress(); - if (caretProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - menuPositionCallback = new Callback(this, "menuPositionProc", 5); //$NON-NLS-1$ - menuPositionProc = menuPositionCallback.getAddress(); - if (menuPositionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - sizeAllocateCallback = new Callback(this, "sizeAllocateProc", 3); //$NON-NLS-1$ - sizeAllocateProc = sizeAllocateCallback.getAddress(); - if (sizeAllocateProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - sizeRequestCallback = new Callback(this, "sizeRequestProc", 3); //$NON-NLS-1$ - sizeRequestProc = sizeRequestCallback.getAddress(); - if (sizeRequestProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - shellMapCallback = new Callback(this, "shellMapProc", 3); //$NON-NLS-1$ - shellMapProc = shellMapCallback.getAddress(); - if (shellMapProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - shellMapProcClosure = OS.g_cclosure_new (shellMapProc, 0, 0); - OS.g_closure_ref (shellMapProcClosure); - - treeSelectionCallback = new Callback(this, "treeSelectionProc", 4); //$NON-NLS-1$ - treeSelectionProc = treeSelectionCallback.getAddress(); - if (treeSelectionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - cellDataCallback = new Callback (this, "cellDataProc", 5); //$NON-NLS-1$ - cellDataProc = cellDataCallback.getAddress (); - if (cellDataProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - setDirectionCallback = new Callback (this, "setDirectionProc", 2); //$NON-NLS-1$ - setDirectionProc = setDirectionCallback.getAddress (); - if (setDirectionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - emissionProcCallback = new Callback (this, "emissionProc", 4); //$NON-NLS-1$ - emissionProc = emissionProcCallback.getAddress (); - if (emissionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - allChildrenCallback = new Callback (this, "allChildrenProc", 2); //$NON-NLS-1$ - allChildrenProc = allChildrenCallback.getAddress (); - if (allChildrenProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - checkIfEventCallback = new Callback (this, "checkIfEventProc", 3); //$NON-NLS-1$ - checkIfEventProc = checkIfEventCallback.getAddress (); - if (checkIfEventProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - idleCallback = new Callback (this, "idleProc", 1); //$NON-NLS-1$ - idleProc = idleCallback.getAddress (); - if (idleProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); -} - -void initializeSubclasses () { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - pangoLayoutNewCallback = new Callback (this, "pangoLayoutNewProc", 3); //$NON-NLS-1$ - pangoLayoutNewProc = pangoLayoutNewCallback.getAddress (); - if (pangoLayoutNewProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - int /*long*/ pangoLayoutType = OS.PANGO_TYPE_LAYOUT (); - int /*long*/ pangoLayoutClass = OS.g_type_class_ref (pangoLayoutType); - pangoLayoutNewDefaultProc = OS.G_OBJECT_CLASS_CONSTRUCTOR (pangoLayoutClass); - OS.G_OBJECT_CLASS_SET_CONSTRUCTOR (pangoLayoutClass, pangoLayoutNewProc); - OS.g_type_class_unref (pangoLayoutClass); - } -} - -void initializeSystemSettings () { - styleSetCallback = new Callback (this, "styleSetProc", 3); //$NON-NLS-1$ - styleSetProc = styleSetCallback.getAddress (); - if (styleSetProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - OS.g_signal_connect (shellHandle, OS.style_set, styleSetProc, 0); - - /* - * Feature in GTK. Despite the fact that the - * gtk-entry-select-on-focus property is a global - * setting, it is initialized when the GtkEntry - * is initialized. This means that it cannot be - * accessed before a GtkEntry is created. The - * fix is to for the initializaion by creating - * a temporary GtkEntry. - */ - int /*long*/ entry = OS.gtk_entry_new (); - OS.gtk_widget_destroy (entry); - int [] buffer2 = new int [1]; - int /*long*/ settings = OS.gtk_settings_get_default (); - OS.g_object_get (settings, OS.gtk_entry_select_on_focus, buffer2, 0); - entrySelectOnFocus = buffer2 [0] != 0; -} - -void initializeWidgetTable () { - indexTable = new int [GROW_SIZE]; - widgetTable = new Widget [GROW_SIZE]; - for (int i=0; i= OS.VERSION (2, 2, 0)) { - int /*long*/ screen = OS.gdk_screen_get_default (); - if (screen != 0) { - int /*long*/ ptr2 = OS.gdk_x11_screen_get_window_manager_name (screen); - if (ptr2 != 0) { - int length = OS.strlen (ptr2); - if (length > 0) { - byte [] buffer2 = new byte [length]; - OS.memmove (buffer2, ptr2, length); - windowManager = new String (Converter.mbcsToWcs (null, buffer2)); - } - } - } - } -} - -/** - * Invokes platform specific functionality to dispose a GC handle. - *

    - * IMPORTANT: This method is not part of the public - * API for Display. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - *

    - * - * @param hDC the platform specific GC handle - * @param data the platform specific GC data - */ -public void internal_dispose_GC (int /*long*/ gdkGC, GCData data) { - OS.g_object_unref (gdkGC); -} - -/** - * Invokes platform specific functionality to allocate a new GC handle. - *

    - * IMPORTANT: This method is not part of the public - * API for Display. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - *

    - * - * @param data the platform specific GC data - * @return the platform specific GC handle - * - * @exception SWTException
      - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * @exception SWTError
      - *
    • ERROR_NO_HANDLES if a handle could not be obtained for gc creation
    • - *
    - */ -public int /*long*/ internal_new_GC (GCData data) { - if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED); - int /*long*/ root = OS.GDK_ROOT_PARENT (); - int /*long*/ gdkGC = OS.gdk_gc_new (root); - if (gdkGC == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_gc_set_subwindow (gdkGC, OS.GDK_INCLUDE_INFERIORS); - if (data != null) { - int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; - if ((data.style & mask) == 0) { - data.style |= SWT.LEFT_TO_RIGHT; - } - data.device = this; - data.drawable = root; - data.background = getSystemColor (SWT.COLOR_WHITE).handle; - data.foreground = getSystemColor (SWT.COLOR_BLACK).handle; - data.font = getSystemFont (); - } - return gdkGC; -} - -boolean isValidThread () { - return thread == Thread.currentThread (); -} - -/** - * Maps a point from one coordinate system to another. - * When the control is null, coordinates are mapped to - * the display. - *

    - * NOTE: On right-to-left platforms where the coordinate - * systems are mirrored, special care needs to be taken - * when mapping coordinates from one control to another - * to ensure the result is correctly mirrored. - * - * Mapping a point that is the origin of a rectangle and - * then adding the width and height is not equivalent to - * mapping the rectangle. When one control is mirrored - * and the other is not, adding the width and height to a - * point that was mapped causes the rectangle to extend - * in the wrong direction. Mapping the entire rectangle - * instead of just one point causes both the origin and - * the corner of the rectangle to be mapped. - *

    - * - * @param from the source Control or null - * @param to the destination Control or null - * @param point to be mapped - * @return point with mapped coordinates - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the point is null
    • - *
    • ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed
    • - *
    - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @since 2.1.2 - */ -public Point map (Control from, Control to, Point point) { - checkDevice (); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - return map (from, to, point.x, point.y); -} - -/** - * Maps a point from one coordinate system to another. - * When the control is null, coordinates are mapped to - * the display. - *

    - * NOTE: On right-to-left platforms where the coordinate - * systems are mirrored, special care needs to be taken - * when mapping coordinates from one control to another - * to ensure the result is correctly mirrored. - * - * Mapping a point that is the origin of a rectangle and - * then adding the width and height is not equivalent to - * mapping the rectangle. When one control is mirrored - * and the other is not, adding the width and height to a - * point that was mapped causes the rectangle to extend - * in the wrong direction. Mapping the entire rectangle - * instead of just one point causes both the origin and - * the corner of the rectangle to be mapped. - *

    - * - * @param from the source Control or null - * @param to the destination Control or null - * @param x coordinates to be mapped - * @param y coordinates to be mapped - * @return point with mapped coordinates - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed
    • - *
    - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @since 2.1.2 - */ -public Point map (Control from, Control to, int x, int y) { - checkDevice (); - if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - Point point = new Point (x, y); - if (from == to) return point; - if (from != null) { - int /*long*/ window = from.eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - if ((from.style & SWT.MIRRORED) != 0) point.x = from.getClientWidth () - point.x; - point.x += origin_x [0]; - point.y += origin_y [0]; - } - if (to != null) { - int /*long*/ window = to.eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - point.x -= origin_x [0]; - point.y -= origin_y [0]; - if ((to.style & SWT.MIRRORED) != 0) point.x = to.getClientWidth () - point.x; - } - return point; -} - -/** - * Maps a point from one coordinate system to another. - * When the control is null, coordinates are mapped to - * the display. - *

    - * NOTE: On right-to-left platforms where the coordinate - * systems are mirrored, special care needs to be taken - * when mapping coordinates from one control to another - * to ensure the result is correctly mirrored. - * - * Mapping a point that is the origin of a rectangle and - * then adding the width and height is not equivalent to - * mapping the rectangle. When one control is mirrored - * and the other is not, adding the width and height to a - * point that was mapped causes the rectangle to extend - * in the wrong direction. Mapping the entire rectangle - * instead of just one point causes both the origin and - * the corner of the rectangle to be mapped. - *

    - * - * @param from the source Control or null - * @param to the destination Control or null - * @param rectangle to be mapped - * @return rectangle with mapped coordinates - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the rectangle is null
    • - *
    • ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed
    • - *
    - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @since 2.1.2 - */ -public Rectangle map (Control from, Control to, Rectangle rectangle) { - checkDevice(); - if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT); - return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height); -} - -static char mbcsToWcs (char ch) { - int key = ch & 0xFFFF; - if (key <= 0x7F) return ch; - byte [] buffer; - if (key <= 0xFF) { - buffer = new byte [1]; - buffer [0] = (byte) key; - } else { - buffer = new byte [2]; - buffer [0] = (byte) ((key >> 8) & 0xFF); - buffer [1] = (byte) (key & 0xFF); - } - char [] result = Converter.mbcsToWcs (null, buffer); - if (result.length == 0) return 0; - return result [0]; -} - -int /*long*/ menuPositionProc (int /*long*/ menu, int /*long*/ x, int /*long*/ y, int /*long*/ push_in, int /*long*/ user_data) { - Widget widget = getWidget (menu); - if (widget == null) return 0; - return widget.menuPositionProc (menu, x, y, push_in, user_data); -} - -/** - * Maps a point from one coordinate system to another. - * When the control is null, coordinates are mapped to - * the display. - *

    - * NOTE: On right-to-left platforms where the coordinate - * systems are mirrored, special care needs to be taken - * when mapping coordinates from one control to another - * to ensure the result is correctly mirrored. - * - * Mapping a point that is the origin of a rectangle and - * then adding the width and height is not equivalent to - * mapping the rectangle. When one control is mirrored - * and the other is not, adding the width and height to a - * point that was mapped causes the rectangle to extend - * in the wrong direction. Mapping the entire rectangle - * instead of just one point causes both the origin and - * the corner of the rectangle to be mapped. - *

    - * - * @param from the source Control or null - * @param to the destination Control or null - * @param x coordinates to be mapped - * @param y coordinates to be mapped - * @param width coordinates to be mapped - * @param height coordinates to be mapped - * @return rectangle with mapped coordinates - * - * @exception IllegalArgumentException
      - *
    • ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed
    • - *
    - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @since 2.1.2 - */ -public Rectangle map (Control from, Control to, int x, int y, int width, int height) { - checkDevice(); - if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - Rectangle rect = new Rectangle (x, y, width, height); - if (from == to) return rect; - boolean fromRTL = false, toRTL = false; - if (from != null) { - int /*long*/ window = from.eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - if (fromRTL = (from.style & SWT.MIRRORED) != 0) rect.x = from.getClientWidth() - rect.x; - rect.x += origin_x [0]; - rect.y += origin_y [0]; - } - if (to != null) { - int /*long*/ window = to.eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - rect.x -= origin_x [0]; - rect.y -= origin_y [0]; - if (toRTL = (to.style & SWT.MIRRORED) != 0) rect.x = to.getClientWidth () - rect.x; - } - if (fromRTL != toRTL) rect.x -= rect.width; - return rect; -} - -int /*long*/ mouseHoverProc (int /*long*/ handle) { - Widget widget = getWidget (handle); - if (widget == null) return 0; - return widget.hoverProc (handle); -} - -int /*long*/ pangoLayoutNewProc (int /*long*/ type, int /*long*/ n_construct_properties, int /*long*/ construct_properties) { - int /*long*/ layout = OS.Call (pangoLayoutNewDefaultProc, type, (int)/*64*/n_construct_properties, construct_properties); - OS.pango_layout_set_auto_dir (layout, false); - return layout; -} - -/** - * Generate a low level system event. - * - * post is used to generate low level keyboard - * and mouse events. The intent is to enable automated UI - * testing by simulating the input from the user. Most - * SWT applications should never need to call this method. - *

    - * Note that this operation can fail when the operating system - * fails to generate the event for any reason. For example, - * this can happen when there is no such key or mouse button - * or when the system event queue is full. - *

    - *

    - * Event Types: - *

    KeyDown, KeyUp - *

    The following fields in the Event apply: - *

      - *
    • (in) type KeyDown or KeyUp
    • - *

      Either one of: - *

    • (in) character a character that corresponds to a keyboard key
    • - *
    • (in) keyCode the key code of the key that was typed, - * as defined by the key code constants in class SWT
    • - *
    - *

    MouseDown, MouseUp

    - *

    The following fields in the Event apply: - *

      - *
    • (in) type MouseDown or MouseUp - *
    • (in) button the button that is pressed or released - *
    - *

    MouseMove

    - *

    The following fields in the Event apply: - *

      - *
    • (in) type MouseMove - *
    • (in) x the x coordinate to move the mouse pointer to in screen coordinates - *
    • (in) y the y coordinate to move the mouse pointer to in screen coordinates - *
    - *

    MouseWheel

    - *

    The following fields in the Event apply: - *

      - *
    • (in) type MouseWheel - *
    • (in) detail either SWT.SCROLL_LINE or SWT.SCROLL_PAGE - *
    • (in) count the number of lines or pages to scroll - *
    - * - * - * @param event the event to be generated - * - * @return true if the event was generated or false otherwise - * - * @exception IllegalArgumentException
      - *
    • ERROR_NULL_ARGUMENT - if the event is null
    • - *
    - * @exception SWTException
      - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    - * - * @since 3.0 - * - */ -public boolean post (Event event) { - /* - * Get the operating system lock before synchronizing on the device - * lock so that the device lock will not be held should another - * thread already be in the operating system. This avoids deadlock - * should the other thread need the device lock. - */ - Lock lock = OS.lock; - lock.lock(); - try { - synchronized (Device.class) { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - if (event == null) error (SWT.ERROR_NULL_ARGUMENT); - if (!OS.GDK_WINDOWING_X11()) return false; - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - int type = event.type; - switch (type) { - case SWT.KeyDown: - case SWT.KeyUp: { - int keyCode = 0; - int /*long*/ keysym = untranslateKey (event.keyCode); - if (keysym != 0) keyCode = OS.XKeysymToKeycode (xDisplay, keysym); - if (keyCode == 0) { - char key = event.character; - switch (key) { - case SWT.BS: keysym = OS.GDK_BackSpace; break; - case SWT.CR: keysym = OS.GDK_Return; break; - case SWT.DEL: keysym = OS.GDK_Delete; break; - case SWT.ESC: keysym = OS.GDK_Escape; break; - case SWT.TAB: keysym = OS.GDK_Tab; break; - case SWT.LF: keysym = OS.GDK_Linefeed; break; - default: - keysym = key; - } - keyCode = OS.XKeysymToKeycode (xDisplay, keysym); - if (keyCode == 0) return false; - } - OS.XTestFakeKeyEvent (xDisplay, keyCode, type == SWT.KeyDown, 0); - return true; - } - case SWT.MouseDown: - case SWT.MouseMove: - case SWT.MouseUp: { - if (type == SWT.MouseMove) { - OS.XTestFakeMotionEvent (xDisplay, -1, event.x, event.y, 0); - } else { - int button = event.button; - switch (button) { - case 1: - case 2: - case 3: break; - case 4: button = 6; break; - case 5: button = 7; break; - default: return false; - } - OS.XTestFakeButtonEvent (xDisplay, button, type == SWT.MouseDown, 0); - } - return true; - } - /* - * This code is intentionally commented. After posting a - * mouse wheel event the system may respond unpredictably - * to subsequent mouse actions. - */ -// case SWT.MouseWheel: { -// if (event.count == 0) return false; -// int button = event.count < 0 ? 5 : 4; -// OS.XTestFakeButtonEvent (xDisplay, button, type == SWT.MouseWheel, 0); -// } - } - return false; - } - } finally { - lock.unlock(); - } -} - -void postEvent (Event event) { - /* - * Place the event at the end of the event queue. - * This code is always called in the Display's - * thread so it must be re-enterant but does not - * need to be synchronized. - */ - if (eventQueue == null) eventQueue = new Event [4]; - int index = 0; - int length = eventQueue.length; - while (index < length) { - if (eventQueue [index] == null) break; - index++; - } - if (index == length) { - Event [] newQueue = new Event [length + 4]; - System.arraycopy (eventQueue, 0, newQueue, 0, length); - eventQueue = newQueue; - } - eventQueue [index] = event; -} - -void putGdkEvents () { - if (gdkEventCount != 0) { - for (int i = 0; i < gdkEventCount; i++) { - int /*long*/ event = gdkEvents [i]; - Widget widget = gdkEventWidgets [i]; - if (widget == null || !widget.isDisposed ()) { - OS.gdk_event_put (event); - } - OS.gdk_event_free (event); - gdkEvents [i] = 0; - gdkEventWidgets [i] = null; - } - gdkEventCount = 0; - } -} - -/** - * Reads an event from the operating system's event queue, - * dispatches it appropriately, and returns true - * if there is potentially more work to do, or false - * if the caller can sleep until another event is placed on - * the event queue. - *

    - * In addition to checking the system event queue, this method also - * checks if any inter-thread messages (created by syncExec() - * or asyncExec()) are waiting to be processed, and if - * so handles them before returning. - *

    - * - * @return false if the caller can sleep upon return from this method - * - * @exception SWTException
      - *
    • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • - *
    • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • - *
    • ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message
    • - *
    - * - * @see #sleep - * @see #wake - */ -public boolean readAndDispatch () { - checkDevice (); - boolean events = false; - events |= runSettings (); - events |= runPopups (); - events |= OS.g_main_context_iteration (0, false); - if (events) { - runDeferredEvents (); - return true; - } - return isDisposed () || runAsyncMessages (false); -} - -static void register (Display display) { - synchronized (Device.class) { - for (int i=0; i - * Disposes all shells which are currently open on the display. - * After this method has been invoked, all related related shells - * will answer true when sent the message - * isDisposed(). - *

    - * When a device is destroyed, resources that were acquired - * on behalf of the programmer need to be returned to the - * operating system. For example, if the device allocated a - * font to be used as the system font, this font would be - * freed in release. Also,to assist the garbage - * collector and minimize the amount of memory that is not - * reclaimed when the programmer keeps a reference to a - * disposed device, all fields except the handle are zero'd. - * The handle is needed by destroy. - *

    - * This method is called before destroy. - * - * @see Device#dispose - * @see #destroy - */ -protected void release () { - sendEvent (SWT.Dispose, new Event ()); - Shell [] shells = getShells (); - for (int i=0; i