package org.eclipse.swt.graphics; /* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is 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 */ import org.eclipse.swt.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; /** * This class is the abstract superclass of all device objects, * such as the Display device and the Printer device. Devices * can have a graphics context (GC) created for them, and they * can be drawn on by sending messages to the associated GC. */ public abstract class Device implements Drawable { /* Debugging */ public static boolean DEBUG; boolean debug = DEBUG; boolean tracking = DEBUG; Error [] errors; Object [] objects; /* Colormap and reference count */ GdkColor [] gdkColors; int [] colorRefCount; /* Disposed flag */ boolean disposed; /* Warning and Error Handlers */ int logProc; Callback logCallback; //NOT DONE - get list of valid names String [] log_domains = {"GLib-GObject", "GLib", "GObject", "Pango", "ATK", "GdkPixbuf", "Gdk", "Gtk"}; int [] handler_ids = new int [log_domains.length]; int warningLevel; /* * The following colors are listed in the Windows * Programmer's Reference as the colors in the default * palette. */ Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE; Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED; Color COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE; /* System Font */ Font systemFont; /* * TEMPORARY CODE. When a graphics object is * created and the device parameter is null, * the current Display is used. This presents * a problem because SWT graphics does not * reference classes in SWT widgets. The correct * fix is to remove this feature. Unfortunately, * too many application programs rely on this * feature. * * This code will be removed in the future. */ protected static Device CurrentDevice; protected static Runnable DeviceFinder; static { try { Class.forName ("org.eclipse.swt.widgets.Display"); } catch (Throwable e) {} } /* * TEMPORARY CODE. */ static Device getDevice () { if (DeviceFinder != null) DeviceFinder.run(); Device device = CurrentDevice; CurrentDevice = null; return device; } /** * Constructs a new instance of this class. *
* You must dispose the device when it is no longer required. *
* * @param data the DeviceData which describes the receiver * * @see #create * @see #init * @see DeviceData */ public Device(DeviceData data) { if (data != null) { debug = data.debug; tracking = data.tracking; } if (tracking) { errors = new Error [128]; objects = new Object [128]; } create (data); init (); /* Initialize the system font slot */ systemFont = getSystemFont (); } protected void checkDevice () { if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED); } protected void create (DeviceData data) { } /** * Disposes of the operating system resources associated with * the receiver. After this method has been invoked, the receiver * will answertrue
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; iDeviceData
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 SWTException 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 true if scalable fonts should be returned.
* @return the matching font data
*
* @exception SWTException * 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. *
* * @return a font * * @exception SWTExceptiontrue
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 SWTException Device
. 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.
*
*
* @param data the platform specific GC data
* @return the platform specific GC handle
*
* @private
*/
public abstract int internal_new_GC (GCData data);
/**
* Invokes platform specific functionality to dispose a GC handle.
*
* IMPORTANT: This method is not part of the public
* API for Device
. 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.
*
true
if the device has been disposed,
* and false
otherwise.
*
* 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 true
when the device is disposed and false
otherwise
*/
public boolean isDisposed () {
return disposed;
}
int logProc (int log_domain, int log_level, int message, int user_data) {
if (DEBUG || (debug && warningLevel == 0)) {
new Error ().printStackTrace ();
OS.g_log_default_handler (log_domain, log_level, message, 0);
}
return 0;
}
void new_Object (Object object) {
for (int i=0; ifalse
* message printing is not blocked.
*
* @param warnings true
if warnings should be handled, and false
otherwise
*
* @exception SWTException
*
*/
public void setWarnings (boolean warnings) {
checkDevice ();
if (warnings) {
if (--warningLevel == 0) {
if (debug) return;
for (int i=0; i