jdk/src/windows/native/sun/windows/awt_PopupMenu.cpp
author dxu
Thu, 04 Apr 2013 15:39:17 -0700
changeset 16734 da1901d79073
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8000406: change files using @GenerateNativeHeader to use @Native Summary: Use @Native annotation to mark constants interested by native codes Reviewed-by: alanb, anthony, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1954
diff changeset
     2
 * Copyright (c) 1996, 2007, 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: 1954
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: 1954
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: 1954
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1954
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1954
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "awt_PopupMenu.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "awt_Event.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "awt_Window.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <sun_awt_windows_WPopupMenuPeer.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <java_awt_Event.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/* IMPORTANT! Read the README.JNI file for notes on JNI converted AWT code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/***********************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
// struct for _Show method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
struct ShowStruct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    jobject self;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    jobject event;
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
 * AwtPopupMenu class methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
AwtPopupMenu::AwtPopupMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    m_parent = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
AwtPopupMenu::~AwtPopupMenu()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
void AwtPopupMenu::Dispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    m_parent = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    AwtMenu::Dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
LPCTSTR AwtPopupMenu::GetClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  return TEXT("SunAwtPopupMenu");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
/* Create a new AwtPopupMenu object and menu.   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
AwtPopupMenu* AwtPopupMenu::Create(jobject self, AwtComponent* parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    jobject target = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    AwtPopupMenu* popupMenu = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (env->EnsureLocalCapacity(1) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        target = env->GetObjectField(self, AwtObject::targetID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        JNI_CHECK_NULL_GOTO(target, "null target", done);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        popupMenu = new AwtPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        SetLastError(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        HMENU hMenu = ::CreatePopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // fix for 5088782
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (!CheckMenuCreation(env, self, hMenu))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        popupMenu->SetHMenu(hMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        popupMenu->LinkObjects(env, self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        popupMenu->SetParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    } catch (...) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        throw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
done:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    return popupMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
void AwtPopupMenu::Show(JNIEnv *env, jobject event, BOOL isTrayIconPopup)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * For not TrayIcon popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Convert the event's XY to absolute coordinates.  The XY is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * relative to the origin component, which is passed by PopupMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * as the event's target.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    if (env->EnsureLocalCapacity(2) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        env->DeleteGlobalRef(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    jobject origin = (env)->GetObjectField(event, AwtEvent::targetID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    jobject peerOrigin = GetPeerForTarget(env, origin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    PDATA pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    JNI_CHECK_PEER_GOTO(peerOrigin, done);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        AwtComponent* awtOrigin = (AwtComponent*)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        POINT pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        UINT flags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        pt.x = (env)->GetIntField(event, AwtEvent::xID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        pt.y = (env)->GetIntField(event, AwtEvent::yID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (!isTrayIconPopup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            ::MapWindowPoints(awtOrigin->GetHWnd(), 0, (LPPOINT)&pt, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            // Adjust to account for the Inset values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            RECT rctInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            awtOrigin->GetInsets(&rctInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            pt.x -= rctInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            pt.y -= rctInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            flags = TPM_LEFTALIGN | TPM_RIGHTBUTTON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            ::SetForegroundWindow(awtOrigin->GetHWnd());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            flags = TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_RIGHTBUTTON | TPM_BOTTOMALIGN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        /* Invoke the popup. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        ::TrackPopupMenu(GetHMenu(), flags, pt.x, pt.y, 0, awtOrigin->GetHWnd(), NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (isTrayIconPopup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            ::PostMessage(awtOrigin->GetHWnd(), WM_NULL, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 done:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    env->DeleteLocalRef(origin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    env->DeleteLocalRef(peerOrigin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    env->DeleteGlobalRef(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
void AwtPopupMenu::_Show(void *param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    static jclass popupMenuCls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    if (popupMenuCls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        jclass popupMenuClsLocal =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            env->FindClass("java/awt/PopupMenu");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (!popupMenuClsLocal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            /* exception already thrown */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            ShowStruct *ss = (ShowStruct*)param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (ss->self != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                env->DeleteGlobalRef(ss->self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            delete ss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        popupMenuCls = (jclass)env->NewGlobalRef(popupMenuClsLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        env->DeleteLocalRef(popupMenuClsLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    static jfieldID isTrayIconPopupID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    if (isTrayIconPopupID == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        isTrayIconPopupID = env->GetFieldID(popupMenuCls, "isTrayIconPopup", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        DASSERT(isTrayIconPopupID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    ShowStruct *ss = (ShowStruct*)param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    if (ss->self != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        PDATA pData = JNI_GET_PDATA(ss->self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (pData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            AwtPopupMenu *p = (AwtPopupMenu *)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            jobject target = p->GetTarget(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            BOOL isTrayIconPopup = env->GetBooleanField(target, isTrayIconPopupID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            p->Show(env, ss->event, isTrayIconPopup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        env->DeleteGlobalRef(ss->self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    delete ss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
void AwtPopupMenu::AddItem(AwtMenuItem *item)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    AwtMenu::AddItem(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    if (GetMenuContainer() != NULL) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    if (env->EnsureLocalCapacity(1) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    jobject target = GetTarget(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    if (!(jboolean)env->GetBooleanField(target, AwtMenuItem::enabledID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        item->Enable(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
void AwtPopupMenu::Enable(BOOL isEnabled)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    AwtMenu *menu = GetMenuContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    if (menu != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        AwtMenu::Enable(isEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    if (env->EnsureLocalCapacity(1) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    jobject target = GetTarget(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    int nCount = CountItem(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    for (int i = 0; i < nCount; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        AwtMenuItem *item = GetItem(target,i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        jobject jitem = item->GetTarget(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        BOOL bItemEnabled = isEnabled && (jboolean)env->GetBooleanField(jitem,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            AwtMenuItem::enabledID);
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   236
        jstring labelStr = static_cast<jstring>(env->GetObjectField(jitem, AwtMenuItem::labelID));
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   237
        LPCWSTR labelStrW = JNU_GetStringPlatformChars(env, labelStr, NULL);
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   238
        if (labelStrW  && wcscmp(labelStrW, L"-") != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            item->Enable(bItemEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   241
        JNU_ReleaseStringPlatformChars(env, labelStr, labelStrW);
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   242
        env->DeleteLocalRef(labelStr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        env->DeleteLocalRef(jitem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
BOOL AwtPopupMenu::IsDisabledAndPopup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    if (GetMenuContainer() != NULL) return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    if (env->EnsureLocalCapacity(1) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    jobject target = GetTarget(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    BOOL bEnabled = (jboolean)env->GetBooleanField(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            AwtMenuItem::enabledID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    return !bEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * WPopupMenuPeer native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 * Class:     sun_awt_windows_WPopupMenuPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * Method:    createMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 * Signature: (Lsun/awt/windows/WComponentPeer;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
Java_sun_awt_windows_WPopupMenuPeer_createMenu(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                               jobject parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    PDATA pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    JNI_CHECK_PEER_RETURN(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    AwtComponent* awtParent = (AwtComponent *)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    AwtToolkit::CreateComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        self, awtParent, (AwtToolkit::ComponentFactory)AwtPopupMenu::Create, FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    JNI_CHECK_PEER_CREATION_RETURN(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * Class:     sun_awt_windows_WPopupMenuPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 * Method:    _show
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 * Signature: (Ljava/awt/Event;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
Java_sun_awt_windows_WPopupMenuPeer__1show(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                           jobject event)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    ShowStruct *ss = new ShowStruct;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    ss->self = env->NewGlobalRef(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    ss->event = env->NewGlobalRef(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    // fix for 6268046: invoke the function without CriticalSection's synchronization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    AwtToolkit::GetInstance().InvokeFunction(AwtPopupMenu::_Show, ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    // global ref is deleted in _Show() and ss is deleted in Show()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
} /* extern "C" */