jdk/src/windows/native/sun/windows/awt_PrintDialog.cpp
changeset 24159 51f49b4d2bfc
parent 23635 71c09f77edb5
equal deleted inserted replaced
24158:6afb40c4e9f8 24159:51f49b4d2bfc
   191     jboolean result = JNI_FALSE;
   191     jboolean result = JNI_FALSE;
   192 
   192 
   193     // as peer object is used later on another thread, create a global ref
   193     // as peer object is used later on another thread, create a global ref
   194     jobject peerGlobalRef = env->NewGlobalRef(peer);
   194     jobject peerGlobalRef = env->NewGlobalRef(peer);
   195     DASSERT(peerGlobalRef != NULL);
   195     DASSERT(peerGlobalRef != NULL);
       
   196     CHECK_NULL_RETURN(peerGlobalRef, 0);
   196     jobject target = env->GetObjectField(peerGlobalRef, AwtObject::targetID);
   197     jobject target = env->GetObjectField(peerGlobalRef, AwtObject::targetID);
   197     DASSERT(target != NULL);
   198     DASSERT(target != NULL);
       
   199     if (target == NULL) {
       
   200         env->DeleteGlobalRef(peerGlobalRef);
       
   201         return 0;
       
   202     }
   198     jobject parent = env->GetObjectField(peerGlobalRef, AwtPrintDialog::parentID);
   203     jobject parent = env->GetObjectField(peerGlobalRef, AwtPrintDialog::parentID);
   199     jobject control = env->GetObjectField(target, AwtPrintDialog::controlID);
   204     jobject control = env->GetObjectField(target, AwtPrintDialog::controlID);
   200     DASSERT(control != NULL);
   205     DASSERT(control != NULL);
       
   206     if (control == NULL) {
       
   207         env->DeleteGlobalRef(peerGlobalRef);
       
   208         env->DeleteLocalRef(target);
       
   209         if (parent != NULL) {
       
   210           env->DeleteLocalRef(parent);
       
   211         }
       
   212         return 0;
       
   213     }
   201 
   214 
   202     AwtComponent *awtParent = (parent != NULL) ? (AwtComponent *)JNI_GET_PDATA(parent) : NULL;
   215     AwtComponent *awtParent = (parent != NULL) ? (AwtComponent *)JNI_GET_PDATA(parent) : NULL;
   203     HWND hwndOwner = awtParent ? awtParent->GetHWnd() : NULL;
   216     HWND hwndOwner = awtParent ? awtParent->GetHWnd() : NULL;
   204 
   217 
   205     PRINTDLG pd;
   218     PRINTDLG pd;
   206     memset(&pd, 0, sizeof(PRINTDLG));
   219     memset(&pd, 0, sizeof(PRINTDLG));
   207     pd.lStructSize = sizeof(PRINTDLG);
   220     pd.lStructSize = sizeof(PRINTDLG);
   208     pd.lCustData = (LPARAM)peerGlobalRef;
   221     pd.lCustData = (LPARAM)peerGlobalRef;
   209     BOOL ret = AwtPrintControl::InitPrintDialog(env, control, pd);
   222     BOOL ret;
       
   223     try {
       
   224         ret = AwtPrintControl::InitPrintDialog(env, control, pd);
       
   225     } catch (std::bad_alloc&) {
       
   226         env->DeleteGlobalRef(peerGlobalRef);
       
   227         env->DeleteLocalRef(target);
       
   228         if (parent != NULL) {
       
   229           env->DeleteLocalRef(parent);
       
   230         }
       
   231         env->DeleteLocalRef(control);
       
   232         throw;
       
   233     }
   210     if (!ret) {
   234     if (!ret) {
   211         /* Couldn't use the printer, or spooler isn't running
   235         /* Couldn't use the printer, or spooler isn't running
   212          * Call Page dialog with ' PD_RETURNDEFAULT' so it doesn't try
   236          * Call Page dialog with ' PD_RETURNDEFAULT' so it doesn't try
   213          * to show the dialog, but does prompt the user to install a printer.
   237          * to show the dialog, but does prompt the user to install a printer.
   214          * If this returns false, then they declined and we just return.
   238          * If this returns false, then they declined and we just return.