org.eclipse.swt.widgets.Control Maven / Gradle / Ivy
Show all versions of org.eclipse.swt.macosx.x86_64 Show documentation
/******************************************************************************* * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation * Stefan Xenos (Google) - bug 468854 - Add a requestLayout method to Control *******************************************************************************/ package org.eclipse.swt.widgets; import org.eclipse.swt.*; import org.eclipse.swt.accessibility.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.cocoa.*; /** * Control is the abstract superclass of all windowed user interface classes. *
if the receiver is enabled and all * ancestors up to and including the receiver's nearest ancestor * shell are enabled. Otherwise,*
*
*- Styles: *
- BORDER
*- LEFT_TO_RIGHT, RIGHT_TO_LEFT, FLIP_TEXT_DIRECTION
*- Events: *
- DragDetect, FocusIn, FocusOut, Help, KeyDown, KeyUp, MenuDetect, MouseDoubleClick, MouseDown, MouseEnter, * MouseExit, MouseHover, MouseUp, MouseMove, MouseWheel, MouseHorizontalWheel, MouseVerticalWheel, Move, * Paint, Resize, Traverse
** Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified. *
* IMPORTANT: This class is intended to be subclassed only * within the SWT implementation. *
* * @see Control snippets * @see SWT Example: ControlExample * @see Sample code and further information * @noextend This class is not intended to be subclassed by clients. */ public abstract class Control extends Widget implements Drawable { /** * the handle to the OS resource * (Warning: This field is platform dependent) ** IMPORTANT: This field 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 is not available on all * platforms and should never be accessed from application code. *
* * @noreference This field is not intended to be referenced by clients. */ public NSView view; Composite parent; String toolTipText; Object layoutData; int drawCount, backgroundAlpha = 255; Menu menu; double /*float*/ [] foreground, background; Image backgroundImage; Font font; Cursor cursor; Region region; NSBezierPath regionPath; long /*int*/ visibleRgn; Accessible accessible; boolean touchEnabled; final static int CLIPPING = 1 << 10; final static int VISIBLE_REGION = 1 << 12; /** * Magic number comes from experience. There's no API for this value in Cocoa or Carbon. */ static final int DEFAULT_DRAG_HYSTERESIS = 5; Control () { /* Do nothing */ } /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. ** The style value is either one of the style constants defined in * class
* * @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 IllegalArgumentExceptionSWT
which is applicable to instances of this * class, or must be built by bitwise OR'ing together * (that is, using theint
"|" operator) two or more * of thoseSWT
style constants. The class description * lists the style constants that are applicable to the class. * Style bits are also inherited from superclasses. **
* @exception SWTException- ERROR_NULL_ARGUMENT - if the parent is null
**
* * @see SWT#BORDER * @see SWT#LEFT_TO_RIGHT * @see SWT#RIGHT_TO_LEFT * @see Widget#checkSubclass * @see Widget#getStyle */ public Control (Composite parent, int style) { super (parent, style); this.parent = parent; createWidget (); } @Override boolean acceptsFirstMouse (long /*int*/ id, long /*int*/ sel, long /*int*/ theEvent) { Shell shell = getShell (); if ((shell.style & SWT.ON_TOP) != 0) return true; return super.acceptsFirstMouse (id, sel, theEvent); } @Override long /*int*/ accessibleHandle() { long /*int*/ returnValue = view.id; if (view instanceof NSControl) { if (((NSControl) view).cell() != null) { returnValue = ((NSControl) view).cell().id; } } return returnValue; } @Override long /*int*/ accessibilityActionDescription(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0) { if (id == accessibleHandle() && accessible != null) { NSString actionName = new NSString(arg0); id returnValue = accessible.internal_accessibilityActionDescription(actionName, ACC.CHILDID_SELF); if (returnValue != null) return returnValue.id; } return super.accessibilityActionDescription(id, sel, arg0); } @Override long /*int*/ accessibilityActionNames(long /*int*/ id, long /*int*/ sel) { long /*int*/ returnValue = super.accessibilityActionNames(id, sel); if (handleIsAccessible(id)) { if (accessible != null) { NSArray baseArray = accessible.internal_accessibilityActionNames(ACC.CHILDID_SELF); if (baseArray != null) returnValue = baseArray.id; } if (hooks(SWT.MenuDetect) || (menu != null && !menu.isDisposed())) { NSArray baseArray = new NSArray(returnValue); NSMutableArray ourNames = NSMutableArray.arrayWithCapacity(baseArray.count() + 1); ourNames.addObjectsFromArray(baseArray); ourNames.addObject(OS.NSAccessibilityShowMenuAction); returnValue = ourNames.id; } } return returnValue; } @Override long /*int*/ accessibilityAttributeNames(long /*int*/ id, long /*int*/ sel) { long /*int*/ returnValue = 0; if (handleIsAccessible(id) && accessible != null) { // See if the accessible is defining the attribute set for the control. id value = accessible.internal_accessibilityAttributeNames(ACC.CHILDID_SELF); returnValue = (value != null ? value.id : 0); // If not, ask Cocoa for the set for this control. if (returnValue == 0) returnValue = super.accessibilityAttributeNames(id, sel); // Add relationship attributes. returnValue = accessible.internal_addRelationAttributes(returnValue); } // If the SWT accessibility didn't give us anything get the default for the view/cell. if (returnValue == 0) returnValue = super.accessibilityAttributeNames(id, sel); return returnValue; } /** * @param id NSView/NSCell that makes up this control. Could be the view itself. * @return true if id is something whose accessible properties can be augmented * or overridden by the SWT Accessible. false if the Cocoa defaults for the control should * be used. */ boolean handleIsAccessible(long /*int*/ id) { return id == accessibleHandle(); } @Override long /*int*/ accessibilityParameterizedAttributeNames(long /*int*/ id, long /*int*/ sel) { if (handleIsAccessible(id) && accessible != null) { NSArray returnValue = accessible.internal_accessibilityParameterizedAttributeNames(ACC.CHILDID_SELF); if (returnValue != null) return returnValue.id; } return super.accessibilityParameterizedAttributeNames(id, sel); } @Override void accessibilityPerformAction(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0) { if (handleIsAccessible(id) && accessible != null) { NSString action = new NSString(arg0); if (accessible.internal_accessibilityPerformAction(action, ACC.CHILDID_SELF)) return; } super.accessibilityPerformAction(id, sel, arg0); } @Override long /*int*/ accessibilityFocusedUIElement(long /*int*/ id, long /*int*/ sel) { id returnValue = null; if (handleIsAccessible(id) && accessible != null) { returnValue = accessible.internal_accessibilityFocusedUIElement(ACC.CHILDID_SELF); } // If we had an accessible and it didn't handle the attribute request, let the // superclass handle it. if (returnValue == null) return super.accessibilityFocusedUIElement(id, sel); else return returnValue.id; } @Override long /*int*/ accessibilityHitTest(long /*int*/ id, long /*int*/ sel, NSPoint point) { id returnValue = null; if (handleIsAccessible(id) && accessible != null) { returnValue = accessible.internal_accessibilityHitTest(point, ACC.CHILDID_SELF); } // If we had an accessible and it didn't handle the attribute request, let the // superclass handle it. if (returnValue == null) return super.accessibilityHitTest(id, sel, point); else return returnValue.id; } @Override long /*int*/ accessibilityAttributeValue(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0) { NSString attribute = new NSString(arg0); long /*int*/ returnValue = 0; id returnObject = null; if (handleIsAccessible(id) && accessible != null) { returnObject = accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF); } // If we had an accessible and it didn't handle the attribute request, let the // superclass handle it. if (returnObject == null) { returnValue = super.accessibilityAttributeValue(id, sel, arg0); // Feature in Cocoa: SWT doesn't use setToolTip for tooltip support, so if the // help attribute was requested return toolTipText. if (returnObject == null) { if (attribute.isEqualToString(OS.NSAccessibilityHelpAttribute)) { if (toolTipText != null) returnValue = NSString.stringWith(toolTipText).id; } } } else { returnValue = returnObject.id; } return returnValue; } @Override long /*int*/ accessibilityAttributeValue_forParameter(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, long /*int*/ arg1) { NSString attribute = new NSString(arg0); id returnValue = null; if (handleIsAccessible(id) && accessible != null) { id parameter = new id(arg1); returnValue = accessible.internal_accessibilityAttributeValue_forParameter(attribute, parameter, ACC.CHILDID_SELF); } // If we had an accessible and it didn't handle the attribute request, let the // superclass handle it. if (returnValue == null) return super.accessibilityAttributeValue_forParameter(id, sel, arg0, arg1); else return returnValue.id; } @Override boolean accessibilityIsAttributeSettable(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0) { boolean returnValue = false; if (handleIsAccessible(id) && accessible != null) { NSString attribute = new NSString (arg0); returnValue = accessible.internal_accessibilityIsAttributeSettable(attribute, ACC.CHILDID_SELF); } if (!returnValue) { returnValue = super.accessibilityIsAttributeSettable(id, sel, arg0); } return returnValue; } @Override void accessibilitySetValue_forAttribute(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, long /*int*/ arg1) { if (handleIsAccessible(id) && accessible != null) { id value = new id(arg0); NSString attribute = new NSString(arg1); accessible.internal_accessibilitySetValue_forAttribute(value, attribute, ACC.CHILDID_SELF); } else { super.accessibilitySetValue_forAttribute(id, sel, arg0, arg1); } } /** * 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- 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
*ControlListener
* interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see ControlListener * @see #removeControlListener */ public void addControlListener(ControlListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Resize,typedListener); addListener (SWT.Move,typedListener); } /** * Adds the listener to the collection of listeners who will * be notified when a drag gesture occurs, by sending it * one of the messages defined in the- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*DragDetectListener
* interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see DragDetectListener * @see #removeDragDetectListener * * @since 3.3 */ public void addDragDetectListener (DragDetectListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.DragDetect,typedListener); } /** * Adds the listener to the collection of listeners who will * be notified when the control gains or loses focus, by sending * it one of the messages defined in the- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*FocusListener
* interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see FocusListener * @see #removeFocusListener */ public void addFocusListener(FocusListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener(SWT.FocusIn,typedListener); addListener(SWT.FocusOut,typedListener); } /** * Adds the listener to the collection of listeners who will * be notified when gesture events are generated for the control, * by sending it one of the messages defined in the *- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*GestureListener
interface. ** NOTE: If
*setTouchEnabled(true)
has previously been * invoked on the receiver thensetTouchEnabled(false)
* must be invoked on it to specify that gesture events should be * sent instead of touch events. ** Warning: This API is currently only implemented on Windows and Cocoa. * SWT doesn't send Gesture or Touch events on GTK. *
* * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see GestureListener * @see #removeGestureListener * @see #setTouchEnabled * * @since 3.7 */ public void addGestureListener (GestureListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Gesture, typedListener); } /** * Adds the listener to the collection of listeners who will * be notified when help events are generated for the control, * by sending it one of the messages defined in the *- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*HelpListener
interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see HelpListener * @see #removeHelpListener */ public void addHelpListener (HelpListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Help, typedListener); } /** * Adds the listener to the collection of listeners who will * be notified when keys are pressed and released on the system keyboard, by sending * it one of the messages defined in the- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*KeyListener
* interface. ** When a key listener is added to a control, the control * will take part in widget traversal. By default, all * traversal keys (such as the tab key and so on) are * delivered to the control. In order for a control to take * part in traversal, it should listen for traversal events. * Otherwise, the user can traverse into a control but not * out. Note that native controls such as table and tree * implement key traversal in the operating system. It is * not necessary to add traversal listeners for these controls, * unless you want to override the default traversal. *
* @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see KeyListener * @see #removeKeyListener */ public void addKeyListener(KeyListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener(SWT.KeyUp,typedListener); addListener(SWT.KeyDown,typedListener); } /** * Adds the listener to the collection of listeners who will * be notified when the platform-specific context menu trigger * has occurred, by sending it one of the messages defined in * the- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*MenuDetectListener
interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see MenuDetectListener * @see #removeMenuDetectListener * * @since 3.3 */ public void addMenuDetectListener (MenuDetectListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.MenuDetect, typedListener); } /** * Adds the listener to the collection of listeners who will * be notified when mouse buttons are pressed and released, by sending * it one of the messages defined in the- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*MouseListener
* interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see MouseListener * @see #removeMouseListener */ public void addMouseListener(MouseListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener(SWT.MouseDown,typedListener); addListener(SWT.MouseUp,typedListener); addListener(SWT.MouseDoubleClick,typedListener); } /** * Adds the listener to the collection of listeners who will * be notified when the mouse passes or hovers over controls, by sending * it one of the messages defined in the- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*MouseTrackListener
* interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see MouseTrackListener * @see #removeMouseTrackListener */ public void addMouseTrackListener (MouseTrackListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.MouseEnter,typedListener); addListener (SWT.MouseExit,typedListener); addListener (SWT.MouseHover,typedListener); } /** * Adds the listener to the collection of listeners who will * be notified when the mouse moves, by sending it one of the * messages defined in the- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*MouseMoveListener
* interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see MouseMoveListener * @see #removeMouseMoveListener */ public void addMouseMoveListener(MouseMoveListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener(SWT.MouseMove,typedListener); } /** * Adds the listener to the collection of listeners who will * be notified when the mouse wheel is scrolled, by sending * it one of the messages defined in the *- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*MouseWheelListener
interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see MouseWheelListener * @see #removeMouseWheelListener * * @since 3.3 */ public void addMouseWheelListener (MouseWheelListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.MouseWheel, typedListener); } void addRelation (Control control) { } /** * Adds the listener to the collection of listeners who will * be notified when the receiver needs to be painted, by sending it * one of the messages defined in the- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*PaintListener
* interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see PaintListener * @see #removePaintListener */ public void addPaintListener(PaintListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener(SWT.Paint,typedListener); } static final double SYNTHETIC_BOLD = -2.5; static final double SYNTHETIC_ITALIC = 0.2; void addTraits(NSMutableDictionary dict, Font font) { if ((font.extraTraits & OS.NSBoldFontMask) != 0) { dict.setObject(NSNumber.numberWithDouble(SYNTHETIC_BOLD), OS.NSStrokeWidthAttributeName); } if ((font.extraTraits & OS.NSItalicFontMask) != 0) { dict.setObject(NSNumber.numberWithDouble(SYNTHETIC_ITALIC), OS.NSObliquenessAttributeName); } } /** * Adds the listener to the collection of listeners who will * be notified when touch events occur, by sending it * one of the messages defined in the- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*TouchListener
* interface. ** NOTE: You must also call
*setTouchEnabled(true)
to * specify that touch events should be sent, which will cause gesture * events to not be sent. ** Warning: This API is currently only implemented on Windows and Cocoa. * SWT doesn't send Gesture or Touch events on GTK. *
* * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see TouchListener * @see #removeTouchListener * @see #setTouchEnabled * * @since 3.7 */ public void addTouchListener (TouchListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Touch,typedListener); } /** * Adds the listener to the collection of listeners who will * be notified when traversal events occur, by sending it * one of the messages defined in the- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*TraverseListener
* interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT - if the listener is null
**
* * @see TraverseListener * @see #removeTraverseListener */ public void addTraverseListener (TraverseListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Traverse,typedListener); } @Override boolean becomeFirstResponder (long /*int*/ id, long /*int*/ sel) { if ((state & DISABLED) != 0) return false; return super.becomeFirstResponder (id, sel); } @Override void beginGestureWithEvent (long /*int*/ id, long /*int*/ sel, long /*int*/ event) { if (!gestureEvent(id, event, SWT.GESTURE_BEGIN)) return; super.beginGestureWithEvent(id, sel, event); } @Override void endGestureWithEvent (long /*int*/ id, long /*int*/ sel, long /*int*/ event) { if (!gestureEvent(id, event, SWT.GESTURE_END)) return; super.endGestureWithEvent(id, sel, event); } void calculateVisibleRegion (NSView view, long /*int*/ visibleRgn, boolean clipChildren) { long /*int*/ tempRgn = OS.NewRgn (); if (!view.isHiddenOrHasHiddenAncestor() && isDrawing()) { long /*int*/ childRgn = OS.NewRgn (); NSWindow window = view.window (); NSView contentView = window.contentView(); NSView frameView = contentView.superview(); NSRect bounds = contentView.visibleRect(); bounds = contentView.convertRect_toView_(bounds, view); short[] rect = new short[4]; OS.SetRect(rect, (short)bounds.x, (short)bounds.y, (short)(bounds.x + bounds.width), (short)(bounds.y + bounds.height)); OS.RectRgn(visibleRgn, rect); NSView tempView = view, lastControl = null; while (tempView.id != frameView.id) { bounds = tempView.visibleRect(); bounds = tempView.convertRect_toView_(bounds, view); OS.SetRect(rect, (short)bounds.x, (short)bounds.y, (short)(bounds.x + bounds.width), (short)(bounds.y + bounds.height)); OS.RectRgn(tempRgn, rect); OS.SectRgn (tempRgn, visibleRgn, visibleRgn); if (OS.EmptyRgn (visibleRgn)) break; if (clipChildren || tempView.id != view.id) { NSArray subviews = tempView.subviews(); long /*int*/ count = subviews.count(); for (int i = 0; i < count; i++) { NSView child = new NSView (subviews.objectAtIndex(count - i - 1)); if (lastControl != null && child.id == lastControl.id) break; if (child.isHidden()) continue; bounds = child.visibleRect(); bounds = child.convertRect_toView_(bounds, view); OS.SetRect(rect, (short)bounds.x, (short)bounds.y, (short)(bounds.x + bounds.width), (short)(bounds.y + bounds.height)); OS.RectRgn(tempRgn, rect); OS.UnionRgn (tempRgn, childRgn, childRgn); } } lastControl = tempView; tempView = tempView.superview(); } OS.DiffRgn (visibleRgn, childRgn, visibleRgn); OS.DisposeRgn (childRgn); } else { OS.CopyRgn (tempRgn, visibleRgn); } OS.DisposeRgn (tempRgn); } @Override void cancelOperation(long /*int*/ id, long /*int*/ sel, long /*int*/ sender) { // Cmd-. and escape arrive here. Forward the current event as a key event. if (hasKeyboardFocus(id)) { NSEvent nsEvent = NSApplication.sharedApplication().currentEvent(); Shell s = this.getShell(); s.keyInputHappened = false; boolean [] consume = new boolean [1]; if (translateTraversal (nsEvent.keyCode (), nsEvent, consume)) return; if (isDisposed ()) return; if (!sendKeyEvent (nsEvent, SWT.KeyDown)) return; } } void checkBackground () { Shell shell = getShell (); if (this == shell) return; state &= ~PARENT_BACKGROUND; Composite composite = parent; do { int mode = composite.backgroundMode; if (mode != 0 || backgroundAlpha == 0) { if (mode == SWT.INHERIT_DEFAULT || backgroundAlpha == 0) { Control control = this; do { if ((control.state & THEME_BACKGROUND) == 0) { return; } control = control.parent; } while (control != composite); } state |= PARENT_BACKGROUND; return; } if (composite == shell) break; composite = composite.parent; } while (true); } void checkBuffered () { style |= SWT.DOUBLE_BUFFERED; } void checkToolTip (Widget target) { if (isVisible () && display.tooltipControl == this && (target == null || display.tooltipTarget == target)) { Shell shell = getShell (); shell.sendToolTipEvent (false); shell.sendToolTipEvent (true); } } /** * Returns the preferred size (in points) of the receiver. *- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
** The preferred size of a control is the size that it would * best be displayed at. The width hint and height hint arguments * allow the caller to ask a control questions such as "Given a particular * width, how high does the control need to be to show all of the contents?" * To indicate that the caller does not wish to constrain a particular * dimension, the constant
* * @param wHint the width hint (can beSWT.DEFAULT
is passed for the hint. *SWT.DEFAULT
) * @param hHint the height hint (can beSWT.DEFAULT
) * @return the preferred size of the control * * @exception SWTException*
* * @see Layout * @see #getBorderWidth * @see #getBounds * @see #getSize * @see #pack(boolean) * @see "computeTrim, getClientArea for controls that implement them" */ public Point computeSize (int wHint, int hHint) { return computeSize (wHint, hHint, true); } /** * Returns the preferred size (in points) of the receiver. *- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
** The preferred size of a control is the size that it would * best be displayed at. The width hint and height hint arguments * allow the caller to ask a control questions such as "Given a particular * width, how high does the control need to be to show all of the contents?" * To indicate that the caller does not wish to constrain a particular * dimension, the constant
SWT.DEFAULT
is passed for the hint. ** If the changed flag is
* * @param wHint the width hint (can betrue
, it indicates that the receiver's * contents have changed, therefore any caches that a layout manager * containing the control may have been keeping need to be flushed. When the * control is resized, the changed flag will befalse
, so layout * manager caches can be retained. *SWT.DEFAULT
) * @param hHint the height hint (can beSWT.DEFAULT
) * @param changedtrue
if the control's contents have changed, andfalse
otherwise * @return the preferred size of the control. * * @exception SWTException*
* * @see Layout * @see #getBorderWidth * @see #getBounds * @see #getSize * @see #pack(boolean) * @see "computeTrim, getClientArea for controls that implement them" */ public Point computeSize (int wHint, int hHint, boolean changed) { checkWidget (); int width = DEFAULT_WIDTH; int height = DEFAULT_HEIGHT; if (wHint != SWT.DEFAULT) width = wHint; if (hHint != SWT.DEFAULT) height = hHint; int border = getBorderWidth (); width += border * 2; height += border * 2; return new Point (width, height); } Widget computeTabGroup () { if (isTabGroup()) return this; return parent.computeTabGroup (); } Widget[] computeTabList() { if (isTabGroup()) { if (getVisible() && getEnabled()) { return new Widget[] {this}; } } return new Widget[0]; } Control computeTabRoot () { Control[] tabList = parent._getTabList(); if (tabList != null) { int index = 0; while (index < tabList.length) { if (tabList [index] == this) break; index++; } if (index == tabList.length) { if (isTabGroup ()) return this; } } return parent.computeTabRoot (); } NSView contentView () { return view; } NSAttributedString createString (String string, Font font, double /*float*/ [] foreground, int alignment, boolean wrap, boolean enabled, boolean mnemonics) { NSMutableDictionary dict = ((NSMutableDictionary)new NSMutableDictionary().alloc()).initWithCapacity(5); if (font == null) font = this.font != null ? this.font : defaultFont(); dict.setObject (font.handle, OS.NSFontAttributeName); addTraits(dict, font); if (enabled) { if (foreground != null) { NSColor color = NSColor.colorWithDeviceRed(foreground[0], foreground[1], foreground[2], foreground[3]); dict.setObject (color, OS.NSForegroundColorAttributeName); } } else { dict.setObject (NSColor.disabledControlTextColor (), OS.NSForegroundColorAttributeName); } NSMutableParagraphStyle paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle ().alloc ().init (); paragraphStyle.setLineBreakMode (wrap ? OS.NSLineBreakByWordWrapping : OS.NSLineBreakByClipping); if (alignment != 0) { int align = OS.NSLeftTextAlignment; if ((alignment & SWT.CENTER) != 0) { align = OS.NSCenterTextAlignment; } else if ((alignment & SWT.RIGHT) != 0) { align = OS.NSRightTextAlignment; } paragraphStyle.setAlignment (align); } if ((style & SWT.RIGHT_TO_LEFT) != 0) { paragraphStyle.setBaseWritingDirection(OS.NSWritingDirectionRightToLeft); } else { paragraphStyle.setBaseWritingDirection(OS.NSWritingDirectionLeftToRight); } dict.setObject (paragraphStyle, OS.NSParagraphStyleAttributeName); paragraphStyle.release (); int length = string.length (); char [] chars = new char [length]; string.getChars (0, chars.length, chars, 0); if (mnemonics) length = fixMnemonic (chars); NSString str = ((NSString)new NSString().alloc()).initWithCharacters(chars, length); NSAttributedString attribStr = ((NSAttributedString) new NSAttributedString ().alloc ()).initWithString (str, dict); str.release(); dict.release(); return attribStr; } @Override void createWidget () { state |= DRAG_DETECT; checkOrientation (parent); super.createWidget (); checkBackground (); checkBuffered (); setDefaultFont (); setZOrder (); setRelations (); if ((state & PARENT_BACKGROUND) != 0) { setBackground (); } display.clearPool (); } Color defaultBackground () { return display.getWidgetColor (SWT.COLOR_WIDGET_BACKGROUND); } Font defaultFont () { if (display.smallFonts) return display.getSystemFont (); return Font.cocoa_new (display, defaultNSFont ()); } Color defaultForeground () { return display.getWidgetColor (SWT.COLOR_WIDGET_FOREGROUND); } NSFont defaultNSFont () { return display.getSystemFont().handle; } @Override void deregister () { super.deregister (); display.removeWidget (view); } @Override void destroyWidget () { NSView view = topView (); view.removeFromSuperview (); releaseHandle (); } @Override void doCommandBySelector (long /*int*/ id, long /*int*/ sel, long /*int*/ selector) { if (hasKeyboardFocus(id)) { if (imeInComposition ()) return; Shell s = this.getShell(); NSEvent nsEvent = NSApplication.sharedApplication ().currentEvent (); if (nsEvent != null && nsEvent.type () == OS.NSKeyDown) { /* * Feature in Cocoa. Pressing Alt+UpArrow invokes doCommandBySelector * twice, with selectors moveBackward and moveToBeginningOfParagraph * (Alt+DownArrow behaves similarly). In order to avoid sending * multiple events for these keys, do not send a KeyDown if we already sent one * during this keystroke. This rule does not apply if the command key * is down, because we likely triggered the current key sequence via flagsChanged. */ long /*int*/ modifiers = nsEvent.modifierFlags(); if (s.keyInputHappened == false || (modifiers & OS.NSCommandKeyMask) != 0) { s.keyInputHappened = true; boolean [] consume = new boolean [1]; if (translateTraversal (nsEvent.keyCode (), nsEvent, consume)) return; if (isDisposed ()) return; if (!sendKeyEvent (nsEvent, SWT.KeyDown)) return; if (consume [0]) return; } } if ((state & CANVAS) != 0) return; } super.doCommandBySelector (id, sel, selector); } /** * Detects a drag and drop gesture. This method is used * to detect a drag gesture when called from within a mouse * down listener. * *- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*By default, a drag is detected when the gesture * occurs anywhere within the client area of a control. * Some controls, such as tables and trees, override this * behavior. In addition to the operating system specific * drag gesture, they require the mouse to be inside an * item. Custom widget writers can use
* * @param event the mouse down event * * @returnsetDragDetect
* to disable the default detection, listen for mouse down, * and then calldragDetect()
from within the * listener to conditionally detect a drag. *true
if the gesture occurred, andfalse
otherwise. * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT if the event is null
**
* * @see DragDetectListener * @see #addDragDetectListener * * @see #getDragDetect * @see #setDragDetect * * @since 3.3 */ public boolean dragDetect (Event event) { checkWidget (); if (event == null) error (SWT.ERROR_NULL_ARGUMENT); return dragDetect (event.button, event.count, event.stateMask, event.x, event.y); } /** * Detects a drag and drop gesture. This method is used * to detect a drag gesture when called from within a mouse * down listener. * *- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*By default, a drag is detected when the gesture * occurs anywhere within the client area of a control. * Some controls, such as tables and trees, override this * behavior. In addition to the operating system specific * drag gesture, they require the mouse to be inside an * item. Custom widget writers can use
* * @param event the mouse down event * * @returnsetDragDetect
* to disable the default detection, listen for mouse down, * and then calldragDetect()
from within the * listener to conditionally detect a drag. *true
if the gesture occurred, andfalse
otherwise. * * @exception IllegalArgumentException*
* @exception SWTException- ERROR_NULL_ARGUMENT if the event is null
**
* * @see DragDetectListener * @see #addDragDetectListener * * @see #getDragDetect * @see #setDragDetect * * @since 3.3 */ public boolean dragDetect (MouseEvent event) { checkWidget (); if (event == null) error (SWT.ERROR_NULL_ARGUMENT); return dragDetect (event.button, event.count, event.stateMask, event.x, event.y); } boolean dragDetect (int button, int count, int stateMask, int x, int y) { if (button != 1 || count != 1) return false; if (!dragDetect (x, y, false, null)) return false; return sendDragEvent (button, stateMask, x, y); } boolean dragDetect (int x, int y, boolean filter, boolean [] consume) { /** * Feature in Cocoa. Mouse drag events do not account for hysteresis. * As soon as the mouse drags a mouse dragged event is fired. Fix is to * check for another mouse drag event that is at least 5 pixels away * from the start of the drag. */ NSApplication application = NSApplication.sharedApplication(); boolean dragging = false; long /*int*/ eventType = OS.NSLeftMouseDown; double /*float*/ dragX = x; double /*float*/ dragY = y; /** * To check for an actual drag we need to pull off mouse moved and mouse up events * to detect if the user dragged outside of a 10 x 10 box centered on the mouse down location. * We still want the view to see the events, so save them and re-post when done checking. * If no motion happens for .3 seconds, bail. */ NSEvent mouseUpEvent = null; NSMutableArray dragEvents = NSMutableArray.arrayWithCapacity(10); NSDate timeout = NSDate.dateWithTimeIntervalSinceNow(0.3); while (eventType != OS.NSLeftMouseUp) { NSEvent event = application.nextEventMatchingMask((OS.NSLeftMouseUpMask | OS.NSLeftMouseDraggedMask), timeout, OS.NSEventTrackingRunLoopMode, true); // No event means nextEventMatchingMask timed out. if (event == null) { dragging = true; break; } eventType = event.type(); if (eventType == OS.NSLeftMouseDragged) { dragEvents.addObject(event); NSPoint windowLoc = event.locationInWindow(); NSPoint viewLoc = view.convertPoint_fromView_(windowLoc, null); if (!view.isFlipped ()) { viewLoc.y = view.bounds().height - viewLoc.y; } if ((Math.abs(viewLoc.x - dragX) > DEFAULT_DRAG_HYSTERESIS) || (Math.abs(viewLoc.y - dragY) > DEFAULT_DRAG_HYSTERESIS)) { dragging = true; break; } } else if (eventType == OS.NSLeftMouseUp) { mouseUpEvent = event; } } // Push back any events we took out of the queue so the control can receive them. if (mouseUpEvent != null) application.postEvent(mouseUpEvent, true); if (dragEvents.count() > 0) { while (dragEvents.count() > 0) { NSEvent currEvent = new NSEvent(dragEvents.objectAtIndex(dragEvents.count() - 1).id); dragEvents.removeLastObject(); application.postEvent(currEvent, true); } } return dragging; } boolean drawGripper (GC gc, int x, int y, int width, int height, boolean vertical) { return false; } boolean drawsBackground() { return true; } @Override void drawWidget (long /*int*/ id, NSGraphicsContext context, NSRect rect) { if (id != paintView().id) return; if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return; /* Send paint event */ GCData data = new GCData (); data.paintRect = rect; GC gc = GC.cocoa_new (this, data); Event event = new Event (); event.gc = gc; event.x = (int)rect.x; event.y = (int)rect.y; event.width = (int)rect.width; event.height = (int)rect.height; sendEvent (SWT.Paint, event); event.gc = null; gc.dispose (); } void enableWidget (boolean enabled) { if (view instanceof NSControl) { ((NSControl)view).setEnabled(enabled); } updateCursorRects (isEnabled ()); } boolean equals(double /*float*/ [] color1, double /*float*/ [] color2) { if (color1 == color2) return true; if (color1 == null) return color2 == null; if (color2 == null) return color1 == null; for (int i = 0; i < color1.length; i++) { if (color1 [i] != color2 [i]) return false; } return true; } NSView eventView () { return view; } void fillBackground (NSView view, NSGraphicsContext context, NSRect rect, int imgHeight) { fillBackground(view, context, rect, imgHeight, null, 0, 0); } void fillBackground (NSView view, NSGraphicsContext context, NSRect rect, int imgHeight, NSView gcView, int tx, int ty) { if (!drawsBackground()) return; Control control = findBackgroundControl(); if (control == null) control = this; Image image = control.backgroundImage; if (image != null && !image.isDisposed()) { context.saveGraphicsState(); NSColor.colorWithPatternImage(image.handle).setFill(); NSPoint phase = new NSPoint(); NSView controlView = control.view; if (!controlView.isFlipped()) { phase.y = controlView.bounds().height; } if (imgHeight == -1) { NSView contentView = controlView.window().contentView(); phase = controlView.convertPoint_toView_(phase, contentView); phase.y = contentView.bounds().height - phase.y; } else { phase = view.convertPoint_toView_(phase, controlView); phase.y += imgHeight - backgroundImage.getBounds().height; } if (gcView != null) { NSPoint pt = gcView.convertPoint_toView_(new NSPoint(), view); phase.x += pt.x; phase.y -= pt.y; } phase.x -= tx; phase.y += ty; context.setPatternPhase(phase); NSBezierPath.fillRect(rect); context.restoreGraphicsState(); return; } double /*float*/ [] background = control.background; double /*float*/ alpha; if (background == null) { if (isTransparent()) return; background = control.defaultBackground ().handle; alpha = getThemeAlpha (); } else { alpha = background[3]; } context.saveGraphicsState (); NSColor.colorWithDeviceRed (background [0], background [1], background [2], alpha).setFill (); NSBezierPath.fillRect (rect); context.restoreGraphicsState (); } Cursor findCursor () { if (cursor != null) return cursor; return parent.findCursor (); } Control findBackgroundControl () { if ((backgroundImage != null || background != null) && backgroundAlpha > 0) return this; return (!isTransparent() && (state & PARENT_BACKGROUND) != 0) ? parent.findBackgroundControl () : null; } Menu [] findMenus (Control control) { if (menu != null && this != control) return new Menu [] {menu}; return new Menu [0]; } Widget findTooltip (NSPoint pt) { return this; } void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) { oldShell.fixShell (newShell, this); oldDecorations.fixDecorations (newDecorations, this, menus); } void fixFocus (Control focusControl) { Shell shell = getShell (); Control control = this; while (control != shell && (control = control.parent) != null) { if (control.setFocus ()) return; } shell.setSavedFocus (focusControl); NSWindow window = view.window(); if (!window.makeFirstResponder(null)) { // Force first responder to resign. window.endEditingFor(null); } } @Override void flagsChanged (long /*int*/ id, long /*int*/ sel, long /*int*/ theEvent) { if (hasKeyboardFocus(id)) { if ((state & WEBKIT_EVENTS_FIX) == 0) { Shell s = this.getShell(); s.keyInputHappened = false; int mask = 0; NSEvent nsEvent = new NSEvent (theEvent); long /*int*/ modifiers = nsEvent.modifierFlags (); int keyCode = Display.translateKey (nsEvent.keyCode ()); switch (keyCode) { case SWT.ALT: mask = OS.NSAlternateKeyMask; break; case SWT.CONTROL: mask = OS.NSControlKeyMask; break; case SWT.COMMAND: mask = OS.NSCommandKeyMask; break; case SWT.SHIFT: mask = OS.NSShiftKeyMask; break; case SWT.CAPS_LOCK: Event event = new Event(); event.keyCode = keyCode; setInputState (event, nsEvent, SWT.KeyDown); sendKeyEvent (SWT.KeyDown, event); setInputState (event, nsEvent, SWT.KeyUp); sendKeyEvent (SWT.KeyUp, event); break; } if (mask != 0) { s.keyInputHappened = true; int type = (mask & modifiers) != 0 ? SWT.KeyDown : SWT.KeyUp; Event event = new Event(); event.keyCode = keyCode; setLocationMask(event, nsEvent); setInputState (event, nsEvent, type); if (!sendKeyEvent (type, event)) return; } } } super.flagsChanged (id, sel, theEvent); } NSView focusView () { return view; } /** * Forces the receiver to have the keyboard focus, causing * all keyboard events to be delivered to it. * * @return- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*true
if the control got focus, andfalse
if it was unable to. * * @exception SWTException*
* * @see #setFocus */ public boolean forceFocus () { checkWidget(); if (display.focusEvent == SWT.FocusOut) return false; Decorations shell = menuShell (); shell.setSavedFocus (this); if (!isEnabled () || !isVisible () || !isActive ()) return false; if (isFocusControl ()) return true; shell.setSavedFocus (null); NSView focusView = focusView (); if (!focusView.canBecomeKeyView()) return false; boolean result = forceFocus(focusView); if (isDisposed ()) return false; shell.setSavedFocus (this); /* * Feature in Cocoa. If the window is inactive when forceFocus is called bringToTop * eventually calls makeKeyAndOrderFront. This activates the window immediately, but unlike other platforms, * it also immediately fire notifications that the window was activated, as opposed to posting an event * to be handled on the next pass of readAndDispatch(). * * Shell#windowDidBecomeKey will call Decorations#restoreFocus, so the saved focus must be set * before the window is activated or the wrong control will get focus. */ shell.bringToTop (false); if (isDisposed ()) return false; return result; } boolean forceFocus (NSView focusView) { NSWindow window = view.window (); if(window == null) { return false; } return window.makeFirstResponder (focusView); } boolean gestureEvent(long /*int*/ id, long /*int*/ eventPtr, int detail) { if (!display.sendEvent) return true; display.sendEvent = false; // For cross-platform compatibility, touch events and gestures are mutually exclusive. // Don't send a gesture if touch events are enabled for this control. if (touchEnabled) return true; if (!isEventView (id)) return true; if (!hooks(SWT.Gesture) && !filters(SWT.Gesture)) return true; NSEvent nsEvent = new NSEvent(eventPtr); Event event = new Event(); NSPoint windowPoint; NSView view = eventView (); windowPoint = nsEvent.locationInWindow(); NSPoint point = view.convertPoint_fromView_(windowPoint, null); if (!view.isFlipped ()) { point.y = view.bounds().height - point.y; } event.x = (int) point.x; event.y = (int) point.y; setInputState (event, nsEvent, SWT.Gesture); event.detail = detail; if (detail == SWT.GESTURE_BEGIN) { display.rotation = 0.0; display.magnification = 1.0; display.gestureActive = true; } else if (detail == SWT.GESTURE_END) { display.gestureActive = false; } switch (detail) { case SWT.GESTURE_SWIPE: event.xDirection = (int) -nsEvent.deltaX(); event.yDirection = (int) -nsEvent.deltaY(); break; case SWT.GESTURE_ROTATE: { display.rotation += nsEvent.rotation(); event.rotation = display.rotation; break; } case SWT.GESTURE_MAGNIFY: display.magnification *= (1.0 + nsEvent.magnification()); event.magnification = display.magnification; break; case SWT.GESTURE_PAN: // Panning increment is expressed in terms of the direction of movement, // not in terms of scrolling increment. if (display.gestureActive) { event.xDirection = (int) nsEvent.deltaX(); event.yDirection = (int) nsEvent.deltaY(); if (event.xDirection == 0 && event.yDirection == 0) return true; } break; } sendEvent (SWT.Gesture, event); return event.doit; } /** * Returns the accessible object for the receiver. *- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
** If this is the first time this object is requested, * then the object is created and returned. The object * returned by getAccessible() does not need to be disposed. *
* * @return the accessible object * * @exception SWTException*
* * @see Accessible#addAccessibleListener * @see Accessible#addAccessibleControlListener * * @since 2.0 */ public Accessible getAccessible () { checkWidget (); if (accessible == null) accessible = new_Accessible (this); return accessible; } /** * Returns the receiver's background color. *- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
** Note: This operation is a hint and may be overridden by the platform. * For example, on some versions of Windows the background of a TabFolder, * is a gradient rather than a solid color. *
* @return the background color * * @exception SWTException*
*/ public Color getBackground () { checkWidget(); if (backgroundAlpha == 0) { Color color = Color.cocoa_new (display, background, 0); return color; } else { Control control = findBackgroundControl (); if (control == null) control = this; return control.getBackgroundColor (); } } Color getBackgroundColor () { return background != null ? Color.cocoa_new (display, background, backgroundAlpha) : defaultBackground (); } /** * Returns the receiver's background image. * * @return the background image * * @exception SWTException- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
**
* * @since 3.2 */ public Image getBackgroundImage () { checkWidget(); Control control = findBackgroundControl (); if (control == null) control = this; return control.backgroundImage; } /** * Returns the receiver's border width in points. * * @return the border width * * @exception SWTException- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
**
*/ public int getBorderWidth () { checkWidget(); return 0; } /** * Returns a rectangle describing the receiver's size and location in points * relative to its parent (or its display if its parent is null), * unless the receiver is a shell. In this case, the location is * relative to the display. * * @return the receiver's bounding rectangle * * @exception SWTException- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
**
*/ public Rectangle getBounds () { checkWidget(); NSRect rect = topView().frame(); return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); } /** * Returns- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*true
if the receiver is detecting * drag gestures, andfalse
otherwise. * * @return the receiver's drag detect state * * @exception SWTException*
* * @since 3.3 */ public boolean getDragDetect () { checkWidget (); return (state & DRAG_DETECT) != 0; } @Override boolean getDrawing () { return drawCount <= 0; } /** * Returns the receiver's cursor, or null if it has not been set. *- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
** When the mouse pointer passes over a control its appearance * is changed to match the control's cursor. *
* * @return the receiver's cursor ornull
* * @exception SWTException*
* * @since 3.3 */ public Cursor getCursor () { checkWidget(); return cursor; } /** * Returns- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*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*
* * @see #isEnabled */ public boolean getEnabled () { checkWidget(); return (state & DISABLED) == 0; } /** * Returns the font that the receiver will use to paint textual information. * * @return the receiver's font * * @exception SWTException- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
**
*/ public Font getFont () { checkWidget(); return font != null ? font : defaultFont (); } /** * Returns the foreground color that the receiver will use to draw. * * @return the receiver's foreground color * * @exception SWTException- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
**
*/ public Color getForeground () { checkWidget(); return getForegroundColor (); } Color getForegroundColor () { return foreground != null ? Color.cocoa_new (display, foreground) : defaultForeground (); } /** * Returns layout data which is associated with the receiver. * * @return the receiver's layout data * * @exception SWTException- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
**
*/ public Object getLayoutData () { checkWidget(); return layoutData; } /** * Returns a point describing the receiver's location relative * to its parent in points (or its display if its parent is null), unless * the receiver is a shell. In this case, the point is * relative to the display. * * @return the receiver's location * * @exception SWTException- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
**
*/ public Point getLocation () { checkWidget(); NSRect rect = topView().frame(); return new Point((int)rect.x, (int)rect.y); } /** * Returns the receiver's pop up menu if it has one, or null * if it does not. All controls may optionally have a pop up * menu that is displayed when the user requests one for * the control. The sequence of key strokes, button presses * and/or button releases that are used to request a pop up * menu is platform specific. * * @return the receiver's menu * * @exception SWTException- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
**
*/ public Menu getMenu () { checkWidget(); return menu; } int getMininumHeight () { return 0; } /** * Returns the receiver's monitor. * * @return the receiver's monitor * * @exception 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 Monitor getMonitor () { checkWidget(); Monitor [] monitors = display.getMonitors (); if (monitors.length == 1) return monitors [0]; int index = -1, value = -1; Rectangle bounds = getBounds (); if (this != getShell ()) { bounds = display.map (this.parent, null, bounds); } for (int i=0; i- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*0 && area > value) { index = i; value = area; } } if (index >= 0) return monitors [index]; int centerX = bounds.x + bounds.width / 2, centerY = bounds.y + bounds.height / 2; for (int i=0; i rect.x + rect.width ? centerX - rect.x - rect.width : 0; int y = centerY < rect.y ? rect.y - centerY : centerY > rect.y + rect.height ? centerY - rect.y - rect.height : 0; int distance = x * x + y * y; if (index == -1 || distance < value) { index = i; value = distance; } } return monitors [index]; } /** * Returns the orientation of the receiver, which will be one of the * constants SWT.LEFT_TO_RIGHT
orSWT.RIGHT_TO_LEFT
. * * @return the orientation style * * @exception SWTException*
* * @since 3.7 */ public int getOrientation () { checkWidget (); return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); } /** * Returns the receiver's parent, which must be a- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*Composite
* or null when the receiver is a shell that was created with null or * a display for a parent. * * @return the receiver's parent * * @exception SWTException*
*/ public Composite getParent () { checkWidget(); return parent; } Control [] getPath () { int count = 0; Shell shell = getShell (); Control control = this; while (control != shell) { count++; control = control.parent; } control = this; Control [] result = new Control [count]; while (control != shell) { result [--count] = control; control = control.parent; } return result; } NSBezierPath getPath(Region region) { if (region == null) return null; return getPath(region.handle); } NSBezierPath getPath(long /*int*/ region) { Callback callback = new Callback(this, "regionToRects", 4); if (callback.getAddress() == 0) error(SWT.ERROR_NO_MORE_CALLBACKS); NSBezierPath path = NSBezierPath.bezierPath(); path.retain(); OS.QDRegionToRects(region, OS.kQDParseRegionFromTopLeft, callback.getAddress(), path.id); callback.dispose(); if (path.isEmpty()) path.appendBezierPathWithRect(new NSRect()); return path; } /** * Returns the region that defines the shape of the control, * or null if the control has the default shape. * * @return the region that defines the shape of the shell (or null) * * @exception SWTException- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
**
* * @since 3.4 */ public Region getRegion () { checkWidget (); return region; } /** * Returns the receiver's shell. For all controls other than * shells, this simply returns the control's nearest ancestor * shell. Shells return themselves, even if they are children * of other shells. * * @return the receiver's shell * * @exception SWTException- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
**
* * @see #getParent */ public Shell getShell () { checkWidget(); return parent.getShell (); } /** * Returns a point describing the receiver's size in points. 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(); NSRect rect = topView().frame(); return new Point((int)rect.width, (int)rect.height); } /** * Returns the text direction of the receiver, which will be one of the * constants- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*SWT.LEFT_TO_RIGHT
orSWT.RIGHT_TO_LEFT
. * * @return the text direction style * * @exception SWTException*
* * @since 3.102 */ public int getTextDirection() { checkWidget (); /* return the widget orientation */ return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); } float getThemeAlpha () { return 1 * parent.getThemeAlpha (); } /** * 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- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*true
if this control is set to send touch events, or *false
if it is set to send gesture events instead. This method * also returnsfalse
if a touch-based input device is not detected * (this can be determined withDisplay#getTouchEnabled()
). Use * {@link #setTouchEnabled(boolean)} to switch the events that a control sends * between touch events and gesture events. * * @returntrue
if the control is set to send touch events, orfalse
otherwise * * @exception SWTException*
* * @see #setTouchEnabled * @see Display#getTouchEnabled * * @since 3.7 */ public boolean getTouchEnabled() { checkWidget(); return display.getTouchEnabled() && touchEnabled; } /** * Returns- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*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*
*/ public boolean getVisible () { checkWidget(); return (state & HIDDEN) == 0; } long /*int*/ getVisibleRegion () { if (visibleRgn == 0) { visibleRgn = OS.NewRgn (); calculateVisibleRegion (view, visibleRgn, true); } long /*int*/ result = OS.NewRgn (); OS.CopyRgn (visibleRgn, result); return result; } boolean hasBorder () { return (style & SWT.BORDER) != 0; } boolean hasFocus () { return display.getFocusControl() == this; } boolean hasRegion () { return region != null || parent.hasRegion (); } @Override long /*int*/ hitTest (long /*int*/ id, long /*int*/ sel, NSPoint point) { if ((state & DISABLED) != 0) return 0; if (!isActive ()) return 0; if (regionPath != null) { NSView rgnView = topView (); if (!rgnView.isFlipped()) rgnView = eventView (); NSPoint pt = rgnView.convertPoint_fromView_ (point, new NSView (id).superview()); if (!regionPath.containsPoint(pt)) return 0; } return super.hitTest(id, sel, point); } boolean imeInComposition () { return false; } @Override boolean insertText (long /*int*/ id, long /*int*/ sel, long /*int*/ string) { // sendKeyEvent may do something to run the event loop. That would cause // 'string' to be released before any superclass could use it, so save it // until this method finishes. NSObject saver = new NSObject(string); saver.retain(); try { if (hasKeyboardFocus(id)) { Shell s = this.getShell(); NSEvent nsEvent = NSApplication.sharedApplication ().currentEvent (); if (nsEvent != null) { long /*int*/ type = nsEvent.type (); if (type == OS.NSKeyDown || type == OS.NSKeyUp || type == OS.NSSystemDefined) { NSString str = new NSString (string); if (str.isKindOfClass (OS.class_NSAttributedString)) { str = new NSAttributedString (string).string (); } int length = (int)/*64*/str.length (); char[] buffer = new char [length]; str.getCharacters(buffer); for (int i = 0; i < buffer.length; i++) { s.keyInputHappened = true; Event event = new Event (); if (i == 0 && type == OS.NSKeyDown) setKeyState (event, SWT.KeyDown, nsEvent); event.character = buffer [i]; if (!sendKeyEvent (SWT.KeyDown, event)) return false; } } } if ((state & CANVAS) != 0) return true; } return super.insertText (id, sel, string); } finally { saver.release(); } } /** * Invokes platform specific functionality to allocate a new GC handle. *- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
*- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
** IMPORTANT: This method is not part of the public * API for
* * @param data the platform specific GC data * @return the platform specific GC handle * * @noreference This method is not intended to be referenced by clients. */ @Override public long /*int*/ internal_new_GC (GCData data) { checkWidget(); NSView view = paintView(); NSGraphicsContext graphicsContext = null; if (data != null && data.paintRect != null) { graphicsContext = NSGraphicsContext.currentContext(); if (!view.isFlipped()) data.state &= ~VISIBLE_REGION; } if (graphicsContext == null) { NSWindow window = view.window(); /* * Force the device to be created before attempting * to create a GC on a deferred NSWindow. */ if (window.windowNumber() <= 0) { double /*float*/ alpha = window.alphaValue(); window.setAlphaValue(0); window.orderBack(null); window.orderOut(null); window.setAlphaValue(alpha); } graphicsContext = NSGraphicsContext.graphicsContextWithWindow (window); NSGraphicsContext flippedContext = NSGraphicsContext.graphicsContextWithGraphicsPort(graphicsContext.graphicsPort(), true); graphicsContext = flippedContext; if (data != null) { data.flippedContext = flippedContext; data.state &= ~VISIBLE_REGION; data.visibleRgn = getVisibleRegion(); display.addContext (data); } } if (data != null) { int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; if ((data.style & mask) == 0) { data.style |= style & (mask | SWT.MIRRORED); } data.device = display; data.thread = display.thread; data.view = view; data.view.retain(); data.view.window().retain(); data.foreground = getForegroundColor ().handle; Control control = findBackgroundControl (); if (control == null) control = this; data.background = control.getBackgroundColor ().handle; data.font = font != null ? font : defaultFont (); } if (graphicsContext != null) { return graphicsContext.id; } return 0; } /** * Invokes platform specific functionality to dispose a GC handle. *Control
. It is marked public only so that it * can be shared within the packages provided by SWT. It is not * available on all platforms, and should never be called from * application code. ** IMPORTANT: This method is not part of the public * API for
* * @param hDC the platform specific GC handle * @param data the platform specific GC data * * @noreference This method is not intended to be referenced by clients. */ @Override public void internal_dispose_GC (long /*int*/ hDC, GCData data) { checkWidget (); long /*int*/ context = hDC; NSGraphicsContext graphicsContext = new NSGraphicsContext (context); display.removeContext (data); if (data != null) { if (data.paintRect == null) graphicsContext.flushGraphics (); if (data.visibleRgn != 0) OS.DisposeRgn(data.visibleRgn); data.visibleRgn = 0; if (data.view != null) { data.view.window().release(); data.view.release(); data.view = null; } } } void invalidateChildrenVisibleRegion () { } void invalidateVisibleRegion () { int index = 0; Control[] siblings = parent._getChildren (); while (index < siblings.length && siblings [index] != this) index++; for (int i=index; iControl
. 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. *true false
is returned. * A disabled control is typically not selectable from the user * interface and draws with an inactive or "grayed" look. * * @return the receiver's enabled state * * @exception SWTException
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
true
if the receiver has the user-interface
* focus, and false
otherwise.
*
* @return the receiver's focus state
*
* @exception SWTException -
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
true
if the underlying operating
* system supports this reparenting, otherwise false
*
* @return true
if the widget can be reparented, otherwise false
*
* @exception SWTException -
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
false
is returned.
*
* @return the receiver's visibility state
*
* @exception SWTException -
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_INVALID_ARGUMENT - if the control has been disposed *
-
*
- 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 the control has been disposed *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
* If the changed flag is true
, it indicates that the receiver's
* contents have changed, therefore any caches that a layout manager
* containing the control may have been keeping need to be flushed. When the
* control is resized, the changed flag will be false
, so layout
* manager caches can be retained.
*
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
true
if the operation was successful and false
otherwise
*
* @exception IllegalArgumentException -
*
- ERROR_NULL_ARGUMENT - if the gc is null *
- ERROR_INVALID_ARGUMENT - if the gc has been disposed *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
* The control will not be repositioned synchronously. This method is * fast-running and only marks the control for future participation in * a deferred layout. *
* Invoking this method multiple times before the layout occurs is an * inexpensive no-op. * * @since 3.105 */ public void requestLayout () { getShell ().layout (new Control[] {this}, SWT.DEFER); } /** * Causes the entire bounds of the receiver to be marked * as needing to be redrawn. The next time a paint request * is processed, the control will be completely painted, * including the background. * * @exception SWTException
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
all
flag is true
, any
* children of the receiver which intersect with the specified
* area will also paint their intersecting areas. If the
* all
flag is false
, the children
* will not be painted.
*
* @param x the x coordinate of the area to draw
* @param y the y coordinate of the area to draw
* @param width the width of the area to draw
* @param height the height of the area to draw
* @param all true
if children should redraw, and false
otherwise
*
* @exception SWTException -
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_NULL_ARGUMENT - if the listener is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
* Note: This operation is a hint and may be overridden by the platform. * For example, on Windows the background of a Button cannot be changed. *
* @param color the new color (or null) * * @exception IllegalArgumentException-
*
- ERROR_INVALID_ARGUMENT - if the argument has been disposed *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
* Note: This operation is a hint and may be overridden by the platform. * For example, on Windows the background of a Button cannot be changed. *
* @param image the new image (or null) * * @exception IllegalArgumentException-
*
- ERROR_INVALID_ARGUMENT - if the argument has been disposed *
- ERROR_INVALID_ARGUMENT - if the argument is not a bitmap *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
x
and
* y
arguments are relative to the receiver's
* parent (or its display if its parent is null), unless
* the receiver is a shell. In this case, the x
* and y
arguments are relative to the display.
* * Note: Attempting to set the width or height of the * receiver to a negative number will cause that * value to be set to zero instead. *
** Note: On GTK, attempting to set the width or height of the * receiver to a number higher or equal 2^14 will cause them to be * set to (2^14)-1 instead. *
* * @param x the new x coordinate for the receiver * @param y the new y coordinate for the receiver * @param width the new width for the receiver * @param height the new height for the receiver * * @exception SWTException-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
x
and
* y
fields of the rectangle are relative to
* the receiver's parent (or its display if its parent is null).
* * Note: Attempting to set the width or height of the * receiver to a negative number will cause that * value to be set to zero instead. *
** Note: On GTK, attempting to set the width or height of the * receiver to a number higher or equal 2^14 will cause them to be * set to (2^14)-1 instead. *
* * @param rect the new bounds for the receiver * * @exception SWTException-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
true
, causes the receiver to have
* all mouse events delivered to it until the method is called with
* false
as the argument. Note that on some platforms,
* a mouse button must currently be down for capture to be assigned.
*
* @param capture true
to capture the mouse, and false
to release it
*
* @exception SWTException -
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
* When the mouse pointer passes over a control its appearance * is changed to match the control's cursor. *
* * @param cursor the new cursor (or null) * * @exception IllegalArgumentException-
*
- ERROR_INVALID_ARGUMENT - if the argument has been disposed *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
true
, the receiver will detect drag gestures,
* otherwise these gestures will be ignored.
*
* @param dragDetect the new drag detect state
*
* @exception SWTException -
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
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 *
true
if the control got focus, and false
if it was unable to.
*
* @exception SWTException -
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_INVALID_ARGUMENT - if the argument has been disposed *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
* Note: This operation is a hint and may be overridden by the platform. *
* @param color the new color (or null) * * @exception IllegalArgumentException-
*
- ERROR_INVALID_ARGUMENT - if the argument has been disposed *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
* Note: Disposing of a control that has a pop up menu will * dispose of the menu. To avoid this behavior, set the * menu to null before the control is disposed. *
* * @param menu the new pop up menu * * @exception IllegalArgumentException-
*
- ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu *
- ERROR_INVALID_PARENT - if the menu is not in the same widget tree *
- ERROR_INVALID_ARGUMENT - if the menu has been disposed *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
SWT.LEFT_TO_RIGHT
or SWT.RIGHT_TO_LEFT
.
* * * @param orientation new orientation style * * @exception SWTException
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
true
if the parent is successfully changed.
*
* @param parent the new parent for the control.
* @return true
if the parent is changed and false
otherwise.
*
* @exception IllegalArgumentException -
*
- ERROR_INVALID_ARGUMENT - if the argument has been disposed *
- ERROR_NULL_ARGUMENT - if the parent is
null
*
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
false
, causes subsequent drawing
* operations in the receiver to be ignored. No drawing of any kind
* can occur in the receiver until the flag is set to true.
* Graphics operations that occurred while the flag was
* false
are lost. When the flag is set to true
,
* the entire widget is marked as needing to be redrawn. Nested calls
* to this method are stacked.
* * Note: This operation is a hint and may not be supported on some * platforms or for some widgets. *
* * @param redraw the new redraw state * * @exception SWTException-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
-
*
- ERROR_INVALID_ARGUMENT - if the region has been disposed *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
* Note: Attempting to set the width or height of the * receiver to a negative number will cause that * value to be set to zero instead. *
** Note: On GTK, attempting to set the width or height of the * receiver to a number higher or equal 2^14 will cause them to be * set to (2^14)-1 instead. *
* * @param width the new width in points for the receiver * @param height the new height in points 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 *
* Note: Attempting to set the width or height of the * receiver to a negative number will cause them to be * set to zero instead. *
** Note: On GTK, attempting to set the width or height of the * receiver to a number higher or equal 2^14 will cause them to be * set to (2^14)-1 instead. *
* * @param size the new size in points for the receiver * * @exception IllegalArgumentException-
*
- ERROR_NULL_ARGUMENT - if the point is null *
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
SWT.LEFT_TO_RIGHT
,
* SWT.RIGHT_TO_LEFT
, or SWT.AUTO_TEXT_DIRECTION
.
*
* setOrientation
would override this value with the text direction
* that is consistent with the new orientation.
*
* Warning: This API is currently only implemented on Windows. * It doesn't set the base text direction on GTK and Cocoa. *
* * @param textDirection the base text direction 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 *
* 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 *
false
causes the receiver to send gesture events
* instead. No exception is thrown if a touch-based input device is not
* detected (this can be determined with Display#getTouchEnabled()
).
*
* @param enabled the new touch-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 Display#getTouchEnabled * * @since 3.7 */ public void setTouchEnabled(boolean enabled) { checkWidget(); eventView().setAcceptsTouchEvents(enabled); touchEnabled = enabled; } /** * Marks the receiver as visible if the argument is
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
- ERROR_NULL_ARGUMENT - if the point is null *
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
- ERROR_NULL_ARGUMENT - if the point is null *
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
- ERROR_NULL_ARGUMENT if the event is null *
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
- ERROR_NULL_ARGUMENT if the event is null *
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver *
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-
*
* NOTE: To properly map a rectangle or a corner of a rectangle on a right-to-left platform, use * {@link Display#map(Control, Control, Rectangle)}. *
* * @param x the x coordinate in points to be translated * @param y the y coordinate in points to be translated * @return the translated coordinates * * @exception SWTException-
*
* NOTE: To properly map a rectangle or a corner of a rectangle on a right-to-left platform, use * {@link Display#map(Control, Control, Rectangle)}. *
* * @param point the point to be translated (must not be null) * @return the translated coordinates * * @exception IllegalArgumentException-
*
-
*
* NOTE: To properly map a rectangle or a corner of a rectangle on a right-to-left platform, use * {@link Display#map(Control, Control, Rectangle)}. *
* * @param x the x coordinate to be translated * @param y the y coordinate to be translated * @return the translated coordinates * * @exception SWTException-
*
* NOTE: To properly map a rectangle or a corner of a rectangle on a right-to-left platform, use * {@link Display#map(Control, Control, Rectangle)}. *
* * @param point the point to be translated (must not be null) * @return the translated coordinates * * @exception IllegalArgumentException-
*
-
*
KeyDown
event.
*
* Valid traversal values are
* SWT.TRAVERSE_NONE
, SWT.TRAVERSE_MNEMONIC
,
* SWT.TRAVERSE_ESCAPE
, SWT.TRAVERSE_RETURN
,
* SWT.TRAVERSE_TAB_NEXT
, SWT.TRAVERSE_TAB_PREVIOUS
,
* SWT.TRAVERSE_ARROW_NEXT
, SWT.TRAVERSE_ARROW_PREVIOUS
,
* SWT.TRAVERSE_PAGE_NEXT
and SWT.TRAVERSE_PAGE_PREVIOUS
.
* If traversal
is SWT.TRAVERSE_NONE
then the Traverse
* event is created with standard values based on the KeyDown event. If
* traversal
is one of the other traversal constants then the Traverse
* event is created with this detail, and its doit
is taken from the
* KeyDown event.
*
SWT.TRAVERSE_NONE
to compute
* this from event
* @param event the KeyDown event
*
* @return true
if the traversal succeeded
*
* @exception IllegalArgumentException -
*
-
*
KeyDown
event.
*
* Valid traversal values are
* SWT.TRAVERSE_NONE
, SWT.TRAVERSE_MNEMONIC
,
* SWT.TRAVERSE_ESCAPE
, SWT.TRAVERSE_RETURN
,
* SWT.TRAVERSE_TAB_NEXT
, SWT.TRAVERSE_TAB_PREVIOUS
,
* SWT.TRAVERSE_ARROW_NEXT
, SWT.TRAVERSE_ARROW_PREVIOUS
,
* SWT.TRAVERSE_PAGE_NEXT
and SWT.TRAVERSE_PAGE_PREVIOUS
.
* If traversal
is SWT.TRAVERSE_NONE
then the Traverse
* event is created with standard values based on the KeyDown event. If
* traversal
is one of the other traversal constants then the Traverse
* event is created with this detail, and its doit
is taken from the
* KeyDown event.
*
SWT.TRAVERSE_NONE
to compute
* this from event
* @param event the KeyDown event
*
* @return true
if the traversal succeeded
*
* @exception IllegalArgumentException -
*
-
*
SWT.TRAVERSE_ESCAPE
, SWT.TRAVERSE_RETURN
,
* SWT.TRAVERSE_TAB_NEXT
, SWT.TRAVERSE_TAB_PREVIOUS
,
* SWT.TRAVERSE_ARROW_NEXT
, SWT.TRAVERSE_ARROW_PREVIOUS
,
* SWT.TRAVERSE_PAGE_NEXT
and SWT.TRAVERSE_PAGE_PREVIOUS
.
*
* @param traversal the type of traversal
* @return true if the traversal succeeded
*
* @exception SWTException -
*
* Note: This method does not cause a redraw. *
* * @exception SWTException-
*