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

📄 control.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	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);}boolean sendKeyEvent (int type, int msg, int wParam, int lParam) {	Event event = new Event ();	if (!setKeyState (event, type, wParam, lParam)) return true;	return sendKeyEvent (type, msg, wParam, lParam, event);}boolean sendKeyEvent (int type, int msg, int wParam, int lParam, Event event) {	sendEvent (type, event);	// widget could be disposed at this point		/*	* It is possible (but unlikely), that application	* code could have disposed the widget in the key	* events.  If this happens, end the processing of	* the key by returning false.	*/	if (isDisposed ()) return false;	return event.doit;}boolean sendFocusEvent (int type, int hwnd) {	Shell shell = getShell ();		/*	* It is possible (but unlikely), that application	* code could have disposed the widget in the focus	* out event.  If this happens keep going to send	* the deactivate events.	*/	sendEvent (type);	// widget could be disposed at this point		switch (type) {		case SWT.FocusIn:			/*			* It is possible that the shell may be			* disposed at this point.  If this happens			* don't send the activate and deactivate			* events.			*/				if (!shell.isDisposed ()) {				shell.setActiveControl (this);			}			break;		case SWT.FocusOut:			/*			* It is possible that the shell may be			* disposed at this point.  If this happens			* don't send the activate and deactivate			* events.			*/			if (!shell.isDisposed ()) {				Display display = shell.display;				Control control = hwnd != -1 ? display.findControl (hwnd) : display.getFocusControl ();				if (control == null || shell != control.getShell ()) {					shell.setActiveControl (null);				}			}			break;	}	return true;}boolean sendMouseEvent (int type, int button, int msg, int wParam, int lParam) {	Event event = new Event ();	event.button = button;	event.x = (short) (lParam & 0xFFFF);	event.y = (short) (lParam >> 16);	setInputState (event, type);	return sendMouseEvent (type, msg, wParam, lParam, event);}boolean sendMouseEvent (int type, int msg, int wParam, int lParam, Event event) {	postEvent (type, event);	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 = -1;	if (color != null) {		if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);		pixel = color.handle;	}	setBackgroundPixel (pixel);}void setBackgroundPixel (int pixel) {	if (background == pixel) return;	background = pixel;	OS.InvalidateRect (handle, null, true);}/** * 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), unless  * the receiver is a shell. In this case, the <code>x</code> * and <code>y</code> arguments are relative to the display. * <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 ();	int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE;	setBounds (x, y, Math.max (0, width), Math.max (0, height), flags);}void setBounds (int x, int y, int width, int height, int flags) {	if (parent == null) {		SetWindowPos (handle, 0, x, y, width, height, flags);		return;	}	forceResize ();	WINDOWPOS [] lpwp = parent.lpwp;	if (lpwp == null) {		/*		* This code is intentionally commented.  All widgets that		* are created by SWT have WS_CLIPSIBLINGS to ensure that		* application code does not draw outside of the control.		*///		int count = parent.getChildrenCount ();//		if (count > 1) {//			int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);//			if ((bits & OS.WS_CLIPSIBLINGS) == 0) flags |= OS.SWP_NOCOPYBITS;//		}		SetWindowPos (handle, 0, x, y, width, height, flags);		return;	}	int index = 0;	while (index < lpwp.length) {		if (lpwp [index] == null) break;		index ++;	}	if (index == lpwp.length) {		WINDOWPOS [] newLpwp = new WINDOWPOS [lpwp.length + 4];		System.arraycopy (lpwp, 0, newLpwp, 0, lpwp.length);		parent.lpwp = lpwp = newLpwp;	}	WINDOWPOS wp = new WINDOWPOS ();	wp.hwnd = handle;	wp.x = x;	wp.y = y;	wp.cx = width;	wp.cy = height;	wp.flags = flags;	lpwp [index] = wp;}/** * 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) {	checkWidget ();	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 ();	if (capture) {		OS.SetCapture (handle);	} else {		if (OS.GetCapture () == handle) {			OS.ReleaseCapture ();		}	}}void setCursor () {	int lParam = OS.HTCLIENT | (OS.WM_MOUSEMOVE << 16);	OS.SendMessage (handle, OS.WM_SETCURSOR, handle, lParam);}/** * 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 ();	if (cursor != null && cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);	this.cursor = cursor;	if (OS.IsWinCE) {		int hCursor = cursor != null ? cursor.handle : 0;		OS.SetCursor (hCursor);		return;	}	int hwndCursor = OS.GetCapture ();	if (hwndCursor == 0) {		POINT pt = new POINT ();		if (!OS.GetCursorPos (pt)) return;		int hwnd = hwndCursor = OS.WindowFromPoint (pt);		while (hwnd != 0 && hwnd != handle) {			hwnd = OS.GetParent (hwnd);		}		if (hwnd == 0) return;	}	Control control = display.getControl (hwndCursor);	if (control == null) control = this;	control.setCursor ();}void setDefaultFont () {	int hFont = display.systemFont ();	OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);}/** * 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 ();	/*	* Feature in Windows.  If the receiver has focus, disabling	* the receiver causes no window to have focus.  The fix is	* to assign focus to the first ancestor window that takes	* focus.  If no window will take focus, set focus to the	* desktop.	*/	Control control = null;	boolean fixFocus = false;	if (!enabled) {		control = display.getFocusControl ();		fixFocus = isFocusAncestor (control);	}	enableWidget (enabled);	if (fixFocus) fixFocus (control);}/** * Causes the receiver to have the <em>keyboard focus</em>,  * such that all keyboard events will be delivered to it.  Focus * reassignment will respect applicable platform constraints. * * @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 ();	if ((style & SWT.NO_FOCUS) != 0) return false;	return forceFocus ();}/** * 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 ();	int hFont = 0;	if (font != null) { 		if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);		hFont = font.handle;	}	if (hFont == 0) hFont = defaultFont ();	OS.SendMessage (handle, OS.WM_SETFONT, hFont, 1);}/** * 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 = -1;	if (color != null) {		if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);		pixel = color.handle;	}	setForegroundPixel (pixel);}void setForegroundPixel (int pixel) {	if (foreground == pixel) return;	foreground = pixel;	OS.InvalidateRect (handle, null, true);}/** * Sets the layout data associated with the receiver to the argument. *  * @param layoutData the new layout data for the receiver. *  * @

⌨️ 快捷键说明

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