jdk/src/windows/native/sun/windows/awt_Toolkit.cpp
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7952 5290e1887780
child 9050 26c2c1de1631
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7952
diff changeset
     2
 * Copyright (c) 1996, 2011, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 6642
diff changeset
    26
#define _JNI_IMPLEMENTATION_
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 6642
diff changeset
    27
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 887
diff changeset
    28
#include "awt.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <signal.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <windowsx.h>
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
    31
#include <process.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "awt_DrawingSurface.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "awt_AWTEvent.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "awt_Canvas.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "awt_Clipboard.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "awt_Frame.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "awt_Dialog.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "awt_Font.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include "awt_Cursor.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "awt_InputEvent.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "awt_KeyEvent.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "awt_List.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "awt_Palette.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "awt_PopupMenu.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#include "awt_Toolkit.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#include "awt_DesktopProperties.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#include "awt_FileDialog.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include "CmdIDList.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#include "awt_new.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#include "debug_trace.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#include "debug_mem.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#include "ComCtl32Util.h"
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
    56
#include "DllUtil.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
    58
#include "D3DPipelineManager.h"
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
    59
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#include <awt_DnDDT.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
#include <awt_DnDDS.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#include <java_awt_Toolkit.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#include <java_awt_event_InputMethodEvent.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#include <java_awt_peer_ComponentPeer.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
extern void initScreens(JNIEnv *env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
extern "C" void awt_dnd_initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
extern "C" void awt_dnd_uninitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
extern "C" void awt_clipboard_uninitialize(JNIEnv *env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
extern "C" BOOL g_bUserHasChangedInputLang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
extern CriticalSection windowMoveLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
extern BOOL windowMoveLockHeld;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
// Needed by JAWT: see awt_DrawingSurface.cpp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
extern jclass jawtVImgClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
extern jclass jawtVSMgrClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
extern jclass jawtComponentClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
extern jfieldID jawtPDataID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
extern jfieldID jawtSDataID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
extern jfieldID jawtSMgrID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
    84
extern void DWMResetCompositionEnabled();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
    85
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * Utilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
/* Initialize the Java VM instance variable when the library is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
   first loaded */
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
    92
JavaVM *jvm = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
JNI_OnLoad(JavaVM *vm, void *reserved)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    jvm = vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    return JNI_VERSION_1_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    CATCH_BAD_ALLOC_RET(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
extern "C" JNIEXPORT jboolean JNICALL AWTIsHeadless() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    static JNIEnv *env = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    static jboolean isHeadless;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    jmethodID headlessFn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    jclass graphicsEnvClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    if (env == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        graphicsEnvClass = env->FindClass(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            "java/awt/GraphicsEnvironment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (graphicsEnvClass == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        headlessFn = env->GetStaticMethodID(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            graphicsEnvClass, "isHeadless", "()Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (headlessFn == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        isHeadless = env->CallStaticBooleanMethod(graphicsEnvClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            headlessFn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    return isHeadless;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
#define IDT_AWT_MOUSECHECK 0x101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
static LPCTSTR szAwtToolkitClassName = TEXT("SunAwtToolkit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
6642
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5506
diff changeset
   133
static const int MOUSE_BUTTONS_WINDOWS_SUPPORTED = 5; //three standard buttons + XBUTTON1 + XBUTTON2.
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5506
diff changeset
   134
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
UINT AwtToolkit::GetMouseKeyState()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    static BOOL mbSwapped = ::GetSystemMetrics(SM_SWAPBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    UINT mouseKeyState = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    if (HIBYTE(::GetKeyState(VK_CONTROL)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        mouseKeyState |= MK_CONTROL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    if (HIBYTE(::GetKeyState(VK_SHIFT)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        mouseKeyState |= MK_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    if (HIBYTE(::GetKeyState(VK_LBUTTON)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        mouseKeyState |= (mbSwapped ? MK_RBUTTON : MK_LBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    if (HIBYTE(::GetKeyState(VK_RBUTTON)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        mouseKeyState |= (mbSwapped ? MK_LBUTTON : MK_RBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    if (HIBYTE(::GetKeyState(VK_MBUTTON)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        mouseKeyState |= MK_MBUTTON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    return mouseKeyState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
// Normal ::GetKeyboardState call only works if current thread has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
// a message pump, so provide a way for other threads to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
// the keyboard state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
void AwtToolkit::GetKeyboardState(PBYTE keyboardState)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    CriticalSection::Lock       l(AwtToolkit::GetInstance().m_lockKB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    DASSERT(!IsBadWritePtr(keyboardState, KB_STATE_SIZE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    memcpy(keyboardState, AwtToolkit::GetInstance().m_lastKeyboardState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
           KB_STATE_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
void AwtToolkit::SetBusy(BOOL busy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    static jclass awtAutoShutdownClass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    static jmethodID notifyBusyMethodID = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    static jmethodID notifyFreeMethodID = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    if (awtAutoShutdownClass == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        jclass awtAutoShutdownClassLocal = env->FindClass("sun/awt/AWTAutoShutdown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            env->ExceptionDescribe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            env->ExceptionClear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        DASSERT(awtAutoShutdownClassLocal != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (awtAutoShutdownClassLocal == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        awtAutoShutdownClass = (jclass)env->NewGlobalRef(awtAutoShutdownClassLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        env->DeleteLocalRef(awtAutoShutdownClassLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        notifyBusyMethodID = env->GetStaticMethodID(awtAutoShutdownClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                                    "notifyToolkitThreadBusy", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            env->ExceptionDescribe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            env->ExceptionClear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        notifyFreeMethodID = env->GetStaticMethodID(awtAutoShutdownClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                                    "notifyToolkitThreadFree", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            env->ExceptionDescribe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            env->ExceptionClear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        DASSERT(notifyBusyMethodID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        DASSERT(notifyFreeMethodID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (notifyBusyMethodID == NULL || notifyFreeMethodID == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    } /* awtAutoShutdownClass == NULL*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    if (busy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        env->CallStaticVoidMethod(awtAutoShutdownClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                  notifyBusyMethodID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        env->CallStaticVoidMethod(awtAutoShutdownClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                  notifyFreeMethodID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        env->ExceptionDescribe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        env->ExceptionClear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
BOOL AwtToolkit::activateKeyboardLayout(HKL hkl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    // This call should succeed in case of one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    // 1. Win 9x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    // 2. NT with that HKL already loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    HKL prev = ::ActivateKeyboardLayout(hkl, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    // If the above call fails, try loading the layout in case of NT
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 887
diff changeset
   228
    if (!prev) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        // create input locale string, e.g., "00000409", from hkl.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        TCHAR inputLocale[9];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        TCHAR buf[9];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        _tcscpy(inputLocale, TEXT("00000000"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    // 64-bit: ::LoadKeyboardLayout() is such a weird API - a string of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    // the hex value you want?!  Here we're converting our HKL value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    // a string.  Hopefully there is no 64-bit trouble.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        _i64tot(reinterpret_cast<INT_PTR>(hkl), buf, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        size_t len = _tcslen(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        memcpy(&inputLocale[8-len], buf, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        // load and activate the keyboard layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        hkl = ::LoadKeyboardLayout(inputLocale, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (hkl != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            prev = ::ActivateKeyboardLayout(hkl, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    return (prev != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * Exported functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
extern "C" BOOL APIENTRY DllMain(HANDLE hInstance, DWORD ul_reason_for_call,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                 LPVOID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    // Don't use the TRY and CATCH_BAD_ALLOC_RET macros if we're detaching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    // the library. Doing so causes awt.dll to call back into the VM during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    // shutdown. This crashes the HotSpot VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    switch (ul_reason_for_call) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    case DLL_PROCESS_ATTACH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        AwtToolkit::GetInstance().SetModuleHandle((HMODULE)hInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        CATCH_BAD_ALLOC_RET(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    case DLL_PROCESS_DETACH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        DTrace_DisableMutex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        DMem_DisableMutex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
#endif DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * AwtToolkit fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
AwtToolkit AwtToolkit::theInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
/* ids for WToolkit fields accessed from native code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
jmethodID AwtToolkit::windowsSettingChangeMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
jmethodID AwtToolkit::displayChangeMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
/* ids for Toolkit methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
jmethodID AwtToolkit::getDefaultToolkitMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
jmethodID AwtToolkit::getFontMetricsMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
jmethodID AwtToolkit::insetsMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 * AwtToolkit methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
AwtToolkit::AwtToolkit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    m_localPump = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    m_mainThreadId = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    m_toolkitHWnd = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    m_inputMethodHWnd = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    m_verbose = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    m_isActive = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    m_isDisposed = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    m_vmSignalled = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    m_isDynamicLayoutSet = FALSE;
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
   307
    m_areExtraMouseButtonsEnabled = TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    m_verifyComponents = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    m_breakOnError = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    m_breakMessageLoop = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    m_messageLoopResult = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    m_lastMouseOver = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    m_mouseDown = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    m_hGetMessageHook = 0;
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
   319
    m_hMouseLLHook = 0;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
   320
    m_lastWindowUnderMouse = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    m_timer = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    m_cmdIDs = new AwtCmdIDList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    m_pModalDialog = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    m_peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    m_dllHandle = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    m_displayChanged = FALSE;
105
e08ac2105adc 6595651: Focus transfers broken for applications embedding AWT across processes
son
parents: 2
diff changeset
   329
    m_embedderProcessID = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    // XXX: keyboard mapping should really be moved out of AwtComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    AwtComponent::InitDynamicKeyMapTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    // initialize kb state array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    ::GetKeyboardState(m_lastKeyboardState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    m_waitEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    eventNumber = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
AwtToolkit::~AwtToolkit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
 *  The code has been moved to AwtToolkit::Dispose() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
HWND AwtToolkit::CreateToolkitWnd(LPCTSTR name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    HWND hwnd = CreateWindow(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        szAwtToolkitClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        (LPCTSTR)name,                    /* window name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        WS_DISABLED,                      /* window style */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        -1, -1,                           /* position of window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        0, 0,                             /* width and height */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        NULL, NULL,                       /* hWndParent and hWndMenu */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        GetModuleHandle(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        NULL);                            /* lpParam */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    DASSERT(hwnd != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    return hwnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   362
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   363
struct ToolkitThreadProc_Data {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   364
    bool result;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   365
    HANDLE hCompleted;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   366
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   367
    jobject thread;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   368
};
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   369
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   370
void ToolkitThreadProc(void *param)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   371
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   372
    ToolkitThreadProc_Data *data = (ToolkitThreadProc_Data *)param;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   373
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   374
    bool bNotified = false;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   375
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   376
    JNIEnv *env;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   377
    JavaVMAttachArgs attachArgs;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   378
    attachArgs.version  = JNI_VERSION_1_2;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   379
    attachArgs.name     = "AWT-Windows";
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   380
    attachArgs.group    = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   381
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   382
    jint res = jvm->AttachCurrentThreadAsDaemon((void **)&env, &attachArgs);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   383
    if (res < 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   384
        return;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   385
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   386
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   387
    jobject thread = env->NewGlobalRef(data->thread);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   388
    if (thread != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   389
        jclass cls = env->GetObjectClass(thread);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   390
        if (cls != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   391
            jmethodID runId = env->GetMethodID(cls, "run", "()V");
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   392
            if (runId != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   393
                data->result = true;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   394
                ::SetEvent(data->hCompleted);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   395
                bNotified = true;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   396
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   397
                env->CallVoidMethod(thread, runId);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   398
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   399
                if (env->ExceptionCheck()) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   400
                    env->ExceptionDescribe();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   401
                    env->ExceptionClear();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   402
                    // TODO: handle
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   403
                }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   404
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   405
            env->DeleteLocalRef(cls);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   406
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   407
        env->DeleteGlobalRef(thread);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   408
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   409
    if (!bNotified) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   410
        ::SetEvent(data->hCompleted);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   411
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   412
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   413
    jvm->DetachCurrentThread();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   414
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   415
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   416
/*
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   417
 * Class:     sun_awt_windows_WToolkit
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   418
 * Method:    startToolkitThread
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   419
 * Signature: (Ljava/lang/Runnable;)Z
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   420
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   421
JNIEXPORT jboolean JNICALL
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   422
Java_sun_awt_windows_WToolkit_startToolkitThread(JNIEnv *env, jclass cls, jobject thread)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   423
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   424
    AwtToolkit& tk = AwtToolkit::GetInstance();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   425
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   426
    ToolkitThreadProc_Data data;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   427
    data.result = false;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   428
    data.thread = env->NewGlobalRef(thread);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   429
    if (data.thread == NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   430
        return JNI_FALSE;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   431
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   432
    data.hCompleted = ::CreateEvent(NULL, FALSE, FALSE, NULL);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   433
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   434
    bool result = tk.GetPreloadThread()
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   435
                    .InvokeAndTerminate(ToolkitThreadProc, &data);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   436
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   437
    if (result) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   438
        ::WaitForSingleObject(data.hCompleted, INFINITE);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   439
        result = data.result;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   440
    } else {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   441
        // no awt preloading
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   442
        // return back to the usual toolkit way
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   443
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   444
    ::CloseHandle(data.hCompleted);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   445
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   446
    env->DeleteGlobalRef(data.thread);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   447
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   448
    return result ? JNI_TRUE : JNI_FALSE;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   449
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   450
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
BOOL AwtToolkit::Initialize(BOOL localPump) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    AwtToolkit& tk = AwtToolkit::GetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    if (!tk.m_isActive || tk.m_mainThreadId != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        /* Already initialized. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    // This call is moved here from AwtToolkit constructor. Having it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    // there led to the bug 6480630: there could be a situation when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    // ComCtl32Util was constructed but not disposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    ComCtl32Util::GetInstance().InitLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   464
    if (!localPump) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   465
        // if preload thread was run, terminate it
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   466
        preloadThread.Terminate(true);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   467
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   468
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /* Register this toolkit's helper window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    VERIFY(tk.RegisterClass() != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    // Set up operator new/malloc out of memory handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    NewHandler::init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        // Bugs 4032109, 4047966, and 4071991 to fix AWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        //      crash in 16 color display mode.  16 color mode is supported.  Less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        //      than 16 color is not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        // creighto@eng.sun.com 1997-10-07
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        // Check for at least 16 colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    HDC hDC = ::GetDC(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if ((::GetDeviceCaps(hDC, BITSPIXEL) * ::GetDeviceCaps(hDC, PLANES)) < 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                ::MessageBox(NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                             TEXT("Sorry, but this release of Java requires at least 16 colors"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                             TEXT("AWT Initialization Error"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                             MB_ICONHAND | MB_APPLMODAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                ::DeleteDC(hDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                JNU_ThrowByName(env, "java/lang/InternalError",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                "unsupported screen depth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    ::ReleaseDC(NULL, hDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        ///////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    tk.m_localPump = localPump;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    tk.m_mainThreadId = ::GetCurrentThreadId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * Create the one-and-only toolkit window.  This window isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * displayed, but is used to route messages to this thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    tk.m_toolkitHWnd = tk.CreateToolkitWnd(TEXT("theAwtToolkitWindow"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    DASSERT(tk.m_toolkitHWnd != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * Setup a GetMessage filter to watch all messages coming out of our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * queue from PreProcessMsg().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    tk.m_hGetMessageHook = ::SetWindowsHookEx(WH_GETMESSAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                                              (HOOKPROC)GetMessageFilter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                                              0, tk.m_mainThreadId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    awt_dnd_initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
BOOL AwtToolkit::Dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    DTRACE_PRINTLN("In AwtToolkit::Dispose()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    AwtToolkit& tk = AwtToolkit::GetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    if (!tk.m_isActive || tk.m_mainThreadId != ::GetCurrentThreadId()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    tk.m_isActive = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    awt_dnd_uninitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    awt_clipboard_uninitialize((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   534
    // dispose Direct3D-related resources. This should be done
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   535
    // before AwtObjectList::Cleanup() as the d3d will attempt to
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   536
    // shutdown when the last of its windows is disposed of
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
   537
    D3DInitializer::GetInstance().Clean();
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   538
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    AwtObjectList::Cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    AwtFont::Cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    if (tk.m_inputMethodHWnd != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        ::SendMessage(tk.m_inputMethodHWnd, WM_IME_CONTROL, IMC_OPENSTATUSWINDOW, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    tk.m_inputMethodHWnd = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    // wait for any messages to be processed, in particular,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    // all WM_AWT_DELETEOBJECT messages that delete components; no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    // new messages will appear as all the windows except toolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    // window are unsubclassed and destroyed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    MSG msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    while (::GetMessage(&msg, NULL, 0, 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        ::TranslateMessage(&msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        ::DispatchMessage(&msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    HWND toolkitHWndToDestroy = tk.m_toolkitHWnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    tk.m_toolkitHWnd = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    VERIFY(::DestroyWindow(toolkitHWndToDestroy) != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    tk.UnregisterClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    ::UnhookWindowsHookEx(tk.m_hGetMessageHook);
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
   564
    UninstallMouseLowLevelHook();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    tk.m_mainThreadId = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    delete tk.m_cmdIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    ::CloseHandle(m_waitEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    tk.m_isDisposed = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
void AwtToolkit::SetDynamicLayout(BOOL dynamic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    m_isDynamicLayoutSet = dynamic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
BOOL AwtToolkit::IsDynamicLayoutSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    return m_isDynamicLayoutSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
BOOL AwtToolkit::IsDynamicLayoutSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    // SPI_GETDRAGFULLWINDOWS is only supported on Win95 if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    // Windows Plus! is installed.  Otherwise, box frame resize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    BOOL fullWindowDragEnabled = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    int result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    result = ::SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                                  &fullWindowDragEnabled, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    return (fullWindowDragEnabled && (result != 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
BOOL AwtToolkit::IsDynamicLayoutActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    return (IsDynamicLayoutSet() && IsDynamicLayoutSupported());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
ATOM AwtToolkit::RegisterClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    WNDCLASS  wc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    wc.style         = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    wc.lpfnWndProc   = (WNDPROC)WndProc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    wc.cbClsExtra    = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    wc.cbWndExtra    = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    wc.hInstance     = AwtToolkit::GetInstance().GetModuleHandle(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    wc.hIcon         = AwtToolkit::GetInstance().GetAwtIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    wc.hCursor       = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    wc.lpszMenuName  = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    wc.lpszClassName = szAwtToolkitClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    ATOM ret = ::RegisterClass(&wc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    DASSERT(ret != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
void AwtToolkit::UnregisterClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    VERIFY(::UnregisterClass(szAwtToolkitClassName, AwtToolkit::GetInstance().GetModuleHandle()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
 * Structure holding the information to create a component. This packet is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
 * sent to the toolkit window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
struct ComponentCreatePacket {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    void* hComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    void* hParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    void (*factory)(void*, void*);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
 * Create an AwtXxxx component using a given factory function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
 * Implemented by sending a message to the toolkit window to invoke the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
 * factory function from that thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
void AwtToolkit::CreateComponent(void* component, void* parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                                 ComponentFactory compFactory, BOOL isParentALocalReference)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    /* Since Local references are not valid in another Thread, we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
       create a global reference before we send this to the Toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
       In some cases this method is called with parent being a native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
       malloced struct so we cannot and do not need to create a Global
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
       Reference from it. This is indicated by isParentALocalReference */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    jobject gcomponent = env->NewGlobalRef((jobject)component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    jobject gparent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    if (isParentALocalReference) gparent = env->NewGlobalRef((jobject)parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    ComponentCreatePacket ccp = { gcomponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                                  isParentALocalReference == TRUE ?  gparent : parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                                   compFactory };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    AwtToolkit::GetInstance().SendMessage(WM_AWT_COMPONENT_CREATE, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                                          (LPARAM)&ccp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    env->DeleteGlobalRef(gcomponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    if (isParentALocalReference) env->DeleteGlobalRef(gparent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
 * Destroy an HWND that was created in the toolkit thread. Can be used on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
 * Components and the toolkit window itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
void AwtToolkit::DestroyComponentHWND(HWND hwnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    if (!::IsWindow(hwnd)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    AwtToolkit& tk = AwtToolkit::GetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    if ((tk.m_lastMouseOver != NULL) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        (tk.m_lastMouseOver->GetHWnd() == hwnd))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        tk.m_lastMouseOver = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    ::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    tk.SendMessage(WM_AWT_DESTROY_WINDOW, (WPARAM)hwnd, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
#ifndef SPY_MESSAGES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
#define SpyWinMessage(hwin,msg,str)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
void SpyWinMessage(HWND hwnd, UINT message, LPCTSTR szComment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
 * An AwtToolkit window is just a means of routing toolkit messages to here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
LRESULT CALLBACK AwtToolkit::WndProc(HWND hWnd, UINT message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                                     WPARAM wParam, LPARAM lParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    JNIEnv *env = GetEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    JNILocalFrame lframe(env, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    SpyWinMessage(hWnd, message, TEXT("AwtToolkit"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    AwtToolkit::GetInstance().eventNumber++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * Awt widget creation messages are routed here so that all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * widgets are created on the main thread.  Java allows widgets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * to live beyond their creating thread -- by creating them on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * the main thread, a widget can always be properly disposed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    switch (message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
      case WM_AWT_EXECUTE_SYNC: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
          jobject peerObject = (jobject)wParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
          AwtObject* object = (AwtObject *)JNI_GET_PDATA(peerObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
          DASSERT( !IsBadReadPtr(object, sizeof(AwtObject)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
          AwtObject::ExecuteArgs *args = (AwtObject::ExecuteArgs *)lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
          DASSERT(!IsBadReadPtr(args, sizeof(AwtObject::ExecuteArgs)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
          LRESULT result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
          if (object != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
              result = object->WinThreadExecProc(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
          env->DeleteGlobalRef(peerObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
          return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
      case WM_AWT_COMPONENT_CREATE: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
          ComponentCreatePacket* ccp = (ComponentCreatePacket*)lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
          DASSERT(ccp->factory != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
          DASSERT(ccp->hComponent != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
          (*ccp->factory)(ccp->hComponent, ccp->hParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
      case WM_AWT_DESTROY_WINDOW: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
          /* Destroy widgets from this same thread that created them */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
          VERIFY(::DestroyWindow((HWND)wParam) != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
      case WM_AWT_DISPOSE: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
          BOOL canDispose = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
          CriticalSection &syncCS = AwtToolkit::GetInstance().GetSyncCS();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
          int shouldEnterCriticalSection = (int)lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
          if (shouldEnterCriticalSection == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
              canDispose = syncCS.TryEnter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
          if (canDispose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
              AwtObject *o = (AwtObject *)wParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
              o->Dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
              if (shouldEnterCriticalSection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                  syncCS.Leave();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
              AwtToolkit::GetInstance().PostMessage(WM_AWT_DISPOSE, wParam, lParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
      case WM_AWT_DELETEOBJECT: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
          AwtObject *p = (AwtObject *)wParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
          if (p->CanBeDeleted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
              // all the messages for this component are processed, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
              // it can be deleted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
              delete p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
              // postpone deletion, waiting for all the messages for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
              // component to be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
              AwtToolkit::GetInstance().PostMessage(WM_AWT_DELETEOBJECT, wParam, (LPARAM)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
      case WM_AWT_OBJECTLISTCLEANUP: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
          AwtObjectList::Cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
      case WM_SYSCOLORCHANGE: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
          jclass systemColorClass = env->FindClass("java/awt/SystemColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
          DASSERT(systemColorClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
          jmethodID mid = env->GetStaticMethodID(systemColorClass, "updateSystemColors", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
          DASSERT(mid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
          env->CallStaticVoidMethod(systemColorClass, mid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
          /* FALL THROUGH - NO BREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
      case WM_SETTINGCHANGE: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
          AwtWin32GraphicsDevice::ResetAllMonitorInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
          /* FALL THROUGH - NO BREAK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
// Remove this define when we move to newer (XP) version of SDK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
#define WM_THEMECHANGED                 0x031A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
      case WM_THEMECHANGED: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
          /* Upcall to WToolkit when user changes configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
           *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
           * NOTE: there is a bug in Windows 98 and some older versions of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
           * Windows NT (it seems to be fixed in NT4 SP5) where no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
           * WM_SETTINGCHANGE is sent when any of the properties under
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
           * Control Panel -> Display are changed.  You must _always_ query
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
           * the system for these - you can't rely on cached values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
           */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
          jobject peer = AwtToolkit::GetInstance().m_peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
          if (peer != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
              env->CallVoidMethod(peer, AwtToolkit::windowsSettingChangeMID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
      }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   804
#ifndef WM_DWMCOMPOSITIONCHANGED
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   805
#define WM_DWMCOMPOSITIONCHANGED        0x031E
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   806
#define WM_DWMNCRENDERINGCHANGED        0x031F
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   807
#define WM_DWMCOLORIZATIONCOLORCHANGED  0x0320
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   808
#define WM_DWMWINDOWMAXIMIZEDCHANGED    0x0321
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   809
#endif // WM_DWMCOMPOSITIONCHANGED
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   810
      case WM_DWMCOMPOSITIONCHANGED: {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   811
          DWMResetCompositionEnabled();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   812
          return 0;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   813
      }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 105
diff changeset
   814
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
      case WM_TIMER: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
          // 6479820. Should check if a window is in manual resizing process: skip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
          // sending any MouseExit/Enter events while inside resize-loop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
          // Note that window being in manual moving process could still
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
          // produce redundant enter/exit mouse events. In future, they can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
          // made skipped in a similar way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
           if (AwtWindow::IsResizing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
               return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
          // Create an artifical MouseExit message if the mouse left to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
          // a non-java window (bad mouse!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
          POINT pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
          AwtToolkit& tk = AwtToolkit::GetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
          if (::GetCursorPos(&pt)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
              HWND hWndOver = ::WindowFromPoint(pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
              AwtComponent * last_M;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
              if ( AwtComponent::GetComponent(hWndOver) == NULL && tk.m_lastMouseOver != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                  last_M = tk.m_lastMouseOver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                  // translate point from screen to target window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                  MapWindowPoints(HWND_DESKTOP, last_M->GetHWnd(), &pt, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                  last_M->SendMessage(WM_AWT_MOUSEEXIT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                                      GetMouseKeyState(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                                      POINTTOPOINTS(pt));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                  tk.m_lastMouseOver = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
          if (tk.m_lastMouseOver == NULL && tk.m_timer != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
              VERIFY(::KillTimer(tk.m_toolkitHWnd, tk.m_timer));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
              tk.m_timer = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
      case WM_DESTROYCLIPBOARD: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
          if (!AwtClipboard::IsGettingOwnership())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
              AwtClipboard::LostOwnership((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
      case WM_CHANGECBCHAIN: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
          AwtClipboard::WmChangeCbChain(wParam, lParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
      case WM_DRAWCLIPBOARD: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
          AwtClipboard::WmDrawClipboard((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), wParam, lParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
      case WM_AWT_LIST_SETMULTISELECT: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
          jobject peerObject = (jobject)wParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
          AwtList* list = (AwtList *)JNI_GET_PDATA(peerObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
          DASSERT( !IsBadReadPtr(list, sizeof(AwtObject)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
          list->SetMultiSelect(static_cast<BOOL>(lParam));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
      // Special awt message to call Imm APIs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
      // ImmXXXX() API must be used in the main thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
      // In other thread these APIs does not work correctly even if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
      // it returs with no error. (This restriction is not documented)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
      // So we must use thse messages to call these APIs in main thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
      case WM_AWT_CREATECONTEXT: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        return reinterpret_cast<LRESULT>(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            reinterpret_cast<void*>(ImmCreateContext()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
      case WM_AWT_DESTROYCONTEXT: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
          ImmDestroyContext((HIMC)wParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
      case WM_AWT_ASSOCIATECONTEXT: {
2952
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   882
          EnableNativeIMEStruct *data = (EnableNativeIMEStruct*)wParam;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   883
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   884
          jobject peer = data->peer;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   885
          jobject self = data->self;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   886
          jint context = data->context;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   887
          jboolean useNativeCompWindow = data->useNativeCompWindow;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   888
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   889
          AwtComponent* comp = (AwtComponent*)JNI_GET_PDATA(peer);
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   890
          if (comp != NULL)
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   891
          {
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   892
              comp->SetInputMethod(self, useNativeCompWindow);
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   893
              comp->ImmAssociateContext((HIMC)context);
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   894
          }
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   895
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   896
          if (peer != NULL) {
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   897
              env->DeleteGlobalRef(peer);
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   898
          }
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   899
          if (self != NULL) {
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   900
              env->DeleteGlobalRef(self);
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   901
          }
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   902
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   903
          delete data;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   904
          return 0;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   905
      }
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   906
      case WM_AWT_GET_DEFAULT_IME_HANDLER: {
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   907
          LRESULT ret = (LRESULT)FALSE;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   908
          jobject peer = (jobject)wParam;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   909
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   910
          AwtComponent* comp = (AwtComponent*)JNI_GET_PDATA(peer);
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   911
          if (comp != NULL) {
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   912
              HWND defaultIMEHandler = ImmGetDefaultIMEWnd(comp->GetHWnd());
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   913
              if (defaultIMEHandler != NULL) {
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   914
                  AwtToolkit::GetInstance().SetInputMethodWindow(defaultIMEHandler);
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   915
                  ret = (LRESULT)TRUE;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   916
              }
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   917
          }
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   918
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   919
          if (peer != NULL) {
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   920
              env->DeleteGlobalRef(peer);
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   921
          }
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   922
          return ret;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   923
      }
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   924
      case WM_AWT_HANDLE_NATIVE_IME_EVENT: {
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   925
          jobject peer = (jobject)wParam;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   926
          AwtComponent* comp = (AwtComponent*)JNI_GET_PDATA(peer);
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   927
          MSG* msg = (MSG*)lParam;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   928
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   929
          long modifiers = comp->GetJavaModifiers();
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   930
          if ((comp != NULL) && (msg->message==WM_CHAR || msg->message==WM_SYSCHAR)) {
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   931
              WCHAR unicodeChar = (WCHAR)msg->wParam;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   932
              comp->SendKeyEvent(java_awt_event_KeyEvent_KEY_TYPED,
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   933
                                 0, //to be fixed nowMillis(),
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   934
                                 java_awt_event_KeyEvent_CHAR_UNDEFINED,
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   935
                                 unicodeChar,
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   936
                                 modifiers,
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   937
                                 java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN, (jlong)0,
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   938
                                 msg);
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   939
          } else if (comp != NULL) {
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   940
              MSG* pCopiedMsg = new MSG;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   941
              *pCopiedMsg = *msg;
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   942
              comp->SendMessage(WM_AWT_HANDLE_EVENT, (WPARAM) FALSE,
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   943
                                (LPARAM) pCopiedMsg);
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   944
          }
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   945
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   946
          if (peer != NULL) {
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   947
              env->DeleteGlobalRef(peer);
0679c7600523 6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents: 2810
diff changeset
   948
          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
      case WM_AWT_ENDCOMPOSITION: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
          /*right now we just cancel the composition string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
          may need to commit it in the furture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
          Changed to commit it according to the flag 10/29/98*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
          ImmNotifyIME((HIMC)wParam, NI_COMPOSITIONSTR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                       (lParam ? CPS_COMPLETE : CPS_CANCEL), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
      case WM_AWT_SETCONVERSIONSTATUS: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
          DWORD cmode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
          DWORD smode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
          ImmGetConversionStatus((HIMC)wParam, (LPDWORD)&cmode, (LPDWORD)&smode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
          ImmSetConversionStatus((HIMC)wParam, (DWORD)LOWORD(lParam), smode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
      case WM_AWT_GETCONVERSIONSTATUS: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
          DWORD cmode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
          DWORD smode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
          ImmGetConversionStatus((HIMC)wParam, (LPDWORD)&cmode, (LPDWORD)&smode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
          return cmode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
      case WM_AWT_ACTIVATEKEYBOARDLAYOUT: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
          if (wParam && g_bUserHasChangedInputLang) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
              // Input language has been changed since the last WInputMethod.getNativeLocale()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
              // call.  So let's honor the user's selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
              // Note: we need to check this flag inside the toolkit thread to synchronize access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
              // to the flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
              return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
          if (lParam == (LPARAM)::GetKeyboardLayout(0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
              // already active
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
              return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
          // Since ActivateKeyboardLayout does not post WM_INPUTLANGCHANGEREQUEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
          // we explicitly need to do the same thing here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
          static BYTE keyboardState[AwtToolkit::KB_STATE_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
          AwtToolkit::GetKeyboardState(keyboardState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
          WORD ignored;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
          ::ToAscii(VK_SPACE, ::MapVirtualKey(VK_SPACE, 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                    keyboardState, &ignored, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
          return (LRESULT)activateKeyboardLayout((HKL)lParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
      case WM_AWT_OPENCANDIDATEWINDOW: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
          jobject peerObject = (jobject)wParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
          AwtComponent* p = (AwtComponent*)JNI_GET_PDATA(peerObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
          DASSERT( !IsBadReadPtr(p, sizeof(AwtObject)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
          // fix for 4805862: use GET_X_LPARAM and GET_Y_LPARAM macros
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
          // instead of LOWORD and HIWORD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
          p->OpenCandidateWindow(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
          env->DeleteGlobalRef(peerObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
       * send this message via ::SendMessage() and the MPT will acquire the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
       * HANDLE synchronized with the sender's thread. The HANDLE must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
       * signalled or deadlock may occur between the MPT and the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
      case WM_AWT_WAIT_FOR_SINGLE_OBJECT: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        return ::WaitForSingleObject((HANDLE)lParam, INFINITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
      case WM_AWT_INVOKE_METHOD: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        return (LRESULT)(*(void*(*)(void*))wParam)((void *)lParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
      case WM_AWT_INVOKE_VOID_METHOD: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        return (LRESULT)(*(void*(*)(void))wParam)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
      case WM_AWT_SETOPENSTATUS: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
          ImmSetOpenStatus((HIMC)wParam, (BOOL)lParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
      case WM_AWT_GETOPENSTATUS: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
          return (DWORD)ImmGetOpenStatus((HIMC)wParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
      case WM_DISPLAYCHANGE: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
          // Reinitialize screens
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
          initScreens(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
          // Notify Java side - call WToolkit.displayChanged()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
          jclass clazz = env->FindClass("sun/awt/windows/WToolkit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
          env->CallStaticVoidMethod(clazz, AwtToolkit::displayChangeMID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
          GetInstance().m_displayChanged = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
          ::PostMessage(HWND_BROADCAST, WM_PALETTEISCHANGING, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
      case WM_AWT_SETCURSOR: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
          ::SetCursor((HCURSOR)wParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
          return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
      /* Session management */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
      case WM_QUERYENDSESSION: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
          /* Shut down cleanly */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
          if (JVM_RaiseSignal(SIGTERM)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
              AwtToolkit::GetInstance().m_vmSignalled = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
          return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
      case WM_ENDSESSION: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
          // Keep pumping messages until the shutdown sequence halts the VM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
          // or we exit the MessageLoop because of a WM_QUIT message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
          AwtToolkit& tk = AwtToolkit::GetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
          // if WM_QUERYENDSESSION hasn't successfully raised SIGTERM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
          // we ignore the ENDSESSION message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
          if (!tk.m_vmSignalled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
              return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
          tk.MessageLoop(AwtToolkit::PrimaryIdleFunc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                         AwtToolkit::CommonPeekMessageFunc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
          // Dispose here instead of in eventLoop so that we don't have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
          // to return from the WM_ENDSESSION handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
          tk.Dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
          // Never return. The VM will halt the process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
          hang_if_shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
          // Should never get here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
          DASSERT(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
      case WM_SYNC_WAIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
          SetEvent(AwtToolkit::GetInstance().m_waitEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    return DefWindowProc(hWnd, message, wParam, lParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    CATCH_BAD_ALLOC_RET(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
LRESULT CALLBACK AwtToolkit::GetMessageFilter(int code,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                                              WPARAM wParam, LPARAM lParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    if (code >= 0 && wParam == PM_REMOVE && lParam != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
       if (AwtToolkit::GetInstance().PreProcessMsg(*(MSG*)lParam) !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
               mrPassAlong) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
           /* PreProcessMsg() wants us to eat it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
           ((MSG*)lParam)->message = WM_NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    return ::CallNextHookEx(AwtToolkit::GetInstance().m_hGetMessageHook, code,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                            wParam, lParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    CATCH_BAD_ALLOC_RET(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1107
void AwtToolkit::InstallMouseLowLevelHook()
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1108
{
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1109
    // We need the low-level hook since we need to process mouse move
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1110
    // messages outside of our windows.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1111
    m_hMouseLLHook = ::SetWindowsHookEx(WH_MOUSE_LL,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1112
            (HOOKPROC)MouseLowLevelHook,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1113
            GetModuleHandle(), NULL);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1114
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1115
    // Reset the old value
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1116
    m_lastWindowUnderMouse = NULL;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1117
}
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1118
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1119
void AwtToolkit::UninstallMouseLowLevelHook()
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1120
{
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1121
    if (m_hMouseLLHook != 0) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1122
        ::UnhookWindowsHookEx(m_hMouseLLHook);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1123
        m_hMouseLLHook = 0;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1124
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1125
}
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1126
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1127
LRESULT CALLBACK AwtToolkit::MouseLowLevelHook(int code,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1128
        WPARAM wParam, LPARAM lParam)
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1129
{
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1130
    TRY;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1131
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1132
    if (code >= 0 && wParam == WM_MOUSEMOVE) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1133
        POINT pt = ((MSLLHOOKSTRUCT*)lParam)->pt;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1134
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1135
        // We can't use GA_ROOTOWNER since in this case we'll go up to
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1136
        // the root Java toplevel, not the actual owned toplevel.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1137
        HWND hwnd = ::GetAncestor(::WindowFromPoint(pt), GA_ROOT);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1138
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1139
        AwtToolkit& tk = AwtToolkit::GetInstance();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1140
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1141
        if (tk.m_lastWindowUnderMouse != hwnd) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1142
            AwtWindow *fw = NULL, *tw = NULL;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1143
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1144
            if (tk.m_lastWindowUnderMouse) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1145
                fw = (AwtWindow*)
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1146
                    AwtComponent::GetComponent(tk.m_lastWindowUnderMouse);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1147
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1148
            if (hwnd) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1149
                tw = (AwtWindow*)AwtComponent::GetComponent(hwnd);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1150
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1151
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1152
            tk.m_lastWindowUnderMouse = hwnd;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1153
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1154
            if (fw) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1155
                fw->UpdateSecurityWarningVisibility();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1156
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1157
            // ... however, because we use GA_ROOT, we may find the warningIcon
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1158
            // which is not a Java windows.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1159
            if (AwtWindow::IsWarningWindow(hwnd)) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1160
                hwnd = ::GetParent(hwnd);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1161
                if (hwnd) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1162
                    tw = (AwtWindow*)AwtComponent::GetComponent(hwnd);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1163
                }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1164
                tk.m_lastWindowUnderMouse = hwnd;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1165
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1166
            if (tw) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1167
                tw->UpdateSecurityWarningVisibility();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1168
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1169
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1170
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1171
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1172
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1173
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1174
    return ::CallNextHookEx(AwtToolkit::GetInstance().m_hMouseLLHook, code,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1175
            wParam, lParam);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1176
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1177
    CATCH_BAD_ALLOC_RET(0);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1178
}
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1179
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
 * The main message loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
const int AwtToolkit::EXIT_ENCLOSING_LOOP      = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
const int AwtToolkit::EXIT_ALL_ENCLOSING_LOOPS = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
 * Called upon event idle to ensure that we have released any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
 * CriticalSections that we took during window event processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
 * Note that this gets used more often than you would think; some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
 * window moves actually happen over more than one event burst.  So,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
 * for example, we might get a WINDOWPOSCHANGING event, then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
 * idle and release the lock here, then eventually we get the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
 * WINDOWPOSCHANGED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
 * This method may be called from WToolkit.embeddedEventLoopIdleProcessing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
 * if there is a separate event loop that must do the same CriticalSection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
 * check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
 * See bug #4526587 for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
void VerifyWindowMoveLockReleased()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    if (windowMoveLockHeld) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        windowMoveLockHeld = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        windowMoveLock.Leave();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
UINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
AwtToolkit::MessageLoop(IDLEPROC lpIdleFunc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                        PEEKMESSAGEPROC lpPeekMessageFunc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    DTRACE_PRINTLN("AWT event loop started");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    DASSERT(lpIdleFunc != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    DASSERT(lpPeekMessageFunc != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    m_messageLoopResult = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    while (!m_breakMessageLoop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        (*lpIdleFunc)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        PumpWaitingMessages(lpPeekMessageFunc); /* pumps waiting messages */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        // Catch problems with windowMoveLock critical section.  In case we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        // misunderstood the way windows processes window move/resize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        // events, we don't want to hold onto the windowMoveLock CS forever.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        // If we've finished processing events for now, release the lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        // if held.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        VerifyWindowMoveLockReleased();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    if (m_messageLoopResult == EXIT_ALL_ENCLOSING_LOOPS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        ::PostQuitMessage(EXIT_ALL_ENCLOSING_LOOPS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    m_breakMessageLoop = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    DTRACE_PRINTLN("AWT event loop ended");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    return m_messageLoopResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
 * Exit the enclosing message loop(s).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
 * The message will be ignored if Windows is currently is in an internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
 * message loop (such as a scroll bar drag). So we first send IDCANCEL and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
 * WM_CANCELMODE messages to every Window on the thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
static BOOL CALLBACK CancelAllThreadWindows(HWND hWnd, LPARAM)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    ::SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM)hWnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
    ::SendMessage(hWnd, WM_CANCELMODE, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    CATCH_BAD_ALLOC_RET(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
static void DoQuitMessageLoop(void* param) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    int status = *static_cast<int*>(param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    AwtToolkit::GetInstance().QuitMessageLoop(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
void AwtToolkit::QuitMessageLoop(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * Fix for 4623377.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * Reinvoke QuitMessageLoop on the toolkit thread, so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * m_breakMessageLoop is accessed on a single thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    if (!AwtToolkit::IsMainThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        InvokeFunction(DoQuitMessageLoop, &status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * Fix for BugTraq ID 4445747.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * EnumThreadWindows() is very slow during dnd on Win9X/ME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     * This call is unnecessary during dnd, since we postpone processing of all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * messages that can enter internal message loop until dnd is over.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
      if (status == EXIT_ALL_ENCLOSING_LOOPS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
          ::EnumThreadWindows(MainThread(), (WNDENUMPROC)CancelAllThreadWindows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                              0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     * Fix for 4623377.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * Modal loop may not exit immediatelly after WM_CANCELMODE, so it still can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     * eat WM_QUIT message and the nested message loop will never exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * The fix is to use AwtToolkit instance variables instead of WM_QUIT to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * guarantee that we exit from the nested message loop when any possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * modal loop quits. In this case CancelAllThreadWindows is needed only to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * ensure that the nested message loop exits quickly and doesn't wait until
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * a possible modal loop completes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    m_breakMessageLoop = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    m_messageLoopResult = status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * Fix for 4683602.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * Post an empty message, to wake up the toolkit thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * if it is currently in WaitMessage(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    PostMessage(WM_NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
 * Called by the message loop to pump the message queue when there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
 * messages waiting. Can also be called anywhere to pump messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
BOOL AwtToolkit::PumpWaitingMessages(PEEKMESSAGEPROC lpPeekMessageFunc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    MSG  msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    BOOL foundOne = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    DASSERT(lpPeekMessageFunc != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    while (!m_breakMessageLoop && (*lpPeekMessageFunc)(msg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        foundOne = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        if (msg.message == WM_QUIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            m_breakMessageLoop = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            m_messageLoopResult = static_cast<UINT>(msg.wParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            if (m_messageLoopResult == EXIT_ALL_ENCLOSING_LOOPS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                ::PostQuitMessage(static_cast<int>(msg.wParam));  // make sure all loops exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        else if (msg.message != WM_NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
             * The AWT in standalone mode (that is, dynamically loaded from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
             * Java VM) doesn't have any translation tables to worry about, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
             * TranslateAccelerator isn't called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            ::TranslateMessage(&msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            ::DispatchMessage(&msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
    return foundOne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
VOID CALLBACK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
AwtToolkit::PrimaryIdleFunc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    AwtToolkit::SetBusy(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    ::WaitMessage();               /* allow system to go idle */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    AwtToolkit::SetBusy(TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
VOID CALLBACK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
AwtToolkit::SecondaryIdleFunc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    ::WaitMessage();               /* allow system to go idle */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
BOOL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
AwtToolkit::CommonPeekMessageFunc(MSG& msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    return ::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
 * Perform pre-processing on a message before it is translated &
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
 * dispatched.  Returns true to eat the message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
BOOL AwtToolkit::PreProcessMsg(MSG& msg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     * Offer preprocessing first to the target component, then call out to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * specific mouse and key preprocessor methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    AwtComponent* p = AwtComponent::GetComponent(msg.hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    if (p && p->PreProcessMsg(msg) == mrConsume)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 887
diff changeset
  1377
    if ((msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST) ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        (msg.message >= WM_NCMOUSEMOVE && msg.message <= WM_NCMBUTTONDBLCLK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        if (PreProcessMouseMsg(p, msg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    else if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        if (PreProcessKeyMsg(p, msg))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
BOOL AwtToolkit::PreProcessMouseMsg(AwtComponent* p, MSG& msg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    WPARAM mouseWParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    LPARAM mouseLParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * Fix for BugTraq ID 4395290.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * Do not synthesize mouse enter/exit events during drag-and-drop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * since it messes up LightweightDispatcher.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    if (AwtDropTarget::IsLocalDnD()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 887
diff changeset
  1404
    if (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        mouseWParam = msg.wParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        mouseLParam = msg.lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
        mouseWParam = GetMouseKeyState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * Get the window under the mouse, as it will be different if its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * captured.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
    DWORD dwCurPos = ::GetMessagePos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    DWORD dwScreenPos = dwCurPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    POINT curPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    // fix for 4805862
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    // According to MSDN: do not use LOWORD and HIWORD macros to extract x and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    // y coordinates because these macros return incorrect results on systems
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    // with multiple monitors (signed values are treated as unsigned)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
    curPos.x = GET_X_LPARAM(dwCurPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
    curPos.y = GET_Y_LPARAM(dwCurPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
    HWND hWndFromPoint = ::WindowFromPoint(curPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    // hWndFromPoint == 0 if mouse is over a scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
    AwtComponent* mouseComp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        AwtComponent::GetComponent(hWndFromPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
    // Need extra copies for non-client area issues
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    AwtComponent* mouseWheelComp = mouseComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
    HWND hWndForWheel = hWndFromPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
    // If the point under the mouse isn't in the client area,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
    // ignore it to maintain compatibility with Solaris (#4095172)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
    RECT windowRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
    ::GetClientRect(hWndFromPoint, &windowRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    POINT topLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    topLeft.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    topLeft.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    ::ClientToScreen(hWndFromPoint, &topLeft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
    windowRect.top += topLeft.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    windowRect.bottom += topLeft.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    windowRect.left += topLeft.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
    windowRect.right += topLeft.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    if ((curPos.y < windowRect.top) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        (curPos.y >= windowRect.bottom) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        (curPos.x < windowRect.left) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
        (curPos.x >= windowRect.right)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        mouseComp = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        hWndFromPoint = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * Look for mouse transitions between windows & create
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     * MouseExit & MouseEnter messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    // 6479820. Should check if a window is in manual resizing process: skip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    // sending any MouseExit/Enter events while inside resize-loop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    // Note that window being in manual moving process could still
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    // produce redundant enter/exit mouse events. In future, they can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    // made skipped in a similar way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
    if (mouseComp != m_lastMouseOver && !AwtWindow::IsResizing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
         * Send the messages right to the windows so that they are in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
         * the right sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        if (m_lastMouseOver) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            dwCurPos = dwScreenPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            curPos.x = LOWORD(dwCurPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            curPos.y = HIWORD(dwCurPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            ::MapWindowPoints(HWND_DESKTOP, m_lastMouseOver->GetHWnd(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                              &curPos, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
            mouseLParam = MAKELPARAM((WORD)curPos.x, (WORD)curPos.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            m_lastMouseOver->SendMessage(WM_AWT_MOUSEEXIT, mouseWParam,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                                         mouseLParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        if (mouseComp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                dwCurPos = dwScreenPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                curPos.x = LOWORD(dwCurPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                curPos.y = HIWORD(dwCurPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                ::MapWindowPoints(HWND_DESKTOP, mouseComp->GetHWnd(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                                  &curPos, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                mouseLParam = MAKELPARAM((WORD)curPos.x, (WORD)curPos.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            mouseComp->SendMessage(WM_AWT_MOUSEENTER, mouseWParam,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                                   mouseLParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        m_lastMouseOver = mouseComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
     * For MouseWheelEvents, hwnd must be changed to be the Component under
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
     * the mouse, not the Component with the input focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
    if (msg.message == WM_MOUSEWHEEL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        mouseWheelComp != NULL) { //i.e. mouse is over client area for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                                  //window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        msg.hwnd = hWndForWheel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     * Make sure we get at least one last chance to check for transitions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     * before we sleep
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    if (m_lastMouseOver && !m_timer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        m_timer = ::SetTimer(m_toolkitHWnd, IDT_AWT_MOUSECHECK, 200, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    return FALSE;  /* Now go ahead and process current message as usual */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
BOOL AwtToolkit::PreProcessKeyMsg(AwtComponent* p, MSG& msg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
    // get keyboard state for use in AwtToolkit::GetKeyboardState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
    CriticalSection::Lock       l(m_lockKB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
    ::GetKeyboardState(m_lastKeyboardState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
void *AwtToolkit::SyncCall(void *(*ftn)(void *), void *param) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
    if (!IsMainThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        CriticalSection::Lock l(GetSyncCS());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        return (*ftn)(param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        return (*ftn)(param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
void AwtToolkit::SyncCall(void (*ftn)(void *), void *param) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    if (!IsMainThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        CriticalSection::Lock l(GetSyncCS());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        (*ftn)(param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        (*ftn)(param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
void *AwtToolkit::SyncCall(void *(*ftn)(void)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    if (!IsMainThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        CriticalSection::Lock l(GetSyncCS());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        return (*ftn)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        return (*ftn)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
void AwtToolkit::SyncCall(void (*ftn)(void)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    if (!IsMainThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        CriticalSection::Lock l(GetSyncCS());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        (*ftn)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        (*ftn)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
UINT AwtToolkit::CreateCmdID(AwtObject* object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
    return m_cmdIDs->Add(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
void AwtToolkit::RemoveCmdID(UINT id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    m_cmdIDs->Remove(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
AwtObject* AwtToolkit::LookupCmdID(UINT id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
    return m_cmdIDs->Lookup(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
HICON AwtToolkit::GetAwtIcon()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
    return ::LoadIcon(GetModuleHandle(), TEXT("AWT_ICON"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
HICON AwtToolkit::GetAwtIconSm()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
    static HICON defaultIconSm = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    static int prevSmx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
    static int prevSmy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    int smx = GetSystemMetrics(SM_CXSMICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
    int smy = GetSystemMetrics(SM_CYSMICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
    // Fixed 6364216: LoadImage() may leak memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
    if (defaultIconSm == NULL || smx != prevSmx || smy != prevSmy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
        defaultIconSm = (HICON)LoadImage(GetModuleHandle(), TEXT("AWT_ICON"), IMAGE_ICON, smx, smy, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
        prevSmx = smx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        prevSmy = smy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
    return defaultIconSm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
4367
e60cfd711532 6901021: Security Warning Icon not getting displayed properly when frame loses focus
anthony
parents: 3498
diff changeset
  1596
// The icon at index 0 must be gray. See AwtWindow::GetSecurityWarningIcon()
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1597
HICON AwtToolkit::GetSecurityWarningIcon(UINT index, UINT w, UINT h)
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1598
{
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1599
    //Note: should not exceed 10 because of the current implementation.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1600
    static const int securityWarningIconCounter = 3;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1601
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1602
    static HICON securityWarningIcon[securityWarningIconCounter]      = {NULL, NULL, NULL};;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1603
    static UINT securityWarningIconWidth[securityWarningIconCounter]  = {0, 0, 0};
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1604
    static UINT securityWarningIconHeight[securityWarningIconCounter] = {0, 0, 0};
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1605
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1606
    index = AwtToolkit::CalculateWave(index, securityWarningIconCounter);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1607
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1608
    if (securityWarningIcon[index] == NULL ||
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1609
            w != securityWarningIconWidth[index] ||
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1610
            h != securityWarningIconHeight[index])
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1611
    {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1612
        if (securityWarningIcon[index] != NULL)
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1613
        {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1614
            ::DestroyIcon(securityWarningIcon[index]);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1615
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1616
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1617
        static const wchar_t securityWarningIconName[] = L"SECURITY_WARNING_";
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1618
        wchar_t iconResourceName[sizeof(securityWarningIconName) + 2];
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1619
        ::ZeroMemory(iconResourceName, sizeof(iconResourceName));
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1620
        wcscpy(iconResourceName, securityWarningIconName);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1621
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1622
        wchar_t strIndex[2];
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1623
        ::ZeroMemory(strIndex, sizeof(strIndex));
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1624
        strIndex[0] = L'0' + index;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1625
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1626
        wcscat(iconResourceName, strIndex);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1627
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1628
        securityWarningIcon[index] = (HICON)::LoadImage(GetModuleHandle(),
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1629
                iconResourceName,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1630
                IMAGE_ICON, w, h, LR_DEFAULTCOLOR);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1631
        securityWarningIconWidth[index] = w;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1632
        securityWarningIconHeight[index] = h;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1633
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1634
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1635
    return securityWarningIcon[index];
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1636
}
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1637
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
void AwtToolkit::SetHeapCheck(long flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    if (flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
        printf("heap checking not supported with this build\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
void throw_if_shutdown(void) throw (awt_toolkit_shutdown)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    AwtToolkit::GetInstance().VerifyActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
void hang_if_shutdown(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
        AwtToolkit::GetInstance().VerifyActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
    } catch (awt_toolkit_shutdown&) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
        // Never return. The VM will halt the process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        ::WaitForSingleObject(::CreateEvent(NULL, TRUE, FALSE, NULL),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                              INFINITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        // Should never get here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
        DASSERT(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
105
e08ac2105adc 6595651: Focus transfers broken for applications embedding AWT across processes
son
parents: 2
diff changeset
  1661
// for now we support only one embedder, but should be ready for future
e08ac2105adc 6595651: Focus transfers broken for applications embedding AWT across processes
son
parents: 2
diff changeset
  1662
void AwtToolkit::RegisterEmbedderProcessId(HWND embedder)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
{
105
e08ac2105adc 6595651: Focus transfers broken for applications embedding AWT across processes
son
parents: 2
diff changeset
  1664
    if (m_embedderProcessID) {
e08ac2105adc 6595651: Focus transfers broken for applications embedding AWT across processes
son
parents: 2
diff changeset
  1665
        // we already set embedder process and do not expect
e08ac2105adc 6595651: Focus transfers broken for applications embedding AWT across processes
son
parents: 2
diff changeset
  1666
        // two different processes to embed the same AwtToolkit
e08ac2105adc 6595651: Focus transfers broken for applications embedding AWT across processes
son
parents: 2
diff changeset
  1667
        return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
105
e08ac2105adc 6595651: Focus transfers broken for applications embedding AWT across processes
son
parents: 2
diff changeset
  1670
    embedder = ::GetAncestor(embedder, GA_ROOT);
e08ac2105adc 6595651: Focus transfers broken for applications embedding AWT across processes
son
parents: 2
diff changeset
  1671
    ::GetWindowThreadProcessId(embedder, &m_embedderProcessID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
JNIEnv* AwtToolkit::m_env;
3498
dbd1b49d341b 6851688: Hung up in applet application
uta
parents: 2952
diff changeset
  1675
DWORD AwtToolkit::m_threadId;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
void AwtToolkit::SetEnv(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
    if (m_env != NULL) { // If already cashed (by means of embeddedInit() call).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
    }
3498
dbd1b49d341b 6851688: Hung up in applet application
uta
parents: 2952
diff changeset
  1681
    m_threadId = GetCurrentThreadId();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
    m_env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
JNIEnv* AwtToolkit::GetEnv() {
3498
dbd1b49d341b 6851688: Hung up in applet application
uta
parents: 2952
diff changeset
  1686
    return (m_env == NULL || m_threadId != GetCurrentThreadId()) ?
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        (JNIEnv*)JNU_GetEnv(jvm, JNI_VERSION_1_2) : m_env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1690
BOOL AwtToolkit::GetScreenInsets(int screenNum, RECT * rect)
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1691
{
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1692
    /* if primary display */
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1693
    if (screenNum == 0) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1694
        RECT rRW;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1695
        if (::SystemParametersInfo(SPI_GETWORKAREA,0,(void *) &rRW,0) == TRUE) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1696
            rect->top = rRW.top;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1697
            rect->left = rRW.left;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1698
            rect->bottom = ::GetSystemMetrics(SM_CYSCREEN) - rRW.bottom;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1699
            rect->right = ::GetSystemMetrics(SM_CXSCREEN) - rRW.right;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1700
            return TRUE;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1701
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1702
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1703
    /* if additional display */
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1704
    else {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1705
        MONITORINFO *miInfo;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1706
        miInfo = AwtWin32GraphicsDevice::GetMonitorInfo(screenNum);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1707
        if (miInfo) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1708
            rect->top = miInfo->rcWork.top    - miInfo->rcMonitor.top;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1709
            rect->left = miInfo->rcWork.left   - miInfo->rcMonitor.left;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1710
            rect->bottom = miInfo->rcMonitor.bottom - miInfo->rcWork.bottom;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1711
            rect->right = miInfo->rcMonitor.right - miInfo->rcWork.right;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1712
            return TRUE;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1713
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1714
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1715
    return FALSE;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1716
}
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1717
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1718
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1719
void AwtToolkit::GetWindowRect(HWND hWnd, LPRECT lpRect)
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1720
{
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1721
    try {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1722
        if (S_OK == DwmAPI::DwmGetWindowAttribute(hWnd,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1723
                DwmAPI::DWMWA_EXTENDED_FRAME_BOUNDS,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1724
                lpRect, sizeof(*lpRect)))
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1725
        {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1726
            return;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1727
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1728
    } catch (const DllUtil::Exception &) {}
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1729
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1730
    ::GetWindowRect(hWnd, lpRect);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1731
}
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  1732
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1733
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1734
/************************************************************************
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1735
 * AWT preloading support
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1736
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1737
bool AwtToolkit::PreloadAction::EnsureInited()
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1738
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1739
    DWORD _initThreadId = GetInitThreadID();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1740
    if (_initThreadId != 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1741
        // already inited
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1742
        // ensure the action is inited on correct thread
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1743
        PreloadThread &preloadThread
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1744
            = AwtToolkit::GetInstance().GetPreloadThread();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1745
        if (_initThreadId == preloadThread.GetThreadId()) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1746
            if (!preloadThread.IsWrongThread()) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1747
                return true;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1748
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1749
            // inited on preloadThread (wrongThread), not cleaned yet
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1750
            // have to wait cleanup completion
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1751
            preloadThread.Wait4Finish();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1752
        } else {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1753
            // inited on other thread (Toolkit thread?)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1754
            // consider as correctly inited
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1755
            return true;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1756
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1757
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1758
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1759
    // init on Toolkit thread
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1760
    AwtToolkit::GetInstance().InvokeFunction(InitWrapper, this);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1761
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1762
    return true;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1763
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1764
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1765
DWORD AwtToolkit::PreloadAction::GetInitThreadID()
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1766
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1767
    CriticalSection::Lock lock(initLock);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1768
    return initThreadId;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1769
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1770
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1771
bool AwtToolkit::PreloadAction::Clean()
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1772
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1773
    DWORD _initThreadId = GetInitThreadID();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1774
    if (_initThreadId == ::GetCurrentThreadId()) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1775
        // inited on this thread
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1776
        Clean(false);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1777
        return true;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1778
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1779
    return false;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1780
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1781
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1782
/*static*/
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1783
void AwtToolkit::PreloadAction::InitWrapper(void *param)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1784
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1785
    PreloadAction *pThis = (PreloadAction *)param;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1786
    pThis->Init();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1787
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1788
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1789
void AwtToolkit::PreloadAction::Init()
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1790
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1791
    CriticalSection::Lock lock(initLock);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1792
    if (initThreadId == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1793
        initThreadId = ::GetCurrentThreadId();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1794
        InitImpl();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1795
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1796
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1797
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1798
void AwtToolkit::PreloadAction::Clean(bool reInit) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1799
    CriticalSection::Lock lock(initLock);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1800
    if (initThreadId != 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1801
        //ASSERT(initThreadId == ::GetCurrentThreadId());
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1802
        CleanImpl(reInit);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1803
        initThreadId = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1804
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1805
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1806
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1807
// PreloadThread implementation
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1808
AwtToolkit::PreloadThread::PreloadThread()
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1809
    : status(None), wrongThread(false), threadId(0),
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1810
    pActionChain(NULL), pLastProcessedAction(NULL),
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1811
    execFunc(NULL), execParam(NULL)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1812
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1813
    hFinished = ::CreateEvent(NULL, TRUE, FALSE, NULL);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1814
    hAwake = ::CreateEvent(NULL, FALSE, FALSE, NULL);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1815
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1816
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1817
AwtToolkit::PreloadThread::~PreloadThread()
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1818
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1819
    //Terminate(false);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1820
    ::CloseHandle(hFinished);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1821
    ::CloseHandle(hAwake);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1822
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1823
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1824
bool AwtToolkit::PreloadThread::AddAction(AwtToolkit::PreloadAction *pAction)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1825
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1826
    CriticalSection::Lock lock(threadLock);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1827
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1828
    if (status > Preloading) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1829
        // too late - the thread already terminated or run as toolkit thread
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1830
        return false;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1831
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1832
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1833
    if (pActionChain == NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1834
        // 1st action
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1835
        pActionChain = pAction;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1836
    } else {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1837
        // add the action to the chain
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1838
        PreloadAction *pChain = pActionChain;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1839
        while (true) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1840
            PreloadAction *pNext = pChain->GetNext();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1841
            if (pNext == NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1842
                break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1843
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1844
            pChain = pNext;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1845
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1846
        pChain->SetNext(pAction);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1847
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1848
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1849
    if (status > None) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1850
        // the thread is already running (status == Preloading)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1851
        AwakeThread();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1852
        return true;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1853
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1854
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1855
    // need to start thread
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1856
    ::ResetEvent(hAwake);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1857
    ::ResetEvent(hFinished);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1858
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1859
    HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0x100000, StaticThreadProc,
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1860
                                            this, 0, &threadId);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1861
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1862
    if (hThread == 0) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1863
        threadId = 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1864
        return false;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1865
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1866
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1867
    status = Preloading;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1868
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1869
    ::CloseHandle(hThread);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1870
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1871
    return true;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1872
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1873
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1874
bool AwtToolkit::PreloadThread::Terminate(bool wrongThread)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1875
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1876
    CriticalSection::Lock lock(threadLock);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1877
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1878
    if (status != Preloading) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1879
        return false;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1880
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1881
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1882
    execFunc = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1883
    execParam = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1884
    this->wrongThread = wrongThread;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1885
    status = Cleaning;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1886
    AwakeThread();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1887
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1888
    return true;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1889
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1890
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1891
bool AwtToolkit::PreloadThread::InvokeAndTerminate(void(_cdecl *fn)(void *), void *param)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1892
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1893
    CriticalSection::Lock lock(threadLock);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1894
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1895
    if (status != Preloading) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1896
        return false;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1897
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1898
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1899
    execFunc = fn;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1900
    execParam = param;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1901
    status = fn == NULL ? Cleaning : RunningToolkit;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1902
    AwakeThread();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1903
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1904
    return true;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1905
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1906
7256
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7018
diff changeset
  1907
bool AwtToolkit::PreloadThread::OnPreloadThread()
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7018
diff changeset
  1908
{
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7018
diff changeset
  1909
    return GetThreadId() == ::GetCurrentThreadId();
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7018
diff changeset
  1910
}
adb296cc2eae 6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents: 7018
diff changeset
  1911
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1912
/*static*/
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1913
unsigned WINAPI AwtToolkit::PreloadThread::StaticThreadProc(void *param)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1914
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1915
    AwtToolkit::PreloadThread *pThis = (AwtToolkit::PreloadThread *)param;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1916
    return pThis->ThreadProc();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1917
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1918
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1919
unsigned AwtToolkit::PreloadThread::ThreadProc()
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1920
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1921
    void(_cdecl *_execFunc)(void *) = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1922
    void *_execParam = NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1923
    bool _wrongThread = false;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1924
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1925
    // initialization
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1926
    while (true) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1927
        PreloadAction *pAction;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1928
        {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1929
            CriticalSection::Lock lock(threadLock);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1930
            if (status != Preloading) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1931
                // get invoke parameters
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1932
                _execFunc = execFunc;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1933
                _execParam = execParam;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1934
                _wrongThread = wrongThread;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1935
                break;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1936
            }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1937
            pAction = GetNextAction();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1938
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1939
        if (pAction != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1940
            pAction->Init();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1941
        } else {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1942
            ::WaitForSingleObject(hAwake, INFINITE);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1943
        }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1944
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1945
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1946
    // call a function from InvokeAndTerminate
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1947
    if (_execFunc != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1948
        _execFunc(_execParam);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1949
    } else {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1950
        // time to terminate..
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1951
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1952
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1953
    // cleanup
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1954
    {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1955
        CriticalSection::Lock lock(threadLock);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1956
        pLastProcessedAction = NULL; // goto 1st action in the chain
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1957
        status = Cleaning;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1958
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1959
    for (PreloadAction *pAction = GetNextAction(); pAction != NULL;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1960
            pAction = GetNextAction()) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1961
        pAction->Clean(_wrongThread);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1962
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1963
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1964
    // don't clear threadId! it is used by PreloadAction::EnsureInited
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1965
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1966
    {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1967
        CriticalSection::Lock lock(threadLock);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1968
        status = Finished;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1969
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1970
    ::SetEvent(hFinished);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1971
    return 0;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1972
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1973
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1974
AwtToolkit::PreloadAction* AwtToolkit::PreloadThread::GetNextAction()
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1975
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1976
    CriticalSection::Lock lock(threadLock);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1977
    PreloadAction *pAction = (pLastProcessedAction == NULL)
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1978
                                    ? pActionChain
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1979
                                    : pLastProcessedAction->GetNext();
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1980
    if (pAction != NULL) {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1981
        pLastProcessedAction = pAction;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1982
    }
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1983
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1984
    return pAction;
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1985
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1986
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1987
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1988
extern "C" {
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1989
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1990
/* Terminates preload thread (if it's still alive
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1991
 * - it may occur if the application doesn't use AWT).
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1992
 * The function is called from launcher after completion main java thread.
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1993
 */
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1994
__declspec(dllexport) void preloadStop()
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1995
{
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1996
    AwtToolkit::GetInstance().GetPreloadThread().Terminate(false);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1997
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1998
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  1999
}
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  2000
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 6642
diff changeset
  2001
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
 * Toolkit native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
 * Class:     java_awt_Toolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
Java_java_awt_Toolkit_initIDs(JNIEnv *env, jclass cls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
    AwtToolkit::getDefaultToolkitMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
        env->GetStaticMethodID(cls,"getDefaultToolkit","()Ljava/awt/Toolkit;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
    AwtToolkit::getFontMetricsMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
        env->GetMethodID(cls, "getFontMetrics",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
                         "(Ljava/awt/Font;)Ljava/awt/FontMetrics;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
        AwtToolkit::insetsMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                env->GetMethodID(env->FindClass("java/awt/Insets"), "<init>", "(IIII)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
    DASSERT(AwtToolkit::getDefaultToolkitMID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
    DASSERT(AwtToolkit::getFontMetricsMID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
        DASSERT(AwtToolkit::insetsMID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
 * WToolkit native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
Java_sun_awt_windows_WToolkit_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
    AwtToolkit::windowsSettingChangeMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
        env->GetMethodID(cls, "windowsSettingChange", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
    DASSERT(AwtToolkit::windowsSettingChangeMID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
    AwtToolkit::displayChangeMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
    env->GetStaticMethodID(cls, "displayChanged", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
    DASSERT(AwtToolkit::displayChangeMID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
    // Set various global IDs needed by JAWT code.  Note: these
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
    // variables cannot be set by JAWT code directly due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
    // different permissions that that code may be run under
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
    // (bug 4796548).  It would be nice to initialize these
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
    // variables lazily, but given the minimal number of calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
    // for this, it seems simpler to just do it at startup with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
    // negligible penalty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
    jclass sDataClassLocal = env->FindClass("sun/java2d/SurfaceData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
    DASSERT(sDataClassLocal != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
    jclass vImgClassLocal = env->FindClass("sun/awt/image/SunVolatileImage");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
    DASSERT(vImgClassLocal != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
    jclass vSMgrClassLocal =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
        env->FindClass("sun/awt/image/VolatileSurfaceManager");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
    DASSERT(vSMgrClassLocal != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
    jclass componentClassLocal = env->FindClass("java/awt/Component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
    DASSERT(componentClassLocal != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
    jawtSMgrID = env->GetFieldID(vImgClassLocal, "volSurfaceManager",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                                 "Lsun/awt/image/VolatileSurfaceManager;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
    DASSERT(jawtSMgrID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
    jawtSDataID = env->GetFieldID(vSMgrClassLocal, "sdCurrent",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                                  "Lsun/java2d/SurfaceData;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
    DASSERT(jawtSDataID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
    jawtPDataID = env->GetFieldID(sDataClassLocal, "pData", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
    DASSERT(jawtPDataID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
    // Save these classes in global references for later use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
    jawtVImgClass = (jclass)env->NewGlobalRef(vImgClassLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
    jawtComponentClass = (jclass)env->NewGlobalRef(componentClassLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
 * Class:     sun_awt_windows_Toolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
 * Method:    disableCustomPalette
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
Java_sun_awt_windows_WToolkit_disableCustomPalette(JNIEnv *env, jclass cls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
    AwtPalette::DisableCustomPalette();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
 * Method:    embeddedInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
 * Signature: ()Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
Java_sun_awt_windows_WToolkit_embeddedInit(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
    AwtToolkit::SetEnv(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
    return AwtToolkit::GetInstance().Initialize(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
    CATCH_BAD_ALLOC_RET(JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
 * Method:    embeddedDispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
 * Signature: ()Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
Java_sun_awt_windows_WToolkit_embeddedDispose(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
    BOOL retval = AwtToolkit::GetInstance().Dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
    AwtToolkit::GetInstance().SetPeer(env, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
    return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
    CATCH_BAD_ALLOC_RET(JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
 * Method:    embeddedEventLoopIdleProcessing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
Java_sun_awt_windows_WToolkit_embeddedEventLoopIdleProcessing(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
    jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
    VerifyWindowMoveLockReleased();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
 * Method:    init
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
 * Signature: ()Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
Java_sun_awt_windows_WToolkit_init(JNIEnv *env, jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
    AwtToolkit::SetEnv(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
    AwtToolkit::GetInstance().SetPeer(env, self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
    // This call will fail if the Toolkit was already initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
    // In that case, we don't want to start another message pump.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
    return AwtToolkit::GetInstance().Initialize(TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
    CATCH_BAD_ALLOC_RET(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
 * Method:    eventLoop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
Java_sun_awt_windows_WToolkit_eventLoop(JNIEnv *env, jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
    DASSERT(AwtToolkit::GetInstance().localPump());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
    AwtToolkit::SetBusy(TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
    AwtToolkit::GetInstance().MessageLoop(AwtToolkit::PrimaryIdleFunc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
                                          AwtToolkit::CommonPeekMessageFunc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
    AwtToolkit::GetInstance().Dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
    AwtToolkit::SetBusy(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * IMPORTANT NOTES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     *   The AwtToolkit has been destructed by now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     * DO NOT CALL any method of AwtToolkit!!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
 * Method:    shutdown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
Java_sun_awt_windows_WToolkit_shutdown(JNIEnv *env, jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
    AwtToolkit& tk = AwtToolkit::GetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
    tk.QuitMessageLoop(AwtToolkit::EXIT_ALL_ENCLOSING_LOOPS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
    while (!tk.IsDisposed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
        Sleep(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
 * Method:    startSecondaryEventLoop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
 * Signature: ()V;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
Java_sun_awt_windows_WToolkit_startSecondaryEventLoop(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
    JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
    jclass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
    DASSERT(AwtToolkit::MainThread() == ::GetCurrentThreadId());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
    AwtToolkit::GetInstance().MessageLoop(AwtToolkit::SecondaryIdleFunc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
                                          AwtToolkit::CommonPeekMessageFunc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
 * Method:    quitSecondaryEventLoop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
 * Signature: ()V;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
Java_sun_awt_windows_WToolkit_quitSecondaryEventLoop(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
    JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
    jclass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
    AwtToolkit::GetInstance().QuitMessageLoop(AwtToolkit::EXIT_ENCLOSING_LOOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
 * Method:    makeColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
 * Signature: ()Ljava/awt/image/ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
Java_sun_awt_windows_WToolkit_makeColorModel(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
    return AwtWin32GraphicsDevice::GetColorModel(env, JNI_FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
        AwtWin32GraphicsDevice::GetDefaultDeviceIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
    CATCH_BAD_ALLOC_RET(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
 * Method:    getMaximumCursorColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
 * Signature: ()I
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
Java_sun_awt_windows_WToolkit_getMaximumCursorColors(JNIEnv *env, jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
    HDC hIC = ::CreateIC(TEXT("DISPLAY"), NULL, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
    int nColor = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
    switch (::GetDeviceCaps(hIC, BITSPIXEL) * ::GetDeviceCaps(hIC, PLANES)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
        case 1:         nColor = 2;             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
        case 4:         nColor = 16;            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
        case 8:         nColor = 256;           break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        case 16:        nColor = 65536;         break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
        case 24:        nColor = 16777216;      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
    ::DeleteDC(hIC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
    return nColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
    CATCH_BAD_ALLOC_RET(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
 * Method:    getScreenWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
 * Signature: ()I
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
Java_sun_awt_windows_WToolkit_getScreenWidth(JNIEnv *env, jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
    return ::GetSystemMetrics(SM_CXSCREEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
    CATCH_BAD_ALLOC_RET(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
 * Method:    getScreenHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
 * Signature: ()I
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
Java_sun_awt_windows_WToolkit_getScreenHeight(JNIEnv *env, jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
    return ::GetSystemMetrics(SM_CYSCREEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
    CATCH_BAD_ALLOC_RET(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
 * Method:    getSreenInsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
 * Signature: (I)Ljava/awt/Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
Java_sun_awt_windows_WToolkit_getScreenInsets(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
                                              jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
                                              jint screen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
    jobject insets = NULL;
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  2341
    RECT rect;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  2345
    if (AwtToolkit::GetScreenInsets(screen, &rect)) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  2346
        insets = env->NewObject(env->FindClass("java/awt/Insets"),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
                AwtToolkit::insetsMID,
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  2348
                rect.top,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  2349
                rect.left,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  2350
                rect.bottom,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1962
diff changeset
  2351
                rect.right);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
    if (safe_ExceptionOccurred(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
    return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
    CATCH_BAD_ALLOC_RET(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
 * Method:    nativeSync
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
Java_sun_awt_windows_WToolkit_nativeSync(JNIEnv *env, jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
    // Synchronize both GDI and DDraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
    VERIFY(::GdiFlush());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
 * Method:    beep
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
Java_sun_awt_windows_WToolkit_beep(JNIEnv *env, jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
    VERIFY(::MessageBeep(MB_OK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
 * Method:    getLockingKeyStateNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
 * Signature: (I)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
Java_sun_awt_windows_WToolkit_getLockingKeyStateNative(JNIEnv *env, jobject self, jint javaKey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
    UINT windowsKey, modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
    AwtComponent::JavaKeyToWindowsKey(javaKey, &windowsKey, &modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
    if (windowsKey == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", "Keyboard doesn't have requested key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
    // low order bit in keyboardState indicates whether the key is toggled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
    BYTE keyboardState[AwtToolkit::KB_STATE_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
    AwtToolkit::GetKeyboardState(keyboardState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
    return keyboardState[windowsKey] & 0x01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
    CATCH_BAD_ALLOC_RET(JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
 * Method:    setLockingKeyStateNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
 * Signature: (IZ)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
Java_sun_awt_windows_WToolkit_setLockingKeyStateNative(JNIEnv *env, jobject self, jint javaKey, jboolean state)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
    UINT windowsKey, modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
    AwtComponent::JavaKeyToWindowsKey(javaKey, &windowsKey, &modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
    if (windowsKey == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", "Keyboard doesn't have requested key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
    // if the key isn't in the desired state yet, simulate key events to get there
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
    // low order bit in keyboardState indicates whether the key is toggled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
    BYTE keyboardState[AwtToolkit::KB_STATE_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
    AwtToolkit::GetKeyboardState(keyboardState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
    if ((keyboardState[windowsKey] & 0x01) != state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
        ::keybd_event(windowsKey, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
        ::keybd_event(windowsKey, 0, KEYEVENTF_KEYUP, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
 * Method:    loadSystemColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
 * Signature: ([I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
Java_sun_awt_windows_WToolkit_loadSystemColors(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
                                               jintArray colors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
    static int indexMap[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
        COLOR_DESKTOP, /* DESKTOP */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
        COLOR_ACTIVECAPTION, /* ACTIVE_CAPTION */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
        COLOR_CAPTIONTEXT, /* ACTIVE_CAPTION_TEXT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
        COLOR_ACTIVEBORDER, /* ACTIVE_CAPTION_BORDER */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
        COLOR_INACTIVECAPTION, /* INACTIVE_CAPTION */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
        COLOR_INACTIVECAPTIONTEXT, /* INACTIVE_CAPTION_TEXT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
        COLOR_INACTIVEBORDER, /* INACTIVE_CAPTION_BORDER */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
        COLOR_WINDOW, /* WINDOW */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
        COLOR_WINDOWFRAME, /* WINDOW_BORDER */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
        COLOR_WINDOWTEXT, /* WINDOW_TEXT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
        COLOR_MENU, /* MENU */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        COLOR_MENUTEXT, /* MENU_TEXT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
        COLOR_WINDOW, /* TEXT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
        COLOR_WINDOWTEXT, /* TEXT_TEXT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
        COLOR_HIGHLIGHT, /* TEXT_HIGHLIGHT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
        COLOR_HIGHLIGHTTEXT, /* TEXT_HIGHLIGHT_TEXT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
        COLOR_GRAYTEXT, /* TEXT_INACTIVE_TEXT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
        COLOR_3DFACE, /* CONTROL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
        COLOR_BTNTEXT, /* CONTROL_TEXT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
        COLOR_3DLIGHT, /* CONTROL_HIGHLIGHT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
        COLOR_3DHILIGHT, /* CONTROL_LT_HIGHLIGHT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
        COLOR_3DSHADOW, /* CONTROL_SHADOW */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
        COLOR_3DDKSHADOW, /* CONTROL_DK_SHADOW */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
        COLOR_SCROLLBAR, /* SCROLLBAR */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
        COLOR_INFOBK, /* INFO */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
        COLOR_INFOTEXT, /* INFO_TEXT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
    jint colorLen = env->GetArrayLength(colors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
    jint* colorsPtr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
        colorsPtr = (jint *)env->GetPrimitiveArrayCritical(colors, 0);
7952
5290e1887780 6999620: [parfait] potential buffer overruns in 2d and awt
bae
parents: 7668
diff changeset
  2494
        for (int i = 0; i < (sizeof indexMap)/(sizeof *indexMap) && i < colorLen; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
            colorsPtr[i] = DesktopColor2RGB(indexMap[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
    } catch (...) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
        if (colorsPtr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
            env->ReleasePrimitiveArrayCritical(colors, colorsPtr, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
        throw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
    env->ReleasePrimitiveArrayCritical(colors, colorsPtr, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
extern "C" JNIEXPORT jobject JNICALL DSGetComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
    (JNIEnv* env, void* platformInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
    HWND hWnd = (HWND)platformInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
    if (!::IsWindow(hWnd))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
    AwtComponent* comp = AwtComponent::GetComponent(hWnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
    if (comp == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
    return comp->GetTarget(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
    CATCH_BAD_ALLOC_RET(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
Java_sun_awt_windows_WToolkit_postDispose(JNIEnv *env, jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
    TRY_NO_VERIFY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
    // If this method was called, that means runFinalizersOnExit is turned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
    // on and the VM is exiting cleanly. We should signal the debug memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
    // manager to generate a leaks report.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
    AwtDebugSupport::GenerateLeaksReport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
 * Method:    setDynamicLayoutNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
 * Signature: (Z)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
Java_sun_awt_windows_WToolkit_setDynamicLayoutNative(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
  jobject self, jboolean dynamic)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
    AwtToolkit::GetInstance().SetDynamicLayout(dynamic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
 * Method:    isDynamicLayoutSupportedNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
 * Signature: ()Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
Java_sun_awt_windows_WToolkit_isDynamicLayoutSupportedNative(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
  jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
    return (jboolean) AwtToolkit::GetInstance().IsDynamicLayoutSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
    CATCH_BAD_ALLOC_RET(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
 * Class:     sun_awt_windows_WToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
 * Method:    printWindowsVersion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
 * Signature: ()Ljava/lang/String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
Java_sun_awt_windows_WToolkit_getWindowsVersion(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
    WCHAR szVer[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
    DWORD version = ::GetVersion();
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 6642
diff changeset
  2587
    swprintf(szVer, 128, L"0x%x = %ld", version, version);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
    int l = lstrlen(szVer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 887
diff changeset
  2590
    if (IS_WIN2000) {
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 887
diff changeset
  2591
        if (IS_WINXP) {
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 887
diff changeset
  2592
            if (IS_WINVISTA) {
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 6642
diff changeset
  2593
                swprintf(szVer + l, 128, L" (Windows Vista)");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
            } else {
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 6642
diff changeset
  2595
                swprintf(szVer + l, 128, L" (Windows XP)");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
        } else {
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 6642
diff changeset
  2598
            swprintf(szVer + l, 128, L" (Windows 2000)");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
    } else {
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 6642
diff changeset
  2601
        swprintf(szVer + l, 128, L" (Unknown)");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
    return JNU_NewStringPlatform(env, szVer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
    CATCH_BAD_ALLOC_RET(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
Java_sun_awt_windows_WToolkit_syncNativeQueue(JNIEnv *env, jobject self, jlong timeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
    AwtToolkit & tk = AwtToolkit::GetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
    DWORD eventNumber = tk.eventNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
    tk.PostMessage(WM_SYNC_WAIT, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
    ::WaitForSingleObject(tk.m_waitEvent, INFINITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
    DWORD newEventNumber = tk.eventNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
    return (newEventNumber - eventNumber) > 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
/* Convert a Windows desktop color index into an RGB value. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
COLORREF DesktopColor2RGB(int colorIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
    DWORD sysColor = ::GetSysColor(colorIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
    return ((GetRValue(sysColor)<<16) | (GetGValue(sysColor)<<8) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
            (GetBValue(sysColor)) | 0xff000000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
 * Class:     sun_awt_SunToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
 * Method:    closeSplashScreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
extern "C" JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
Java_sun_awt_SunToolkit_closeSplashScreen(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
    typedef void (*SplashClose_t)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
    HMODULE hSplashDll = GetModuleHandle(_T("splashscreen.dll"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
    if (!hSplashDll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
        return; // dll not loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
    SplashClose_t splashClose = (SplashClose_t)GetProcAddress(hSplashDll,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
        "SplashClose");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
    if (splashClose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
        splashClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
}
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2649
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2650
/*
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2651
 * accessible from awt_Component
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2652
 */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2653
BOOL AwtToolkit::areExtraMouseButtonsEnabled() {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2654
    return m_areExtraMouseButtonsEnabled;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2655
}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2656
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2657
/*
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2658
 * Class:     sun_awt_windows_WToolkit
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2659
 * Method:    setExtraMouseButtonsEnabledNative
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2660
 * Signature: (Z)V
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2661
 */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2662
extern "C" JNIEXPORT void JNICALL Java_sun_awt_windows_WToolkit_setExtraMouseButtonsEnabledNative
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2663
(JNIEnv *env, jclass self, jboolean enable){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2664
    TRY;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2665
    AwtToolkit::GetInstance().setExtraMouseButtonsEnabled(enable);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2666
    CATCH_BAD_ALLOC;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2667
}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2668
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2669
void AwtToolkit::setExtraMouseButtonsEnabled(BOOL enable) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2670
    m_areExtraMouseButtonsEnabled = enable;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1954
diff changeset
  2671
}
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2472
diff changeset
  2672
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2472
diff changeset
  2673
JNIEXPORT jint JNICALL Java_sun_awt_windows_WToolkit_getNumberOfButtonsImpl
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2472
diff changeset
  2674
(JNIEnv *, jobject self) {
6642
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5506
diff changeset
  2675
    return AwtToolkit::GetNumberOfButtons();
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2472
diff changeset
  2676
}
6642
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5506
diff changeset
  2677
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5506
diff changeset
  2678
UINT AwtToolkit::GetNumberOfButtons() {
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5506
diff changeset
  2679
    return MOUSE_BUTTONS_WINDOWS_SUPPORTED;
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5506
diff changeset
  2680
}