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 getParentWindowID; 51 static jmethodID getWin32MediaID; 52 static jmethodID setWin32MediaID; 53 static jmethodID getWin32MediaTrayID; 54 static jmethodID setWin32MediaTrayID; 55 static jmethodID getColorID; 56 static jmethodID getCopiesID; 57 static jmethodID getSelectID; 58 static jmethodID getDestID; 59 static jmethodID getDialogID; 60 static jmethodID getFromPageID; 61 static jmethodID getMaxPageID; 62 static jmethodID getMinPageID; 63 static jmethodID getCollateID; 64 static jmethodID getOrientID; 65 static jmethodID getQualityID; 66 static jmethodID getPrintToFileEnabledID; 67 static jmethodID getPrinterID; 68 static jmethodID setPrinterID; 69 static jmethodID getResID; 70 static jmethodID getSidesID; 71 static jmethodID getToPageID; 72 static jmethodID setToPageID; 73 static jmethodID setNativeAttID; 74 static jmethodID setRangeCopiesID; 75 static jmethodID setResID; 76 static jmethodID setJobAttributesID; 77 78 static void initIDs(JNIEnv *env, jclass cls); 79 static BOOL FindPrinter(jstring printerName, LPBYTE pPrinterEnum, 80 LPDWORD pcbBuf, LPTSTR * foundPrinter, 81 LPTSTR * foundPORT); 82 // This function determines whether the printer driver 83 // for the passed printer handle supports PRINTER_INFO 84 // structure of level dwLevel. 85 static BOOL IsSupportedLevel(HANDLE hPrinter, DWORD dwLevel); 86 static BOOL CreateDevModeAndDevNames(PRINTDLG *ppd, 87 LPTSTR pPrinterName, 88 LPTSTR pPortName); 89 static BOOL InitPrintDialog(JNIEnv *env, 90 jobject printCtrl, PRINTDLG &pd); 91 static BOOL UpdateAttributes(JNIEnv *env, 92 jobject printCtrl, PRINTDLG &pd); 93 static WORD getNearestMatchingPaper(LPTSTR printer, LPTSTR port, 94 double origWid, double origHgt, 95 double* newWid, double *newHgt); 96 97 static BOOL getDevmode(HANDLE hPrinter, 98 LPTSTR pPrinterName, 99 LPDEVMODE *pDevMode); 100 101 inline static HWND getParentID(JNIEnv *env, jobject self) { 102 return (HWND)env->CallLongMethod(self, getParentWindowID); 103 } 104 105 inline static HDC getPrintDC(JNIEnv *env, jobject self) { 106 return (HDC)env->CallLongMethod(self, getPrintDCID); 107 } 108 109 inline static void setPrintDC(JNIEnv *env, jobject self, HDC printDC) { 110 env->CallVoidMethod(self, setPrintDCID, (jlong)printDC); 111 } 112 113 inline static HGLOBAL getPrintHDMode(JNIEnv *env, jobject self) { 114 return (HGLOBAL) env->CallLongMethod(self, getDevmodeID); 115 } 116 117 inline static void setPrintHDMode(JNIEnv *env, jobject self, 118 HGLOBAL hGlobal) { 119 env->CallVoidMethod(self, setDevmodeID, 120 reinterpret_cast<jlong>(hGlobal)); 121 } 122 123 inline static HGLOBAL getPrintHDName(JNIEnv *env, jobject self) { 124 return (HGLOBAL) env->CallLongMethod(self, getDevnamesID); 125 } 126 127 inline static void setPrintHDName(JNIEnv *env, jobject self, 128 HGLOBAL hGlobal) { 129 env->CallVoidMethod(self, setDevnamesID, 130 reinterpret_cast<jlong>(hGlobal)); 131 } 132 133 }; 134 135 #endif