# HG changeset patch
# User Frank Benoit
+ * IMPORTANT: This field is not part of the DWT
+ * public API. It is marked public only so that it can be shared
+ * within the packages provided by DWT. It is not available on all
+ * platforms and should never be accessed from application code.
+ *
+ * You must dispose the device when it is no longer required.
+ *
+ * You must dispose the device when it is no longer required.
+ *
+ * Currently, it is an error to invoke any method (other than
+ *
+ * In future releases of DWT, there may be more or fewer error
+ * checks and exceptions may be thrown for different reasons.
+ *
+ *
+ * @exception DWTException
+ * This method is called before
+ * Subclasses are supposed to reimplement this method and not
+ * call the
+ * This method is called after
+ * Subclasses are supposed to reimplement this method and not
+ * call the
+ * 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.
+ *
+ * This method is called after
+ * If subclasses reimplement this method, they must
+ * call the
+ * IMPORTANT: This method is not part of the public
+ * API for
+ * IMPORTANT: This method is not part of the public
+ * API for
+ * 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 DWTException
if the receiver can not
+ * be accessed by the caller. This may include both checks on
+ * the state of the receiver and more generally on the entire
+ * execution context. This method should be called by
+ * device implementors to enforce the standard DWT invariants.
+ * isDisposed()
and dispose()
) on a
+ * device that has had its dispose()
method called.
+ *
+ *
+ */
+protected void checkDevice () {
+ if (disposed) DWT.error(DWT.ERROR_DEVICE_DISPOSED);
+}
+
+void checkGDIP() {
+ if (gdipToken !is null) return;
+ if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED);
+ int oldErrorMode = OS.SetErrorMode (OS.SEM_FAILCRITICALERRORS);
+ try {
+ int [] token = new int [1];
+ GdiplusStartupInput input = new GdiplusStartupInput ();
+ input.GdiplusVersion = 1;
+ if (Gdip.GdiplusStartup (token, input, 0) is 0) {
+ gdipToken = token;
+ }
+ } catch (Throwable t) {
+ DWT.error (DWT.ERROR_NO_GRAPHICS_LIBRARY, t, " [GDI+ is required]"); //$NON-NLS-1$
+ } finally {
+ OS.SetErrorMode (oldErrorMode);
+ }
+}
+
+/**
+ * Creates the device in the operating system. If the device
+ * does not have a handle, this method may do nothing depending
+ * on the device.
+ * init
.
+ * super
implementation.
+ * release
.
+ * super
implementation.
+ * true
when sent the message
+ * isDisposed()
.
+ *
+ * @see #release
+ * @see #destroy
+ * @see #checkDevice
+ */
+public void dispose () {
+ if (isDisposed()) return;
+ checkDevice ();
+ release ();
+ destroy ();
+ disposed = true;
+ if (tracking) {
+ objects = null;
+ errors = null;
+ }
+}
+
+void dispose_Object (Object object) {
+ for (int i=0; i
+ *
+ */
+public Rectangle getBounds () {
+ checkDevice ();
+ int hDC = internal_new_GC (null);
+ int width = OS.GetDeviceCaps (hDC, OS.HORZRES);
+ int height = OS.GetDeviceCaps (hDC, OS.VERTRES);
+ internal_dispose_GC (hDC, null);
+ return new Rectangle (0, 0, width, height);
+}
+
+/**
+ * Returns a DeviceData
based on the receiver.
+ * Modifications made to this DeviceData
will not
+ * affect the receiver.
+ *
+ * @return a DeviceData
containing the device's data and attributes
+ *
+ * @exception DWTException
+ *
+ *
+ * @see DeviceData
+ */
+public DeviceData getDeviceData () {
+ checkDevice();
+ DeviceData data = new DeviceData ();
+ data.debug = debug;
+ data.tracking = tracking;
+ int count = 0, length = 0;
+ if (tracking) length = objects.length;
+ for (int i=0; i
+ *
+ */
+public int getDepth () {
+ checkDevice ();
+ int hDC = internal_new_GC (null);
+ int bits = OS.GetDeviceCaps (hDC, OS.BITSPIXEL);
+ int planes = OS.GetDeviceCaps (hDC, OS.PLANES);
+ internal_dispose_GC (hDC, null);
+ return bits * planes;
+}
+
+/**
+ * Returns a point whose x coordinate is the horizontal
+ * dots per inch of the display, and whose y coordinate
+ * is the vertical dots per inch of the display.
+ *
+ * @return the horizontal and vertical DPI
+ *
+ * @exception DWTException
+ *
+ */
+public Point getDPI () {
+ checkDevice ();
+ int hDC = internal_new_GC (null);
+ int dpiX = OS.GetDeviceCaps (hDC, OS.LOGPIXELSX);
+ int dpiY = OS.GetDeviceCaps (hDC, OS.LOGPIXELSY);
+ internal_dispose_GC (hDC, null);
+ return new Point (dpiX, dpiY);
+}
+
+/**
+ * Returns FontData
objects which describe
+ * the fonts that match the given arguments. If the
+ * faceName
is null, all fonts will be returned.
+ *
+ * @param faceName the name of the font to look for, or null
+ * @param scalable if true only scalable fonts are returned, otherwise only non-scalable fonts are returned.
+ * @return the matching font data
+ *
+ * @exception DWTException
+ *
+ */
+public FontData [] getFontList (String faceName, bool scalable) {
+ checkDevice ();
+
+ /* Create the callback */
+ Callback callback = new Callback (this, "EnumFontFamProc", 4); //$NON-NLS-1$
+ int lpEnumFontFamProc = callback.getAddress ();
+ if (lpEnumFontFamProc is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS);
+
+ /* Initialize the instance variables */
+ metrics = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
+ pixels = new int[nFonts];
+ logFonts = new LOGFONT [nFonts];
+ for (int i=0; i
+ *
+ *
+ * @see DWT
+ */
+public Color getSystemColor (int id) {
+ checkDevice ();
+ int pixel = 0x00000000;
+ switch (id) {
+ case DWT.COLOR_WHITE: pixel = 0x00FFFFFF; break;
+ case DWT.COLOR_BLACK: pixel = 0x00000000; break;
+ case DWT.COLOR_RED: pixel = 0x000000FF; break;
+ case DWT.COLOR_DARK_RED: pixel = 0x00000080; break;
+ case DWT.COLOR_GREEN: pixel = 0x0000FF00; break;
+ case DWT.COLOR_DARK_GREEN: pixel = 0x00008000; break;
+ case DWT.COLOR_YELLOW: pixel = 0x0000FFFF; break;
+ case DWT.COLOR_DARK_YELLOW: pixel = 0x00008080; break;
+ case DWT.COLOR_BLUE: pixel = 0x00FF0000; break;
+ case DWT.COLOR_DARK_BLUE: pixel = 0x00800000; break;
+ case DWT.COLOR_MAGENTA: pixel = 0x00FF00FF; break;
+ case DWT.COLOR_DARK_MAGENTA: pixel = 0x00800080; break;
+ case DWT.COLOR_CYAN: pixel = 0x00FFFF00; break;
+ case DWT.COLOR_DARK_CYAN: pixel = 0x00808000; break;
+ case DWT.COLOR_GRAY: pixel = 0x00C0C0C0; break;
+ case DWT.COLOR_DARK_GRAY: pixel = 0x00808080; 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 freed because it was allocated by the
+ * system, not the application.
+ *
+ *
+ */
+public Font getSystemFont () {
+ checkDevice ();
+ int hFont = OS.GetStockObject (OS.SYSTEM_FONT);
+ return Font.win32_new (this, hFont);
+}
+
+/**
+ * Returns true
if the underlying window system prints out
+ * warning messages on the console, and setWarnings
+ * had previously been called with true
.
+ *
+ * @return true
if warnings are being handled, and false
otherwise
+ *
+ * @exception DWTException
+ *
+ */
+public bool getWarnings () {
+ checkDevice ();
+ return false;
+}
+
+/**
+ * Initializes any internal resources needed by the
+ * device.
+ * create
.
+ * super
implementation.
+ * Device
. It is marked public only so that it
+ * can be shared within the packages provided by DWT. It is not
+ * available on all platforms, and should never be called from
+ * application code.
+ * Device
. It is marked public only so that it
+ * can be shared within the packages provided by DWT. It is not
+ * available on all platforms, and should never be called from
+ * application code.
+ * true
if the device has been disposed,
+ * and false
otherwise.
+ * true
when the device is disposed and false
otherwise
+ */
+public bool isDisposed () {
+ return disposed;
+}
+
+/**
+ * Loads the font specified by a file. The font will be
+ * present in the list of fonts available to the application.
+ *
+ * @param path the font file path
+ * @return whether the font was successfully loaded
+ *
+ * @exception DWTException
+ *
+ *
+ * @see Font
+ *
+ * @since 3.3
+ */
+public bool loadFont (String path) {
+ checkDevice();
+ if (path is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
+ if (OS.IsWinNT && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
+ TCHAR lpszFilename = new TCHAR (0, path, true);
+ return OS.AddFontResourceEx (lpszFilename, OS.FR_PRIVATE, 0) !is 0;
+ }
+ return false;
+}
+
+void new_Object (Object object) {
+ for (int i=0; irelease
. 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 destroy
.
+ *
destroy
.
+ *
+ * If subclasses reimplement this method, they must
+ * call the super
implementation.
+ *
false
prevents these
+ * messages from being printed. If the argument is true
then
+ * message printing is not blocked.
+ *
+ * @param warnings true
if warnings should be printed, and false
otherwise
+ *
+ * @exception DWTException + * IMPORTANT: This class is intended to be subclassed only + * within the DWT implementation. However, it has not been marked + * final to allow those outside of the DWT development team to implement + * patched versions of the class in order to get around specific + * limitations in advance of when those limitations can be addressed + * by the team. Any class built using subclassing to access the internals + * of this class will likely fail to compile or run between releases and + * may be strongly platform specific. Subclassing should not be attempted + * without an intimate and detailed understanding of the workings of the + * hierarchy. No support is provided for user-written classes which are + * implemented as subclasses of this class. + *
+ * + * @see #dispose + * @see #isDisposed + * + * @since 3.1 + */ +public abstract class Resource { + + /** + * the device where this resource was created + */ + Device device; + +/** + * Disposes of the operating system resources associated with + * this resource. Applications must dispose of all resources + * which they allocate. + */ +public abstract void dispose(); + +/** + * Returns theDevice
where this resource was
+ * created.
+ *
+ * @return Device
the device of the receiver
+ *
+ * @since 3.2
+ */
+public Device getDevice() {
+ Device device = this.device;
+ if (device is null || isDisposed ()) DWT.error (DWT.ERROR_GRAPHIC_DISPOSED);
+ return device;
+}
+
+/**
+ * Returns true
if the resource has been disposed,
+ * and false
otherwise.
+ *
+ * This method gets the dispose state for the resource.
+ * When a resource has been disposed, it is an error to
+ * invoke any other method using the resource.
+ *
+ * @return true
when the resource is disposed and false
otherwise
+ */
+public abstract bool isDisposed();
+
+}