/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/widgets/Display.d
D | 4714 lines | 2816 code | 269 blank | 1629 comment | 611 complexity | a821669b0ad42c1020d89f2e221b34ff MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Port to the D programming language:
- * Frank Benoit <benoit@tionex.de>
- *******************************************************************************/
- module org.eclipse.swt.widgets.Display;
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.SWTError;
- import org.eclipse.swt.SWTException;
- import org.eclipse.swt.graphics.Color;
- import org.eclipse.swt.graphics.Cursor;
- import org.eclipse.swt.graphics.Device;
- import org.eclipse.swt.graphics.DeviceData;
- import org.eclipse.swt.graphics.Font;
- import org.eclipse.swt.graphics.GC;
- import org.eclipse.swt.graphics.GCData;
- import org.eclipse.swt.graphics.Image;
- import org.eclipse.swt.graphics.ImageData;
- import org.eclipse.swt.graphics.PaletteData;
- import org.eclipse.swt.graphics.Point;
- import org.eclipse.swt.graphics.RGB;
- import org.eclipse.swt.graphics.Rectangle;
- import org.eclipse.swt.graphics.Resource;
- import org.eclipse.swt.internal.ImageList;
- import org.eclipse.swt.internal.Library;
- import org.eclipse.swt.internal.win32.OS;
- import org.eclipse.swt.widgets.Control;
- import org.eclipse.swt.widgets.Dialog;
- import org.eclipse.swt.widgets.Tray;
- import org.eclipse.swt.widgets.Event;
- import org.eclipse.swt.widgets.EventTable;
- import org.eclipse.swt.widgets.Menu;
- import org.eclipse.swt.widgets.MenuItem;
- import org.eclipse.swt.widgets.Synchronizer;
- import org.eclipse.swt.widgets.Monitor;
- import org.eclipse.swt.widgets.Shell;
- import org.eclipse.swt.widgets.Listener;
- import org.eclipse.swt.widgets.Widget;
- import org.eclipse.swt.widgets.TrayItem;
- import java.lang.all;
- import java.lang.Thread;
- /**
- * 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, Settings</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
- * @see <a href="http://www.eclipse.org/swt/snippets/#display">Display snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
- public class Display : Device {
- /**
- * the handle to the OS message queue
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public MSG* msg;
- /* Windows and Events */
- Event [] eventQueue;
- //Callback windowCallback;
- //int windowProc_;
- int threadId;
- StringT windowClass_, windowShadowClass;
- static mixin(GSHARED(`int WindowClassCount;`));
- static const String WindowName = "SWT_Window"; //$NON-NLS-1$
- static const String WindowShadowName = "SWT_WindowShadow"; //$NON-NLS-1$
- EventTable eventTable, filterTable;
- /* Widget Table */
- int freeSlot;
- int [] indexTable;
- Control lastControl, lastGetControl;
- HANDLE lastHwnd;
- HWND lastGetHwnd;
- Control [] controlTable;
- static const int GROW_SIZE = 1024;
- private mixin(GSHARED(`static /+const+/ int SWT_OBJECT_INDEX;`));
- static const bool USE_PROPERTY = !OS.IsWinCE;
- private mixin(GSHARED(`static bool static_this_completed = false;`));
- private static void static_this() {
- if( static_this_completed ){
- return;
- }
- synchronized {
- if( static_this_completed ){
- return;
- }
- static if (USE_PROPERTY) {
- SWT_OBJECT_INDEX = OS.GlobalAddAtom (StrToTCHARz("SWT_OBJECT_INDEX")); //$NON-NLS-1$
- } else {
- SWT_OBJECT_INDEX = 0;
- }
- static_this_StartupInfo ();
- static_this_DeviceFinder ();
- static_this_completed = true;
- }
- }
- /* Startup info */
- private static mixin(GSHARED(`STARTUPINFO* lpStartupInfo;`));
- private static void static_this_StartupInfo (){
- static if (!OS.IsWinCE) {
- lpStartupInfo = new STARTUPINFO ();
- lpStartupInfo.cb = STARTUPINFO.sizeof;
- OS.GetStartupInfo (lpStartupInfo);
- }
- }
- /* XP Themes */
- HTHEME hButtonTheme_, hEditTheme_, hExplorerBarTheme_, hScrollBarTheme_, hTabTheme_;
- static const wchar [] BUTTON = "BUTTON\0"w;
- static const wchar [] EDIT = "EDIT\0"w;
- static const wchar [] EXPLORER = "EXPLORER\0"w;
- static const wchar [] EXPLORERBAR = "EXPLORERBAR\0"w;
- static const wchar [] SCROLLBAR = "SCROLLBAR\0"w;
- static const wchar [] LISTVIEW = "LISTVIEW\0"w;
- static const wchar [] TAB = "TAB\0"w;
- static const wchar [] TREEVIEW = "TREEVIEW\0"w;
- /* Focus */
- int focusEvent;
- Control focusControl;
- /* 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 const int ID_START = 108;
- /* Filter Hook */
- //Callback msgFilterCallback;
- //int msgFilterProc_,
- HHOOK filterHook;
- bool runDragDrop = true, dragCancelled = false;
- MSG* hookMsg;
- /* Idle Hook */
- //Callback foregroundIdleCallback;
- //int foregroundIdleProc_;
- HHOOK idleHook;
- /* Message Hook and Embedding */
- bool ignoreNextKey;
- //Callback getMsgCallback, embeddedCallback;
- int getMsgProc_;
- HHOOK msgHook;
- HWND embeddedHwnd;
- int embeddedProc_;
- static const String AWT_WINDOW_CLASS = "SunAwtWindow";
- static const short [] ACCENTS = [ cast(short) '~', '`', '\'', '^', '"'];
- /* Sync/Async Widget Communication */
- Synchronizer synchronizer;
- bool runMessages = true, runMessagesInIdle = false, runMessagesInMessageProc = true;
- static const String RUN_MESSAGES_IN_IDLE_KEY = "org.eclipse.swt.internal.win32.runMessagesInIdle"; //$NON-NLS-1$
- static const String RUN_MESSAGES_IN_MESSAGE_PROC_KEY = "org.eclipse.swt.internal.win32.runMessagesInMessageProc"; //$NON-NLS-1$
- Thread thread;
- /* Display Shutdown */
- Runnable [] disposeList;
- /* System Tray */
- Tray tray;
- int nextTrayId;
- /* Timers */
- int /*long*/ [] timerIds;
- Runnable [] timerList;
- int /*long*/ nextTimerId = SETTINGS_ID + 1;
- static const int SETTINGS_ID = 100;
- static const int SETTINGS_DELAY = 2000;
- /* Keyboard and Mouse */
- RECT* clickRect;
- int clickCount, lastTime, lastButton;
- HWND lastClickHwnd;
- int scrollRemainder;
- int lastKey, lastAscii, lastMouse;
- bool lastVirtual, lastNull, lastDead;
- ubyte [256] keyboard;
- bool accelKeyHit, mnemonicKeyHit;
- bool lockActiveWindow, captureChanged, xMouse;
- /* Tool Tips */
- int nextToolTipId;
- /* MDI */
- bool ignoreRestoreFocus;
- Control lastHittestControl;
- int lastHittest;
- /* Message Only Window */
- HWND hwndMessage;
- /* System Resources */
- LOGFONT* lfSystemFont;
- Font systemFont;
- Image errorImage, infoImage, questionImage, warningIcon;
- Cursor [] cursors;
- Resource [] resources;
- static const int RESOURCE_SIZE = 1 + 4 + SWT.CURSOR_HAND + 1;
- /* ImageList Cache */
- ImageList[] imageList, toolImageList, toolHotImageList, toolDisabledImageList;
- /* Custom Colors for ChooseColor */
- COLORREF* lpCustColors;
- /* Sort Indicators */
- Image upArrow, downArrow;
- /* Table */
- char [] tableBuffer;
- NMHDR* hdr;
- NMLVDISPINFO* plvfi;
- HWND hwndParent;
- int columnCount;
- bool [] columnVisible;
- /* Resize and move recursion */
- int resizeCount;
- static const int RESIZE_LIMIT = 4;
- /* Display Data */
- Object data;
- String [] keys;
- Object [] values;
- /* Key Mappings */
- static const 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 mixin(GSHARED(`Display Default;`));
- static mixin(GSHARED(`Display [] Displays;`));
- /* Multiple Monitors */
- org.eclipse.swt.widgets.Monitor.Monitor[] monitors = null;
- int monitorCount = 0;
- /* Modality */
- Shell [] modalShells;
- Dialog modalDialog;
- static mixin(GSHARED(`bool TrimEnabled = false;`));
- /* Private SWT Window Messages */
- static const int SWT_GETACCELCOUNT = OS.WM_APP;
- static const int SWT_GETACCEL = OS.WM_APP + 1;
- static const int SWT_KEYMSG = OS.WM_APP + 2;
- static const int SWT_DESTROY = OS.WM_APP + 3;
- static const int SWT_TRAYICONMSG = OS.WM_APP + 4;
- static const int SWT_NULL = OS.WM_APP + 5;
- static const int SWT_RUNASYNC = OS.WM_APP + 6;
- static mixin(GSHARED(`int SWT_TASKBARCREATED;`));
- static mixin(GSHARED(`int SWT_RESTORECARET;`));
- static mixin(GSHARED(`int DI_GETDRAGIMAGE;`));
- /* Workaround for Adobe Reader 7.0 */
- int hitCount;
- /* Package Name */
- static const 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.
- */
- private static void static_this_DeviceFinder () {
- DeviceFinder = new class() Runnable {
- public void run () {
- Device device = getCurrent ();
- if (device is null) {
- device = getDefault ();
- }
- setDevice (device);
- }
- };
- }
- /*
- * TEMPORARY CODE.
- */
- static void setDevice (Device device) {
- static_this();
- 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 called from a thread that already created an existing display</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 this () {
- this (null);
- }
- /**
- * Constructs a new instance of this class using the parameter.
- *
- * @param data the device data
- */
- public this (DeviceData data) {
- static_this();
- msg = new MSG();
- hookMsg = new MSG();
- super (data);
- synchronizer = new Synchronizer (this);
- cursors = new Cursor [SWT.CURSOR_HAND + 1];
- }
- Control _getFocusControl () {
- return findControl (OS.GetFocus ());
- }
- void addBar (Menu menu) {
- if (bars is null) bars = new Menu [4];
- int length_ = bars.length;
- for (int i=0; i<length_; i++) {
- if (bars [i] is menu) return;
- }
- int index = 0;
- while (index < length_) {
- if (bars [index] is null) break;
- index++;
- }
- if (index is length_) {
- Menu [] newBars = new Menu [length_ + 4];
- System.arraycopy (bars, 0, newBars, 0, length_);
- bars = newBars;
- }
- bars [index] = menu;
- }
- void addControl (HANDLE handle, Control control) {
- if (handle is null) return;
- if (freeSlot is -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;
- }
- static if (USE_PROPERTY) {
- OS.SetProp (handle, cast(wchar*)SWT_OBJECT_INDEX, cast(void*) freeSlot + 1);
- } else {
- OS.SetWindowLongPtr (handle, OS.GWLP_USERDATA, freeSlot + 1);
- }
- int oldSlot = freeSlot;
- freeSlot = indexTable [oldSlot];
- indexTable [oldSlot] = -2;
- controlTable [oldSlot] = control;
- }
- /**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs anywhere
- * in a widget. The event type is one of the event constants
- * defined in class <code>SWT</code>. When the event does occur,
- * the listener is notified by sending it the <code>handleEvent()</code>
- * message.
- * <p>
- * Setting the type of an event to <code>SWT.None</code> from
- * within the <code>handleEvent()</code> method can be used to
- * change the event type and stop subsequent Java listeners
- * from running. Because event filters run before other listeners,
- * event filters can both block other listeners and set arbitrary
- * fields within an event. For this reason, event filters are both
- * powerful and dangerous. They should generally be avoided for
- * performance, debugging and code maintenance reasons.
- * </p>
- *
- * @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 SWT
- * @see #removeFilter
- * @see #removeListener
- *
- * @since 3.0
- */
- public void addFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable is null) filterTable = new EventTable ();
- filterTable.hook (eventType, listener);
- }
- /**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- * 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
- * @see SWT
- * @see #removeListener
- *
- * @since 2.0
- */
- public void addListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable is null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
- }
- void addMenuItem (MenuItem item) {
- if (items is null) items = new MenuItem [64];
- for (int i=0; i<items.length; i++) {
- if (items [i] is 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 is null) popups = new Menu [4];
- int length_ = popups.length;
- for (int i=0; i<length_; i++) {
- if (popups [i] is menu) return;
- }
- int index = 0;
- while (index < length_) {
- if (popups [index] is null) break;
- index++;
- }
- if (index is length_) {
- Menu [] newPopups = new Menu [length_ + 4];
- System.arraycopy (popups, 0, newPopups, 0, length_);
- popups = newPopups;
- }
- popups [index] = menu;
- }
- int asciiKey (int key) {
- static if (OS.IsWinCE) return 0;
- /* Get the current keyboard. */
- for (int i=0; i<keyboard.length; i++) keyboard [i] = 0;
- if (!OS.GetKeyboardState (keyboard.ptr)) return 0;
- /* Translate the key to ASCII or UNICODE using the virtual keyboard */
- static if (OS.IsUnicode) {
- wchar result;
- if (OS.ToUnicode (key, key, keyboard.ptr, &result, 1, 0) is 1) return result;
- } else {
- short [] result = new short [1];
- if (OS.ToAscii (key, key, keyboard, result, 0) is 1) return result [0];
- }
- return 0;
- }
- /**
- * 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. Specifying <code>null</code> as the
- * runnable simply wakes the user-interface thread when run.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #syncExec
- */
- public void asyncExec (Runnable runnable) {
- synchronized (Device.classinfo) {
- 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);
- }
- override protected void checkDevice () {
- if (thread is null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (thread !is Thread.currentThread ()) {
- /*
- * Bug in IBM JVM 1.6. For some reason, under
- * conditions that are yet to be full understood,
- * Thread.currentThread() is either returning null
- * or a different instance from the one that was
- * saved when the Display was created. This is
- * possibly a JIT problem because modifying this
- * method to print logging information when the
- * error happens seems to fix the problem. The
- * fix is to use operating system calls to verify
- * that the current thread is not the Display thread.
- *
- * NOTE: Despite the fact that Thread.currentThread()
- * is used in other places, the failure has not been
- * observed in all places where it is called.
- */
- if (threadId !is OS.GetCurrentThreadId ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- }
- static void checkDisplay (Thread thread, bool multiple) {
- synchronized (Device.classinfo) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] !is null) {
- if (!multiple) SWT.error (SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]"); //$NON-NLS-1$
- if (Displays [i].thread is thread) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
- }
- }
- void clearModal (Shell shell) {
- if (modalShells is null) return;
- int index = 0, length_ = modalShells.length;
- while (index < length_) {
- if (modalShells [index] is shell) break;
- if (modalShells [index] is null) return;
- index++;
- }
- if (index is length_) return;
- System.arraycopy (modalShells, index + 1, modalShells, index, --length_ - index);
- modalShells [length_] = null;
- if (index is 0 && modalShells [0] is null) modalShells = null;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
- }
- int controlKey (int key) {
- int upper = cast(int)OS.CharUpper (cast(wchar*) 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
- */
- override protected void create (DeviceData data) {
- checkSubclass ();
- checkDisplay (thread = Thread.currentThread (), true);
- createDisplay (data);
- register (this);
- if (Default is null) Default = this;
- }
- void createDisplay (DeviceData data) {
- }
- static HBITMAP create32bitDIB (Image image) {
- static_this();
- int transparentPixel = -1, alpha = -1;
- HBITMAP hMask;
- HBITMAP hBitmap;
- byte[] alphaData = null;
- switch (image.type) {
- case SWT.ICON:
- ICONINFO info;
- OS.GetIconInfo (image.handle, &info);
- hBitmap = info.hbmColor;
- hMask = info.hbmMask;
- break;
- case SWT.BITMAP:
- ImageData data = image.getImageData ();
- hBitmap = image.handle;
- alpha = data.alpha;
- alphaData = data.alphaData;
- transparentPixel = data.transparentPixel;
- break;
- default:
- }
- BITMAP bm;
- OS.GetObject (hBitmap, BITMAP.sizeof, &bm);
- int imgWidth = bm.bmWidth;
- int imgHeight = bm.bmHeight;
- auto hDC = OS.GetDC (null);
- auto srcHdc = OS.CreateCompatibleDC (hDC);
- auto oldSrcBitmap = OS.SelectObject (srcHdc, hBitmap);
- auto memHdc = OS.CreateCompatibleDC (hDC);
- BITMAPINFOHEADER bmiHeader;
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = imgWidth;
- bmiHeader.biHeight = -imgHeight;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = cast(short)32;
- bmiHeader.biCompression = OS.BI_RGB;
- byte [] bmi = new byte [BITMAPINFOHEADER.sizeof];
- bmi[ 0 .. BITMAPINFOHEADER.sizeof ] = (cast(byte*)&bmiHeader)[ 0 .. BITMAPINFOHEADER.sizeof ];
- void* pBits;
- auto memDib = OS.CreateDIBSection (null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, &pBits, null, 0);
- if (memDib is null) SWT.error (SWT.ERROR_NO_HANDLES);
- auto oldMemBitmap = OS.SelectObject (memHdc, memDib);
- BITMAP dibBM;
- OS.GetObject (memDib, BITMAP.sizeof, &dibBM);
- int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight;
- OS.BitBlt (memHdc, 0, 0, imgWidth, imgHeight, srcHdc, 0, 0, OS.SRCCOPY);
- byte red = 0, green = 0, blue = 0;
- if (transparentPixel !is -1) {
- if (bm.bmBitsPixel <= 8) {
- byte [4] color;
- OS.GetDIBColorTable (srcHdc, transparentPixel, 1, cast(RGBQUAD*)color.ptr);
- blue = color [0];
- green = color [1];
- red = color [2];
- } else {
- switch (bm.bmBitsPixel) {
- case 16:
- blue = cast(byte)((transparentPixel & 0x1F) << 3);
- green = cast(byte)((transparentPixel & 0x3E0) >> 2);
- red = cast(byte)((transparentPixel & 0x7C00) >> 7);
- break;
- case 24:
- blue = cast(byte)((transparentPixel & 0xFF0000) >> 16);
- green = cast(byte)((transparentPixel & 0xFF00) >> 8);
- red = cast(byte)(transparentPixel & 0xFF);
- break;
- case 32:
- blue = cast(byte)((transparentPixel & 0xFF000000) >>> 24);
- green = cast(byte)((transparentPixel & 0xFF0000) >> 16);
- red = cast(byte)((transparentPixel & 0xFF00) >> 8);
- break;
- default:
- }
- }
- }
- byte [] srcData = (cast(byte*)pBits)[ 0 .. sizeInBytes].dup;
- if (hMask !is null) {
- OS.SelectObject(srcHdc, hMask);
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- if (OS.GetPixel(srcHdc, x, y) !is 0) {
- srcData [dp + 0] = srcData [dp + 1] = srcData [dp + 2] = srcData[dp + 3] = cast(byte)0;
- } else {
- srcData[dp + 3] = cast(byte)0xFF;
- }
- dp += 4;
- }
- }
- } else if (alpha !is -1) {
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- srcData [dp + 3] = cast(byte)alpha;
- if (srcData [dp + 3] is 0) srcData [dp + 0] = srcData [dp + 1] = srcData [dp + 2] = 0;
- dp += 4;
- }
- }
- } else if (alphaData !is null) {
- for (int y = 0, dp = 0, ap = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- srcData [dp + 3] = alphaData [ap++];
- if (srcData [dp + 3] is 0) srcData [dp + 0] = srcData [dp + 1] = srcData [dp + 2] = 0;
- dp += 4;
- }
- }
- } else if (transparentPixel !is -1) {
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- if (srcData [dp] is blue && srcData [dp + 1] is green && srcData [dp + 2] is red) {
- srcData [dp + 0] = srcData [dp + 1] = srcData [dp + 2] = srcData [dp + 3] = cast(byte)0;
- } else {
- srcData [dp + 3] = cast(byte)0xFF;
- }
- dp += 4;
- }
- }
- } else {
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- srcData [dp + 3] = cast(byte)0xFF;
- dp += 4;
- }
- }
- }
- (cast(byte*)pBits)[ 0 .. sizeInBytes] = srcData[];
- OS.SelectObject (srcHdc, oldSrcBitmap);
- OS.SelectObject (memHdc, oldMemBitmap);
- OS.DeleteObject (srcHdc);
- OS.DeleteObject (memHdc);
- OS.ReleaseDC (null, hDC);
- if (hBitmap !is image.handle && hBitmap !is null) OS.DeleteObject (hBitmap);
- if (hMask !is null) OS.DeleteObject (hMask);
- return memDib;
- }
- static HBITMAP create32bitDIB (HBITMAP hBitmap, int alpha, byte [] alphaData, int transparentPixel) {
- static_this();
- BITMAP bm;
- OS.GetObject (hBitmap, BITMAP.sizeof, &bm);
- int imgWidth = bm.bmWidth;
- int imgHeight = bm.bmHeight;
- auto hDC = OS.GetDC (null);
- auto srcHdc = OS.CreateCompatibleDC (hDC);
- auto oldSrcBitmap = OS.SelectObject (srcHdc, hBitmap);
- auto memHdc = OS.CreateCompatibleDC (hDC);
- BITMAPINFOHEADER bmiHeader;
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = imgWidth;
- bmiHeader.biHeight = -imgHeight;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = cast(short)32;
- bmiHeader.biCompression = OS.BI_RGB;
- byte [] bmi = (cast(byte*)&bmiHeader)[ 0 .. BITMAPINFOHEADER.sizeof];
- void* pBits;
- auto memDib = OS.CreateDIBSection (null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, &pBits, null, 0);
- if (memDib is null) SWT.error (SWT.ERROR_NO_HANDLES);
- auto oldMemBitmap = OS.SelectObject (memHdc, memDib);
- BITMAP dibBM;
- OS.GetObject (memDib, BITMAP.sizeof, &dibBM);
- int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight;
- OS.BitBlt (memHdc, 0, 0, imgWidth, imgHeight, srcHdc, 0, 0, OS.SRCCOPY);
- byte red = 0, green = 0, blue = 0;
- if (transparentPixel !is -1) {
- if (bm.bmBitsPixel <= 8) {
- byte [4] color;
- OS.GetDIBColorTable (srcHdc, transparentPixel, 1, cast(RGBQUAD*)color.ptr);
- blue = color [0];
- green = color [1];
- red = color [2];
- } else {
- switch (bm.bmBitsPixel) {
- case 16:
- blue = cast(byte)((transparentPixel & 0x1F) << 3);
- green = cast(byte)((transparentPixel & 0x3E0) >> 2);
- red = cast(byte)((transparentPixel & 0x7C00) >> 7);
- break;
- case 24:
- blue = cast(byte)((transparentPixel & 0xFF0000) >> 16);
- green = cast(byte)((transparentPixel & 0xFF00) >> 8);
- red = cast(byte)(transparentPixel & 0xFF);
- break;
- case 32:
- blue = cast(byte)((transparentPixel & 0xFF000000) >>> 24);
- green = cast(byte)((transparentPixel & 0xFF0000) >> 16);
- red = cast(byte)((transparentPixel & 0xFF00) >> 8);
- break;
- default:
- }
- }
- }
- OS.SelectObject (srcHdc, oldSrcBitmap);
- OS.SelectObject (memHdc, oldMemBitmap);
- OS.DeleteObject (srcHdc);
- OS.DeleteObject (memHdc);
- OS.ReleaseDC (null, hDC);
- byte [] srcData = (cast(byte*)pBits)[ 0 .. sizeInBytes ].dup;
- if (alpha !is -1) {
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- srcData [dp + 3] = cast(byte)alpha;
- dp += 4;
- }
- }
- } else if (alphaData !is null) {
- for (int y = 0, dp = 0, ap = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- srcData [dp + 3] = alphaData [ap++];
- dp += 4;
- }
- }
- } else if (transparentPixel !is -1) {
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- if (srcData [dp] is blue && srcData [dp + 1] is green && srcData [dp + 2] is red) {
- srcData [dp + 3] = cast(byte)0;
- } else {
- srcData [dp + 3] = cast(byte)0xFF;
- }
- dp += 4;
- }
- }
- }
- (cast(byte*)pBits)[ 0 .. sizeInBytes ] = srcData[];
- return memDib;
- }
- static Image createIcon (Image image) {
- static_this();
- Device device = image.getDevice ();
- ImageData data = image.getImageData ();
- if (data.alpha is -1 && data.alphaData is null) {
- ImageData mask = data.getTransparencyMask ();
- return new Image (device, data, mask);
- }
- int width = data.width, height = data.height;
- HBITMAP hMask, hBitmap;
- auto hDC = device.internal_new_GC (null);
- auto dstHdc = OS.CreateCompatibleDC (hDC);
- HBITMAP oldDstBitmap;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
- hBitmap = Display.create32bitDIB (image.handle, data.alpha, data.alphaData, data.transparentPixel);
- hMask = OS.CreateBitmap (width, height, 1, 1, null);
- oldDstBitmap = OS.SelectObject (dstHdc, hMask);
- OS.PatBlt (dstHdc, 0, 0, width, height, OS.BLACKNESS);
- } else {
- hMask = Display.createMaskFromAlpha (data, width, height);
- /* Icons need black pixels where the mask is transparent */
- hBitmap = OS.CreateCompatibleBitmap (hDC, width, height);
- oldDstBitmap = OS.SelectObject (dstHdc, hBitmap);
- auto srcHdc = OS.CreateCompatibleDC (hDC);
- auto oldSrcBitmap = OS.SelectObject (srcHdc, image.handle);
- OS.PatBlt (dstHdc, 0, 0, width, height, OS.BLACKNESS);
- OS.BitBlt (dstHdc, 0, 0, width, height, srcHdc, 0, 0, OS.SRCINVERT);
- OS.SelectObject (srcHdc, hMask);
- OS.BitBlt (dstHdc, 0, 0, width, height, srcHdc, 0, 0, OS.SRCAND);
- OS.SelectObject (srcHdc, image.handle);
- OS.BitBlt (dstHdc, 0, 0, width, height, srcHdc, 0, 0, OS.SRCINVERT);
- OS.SelectObject (srcHdc, oldSrcBitmap);
- OS.DeleteDC (srcHdc);
- }
- OS.SelectObject (dstHdc, oldDstBitmap);
- OS.DeleteDC (dstHdc);
- device.internal_dispose_GC (hDC, null);
- ICONINFO info;
- info.fIcon = true;
- info.hbmColor = hBitmap;
- info.hbmMask = hMask;
- auto hIcon = OS.CreateIconIndirect (&info);
- if (hIcon is null) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.DeleteObject (hBitmap);
- OS.DeleteObject (hMask);
- return Image.win32_new (device, SWT.ICON, hIcon);
- }
- static HBITMAP createMaskFromAlpha (ImageData data, int destWidth, int destHeight) {
- static_this();
- int srcWidth = data.width;
- int srcHeight = data.height;
- ImageData mask = ImageData.internal_new (srcWidth, srcHeight, 1,
- new PaletteData([new RGB (0, 0, 0), new RGB (0xff, 0xff, 0xff)]),
- 2, null, 1, null, null, -1, -1, -1, 0, 0, 0, 0);
- int ap = 0;
- for (int y = 0; y < mask.height; y++) {
- for (int x = 0; x < mask.width; x++) {
- mask.setPixel (x, y, (data.alphaData [ap++] & 0xff) <= 127 ? 1 : 0);
- }
- }
- auto hMask = OS.CreateBitmap (srcWidth, srcHeight, 1, 1, mask.data.ptr);
- if (srcWidth !is destWidth || srcHeight !is destHeight) {
- auto hdc = OS.GetDC (null);
- auto hdc1 = OS.CreateCompatibleDC (hdc);
- OS.SelectObject (hdc1, hMask);
- auto hdc2 = OS.CreateCompatibleDC (hdc);
- auto hMask2 = OS.CreateBitmap (destWidth, destHeight, 1, 1, null);
- OS.SelectObject (hdc2, hMask2);
- static if (!OS.IsWinCE) OS.SetStretchBltMode(hdc2, OS.COLORONCOLOR);
- OS.StretchBlt (hdc2, 0, 0, destWidth, destHeight, hdc1, 0, 0, srcWidth, srcHeight, OS.SRCCOPY);
- OS.DeleteDC (hdc1);
- OS.DeleteDC (hdc2);
- OS.ReleaseDC (null, hdc);
- OS.DeleteObject(hMask);
- hMask = hMask2;
- }
- return hMask;
- }
- static void deregister (Display display) {
- synchronized (Device.classinfo) {
- for (int i=0; i<Displays.length; i++) {
- if (display is 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 Device#dispose
- * @see #release
- */
- override protected void destroy () {
- if (this is 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. Specifying a <code>null</code> runnable
- * is ignored.
- *
- * @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 is null) disposeList = new Runnable [4];
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] is null) {
- disposeList [i] = runnable;
- return;
- }
- }
- Runnable [] newDisposeList = new Runnable [disposeList.length + 4];
- SimpleType!(Runnable).arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);
- newDisposeList [disposeList.length] = runnable;
- disposeList = newDisposeList;
- }
- void drawMenuBars () {
- if (bars is null) return;
- for (int i=0; i<bars.length; i++) {
- Menu menu = bars [i];
- if (menu !is null && !menu.isDisposed ()) menu.update ();
- }
- bars = null;
- }
- private static extern(Windows) int embeddedFunc (HWND hwnd, int msg, int wParam, int lParam) {
- switch (msg) {
- case SWT_KEYMSG: {
- MSG* keyMsg = cast(MSG*)lParam;
- OS.TranslateMessage (keyMsg);
- OS.DispatchMessage (keyMsg);
- auto hHeap = OS.GetProcessHeap ();
- OS.HeapFree (hHeap, 0, cast(void*)lParam);
- break;
- }
- case SWT_DESTROY: {
- OS.DestroyWindow (hwnd);
- //if (embeddedCallback !is null) embeddedCallback.dispose ();
- //if (getMsgCallback !is null) getMsgCallback.dispose ();
- //embeddedCallback = getMsgCallback = null;
- //embeddedProc_ = getMsgProc_ = 0;
- break;
- }
- default:
- }
- 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 SWT#error(int)
- */
- void error (int code) {
- SWT.error (code);
- }
- bool filterEvent (Event event) {
- if (filterTable !is null) filterTable.sendEvent (event);
- return false;
- }
- bool filters (int eventType) {
- if (filterTable is null) return false;
- return filterTable.hooks (eventType);
- }
- bool filterMessage (MSG* msg) {
- int message = msg.message;
- if (OS.WM_KEYFIRST <= message && message <= OS.WM_KEYLAST) {
- Control control = findControl (msg.hwnd);
- if (control !is null) {
- if (translateAccelerator (msg, control) || translateMnemonic (msg, control) || translateTraversal (msg, control)) {
- lastAscii = lastKey = 0;
- lastVirtual = lastNull = lastDead = false;
- return true;
- }
- }
- }
- return false;
- }
- Control findControl (HANDLE handle) {
- if (handle is null) return null;
- HWND hwndOwner = null;
- do {
- Control control = getControl (handle);
- if (control !is null) return control;
- hwndOwner = OS.GetWindow (handle, OS.GW_OWNER);
- handle = OS.GetParent (handle);
- } while (handle !is null && handle !is hwndOwner);
- return null;
- }
- /**
- * 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.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @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 (HANDLE handle) {
- checkDevice ();
- return getControl (handle);
- }
- /**
- * Given the operating system handle for a widget,
- * and widget-specific id, returns the instance of
- * the <code>Widget</code> subclass which represents
- * the handle/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT widget that the handle/id pair 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>
- *
- * @since 3.1
- */
- public Widget findWidget (HANDLE handle, int id) {
- checkDevice ();
- //TODO - should ids be long
- Control control = getControl (handle);
- return control !is null ? control.findItem (cast(HANDLE) id) : null;
- }
- /**
- * Given a widget and a widget-specific id, returns the
- * instance of the <code>Widget</code> subclass which represents
- * the widget/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- *
- * @param widget the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT subwidget (usually an item) that the widget/id pair 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>
- *
- * @since 3.3
- */
- public Widget findWidget (Widget widget, int /*long*/ id) {
- checkDevice ();
- //TODO - should ids be long
- if (cast(Control)widget) {
- return findWidget ((cast(Control) widget).handle, id);
- }
- return null;
- }
- private static extern(Windows) int foregroundIdleProcFunc (int code, uint wParam, int lParam) {
- auto d = Display.getCurrent();
- return d.foregroundIdleProc( code, wParam, lParam );
- }
- int foregroundIdleProc (int code, int wParam, int lParam) {
- if (code >= 0) {
- if (runMessages && getMessageCount () !is 0) {
- if (runMessagesInIdle) {
- if (runMessagesInMessageProc) {
- OS.PostMessage (hwndMessage, SWT_RUNASYNC, 0, 0);
- } else {
- runAsyncMessages (false);
- }
- }
- wakeThread ();
- }
- }
- return OS.CallNextHookEx (idleHook, code, wParam, lParam);
- }
- /**
- * 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. Specifying
- * <code>null</code> as the thread will return <code>null</code>
- * for the display.
- *
- * @param thread the user-interface thread
- * @return the display for the given thread
- */
- public static Display findDisplay (Thread thread) {
- static_this();
- synchronized (Device.classinfo) {
- for (int i=0; i<Displays.length; i++) {
- Display display = Displays [i];
- if (display !is null && display.thread is 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 !is null ? control.getShell () : null;
- }
- /**
- * Returns a rectangle describing the receiver's size and location. Note that
- * on multi-monitor systems the origin can be negative.
- *
- * @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>
- */
- override 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_YVIRTUALSCR…
Large files files are truncated, but you can click here to view the full file