src/java.desktop/windows/native/libawt/windows/awt_Choice.cpp
author serb
Wed, 18 Apr 2018 14:07:41 -0700
changeset 49998 9070717a16a1
parent 47404 e0aec2769cff
permissions -rw-r--r--
8187392: Deprecated methods in the peers can be removed Reviewed-by: prr, kaddepalli
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49998
9070717a16a1 8187392: Deprecated methods in the peers can be removed
serb
parents: 47404
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: 2468
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: 2468
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: 2468
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2468
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2468
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
    26
#include <windowsx.h>
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
    27
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "awt_Toolkit.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "awt_Choice.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "awt_Canvas.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "awt_Dimension.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "awt_Container.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
    35
#include "ComCtl32Util.h"
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
    36
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <java_awt_Toolkit.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <java_awt_FontMetrics.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <java_awt_event_InputEvent.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/* IMPORTANT! Read the README.JNI file for notes on JNI converted AWT code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
// Struct for _Reshape() method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
struct ReshapeStruct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    jobject choice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    jint x, y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    jint width, height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
// Struct for _Select() method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
struct SelectStruct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    jobject choice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    jint index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
// Struct for _AddItems() method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
struct AddItemsStruct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    jobject choice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    jobjectArray items;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    jint index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
// Struct for _Remove() method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
struct RemoveStruct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    jobject choice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    jint index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
/* Bug #4509045: set if SetDragCapture captured mouse */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
BOOL AwtChoice::mouseCapture = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/* Bug #4338368: consume the spurious MouseUp when the choice loses focus */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
BOOL AwtChoice::skipNextMouseUp = FALSE;
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
    77
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
    78
BOOL AwtChoice::sm_isMouseMoveInList = FALSE;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
    79
2468
acce8749692e 6516404: regression: Choice vertical scrollbar is not seen when the item in the choice is increased more than
dcherepanov
parents: 2464
diff changeset
    80
static const UINT MINIMUM_NUMBER_OF_VISIBLE_ITEMS = 8;
acce8749692e 6516404: regression: Choice vertical scrollbar is not seen when the item in the choice is increased more than
dcherepanov
parents: 2464
diff changeset
    81
13997
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
    82
namespace {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
    83
    jfieldID selectedIndexID;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
    84
}
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
    85
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
/*************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * AwtChoice class methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
AwtChoice::AwtChoice() {
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
    91
    m_hList = NULL;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
    92
    m_listDefWindowProc = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
LPCTSTR AwtChoice::GetClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    return TEXT("COMBOBOX");  /* System provided combobox class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
    99
void AwtChoice::Dispose() {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   100
    if (m_hList != NULL && m_listDefWindowProc != NULL) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   101
        ComCtl32Util::GetInstance().UnsubclassHWND(m_hList, ListWindowProc, m_listDefWindowProc);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   102
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   103
    AwtComponent::Dispose();
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   104
}
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   105
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
AwtChoice* AwtChoice::Create(jobject peer, jobject parent) {
47404
e0aec2769cff 8165543: Better window framing
serb
parents: 47216
diff changeset
   107
    DASSERT(AwtToolkit::IsMainThread());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    jobject target = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    AwtChoice* c = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    RECT rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (env->EnsureLocalCapacity(1) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
47404
e0aec2769cff 8165543: Better window framing
serb
parents: 47216
diff changeset
   118
        PDATA pData;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        AwtCanvas* awtParent;
47404
e0aec2769cff 8165543: Better window framing
serb
parents: 47216
diff changeset
   120
        JNI_CHECK_PEER_GOTO(parent, done);
e0aec2769cff 8165543: Better window framing
serb
parents: 47216
diff changeset
   121
        awtParent = (AwtCanvas*)pData;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        target = env->GetObjectField(peer, AwtObject::targetID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        JNI_CHECK_NULL_GOTO(target, "null target", done);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        c = new AwtChoice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            DWORD style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                          CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            DWORD exStyle = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            if (GetRTL()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                if (GetRTLReadingOrder())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    exStyle |= WS_EX_RTLREADING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
             * In OWNER_DRAW, the size of the edit control part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
             * choice must be determinded in its creation, when the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
             * cannot get the choice's instance from its handle.  So
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
             * record the pair of the ID and the instance of the choice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            UINT myId = awtParent->CreateControlID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            DASSERT(myId > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            c->m_myControlID = myId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            awtParent->PushChild(myId, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            jint x = env->GetIntField(target, AwtComponent::xID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            jint y = env->GetIntField(target, AwtComponent::yID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            jint width = env->GetIntField(target, AwtComponent::widthID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            jint height = env->GetIntField(target, AwtComponent::heightID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            jobject dimension = JNU_CallMethodByName(env, NULL, peer,
49998
9070717a16a1 8187392: Deprecated methods in the peers can be removed
serb
parents: 47404
diff changeset
   155
                                                     "getPreferredSize",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                                     "()Ljava/awt/Dimension;").l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            DASSERT(!safe_ExceptionOccurred(env));
24173
176b551268a3 8035734: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Choice.cpp
pchelko
parents: 23010
diff changeset
   158
            if (env->ExceptionCheck()) goto done;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            if (dimension != NULL && width == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                width = env->GetIntField(dimension, AwtDimension::widthID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            c->CreateHWnd(env, L"", style, exStyle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                          x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                          awtParent->GetHWnd(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                          reinterpret_cast<HMENU>(static_cast<INT_PTR>(myId)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                          ::GetSysColor(COLOR_WINDOWTEXT),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                          ::GetSysColor(COLOR_WINDOW),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                          peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            /* suppress inheriting parent's color. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            c->m_backgroundColorSet = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            c->UpdateBackground(env, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            /* Bug 4255631 Solaris: Size returned by Choice.getSize() does not match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
             * actual size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
             * Fix: Set the Choice to its actual size in the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            ::GetClientRect(c->GetHWnd(), &rc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            env->SetIntField(target, AwtComponent::widthID,  (jint) rc.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            env->SetIntField(target, AwtComponent::heightID, (jint) rc.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
2468
acce8749692e 6516404: regression: Choice vertical scrollbar is not seen when the item in the choice is increased more than
dcherepanov
parents: 2464
diff changeset
   183
            if (IS_WINXP) {
acce8749692e 6516404: regression: Choice vertical scrollbar is not seen when the item in the choice is increased more than
dcherepanov
parents: 2464
diff changeset
   184
                ::SendMessage(c->GetHWnd(), CB_SETMINVISIBLE, (WPARAM) MINIMUM_NUMBER_OF_VISIBLE_ITEMS, 0);
acce8749692e 6516404: regression: Choice vertical scrollbar is not seen when the item in the choice is increased more than
dcherepanov
parents: 2464
diff changeset
   185
            }
acce8749692e 6516404: regression: Choice vertical scrollbar is not seen when the item in the choice is increased more than
dcherepanov
parents: 2464
diff changeset
   186
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            env->DeleteLocalRef(dimension);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    } catch (...) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        throw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
done:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
// calculate height of drop-down list part of the combobox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
// to show all the items up to a maximum of eight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
int AwtChoice::GetDropDownHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    int itemHeight =(int)::SendMessage(GetHWnd(), CB_GETITEMHEIGHT, (UINT)0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    int numItemsToShow = (int)::SendMessage(GetHWnd(), CB_GETCOUNT, 0,0);
2468
acce8749692e 6516404: regression: Choice vertical scrollbar is not seen when the item in the choice is increased more than
dcherepanov
parents: 2464
diff changeset
   206
    numItemsToShow = min(MINIMUM_NUMBER_OF_VISIBLE_ITEMS, numItemsToShow);
34394
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 26751
diff changeset
   207
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    // drop-down height snaps to nearest line, so add a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    // fudge factor of 1/2 line to ensure last line shows
34394
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 26751
diff changeset
   210
    return ScaleDownY(itemHeight * numItemsToShow + itemHeight / 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
// get the height of the field portion of the combobox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
int AwtChoice::GetFieldHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    int fieldHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    int borderHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    fieldHeight =(int)::SendMessage(GetHWnd(), CB_GETITEMHEIGHT, (UINT)-1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    // add top and bottom border lines; border size is different for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    // Win 4.x (3d edge) vs 3.x (1 pixel line)
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   221
    borderHeight = ::GetSystemMetrics(SM_CYEDGE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    fieldHeight += borderHeight*2;
34394
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 26751
diff changeset
   223
    return ScaleDownY(fieldHeight);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
// gets the total height of the combobox, including drop down
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
int AwtChoice::GetTotalHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    int dropHeight = GetDropDownHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    int fieldHeight = GetFieldHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    int totalHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    // border on drop-down portion is always non-3d (so don't use SM_CYEDGE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    int borderHeight = ::GetSystemMetrics(SM_CYBORDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    // total height = drop down height + field height + top+bottom drop down border lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    totalHeight = dropHeight + fieldHeight +borderHeight*2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    return totalHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
// Recalculate and set the drop-down height for the Choice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
void AwtChoice::ResetDropDownHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    RECT    rcWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    ::GetWindowRect(GetHWnd(), &rcWindow);
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 13997
diff changeset
   246
    // resize the drop down to accommodate added/removed items
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    int     totalHeight = GetTotalHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    ::SetWindowPos(GetHWnd(), NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    0, 0, rcWindow.right - rcWindow.left, totalHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
/* Fix for the bug 4327666: set the capture for middle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
   and right mouse buttons, but leave left button alone */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
void AwtChoice::SetDragCapture(UINT flags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    if ((flags & MK_LBUTTON) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if ((::GetCapture() == GetHWnd()) && mouseCapture) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            /* On MK_LBUTTON ComboBox captures mouse itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
               so we should release capture and clear flag to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
               prevent releasing capture by ReleaseDragCapture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            ::ReleaseCapture();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            mouseCapture = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   268
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    // don't want to interfere with other controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    if (::GetCapture() == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        ::SetCapture(GetHWnd());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        mouseCapture = 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
/* Fix for Bug 4509045: should release capture only if it is set by SetDragCapture */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
void AwtChoice::ReleaseDragCapture(UINT flags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    if ((::GetCapture() == GetHWnd()) && ((flags & ALL_MK_BUTTONS) == 0) && mouseCapture) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        ::ReleaseCapture();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        mouseCapture = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
void AwtChoice::Reshape(int x, int y, int w, int h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    // Choice component height is fixed (when rolled up)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    // so vertically center the choice in it's bounding box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    jobject target = GetTarget(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    jobject parent = env->GetObjectField(target, AwtComponent::parentID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    RECT rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    int fieldHeight = GetFieldHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    if ((parent != NULL && env->GetObjectField(parent, AwtContainer::layoutMgrID) != NULL) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        fieldHeight > 0 && fieldHeight < h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        y += (h - fieldHeight) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /* Fix for 4783342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Choice should ignore reshape on height changes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * as height is dependent on Font size only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    AwtComponent* awtParent = GetParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    BOOL bReshape = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    if (awtParent != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        ::GetWindowRect(GetHWnd(), &rc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        int oldW = rc.right - rc.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        RECT parentRc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        ::GetWindowRect(awtParent->GetHWnd(), &parentRc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        int oldX = rc.left - parentRc.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        int oldY = rc.top - parentRc.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        bReshape = (x != oldX || y != oldY || w != oldW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    if (bReshape)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        int totalHeight = GetTotalHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        AwtComponent::Reshape(x, y, w, totalHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /* Bug 4255631 Solaris: Size returned by Choice.getSize() does not match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * actual size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Fix: Set the Choice to its actual size in the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    ::GetClientRect(GetHWnd(), &rc);
34394
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 26751
diff changeset
   327
    env->SetIntField(target, AwtComponent::widthID, ScaleDownX(rc.right));
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 26751
diff changeset
   328
    env->SetIntField(target, AwtComponent::heightID, ScaleDownY(rc.bottom));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    env->DeleteLocalRef(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
jobject AwtChoice::PreferredItemSize(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    jobject dimension = JNU_CallMethodByName(env, NULL, GetPeer(env),
49998
9070717a16a1 8187392: Deprecated methods in the peers can be removed
serb
parents: 47404
diff changeset
   337
                                             "getPreferredSize",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                             "()Ljava/awt/Dimension;").l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    DASSERT(!safe_ExceptionOccurred(env));
24173
176b551268a3 8035734: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Choice.cpp
pchelko
parents: 23010
diff changeset
   340
    CHECK_NULL_RETURN(dimension, NULL);
176b551268a3 8035734: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Choice.cpp
pchelko
parents: 23010
diff changeset
   341
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /* This size is window size of choice and it's too big for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * drop down item height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    env->SetIntField(dimension, AwtDimension::heightID,
40168
90c3fc775db8 8144594: HiDPI: awt.Choice looks improperly (Win 8)
rchamyal
parents: 34394
diff changeset
   346
                       ScaleUpY(GetFontHeight(env)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    return dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
void AwtChoice::SetFont(AwtFont* font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    AwtComponent::SetFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    //Get the text metrics and change the height of each item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    HDC hDC = ::GetDC(GetHWnd());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    DASSERT(hDC != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    TEXTMETRIC tm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    HANDLE hFont = font->GetHFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    VERIFY(::SelectObject(hDC, hFont) != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    VERIFY(::GetTextMetrics(hDC, &tm));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    long h = tm.tmHeight + tm.tmExternalLeading;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    VERIFY(::ReleaseDC(GetHWnd(), hDC) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    int nCount = (int)::SendMessage(GetHWnd(), CB_GETCOUNT, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    for(int i = 0; i < nCount; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        VERIFY(::SendMessage(GetHWnd(), CB_SETITEMHEIGHT, i, MAKELPARAM(h, 0)) != CB_ERR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    //Change the height of the Edit Box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    VERIFY(::SendMessage(GetHWnd(), CB_SETITEMHEIGHT, (UINT)-1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                         MAKELPARAM(h, 0)) != CB_ERR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    jobject target = GetTarget(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    jint height = env->GetIntField(target, AwtComponent::heightID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    Reshape(env->GetIntField(target, AwtComponent::xID),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            env->GetIntField(target, AwtComponent::yID),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            env->GetIntField(target, AwtComponent::widthID),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   385
static int lastClickX = -1;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   386
static int lastClickY = -1;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   387
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   388
LRESULT CALLBACK AwtChoice::ListWindowProc(HWND hwnd, UINT message,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   389
                                           WPARAM wParam, LPARAM lParam)
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   390
{
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   391
    /*
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   392
     * We don't pass the choice WM_LBUTTONDOWN message. As the result the choice's list
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   393
     * doesn't forward mouse messages it captures. Below we do forward what we need.
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   394
     */
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   395
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   396
    TRY;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   397
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   398
    DASSERT(::IsWindow(hwnd));
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   399
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   400
    switch (message) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   401
        case WM_LBUTTONDOWN: {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   402
            DWORD curPos = ::GetMessagePos();
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   403
            lastClickX = GET_X_LPARAM(curPos);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   404
            lastClickY = GET_Y_LPARAM(curPos);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   405
            break;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   406
        }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   407
        case WM_MOUSEMOVE: {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   408
            RECT rect;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   409
            ::GetClientRect(hwnd, &rect);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   410
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   411
            POINT pt = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   412
            if (::PtInRect(&rect, pt)) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   413
                sm_isMouseMoveInList = TRUE;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   414
            }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   415
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   416
            POINT lastPt = {lastClickX, lastClickY};
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   417
            ::ScreenToClient(hwnd, &lastPt);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   418
            if (::PtInRect(&rect, lastPt)) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   419
                break; // ignore when dragging inside the list
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   420
            }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   421
        }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   422
        case WM_LBUTTONUP: {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   423
            lastClickX = -1;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   424
            lastClickY = -1;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   425
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   426
            AwtChoice *c = (AwtChoice *)::GetWindowLongPtr(hwnd, GWLP_USERDATA);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   427
            if (c != NULL) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   428
                // forward the msg to the choice
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   429
                c->WindowProc(message, wParam, lParam);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   430
            }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   431
        }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   432
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   433
    return ComCtl32Util::GetInstance().DefWindowProc(NULL, hwnd, message, wParam, lParam);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   434
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   435
    CATCH_BAD_ALLOC_RET(0);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   436
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
MsgRouting AwtChoice::WmNotify(UINT notifyCode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    if (notifyCode == CBN_SELCHANGE) {
13997
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   442
        int selectedIndex = (int)SendMessage(CB_GETCURSEL);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   443
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   444
        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   445
        jobject target = GetTarget(env);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   446
        int previousIndex = env->GetIntField(target, selectedIndexID);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   447
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   448
        if (selectedIndex != CB_ERR && selectedIndex != previousIndex){
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   449
            DoCallback("handleAction", "(I)V", selectedIndex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   451
    } else if (notifyCode == CBN_DROPDOWN) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   452
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   453
        if (m_hList == NULL) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   454
            COMBOBOXINFO cbi;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   455
            cbi.cbSize = sizeof(COMBOBOXINFO);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   456
            ::GetComboBoxInfo(GetHWnd(), &cbi);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   457
            m_hList = cbi.hwndList;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   458
            m_listDefWindowProc = ComCtl32Util::GetInstance().SubclassHWND(m_hList, ListWindowProc);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   459
            DASSERT(::GetWindowLongPtr(m_hList, GWLP_USERDATA) == NULL);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   460
            ::SetWindowLongPtr(m_hList, GWLP_USERDATA, (LONG_PTR)this);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   461
        }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   462
        sm_isMouseMoveInList = FALSE;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   463
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   464
        // Clicking in the dropdown list steals focus from the proxy.
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   465
        // So, set the focus-restore flag up.
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   466
        SetRestoreFocus(TRUE);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   467
    } else if (notifyCode == CBN_CLOSEUP) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   468
        SetRestoreFocus(FALSE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    return mrDoDefault;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
MsgRouting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
AwtChoice::OwnerDrawItem(UINT /*ctrlId*/, DRAWITEMSTRUCT& drawInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    DrawListItem((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), drawInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    return mrConsume;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
MsgRouting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
AwtChoice::OwnerMeasureItem(UINT /*ctrlId*/, MEASUREITEMSTRUCT& measureInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    MeasureListItem((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), measureInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    return mrConsume;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
/* Bug #4338368: when a choice loses focus, it triggers spurious MouseUp event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
 * even if the focus was lost due to TAB key pressing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
MsgRouting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
AwtChoice::WmKillFocus(HWND hWndGotFocus)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    skipNextMouseUp = TRUE;
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   495
    return AwtComponent::WmKillFocus(hWndGotFocus);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
MsgRouting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
AwtChoice::WmMouseUp(UINT flags, int x, int y, int button)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    if (skipNextMouseUp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        skipNextMouseUp = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        return mrDoDefault;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    return AwtComponent::WmMouseUp(flags, x, y, button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
MsgRouting AwtChoice::HandleEvent(MSG *msg, BOOL synthetic)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
{
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   510
    if (IsFocusingMouseMessage(msg)) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   511
        SendMessage(CB_SHOWDROPDOWN, ~SendMessage(CB_GETDROPPEDSTATE, 0, 0), 0);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   512
        delete msg;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   513
        return mrConsume;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   514
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   515
    // To simulate the native behavior, we close the list on WM_LBUTTONUP if
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   516
    // WM_MOUSEMOVE has been dedected on the list since it has been dropped down.
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   517
    if (msg->message == WM_LBUTTONUP && SendMessage(CB_GETDROPPEDSTATE, 0, 0) &&
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   518
        sm_isMouseMoveInList)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    {
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   520
        SendMessage(CB_SHOWDROPDOWN, FALSE, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    return AwtComponent::HandleEvent(msg, synthetic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
BOOL AwtChoice::InheritsNativeMouseWheelBehavior() {return true;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
void AwtChoice::_Reshape(void *param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    ReshapeStruct *rs = (ReshapeStruct *)param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    jobject choice = rs->choice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    jint x = rs->x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    jint y = rs->y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    jint width = rs->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    jint height = rs->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    AwtChoice *c = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    PDATA pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    JNI_CHECK_PEER_GOTO(choice, done);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    c = (AwtChoice *)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    if (::IsWindow(c->GetHWnd()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        c->Reshape(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        c->VerifyState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
done:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    env->DeleteGlobalRef(choice);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    delete rs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
void AwtChoice::_Select(void *param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    SelectStruct *ss = (SelectStruct *)param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    jobject choice = ss->choice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    jint index = ss->index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    AwtChoice *c = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    PDATA pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    JNI_CHECK_PEER_GOTO(choice, done);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    c = (AwtChoice *)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    if (::IsWindow(c->GetHWnd()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        c->SendMessage(CB_SETCURSEL, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
//        c->VerifyState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
done:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    env->DeleteGlobalRef(choice);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    delete ss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
void AwtChoice::_AddItems(void *param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    AddItemsStruct *ais = (AddItemsStruct *)param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    jobject choice = ais->choice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    jobjectArray items = ais->items;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    jint index = ais->index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    AwtChoice *c = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    PDATA pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    JNI_CHECK_PEER_GOTO(choice, done);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    JNI_CHECK_NULL_GOTO(items, "null items", done);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    c = (AwtChoice *)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    if (::IsWindow(c->GetHWnd()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        jsize i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        int itemCount = env->GetArrayLength(items);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        if (itemCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
           c->SendMessage(WM_SETREDRAW, (WPARAM)FALSE, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
           for (i = 0; i < itemCount; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
           {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
               jstring item = (jstring)env->GetObjectArrayElement(items, i);
24173
176b551268a3 8035734: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Choice.cpp
pchelko
parents: 23010
diff changeset
   607
               if (env->ExceptionCheck()) goto done;
176b551268a3 8035734: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Choice.cpp
pchelko
parents: 23010
diff changeset
   608
               if (item == NULL) goto next_elem;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
               c->SendMessage(CB_INSERTSTRING, index + i, JavaStringBuffer(env, item));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
               env->DeleteLocalRef(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
next_elem:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
               ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
           c->SendMessage(WM_SETREDRAW, (WPARAM)TRUE, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
           InvalidateRect(c->GetHWnd(), NULL, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
           c->ResetDropDownHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
           c->VerifyState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
done:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    env->DeleteGlobalRef(choice);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    env->DeleteGlobalRef(items);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    delete ais;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
void AwtChoice::_Remove(void *param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    RemoveStruct *rs = (RemoveStruct *)param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    jobject choice = rs->choice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    jint index = rs->index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    AwtChoice *c = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    PDATA pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    JNI_CHECK_PEER_GOTO(choice, done);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    c = (AwtChoice *)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    if (::IsWindow(c->GetHWnd()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        c->SendMessage(CB_DELETESTRING, index, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        c->ResetDropDownHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        c->VerifyState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
done:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    env->DeleteGlobalRef(choice);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    delete rs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
void AwtChoice::_RemoveAll(void *param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    jobject choice = (jobject)param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    AwtChoice *c = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    PDATA pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    JNI_CHECK_PEER_GOTO(choice, done);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    c = (AwtChoice *)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    if (::IsWindow(c->GetHWnd()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        c->SendMessage(CB_RESETCONTENT, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        c->ResetDropDownHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        c->VerifyState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
done:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    env->DeleteGlobalRef(choice);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   678
void AwtChoice::_CloseList(void *param)
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   679
{
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   680
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   681
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   682
    jobject choice = (jobject)param;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   683
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   684
    AwtChoice *c = NULL;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   685
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   686
    PDATA pData;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   687
    JNI_CHECK_PEER_GOTO(choice, done);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   688
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   689
    c = (AwtChoice *)pData;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   690
    if (::IsWindow(c->GetHWnd()) && c->SendMessage(CB_GETDROPPEDSTATE, 0, 0)) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   691
        c->SendMessage(CB_SHOWDROPDOWN, FALSE, 0);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   692
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   693
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   694
done:
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   695
    env->DeleteGlobalRef(choice);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   696
}
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   697
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
 * WChoicePeer native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
13997
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   704
JNIEXPORT void JNICALL
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   705
Java_java_awt_Choice_initIDs(JNIEnv *env, jclass cls)
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   706
{
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   707
    TRY;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   708
    selectedIndexID = env->GetFieldID(cls, "selectedIndex", "I");
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   709
    DASSERT(selectedIndexID);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   710
    CATCH_BAD_ALLOC;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   711
}
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents: 10088
diff changeset
   712
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
 * Class:     sun_awt_windows_WChoicePeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
 * Method:    select
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
 * Signature: (I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
Java_sun_awt_windows_WChoicePeer_select(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                                        jint index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    SelectStruct *ss = new SelectStruct;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    ss->choice = env->NewGlobalRef(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    ss->index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    AwtToolkit::GetInstance().SyncCall(AwtChoice::_Select, ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    // global refs and ss are removed in _Select
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
 * Class:     sun_awt_windows_WChoicePeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
 * Method:    remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
 * Signature: (I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
Java_sun_awt_windows_WChoicePeer_remove(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                                        jint index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    RemoveStruct *rs = new RemoveStruct;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    rs->choice = env->NewGlobalRef(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    rs->index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    AwtToolkit::GetInstance().SyncCall(AwtChoice::_Remove, rs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    // global ref and rs are deleted in _Remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
 * Class:     sun_awt_windows_WChoicePeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
 * Method:    removeAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
Java_sun_awt_windows_WChoicePeer_removeAll(JNIEnv *env, jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    jobject selfGlobalRef = env->NewGlobalRef(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    AwtToolkit::GetInstance().SyncCall(AwtChoice::_RemoveAll, (void *)selfGlobalRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    // selfGlobalRef is deleted in _RemoveAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
 * Class:     sun_awt_windows_WChoicePeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
 * Method:    addItems
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
 * Signature: ([Ljava/lang/String;I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
Java_sun_awt_windows_WChoicePeer_addItems(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                                          jobjectArray items, jint index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    AddItemsStruct *ais = new AddItemsStruct;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    ais->choice = env->NewGlobalRef(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    ais->items = (jobjectArray)env->NewGlobalRef(items);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    ais->index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    AwtToolkit::GetInstance().SyncCall(AwtChoice::_AddItems, ais);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    // global refs and ais are deleted in _AddItems
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
 * Class:     sun_awt_windows_WChoicePeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
 * Method:    reshape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
 * Signature: (IIII)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
Java_sun_awt_windows_WChoicePeer_reshape(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                                         jint x, jint y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                                         jint width, jint height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    ReshapeStruct *rs = new ReshapeStruct;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    rs->choice = env->NewGlobalRef(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    rs->x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    rs->y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    rs->width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    rs->height = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    AwtToolkit::GetInstance().SyncCall(AwtChoice::_Reshape, rs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    // global ref and rs are deleted in _Reshape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
 * Class:     sun_awt_windows_WChoicePeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
 * Method:    create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
 * Signature: (Lsun/awt/windows/WComponentPeer;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
Java_sun_awt_windows_WChoicePeer_create(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                                        jobject parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    AwtToolkit::CreateComponent(self, parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                                (AwtToolkit::ComponentFactory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                                AwtChoice::Create);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   838
/*
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   839
 * Class:     sun_awt_windows_WChoicePeer
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   840
 * Method:    closeList
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   841
 * Signature: ()V
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   842
 */
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   843
JNIEXPORT void JNICALL
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   844
Java_sun_awt_windows_WChoicePeer_closeList(JNIEnv *env, jobject self)
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   845
{
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   846
    TRY;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   847
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   848
    jobject selfGlobalRef = env->NewGlobalRef(self);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   849
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   850
    AwtToolkit::GetInstance().SyncCall(AwtChoice::_CloseList, (void *)selfGlobalRef);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   851
    // global ref is deleted in _CloseList
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   852
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   853
    CATCH_BAD_ALLOC;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 1954
diff changeset
   854
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
 * Diagnostic routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
void AwtChoice::VerifyState()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    if (AwtToolkit::GetInstance().VerifyComponents() == FALSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    if (m_callbacksEnabled == FALSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        /* Component is not fully setup yet. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    AwtComponent::VerifyState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    if (env->PushLocalFrame(1) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    jobject target = GetTarget(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    // To avoid possibly running client code on the toolkit thread, don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    // do the following checks if we're running on the toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    if (AwtToolkit::MainThread() != ::GetCurrentThreadId()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        // Compare number of items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        int nTargetItems = JNU_CallMethodByName(env, NULL, target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                                                "countItems", "()I").i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        DASSERT(!safe_ExceptionOccurred(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        int nPeerItems = (int)::SendMessage(GetHWnd(), CB_GETCOUNT, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        DASSERT(nTargetItems == nPeerItems);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        // Compare selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        int targetIndex = JNU_CallMethodByName(env, NULL, target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                                               "getSelectedIndex", "()I").i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        DASSERT(!safe_ExceptionOccurred(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        int peerCurSel = (int)::SendMessage(GetHWnd(), CB_GETCURSEL, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        DASSERT(targetIndex == peerCurSel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    env->PopLocalFrame(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
#endif //DEBUG