1 /*
   2  * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #ifndef _AWT_PRINT_CONTROL_H_
  27 #define _AWT_PRINT_CONTROL_H_
  28 
  29 #include "stdhdrs.h"
  30 #include <commdlg.h>
  31 
  32 /************************************************************************
  33  * AwtPrintControl class
  34  */
  35 
  36 class AwtPrintControl {
  37 public:
  38 
  39     /* sun.awt.windows.WPrinterJob methods & fields */
  40 
  41     static jfieldID  dialogOwnerPeerID;
  42     static jfieldID  driverDoesMultipleCopiesID;
  43     static jfieldID  driverDoesCollationID;
  44     static jmethodID getPrintDCID;
  45     static jmethodID setPrintDCID;
  46     static jmethodID getDevmodeID;
  47     static jmethodID setDevmodeID;
  48     static jmethodID getDevnamesID;
  49     static jmethodID setDevnamesID;
  50     static jmethodID getWin32MediaID;
  51     static jmethodID setWin32MediaID;
  52     static jmethodID getWin32MediaTrayID;
  53     static jmethodID setWin32MediaTrayID;
  54     static jmethodID getColorID;
  55     static jmethodID getCopiesID;
  56     static jmethodID getSelectID;
  57     static jmethodID getDestID;
  58     static jmethodID getDialogID;
  59     static jmethodID getFromPageID;
  60     static jmethodID getMaxPageID;
  61     static jmethodID getMinPageID;
  62     static jmethodID getCollateID;
  63     static jmethodID getOrientID;
  64     static jmethodID getQualityID;
  65     static jmethodID getPrintToFileEnabledID;
  66     static jmethodID getPrinterID;
  67     static jmethodID setPrinterID;
  68     static jmethodID getResID;
  69     static jmethodID getSidesID;
  70     static jmethodID getToPageID;
  71     static jmethodID setToPageID;
  72     static jmethodID setNativeAttID;
  73     static jmethodID setRangeCopiesID;
  74     static jmethodID setResID;
  75     static jmethodID setJobAttributesID;
  76 
  77     static void initIDs(JNIEnv *env, jclass cls);
  78     static BOOL FindPrinter(jstring printerName, LPBYTE pPrinterEnum,
  79                             LPDWORD pcbBuf, LPTSTR * foundPrinter,
  80                             LPTSTR * foundPORT);
  81     // This function determines whether the printer driver
  82     // for the passed printer handle supports PRINTER_INFO
  83     // structure of level dwLevel.
  84     static BOOL IsSupportedLevel(HANDLE hPrinter, DWORD dwLevel);
  85     static BOOL CreateDevModeAndDevNames(PRINTDLG *ppd,
  86                                                LPTSTR pPrinterName,
  87                                                LPTSTR pPortName);
  88     static BOOL InitPrintDialog(JNIEnv *env,
  89                                       jobject printCtrl, PRINTDLG &pd);
  90     static BOOL UpdateAttributes(JNIEnv *env,
  91                                       jobject printCtrl, PRINTDLG &pd);
  92     static WORD getNearestMatchingPaper(LPTSTR printer, LPTSTR port,
  93                                       double origWid, double origHgt,
  94                                       double* newWid, double *newHgt);
  95 
  96     static BOOL getDevmode(HANDLE hPrinter,
  97                                  LPTSTR pPrinterName,
  98                                  LPDEVMODE *pDevMode);
  99 
 100     inline static  HDC getPrintDC(JNIEnv *env, jobject self) {
 101       return (HDC)env->CallLongMethod(self, getPrintDCID);
 102     }
 103 
 104     inline static void setPrintDC(JNIEnv *env, jobject self, HDC printDC) {
 105       env->CallVoidMethod(self, setPrintDCID, (jlong)printDC);
 106     }
 107 
 108     inline static HGLOBAL getPrintHDMode(JNIEnv *env, jobject self) {
 109       return (HGLOBAL) env->CallLongMethod(self, getDevmodeID);
 110     }
 111 
 112     inline static void setPrintHDMode(JNIEnv *env, jobject self,
 113                                       HGLOBAL hGlobal) {
 114       env->CallVoidMethod(self, setDevmodeID,
 115                           reinterpret_cast<jlong>(hGlobal));
 116     }
 117 
 118     inline static HGLOBAL getPrintHDName(JNIEnv *env, jobject self) {
 119       return (HGLOBAL) env->CallLongMethod(self, getDevnamesID);
 120     }
 121 
 122     inline static void setPrintHDName(JNIEnv *env, jobject self,
 123                                       HGLOBAL hGlobal) {
 124       env->CallVoidMethod(self, setDevnamesID,
 125                           reinterpret_cast<jlong>(hGlobal));
 126     }
 127 
 128 };
 129 
 130 #endif