⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 widget.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************* * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html *  * Contributors: *     IBM Corporation - initial API and implementation *******************************************************************************/package org.eclipse.swt.widgets;import org.eclipse.swt.internal.*;import org.eclipse.swt.internal.win32.*;import org.eclipse.swt.*;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 {	int style, state;	Display display;	EventTable eventTable;	Object data;	/* Global state flags */	static final int DISPOSED		= 1<<0;	static final int CANVAS			= 1<<1;	static final int KEYED_DATA		= 1<<2;	static final int DISABLED		= 1<<3;	static final int HIDDEN			= 1<<4;		/* Default widths for widgets */	static final int DEFAULT_WIDTH	= 64;	static final int DEFAULT_HEIGHT	= 64;	/* Check and initialize the Common Controls DLL */	static final int MAJOR = 4, MINOR = 71;	static {		if (!OS.IsWinCE) {			if ((OS.COMCTL32_MAJOR << 16 | OS.COMCTL32_MINOR) < (MAJOR << 16 | MINOR)) {				System.out.println ("***WARNING: SWT requires comctl32.dll version " + MAJOR + "." + MINOR + " or greater"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$				System.out.println ("***WARNING: Detected: " + OS.COMCTL32_MAJOR + "." + OS.COMCTL32_MINOR); //$NON-NLS-1$ //$NON-NLS-2$			}		}		OS.InitCommonControls ();	}	/** * 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 * lists the style constants that are applicable to the class. * Style bits are also inherited from superclasses. * </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) {	checkSubclass ();	checkParent (parent);	this.style = style;	display = parent.display;}/** * 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 listener) {	checkWidget();	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);	if (eventTable == null) eventTable = new EventTable ();	eventTable.hook (eventType, listener);}/** * 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) {	checkWidget();	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);	TypedListener typedListener = new TypedListener (listener);	addListener (SWT.Dispose, typedListener);}/** * Returns a style with exactly one style bit set out of * the specified set of exclusive style bits. All other * possible bits are cleared when the first matching bit * is found. Bits that are not part of the possible set * are untouched. * * @param style the original style bits * @param int0 the 0th possible style bit * @param int1 the 1st possible style bit * @param int2 the 2nd possible style bit * @param int3 the 3rd possible style bit * @param int4 the 4th possible style bit * @param int5 the 5th possible style bit * * @return the new style bits */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;}void checkOrientation (Widget parent) {	style &= ~SWT.MIRRORED;	if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {		if (parent != null) {			if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT;			if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT;		}	}	style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0);}/** * Throws an exception if the specified widget can not be * used as a parent for the receiver. * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li> *    <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> * </ul> */void checkParent (Widget parent) {	if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);	parent.checkWidget ();}/** * 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 () {	Display display = this.display;	if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);	if (display.thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);	if ((state & DISPOSED) != 0) error (SWT.ERROR_WIDGET_DISPOSED);}/** * Destroys the widget in the operating system and releases * the widget's handle.  If the widget does not have a handle, * this method may hide the widget, mark the widget as destroyed * or do nothing, depending on the widget. * <p> * When a widget is destroyed in the operating system, its * descendents are also destroyed by the operating system. * This means that it is only necessary to call <code>destroyWidget</code> * on the root of the widget tree. * </p><p> * This method is called after <code>releaseWidget</code>. * </p> * @see #dispose * @see #releaseChild * @see #releaseWidget * @see #releaseHandle */void destroyWidget () {	releaseHandle ();}int DeferWindowPos(int hWinPosInfo, int hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags){	if (OS.IsWinCE) {		/*		* Feature in Windows.  On Windows CE, DeferWindowPos always causes		* a WM_SIZE message, even when the new size is the same as the old		* size.  The fix is to detect that the size has not changed and set		* SWP_NOSIZE.		*/		if ((uFlags & OS.SWP_NOSIZE) == 0) {			RECT lpRect = new RECT ();			OS.GetWindowRect (hWnd, lpRect);			if (cy == lpRect.bottom - lpRect.top && cx == lpRect.right - lpRect.left) {				/*				* Feature in Windows.  On Windows CE, DeferWindowPos when called				* with SWP_DRAWFRAME always causes a WM_SIZE message, even				* when SWP_NOSIZE is set and when the new size is the same as the				* old size.  The fix is to clear SWP_DRAWFRAME when the size is				* the same.				*/				uFlags &= ~OS.SWP_DRAWFRAME;				uFlags |= OS.SWP_NOSIZE;			}		}	}	return OS.DeferWindowPos (hWinPosInfo, hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);}/** * 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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -