?? display.java
字號:
/******************************************************************************* * 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.graphics.*;/** * Instances of this class are responsible for managing the * connection between SWT and the underlying operating * system. Their most important function is to implement * the SWT event loop in terms of the platform event model. * They also provide various methods for accessing information * about the operating system, and have overall control over * the operating system resources which SWT allocates. * <p> * Applications which are built with SWT will <em>almost always</em> * require only a single display. In particular, some platforms * which SWT supports will not allow more than one <em>active</em> * display. In other words, some platforms do not support * creating a new display if one already exists that has not been * sent the <code>dispose()</code> message. * <p> * In SWT, the thread which creates a <code>Display</code> * instance is distinguished as the <em>user-interface thread</em> * for that display. * </p> * The user-interface thread for a particular display has the * following special attributes: * <ul> * <li> * The event loop for that display must be run from the thread. * </li> * <li> * Some SWT API methods (notably, most of the public methods in * <code>Widget</code> and its subclasses), may only be called * from the thread. (To support multi-threaded user-interface * applications, class <code>Display</code> provides inter-thread * communication methods which allow threads other than the * user-interface thread to request that it perform operations * on their behalf.) * </li> * <li> * The thread is not allowed to construct other * <code>Display</code>s until that display has been disposed. * (Note that, this is in addition to the restriction mentioned * above concerning platform support for multiple displays. Thus, * the only way to have multiple simultaneously active displays, * even on platforms which support it, is to have multiple threads.) * </li> * </ul> * Enforcing these attributes allows SWT to be implemented directly * on the underlying operating system's event model. This has * numerous benefits including smaller footprint, better use of * resources, safer memory management, clearer program logic, * better performance, and fewer overall operating system threads * required. The down side however, is that care must be taken * (only) when constructing multi-threaded applications to use the * inter-thread communication mechanisms which this class provides * when required. * </p><p> * All SWT API methods which may only be called from the user-interface * thread are distinguished in their documentation by indicating that * they throw the "<code>ERROR_THREAD_INVALID_ACCESS</code>" * SWT exception. * </p> * <dl> * <dt><b>Styles:</b></dt> * <dd>(none)</dd> * <dt><b>Events:</b></dt> * <dd>Close, Dispose</dd> * </dl> * <p> * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> * @see #syncExec * @see #asyncExec * @see #wake * @see #readAndDispatch * @see #sleep * @see Device#dispose */public class Display extends Device { /** * the handle to the OS message queue * (Warning: This field is platform dependent) */ public MSG msg = new MSG (); /* Windows and Events */ Event [] eventQueue; Callback windowCallback; int windowProc, threadId, processId; TCHAR windowClass; static int WindowClassCount; static final String WindowName = "SWT_Window"; //$NON-NLS-1$ EventTable eventTable, filterTable; /* Widget Table */ int freeSlot; int [] indexTable; Control [] controlTable; final static int GROW_SIZE = 1024; /* Menus */ Menu [] bars, popups; MenuItem [] items; /* * The start value for WM_COMMAND id's. * Windows reserves the values 0..100. * * The SmartPhone SWT resource file reserves * the values 101..107. */ static final int ID_START = 108; /* Filter Hook */ Callback msgFilterCallback; int msgFilterProc, filterHook; MSG hookMsg = new MSG (); boolean ignoreMsgFilter; /* Message Hook */ Callback getMsgCallback, embeddedCallback; int getMsgProc, msgHook, embeddedHwnd, embeddedProc; /* Sync/Async Widget Communication */ Synchronizer synchronizer = new Synchronizer (this); Thread thread; /* Display Shutdown */ Runnable [] disposeList; /* System Tray */ Tray tray; int nextTrayId = 0; /* Timers */ int timerCount; int [] timerIds; Runnable [] timerList; /* Keyboard and Mouse State */ int lastKey, lastAscii, lastMouse; boolean lastVirtual, lastNull, lastDead; byte [] keyboard = new byte [256]; boolean accelKeyHit, mnemonicKeyHit; boolean lockActiveWindow; /* MDI */ boolean ignoreRestoreFocus; Control lastHittestControl; int lastHittest; /* Message Only Window */ Callback messageCallback; int hwndMessage, messageProc; int [] systemFonts; /* System Images Cache */ int errorIcon, infoIcon, questionIcon, warningIcon; /* System Cursors Cache */ Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1]; /* ImageList Cache */ ImageList[] imageList, toolImageList, toolHotImageList, toolDisabledImageList; /* Custom Colors for ChooseColor */ int lpCustColors; /* Display Data */ Object data; String [] keys; Object [] values; /* Key Mappings */ static final int [] [] KeyTable = { /* Keyboard and Mouse Masks */ {OS.VK_MENU, SWT.ALT}, {OS.VK_SHIFT, SWT.SHIFT}, {OS.VK_CONTROL, SWT.CONTROL},// {OS.VK_????, SWT.COMMAND}, /* NOT CURRENTLY USED */ // {OS.VK_LBUTTON, SWT.BUTTON1},// {OS.VK_MBUTTON, SWT.BUTTON3},// {OS.VK_RBUTTON, SWT.BUTTON2}, /* Non-Numeric Keypad Keys */ {OS.VK_UP, SWT.ARROW_UP}, {OS.VK_DOWN, SWT.ARROW_DOWN}, {OS.VK_LEFT, SWT.ARROW_LEFT}, {OS.VK_RIGHT, SWT.ARROW_RIGHT}, {OS.VK_PRIOR, SWT.PAGE_UP}, {OS.VK_NEXT, SWT.PAGE_DOWN}, {OS.VK_HOME, SWT.HOME}, {OS.VK_END, SWT.END}, {OS.VK_INSERT, SWT.INSERT}, /* Virtual and Ascii Keys */ {OS.VK_BACK, SWT.BS}, {OS.VK_RETURN, SWT.CR}, {OS.VK_DELETE, SWT.DEL}, {OS.VK_ESCAPE, SWT.ESC}, {OS.VK_RETURN, SWT.LF}, {OS.VK_TAB, SWT.TAB}, /* Functions Keys */ {OS.VK_F1, SWT.F1}, {OS.VK_F2, SWT.F2}, {OS.VK_F3, SWT.F3}, {OS.VK_F4, SWT.F4}, {OS.VK_F5, SWT.F5}, {OS.VK_F6, SWT.F6}, {OS.VK_F7, SWT.F7}, {OS.VK_F8, SWT.F8}, {OS.VK_F9, SWT.F9}, {OS.VK_F10, SWT.F10}, {OS.VK_F11, SWT.F11}, {OS.VK_F12, SWT.F12}, {OS.VK_F13, SWT.F13}, {OS.VK_F14, SWT.F14}, {OS.VK_F15, SWT.F15}, /* Numeric Keypad Keys */ {OS.VK_MULTIPLY, SWT.KEYPAD_MULTIPLY}, {OS.VK_ADD, SWT.KEYPAD_ADD}, {OS.VK_RETURN, SWT.KEYPAD_CR}, {OS.VK_SUBTRACT, SWT.KEYPAD_SUBTRACT}, {OS.VK_DECIMAL, SWT.KEYPAD_DECIMAL}, {OS.VK_DIVIDE, SWT.KEYPAD_DIVIDE}, {OS.VK_NUMPAD0, SWT.KEYPAD_0}, {OS.VK_NUMPAD1, SWT.KEYPAD_1}, {OS.VK_NUMPAD2, SWT.KEYPAD_2}, {OS.VK_NUMPAD3, SWT.KEYPAD_3}, {OS.VK_NUMPAD4, SWT.KEYPAD_4}, {OS.VK_NUMPAD5, SWT.KEYPAD_5}, {OS.VK_NUMPAD6, SWT.KEYPAD_6}, {OS.VK_NUMPAD7, SWT.KEYPAD_7}, {OS.VK_NUMPAD8, SWT.KEYPAD_8}, {OS.VK_NUMPAD9, SWT.KEYPAD_9},// {OS.VK_????, SWT.KEYPAD_EQUAL}, /* Other keys */ {OS.VK_CAPITAL, SWT.CAPS_LOCK}, {OS.VK_NUMLOCK, SWT.NUM_LOCK}, {OS.VK_SCROLL, SWT.SCROLL_LOCK}, {OS.VK_PAUSE, SWT.PAUSE}, {OS.VK_CANCEL, SWT.BREAK}, {OS.VK_SNAPSHOT, SWT.PRINT_SCREEN},// {OS.VK_????, SWT.HELP}, }; /* Multiple Displays */ static Display Default; static Display [] Displays = new Display [4]; /* Multiple Monitors */ static Monitor[] monitors = null; static int monitorCount = 0; /* Modality */ Shell [] modalShells; Shell modalDialogShell; static boolean TrimEnabled = false; /* Private SWT Window Messages */ static final int SWT_GETACCELCOUNT = OS.WM_APP; static final int SWT_GETACCEL = OS.WM_APP + 1; static final int SWT_KEYMSG = OS.WM_APP + 2; static final int SWT_DESTROY = OS.WM_APP + 3; static final int SWT_RESIZE = OS.WM_APP + 4; static final int SWT_TRAYICONMSG = OS.WM_APP + 5; static int SWT_TASKBARCREATED; /* Package Name */ static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$ /* * This code is intentionally commented. In order * to support CLDC, .class cannot be used because * it does not compile on some Java compilers when * they are targeted for CLDC. */// static {// String name = Display.class.getName ();// int index = name.lastIndexOf ('.');// PACKAGE_PREFIX = name.substring (0, index + 1);// } /* * TEMPORARY CODE. Install the runnable that * gets the current display. This code will * be removed in the future. */ static { DeviceFinder = new Runnable () { public void run () { Device device = getCurrent (); if (device == null) { device = getDefault (); } setDevice (device); } }; } /** TEMPORARY CODE.*/static void setDevice (Device device) { CurrentDevice = device;} /** * Constructs a new instance of this class. * <p> * Note: The resulting display is marked as the <em>current</em> * display. If this is the first display which has been * constructed since the application started, it is also * marked as the <em>default</em> display. * </p> * * @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 #getCurrent * @see #getDefault * @see Widget#checkSubclass * @see Shell */public Display () { this (null);}public Display (DeviceData data) { super (data);}int asciiKey (int key) { if (OS.IsWinCE) return 0; /* Get the current keyboard. */ for (int i=0; i<keyboard.length; i++) keyboard [i] = 0; if (!OS.GetKeyboardState (keyboard)) return 0; /* Translate the key to ASCII or UNICODE using the virtual keyboard */ if (OS.IsUnicode) { char [] result = new char [1]; if (OS.ToUnicode (key, key, keyboard, result, 1, 0) == 1) return result [0]; } else { short [] result = new short [1]; if (OS.ToAscii (key, key, keyboard, result, 0) == 1) return result [0]; } return 0;}/** * Adds the listener to the collection of listeners who will * be notifed when an event of the given type occurs anywhere * in this display. When the event does occur, 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_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 Listener * @see #removeFilter * @see #removeListener * * @since 3.0 */public void addFilter (int eventType, Listener listener) { checkDevice (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (filterTable == null) filterTable = new EventTable (); filterTable.hook (eventType, listener);}/** * 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 display, 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_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 Listener
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -