jdk/src/windows/native/sun/windows/awt_PrintDialog.cpp
author dcherepanov
Tue, 17 Feb 2009 14:30:52 +0300
changeset 2456 45ee87a35349
parent 1954 b93b85df3211
child 2464 3c6755bdc55f
permissions -rw-r--r--
6792023: Print suspends on Windows 2000 Pro since 6u12 b01 Reviewed-by: art, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
     2
 * Copyright 1999-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    26
#include "awt.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "awt_PrintDialog.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "awt_Dialog.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "awt_PrintControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "awt_Window.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "ComCtl32Util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <sun_awt_windows_WPrintDialog.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <sun_awt_windows_WPrintDialogPeer.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
jfieldID AwtPrintDialog::controlID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
jfieldID AwtPrintDialog::parentID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
jmethodID AwtPrintDialog::setHWndMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
BOOL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
AwtPrintDialog::PrintDlg(LPPRINTDLG data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    return static_cast<BOOL>(reinterpret_cast<INT_PTR>(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        AwtToolkit::GetInstance().InvokeFunction(
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    44
            reinterpret_cast<void *(*)(void *)>(::PrintDlg), data)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
LRESULT CALLBACK PrintDialogWndProc(HWND hWnd, UINT message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                                    WPARAM wParam, LPARAM lParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    switch (message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        case WM_COMMAND: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            if ((LOWORD(wParam) == IDOK) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                (LOWORD(wParam) == IDCANCEL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                // If we recieve on of these two notifications, the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                // is about to be closed. It's time to unblock all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                // windows blocked by this dialog, as doing so from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                // WM_DESTROY handler is too late
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                jobject peer = (jobject)(::GetProp(hWnd, ModalDialogPeerProp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                env->CallVoidMethod(peer, AwtPrintDialog::setHWndMID, (jlong)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
2456
45ee87a35349 6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents: 1954
diff changeset
    68
    WNDPROC lpfnWndProc = (WNDPROC)(::GetProp(hWnd, NativeDialogWndProcProp));
45ee87a35349 6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents: 1954
diff changeset
    69
    return ComCtl32Util::GetInstance().DefWindowProc(lpfnWndProc, hWnd, message, wParam, lParam);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
static UINT_PTR CALLBACK
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
PrintDialogHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    switch(uiMsg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        case WM_INITDIALOG: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            PRINTDLG *pd = (PRINTDLG *)lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            jobject peer = (jobject)(pd->lCustData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            env->CallVoidMethod(peer, AwtPrintDialog::setHWndMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                                (jlong)hdlg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            ::SetProp(hdlg, ModalDialogPeerProp, reinterpret_cast<HANDLE>(peer));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            // fix for 4632159 - disable CS_SAVEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            DWORD style = ::GetClassLong(hdlg, GCL_STYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            ::SetClassLong(hdlg,GCL_STYLE, style & ~CS_SAVEBITS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            ::SetFocus(hdlg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            // set appropriate icon for parentless dialogs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            jobject awtParent = env->GetObjectField(peer, AwtPrintDialog::parentID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            if (awtParent == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                ::SendMessage(hdlg, WM_SETICON, (WPARAM)ICON_BIG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                              (LPARAM)AwtToolkit::GetInstance().GetAwtIcon());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                env->DeleteLocalRef(awtParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            // subclass dialog's parent to receive additional messages
2456
45ee87a35349 6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents: 1954
diff changeset
   103
            WNDPROC lpfnWndProc = ComCtl32Util::GetInstance().SubclassHWND(hdlg,
45ee87a35349 6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents: 1954
diff changeset
   104
                                                                           PrintDialogWndProc);
45ee87a35349 6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents: 1954
diff changeset
   105
            ::SetProp(hdlg, NativeDialogWndProcProp, reinterpret_cast<HANDLE>(lpfnWndProc));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        case WM_DESTROY: {
2456
45ee87a35349 6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents: 1954
diff changeset
   110
            WNDPROC lpfnWndProc = (WNDPROC)(::GetProp(hdlg, NativeDialogWndProcProp));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            ComCtl32Util::GetInstance().UnsubclassHWND(hdlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                                       PrintDialogWndProc,
2456
45ee87a35349 6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents: 1954
diff changeset
   113
                                                       lpfnWndProc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            ::RemoveProp(hdlg, ModalDialogPeerProp);
2456
45ee87a35349 6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents: 1954
diff changeset
   115
            ::RemoveProp(hdlg, NativeDialogWndProcProp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    CATCH_BAD_ALLOC_RET(TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
void AwtPrintDialog::_ToFront(void *param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    jobject self = (jobject)param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    HWND hdlg = (HWND)(env->GetLongField(self, AwtComponent::hwndID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    if (::IsWindow(hdlg))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        ::SetWindowPos(hdlg, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    env->DeleteGlobalRef(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
void AwtPrintDialog::_ToBack(void *param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    jobject self = (jobject)param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    HWND hdlg = (HWND)(env->GetLongField(self, AwtComponent::hwndID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    if (::IsWindow(hdlg))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        ::SetWindowPos(hdlg, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    env->DeleteGlobalRef(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
Java_sun_awt_windows_WPrintDialog_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    AwtPrintDialog::controlID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        env->GetFieldID(cls, "pjob", "Ljava/awt/print/PrinterJob;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    DASSERT(AwtPrintDialog::controlID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    AwtPrintControl::initIDs(env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
Java_sun_awt_windows_WPrintDialog_setPeer(JNIEnv *env, jobject target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                          jobject peer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    env->SetObjectField(target, AwtComponent::peerID, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
Java_sun_awt_windows_WPrintDialogPeer_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    AwtPrintDialog::parentID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        env->GetFieldID(cls, "parent", "Lsun/awt/windows/WComponentPeer;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    AwtPrintDialog::setHWndMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        env->GetMethodID(cls, "setHWnd", "(J)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    DASSERT(AwtPrintDialog::parentID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    DASSERT(AwtPrintDialog::setHWndMID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
Java_sun_awt_windows_WPrintDialogPeer__1show(JNIEnv *env, jobject peer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    jboolean result = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    // as peer object is used later on another thread, create a global ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    jobject peerGlobalRef = env->NewGlobalRef(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    DASSERT(peerGlobalRef != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    jobject target = env->GetObjectField(peerGlobalRef, AwtObject::targetID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    DASSERT(target != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    jobject parent = env->GetObjectField(peerGlobalRef, AwtPrintDialog::parentID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    jobject control = env->GetObjectField(target, AwtPrintDialog::controlID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    DASSERT(control != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    AwtComponent *awtParent = (parent != NULL) ? (AwtComponent *)JNI_GET_PDATA(parent) : NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    HWND hwndOwner = awtParent ? awtParent->GetHWnd() : NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    PRINTDLG pd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    memset(&pd, 0, sizeof(PRINTDLG));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    pd.lStructSize = sizeof(PRINTDLG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    pd.lCustData = (LPARAM)peerGlobalRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    BOOL ret = AwtPrintControl::InitPrintDialog(env, control, pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    if (!ret) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        /* Couldn't use the printer, or spooler isn't running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
         * Call Page dialog with ' PD_RETURNDEFAULT' so it doesn't try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
         * to show the dialog, but does prompt the user to install a printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
         * If this returns false, then they declined and we just return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        ret = AwtPrintDialog::PrintDlg(&pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    if (!ret) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
      result = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
      pd.lpfnPrintHook = (LPPRINTHOOKPROC)PrintDialogHookProc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
      pd.lpfnSetupHook = (LPSETUPHOOKPROC)PrintDialogHookProc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
      pd.Flags |= PD_ENABLESETUPHOOK | PD_ENABLEPRINTHOOK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
          Fix for 6488834.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
          To disable Win32 native parent modality we have to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
          hwndOwner field to either NULL or some hidden window. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
          parentless dialogs we use NULL to show them in the taskbar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
          and for all other dialogs AwtToolkit's HWND is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
      if (awtParent != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
          pd.hwndOwner = AwtToolkit::GetInstance().GetHWnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
          pd.hwndOwner = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      AwtDialog::CheckInstallModalHook();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      BOOL ret = AwtPrintDialog::PrintDlg(&pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      if (ret)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        AwtPrintControl::UpdateAttributes(env, control, pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        result = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        result = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
      DASSERT(env->GetLongField(peer, AwtComponent::hwndID) == 0L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      AwtDialog::CheckUninstallModalHook();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      AwtDialog::ModalActivateNextWindow(NULL, target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    env->DeleteGlobalRef(peerGlobalRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    if (parent != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
      env->DeleteLocalRef(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    env->DeleteLocalRef(control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    CATCH_BAD_ALLOC_RET(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
Java_sun_awt_windows_WPrintDialogPeer_toFront(JNIEnv *env, jobject peer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    AwtToolkit::GetInstance().SyncCall(AwtPrintDialog::_ToFront,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                                       (void *)(env->NewGlobalRef(peer)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    // global ref is deleted in _ToFront
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
Java_sun_awt_windows_WPrintDialogPeer_toBack(JNIEnv *env, jobject peer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    AwtToolkit::GetInstance().SyncCall(AwtPrintDialog::_ToBack,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                       (void *)(env->NewGlobalRef(peer)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    // global ref is deleted in _ToBack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
} /* extern "C" */