< prev index next >

src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp

Print this page




 215                                                                 jlong chgObject) {
 216     FindClosePrinterChangeNotification((HANDLE)chgObject);
 217 }
 218 
 219 
 220 JNIEXPORT jint JNICALL
 221 Java_sun_print_PrintServiceLookupProvider_notifyPrinterChange(JNIEnv *env,
 222                                                            jobject peer,
 223                                                            jlong chgObject) {
 224     DWORD dwChange;
 225 
 226     DWORD ret = WaitForSingleObject((HANDLE)chgObject, INFINITE);
 227     if (ret == WAIT_OBJECT_0) {
 228         return(FindNextPrinterChangeNotification((HANDLE)chgObject,
 229                                                   &dwChange, NULL, NULL));
 230     } else {
 231         return 0;
 232     }
 233 }
 234 







































































 235 
 236 JNIEXPORT jfloatArray JNICALL
 237 Java_sun_print_Win32PrintService_getMediaPrintableArea(JNIEnv *env,
 238                                                   jobject peer,
 239                                                   jstring printer,
 240                                                   jint  papersize)
 241 {
 242     TRY;
 243 
 244     LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
 245                                                             printer, NULL);
 246     if (printerName == NULL) {
 247         return NULL;
 248     }
 249 
 250     jfloatArray printableArray = NULL;
 251 
 252     SAVE_CONTROLWORD
 253     HDC pdc = CreateDC(TEXT("WINSPOOL"), printerName, NULL, NULL);
 254     RESTORE_CONTROLWORD




 215                                                                 jlong chgObject) {
 216     FindClosePrinterChangeNotification((HANDLE)chgObject);
 217 }
 218 
 219 
 220 JNIEXPORT jint JNICALL
 221 Java_sun_print_PrintServiceLookupProvider_notifyPrinterChange(JNIEnv *env,
 222                                                            jobject peer,
 223                                                            jlong chgObject) {
 224     DWORD dwChange;
 225 
 226     DWORD ret = WaitForSingleObject((HANDLE)chgObject, INFINITE);
 227     if (ret == WAIT_OBJECT_0) {
 228         return(FindNextPrinterChangeNotification((HANDLE)chgObject,
 229                                                   &dwChange, NULL, NULL));
 230     } else {
 231         return 0;
 232     }
 233 }
 234 
 235 JNIEXPORT jobjectArray JNICALL
 236 Java_sun_print_PrintServiceLookupProvider_getRemotePrintersNames(JNIEnv *env,
 237                                                            jobject peer)
 238 {
 239     TRY;
 240 
 241     int remotePrintersCount = 0;
 242     DWORD cbNeeded = 0;
 243     DWORD cReturned = 0;
 244     LPBYTE pPrinterEnum = NULL;
 245     LPBYTE pNetworkPrinterLoc = NULL;
 246 
 247     jstring utf_str;
 248     jclass clazz = env->FindClass("java/lang/String");
 249     if (clazz == NULL) {
 250         return NULL;
 251     }
 252     jobjectArray nameArray;
 253 
 254     try {
 255         ::EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
 256                        NULL, 4, NULL, 0, &cbNeeded, &cReturned);
 257         pPrinterEnum = new BYTE[cbNeeded];
 258         pNetworkPrinterLoc = new BYTE[cbNeeded/sizeof(PRINTER_INFO_4)];
 259         ::EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
 260                        NULL, 4, pPrinterEnum, cbNeeded, &cbNeeded,
 261                        &cReturned);
 262 
 263         if (cReturned > 0) {
 264             for (DWORD i = 0; i < cReturned; i++) {
 265                 PRINTER_INFO_4 *info4 = (PRINTER_INFO_4 *) (pPrinterEnum + i * sizeof(PRINTER_INFO_4));
 266 
 267                 // PRINTER_ATTRIBUTE_NETWORK = 0x00000010
 268                 // Store the network printers indexes
 269                 if (info4->Attributes & 0x00000010) {
 270                     pNetworkPrinterLoc[remotePrintersCount++] = i;
 271                 }
 272             }
 273 
 274             // Allocate space only for the network type printers
 275             nameArray = env->NewObjectArray(remotePrintersCount, clazz, NULL);
 276             if (nameArray == NULL) {
 277                 throw std::bad_alloc();
 278             }
 279         } else {
 280             nameArray = NULL;
 281         }
 282 
 283         // Loop thro' network printers list only
 284         for (int i = 0; i < remotePrintersCount; i++) {
 285             PRINTER_INFO_4 *info4 = (PRINTER_INFO_4 *)
 286                 (pPrinterEnum + pNetworkPrinterLoc[i] * sizeof(PRINTER_INFO_4));
 287             utf_str = JNU_NewStringPlatform(env, info4->pPrinterName);
 288             if (utf_str == NULL) {
 289                 throw std::bad_alloc();
 290             }
 291             env->SetObjectArrayElement(nameArray, i, utf_str);
 292             env->DeleteLocalRef(utf_str);
 293         }
 294     } catch (std::bad_alloc&) {
 295         delete [] pPrinterEnum;
 296         delete [] pNetworkPrinterLoc;
 297         throw;
 298     }
 299 
 300     delete [] pPrinterEnum;
 301     delete [] pNetworkPrinterLoc;
 302     return nameArray;
 303 
 304     CATCH_BAD_ALLOC_RET(NULL);
 305 }
 306 
 307 JNIEXPORT jfloatArray JNICALL
 308 Java_sun_print_Win32PrintService_getMediaPrintableArea(JNIEnv *env,
 309                                                   jobject peer,
 310                                                   jstring printer,
 311                                                   jint  papersize)
 312 {
 313     TRY;
 314 
 315     LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
 316                                                             printer, NULL);
 317     if (printerName == NULL) {
 318         return NULL;
 319     }
 320 
 321     jfloatArray printableArray = NULL;
 322 
 323     SAVE_CONTROLWORD
 324     HDC pdc = CreateDC(TEXT("WINSPOOL"), printerName, NULL, NULL);
 325     RESTORE_CONTROLWORD


< prev index next >