?? decorations.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.win32.*;import org.eclipse.swt.*;import org.eclipse.swt.graphics.*;/** * Instances of this class provide the appearance and * behavior of <code>Shells</code>, but are not top * level shells or dialogs. Class <code>Shell</code> * shares a significant amount of code with this class, * and is a subclass. * <p> * IMPORTANT: This class was intended to be abstract and * should <em>never</em> be referenced or instantiated. * Instead, the class <code>Shell</code> should be used. * </p> * <p> * Instances are always displayed in one of the maximized, * minimized or normal states: * <ul> * <li> * When an instance is marked as <em>maximized</em>, the * window manager will typically resize it to fill the * entire visible area of the display, and the instance * is usually put in a state where it can not be resized * (even if it has style <code>RESIZE</code>) until it is * no longer maximized. * </li><li> * When an instance is in the <em>normal</em> state (neither * maximized or minimized), its appearance is controlled by * the style constants which were specified when it was created * and the restrictions of the window manager (see below). * </li><li> * When an instance has been marked as <em>minimized</em>, * its contents (client area) will usually not be visible, * and depending on the window manager, it may be * "iconified" (that is, replaced on the desktop by a small * simplified representation of itself), relocated to a * distinguished area of the screen, or hidden. Combinations * of these changes are also possible. * </li> * </ul> * </p> * Note: The styles supported by this class must be treated * as <em>HINT</em>s, since the window manager for the * desktop on which the instance is visible has ultimate * control over the appearance and behavior of decorations. * For example, some window managers only support resizable * windows and will always assume the RESIZE style, even if * it is not set. * <dl> * <dt><b>Styles:</b></dt> * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL</dd> * <dt><b>Events:</b></dt> * <dd>(none)</dd> * </dl> * Class <code>SWT</code> provides two "convenience constants" * for the most commonly required style combinations: * <dl> * <dt><code>SHELL_TRIM</code></dt> * <dd> * the result of combining the constants which are required * to produce a typical application top level shell: (that * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>) * </dd> * <dt><code>DIALOG_TRIM</code></dt> * <dd> * the result of combining the constants which are required * to produce a typical application dialog shell: (that * is, <code>TITLE | CLOSE | BORDER</code>) * </dd> * </dl> * <p> * IMPORTANT: This class is intended to be subclassed <em>only</em> * within the SWT implementation. * </p> * * @see #getMinimized * @see #getMaximized * @see Shell * @see SWT */public class Decorations extends Canvas { Image image, smallImage, largeImage; Image [] images; Menu menuBar; Menu [] menus; Control savedFocus; Button defaultButton, saveDefault; int swFlags, hAccel, nAccel;/** * Prevents uninitialized instances from being created outside the package. */Decorations () {}/** * 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 composite control which will be the parent of the new instance (cannot be null) * @param style the style of control 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#BORDER * @see SWT#CLOSE * @see SWT#MIN * @see SWT#MAX * @see SWT#RESIZE * @see SWT#TITLE * @see SWT#NO_TRIM * @see SWT#SHELL_TRIM * @see SWT#DIALOG_TRIM * @see SWT#ON_TOP * @see SWT#TOOL * @see Widget#checkSubclass * @see Widget#getStyle */public Decorations (Composite parent, int style) { super (parent, checkStyle (style));}void addMenu (Menu menu) { if (menus == null) menus = new Menu [4]; for (int i=0; i<menus.length; i++) { if (menus [i] == null) { menus [i] = menu; return; } } Menu [] newMenus = new Menu [menus.length + 4]; newMenus [menus.length] = menu; System.arraycopy (menus, 0, newMenus, 0, menus.length); menus = newMenus;}void bringToTop () { /* * This code is intentionally commented. On some platforms, * the ON_TOP style creates a shell that will stay on top * of every other shell on the desktop. Using SetWindowPos () * with HWND_TOP caused problems on Windows 98 so this code is * commented out until this functionality is specified and * the problems are fixed. */// if ((style & SWT.ON_TOP) != 0) {// int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE; // OS.SetWindowPos (handle, OS.HWND_TOP, 0, 0, 0, 0, flags);// } else { OS.BringWindowToTop (handle);// }}static int checkStyle (int style) { if (OS.IsWinCE) { /* * Feature in WinCE PPC. WS_MINIMIZEBOX or WS_MAXIMIZEBOX * are not supposed to be used. If they are, the result * is a button which does not repaint correctly. The fix * is to remove this style. */ if ((style & SWT.MIN) != 0) style &= ~SWT.MIN; if ((style & SWT.MAX) != 0) style &= ~SWT.MAX; return style; } /* * If either WS_MINIMIZEBOX or WS_MAXIMIZEBOX are set, * we must also set WS_SYSMENU or the buttons will not * appear. */ if ((style & (SWT.MIN | SWT.MAX)) != 0) style |= SWT.CLOSE; /* * Both WS_SYSMENU and WS_CAPTION must be set in order * to for the system menu to appear. */ if ((style & SWT.CLOSE) != 0) style |= SWT.TITLE; /* * Bug in Windows. The WS_CAPTION style must be * set when the window is resizable or it does not * draw properly. */ /* * This code is intentionally commented. It seems * that this problem originally in Windows 3.11, * has been fixed in later versions. Because the * exact nature of the drawing problem is unknown, * keep the commented code around in case it comes * back. */// if ((style & SWT.RESIZE) != 0) style |= SWT.TITLE; return style;}protected void checkSubclass () { if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);}int callWindowProc (int msg, int wParam, int lParam) { return OS.DefMDIChildProc (handle, msg, wParam, lParam);}Control computeTabGroup () { return this;}Control computeTabRoot () { return this;}public Rectangle computeTrim (int x, int y, int width, int height) { checkWidget (); /* Get the size of the trimmings */ RECT rect = new RECT (); OS.SetRect (rect, x, y, x + width, y + height); int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); boolean hasMenu = OS.IsWinCE ? false : OS.GetMenu (handle) != 0; OS.AdjustWindowRectEx (rect, bits, hasMenu, OS.GetWindowLong (handle, OS.GWL_EXSTYLE)); /* Get the size of the scroll bars */ if (horizontalBar != null) rect.bottom += OS.GetSystemMetrics (OS.SM_CYHSCROLL); if (verticalBar != null) rect.right += OS.GetSystemMetrics (OS.SM_CXVSCROLL); /* Get the height of the menu bar */ if (hasMenu) { RECT testRect = new RECT (); OS.SetRect (testRect, 0, 0, rect.right - rect.left, rect.bottom - rect.top); OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, testRect); while ((testRect.bottom - testRect.top) < height) { rect.top -= OS.GetSystemMetrics (OS.SM_CYMENU) - OS.GetSystemMetrics (OS.SM_CYBORDER); OS.SetRect(testRect, 0, 0, rect.right - rect.left, rect.bottom - rect.top); OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, testRect); } } return new Rectangle (rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);}void createAccelerators () { hAccel = nAccel = 0; int maxAccel = 0; MenuItem [] items = display.items; if (menuBar == null || items == null) { if (!OS.IsPPC) return; maxAccel = 1; } else { maxAccel = OS.IsPPC ? items.length + 1 : items.length; } ACCEL accel = new ACCEL (); byte [] buffer1 = new byte [ACCEL.sizeof]; byte [] buffer2 = new byte [maxAccel * ACCEL.sizeof]; if (menuBar != null && items != null) { for (int i=0; i<items.length; i++) { MenuItem item = items [i]; if (item != null && item.accelerator != 0) { Menu menu = item.parent; if (menu.parent == this) { while (menu != null && menu != menuBar) { menu = menu.getParentMenu (); } if (menu == menuBar) { item.fillAccel (accel); OS.MoveMemory (buffer1, accel, ACCEL.sizeof); System.arraycopy (buffer1, 0, buffer2, nAccel * ACCEL.sizeof, ACCEL.sizeof); nAccel++; } } } } } if (OS.IsPPC) { /* * Note on WinCE PPC. Close the shell when user taps CTRL-Q. * IDOK represents the "Done Button" which also closes the shell. */ accel.fVirt = (byte) (OS.FVIRTKEY | OS.FCONTROL); accel.key = (short) 'Q'; accel.cmd = (short) OS.IDOK; OS.MoveMemory (buffer1, accel, ACCEL.sizeof); System.arraycopy (buffer1, 0, buffer2, nAccel * ACCEL.sizeof, ACCEL.sizeof); nAccel++; } if (nAccel != 0) hAccel = OS.CreateAcceleratorTable (buffer2, nAccel);}void createHandle () { super.createHandle (); if (parent == null) return; setParent (); setSystemMenu ();}void createWidget () { super.createWidget (); swFlags = OS.IsWinCE ? OS.SW_SHOWMAXIMIZED : OS.SW_SHOWNOACTIVATE; hAccel = -1;}void destroyAccelerators () { if (hAccel != 0 && hAccel != -1) OS.DestroyAcceleratorTable (hAccel); hAccel = -1;}public void dispose () { if (isDisposed()) return; if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); if (!(this instanceof Shell)) { setVisible (false); if (!traverseDecorations (false)) { Shell shell = getShell (); shell.setFocus (); } } super.dispose ();}Menu findMenu (int hMenu) { if (menus == null) return null; for (int i=0; i<menus.length; i++) { Menu menu = menus [i]; if (menu != null && hMenu == menu.handle) return menu; } return null;}void fixDecorations (Decorations newDecorations, Control control, Menu [] menus) { if (this == newDecorations) return; if (control == savedFocus) savedFocus = null; if (control == defaultButton) defaultButton = null; if (control == saveDefault) saveDefault = null; if (menus == null) return; Menu menu = control.menu; if (menu != null) { int index = 0; while (index <menus.length) { if (menus [index] == menu) { control.setMenu (null); return; } index++; } menu.fixMenus (newDecorations); destroyAccelerators (); newDecorations.destroyAccelerators (); }}public Rectangle getBounds () { checkWidget (); if (!OS.IsWinCE) { if (OS.IsIconic (handle)) { WINDOWPLACEMENT lpwndpl = new WINDOWPLACEMENT (); lpwndpl.length = WINDOWPLACEMENT.sizeof; OS.GetWindowPlacement (handle, lpwndpl); int width = lpwndpl.right - lpwndpl.left; int height = lpwndpl.bottom - lpwndpl.top; return new Rectangle (lpwndpl.left, lpwndpl.top, width, height); } } return super.getBounds ();}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -