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

📄 display.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
 * @see #removeListener *  * @since 2.0  */public void addListener (int eventType, Listener listener) {	checkDevice ();	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);	if (eventTable == null) eventTable = new EventTable ();	eventTable.hook (eventType, listener);}void addBar (Menu menu) {	if (bars == null) bars = new Menu [4];	int length = bars.length;	for (int i=0; i<length; i++) {		if (bars [i] == menu) return;	}	int index = 0;	while (index < length) {		if (bars [index] == null) break;		index++;	}	if (index == length) {		Menu [] newBars = new Menu [length + 4];		System.arraycopy (bars, 0, newBars, 0, length);		bars = newBars;	}	bars [index] = menu;}void addControl (int handle, Control control) {	if (handle == 0) return;	if (freeSlot == -1) {		int length = (freeSlot = indexTable.length) + GROW_SIZE;		int [] newIndexTable = new int [length];		Control [] newControlTable = new Control [length];		System.arraycopy (indexTable, 0, newIndexTable, 0, freeSlot);		System.arraycopy (controlTable, 0, newControlTable, 0, freeSlot);		for (int i=freeSlot; i<length-1; i++) newIndexTable [i] = i + 1;		newIndexTable [length - 1] = -1;		indexTable = newIndexTable;		controlTable = newControlTable;	}	OS.SetWindowLong (handle, OS.GWL_USERDATA, freeSlot + 1);	int oldSlot = freeSlot;	freeSlot = indexTable [oldSlot];	indexTable [oldSlot] = -2;	controlTable [oldSlot] = control;}void addMenuItem (MenuItem item) {	if (items == null) items = new MenuItem [64];	for (int i=0; i<items.length; i++) {		if (items [i] == null) {			item.id = i + ID_START;			items [i] = item;			return;		}	}	item.id = items.length + ID_START;	MenuItem [] newItems = new MenuItem [items.length + 64];	newItems [items.length] = item;	System.arraycopy (items, 0, newItems, 0, items.length);	items = newItems;}void addPopup (Menu menu) {	if (popups == null) popups = new Menu [4];	int length = popups.length;	for (int i=0; i<length; i++) {		if (popups [i] == menu) return;	}	int index = 0;	while (index < length) {		if (popups [index] == null) break;		index++;	}	if (index == length) {		Menu [] newPopups = new Menu [length + 4];		System.arraycopy (popups, 0, newPopups, 0, length);		popups = newPopups;	}	popups [index] = menu;}/** * Causes the <code>run()</code> method of the runnable to * be invoked by the user-interface thread at the next  * reasonable opportunity. The caller of this method continues  * to run in parallel, and is not notified when the * runnable has completed. * * @param runnable code to run on the user-interface thread. * * @exception SWTException <ul> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> *  * @see #syncExec */public void asyncExec (Runnable runnable) {	if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);	synchronizer.asyncExec (runnable);}/** * Causes the system hardware to emit a short sound * (if it supports this capability). *  * @exception SWTException <ul> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */public void beep () {	checkDevice ();	OS.MessageBeep (OS.MB_OK);}/** * Checks that this class can be subclassed. * <p> * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>. * </p> * * @exception SWTException <ul> *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> * </ul> * * @see Widget#checkSubclass */protected void checkSubclass () {	if (!isValidClass (getClass ())) error (SWT.ERROR_INVALID_SUBCLASS);}protected void checkDevice () {	if (thread == null) error (SWT.ERROR_WIDGET_DISPOSED);	if (thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);	if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);}static synchronized void checkDisplay (Thread thread) {	for (int i=0; i<Displays.length; i++) {		if (Displays [i] != null && Displays [i].thread == thread) {			SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);		}	}}void clearModal (Shell shell) {	if (modalShells == null) return;	int index = 0, length = modalShells.length;	while (index < length) {		if (modalShells [index] == shell) break;		if (modalShells [index] == null) return;		index++;	}	if (index == length) return;	System.arraycopy (modalShells, index + 1, modalShells, index, --length - index);	modalShells [length] = null;	if (index == 0 && modalShells [0] == null) modalShells = null;	Shell [] shells = getShells ();	for (int i=0; i<shells.length; i++) shells [i].updateModal ();}int controlKey (int key) {	int upper = OS.CharUpper ((short) key);	if (64 <= upper && upper <= 95) return upper & 0xBF;	return key;}/** * Requests that the connection between SWT and the underlying * operating system be closed. * * @exception SWTException <ul> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see Device#dispose *  * @since 2.0 */public void close () {	checkDevice ();	Event event = new Event ();	sendEvent (SWT.Close, event);	if (event.doit) dispose ();}/** * Creates the device in the operating system.  If the device * does not have a handle, this method may do nothing depending * on the device. * <p> * This method is called before <code>init</code>. * </p> * * @param data the DeviceData which describes the receiver * * @see #init */protected void create (DeviceData data) {	checkSubclass ();	checkDisplay (thread = Thread.currentThread ());	createDisplay (data);	register (this);	if (Default == null) Default = this;}void createDisplay (DeviceData data) {}static synchronized void deregister (Display display) {	for (int i=0; i<Displays.length; i++) {		if (display == Displays [i]) Displays [i] = null;	}}/** * Destroys the device in the operating system and releases * the device's handle.  If the device does not have a handle, * this method may do nothing depending on the device. * <p> * This method is called after <code>release</code>. * </p> * @see #dispose * @see #release */protected void destroy () {	if (this == Default) Default = null;	deregister (this);	destroyDisplay ();}void destroyDisplay () {}/** * Causes the <code>run()</code> method of the runnable to * be invoked by the user-interface thread just before the * receiver is disposed. * * @param runnable code to run at dispose time. *  * @exception SWTException <ul> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */public void disposeExec (Runnable runnable) {	checkDevice ();	if (disposeList == null) disposeList = new Runnable [4];	for (int i=0; i<disposeList.length; i++) {		if (disposeList [i] == null) {			disposeList [i] = runnable;			return;		}	}	Runnable [] newDisposeList = new Runnable [disposeList.length + 4];	System.arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);	newDisposeList [disposeList.length] = runnable;	disposeList = newDisposeList;}void drawMenuBars () {	if (bars == null) return;	for (int i=0; i<bars.length; i++) {		Menu menu = bars [i];		if (menu != null && !menu.isDisposed ()) menu.update ();	}	bars = null;}int embeddedProc (int hwnd, int msg, int wParam, int lParam) {	switch (msg) {		case SWT_KEYMSG: {			MSG keyMsg = new MSG ();			OS.MoveMemory (keyMsg, lParam, MSG.sizeof);			OS.TranslateMessage (keyMsg);			OS.DispatchMessage (keyMsg);			int hHeap = OS.GetProcessHeap ();			OS.HeapFree (hHeap, 0, lParam);			break;		}		case SWT_DESTROY: {			OS.DestroyWindow (hwnd);			if (embeddedCallback != null) embeddedCallback.dispose ();			if (getMsgCallback != null) getMsgCallback.dispose ();			embeddedCallback = getMsgCallback = null;			embeddedProc = getMsgProc = 0;			break;		}		case SWT_RESIZE: {			int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE;			OS.SetWindowPos (wParam, 0, 0, 0, lParam & 0xFFFF, lParam >> 16, flags);			break;		}	}	return OS.DefWindowProc (hwnd, msg, wParam, lParam);}/** * Does whatever display specific cleanup is required, and then * uses the code in <code>SWTError.error</code> to handle the error. * * @param code the descriptive error code * * @see SWTError#error */void error (int code) {	SWT.error (code);}boolean filterEvent (Event event) {	if (filterTable != null) filterTable.sendEvent (event);	return false;}boolean filters (int eventType) {	if (filterTable == null) return false;	return filterTable.hooks (eventType);}boolean filterMessage (MSG msg) {	int message = msg.message;	if (OS.WM_KEYFIRST <= message && message <= OS.WM_KEYLAST) {		Control control = findControl (msg.hwnd);		if (control != null) {			if (translateAccelerator (msg, control) || translateMnemonic (msg, control) || translateTraversal (msg, control)) {					lastAscii = lastKey = 0;				lastVirtual = lastNull = lastDead = false;				return true;			}		}	}	return false;}/** * Given the operating system handle for a widget, returns * the instance of the <code>Widget</code> subclass which * represents it in the currently running application, if * such exists, or null if no matching widget can be found. * * @param handle the handle for the widget * @return the SWT widget that the handle represents * * @exception SWTException <ul> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */public Widget findWidget (int handle) {	checkDevice ();	return getControl (handle);}Control findControl (int handle) {	if (handle == 0) return null;	do {		Control control = getControl (handle);		if (control != null) return control;	} while ((handle = OS.GetParent (handle)) != 0);	return null;}/** * Returns the display which the given thread is the * user-interface thread for, or null if the given thread * is not a user-interface thread for any display. * * @param thread the user-interface thread * @return the display for the given thread */public static synchronized Display findDisplay (Thread thread) {	for (int i=0; i<Displays.length; i++) {		Display display = Displays [i];		if (display != null && display.thread == thread) {			return display;		}	}	return null;}/** * Returns the currently active <code>Shell</code>, or null * if no shell belonging to the currently running application * is active. * * @return the active shell or null * * @exception SWTException <ul> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */public Shell getActiveShell () {	checkDevice ();	Control control = findControl (OS.GetActiveWindow ());	return control != null ? control.getShell () : null;}/** * Returns a rectangle describing the receiver's size and location. * * @return the bounding rectangle * * @exception SWTException <ul> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */public Rectangle getBounds () {	checkDevice ();	if (OS.GetSystemMetrics (OS.SM_CMONITORS) < 2) {		int width = OS.GetSystemMetrics (OS.SM_CXSCREEN);		int height = OS.GetSystemMetrics (OS.SM_CYSCREEN);		return new Rectangle (0, 0, width, height);	}	int x = OS.GetSystemMetrics (OS.SM_XVIRTUALSCREEN);	int y = OS.GetSystemMetrics (OS.SM_YVIRTUALSCREEN);	

⌨️ 快捷键说明

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