| package org.eclipse.swt.widgets; |
| |
| /* |
| * (c) Copyright IBM Corp. 2000, 2001. |
| * All Rights Reserved |
| */ |
| |
| import org.eclipse.swt.*; |
| import org.eclipse.swt.internal.*; |
| import org.eclipse.swt.internal.gtk.*; |
| import org.eclipse.swt.events.*; |
| |
| /** |
| * This class is the abstract superclass of all user interface objects. |
| * Widgets are created, disposed and issue notification to listeners |
| * when events occur which affect them. |
| * <dl> |
| * <dt><b>Styles:</b></dt> |
| * <dd>(none)</dd> |
| * <dt><b>Events:</b></dt> |
| * <dd>Dispose</dd> |
| * </dl> |
| * <p> |
| * IMPORTANT: This class is intended to be subclassed <em>only</em> |
| * within the SWT implementation. However, it has not been marked |
| * final to allow those outside of the SWT development team to implement |
| * patched versions of the class in order to get around specific |
| * limitations in advance of when those limitations can be addressed |
| * by the team. Any class built using subclassing to access the internals |
| * of this class will likely fail to compile or run between releases and |
| * may be strongly platform specific. Subclassing should not be attempted |
| * without an intimate and detailed understanding of the workings of the |
| * hierarchy. No support is provided for user-written classes which are |
| * implemented as subclasses of this class. |
| * </p> |
| * |
| * @see #checkSubclass |
| */ |
| |
| public abstract class Widget { |
| |
| public int handle; |
| int style, state; |
| EventTable eventTable; |
| Object data; |
| String [] keys; |
| Object [] values; |
| |
| /* Global state flags */ |
| // static final int AUTOMATIC = 1<<0; |
| // static final int ACTIVE = 1<<1; |
| // static final int AUTOGRAB = 1<<2; |
| // static final int MULTIEXPOSE = 1<<3; |
| // static final int RESIZEREDRAW = 1<<4; |
| // static final int WRAP = 1<<5; |
| // static final int DISABLED = 1<<6; |
| // static final int HIDDEN = 1<<7; |
| // static final int FOREGROUND = 1<<8; |
| // static final int BACKGROUND = 1<<9; |
| static final int DISPOSED = 1<<10; |
| static final int HANDLE = 1<<11; |
| static final int CANVAS = 1<<12; |
| |
| /* Default widths for widgets */ |
| static final int DEFAULT_WIDTH = 64; |
| static final int DEFAULT_HEIGHT = 64; |
| static final char Mnemonic = '&'; |
| |
| /** |
| * Prevents uninitialized instances from being created outside the package. |
| */ |
| Widget () {} |
| |
| /** |
| * Constructs a new instance of this class given its parent |
| * and a style value describing its behavior and appearance. |
| * <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 widget which will be the parent of the new instance (cannot be null) |
| * @param style the style of widget 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 #checkSubclass |
| * @see #getStyle |
| */ |
| public Widget (Widget parent, int style) { |
| if (parent == null) error (SWT.ERROR_NULL_ARGUMENT); |
| if (!parent.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| this.style = style; |
| } |
| /** |
| * Adds the listener to the collection of listeners who will |
| * be notifed when an event of the given type occurs. When the |
| * event does occur in the widget, the listener is notified by |
| * sending it the <code>handleEvent()</code> message. |
| * |
| * @param eventType the type of event to listen for |
| * @param listener the listener which should be notified when the event occurs |
| * |
| * @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 Listener |
| * @see #removeListener |
| */ |
| public void addListener (int eventType, Listener handler) { |
| if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); |
| if (handler == null) error (SWT.ERROR_NULL_ARGUMENT); |
| if (eventTable == null) eventTable = new EventTable (); |
| eventTable.hook (eventType, handler); |
| } |
| /** |
| * Adds the listener to the collection of listeners who will |
| * be notifed when the widget is disposed. When the widget is |
| * disposed, the listener is notified by sending it the |
| * <code>widgetDisposed()</code> message. |
| * |
| * @param listener the listener which should be notified when the receiver is disposed |
| * |
| * @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 DisposeListener |
| * @see #removeDisposeListener |
| */ |
| public void addDisposeListener (DisposeListener listener) { |
| if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); |
| if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); |
| TypedListener typedListener = new TypedListener (listener); |
| addListener (SWT.Dispose, typedListener); |
| } |
| static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) { |
| int mask = int0 | int1 | int2 | int3 | int4 | int5; |
| if ((style & mask) == 0) style |= int0; |
| if ((style & int0) != 0) style = (style & ~mask) | int0; |
| if ((style & int1) != 0) style = (style & ~mask) | int1; |
| if ((style & int2) != 0) style = (style & ~mask) | int2; |
| if ((style & int3) != 0) style = (style & ~mask) | int3; |
| if ((style & int4) != 0) style = (style & ~mask) | int4; |
| if ((style & int5) != 0) style = (style & ~mask) | int5; |
| return style; |
| } |
| |
| /** |
| * Checks that this class can be subclassed. |
| * <p> |
| * The SWT class library is intended to be subclassed |
| * only at specific, controlled points (most notably, |
| * <code>Composite</code> and <code>Canvas</code> when |
| * implementing new widgets). This method enforces this |
| * rule unless it is overridden. |
| * </p><p> |
| * <em>IMPORTANT:</em> By providing an implementation of this |
| * method that allows a subclass of a class which does not |
| * normally allow subclassing to be created, the implementer |
| * agrees to be fully responsible for the fact that any such |
| * subclass will likely fail between SWT releases and will be |
| * strongly platform specific. No support is provided for |
| * user-written classes which are implemented in this fashion. |
| * </p><p> |
| * The ability to subclass outside of the allowed SWT classes, |
| * is intended purely to enable those not on the SWT development |
| * team to implement patches in order to get around specific |
| * limitations in advance of when those limitations can be |
| * addressed by the team. Subclassing should not be attempted |
| * without an intimate and detailed understanding of the hierarchy. |
| * </p> |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> |
| * </ul> |
| */ |
| protected void checkSubclass () { |
| if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); |
| } |
| |
| /** |
| * Throws an <code>SWTException</code> if the receiver can not |
| * be accessed by the caller. This may include both checks on |
| * the state of the receiver and more generally on the entire |
| * execution context. This method <em>should</em> be called by |
| * widget implementors to enforce the standard SWT invariants. |
| * <p> |
| * Currently, it is an error to invoke any method (other than |
| * <code>isDisposed()</code>) on a widget that has had its |
| * <code>dispose()</code> method called. It is also an error |
| * to call widget methods from any thread that is different |
| * from the thread that created the widget. |
| * </p><p> |
| * In future releases of SWT, there may be more or fewer error |
| * checks and exceptions may be thrown for different reasons. |
| * </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> |
| */ |
| protected void checkWidget () { |
| if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); |
| } |
| |
| /* |
| * HANDLE CODE |
| * |
| * HANDLE CODE 1: HANDLE CREATION CODE - The createWidget() cycle. |
| */ |
| |
| void createWidget (int index) { |
| createHandle (index); |
| hookEvents (); |
| configure (); |
| setHandleStyle (); |
| register (); |
| setInitialSize (); |
| showHandle (); |
| } |
| |
| void register () { |
| if (handle == 0) return; |
| if ((state & HANDLE) != 0) WidgetTable.put (handle, this); |
| } |
| |
| void createHandle (int index) {} |
| void configure () {} |
| void setHandleStyle () {} |
| void setInitialSize () {} |
| void hookEvents () {} |
| void showHandle () {} |
| int paintHandle () { return 0; } |
| |
| /* HANDLE CODE 3: |
| * Handle Destruction |
| */ |
| |
| void deregister () { |
| if (handle == 0) return; |
| if ((state & HANDLE) != 0) WidgetTable.remove (handle); |
| } |
| void destroyWidget () { |
| int topHandle = topHandle (); |
| releaseHandle (); |
| if (topHandle != 0 && (state & HANDLE) != 0) { |
| OS.gtk_widget_destroy (topHandle); |
| } |
| } |
| /** |
| * Disposes of the operating system resources associated with |
| * the receiver and all its descendents. After this method has |
| * been invoked, the receiver and all descendents will answer |
| * <code>true</code> when sent the message <code>isDisposed()</code>. |
| * Any internal connections between the widgets in the tree will |
| * have been removed to facilitate garbage collection. |
| * <p> |
| * NOTE: This method is not called recursively on the descendents |
| * of the receiver. This means that, widget implementers can not |
| * detect when a widget is being disposed of by re-implementing |
| * this method, but should instead listen for the <code>Dispose</code> |
| * event. |
| * </p> |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| * |
| * @see #addDisposeListener |
| * @see #removeDisposeListener |
| * @see #checkWidget |
| */ |
| public void dispose () { |
| /* |
| * Note: It is valid to attempt to dispose a widget |
| * more than once. If this happens, fail silently. |
| */ |
| if (isDisposed()) return; |
| if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| releaseChild (); |
| releaseWidget (); |
| destroyWidget (); |
| } |
| |
| void error (int code) { |
| throw new SWTError (code); |
| } |
| |
| |
| |
| /** |
| * Returns the application defined widget data associated |
| * with the receiver, or null if it has not been set. The |
| * <em>widget data</em> is a single, unnamed field that is |
| * stored with every widget. |
| * <p> |
| * Applications may put arbitrary objects in this field. If |
| * the object stored in the widget data needs to be notified |
| * when the widget is disposed of, it is the application's |
| * responsibility to hook the Dispose event on the widget and |
| * do so. |
| * </p> |
| * |
| * @return the widget data |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li> |
| * </ul> |
| * |
| * @see #setData |
| */ |
| public Object getData () { |
| if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); |
| return data; |
| } |
| /** |
| * Returns the application defined property of the receiver |
| * with the specified name, or null if it has not been set. |
| * <p> |
| * Applications may have associated arbitrary objects with the |
| * receiver in this fashion. If the objects stored in the |
| * properties need to be notified when the widget is disposed |
| * of, it is the application's responsibility to hook the |
| * Dispose event on the widget and do so. |
| * </p> |
| * |
| * @param key the name of the property |
| * @return the value of the property or null if it has not been set |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_NULL_ARGUMENT - if the key 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 #setData |
| */ |
| public Object getData (String key) { |
| if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); |
| if (key == null) error (SWT.ERROR_NULL_ARGUMENT); |
| if (keys == null) return null; |
| for (int i=0; i<keys.length; i++) { |
| if (keys [i].equals (key)) return values [i]; |
| } |
| return null; |
| } |
| /** |
| * Returns the <code>Display</code> that is associated with |
| * the receiver. |
| * <p> |
| * A widget's display is either provided when it is created |
| * (for example, top level <code>Shell</code>s) or is the |
| * same as its parent's display. |
| * </p> |
| * |
| * @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 abstract Display getDisplay (); |
| String getName () { |
| // String string = getClass ().getName (); |
| // int index = string.lastIndexOf ('.'); |
| // if (index == -1) return string; |
| String string = getClass ().getName (); |
| int index = string.length (); |
| while ((--index > 0) && (string.charAt (index) != '.')); |
| return string.substring (index + 1, string.length ()); |
| } |
| String getNameText () { |
| return ""; |
| } |
| /** |
| * Returns the receiver's style information. |
| * <p> |
| * Note that the value which is returned by this method <em>may |
| * not match</em> the value which was provided to the constructor |
| * when the receiver was created. This can occur when the underlying |
| * operating system does not support a particular combination of |
| * requested styles. For example, if the platform widget used to |
| * implement a particular SWT widget always has scroll bars, the |
| * result of calling this method would always have the |
| * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set. |
| * </p> |
| * |
| * @return the style bits |
| * |
| * @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 getStyle () { |
| if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); |
| return style; |
| } |
| |
| /** |
| * Returns <code>true</code> if the widget has been disposed, |
| * and <code>false</code> otherwise. |
| * <p> |
| * This method gets the dispose state for the widget. |
| * When a widget has been disposed, it is an error to |
| * invoke any other method using the widget. |
| * </p> |
| * |
| * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise |
| */ |
| public boolean isDisposed () { |
| if (handle != 0) return false; |
| if ((state & HANDLE) != 0) return true; |
| return (state & DISPOSED) != 0; |
| } |
| |
| /** |
| * Returns <code>true</code> if there are any listeners |
| * for the specified event type associated with the receiver, |
| * and <code>false</code> otherwise. |
| * |
| * @param eventType the type of event |
| * @return true if the event is hooked |
| * |
| * @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> |
| */ |
| protected boolean isListening (int eventType) { |
| if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); |
| return hooks (eventType); |
| } |
| |
| |
| /* |
| * Returns <code>true</code> if the specified eventType is |
| * hooked, and <code>false</code> otherwise. Implementations |
| * of SWT can avoid creating objects and sending events |
| * when an event happens in the operating system but |
| * there are no listeners hooked for the event. |
| * |
| * @param eventType the event to be checked |
| * |
| * @return <code>true</code> when the eventType is hooked and <code>false</code> otherwise |
| * |
| * @see #isListening |
| */ |
| boolean hooks (int eventType) { |
| if (eventTable == null) return false; |
| return eventTable.hooks (eventType); |
| } |
| |
| boolean isValidThread () { |
| return getDisplay ().isValidThread (); |
| } |
| public boolean isValidWidget () { |
| if (handle != 0) return true; |
| if ((state & HANDLE) != 0) return false; |
| return (state & DISPOSED) == 0; |
| } |
| |
| boolean isValidSubclass() { |
| return Display.isValidClass(getClass()); |
| } |
| |
| char mbcsToWcs (char ch) { |
| int key = ch & 0xFFFF; |
| if (key <= 0x7F) return ch; |
| byte [] buffer; |
| if (key <= 0xFF) { |
| buffer = new byte [1]; |
| buffer [0] = (byte) key; |
| } else { |
| buffer = new byte [2]; |
| buffer [0] = (byte) ((key >> 8) & 0xFF); |
| buffer [1] = (byte) (key & 0xFF); |
| } |
| char [] result = Converter.mbcsToWcs (null, buffer); |
| if (result.length == 0) return 0; |
| return result [0]; |
| } |
| /** |
| * Notifies all of the receiver's listeners for events |
| * of the given type that one such event has occurred by |
| * invoking their <code>handleEvent()</code> method. |
| * |
| * @param eventType the type of event which has occurred |
| * @param event the event data |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_NULL_ARGUMENT - if the event 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 notifyListeners (int eventType, Event event) { |
| checkWidget(); |
| if (event == null) error (SWT.ERROR_NULL_ARGUMENT); |
| if (eventTable == null) return; |
| event.type = eventType; |
| event.widget = this; |
| eventTable.sendEvent (event); |
| } |
| void postEvent (int eventType) { |
| if (eventTable == null) return; |
| postEvent (eventType, new Event ()); |
| } |
| void postEvent (int eventType, Event event) { |
| if (eventTable == null) return; |
| event.type = eventType; |
| event.widget = this; |
| getDisplay ().postEvent (event); |
| } |
| |
| int processEvent (int eventNumber, int int0, int int1, int int2) { |
| switch (eventNumber) { |
| case SWT.Arm: return processArm (int0, int1, int2); |
| case SWT.Collapse: return processCollapse (int0, int1, int2); |
| case SWT.Expand: return processExpand (int0, int1, int2); |
| case SWT.Dispose: return processDispose (int0, int1, int2); |
| case SWT.DefaultSelection: return processDoubleSelection (int0, int1, int2); |
| case SWT.FocusIn: return processFocusIn (int0, int1, int2); |
| case SWT.FocusOut: return processFocusOut (int0, int1, int2); |
| case SWT.Help: return processHelp (int0, int1, int2); |
| case SWT.Hide: return processHide (int0, int1, int2); |
| case SWT.KeyDown: return processKeyDown (int0, int1, int2); |
| case SWT.KeyUp: return processKeyUp (int0, int1, int2); |
| case SWT.Iconify: return processIconify (int0, int1, int2); |
| case SWT.Deiconify: return processDeiconify (int0, int1, int2); |
| case SWT.Modify: return processModify (int0, int1, int2); |
| case SWT.MouseDown: return processMouseDown (int0, int1, int2); |
| case SWT.MouseEnter: return processMouseEnter (int0, int1, int2); |
| case SWT.MouseExit: return processMouseExit (int0, int1, int2); |
| case SWT.MouseHover: return processMouseHover (int0, int1, int2); |
| case SWT.MouseMove: return processMouseMove (int0, int1, int2); |
| case SWT.MouseUp: return processMouseUp (int0, int1, int2); |
| case SWT.Paint: return processPaint (int0, int1, int2); |
| case SWT.Resize: return processResize (int0, int1, int2); |
| case SWT.Show: return processShow (int0, int1, int2); |
| case SWT.Selection: return processSelection (int0, int1, int2); |
| case SWT.Verify: return processVerify (int0, int1, int2); |
| } |
| return 0; |
| } |
| |
| int processArm (int int0, int int1, int int2) { |
| return 0; |
| } |
| |
| /* |
| * Item expand/collapse in a tree. |
| */ |
| int processCollapse (int int0, int int1, int int2) { |
| return 1; // stop emission |
| } |
| int processExpand (int int0, int int1, int int2) { |
| return 1; // stop emission |
| } |
| |
| /* |
| * Close a Shell, triggered by delete_event |
| */ |
| int processDispose (int arg0, int arg1, int int2) { |
| return 1; |
| } |
| |
| /* |
| * The WM has Iconified/Deiconified a Shell. |
| * The Gtk event is map_event/unmap_event |
| */ |
| int processIconify (int int0, int int1, int int2) { |
| return 0; |
| } |
| int processDeiconify (int int0, int int1, int int2) { |
| return 0; |
| } |
| |
| int processHelp (int int0, int int1, int int2) { |
| return 0; |
| } |
| int processHide (int int0, int int1, int int2) { |
| return 0; |
| } |
| int processFocusIn(int int0, int int1, int int2) { |
| return 0; |
| } |
| int processFocusOut(int int0, int int1, int int2) { |
| return 0; |
| } |
| int processKeyDown (int arg0, int arg1, int int2) { |
| return 0; |
| } |
| int processKeyUp (int arg0, int arg1, int int2) { |
| return 0; |
| } |
| int processModify (int arg0, int arg1, int int2) { |
| return 0; |
| } |
| int processMouseDown (int arg0, int arg1, int int2) { |
| return 0; |
| } |
| int processMouseEnter (int arg0, int arg1, int int2) { |
| return 0; |
| } |
| int processMouseExit (int arg0, int arg1, int int2) { |
| /* Do nothing */ |
| return 0; |
| } |
| int processMouseHover (int arg0, int arg1, int int2) { |
| /* Do nothing */ |
| return 0; |
| } |
| int processMouseMove (int arg0, int arg1, int int2) { |
| /* Do nothing */ |
| /* Even though we do nothing, we still need to at least |
| * motify the X Server we are ready to process more events. |
| * However, only OS controls can receive this event. |
| */ |
| return 0; |
| } |
| |
| int processMouseUp (int arg0, int arg1, int int2) { |
| return 0; |
| } |
| int processPaint (int int0, int int1, int int2) { |
| return 0; |
| } |
| int processResize (int int0, int int1, int int2) { |
| return 0; |
| } |
| int processSelection (int int0, int int1, int int2) { |
| return 0; |
| } |
| int processShow (int int0, int int1, int int2) { |
| return 0; |
| } |
| int processDoubleSelection (int int0, int int1, int int2) { |
| return 0; |
| } |
| int processVerify (int int0, int int1, int int2) { |
| sendEvent (SWT.Verify); |
| return 0; |
| } |
| |
| void signal_connect (int handle, String eventName, int swtEvent, int numArgs) { |
| int proc=0; |
| switch (numArgs) { |
| case 2: proc=getDisplay().windowProc2; break; |
| case 3: proc=getDisplay().windowProc3; break; |
| case 4: proc=getDisplay().windowProc4; break; |
| case 5: proc=getDisplay().windowProc5; break; |
| default: error(SWT.ERROR_INVALID_ARGUMENT); |
| } |
| /*OS.g_signal_connect (handle, eventName, proc, swtEvent);*/ |
| byte [] buffer = Converter.wcsToMbcs (null, eventName, true); |
| OS.gtk_signal_connect(handle, buffer, proc, swtEvent); |
| } |
| void signal_connect_after (int handle, String eventName, int swtEvent, int numArgs) { |
| byte [] buffer = Converter.wcsToMbcs (null, eventName, true); |
| int proc=0; |
| switch (numArgs) { |
| case 2: proc=getDisplay().windowProc2; break; |
| case 3: proc=getDisplay().windowProc3; break; |
| case 4: proc=getDisplay().windowProc4; break; |
| case 5: proc=getDisplay().windowProc5; break; |
| default: error(SWT.ERROR_INVALID_ARGUMENT); |
| } |
| OS.gtk_signal_connect_after (handle, buffer, proc, swtEvent); |
| } |
| |
| void releaseChild () { |
| /* Do nothing */ |
| } |
| void releaseHandle () { |
| handle = 0; |
| state |= DISPOSED; |
| } |
| void releaseWidget () { |
| sendEvent (SWT.Dispose); |
| deregister (); |
| eventTable = null; |
| data = null; |
| } |
| /** |
| * Removes the listener from the collection of listeners who will |
| * be notifed when an event of the given type occurs. |
| * |
| * @param eventType the type of event to listen for |
| * @param listener the listener which should no longer be notified when the event occurs |
| * |
| * @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 Listener |
| * @see #addListener |
| */ |
| public void removeListener (int eventType, Listener handler) { |
| if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); |
| if (handler == null) error (SWT.ERROR_NULL_ARGUMENT); |
| if (eventTable == null) return; |
| eventTable.unhook (eventType, handler); |
| } |
| /** |
| * Warning: API under construction. |
| */ |
| protected void removeListener (int eventType, SWTEventListener handler) { |
| if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); |
| if (handler == null) error (SWT.ERROR_NULL_ARGUMENT); |
| if (eventTable == null) return; |
| eventTable.unhook (eventType, handler); |
| } |
| /** |
| * Removes the listener from the collection of listeners who will |
| * be notifed when the widget is disposed. |
| * |
| * @param listener the listener which should no longer be notified when the receiver is disposed |
| * |
| * @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 DisposeListener |
| * @see #removeDisposeListener |
| */ |
| public void removeDisposeListener (DisposeListener listener) { |
| if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); |
| if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); |
| if (eventTable == null) return; |
| eventTable.unhook (SWT.Dispose, listener); |
| } |
| void sendEvent (int eventType) { |
| if (eventTable == null) return; |
| sendEvent (eventType, new Event ()); |
| } |
| void sendEvent (int eventType, Event event) { |
| if (eventTable == null) return; |
| event.widget = this; |
| event.type = eventType; |
| eventTable.sendEvent (event); |
| } |
| /** |
| * Sets the application defined widget data associated |
| * with the receiver to be the argument. The <em>widget |
| * data</em> is a single, unnamed field that is stored |
| * with every widget. |
| * <p> |
| * Applications may put arbitrary objects in this field. If |
| * the object stored in the widget data needs to be notified |
| * when the widget is disposed of, it is the application's |
| * responsibility to hook the Dispose event on the widget and |
| * do so. |
| * </p> |
| * |
| * @param data the widget data |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li> |
| * </ul> |
| */ |
| public void setData (Object data) { |
| checkWidget(); |
| this.data = data; |
| } |
| /** |
| * Sets the application defined property of the receiver |
| * with the specified name to the given value. |
| * <p> |
| * Applications may associate arbitrary objects with the |
| * receiver in this fashion. If the objects stored in the |
| * properties need to be notified when the widget is disposed |
| * of, it is the application's responsibility to hook the |
| * Dispose event on the widget and do so. |
| * </p> |
| * |
| * @param key the name of the property |
| * @param value the new value for the property |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_NULL_ARGUMENT - if the key 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 #getData |
| */ |
| public void setData (String key, Object value) { |
| if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); |
| if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); |
| if (key == null) error (SWT.ERROR_NULL_ARGUMENT); |
| |
| /* Remove the key/value pair */ |
| if (value == null) { |
| if (keys == null) return; |
| int index = 0; |
| while (index < keys.length && !keys [index].equals (key)) index++; |
| if (index == keys.length) return; |
| if (keys.length == 1) { |
| keys = null; |
| values = null; |
| } else { |
| String [] newKeys = new String [keys.length - 1]; |
| Object [] newValues = new Object [values.length - 1]; |
| System.arraycopy (keys, 0, newKeys, 0, index); |
| System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index); |
| System.arraycopy (values, 0, newValues, 0, index); |
| System.arraycopy (values, index + 1, newValues, index, newValues.length - index); |
| keys = newKeys; |
| values = newValues; |
| } |
| return; |
| } |
| |
| /* Add the key/value pair */ |
| if (keys == null) { |
| keys = new String [] {key}; |
| values = new Object [] {value}; |
| return; |
| } |
| for (int i=0; i<keys.length; i++) { |
| if (keys [i].equals (key)) { |
| values [i] = value; |
| return; |
| } |
| } |
| String [] newKeys = new String [keys.length + 1]; |
| Object [] newValues = new Object [values.length + 1]; |
| System.arraycopy (keys, 0, newKeys, 0, keys.length); |
| System.arraycopy (values, 0, newValues, 0, values.length); |
| newKeys [keys.length] = key; |
| newValues [values.length] = value; |
| keys = newKeys; |
| values = newValues; |
| } |
| /** |
| * Returns a string containing a concise, human-readable |
| * description of the receiver. |
| * |
| * @return a string representation of the receiver |
| */ |
| public String toString () { |
| String string = "*Disposed*"; |
| if (!isDisposed ()) { |
| string = "*Wrong Thread*"; |
| if (isValidThread ()) string = getNameText (); |
| } |
| return getName () + " {" + string + "}"; |
| } |
| int topHandle () { |
| return handle; |
| } |
| char wcsToMbcs (char ch) { |
| int key = ch & 0xFFFF; |
| if (key <= 0x7F) return ch; |
| byte [] buffer = Converter.wcsToMbcs (null, new char [] {ch}, false); |
| if (buffer.length == 1) return (char) buffer [0]; |
| if (buffer.length == 2) { |
| return (char) (((buffer [0] & 0xFF) << 8) | (buffer [1] & 0xFF)); |
| } |
| return 0; |
| } |
| } |