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