blob: 1d1ebf5f0501722693356d884f3fc0088e057d96 [file] [log] [blame]
package org.eclipse.swt.widgets;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved
*/
import org.eclipse.swt.internal.photon.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.*;
/**
* Control is the abstract superclass of all windowed user interface classes.
* <p>
* <dl>
* <dt><b>Styles:</b>
* <dd>BORDER</dd>
* <dt><b>Events:</b>
* <dd>FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter,
* MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize</dd>
* </dl>
* <p>
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
* </p>
*/
public abstract class Control extends Widget implements Drawable {
Composite parent;
Menu menu;
Object layoutData;
String toolTipText;
int toolTipHandle;
Control () {
/* Do nothing */
}
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
* <p>
* The style value is either one of the style constants defined in
* class <code>SWT</code> which is applicable to instances of this
* class, or must be built by <em>bitwise OR</em>'ing together
* (that is, using the <code>int</code> "|" operator) two or more
* of those <code>SWT</code> style constants. The class description
* for all SWT widget classes should include a comment which
* describes the style constants which are applicable to the class.
* </p>
*
* @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 <ul>
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*
* @see SWT
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
public Control (Composite parent, int style) {
super (parent, style);
this.parent = parent;
createWidget (0);
}
/**
* 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 <code>ControlListener</code>
* interface.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @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 gains or loses focus, by sending
* it one of the messages defined in the <code>FocusListener</code>
* interface.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @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 the help events are generated for the control, by sending
* it one of the messages defined in the <code>HelpListener</code>
* interface.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @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 <code>KeyListener</code>
* interface.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @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 mouse buttons are pressed and released, by sending
* it one of the messages defined in the <code>MouseListener</code>
* interface.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @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 <code>MouseTrackListener</code>
* interface.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @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 <code>MouseMoveListener</code>
* interface.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @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 receiver needs to be painted, by sending it
* one of the messages defined in the <code>PaintListener</code>
* interface.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @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);
}
/**
* 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 <code>TraverseListener</code>
* interface.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @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);
}
/**
* Forces the receiver to have the <em>keyboard focus</em>, causing
* all keyboard events to be delivered to it.
*
* @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see #setFocus
*/
public boolean forceFocus () {
checkWidget();
int shellHandle = OS.PtFindDisjoint (handle);
OS.PtWindowToFront (shellHandle);
OS.PtContainerGiveFocus (handle, null);
return hasFocus ();
}
/**
* Returns the preferred size of the receiver.
* <p>
* The <em>prefered size</em> 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 <code>SWT.DEFAULT</code> is passed for the hint.
* </p>
*
* @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
* @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
* @return the preferred size of the control
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see Layout
*/
public Point computeSize (int wHint, int hHint) {
return computeSize (wHint, hHint, true);
}
/**
* Returns the preferred size of the receiver.
* <p>
* The <em>prefered size</em> 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 <code>SWT.DEFAULT</code> is passed for the hint.
* </p><p>
* If the changed flag is <code>true</code>, it indicates that the receiver's
* <em>contents</em> 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 <code>false</code>, so layout
* manager caches can be retained.
* </p>
*
* @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
* @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
* @param changed <code>true</code> if the control's contents have changed, and <code>false</code> otherwise
* @return the preferred size of the control.
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see Layout
*/
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);
}
void createWidget (int index) {
super.createWidget (index);
setZOrder ();
realizeWidget ();
}
byte [] defaultFont () {
Display display = getDisplay ();
return display.TEXT_FONT;
}
/**
* Returns the receiver's background color.
*
* @return the background color
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Color getBackground () {
checkWidget();
int [] args = {OS.Pt_ARG_FILL_COLOR, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return Color.photon_new (getDisplay (), args [1]);
}
/**
* Returns the font that the receiver will use to paint textual information.
*
* @return the receiver's font
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Font getFont () {
checkWidget();
int [] args = {
OS.Pt_ARG_TEXT_FONT, 0, 0,
OS.Pt_ARG_LIST_FONT, 0, 0,
OS.Pt_ARG_TITLE_FONT, 0, 0,
};
OS.PtGetResources (handle, args.length / 3, args);
byte [] font;
int ptr = args [1];
if (ptr == 0) ptr = args [4];
if (ptr == 0) ptr = args [7];
if (ptr == 0) {
font = defaultFont ();
} else {
int length = OS.strlen (ptr);
font = new byte [length + 1];
OS.memmove (font, ptr, length);
}
return Font.photon_new (getDisplay (), font);
}
/**
* Returns the foreground color that the receiver will use to draw.
*
* @return the receiver's foreground color
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Color getForeground () {
checkWidget();
int [] args = {OS.Pt_ARG_COLOR, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return Color.photon_new (getDisplay (), args [1]);
}
/**
* Returns the receiver's border width.
*
* @return the border width
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public int getBorderWidth () {
checkWidget();
int topHandle = topHandle ();
int [] args = {
OS.Pt_ARG_BASIC_FLAGS, 0, 0,
OS.Pt_ARG_FLAGS, 0, 0,
// OS.Pt_ARG_BEVEL_WIDTH, 0, 0,
};
OS.PtGetResources (topHandle, args.length / 3, args);
if ((args [4] & OS.Pt_HIGHLIGHTED) == 0) return 0;
int border = 0;
int flags = args [1];
if ((flags & OS.Pt_ALL_ETCHES) != 0) border++;
if ((flags & OS.Pt_ALL_OUTLINES) != 0) border++;
if ((flags & OS.Pt_ALL_INLINES) != 0) border++;
// if ((flags & OS.Pt_ALL_BEVELS) != 0) border += args [7];
return border;
}
/**
* 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 <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Rectangle getBounds () {
checkWidget();
int topHandle = topHandle ();
PhArea_t area = new PhArea_t ();
OS.PtWidgetArea (topHandle, area);
return new Rectangle (area.pos_x, area.pos_y, area.size_w, area.size_h);
}
/**
* Returns the display that the receiver was created on.
*
* @return the receiver's display
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Display getDisplay () {
Composite parent = this.parent;
if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
return parent.getDisplay ();
}
/**
* Returns <code>true</code> if the receiver is enabled, and
* <code>false</code> 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 <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public boolean getEnabled () {
checkWidget();
int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return (args [1] & OS.Pt_BLOCKED) == 0;
}
/**
* Returns layout data which is associated with the receiver.
*
* @return the receiver's layout data
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Object getLayoutData () {
checkWidget();
return layoutData;
}
/**
* Returns a point describing the receiver's location relative
* to its parent (or its display if its parent is null).
*
* @return the receiver's location
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Point getLocation () {
checkWidget();
int topHandle = topHandle ();
PhArea_t area = new PhArea_t ();
OS.PtWidgetArea (topHandle, area);
return new Point (area.pos_x, area.pos_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 <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Menu getMenu () {
checkWidget();
return null;
}
/**
* Returns the receiver's parent, which must be a <code>Composite</code>
* 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 <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Composite getParent () {
checkWidget();
return parent;
}
Control [] getPath () {
int count = 0;
Shell shell = getShell ();
Control control = this;
while (control != shell) {
count++;
control = control.parent;
}
control = this;
Control [] result = new Control [count];
while (control != shell) {
result [--count] = control;
control = control.parent;
}
return result;
}
/**
* Returns 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 <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Point getSize () {
checkWidget();
int topHandle = topHandle ();
PhArea_t area = new PhArea_t ();
OS.PtWidgetArea (topHandle, area);
return new Point (area.size_w, area.size_h);
}
/**
* Returns the receiver's tool tip text, or null if it has
* not been set.
*
* @return the receiver's tool tip text
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public String getToolTipText () {
checkWidget();
return toolTipText;
}
/**
* 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 <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see #getParent
*/
public Shell getShell () {
checkWidget();
return parent.getShell ();
}
/**
* Returns <code>true</code> if the receiver is visible, and
* <code>false</code> otherwise.
* <p>
* 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.
* </p>
*
* @return the receiver's visibility state
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public boolean getVisible () {
checkWidget();
int topHandle = topHandle ();
int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
OS.PtGetResources (topHandle, args.length / 3, args);
return (args [1] & OS.Pt_DELAY_REALIZE) == 0;
}
boolean hasFocus () {
return OS.PtIsFocused (handle) != 0;
}
void hookEvents () {
int windowProc = getDisplay ().windowProc;
int focusHandle = focusHandle ();
OS.PtAddFilterCallback (handle, OS.Ph_EV_KEY, windowProc, SWT.KeyDown);
OS.PtAddEventHandler (handle, OS.Ph_EV_BUT_PRESS, windowProc, SWT.MouseDown);
OS.PtAddEventHandler (handle, OS.Ph_EV_BUT_RELEASE, windowProc, SWT.MouseUp);
OS.PtAddEventHandler (handle, OS.Ph_EV_PTR_MOTION, windowProc, SWT.MouseMove);
OS.PtAddEventHandler (handle, OS.Ph_EV_BOUNDARY, windowProc, SWT.MouseEnter);
OS.PtAddCallback (focusHandle, OS.Pt_CB_GOT_FOCUS, windowProc, SWT.FocusIn);
OS.PtAddCallback (focusHandle, OS.Pt_CB_LOST_FOCUS, windowProc, SWT.FocusOut);
OS.PtAddCallback (handle, OS.Pt_CB_MENU, windowProc, SWT.Show);
}
int focusHandle () {
return handle;
}
/**
* Invokes platform specific functionality to allocate a new GC handle.
* <p>
* <b>IMPORTANT:</b> This method is <em>not</em> part of the public
* API for <code>Control</code>. 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.
* </p>
*
* @param data the platform specific GC data
* @return the platform specific GC handle
*
* @private
*/
public int internal_new_GC (GCData data) {
checkWidget();
int phGC = OS.PgCreateGC(0); // NOTE: PgCreateGC ignores the parameter
if (phGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
int [] args = {OS.Pt_ARG_COLOR, 0, 0, OS.Pt_ARG_FILL_COLOR, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
data.device = getDisplay ();
data.widget = handle;
data.topWidget = topHandle ();
data.foreground = args [1];
data.background = args [4];
data.font = getFont ().handle;
return phGC;
}
/**
* Invokes platform specific functionality to dispose a GC handle.
* <p>
* <b>IMPORTANT:</b> This method is <em>not</em> part of the public
* API for <code>Control</code>. 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.
* </p>
*
* @param handle the platform specific GC handle
* @param data the platform specific GC data
*
* @private
*/
public void internal_dispose_GC (int phGC, GCData data) {
checkWidget ();
OS.PgDestroyGC(phGC);
}
/**
* Returns <code>true</code> if the receiver is enabled, and
* <code>false</code> 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 <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public boolean isEnabled () {
checkWidget();
return getEnabled () && parent.isEnabled ();
}
public boolean isFocusAncestor () {
Display display = getDisplay ();
Control control = display.getFocusControl ();
while (control != null && control != this) {
control = control.parent;
}
return control == this;
}
/**
* Returns <code>true</code> if the receiver has the user-interface
* focus, and <code>false</code> otherwise.
*
* @return the receiver's focus state
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public boolean isFocusControl () {
checkWidget();
return hasFocus ();
}
/**
* Returns <code>true</code> if the underlying operating
* system supports this reparenting, otherwise <code>false</code>
*
* @return <code>true</code> if the widget can be reparented, otherwise <code>false</code>
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public boolean isReparentable () {
checkWidget();
return false;
}
/**
* Returns <code>true</code> if the receiver is visible, and
* <code>false</code> otherwise.
* <p>
* 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.
* </p>
*
* @return the receiver's visibility state
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public boolean isVisible () {
checkWidget();
return OS.PtWidgetIsRealized (handle);
}
Decorations menuShell () {
return parent.menuShell ();
}
/**
* Moves the receiver above the specified control in the
* drawing order. If the argument is null, then the receiver
* is moved to the top of the drawing order. The control at
* the top of the drawing order will not be covered by other
* controls even if they occupy intersecting areas.
*
* @param the sibling control (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void moveAbove (Control control) {
checkWidget();
int topHandle1 = topHandle ();
if (control == null) {
OS.PtWidgetToFront (topHandle1);
OS.PtWindowToFront (topHandle1);
return;
}
if (control.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
int topHandle2 = control.topHandle ();
OS.PtWidgetInsert (topHandle1, topHandle2, 0);
}
/**
* Moves the receiver below the specified control in the
* drawing order. If the argument is null, then the receiver
* is moved to the bottom of the drawing order. The control at
* the bottom of the drawing order will be covered by all other
* controls which occupy intersecting areas.
*
* @param the sibling control (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void moveBelow (Control control) {
checkWidget();
int topHandle1 = topHandle ();
if (control == null) {
OS.PtWidgetToBack (topHandle1);
OS.PtWindowToBack (topHandle1);
return;
}
if (control.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
int topHandle2 = control.topHandle ();
OS.PtWidgetInsert (topHandle1, topHandle2, 1);
}
/**
* 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 <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see #computeSize
*/
public void pack () {
checkWidget();
pack (true);
}
/**
* Causes the receiver to be resized to its preferred size.
* For a composite, this involves computing the preferred size
* from its layout, if there is one.
* <p>
* If the changed flag is <code>true</code>, it indicates that the receiver's
* <em>contents</em> 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 <code>false</code>, so layout
* manager caches can be retained.
* </p>
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see #computeSize
*/
public void pack (boolean changed) {
checkWidget();
setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
}
int processPaint (int damage) {
sendPaintEvent (damage);
return OS.Pt_CONTINUE;
}
int processFocusIn (int info) {
sendEvent (SWT.FocusIn);
if (isDisposed ()) return OS.Pt_CONTINUE;
int index = 0;
Shell shell = getShell ();
Control [] focusIn = getPath ();
Control lastFocus = shell.lastFocus;
if (lastFocus != null) {
if (!lastFocus.isDisposed ()) {
Control [] focusOut = lastFocus.getPath ();
int length = Math.min (focusIn.length, focusOut.length);
while (index < length) {
if (focusIn [index] != focusOut [index]) break;
index++;
}
for (int i=focusOut.length-1; i>=index; --i) {
focusOut [i].sendEvent (SWT.Deactivate);
}
}
shell.lastFocus = null;
}
for (int i=focusIn.length-1; i>=index; --i) {
focusIn [i].sendEvent (SWT.Activate);
}
/*
* Feature in Photon. Cannot return Pt_END
* or the text widget will not take focus.
*/
return OS.Pt_CONTINUE;
}
int processFocusOut (int info) {
sendEvent (SWT.FocusOut);
if (isDisposed ()) return OS.Pt_CONTINUE;
Shell shell = getShell ();
shell.lastFocus = this;
Display display = getDisplay ();
Control focusControl = display.getFocusControl ();
if (focusControl == null || shell != focusControl.getShell ()) {
Control [] focusOut = getPath ();
for (int i=focusOut.length-1; i>=0; --i) {
focusOut [i].sendEvent (SWT.Deactivate);
}
shell.lastFocus = null;
}
/*
* Feature in Photon. Cannot return Pt_END
* or the text widget will not take focus.
*/
return OS.Pt_CONTINUE;
}
int processKey (int info) {
if (!hasFocus ()) return OS.Pt_PROCESS;
if (info == 0) return OS.Pt_PROCESS;
PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
if (cbinfo.event == 0) return OS.Pt_PROCESS;
PhEvent_t ev = new PhEvent_t ();
OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
if ((ev.processing_flags & OS.Ph_FAKE_EVENT) != 0) {
return OS.Pt_PROCESS;
}
int data = OS.PhGetData (cbinfo.event);
if (data == 0) return OS.Pt_PROCESS;
PhKeyEvent_t ke = new PhKeyEvent_t ();
OS.memmove (ke, data, PhKeyEvent_t.sizeof);
/*
* Feature in Photon. When the user presses certain keys
* (such as the arrow keys), Photon sends 2 event for one
* key press. The first event has only the scan code while
* the second has the keysym and other information. This
* also happens for key release. The fix is to ignore the
* first event.
*/
if (ke.key_flags == OS.Pk_KF_Scan_Valid) {
return OS.Pt_PROCESS;
}
if ((ke.key_flags & OS.Pk_KF_Key_Repeat) != 0) {
if ((ke.key_flags & OS.Pk_KF_Sym_Valid) != 0) {
switch (ke.key_sym) {
case OS.Pk_Alt_L:
case OS.Pk_Alt_R:
case OS.Pk_Control_L:
case OS.Pk_Control_R:
case OS.Pk_Shift_L:
case OS.Pk_Shift_R:
return OS.Pt_PROCESS;
}
}
}
/* Determine if this is a traverse event */
if ((ke.key_flags & (OS.Pk_KF_Key_Down | OS.Pk_KF_Key_Repeat)) != 0) {
/*
* Fetuare in Photon. The key_sym value is not valid when Ctrl
* or Alt is pressed. The fix is to detect this case and try to
* use the key_cap value.
*/
int key = ke.key_sym;
if ((ke.key_flags & OS.Pk_KF_Sym_Valid) == 0) {
key = 0;
if ((ke.key_flags & OS.Pk_KF_Cap_Valid) != 0) {
if (ke.key_cap == OS.Pk_Tab && (ke.key_mods & OS.Pk_KM_Ctrl) != 0) {
key = OS.Pk_Tab;
}
}
}
switch (key) {
case OS.Pk_Escape:
case OS.Pk_Return:
case OS.Pk_KP_Tab:
case OS.Pk_Tab:
case OS.Pk_Up:
case OS.Pk_Down:
case OS.Pk_Left:
case OS.Pk_Right: {
if (key != OS.Pk_Return) {
ev.processing_flags |= OS.Ph_NOT_CUAKEY;
OS.memmove (cbinfo.event, ev, PhEvent_t.sizeof);
}
if (translateTraversal (key, ke)) {
ev.processing_flags |= OS.Ph_CONSUMED;
OS.memmove (cbinfo.event, ev, PhEvent_t.sizeof);
return OS.Pt_PROCESS;
}
}
}
}
Display display = getDisplay ();
Event event = new Event ();
event.time = ev.timestamp;
int type = SWT.KeyUp;
if ((ke.key_flags & (OS.Pk_KF_Key_Down | OS.Pk_KF_Key_Repeat)) != 0) {
type = SWT.KeyDown;
}
if ((ke.key_flags & OS.Pk_KF_Sym_Valid) != 0) {
event.keyCode = Display.translateKey (ke.key_sym);
if (event.keyCode == 0) {
switch (ke.key_sym) {
case OS.Pk_BackSpace: event.character = '\b'; break;
case OS.Pk_Tab: event.character = '\t'; break;
case OS.Pk_Linefeed: event.character = '\n'; break;
case OS.Pk_Clear: event.character = 0xB; break;
case OS.Pk_Return: event.character = '\r'; break;
case OS.Pk_Pause: event.character = 0x13; break;
case OS.Pk_Scroll_Lock: event.character = 0x14; break;
case OS.Pk_Escape: event.character = 0x1B; break;
case OS.Pk_Delete: event.character = 0x7F; break;
default:
event.character = (char) ke.key_sym;
}
}
display.lastKey = event.keyCode;
display.lastAscii = event.character;
}
setKeyState(event, ke);
if (type == SWT.KeyUp) {
if (event.keyCode == 0) event.keyCode = display.lastKey;
if (event.character == 0) event.character = (char) display.lastAscii;
}
postEvent (type, event);
return OS.Pt_PROCESS;
}
int processMouse (int info) {
if (info == 0) return OS.Pt_END;
PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
if (cbinfo.event == 0) return OS.Pt_END;
PhEvent_t ev = new PhEvent_t ();
OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
if ((ev.processing_flags & OS.Ph_FAKE_EVENT) != 0) {
return OS.Pt_CONTINUE;
}
Event event = new Event ();
switch (ev.type) {
case OS.Ph_EV_BUT_PRESS:
event.type = SWT.MouseDown;
break;
case OS.Ph_EV_BUT_RELEASE:
if (ev.subtype != OS.Ph_EV_RELEASE_PHANTOM) {
return OS.Pt_END;
}
event.type = SWT.MouseUp;
break;
case OS.Ph_EV_PTR_MOTION_BUTTON:
case OS.Ph_EV_PTR_MOTION_NOBUTTON:
event.type = SWT.MouseMove;
break;
case OS.Ph_EV_DRAG:
if (ev.subtype != OS.Ph_EV_DRAG_MOTION_EVENT) {
return OS.Pt_END;
}
event.type = SWT.MouseMove;
break;
}
event.time = ev.timestamp;
int data = OS.PhGetData (cbinfo.event);
if (data == 0) return OS.Pt_END;
PhPointerEvent_t pe = new PhPointerEvent_t ();
OS.memmove (pe, data, PhPointerEvent_t.sizeof);
event.x = pe.pos_x + ev.translation_x;
event.y = pe.pos_y + ev.translation_y;
if (ev.type == OS.Ph_EV_BUT_PRESS || ev.type == OS.Ph_EV_BUT_RELEASE) {
switch (pe.buttons) {
case OS.Ph_BUTTON_SELECT: event.button = 1; break;
case OS.Ph_BUTTON_ADJUST: event.button = 2; break;
case OS.Ph_BUTTON_MENU: event.button = 3; break;
}
}
setMouseState (ev.type, event, pe);
postEvent (event.type, event);
if (ev.type == OS.Ph_EV_BUT_PRESS && pe.click_count == 2) {
Event clickEvent = new Event ();
clickEvent.time = event.time;
clickEvent.x = event.x;
clickEvent.y = event.y;
clickEvent.button = event.button;
clickEvent.stateMask = event.stateMask;
postEvent (SWT.MouseDoubleClick, clickEvent);
}
ev.processing_flags |= OS.Ph_CONSUMED;
OS.memmove (cbinfo.event, ev, PhEvent_t.sizeof);
return OS.Pt_CONTINUE;
}
int processMouseEnter (int info) {
if (info == 0) return OS.Pt_END;
PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
if (cbinfo.event == 0) return OS.Pt_END;
PhEvent_t ev = new PhEvent_t ();
OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
int rects = OS.PhGetRects (cbinfo.event);
PhRect_t rect = new PhRect_t ();
OS.memmove (rect, rects, PhRect_t.sizeof);
Event event = new Event ();
event.time = ev.timestamp;
event.x = rect.ul_x;
event.y = rect.ul_y;
switch (ev.subtype) {
case OS.Ph_EV_PTR_ENTER:
case OS.Ph_EV_PTR_ENTER_FROM_CHILD:
sendEvent (SWT.MouseEnter, event);
break;
case OS.Ph_EV_PTR_LEAVE:
case OS.Ph_EV_PTR_LEAVE_TO_CHILD:
sendEvent (SWT.MouseExit, event);
break;
case OS.Ph_EV_PTR_STEADY:
postEvent (SWT.MouseHover, event);
destroyToolTip (toolTipHandle);
toolTipHandle = createToolTip (toolTipText, handle, getFont ().handle);
break;
case OS.Ph_EV_PTR_UNSTEADY:
destroyToolTip (toolTipHandle);
toolTipHandle = 0;
break;
}
return OS.Pt_END;
}
int processShow (int info) {
if (info == 0) return OS.Pt_END;
PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
if (cbinfo.reason == OS.Pt_CB_MENU) {
if (menu != null && !menu.isDisposed ()) {
menu.setVisible (true);
}
}
return OS.Pt_CONTINUE;
}
void realizeWidget() {
int parentHandle = parent.handle;
if (OS.PtWidgetIsRealized (parentHandle)) {
OS.PtRealizeWidget (topHandle ());
}
}
void releaseWidget () {
super.releaseWidget ();
if (toolTipHandle != 0) destroyToolTip (toolTipHandle);
toolTipHandle = 0;
if (menu != null && !menu.isDisposed ()) {
menu.dispose ();
}
menu = null;
parent = null;
layoutData = null;
}
/**
* 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.
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see #update
*/
public void redraw () {
checkWidget();
OS.PtDamageWidget (handle);
}
/**
* Causes the rectangular area of the receiver specified by
* the arguments to be marked as needing to be redrawn.
* The next time a paint request is processed, that area of
* the receiver will be painted. If the <code>all</code> flag
* is <code>true</code>, any children of the receiver which
* intersect with the specified area will also paint their
* intersecting areas. If the <code>all</code> flag is
* <code>false</code>, 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 <code>true</code> if children should redraw, and <code>false</code> otherwise
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see #update
*/
public void redraw (int x, int y, int width, int height, boolean allChildren) {
checkWidget ();
if (width <= 0 || height <= 0) return;
PhRect_t rect = new PhRect_t ();
rect.ul_x = (short) x;
rect.ul_y = (short) y;
rect.lr_x = (short) (x + width - 1);
rect.lr_y = (short) (y + height - 1);
OS.PtDamageExtent (handle, rect);
}
/**
* 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 be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @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 gains or loses focus.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see FocusListener
* @see #addFocusListener
*/
public void removeFocusListener(FocusListener listener) {
checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.FocusIn, listener);
eventTable.unhook (SWT.FocusOut, listener);
}
/**
* Removes the listener from the collection of listeners who will
* be notified when the help events are generated for the control.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see HelpListener
* @see #addHelpListener
*/
public void removeHelpListener (HelpListener listener) {
checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Help, listener);
}
/**
* Removes the listener from the collection of listeners who will
* be notified when keys are pressed and released on the system keyboard.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see KeyListener
* @see #addKeyListener
*/
public void removeKeyListener(KeyListener listener) {
checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.KeyUp, listener);
eventTable.unhook (SWT.KeyDown, listener);
}
/**
* Removes the listener from the collection of listeners who will
* be notified when the mouse passes or hovers over controls.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see MouseTrackListener
* @see #addMouseTrackListener
*/
public void removeMouseTrackListener(MouseTrackListener listener) {
checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.MouseEnter, listener);
eventTable.unhook (SWT.MouseExit, listener);
eventTable.unhook (SWT.MouseHover, listener);
}
/**
* Removes the listener from the collection of listeners who will
* be notified when mouse buttons are pressed and released.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see MouseListener
* @see #addMouseListener
*/
public void removeMouseListener (MouseListener listener) {
checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.MouseDown, listener);
eventTable.unhook (SWT.MouseUp, listener);
eventTable.unhook (SWT.MouseDoubleClick, listener);
}
/**
* Removes the listener from the collection of listeners who will
* be notified when the mouse moves.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see MouseMoveListener
* @see #addMouseMoveListener
*/
public void removeMouseMoveListener(MouseMoveListener listener) {
checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.MouseMove, listener);
}
/**
* Removes the listener from the collection of listeners who will
* be notified when the receiver needs to be painted.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see PaintListener
* @see #addPaintListener
*/
public void removePaintListener(PaintListener listener) {
checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook(SWT.Paint, listener);
}
/**
* Removes the listener from the collection of listeners who will
* be notified when traversal events occur.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see TraverseListener
* @see #addTraverseListener
*/
public void removeTraverseListener(TraverseListener listener) {
checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Traverse, listener);
}
void setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
int topHandle = topHandle ();
PhArea_t area = new PhArea_t ();
OS.PtWidgetArea (topHandle, area);
boolean sameOrigin = x == area.pos_x && y == area.pos_y;
boolean sameExtent = width == area.size_w && height == area.size_h;
if (move && resize) {
area.pos_x = (short) x;
area.pos_y = (short) y;
area.size_w = (short) (Math.max (width, 0));
area.size_h = (short) (Math.max (height, 0));
int ptr = OS.malloc (PhArea_t.sizeof);
OS.memmove (ptr, area, PhArea_t.sizeof);
int [] args = {OS.Pt_ARG_AREA, ptr, 0};
OS.PtSetResources (topHandle, args.length / 3, args);
OS.free (ptr);
} else {
if (move) {
PhPoint_t pt = new PhPoint_t ();
pt.x = (short) x;
pt.y = (short) y;
int ptr = OS.malloc (PhPoint_t.sizeof);
OS.memmove (ptr, pt, PhPoint_t.sizeof);
int [] args = {OS.Pt_ARG_POS, ptr, 0};
OS.PtSetResources (topHandle, args.length / 3, args);
OS.free (ptr);
}
if (resize) {
int [] args = {
OS.Pt_ARG_WIDTH, Math.max (width, 0), 0,
OS.Pt_ARG_HEIGHT, Math.max (height, 0), 0,
};
OS.PtSetResources (topHandle, args.length / 3, args);
}
}
if (!OS.PtWidgetIsRealized (topHandle)) {
OS.PtExtentWidgetFamily (topHandle);
}
if (!sameOrigin & move) sendEvent (SWT.Move);
if (!sameExtent & resize & sendResize()) sendEvent (SWT.Resize);
}
/**
* Sets the receiver's size and location to the rectangular
* area specified by the arguments. The <code>x</code> and
* <code>y</code> arguments are relative to the receiver's
* parent (or its display if its parent is null).
* <p>
* 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.
* </p>
*
* @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 <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setBounds (int x, int y, int width, int height) {
checkWidget();
setBounds (x, y, width, height, true, true);
}
/**
* Sets the receiver's size and location to the rectangular
* area specified by the argument. The <code>x</code> and
* <code>y</code> fields of the rectangle are relative to
* the receiver's parent (or its display if its parent is null).
* <p>
* 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.
* </p>
*
* @param rect the new bounds for the receiver
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setBounds (Rectangle rect) {
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
setBounds (rect.x, rect.y, rect.width, rect.height);
}
/**
* If the argument is <code>true</code>, causes the receiver to have
* all mouse events delivered to it until the method is called with
* <code>false</code> as the argument.
*
* @param capture <code>true</code> to capture the mouse, and <code>false</code> to release it
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setCapture (boolean capture) {
checkWidget();
}
/**
* Sets the receiver's cursor to the cursor specified by the
* argument, or to the default cursor for that kind of control
* if the argument is null.
* <p>
* When the mouse pointer passes over a control its appearance
* is changed to match the control's cursor.
* </p>
*
* @param cursor the new cursor (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setCursor (Cursor cursor) {
checkWidget();
int type = OS.Ph_CURSOR_INHERIT;
int bitmap = 0;
if (cursor != null) {
if (cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
type = cursor.type;
bitmap = cursor.bitmap;
}
int [] args = new int []{
OS.Pt_ARG_CURSOR_TYPE, type, 0,
OS.Pt_ARG_BITMAP_CURSOR, bitmap, 0,
};
OS.PtSetResources (handle, args.length / 3, args);
/*
* Bug in Photon. For some reason, the widget cursor will
* not change, when the new cursor is a bitmap cursor, if
* the flag Ph_CURSOR_NO_INHERIT is reset. The fix is to reset
* this flag after changing the cursor type to Ph_CURSOR_BITMAP.
*/
if (type == OS.Ph_CURSOR_BITMAP) {
type &= ~OS.Ph_CURSOR_NO_INHERIT;
args = new int []{OS.Pt_ARG_CURSOR_TYPE, type, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
}
/**
* Enables the receiver if the argument is <code>true</code>,
* 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 <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setEnabled (boolean enabled) {
checkWidget();
int [] args = {
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_BLOCKED, OS.Pt_BLOCKED,
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_GHOST, OS.Pt_GHOST,
};
OS.PtSetResources (handle, args.length / 3, args);
}
/**
* Causes the receiver to have the <em>keyboard focus</em>,
* such that all keyboard events will be delivered to it.
*
* @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see #forceFocus
*/
public boolean setFocus () {
checkWidget();
return forceFocus ();
}
void sendPaintEvent (int damage) {
if (!hooks(SWT.Paint)) return;
/* Translate the damage to widget coordinates */
short [] widgetX = new short [1];
short [] widgetY = new short [1];
OS.PtGetAbsPosition (handle, widgetX, widgetY);
short [] shellX = new short [1];
short [] shellY = new short [1];
int shellHandle = OS.PtFindDisjoint (handle);
OS.PtGetAbsPosition (shellHandle, shellX, shellY);
PhPoint_t pt = new PhPoint_t ();
pt.x = (short) (shellX [0] - widgetX [0]);
pt.y = (short) (shellY [0] - widgetY [0]);
damage = OS.PhCopyTiles (damage);
damage = OS.PhTranslateTiles (damage, pt);
/* Send the paint event */
PhTile_t tile = new PhTile_t ();
OS.memmove (tile, damage, PhTile_t.sizeof);
if (tile.rect_ul_x != tile.rect_lr_x || tile.rect_ul_y != tile.rect_lr_y) {
Event event = new Event ();
event.x = tile.rect_ul_x;
event.y = tile.rect_ul_y;
event.width = tile.rect_lr_x - tile.rect_ul_x + 1;
event.height = tile.rect_lr_y - tile.rect_ul_y + 1;
Region region = Region.photon_new (tile.next);
GC gc = event.gc = new GC (this);
gc.setClipping (region);
sendEvent (SWT.Paint, event);
gc.dispose ();
event.gc = null;
}
OS.PhFreeTiles (damage);
}
boolean sendResize () {
return true;
}
/**
* Sets the receiver's background color to the color specified
* by the argument, or to the default system color for the control
* if the argument is null.
*
* @param color the new color (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setBackground (Color color) {
checkWidget();
int pixel = OS.Pt_DEFAULT_COLOR;
if (color != null) {
if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
pixel = color.handle;
}
int [] args = {OS.Pt_ARG_FILL_COLOR, pixel, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
/**
* Sets the font that the receiver will use to paint textual information
* to the font specified by the argument, or to the default font for that
* kind of control if the argument is null.
*
* @param font the new font (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setFont (Font font) {
checkWidget();
byte[] buffer;
if (font != null) {
if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
buffer = font.handle;
} else {
buffer = defaultFont();
}
int ptr = OS.malloc (buffer.length);
OS.memmove (ptr, buffer, buffer.length);
int [] args = {
OS.Pt_ARG_TEXT_FONT, ptr, 0,
OS.Pt_ARG_LIST_FONT, ptr, 0,
OS.Pt_ARG_TITLE_FONT, ptr, 0,
};
OS.PtSetResources (handle, args.length / 3, args);
OS.free (ptr);
}
/**
* Sets the receiver's foreground color to the color specified
* by the argument, or to the default system color for the control
* if the argument is null.
*
* @param color the new color (or null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setForeground (Color color) {
checkWidget();
int pixel = OS.Pt_DEFAULT_COLOR;
if (color != null) {
if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
pixel = color.handle;
}
int [] args = {OS.Pt_ARG_COLOR, pixel, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
/**
* Sets the layout data associated with the receiver to the argument.
*
* @param layoutData the new layout data for the receiver.
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setLayoutData (Object layoutData) {
checkWidget();
this.layoutData = layoutData;
}
/**
* Sets the receiver's location to the point specified by
* the arguments which are relative to the receiver's
* parent (or its display if its parent is null).
*
* @param x the new x coordinate for the receiver
* @param y the new y coordinate for the receiver
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setLocation (int x, int y) {
checkWidget();
setBounds (x, y, 0, 0, true, false);
}
/**
* Sets the receiver's location to the point specified by
* the argument which is relative to the receiver's
* parent (or its display if its parent is null).
*
* @param location the new location for the receiver
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setLocation (Point location) {
checkWidget();
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
setLocation (location.x, location.y);
}
/**
* Sets the receiver's pop up menu to the argument.
* All controls may optionally have a pop up
* menu that is displayed when the user requests one for
* the control. The sequence of key strokes, button presses
* and/or button releases that are used to request a pop up
* menu is platform specific.
*
* @param menu the new pop up menu
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
* <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
* <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setMenu (Menu menu) {
checkWidget();
int flags = 0;
if (menu != null) {
if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
flags = OS.Pt_MENUABLE;
}
int [] args = {
OS.Pt_ARG_FLAGS, flags, OS.Pt_ALL_BUTTONS | OS.Pt_MENUABLE,
};
OS.PtSetResources (handle, args.length / 3, args);
this.menu = menu;
}
/**
* Changes the parent of the widget to be the one provided if
* the underlying operating system supports this feature.
* Answers <code>true</code> if the parent is successfully changed.
*
* @param parent the new parent for the control.
* @return <code>true</code> if the parent is changed and <code>false</code> otherwise.
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
* </ul>
* @exception SWTError <ul>
* <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
* <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
* </ul>
*/
public boolean setParent (Composite parent) {
checkWidget();
if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
return false;
}
/**
* Sets the receiver's size to the point specified by the argument.
* <p>
* Note: Attempting to set the width or height of the
* receiver to a negative number will cause them to be
* set to zero instead.
* </p>
*
* @param size the new size for the receiver
* @param height the new height for the receiver
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the point is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setSize (Point size) {
checkWidget();
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
setSize (size.x, size.y);
}
/**
* If the argument is <code>false</code>, 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
* <code>false</code> are lost. When the flag is set to <code>true</code>,
* the entire widget is marked as needing to be redrawn.
* <p>
* Note: This operation is a hint and may not be supported on some
* platforms or for some widgets.
* </p>
*
* @param redraw the new redraw state
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see #redraw
* @see #update
*/
public void setRedraw (boolean redraw) {
checkWidget();
if (redraw) {
OS.PtContainerRelease (handle);
} else {
OS.PtContainerHold (handle);
}
}
/**
* Sets the receiver's size to the point specified by the arguments.
* <p>
* 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.
* </p>
*
* @param width the new width for the receiver
* @param height the new height for the receiver
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setSize (int width, int height) {
checkWidget();
setBounds (0, 0, width, height, false, true);
}
/**
* Marks the receiver as visible if the argument is <code>true</code>,
* and marks it invisible otherwise.
* <p>
* 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.
* </p>
*
* @param visible the new visibility state
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setVisible (boolean visible) {
checkWidget();
int topHandle = topHandle ();
int [] args = {
OS.Pt_ARG_FLAGS, visible ? 0 : OS.Pt_DELAY_REALIZE, OS.Pt_DELAY_REALIZE,
};
OS.PtSetResources (topHandle, args.length / 3, args);
if (visible) {
sendEvent (SWT.Show);
OS.PtRealizeWidget (topHandle);
} else {
OS.PtUnrealizeWidget (topHandle);
sendEvent(SWT.Hide);
}
}
/**
* Sets the receiver's tool tip text to the argument, which
* may be null indicating that no tool tip text should be shown.
*
* @param string the new tool tip text (or null)
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setToolTipText (String string) {
checkWidget();
toolTipText = string;
}
void setZOrder() {
OS.PtWidgetToBack (topHandle ());
}
void sort (int [] items) {
/* Shell Sort from K&R, pg 108 */
int length = items.length;
for (int gap=length/2; gap>0; gap/=2) {
for (int i=gap; i<length; i++) {
for (int j=i-gap; j>=0; j-=gap) {
if (items [j] <= items [j + gap]) {
int swap = items [j];
items [j] = items [j + gap];
items [j + gap] = swap;
}
}
}
}
}
/**
* Returns a point which is the result of converting the
* argument, which is specified in display relative coordinates,
* to coordinates relative to the receiver.
* <p>
* @param point the point to be translated (must not be null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the point is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Point toControl (Point point) {
checkWidget();
short [] x = new short [1], y = new short [1];
OS.PtGetAbsPosition (handle, x, y);
return new Point (point.x - x [0], point.y - y [0]);
}
/**
* Returns a point which is the result of converting the
* argument, which is specified in coordinates relative to
* the receiver, to display relative coordinates.
* <p>
* @param point the point to be translated (must not be null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the point is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public Point toDisplay (Point point) {
checkWidget();
short [] x = new short [1], y = new short [1];
OS.PtGetAbsPosition (handle, x, y);
return new Point (point.x + x [0], point.y + y [0]);
}
boolean translateTraversal (int key_sym, PhKeyEvent_t phEvent) {
int detail = 0;
boolean shift = (phEvent.key_mods & OS.Pk_KM_Shift) != 0;
boolean control = (phEvent.key_mods & OS.Pk_KM_Ctrl) != 0;
switch (key_sym) {
case OS.Pk_Escape:
Shell shell = getShell ();
if (shell.parent == null) return false;
if (!shell.isVisible () || !shell.isEnabled ()) return false;
detail = SWT.TRAVERSE_ESCAPE;
break;
case OS.Pk_Return:
Button button = menuShell ().getDefaultButton ();
if (button == null || button.isDisposed ()) return false;
if (!button.isVisible () || !button.isEnabled ()) return false;
detail = SWT.TRAVERSE_RETURN;
break;
case OS.Pk_Tab:
case OS.Pk_KP_Tab:
detail = SWT.TRAVERSE_TAB_NEXT;
if (shift) detail = SWT.TRAVERSE_TAB_PREVIOUS;
break;
case OS.Pk_Up:
case OS.Pk_Left:
detail = SWT.TRAVERSE_ARROW_PREVIOUS;
break;
case OS.Pk_Down:
case OS.Pk_Right:
detail = SWT.TRAVERSE_ARROW_NEXT;
break;
default:
return false;
}
boolean doit = (detail & traversalCode (key_sym, phEvent)) != 0;
if (!doit && control && (key_sym == OS.Pk_Tab || key_sym == OS.Pk_Tab)) {
doit = true;
control = false;
}
if (hooks (SWT.Traverse)) {
Event event = new Event();
event.doit = doit;
event.detail = detail;
setKeyState (event, phEvent);
sendEvent (SWT.Traverse, event);
if (isDisposed ()) return true;
doit = event.doit;
detail = event.detail;
}
if (doit) {
switch (detail) {
case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
case SWT.TRAVERSE_RETURN: return traverseReturn ();
case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true, control);
case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false, control);
case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true);
case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false);
}
}
return false;
}
int traversalCode (int key_sym, PhKeyEvent_t ke) {
return
SWT.TRAVERSE_ESCAPE | SWT.TRAVERSE_RETURN |
SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS |
SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS;
}
/**
* Based on the argument, perform one of the expected platform
* traversal action. The argument should be one of the constants:
* <code>SWT.TRAVERSE_ESCAPE</code>, <code>SWT.TRAVERSE_RETURN</code>,
* <code>SWT.TRAVERSE_TAB_NEXT</code>, <code>SWT.TRAVERSE_TAB_PREVIOUS</code>,
* <code>SWT.TRAVERSE_ARROW_NEXT</code> and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>.
*
* @param traversal the type of traversal
* @return true if the traversal succeeded
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public boolean traverse (int traversal) {
checkWidget();
if (!isFocusControl () && !setFocus ()) return false;
switch (traversal) {
case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
case SWT.TRAVERSE_RETURN: return traverseReturn ();
case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true, false);
case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false, false);
case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true);
case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false);
}
return false;
}
boolean traverseEscape () {
Shell shell = getShell ();
if (shell.parent == null) return false;
if (!shell.isVisible () || !shell.isEnabled ()) return false;
shell.close ();
return true;
}
boolean traverseGroup (boolean next, boolean control) {
if (control) {
if (next) return OS.PtGlobalFocusPrevContainer (handle, null) != 0;
return OS.PtGlobalFocusNextContainer (handle, null) != 0;
}
if (next) return OS.PtGlobalFocusPrev (handle, null) != 0;
return OS.PtGlobalFocusNext (handle, null) != 0;
}
boolean traverseItem (boolean next) {
if (next) return OS.PtContainerFocusPrev (handle, null) != 0;
return OS.PtContainerFocusNext (handle, null) != 0;
}
boolean traverseReturn () {
Button button = menuShell ().getDefaultButton ();
if (button == null || button.isDisposed ()) return false;
if (!button.isVisible () || !button.isEnabled ()) return false;
button.click ();
return true;
}
/**
* Forces all outstanding paint requests for the widget tree
* to be processed before this method returns.
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see #redraw
*/
public void update () {
checkWidget();
OS.PtFlush ();
}
}