📄 device.java
字号:
* </ul> */public FontData [] getFontList (String faceName, boolean scalable) { checkDevice (); /* Create the callback */ Callback callback = new Callback (this, "EnumFontFamProc", 4); int lpEnumFontFamProc = callback.getAddress (); /* Initialize the instance variables */ logFonts = new LOGFONT [nFonts]; for (int i=0; i<logFonts.length; i++) { logFonts [i] = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA (); } nFonts = 0; /* Enumerate */ int offset = 0; int hDC = internal_new_GC (null); if (faceName == null) { /* The user did not specify a face name, so they want all versions of all available face names */ OS.EnumFontFamilies (hDC, null, lpEnumFontFamProc, scalable ? 1 : 0); /** * For bitmapped fonts, EnumFontFamilies only enumerates once for each font, regardless * of how many styles are available. If the user wants bitmapped fonts, enumerate on * each face name now. */ offset = nFonts; for (int i=0; i<offset; i++) { LOGFONT lf = logFonts [i]; /** * Bug in Windows 98. When EnumFontFamiliesEx is called with a specified face name, it * should enumerate for each available style of that font. Instead, it only enumerates * once. The fix is to call EnumFontFamilies, which works as expected. */ if (OS.IsUnicode) { OS.EnumFontFamiliesW (hDC, ((LOGFONTW)lf).lfFaceName, lpEnumFontFamProc, scalable ? 1 : 0); } else { OS.EnumFontFamiliesA (hDC, ((LOGFONTA)lf).lfFaceName, lpEnumFontFamProc, scalable ? 1 : 0); } } } else { /* Use the character encoding for the default locale */ TCHAR lpFaceName = new TCHAR (0, faceName, true); /** * Bug in Windows 98. When EnumFontFamiliesEx is called with a specified face name, it * should enumerate for each available style of that font. Instead, it only enumerates * once. The fix is to call EnumFontFamilies, which works as expected. */ OS.EnumFontFamilies (hDC, lpFaceName, lpEnumFontFamProc, scalable ? 1 : 0); } internal_dispose_GC (hDC, null); /* Create the fontData from the logfonts */ int count = nFonts - offset; FontData [] result = new FontData [count]; for (int i=0; i<count; i++) { LOGFONT logFont = logFonts [i+offset]; result [i] = FontData.win32_new (logFont, computePoints(logFont)); } /* Clean up */ callback.dispose (); logFonts = null; return result;}String getLastError () { int error = OS.GetLastError(); if (error == 0) return ""; return " [GetLastError=0x" + Integer.toHexString(error) + "]";}String getLastErrorText () { int error = OS.GetLastError(); if (error == 0) return ""; int[] buffer = new int[1]; int dwFlags = OS.FORMAT_MESSAGE_ALLOCATE_BUFFER | OS.FORMAT_MESSAGE_FROM_SYSTEM | OS.FORMAT_MESSAGE_IGNORE_INSERTS; int length = OS.FormatMessage(dwFlags, 0, error, OS.LANG_USER_DEFAULT, buffer, 0, 0); if (length == 0) return " [GetLastError=0x" + Integer.toHexString(error) + "]"; TCHAR buffer1 = new TCHAR(0, length); OS.MoveMemory(buffer1, buffer[0], length * TCHAR.sizeof); if (buffer[0] != 0) OS.LocalFree(buffer[0]); return buffer1.toString(0, length);}/** * Returns the matching standard color for the given * constant, which should be one of the color constants * specified in class <code>SWT</code>. Any value other * than one of the SWT color constants which is passed * in will result in the color black. This color should * not be free'd because it was allocated by the system, * not the application. * * @param id the color constant * @return the matching color * * @exception SWTException <ul> * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see SWT */public Color getSystemColor (int id) { checkDevice (); int pixel = 0x02000000; switch (id) { case SWT.COLOR_WHITE: pixel = 0x02FFFFFF; break; case SWT.COLOR_BLACK: pixel = 0x02000000; break; case SWT.COLOR_RED: pixel = 0x020000FF; break; case SWT.COLOR_DARK_RED: pixel = 0x02000080; break; case SWT.COLOR_GREEN: pixel = 0x0200FF00; break; case SWT.COLOR_DARK_GREEN: pixel = 0x02008000; break; case SWT.COLOR_YELLOW: pixel = 0x0200FFFF; break; case SWT.COLOR_DARK_YELLOW: pixel = 0x02008080; break; case SWT.COLOR_BLUE: pixel = 0x02FF0000; break; case SWT.COLOR_DARK_BLUE: pixel = 0x02800000; break; case SWT.COLOR_MAGENTA: pixel = 0x02FF00FF; break; case SWT.COLOR_DARK_MAGENTA: pixel = 0x02800080; break; case SWT.COLOR_CYAN: pixel = 0x02FFFF00; break; case SWT.COLOR_DARK_CYAN: pixel = 0x02808000; break; case SWT.COLOR_GRAY: pixel = 0x02C0C0C0; break; case SWT.COLOR_DARK_GRAY: pixel = 0x02808080; break; } return Color.win32_new (this, pixel);}/** * Returns a reasonable font for applications to use. * On some platforms, this will match the "default font" * or "system font" if such can be found. This font * should not be free'd because it was allocated by the * system, not the application. * <p> * Typically, applications which want the default look * should simply not set the font on the widgets they * create. Widgets are always created with the correct * default font for the class of user-interface component * they represent. * </p> * * @return a font * * @exception SWTException <ul> * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */public Font getSystemFont () { checkDevice (); int hFont = OS.GetStockObject (OS.SYSTEM_FONT); return Font.win32_new (this, hFont);}/** * Returns <code>true</code> if the underlying window system prints out * warning messages on the console, and <code>setWarnings</code> * had previously been called with <code>true</code>. * * @return <code>true</code>if warnings are being handled, and <code>false</code> otherwise * * @exception SWTException <ul> * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */public boolean getWarnings () { checkDevice (); return false;}/** * Initializes any internal resources needed by the * device. * <p> * This method is called after <code>create</code>. * </p><p> * If subclasses reimplement this method, they must * call the <code>super</code> implementation. * </p> * * @see #create */protected void init () { if (debug) { if (!OS.IsWinCE) OS.GdiSetBatchLimit(1); } /* Initialize scripts list */ if (!OS.IsWinCE) { int [] ppSp = new int [1]; int [] piNumScripts = new int [1]; OS.ScriptGetProperties (ppSp, piNumScripts); scripts = new int [piNumScripts [0]]; OS.MoveMemory (scripts, ppSp [0], scripts.length * 4); } /* * If we're not on a device which supports palettes, * don't create one. */ int hDC = internal_new_GC (null); int rc = OS.GetDeviceCaps (hDC, OS.RASTERCAPS); int bits = OS.GetDeviceCaps (hDC, OS.BITSPIXEL); int planes = OS.GetDeviceCaps (hDC, OS.PLANES); bits *= planes; if ((rc & OS.RC_PALETTE) == 0 || bits != 8) { internal_dispose_GC (hDC, null); return; } int numReserved = OS.GetDeviceCaps (hDC, OS.NUMRESERVED); int numEntries = OS.GetDeviceCaps (hDC, OS.SIZEPALETTE); if (OS.IsWinCE) { /* * Feature on WinCE. For some reason, certain 8 bit WinCE * devices return 0 for the number of reserved entries in * the system palette. Their system palette correctly contains * the usual 20 system colors. The workaround is to assume * there are 20 reserved system colors instead of 0. */ if (numReserved == 0 && numEntries >= 20) numReserved = 20; } /* Create the palette and reference counter */ colorRefCount = new int [numEntries]; /* 4 bytes header + 4 bytes per entry * numEntries entries */ byte [] logPalette = new byte [4 + 4 * numEntries]; /* 2 bytes = special header */ logPalette [0] = 0x00; logPalette [1] = 0x03; /* 2 bytes = number of colors, LSB first */ logPalette [2] = 0; logPalette [3] = 1; /* * Create a palette which contains the system entries * as they are located in the system palette. The * MSDN article 'Memory Device Contexts' describes * where system entries are located. On an 8 bit * display with 20 reserved colors, the system colors * will be the first 10 entries and the last 10 ones. */ byte[] lppe = new byte [4 * numEntries]; OS.GetSystemPaletteEntries (hDC, 0, numEntries, lppe); /* Copy all entries from the system palette */ System.arraycopy (lppe, 0, logPalette, 4, 4 * numEntries); /* Lock the indices corresponding to the system entries */ for (int i = 0; i < numReserved / 2; i++) { colorRefCount [i] = 1; colorRefCount [numEntries - 1 - i] = 1; } internal_dispose_GC (hDC, null); hPalette = OS.CreatePalette (logPalette);}/** * Invokes platform specific functionality to allocate a new GC handle. * <p> * <b>IMPORTANT:</b> This method is <em>not</em> part of the public * API for <code>Device</code>. 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 called from * application code. * </p> * * @param data the platform specific GC data * @return the platform specific GC handle */public abstract int internal_new_GC (GCData data);/** * Invokes platform specific functionality to dispose a GC handle. * <p> * <b>IMPORTANT:</b> This method is <em>not</em> part of the public * API for <code>Device</code>. 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 called from * application code. * </p> * * @param hDC the platform specific GC handle * @param data the platform specific GC data */public abstract void internal_dispose_GC (int hDC, GCData data);/** * Returns <code>true</code> if the device has been disposed, * and <code>false</code> otherwise. * <p> * This method gets the dispose state for the device. * When a device has been disposed, it is an error to * invoke any other method using the device. * * @return <code>true</code> when the device is disposed and <code>false</code> otherwise */public boolean isDisposed () { return disposed;}void new_Object (Object object) { for (int i=0; i<objects.length; i++) { if (objects [i] == null) { objects [i] = object; errors [i] = new Error (); return; } } Object [] newObjects = new Object [objects.length + 128]; System.arraycopy (objects, 0, newObjects, 0, objects.length); newObjects [objects.length] = object; objects = newObjects; Error [] newErrors = new Error [errors.length + 128]; System.arraycopy (errors, 0, newErrors, 0, errors.length); newErrors [errors.length] = new Error (); errors = newErrors;}/** * Releases any internal resources back to the operating * system and clears all fields except the device handle. * <p> * When a device is destroyed, resources that were acquired * on behalf of the programmer need to be returned to the * operating system. For example, if the device allocated a * font to be used as the system font, this font would be * freed in <code>release</code>. Also,to assist the garbage * collector and minimize the amount of memory that is not * reclaimed when the programmer keeps a reference to a * disposed device, all fields except the handle are zero'd. * The handle is needed by <code>destroy</code>. * </p> * This method is called before <code>destroy</code>. * </p><p> * If subclasses reimplement this method, they must * call the <code>super</code> implementation. * </p> * * @see #dispose * @see #destroy */protected void release () { scripts = null; logFontsCache = null; if (hPalette != 0) OS.DeleteObject (hPalette); hPalette = 0; colorRefCount = null; logFonts = null; nFonts = 0;}/** * If the underlying window system supports printing warning messages * to the console, setting warnings to <code>true</code> prevents these * messages from being printed. If the argument is <code>false</code> * message printing is not blocked. * * @param warnings <code>true</code>if warnings should be handled, and <code>false</code> otherwise * * @exception SWTException <ul> * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */public void setWarnings (boolean warnings) { checkDevice ();}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -