();
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Menu
) and a style value describing its behavior and
- * appearance. The item is added to the end of the items maintained by its
- * parent.
- *
- * 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 menu 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#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public MenuItem(Menu parent, int style) {
- super(parent, checkStyle(style));
- this.parent = parent;
- createAction(parent, style, -1);
- initializeKeys();
- }
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Menu
), a style value describing its behavior and appearance,
- * and the index at which to place it in the items maintained by its parent.
- *
- * 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 menu control which will be the parent of the new instance
- * (cannot be null)
- * @param style
- * the style of control to construct
- * @param index
- * the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the parent is null
- * - ERROR_INVALID_RANGE - if the index is not between 0
- * and the number of elements in the parent (inclusive)
- *
- * @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#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public MenuItem(Menu parent, int style, int index) {
- super(parent, checkStyle(style));
- this.parent = parent;
- createAction(parent, style, index);
- initializeKeys();
- }
-
- MenuItem(Menu parent, Menu menu, int style, int index) {
- super(parent, checkStyle(style));
- this.parent = parent;
- this.menu = menu;
- if (menu != null) {
- menu.cascade = this;
- }
- display.addMenuItem(this);
- initializeKeys();
- }
-
- protected void createAction(Menu parent, int style, int index) {
- action = new QAction(parent.getQWidget());
-
- parent.addAction(action, index);
- int bits = SWT.CHECK | SWT.RADIO | SWT.PUSH | SWT.SEPARATOR;
- switch (style & bits) {
- case SWT.SEPARATOR:
- action.setSeparator(true);
- break;
- case SWT.RADIO:
- action.setCheckable(true);
- parent.addToActionGroup(action);
- break;
- case SWT.CHECK:
- action.setCheckable(true);
- break;
- case SWT.PUSH:
- default:
- break;
- }
- connectSignals();
- display.addControl(action, this);
- }
-
- QAction getQAction() {
- return action;
- }
-
- protected void connectSignals() {
- if ((style & SWT.CASCADE) == 0) {
- getQAction().triggered.connect(this, "triggerEvent(boolean)");//$NON-NLS-1$
- }
- getQAction().hovered.connect(this, "hoverEvent()");//$NON-NLS-1$
- }
-
- protected void triggerEvent(boolean triggered) {
- Event event = new Event();
- sendEvent(SWT.Selection, event);
- }
-
- protected void hoverEvent() {
- sendEvent(SWT.Arm);
- }
-
- /**
- * Initialize the hashmaps with the SWT keys mapping to QT keys. This is
- * needed for the accelerator.
- */
- private void initializeKeys() {
-
- modifiers.put(SWT.CTRL, Qt.Modifier.CTRL.value()); // 262144, 67108864
- modifiers.put(SWT.MOD1, Qt.Modifier.CTRL.value()); // 262144, 67108864
- modifiers.put(SWT.SHIFT, Qt.Modifier.SHIFT.value());
- modifiers.put(SWT.MOD2, Qt.Modifier.SHIFT.value());
- modifiers.put(SWT.ALT, Qt.Modifier.ALT.value());
-
- accelerators.put(SWT.ARROW_DOWN, Qt.Key.Key_Down.value()); // 16777218
- accelerators.put(SWT.ARROW_LEFT, Qt.Key.Key_Left.value()); // 16777219
- accelerators.put(SWT.ARROW_RIGHT, Qt.Key.Key_Right.value()); // 16777220
- accelerators.put(SWT.ARROW_UP, Qt.Key.Key_Up.value()); // 16777217
- accelerators.put(SWT.F1, Qt.Key.Key_F1.value()); // 16777226
- accelerators.put(SWT.F2, Qt.Key.Key_F2.value());
- accelerators.put(SWT.F3, Qt.Key.Key_F3.value());
- accelerators.put(SWT.F4, Qt.Key.Key_F4.value());
- accelerators.put(SWT.F5, Qt.Key.Key_F5.value());
- accelerators.put(SWT.F6, Qt.Key.Key_F6.value());
- accelerators.put(SWT.F7, Qt.Key.Key_F7.value());
- accelerators.put(SWT.F8, Qt.Key.Key_F8.value());
- accelerators.put(SWT.F9, Qt.Key.Key_F9.value());
- accelerators.put(SWT.F10, Qt.Key.Key_F10.value());
- accelerators.put(SWT.F11, Qt.Key.Key_F11.value());
- accelerators.put(SWT.F12, Qt.Key.Key_F12.value());
- accelerators.put(SWT.F13, Qt.Key.Key_F13.value());
- accelerators.put(SWT.F14, Qt.Key.Key_F14.value());
- accelerators.put(SWT.F15, Qt.Key.Key_F15.value());
- accelerators.put(SWT.PAGE_UP, Qt.Key.Key_PageUp.value());
- accelerators.put(SWT.PAGE_DOWN, Qt.Key.Key_PageDown.value());
- accelerators.put(SWT.HOME, Qt.Key.Key_Home.value());
- accelerators.put(SWT.END, Qt.Key.Key_End.value());
- accelerators.put(SWT.INSERT, Qt.Key.Key_Insert.value());
- }
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when the arm events are generated for the control, by sending it one of
- * the messages defined in the ArmListener
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 ArmListener
- * @see #removeArmListener
- */
- public void addArmListener(ArmListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Arm, typedListener);
- }
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when the 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 the menu item is selected by the user, by sending it one of the
- * messages defined in the SelectionListener
interface.
- *
- * When widgetSelected
is called, the stateMask field of the
- * event object is valid. widgetDefaultSelected
is not called.
- *
- *
- * @param listener
- * the listener which should be notified when the menu item is
- * selected by the user
- *
- * @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);
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- static int checkStyle(int style) {
- return checkBits(style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);
- }
-
- @Override
- void destroyWidget() {
- parent.removeAction(getQAction());
- super.destroyWidget();
- }
-
- void fixMenus(Decorations newParent) {
- if (menu != null) {
- menu.fixMenus(newParent);
- }
- }
-
- /**
- * Returns the widget accelerator. An accelerator is the bit-wise OR of zero
- * or more modifier masks and a key. Examples:
- * SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2
. The default
- * value is zero, indicating that the menu item does not have an
- * accelerator.
- *
- * @return the accelerator or 0
- *
- *
- * @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 getAccelerator() {
- checkWidget();
- return accelerator;
- }
-
- /**
- * 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
- *
- *
- * @since 3.1
- */
- /* public */Rectangle getBounds() {
- checkWidget();
- return QtSWTConverter.convert(getQWidget().frameGeometry());
- }
-
- /**
- * Returns true
if the receiver is enabled, and
- * false
otherwise. A disabled menu item 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 getQAction().isEnabled();
- }
-
- /**
- * Gets the identifier associated with 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.7
- */
- public int getID () {
- checkWidget();
- return userId;
- }
-
- /**
- * Returns the receiver's cascade menu if it has one or null if it does not.
- * Only CASCADE
menu items can have a pull down menu. The
- * sequence of key strokes, button presses and/or button releases that are
- * used to request a pull down 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
- *
- */
- @Override
- public Menu getMenu() {
- checkWidget();
- return menu;
- }
-
- @Override
- String getNameText() {
- if ((style & SWT.SEPARATOR) != 0) {
- return "|";//$NON-NLS-1$
- }
- return super.getNameText();
- }
-
- /**
- * Returns the receiver's parent, which must be a Menu
.
- *
- * @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 Menu getParent() {
- checkWidget();
- return parent;
- }
-
- /**
- * 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.
- *
- * @return the selection 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 getSelection() {
- checkWidget();
- return getQAction().isChecked();
- }
-
- /**
- * Returns true
if the receiver is enabled and all of the
- * receiver's ancestors are enabled, and false
otherwise. A
- * disabled menu item 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() {
- return getEnabled() && parent.isEnabled();
- }
-
- @Override
- void releaseChildren(boolean destroy) {
- if (menu != null) {
- menu.release(false);
- menu = null;
- }
- super.releaseChildren(destroy);
- }
-
- @Override
- void releaseQWidget() {
- if ((style & SWT.RADIO) != 0) {
- parent.removeFromActionGroup(action);
- }
- parent.removeAction(action);
- display.removeControl(action);
- parent = null;
- action = null;
- id = -1;
- super.releaseQWidget();
- }
-
- @Override
- void releaseParent() {
- super.releaseParent();
- if (menu != null) {
- menu.dispose();
- }
- menu = null;
- }
-
- @Override
- void releaseWidget() {
- super.releaseWidget();
- accelerator = 0;
- display.removeMenuItem(this);
- }
-
- /**
- * Removes the listener from the collection of listeners who will be
- * notified when the arm 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 ArmListener
- * @see #addArmListener
- */
- public void removeArmListener(ArmListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (eventTable == null) {
- return;
- }
- eventTable.unhook(SWT.Arm, 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 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 selectRadio() {
- int index = 0;
- MenuItem[] items = parent.getItems();
- while (index < items.length && items[index] != this) {
- index++;
- }
- int i = index - 1;
- while (i >= 0 && items[i].setRadioSelection(false)) {
- --i;
- }
- int j = index + 1;
- while (j < items.length && items[j].setRadioSelection(false)) {
- j++;
- }
- setSelection(true);
- }
-
- /**
- * Sets the widget accelerator. An accelerator is the bit-wise OR of zero or
- * more modifier masks and a key. Examples:
- * SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2
.
- * SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2
. The default
- * value is zero, indicating that the menu item does not have an
- * accelerator.
- *
- * @param accelerator
- * an integer that is the bit-wise OR of masks and a key
- *
- *
- * @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 setAccelerator(int accelerator) {
- checkWidget();
- int seq = 0;
- if (this.accelerator == accelerator) {
- return;
- }
- this.accelerator = accelerator;
- /*
- * fetch the modifiers of the accelerator (something like
- * CTRL+SHIFT...). There can be more than one modifier.
- */
- for (Integer modifier : modifiers.keySet()) {
- if ((accelerator & modifier) != 0) {
- accelerator -= modifier;
- seq += modifiers.get(modifier);
- }
- }
-
- /*
- * Fetch uppercase characters and other ascii characters (+, =, ?...).
- * Only one of this chars is allowed.
- */
- if (accelerator >= 32 && accelerator <= 96 || accelerator >= 123 && accelerator <= 127) {
- seq += accelerator;
- accelerator -= accelerator;
- }
- /*
- * Transform lowercase characters to uppercase characters, because QT
- * can only handle uppercase characters and there is no difference
- * between CTRL+m and CTRL+M. Only one of this chars is allowed.
- */
- if (accelerator >= 97 && accelerator <= 122) {
- seq += accelerator - 32; // make a uppercase character out of a lowercase character
- accelerator -= accelerator;
- }
-
- /* fetch characters like F1, arrow keys or Page Up. Only one is allowed */
- if (accelerator != 0) {
- for (Integer acc : accelerators.keySet()) {
- if (accelerator == acc) {
- accelerator -= acc;
- seq += accelerators.get(acc);
- }
- }
- }
-
- if (accelerator != 0) { // something went wrong here. Not every character could be fetched.
- return;
- }
- getQAction().setShortcut(new QKeySequence(seq));
-
- }
-
- /*
- * private QKeySequence acceleratorToString(int accelerator) { int seq = 0;
- * if ((accelerator & SWT.MOD1) != 0 || (accelerator & SWT.CTRL) != 0) { //
- * on Windows systems SWT.MOD1 is the ctrl key accelerator -= SWT.MOD1; seq
- * += Qt.Modifier.CTRL.value(); } if ((accelerator & SWT.MOD2) != 0 ||
- * (accelerator & SWT.SHIFT) != 0) { // on Windows systems SWT.MOD2 is the
- * shift key accelerator -= SWT.MOD2; seq += Qt.Modifier.SHIFT.value(); } if
- * ((accelerator & SWT.MOD3) != 0 || (accelerator & SWT.ALT) != 0) {
- * accelerator -= SWT.MOD3; seq += Qt.Modifier.ALT.value(); } if
- * (accelerator >= 65 && accelerator <= 90) { seq += accelerator; } else if
- * (accelerator >= 97 && accelerator <= 122) { seq += accelerator - 32; //
- * this takes care of lowercase characters. CTRL+m should be the same as
- * CTRL+M } else if ((accelerator & SWT.ARROW_DOWN) != 0) { seq +=
- * Qt.Key.Key_Down.value(); } else if ((accelerator & SWT.ARROW_LEFT) != 0)
- * { seq += Qt.Key.Key_Left.value(); } else if ((accelerator &
- * SWT.ARROW_RIGHT) != 0) { seq += Qt.Key.Key_Right.value(); } else if
- * ((accelerator & SWT.ARROW_UP) != 0) { seq += Qt.Key.Key_Up.value(); }
- * else if ((accelerator & SWT.F1) != 0) { seq += Qt.Key.Key_F1.value(); }
- * return new QKeySequence(seq); }
- */
- /**
- * Enables the receiver if the argument is true
, and disables
- * it otherwise. A disabled menu item 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();
- getQAction().setEnabled(enabled);
- }
-
- /**
- * Sets the identifier associated with the receiver to the argument.
- *
- * @param id the new identifier. This must be a non-negative value. System-defined identifiers are negative values.
- *
- * @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
- * - ERROR_INVALID_ARGUMENT - if called with an negative-valued argument.
- *
- *
- * @since 3.7
- */
- public void setID (int id) {
- checkWidget();
- if (id < 0) error(SWT.ERROR_INVALID_ARGUMENT);
- userId = id;
- }
-
- /**
- * Sets the image the receiver will display to the argument.
- *
- * Note: This operation is a hint and is not supported on platforms that do
- * not have this concept (for example, Windows NT). Furthermore, some
- * platforms (such as GTK), cannot display both a check box and an image at
- * the same time. Instead, they hide the image and display the check box.
- *
- *
- * @param image
- * the image to display
- *
- * @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
- *
- */
- @Override
- public void setImage(Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) {
- return;
- }
- super.setImage(image);
- if (image != null) {
- getQAction().setIcon(image.getQIcon());
- } else {
- getQAction().setIcon((QIcon) null);
- }
- }
-
- /**
- * Sets the receiver's pull down menu to the argument. Only
- * CASCADE
menu items can have a pull down menu. The sequence
- * of key strokes, button presses and/or button releases that are used to
- * request a pull down menu is platform specific.
- *
- * Note: Disposing of a menu item that has a pull down menu will dispose of
- * the menu. To avoid this behavior, set the menu to null before the menu
- * item is disposed.
- *
- *
- * @param menu
- * the new pull down menu
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop
- * down menu
- * - ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a
- *
CASCADE
- * - 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 setMenu(Menu menu) {
- checkWidget();
-
- /* Check to make sure the new menu is valid */
- if ((style & SWT.CASCADE) == 0) {
- error(SWT.ERROR_MENUITEM_NOT_CASCADE);
- }
- if (menu != null) {
- if (menu.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if ((menu.style & SWT.DROP_DOWN) == 0) {
- error(SWT.ERROR_MENU_NOT_DROP_DOWN);
- }
- if (menu.parent != parent.parent) {
- error(SWT.ERROR_INVALID_PARENT);
- }
- }
- setMenu(menu, false);
- }
-
- void setMenu(Menu menu, boolean dispose) {
- if ((style & SWT.CASCADE) == 0) {
- error(SWT.ERROR_MENUITEM_NOT_CASCADE);
- }
- QMenu qMenu = null;
- if (menu != null) {
- if ((menu.style & SWT.DROP_DOWN) == 0) {
- error(SWT.ERROR_MENU_NOT_DROP_DOWN);
- }
- if (menu.parent != parent.parent) {
- error(SWT.ERROR_INVALID_PARENT);
- }
- qMenu = menu.getQMenu();
- }
- Menu oldMenu = this.menu;
- if (oldMenu == menu) {
- return;
- }
- if (oldMenu != null) {
- oldMenu.cascade = null;
- }
- this.menu = menu;
- getQAction().setMenu(qMenu);
- if (this.menu != null) {
- this.menu.cascade = this;
- }
- }
-
- boolean setRadioSelection(boolean value) {
- if ((style & SWT.RADIO) == 0) {
- return false;
- }
- if (getSelection() != value) {
- setSelection(value);
- postEvent(SWT.Selection);
- }
- return true;
- }
-
- /**
- * Sets the selection state of the receiver.
- *
- * When the receiver is of type CHECK
or RADIO
, it
- * is selected when it is checked.
- *
- * @param selected
- * the new selection 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 setSelection(boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) {
- return;
- }
- getQAction().setChecked(selected);
- }
-
- /**
- * Sets the receiver's text. The string may include the mnemonic character
- * and accelerator text.
- *
- * 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 emphasised in a platform specific manner.
- * The mnemonic indicator character '&' can be escaped by doubling it in
- * the string, causing a single '&' to be displayed.
- *
- *
- * Accelerator text is indicated by the '\t' character. On platforms that
- * support accelerator text, the text that follows the '\t' character is
- * displayed to the user, typically indicating the key stroke that will
- * cause the item to become selected. On most platforms, the accelerator
- * text appears right aligned in the menu. Setting the accelerator text does
- * not install the accelerator key sequence. The accelerator key sequence is
- * installed using #setAccelerator.
- *
- *
- * @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
- *
- *
- * @see #setAccelerator
- */
- @Override
- public void setText(String string) {
- checkWidget();
- if (string == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if ((style & SWT.SEPARATOR) != 0) {
- return;
- }
- if (text.equals(string)) {
- return;
- }
- super.setText(string);
- getQAction().setText(string);
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/MessageBox.java
deleted file mode 100644
index 297dd3161f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/MessageBox.java
+++ /dev/null
@@ -1,312 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-
-/**
- * Instances of this class are used to inform or warn the user.
- *
- * - Styles:
- * - ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING
- * - OK, OK | CANCEL
- * - YES | NO, YES | NO | CANCEL
- * - RETRY | CANCEL
- * - ABORT | RETRY | IGNORE
- * - Events:
- * - (none)
- *
- *
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION,
- * ICON_WARNING and ICON_WORKING may be specified.
- *
- *
- * 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 MessageBox extends Dialog {
- String message = ""; //$NON-NLS-1$
-
- /**
- * 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 MessageBox(Shell parent) {
- this(parent, SWT.OK | SWT.ICON_INFORMATION | 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 MessageBox(Shell parent, int style) {
- super(parent, checkStyle(parent, checkStyle(style)));
- checkSubclass();
- }
-
- static int checkStyle(int style) {
- int mask = SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE;
- int bits = style & mask;
- if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) {
- return style;
- }
- if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) {
- return style;
- }
- if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) {
- return style;
- }
- style = style & ~mask | SWT.OK;
- return style;
- }
-
- /**
- * Returns the dialog's message, or an empty string if it does not have one.
- * The message is a description of the purpose for which the dialog was
- * opened. This message will be visible in 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 the ID of the button that was selected to dismiss the message box
- * (e.g. SWT.OK, SWT.CANCEL, etc.)
- *
- * @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 int open() {
-
- /* Compute the MessageBox style */
- // int buttonBits = 0;
- // if ((style & SWT.OK) == SWT.OK) {
- // buttonBits = OS.MB_OK;
- // }
- // if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) {
- // buttonBits = OS.MB_OKCANCEL;
- // }
- // if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) {
- // buttonBits = OS.MB_YESNO;
- // }
- // if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) {
- // buttonBits = OS.MB_YESNOCANCEL;
- // }
- // if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) {
- // buttonBits = OS.MB_RETRYCANCEL;
- // }
- // if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) {
- // buttonBits = OS.MB_ABORTRETRYIGNORE;
- // }
- // if (buttonBits == 0) {
- // buttonBits = OS.MB_OK;
- // }
- //
- // int iconBits = 0;
- // if ((style & SWT.ICON_ERROR) != 0) {
- // iconBits = OS.MB_ICONERROR;
- // }
- // if ((style & SWT.ICON_INFORMATION) != 0) {
- // iconBits = OS.MB_ICONINFORMATION;
- // }
- // if ((style & SWT.ICON_QUESTION) != 0) {
- // iconBits = OS.MB_ICONQUESTION;
- // }
- // if ((style & SWT.ICON_WARNING) != 0) {
- // iconBits = OS.MB_ICONWARNING;
- // }
- // if ((style & SWT.ICON_WORKING) != 0) {
- // iconBits = OS.MB_ICONINFORMATION;
- // }
- //
- // /* Only MB_APPLMODAL is supported on WinCE */
- // int modalBits = 0;
- //
- // if ((style & SWT.PRIMARY_MODAL) != 0) {
- // modalBits = OS.MB_APPLMODAL;
- // }
- // if ((style & SWT.APPLICATION_MODAL) != 0) {
- // modalBits = OS.MB_TASKMODAL;
- // }
- // if ((style & SWT.SYSTEM_MODAL) != 0) {
- // modalBits = OS.MB_SYSTEMMODAL;
- // }
- //
- // int bits = buttonBits | iconBits | modalBits;
- // if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- // bits |= OS.MB_RTLREADING | OS.MB_RIGHT;
- // }
- // if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- // if (parent != null && (parent.style & SWT.MIRRORED) != 0) {
- // bits |= OS.MB_RTLREADING | OS.MB_RIGHT;
- // }
- // }
- //
- // /*
- // * Feature in Windows. System modal is not supported on Windows 95 and
- // * NT. The fix is to convert system modal to task modal.
- // */
- // if ((bits & OS.MB_SYSTEMMODAL) != 0) {
- // bits |= OS.MB_TASKMODAL;
- // bits &= ~OS.MB_SYSTEMMODAL;
- // /* Force a system modal message box to the front */
- // bits |= OS.MB_TOPMOST;
- // }
- //
- // /*
- // * Feature in Windows. In order for MB_TASKMODAL to work, the parent
- // * HWND of the MessageBox () call must be NULL. If the parent is not
- // * NULL, MB_TASKMODAL behaves the same as MB_APPLMODAL. The fix to set
- // * the parent HWND anyway and not rely on MB_MODAL to work by making the
- // * parent be temporarily modal.
- // */
- // int /* long */hwndOwner = 0; //parent != null ? parent.handle : 0;
- // Dialog oldModal = null;
- // Display display = null;
- // if ((bits & OS.MB_TASKMODAL) != 0) {
- // display = parent.getDisplay();
- // oldModal = display.getModalDialog();
- // display.setModalDialog(this);
- // }
- //
- // /* Open the message box */
- // /* Use the character encoding for the default locale */
- // TCHAR buffer1 = new TCHAR(0, message, true);
- // TCHAR buffer2 = new TCHAR(0, title, true);
- // int code = OS.MessageBox(hwndOwner, buffer1, buffer2, bits);
- //
- // /* Clear the temporarily dialog modal parent */
- // if ((bits & OS.MB_TASKMODAL) != 0) {
- // display.setModalDialog(oldModal);
- // }
- //
- // /*
- // * This code is intentionally commented. On some platforms, the owner
- // * window is repainted right away when a dialog window exits. This
- // * behavior is currently unspecified.
- // */
- // // if (hwndOwner != 0) OS.UpdateWindow (hwndOwner);
- //
- // /* Compute and return the result */
- // if (code != 0) {
- // int type = bits & 0x0F;
- // if (type == OS.MB_OK) {
- // return SWT.OK;
- // }
- // if (type == OS.MB_OKCANCEL) {
- // return code == OS.IDOK ? SWT.OK : SWT.CANCEL;
- // }
- // if (type == OS.MB_YESNO) {
- // return code == OS.IDYES ? SWT.YES : SWT.NO;
- // }
- // if (type == OS.MB_YESNOCANCEL) {
- // if (code == OS.IDYES) {
- // return SWT.YES;
- // }
- // if (code == OS.IDNO) {
- // return SWT.NO;
- // }
- // return SWT.CANCEL;
- // }
- // if (type == OS.MB_RETRYCANCEL) {
- // return code == OS.IDRETRY ? SWT.RETRY : SWT.CANCEL;
- // }
- // if (type == OS.MB_ABORTRETRYIGNORE) {
- // if (code == OS.IDRETRY) {
- // return SWT.RETRY;
- // }
- // if (code == OS.IDABORT) {
- // return SWT.ABORT;
- // }
- // return SWT.IGNORE;
- // }
- // }
- return SWT.CANCEL;
- }
-
- /**
- * 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/qt/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ProgressBar.java
deleted file mode 100644
index dc80139bfa..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ProgressBar.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.core.QSize;
-import com.trolltech.qt.gui.QProgressBar;
-import com.trolltech.qt.gui.QWidget;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.Point;
-
-/**
- * Instances of the receiver represent an unselectable user interface object
- * that is used to display progress, typically in the form of a bar.
- *
- * - Styles:
- * - SMOOTH, HORIZONTAL, VERTICAL, INDETERMINATE
- * - Events:
- * - (none)
- *
- *
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- *
- *
- * IMPORTANT: This class is intended to be subclassed only within the
- * SWT implementation.
- *
- *
- * @see ProgressBar
- * snippets
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ProgressBar extends Control {
- static final int DELAY = 100;
- int foreground = -1, background = -1;
- private int timerID = -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#SMOOTH
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public ProgressBar(Composite parent, int style) {
- super(parent, checkStyle(style));
- }
-
- @Override
- protected QWidget createQWidget(int style) {
- QProgressBar progressBar = new QProgressBar();
- return progressBar;
- }
-
- @Override
- protected void setupQWidget() {
- if ((style & SWT.INDETERMINATE) != 0) {
- getQProgressBar().setRange(0, 0);
- // Funny: this avoids a JVM crash: EXCEPTION_INT_DIVIDE_BY_ZERO (0xc0000094)
- // http://eclipse.compeople.eu/wiki/index.php/Compeople:SWTQtImplementierungsdetails#DIVISION_BY_ZERO
- getQProgressBar().setTextVisible(false);
- }
- // this causes a lot of events, commented for debugging
- //startTimer(getQProgressBar());
- super.setupQWidget();
- }
-
- private QProgressBar getQProgressBar() {
- return (QProgressBar) getQWidget();
- }
-
- static int checkStyle(int style) {
- style |= SWT.NO_FOCUS;
- return checkBits(style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
- }
-
- @Override
- public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
- QSize size = getQProgressBar().sizeHint();
- return new Point(size.width(), size.height());
- }
-
- /**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @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 getMaximum() {
- checkWidget();
- return getQProgressBar().maximum();
- }
-
- /**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @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 getMinimum() {
- checkWidget();
- return getQProgressBar().minimum();
- }
-
- /**
- * Returns the single 'selection' that is the receiver's position.
- *
- * @return the selection
- *
- * @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 getSelection() {
- checkWidget();
- return getQProgressBar().value();
- }
-
- /**
- * Returns the state of the receiver. The value will be one of:
- *
- * - {@link SWT#NORMAL}
- * - {@link SWT#ERROR}
- * - {@link SWT#PAUSED}
- *
- *
- * @return the 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 int getState() {
- checkWidget();
- return SWT.NORMAL;
- }
-
- @Override
- void releaseWidget() {
- stopTimer();
- super.releaseWidget();
- }
-
- void startTimer(QProgressBar progressBar) {
- stopTimer();
- // TODO dynamic interval for startTimer
- timerID = progressBar.startTimer(DELAY);
- }
-
- void stopTimer() {
- if (timerID != -1) {
- getQProgressBar().killTimer(timerID);
- }
- }
-
- /**
- * Sets the maximum value that the receiver will allow. This new value will
- * be ignored if it is not greater than the receiver's current minimum
- * value. If the new maximum is applied then the receiver's selection value
- * will be adjusted if necessary to fall within its new range.
- *
- * @param value
- * the new maximum, which must be greater than the current
- * minimum
- *
- * @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 setMaximum(int value) {
- checkWidget();
- getQProgressBar().setMaximum(value);
- }
-
- /**
- * Sets the minimum value that the receiver will allow. This new value will
- * be ignored if it is negative or is not less than the receiver's current
- * maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new
- * range.
- *
- * @param value
- * the new minimum, which must be nonnegative and less than the
- * current maximum
- *
- * @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 setMinimum(int value) {
- checkWidget();
- getQProgressBar().setMinimum(value);
- }
-
- /**
- * Sets the single 'selection' that is the receiver's position to the
- * argument which must be greater than or equal to zero.
- *
- * @param value
- * the new selection (must be zero or greater)
- *
- * @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(int value) {
- checkWidget();
- getQProgressBar().setValue(value);
- }
-
- /**
- * Sets the state of the receiver. The state must be one of these values:
- *
- * - {@link SWT#NORMAL}
- * - {@link SWT#ERROR}
- * - {@link SWT#PAUSED}
- *
- *
- * @param state
- * the new 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 setState(int state) {
- checkWidget();
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Sash.java
deleted file mode 100644
index 399d863b45..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Sash.java
+++ /dev/null
@@ -1,387 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.core.QObject;
-import com.trolltech.qt.core.QPoint;
-import com.trolltech.qt.core.QRect;
-import com.trolltech.qt.core.Qt.CursorShape;
-import com.trolltech.qt.core.Qt.MouseButton;
-import com.trolltech.qt.gui.QCursor;
-import com.trolltech.qt.gui.QFrame;
-import com.trolltech.qt.gui.QMouseEvent;
-import com.trolltech.qt.gui.QWidget;
-import com.trolltech.qt.gui.QFrame.Shadow;
-import com.trolltech.qt.gui.QFrame.Shape;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Point;
-
-/**
- * Instances of the receiver represent a selectable user interface object that
- * allows the user to drag a rubber banded outline of the sash within the parent
- * control.sw
- *
- * - Styles:
- * - HORIZONTAL, VERTICAL, SMOOTH
- * - Events:
- * - Selection
- *
- *
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- *
- *
- * IMPORTANT: This class is intended to be subclassed only within the
- * SWT implementation.
- *
- *
- * @see Sash snippets
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Sash extends Control {
- private boolean dragging;
- private int startX, startY, lastX, lastY;
-
- /**
- * 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#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public Sash(Composite parent, int style) {
- super(parent, checkStyle(style));
- }
-
- @Override
- protected QWidget createQWidget(int style) {
- state |= THEME_BACKGROUND;
- return new QFrame();
- }
-
- protected QFrame getQFrame() {
- return (QFrame) getQWidget();
- }
-
- @Override
- protected void checkAndUpdateBorder() {
- if ((style & SWT.BORDER) != 0) {
- getQFrame().setFrameShape(Shape.Panel);
- getQFrame().setFrameShadow(Shadow.Sunken);
- } else {
- getQFrame().setFrameShape(Shape.NoFrame);
- }
- }
-
- /**
- * 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.
- *
- * When widgetSelected
is called, the x, y, width, and height
- * fields of the event object are valid. If the receiver is being dragged,
- * the event object detail field contains the value SWT.DRAG
.
- * widgetDefaultSelected
is not called.
- *
- *
- * @param listener
- * the listener which should be notified when the control is
- * selected by the user
- *
- * @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);
- }
-
- static int checkStyle(int style) {
- return checkBits(style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
- }
-
- @Override
- public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth();
- int width = border * 2, height = border * 2;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += DEFAULT_WIDTH;
- height += 3;
- } else {
- width += 3;
- height += DEFAULT_HEIGHT;
- }
- if (wHint != SWT.DEFAULT) {
- width = wHint + border * 2;
- }
- if (hHint != SWT.DEFAULT) {
- height = hHint + border * 2;
- }
- return new Point(width, height);
- }
-
- /**
- * 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);
- }
-
- @Override
- public boolean qtMouseMoveEvent(QObject source, QMouseEvent mouseEvent) {
- if (source == getQWidget()) {
- return handleMouseMove(mouseEvent);
- }
- return super.qtMouseMoveEvent(source, mouseEvent);
- }
-
- @Override
- public boolean qtMouseButtonPressEvent(QObject source, QMouseEvent mouseEvent) {
- if (super.qtMouseButtonPressEvent(source, mouseEvent)) {
- return true; // cancel;
- }
- return handleMousePress(mouseEvent);
- }
-
- @Override
- public boolean qtMouseButtonReleaseEvent(QObject source, QMouseEvent mouseEvent) {
- if (super.qtMouseButtonReleaseEvent(source, mouseEvent)) {
- return true; // cancel
- }
- return handleMouseRelease(mouseEvent);
- }
-
- private boolean handleMousePress(QMouseEvent mouseEvent) {
- if (!isLeftMouseButton(mouseEvent)) {
- return false;
- }
- QPoint pt = mouseEvent.globalPos();
- QRect rect = getQWidget().frameGeometry();
- startX = pt.x() - rect.left();
- startY = pt.y() - rect.top();
- lastX = rect.left();
- lastY = rect.top();
- int width = rect.width();
- int height = rect.height();
-
- Event event = new Event();
- event.x = lastX;
- event.y = lastY;
- event.width = width;
- event.height = height;
- if ((style & SWT.SMOOTH) == 0) {
- event.detail = SWT.DRAG;
- }
- sendEvent(SWT.Selection, event);
- if (isDisposed()) {
- return true;
- }
-
- /* Draw the banding rectangle */
- if (event.doit) {
- dragging = true;
- lastX = event.x;
- lastY = event.y;
- menuShell().bringToTop();
- if (isDisposed()) {
- return true;
- }
- if ((style & SWT.SMOOTH) != 0) {
- setBounds(event.x, event.y, width, height, true, true);
- // widget could be disposed at this point
- }
- }
- return false;
- }
-
- private boolean isLeftMouseButton(QMouseEvent mouseEvent) {
- return MouseButton.LeftButton.equals(mouseEvent.button()) || mouseEvent.buttons().isSet(MouseButton.LeftButton);
- }
-
- private boolean handleMouseRelease(QMouseEvent mouseEvent) {
- if (!(dragging && isLeftMouseButton(mouseEvent))) {
- return false;
- }
-
- dragging = false;
- QRect rect = getQWidget().frameGeometry();
- int width = rect.width();
- int height = rect.height();
-
- Event event = new Event();
- event.x = lastX;
- event.y = lastY;
- event.width = width;
- event.height = height;
- sendEvent(SWT.Selection, event);
- if (isDisposed()) {
- return true;
- }
- if (event.doit) {
- if ((style & SWT.SMOOTH) != 0) {
- setBounds(event.x, event.y, width, height, true, true);
- // widget could be disposed at this point
- }
- }
- return false;
- }
-
- private boolean handleMouseMove(QMouseEvent mouseEvent) {
- if (!(dragging && isLeftMouseButton(mouseEvent))) {
- return false;
- }
-
- QPoint pt = mouseEvent.globalPos();
- QRect rect = getQWidget().frameGeometry();
- int width = rect.width();
- int height = rect.height();
- QRect clientRect = getQWidget().parentWidget().frameGeometry();
-
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- int clientWidth = clientRect.width();
- newX = Math.min(Math.max(0, pt.x() - startX), clientWidth - width);
- } else {
- int clientHeight = clientRect.height();
- newY = Math.min(Math.max(0, pt.y() - startY), clientHeight - height);
- }
- if (newX == lastX && newY == lastY) {
- return false;
- }
-
- /* The event must be sent because doit flag is used */
- Event event = new Event();
- event.x = newX;
- event.y = newY;
- event.width = width;
- event.height = height;
- if ((style & SWT.SMOOTH) == 0) {
- event.detail = SWT.DRAG;
- }
- sendEvent(SWT.Selection, event);
- if (isDisposed()) {
- return true;
- }
-
- if (event.doit) {
- lastX = event.x;
- lastY = event.y;
- }
- if ((style & SWT.SMOOTH) != 0) {
- setBounds(lastX, lastY, width, height, true, true);
- // widget could be disposed at this point
- }
- return false;
- }
-
- @Override
- public boolean qtMouseEnterEvent(Object source) {
- if (source == getQWidget()) {
- if ((style & SWT.HORIZONTAL) != 0) {
- getQWidget().setCursor(new QCursor(CursorShape.SizeVerCursor));
- } else {
- getQWidget().setCursor(new QCursor(CursorShape.SizeHorCursor));
- }
- }
- return super.qtMouseEnterEvent(source);
- }
-
- @Override
- public boolean qtMouseLeaveEvent(Object source) {
- if (source == getQWidget()) {
- getQWidget().setCursor(new QCursor(CursorShape.ArrowCursor));
- }
- return super.qtMouseLeaveEvent(source);
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Scale.java
deleted file mode 100644
index b7ee6cb7c0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Scale.java
+++ /dev/null
@@ -1,494 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.core.Qt.Orientation;
-import com.trolltech.qt.gui.QAbstractSlider;
-import com.trolltech.qt.gui.QSlider;
-import com.trolltech.qt.gui.QWidget;
-import com.trolltech.qt.gui.QSlider.TickPosition;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Point;
-
-/**
- * Instances of the receiver represent a selectable user interface object that
- * present a range of continuous numeric values.
- *
- * - Styles:
- * - HORIZONTAL, VERTICAL
- * - Events:
- * - Selection
- *
- *
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- *
- *
- *
- * IMPORTANT: This class is intended to be subclassed only within the
- * SWT implementation.
- *
- *
- * @see Scale snippets
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Scale extends 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#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public Scale(Composite parent, int style) {
- super(parent, checkStyle(style));
- }
-
- @Override
- protected QWidget createQWidget(int style) {
- final Orientation orientation = (style & SWT.HORIZONTAL) != 0 ? Orientation.Horizontal : Orientation.Vertical;
- return new QSlider(orientation);
- }
-
- @Override
- protected void setupQWidget() {
- super.setupQWidget();
- setMinimum(0);
- setMaximum(100);
- setIncrement(1);
- setPageIncrement(10);
- getQSlider().setTickPosition(TickPosition.TicksBothSides);
- }
-
- QSlider getQSlider() {
- return (QSlider) getQWidget();
- }
-
- @Override
- protected void connectSignals() {
- getQSlider().actionTriggered.connect(this, "actionTriggered(int)"); //$NON-NLS-1$
- getQSlider().rangeChanged.connect(this, "rangeChanged(int,int)"); //$NON-NLS-1$
- getQSlider().sliderMoved.connect(this, "sliderMoved(int)"); //$NON-NLS-1$
- getQSlider().sliderPressed.connect(this, "sliderPressed()"); //$NON-NLS-1$
- getQSlider().sliderReleased.connect(this, "sliderReleased()"); //$NON-NLS-1$
- getQSlider().valueChanged.connect(this, "valueChanged(int)"); //$NON-NLS-1$
- }
-
- protected void actionTriggered(int action) {
- System.out.println("actionTriggered :" + action + " " + getQSlider().value()); //$NON-NLS-1$//$NON-NLS-2$
- Event event = new Event();
- if (action == QAbstractSlider.SliderAction.SliderToMinimum.value()) {
- event.detail = SWT.HOME;
- } else if (action == QAbstractSlider.SliderAction.SliderToMaximum.value()) {
- event.detail = SWT.END;
- } else if (action == QAbstractSlider.SliderAction.SliderSingleStepAdd.value()) {
- event.detail = SWT.ARROW_DOWN;
- } else if (action == QAbstractSlider.SliderAction.SliderSingleStepSub.value()) {
- event.detail = SWT.ARROW_UP;
- } else if (action == QAbstractSlider.SliderAction.SliderPageStepAdd.value()) {
- event.detail = SWT.PAGE_UP;
- } else if (action == QAbstractSlider.SliderAction.SliderPageStepSub.value()) {
- event.detail = SWT.PAGE_DOWN;
- } else if (action == QAbstractSlider.SliderAction.SliderMove.value()) {
- event.detail = SWT.DRAG;
- } else {
- return;
- }
- // see actionTrigger signal
- getQSlider().setValue(getQSlider().sliderPosition());
- sendEvent(SWT.Selection, event);
- }
-
- // TODO: implement the events
- protected void rangeChanged(int min, int max) {
- System.out.println("rangeChanged :" + min + ", " + max); //$NON-NLS-1$//$NON-NLS-2$
- }
-
- protected void sliderMoved(int pos) {
- System.out.println("sliderMoved :" + pos); //$NON-NLS-1$
- }
-
- protected void sliderPressed() {
- System.out.println("sliderPressed"); //$NON-NLS-1$
- }
-
- protected void sliderReleased() {
- System.out.println("sliderReleased"); //$NON-NLS-1$
- Event event = new Event();
- event.detail = SWT.NONE;
- sendEvent(SWT.Selection, event);
- }
-
- protected void valueChanged(int value) {
- System.out.println("valueChanged :" + value); //$NON-NLS-1$
- }
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when the user changes the receiver's value, by sending it one of the
- * messages defined in the SelectionListener
interface.
- *
- * widgetSelected
is called when the user changes the
- * receiver's value. widgetDefaultSelected
is not called.
- *
- *
- * @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
- */
- 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);
- }
-
- static int checkStyle(int style) {
- return checkBits(style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
- }
-
- @Override
- public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth();
- int width = border * 2;
- int height = border * 2;
- // default size: this is just the two arrows + thumb
- Point defaultSize = super.computeSize(wHint, hHint, changed);
- if ((style & SWT.HORIZONTAL) != 0) {
- width += defaultSize.y * 6;
- height += defaultSize.y;
- } else {
- width += defaultSize.x;
- height += defaultSize.x * 6;
- }
- if (wHint != SWT.DEFAULT) {
- width = wHint + border * 2;
- }
- if (hHint != SWT.DEFAULT) {
- height = hHint + border * 2;
- }
- return new Point(width, height);
- }
-
- // TODO What should happen here?
- // int defaultForeground() {
- // return display.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
- // }
-
- /**
- * Returns the amount that the receiver's value will be modified by when the
- * up/down (or right/left) arrows are pressed.
- *
- * @return the increment
- *
- * @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 getIncrement() {
- checkWidget();
- return getQSlider().singleStep();
- }
-
- /**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @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 getMaximum() {
- checkWidget();
- return getQSlider().maximum();
- }
-
- /**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @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 getMinimum() {
- checkWidget();
- return getQSlider().minimum();
- }
-
- /**
- * Returns the amount that the receiver's value will be modified by when the
- * page increment/decrement areas are selected.
- *
- * @return the page increment
- *
- * @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 getPageIncrement() {
- checkWidget();
- return getQSlider().pageStep();
- }
-
- /**
- * Returns the 'selection', which is the receiver's position.
- *
- * @return the selection
- *
- * @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 getSelection() {
- checkWidget();
- return getQSlider().value();
- }
-
- /**
- * Removes the listener from the collection of listeners who will be
- * notified when the user changes the receiver's value.
- *
- * @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);
- }
-
- /**
- * Sets the amount that the receiver's value will be modified by when the
- * up/down (or right/left) arrows are pressed to the argument, which must be
- * at least one.
- *
- * @param increment
- * the new increment (must be greater than 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
- *
- */
- public void setIncrement(int increment) {
- checkWidget();
- if (increment < 1) {
- return;
- }
- if (increment > getMaximum() - getMinimum()) {
- return;
- }
- getQSlider().setSingleStep(increment);
- }
-
- /**
- * Sets the maximum value that the receiver will allow. This new value will
- * be ignored if it is not greater than the receiver's current minimum
- * value. If the new maximum is applied then the receiver's selection value
- * will be adjusted if necessary to fall within its new range.
- *
- * @param value
- * the new maximum, which must be greater than the current
- * minimum
- *
- * @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 setMaximum(int value) {
- checkWidget();
- if (0 <= getMinimum() && getMinimum() < value) {
- getQSlider().setMaximum(value);
- }
- }
-
- /**
- * Sets the minimum value that the receiver will allow. This new value will
- * be ignored if it is negative or is not less than the receiver's current
- * maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new
- * range.
- *
- * @param value
- * the new minimum, which must be nonnegative and less than the
- * current maximum
- *
- * @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 setMinimum(int value) {
- checkWidget();
- if (0 <= value && value < getMaximum()) {
- getQSlider().setMinimum(value);
- }
- }
-
- /**
- * Sets the amount that the receiver's value will be modified by when the
- * page increment/decrement areas are selected to the argument, which must
- * be at least one.
- *
- * @param pageIncrement
- * the page increment (must be greater than 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
- *
- */
- public void setPageIncrement(int pageIncrement) {
- checkWidget();
- if (pageIncrement < 1) {
- return;
- }
- if (pageIncrement > getMaximum() - getMinimum()) {
- return;
- }
- getQSlider().setPageStep(pageIncrement);
- getQSlider().setTickInterval(pageIncrement);
- }
-
- /**
- * Sets the 'selection', which is the receiver's value, to the argument
- * which must be greater than or equal to zero.
- *
- * @param value
- * the new selection (must be zero or greater)
- *
- * @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(int value) {
- checkWidget();
- getQSlider().setValue(value);
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ScrollBar.java
deleted file mode 100644
index 1b839a5fab..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ScrollBar.java
+++ /dev/null
@@ -1,876 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.gui.QScrollBar;
-import com.trolltech.qt.gui.QAbstractSlider.SliderAction;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.internal.qt.QtSWTConverter;
-
-/**
- * Instances of this class are selectable user interface objects that represent
- * a range of positive, numeric values.
- *
- * At any given moment, a given scroll bar will have a single 'selection' that
- * is considered to be its value, which is constrained to be within the range of
- * values the scroll bar represents (that is, between its minimum and
- * maximum values).
- *
- *
- * Typically, scroll bars will be made up of five areas:
- *
- * - an arrow button for decrementing the value
- * - a page decrement area for decrementing the value by a larger amount
- * - a thumb for modifying the value by mouse dragging
- * - a page increment area for incrementing the value by a larger amount
- * - an arrow button for incrementing the value
- *
- * Based on their style, scroll bars are either HORIZONTAL
(which
- * have a left facing button for decrementing the value and a right facing
- * button for incrementing it) or VERTICAL
(which have an upward
- * facing button for decrementing the value and a downward facing buttons for
- * incrementing it).
- *
- *
- * On some platforms, the size of the scroll bar's thumb can be varied relative
- * to the magnitude of the range of values it represents (that is, relative to
- * the difference between its maximum and minimum values). Typically, this is
- * used to indicate some proportional value such as the ratio of the visible
- * area of a document to the total amount of space that it would take to display
- * it. SWT supports setting the thumb size even if the underlying platform does
- * not, but in this case the appearance of the scroll bar will not change.
- *
- *
- * Scroll bars are created by specifying either H_SCROLL
,
- * V_SCROLL
or both when creating a Scrollable
. They
- * are accessed from the Scrollable
using
- * getHorizontalBar
and getVerticalBar
.
- *
- *
- * Note: Scroll bars are not Controls. On some platforms, scroll bars that
- * appear as part of some standard controls such as a text or list have no
- * operating system resources and are not children of the control. For this
- * reason, scroll bars are treated specially. To create a control that looks
- * like a scroll bar but has operating system resources, use Slider
- * .
- *
- *
- * - Styles:
- * - HORIZONTAL, VERTICAL
- * - Events:
- * - Selection
- *
- *
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Slider
- * @see Scrollable
- * @see Scrollable#getHorizontalBar
- * @see Scrollable#getVerticalBar
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class ScrollBar extends Widget {
- private Scrollable parent;
- private boolean visible = true;
- private boolean enabled = true;
-
- /**
- * 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#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- ScrollBar(Scrollable parent, int style) {
- super(parent, checkStyle(style));
- this.parent = parent;
- createWidget(style);
- connectSignals();
- }
-
- static int checkStyle(int style) {
- return checkBits(style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
- }
-
- private void createWidget(int style) {
- if (!parent.isQScrollArea()) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- QScrollBar scrollBar = null;
- if ((style & SWT.HORIZONTAL) != 0) {
- scrollBar = parent.getQScrollArea().horizontalScrollBar();
- } else {
- scrollBar = parent.getQScrollArea().verticalScrollBar();
- }
- if (scrollBar == null) {
- SWT.error(SWT.ERROR_UNSPECIFIED);
- }
- setQWidget(scrollBar);
- scrollBar.setMinimum(0);
- scrollBar.setSliderPosition(0);
- scrollBar.setTracking(false);
- }
-
- private void connectSignals() {
- QScrollBar sb = getQScrollBar();
- sb.sliderMoved.connect(this, "dragging()"); //$NON-NLS-1$
- sb.sliderReleased.connect(this, "dragEnd()"); //$NON-NLS-1$
- sb.actionTriggered.connect(this, "actionTriggered(int)"); //$NON-NLS-1$
- }
-
- void dragging() {
- postSliderEvent(SWT.DRAG);
- }
-
- void dragEnd() {
- postSliderEvent(SWT.NONE);
- }
-
- void actionTriggered(int code) {
- SliderAction action = SliderAction.resolve(code);
- switch (action) {
- case SliderSingleStepSub: // button up
- postSliderEvent(SWT.ARROW_UP);
- break;
- case SliderSingleStepAdd: // button down
- postSliderEvent(SWT.ARROW_DOWN);
- break;
- case SliderPageStepSub: // page up
- postSliderEvent(SWT.PAGE_UP);
- break;
- case SliderPageStepAdd: // page down
- postSliderEvent(SWT.PAGE_DOWN);
- break;
- case SliderToMinimum: // at start
- postSliderEvent(SWT.HOME);
- break;
- case SliderToMaximum: // at end
- postSliderEvent(SWT.END);
- break;
- case SliderMove: // at end
- postSliderEvent(SWT.DRAG);
- break;
- default:
- System.err.println("unknown action: " + action); //$NON-NLS-1$
- }
- }
-
- QScrollBar getQScrollBar() {
- return (QScrollBar) getQWidget();
- }
-
- private void postSliderEvent(int subType) {
- Event event = new Event();
- event.detail = subType;
- postEvent(SWT.Selection, event);
- }
-
- @Override
- void releaseQWidget() {
- super.releaseQWidget();
- parent = null;
- }
-
- @Override
- void releaseParent() {
- super.releaseParent();
- parent.releaseBar(this);
- }
-
- @Override
- void destroyWidget() {
- parent.destroyScrollBar(style);
- }
-
- /**
- * Returns the receiver's parent, which must be a Scrollable.
- *
- * @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 Scrollable getParent() {
- checkWidget();
- return parent;
- }
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when the user changes the receiver's value, by sending it one of the
- * messages defined in the SelectionListener
interface.
- *
- * When widgetSelected
is called, the event object detail field
- * contains one of the following values: SWT.NONE
- for the end
- * of a drag. SWT.DRAG
. SWT.HOME
.
- * SWT.END
. SWT.ARROW_DOWN
.
- * SWT.ARROW_UP
. SWT.PAGE_DOWN
.
- * SWT.PAGE_UP
. widgetDefaultSelected
is not
- * called.
- *
- *
- * @param listener
- * the listener which should be notified when the user changes
- * the receiver's value
- *
- * @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);
- }
-
- /**
- * Removes the listener from the collection of listeners who will be
- * notified when the user changes the receiver's value.
- *
- * @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);
- }
-
- /**
- * Returns the amount that the receiver's value will be modified by when the
- * up/down (or right/left) arrows are pressed.
- *
- * @return the increment
- *
- * @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 getIncrement() {
- checkWidget();
- return getQScrollBar().singleStep();
- }
-
- /**
- * Sets the amount that the receiver's value will be modified by when the
- * up/down (or right/left) arrows are pressed to the argument, which must be
- * at least one.
- *
- * @param value
- * the new increment (must be greater than 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
- *
- */
- public void setIncrement(int value) {
- checkWidget();
- if (value < 1) {
- return;
- }
- getQScrollBar().setSingleStep(value);
- }
-
- /**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @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 getMaximum() {
- checkWidget();
- return getQScrollBar().maximum(); // + getQScrollBar().pageStep();
- }
-
- /**
- * Sets the maximum. If this value is negative or less than or equal to the
- * minimum, the value is ignored. If necessary, first the thumb and then the
- * selection are adjusted to fit within the new range.
- *
- * @param value
- * the new maximum
- *
- * @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 setMaximum(int value) {
- checkWidget();
- if (value < 0) {
- return;
- }
- QScrollBar scrollBar = getQScrollBar();
- int min = scrollBar.minimum();
- if (value <= min) {
- return;
- }
-
- // int maxValue = value - scrollBar.pageStep();
- // if (maxValue < min) {
- // scrollBar.setPageStep(value - min);
- // maxValue = min;
- // }
- //
- // if (scrollBar.value() > maxValue) {
- // scrollBar.setValue(maxValue);
- // }
- scrollBar.setMaximum(value);
- }
-
- /**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @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 getMinimum() {
- checkWidget();
- return getQScrollBar().minimum();
- }
-
- /**
- * Sets the minimum value. If this value is negative or greater than or
- * equal to the maximum, the value is ignored. If necessary, first the thumb
- * and then the selection are adjusted to fit within the new range.
- *
- * @param value
- * the new minimum
- *
- * @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 setMinimum(int value) {
- checkWidget();
- if (value < 0) {
- return;
- }
- QScrollBar scrollBar = getQScrollBar();
- int max = scrollBar.maximum();
- if (value >= max) {
- return;
- }
- //
- // if (max + pageStep - value < pageStep) {
- // scrollBar.setPageStep(max + pageStep - value);
- // scrollBar.setMaximum(value);
- // }
- //
- // if (scrollBar.value() < value) {
- // scrollBar.setValue(value);
- // }
- scrollBar.setMinimum(value);
- }
-
- /**
- * Returns the amount that the receiver's value will be modified by when the
- * page increment/decrement areas are selected.
- *
- * @return the page increment
- *
- * @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 getPageIncrement() {
- checkWidget();
- return getQScrollBar().pageStep();
- }
-
- /**
- * Sets the amount that the receiver's value will be modified by when the
- * page increment/decrement areas are selected to the argument, which must
- * be at least one.
- *
- * @param value
- * the page increment (must be greater than 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
- *
- */
- public void setPageIncrement(int value) {
- checkWidget();
- if (value < 1) {
- return;
- }
- getQScrollBar().setPageStep(value);
- }
-
- /**
- * Returns the single 'selection' that is the receiver's value.
- *
- * @return the selection
- *
- * @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 getSelection() {
- checkWidget();
- return getQScrollBar().sliderPosition();
- }
-
- /**
- * Sets the single selection that is the receiver's value to the
- * argument which must be greater than or equal to zero.
- *
- * @param selection
- * the new selection (must be zero or greater)
- *
- * @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(int selection) {
- checkWidget();
- int min = getQScrollBar().minimum();
- if (selection < min) {
- selection = min;
- } else {
- int max = getQScrollBar().maximum();
- if (selection > max) {
- selection = max;
- }
- }
- int value = getQScrollBar().value();
- if (value != selection) {
- getQScrollBar().setSliderPosition(selection);
- }
- //System.out.println(this);
- }
-
- /**
- * 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();
- if (!isVisible()) {
- parent.updateQLayouts();
- }
- return QtSWTConverter.convert(getQWidget().size());
- }
-
- /**
- * Returns the size of the receiver's thumb relative to the difference
- * between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @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 ScrollBar
- */
- public int getThumb() {
- checkWidget();
- return getQScrollBar().pageStep();
- }
-
- /**
- * Sets the size of the receiver's thumb relative to the difference between
- * its maximum and minimum values. This new value will be ignored if it is
- * less than one, and will be clamped if it exceeds the receiver's current
- * range.
- *
- * @param value
- * the new thumb value, which must be at least one and not larger
- * than the size of the current range
- *
- * @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 setThumb(int value) {
- checkWidget();
- if (value < 1) {
- return;
- }
- if (value < 1) {
- return;
- }
- int pageStep = getQScrollBar().pageStep();
- if (value == pageStep) {
- return;
- }
-
- int qMax = getQScrollBar().maximum();
- int range = qMax + pageStep - getQScrollBar().minimum();
- if (value > range) {
- value = range;
- }
- int newQMaximum = qMax - (value - pageStep);
- if (getQScrollBar().value() > newQMaximum) {
- getQScrollBar().setValue(newQMaximum);
- }
-
- getQScrollBar().setPageStep(value);
-
- getQScrollBar().setMaximum(newQMaximum);
- }
-
- /**
- * Sets the receiver's selection, minimum value, maximum value, thumb,
- * increment and page increment all at once.
- *
- * Note: This is similar to setting the values individually using the
- * appropriate methods, but may be implemented in a more efficient fashion
- * on some platforms.
- *
- *
- * @param selection
- * the new selection value
- * @param minimum
- * the new minimum value
- * @param maximum
- * the new maximum value
- * @param thumb
- * the new thumb value
- * @param increment
- * the new increment value
- * @param pageIncrement
- * the new pageIncrement value
- *
- * @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 setValues(int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- setSelection(selection);
- setMinimum(minimum);
- setMaximum(maximum);
- setThumb(thumb);
- setIncrement(increment);
- setPageIncrement(pageIncrement);
- }
-
- /**
- * 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 this.visible;
- }
-
- /**
- * 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 getQWidget().isVisible() && parent.isVisible();
- }
-
- /**
- * 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 == getVisible()) {
- return;
- }
- this.visible = visible;
- getQWidget().setVisible(visible);
- }
-
- /**
- * 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 enabled;
- }
-
- /**
- * Returns true
if the receiver is enabled and all of the
- * receiver's ancestors are 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 #getEnabled
- */
- public boolean isEnabled() {
- checkWidget();
- return getQWidget().isEnabled() && parent.isEnabled();
- }
-
- /**
- * 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();
- this.enabled = enabled;
- getQWidget().setEnabled(enabled);
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("ScrollBar{"); //$NON-NLS-1$
- sb.append("orient: "); //$NON-NLS-1$
- sb.append(((style & SWT.HORIZONTAL) != 0 ? "HORI" : "VERT")); //$NON-NLS-1$ //$NON-NLS-2$
- sb.append(", selection: "); //$NON-NLS-1$
- sb.append(getSelection());
- sb.append(", minimum: "); //$NON-NLS-1$
- sb.append(getMinimum());
- sb.append(", maximum: "); //$NON-NLS-1$
- sb.append(getMaximum());
- sb.append(", thumb: "); //$NON-NLS-1$
- sb.append(getThumb());
- sb.append(", increment: "); //$NON-NLS-1$
- sb.append(getIncrement());
- sb.append(", pageIncrement: "); //$NON-NLS-1$
- sb.append(getPageIncrement());
- sb.append("}"); //$NON-NLS-1$
- return sb.toString();
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Scrollable.java
deleted file mode 100644
index a9b7b8738a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Scrollable.java
+++ /dev/null
@@ -1,430 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.core.QSize;
-import com.trolltech.qt.core.Qt.FocusPolicy;
-import com.trolltech.qt.core.Qt.ScrollBarPolicy;
-import com.trolltech.qt.gui.QAbstractScrollArea;
-import com.trolltech.qt.gui.QLayout;
-import com.trolltech.qt.gui.QScrollArea;
-import com.trolltech.qt.gui.QWidget;
-import com.trolltech.qt.gui.QFrame.Shape;
-import com.trolltech.qt.gui.QSizePolicy.Policy;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.internal.qt.QtSWTConverter;
-import org.eclipse.swt.internal.qt.StylableScrollArea;
-
-/**
- * This class is the abstract superclass of all classes which represent controls
- * that have standard scroll bars.
- *
- * - Styles:
- * - H_SCROLL, V_SCROLL
- * - Events:
- *
- (none)
- *
- *
- * IMPORTANT: This class is intended to be subclassed only within the
- * SWT implementation.
- *
- *
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public abstract class Scrollable extends Control {
- private ScrollBar horizontalBar;
- private ScrollBar verticalBar;
- private QWidget masterWidget;
- private QWidget contentWidget;
-
- /**
- * Prevents uninitialized instances from being created outside the package.
- */
- Scrollable() {
- }
-
- /**
- * 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#H_SCROLL
- * @see SWT#V_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public Scrollable(Composite parent, int style) {
- super(parent, style);
- createScrollBars(style);
- }
-
- @Override
- QWidget createQWidget(int style) {
- QScrollArea scrollArea = new StylableScrollArea();
- scrollArea.setFrameShape(Shape.NoFrame);
- scrollArea.setFocusPolicy(FocusPolicy.TabFocus);
- scrollArea.setWidgetResizable(!isScrollingEnabled());
- setQMasterWidget(scrollArea);
-
- contentWidget = new QWidget();
- contentWidget.setSizePolicy(Policy.MinimumExpanding, Policy.MinimumExpanding);
- contentWidget.setProperty("widgetType", "scrollareaContent"); //$NON-NLS-1$//$NON-NLS-2$
- contentWidget.setContentsMargins(0, 0, 0, 0);
- contentWidget.resize(0, 0);
-
- scrollArea.setWidget(contentWidget);
- scrollArea.resize(0, 0);
-
- return contentWidget;
- }
-
- @Override
- boolean isQScrollArea() {
- return getQMasterWidget() instanceof QAbstractScrollArea;
- }
-
- protected void setQMasterWidget(QWidget masterWidget) {
- this.masterWidget = masterWidget;
- }
-
- @Override
- protected QWidget getQMasterWidget() {
- if (masterWidget != null) {
- return masterWidget;
- }
- return super.getQMasterWidget();
- }
-
- @Override
- protected void updateFocusPolicy() {
- super.updateFocusPolicy();
- if ((style & SWT.NO_FOCUS) != 0) {
- if (isQScrollArea()) {
- getQMasterWidget().setFocusPolicy(FocusPolicy.NoFocus);
- }
- }
- }
-
- QAbstractScrollArea getQScrollArea() {
- return (QAbstractScrollArea) getQMasterWidget();
- }
-
- private StylableScrollArea getStylableScrollArea() {
- return (StylableScrollArea) getQMasterWidget();
- }
-
- private void createScrollBars(int style) {
- if (isQScrollArea()) {
- if ((style & SWT.H_SCROLL) != 0) {
- setHBarPolicy(true);
- if (horizontalBar == null) {
- horizontalBar = createScrollBar(SWT.HORIZONTAL);
- }
- } else {
- setHBarPolicy(false);
- }
-
- if ((style & SWT.V_SCROLL) != 0) {
- setVBarPolicy(true);
- if (verticalBar == null) {
- verticalBar = createScrollBar(SWT.VERTICAL);
- }
- } else {
- setVBarPolicy(false);
- }
- }
- }
-
- protected boolean isScrollingEnabled() {
- return (style & SWT.V_SCROLL) != 0 || (style & SWT.H_SCROLL) != 0;
- }
-
- protected void setHBarPolicy(boolean enableScrollbar) {
- getQScrollArea().setHorizontalScrollBarPolicy(
- enableScrollbar ? ScrollBarPolicy.ScrollBarAsNeeded : ScrollBarPolicy.ScrollBarAlwaysOff);
- }
-
- protected void setVBarPolicy(boolean enableScrollbar) {
- getQScrollArea().setVerticalScrollBarPolicy(
- enableScrollbar ? ScrollBarPolicy.ScrollBarAsNeeded : ScrollBarPolicy.ScrollBarAlwaysOff);
- }
-
- void destroyScrollBar(int type) {
- if ((type & SWT.HORIZONTAL) != 0) {
- style &= ~SWT.H_SCROLL;
- horizontalBar.dispose();
- horizontalBar = null;
- }
- if ((type & SWT.VERTICAL) != 0) {
- style &= ~SWT.V_SCROLL;
- verticalBar.dispose();
- verticalBar = null;
- }
- }
-
- @Override
- protected void setBounds(int x, int y, int width, int height, boolean move, boolean resize) {
- super.setBounds(x, y, width, height, move, resize);
- if (resize && contentWidget != null && isScrollingEnabled()) { //
- Point prefSize = computeSize(SWT.DEFAULT, SWT.DEFAULT);
- int newWidth = Math.max(width - getVerticalBarWidth(), prefSize.x);
- int newHeight = Math.max(height - getHorizontalBarHeight(), prefSize.y);
- QSize sizeHint = contentWidget.sizeHint();
- if (sizeHint.isValid()) {
- newWidth = Math.max(newWidth, sizeHint.width());
- newHeight = Math.max(newHeight, sizeHint.height());
- }
- contentWidget.resize(newWidth, newHeight);
- }
- }
-
- @Override
- public Object getData(String key) {
- checkWidget();
- if (key == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- if ("__Qt_gradientStart".equals(key)) { //$NON-NLS-1$
- return Color.qt_new(display, getStylableScrollArea().getGradientStart());
- } else if ("__Qt_gradientEnd".equals(key)) { //$NON-NLS-1$
- return Color.qt_new(display, getStylableScrollArea().getGradientEnd());
- } else if ("__Qt_text".equals(key)) { //$NON-NLS-1$
- return Color.qt_new(display, getStylableScrollArea().getText());
- } else if ("__Qt_border".equals(key)) { //$NON-NLS-1$
- return Color.qt_new(display, getStylableScrollArea().getBorder());
- }
-
- return super.getData(key);
- }
-
- /**
- * Given a desired client area for the receiver (as described by
- * the arguments), returns the bounding rectangle which would be required to
- * produce that client area.
- *
- * In other words, it returns a rectangle such that, if the receiver's
- * bounds were set to that rectangle, the area of the receiver which is
- * capable of displaying data (that is, not covered by the "trimmings")
- * would be the rectangle described by the arguments (relative to the
- * receiver's parent).
- *
- *
- * @param x
- * the desired x coordinate of the client area
- * @param y
- * the desired y coordinate of the client area
- * @param width
- * the desired width of the client area
- * @param height
- * the desired height of the client area
- * @return the required bounds to produce the given client area
- *
- * @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 #getClientArea
- */
- public Rectangle computeTrim(int x, int y, int width, int height) {
- checkWidget();
- int border = getBorderWidth();
- int xn = x - border;
- int yn = y - border;
- int widthNew = width + 2 * border;
- int heightNew = height + 2 * border;
-
- widthNew += getVerticalBarWidth();
-
- heightNew += getHorizontalBarHeight();
-
- return new Rectangle(xn, yn, widthNew, heightNew);
- }
-
- private int getVerticalBarWidth() {
- ScrollBar bar = getVerticalBar();
- if (bar != null) {
- return bar.getSize().x;
- }
- return 0;
- }
-
- private int getHorizontalBarHeight() {
- ScrollBar bar = getHorizontalBar();
- if (bar != null) {
- return bar.getSize().y;
- }
- return 0;
- }
-
- ScrollBar createScrollBar(int type) {
- ScrollBar bar = new ScrollBar(this, type);
- if ((state & CANVAS) != 0) {
- bar.setMaximum(100);
- bar.setThumb(10);
- }
- return bar;
- }
-
- /**
- * Returns a rectangle which describes the area of the receiver which is
- * capable of displaying data (that is, not covered by the "trimmings").
- *
- * @return the client area
- *
- * @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 #computeTrim
- */
- public Rectangle getClientArea() {
- checkWidget();
- if (!isVisible()) {
- updateQLayouts();
- }
-
- Rectangle clientArea = QtSWTConverter.convert(getQWidget().geometry());
- if (clientArea.width < 0) {
- clientArea.width = DEFAULT_WIDTH;
- }
- if (clientArea.height < 0) {
- clientArea.height = DEFAULT_HEIGHT;
- }
-
- return clientArea;
- }
-
- void updateQLayouts() {
- if (parent != null) {
- parent.updateQLayouts();
- }
- updateLayoutOfQWidget();
- }
-
- void updateLayoutOfQWidget() {
- QLayout layout = getQWidget().layout();
- if (layout != null) {
- layout.activate();
- layout.update();
- }
- }
-
- /**
- * Returns the receiver's horizontal scroll bar if it has one, and null if
- * it does not.
- *
- * @return the horizontal scroll 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 ScrollBar getHorizontalBar() {
- checkWidget();
- return horizontalBar;
- }
-
- /**
- * Returns the receiver's vertical scroll bar if it has one, and null if it
- * does not.
- *
- * @return the vertical scroll 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 ScrollBar getVerticalBar() {
- checkWidget();
- return verticalBar;
- }
-
- @Override
- void releaseQWidget() {
- masterWidget = null;
- contentWidget = null;
- super.releaseQWidget();
- }
-
- void releaseBar(ScrollBar bar) {
- if (horizontalBar == bar) {
- horizontalBar = null;
- }
- if (verticalBar == bar) {
- verticalBar = null;
- }
- }
-
- @Override
- void releaseChildren(boolean destroy) {
- if (horizontalBar != null) {
- horizontalBar.release(false);
- horizontalBar = null;
- }
- if (verticalBar != null) {
- verticalBar.release(false);
- verticalBar = null;
- }
- super.releaseChildren(destroy);
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Shell.java
deleted file mode 100644
index 9011fa14dd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Shell.java
+++ /dev/null
@@ -1,1510 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.core.QObject;
-import com.trolltech.qt.core.QPoint;
-import com.trolltech.qt.core.QSize;
-import com.trolltech.qt.core.Qt.FocusPolicy;
-import com.trolltech.qt.core.Qt.FocusReason;
-import com.trolltech.qt.core.Qt.WindowFlags;
-import com.trolltech.qt.core.Qt.WindowModality;
-import com.trolltech.qt.core.Qt.WindowState;
-import com.trolltech.qt.core.Qt.WindowStates;
-import com.trolltech.qt.core.Qt.WindowType;
-import com.trolltech.qt.gui.QDialog;
-import com.trolltech.qt.gui.QMainWindow;
-import com.trolltech.qt.gui.QMouseEvent;
-import com.trolltech.qt.gui.QScrollArea;
-import com.trolltech.qt.gui.QStyle;
-import com.trolltech.qt.gui.QVBoxLayout;
-import com.trolltech.qt.gui.QWidget;
-import com.trolltech.qt.gui.QWindowStateChangeEvent;
-import com.trolltech.qt.gui.QFrame.Shape;
-import com.trolltech.qt.gui.QSizePolicy.Policy;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.ShellListener;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.graphics.Region;
-import org.eclipse.swt.internal.qt.QtSWTConverter;
-
-/**
- * Instances of this class represent the "windows" which the desktop or
- * "window manager" is managing. Instances that do not have a parent (that is,
- * they are built using the constructor, which takes a Display
as
- * the argument) are described as top level shells. Instances that do
- * have a parent are described as secondary or dialog shells.
- *
- * 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.
- *
- *
- *
- * The modality of an instance may be specified using style bits. The
- * modality style bits are used to determine whether input is blocked for other
- * shells on the display. The PRIMARY_MODAL
style allows an
- * instance to block input to its parent. The APPLICATION_MODAL
- * style allows an instance to block input to every other shell in the display.
- * The SYSTEM_MODAL
style allows an instance to block input to all
- * shells, including shells belonging to different applications.
- *
- *
- * Note: The styles supported by this class are 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 and
- * modality. For example, some window managers only support resizable windows
- * and will always assume the RESIZE style, even if it is not set. In addition,
- * if a modality style is not supported, it is "upgraded" to a more restrictive
- * modality style that is supported. For example, if PRIMARY_MODAL
- * is not supported, it would be upgraded to APPLICATION_MODAL
. A
- * modality style may also be "downgraded" to a less restrictive style. For
- * example, most operating systems no longer support SYSTEM_MODAL
- * because it can freeze up the desktop, so this is typically downgraded to
- * APPLICATION_MODAL
.
- *
- * - Styles:
- * - BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL
- * - APPLICATION_MODAL, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL
- * - Events:
- * - Activate, Close, Deactivate, Deiconify, Iconify
- *
- * 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
)
- *
- *
- *
- * Note: Only one of the styles APPLICATION_MODAL, MODELESS, PRIMARY_MODAL and
- * SYSTEM_MODAL may be specified.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Decorations
- * @see SWT
- * @see Shell snippets
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- */
-public class Shell extends Decorations {
- Menu activeMenu;
- boolean fullScreen, wasMaximized, modified;
- Control lastActive;
- private QMainWindow mainWindow;
- private QDialog dialogWindow;
- private QStyle oldStyle;
-
- /**
- * Constructs a new instance of this class. This is equivalent to calling
- * Shell((Display) 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 Shell() {
- this((Display) null);
- }
-
- /**
- * Constructs a new instance of this class given only the style value
- * describing its behavior and appearance. This is equivalent to calling
- * Shell((Display) null, style)
.
- *
- * 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 style
- * the style of control to construct
- *
- * @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#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- */
- public Shell(int style) {
- this((Display) null, style);
- }
-
- /**
- * Constructs a new instance of this class given only the display to create
- * it on. It is created with style SWT.SHELL_TRIM
.
- *
- * Note: Currently, null can be passed in for the display argument. This has
- * the effect of creating the shell on the currently active display if there
- * is one. If there is no current display, the shell is created on a
- * "default" display. Passing in null as the display argument is not
- * considered to be good coding style, and may not be supported in a future
- * release of SWT.
- *
- *
- * @param display
- * the display to create the shell on
- *
- * @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 Shell(Display display) {
- this(display, SWT.SHELL_TRIM);
- }
-
- /**
- * Constructs a new instance of this class given the display to create it on
- * 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.
- *
- *
- * Note: Currently, null can be passed in for the display argument. This has
- * the effect of creating the shell on the currently active display if there
- * is one. If there is no current display, the shell is created on a
- * "default" display. Passing in null as the display argument is not
- * considered to be good coding style, and may not be supported in a future
- * release of SWT.
- *
- *
- * @param display
- * the display to create the shell on
- * @param style
- * the style of control to construct
- *
- * @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#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- */
- public Shell(Display display, int style) {
- this(display, null, style, false);
- }
-
- Shell(Display display, Shell parent, int style, boolean embedded) {
- super();
- checkSubclass();
- if (display == null) {
- display = Display.getCurrent();
- }
- if (display == null) {
- display = Display.getDefault();
- }
- if (!display.isValidThread()) {
- error(SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- if (parent != null && parent.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.style = checkStyle(style);
- this.parent = parent;
- this.display = display;
- // if (handle != 0 && !embedded) {
- // state |= FOREIGN_HANDLE;
- // }
- createWidget(parent, style);
- }
-
- /**
- * Constructs a new instance of this class given only its parent. It is
- * created with style SWT.DIALOG_TRIM
.
- *
- * Note: Currently, null can be passed in for the parent. This has the
- * effect of creating the shell on the currently active display if there is
- * one. If there is no current display, the shell is created on a "default"
- * display. Passing in null as the parent is not considered to be good
- * coding style, and may not be supported in a future release of SWT.
- *
- *
- * @param parent
- * a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_INVALID_ARGUMENT - if the parent is disposed
- *
- * @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 Shell(Shell parent) {
- this(parent, SWT.DIALOG_TRIM);
- }
-
- /**
- * 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.
- *
- *
- * Note: Currently, null can be passed in for the parent. This has the
- * effect of creating the shell on the currently active display if there is
- * one. If there is no current display, the shell is created on a "default"
- * display. Passing in null as the parent is not considered to be good
- * coding style, and may not be supported in a future release of SWT.
- *
- *
- * @param parent
- * a shell which will be the parent of the new instance
- * @param style
- * the style of control to construct
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_INVALID_ARGUMENT - if the parent is disposed
- *
- * @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 SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- */
- public Shell(Shell parent, int style) {
- this(parent != null ? parent.display : null, parent, style, false);
- }
-
- @Override
- QWidget createQWidget(int style) {
- QScrollArea scrollArea;
- if (parent == null) {
- // new window
- mainWindow = new QMainWindow(null, createWindowFlags(style));
- scrollArea = new QScrollArea(mainWindow);
- mainWindow.setCentralWidget(scrollArea);
- } else {
- // new dialog
- dialogWindow = new QDialog(parent.getQWidget(), createWindowFlags(style));
- scrollArea = new QScrollArea(dialogWindow);
-
- QVBoxLayout layout = new QVBoxLayout(dialogWindow);
- layout.addWidget(scrollArea);
- layout.setContentsMargins(0, 0, 0, 0);
- }
-
- scrollArea.setFrameShape(Shape.NoFrame);
- scrollArea.setContentsMargins(0, 0, 0, 0);
- scrollArea.setWidgetResizable(true);
- setQMasterWidget(scrollArea);
-
- QWidget contentWidget = new QWidget();
- contentWidget.setProperty("widgetType", "scrollareaContent"); //$NON-NLS-1$ //$NON-NLS-2$
- contentWidget.setSizePolicy(Policy.MinimumExpanding, Policy.MinimumExpanding);
- contentWidget.setContentsMargins(0, 0, 0, 0);
- contentWidget.resize(0, 0);
- scrollArea.setWidget(contentWidget);
-
- scrollArea.resize(0, 0);
-
- int policy = getWindowControl().focusPolicy().value() & ~FocusPolicy.ClickFocus.value();
- getWindowControl().setFocusPolicy(FocusPolicy.resolve(policy));
-
- state |= CANVAS;
-
- return scrollArea.widget();
- }
-
- private WindowFlags createWindowFlags(int style) {
- int flags = parent == null ? WindowType.Window.value() : WindowType.Dialog.value()
- | WindowModality.WindowModal.value();
- flags |= WindowType.CustomizeWindowHint.value();
- if ((style & SWT.CLOSE) != 0) {
- flags |= WindowType.WindowSystemMenuHint.value() | WindowType.WindowCloseButtonHint.value();
- }
- if ((style & SWT.MIN) != 0) {
- flags |= WindowType.WindowMinimizeButtonHint.value();
- }
- if ((style & SWT.MAX) != 0) {
- flags |= WindowType.WindowMaximizeButtonHint.value();
- }
- if ((style & SWT.NO_TRIM) != 0) {
- flags |= WindowType.FramelessWindowHint.value();
- }
- if ((style & SWT.TITLE) != 0) {
- flags |= WindowType.WindowTitleHint.value();
- }
- if ((style & SWT.ON_TOP) != 0) {
- flags |= WindowType.WindowStaysOnTopHint.value();
- }
- return new WindowFlags(flags);
- }
-
- @Override
- protected void setupQWidget() {
- getWindowControl().adjustSize();
- // no setup
- }
-
- @Override
- void registerQWidget() {
- super.registerQWidget();
- display.addControl(getWindowControl(), this);
- }
-
- @Override
- void deregisterQWidget() {
- display.removeControl(getWindowControl());
- super.deregisterQWidget();
- }
-
- @Override
- protected QWidget getQMasterWidget() {
- return getWindowControl();
- }
-
- @Override
- QWidget getMenuContainer() {
- return getWindowControl();
- }
-
- QDialog getQDialog() {
- return dialogWindow;
- }
-
- boolean isDialog() {
- return dialogWindow != null;
- }
-
- @Override
- public void setStyleSheet(String style) {
- if (style == null || style.trim().length() == 0) {
- getWindowControl().setStyleSheet(null);
- if (oldStyle != null) {
- getWindowControl().setStyle(oldStyle);
- oldStyle = null;
- }
- } else {
- oldStyle = getWindowControl().style();
- getWindowControl().setStyleSheet(style);
- }
- updateLayout();
- }
-
- @Override
- public void updateStyleSheet() {
- if (null != getWindowControl().style()) {
- getWindowControl().setStyle(getWindowControl().style());
- updateLayout();
- }
- }
-
- @Override
- protected QWidget getWindowControl() {
- return mainWindow != null ? mainWindow : dialogWindow;
- }
-
- /**
- * Invokes platform specific functionality to allocate a new shell that is
- * embedded.
- *
- * IMPORTANT: This method is not part of the public API for
- * Shell
. 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 display
- * the display for the shell
- * @param qMetrics
- * the handle for the shell
- * @return a new shell object containing the specified display and handle
- */
- public static Shell qt_new(Display display) {
- return new Shell(display, null, SWT.NO_TRIM, true);
- }
-
- static int checkStyle(int style) {
- style = Decorations.checkStyle(style);
- style &= ~SWT.TRANSPARENT;
- int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL;
- int bits = style & ~mask;
- if ((style & SWT.SYSTEM_MODAL) != 0) {
- return bits | SWT.SYSTEM_MODAL;
- }
- if ((style & SWT.APPLICATION_MODAL) != 0) {
- return bits | SWT.APPLICATION_MODAL;
- }
- if ((style & SWT.PRIMARY_MODAL) != 0) {
- return bits | SWT.PRIMARY_MODAL;
- }
- return bits;
- }
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when operations are performed on the receiver, by sending the listener
- * one of the messages defined in the ShellListener
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 ShellListener
- * @see #removeShellListener
- */
- public void addShellListener(ShellListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Close, typedListener);
- addListener(SWT.Iconify, typedListener);
- addListener(SWT.Deiconify, typedListener);
- addListener(SWT.Activate, typedListener);
- addListener(SWT.Deactivate, typedListener);
- }
-
- /**
- * Requests that the window manager close the receiver in the same way it
- * would be closed when the user clicks on the "close box" or performs some
- * other platform specific key or mouse combination that indicates the
- * window should be removed.
- *
- * @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#Close
- * @see #dispose
- */
- public void close() {
- checkWidget();
- closeWidget();
- }
-
- @Override
- void enableWidget(boolean enabled) {
- Control oldFocus = display.getFocusControl();
- super.enableWidget(enabled);
- if (enabled) {
- _update();
- } else {
-
- // All children were looped through and disabled by QWidget unless
- // they
- // were explicitly disabled. SWT behavior is not to disable the
- // dialog
- // Shells so we have to restore their states.
- Shell shells[] = getShells();
- for (int i = 0; i < shells.length; ++i) {
- if (shells[i].parent == this) {
- if (shells[i].getEnabled()) {
- shells[i].getQWidget().setEnabled(true);
- }
- }
- }
- // Because dialog Shell might have been temporarily disabled the
- // focus might
- // have been lost and must be restored.
- if (oldFocus != null) {
- oldFocus.menuShell().restoreFocus();
- }
- }
- }
-
- @Override
- Control findBackgroundControl() {
- return background != null || backgroundImage != null ? this : null;
- }
-
- @Override
- Cursor findCursor() {
- return cursor;
- }
-
- @Override
- Control findThemeControl() {
- return null;
- }
-
- void fixShell(Shell newShell, Control control) {
- if (this == newShell) {
- return;
- }
- if (control == lastActive) {
- setActiveControl(null);
- }
- }
-
- /**
- * If the receiver is visible, moves it to the top of the drawing order for
- * the display on which it was created (so that all other shells on that
- * display, which are not the receiver's children will be drawn behind it)
- * and forces the window manager to make the shell active.
- *
- * @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.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
- public void forceActive() {
- checkWidget();
- if (!isVisible()) {
- return;
- }
- bringToTop();
- }
-
- void forceResize() {
- /* Do nothing */
- }
-
- /**
- * Returns the receiver's alpha value. The alpha value is between 0
- * (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @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 int getAlpha() {
- checkWidget();
- double opacity = getQWidget().windowOpacity();
- return (int) (255 * opacity);
- }
-
- @Override
- public Rectangle getBounds() {
- checkWidget();
- QPoint pos = getWindowControl().pos();
- QSize size = getWindowControl().size();
- return new Rectangle(pos.x(), pos.y(), size.width(), size.height());
- }
-
- @Override
- public Rectangle getClientArea() {
- checkWidget();
- if (!isVisible()) {
- updateQLayouts();
- }
-
- Rectangle clientArea = QtSWTConverter.convert(getQWidget().rect());
- if (clientArea.width < 0) {
- clientArea.width = 0;
- }
- if (clientArea.height < 0) {
- clientArea.height = 0;
- }
-
- return clientArea;
- }
-
- /**
- * Returns true
if the receiver is currently in fullscreen
- * state, and false otherwise.
- *
- *
- * @return the fullscreen 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 getFullScreen() {
- checkWidget();
- return fullScreen;
- }
-
- /**
- * Returns the receiver's input method editor mode. This will be the result
- * of bitwise OR'ing together one or more of the following constants defined
- * in class SWT
: NONE
, ROMAN
,
- * DBCS
, PHONETIC
, NATIVE
,
- * ALPHA
.
- *
- * @return the IME 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
- */
- public int getImeInputMode() {
- checkWidget();
- // TODO how to do it with Qt?
- return SWT.NONE;
- }
-
- @Override
- public Point getLocation() {
- checkWidget();
- if (getWindowControl().isMinimized()) {
- return super.getLocation();
- }
- return QtSWTConverter.convert(getWindowControl().pos());
- }
-
- @Override
- public boolean getMaximized() {
- checkWidget();
- return !fullScreen && super.getMaximized();
- }
-
- /**
- * Returns a point describing the minimum receiver's size. The x coordinate
- * of the result is the minimum width of the receiver. The y coordinate of
- * the result is the minimum 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
- *
- *
- * @since 3.1
- */
- public Point getMinimumSize() {
- checkWidget();
- return QtSWTConverter.convert(getWindowControl().minimumSize());
- }
-
- /**
- * Gets the receiver's modified 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.5
- */
- public boolean getModified() {
- checkWidget();
- return modified;
- }
-
- /**
- * Returns the region that defines the shape of the shell, or null if the
- * shell 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.0
- *
- */
- @Override
- public Region getRegion() {
- /* This method is needed for the @since 3.0 Javadoc */
- checkWidget();
- return region;
- }
-
- @Override
- public Shell getShell() {
- checkWidget();
- return this;
- }
-
- @Override
- public Point getSize() {
- checkWidget();
- return QtSWTConverter.convert(getWindowControl().size());
- }
-
- /**
- * Returns an array containing all shells which are descendants of the
- * receiver.
- *
- *
- * @return the dialog shells
- *
- * @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 Shell[] getShells() {
- checkWidget();
- int count = 0;
- Shell[] shells = display.getShells();
- for (int i = 0; i < shells.length; i++) {
- Control shell = shells[i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) {
- count++;
- }
- }
- int index = 0;
- Shell[] result = new Shell[count];
- for (int i = 0; i < shells.length; i++) {
- Control shell = shells[i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) {
- result[index++] = shells[i];
- }
- }
- return result;
- }
-
- /**
- * Returns the instance of the ToolBar object representing the tool bar that can appear on the
- * trim of the shell. This will return null
if the platform does not support tool bars that
- * not part of the content area of the shell, or if the style of the shell does not support a
- * tool bar.
- *
- *
- * @return a ToolBar object representing the window's tool 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
- *
- *
- * @since 3.7
- */
- public ToolBar getToolBar() {
- return null;
- }
-
- @Override
- protected Composite findDeferredControl() {
- return layoutCount > 0 ? this : null;
- }
-
- // @Override
- // public boolean isEnabled() {
- // checkWidget();
- // return getEnabled();
- //}
-
- /**
- * Moves the receiver to the top of the drawing order for the display on
- * which it was created (so that all other shells on that display, which are
- * not the receiver's children will be drawn behind it), marks it visible,
- * sets the focus and asks the window manager to make the shell active.
- *
- * @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 Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#setActive
- * @see Shell#forceActive
- */
- public void open() {
- checkWidget();
- updateLayout();
- setVisible(true);
- bringToTop();
- if (isDisposed()) {
- return;
- }
- if (!restoreFocus() && !traverseGroup(true)) {
- setFocus(FocusReason.OtherFocusReason);
- }
- }
-
- @Override
- public boolean print(GC gc) {
- checkWidget();
- if (gc == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (gc.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- //TODO
- return false;
- }
-
- @Override
- void releaseChildren(boolean destroy) {
- Shell[] shells = getShells();
- for (int i = 0; i < shells.length; i++) {
- Shell shell = shells[i];
- if (shell != null && !shell.isDisposed()) {
- shell.release(false);
- }
- }
- super.releaseChildren(destroy);
- }
-
- @Override
- void releaseParent() {
- /* Do nothing */
- }
-
- @Override
- void releaseQWidget() {
- getWindowControl().close();
- super.releaseQWidget();
- mainWindow = null;
- dialogWindow = null;
- }
-
- @Override
- void releaseWidget() {
- super.releaseWidget();
- lastActive = null;
- }
-
- @Override
- void removeMenu(Menu menu) {
- super.removeMenu(menu);
- if (menu == activeMenu) {
- activeMenu = null;
- }
- }
-
- /**
- * Removes the listener from the collection of listeners who will be
- * notified when operations are performed on the receiver.
- *
- * @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 ShellListener
- * @see #addShellListener
- */
- public void removeShellListener(ShellListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (eventTable == null) {
- return;
- }
- eventTable.unhook(SWT.Close, listener);
- eventTable.unhook(SWT.Iconify, listener);
- eventTable.unhook(SWT.Deiconify, listener);
- eventTable.unhook(SWT.Activate, listener);
- eventTable.unhook(SWT.Deactivate, listener);
- }
-
- /**
- * If the receiver is visible, moves it to the top of the drawing order for
- * the display on which it was created (so that all other shells on that
- * display, which are not the receiver's children will be drawn behind it)
- * and asks the window manager to make the shell active
- *
- * @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.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
- public void setActive() {
- checkWidget();
- if (!isVisible()) {
- return;
- }
- bringToTop();
- // widget could be disposed at this point
- }
-
- void setActiveControl(Control control) {
- if (control != null && control.isDisposed()) {
- control = null;
- }
- if (lastActive != null && lastActive.isDisposed()) {
- lastActive = null;
- }
- if (lastActive == control) {
- return;
- }
-
- /*
- * Compute the list of controls to be activated and deactivated by
- * finding the first common parent control.
- */
- Control[] activate = control == null ? new Control[0] : control.getPath();
- Control[] deactivate = lastActive == null ? new Control[0] : lastActive.getPath();
- lastActive = control;
- int index = 0, length = Math.min(activate.length, deactivate.length);
- while (index < length) {
- if (activate[index] != deactivate[index]) {
- break;
- }
- index++;
- }
-
- /*
- * It is possible (but unlikely), that application code could have
- * destroyed some of the widgets. If this happens, keep processing those
- * widgets that are not disposed.
- */
- for (int i = deactivate.length - 1; i >= index; --i) {
- if (!deactivate[i].isDisposed()) {
- deactivate[i].sendEvent(SWT.Deactivate);
- }
- }
- for (int i = activate.length - 1; i >= index; --i) {
- if (!activate[i].isDisposed()) {
- activate[i].sendEvent(SWT.Activate);
- }
- }
- }
-
- /**
- * Sets the receiver's alpha value which must be between 0 (transparent) and
- * 255 (opaque).
- *
- * This operation requires the operating system's advanced widgets subsystem
- * which may not be available on some platforms.
- *
- *
- * @param alpha
- * the alpha value
- *
- * @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 setAlpha(int alpha) {
- checkWidget();
- if (alpha < 0 || alpha > 255) {
- return;
- }
- getQWidget().setWindowOpacity((double) alpha / 255);
- }
-
- @Override
- protected void setBounds(int x, int y, int width, int height, boolean move, boolean resize) {
- if (fullScreen) {
- setFullScreen(false);
- }
-
- Rectangle geometry = QtSWTConverter.convert(getWindowControl().frameGeometry());
- if (move) {
- int oldX = geometry.x;
- int oldY = geometry.y;
- boolean moved = oldX != x || oldY != y;
- if (moved) {
- getWindowControl().move(x, y);
- }
- }
-
- if (resize) {
- int oldW = geometry.width;
- int oldH = geometry.height;
- boolean resized = oldW != width || oldH != height;
-
- if (resized) {
- if ((style & SWT.RESIZE) == 0) {
- unlockSize();
- }
-
- getWindowControl().resize(width, height);
-
- if ((style & SWT.RESIZE) == 0) {
- getWindowControl().setFixedSize(Math.max(0, width), Math.max(0, height));
- }
- }
- }
- }
-
- @Override
- public void setEnabled(boolean enabled) {
- checkWidget();
- if (super.getEnabled() == enabled) {
- return;
- }
- super.setEnabled(enabled);
- if (enabled && getWindowControl().isActiveWindow()) {
- if (!restoreFocus()) {
- traverseGroup(true);
- }
- }
- }
-
- /**
- * Sets the full screen state of the receiver. If the argument is
- * true
causes the receiver to switch to the full screen state,
- * and if the argument is false
and the receiver was previously
- * switched into full screen state, causes the receiver to switch back to
- * either the maximmized or normal states.
- *
- * Note: The result of intermixing calls to setFullScreen(true)
, 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 fullScreen
- * the new fullscreen 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 setFullScreen(boolean fullScreen) {
- checkWidget();
- if (this.fullScreen == fullScreen) {
- return;
- }
- this.fullScreen = fullScreen;
- if (fullScreen) {
- getWindowControl().showFullScreen();
- } else {
- getWindowControl().showNormal();
- }
- }
-
- /**
- * Sets the input method editor mode to the argument which should be the
- * result of bitwise OR'ing together one or more of the following constants
- * defined in class SWT
: NONE
, ROMAN
,
- * DBCS
, PHONETIC
, NATIVE
,
- * ALPHA
.
- *
- * @param mode
- * the new IME 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
- */
- public void setImeInputMode(int mode) {
- checkWidget();
- // TODO
- }
-
- /**
- * Sets the receiver's minimum size to the size specified by the arguments.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param width
- * the new minimum width for the receiver
- * @param height
- * the new minimum 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
- *
- *
- * @since 3.1
- */
- public void setMinimumSize(int width, int height) {
- checkWidget();
- getQWidget().setMinimumSize(width, height);
- }
-
- /**
- * Sets the receiver's minimum size to the size specified by the argument.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param size
- * the new minimum 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
- *
- *
- * @since 3.1
- */
- public void setMinimumSize(Point size) {
- checkWidget();
- if (size == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- setMinimumSize(size.x, size.y);
- }
-
- /**
- * Sets the receiver's modified state as specified by the argument.
- *
- * @param modified
- * the new modified state 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
- *
- *
- * @since 3.5
- */
- public void setModified(boolean modified) {
- checkWidget();
- this.modified = modified;
- }
-
- /**
- * Sets the shape of the shell to the region specified by the argument. When
- * the argument is null, the default shape of the shell is restored. The
- * shell must be created with the style SWT.NO_TRIM in order to specify a
- * region.
- *
- * @param region
- * the region that defines the shape of the shell (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.0
- *
- */
- @Override
- public void setRegion(Region region) {
- checkWidget();
- if ((style & SWT.NO_TRIM) == 0) {
- return;
- }
- super.setRegion(region);
- }
-
- @Override
- public void setVisible(boolean visible) {
- checkWidget();
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- if ((style & mask) != 0) {
- if (visible) {
- display.setModalShell(this);
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- display.setModalDialog(null);
- }
- Control control = display.getFocusControl();
- if (control != null && !control.isActive()) {
- bringToTop();
- if (isDisposed()) {
- return;
- }
- }
- getWindowControl().setWindowModality(getModalityFromStyle());
- QWidget mouseGrabber = QWidget.mouseGrabber();
- if (mouseGrabber != null) {
- mouseGrabber.releaseMouse();
- }
- } else {
- display.clearModal(this);
- }
- } else {
- updateModal();
- }
-
- _setVisible(getWindowControl(), visible);
- }
-
- private WindowModality getModalityFromStyle() {
- if ((style & SWT.SYSTEM_MODAL) != 0) {
- return WindowModality.ApplicationModal;
- }
- if ((style & SWT.APPLICATION_MODAL) != 0) {
- return WindowModality.ApplicationModal;
- }
- if ((style & SWT.PRIMARY_MODAL) != 0) {
- return WindowModality.ApplicationModal;
- }
- return WindowModality.NonModal;
- }
-
- @Override
- boolean traverseEscape() {
- if (parent == null) {
- return false;
- }
- if (!isVisible() || !isEnabled()) {
- return false;
- }
- close();
- return true;
- }
-
- void updateModal() {
- }
-
- @Override
- public boolean qtCloseEvent() {
- return closeWidget();
- }
-
- @Override
- public boolean qtWindowStateChangeEvent(QObject source, QWindowStateChangeEvent event) {
- if (source != getWindowControl()) {
- return false;
- }
- WindowStates oldState = event.oldState();
- WindowStates newState = getWindowControl().windowState();
- if (oldState.isSet(WindowState.WindowMinimized) && !newState.isSet(WindowState.WindowMinimized)) {
- sendEvent(SWT.Deiconify);
- return false;
- }
- if (!oldState.isSet(WindowState.WindowMinimized) && newState.isSet(WindowState.WindowMinimized)) {
- sendEvent(SWT.Iconify);
- menuShell().saveFocus();
- return false;
- }
- return false;
- }
-
- @Override
- public boolean qtMouseButtonPressEvent(QObject source, QMouseEvent mouseEvent) {
- if (source == getQWidget()) {
- QWidget clickTarget = getQWidget().childAt(mouseEvent.x(), mouseEvent.y());
- if (clickTarget != null && clickTarget != getQWidget()) {
- Widget swtControl = display.findControl(clickTarget);
- if (swtControl instanceof Control) {
- setActiveControl((Control) swtControl);
- }
- }
- }
- return false;
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Slider.java
deleted file mode 100644
index b85060a66c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Slider.java
+++ /dev/null
@@ -1,632 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.core.Qt.FocusPolicy;
-import com.trolltech.qt.core.Qt.Orientation;
-import com.trolltech.qt.gui.QAbstractSlider;
-import com.trolltech.qt.gui.QScrollBar;
-import com.trolltech.qt.gui.QWidget;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Point;
-
-/**
- * Instances of this class are selectable user interface objects that represent
- * a range of positive, numeric values.
- *
- * At any given moment, a given slider will have a single 'selection' that is
- * considered to be its value, which is constrained to be within the range of
- * values the slider represents (that is, between its minimum and
- * maximum values).
- *
- *
- * Typically, sliders will be made up of five areas:
- *
- * - an arrow button for decrementing the value
- * - a page decrement area for decrementing the value by a larger amount
- * - a thumb for modifying the value by mouse dragging
- * - a page increment area for incrementing the value by a larger amount
- * - an arrow button for incrementing the value
- *
- * Based on their style, sliders are either HORIZONTAL
(which have
- * a left facing button for decrementing the value and a right facing button for
- * incrementing it) or VERTICAL
(which have an upward facing button
- * for decrementing the value and a downward facing buttons for incrementing
- * it).
- *
- *
- * On some platforms, the size of the slider's thumb can be varied relative to
- * the magnitude of the range of values it represents (that is, relative to the
- * difference between its maximum and minimum values). Typically, this is used
- * to indicate some proportional value such as the ratio of the visible area of
- * a document to the total amount of space that it would take to display it. SWT
- * supports setting the thumb size even if the underlying platform does not, but
- * in this case the appearance of the slider will not change.
- *
- *
- * - Styles:
- * - HORIZONTAL, VERTICAL
- * - Events:
- * - Selection
- *
- *
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see ScrollBar
- * @see Slider
- * snippets
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Slider extends Control {
-
- private int thumb; // TODO Not supported by Qt?
- private int maximum;
-
- /**
- * 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#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public Slider(Composite parent, int style) {
- super(parent, checkStyle(style));
- }
-
- @Override
- protected void connectSignals() {
- getQScrollBar().actionTriggered.connect(this, "actionTriggered(int)"); //$NON-NLS-1$
- getQScrollBar().rangeChanged.connect(this, "rangeChanged(int,int)"); //$NON-NLS-1$
- getQScrollBar().sliderMoved.connect(this, "sliderMoved(int)"); //$NON-NLS-1$
- getQScrollBar().sliderPressed.connect(this, "sliderPressed()"); //$NON-NLS-1$
- getQScrollBar().sliderReleased.connect(this, "sliderReleased()"); //$NON-NLS-1$
- getQScrollBar().valueChanged.connect(this, "valueChanged(int)"); //$NON-NLS-1$
- }
-
- protected void actionTriggered(int action) {
- System.out.println("actionTriggered :" + action + " " + getQScrollBar().value()); //$NON-NLS-1$//$NON-NLS-2$
- Event event = new Event();
- if (action == QAbstractSlider.SliderAction.SliderToMinimum.value()) {
- event.detail = SWT.HOME;
- } else if (action == QAbstractSlider.SliderAction.SliderToMaximum.value()) {
- event.detail = SWT.END;
- } else if (action == QAbstractSlider.SliderAction.SliderSingleStepAdd.value()) {
- event.detail = SWT.ARROW_DOWN;
- } else if (action == QAbstractSlider.SliderAction.SliderSingleStepSub.value()) {
- event.detail = SWT.ARROW_UP;
- } else if (action == QAbstractSlider.SliderAction.SliderPageStepAdd.value()) {
- event.detail = SWT.PAGE_UP;
- } else if (action == QAbstractSlider.SliderAction.SliderPageStepSub.value()) {
- event.detail = SWT.PAGE_DOWN;
- } else if (action == QAbstractSlider.SliderAction.SliderMove.value()) {
- event.detail = SWT.DRAG;
- } else {
- return;
- }
- // see actionTrigger signal
- getQScrollBar().setValue(getQScrollBar().sliderPosition());
- sendEvent(SWT.Selection, event);
- }
-
- protected void rangeChanged(int min, int max) {
- System.out.println("rangeChanged :" + min + ", " + max); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- protected void sliderMoved(int pos) {
- System.out.println("sliderMoved :" + pos); //$NON-NLS-1$
- }
-
- protected void sliderPressed() {
- System.out.println("sliderPressed"); //$NON-NLS-1$
- }
-
- protected void sliderReleased() {
- System.out.println("sliderReleased"); //$NON-NLS-1$
- Event event = new Event();
- event.detail = SWT.NONE;
- sendEvent(SWT.Selection, event);
- }
-
- protected void valueChanged(int value) {
- System.out.println("valueChanged :" + value); //$NON-NLS-1$
- }
-
- @Override
- protected QWidget createQWidget(int style) {
- final Orientation orientation = (style & SWT.HORIZONTAL) != 0 ? Orientation.Horizontal : Orientation.Vertical;
- return new QScrollBar(orientation);
- }
-
- @Override
- protected void setupQWidget() {
- super.setupQWidget();
- getQScrollBar().setFocusPolicy(FocusPolicy.WheelFocus);
- setThumb(10);
- setMinimum(0);
- setMaximum(100);
- setIncrement(1);
- setPageIncrement(10);
- }
-
- QAbstractSlider getQScrollBar() {
- return (QAbstractSlider) getQWidget();
- }
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when the user changes the receiver's value, by sending it one of the
- * messages defined in the SelectionListener
interface.
- *
- * When widgetSelected
is called, the event object detail field
- * contains one of the following values: SWT.NONE
- for the end
- * of a drag. SWT.DRAG
. SWT.HOME
.
- * SWT.END
. SWT.ARROW_DOWN
.
- * SWT.ARROW_UP
. SWT.PAGE_DOWN
.
- * SWT.PAGE_UP
. widgetDefaultSelected
is not
- * called.
- *
- *
- * @param listener
- * the listener which should be notified when the user changes
- * the receiver's value
- *
- * @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);
- }
-
- static int checkStyle(int style) {
- return checkBits(style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
- }
-
- @Override
- public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth();
- int width = border * 2;
- int height = border * 2;
- // default size: this is just the two arrows + thumb
- Point defaultSize = super.computeSize(wHint, hHint, changed);
- if ((style & SWT.HORIZONTAL) != 0) {
- width += defaultSize.y * 10;
- height += defaultSize.y;
- } else {
- width += defaultSize.x;
- height += defaultSize.x * 10;
- }
- if (wHint != SWT.DEFAULT) {
- width = wHint + border * 2;
- }
- if (hHint != SWT.DEFAULT) {
- height = hHint + border * 2;
- }
- return new Point(width, height);
- }
-
- // TODO Is this ok?
-
- // int defaultBackground() {
- // return OS.GetSysColor(OS.COLOR_SCROLLBAR);
- // }
- //
- // int defaultForeground() {
- // return OS.GetSysColor(OS.COLOR_BTNFACE);
- // }
-
- /**
- * Returns the amount that the receiver's value will be modified by when the
- * up/down (or right/left) arrows are pressed.
- *
- * @return the increment
- *
- * @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 getIncrement() {
- checkWidget();
- return getQScrollBar().singleStep();
- }
-
- /**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @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 getMaximum() {
- checkWidget();
- return maximum;
- }
-
- /**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @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 getMinimum() {
- checkWidget();
- return getQScrollBar().minimum();
- }
-
- /**
- * Returns the amount that the receiver's value will be modified by when the
- * page increment/decrement areas are selected.
- *
- * @return the page increment
- *
- * @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 getPageIncrement() {
- checkWidget();
- return getQScrollBar().pageStep();
- }
-
- /**
- * Returns the 'selection', which is the receiver's value.
- *
- * @return the selection
- *
- * @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 getSelection() {
- checkWidget();
- return getQScrollBar().value();
- }
-
- /**
- * Returns the size of the receiver's thumb relative to the difference
- * between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @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 getThumb() {
- checkWidget();
- return thumb;
- }
-
- /**
- * Removes the listener from the collection of listeners who will be
- * notified when the user changes the receiver's value.
- *
- * @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);
- }
-
- /**
- * Sets the amount that the receiver's value will be modified by when the
- * up/down (or right/left) arrows are pressed to the argument, which must be
- * at least one.
- *
- * @param value
- * the new increment (must be greater than 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
- *
- */
- public void setIncrement(int value) {
- checkWidget();
- if (value < 1) {
- return;
- }
- getQScrollBar().setSingleStep(value);
- }
-
- /**
- * Sets the maximum. If this value is negative or less than or equal to the
- * minimum, the value is ignored. If necessary, first the thumb and then the
- * selection are adjusted to fit within the new range.
- *
- * @param value
- * the new maximum, which must be greater than the current
- * minimum
- *
- * @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 setMaximum(int value) {
- checkWidget();
- if (value < 0 || value <= getQScrollBar().minimum()) {
- return;
- }
- maximum = value;
- getQScrollBar().setMaximum(maximum - thumb);
- }
-
- /**
- * Sets the minimum value. If this value is negative or greater than or
- * equal to the maximum, the value is ignored. If necessary, first the thumb
- * and then the selection are adjusted to fit within the new range.
- *
- * @param value
- * the new minimum
- *
- * @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 setMinimum(int value) {
- checkWidget();
- if (value < 0 || value >= getQScrollBar().maximum()) {
- return;
- }
- getQScrollBar().setMinimum(value);
- }
-
- /**
- * Sets the amount that the receiver's value will be modified by when the
- * page increment/decrement areas are selected to the argument, which must
- * be at least one.
- *
- * @param value
- * the page increment (must be greater than 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
- *
- */
- public void setPageIncrement(int value) {
- checkWidget();
- if (value < 1) {
- return;
- }
- getQScrollBar().setPageStep(value);
- }
-
- /**
- * Sets the 'selection', which is the receiver's value, to the argument
- * which must be greater than or equal to zero.
- *
- * @param value
- * the new selection (must be zero or greater)
- *
- * @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(int value) {
- checkWidget();
- getQScrollBar().setValue(value);
- }
-
- /**
- * Sets the size of the receiver's thumb relative to the difference between
- * its maximum and minimum values. This new value will be ignored if it is
- * less than one, and will be clamped if it exceeds the receiver's current
- * range.
- *
- * @param value
- * the new thumb value, which must be at least one and not larger
- * than the size of the current range
- *
- * @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 setThumb(int value) {
- checkWidget();
- if (value < 1) {
- return;
- }
- this.thumb = value;
- setMaximum(maximum); // adjust the maximum which depends on the thumb
- }
-
- /**
- * Sets the receiver's selection, minimum value, maximum value, thumb,
- * increment and page increment all at once.
- *
- * Note: This is similar to setting the values individually using the
- * appropriate methods, but may be implemented in a more efficient fashion
- * on some platforms.
- *
- *
- * @param selection
- * the new selection value
- * @param minimum
- * the new minimum value
- * @param maximum
- * the new maximum value
- * @param thumb
- * the new thumb value
- * @param increment
- * the new increment value
- * @param pageIncrement
- * the new pageIncrement value
- *
- * @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 setValues(int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- if (minimum < 0) {
- return;
- }
- if (maximum < 0) {
- return;
- }
- if (thumb < 1) {
- return;
- }
- if (increment < 1) {
- return;
- }
- if (pageIncrement < 1) {
- return;
- }
- setMinimum(minimum);
- setMaximum(maximum);
- setThumb(thumb);
- setSelection(selection);
- setIncrement(increment);
- setPageIncrement(pageIncrement);
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Spinner.java
deleted file mode 100644
index 19c26a6a6e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Spinner.java
+++ /dev/null
@@ -1,948 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.core.QSize;
-import com.trolltech.qt.gui.QApplication;
-import com.trolltech.qt.gui.QDoubleSpinBox;
-import com.trolltech.qt.gui.QWidget;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.events.VerifyListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-
-/**
- * Instances of this class are selectable user interface objects that allow the
- * user to enter and modify numeric 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:
- * - READ_ONLY, WRAP
- * - Events:
- * - Selection, Modify, Verify
- *
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Spinner
- * snippets
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Spinner extends Composite {
- boolean ignoreModify;
- int pageIncrement, digits;
- int selection = 0;
-
- /**
- * the operating system limit for the number of characters that the text
- * field in an instance of this class can hold
- *
- * @since 3.4
- */
- public static final 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 {
- //TODO: 3 is just an imaginary value. see bug 161
- LIMIT = 3;
- }
-
- /**
- * 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#READ_ONLY
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public Spinner(Composite parent, int style) {
- super(parent, checkStyle(style));
-
- // setting default values of the SWT widget:
- ((QDoubleSpinBox) getQWidget()).setDecimals(0);
- ((QDoubleSpinBox) getQWidget()).setMaximum(100);
-
- ((QDoubleSpinBox) getQWidget()).setSingleStep(getIncrement() / Math.pow(10, this.digits));
- }
-
- @Override
- protected QWidget createQWidget(int style) {
- state &= ~(CANVAS | THEME_BACKGROUND);
- QWidget spinner = new QDoubleSpinBox();
- connectSignals(spinner);
- return spinner;
- }
-
- 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.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- private void connectSignals(QWidget spinner) {
- ((QDoubleSpinBox) spinner).valueChanged.connect(this, "valueChanged()"); //$NON-NLS-1$
- //TODO: connection for selection and verify event is missing, but there's not suitable event in QDoubleSpinBox (bug 159)
- }
-
- protected void valueChanged() {
- Event event = new Event();
- sendEvent(SWT.Modify, event);
- }
-
- /**
- * 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 control is selected by the user, by sending it one of the
- * messages defined in the SelectionListener
interface.
- *
- * widgetSelected
is not called for texts.
- * widgetDefaultSelected
is typically called when ENTER is
- * pressed in a single-line text.
- *
- *
- * @param listener
- * the listener which should be notified when the control is
- * selected by the user
- *
- * @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
- */
- void addVerifyListener(VerifyListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Verify, typedListener);
- }
-
- @Override
- public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
- QSize size = ((QDoubleSpinBox) getQWidget()).sizeHint();
- return new Point(size.width(), size.height());
- }
-
- @Override
- public Rectangle computeTrim(int x, int y, int width, int height) {
- checkWidget();
- return super.computeTrim(x, y, 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
- *
- */
- public void copy() {
- checkWidget();
- QApplication.clipboard().setText(((QDoubleSpinBox) getQWidget()).text());
- }
-
- /**
- * Cuts the selected text.
- *
- * 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
- *
- */
- public void cut() {
- checkWidget();
- if ((style & SWT.READ_ONLY) != 0) {
- return;
- }
- QApplication.clipboard().setText(((QDoubleSpinBox) getQWidget()).text());
- ((QDoubleSpinBox) getQWidget()).setValue(0);
- this.selection = 0;
- }
-
- @Override
- void enableWidget(boolean enabled) {
- super.enableWidget(enabled);
- }
-
- @Override
- void deregisterQWidget() {
- super.deregisterQWidget();
- }
-
- @Override
- boolean hasFocus() {
- return getQWidget().hasFocus();
- }
-
- /**
- * Returns the number of decimal places used by the receiver.
- *
- * @return the digits
- *
- * @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 getDigits() {
- checkWidget();
- return digits;
- }
-
- String getDecimalSeparator() {
- // TODO check locale
- return "."; //$NON-NLS-1$
- }
-
- /**
- * Returns the amount that the receiver's value will be modified by when the
- * up/down arrows are pressed.
- *
- * @return the increment
- *
- * @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 getIncrement() {
- checkWidget();
- double step = ((QDoubleSpinBox) getQWidget()).singleStep();
- int qstep = (int) (step * Math.pow(10, this.digits));
- return qstep;
- }
-
- /**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @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 getMaximum() {
- checkWidget();
- return (int) (((QDoubleSpinBox) getQWidget()).maximum() * Math.pow(10, this.digits));
- }
-
- /**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @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 getMinimum() {
- checkWidget();
- return (int) (((QDoubleSpinBox) getQWidget()).minimum() * Math.pow(10, this.digits));
- }
-
- /**
- * Returns the amount that the receiver's position will be modified by when
- * the page up/down keys are pressed.
- *
- * @return the page increment
- *
- * @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 getPageIncrement() {
- checkWidget();
- return (int) ((QDoubleSpinBox) getQWidget()).singleStep();
- }
-
- /**
- * Returns the selection, which is the receiver's position.
- *
- * @return the selection
- *
- * @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 getSelection() {
- checkWidget();
- int qselection = (int) (((QDoubleSpinBox) getQWidget()).value() * Math.pow(10, this.digits));
- this.selection = qselection;
- return qselection;
- }
-
- int getSelectionText(boolean[] parseFail) {
- // TODO
- return -1;
- }
-
- /**
- * 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
- *
- *
- * @since 3.4
- */
- public String getText() {
- checkWidget();
- return ((QDoubleSpinBox) getQWidget()).text();
- }
-
- /**
- * 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
- * Spinner.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
- *
- * @since 3.4
- */
- public int getTextLimit() {
- checkWidget();
- //TODO: not sure about this...
- int maxChars = String.valueOf(getMaximum()).trim().length();
- int minChars = String.valueOf(getMinimum()).trim().length();
- return maxChars > minChars ? maxChars : minChars;
- }
-
- /**
- * 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
- *
- */
- public void paste() {
- boolean isNumber = true;
- double pasteNumber;
-
- checkWidget();
- if ((style & SWT.READ_ONLY) != 0) {
- return;
- }
- String pasteText = QApplication.clipboard().text();
-
- try {
- pasteNumber = Double.parseDouble(pasteText);
- } catch (NumberFormatException e) {
- isNumber = false;
- return; // it's not a valid number, so just return and don't paste anything
- }
- if (isNumber && pasteNumber <= getMaximum() && pasteNumber >= getMinimum()) {
- this.selection = Integer.valueOf(QApplication.clipboard().text());
- ((QDoubleSpinBox) getQWidget()).setValue(pasteNumber);
- }
- }
-
- @Override
- void registerQWidget() {
- super.registerQWidget();
- }
-
- @Override
- void releaseQWidget() {
- super.releaseQWidget();
- }
-
- /**
- * 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 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);
- }
-
- /**
- * 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
- */
- void removeVerifyListener(VerifyListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (eventTable == null) {
- return;
- }
- eventTable.unhook(SWT.Verify, listener);
- }
-
- /**
- * Sets the number of decimal places used by the receiver.
- *
- * The digit setting is used to allow for floating point values in the
- * receiver. For example, to set the selection to a floating point value of
- * 1.37 call setDigits() with a value of 2 and setSelection() with a value
- * of 137. Similarly, if getDigits() has a value of 2 and getSelection()
- * returns 137 this should be interpreted as 1.37. This applies to all
- * numeric APIs.
- *
- *
- * @param value
- * the new digits (must be greater than or equal to zero)
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_INVALID_ARGUMENT - if the value is less than
- * 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
- *
- */
- public void setDigits(int value) {
- checkWidget();
- if (value < 0) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (value == this.digits) {
- return;
- }
-
- this.digits = value;
- ((QDoubleSpinBox) getQWidget()).setDecimals(value);
- ((QDoubleSpinBox) getQWidget()).setValue(selection / Math.pow(10, value));
- }
-
- /**
- * Sets the amount that the receiver's value will be modified by when the
- * up/down arrows are pressed to the argument, which must be at least one.
- *
- * @param value
- * the new increment (must be greater than 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
- *
- */
- public void setIncrement(int value) {
- checkWidget();
- if (value < 1) {
- return;
- }
- ((QDoubleSpinBox) getQWidget()).setSingleStep(value / Math.pow(10, this.digits));
- }
-
- /**
- * Sets the maximum value that the receiver will allow. This new value will
- * be ignored if it is not greater than the receiver's current minimum
- * value. If the new maximum is applied then the receiver's selection value
- * will be adjusted if necessary to fall within its new range.
- *
- * @param value
- * the new maximum, which must be greater than the current
- * minimum
- *
- * @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 setMaximum(int value) {
- checkWidget();
- ((QDoubleSpinBox) getQWidget()).setMaximum(value / Math.pow(10, this.digits));
- }
-
- /**
- * Sets the minimum value that the receiver will allow. This new value will
- * be ignored if it is not less than the receiver's current maximum value.
- * If the new minimum is applied then the receiver's selection value will be
- * adjusted if necessary to fall within its new range.
- *
- * @param value
- * the new minimum, which must be less than the current maximum
- *
- * @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 setMinimum(int value) {
- checkWidget();
- ((QDoubleSpinBox) getQWidget()).setMinimum(value / Math.pow(10, this.digits));
- }
-
- /**
- * Sets the amount that the receiver's position will be modified by when the
- * page up/down keys are pressed to the argument, which must be at least
- * one.
- *
- * @param value
- * the page increment (must be greater than 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
- *
- */
- public void setPageIncrement(int value) {
- checkWidget();
- if (value < 1) {
- return;
- }
- pageIncrement = value; // TODO: see bug 160
- }
-
- /**
- * Sets the selection, which is the receiver's position, to the
- * argument. If the argument is not within the range specified by minimum
- * and maximum, it will be adjusted to fall within this range.
- *
- * @param value
- * the new selection (must be zero or greater)
- *
- * @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(int value) {
- checkWidget();
- this.selection = value;
- ((QDoubleSpinBox) getQWidget()).setDecimals(this.digits);
- ((QDoubleSpinBox) getQWidget()).setValue(value / Math.pow(10, digits));
-
- }
-
- /**
- * 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(Spinner.LIMIT)
. Specifying a limit value larger
- * than Spinner.LIMIT
sets the receiver's limit to
- * Spinner.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
- *
- * @since 3.4
- */
- public void setTextLimit(int limit) {
- checkWidget();
- if (limit == 0) {
- error(SWT.ERROR_CANNOT_BE_ZERO);
- }
-
- if (limit < 0 || limit > LIMIT) {
- limit = LIMIT;
- }
-
- //TODO setting the text limit to the QDoubleSpinBox
- }
-
- /**
- * Sets the receiver's selection, minimum value, maximum value, digits,
- * increment and page increment all at once.
- *
- * Note: This is similar to setting the values individually using the
- * appropriate methods, but may be implemented in a more efficient fashion
- * on some platforms.
- *
- *
- * @param selection
- * the new selection value
- * @param minimum
- * the new minimum value
- * @param maximum
- * the new maximum value
- * @param digits
- * the new digits value
- * @param increment
- * the new increment value
- * @param pageIncrement
- * the new pageIncrement value
- *
- * @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 setValues(int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) {
- checkWidget();
- if (maximum <= minimum) {
- return;
- }
- if (digits < 0) {
- return;
- }
- if (increment < 1) {
- return;
- }
- if (pageIncrement < 1) {
- return;
- }
- this.selection = Math.min(Math.max(minimum, selection), maximum);
- ((QDoubleSpinBox) getQWidget()).setValue(this.selection);
- setIncrement(increment);
- this.pageIncrement = pageIncrement;
- this.digits = digits;
- }
-
- String verifyText(String string, int start, int end, Event keyEvent) {
- // Event event = new Event();
- // event.text = string;
- // event.start = start;
- // event.end = end;
- // if (keyEvent != null) {
- // event.character = keyEvent.character;
- // event.keyCode = keyEvent.keyCode;
- // event.stateMask = keyEvent.stateMask;
- // }
- // int index = 0;
- // if (digits > 0) {
- // String decimalSeparator = getDecimalSeparator();
- // index = string.indexOf(decimalSeparator);
- // if (index != -1) {
- // string = string.substring(0, index) + string.substring(index + 1);
- // }
- // index = 0;
- // }
- // if (string.length() > 0) {
- // int[] min = new int[1];
- // OS.SendMessage(hwndUpDown, OS.UDM_GETRANGE32, min, null);
- // if (min[0] < 0 && string.charAt(0) == '-')
- // index++;
- // }
- // while (index < string.length()) {
- // if (!Character.isDigit(string.charAt(index)))
- // break;
- // index++;
- // }
- // event.doit = index == string.length();
- // if ( !OS.IsUnicode && OS.IsDBLocale ) {
- // event.start = mbcsToWcsPos( start );
- // event.end = mbcsToWcsPos( end );
- // }
- // sendEvent(SWT.Verify, event);
- // if (!event.doit || isDisposed())
- return null;
- // return event.text;
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TabFolder.java
deleted file mode 100644
index 90fd790cba..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TabFolder.java
+++ /dev/null
@@ -1,755 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import java.util.ArrayList;
-
-import com.trolltech.qt.gui.QTabWidget;
-import com.trolltech.qt.gui.QVBoxLayout;
-import com.trolltech.qt.gui.QWidget;
-import com.trolltech.qt.gui.QSizePolicy.Policy;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.internal.qt.QtSWTConverter;
-
-/**
- * Instances of this class implement the notebook user interface metaphor. It
- * allows the user to select a notebook page from set of pages.
- *
- * The item children that may be added to instances of this class must be of
- * type TabItem
. Control
children are created and then
- * set into a tab item using TabItem#setControl
.
- *
- *
- * Note that although this class is a subclass of Composite
, it
- * does not make sense to set a layout on it.
- *
- *
- *
- * - Styles:
- * - TOP, BOTTOM
- * - Events:
- * - Selection
- *
- *
- * Note: Only one of the styles TOP and BOTTOM may be specified.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see TabFolder,
- * TabItem snippets
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabFolder extends Composite {
- private java.util.List items;
- private java.util.List tabWidgets;
-
- /**
- * 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 TabFolder(Composite parent, int style) {
- super(parent, checkStyle(style));
- }
-
- @Override
- protected QWidget createQWidget(int style) {
- state &= ~(CANVAS | THEME_BACKGROUND);
- items = new ArrayList(4);
- tabWidgets = new ArrayList(4);
- return new QTabWidget();
- }
-
- @Override
- protected void connectSignals() {
- getQTabWidget().currentChanged.connect(this, "selectionEvent(int)");//$NON-NLS-1$
- }
-
- QTabWidget getQTabWidget() {
- return (QTabWidget) getQWidget();
- }
-
- protected void selectionEvent(int index) {
- if (index != -1 && items != null) {
- TabItem item = getItem(index);
- Event event = new Event();
- event.item = item;
- sendEvent(SWT.Selection, event);
- }
- }
-
- protected void addQChild() {
- // do nothing
- }
-
- static int checkStyle(int style) {
- style = checkBits(style, SWT.TOP, SWT.BOTTOM, 0, 0, 0, 0);
-
- /*
- * 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.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- void createItem(TabItem item, int index) {
- int count = getQTabWidget().count();
- if (!(0 <= index && index <= count)) {
- error(SWT.ERROR_INVALID_RANGE);
- }
-
- items.add(index, item);
-
- QWidget widget = new QWidget();
- widget.setSizePolicy(Policy.Expanding, Policy.Expanding);
- widget.setContentsMargins(0, 0, 0, 0);
- QVBoxLayout layout = new QVBoxLayout();
- layout.setContentsMargins(0, 0, 0, 0);
- widget.setLayout(layout);
-
- tabWidgets.add(index, widget);
-
- getQTabWidget().insertTab(index, widget, item.getText());
-
- /*
- * Send a selection event when the item that is added becomes the new
- * selection. This only happens when the first item is added.
- */
- if (index == 0) {
- Event event = new Event();
- event.item = item;
- sendEvent(SWT.Selection, event);
- }
- }
-
- void updateItem(TabItem item, Control oldControl) {
- int index = indexOf(item);
- QWidget container = tabWidgets.get(index);
-
- if (oldControl != null) {
- QWidget widget = oldControl.getQMasterWidget();
- if (widget != null) {
- container.layout().removeWidget(widget);
- }
- }
-
- Control control = item.getControl();
- QWidget widget = null;
- if (control != null) {
- widget = control.getQMasterWidget();
- }
- if (widget == null) {
- return;
- }
- container.layout().addWidget(widget);
- }
-
- void destroyItem(TabItem item) {
- int count = getQTabWidget().count();
- int index = 0;
- while (index < count) {
- if (items.get(index) == item) {
- break;
- }
- index++;
- }
- if (index == count) {
- return;
- }
- int selectionIndex = getQTabWidget().currentIndex();
- items.remove(count);
- if (count > 0 && index == selectionIndex) {
- setSelection(Math.max(0, selectionIndex - 1), true);
- }
- }
-
- @Override
- Control findThemeControl() {
- /* It is not possible to change the background of this control */
- return this;
- }
-
- @Override
- public Rectangle getClientArea() {
- checkWidget();
- return QtSWTConverter.convert(getQTabWidget().contentsRect());
- }
-
- /**
- * 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.
- *
- * When widgetSelected
is called, the item field of the event
- * object is valid. widgetDefaultSelected
is not called.
- *
- *
- * @param listener
- * the listener which should be notified when the user changes
- * the receiver's selection
- *
- * @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);
- }
-
- /**
- * Returns the item at the given, zero-relative index in the receiver.
- * 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 TabItem getItem(int index) {
- checkWidget();
- int count = getQTabWidget().count();
- if (!(0 <= index && index < count)) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- return items.get(index);
- }
-
- /**
- * Returns the tab item at the given point in the receiver or null if no
- * such item exists. The point is in the coordinate system of the receiver.
- *
- * @param point
- * the point used to locate the item
- * @return the tab item at the given point, or null if the point is not in a
- * tab item
- *
- * @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
- *
- *
- * @since 3.4
- */
- public TabItem getItem(Point point) {
- checkWidget();
- if (point == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- QWidget widget = getQTabWidget().childAt(point.x, point.y);
- if (widget == null) {
- return null;
- }
- int index = getQTabWidget().indexOf(widget);
- if (index < 0 || index >= items.size()) {
- return null;
- }
- return items.get(index);
- }
-
- /**
- * Returns the number of items contained in the receiver.
- *
- * @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 getQTabWidget().count();
- }
-
- /**
- * Returns an array of TabItem
s which are the items in the
- * receiver.
- *
- * 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
- *
- * @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 TabItem[] getItems() {
- checkWidget();
- int count = getQTabWidget().count();
- TabItem[] result = new TabItem[count];
- System.arraycopy(items, 0, result, 0, count);
- return result;
- }
-
- /**
- * Returns an array of TabItem
s that are currently selected in
- * the receiver. An empty array indicates that no items are selected.
- *
- * Note: This is not the actual structure used by the receiver to maintain
- * its selection, so modifying the array will not affect the receiver.
- *
- *
- * @return an array representing the selection
- *
- * @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 TabItem[] getSelection() {
- checkWidget();
- int index = getQTabWidget().currentIndex();
- if (index == -1) {
- return new TabItem[0];
- }
- return new TabItem[] { items.get(index) };
- }
-
- /**
- * Returns the zero-relative index of the item which is currently selected
- * in the receiver, 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();
- return getQTabWidget().currentIndex();
- }
-
- /**
- * 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 item
- * the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item 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(TabItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- int count = getQTabWidget().count();
- for (int i = 0; i < count; i++) {
- if (items.get(i) == item) {
- return i;
- }
- }
- return -1;
- }
-
- @Override
- Point minimumSize(int wHint, int hHint, boolean flushCache) {
- Control[] children = _getChildren();
- int width = 0, height = 0;
- for (int i = 0; i < children.length; i++) {
- Control child = children[i];
- int index = 0;
- int count = getChildrenCount();
- while (index < count) {
- if (items.get(index).control == child) {
- break;
- }
- index++;
- }
- if (index == count) {
- Rectangle rect = child.getBounds();
- width = Math.max(width, rect.x + rect.width);
- height = Math.max(height, rect.y + rect.height);
- } else {
- Point size = child.computeSize(wHint, hHint, flushCache);
- width = Math.max(width, size.x);
- height = Math.max(height, size.y);
- }
- }
- return new Point(width, height);
- }
-
- @Override
- boolean mnemonicHit(char key) {
- for (int i = 0; i < items.size(); i++) {
- TabItem item = items.get(i);
- if (item != null) {
- char ch = findMnemonic(item.getText());
- if (Character.toUpperCase(key) == Character.toUpperCase(ch)) {
- if (forceFocus()) {
- if (i != getSelectionIndex()) {
- setSelection(i, true);
- }
- return true;
- }
- }
- }
- }
- return false;
- }
-
- @Override
- boolean mnemonicMatch(char key) {
- for (int i = 0; i < items.size(); i++) {
- TabItem item = items.get(i);
- if (item != null) {
- char ch = findMnemonic(item.getText());
- if (Character.toUpperCase(key) == Character.toUpperCase(ch)) {
- return true;
- }
- }
- }
- return false;
- }
-
- @Override
- void releaseChildren(boolean destroy) {
- if (items != null) {
- int count = getQTabWidget().count();
- for (int i = 0; i < count; i++) {
- TabItem item = items.get(i);
- if (item != null && !item.isDisposed()) {
- item.release(false);
- }
- }
- items = null;
- }
- super.releaseChildren(destroy);
- }
-
- @Override
- void removeControl(Control control) {
- super.removeControl(control);
- int count = getQTabWidget().count();
- for (int i = 0; i < count; i++) {
- TabItem item = items.get(i);
- if (item.control == control) {
- getQTabWidget().removeTab(i);
- item.setControl(null);
- }
- }
- }
-
- /**
- * 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);
- }
-
- /**
- * Sets the receiver's selection to the given item. The current selected is
- * first cleared, then the new item is selected.
- *
- * @param item
- * the item to select
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item 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
- *
- *
- * @since 3.2
- */
- public void setSelection(TabItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- setSelection(new TabItem[] { item });
- }
-
- /**
- * Sets the receiver's selection to be the given array of items. The current
- * selected is first cleared, then the new items are selected.
- *
- * @param items
- * the array of items
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if 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 setSelection(TabItem[] items) {
- checkWidget();
- if (items == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (items.length == 0) {
- setSelection(-1, false);
- } else {
- for (int i = items.length - 1; i >= 0; --i) {
- int index = indexOf(items[i]);
- if (index != -1) {
- setSelection(index, false);
- }
- }
- }
- }
-
- @Override
- public void setFont(Font font) {
- checkWidget();
- Rectangle oldRect = getClientArea();
- super.setFont(font);
- Rectangle newRect = getClientArea();
- if (!oldRect.equals(newRect)) {
- //sendResize();
- int index = getQTabWidget().currentIndex();
- if (index != -1) {
- TabItem item = items.get(index);
- Control control = item.control;
- if (control != null && !control.isDisposed()) {
- control.setBounds(getClientArea());
- }
- }
- }
- }
-
- /**
- * Selects the item at the given zero-relative index in the receiver. If the
- * item at the index was already selected, it remains selected. The current
- * selection is first cleared, then the new items are 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 setSelection(int index) {
- checkWidget();
- int count = getQTabWidget().count();
- if (!(0 <= index && index < count)) {
- return;
- }
- setSelection(index, false);
- }
-
- void setSelection(int index, boolean notify) {
- int oldIndex = getQTabWidget().currentIndex();
- if (oldIndex == index) {
- return;
- }
- if (oldIndex != -1) {
- TabItem item = items.get(oldIndex);
- Control control = item.control;
- if (control != null && !control.isDisposed()) {
- control.setVisible(false);
- }
- }
- getQTabWidget().setCurrentIndex(index);
- int newIndex = getQTabWidget().currentIndex();
- if (newIndex != -1) {
- TabItem item = items.get(newIndex);
- Control control = item.control;
- if (control != null && !control.isDisposed()) {
- control.setBounds(getClientArea());
- control.setVisible(true);
- }
- if (notify) {
- Event event = new Event();
- event.item = item;
- sendEvent(SWT.Selection, event);
- }
- }
- }
-
- @Override
- boolean traversePage(boolean next) {
- int count = getItemCount();
- if (count <= 1) {
- return false;
- }
- int index = getSelectionIndex();
- if (index == -1) {
- index = 0;
- } else {
- int offset = next ? 1 : -1;
- index = (index + offset + count) % count;
- }
- setSelection(index, true);
- if (index == getSelectionIndex()) {
- // TODO
- //OS.SendMessage(handle, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
- return true;
- }
- return false;
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TabItem.java
deleted file mode 100644
index e6a3286797..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TabItem.java
+++ /dev/null
@@ -1,389 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-
-/**
- * Instances of this class represent a selectable user interface object
- * corresponding to a tab for a page in a tab folder.
- *
- * - Styles:
- * - (none)
- * - Events:
- * - (none)
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see TabFolder,
- * TabItem snippets
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class TabItem extends Item {
- TabFolder parent;
- Control control;
- private String toolTipText;
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * TabFolder
) and a style value describing its behavior and
- * appearance. The item is added to the end of the items maintained by its
- * parent.
- *
- * 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 TabItem(TabFolder parent, int style) {
- super(parent, style);
- this.parent = parent;
- parent.createItem(this, parent.getItemCount());
- }
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * TabFolder
), a style value describing its behavior and
- * appearance, and the index at which to place it in the items maintained by
- * its parent.
- *
- * 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
- * @param index
- * the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the parent is null
- * - ERROR_INVALID_RANGE - if the index is not between 0
- * and the number of elements in the parent (inclusive)
- *
- * @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 TabItem(TabFolder parent, int style, int index) {
- super(parent, style);
- this.parent = parent;
- parent.createItem(this, index);
- }
-
- void _setText(int index, String string) {
- parent.getQTabWidget().setTabText(index, string);
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- @Override
- void destroyWidget() {
- parent.destroyItem(this);
- releaseQWidget();
- }
-
- /**
- * Returns the control that is used to fill the client area of the tab
- * folder when the user selects the tab item. If no control has been set,
- * return null
.
- *
- *
- * @return 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
- *
- */
- public Control getControl() {
- checkWidget();
- return control;
- }
-
- /**
- * Returns a rectangle describing the receiver's size and location relative
- * to its parent.
- *
- * @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
- *
- *
- * @since 3.4
- */
- public Rectangle getBounds() {
- checkWidget();
- int index = parent.indexOf(this);
- if (index == -1 || control == null) {
- return new Rectangle(0, 0, 0, 0);
- }
- return control.getBounds();
- }
-
- /**
- * Returns the receiver's parent, which must be a TabFolder
.
- *
- * @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 TabFolder getParent() {
- checkWidget();
- return parent;
- }
-
- /**
- * 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;
- }
-
- @Override
- void releaseQWidget() {
- super.releaseQWidget();
- parent = null;
- }
-
- @Override
- void releaseParent() {
- super.releaseParent();
- int index = parent.indexOf(this);
- if (index == parent.getSelectionIndex()) {
- if (control != null) {
- control.setVisible(false);
- }
- }
- }
-
- @Override
- void releaseWidget() {
- super.releaseWidget();
- control = null;
- }
-
- /**
- * Sets the control that is used to fill the client area of the tab folder
- * when the user selects the tab item.
- *
- *
- * @param control
- * the new control (or null)
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_INVALID_ARGUMENT - if the control 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 setControl(Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (control.parent != parent) {
- error(SWT.ERROR_INVALID_PARENT);
- }
- }
- if (this.control != null && this.control.isDisposed()) {
- this.control = null;
- }
- Control oldControl = this.control, newControl = control;
- this.control = control;
- parent.updateItem(this, oldControl);
- int index = parent.indexOf(this), selectionIndex = parent.getSelectionIndex();
- if (index != selectionIndex) {
- if (newControl != null) {
- if (selectionIndex != -1) {
- Control selectedControl = parent.getItem(selectionIndex).getControl();
- if (selectedControl == newControl) {
- return;
- }
- }
- return;
- }
- }
- }
-
- @Override
- public void setImage(Image image) {
- checkWidget();
- int index = parent.indexOf(this);
- if (index == -1) {
- return;
- }
- super.setImage(image);
- // TODO
- }
-
- /**
- * Sets the receiver's text. The string may include the mnemonic character.
- *
- *
- * 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 emphasised in a platform specific manner.
- * The mnemonic indicator character '&' can be escaped by doubling it in
- * the string, causing a single '&' to be displayed.
- *
- *
- * @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
- *
- *
- */
- @Override
- public void setText(String string) {
- checkWidget();
- if (string == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (string.equals(text)) {
- return;
- }
- int index = parent.indexOf(this);
- if (index == -1) {
- return;
- }
- super.setText(string);
- _setText(index, string);
- }
-
- /**
- * 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();
- toolTipText = string;
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Table.java
deleted file mode 100644
index 4783422fed..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Table.java
+++ /dev/null
@@ -1,2561 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import static com.trolltech.qt.core.Qt.ItemDataRole.*;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import com.trolltech.qt.core.QModelIndex;
-import com.trolltech.qt.core.QSize;
-import com.trolltech.qt.core.Qt;
-import com.trolltech.qt.core.Qt.AlignmentFlag;
-import com.trolltech.qt.core.Qt.DropActions;
-import com.trolltech.qt.core.Qt.ItemFlag;
-import com.trolltech.qt.core.Qt.ItemFlags;
-import com.trolltech.qt.core.Qt.Orientation;
-import com.trolltech.qt.core.Qt.ScrollBarPolicy;
-import com.trolltech.qt.core.Qt.SortOrder;
-import com.trolltech.qt.gui.QAbstractTableModel;
-import com.trolltech.qt.gui.QBrush;
-import com.trolltech.qt.gui.QDragEnterEvent;
-import com.trolltech.qt.gui.QDragLeaveEvent;
-import com.trolltech.qt.gui.QDragMoveEvent;
-import com.trolltech.qt.gui.QDropEvent;
-import com.trolltech.qt.gui.QHeaderView;
-import com.trolltech.qt.gui.QItemSelection;
-import com.trolltech.qt.gui.QTableView;
-import com.trolltech.qt.gui.QWidget;
-import com.trolltech.qt.gui.QAbstractItemView.DragDropMode;
-import com.trolltech.qt.gui.QAbstractItemView.EditTrigger;
-import com.trolltech.qt.gui.QAbstractItemView.SelectionBehavior;
-import com.trolltech.qt.gui.QAbstractItemView.SelectionMode;
-import com.trolltech.qt.gui.QHeaderView.ResizeMode;
-import com.trolltech.qt.gui.QItemSelectionModel.SelectionFlag;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.internal.qt.QtSWTConverter;
-import org.eclipse.swt.internal.qt.SignalConnector;
-
-/**
- * Instances of this class implement a selectable user interface object that
- * displays a list of images and strings and issues notification when selected.
- *
- * The item children that may be added to instances of this class must be of
- * type TableItem
.
- *
- *
- * Style VIRTUAL
is used to create a Table
whose
- * TableItem
s are to be populated by the client on an on-demand
- * basis instead of up-front. This can provide significant performance
- * improvements for tables that are very large or for which
- * TableItem
population is expensive (for example, retrieving
- * values from an external source).
- *
- *
- * Here is an example of using a Table
with style
- * VIRTUAL
:
- * final Table table = new Table (parent, SWT.VIRTUAL | SWT.BORDER);
- * table.setItemCount (1000000);
- * table.addListener (SWT.SetData, new Listener () {
- * public void handleEvent (Event event) {
- * TableItem item = (TableItem) event.item;
- * int index = table.indexOf (item);
- * item.setText ("Item " + index);
- * System.out.println (item.getText ());
- * }
- * });
- *
- *
- *
- * Note that although this class is a subclass of Composite
, it
- * does not normally make sense to add Control
children to it, or
- * set a layout on it, unless implementing something like a cell editor.
- *
- *
- *
- * - Styles:
- * - SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL, NO_SCROLL
- * - Events:
- * - Selection, DefaultSelection, SetData, MeasureItem, EraseItem, PaintItem
- *
- *
- *
- * Note: Only one of the styles SINGLE, and MULTI may be specified.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Table, TableItem,
- * TableColumn snippets
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Table extends Composite {
- // aka rows, contains the cells/data
- TableColumn sortColumn;
- private int sortDirection;
- private TableModel model;
-
- private SignalConnector itemSelectionChanged;
- private static final int DEFAULT_ITEMHIGHT = 14;
- private int itemHeight = DEFAULT_ITEMHIGHT;
-
- /**
- * 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#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#HIDE_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public Table(Composite parent, int style) {
- super(parent, checkStyle(style));
- }
-
- @Override
- protected QWidget createQWidget(int style) {
- state &= ~(CANVAS | THEME_BACKGROUND);
-
- QTableView table = new MyQTableWidget();
- model = new TableModel(isVirtual());
- table.setModel(model);
-
- table.verticalHeader().hide();
- table.horizontalHeader().hide();
- table.setEditTriggers(EditTrigger.NoEditTriggers);
- table.setShowGrid(false);
- table.setWordWrap(false);
- table.setHorizontalScrollBarPolicy(ScrollBarPolicy.ScrollBarAsNeeded);
- table.setVerticalScrollBarPolicy(ScrollBarPolicy.ScrollBarAsNeeded);
- table.horizontalHeader().setResizeMode(ResizeMode.Interactive);
- table.horizontalHeader().setStretchLastSection(true);
- table.horizontalHeader().setDefaultAlignment(Qt.AlignmentFlag.AlignLeft);
- table.horizontalHeader().setContentsMargins(0, 0, 0, 0);
- if ((style & SWT.MULTI) != 0) {
- table.setSelectionMode(SelectionMode.ExtendedSelection);
- } else {
- table.setSelectionMode(SelectionMode.SingleSelection);
- }
- table.setSelectionBehavior(SelectionBehavior.SelectRows);
- setQMasterWidget(table);
- return table.viewport();
- }
-
- @Override
- protected void connectSignals() {
- itemSelectionChanged = new SignalConnector(getQTableWidget().selectionModel().selectionChanged, this,
- "qtItemSelectionChangedEvent()").connect(); //$NON-NLS-1$
- }
-
- protected void qtItemSelectionChangedEvent() {
- int selectionIndex = getSelectionIndex();
- Event event = new Event();
- event.type = SWT.Selection;
- if (selectionIndex != -1) {
- event.item = getItem(selectionIndex);
- }
- sendEvent(SWT.Selection, event, true);
- }
-
- protected void selectionEvent(QItemSelection selected, QItemSelection deselected) {
- sendEvent(SWT.Selection);
- }
-
- public QTableView getQTableWidget() {
- return (QTableView) getQMasterWidget();
- }
-
- static int checkStyle(int style) {
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- return checkBits(style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
- }
-
- @Override
- protected void updateAutoFillBackground() {
- // nothing
- }
-
- @Override
- protected void updateBackground() {
- super.updateBackground();
- }
-
- @Override
- void updateBackgroundImage() {
- //super.updateBackgroundImage();
- }
-
- @Override
- protected Color getDefaultBackgroundColor() {
- return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
- }
-
- @Override
- public void setDragEnabled(boolean enabled) {
- getQTableWidget().setDragEnabled(enabled);
- }
-
- @Override
- public void setAcceptDrops(boolean accept) {
- super.setAcceptDrops(accept);
- getQTableWidget().setDragDropMode(DragDropMode.DragDrop);
- getQTableWidget().setDropIndicatorShown(true);
- }
-
- void addItem(TableItem item, int row) {
- model.addItem(item, row, false);
- }
-
- void removeRow(TableItem row) {
- model.removeRow(row);
- }
-
- void addColumn(TableColumn column, int index) {
- model.addColumn(column, index);
- }
-
- void removeColumn(TableColumn column) {
- model.removeColumn(column);
- }
-
- void rowChanged(TableItem row) {
- model.rowChanged(row);
- }
-
- void cellChanged(TableItem row, int column) {
- model.cellChanged(row, column);
- }
-
- void columnChanged(TableColumn column) {
- model.columnChanged(column);
- }
-
- Rectangle visualRect(TableItem row, int column) {
- return QtSWTConverter.convert(getQTableWidget().visualRect(model.index(indexOf(row), column)));
- }
-
- /**
- * 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.
- *
- * When widgetSelected
is called, the item field of the event
- * object is valid. If the receiver has the SWT.CHECK
style and
- * the check selection changes, the event object detail field contains the
- * value SWT.CHECK
. widgetDefaultSelected
is
- * typically called when an item is double-clicked. The item field of the
- * event object is valid for default selection, but the detail field is not
- * used.
- *
- *
- * @param listener
- * the listener which should be notified when the user changes
- * the receiver's selection
- *
- * @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);
- }
-
- boolean checkData(TableItem item, boolean redraw) {
- if ((style & SWT.VIRTUAL) == 0) {
- return true;
- }
-
- if (!item.cached) {
- item.cached = true;
- Event event = new Event();
- event.item = item;
- event.index = indexOf(item);
- sendEvent(SWT.SetData, event);
- // widget could be disposed at this point
- if (isDisposed() || item.isDisposed()) {
- return false;
- }
- }
- return true;
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- /**
- * Clears the item at the given zero-relative index in the receiver. The
- * text, icon and other attributes of the item are set to the default value.
- * If the table was created with the SWT.VIRTUAL
style, these
- * attributes are requested again as needed.
- *
- * @param index
- * the index of the item to clear
- *
- * @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
- *
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
- public void clear(int index) {
- checkWidget();
- validateItemIndex(index);
- model.getRow(index).clear();
- }
-
- /**
- * Removes the items from the receiver which are between the given
- * zero-relative start and end indices (inclusive). The text, icon and other
- * attributes of the items are set to their default values. If the table was
- * created with the SWT.VIRTUAL
style, these attributes are
- * requested again as needed.
- *
- * @param start
- * the start index of the item to clear
- * @param end
- * the end index of the item to clear
- *
- * @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
- *
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
- public void clear(int start, int end) {
- checkWidget();
- if (start > end) {
- return;
- }
- int count = model.rowCount();
- if (!(0 <= start && start <= end && end < count)) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- if (start == 0 && end == count - 1) {
- clearAll();
- }
- for (int index = start; index < end; index++) {
- model.getRow(index).clear();
- }
- }
-
- /**
- * Clears the items at the given zero-relative indices in the receiver. The
- * text, icon and other attributes of the items are set to their default
- * values. If the table was created with the SWT.VIRTUAL
style,
- * these attributes are requested again as needed.
- *
- * @param indices
- * the array of indices of the items
- *
- * @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 indices 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
- *
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
- public void clear(int[] indices) {
- checkWidget();
- if (indices == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (indices.length == 0) {
- return;
- }
- int count = model.rowCount();
- for (int i = 0; i < indices.length; i++) {
- if (!(0 <= indices[i] && indices[i] < count)) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- }
- for (int index : indices) {
- model.getRow(index).clear();
- }
- }
-
- /**
- * Clears all the items in the receiver. The text, icon and other attributes
- * of the items are set to their default values. If the table was created
- * with the SWT.VIRTUAL
style, these attributes are requested
- * again as needed.
- *
- * @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#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
- public void clearAll() {
- checkWidget();
- model.clearAllItems();
- //getQTableWidget().clearContents();
- }
-
- @Override
- public void pack() {
- // getQTableWidget().resizeColumnsToContents();
- // getQTableWidget().resizeRowsToContents();
- }
-
- @Override
- public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
- QSize size = getQTableWidget().sizeHint();
-
- if (getItemCount() > 0) {
- int width = 0;
- int height = 0;
-
- // Checkbox column
- if ((style & SWT.CHECK) != 0 || (style & SWT.RADIO) != 0) {
- width += getQTableWidget().columnWidth(0);
- }
-
- if (getColumnCount() > 0) {
- for (int i = 0; i < getColumnCount(); i++) {
- // if ( getColumn( i ).useFixedWidth ) {
- // width += getQTableWidget().columnWidth( i );
- // } else {
- width += getColumn(i).getPreferredColumnWidth(i);
- // }
- }
- } else { // list mode width +=
- getQTableWidget().sizeHintForColumn(1);
- }
-
- int borderWidth = getBorderWidth();
- width += 2 * borderWidth;
- height += 2 * borderWidth;
- height += getHeaderHeight();
- int items = getItemCount();
- height += items * _getItemHeight();
- size.setWidth(width);
- size.setHeight(height);
- }
-
- return QtSWTConverter.convert(size);
- }
-
- /**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver is selected,
- * it is deselected. If the item at the index was not selected, it remains
- * deselected. Indices that are out of range and duplicate indices are
- * ignored.
- *
- * @param indices
- * the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the set of indices 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 deselect(int[] indices) {
- checkWidget();
- if (indices == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (indices.length == 0) {
- return;
- }
- for (int index : indices) {
- _select(index, false);
- }
- }
-
- /**
- * Deselects the item at the given zero-relative index in the receiver. If
- * the item at the index was already deselected, it remains deselected.
- * Indices that are out of range are ignored.
- *
- * @param index
- * the index of the item to deselect
- *
- * @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 deselect(int index) {
- checkWidget();
- _select(index, false);
- }
-
- /**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver is selected,
- * it is deselected. If the item at the index was not selected, it remains
- * deselected. The range of the indices is inclusive. Indices that are out
- * of range are ignored.
- *
- * @param start
- * the start index of the items to deselect
- * @param end
- * the end index of the items to deselect
- *
- * @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 deselect(int start, int end) {
- checkWidget();
- _select(start, end, false);
- }
-
- /**
- * Deselects all selected items in 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 deselectAll() {
- checkWidget();
- itemSelectionChanged.runDisconnected(new Runnable() {
- public void run() {
- getQTableWidget().clearSelection();
- }
- });
- }
-
- /**
- * Returns the column at the given, zero-relative index in the receiver.
- * Throws an exception if the index is out of range. Columns are returned in
- * the order that they were created. If no TableColumn
s were
- * created by the programmer, this method will throw
- * ERROR_INVALID_RANGE
despite the fact that a single column of
- * data may be visible in the table. This occurs when the programmer uses
- * the table like a list, adding items but never creating a column.
- *
- * @param index
- * the index of the column to return
- * @return the column 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
- *
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
- public TableColumn getColumn(int index) {
- checkWidget();
- return model.getColumn(index);
- }
-
- /**
- * Returns the number of columns contained in the receiver. If no
- * TableColumn
s were created by the programmer, this value is
- * zero, despite the fact that visually, one column of items may be visible.
- * This occurs when the programmer uses the table like a list, adding items
- * but never creating a column.
- *
- * @return the number of columns
- *
- * @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 getColumnCount() {
- checkWidget();
- return model.columnCount();
- }
-
- /**
- * Returns an array of zero-relative integers that map the creation order of
- * the receiver's items to the order in which they are currently being
- * displayed.
- *
- * Specifically, the indices of the returned array represent the current
- * visual order of the items, and the contents of the array represent the
- * creation order of the items.
- *
- *
- * 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 current visual order of the receiver's 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
- *
- *
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
- public int[] getColumnOrder() {
- checkWidget();
- if (model.columnCount() == 0) {
- return new int[0];
- }
- return _getColumnOrder();
- }
-
- private int[] _getColumnOrder() {
- int columnCount = model.columnCount();
- int[] order = new int[columnCount];
- QHeaderView header = getQTableWidget().horizontalHeader();
- for (int i = 0; i < columnCount; i++) {
- order[i] = header.visualIndex(i);
- }
- return order;
- }
-
- /**
- * Returns an array of TableColumn
s which are the columns in
- * the receiver. Columns are returned in the order that they were created.
- * If no TableColumn
s were created by the programmer, the array
- * is empty, despite the fact that visually, one column of items may be
- * visible. This occurs when the programmer uses the table like a list,
- * adding items but never creating a column.
- *
- * 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
- *
- * @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 Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
- public TableColumn[] getColumns() {
- checkWidget();
- return model.getColumns();
- }
-
- /**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @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 getGridLineWidth() {
- checkWidget();
- return getQTableWidget().showGrid() ? 1 : 0;
- }
-
- /**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not 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 2.0
- */
- public int getHeaderHeight() {
- checkWidget();
- if (getQTableWidget().horizontalHeader().isVisible()) {
- return getQTableWidget().horizontalHeader().height();
- }
- return 0;
- }
-
- /**
- * Returns true
if the receiver's header 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 header'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 getHeaderVisible() {
- checkWidget();
- return !getQTableWidget().horizontalHeader().isHidden();
- }
-
- /**
- * Returns the item at the given, zero-relative index in the receiver.
- * 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 TableItem getItem(int index) {
- checkWidget();
- validateItemIndex(index);
- return model.getRow(index);
- }
-
- void validateItemIndex(int index) {
- if (!(0 <= index && index < model.rowCount())) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- }
-
- /**
- * Returns the item at the given point in the receiver or null if no such
- * item exists. The point is in the coordinate system of the receiver.
- *
- * The item that is returned represents an item that could be selected by
- * the user. For example, if selection only occurs in items in the first
- * column, then null is returned if the point is outside of the item. Note
- * that the SWT.FULL_SELECTION style hint, which specifies the selection
- * policy, determines the extent of the selection.
- *
- *
- * @param point
- * the point used to locate the item
- * @return the item at the given point, or null if the point is not in a
- * selectable item
- *
- * @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 TableItem getItem(Point point) {
- checkWidget();
- if (point == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- int row = getQTableWidget().rowAt(point.y);
- if (row < 0) {
- return null;
- }
- return model.getRow(row);
- }
-
- /**
- * Returns the number of items contained in the receiver.
- *
- * @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 model.rowCount();
- }
-
- /**
- * Returns the height of the area which would be used to display
- * one of the items in the receiver.
- *
- * @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 _getItemHeight();
- }
-
- int _getItemHeight() {
- int itemHeight = 0;
- if (model.rowCount() > 0) {
- itemHeight = getQTableWidget().rowHeight(0);
- } else {
- // getQTableWidget().insertRow(0);
- // itemHeight = getQTableWidget().rowHeight(0);
- // getQTableWidget().removeRow(0);
- }
- return itemHeight;
- }
-
- /**
- * Returns a (possibly empty) array of TableItem
s which are the
- * items in the receiver.
- *
- * 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
- *
- * @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 TableItem[] getItems() {
- checkWidget();
- return model.getRows();
- }
-
- /**
- * Returns true
if the receiver's lines are visible, and
- * false
otherwise. Note that some platforms draw grid lines
- * while others may draw alternating row colors.
- *
- * 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 visibility state of the lines
- *
- * @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 getLinesVisible() {
- checkWidget();
- return getQTableWidget().showGrid();
- }
-
- /**
- * Returns an array of TableItem
s that are currently selected
- * in the receiver. The order of the items is unspecified. An empty array
- * indicates that no items are selected.
- *
- * Note: This is not the actual structure used by the receiver to maintain
- * its selection, so modifying the array will not affect the receiver.
- *
- *
- * @return an array representing the selection
- *
- * @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 TableItem[] getSelection() {
- checkWidget();
- List selection = getQTableWidget().selectionModel().selectedRows();
-
- /*
- * This is an insert sort for sorting items according to their rows. In
- * SWT/Win32 the selection is returned sorted that way.
- */
- for (int i = 0; i < selection.size(); i++) {
- QModelIndex selectedItem = selection.get(i);
- int j = i;
- while (j > 0 && selection.get(j - 1).row() > selectedItem.row()) {
- selection.set(j, selection.get(j - 1));
- j = j - 1;
- }
- selection.set(j, selectedItem);
- }
-
- TableItem items[] = new TableItem[selection.size()];
- int i = 0;
- for (QModelIndex index : selection) {
- items[i++] = model.getRow(index.row());
- }
- return items;
- }
-
- /**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected 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 getSelectionCount() {
- checkWidget();
- return getQTableWidget().selectionModel().selectedRows().size();
- }
-
- /**
- * Returns the zero-relative index of the item which is currently selected
- * in the receiver, 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 (model.rowCount() == 0) {
- return -1;
- }
- // if (getQTableWidget().selectionModel().hasSelection()) {
- List selectedRows = getQTableWidget().selectionModel().selectedRows();
- if (selectedRows.size() > 0) {
- return selectedRows.get(0).row();
- }
- // }
- return -1;
- }
-
- /**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified. The
- * array is empty if no items are selected.
- *
- * Note: This is not the actual structure used by the receiver to maintain
- * its selection, so modifying the array will not affect the receiver.
- *
- *
- * @return the array of indices of the selected 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[] getSelectionIndices() {
- checkWidget();
- List selectedIndices = getQTableWidget().selectionModel().selectedRows();
- int[] result = new int[selectedIndices.size()];
- int i = 0;
- for (QModelIndex index : selectedIndices) {
- result[i++] = index.row();
- }
- return result;
- }
-
- /**
- * Returns the column which shows the sort indicator for the receiver. The
- * value may be null if no column shows the sort indicator.
- *
- * @return the sort indicator
- *
- * @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 #setSortColumn(TableColumn)
- *
- * @since 3.2
- */
- public TableColumn getSortColumn() {
- checkWidget();
- return sortColumn;
- }
-
- /**
- * Returns the direction of the sort indicator for the receiver. The value
- * will be one of UP
, DOWN
or NONE
.
- *
- * @return the sort direction
- *
- * @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 #setSortDirection(int)
- *
- * @since 3.2
- */
- public int getSortDirection() {
- checkWidget();
- return sortDirection;
- }
-
- /**
- * Returns the zero-relative index of the item which is currently at the top
- * of the receiver. This index can change when items are scrolled or new
- * items are added or removed.
- *
- * @return the index of the top 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 getTopIndex() {
- checkWidget();
- return getQTableWidget().rowAt(1);
- }
-
- /**
- * Searches the receiver's list starting at the first column (index 0) until
- * a column is found that is equal to the argument, and returns the index of
- * that column. If no column is found, returns -1.
- *
- * @param column
- * the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the column 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(TableColumn column) {
- checkWidget();
- if (column == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- return model.indexOf(column);
- }
-
- /**
- * 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 item
- * the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item 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(TableItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- return model.indexOf(item);
- }
-
- boolean isCustomToolTip() {
- return hooks(SWT.MeasureItem);
- }
-
- /**
- * Returns true
if the item is selected, and false
- * otherwise. Indices out of range are ignored.
- *
- * @param index
- * the index of the item
- * @return the selection state of the item at the index
- *
- * @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 isSelected(int index) {
- checkWidget();
- validateItemIndex(index);
- return model.getRow(index).isSelected();
- }
-
- @Override
- void releaseChildren(boolean destroy) {
- model.release();
- super.releaseChildren(destroy);
- }
-
- /**
- * Removes the items from the receiver's list at the given zero-relative
- * indices.
- *
- * @param indices
- * the array of indices of the items
- *
- * @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 indices 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 remove(int[] indices) {
- checkWidget();
- if (indices == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (indices.length == 0) {
- return;
- }
- model.removeItems(indices);
- }
-
- /**
- * Removes the item from the receiver 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();
- validateItemIndex(index);
- model.removeRowItem(index);
- }
-
- /**
- * Removes the items from the receiver 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;
- }
- int count = model.rowCount();
- if (!(0 <= start && start <= end && end < count)) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- if (start == 0 && end == count - 1) {
- removeAll();
- } else {
- for (int index = end; index >= start; index--) {
- model.removeRowItem(index);
- }
- }
- }
-
- /**
- * Removes all of the items from 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 removeAll() {
- checkWidget();
- model.releaseItems();
- // getQTableWidget().clearContents();
- // getQTableWidget().setRowCount(0);
- }
-
- /**
- * 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(SelectionListener)
- */
- 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);
- }
-
- /**
- * Selects the items at the given zero-relative indices in the receiver. The
- * current selection is not cleared before the new items are selected.
- *
- * If the item at a given index is not selected, it is selected. If the item
- * at a given index was already selected, it remains selected. Indices that
- * are out of range and duplicate indices are ignored. If the receiver is
- * single-select and multiple indices are specified, then all indices are
- * ignored.
- *
- *
- * @param indices
- * the array of indices for the items to select
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the array of indices 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 Table#setSelection(int[])
- */
- public void select(int[] indices) {
- checkWidget();
- if (indices == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- int length = indices.length;
- if (length == 0 || (style & SWT.SINGLE) != 0 && length > 1) {
- return;
- }
- for (int index : indices) {
- _select(index, true);
- }
- }
-
- /**
- * Selects the item at the given zero-relative index in the receiver. 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();
- _select(index, true);
- }
-
- void _select(int index, boolean selected) {
- if (index < 0 || index >= model.rowCount()) {
- return;
- }
- getQTableWidget().selectionModel().select(model.index(index, 0),
- SelectionFlag.createQFlags(SelectionFlag.Select, SelectionFlag.Rows));
- model.getRow(index).setSelected(selected);
- }
-
- /**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive. The current
- * selection is not cleared before the new items are selected.
- *
- * If an item in the given range is not selected, it is selected. If an item
- * in the given range was already selected, it remains selected. Indices
- * that are out of range are ignored and no items will be selected if start
- * is greater than end. If the receiver is single-select and there is more
- * than one item in the given range, then all indices are ignored.
- *
- *
- * @param start
- * the start of the range
- * @param end
- * the end of the range
- *
- * @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 Table#setSelection(int,int)
- */
- public void select(int start, int end) {
- checkWidget();
- _select(start, end, true);
- }
-
- void _select(int start, int end, boolean selected) {
- if (end < 0 || start > end || (style & SWT.SINGLE) != 0 && start != end) {
- return;
- }
- int count = model.rowCount();
- if (count == 0 || start >= count) {
- return;
- }
- start = Math.max(0, start);
- end = Math.min(end, count - 1);
- if (start == 0 && end == count - 1) {
- if (selected) {
- selectAll();
- } else {
- deselectAll();
- }
- } else {
- for (int index = start; index < end; index++) {
- _select(index, selected);
- }
- }
- }
-
- /**
- * Selects all of the items in the receiver.
- *
- * If the receiver is single-select, do nothing.
- *
- *
- * @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 selectAll() {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) {
- return;
- }
- getQTableWidget().selectAll();
- }
-
- /**
- * Sets the order that the items in the receiver should be displayed in to
- * the given argument which is described in terms of the zero-relative
- * ordering of when the items were added.
- *
- * @param order
- * the new order to display the 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
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item order is null
- * - ERROR_INVALID_ARGUMENT - if the item order is not the
- * same length as the number of items
- *
- *
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
- public void setColumnOrder(int[] order) {
- checkWidget();
- if (validateColumnOrder(order)) {
- int columnCount = getColumnCount();
- QHeaderView header = getQTableWidget().horizontalHeader();
- for (int i = 0; i < columnCount; i++) {
- int visualIndex = header.visualIndex(i);
- header.moveSection(visualIndex, order[i]);
- }
- }
- }
-
- private boolean validateColumnOrder(int[] order) {
- if (order == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- int columnCount = model.columnCount();
- if (columnCount == 0) {
- if (order.length != 0) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- return false;
- }
- if (order.length != columnCount) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int[] oldOrder = _getColumnOrder();
-
- boolean reorder = false;
- boolean[] seen = new boolean[columnCount];
- for (int i = 0; i < order.length; i++) {
- int index = order[i];
- if (index < 0 || index >= columnCount) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- if (seen[index]) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- seen[index] = true;
- if (index != oldOrder[i]) {
- reorder = true;
- }
- }
- return reorder;
- }
-
- /**
- * Marks the receiver's header 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 show
- * 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 setHeaderVisible(boolean show) {
- checkWidget();
- if (show) {
- getQTableWidget().horizontalHeader().show();
- } else {
- getQTableWidget().horizontalHeader().hide();
- }
- }
-
- /**
- * Sets the number of items contained in the receiver.
- *
- * @param count
- * 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
- *
- *
- * @since 3.0
- */
- public void setItemCount(int count) {
- checkWidget();
- model.setItemCount(count);
- }
-
- /**
- * @return true if Table was created with SWT.VIRTUAL style
- */
- boolean isVirtual() {
- return (style & SWT.VIRTUAL) != 0;
- }
-
- /**
- * Sets the height of the area which would be used to display one
- * of the items in the table.
- *
- * @param itemHeight
- * 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
- *
- *
- * @since 3.2
- */
- /* public */void setItemHeight(int itemHeight) {
- checkWidget();
- if (itemHeight < -1) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.itemHeight = itemHeight;
- int rows = model.rowCount();
- for (int row = 0; row < rows; row++) {
- getQTableWidget().setRowHeight(row, itemHeight);
- }
- }
-
- /**
- * Marks the receiver's lines as visible if the argument is
- * true
, and marks it invisible otherwise. Note that some
- * platforms draw grid lines while others may draw alternating row colors.
- *
- * 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 show
- * 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 setLinesVisible(boolean show) {
- checkWidget();
- getQTableWidget().setShowGrid(show);
- }
-
- /**
- * Selects the items at the given zero-relative indices in the receiver. The
- * current selection is cleared before the new items are selected.
- *
- * Indices that are out of range and duplicate indices are ignored. If the
- * receiver is single-select and multiple indices are specified, then all
- * indices are ignored.
- *
- *
- * @param indices
- * the indices of the items to select
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the array of indices 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 Table#deselectAll()
- * @see Table#select(int[])
- */
- public void setSelection(int[] indices) {
- checkWidget();
- if (indices == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- deselectAll();
- int length = indices.length;
- if (length == 0 || (style & SWT.SINGLE) != 0 && length > 1) {
- return;
- }
- select(indices);
- showSelection();
- }
-
- /**
- * Sets the receiver's selection to the given item. The current selection is
- * cleared before the new item is selected.
- *
- * If the item is not in the receiver, then it is ignored.
- *
- *
- * @param item
- * the item to select
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item is null
- * - ERROR_INVALID_ARGUMENT - if the item 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.2
- */
- public void setSelection(TableItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- setSelection(new TableItem[] { item });
- }
-
- /**
- * Sets the receiver's selection to be the given array of items. The current
- * selection is cleared before the new items are selected.
- *
- * Items that are not in the receiver are ignored. If the receiver is
- * single-select and multiple items are specified, then all items are
- * ignored.
- *
- *
- * @param items
- * the array of items
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the array of items is null
- * - ERROR_INVALID_ARGUMENT - if one of the items 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 Table#deselectAll()
- * @see Table#select(int[])
- * @see Table#setSelection(int[])
- */
- public void setSelection(TableItem[] items) {
- checkWidget();
- if (items == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- deselectAll();
- int length = items.length;
- if (length == 0 || (style & SWT.SINGLE) != 0 && length > 1) {
- return;
- }
- for (int i = length - 1; i >= 0; --i) {
- int index = indexOf(items[i]);
- if (index != -1) {
- select(index);
- }
- }
- showSelection();
- }
-
- /**
- * Selects the item at the given zero-relative index in the receiver. The
- * current selection is first cleared, then the new item is selected.
- *
- * @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
- *
- *
- * @see Table#deselectAll()
- * @see Table#select(int)
- */
- public void setSelection(int index) {
- checkWidget();
- deselectAll();
- select(index);
- showSelection();
- }
-
- /**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive. The current
- * selection is cleared before the new items are selected.
- *
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end. If the receiver is single-select and there
- * is more than one item in the given range, then all indices are ignored.
- *
- *
- * @param start
- * the start index of the items to select
- * @param end
- * the end index of the items 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
- *
- *
- * @see Table#deselectAll()
- * @see Table#select(int,int)
- */
- public void setSelection(int start, int end) {
- checkWidget();
- deselectAll();
- if (end < 0 || start > end || (style & SWT.SINGLE) != 0 && start != end) {
- return;
- }
- int count = model.rowCount();
- if (count == 0 || start >= count) {
- return;
- }
- start = Math.max(0, start);
- end = Math.min(end, count - 1);
- select(start, end);
- showSelection();
- }
-
- /**
- * Sets the column used by the sort indicator for the receiver. A null value
- * will clear the sort indicator. The current sort column is cleared before
- * the new column is set.
- *
- * @param column
- * the column used by the sort indicator or null
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_INVALID_ARGUMENT - if the column is 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.2
- */
- public void setSortColumn(TableColumn column) {
- checkWidget();
- if (column != null && column.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- sortColumn = column;
- if (sortColumn != null && sortDirection != SWT.NONE) {
- getQTableWidget().sortByColumn(column.getColumn(), getSortOrder());
- }
- }
-
- private SortOrder getSortOrder() {
- if ((sortDirection & SWT.UP) != 0) {
- return SortOrder.AscendingOrder;
- }
- return SortOrder.DescendingOrder;
- }
-
- /**
- * Sets the direction of the sort indicator for the receiver. The value can
- * be one of UP
, DOWN
or NONE
.
- *
- * @param direction
- * the direction of the sort indicator
- *
- * @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 setSortDirection(int direction) {
- checkWidget();
- if ((direction & (SWT.UP | SWT.DOWN)) == 0 && direction != SWT.NONE) {
- return;
- }
- sortDirection = direction;
- if (sortColumn != null && !sortColumn.isDisposed()) {
- getQTableWidget().sortByColumn(sortColumn.getColumn(), getSortOrder());
- }
- }
-
- /**
- * Sets the zero-relative index of the item which is currently at the top of
- * the receiver. This index can change when items are scrolled or new items
- * are added and removed.
- *
- * @param index
- * the index of the top 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 void setTopIndex(int index) {
- checkWidget();
- if (!(0 <= index && index < model.rowCount())) {
- return;
- }
- // int currentColumn = getQTableWidget().currentColumn();
- // QTableWidgetItem item = model.getItem(index).getCellItem(currentColumn);
- // getQTableWidget().scrollToItem(item, ScrollHint.PositionAtTop);
- }
-
- /**
- * Shows the column. If the column is already showing in the receiver, this
- * method simply returns. Otherwise, the columns are scrolled until the
- * column is visible.
- *
- * @param column
- * the column to be shown
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the column is null
- * - ERROR_INVALID_ARGUMENT - if the column 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 showColumn(TableColumn column) {
- checkWidget();
- if (column == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (column.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (column.getParent() != this) {
- return;
- }
- if (model.rowCount() == 0) {
- return;
- }
- QModelIndex index = getQTableWidget().currentIndex();
- getQTableWidget().scrollTo(model.index(index.row(), model.indexOf(column)));
- }
-
- /**
- * Shows the item. If the item is already showing in the receiver, this
- * method simply returns. Otherwise, the items are scrolled until the item
- * is visible.
- *
- * @param item
- * the item to be shown
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item is null
- * - ERROR_INVALID_ARGUMENT - if the item 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 Table#showSelection()
- */
- public void showItem(TableItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (item.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int index = indexOf(item);
- if (index != -1) {
- showItem(index, 0);
- }
- }
-
- void showItem(int row, int col) {
- getQTableWidget().scrollTo(model.index(row, col));
- }
-
- /**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until the
- * selection is 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
- *
- *
- * @see Table#showItem(TableItem)
- */
- public void showSelection() {
- checkWidget();
- getQTableWidget().scrollTo(getQTableWidget().selectionModel().currentIndex());
- }
-
- void update(boolean all) {
- getQTableWidget().update();
- }
-
- private final class MyQTableWidget extends QTableView {
-
- @Override
- protected void startDrag(DropActions supportedActions) {
- // System.out.println("MyQTreeWidget.startDrag: " + supportedActions);
- }
-
- @Override
- protected void dropEvent(QDropEvent event) {
- sendDropEvent(event);
- }
-
- @Override
- protected void dragMoveEvent(QDragMoveEvent event) {
- sendDragMoveEvent(event);
- }
-
- @Override
- protected void dragEnterEvent(QDragEnterEvent event) {
- sendDragEnterEvent(event);
- }
-
- @Override
- protected void dragLeaveEvent(QDragLeaveEvent event) {
- sendDragLeaveEvent(event);
- }
-
- }
-
- final class TableModel extends QAbstractTableModel {
- private ArrayList rows;
- private List columns;
- private final boolean virtual;
-
- TableModel(boolean virtual) {
- this.virtual = virtual;
- init();
- }
-
- public void init() {
- rows = new ArrayList(4);
- columns = new ArrayList(4);
- }
-
- @Override
- public Object data(QModelIndex index, int role) {
- int row = index.row();
- int column = index.column();
- TableItem rowItem = getRow(row);
- switch (role) {
- case DisplayRole:
- return rowItem.getText(column);
- case CheckStateRole:
- if ((style & SWT.CHECK) != 0 && column == 0) {
- return rowItem.getChecked();
- }
- break;
- case DecorationRole:
- Image img = rowItem.getImage(column);
- if (img != null) {
- return img.getQPixmap();
- }
- break;
- case BackgroundRole: {
- Color color = rowItem.getBackground(column);
- if (color != null) {
- return new QBrush(color.getColor());
- }
- break;
- }
- case ForegroundRole: {
- Color color = rowItem.getForeground(column);
- if (color != null) {
- return new QBrush(color.getColor());
- }
- break;
- }
- }
- return null;
- }
-
- @Override
- public boolean setData(QModelIndex index, Object value, int role) {
- if (role == CheckStateRole) {
- getRow(index.row()).setChecked(((Boolean) value).booleanValue());
- dataChanged.emit(index, index);
- return true;
- }
- return super.setData(index, value, role);
- }
-
- @Override
- public ItemFlags flags(QModelIndex index) {
- int column = index.column();
- if ((style & SWT.CHECK) != 0 && column == 0) {
- return new ItemFlags(new ItemFlag[] { ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEditable,
- ItemFlag.ItemIsEnabled, ItemFlag.ItemIsUserCheckable });
- }
- return super.flags(index);
- }
-
- @Override
- public int rowCount(QModelIndex index) {
- return rows.size();
- }
-
- void setItemCount(int count) {
- count = Math.max(0, count);
- if (count < rows.size()) {
- beginRemoveRows(null, rows.size(), count - 1);
- for (int i = rows.size() - 1; i >= count; i--) {
- TableItem row = rows.remove(i);
- row.release(false);
- }
- endRemoveRows();
- } else {
- beginInsertRows(null, rows.size(), count - 1);
- rows.ensureCapacity(count);
- boolean virtual = isVirtual();
- for (int i = rows.size(); i < count; i++) {
- if (virtual) {
- rows.add(null);
- } else {
- rows.add(new TableItem(Table.this, SWT.NONE, i));
- }
- }
- endInsertRows();
- }
- }
-
- TableItem getRow(int index) {
- TableItem item = rows.get(index);
- if (item != null) {
- return item;
- }
- if (!virtual) {
- return null;
- }
- item = new TableItem(Table.this, SWT.NONE, index, false);
- addItem(item, index, true);
- return item;
- }
-
- public TableItem[] getRows() {
- TableItem[] out = new TableItem[rows.size()];
- if (virtual) {
- int count = out.length;
- for (int i = 0; i < count; i++) {
- out[i] = getRow(i);
- }
- } else {
- rows.toArray(out);
- }
- return out;
- }
-
- int indexOf(TableItem row) {
- return rows.indexOf(row);
- }
-
- void addItem(TableItem rowItem, int row, boolean update) {
- beginInsertRows(null, row, row);
- // if we add items then we need an first column to hold them
- if (columns.size() == 0) {
- new TableColumn(Table.this, SWT.NONE);
- }
- if (update) {
- rows.set(row, rowItem);
- } else {
- if (row == rows.size()) {
- rows.add(rowItem);
- } else {
- rows.add(row, rowItem);
- }
- }
- endInsertRows();
- getQTableWidget().setRowHeight(row, itemHeight);
- }
-
- void cellChanged(TableItem rowItem, int column) {
- int row = indexOf(rowItem);
- QModelIndex index = index(row, column);
- dataChanged.emit(index, index);
- }
-
- void rowChanged(TableItem rowItem) {
- int row = indexOf(rowItem);
- dataChanged.emit(index(row, 0), index(row, columns.size() - 1));
- }
-
- void removeRow(TableItem row) {
- removeRowItem(rows.indexOf(row));
- }
-
- void removeRowItem(int index) {
- if (index != -1) {
- beginRemoveRows(null, index, index);
- TableItem item = rows.remove(index);
- if (item != null && !item.isDisposed()) {
- item.release(false);
- }
- endRemoveRows();
- }
- }
-
- void removeItems(int[] indices) {
- int[] newIndices = new int[indices.length];
- System.arraycopy(indices, 0, newIndices, 0, indices.length);
- Arrays.sort(newIndices);
- for (int i = indices.length - 1; i >= 0; i--) {
- validateItemIndex(indices[i]);
- removeRowItem(indices[i]);
- }
- }
-
- void clearAllItems() {
- for (TableItem item : rows) {
- if (item != null) {
- item.clear();
- }
- }
- }
-
- @Override
- public int columnCount(QModelIndex index) {
- return columns.size();
- }
-
- TableColumn getColumn(int index) {
- validateColumnIndex(index);
- return columns.get(index);
- }
-
- int indexOf(TableColumn column) {
- return columns.indexOf(column);
- }
-
- private void validateColumnIndex(int index) {
- if (!(0 <= index && index < columnCount())) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- }
-
- void addColumn(TableColumn column, int index) {
- if (!(0 <= index && index <= columnCount())) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- beginInsertColumns(null, index, index);
- if (index == columns.size()) {
- columns.add(column);
- } else {
- columns.add(index, column);
- }
- int columnCount = columns.size();
- for (TableItem item : rows) {
- if (item != null) {
- item.addColumn(index, columnCount);
- }
- }
- endInsertColumns();
- }
-
- void removeColumn(TableColumn column) {
- int index = columns.indexOf(column);
- if (index == -1) {
- return;
- }
- beginRemoveColumns(null, index, index);
- int columnCount = columnCount();
- columns.remove(column);
- for (TableItem item : rows) {
- if (item != null) {
- item.removeColumn(index, columnCount);
- }
- }
- endRemoveColumns();
- }
-
- TableColumn[] getColumns() {
- TableColumn[] out = new TableColumn[columns.size()];
- return columns.toArray(out);
- }
-
- void release() {
- releaseItems();
- releaseColumns();
- }
-
- private void releaseItems() {
- beginRemoveRows(null, 0, rows.size() - 1);
- for (TableItem item : rows) {
- if (item != null && !item.isDisposed()) {
- item.release(false);
- }
- }
- rows.clear();
- endRemoveRows();
- }
-
- private void releaseColumns() {
- beginRemoveColumns(null, 0, columns.size() - 1);
- for (TableColumn column : columns) {
- if (!column.isDisposed()) {
- column.release(false);
- }
- }
- columns.clear();
- endRemoveColumns();
- }
-
- @Override
- public Object headerData(int index, Orientation orientation, int role) {
- if (index >= columns.size()) {
- return null;
- }
- switch (role) {
- case DisplayRole:
- return columnText(index);
- case ToolTipRole:
- return columnTooltip(index);
- case TextAlignmentRole:
- return columnAlignment(index);
- }
- return null;
- }
-
- private Object columnAlignment(int index) {
- int alignment = columns.get(index).getAlignment();
- switch (alignment) {
- case SWT.LEFT:
- return AlignmentFlag.AlignLeft;
- case SWT.CENTER:
- return AlignmentFlag.AlignCenter;
- case SWT.RIGHT:
- return AlignmentFlag.AlignRight;
- }
- return null;
- }
-
- private Object columnText(int index) {
- return columns.get(index).getText();
- }
-
- private Object columnTooltip(int index) {
- return columns.get(index).getToolTipText();
- }
-
- void columnChanged(TableColumn column) {
- int index = indexOf(column);
- columnChanged(index, index);
- }
-
- void columnChanged(int from, int to) {
- headerDataChanged.emit(Orientation.Horizontal, from, to);
- }
-
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TableColumn.java
deleted file mode 100644
index 84e2e3da83..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TableColumn.java
+++ /dev/null
@@ -1,664 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.gui.QTableView;
-import com.trolltech.qt.gui.QHeaderView.ResizeMode;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Instances of this class represent a column in a table widget.
- *
- *
- * - Styles:
- * - LEFT, RIGHT, CENTER
- * - Events:
- * - Move, Resize, Selection
- *
- *
- *
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Table, TableItem,
- * TableColumn snippets
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TableColumn extends Item {
- private Table parent;
- private boolean resizable, moveable;
- private String tooltip;
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Table
) and a style value describing its behavior and
- * appearance. The item is added to the end of the items maintained by its
- * parent.
- *
- * 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#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public TableColumn(Table parent, int style) {
- this(parent, style, parent.getColumnCount());
- }
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Table
), a style value describing its behavior and
- * appearance, and the index at which to place it in the items maintained by
- * its parent.
- *
- * 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.
- *
- *
- * Note that due to a restriction on some platforms, the first column is
- * always left aligned.
- *
- *
- * @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
- * @param index
- * the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the parent is null
- * - ERROR_INVALID_RANGE - if the index is not between 0
- * and the number of elements in the parent (inclusive)
- *
- * @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#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public TableColumn(Table parent, int style, int index) {
- super(parent, checkStyle(style));
- resizable = true;
- this.parent = parent;
- parent.addColumn(this, index);
- }
-
- /**
- * 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 the control is selected by the user, by sending it one of the
- * messages defined in the SelectionListener
interface.
- *
- * widgetSelected
is called when the column header is selected.
- * widgetDefaultSelected
is not called.
- *
- *
- * @param listener
- * the listener which should be notified when the control is
- * selected by the user
- *
- * @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);
- }
-
- static int checkStyle(int style) {
- return checkBits(style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- QTableView getQTableView() {
- return parent.getQTableWidget();
- }
-
- int getColumn() {
- return parent.indexOf(this);
- }
-
- @Override
- void destroyWidget() {
- parent.removeColumn(this);
- releaseQWidget();
- }
-
- /**
- * 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
.
- *
- * @return the alignment
- *
- * @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 getAlignment() {
- checkWidget();
- 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;
- }
-
- @Override
- String getNameText() {
- return getText();
- }
-
- /**
- * Returns the receiver's parent, which must be a Table
.
- *
- * @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 Table getParent() {
- checkWidget();
- return parent;
- }
-
- /**
- * Gets the moveable attribute. A column that is not moveable cannot be
- * reordered by the user by dragging the header but may be reordered by the
- * programmer.
- *
- * @return the moveable attribute
- *
- * @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 Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
- public boolean getMoveable() {
- checkWidget();
- return moveable;
- }
-
- /**
- * Gets the resizable attribute. A column that is not resizable cannot be
- * dragged by the user but may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @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 getResizable() {
- checkWidget();
- return resizable;
- }
-
- protected int getPreferredColumnWidth(int index) {
- if (index != -1) {
- int width = getQTableView().sizeHintForColumn(index);
- if (parent.getHeaderVisible()) {
- width = Math.max(width, getQTableView().horizontalHeader().sectionSizeHint(index));
- }
- return width;
- }
- return 0;
- }
-
- /**
- * 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
- *
- *
- * @since 3.2
- */
- public String getToolTipText() {
- checkWidget();
- return this.tooltip;
- }
-
- /**
- * Gets the width of the receiver.
- *
- * @return the 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 getWidth() {
- checkWidget();
- int index = getColumn();
- if (index == -1) {
- return 0;
- }
- return getQTableView().columnWidth(index);
- }
-
- /**
- * 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
- *
- *
- */
- public void pack() {
- checkWidget();
- getQTableView().resizeColumnToContents(getColumn());
- }
-
- @Override
- void releaseQWidget() {
- super.releaseQWidget();
- parent = null;
- }
-
- @Override
- void releaseParent() {
- super.releaseParent();
- if (parent.sortColumn == this) {
- parent.sortColumn = null;
- }
- }
-
- /**
- * 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 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);
- }
-
- /**
- * Controls how text and images will be displayed in the receiver. The
- * argument should be one of LEFT
, RIGHT
or
- * CENTER
.
- *
- * Note that due to a restriction on some platforms, the first column is
- * always left aligned.
- *
- *
- * @param alignment
- * the new alignment
- *
- * @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 setAlignment(int alignment) {
- checkWidget();
- 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);
- parent.columnChanged(this);
- }
-
- @Override
- public void setImage(Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- super.setImage(image);
- parent.columnChanged(this);
- }
-
- /**
- * Sets the moveable attribute. A column that is moveable can be reordered
- * by the user by dragging the header. A column that is not moveable cannot
- * be dragged by the user but may be reordered by the programmer.
- *
- * @param moveable
- * the moveable attribute
- *
- * @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 Table#setColumnOrder(int[])
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.1
- */
- public void setMoveable(boolean moveable) {
- checkWidget();
- this.moveable = moveable;
- // TODO how to it for single column?
- getQTableView().horizontalHeader().setMovable(moveable);
- }
-
- /**
- * Sets the resizable attribute. A column that is resizable can be resized
- * by the user dragging the edge of the header. A column that is not
- * resizable cannot be dragged by the user but may be resized by the
- * programmer.
- *
- * @param resizable
- * the resize attribute
- *
- * @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 setResizable(boolean resizable) {
- checkWidget();
- this.resizable = resizable;
- ResizeMode resizeMode = resizable ? ResizeMode.Interactive : ResizeMode.Fixed;
- int col = getColumn();
- if (col != -1) {
- getQTableView().horizontalHeader().setResizeMode(col, resizeMode);
- }
- }
-
- @Override
- public void setText(String string) {
- checkWidget();
- if (string == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (string.equals(text)) {
- return;
- }
- super.setText(string);
- parent.columnChanged(this);
- }
-
- /**
- * 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
- *
- *
- * @since 3.2
- */
- public void setToolTipText(String string) {
- checkWidget();
- this.tooltip = string;
- parent.columnChanged(this);
- }
-
- /**
- * Sets the width of the receiver.
- *
- * @param width
- * the new 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 void setWidth(int width) {
- checkWidget();
- if (width < 0) {
- return;
- }
- int index = getColumn();
- if (index == -1) {
- return;
- }
- getQTableView().setColumnWidth(index, width);
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TableItem.java
deleted file mode 100644
index fc27cd11a4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TableItem.java
+++ /dev/null
@@ -1,1441 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.core.Qt.FocusPolicy;
-import com.trolltech.qt.gui.QRadioButton;
-import com.trolltech.qt.gui.QTableView;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-
-/**
- * Instances of this class represent a selectable user interface object that
- * represents an item in a table.
- *
- * - Styles:
- * - (none)
- * - Events:
- * - (none)
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Table, TableItem,
- * TableColumn snippets
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class TableItem extends Item {
- Table parent;
- String[] strings;
- Image[] images;
- Font font;
- Font[] cellFont;
- boolean checked, grayed, cached;
- int imageIndent;
- Color background;
- Color foreground;
- int[] cellBackground, cellForeground;
- private QRadioButton radioButton;
- private boolean selected;
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Table
) and a style value describing its behavior and
- * appearance. The item is added to the end of the items maintained by its
- * parent.
- *
- * 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 TableItem(Table parent, int style) {
- this(parent, style, checkNull(parent).getItemCount(), true);
- }
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Table
), a style value describing its behavior and
- * appearance, and the index at which to place it in the items maintained by
- * its parent.
- *
- * 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
- * @param index
- * the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the parent is null
- * - ERROR_INVALID_RANGE - if the index is not between 0
- * and the number of elements in the parent (inclusive)
- *
- * @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 TableItem(Table parent, int style, int index) {
- this(parent, style, index, true);
- }
-
- TableItem(Table parent, int style, int index, boolean create) {
- super(parent, style);
- this.parent = parent;
- if (create) {
- parent.addItem(this, index);
- updateCheckAndRadioPropertyForRow(index);
- }
- setText(index, "");//$NON-NLS-1$
- }
-
- private void updateCheckAndRadioPropertyForRow(int row) {
- if (radioButton == null && (parent.style & SWT.RADIO) != 0 && (parent.style & SWT.SINGLE) != 0) {
- //TODO
- radioButton = new QRadioButton();
- radioButton.released.connect(this, "radioButtonClickEvent()");//$NON-NLS-1$
- radioButton.setFocusPolicy(FocusPolicy.NoFocus);
- //getQTableWidget().setCellWidget(row, 0, radioButton);
- }
- }
-
- protected void radioButtonClickEvent() {
- sendEvent(SWT.Selection);
- }
-
- static Table checkNull(Table control) {
- if (control == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- return control;
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- QTableView getQTableWidget() {
- return parent.getQTableWidget();
- }
-
- // int getRow() {
- // return parent.indexOf(this);
- // }
-
- void clear() {
- text = "";//$NON-NLS-1$
- image = null;
- font = null;
- strings = null;
- images = null;
- imageIndent = 0;
- checked = grayed = false;
- if (background != null) {
- background.dispose();
- background = null;
- }
- if (foreground != null) {
- foreground.dispose();
- foreground = null;
- }
- cellFont = null;
- cellBackground = cellForeground = null;
- if (parent.isVirtual()) {
- cached = false;
- }
- }
-
- @Override
- void destroyWidget() {
- parent.removeRow(this);
- releaseQWidget();
- }
-
- /**
- * Returns the receiver's background 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
- *
- *
- * @since 2.0
- */
- public Color getBackground() {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- if (background == null) {
- return parent.getBackground();
- }
- return background;
- }
-
- /**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index
- * the column index
- * @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
- *
- *
- * @since 3.0
- */
- public Color getBackground(int index) {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return getBackground();
- }
- int pixel = cellBackground != null ? cellBackground[index] : -1;
- return pixel == -1 ? getBackground() : Color.qt_new(display, pixel);
- }
-
- /**
- * Returns a rectangle describing the receiver's size and location relative
- * to its parent.
- *
- * @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
- *
- *
- * @since 3.2
- */
- public Rectangle getBounds() {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- return getBounds(0);
- }
-
- /**
- * Returns a rectangle describing the receiver's size and location relative
- * to its parent at a column in the table.
- *
- * @param column
- * the index that specifies the column
- * @return the receiver's bounding column 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(int column) {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
-
- if (column < 0 || column >= parent.getItemCount()) {
- return new Rectangle(0, 0, 0, 0);
- }
- return parent.visualRect(this, column);
- }
-
- /**
- * Returns true
if the receiver is checked, and false
- * otherwise. When the parent does not have the CHECK
style,
- * return false.
- *
- * @return the checked state of the checkbox
- *
- * @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 getChecked() {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- if ((parent.style & SWT.CHECK) == 0) {
- return false;
- }
- return checked;
- }
-
- /**
- * Returns the font that the receiver will use to paint textual information
- * for this item.
- *
- * @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
- *
- *
- * @since 3.0
- */
- public Font getFont() {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- return font != null ? font : parent.getFont();
- }
-
- /**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index
- * the column index
- * @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
- *
- *
- * @since 3.0
- */
- public Font getFont(int index) {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return getFont();
- }
- if (cellFont == null || cellFont[index] == null) {
- return getFont();
- }
- return cellFont[index];
- }
-
- /**
- * 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
- *
- *
- * @since 2.0
- */
- public Color getForeground() {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- if (foreground == null) {
- return parent.getForeground();
- }
- return foreground;
- }
-
- /**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index
- * the column index
- * @return the 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
- *
- *
- * @since 3.0
- */
- public Color getForeground(int index) {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return getForeground();
- }
- int pixel = cellForeground != null ? cellForeground[index] : -1;
- return pixel == -1 ? getForeground() : Color.qt_new(display, pixel);
- }
-
- /**
- * Returns true
if the receiver is grayed, and false otherwise.
- * When the parent does not have the CHECK
style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @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 getGrayed() {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- if ((parent.style & SWT.CHECK) == 0) {
- return false;
- }
- return grayed;
- }
-
- @Override
- public Image getImage() {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- return super.getImage();
- }
-
- /**
- * Returns the image stored at the given column index in the receiver, or
- * null if the image has not been set or if the column does not exist.
- *
- * @param index
- * the column index
- * @return the image stored at the given column index in 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 Image getImage(int index) {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- if (index == 0) {
- return getImage();
- }
- if (images != null) {
- if (0 <= index && index < images.length) {
- return images[index];
- }
- }
- return null;
- }
-
- /**
- * Returns a rectangle describing the size and location relative to its
- * parent of an image at a column in the table. An empty rectangle is
- * returned if index exceeds the index of the table's last column.
- *
- * @param index
- * the index that specifies the column
- * @return the receiver's bounding image 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 getImageBounds(int index) {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- //TODO
- return getBounds(index);
- }
-
- /**
- * Gets the image indent.
- *
- * @return the indent
- *
- * @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 getImageIndent() {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- return imageIndent;
- }
-
- @Override
- String getNameText() {
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (!cached) {
- return "*virtual*"; //$NON-NLS-1$
- }
- }
- return super.getNameText();
- }
-
- /**
- * Returns the receiver's parent, which must be a Table
.
- *
- * @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 Table getParent() {
- checkWidget();
- return parent;
- }
-
- @Override
- public String getText() {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- return super.getText();
- }
-
- /**
- * Returns the text stored at the given column index in the receiver, or
- * empty string if the text has not been set.
- *
- * @param index
- * the column index
- * @return the text stored at the given column index in 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 String getText(int index) {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- if (index == 0) {
- return getText();
- }
- if (strings != null) {
- if (0 <= index && index < strings.length) {
- String string = strings[index];
- return string != null ? string : "";//$NON-NLS-1$
- }
- }
- return "";//$NON-NLS-1$
- }
-
- /**
- * Returns a rectangle describing the size and location relative to its
- * parent of the text at a column in the table. An empty rectangle is
- * returned if index exceeds the index of the table's last column.
- *
- * @param index
- * the index that specifies the column
- * @return the receiver's bounding text 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
- *
- *
- * @since 3.3
- */
- public Rectangle getTextBounds(int index) {
- checkWidget();
- if (!parent.checkData(this, true)) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- //TODO
- return getBounds(index);
- }
-
- @Override
- void releaseQWidget() {
- super.releaseQWidget();
- radioButton = null;
- parent = null;
- }
-
- @Override
- void releaseWidget() {
- super.releaseWidget();
- strings = null;
- images = null;
- cellFont = null;
- cellBackground = cellForeground = null;
- }
-
- /**
- * Sets the receiver's background color to the color specified by the
- * argument, or to the default system color for the item if the argument is
- * null.
- *
- * @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
- *
- *
- * @since 2.0
- */
- public void setBackground(Color color) {
- checkWidget();
- if (color != null && color.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = background;
- if (color == null) {
- background = null;
- } else {
- if (color.equals(background)) {
- return;
- }
- background = color;
- }
- if (oldColor != null) {
- oldColor.dispose();
- }
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
-
- parent.rowChanged(this);
- }
-
- /**
- * Sets the background color at the given column index in the receiver to
- * the color specified by the argument, or to the default system color for
- * the item if the argument is null.
- *
- * @param index
- * the column index
- * @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
- *
- *
- * @since 3.0
- */
- public void setBackground(int index, Color color) {
- checkWidget();
- if (color != null && color.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return;
- }
- int pixel = -1;
- if (color != null) {
- pixel = color.getPixel();
- }
- if (cellBackground == null) {
- cellBackground = new int[count];
- for (int i = 0; i < count; i++) {
- cellBackground[i] = -1;
- }
- }
- if (cellBackground[index] == pixel) {
- return;
- }
- cellBackground[index] = pixel;
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- parent.cellChanged(this, index);
- // QBrush brush = new QBrush(QtSWTConverter.convert(color));
- // getCellItem(index).setBackground(brush);
- }
-
- /**
- * Sets the checked state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param checked
- * the new checked state of the checkbox
- *
- * @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 setChecked(boolean checked) {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) {
- return;
- }
- if (this.checked == checked) {
- return;
- }
- setChecked(checked, false);
- }
-
- void setChecked(boolean checked, boolean notify) {
- this.checked = checked;
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- if (notify) {
- Event event = new Event();
- event.item = this;
- event.detail = SWT.CHECK;
- parent.postEvent(SWT.Selection, event);
- }
- parent.cellChanged(this, 0);
- // CheckState state = checked ? CheckState.Checked : CheckState.Unchecked;
- // getCellItem(0).setData(ItemDataRole.CheckStateRole, state);
- }
-
- /**
- * Sets the font that the receiver will use to paint textual information for
- * this item 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
- *
- *
- * @since 3.0
- */
- public void setFont(Font font) {
- checkWidget();
- if (font != null && font.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- Font oldFont = this.font;
- if (oldFont == font) {
- return;
- }
- this.font = font;
- if (oldFont != null && oldFont.equals(font)) {
- return;
- }
- if (font != null) {
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- }
- parent.rowChanged(this);
- // int row = getRow();
- // int columnCount = parent.getColumnCount();
- // for (int col = 0; col < columnCount; col++) {
- // getCellItem(row, col).setFont(font.getQFont());
- // }
- }
-
- /**
- * Sets the font that the receiver will use to paint textual information for
- * the specified cell in this item to the font specified by the argument, or
- * to the default font for that kind of control if the argument is null.
- *
- * @param index
- * the column index
- * @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
- *
- *
- * @since 3.0
- */
- public void setFont(int index, Font font) {
- checkWidget();
- if (font != null && font.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return;
- }
- if (cellFont == null) {
- if (font == null) {
- return;
- }
- cellFont = new Font[count];
- }
- Font oldFont = cellFont[index];
- if (oldFont == font) {
- return;
- }
- cellFont[index] = font;
- if (oldFont != null && oldFont.equals(font)) {
- return;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- parent.cellChanged(this, index);
- //getCellItem(index).setFont(font.getQFont());
- }
-
- /**
- * Sets the receiver's foreground color to the color specified by the
- * argument, or to the default system color for the item if the argument is
- * null.
- *
- * @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
- *
- *
- * @since 2.0
- */
- public void setForeground(Color color) {
- checkWidget();
- if (color != null && color.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = foreground;
- if (color == null) {
- foreground = null;
- } else {
- if (color.equals(foreground)) {
- return;
- }
- foreground = color;
- }
- if (oldColor != null) {
- oldColor.dispose();
- }
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- parent.rowChanged(this);
- // int row = getRow();
- // int columnCount = parent.getColumnCount();
- // QBrush brush = null;
- // if (foreground != null) {
- // brush = new QBrush(foreground.getColor());
- // }
- // for (int col = 0; col < columnCount; col++) {
- // getCellItem(row, col).setForeground(brush);
- // }
- }
-
- /**
- * Sets the foreground color at the given column index in the receiver to
- * the color specified by the argument, or to the default system color for
- * the item if the argument is null.
- *
- * @param index
- * the column index
- * @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
- *
- *
- * @since 3.0
- */
- public void setForeground(int index, Color color) {
- checkWidget();
- if (color != null && color.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return;
- }
- int pixel = -1;
- if (color != null) {
- pixel = color.getPixel();
- }
- if (cellForeground == null) {
- cellForeground = new int[count];
- for (int i = 0; i < count; i++) {
- cellForeground[i] = -1;
- }
- }
- if (cellForeground[index] == pixel) {
- return;
- }
- cellForeground[index] = pixel;
- if (parent.isVirtual()) {
- cached = true;
- }
- parent.cellChanged(this, index);
- //getCellItem(index).setForeground(new QBrush(QtSWTConverter.convert(color)));
- }
-
- /**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param grayed
- * the new grayed state of the checkbox;
- *
- * @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 setGrayed(boolean grayed) {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) {
- return;
- }
- if (this.grayed == grayed) {
- return;
- }
- this.grayed = grayed;
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- parent.cellChanged(this, 0);
- //getCellItem(0).setCheckState(CheckState.PartiallyChecked);
- }
-
- /**
- * Sets the image for multiple columns in the table.
- *
- * @param images
- * the array of new images
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the array of images is null
- * - ERROR_INVALID_ARGUMENT - if one of the images 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[] images) {
- checkWidget();
- if (images == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- for (int i = 0; i < images.length; i++) {
- setImage(i, images[i]);
- }
- }
-
- /**
- * Sets the receiver's image at a column.
- *
- * @param index
- * the column index
- * @param image
- * the new image
- *
- * @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(int index, Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (index == 0) {
- if (image != null && image.isIcon()) {
- if (image.equals(this.image)) {
- return;
- }
- }
- super.setImage(image);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return;
- }
- if (images == null && index != 0) {
- images = new Image[count];
- images[0] = image;
- }
- if (images != null) {
- if (image != null && image.isIcon()) {
- if (image.equals(images[index])) {
- return;
- }
- }
- images[index] = image;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- parent.cellChanged(this, index);
- //getCellItem(index).setIcon(image.getQIcon());
- }
-
- @Override
- public void setImage(Image image) {
- checkWidget();
- setImage(0, image);
- }
-
- /**
- * Sets the indent of the first column's image, expressed in terms of the
- * image's width.
- *
- * @param indent
- * the new indent
- *
- *
- * @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
- *
- *
- * @deprecated this functionality is not supported on most platforms
- */
- @Deprecated
- public void setImageIndent(int indent) {
- checkWidget();
- //TODO
- // if ( indent < 0 )
- // return;
- // if ( imageIndent == indent )
- // return;
- // imageIndent = indent;
- // if ( ( parent.style & SWT.VIRTUAL ) != 0 ) {
- // cached = true;
- // } else {
- // }
- }
-
- /**
- * Sets the text for multiple columns in the table.
- *
- * @param strings
- * the array of new strings
- *
- * @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[] strings) {
- checkWidget();
- if (strings == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- for (int i = 0; i < strings.length; i++) {
- String string = strings[i];
- if (string != null) {
- setText(i, string);
- }
- }
- }
-
- /**
- * Sets the receiver's text at a column
- *
- * @param index
- * the column index
- * @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(int index, String string) {
- checkWidget();
- if (string == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (index == 0) {
- if (string.equals(text)) {
- return;
- }
- super.setText(string);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return;
- }
- if (strings == null && index != 0) {
- strings = new String[count];
- strings[0] = text;
- }
- if (strings != null) {
- if (string.equals(strings[index])) {
- return;
- }
- strings[index] = string;
- }
- if (parent.isVirtual()) {
- cached = true;
- }
- parent.cellChanged(this, index);
- //getCellItem(index).setText(string);
- }
-
- @Override
- public void setText(String string) {
- checkWidget();
- setText(0, string);
- }
-
- void addColumn(int index, int columnCount) {
- String[] strings = this.strings;
- if (strings != null) {
- String[] temp = new String[columnCount + 1];
- System.arraycopy(strings, 0, temp, 0, index);
- System.arraycopy(strings, index, temp, index + 1, columnCount - index);
- strings = temp;
- }
- Image[] images = this.images;
- if (images != null) {
- Image[] temp = new Image[columnCount + 1];
- System.arraycopy(images, 0, temp, 0, index);
- System.arraycopy(images, index, temp, index + 1, columnCount - index);
- this.images = temp;
- }
- if (index == 0) {
- if (columnCount != 0) {
- if (strings == null) {
- this.strings = new String[columnCount + 1];
- this.strings[1] = text;
- }
- text = ""; //$NON-NLS-1$
- if (images == null) {
- images = new Image[columnCount + 1];
- images[1] = image;
- }
- image = null;
- }
- }
- if (cellBackground != null) {
- int[] cellBackground = this.cellBackground;
- int[] temp = new int[columnCount + 1];
- System.arraycopy(cellBackground, 0, temp, 0, index);
- System.arraycopy(cellBackground, index, temp, index + 1, columnCount - index);
- temp[index] = -1;
- this.cellBackground = temp;
- }
- if (cellForeground != null) {
- int[] cellForeground = this.cellForeground;
- int[] temp = new int[columnCount + 1];
- System.arraycopy(cellForeground, 0, temp, 0, index);
- System.arraycopy(cellForeground, index, temp, index + 1, columnCount - index);
- temp[index] = -1;
- this.cellForeground = temp;
- }
- if (cellFont != null) {
- Font[] cellFont = this.cellFont;
- Font[] temp = new Font[columnCount + 1];
- System.arraycopy(cellFont, 0, temp, 0, index);
- System.arraycopy(cellFont, index, temp, index + 1, columnCount - index);
- this.cellFont = temp;
- }
- }
-
- void removeColumn(int index, int columnCount) {
- if (columnCount == 0) {
- strings = null;
- images = null;
- cellBackground = null;
- cellForeground = null;
- cellFont = null;
- } else {
- if (strings != null) {
- String[] strings = this.strings;
- if (index == 0) {
- text = strings[1] != null ? strings[1] : ""; //$NON-NLS-1$
- }
- String[] temp = new String[columnCount];
- System.arraycopy(strings, 0, temp, 0, index);
- System.arraycopy(strings, index + 1, temp, index, columnCount - index);
- this.strings = temp;
- } else {
- if (index == 0) {
- text = ""; //$NON-NLS-1$
- }
- }
- if (images != null) {
- Image[] images = this.images;
- if (index == 0) {
- image = images[1];
- }
- Image[] temp = new Image[columnCount];
- System.arraycopy(images, 0, temp, 0, index);
- System.arraycopy(images, index + 1, temp, index, columnCount - index);
- this.images = temp;
- } else {
- if (index == 0) {
- image = null;
- }
- }
- if (cellBackground != null) {
- int[] cellBackground = this.cellBackground;
- int[] temp = new int[columnCount];
- System.arraycopy(cellBackground, 0, temp, 0, index);
- System.arraycopy(cellBackground, index + 1, temp, index, columnCount - index);
- this.cellBackground = temp;
- }
- if (cellForeground != null) {
- int[] cellForeground = this.cellForeground;
- int[] temp = new int[columnCount];
- System.arraycopy(cellForeground, 0, temp, 0, index);
- System.arraycopy(cellForeground, index + 1, temp, index, columnCount - index);
- this.cellForeground = temp;
- }
- if (cellFont != null) {
- Font[] cellFont = this.cellFont;
- Font[] temp = new Font[columnCount];
- System.arraycopy(cellFont, 0, temp, 0, index);
- System.arraycopy(cellFont, index + 1, temp, index, columnCount - index);
- this.cellFont = temp;
- }
- }
-
- }
-
- void setSelected(boolean selected) {
- this.selected = selected;
- // int columns = parent.getColumnCount();
- parent.cellChanged(this, 0);
- // int row = getRow();
- // for (int col = 0; col < columns; col++) {
- // //getCellItem(row, col).setSelected(selected);
- // }
- if ((parent.style & SWT.SINGLE) != 0 && (parent.style & SWT.RADIO) != 0) {
- radioButton.setChecked(selected);
- }
- }
-
- public boolean isSelected() {
- return selected;
-
- // int columns = parent.getColumnCount();
- // int row = getRow();
- // for (int col = 0; col < columns; col++) {
- // //TODO
- // // if (getCellItem(row, col).isSelected()) {
- // // return true;
- // // }
- // }
- // return false;
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Text.java
deleted file mode 100644
index c456792f05..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Text.java
+++ /dev/null
@@ -1,1875 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.core.QPoint;
-import com.trolltech.qt.core.QSize;
-import com.trolltech.qt.core.Qt.LayoutDirection;
-import com.trolltech.qt.gui.QAbstractScrollArea;
-import com.trolltech.qt.gui.QContentsMargins;
-import com.trolltech.qt.gui.QFontMetrics;
-import com.trolltech.qt.gui.QLineEdit;
-import com.trolltech.qt.gui.QMouseEvent;
-import com.trolltech.qt.gui.QScrollBar;
-import com.trolltech.qt.gui.QSizePolicy;
-import com.trolltech.qt.gui.QStyle;
-import com.trolltech.qt.gui.QTextBlock;
-import com.trolltech.qt.gui.QTextCursor;
-import com.trolltech.qt.gui.QTextDocument;
-import com.trolltech.qt.gui.QTextEdit;
-import com.trolltech.qt.gui.QTextLayout;
-import com.trolltech.qt.gui.QWidget;
-import com.trolltech.qt.gui.QFrame.Shape;
-import com.trolltech.qt.gui.QLineEdit.EchoMode;
-import com.trolltech.qt.gui.QTextCursor.MoveMode;
-import com.trolltech.qt.gui.QTextCursor.MoveOperation;
-import com.trolltech.qt.gui.QTextEdit.LineWrapMode;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.events.VerifyListener;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.internal.qt.QtSWTConverter;
-
-/**
- * Instances of this class are selectable user interface objects that allow the
- * user to enter and modify text. Text controls can be either single or
- * multi-line. When a text control is created with a border, the operating
- * system includes a platform specific inset around the contents of the control.
- * When created without a border, an effort is made to remove the inset such
- * that the preferred size of the control is the same size as the contents.
- *
- *
- * - Styles:
- * - CENTER, ICON_CANCEL, ICON_SEARCH, LEFT, MULTI, PASSWORD, SEARCH, SINGLE,
- * RIGHT, READ_ONLY, WRAP
- * - Events:
- * - DefaultSelection, Modify, Verify
- *
- *
- * Note: Only one of the styles MULTI and SINGLE may be specified, and only one
- * of the styles LEFT, CENTER, and RIGHT may be specified.
- *
- *
- * Note: The styles ICON_CANCEL and ICON_SEARCH are hints used in combination
- * with SEARCH. When the platform supports the hint, the text control shows
- * these icons. When an icon is selected, a default selection event is sent with
- * the detail field set to one of ICON_CANCEL or ICON_SEARCH. Normally,
- * application code does not need to check the detail. In the case of
- * ICON_CANCEL, the text is cleared before the default selection event is sent
- * causing the application to search for an empty string.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Text snippets
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Text extends Scrollable {
- private static final int minimumLineSpacing = 14;
- private static final int verticalMargin = 1;
- private static final int horizontalMargin = 2;
-
- int tabs = 8;
- int oldStart, oldEnd;
- boolean doubleClick, ignoreModify, ignoreVerify, ignoreCharacter;
- private int textLimit;
- /**
- * The maximum number of characters that can be entered into a text widget.
- *
- * Note that this value is platform dependent, based upon the native widget
- * implementation.
- *
- */
- public static final int LIMIT;
-
- /**
- * The delimiter used by multi-line text widgets. When text is queried and
- * from the widget, it will be delimited using this delimiter.
- */
- public static final String DELIMITER;
-
- /*
- * These values can be different on different platforms. Therefore they are
- * not initialized in the declaration to stop the compiler from inlining.
- */
- static {
- // LIMIT is the default maxlength of the QLineEdit
- LIMIT = new QLineEdit().maxLength();
- DELIMITER = "\n";//$NON-NLS-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#SINGLE
- * @see SWT#MULTI
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public Text(Composite parent, int style) {
- super(parent, checkStyle(style));
- setTabStops(tabs);
- }
-
- boolean isSingleLineEdit() {
- return (style & SWT.MULTI) == 0;
- }
-
- @Override
- protected QWidget createQWidget(int style) {
- doubleClick = true;
- if (isSingleLineEdit()) {
- return createQLineEdit(style);
- }
- return createQTextEdit(style);
- }
-
- QLineEdit createQLineEdit(int style) {
- QLineEdit lineEdit = new QLineEdit();
- if ((style & SWT.READ_ONLY) != 0) {
- lineEdit.setReadOnly(true);
- }
- if ((style & SWT.PASSWORD) != 0) {
- lineEdit.setEchoMode(EchoMode.Password);
- }
- lineEdit.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum);
- lineEdit.setContentsMargins(0, 0, 0, 0);
-
- connectQLineEditSignals(lineEdit);
-
- lineEdit.setFrame(false);
-
- return lineEdit;
- }
-
- QWidget createQTextEdit(int style) {
- QTextEdit textEdit = new MyQTextEdit();
- if ((style & SWT.READ_ONLY) != 0) {
- textEdit.setReadOnly(true);
- }
- if ((style & SWT.WRAP) != 0) {
- textEdit.setLineWrapMode(LineWrapMode.WidgetWidth);
- } else {
- textEdit.setLineWrapMode(LineWrapMode.NoWrap);
- }
- connectQTextEditSignals(textEdit);
-
- textEdit.setFrameShape(Shape.NoFrame);
- textEdit.setLineWidth(0);
-
- return textEdit;
- }
-
- @Override
- protected void checkAndUpdateBorder(QWidget control) {
- if (isSingleLineEdit()) {
- if ((style & SWT.BORDER) != 0) {
- getQLineEdit().setFrame(true);
- }
- } else {
- super.checkAndUpdateBorder(control);
- }
- }
-
- protected void connectQLineEditSignals(QLineEdit lineEdit) {
- lineEdit.textChanged.connect(this, "textChangeEvent(String)"); //$NON-NLS-1$
- }
-
- protected void connectQTextEditSignals(QTextEdit textEdit) {
- textEdit.textChanged.connect(this, "textChangeEvent()"); //$NON-NLS-1$
- }
-
- protected void textChangeEvent() {
- textChangeEvent(null);
- }
-
- protected void textChangeEvent(String text) {
- Event event = new Event();
- event.data = text;
- sendEvent(SWT.Modify, event);
- }
-
- @Override
- void registerQWidget() {
- super.registerQWidget();
- if (!isSingleLineEdit()) {
- display.addControl(getQTextEdit().viewport(), this);
- }
- }
-
- @Override
- void deregisterQWidget() {
- if (!isSingleLineEdit()) {
- display.removeControl(getQTextEdit().viewport());
- }
- super.deregisterQWidget();
- }
-
- private QLineEdit getQLineEdit() {
- return (QLineEdit) getQWidget();
- }
-
- private QTextEdit getQTextEdit() {
- return (QTextEdit) getQWidget();
- }
-
- @Override
- QAbstractScrollArea getQScrollArea() {
- if (!isSingleLineEdit()) {
- return getQTextEdit();
- }
- return null;
- }
-
- /**
- * 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 control is selected by the user, by sending it one of the
- * messages defined in the SelectionListener
interface.
- *
- * widgetSelected
is not called for texts.
- * widgetDefaultSelected
is typically called when ENTER is
- * pressed in a single-line text, or when ENTER is pressed in a search text.
- * If the receiver has the SWT.SEARCH | SWT.CANCEL
style and
- * the user cancels the search, the event object detail field contains the
- * value SWT.CANCEL
.
- *
- *
- * @param listener
- * the listener which should be notified when the control is
- * selected by the user
- *
- * @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
- */
- public void addVerifyListener(VerifyListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Verify, typedListener);
- }
-
- /**
- * Appends a string.
- *
- * The new text is appended to the text at the end of the widget.
- *
- *
- * @param string
- * the string to be appended
- *
- * @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 append(String string) {
- checkWidget();
- if (string == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- string = Display.withCrLf(string);
- if (isSingleLineEdit()) {
- getQLineEdit().setText(getQLineEdit().text() + string);
- } else {
- getQTextEdit().append(string);
- }
- }
-
- static int checkStyle(int style) {
- if ((style & SWT.SEARCH) != 0) {
- style |= SWT.SINGLE | SWT.BORDER;
- style &= ~SWT.PASSWORD;
- style &= ~SWT.ICON_CANCEL;
- /*
- * NOTE: ICON_CANCEL has the same value as H_SCROLL and ICON_SEARCH
- * has the same value as V_SCROLL so they are cleared because
- * SWT.SINGLE is set.
- */
- }
- if ((style & SWT.SINGLE) != 0 && (style & SWT.MULTI) != 0) {
- style &= ~SWT.MULTI;
- }
- style = checkBits(style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- if ((style & SWT.SINGLE) != 0) {
- style &= ~(SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
- }
- if ((style & SWT.WRAP) != 0) {
- style |= SWT.MULTI;
- style &= ~SWT.H_SCROLL;
- }
- if ((style & SWT.MULTI) != 0) {
- style &= ~SWT.PASSWORD;
- }
- if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) {
- return style;
- }
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) {
- return style | SWT.MULTI;
- }
- return style | SWT.SINGLE;
- }
-
- /**
- * Clears the selection.
- *
- * @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 clearSelection() {
- checkWidget();
- if (isSingleLineEdit()) {
- getQLineEdit().setCursorPosition(getQLineEdit().cursorPosition());
- } else {
- getQTextEdit().textCursor().clearSelection();
- }
- }
-
- @Override
- public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
-
- if (wHint != SWT.DEFAULT && wHint < 0) {
- wHint = SWT.DEFAULT;
- }
- if (hHint != SWT.DEFAULT && hHint < 0) {
- hHint = SWT.DEFAULT;
- }
-
- Point preferredSize;
- if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
- preferredSize = new Point(wHint, hHint);
- } else if (isSingleLineEdit()) {
- if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) {
- preferredSize = getPreferredSingleLineClientAreaSize();
- } else if (hHint == SWT.DEFAULT) {
- preferredSize = new Point(wHint, getPreferredSingleLineClientAreaSize().y);
- } else {
- preferredSize = new Point(getPreferredSingleLineClientAreaSize().x, hHint);
- }
- } else {
- if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) {
- preferredSize = getPreferredClientAreaSize(-1);
- } else if (hHint == SWT.DEFAULT) {
- preferredSize = new Point(wHint, getPreferredClientAreaSize(wHint).y);
- } else {
- preferredSize = new Point(getPreferredClientAreaSize(hHint).y, hHint);
- }
- }
-
- Rectangle trim = computeTrim(0, 0, preferredSize.x, preferredSize.y);
-
- return new Point(trim.width, trim.height);
- }
-
- private Point getPreferredSingleLineClientAreaSize() {
- QFontMetrics fm = new QFontMetrics(getQLineEdit().font());
- QContentsMargins margins = getQLineEdit().getContentsMargins();
- int left = margins.left;
- int top = margins.top;
- int right = margins.right;
- int bottom = margins.bottom;
- int h = Math.max(fm.lineSpacing(), minimumLineSpacing) + 2 * verticalMargin + top + bottom;
- int w = fm.width(getQLineEdit().text()) + 2 * horizontalMargin + left + right;
- Point size = new Point(w, h);
- if (size == null) {
- return new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
- }
- if (size.x < 0) {
- size.x = DEFAULT_WIDTH;
- }
- if (size.y < 0) {
- size.y = DEFAULT_HEIGHT;
- }
- return size;
- }
-
- private Point getPreferredClientAreaSize(int wHint) {
- QTextDocument doc = getQTextEdit().document();
- Point size = null;
- if (doc != null) {
- double oldTextWidth = doc.textWidth();
- if (wHint >= 0) {
- doc.setTextWidth(wHint);
- } else {
- doc.adjustSize();
- }
- QSize preferredSize = doc.size().toSize();
- doc.setTextWidth(oldTextWidth);
- size = new Point(preferredSize.width(), preferredSize.height());
- }
-
- if (size == null) {
- return new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
- }
- if (size.x < 0) {
- size.x = DEFAULT_WIDTH;
- }
- if (size.y < 0) {
- size.y = DEFAULT_HEIGHT;
- }
- return size;
- }
-
- @Override
- public Rectangle computeTrim(int x, int y, int width, int height) {
- checkWidget();
- if (isSingleLineEdit()) {
- if ((style & SWT.BORDER) != 0) {
- int border = 0;
- QStyle style = getQWidget().style();
- if (style != null) {
- border = style.pixelMetric(QStyle.PixelMetric.PM_DefaultFrameWidth);
- }
- x -= border;
- y -= border;
- width += 2 * border;
- height += 2 * border;
- }
- return new Rectangle(x, y, width, height);
- }
- return super.computeTrim(x, y, 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
- *
- */
- public void copy() {
- checkWidget();
- if (isSingleLineEdit()) {
- getQLineEdit().copy();
- } else {
- getQTextEdit().copy();
- }
- }
-
- /**
- * Cuts the selected text.
- *
- * 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
- *
- */
- public void cut() {
- checkWidget();
- if (isSingleLineEdit()) {
- getQLineEdit().cut();
- } else {
- getQTextEdit().cut();
- }
- }
-
- /**
- * Returns the line number of the caret.
- *
- * The line number of the caret is returned.
- *
- *
- * @return the line number
- *
- * @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 getCaretLineNumber() {
- checkWidget();
- if (!isSingleLineEdit()) {
- int lineNumber = 0;
- QTextCursor textCursor = getQTextEdit().textCursor();
- QTextBlock textBlock = textCursor.block();
- QTextLayout textLayout = textBlock.layout();
- if (textLayout != null) {
- lineNumber = textLayout.lineForTextPosition(textCursor.position() - textBlock.position()).lineNumber();
- }
- lineNumber += getNumberOfPrecedingTextLines(textBlock);
- return lineNumber;
- }
- return 0;
- }
-
- private int getNumberOfPrecedingTextLines(QTextBlock textBlock) {
- int lineCount = 0;
- while (textBlock.isValid()) {
- QTextLayout textLayout = textBlock.layout();
- if (textLayout != null) {
- int lines = textLayout.lineCount();
- lineCount += lines > 0 ? lines : 1;
- }
- textBlock = textBlock.previous();
- }
- return lineCount;
- }
-
- /**
- * Returns a point describing the receiver's location relative to its parent
- * (or its display if its parent is null).
- *
- * The location of the caret is returned.
- *
- *
- * @return a point, the location of the caret
- *
- * @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 getCaretLocation() {
- checkWidget();
- if (isSingleLineEdit()) {
- return new Point(0, 0);
- }
- return QtSWTConverter.convertPosition(getQTextEdit().cursorRect());
- }
-
- /**
- * Returns the character position of the caret.
- *
- * Indexing is zero based.
- *
- *
- * @return the position of the caret
- *
- * @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 getCaretPosition() {
- checkWidget();
- if (isSingleLineEdit()) {
- return getQLineEdit().cursorPosition();
- }
- return getQTextEdit().textCursor().position();
- }
-
- /**
- * Returns the number of characters.
- *
- * @return number of characters in 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
- *
- */
- public int getCharCount() {
- checkWidget();
- if (isSingleLineEdit()) {
- return getText().length();
-
- }
- QTextCursor cursor = getQTextEdit().textCursor();
- int oldPosition = cursor.position();
- cursor.movePosition(MoveOperation.End);
- int count = cursor.position();
- cursor.setPosition(oldPosition);
- return count;
- }
-
- /**
- * Returns the double click enabled flag.
- *
- * The double click flag enables or disables the default action of the text
- * widget when the user double clicks.
- *
- *
- * @return whether or not double click is enabled
- *
- * @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 getDoubleClickEnabled() {
- checkWidget();
- return doubleClick;
- }
-
- /**
- * Returns the echo character.
- *
- * The echo character is the character that is displayed when the user
- * enters text or the text is changed by the programmer.
- *
- *
- * @return the echo character
- *
- * @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 #setEchoChar
- */
- public char getEchoChar() {
- checkWidget();
- if (isSingleLineEdit()) {
- if ((style & SWT.PASSWORD) != 0) {
- return '*';
- }
- }
- return '\0';
- }
-
- /**
- * Returns the editable state.
- *
- * @return whether or not the receiver is editable
- *
- * @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 getEditable() {
- checkWidget();
- if (isSingleLineEdit()) {
- return !getQLineEdit().isReadOnly();
- }
- return !getQTextEdit().isReadOnly();
- }
-
- /**
- * Returns the number of lines.
- *
- * @return the number of lines in 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
- *
- */
- public int getLineCount() {
- checkWidget();
- if (isSingleLineEdit()) {
- return 1;
- }
- QTextDocument textDocument = getQTextEdit().document();
- if (textDocument != null) {
- return getNumberOfPrecedingTextLines(textDocument.end());
- }
- return 0;
- }
-
- /**
- * Returns the line delimiter.
- *
- * @return a string that is the line delimiter
- *
- * @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 #DELIMITER
- */
- public String getLineDelimiter() {
- checkWidget();
- return DELIMITER;
- }
-
- /**
- * Returns the height of a line.
- *
- * @return the height of a row of 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 int getLineHeight() {
- checkWidget();
- if (isSingleLineEdit()) {
- return getQLineEdit().fontMetrics().lineSpacing();
- }
- QTextLayout textLayout = getQTextEdit().textCursor().block().layout();
- if (textLayout != null) {
- return (int) Math.round(textLayout.lineAt(0).height());
- }
- return 0;
- }
-
- /**
- * Returns the orientation of the receiver, which will be one of the
- * constants SWT.LEFT_TO_RIGHT
or
- * SWT.RIGHT_TO_LEFT
.
- *
- * @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 the widget message. The message text is displayed as a hint for
- * the user, indicating the purpose of the field.
- *
- * Typically this is used in conjunction with SWT.SEARCH
.
- *
- *
- * @return the widget message
- *
- * @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 String getMessage() {
- checkWidget();
- return getQWidget().whatsThis();
- }
-
- /**
- * Returns the character position at the given point in the receiver or -1
- * if no such position exists. The point is in the coordinate system of the
- * receiver.
- *
- * Indexing is zero based.
- *
- *
- * @return the position of the caret
- *
- * @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
- */
- // TODO - Javadoc
- // /* public */int getPosition( Point point ) {
- // checkWidget();
- // if ( point == null )
- // error( SWT.ERROR_NULL_ARGUMENT );
- // int /* long */lParam = OS.MAKELPARAM( point.x, point.y );
- // int position = OS.LOWORD( OS.SendMessage( handle, OS.EM_CHARFROMPOS, 0,
- // lParam ) );
- // if ( !OS.IsUnicode && OS.IsDBLocale )
- // position = mbcsToWcsPos( position );
- // return position;
- // }
-
- /**
- * Returns a Point
whose x coordinate is the character position
- * representing the start of the selected text, 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 (isSingleLineEdit()) {
- int selectionStart = getQLineEdit().selectionStart();
- if (selectionStart == -1) {
- int cursorPos = getQLineEdit().cursorPosition();
- return new Point(cursorPos, cursorPos);
- }
- return new Point(selectionStart, selectionStart + getQLineEdit().selectedText().length());
- }
- int start = getQTextEdit().textCursor().selectionStart();
- int end = getQTextEdit().textCursor().selectionStart();
- return new Point(Math.min(start, end), Math.max(start, end));
- }
-
- /**
- * Returns the number of selected characters.
- *
- * @return the number of selected characters.
- *
- * @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 getSelectionCount() {
- checkWidget();
- Point selection = getSelection();
- return Math.abs(selection.y - selection.x);
- }
-
- /**
- * Gets the selected text, or an empty string if there is no current
- * selection.
- *
- * @return the selected 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 getSelectionText() {
- checkWidget();
- if (isSingleLineEdit()) {
- return getQLineEdit().selectedText();
- }
- return getQTextEdit().textCursor().selectedText();
- }
-
- /**
- * Returns the number of tabs.
- *
- * Tab stop spacing is specified in terms of the space (' ') character. The
- * width of a single tab stop is the pixel width of the spaces.
- *
- *
- * @return the number of tab characters
- *
- * @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 getTabs() {
- checkWidget();
- return tabs;
- }
-
- /**
- * Returns the widget text.
- *
- * The text for a text widget is the characters in the widget, or an empty
- * string if this has never been set.
- *
- *
- * @return the widget 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 (isSingleLineEdit()) {
- return getQLineEdit().text();
- }
- return getQTextEdit().toPlainText();
- }
-
- /**
- * Returns a range of text. Returns an empty string if the start of the
- * range is greater than the end.
- *
- * Indexing is zero based. The range of a selection is from 0..N-1 where N
- * is the number of characters in the widget.
- *
- *
- * @param start
- * the start of the range
- * @param end
- * the end of the range
- * @return the range of 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(int start, int end) {
- checkWidget();
- if (start > end || end < 0) {
- return "";//$NON-NLS-1$
- }
-
- String text = getText();
- if (text != null) {
- if (start >= text.length()) {
- text = "";//$NON-NLS-1$
- } else {
- start = Math.max(0, start);
- end = Math.min(end, text.length() - 1);
- text = text.substring(start, end + 1);
- }
- }
- return text;
- }
-
- /**
- * Returns the maximum number of characters that the receiver is capable of
- * holding.
- *
- * If this has not been changed by setTextLimit()
, it will be
- * the constant Text.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();
- if (isSingleLineEdit()) {
- return getQLineEdit().maxLength();
- }
- return textLimit > 0 ? textLimit : LIMIT;
- }
-
- /**
- * Returns the zero-relative index of the line which is currently at the top
- * of the receiver.
- *
- * This index can change when lines are scrolled or new lines are added or
- * removed.
- *
- *
- * @return the index of the top line
- *
- * @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 getTopIndex() {
- checkWidget();
- if (isSingleLineEdit()) {
- return 0;
- }
- QScrollBar scrollBar = getQTextEdit().verticalScrollBar();
- int index = 0;
- if (scrollBar != null) {
- int top = scrollBar.value();
- QTextCursor textCursor = getQTextEdit().cursorForPosition(new QPoint(0, 0));
- QTextBlock topBlock = textCursor.block();
- QTextLayout layout = topBlock.layout();
- if (layout != null && layout.position().y() < top) {
- int layoutPos = (int) Math.round(layout.position().y());
- for (int i = 0; i < layout.lineCount()
- && layoutPos + layout.lineAt(i).rect().bottom() <= top + layout.lineAt(i).rect().height() / 2; ++i) {
- ++index;
- }
- }
- index += getNumberOfPrecedingTextLines(topBlock);
- }
- return 0;
- }
-
- /**
- * Returns the top pixel.
- *
- * The top pixel is the pixel position of the line that is currently at the
- * top of the widget. On some platforms, a text widget can be scrolled by
- * pixels instead of lines so that a partial line is displayed at the top of
- * the widget.
- *
- *
- * The top pixel changes when the widget is scrolled. The top pixel does not
- * include the widget trimming.
- *
- *
- * @return the pixel position of the top line
- *
- * @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 getTopPixel() {
- checkWidget();
- if (isSingleLineEdit()) {
- return 0;
- }
- return getQTextEdit().verticalScrollBar().value();
- }
-
- /**
- * Inserts a string.
- *
- * The old selection is replaced with the new text.
- *
- *
- * @param string
- * the string
- *
- * @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 insert(String string) {
- checkWidget();
- if (string == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- string = Display.withCrLf(string);
- getQLineEdit().insert(string);
- }
-
- /**
- * 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
- *
- */
- public void paste() {
- checkWidget();
- if (isSingleLineEdit()) {
- getQLineEdit().paste();
- } else {
- getQTextEdit().paste();
- }
- }
-
- /**
- * 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 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);
- }
-
- /**
- * 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
- */
- public void removeVerifyListener(VerifyListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (eventTable == null) {
- return;
- }
- eventTable.unhook(SWT.Verify, listener);
- }
-
- /**
- * Selects all the text in 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 selectAll() {
- checkWidget();
- if (isSingleLineEdit()) {
- getQLineEdit().selectAll();
- } else {
- QTextCursor textCursor = getQTextEdit().textCursor();
- textCursor.select(QTextCursor.SelectionType.Document);
- getQTextEdit().setTextCursor(textCursor);
- }
- }
-
- /**
- * Sets the double click enabled flag.
- *
- * The double click flag enables or disables the default action of the text
- * widget when the user double clicks.
- *
- *
- * Note: This operation is a hint and is not supported on platforms that do
- * not have this concept.
- *
- *
- * @param doubleClick
- * the new double click flag
- *
- * @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 setDoubleClickEnabled(boolean doubleClick) {
- checkWidget();
- this.doubleClick = doubleClick;
- }
-
- /**
- * Sets the echo character.
- *
- * The echo character is the character that is displayed when the user
- * enters text or the text is changed by the programmer. Setting the echo
- * character to '\0' clears the echo character and redraws the original
- * text. If for any reason the echo character is invalid, or if the platform
- * does not allow modification of the echo character, the default echo
- * character for the platform is used.
- *
- *
- * @param echo
- * the new echo character
- *
- * @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 setEchoChar(char echo) {
- checkWidget();
- if (isSingleLineEdit()) {
- if (echo == '\0') {
- getQLineEdit().setEchoMode(EchoMode.Normal);
- } else {
- getQLineEdit().setEchoMode(EchoMode.Password);
- }
- }
- }
-
- /**
- * Sets the editable state.
- *
- * @param editable
- * the new editable 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 setEditable(boolean editable) {
- checkWidget();
- if (isSingleLineEdit()) {
- getQLineEdit().setReadOnly(!editable);
- } else {
- getQTextEdit().setReadOnly(!editable);
- }
- }
-
- @Override
- public void setFont(Font font) {
- checkWidget();
- super.setFont(font);
- setTabStops(tabs);
- }
-
- /**
- * Sets the widget message. The message text is displayed as a hint for the
- * user, indicating the purpose of the field.
- *
- * Typically this is used in conjunction with SWT.SEARCH
.
- *
- *
- * @param message
- * the new message
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the message 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
- *
- *
- * @since 3.3
- */
- public void setMessage(String message) {
- checkWidget();
- getQWidget().setWhatsThis(message);
- }
-
- /**
- * Sets the orientation of the receiver, which must be one of the constants
- * SWT.LEFT_TO_RIGHT
or SWT.RIGHT_TO_LEFT
.
- *
- * Note: This operation is a hint and is not supported on platforms that do
- * not have this concept.
- *
- *
- * @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) {
- checkWidget();
- int flags = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT;
- if ((orientation & flags) == 0 || (orientation & flags) == flags) {
- return;
- }
-
- style &= ~flags;
- style |= orientation & flags;
-
- LayoutDirection direction = LayoutDirection.LeftToRight;
- if (orientation == SWT.RIGHT_TO_LEFT) {
- direction = LayoutDirection.RightToLeft;
- }
- getQWidget().setLayoutDirection(direction);
- }
-
- /**
- * Sets the selection.
- *
- * Indexing is zero based. The range of a selection is from 0..N where N is
- * the number of characters in the widget.
- *
- *
- * Text selections are specified in terms of caret positions. In a text
- * widget that contains N characters, there are N+1 caret positions, ranging
- * from 0..N. This differs from other functions that address character
- * position such as getText () that use the regular array indexing rules.
- *
- *
- * @param start
- * new caret position
- *
- * @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(int start) {
- checkWidget();
- setSelection(start, start);
- }
-
- /**
- * Sets the selection to the range specified by the given start and end
- * indices.
- *
- * Indexing is zero based. The range of a selection is from 0..N where N is
- * the number of characters in the widget.
- *
- *
- * Text selections are specified in terms of caret positions. In a text
- * widget that contains N characters, there are N+1 caret positions, ranging
- * from 0..N. This differs from other functions that address character
- * position such as getText () that use the usual array indexing rules.
- *
- *
- * @param start
- * the start of the range
- * @param end
- * the end of the range
- *
- * @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(int start, int end) {
- checkWidget();
- int length = getCharCount();
- start = Math.min(Math.max(0, start), length);
- end = Math.min(Math.max(0, end), length);
-
- if (isSingleLineEdit()) {
- getQLineEdit().setSelection(start, end - start);
- } else {
- setCursorPosition(start, true);
- setCursorPosition(end, false);
- }
-
- }
-
- private void setCursorPosition(int pos, boolean moveAnchor) {
- QTextCursor textCursor = getQTextEdit().textCursor();
- textCursor.setPosition(pos, moveAnchor ? MoveMode.MoveAnchor : MoveMode.KeepAnchor);
- getQTextEdit().setTextCursor(textCursor);
- }
-
- /**
- * Sets the selection to the range specified by the given point, where the x
- * coordinate represents the start index and the y coordinate represents the
- * end index.
- *
- * Indexing is zero based. The range of a selection is from 0..N where N is
- * the number of characters in the widget.
- *
- *
- * Text selections are specified in terms of caret positions. In a text
- * widget that contains N characters, there are N+1 caret positions, ranging
- * from 0..N. This differs from other functions that address character
- * position such as getText () that use the usual array indexing rules.
- *
- *
- * @param selection
- * the point
- *
- * @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);
- }
- setSelection(selection.x, selection.y);
- }
-
- /**
- * Sets the number of tabs.
- *
- * Tab stop spacing is specified in terms of the space (' ') character. The
- * width of a single tab stop is the pixel width of the spaces.
- *
- *
- * @param tabs
- * the number of tabs
- *
- *
- * @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 setTabs(int tabs) {
- checkWidget();
- if (tabs < 0) {
- return;
- }
- this.tabs = tabs;
- setTabStops(this.tabs);
- }
-
- void setTabStops(int tabs) {
- if (!isSingleLineEdit()) {
- getQTextEdit().setTabStopWidth(getQTextEdit().fontMetrics().width(" ") * tabs);//$NON-NLS-1$
- }
- }
-
- /**
- * Sets the contents of the receiver to the given string. If the receiver
- * has style SINGLE and the argument contains multiple lines of text, the
- * result of this operation is undefined and may vary from platform to
- * platform.
- *
- * @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);
- }
- string = Display.withCrLf(string);
- if (isSingleLineEdit()) {
- getQLineEdit().setText(string);
- } else {
- getQTextEdit().setText(string);
- }
- }
-
- /**
- * Sets the maximum number of characters that the receiver is capable of
- * holding to be the argument.
- *
- * Instead of trying to set the text limit to zero, consider creating a
- * read-only text widget.
- *
- *
- * To reset this value to the default, use
- * setTextLimit(Text.LIMIT)
. Specifying a limit value larger
- * than Text.LIMIT
sets the receiver's limit to
- * Text.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 (limit < 0 || limit > LIMIT) {
- limit = LIMIT;
- }
-
- if (isSingleLineEdit()) {
- getQLineEdit().setMaxLength(limit);
- } else {
- textLimit = limit;
- if (getCharCount() > limit) {
- getQTextEdit().setPlainText(getText().substring(0, limit));
- }
- }
- }
-
- /**
- * Sets the zero-relative index of the line which is currently at the top of
- * the receiver. This index can change when lines are scrolled or new lines
- * are added and removed.
- *
- * @param index
- * the index of the top 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 void setTopIndex(int index) {
- checkWidget();
- if (!isSingleLineEdit()) {
- index = Math.min(Math.max(index, 0), getLineCount() - 1);
- QScrollBar scrollBar = getQTextEdit().verticalScrollBar();
- QTextDocument textDocument = getQTextEdit().document();
- if (scrollBar != null && textDocument != null) {
- if (index == 0) {
- scrollBar.setValue(0);
- } else {
- QTextBlock textBlock = textDocument.begin();
- int lineCount = 0;
- while (textBlock.isValid()) {
- QTextLayout layout = textBlock.layout();
- if (layout != null) {
- int oldLineCount = lineCount;
- int lines = layout.lineCount();
- lineCount += lines > 0 ? lines : 1;
- if (index < lineCount) {
- int linePosition = (int) Math.round(layout.position().y()
- + layout.lineAt(index - oldLineCount).y());
- scrollBar.setValue(linePosition);
- break;
- }
- }
- textBlock = textBlock.next();
- }
- }
- }
- }
- }
-
- /**
- * Shows the selection.
- *
- * If the selection is already showing in the receiver, this method simply
- * returns. Otherwise, lines are scrolled until the selection is 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
- *
- */
- public void showSelection() {
- checkWidget();
- if (!isSingleLineEdit()) {
- getQTextEdit().ensureCursorVisible();
- }
- }
-
- private final class MyQTextEdit extends QTextEdit {
-
- @Override
- protected void mousePressEvent(QMouseEvent e) {
- super.mousePressEvent(e);
- e.setAccepted(false);
- }
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ToolBar.java
deleted file mode 100644
index 3e7a1a152a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ToolBar.java
+++ /dev/null
@@ -1,530 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import java.util.List;
-
-import com.trolltech.qt.core.QSize;
-import com.trolltech.qt.core.Qt.ContextMenuPolicy;
-import com.trolltech.qt.core.Qt.Orientation;
-import com.trolltech.qt.core.Qt.ToolButtonStyle;
-import com.trolltech.qt.gui.QAction;
-import com.trolltech.qt.gui.QToolBar;
-import com.trolltech.qt.gui.QWidget;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-
-/**
- * Instances of this class support the layout of selectable tool bar items.
- *
- * The item children that may be added to instances of this class must be of
- * type ToolItem
.
- *
- *
- * Note that although this class is a subclass of Composite
, it
- * does not make sense to add Control
children to it, or set a
- * layout on it.
- *
- *
- *
- * - Styles:
- * - FLAT, WRAP, RIGHT, HORIZONTAL, VERTICAL, SHADOW_OUT
- * - Events:
- * - (none)
- *
- *
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see ToolBar, ToolItem
- * snippets
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolBar extends Composite {
- /*
- * From the Windows SDK for TB_SETBUTTONSIZE:
- *
- * "If an application does not explicitly set the button size, the size
- * defaults to 24 by 22 pixels".
- */
- private static final int DEFAULT_WIDTH = 24;
- private static final int DEFAULT_HEIGHT = 22;
-
- /**
- * 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#FLAT
- * @see SWT#WRAP
- * @see SWT#RIGHT
- * @see SWT#HORIZONTAL
- * @see SWT#SHADOW_OUT
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass()
- * @see Widget#getStyle()
- */
- public ToolBar(Composite parent, int style) {
- super(parent, checkStyle(style));
- }
-
- @Override
- protected QWidget createQWidget(int style) {
- state &= ~CANVAS;
- QToolBar toolbar = new QToolBar();
- initOrientation(toolbar, style);
- toolbar.setStyleSheet("QToolBar { border: 0px; margin: 0px;}"); //$NON-NLS-1$ // background-color: #234;
- toolbar.setContentsMargins(0, 0, 0, 0);
- toolbar.setIconSize(new QSize(16, 16));
- toolbar.setToolButtonStyle(ToolButtonStyle.ToolButtonTextBesideIcon);
- toolbar.setContextMenuPolicy(ContextMenuPolicy.CustomContextMenu);
- toolbar.setMovable(false);
- toolbar.setFloatable(false);
- toolbar.resize(0, 0);
- // TODO if ( ( style & SWT.RIGHT ) != 0 ) {
- // TODO if ( ( style & SWT.SHADOW_OUT ) != 0 ) {
- // Visually, the tool bar is often separated from the menu bar by a separator.
- // SWT.SHADOW_OUT style was defined for ToolBar. This style causes tool bars to draw the appropriate separator.
- // On the Macintosh and platforms that do not support this look, the separator is not drawn.
-
- // if ( ( style & SWT.WRAP ) != 0 )
- // qt does not support wrapped mode! :(
-
- return toolbar;
- }
-
- private void initOrientation(QToolBar toolbar, int style) {
- if ((style & SWT.VERTICAL) != 0) {
- toolbar.setOrientation(Orientation.Vertical);
- this.style |= SWT.VERTICAL;
- } else {
- this.style |= SWT.HORIZONTAL;
- toolbar.setOrientation(Orientation.Horizontal);
- }
- }
-
- QToolBar getQToolBar() {
- return (QToolBar) getQWidget();
- }
-
- void addAction(QAction action, int index) {
- int itemCount = _getItemCount();
- if (index >= 0 && index < itemCount) {
- QAction before = getItems()[index].getQAction();
- getQToolBar().insertAction(before, action);
- } else {
- getQToolBar().addAction(action);
- }
- }
-
- QAction addWidget(QWidget widget, int index) {
- int itemCount = _getItemCount();
- QAction action;
- if (index >= 0 && index < itemCount) {
- QAction before = getItems()[index].getQAction();
- action = getQToolBar().insertWidget(before, widget);
- } else {
- action = getQToolBar().addWidget(widget);
- }
- return action;
- }
-
- QWidget removeAction(QAction action) {
- QWidget widget = null;
- if (getQToolBar() != null) {
- widget = getQToolBar().widgetForAction(action);
- getQToolBar().removeAction(action);
- }
- return widget;
- }
-
- static int checkStyle(int style) {
- /*
- * On Windows, only flat tool bars can be traversed.
- */
- if ((style & SWT.FLAT) == 0) {
- style |= SWT.NO_FOCUS;
- }
-
- /*
- * A vertical tool bar cannot wrap because TB_SETROWS fails when the
- * toolbar has TBSTYLE_WRAPABLE.
- */
- if ((style & SWT.VERTICAL) != 0) {
- style &= ~SWT.WRAP;
- }
-
- return style;
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- @Override
- public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
- Point size = super.computeSize(wHint, hHint, changed);
- int width = size.x;
- int height = size.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;
- }
- Rectangle trim = computeTrim(0, 0, width, height);
- width = trim.width;
- height = trim.height;
- return new Point(width, height);
- }
-
- /**
- * Returns the item at the given, zero-relative index in the receiver.
- * 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 ToolItem getItem(int index) {
- checkWidget();
- List list = getQWidget().actions();
- int count = list.size();
- if (!(0 <= index && index < count)) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- Widget widget = display.findControl(list.get(index));
- if (widget == null || !ToolItem.class.isInstance(widget)) {
- error(SWT.ERROR_CANNOT_GET_ITEM);
- }
- return (ToolItem) widget;
- }
-
- /**
- * Returns the item at the given point in the receiver or null if no such
- * item exists. The point is in the coordinate system of the receiver.
- *
- * @param point
- * the point used to locate the item
- * @return the item at the given point
- *
- * @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 ToolItem getItem(Point point) {
- checkWidget();
- if (point == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- ToolItem[] items = getItems();
- for (int i = 0; i < items.length; i++) {
- Rectangle rect = items[i].getBounds();
- if (rect.contains(point)) {
- return items[i];
- }
- }
- return null;
- }
-
- /**
- * Returns the number of items contained in the receiver.
- *
- * @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 _getItemCount();
- }
-
- int _getItemCount() {
- return getQWidget().actions().size();
- }
-
- /**
- * Returns an array of ToolItem
s which are the items in the
- * receiver.
- *
- * 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
- *
- * @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 ToolItem[] getItems() {
- checkWidget();
- List list = getQWidget().actions();
- int count = list.size();
- if (count == 0) {
- return new ToolItem[0];
- }
- ToolItem[] children = new ToolItem[count];
- int items = 0;
- for (QAction action : list) {
- if (action != null) {
- Widget widget = display.findControl(action);
- if (widget != null && widget != this) {
- if (widget instanceof ToolItem) {
- children[items++] = (ToolItem) widget;
- }
- }
- }
- }
- if (items == count) {
- return children;
- }
- ToolItem[] newChildren = new ToolItem[items];
- System.arraycopy(children, 0, newChildren, 0, items);
- return newChildren;
- }
-
- /**
- * Returns the number of rows in the receiver. When the receiver has the
- * WRAP
style, the number of rows can be greater than one.
- * Otherwise, the number of rows is always one.
- *
- * @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 getRowCount() {
- checkWidget();
- if ((style & SWT.VERTICAL) != 0) {
- return _getItemCount();
- }
- return 1;
- }
-
- /**
- * 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 item
- * the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the tool item is null
- * - ERROR_INVALID_ARGUMENT - if the tool item 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 int indexOf(ToolItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (item.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- return getQToolBar().actions().indexOf(item.getQAction());
- }
-
- @Override
- boolean mnemonicHit(char ch) {
- //TODO
- // int key = Display.wcsToMbcs(ch);
- // int[] id = new int[1];
- // if (OS.SendMessage(handle, OS.TB_MAPACCELERATOR, key, id) == 0) {
- // return false;
- // }
- // if ((style & SWT.FLAT) != 0 && !setTabGroupFocus())
- // return false;
- // int index = (int) /* 64 */OS.SendMessage(handle, OS.TB_COMMANDTOINDEX, id[0], 0);
- // if (index == -1)
- // return false;
- // OS.SendMessage(handle, OS.TB_SETHOTITEM, index, 0);
- // items[id[0]].click(false);
- return true;
- }
-
- @Override
- boolean mnemonicMatch(char ch) {
- //TODO
- // int key = Display.wcsToMbcs(ch);
- // int[] id = new int[1];
- // if (OS.SendMessage(handle, OS.TB_MAPACCELERATOR, key, id) == 0) {
- // return false;
- // }
- // /*
- // * Feature in Windows. TB_MAPACCELERATOR matches either the mnemonic
- // * character or the first character in a tool item. This behavior is
- // * undocumented and unwanted. The fix is to ensure that the tool item
- // * contains a mnemonic when TB_MAPACCELERATOR returns true.
- // */
- // int index = (int) /* 64 */OS.SendMessage(handle, OS.TB_COMMANDTOINDEX, id[0], 0);
- // if (index == -1)
- // return false;
- // return findMnemonic(items[id[0]].text) != '\0';
- return true;
- }
-
- @Override
- void releaseChildren(boolean destroy) {
- ToolItem[] items = getItems();
- for (int i = 0; i < items.length; i++) {
- ToolItem item = items[i];
- if (item != null && !item.isDisposed()) {
- item.release(false);
- }
- }
- super.releaseChildren(destroy);
- }
-
- @Override
- void removeControl(Control control) {
- super.removeControl(control);
- for (ToolItem item : getItems()) {
- if (item != null && item.hasControl(control)) {
- item.setControl(null);
- }
- }
- }
-
- @Override
- public boolean setParent(Composite parent) {
- checkWidget();
- if (!super.setParent(parent)) {
- return false;
- }
- getQToolBar().setParent(parent.getQWidget());
- return true;
- }
-
- @Override
- boolean setTabItemFocus() {
- int index = 0;
- ToolItem[] items = getItems();
- while (index < items.length) {
- ToolItem item = items[index];
- if (item != null && (item.style & SWT.SEPARATOR) == 0) {
- if (item.getEnabled()) {
- break;
- }
- }
- index++;
- }
- if (index == items.length) {
- return false;
- }
- return super.setTabItemFocus();
- }
-
- @Override
- public String toString() {
- String s = getName() + "{items: #" + getItemCount() + ":"; //$NON-NLS-1$ //$NON-NLS-2$
- for (ToolItem item : getItems()) {
- s += item + " " + getQToolBar().widgetForAction(item.getQAction()) + ", "; //$NON-NLS-1$ //$NON-NLS-2$
- }
- return s + "}"; //$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ToolItem.java
deleted file mode 100644
index 64f62f9676..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ToolItem.java
+++ /dev/null
@@ -1,981 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.core.QRect;
-import com.trolltech.qt.core.Qt.ContextMenuPolicy;
-import com.trolltech.qt.core.Qt.MouseButton;
-import com.trolltech.qt.gui.QAction;
-import com.trolltech.qt.gui.QIcon;
-import com.trolltech.qt.gui.QMouseEvent;
-import com.trolltech.qt.gui.QStyle;
-import com.trolltech.qt.gui.QStyleOptionToolButton;
-import com.trolltech.qt.gui.QToolBar;
-import com.trolltech.qt.gui.QToolButton;
-import com.trolltech.qt.gui.QWidget;
-import com.trolltech.qt.gui.QIcon.Mode;
-import com.trolltech.qt.gui.QStyle.ComplexControl;
-import com.trolltech.qt.gui.QToolButton.ToolButtonPopupMode;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.internal.qt.QtSWTConverter;
-
-/**
- * Instances of this class represent a selectable user interface object that
- * represents a button in a tool bar.
- *
- * - Styles:
- * - PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN
- * - Events:
- * - Selection
- *
- *
- * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN may
- * be specified.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see ToolBar, ToolItem
- * snippets
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolItem extends Item {
- private ToolBar parent;
- private Control control;
- private Image disabledImage, hotImage;
- private QAction action;
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * ToolBar
) and a style value describing its behavior and
- * appearance. The item is added to the end of the items maintained by its
- * parent.
- *
- * 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#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public ToolItem(ToolBar parent, int style) {
- this(parent, style, -1);
- }
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * ToolBar
), a style value describing its behavior and
- * appearance, and the index at which to place it in the items maintained by
- * its parent.
- *
- * 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
- * @param index
- * the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the parent is null
- * - ERROR_INVALID_RANGE - if the index is not between 0
- * and the number of elements in the parent (inclusive)
- *
- * @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#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public ToolItem(ToolBar parent, int style, int index) {
- super(parent, checkStyle(style));
- this.parent = parent;
- action = createAndAddAction(style, index);
- connectSignals(action);
- }
-
- protected QAction createAndAddAction(int style, int index) {
- QAction action;
- int bits = SWT.CHECK | SWT.RADIO | SWT.PUSH | SWT.SEPARATOR | SWT.DROP_DOWN;
- switch (style & bits) {
- case SWT.SEPARATOR:
- action = createAndAddSeparator(index);
- break;
- case SWT.DROP_DOWN:
- action = createAndAddDropdownButton(index);
- break;
- case SWT.RADIO:
- // if ( parent.actionGroup == null ) {
- // parent.actionGroup = new QActionGroup( parent.getQtControl()
- // );
- // if ( ( parent.style & SWT.NO_RADIO_GROUP ) != 0 ) {
- // parent.actionGroup.setExclusive( false );
- // }
- // }
- // parent.actionGroup.addAction( action );
- case SWT.CHECK:
- action = createAndAddCheckableAction(index);
- break;
- case SWT.PUSH:
- default:
- action = createAndAddAction(index);
- break;
- }
-
- display.addControl(action, this);
-
- QWidget toolWidget = getQToolBar().widgetForAction(action);
- toolWidget.setContextMenuPolicy(ContextMenuPolicy.NoContextMenu);
- display.addControl(toolWidget, this);
-
- return action;
- }
-
- private QAction createAndAddSeparator(int index) {
- QAction action = createAction();
- action.setSeparator(true);
- addToToolbar(action, index);
- return action;
- }
-
- private void addToToolbar(QAction action, int index) {
- parent.addAction(action, index);
- }
-
- private QAction createAction() {
- return new QAction(parent.getQWidget());
- }
-
- private QAction createAndAddAction(int index) {
- QAction action = createAction();
- addToToolbar(action, index);
- return action;
- }
-
- private QAction createAndAddCheckableAction(int index) {
- QAction action = createAction();
- action.setCheckable(true);
- addToToolbar(action, index);
- return action;
- }
-
- private QAction createAndAddDropdownButton(int index) {
- MyToolButton button = new MyToolButton(parent.getQWidget());
- button.setPopupMode(ToolButtonPopupMode.MenuButtonPopup);
- QAction action = parent.addWidget(button, index);
- button.setDefaultAction(action);
- return action;
- }
-
- QAction getQAction() {
- return action;
- }
-
- QWidget getToolbarWidget() {
- return getQToolBar().widgetForAction(action);
- }
-
- QToolBar getQToolBar() {
- return parent.getQToolBar();
- }
-
- protected void connectSignals(QAction action) {
- action.triggered.connect(this, "sendTriggeredEvent()"); //$NON-NLS-1$
- action.hovered.connect(this, "sendHoveredEvent()"); //$NON-NLS-1$
- }
-
- protected void sendTriggeredEvent() {
- Event event = new Event();
- sendEvent(SWT.Selection, event);
- }
-
- protected void sendHoveredEvent() {
- Event event = new Event();
- sendEvent(SWT.Arm, event);
- }
-
- protected void sendShowDropDownEvent() {
- Event event = new Event();
- event.detail = SWT.ARROW;
-
- Rectangle rect = getBounds();
- event.x = rect.x;
- event.y = rect.y + rect.height;
-
- sendEvent(SWT.Selection, event);
- }
-
- /**
- * 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.
- *
- * When widgetSelected
is called when the mouse is over the
- * arrow portion of a drop-down tool, the event object detail field contains
- * the value SWT.ARROW
. widgetDefaultSelected
is
- * not called.
- *
- *
- * @param listener
- * the listener which should be notified when the control is
- * selected by the user,
- *
- * @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);
- }
-
- static int checkStyle(int style) {
- return checkBits(style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- void click(boolean dropDown) {
- if (dropDown) {
- sendShowDropDownEvent();
- } else {
- getQAction().trigger();
- }
- }
-
- @Override
- void destroyWidget() {
- QWidget toolWidget = parent.removeAction(action);
- if (toolWidget != null) {
- toolWidget.disconnect();
- display.removeControl(toolWidget);
- }
- super.destroyWidget();
- }
-
- /**
- * Returns a rectangle describing the receiver's size and location relative
- * to its parent.
- *
- * @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();
- return QtSWTConverter.convert(getQToolBar().actionGeometry(getQAction()));
- }
-
- /**
- * Returns the control that is used to fill the bounds of the item when the
- * item is a SEPARATOR
.
- *
- * @return 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
- *
- */
- public Control getControl() {
- checkWidget();
- return control;
- }
-
- boolean hasControl(Control control) {
- return this.control == control;
- }
-
- /**
- * Returns the receiver's disabled image if it has one, or null if it does
- * not.
- *
- * The disabled image is displayed when the receiver is disabled.
- *
- *
- * @return the receiver's disabled 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 getDisabledImage() {
- checkWidget();
- return disabledImage;
- }
-
- /**
- * Returns the receiver's hot image if it has one, or null if it does not.
- *
- * The hot image is displayed when the mouse enters the receiver.
- *
- *
- * @return the receiver's hot 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 getHotImage() {
- checkWidget();
- return hotImage;
- }
-
- /**
- * Returns the receiver's parent, which must be a ToolBar
.
- *
- * @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 ToolBar getParent() {
- checkWidget();
- return parent;
- }
-
- /**
- * 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 (which some platforms draw as a pushed in
- * button). If the receiver is of any other type, this method returns false.
- *
- *
- * @return the selection 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 getSelection() {
- checkWidget();
- return getQAction().isChecked();
- }
-
- /**
- * 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 getQAction().toolTip();
- }
-
- /**
- * Gets the width of the receiver.
- *
- * @return the 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 getWidth() {
- checkWidget();
- return getQToolBar().actionGeometry(getQAction()).width();
- }
-
- /**
- * Returns true
if the receiver is enabled and all of the
- * receiver's ancestors are 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 #getEnabled
- */
- public boolean isEnabled() {
- checkWidget();
- return getEnabled() && parent.isEnabled();
- }
-
- @Override
- void releaseWidget() {
- super.releaseWidget();
- control = null;
- disabledImage = null;
- hotImage = null;
- }
-
- @Override
- void releaseQWidget() {
- super.releaseQWidget();
- parent.removeAction(action);
- action = null;
- parent = 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
- *
- * - 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 resizeControl() {
- if (control != null && !control.isDisposed()) {
- /*
- * Set the size and location of the control separately to minimize
- * flashing in the case where the control does not resize to the
- * size that was requested. This case can occur when the control is
- * a combo box.
- */
- Rectangle itemRect = getBounds();
- control.setSize(itemRect.width, itemRect.height);
- Rectangle rect = control.getBounds();
- rect.x = itemRect.x + (itemRect.width - rect.width) / 2;
- rect.y = itemRect.y + (itemRect.height - rect.height) / 2;
- control.setLocation(rect.x, rect.y);
- }
- }
-
- void selectRadio() {
- int index = 0;
- ToolItem[] items = parent.getItems();
- while (index < items.length && items[index] != this) {
- index++;
- }
- int i = index - 1;
- while (i >= 0 && items[i].setRadioSelection(false)) {
- --i;
- }
- int j = index + 1;
- while (j < items.length && items[j].setRadioSelection(false)) {
- j++;
- }
- setSelection(true);
- }
-
- /**
- * Sets the control that is used to fill the bounds of the item when the
- * item is a SEPARATOR
.
- *
- * @param control
- * the new control
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_INVALID_ARGUMENT - if the control 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 setControl(Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (control.parent != parent) {
- error(SWT.ERROR_INVALID_PARENT);
- }
- }
- if ((style & SWT.SEPARATOR) == 0) {
- return;
- }
- this.control = control;
- QAction newAction = getQToolBar().insertWidget(getQAction(), control.getQWidget());
- getQToolBar().removeAction(getQAction());
- newAction.setEnabled(action.isEnabled());
- newAction.setText(action.text());
- newAction.setToolTip(action.toolTip());
- newAction.setChecked(action.isChecked());
- updateImages();
- action = newAction;
- resizeControl();
- }
-
- /**
- * 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 getQAction().isEnabled();
- }
-
- /**
- * 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();
- getQAction().setEnabled(enabled);
- }
-
- /**
- * Sets the receiver's disabled image to the argument, which may be null
- * indicating that no disabled image should be displayed.
- *
- * The disabled image is displayed when the receiver is disabled.
- *
- *
- * @param image
- * the disabled image to display on the receiver (may be 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 setDisabledImage(Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) {
- return;
- }
- if (image != null && image.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- disabledImage = image;
- updateImages();
- }
-
- /**
- * Sets the receiver's hot image to the argument, which may be null
- * indicating that no hot image should be displayed.
- *
- * The hot image is displayed when the mouse enters the receiver.
- *
- *
- * @param image
- * the hot image to display on the receiver (may be 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 setHotImage(Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) {
- return;
- }
- if (image != null && image.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- hotImage = image;
- updateImages();
- }
-
- @Override
- public void setImage(Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) {
- return;
- }
- if (image != null && image.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- super.setImage(image);
- updateImages();
- }
-
- private void updateImages() {
- if ((style & SWT.SEPARATOR) != 0) {
- return;
- }
-
- if (image == null && disabledImage == null && hotImage == null) {
- getQAction().setIcon((QIcon) null);
- return;
- }
-
- QIcon icon = new QIcon();
- if (image != null) {
- icon.addPixmap(image.getQPixmap());
- }
-
- if (disabledImage != null) {
- icon.addPixmap(disabledImage.getQPixmap(), Mode.Disabled);
- }
-
- if (hotImage != null) {
- icon.addPixmap(hotImage.getQPixmap(), Mode.Selected);
- }
- getQAction().setIcon(icon);
- }
-
- boolean setRadioSelection(boolean value) {
- if ((style & SWT.RADIO) == 0) {
- return false;
- }
- if (getSelection() != value) {
- setSelection(value);
- postEvent(SWT.Selection);
- }
- return true;
- }
-
- /**
- * Sets the selection state of the receiver.
- *
- * When the receiver is of type CHECK
or RADIO
, it
- * is selected when it is checked (which some platforms draw as a pushed in
- * button).
- *
- *
- * @param selected
- * the new selection 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 setSelection(boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) {
- return;
- }
- getQAction().setChecked(selected);
- }
-
- /**
- * Sets the receiver's text. The string may include the mnemonic character.
- *
- *
- * 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 emphasised in a platform specific manner.
- * The mnemonic indicator character '&' can be escaped by doubling it in
- * the string, causing a single '&' to be displayed.
- *
- *
- * @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
- *
- */
- @Override
- public void setText(String string) {
- checkWidget();
- if (string == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if ((style & SWT.SEPARATOR) != 0) {
- return;
- }
- if (string.equals(text)) {
- return;
- }
- super.setText(string);
- getQAction().setText(string);
- }
-
- /**
- * 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();
- getQAction().setToolTip(string);
- }
-
- /**
- * Sets the width of the receiver, for SEPARATOR
ToolItems.
- *
- * @param width
- * the new 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 void setWidth(int width) {
- checkWidget();
- if ((style & SWT.SEPARATOR) == 0) {
- return;
- }
- if (width < 0) {
- return;
- }
- QWidget widget = getQToolBar().widgetForAction(getQAction());
- widget.resize(width, widget.height());
- }
-
- @Override
- public String toString() {
- return getName() + "{text: " + getQAction().text() + ", tooltip: " + getQAction().toolTip() + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- /**
- * Subclassed QToolButton, to override drop down handling. We check for
- * clicks on the arrow an the right side of the button and show our own
- * drop-down menu, ignoring the default menu.
- */
- private final class MyToolButton extends QToolButton {
- public MyToolButton(QWidget parent) {
- super(parent);
- }
-
- @Override
- protected void mousePressEvent(QMouseEvent e) {
- if (MouseButton.LeftButton.equals(e.button()) && ToolButtonPopupMode.MenuButtonPopup.equals(popupMode())) {
- QStyleOptionToolButton opt = new QStyleOptionToolButton();
- initStyleOption(opt);
- QRect popupr = style().subControlRect(ComplexControl.CC_ToolButton, opt,
- QStyle.SubControl.SC_ToolButtonMenu, this);
- if (popupr.isValid() && popupr.contains(e.pos())) {
- sendShowDropDownEvent();
- return;
- }
- }
- super.mousePressEvent(e);
- }
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ToolTip.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ToolTip.java
deleted file mode 100644
index f79ffbbad4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ToolTip.java
+++ /dev/null
@@ -1,512 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Point;
-
-/**
- * Instances of this class represent popup windows that are used to inform or
- * warn the user.
- *
- *
- * - Styles:
- * - BALLOON, ICON_ERROR, ICON_INFORMATION, ICON_WARNING
- * - Events:
- * - Selection
- *
- *
- *
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, and ICON_WARNING
- * may be specified.
- *
- *
- * IMPORTANT: This class is intended to be subclassed only within the
- * SWT implementation.
- *
- *
- * @see Tool Tips
- * snippets
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class ToolTip extends Widget {
- Shell parent;
- TrayItem item;
- String text = ""; //$NON-NLS-1$
- String message = ""; //$NON-NLS-1$
- int id, x, y;
- boolean autoHide = true, hasLocation, visible;
- static final int TIMER_ID = 100;
-
- /**
- * 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#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_WARNING
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public ToolTip(Shell parent, int style) {
- super(parent, checkStyle(style));
- this.parent = parent;
- checkAndUpdateOrientation(parent);
- // parent.createToolTip(this);
- }
-
- static int checkStyle(int style) {
- int mask = SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING;
- if ((style & mask) == 0) {
- return style;
- }
- return checkBits(style, SWT.ICON_INFORMATION, SWT.ICON_WARNING, SWT.ICON_ERROR, 0, 0, 0);
- }
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when the receiver is selected by the user, by sending it one of the
- * messages defined in the SelectionListener
interface.
- *
- * widgetSelected
is called when the receiver is selected.
- * widgetDefaultSelected
is not called.
- *
- *
- * @param listener
- * the listener which should be notified when the receiver is
- * selected by the user
- *
- * @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);
- }
-
- @Override
- void destroyWidget() {
- if (parent != null) {
- // parent.destroyToolTip( this );
- }
- releaseQWidget();
- }
-
- /**
- * Returns true
if the receiver is automatically hidden by the
- * platform, and false
otherwise.
- *
- * @return the receiver's auto hide 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 getAutoHide() {
- checkWidget();
- return autoHide;
- }
-
- /**
- * Returns the receiver's message, which will be an empty string if it has
- * never been set.
- *
- * @return the receiver's message
- *
- * @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 getMessage() {
- checkWidget();
- return message;
- }
-
- /**
- * Returns the receiver's parent, which must be a Shell
.
- *
- * @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 Shell getParent() {
- checkWidget();
- return parent;
- }
-
- /**
- * Returns the receiver's text, which will be an empty string if it has
- * never been set.
- *
- * @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();
- return text;
- }
-
- /**
- * 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();
- if (item != null) {
- return visible;
- }
- return false;
- }
-
- /**
- * 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();
- if (item != null) {
- return getVisible() && item.getVisible();
- }
- return getVisible();
- }
-
- @Override
- void releaseQWidget() {
- super.releaseQWidget();
- parent = null;
- item = null;
- id = -1;
- }
-
- @Override
- void releaseWidget() {
- super.releaseWidget();
- if (item == null) {
- if (autoHide) {
- // TODO
- }
- }
- if (item != null && item.toolTip == this) {
- item.toolTip = null;
- }
- item = null;
- text = message = null;
- }
-
- /**
- * Removes the listener from the collection of listeners who will be
- * notified when the receiver 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);
- }
-
- /**
- * Makes the receiver hide automatically when true
, and remain
- * visible when false
.
- *
- * @param autoHide
- * the auto hide 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
- * @see #setVisible
- */
- public void setAutoHide(boolean autoHide) {
- checkWidget();
- this.autoHide = autoHide;
- // TODO - update when visible
- }
-
- /**
- * Sets the location of the receiver, which must be a tooltip, to the point
- * specified by the arguments which are relative to the display.
- *
- * Note that this is different from most widgets where the location of the
- * widget is relative to the parent.
- *
- *
- * @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();
- this.x = x;
- this.y = y;
- hasLocation = true;
- // TODO - update when visible
- }
-
- /**
- * Sets the location of the receiver, which must be a tooltip, to the point
- * specified by the argument which is relative to the display.
- *
- * Note that this is different from most widgets where the location of the
- * widget is relative to the parent.
- *
- *
- * Note that the platform window manager ultimately has control over the
- * location of tooltips.
- *
- *
- * @param location
- * the new location 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 setLocation(Point location) {
- checkWidget();
- if (location == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- setLocation(location.x, location.y);
- }
-
- /**
- * Sets the receiver's message.
- *
- * @param string
- * the new message
- *
- * @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 setMessage(String string) {
- checkWidget();
- if (string == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- message = string;
- // TODO - update when visible
- }
-
- /**
- * Sets the receiver's text.
- *
- * @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;
- // TODO - update when visible
- }
-
- /**
- * 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 == getVisible()) {
- return;
- // TODO
- }
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Tracker.java
deleted file mode 100644
index a055510abe..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Tracker.java
+++ /dev/null
@@ -1,859 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-
-/**
- * Instances of this class implement rubber banding rectangles that are drawn
- * onto a parent Composite
or Display
. These
- * rectangles can be specified to respond to mouse and key events by either
- * moving or resizing themselves accordingly. Trackers are typically used to
- * represent window geometries in a lightweight manner.
- *
- *
- * - Styles:
- * - LEFT, RIGHT, UP, DOWN, RESIZE
- * - Events:
- * - Move, Resize
- *
- *
- * Note: Rectangle move behavior is assumed unless RESIZE is specified.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Tracker
- * snippets
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tracker extends Widget {
- Control parent;
- boolean tracking, cancelled, stippled;
- Rectangle[] rectangles = new Rectangle[0], proportions = rectangles;
- Rectangle bounds;
- int /* long */resizeCursor;
- Cursor clientCursor;
- int cursorOrientation = SWT.NONE;
- boolean inEvent = false;
- int /* long */hwndTransparent, hwndOpaque, oldTransparentProc, oldOpaqueProc;
- int oldX, oldY;
-
- /*
- * The following values mirror step sizes on Windows
- */
- final static int STEPSIZE_SMALL = 1;
- final static int STEPSIZE_LARGE = 9;
-
- /**
- * 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
- * - ERROR_INVALID_SUBCLASS - if this class is not an
- * allowed subclass
- *
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public Tracker(Composite parent, int style) {
- super(parent, checkStyle(style));
- this.parent = parent;
- }
-
- /**
- * Constructs a new instance of this class given the display to create it on
- * 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.
- *
- *
- * Note: Currently, null can be passed in for the display argument. This has
- * the effect of creating the tracker on the currently active display if
- * there is one. If there is no current display, the tracker is created on a
- * "default" display. Passing in null as the display argument is not
- * considered to be good coding style, and may not be supported in a future
- * release of SWT.
- *
- *
- * @param display
- * the display to create the tracker on
- * @param style
- * the style of control to construct
- *
- * @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#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- */
- public Tracker(Display display, int style) {
- if (display == null) {
- display = Display.getCurrent();
- }
- if (display == null) {
- display = Display.getDefault();
- }
- if (!display.isValidThread()) {
- error(SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- this.style = checkStyle(style);
- this.display = display;
- }
-
- /**
- * 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 keys are pressed and released on the system keyboard, by sending it
- * one of the messages defined in the KeyListener
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 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);
- }
-
- Point adjustMoveCursor() {
- if (bounds == null) {
- return null;
- }
- int newX = bounds.x + bounds.width / 2;
- int newY = bounds.y;
- // POINT pt = new POINT();
- // pt.x = newX;
- // pt.y = newY;
- // /*
- // * Convert to screen coordinates iff needed
- // */
- // if (parent != null) {
- // //OS.ClientToScreen(parent.handle, pt);
- // }
- // OS.SetCursorPos(pt.x, pt.y);
- //TODO
- return new Point(newX, newY);
- }
-
- Point adjustResizeCursor() {
- if (bounds == null) {
- return null;
- }
- int newX, newY;
-
- if ((cursorOrientation & SWT.LEFT) != 0) {
- newX = bounds.x;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- newX = bounds.x + bounds.width;
- } else {
- newX = bounds.x + bounds.width / 2;
- }
-
- if ((cursorOrientation & SWT.UP) != 0) {
- newY = bounds.y;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- newY = bounds.y + bounds.height;
- } else {
- newY = bounds.y + bounds.height / 2;
- }
-
- // POINT pt = new POINT();
- // pt.x = newX;
- // pt.y = newY;
- // /*
- // * Convert to screen coordinates iff needed
- // */
- // if (parent != null) {
- // //OS.ClientToScreen(parent.handle, pt);
- // }
- // OS.SetCursorPos(pt.x, pt.y);
- //
- // /*
- // * If the client has not provided a custom cursor then determine the
- // * appropriate resize cursor.
- // */
- // if (clientCursor == null) {
- // int /* long */newCursor = 0;
- // switch (cursorOrientation) {
- // case SWT.UP:
- // newCursor = OS.LoadCursor(0, OS.IDC_SIZENS);
- // break;
- // case SWT.DOWN:
- // newCursor = OS.LoadCursor(0, OS.IDC_SIZENS);
- // break;
- // case SWT.LEFT:
- // newCursor = OS.LoadCursor(0, OS.IDC_SIZEWE);
- // break;
- // case SWT.RIGHT:
- // newCursor = OS.LoadCursor(0, OS.IDC_SIZEWE);
- // break;
- // case SWT.LEFT | SWT.UP:
- // newCursor = OS.LoadCursor(0, OS.IDC_SIZENWSE);
- // break;
- // case SWT.RIGHT | SWT.DOWN:
- // newCursor = OS.LoadCursor(0, OS.IDC_SIZENWSE);
- // break;
- // case SWT.LEFT | SWT.DOWN:
- // newCursor = OS.LoadCursor(0, OS.IDC_SIZENESW);
- // break;
- // case SWT.RIGHT | SWT.UP:
- // newCursor = OS.LoadCursor(0, OS.IDC_SIZENESW);
- // break;
- // default:
- // newCursor = OS.LoadCursor(0, OS.IDC_SIZEALL);
- // break;
- // }
- // OS.SetCursor(newCursor);
- // if (resizeCursor != 0) {
- // OS.DestroyCursor(resizeCursor);
- // }
- // resizeCursor = newCursor;
- // }
- //TODO
- return new Point(newX, newY);
- }
-
- static int checkStyle(int style) {
- if ((style & (SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN)) == 0) {
- style |= SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN;
- }
- return style;
- }
-
- /**
- * Stops displaying the tracker rectangles. Note that this is not considered
- * to be a cancelation by the user.
- *
- * @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 close() {
- checkWidget();
- tracking = false;
- }
-
- Rectangle computeBounds() {
- if (rectangles.length == 0) {
- return null;
- }
- int xMin = rectangles[0].x;
- int yMin = rectangles[0].y;
- int xMax = rectangles[0].x + rectangles[0].width;
- int yMax = rectangles[0].y + rectangles[0].height;
-
- for (int i = 1; i < rectangles.length; i++) {
- if (rectangles[i].x < xMin) {
- xMin = rectangles[i].x;
- }
- if (rectangles[i].y < yMin) {
- yMin = rectangles[i].y;
- }
- int rectRight = rectangles[i].x + rectangles[i].width;
- if (rectRight > xMax) {
- xMax = rectRight;
- }
- int rectBottom = rectangles[i].y + rectangles[i].height;
- if (rectBottom > yMax) {
- yMax = rectBottom;
- }
- }
-
- return new Rectangle(xMin, yMin, xMax - xMin, yMax - yMin);
- }
-
- Rectangle[] computeProportions(Rectangle[] rects) {
- Rectangle[] result = new Rectangle[rects.length];
- bounds = computeBounds();
- if (bounds != null) {
- for (int i = 0; i < rects.length; i++) {
- int x = 0, y = 0, width = 0, height = 0;
- if (bounds.width != 0) {
- x = (rects[i].x - bounds.x) * 100 / bounds.width;
- width = rects[i].width * 100 / bounds.width;
- } else {
- width = 100;
- }
- if (bounds.height != 0) {
- y = (rects[i].y - bounds.y) * 100 / bounds.height;
- height = rects[i].height * 100 / bounds.height;
- } else {
- height = 100;
- }
- result[i] = new Rectangle(x, y, width, height);
- }
- }
- return result;
- }
-
- /**
- * Draw the rectangles displayed by the tracker.
- */
- void drawRectangles(Rectangle[] rects, boolean stippled) {
- // if (parent == null && OS.WIN32_VERSION >= OS.VERSION(6, 0)) {
- // RECT rect1 = new RECT();
- // int bandWidth = stippled ? 3 : 1;
- // for (int i = 0; i < rects.length; i++) {
- // Rectangle rect = rects[i];
- // rect1.left = rect.x - bandWidth;
- // rect1.top = rect.y - bandWidth;
- // rect1.right = rect.x + rect.width + bandWidth * 2;
- // rect1.bottom = rect.y + rect.height + bandWidth * 2;
- // OS.RedrawWindow(hwndOpaque, rect1, 0, OS.RDW_INVALIDATE);
- // }
- // return;
- // }
- // int bandWidth = 1;
- // int /* long */hwndTrack = OS.GetDesktopWindow();
- // if (parent != null) {
- // //hwndTrack = parent.handle;
- // }
- // int /* long */hDC = OS.GetDCEx(hwndTrack, 0, OS.DCX_CACHE);
- // int /* long */hBitmap = 0, hBrush = 0, oldBrush = 0;
- // if (stippled) {
- // bandWidth = 3;
- // byte[] bits = { -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0 };
- // hBitmap = OS.CreateBitmap(8, 8, 1, 1, bits);
- // hBrush = OS.CreatePatternBrush(hBitmap);
- // oldBrush = OS.SelectObject(hDC, hBrush);
- // }
- // for (int i = 0; i < rects.length; i++) {
- // Rectangle rect = rects[i];
- // OS.PatBlt(hDC, rect.x, rect.y, rect.width, bandWidth, OS.PATINVERT);
- // OS.PatBlt(hDC, rect.x, rect.y + bandWidth, bandWidth, rect.height - bandWidth * 2, OS.PATINVERT);
- // OS.PatBlt(hDC, rect.x + rect.width - bandWidth, rect.y + bandWidth, bandWidth, rect.height - bandWidth * 2,
- // OS.PATINVERT);
- // OS.PatBlt(hDC, rect.x, rect.y + rect.height - bandWidth, rect.width, bandWidth, OS.PATINVERT);
- // }
- // if (stippled) {
- // OS.SelectObject(hDC, oldBrush);
- // OS.DeleteObject(hBrush);
- // OS.DeleteObject(hBitmap);
- // }
- // OS.ReleaseDC(hwndTrack, hDC);
- }
-
- /**
- * Returns the bounds that are being drawn, expressed relative to the parent
- * widget. If the parent is a Display
then these are screen
- * coordinates.
- *
- * @return the bounds of the Rectangles being drawn
- *
- * @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[] getRectangles() {
- checkWidget();
- Rectangle[] result = new Rectangle[rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles[i];
- result[i] = new Rectangle(current.x, current.y, current.width, current.height);
- }
- return result;
- }
-
- /**
- * Returns true
if the rectangles are drawn with a stippled
- * line, false
otherwise.
- *
- * @return the stippled effect of the rectangles
- *
- * @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 getStippled() {
- checkWidget();
- return stippled;
- }
-
- void moveRectangles(int xChange, int yChange) {
- if (bounds == null) {
- return;
- }
- if (xChange < 0 && (style & SWT.LEFT) == 0) {
- xChange = 0;
- }
- if (xChange > 0 && (style & SWT.RIGHT) == 0) {
- xChange = 0;
- }
- if (yChange < 0 && (style & SWT.UP) == 0) {
- yChange = 0;
- }
- if (yChange > 0 && (style & SWT.DOWN) == 0) {
- yChange = 0;
- }
- if (xChange == 0 && yChange == 0) {
- return;
- }
- bounds.x += xChange;
- bounds.y += yChange;
- for (int i = 0; i < rectangles.length; i++) {
- rectangles[i].x += xChange;
- rectangles[i].y += yChange;
- }
- }
-
- /**
- * Displays the Tracker rectangles for manipulation by the user. Returns
- * when the user has either finished manipulating the rectangles or has
- * cancelled the Tracker.
- *
- * @return true
if the user did not cancel the Tracker,
- * 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 boolean open() {
- checkWidget();
- cancelled = false;
- tracking = true;
-
- /*
- * If exactly one of UP/DOWN is specified as a style then set the cursor
- * orientation accordingly (the same is done for LEFT/RIGHT styles
- * below).
- */
- int vStyle = style & (SWT.UP | SWT.DOWN);
- if (vStyle == SWT.UP || vStyle == SWT.DOWN) {
- cursorOrientation |= vStyle;
- }
- int hStyle = style & (SWT.LEFT | SWT.RIGHT);
- if (hStyle == SWT.LEFT || hStyle == SWT.RIGHT) {
- cursorOrientation |= hStyle;
- }
-
- /*
- * If this tracker is being created without a mouse drag then we need to
- * create a transparent window that fills the screen in order to get all
- * mouse/keyboard events that occur outside of our visible windows (ie.-
- * over the desktop).
- */
- // TODO
- tracking = false;
- return !cancelled;
- }
-
- @Override
- void releaseWidget() {
- super.releaseWidget();
- parent = null;
- rectangles = proportions = null;
- bounds = null;
- }
-
- /**
- * 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.Resize, listener);
- eventTable.unhook(SWT.Move, 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);
- }
-
- void resizeRectangles(int xChange, int yChange) {
- if (bounds == null) {
- return;
- }
- /*
- * If the cursor orientation has not been set in the orientation of this
- * change then try to set it here.
- */
- if (xChange < 0 && (style & SWT.LEFT) != 0 && (cursorOrientation & SWT.RIGHT) == 0) {
- cursorOrientation |= SWT.LEFT;
- }
- if (xChange > 0 && (style & SWT.RIGHT) != 0 && (cursorOrientation & SWT.LEFT) == 0) {
- cursorOrientation |= SWT.RIGHT;
- }
- if (yChange < 0 && (style & SWT.UP) != 0 && (cursorOrientation & SWT.DOWN) == 0) {
- cursorOrientation |= SWT.UP;
- }
- if (yChange > 0 && (style & SWT.DOWN) != 0 && (cursorOrientation & SWT.UP) == 0) {
- cursorOrientation |= SWT.DOWN;
- }
-
- /*
- * If the bounds will flip about the x or y axis then apply the
- * adjustment up to the axis (ie.- where bounds width/height becomes 0),
- * change the cursor's orientation accordingly, and flip each
- * Rectangle's origin (only necessary for > 1 Rectangles)
- */
- if ((cursorOrientation & SWT.LEFT) != 0) {
- if (xChange > bounds.width) {
- if ((style & SWT.RIGHT) == 0) {
- return;
- }
- cursorOrientation |= SWT.RIGHT;
- cursorOrientation &= ~SWT.LEFT;
- bounds.x += bounds.width;
- xChange -= bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions[i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- if (bounds.width < -xChange) {
- if ((style & SWT.LEFT) == 0) {
- return;
- }
- cursorOrientation |= SWT.LEFT;
- cursorOrientation &= ~SWT.RIGHT;
- xChange += bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions[i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- if (yChange > bounds.height) {
- if ((style & SWT.DOWN) == 0) {
- return;
- }
- cursorOrientation |= SWT.DOWN;
- cursorOrientation &= ~SWT.UP;
- bounds.y += bounds.height;
- yChange -= bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions[i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- if (bounds.height < -yChange) {
- if ((style & SWT.UP) == 0) {
- return;
- }
- cursorOrientation |= SWT.UP;
- cursorOrientation &= ~SWT.DOWN;
- yChange += bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions[i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- }
-
- // apply the bounds adjustment
- if ((cursorOrientation & SWT.LEFT) != 0) {
- bounds.x += xChange;
- bounds.width -= xChange;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- bounds.width += xChange;
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- bounds.y += yChange;
- bounds.height -= yChange;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- bounds.height += yChange;
- }
-
- Rectangle[] newRects = new Rectangle[rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle proportion = proportions[i];
- newRects[i] = new Rectangle(proportion.x * bounds.width / 100 + bounds.x, proportion.y * bounds.height
- / 100 + bounds.y, proportion.width * bounds.width / 100, proportion.height * bounds.height / 100);
- }
- rectangles = newRects;
- }
-
- /**
- * Sets the Cursor
of the Tracker. If this cursor is
- * null
then the cursor reverts to the default.
- *
- * @param newCursor
- * the new Cursor
to display
- *
- * @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 newCursor) {
- checkWidget();
- clientCursor = newCursor;
- // TODO
- // if (newCursor != null) {
- // if (inEvent) {
- // OS.SetCursor(clientCursor.handle);
- // }
- // }
- }
-
- /**
- * Specifies the rectangles that should be drawn, expressed relative to the
- * parent widget. If the parent is a Display then these are screen
- * coordinates.
- *
- * @param rectangles
- * the bounds of the rectangles to be drawn
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the set of rectangles is null
- * or contains a null 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 void setRectangles(Rectangle[] rectangles) {
- checkWidget();
- if (rectangles == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- this.rectangles = new Rectangle[rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles[i];
- if (current == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- this.rectangles[i] = new Rectangle(current.x, current.y, current.width, current.height);
- }
- proportions = computeProportions(rectangles);
- }
-
- /**
- * Changes the appearance of the line used to draw the rectangles.
- *
- * @param stippled
- * true
if rectangle should appear stippled
- *
- * @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 setStippled(boolean stippled) {
- checkWidget();
- this.stippled = stippled;
- }
-
- void update() {
- if (parent == null) {
- return;
- }
- if (parent != null) {
- if (parent.isDisposed()) {
- return;
- }
- Shell shell = parent.getShell();
- shell._update();
- } else {
- display.update();
- }
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TrayItem.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TrayItem.java
deleted file mode 100644
index cdee0a48fe..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TrayItem.java
+++ /dev/null
@@ -1,536 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.MenuDetectListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Instances of this class represent icons that can be placed on the system tray
- * or task bar status area.
- *
- *
- * - Styles:
- * - (none)
- * - Events:
- * - DefaultSelection, MenuDetect, Selection
- *
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Tray, TrayItem
- * snippets
- * @see Sample code and further
- * information
- *
- * @since 3.0
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TrayItem extends Item {
- Tray parent;
- int id;
- Image image2;
- ToolTip toolTip;
- String toolTipText;
- boolean visible = true;
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Tray
) and a style value describing its behavior and
- * appearance. The item is added to the end of the items maintained by its
- * parent.
- *
- * 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 TrayItem(Tray parent, int style) {
- super(parent, style);
- this.parent = parent;
- parent.createItem(this, parent.getItemCount());
- createWidget();
- }
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when the receiver is selected by the user, by sending it one of the
- * messages defined in the SelectionListener
interface.
- *
- * widgetSelected
is called when the receiver is selected
- * widgetDefaultSelected
is called when the receiver is
- * double-clicked
- *
- *
- * @param listener
- * the listener which should be notified when the receiver is
- * selected by the user
- *
- * @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 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);
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- void createWidget() {
- // TODO
- }
-
- @Override
- void destroyWidget() {
- parent.destroyItem(this);
- releaseQWidget();
- }
-
- /**
- * Returns the receiver's parent, which must be a Tray
.
- *
- * @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
- *
- *
- * @since 3.2
- */
- public Tray getParent() {
- checkWidget();
- return parent;
- }
-
- /**
- * Returns the receiver's tool tip, 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
- *
- *
- * @since 3.2
- */
- public ToolTip getToolTip() {
- checkWidget();
- return toolTip;
- }
-
- /**
- * 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.
- *
- * @return the receiver's visibility
- *
- * @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 visible;
- }
-
- void recreate() {
- createWidget();
- if (!visible) {
- setVisible(false);
- }
- if (text.length() != 0) {
- setText(text);
- }
- if (image != null) {
- setImage(image);
- }
- if (toolTipText != null) {
- setToolTipText(toolTipText);
- }
- }
-
- @Override
- void releaseQWidget() {
- super.releaseQWidget();
- parent = null;
- }
-
- @Override
- void releaseWidget() {
- super.releaseWidget();
- if (toolTip != null) {
- toolTip.item = null;
- }
- toolTip = null;
- if (image2 != null) {
- image2.dispose();
- }
- image2 = null;
- toolTipText = null;
- // NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new NOTIFYICONDATAW() : new NOTIFYICONDATAA();
- // iconData.cbSize = NOTIFYICONDATA.sizeof;
- // iconData.uID = id;
- // iconData.hWnd = display.hwndMessage;
- // OS.Shell_NotifyIcon(OS.NIM_DELETE, iconData);
- }
-
- /**
- * Removes the listener from the collection of listeners who will be
- * notified when the receiver 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);
- }
-
- /**
- * 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);
- }
-
- /**
- * Sets the receiver's image.
- *
- * @param image
- * the new image
- *
- * @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
- *
- */
- @Override
- public void setImage(Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- super.setImage(image);
- // if (image2 != null)
- // image2.dispose();
- // image2 = null;
- // QImage hIcon = null;
- // Image icon = image;
- // if (icon != null) {
- // switch (icon.type) {
- // case SWT.BITMAP:
- // image2 = Display.createIcon(image);
- // hIcon = image2.getQImage();
- // break;
- // case SWT.ICON:
- // hIcon = icon.getQImage();
- // break;
- // }
- // }
- //getQTray().setIcon( image.getQIcon() );
- }
-
- /**
- * Sets the receiver's tool tip to the argument, which may be null
- * indicating that no tool tip should be shown.
- *
- * @param toolTip
- * the new tool tip (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.2
- */
- public void setToolTip(ToolTip toolTip) {
- checkWidget();
- ToolTip oldTip = this.toolTip, newTip = toolTip;
- if (oldTip != null) {
- oldTip.item = null;
- }
- this.toolTip = newTip;
- if (newTip != null) {
- newTip.item = this;
- }
- }
-
- /**
- * 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();
- toolTipText = string;
- // NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new NOTIFYICONDATAW() : new NOTIFYICONDATAA();
- // TCHAR buffer = new TCHAR(0, toolTipText == null ? "" : toolTipText, true);
- // /*
- // * Note that the size of the szTip field is different in version 5.0 of
- // * shell32.dll.
- // */
- // int length = 64; //OS.SHELL32_MAJOR < 5 ? 64 : 128;
- // if (OS.IsUnicode) {
- // char[] szTip = ((NOTIFYICONDATAW) iconData).szTip;
- // length = Math.min(length - 1, buffer.length());
- // System.arraycopy(buffer.chars, 0, szTip, 0, length);
- // } else {
- // byte[] szTip = ((NOTIFYICONDATAA) iconData).szTip;
- // length = Math.min(length - 1, buffer.length());
- // System.arraycopy(buffer.bytes, 0, szTip, 0, length);
- // }
- // iconData.cbSize = NOTIFYICONDATA.sizeof;
- // iconData.uID = id;
- // // iconData.hWnd = display.hwndMessage;
- // // iconData.uFlags = OS.NIF_TIP;
- // // OS.Shell_NotifyIcon(OS.NIM_MODIFY, iconData);
- }
-
- /**
- * Makes the receiver visible if the argument is true
, and
- * makes it invisible otherwise.
- *
- * @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 (this.visible == visible) {
- return;
- }
- 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;
- }
- }
- this.visible = visible;
- // TODO
- if (!visible) {
- sendEvent(SWT.Hide);
- }
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Tree.java
deleted file mode 100644
index c9a145b5a6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Tree.java
+++ /dev/null
@@ -1,1913 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.trolltech.qt.core.QModelIndex;
-import com.trolltech.qt.core.QSize;
-import com.trolltech.qt.core.Qt.DropActions;
-import com.trolltech.qt.core.Qt.ScrollBarPolicy;
-import com.trolltech.qt.core.Qt.SortOrder;
-import com.trolltech.qt.gui.QAbstractItemDelegate;
-import com.trolltech.qt.gui.QDragEnterEvent;
-import com.trolltech.qt.gui.QDragLeaveEvent;
-import com.trolltech.qt.gui.QDragMoveEvent;
-import com.trolltech.qt.gui.QDropEvent;
-import com.trolltech.qt.gui.QHeaderView;
-import com.trolltech.qt.gui.QPainter;
-import com.trolltech.qt.gui.QStyleOptionViewItem;
-import com.trolltech.qt.gui.QTreeWidget;
-import com.trolltech.qt.gui.QTreeWidgetItem;
-import com.trolltech.qt.gui.QWidget;
-import com.trolltech.qt.gui.QAbstractItemView.DragDropMode;
-import com.trolltech.qt.gui.QAbstractItemView.ScrollHint;
-import com.trolltech.qt.gui.QAbstractItemView.SelectionBehavior;
-import com.trolltech.qt.gui.QAbstractItemView.SelectionMode;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.events.TreeListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-
-/**
- * Instances of this class provide a selectable user interface object that
- * displays a hierarchy of items and issues notification when an item in the
- * hierarchy is selected.
- *
- * The item children that may be added to instances of this class must be of
- * type TreeItem
.
- *
- *
- * Style VIRTUAL
is used to create a Tree
whose
- * TreeItem
s are to be populated by the client on an on-demand
- * basis instead of up-front. This can provide significant performance
- * improvements for trees that are very large or for which TreeItem
- * population is expensive (for example, retrieving values from an external
- * source).
- *
- *
- * Here is an example of using a Tree
with style
- * VIRTUAL
:
- * final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.BORDER);
- * tree.setItemCount(20);
- * tree.addListener(SWT.SetData, new Listener() {
- * public void handleEvent(Event event) {
- * TreeItem item = (TreeItem)event.item;
- * TreeItem parentItem = item.getParentItem();
- * String text = null;
- * if (parentItem == null) {
- * text = "node " + tree.indexOf(item);
- * } else {
- * text = parentItem.getText() + " - " + parentItem.indexOf(item);
- * }
- * item.setText(text);
- * System.out.println(text);
- * item.setItemCount(10);
- * }
- * });
- *
- *
- *
- * Note that although this class is a subclass of Composite
, it
- * does not normally make sense to add Control
children to it, or
- * set a layout on it, unless implementing something like a cell editor.
- *
- *
- *
- * - Styles:
- * - SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL
- * - Events:
- * - Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem,
- * EraseItem, PaintItem
- *
- *
- *
- * Note: Only one of the styles SINGLE and MULTI may be specified.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Tree, TreeItem,
- * TreeColumn snippets
- * @see SWT Example:
- * ControlExample
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tree extends Composite {
- private List items;
- private List columns;
- TreeColumn sortColumn;
- int sortDirection;
- boolean customDraw;
- private boolean linesVisible;
- private static final int GRID_WIDTH = 1;
- private TreeItemDelegate itemDelegate;
-
- /**
- * 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#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public Tree(Composite parent, int style) {
- super(parent, checkStyle(style));
- }
-
- @Override
- protected void connectSignals() {
- QTreeWidget tree = getQTreeWidget();
-
- tree.itemExpanded.connect(this, "qtTreeItemExpandedEvent(QTreeWidgetItem)"); //$NON-NLS-1$
- tree.itemCollapsed.connect(this, "qtTreeItemCollapsedEvent(QTreeWidgetItem)"); //$NON-NLS-1$
- tree.itemDoubleClicked.connect(this, "qtTreeItemDoubleClickedEvent(QTreeWidgetItem,Integer)"); //$NON-NLS-1$
- tree.itemSelectionChanged.connect(this, "qtTreeSelectionChanged()"); //$NON-NLS-1$
- }
-
- @Override
- QWidget createQWidget(int style) {
- state &= ~(CANVAS | THEME_BACKGROUND);
- items = new ArrayList(4);
- columns = new ArrayList(4);
-
- QTreeWidget tree = new MyQTreeWidget();
- tree.setHeaderHidden(true);
-
- if ((style & SWT.NO_SCROLL) != 0) {
- tree.setHorizontalScrollBarPolicy(ScrollBarPolicy.ScrollBarAlwaysOff);
- tree.setVerticalScrollBarPolicy(ScrollBarPolicy.ScrollBarAlwaysOff);
- }
-
- // default value is singleSelection
- if ((style & SWT.MULTI) != 0) {
- tree.setSelectionMode(SelectionMode.ExtendedSelection);
- } else {
- tree.setSelectionMode(SelectionMode.SingleSelection);
- }
-
- if ((style & SWT.FULL_SELECTION) != 0) {
- tree.setSelectionBehavior(SelectionBehavior.SelectRows);
- } else {
- tree.setSelectionBehavior(SelectionBehavior.SelectItems);
- }
-
- QAbstractItemDelegate originalItemDelegate = tree.itemDelegate();
- itemDelegate = new TreeItemDelegate(originalItemDelegate);
- tree.setItemDelegate(itemDelegate);
-
- setQMasterWidget(tree);
- return tree.viewport();
- }
-
- QTreeWidget getQTreeWidget() {
- return (QTreeWidget) getQMasterWidget();
- }
-
- @Override
- protected void checkAndUpdateBorder() {
- checkAndUpdateBorder(getQMasterWidget());
- super.checkAndUpdateBorder();
- }
-
- @Override
- protected Color getDefaultBackgroundColor() {
- return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
- }
-
- static int checkStyle(int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or WS_VSCROLL is not
- * specified, Windows creates trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that applications have
- * consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- /*
- * Note: Windows only supports TVS_NOSCROLL and TVS_NOHSCROLL.
- */
- if ((style & SWT.H_SCROLL) != 0 && (style & SWT.V_SCROLL) == 0) {
- style |= SWT.V_SCROLL;
- }
- return checkBits(style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
- }
-
- @Override
- public void setDragEnabled(boolean enabled) {
- getQTreeWidget().setDragEnabled(enabled);
- }
-
- @Override
- public void setAcceptDrops(boolean accept) {
- super.setAcceptDrops(accept);
- getQTreeWidget().setDragDropMode(DragDropMode.DragDrop);
- getQTreeWidget().setDropIndicatorShown(true);
- }
-
- public void highlightItem(TreeItem item) {
- System.out.println("highlightItem: " + item);
- if (item != null) {
- getQTreeWidget().setCurrentItem(item.getQItem());
- } else {
- getQTreeWidget().setCurrentItem(null);
- }
- }
-
- /**
- * 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.
- *
- * When widgetSelected
is called, the item field of the event
- * object is valid. If the receiver has the SWT.CHECK
style and
- * the check selection changes, the event object detail field contains the
- * value SWT.CHECK
. widgetDefaultSelected
is
- * typically called when an item is double-clicked. The item field of the
- * event object is valid for default selection, but the detail field is not
- * used.
- *
- *
- * @param listener
- * the listener which should be notified when the user changes
- * the receiver's selection
- *
- * @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 an item in the receiver is expanded or collapsed by sending it one
- * of the messages defined in the TreeListener
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 TreeListener
- * @see #removeTreeListener
- */
- public void addTreeListener(TreeListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Expand, typedListener);
- addListener(SWT.Collapse, typedListener);
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- /**
- * Clears the item at the given zero-relative index in the receiver. The
- * text, icon and other attributes of the item are set to the default value.
- * If the tree was created with the SWT.VIRTUAL
style, these
- * attributes are requested again as needed.
- *
- * @param index
- * the index of the item to clear
- * @param all
- * true
if all child items of the indexed item
- * should be cleared recursively, and false
- * otherwise
- *
- * @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
- *
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
- public void clear(int index, boolean all) {
- checkWidget();
- if (_getItemCount() == 0) {
- return;
- }
- validateItemIndex(index);
- items.get(index).clear(0, all);
- }
-
- private void validateItemIndex(int index) {
- if (index < 0 || index >= _getItemCount()) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- }
-
- /**
- * Clears all the items in the receiver. The text, icon and other attributes
- * of the items are set to their default values. If the tree was created
- * with the SWT.VIRTUAL
style, these attributes are requested
- * again as needed.
- *
- * @param all
- * true
if all child items should be cleared
- * recursively, 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 SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
- public void clearAll(boolean all) {
- checkWidget();
- for (TreeItem item : items) {
- item.clear(0, all);
- }
- }
-
- void addColumn(TreeColumn column, int index) {
- int columnCount = columns.size();
- if (!(0 <= index && index <= columnCount)) {
- error(SWT.ERROR_INVALID_RANGE);
- }
-
- if (index == columnCount) {
- columns.add(column);
- } else {
- columns.add(index, column);
- }
- // QHeaderView header = getQTreeWidget().header();
- // if (index >= columnCount) {
- // header.addAction(column.getQAction());
- // } else {
- // QAction before = header.actions().get(index);
- // header.insertAction(before, column.getQAction());
- // }
- }
-
- void removeColumn(TreeColumn treeColumn) {
- columns.remove(treeColumn);
- //getQTreeWidget().headerItem().removeAction(treeColumn.getQAction());
- }
-
- void addItem(TreeItem item, int index) {
- if (index >= 0 && index < _getItemCount()) {
- items.add(index, item);
- getQTreeWidget().insertTopLevelItem(index, item.getQItem());
- } else {
- items.add(item);
- getQTreeWidget().addTopLevelItem(item.getQItem());
- }
- }
-
- void removeItem(TreeItem item) {
- items.remove(item);
- getQTreeWidget().invisibleRootItem().removeChild(item.getQItem());
- }
-
- /**
- * Deselects an item in the receiver. If the item was already deselected, it
- * remains deselected.
- *
- * @param item
- * the item to be deselected
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item is null
- * - ERROR_INVALID_ARGUMENT - if the item 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 deselect(TreeItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (item.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- item.getQItem().setSelected(false);
- }
-
- /**
- * Deselects all selected items in 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 deselectAll() {
- checkWidget();
- getQTreeWidget().clearSelection();
- }
-
- /**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @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 int getGridLineWidth() {
- checkWidget();
- return GRID_WIDTH;
- }
-
- /**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not 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.1
- */
- public int getHeaderHeight() {
- checkWidget();
- return getQTreeWidget().header().height();
- }
-
- /**
- * Returns true
if the receiver's header 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 header'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.1
- */
- public boolean getHeaderVisible() {
- checkWidget();
- return !getQTreeWidget().isHeaderHidden();
- }
-
- /**
- * Returns the column at the given, zero-relative index in the receiver.
- * Throws an exception if the index is out of range. Columns are returned in
- * the order that they were created. If no TreeColumn
s were
- * created by the programmer, this method will throw
- * ERROR_INVALID_RANGE
despite the fact that a single column of
- * data may be visible in the tree. This occurs when the programmer uses the
- * tree like a list, adding items but never creating a column.
- *
- * @param index
- * the index of the column to return
- * @return the column 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
- *
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
- public TreeColumn getColumn(int index) {
- checkWidget();
- if (!(0 <= index && index < columns.size())) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- return columns.get(index);
- }
-
- /**
- * Returns the number of columns contained in the receiver. If no
- * TreeColumn
s were created by the programmer, this value is
- * zero, despite the fact that visually, one column of items may be visible.
- * This occurs when the programmer uses the tree like a list, adding items
- * but never creating a column.
- *
- * @return the number of columns
- *
- * @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 int getColumnCount() {
- checkWidget();
- return _getColumnCount();
- }
-
- int _getColumnCount() {
- return columns.size();
- }
-
- /**
- * Returns an array of zero-relative integers that map the creation order of
- * the receiver's items to the order in which they are currently being
- * displayed.
- *
- * Specifically, the indices of the returned array represent the current
- * visual order of the items, and the contents of the array represent the
- * creation order of the items.
- *
- *
- * 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 current visual order of the receiver's 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
- *
- *
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
- public int[] getColumnOrder() {
- checkWidget();
- if (_getColumnCount() == 0) {
- return new int[0];
- }
- int[] order = new int[_getColumnCount()];
- QHeaderView header = getQTreeWidget().header();
- for (int i = 0; i < order.length; i++) {
- order[i] = header.visualIndex(i);
- }
- return order;
- }
-
- /**
- * Returns an array of TreeColumn
s which are the columns in the
- * receiver. Columns are returned in the order that they were created. If no
- * TreeColumn
s were created by the programmer, the array is
- * empty, despite the fact that visually, one column of items may be
- * visible. This occurs when the programmer uses the tree like a list,
- * adding items but never creating a column.
- *
- * 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
- *
- * @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 Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
- public TreeColumn[] getColumns() {
- checkWidget();
- TreeColumn[] result = new TreeColumn[_getColumnCount()];
- int i = 0;
- for (TreeColumn col : columns) {
- result[i] = col;
- i++;
- }
- return result;
- }
-
- /**
- * Returns the item at the given, zero-relative index in the receiver.
- * 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
- *
- *
- * @since 3.1
- */
- public TreeItem getItem(int index) {
- checkWidget();
- if (index < 0 || index >= items.size()) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- return items.get(index);
- }
-
- /**
- * Returns the item at the given point in the receiver or null if no such
- * item exists. The point is in the coordinate system of the receiver.
- *
- * The item that is returned represents an item that could be selected by
- * the user. For example, if selection only occurs in items in the first
- * column, then null is returned if the point is outside of the item. Note
- * that the SWT.FULL_SELECTION style hint, which specifies the selection
- * policy, determines the extent of the selection.
- *
- *
- * @param point
- * the point used to locate the item
- * @return the item at the given point, or null if the point is not in a
- * selectable item
- *
- * @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 TreeItem getItem(Point point) {
- checkWidget();
- if (point == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- return _getItem(point);
- }
-
- private TreeItem _getItem(Point point) {
- QTreeWidgetItem qItem = getQTreeWidget().itemAt(point.x, point.y);
- for (TreeItem item : items) {
- if (item.getQItem() == qItem) {
- return item;
- }
- TreeItem ti = item.getItem(qItem);
- if (ti != null) {
- return ti;
- }
- }
- return null;
-
- }
-
- /**
- * Returns the number of items contained in the receiver that are direct
- * item children of the receiver. The number that is returned is the number
- * of roots in the tree.
- *
- * @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.size();
- }
-
- int _getItemCount() {
- return items.size();
- }
-
- /**
- * Returns the height of the area which would be used to display
- * one of the items in the tree.
- *
- * @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();
- int itemHeight = 0;
- if (items.size() > 0) {
- itemHeight = getQTreeWidget().sizeHintForRow(0);
- } else {
- // add dummy node and get the height
- getQTreeWidget().addTopLevelItem(new QTreeWidgetItem());
- itemHeight = getQTreeWidget().sizeHintForRow(0);
- getQTreeWidget().clear();
- }
- return itemHeight;
- }
-
- /**
- * Returns a (possibly empty) array of items contained in the receiver that
- * are direct item children of the receiver. These are the roots of the
- * tree.
- *
- * 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
- *
- * @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 TreeItem[] getItems() {
- checkWidget();
- TreeItem[] arr = new TreeItem[_getItemCount()];
- int i = 0;
- for (TreeItem item : items) {
- arr[i] = item;
- i++;
- }
- return arr;
- }
-
- /**
- * Returns true
if the receiver's lines are visible, and
- * false
otherwise. Note that some platforms draw grid lines
- * while others may draw alternating row colors.
- *
- * 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 visibility state of the lines
- *
- * @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 boolean getLinesVisible() {
- checkWidget();
- return linesVisible;
- }
-
- /**
- * Returns the receiver's parent item, which must be a TreeItem
- * or null when the receiver is a root.
- *
- * @return the receiver's parent 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 TreeItem getParentItem() {
- checkWidget();
- return null;
- }
-
- /**
- * Returns an array of TreeItem
s that are currently selected in
- * the receiver. The order of the items is unspecified. An empty array
- * indicates that no items are selected.
- *
- * Note: This is not the actual structure used by the receiver to maintain
- * its selection, so modifying the array will not affect the receiver.
- *
- *
- * @return an array representing the selection
- *
- * @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 TreeItem[] getSelection() {
- checkWidget();
- List selectedQItems = getQTreeWidget().selectedItems();
- if (selectedQItems.isEmpty()) {
- return new TreeItem[0];
- }
-
- TreeItem[] items = new TreeItem[selectedQItems.size()];
- int i = 0;
- for (QTreeWidgetItem item : selectedQItems) {
- Widget widget = display.findControl(item);
- if (widget instanceof TreeItem) {
- items[i] = (TreeItem) widget;
- }
- i++;
- }
- return items;
- }
-
- /**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected 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 getSelectionCount() {
- checkWidget();
- return getQTreeWidget().selectedItems().size();
- }
-
- /**
- * Returns the column which shows the sort indicator for the receiver. The
- * value may be null if no column shows the sort indicator.
- *
- * @return the sort indicator
- *
- * @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 #setSortColumn(TreeColumn)
- *
- * @since 3.2
- */
- public TreeColumn getSortColumn() {
- checkWidget();
- return sortColumn;
- }
-
- /**
- * Returns the direction of the sort indicator for the receiver. The value
- * will be one of UP
, DOWN
or NONE
.
- *
- * @return the sort direction
- *
- * @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 #setSortDirection(int)
- *
- * @since 3.2
- */
- public int getSortDirection() {
- checkWidget();
- return sortDirection;
- }
-
- /**
- * Returns the item which is currently at the top of the receiver. This item
- * can change when items are expanded, collapsed, scrolled or new items are
- * added or removed.
- *
- * @return the item at the top 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 2.1
- */
- public TreeItem getTopItem() {
- checkWidget();
- return _getItem(new Point(1, 1));
- }
-
- /**
- * Searches the receiver's list starting at the first column (index 0) until
- * a column is found that is equal to the argument, and returns the index of
- * that column. If no column is found, returns -1.
- *
- * @param column
- * the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the column 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
- *
- *
- * @since 3.1
- */
- public int indexOf(TreeColumn column) {
- checkWidget();
- if (column == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (column.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- return columns.indexOf(column);
- }
-
- /**
- * 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 item
- * the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item is null
- * - ERROR_INVALID_ARGUMENT - if the item 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.1
- */
- public int indexOf(TreeItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (item.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- return items.indexOf(item);
- }
-
- @Override
- void releaseChildren(boolean destroy) {
- if (items != null) {
- for (TreeItem item : items) {
- if (item != null && !item.isDisposed()) {
- item.release(false);
- }
- }
- items = null;
- }
- if (columns != null) {
- for (TreeColumn column : columns) {
- if (column != null && !column.isDisposed()) {
- column.release(false);
- }
- }
- columns = null;
- }
- super.releaseChildren(destroy);
- }
-
- @Override
- void releaseWidget() {
- super.releaseWidget();
- customDraw = false;
- }
-
- /**
- * Removes all of the items from 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 removeAll() {
- checkWidget();
- List copyOfItems = new ArrayList(items);
- for (TreeItem item : copyOfItems) {
- item.dispose();
- }
- items.clear();
- }
-
- /**
- * 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);
- }
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection, listener);
- }
-
- /**
- * Removes the listener from the collection of listeners who will be
- * notified when items in the receiver are expanded or collapsed.
- *
- * @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 TreeListener
- * @see #addTreeListener
- */
- public void removeTreeListener(TreeListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (eventTable == null) {
- return;
- }
- eventTable.unhook(SWT.Expand, listener);
- eventTable.unhook(SWT.Collapse, listener);
- }
-
- /**
- * Display a mark indicating the point at which an item will be inserted.
- * The drop insert item has a visual hint to show where a dragged item will
- * be inserted when dropped on the tree.
- *
- * @param item
- * the insert item. Null will clear the insertion mark.
- * @param before
- * true places the insert mark above 'item'. false places the
- * insert mark below 'item'.
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_INVALID_ARGUMENT - if the item 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 setInsertMark(TreeItem item, boolean before) {
- checkWidget();
- //TODO d'n'd
- }
-
- /**
- * Sets the number of root-level items contained in the receiver.
- *
- * @param count
- * 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
- *
- *
- * @since 3.2
- */
- public void setItemCount(int count) {
- checkWidget();
- count = Math.max(0, count);
- int itemCount = _getItemCount();
- if (count == itemCount) {
- return;
- }
- boolean isVirtual = (style & SWT.VIRTUAL) != 0;
- if (!isVirtual) {
- setRedraw(false);
- }
-
- if (count < itemCount) {
- for (int i = itemCount - 1; i >= count; i--) {
- removeItem(items.get(i));
- }
- return;
- }
- if (isVirtual) {
- //TODO
- } else {
- for (int i = itemCount; i < count; i++) {
- new TreeItem(this, SWT.NONE, i);
- }
- }
- if (!isVirtual) {
- setRedraw(true);
- }
- }
-
- /**
- * Sets the height of the area which would be used to display one
- * of the items in the tree.
- *
- * @param itemHeight
- * 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
- *
- *
- * @since 3.2
- */
- /* public */void setItemHeight(int itemHeight) {
- checkWidget();
- if (itemHeight < -1) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- itemDelegate.setHeight(itemHeight);
- update();
- }
-
- /**
- * Marks the receiver's lines as visible if the argument is
- * true
, and marks it invisible otherwise. Note that some
- * platforms draw grid lines while others may draw alternating row colors.
- *
- * 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 show
- * 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.1
- */
- public void setLinesVisible(boolean show) {
- checkWidget();
- if (linesVisible == show) {
- return;
- }
- linesVisible = show;
- getQTreeWidget().setAlternatingRowColors(show);
- }
-
- /**
- * Selects an item in the receiver. If the item was already selected, it
- * remains selected.
- *
- * @param item
- * the item to be selected
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item is null
- * - ERROR_INVALID_ARGUMENT - if the item 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 select(TreeItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (item.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- item.getQItem().setSelected(true);
- }
-
- /**
- * Selects all of the items in the receiver.
- *
- * If the receiver is single-select, do nothing.
- *
- *
- * @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 selectAll() {
- checkWidget();
- getQTreeWidget().selectAll();
- }
-
- /**
- * Sets the order that the items in the receiver should be displayed in to
- * the given argument which is described in terms of the zero-relative
- * ordering of when the items were added.
- *
- * @param order
- * the new order to display the 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
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item order is null
- * - ERROR_INVALID_ARGUMENT - if the item order is not the
- * same length as the number of items
- *
- *
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
- public void setColumnOrder(int[] order) {
- checkWidget();
- if (order == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- int columnCount = _getColumnCount();
- if (columnCount == 0) {
- if (order.length != 0) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- return;
- }
- if (order.length != columnCount) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- QHeaderView header = getQTreeWidget().header();
- for (int i = 0; i < columnCount; i++) {
- int visualIndex = header.visualIndex(i);
- header.moveSection(visualIndex, order[i]);
- }
- }
-
- /**
- * Marks the receiver's header 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 show
- * 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.1
- */
- public void setHeaderVisible(boolean show) {
- checkWidget();
- getQTreeWidget().setHeaderHidden(!show);
- }
-
- /**
- * Sets the receiver's selection to the given item. The current selection is
- * cleared before the new item is selected.
- *
- * If the item is not in the receiver, then it is ignored.
- *
- *
- * @param item
- * the item to select
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item is null
- * - ERROR_INVALID_ARGUMENT - if the item 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.2
- */
- public void setSelection(TreeItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- setSelection(new TreeItem[] { item });
- }
-
- /**
- * Sets the receiver's selection to be the given array of items. The current
- * selection is cleared before the new items are selected.
- *
- * Items that are not in the receiver are ignored. If the receiver is
- * single-select and multiple items are specified, then all items are
- * ignored.
- *
- *
- * @param items
- * the array of items
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the array of items is null
- * - ERROR_INVALID_ARGUMENT - if one of the items 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 Tree#deselectAll()
- */
- public void setSelection(TreeItem[] items) {
- checkWidget();
- if (items == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- int length = items.length;
- if (length == 0 || (style & SWT.SINGLE) != 0 && length > 1) {
- deselectAll();
- return;
- }
- getQTreeWidget().clearSelection();
- for (TreeItem item : items) {
- QTreeWidgetItem treeWidgetItem = item.getQItem();
- showItem(treeWidgetItem);
- treeWidgetItem.setSelected(true);
- }
- }
-
- private void showItem(QTreeWidgetItem item) {
- if (item.parent() != null) {
- if (!item.parent().isExpanded()) {
- item.parent().setExpanded(true);
- }
- showItem(item.parent());
- }
- }
-
- /**
- * Sets the column used by the sort indicator for the receiver. A null value
- * will clear the sort indicator. The current sort column is cleared before
- * the new column is set.
- *
- * @param column
- * the column used by the sort indicator or null
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_INVALID_ARGUMENT - if the column is 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.2
- */
- public void setSortColumn(TreeColumn column) {
- checkWidget();
- if (column != null && column.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- sortColumn = column;
- getQTreeWidget().sortByColumn(indexOf(column), getQSortOrder());
- }
-
- /**
- * Sets the direction of the sort indicator for the receiver. The value can
- * be one of UP
, DOWN
or NONE
.
- *
- * @param direction
- * the direction of the sort indicator
- *
- * @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 setSortDirection(int direction) {
- checkWidget();
- if ((direction & (SWT.UP | SWT.DOWN)) == 0 && direction != SWT.NONE) {
- return;
- }
- sortDirection = direction;
- if (sortColumn != null && !sortColumn.isDisposed()) {
- getQTreeWidget().sortByColumn(indexOf(sortColumn), getQSortOrder());
- }
- }
-
- /**
- * @return
- */
- private SortOrder getQSortOrder() {
- if ((sortDirection & SWT.UP) != 0) {
- return SortOrder.AscendingOrder;
- }
- return SortOrder.DescendingOrder;
- }
-
- /**
- * Sets the item which is currently at the top of the receiver. This item
- * can change when items are expanded, collapsed, scrolled or new items are
- * added or removed.
- *
- * @param item
- * the item to be shown
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item is null
- * - ERROR_INVALID_ARGUMENT - if the item 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 Tree#getTopItem()
- *
- * @since 2.1
- */
- public void setTopItem(TreeItem item) {
- checkWidget();
- if (item == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (item.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- _showItem(item, ScrollHint.PositionAtTop);
- }
-
- /**
- * Shows the column. If the column is already showing in the receiver, this
- * method simply returns. Otherwise, the columns are scrolled until the
- * column is visible.
- *
- * @param column
- * the column to be shown
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item is null
- * - ERROR_INVALID_ARGUMENT - if the item 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.1
- */
- public void showColumn(TreeColumn column) {
- checkWidget();
- if (column == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (column.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (column.parent != this) {
- return;
- }
- int index = indexOf(column);
- if (index == -1) {
- return;
- }
- getQTreeWidget().scrollToItem(getQTreeWidget().headerItem().child(index), ScrollHint.EnsureVisible);
- }
-
- /**
- * Shows the item. If the item is already showing in the receiver, this
- * method simply returns. Otherwise, the items are scrolled and expanded
- * until the item is visible.
- *
- * @param item
- * the item to be shown
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item is null
- * - ERROR_INVALID_ARGUMENT - if the item 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 Tree#showSelection()
- */
- public void showItem(TreeItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (item.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- _showItem(item, ScrollHint.EnsureVisible);
- }
-
- private void _showItem(TreeItem item, ScrollHint hint) {
- getQTreeWidget().scrollToItem(item.getQItem(), hint);
- }
-
- /**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until the
- * selection is 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
- *
- *
- * @see Tree#showItem(TreeItem)
- */
- public void showSelection() {
- checkWidget();
- List selection = getQTreeWidget().selectedItems();
- if (selection != null && selection.size() > 0) {
- getQTreeWidget().scrollToItem(selection.get(0), ScrollHint.EnsureVisible);
- }
- }
-
- boolean sendTreeEvent(int eventType, QTreeWidgetItem item) {
- Event event = new Event();
- event.item = display.findControl(item);
- sendEvent(eventType, event, true);
- return !event.doit;
- }
-
- public boolean qtTreeItemCollapsedEvent(QTreeWidgetItem item) {
- return sendTreeEvent(SWT.Collapse, item);
- }
-
- public boolean qtTreeItemExpandedEvent(QTreeWidgetItem item) {
- return sendTreeEvent(SWT.Expand, item);
- }
-
- public void qtTreeItemDoubleClickedEvent(QTreeWidgetItem item, Integer column) {
- sendEvent(SWT.DefaultSelection);
- }
-
- private final class TreeItemDelegate extends QAbstractItemDelegate {
- private final QAbstractItemDelegate wrappedDelegate;
- private int height = -1;
-
- TreeItemDelegate(QAbstractItemDelegate wrappedDelegate) {
- this.wrappedDelegate = wrappedDelegate;
-
- }
-
- public void setHeight(int height) {
- this.height = height;
- }
-
- @Override
- public void paint(QPainter painter, QStyleOptionViewItem item, QModelIndex index) {
- wrappedDelegate.paint(painter, item, index);
- }
-
- @Override
- public QSize sizeHint(QStyleOptionViewItem item, QModelIndex index) {
- QSize size = wrappedDelegate.sizeHint(item, index);
- if (height != -1) {
- size.setHeight(height);
- }
- return size;
- }
-
- }
-
- public boolean qtTreeSelectionChanged() {
- List selectedItems = getQTreeWidget().selectedItems();
- if (selectedItems.size() > 1) {
- System.out.println("more than one item selected in tree, selecting first"); //$NON-NLS-1$
- }
- if (selectedItems.size() == 0) {
- return sendTreeEvent(SWT.Selection, null);
- } else {
- // TODO what if more than one element is selected
- return sendTreeEvent(SWT.Selection, selectedItems.get(0));
- }
- }
-
- private final class MyQTreeWidget extends QTreeWidget {
-
- @Override
- protected void startDrag(DropActions supportedActions) {
- // System.out.println("MyQTreeWidget.startDrag: " + supportedActions);
- }
-
- @Override
- protected void dropEvent(QDropEvent event) {
- sendDropEvent(event);
- }
-
- @Override
- protected void dragMoveEvent(QDragMoveEvent event) {
- sendDragMoveEvent(event);
- }
-
- @Override
- protected void dragEnterEvent(QDragEnterEvent event) {
- sendDragEnterEvent(event);
- }
-
- @Override
- protected void dragLeaveEvent(QDragLeaveEvent event) {
- sendDragLeaveEvent(event);
- }
-
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TreeColumn.java
deleted file mode 100644
index 1693962077..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TreeColumn.java
+++ /dev/null
@@ -1,714 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import com.trolltech.qt.core.Qt.AlignmentFlag;
-import com.trolltech.qt.gui.QHeaderView;
-import com.trolltech.qt.gui.QIcon;
-import com.trolltech.qt.gui.QTreeWidget;
-import com.trolltech.qt.gui.QTreeWidgetItem;
-import com.trolltech.qt.gui.QHeaderView.ResizeMode;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Instances of this class represent a column in a tree widget.
- *
- *
- * - Styles:
- * - LEFT, RIGHT, CENTER
- * - Events:
- * - Move, Resize, Selection
- *
- *
- *
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Tree, TreeItem,
- * TreeColumn snippets
- * @see Sample code and further
- * information
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TreeColumn extends Item {
- Tree parent;
- private boolean resizable, moveable;
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Tree
) and a style value describing its behavior and
- * appearance. The item is added to the end of the items maintained by its
- * parent.
- *
- * 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#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public TreeColumn(Tree parent, int style) {
- super(parent, checkStyle(style));
- resizable = true;
- this.parent = parent;
- createQAction(parent, style, parent.getColumnCount());
- }
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Tree
), a style value describing its behavior and appearance,
- * and the index at which to place it in the items maintained by its parent.
- *
- * 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.
- *
- *
- * Note that due to a restriction on some platforms, the first column is
- * always left aligned.
- *
- *
- * @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
- * @param index
- * the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the parent is null
- * - ERROR_INVALID_RANGE - if the index is not between 0
- * and the number of elements in the parent (inclusive)
- *
- * @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#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
- public TreeColumn(Tree parent, int style, int index) {
- super(parent, checkStyle(style));
- resizable = true;
- this.parent = parent;
- createQAction(parent, style, index);
- }
-
- private void adjustColumnCount() {
- int columnCount = parent.getColumnCount();
- if (getQTreeWidget().columnCount() <= columnCount) {
- getQTreeWidget().setColumnCount(columnCount + 1);
- }
- }
-
- protected void createQAction(Tree parent, int style, int index) {
- adjustColumnCount();
- parent.addColumn(this, index);
- getQHeaderItem().setText(index, ""); //$NON-NLS-1$
- }
-
- @Override
- void releaseQWidget() {
- //display.removeControl(action);
- super.releaseQWidget();
- }
-
- QTreeWidget getQTreeWidget() {
- return parent.getQTreeWidget();
- }
-
- QTreeWidgetItem getQHeaderItem() {
- return getQTreeWidget().headerItem();
- }
-
- QHeaderView getQHeaderView() {
- return getQTreeWidget().header();
- }
-
- /**
- * 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 the control is selected by the user, by sending it one of the
- * messages defined in the SelectionListener
interface.
- *
- * widgetSelected
is called when the column header is selected.
- * widgetDefaultSelected
is not called.
- *
- *
- * @param listener
- * the listener which should be notified when the control is
- * selected by the user
- *
- * @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);
- }
-
- static int checkStyle(int style) {
- return checkBits(style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- @Override
- void destroyWidget() {
- parent.removeColumn(this);
- super.destroyWidget();
- }
-
- /**
- * 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
.
- *
- * @return the alignment
- *
- * @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 getAlignment() {
- checkWidget();
- 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;
- }
-
- /**
- * Gets the moveable attribute. A column that is not moveable cannot be
- * reordered by the user by dragging the header but may be reordered by the
- * programmer.
- *
- * @return the moveable attribute
- *
- * @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 Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
- public boolean getMoveable() {
- checkWidget();
- return moveable;
- }
-
- @Override
- String getNameText() {
- return getText();
- }
-
- /**
- * Returns the receiver's parent, which must be a Tree
.
- *
- * @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 Tree getParent() {
- checkWidget();
- return parent;
- }
-
- /**
- * Gets the resizable attribute. A column that is not resizable cannot be
- * dragged by the user but may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @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 getResizable() {
- checkWidget();
- return resizable;
- }
-
- /**
- * 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
- *
- *
- * @since 3.2
- */
- public String getToolTipText() {
- checkWidget();
- int index = parent.indexOf(this);
- if (index == -1) {
- return ""; //$NON-NLS-1$
- }
- return getQHeaderItem().toolTip(index);
- }
-
- /**
- * Gets the width of the receiver.
- *
- * @return the 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 getWidth() {
- checkWidget();
- int index = parent.indexOf(this);
- if (index == -1) {
- return 0;
- }
- return getQTreeWidget().header().sectionSize(index);
- }
-
- /**
- * 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
- *
- *
- */
- public void pack() {
- checkWidget();
- int index = parent.indexOf(this);
- if (index == -1) {
- return;
- }
- getQTreeWidget().resizeColumnToContents(index);
- }
-
- @Override
- void releaseParent() {
- super.releaseParent();
- if (parent.sortColumn == this) {
- parent.sortColumn = null;
- }
- }
-
- /**
- * 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 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);
- }
-
- /**
- * Controls how text and images will be displayed in the receiver. The
- * argument should be one of LEFT
, RIGHT
or
- * CENTER
.
- *
- * Note that due to a restriction on some platforms, the first column is
- * always left aligned.
- *
- *
- * @param alignment
- * the new alignment
- *
- * @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 setAlignment(int alignment) {
- checkWidget();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) {
- return;
- }
- int index = parent.indexOf(this);
- if (index == -1 || index == 0) {
- return;
- }
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
-
- getQTreeWidget().headerItem().setTextAlignment(index, convertAlignment(style));
- }
-
- private int convertAlignment(int style) {
- if ((style & SWT.CENTER) != 0) {
- return AlignmentFlag.AlignCenter.value();
- } else if ((style & SWT.RIGHT) != 0) {
- return AlignmentFlag.AlignRight.value();
- }
- return AlignmentFlag.AlignLeft.value();
- }
-
- @Override
- public void setImage(Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- super.setImage(image);
- if (parent.sortColumn != this || parent.sortDirection != SWT.NONE) {
- setImage(image, false, false);
- }
- }
-
- void setImage(Image image, boolean sort, boolean right) {
- int index = parent.indexOf(this);
- if (index == -1) {
- return;
- }
- if (image != null) {
- QIcon icon = new QIcon();
- icon.addPixmap(image.getQPixmap());
- getQHeaderItem().setIcon(index, icon);
- } else {
- getQHeaderItem().setIcon(index, (QIcon) null);
- }
- }
-
- /**
- * Sets the moveable attribute. A column that is moveable can be reordered
- * by the user by dragging the header. A column that is not moveable cannot
- * be dragged by the user but may be reordered by the programmer.
- *
- * @param moveable
- * the moveable attribute
- *
- * @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 Tree#setColumnOrder(int[])
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.2
- */
- public void setMoveable(boolean moveable) {
- checkWidget();
- this.moveable = moveable;
- }
-
- /**
- * Sets the resizable attribute. A column that is not resizable cannot be
- * dragged by the user but may be resized by the programmer.
- *
- * @param resizable
- * the resize attribute
- *
- * @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 setResizable(boolean resizable) {
- checkWidget();
- this.resizable = resizable;
- getQHeaderView().setResizeMode(parent.indexOf(this), resizable ? ResizeMode.Interactive : ResizeMode.Fixed);
- }
-
- @Override
- public void setText(String string) {
- checkWidget();
- if (string == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (string.equals(text)) {
- return;
- }
- int index = parent.indexOf(this);
- if (index == -1) {
- return;
- }
- super.setText(string);
- getQHeaderItem().setText(index, string);
- }
-
- /**
- * 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
- *
- *
- * @since 3.2
- */
- public void setToolTipText(String string) {
- checkWidget();
- int index = parent.indexOf(this);
- if (index == -1) {
- return;
- }
- getQHeaderItem().setToolTip(index, string);
- }
-
- /**
- * Sets the width of the receiver.
- *
- * @param width
- * the new 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 void setWidth(int width) {
- checkWidget();
- if (width < 0) {
- return;
- }
- int index = parent.indexOf(this);
- if (index == -1) {
- return;
- }
- getQTreeWidget().setColumnWidth(index, width);
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TreeItem.java
deleted file mode 100644
index 7ecd774bf9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/TreeItem.java
+++ /dev/null
@@ -1,1573 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.trolltech.qt.gui.QBrush;
-import com.trolltech.qt.gui.QIcon;
-import com.trolltech.qt.gui.QTreeWidget;
-import com.trolltech.qt.gui.QTreeWidgetItem;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.internal.qt.QtSWTConverter;
-
-/**
- * Instances of this class represent a selectable user interface object that
- * represents a hierarchy of tree items in a tree widget.
- *
- *
- * - Styles:
- * - (none)
- * - Events:
- * - (none)
- *
- *
- * IMPORTANT: This class is not intended to be subclassed.
- *
- *
- * @see Tree, TreeItem,
- * TreeColumn snippets
- * @see Sample code and further
- * information
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class TreeItem extends Item {
- private QTreeWidgetItem item;
- private List items;
- private Tree parent;
- private TreeItem parentItem;
- private String[] strings;
- private Image[] images;
- private Font font;
- private Font[] cellFont;
- boolean cached;
- private Color background;
- private Color foreground;
- private int[] cellBackground, cellForeground;
- private boolean grayed;
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Tree
or a TreeItem
) and a style value
- * describing its behavior and appearance. The item is added to the end of
- * the items maintained by its parent.
- *
- * 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 tree 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 TreeItem(Tree parent, int style) {
- this(parent, null, style, -1);
- }
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Tree
or a TreeItem
), a style value describing
- * its behavior and appearance, and the index at which to place it in the
- * items maintained by its parent.
- *
- * 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 tree control which will be the parent of the new instance
- * (cannot be null)
- * @param style
- * the style of control to construct
- * @param index
- * the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the parent is null
- * - ERROR_INVALID_RANGE - if the index is not between 0
- * and the number of elements in the parent (inclusive)
- *
- * @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 TreeItem(Tree parent, int style, int index) {
- this(parent, null, style, index);
- }
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Tree
or a TreeItem
) and a style value
- * describing its behavior and appearance. The item is added to the end of
- * the items maintained by its parent.
- *
- * 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 parentItem
- * a tree 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 TreeItem(TreeItem parentItem, int style) {
- this(checkNull(parentItem).parent, parentItem, style, -1);
- }
-
- /**
- * Constructs a new instance of this class given its parent (which must be a
- * Tree
or a TreeItem
), a style value describing
- * its behavior and appearance, and the index at which to place it in the
- * items maintained by its parent.
- *
- * 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 parentItem
- * a tree control which will be the parent of the new instance
- * (cannot be null)
- * @param style
- * the style of control to construct
- * @param index
- * the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the parent is null
- * - ERROR_INVALID_RANGE - if the index is not between 0
- * and the number of elements in the parent (inclusive)
- *
- * @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 TreeItem(TreeItem parentItem, int style, int index) {
- this(checkNull(parentItem).parent, parentItem, style, index);
- }
-
- TreeItem(Tree parent, TreeItem parentItem, int style, int index) {
- super(parent, style);
- this.parent = parent;
- item = new QTreeWidgetItem();
- items = new ArrayList(4);
- if (parentItem != null) {
- this.parentItem = parentItem;
- parentItem.addItem(this, index);
- } else {
- parent.addItem(this, index);
- }
- display.addControl(item, this);
- }
-
- void addItem(TreeItem item, int index) {
- if (index >= 0 && index < items.size()) {
- items.add(index, item);
- this.item.insertChild(index, item.getQItem());
- } else {
- items.add(item);
- this.item.addChild(item.getQItem());
- }
- }
-
- void removeItem(TreeItem item) {
- items.remove(item);
- getQItem().removeChild(item.getQItem());
- }
-
- TreeItem getItem(QTreeWidgetItem qItem) {
- for (TreeItem item : items) {
- if (item.item == qItem) {
- return item;
- }
- TreeItem ti = item.getItem(qItem);
- if (ti != null) {
- return ti;
- }
- }
- return null;
- }
-
- @Override
- void releaseQWidget() {
- super.releaseQWidget();
- item = null;
- }
-
- QTreeWidgetItem getQItem() {
- return item;
- }
-
- QTreeWidget getQTreeWidget() {
- return parent.getQTreeWidget();
- }
-
- static TreeItem checkNull(TreeItem item) {
- if (item == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- return item;
- }
-
- @Override
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- void clear() {
- for (int i = 0; i < parent.getColumnCount(); i++) {
- item.setText(i, null);
- item.setIcon(i, (QIcon) null);
- item.setWhatsThis(i, null);
- item.setFont(i, null);
- }
- text = ""; //$NON-NLS-1$
- image = null;
- strings = null;
- images = null;
- if ((parent.style & SWT.CHECK) != 0) {
- //
- }
- background = foreground = null;
- font = null;
- cellBackground = cellForeground = null;
- cellFont = null;
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = false;
- }
- }
-
- /**
- * Clears the item at the given zero-relative index in the receiver. The
- * text, icon and other attributes of the item are set to the default value.
- * If the tree was created with the SWT.VIRTUAL
style, these
- * attributes are requested again as needed.
- *
- * @param index
- * the index of the item to clear
- * @param all
- * true
if all child items of the indexed item
- * should be cleared recursively, and false
- * otherwise
- *
- * @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
- *
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
- public void clear(int index, boolean all) {
- checkWidget();
- validateItemIndex(index);
- if (index == 0) {
- clear();
- return;
- }
- TreeItem item = items.get(index);
- item.clear(0, all);
- }
-
- private void validateItemIndex(int index) {
- if (index < 0 || index >= items.size()) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- }
-
- /**
- * Clears all the items in the receiver. The text, icon and other attributes
- * of the items are set to their default values. If the tree was created
- * with the SWT.VIRTUAL
style, these attributes are requested
- * again as needed.
- *
- * @param all
- * true
if all child items should be cleared
- * recursively, 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 SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
- public void clearAll(boolean all) {
- checkWidget();
- clear();
- for (TreeItem item : items) {
- item.clearAll(all);
- }
- }
-
- @Override
- void destroyWidget() {
- if (parentItem != null) {
- parentItem.removeItem(this);
- } else {
- parent.removeItem(this);
- }
- super.destroyWidget();
- item = null;
- }
-
- /**
- * Returns the receiver's background 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
- *
- *
- * @since 2.0
- *
- */
- public Color getBackground() {
- checkWidget();
- if (background == null) {
- return parent.getBackground();
- }
- return background;
- }
-
- /**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index
- * the column index
- * @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
- *
- *
- * @since 3.1
- */
- public Color getBackground(int index) {
- checkWidget();
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return getBackground();
- }
- int pixel = cellBackground != null ? cellBackground[index] : -1;
- return pixel == -1 ? getBackground() : Color.qt_new(display, pixel);
- }
-
- /**
- * Returns a rectangle describing the receiver's size and location relative
- * to its parent.
- *
- * @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();
- return QtSWTConverter.convert(getQTreeWidget().visualItemRect(item));
- }
-
- /**
- * Returns a rectangle describing the receiver's size and location relative
- * to its parent at a column in the tree.
- *
- * @param index
- * the index that specifies the column
- * @return the receiver's bounding column 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
- *
- *
- * @since 3.1
- */
- public Rectangle getBounds(int index) {
- checkWidget();
- int count = Math.max(1, item.columnCount());
- if (0 > index || index > count - 1) {
- return new Rectangle(0, 0, 0, 0);
- }
-
- return QtSWTConverter.convert(getQTreeWidget().visualItemRect(item.child(index)));
- }
-
- /**
- * Returns true
if the receiver is checked, and false
- * otherwise. When the parent does not have the
- * CHECK style, return false.
- *
- *
- * @return the checked 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 getChecked() {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) {
- return false;
- }
- return item.isSelected();
- }
-
- /**
- * Returns true
if the receiver is expanded, and false
- * otherwise.
- *
- *
- * @return the expanded 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 getExpanded() {
- checkWidget();
- return item.isExpanded();
- }
-
- /**
- * Returns the font that the receiver will use to paint textual information
- * for this item.
- *
- * @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
- *
- *
- * @since 3.0
- */
- public Font getFont() {
- checkWidget();
- return font != null ? font : parent.getFont();
- }
-
- /**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index
- * the column index
- * @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
- *
- *
- * @since 3.1
- */
- public Font getFont(int index) {
- checkWidget();
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return getFont();
- }
- if (cellFont == null || cellFont[index] == null) {
- return getFont();
- }
- return cellFont[index];
- }
-
- /**
- * 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
- *
- *
- * @since 2.0
- *
- */
- public Color getForeground() {
- checkWidget();
- if (foreground == null) {
- return parent.getForeground();
- }
- return foreground;
- }
-
- /**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index
- * the column index
- * @return the 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
- *
- *
- * @since 3.1
- */
- public Color getForeground(int index) {
- checkWidget();
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return getForeground();
- }
- int pixel = cellForeground != null ? cellForeground[index] : -1;
- return pixel == -1 ? getForeground() : Color.qt_new(display, pixel);
- }
-
- /**
- * Returns true
if the receiver is grayed, and false otherwise.
- * When the parent does not have the CHECK style, return false.
- *
- *
- * @return the grayed state of the checkbox
- *
- * @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 getGrayed() {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) {
- return false;
- }
- return grayed;
- }
-
- /**
- * Returns the item at the given, zero-relative index in the receiver.
- * 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
- *
- *
- * @since 3.1
- */
- public TreeItem getItem(int index) {
- checkWidget();
- if (index < 0 || index >= items.size()) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- return items.get(index);
- }
-
- /**
- * Returns the number of items contained in the receiver that are direct
- * item children of the receiver.
- *
- * @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.size();
- }
-
- /**
- * Returns a (possibly empty) array of TreeItem
s which are the
- * direct item children of the receiver.
- *
- * 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 receiver's 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 TreeItem[] getItems() {
- checkWidget();
- return items.toArray(new TreeItem[items.size()]);
- }
-
- @Override
- public Image getImage() {
- checkWidget();
- return super.getImage();
- }
-
- /**
- * Returns the image stored at the given column index in the receiver, or
- * null if the image has not been set or if the column does not exist.
- *
- * @param index
- * the column index
- * @return the image stored at the given column index in 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 Image getImage(int index) {
- checkWidget();
- if (index == 0) {
- return getImage();
- }
- if (images != null) {
- if (0 <= index && index < images.length) {
- return images[index];
- }
- }
- return null;
- }
-
- /**
- * Returns a rectangle describing the size and location relative to its
- * parent of an image at a column in the tree.
- *
- * @param index
- * the index that specifies the column
- * @return the receiver's bounding image 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
- *
- *
- * @since 3.1
- */
- public Rectangle getImageBounds(int index) {
- checkWidget();
- //TODO image only ?
- return QtSWTConverter.convert(getQTreeWidget().visualItemRect(getQItem().child(index)));
- }
-
- /**
- * Returns the receiver's parent, which must be a Tree
.
- *
- * @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 Tree getParent() {
- checkWidget();
- return parent;
- }
-
- /**
- * Returns the receiver's parent item, which must be a TreeItem
- * or null when the receiver is a root.
- *
- * @return the receiver's parent 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 TreeItem getParentItem() {
- checkWidget();
- return parentItem;
- }
-
- /**
- * Returns the text stored at the given column index in the receiver, or
- * empty string if the text has not been set.
- *
- * @param index
- * the column index
- * @return the text stored at the given column index in 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 String getText(int index) {
- checkWidget();
- if (index == 0) {
- return getText();
- }
- if (strings != null) {
- if (0 <= index && index < strings.length) {
- String string = strings[index];
- return string != null ? string : ""; //$NON-NLS-1$
- }
- }
- return ""; //$NON-NLS-1$
- }
-
- /**
- * Returns a rectangle describing the size and location relative to its
- * parent of the text at a column in the tree.
- *
- * @param index
- * the index that specifies the column
- * @return the receiver's bounding text 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
- *
- *
- * @since 3.3
- */
- public Rectangle getTextBounds(int index) {
- checkWidget();
- //TODO text only ?
- return QtSWTConverter.convert(getQTreeWidget().visualItemRect(getQItem().child(index)));
- }
-
- /**
- * 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 item
- * the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the item is null
- * - ERROR_INVALID_ARGUMENT - if the item 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.1
- */
- public int indexOf(TreeItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (item.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- return items.indexOf(item);
- }
-
- @Override
- void releaseChildren(boolean destroy) {
- if (destroy) {
- for (int i = items.size() - 1; i > -1; i--) {
- items.get(i).dispose();
- }
- items.clear();
- }
- super.releaseChildren(destroy);
- }
-
- @Override
- void releaseWidget() {
- super.releaseWidget();
- strings = null;
- images = null;
- cellBackground = cellForeground = null;
- cellFont = null;
- display.removeControl(item);
- }
-
- /**
- * Removes all of the items from 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 removeAll() {
- checkWidget();
- QTreeWidgetItem qItem = getQItem();
- for (TreeItem item : items) {
- qItem.removeChild(item.getQItem());
- }
- items.clear();
- }
-
- /**
- * Sets the receiver's background color to the color specified by the
- * argument, or to the default system color for the item if the argument is
- * null.
- *
- * @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
- *
- *
- * @since 2.0
- *
- */
- public void setBackground(Color color) {
- checkWidget();
- if (color != null && color.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- Color pixel = null;
- if (color != null) {
- parent.customDraw = true;
- pixel = color;
- }
- if (background == pixel) {
- return;
- }
- background = pixel;
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- }
-
- /**
- * Sets the background color at the given column index in the receiver to
- * the color specified by the argument, or to the default system color for
- * the item if the argument is null.
- *
- * @param index
- * the column index
- * @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
- *
- *
- * @since 3.1
- *
- */
- public void setBackground(int index, Color color) {
- checkWidget();
- if (color != null && color.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return;
- }
- int pixel = -1;
- if (color != null) {
- parent.customDraw = true;
- pixel = color.getPixel();
- }
- if (cellBackground == null) {
- cellBackground = new int[count];
- for (int i = 0; i < count; i++) {
- cellBackground[i] = -1;
- }
- }
- if (cellBackground[index] == pixel) {
- return;
- }
- cellBackground[index] = pixel;
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- }
-
- /**
- * Sets the checked state of the receiver.
- *
- *
- * @param checked
- * the new checked 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 setChecked(boolean checked) {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) {
- return;
- }
- getQItem().setSelected(checked);
- }
-
- /**
- * Sets the expanded state of the receiver.
- *
- *
- * @param expanded
- * the new expanded 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 setExpanded(boolean expanded) {
- checkWidget();
- getQItem().setExpanded(expanded);
- }
-
- /**
- * Sets the font that the receiver will use to paint textual information for
- * this item 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
- *
- *
- * @since 3.0
- */
- public void setFont(Font font) {
- checkWidget();
- if (font != null && font.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- Font oldFont = this.font;
- if (oldFont == font) {
- return;
- }
- this.font = font;
- if (oldFont != null && oldFont.equals(font)) {
- return;
- }
- if (font != null) {
- parent.customDraw = true;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- item.setFont(0, font.getQFont());
- }
-
- /**
- * Sets the font that the receiver will use to paint textual information for
- * the specified cell in this item to the font specified by the argument, or
- * to the default font for that kind of control if the argument is null.
- *
- * @param index
- * the column index
- * @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
- *
- *
- * @since 3.1
- */
- public void setFont(int index, Font font) {
- checkWidget();
- if (font != null && font.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return;
- }
- if (cellFont == null) {
- if (font == null) {
- return;
- }
- cellFont = new Font[count];
- }
- Font oldFont = cellFont[index];
- if (oldFont == font) {
- return;
- }
- cellFont[index] = font;
- if (oldFont != null && oldFont.equals(font)) {
- return;
- }
- if (font != null) {
- parent.customDraw = true;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- if (font == null) {
- item.setFont(index, null);
- } else {
- item.setFont(index, font.getQFont());
- }
- }
-
- /**
- * Sets the receiver's foreground color to the color specified by the
- * argument, or to the default system color for the item if the argument is
- * null.
- *
- * @param color
- * the new color (or null)
- *
- * @since 2.0
- *
- * @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
- *
- *
- * @since 2.0
- *
- */
- public void setForeground(Color color) {
- checkWidget();
- if (color != null && color.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.foreground = color;
- item.setForeground(0, new QBrush(color.getColor()));
- }
-
- /**
- * Sets the foreground color at the given column index in the receiver to
- * the color specified by the argument, or to the default system color for
- * the item if the argument is null.
- *
- * @param index
- * the column index
- * @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
- *
- *
- * @since 3.1
- *
- */
- public void setForeground(int index, Color color) {
- checkWidget();
- if (color != null && color.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return;
- }
- int pixel = -1;
- if (color != null) {
- parent.customDraw = true;
- pixel = color.getPixel();
- }
- if (cellForeground == null) {
- cellForeground = new int[count];
- for (int i = 0; i < count; i++) {
- cellForeground[i] = -1;
- }
- }
- if (cellForeground[index] == pixel) {
- return;
- }
- cellForeground[index] = pixel;
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- }
-
- /**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Tree was created with the SWT.CHECK style.
- *
- * @param grayed
- * the new grayed state of the checkbox
- *
- * @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 setGrayed(boolean grayed) {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) {
- return;
- }
- this.grayed = grayed;
- }
-
- /**
- * Sets the image for multiple columns in the tree.
- *
- * @param images
- * the array of new images
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the array of images is null
- * - ERROR_INVALID_ARGUMENT - if one of the images 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.1
- */
- public void setImage(Image[] images) {
- checkWidget();
- if (images == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- for (int i = 0; i < images.length; i++) {
- setImage(i, images[i]);
- }
- }
-
- /**
- * Sets the receiver's image at a column.
- *
- * @param index
- * the column index
- * @param image
- * the new image
- *
- * @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
- *
- *
- * @since 3.1
- */
- public void setImage(int index, Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (index == 0) {
- if (image != null && image.isIcon()) {
- if (image.equals(this.image)) {
- return;
- }
- }
- super.setImage(image);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return;
- }
- if (images == null && index != 0) {
- images = new Image[count];
- images[0] = image;
- }
- if (images != null) {
- if (image != null && image.isIcon()) {
- if (image.equals(images[index])) {
- return;
- }
- }
- images[index] = image;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- item.setIcon(index, image != null ? image.getQIcon() : null);
- }
-
- @Override
- public void setImage(Image image) {
- checkWidget();
- setImage(0, image);
- }
-
- /**
- * Sets the number of child items contained in the receiver.
- *
- * @param count
- * 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
- *
- *
- * @since 3.2
- */
- public void setItemCount(int count) {
- checkWidget();
- count = Math.max(0, count);
- int itemCount = items.size();
- if (count == itemCount) {
- return;
- }
-
- if (count < itemCount) {
- for (int i = itemCount - 1; i >= count; i--) {
- removeItem(items.get(i));
- }
- return;
- }
- // if (isVirtual) {
- // //TODO
- // } else {
- for (int i = itemCount; i < count; i++) {
- new TreeItem(this, SWT.NONE, i);
- }
- }
-
- /**
- * Sets the text for multiple columns in the tree.
- *
- * @param strings
- * the array of new strings
- *
- * @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
- *
- *
- * @since 3.1
- */
- public void setText(String[] strings) {
- checkWidget();
- if (strings == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- for (int i = 0; i < strings.length; i++) {
- String string = strings[i];
- if (string != null) {
- setText(i, string);
- }
- }
- }
-
- /**
- * Sets the receiver's text at a column
- *
- * @param index
- * the column index
- * @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
- *
- *
- * @since 3.1
- */
- public void setText(int index, String string) {
- checkWidget();
- if (string == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (index == 0) {
- if (string.equals(text)) {
- return;
- }
- super.setText(string);
- }
- int count = Math.max(1, parent.getColumnCount());
- if (0 > index || index > count - 1) {
- return;
- }
- if (strings == null && index != 0) {
- strings = new String[count];
- strings[0] = text;
- }
- if (strings != null) {
- if (string.equals(strings[index])) {
- return;
- }
- strings[index] = string;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- }
- getQItem().setText(index, string);
- }
-
- @Override
- public void setText(String string) {
- checkWidget();
- setText(0, string);
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Widget.java
deleted file mode 100644
index cf693513e6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Widget.java
+++ /dev/null
@@ -1,1358 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import com.trolltech.qt.core.QObject;
-import com.trolltech.qt.gui.QContextMenuEvent;
-import com.trolltech.qt.gui.QKeyEvent;
-import com.trolltech.qt.gui.QMouseEvent;
-import com.trolltech.qt.gui.QMoveEvent;
-import com.trolltech.qt.gui.QPaintEvent;
-import com.trolltech.qt.gui.QResizeEvent;
-import com.trolltech.qt.gui.QWidget;
-import com.trolltech.qt.gui.QWindowStateChangeEvent;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.GCData;
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * This class is the abstract superclass of all user interface objects. Widgets
- * are created, disposed and issue notification to listeners when events occur
- * which affect them.
- *
- * - Styles:
- * - (none)
- * - Events:
- * - Dispose
- *
- *
- * IMPORTANT: This class is intended to be subclassed only within the
- * SWT implementation. However, it has not been marked final to allow those
- * outside of the SWT development team to implement patched versions of the
- * class in order to get around specific limitations in advance of when those
- * limitations can be addressed by the team. Any class built using subclassing
- * to access the internals of this class will likely fail to compile or run
- * between releases and may be strongly platform specific. Subclassing should
- * not be attempted without an intimate and detailed understanding of the
- * workings of the hierarchy. No support is provided for user-written classes
- * which are implemented as subclasses of this class.
- *
- *
- * @see #checkSubclass
- * @see Sample code and further
- * information
- */
-
-public abstract class Widget {
- public static final String QT_SWT_CONTROL_PROPERTY = "__SWT_CONTROL";//$NON-NLS-1$
- int style, state;
- Display display;
- EventTable eventTable;
- private Map data;
- private Object mainData;
-
- /* Global state flags */
- static final int DISPOSED = 1 << 0;
- static final int CANVAS = 1 << 1;
- static final int KEYED_DATA = 1 << 2;
- static final int HIDDEN = 1 << 4;
-
- /* A layout was requested on this widget */
- static final int LAYOUT_NEEDED = 1 << 5;
-
- /* The preferred size of a child has changed */
- static final int LAYOUT_CHANGED = 1 << 6;
-
- /* A layout was requested in this widget hierarchy */
- static final int LAYOUT_CHILD = 1 << 7;
-
- /* Background flags */
- static final int THEME_BACKGROUND = 1 << 8;
- static final int DRAW_BACKGROUND = 1 << 9;
- static final int PARENT_BACKGROUND = 1 << 10;
-
- /* Dispose and release flags */
- static final int RELEASED = 1 << 11;
- static final int DISPOSE_SENT = 1 << 12;
-
- /* More global widget state flags */
- static final int TRACK_MOUSE = 1 << 13;
- static final int FOREIGN_HANDLE = 1 << 14;
- static final int DRAG_DETECT = 1 << 15;
-
- /* Move and resize state flags */
- static final int MOVE_OCCURRED = 1 << 16;
- static final int MOVE_DEFERRED = 1 << 17;
- static final int RESIZE_OCCURRED = 1 << 18;
- static final int RESIZE_DEFERRED = 1 << 19;
-
- /* Ignore WM_CHANGEUISTATE */
- static final int IGNORE_WM_CHANGEUISTATE = 1 << 20;
-
- /* Default size for widgets */
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
-
- /* Check and initialize the Common Controls DLL */
- static final int MAJOR = 5, MINOR = 80;
- private QWidget qWidget;
-
- /**
- * Prevents uninitialized instances from being created outside the package.
- */
- Widget() {
- }
-
- /**
- * 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
- * - ERROR_INVALID_ARGUMENT - if the parent is disposed
- *
- * @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 #checkSubclass
- * @see #getStyle
- */
- public Widget(Widget parent, int style) {
- checkSubclass();
- checkParent(parent);
- this.style = style;
- display = parent.display;
- }
-
- void setQWidget(QWidget qWidget) {
- this.qWidget = qWidget;
- }
-
- public QWidget getQWidget() {
- return qWidget;
- }
-
- protected QWidget getQMasterWidget() {
- return getQWidget();
- }
-
- protected void setStyleSheet(String style) {
- getQMasterWidget().setStyleSheet(style);
- updateLayout();
- }
-
- protected void updateStyleSheet() {
- if (null != getQMasterWidget().style()) {
- getQMasterWidget().setStyle(getQMasterWidget().style());
- updateLayout();
- }
- }
-
- protected void updateLayout() {
- // nothing by default
- }
-
- void _addListener(int eventType, Listener listener) {
- if (eventTable == null) {
- eventTable = new EventTable();
- }
- if (eventType == SWT.DragDetect && this instanceof CTabFolder) {
- System.out.println("adding dnd drag listener");
- }
- eventTable.hook(eventType, listener);
- }
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when an event of the given type occurs. When the event does occur in the
- * widget, the listener is notified by sending it the
- * handleEvent()
message. The event type is one of the event
- * constants defined in class SWT
.
- *
- * @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_WIDGET_DISPOSED - if the receiver has been
- * disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver
- *
- *
- * @see Listener
- * @see SWT
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- */
- public void addListener(int eventType, Listener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- _addListener(eventType, listener);
- }
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when the widget is disposed. When the widget is disposed, the listener is
- * notified by sending it the widgetDisposed()
message.
- *
- * @param listener
- * the listener which should be notified when the receiver is
- * disposed
- *
- * @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 DisposeListener
- * @see #removeDisposeListener
- */
- public void addDisposeListener(DisposeListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Dispose, typedListener);
- }
-
- /**
- * Returns a style with exactly one style bit set out of the specified set
- * of exclusive style bits. All other possible bits are cleared when the
- * first matching bit is found. Bits that are not part of the possible set
- * are untouched.
- *
- * @param style
- * the original style bits
- * @param int0
- * the 0th possible style bit
- * @param int1
- * the 1st possible style bit
- * @param int2
- * the 2nd possible style bit
- * @param int3
- * the 3rd possible style bit
- * @param int4
- * the 4th possible style bit
- * @param int5
- * the 5th possible style bit
- *
- * @return the new style bits
- *
- * refactored: was checkBits
- */
- static int checkBits(int style, int int0, int int1, int int2, int int3, int int4, int int5) {
- int mask = int0 | int1 | int2 | int3 | int4 | int5;
- if ((style & mask) == 0) {
- style |= int0;
- }
- if ((style & int0) != 0) {
- style = style & ~mask | int0;
- }
- if ((style & int1) != 0) {
- style = style & ~mask | int1;
- }
- if ((style & int2) != 0) {
- style = style & ~mask | int2;
- }
- if ((style & int3) != 0) {
- style = style & ~mask | int3;
- }
- if ((style & int4) != 0) {
- style = style & ~mask | int4;
- }
- if ((style & int5) != 0) {
- style = style & ~mask | int5;
- }
- return style;
- }
-
- /* refactored: was checkOrientation */
- void checkAndUpdateOrientation(Widget parent) {
- style &= ~SWT.MIRRORED;
- if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- if (parent != null) {
- if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) {
- style |= SWT.LEFT_TO_RIGHT;
- }
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) {
- style |= SWT.RIGHT_TO_LEFT;
- }
- }
- }
- style = checkBits(style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0);
- }
-
- void checkOpened() {
- /* Do nothing */
- }
-
- /**
- * Throws an exception if the specified widget can not be used as a parent
- * for the receiver.
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the parent is null
- * - ERROR_INVALID_ARGUMENT - if the parent is disposed
- *
- * @exception SWTException
- *
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the parent
- *
- */
- void checkParent(Widget parent) {
- if (parent == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (parent.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- parent.checkWidget();
- parent.checkOpened();
- }
-
- /**
- * Checks that this class can be subclassed.
- *
- * The SWT class library is intended to be subclassed only at specific,
- * controlled points (most notably, Composite
and
- * Canvas
when implementing new widgets). This method enforces
- * this rule unless it is overridden.
- *
- *
- * IMPORTANT: By providing an implementation of this method that
- * allows a subclass of a class which does not normally allow subclassing to
- * be created, the implementer agrees to be fully responsible for the fact
- * that any such subclass will likely fail between SWT releases and will be
- * strongly platform specific. No support is provided for user-written
- * classes which are implemented in this fashion.
- *
- *
- * The ability to subclass outside of the allowed SWT classes is intended
- * purely to enable those not on the SWT development team to implement
- * patches in order to get around specific limitations in advance of when
- * those limitations can be addressed by the team. Subclassing should not be
- * attempted without an intimate and detailed understanding of the
- * hierarchy.
- *
- *
- * @exception SWTException
- *
- * - ERROR_INVALID_SUBCLASS - if this class is not an
- * allowed subclass
- *
- */
- protected void checkSubclass() {
- if (!isValidSubclass()) {
- error(SWT.ERROR_INVALID_SUBCLASS);
- }
- }
-
- /**
- * Throws an SWTException
if the receiver can not be accessed
- * by the caller. This may include both checks on the state of the receiver
- * and more generally on the entire execution context. This method
- * should be called by widget implementors to enforce the standard
- * SWT invariants.
- *
- * Currently, it is an error to invoke any method (other than
- * isDisposed()
) on a widget that has had its
- * dispose()
method called. It is also an error to call widget
- * methods from any thread that is different from the thread that created
- * the widget.
- *
- *
- * In future releases of SWT, there may be more or fewer error checks and
- * exceptions may be thrown for different reasons.
- *
- *
- * @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
- *
- */
- protected void checkWidget() {
- Display display = this.display;
- if (display == null) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- if (display.thread != Thread.currentThread()) {
- error(SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- if ((state & DISPOSED) != 0) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- }
-
- /**
- * Destroys the widget in the operating system and releases the widget's
- * handle. If the widget does not have a handle, this method may hide the
- * widget, mark the widget as destroyed or do nothing, depending on the
- * widget.
- *
- * When a widget is destroyed in the operating system, its descendants are
- * also destroyed by the operating system. This means that it is only
- * necessary to call destroyWidget
on the root of the widget
- * tree.
- *
- *
- * This method is called after releaseWidget()
.
- *
- *
- * See also releaseChild()
, releaseWidget()
and
- * releaseHandle()
.
- *
- *
- * @see #dispose
- */
- void destroyWidget() {
- releaseQWidget();
- }
-
- /**
- * Disposes of the operating system resources associated with the receiver
- * and all its descendants. After this method has been invoked, the receiver
- * and all descendants will answer true
when sent the message
- * isDisposed()
. Any internal connections between the widgets
- * in the tree will have been removed to facilitate garbage collection.
- *
- * NOTE: This method is not called recursively on the descendants of the
- * receiver. This means that, widget implementers can not detect when a
- * widget is being disposed of by re-implementing this method, but should
- * instead listen for the Dispose
event.
- *
- *
- * @exception SWTException
- *
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver
- *
- *
- * @see #addDisposeListener
- * @see #removeDisposeListener
- * @see #checkWidget
- */
- public void dispose() {
- /*
- * Note: It is valid to attempt to dispose a widget more than once. If
- * this happens, fail silently.
- */
- if (isDisposed()) {
- return;
- }
-
- if (!isValidThread()) {
- error(SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- release(true);
- }
-
- /**
- * Does whatever widget specific cleanup is required, and then uses the code
- * in SWTError.error
to handle the error.
- *
- * @param code
- * the descriptive error code
- *
- * @see SWT#error(int)
- */
- void error(int code) {
- SWT.error(code);
- }
-
- boolean filters(int eventType) {
- return display.filters(eventType);
- }
-
- char[] fixMnemonic(String string) {
- return fixMnemonic(string, false);
- }
-
- char[] fixMnemonic(String string, boolean spaces) {
- char[] buffer = new char[string.length() + 1];
- string.getChars(0, string.length(), buffer, 0);
- int i = 0, j = 0;
- while (i < buffer.length) {
- if (buffer[i] == '&') {
- if (i + 1 < buffer.length && buffer[i + 1] == '&') {
- if (spaces) {
- buffer[j] = ' ';
- }
- j++;
- i++;
- }
- i++;
- } else {
- buffer[j++] = buffer[i++];
- }
- }
- while (j < buffer.length) {
- buffer[j++] = 0;
- }
- return buffer;
- }
-
- /**
- * Returns the Display
that is associated with the receiver.
- *
- * A widget's display is either provided when it is created (for example,
- * top level Shell
s) or is the same as its parent's display.
- *
- *
- * @return the receiver's display
- *
- * @exception SWTException
- *
- * - ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed
- *
- */
- public Display getDisplay() {
- Display display = this.display;
- if (display == null) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- return display;
- }
-
- /**
- * Returns an array of listeners who will be notified when an event of the
- * given type occurs. The event type is one of the event constants defined
- * in class SWT
.
- *
- * @param eventType
- * the type of event to listen for
- * @return an array of listeners that will be notified when the event occurs
- *
- * @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 Listener
- * @see SWT
- * @see #addListener(int, Listener)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- *
- * @since 3.4
- */
- public Listener[] getListeners(int eventType) {
- checkWidget();
- if (eventTable == null) {
- return new Listener[0];
- }
- return eventTable.getListeners(eventType);
- }
-
- Menu getMenu() {
- return null;
- }
-
- /**
- * Returns the name of the widget. This is the name of the class without the
- * package name.
- *
- * @return the name of the widget
- */
- String getName() {
- String string = getClass().getName();
- int index = string.lastIndexOf('.');
- if (index == -1) {
- return string;
- }
- return string.substring(index + 1, string.length());
- }
-
- /*
- * Returns a short printable representation for the contents of a widget.
- * For example, a button may answer the label text. This is used by
- * toString
to provide a more meaningful description of the
- * widget.
- *
- * @return the contents string for the widget
- *
- * @see #toString
- */
- String getNameText() {
- return ""; //$NON-NLS-1$
- }
-
- /**
- * Returns the receiver's style information.
- *
- * Note that the value which is returned by this method may
- * not match the value which was provided to the constructor when the
- * receiver was created. This can occur when the underlying operating system
- * does not support a particular combination of requested styles. For
- * example, if the platform widget used to implement a particular SWT widget
- * always has scroll bars, the result of calling this method would always
- * have the SWT.H_SCROLL
and SWT.V_SCROLL
bits
- * set.
- *
- *
- * @return the style bits
- *
- * @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 getStyle() {
- checkWidget();
- return style;
- }
-
- /*
- * Returns true
if the specified eventType is hooked, and
- * false
otherwise. Implementations of SWT can avoid creating
- * objects and sending events when an event happens in the operating system
- * but there are no listeners hooked for the event.
- *
- * @param eventType the event to be checked
- *
- * @return true
when the eventType is hooked and
- * false
otherwise
- *
- * @see #isListening
- */
- boolean hooks(int eventType) {
- if (eventTable == null) {
- return false;
- }
- return eventTable.hooks(eventType);
- }
-
- /**
- * Returns true
if the widget has been disposed, and
- * false
otherwise.
- *
- * This method gets the dispose state for the widget. When a widget has been
- * disposed, it is an error to invoke any other method using the widget.
- *
- *
- * @return true
when the widget is disposed and
- * false
otherwise
- */
- public boolean isDisposed() {
- return (state & DISPOSED) != 0;
- }
-
- /**
- * Returns true
if there are any listeners for the specified
- * event type associated with the receiver, and false
- * otherwise. The event type is one of the event constants defined in class
- * SWT
.
- *
- * @param eventType
- * the type of event
- * @return true if the event is hooked
- *
- * @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
- */
- public boolean isListening(int eventType) {
- checkWidget();
- return hooks(eventType);
- }
-
- /*
- * Returns true
when subclassing is allowed and
- * false
otherwise
- *
- * @return true
when subclassing is allowed and
- * false
otherwise
- */
- boolean isValidSubclass() {
- return Display.isValidClass(getClass());
- }
-
- /*
- * Returns true
when the current thread is the thread that
- * created the widget and false
otherwise.
- *
- * @return true
when the current thread is the thread that
- * created the widget and false
otherwise
- */
- boolean isValidThread() {
- return getDisplay().isValidThread();
- }
-
- GC new_GC(GCData data) {
- return null;
- }
-
- /**
- * Notifies all of the receiver's listeners for events of the given type
- * that one such event has occurred by invoking their
- * handleEvent()
method. The event type is one of the event
- * constants defined in class SWT
.
- *
- * @param eventType
- * the type of event which has occurred
- * @param event
- * the event 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
- *
- *
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- */
- public void notifyListeners(int eventType, Event event) {
- checkWidget();
- if (event == null) {
- event = new Event();
- }
- sendEvent(eventType, event);
- }
-
- void postEvent(int eventType) {
- sendEvent(eventType, null, false);
- }
-
- void postEvent(int eventType, Event event) {
- sendEvent(eventType, event, false);
- }
-
- /*
- * Releases the widget hierarchy and optionally destroys the receiver.
- * Typically, a widget with children will broadcast this message to all
- * children so that they too can release their resources. The
- * releaseHandle
method is used as part of this broadcast to
- * zero the handle fields of the children without calling
- * destroyWidget
. In this scenario, the children are actually
- * destroyed later, when the operating system destroys the widget tree.
- *
- * @param destroy indicates that the receiver should be destroyed
- *
- * @see #dispose
- *
- * @see #releaseParent
- *
- * @see #releaseWidget
- */
- void release(boolean destroy) {
- if ((state & DISPOSE_SENT) == 0) {
- state |= DISPOSE_SENT;
- sendEvent(SWT.Dispose);
- }
- if ((state & DISPOSED) == 0) {
- releaseChildren(destroy);
- }
- if ((state & RELEASED) == 0) {
- state |= RELEASED;
- if (destroy) {
- releaseParent();
- releaseWidget();
- destroyWidget();
- } else {
- releaseWidget();
- releaseQWidget();
- }
- }
- }
-
- void releaseChildren(boolean destroy) {
- }
-
- /*
- * Releases the widget's handle by zero'ing it out. Does not destroy or
- * release any operating system resources. This method is called after
- * releaseWidget
or from destroyWidget
when a
- * widget is being destroyed to ensure that the widget is marked as
- * destroyed in case the act of destroying the widget in the operating
- * system causes application code to run in callback that could access the
- * widget.
- *
- * @see #dispose
- *
- * @see #releaseChildren
- *
- * @see #releaseParent
- *
- * @see #releaseWidget
- */
- void releaseQWidget() {
- state |= DISPOSED;
- display = null;
- qWidget = null;
- }
-
- /*
- * Releases the receiver, a child in a widget hierarchy, from its parent.
- * When a widget is destroyed, it may be necessary to remove it from an
- * internal data structure of the parent. When a widget has no handle, it
- * may also be necessary for the parent to hide the widget or otherwise
- * indicate that the widget has been disposed. For example, disposing a menu
- * bar requires that the menu bar first be released from the shell when the
- * menu bar is active.
- *
- * @see #dispose
- *
- * @see #releaseChildren
- *
- * @see #releaseWidget
- *
- * @see #releaseHandle
- */
- void releaseParent() {
- }
-
- /*
- * Releases any internal resources back to the operating system and clears
- * all fields except the widget handle. When a widget is destroyed,
- * resources that were acquired on behalf of the programmer need to be
- * returned to the operating system. For example, if the widget made a copy
- * of an icon, supplied by the programmer, this copy would be freed in
- * releaseWidget
. 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 widget, all fields except the handle are
- * zero'd. The handle is needed by destroyWidget
.
- *
- * @see #dispose
- *
- * @see #releaseChildren
- *
- * @see #releaseHandle
- *
- * @see #releaseParent
- */
- void releaseWidget() {
- eventTable = null;
- data = null;
- mainData = null;
- }
-
- /**
- * Removes the listener from the collection of listeners who will be
- * notified when an event of the given type occurs. The event type is one of
- * the event constants defined in class SWT
.
- *
- * @param eventType
- * the type of event to listen for
- * @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 Listener
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #notifyListeners
- */
- public void removeListener(int eventType, Listener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (eventTable == null) {
- return;
- }
- eventTable.unhook(eventType, listener);
- }
-
- /**
- * Removes the listener from the collection of listeners who will be
- * notified when an event of the given type occurs.
- *
- * IMPORTANT: This method is not part of the SWT public API.
- * It is marked public only so that it can be shared within the packages
- * provided by SWT. It should never be referenced from application code.
- *
- *
- * @param eventType
- * the type of event to listen for
- * @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 Listener
- * @see #addListener
- */
- protected void removeListener(int eventType, SWTEventListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (eventTable == null) {
- return;
- }
- eventTable.unhook(eventType, listener);
- }
-
- /**
- * Removes the listener from the collection of listeners who will be
- * notified when the widget is disposed.
- *
- * @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 DisposeListener
- * @see #addDisposeListener
- */
- public void removeDisposeListener(DisposeListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (eventTable == null) {
- return;
- }
- eventTable.unhook(SWT.Dispose, listener);
- }
-
- boolean sendDragEvent(int button, int x, int y) {
- Event event = new Event();
- event.button = button;
- event.x = x;
- event.y = y;
- //setInputState(event, SWT.DragDetect);
- sendEvent(SWT.DragDetect, event);
- if (isDisposed()) {
- return false;
- }
- return event.doit;
- }
-
- void sendEvent(Event event) {
- event.display = display;
- if (!display.filterEvent(event)) {
- if (eventTable != null) {
- eventTable.sendEvent(event);
- }
- }
- }
-
- void sendEvent(int eventType) {
- sendEvent(eventType, null, true);
- }
-
- void sendEvent(int eventType, Event event) {
- sendEvent(eventType, event, true);
- }
-
- void sendEvent(int eventType, Event event, boolean send) {
- if (eventTable == null && !display.filters(eventType)) {
- return;
- }
- if (event == null) {
- event = new Event();
- }
- event.type = eventType;
- event.display = display;
- event.widget = this;
- if (event.time == 0) {
- event.time = display.getLastEventTime();
- }
- if (send) {
- sendEvent(event);
- } else {
- display.postEvent(event);
- }
- }
-
- /**
- * Returns the application defined widget data associated with the receiver,
- * or null if it has not been set. The widget data is a single,
- * unnamed field that is stored with every widget.
- *
- * Applications may put arbitrary objects in this field. If the object
- * stored in the widget data needs to be notified when the widget is
- * disposed of, it is the application's responsibility to hook the Dispose
- * event on the widget and do so.
- *
- *
- * @return the widget data
- *
- * @exception SWTException
- *
- * - ERROR_WIDGET_DISPOSED - when the receiver has been
- * disposed
- * - ERROR_THREAD_INVALID_ACCESS - when called from the
- * wrong thread
- *
- *
- * @see #setData(Object)
- */
- public Object getData() {
- checkWidget();
- return mainData;
- }
-
- /**
- * Returns the application defined property of the receiver with the
- * specified name, or null if it has not been set.
- *
- * Applications may have associated arbitrary objects with the receiver in
- * this fashion. If the objects stored in the properties need to be notified
- * when the widget is disposed of, it is the application's responsibility to
- * hook the Dispose event on the widget and do so.
- *
- *
- * @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_WIDGET_DISPOSED - if the receiver has been
- * disposed
- * - ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver
- *
- *
- * @see #setData(String, Object)
- */
- public Object getData(String key) {
- checkWidget();
- if (key == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- Object value = getDataMap().get(key);
- if (value == null) {
- if (getQMasterWidget() != null) {
- value = getQMasterWidget().property(key);
- }
- }
- return value;
- }
-
- private Map getDataMap() {
- if (data == null) {
- data = new HashMap(4);
- }
- return data;
- }
-
- /**
- * Sets the application defined widget data associated with the receiver to
- * be the argument. The widget
- * data is a single, unnamed field that is stored with every widget.
- *
- * Applications may put arbitrary objects in this field. If the object
- * stored in the widget data needs to be notified when the widget is
- * disposed of, it is the application's responsibility to hook the Dispose
- * event on the widget and do so.
- *
- *
- * @param data
- * the widget data
- *
- * @exception SWTException
- *
- * - ERROR_WIDGET_DISPOSED - when the receiver has been
- * disposed
- * - ERROR_THREAD_INVALID_ACCESS - when called from the
- * wrong thread
- *
- *
- * @see #getData()
- */
- public void setData(Object data) {
- checkWidget();
- this.mainData = data;
- }
-
- /**
- * Sets the application defined property of the receiver with the specified
- * name to the given value.
- *
- * Applications may associate arbitrary objects with the receiver in this
- * fashion. If the objects stored in the properties need to be notified when
- * the widget is disposed of, it is the application's responsibility to hook
- * the Dispose event on the widget and do so.
- *
- *
- * @param key
- * the name of the property
- * @param value
- * the new value for the property
- *
- * @exception IllegalArgumentException
- *
- * - ERROR_NULL_ARGUMENT - if the key 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 #getData(String)
- */
- public void setData(String key, Object value) {
- checkWidget();
- if (key == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if ("stylesheet".equals(key)) { //$NON-NLS-1$
- setStyleSheet((String) value);
- return;
- }
-
- if (value == null) {
- if (getDataMap().containsKey(key)) {
- getDataMap().remove(key);
- } else {
- if (getQMasterWidget() != null) {
- getQMasterWidget().setProperty(key, null);
- updateStyleSheet(); // we have to update the style, cause the property can be referenced in the style
- }
- }
- } else {
- // we store Strings/Booleans adin the Qt Control, everything
- // else in the local map
- if (getQMasterWidget() != null && (value instanceof String || value instanceof Boolean)) {
- getQMasterWidget().setProperty(key, value);
- updateStyleSheet(); // we have to update the style, cause the property can be referenced in the style
- } else {
- getDataMap().put(key, value);
- }
- }
- }
-
- boolean showMenu(int x, int y) {
- Event event = new Event();
- event.x = x;
- event.y = y;
- sendEvent(SWT.MenuDetect, event);
- if (!event.doit) {
- return true;
- }
- Menu menu = getMenu();
- if (menu != null && !menu.isDisposed()) {
- if (x != event.x || y != event.y) {
- menu.setLocation(event.x, event.y);
- }
- menu.setVisible(true);
- return true;
- }
- return false;
- }
-
- /**
- * Returns a string containing a concise, human-readable description of the
- * receiver.
- *
- * @return a string representation of the receiver
- */
- @Override
- public String toString() {
- return getName() + " {" + getDescription() + "}"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- private String getDescription() {
- if (isDisposed()) {
- return "*Disposed*"; //$NON-NLS-1$
- }
- if (!isValidThread()) {
- return "*Wrong Thread*"; //$NON-NLS-1$
- }
- return getNameText();
- }
-
- /* Qt Events */
- public boolean qtCloseEvent() {
- return false;
- }
-
- public boolean qtResizeEvent(QObject source, QResizeEvent resizeEvent) {
- return false;
- }
-
- public boolean qtMoveEvent(QObject source, QMoveEvent moveEvent) {
- return false;
- }
-
- public boolean qtPaintEvent(QObject source, QPaintEvent paintEvent) {
- return false;
- }
-
- public boolean qtKeyPressEvent(QObject source, QKeyEvent qEvent) {
- return false;
- }
-
- public boolean qtKeyReleaseEvent(QObject source, QKeyEvent qEvent) {
- return false;
- }
-
- public boolean qtMouseMoveEvent(QObject source, QMouseEvent mouseEvent) {
- return false;
- }
-
- public boolean qtMouseButtonPressEvent(QObject source, QMouseEvent mouseEvent) {
- return false;
- }
-
- public boolean qtMouseButtonReleaseEvent(QObject source, QMouseEvent mouseEvent) {
- return false;
- }
-
- public boolean qtMouseButtonDblClickEvent(QObject source, QMouseEvent mouseEvent) {
- return false;
- }
-
- public boolean qtMouseEnterEvent(Object source) {
- return false;
- }
-
- public boolean qtMouseLeaveEvent(Object source) {
- return false;
- }
-
- public boolean qtContextMenuEvent(Object source, QContextMenuEvent event) {
- return false;
- }
-
- public boolean qtShowEvent(QObject source) {
- return false;
- }
-
- public boolean qtHideEvent(QObject source) {
- return false;
- }
-
- public void qtFocusInEvent(QObject source) {
- // nothing
- }
-
- public void qtFocusOutEvent(QObject source) {
- // nothing
- }
-
- public boolean qtWindowActivateEvent(QObject source) {
- return false;
- }
-
- public boolean qtWindowDeactivateEvent(QObject obj) {
- return false;
- }
-
- public boolean qtWindowStateChangeEvent(QObject obj, QWindowStateChangeEvent event) {
- return false;
- }
-
-}
--
cgit