| package org.eclipse.swt.printing;
|
|
|
| /*
|
| * (c) Copyright IBM Corp. 2000, 2001.
|
| * All Rights Reserved
|
| */
|
|
|
| import org.eclipse.swt.*;
|
| import org.eclipse.swt.graphics.*;
|
| import org.eclipse.swt.internal.*;
|
| import org.eclipse.swt.internal.gtk.*;
|
|
|
| /** |
| * Instances of this class are used to print to a printer. |
| * Applications create a GC on a printer using <code>new GC(printer)</code> |
| * and then draw on the printer GC using the usual graphics calls. |
| * <p> |
| * A <code>Printer</code> object may be constructed by providing |
| * a <code>PrinterData</code> object which identifies the printer. |
| * A <code>PrintDialog</code> presents a print dialog to the user |
| * and returns an initialized instance of <code>PrinterData</code>. |
| * Alternatively, calling <code>new Printer()</code> will construct a |
| * printer object for the user's default printer. |
| * </p><p> |
| * Application code must explicitly invoke the <code>Printer.dispose()</code> |
| * method to release the operating system resources managed by each instance |
| * when those instances are no longer required. |
| * </p> |
| * |
| * @see PrinterData |
| * @see PrintDialog |
| */ |
| public final class Printer extends Device {
|
| PrinterData data;
|
| int printContext, xScreen, xDrawable;
|
| int defaultFontList;
|
|
|
| /** |
| * Returns an array of <code>PrinterData</code> objects |
| * representing all available printers. |
| * |
| * @return the list of available printers |
| */ |
| public static PrinterData[] getPrinterList() {
|
| PrinterData printerList[] = new PrinterData[0];
|
| return printerList;
|
| }
|
|
|
| static PrinterData getDefaultPrinterData() {
|
| /* Use the first printer in the list as the default */
|
| PrinterData[] list = getPrinterList();
|
| if (list.length == 0) {
|
| /* no printers */
|
| SWT.error(SWT.ERROR_NO_HANDLES);
|
| }
|
| return list[0];
|
| }
|
|
|
| /** |
| * Constructs a new printer representing the default printer. |
| * <p> |
| * You must dispose the printer when it is no longer required. |
| * </p> |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_UNSPECIFIED - if there are no valid printers |
| * </ul> |
| * |
| * @see #dispose |
| */ |
| public Printer() {
|
| this(getDefaultPrinterData());
|
| }
|
|
|
| /** |
| * Constructs a new printer given a <code>PrinterData</code> |
| * object representing the desired printer. |
| * <p> |
| * You must dispose the printer when it is no longer required. |
| * </p> |
| * |
| * @param data the printer data for the specified printer |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_INVALID_ARGUMENT - if the specified printer data does not represent a valid printer |
| * <li>ERROR_UNSPECIFIED - if there are no valid printers |
| * </ul> |
| * |
| * @see #dispose |
| */ |
| public Printer(PrinterData data) {
|
| super(data);
|
| }
|
|
|
|
|
| /** |
| * 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>Printer</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 |
| * |
| * @private |
| */ |
| public int internal_new_GC(GCData data) {
|
| return 0;
|
| }
|
|
|
| /** |
| * 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>Printer</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 handle the platform specific GC handle |
| * @param data the platform specific GC data |
| * |
| * @private |
| */ |
| public void internal_dispose_GC(int xGC, GCData data) {
|
| }
|
|
|
| /** |
| * Starts a print job and returns true if the job started successfully |
| * and false otherwise. |
| * <p> |
| * This must be the first method called to initiate a print job, |
| * followed by any number of startPage/endPage calls, followed by |
| * endJob. Calling startPage, endPage, or endJob before startJob |
| * will result in undefined behavior. |
| * </p> |
| * |
| * @return true if the job started successfully and false otherwise. |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> |
| * </ul> |
| * |
| * @see #startPage |
| * @see #endPage |
| * @see #endJob |
| */ |
| public boolean startJob(String jobName) {
|
| return true;
|
| }
|
|
|
| /** |
| * Ends the current print job. |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> |
| * </ul> |
| * |
| * @see #startJob |
| * @see #startPage |
| * @see #endPage |
| */ |
| public void endJob() {
|
| }
|
|
|
| /** |
| * Cancels a print job in progress. |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> |
| * </ul> |
| */ |
| public void cancelJob() {
|
| }
|
|
|
| /** |
| * Starts a page and returns true if the page started successfully |
| * and false otherwise. |
| * <p> |
| * After calling startJob, this method may be called any number of times |
| * along with a matching endPage. |
| * </p> |
| * |
| * @return true if the page started successfully and false otherwise. |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> |
| * </ul> |
| * |
| * @see #endPage |
| * @see #startJob |
| * @see #endJob |
| */ |
| public boolean startPage() {
|
| return true;
|
| }
|
|
|
| /** |
| * Ends the current page. |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> |
| * </ul> |
| * |
| * @see #startPage |
| * @see #startJob |
| * @see #endJob |
| */ |
| public void endPage() {
|
| }
|
|
|
| /** |
| * Returns a point whose x coordinate is the horizontal |
| * dots per inch of the printer, and whose y coordinate |
| * is the vertical dots per inch of the printer. |
| * |
| * @return the horizontal and vertical DPI |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> |
| * </ul> |
| */ |
| public Point getDPI() {
|
| return new Point(0, 0);
|
| }
|
|
|
| /** |
| * Returns a rectangle describing the receiver's size and location. |
| * For a printer, this is the size of a page, in pixels. |
| * |
| * @return the bounding rectangle |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> |
| * </ul> |
| * |
| * @see #getClientArea |
| * @see #computeTrim |
| */ |
| public Rectangle getBounds() {
|
| return null;
|
| }
|
|
|
| /** |
| * Returns a rectangle which describes the area of the |
| * receiver which is capable of displaying data. |
| * For a printer, this is the size of the printable area |
| * of a page, in pixels. |
| * |
| * @return the client area |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> |
| * </ul> |
| * |
| * @see #getBounds |
| * @see #computeTrim |
| */ |
| public Rectangle getClientArea() {
|
| return null;
|
| }
|
|
|
| /** |
| * Given a desired <em>client area</em> for the receiver |
| * (as described by the arguments), returns the bounding |
| * rectangle which would be required to produce that client |
| * area. |
| * <p> |
| * In other words, it returns a rectangle such that, if the |
| * receiver's bounds were set to that rectangle, the area |
| * of the receiver which is capable of displaying data |
| * (that is, not covered by the "trimmings") would be the |
| * rectangle described by the arguments (relative to the |
| * receiver's parent). |
| * </p> |
| * Note that there is no setBounds for a printer. This method |
| * is usually used by passing in the client area (the 'printable |
| * area') of the printer. It can also be useful to pass in 0, 0, 0, 0. |
| * |
| * @return the required bounds to produce the given client area |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> |
| * </ul> |
| * |
| * @see #getBounds |
| * @see #getClientArea |
| */ |
| public Rectangle computeTrim(int x, int y, int width, int height) {
|
| return new Rectangle(0,0,0,0);
|
| }
|
|
|
| /**
|
| * Returns a <code>PrinterData</code> object representing the
|
| * target printer for this print job.
|
| *
|
| * @return a PrinterData object describing the receiver
|
| */
|
| public PrinterData getPrinterData() {
|
| return data;
|
| }
|
|
|
| }
|