jdk/src/windows/native/sun/windows/awt_MenuItem.cpp
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 6485 5e6b2f2666ae
child 9476 148209fd1cf5
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6485
diff changeset
     2
 * Copyright (c) 1996, 2010, 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: 4835
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: 4835
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: 4835
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4835
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4835
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    26
#include "awt.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "awt_MenuItem.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "awt_Menu.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "awt_MenuBar.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "awt_DesktopProperties.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <sun_awt_windows_WCheckboxMenuItemPeer.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
// Begin -- Win32 SDK include files
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <tchar.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <imm.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <ime.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
// End -- Win32 SDK include files
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
//add for multifont menuitem
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <java_awt_CheckboxMenuItem.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <java_awt_Toolkit.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include <java_awt_event_InputEvent.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/* IMPORTANT! Read the README.JNI file for notes on JNI converted AWT code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/***********************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
// struct for _SetLabel() method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
struct SetLabelStruct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    jobject menuitem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    jstring label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * AwtMenuItem fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
HBITMAP AwtMenuItem::bmpCheck;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
jobject AwtMenuItem::systemFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
jfieldID AwtMenuItem::labelID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
jfieldID AwtMenuItem::enabledID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
jfieldID AwtMenuItem::fontID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
jfieldID AwtMenuItem::appContextID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
jfieldID AwtMenuItem::shortcutLabelID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
jfieldID AwtMenuItem::isCheckboxID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
jfieldID AwtMenuItem::stateID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
jmethodID AwtMenuItem::getDefaultFontMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
// Added by waleed to initialize the RTL Flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
LANGID AwtMenuItem::m_idLang = LOWORD(GetKeyboardLayout(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
UINT AwtMenuItem::m_CodePage =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    AwtMenuItem::LangToCodePage(AwtMenuItem::m_idLang);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
BOOL AwtMenuItem::sm_rtl = PRIMARYLANGID(GetInputLanguage()) == LANG_ARABIC ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                           PRIMARYLANGID(GetInputLanguage()) == LANG_HEBREW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
BOOL AwtMenuItem::sm_rtlReadingOrder =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    PRIMARYLANGID(GetInputLanguage()) == LANG_ARABIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * This constant holds width of the default menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * check-mark bitmap for default settings on XP/Vista,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
static const int SM_CXMENUCHECK_DEFAULT_ON_XP = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
static const int SM_CXMENUCHECK_DEFAULT_ON_VISTA = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * AwtMenuItem methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
AwtMenuItem::AwtMenuItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    m_peerObject = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    m_menuContainer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    m_Id = (UINT)-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    m_freeId = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    m_isCheckbox = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
AwtMenuItem::~AwtMenuItem()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
void AwtMenuItem::RemoveCmdID()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    if (m_freeId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        AwtToolkit::GetInstance().RemoveCmdID( GetID() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
void AwtMenuItem::Dispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    RemoveCmdID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    if (m_peerObject != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        JNI_SET_PDATA(m_peerObject, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        env->DeleteGlobalRef(m_peerObject);
4835
dad88ce69af3 6756774: fstdebug jvm fails with assertion (result != deleted_handle(),"Used a deleted global handle.")
dcherepanov
parents: 1954
diff changeset
   117
        m_peerObject = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    AwtObject::Dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
LPCTSTR AwtMenuItem::GetClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  return TEXT("SunAwtMenuItem");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
// Convert Language ID to CodePage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
UINT AwtMenuItem::LangToCodePage(LANGID idLang)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    TCHAR strCodePage[MAX_ACP_STR_LEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    // use the LANGID to create a LCID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    LCID idLocale = MAKELCID(idLang, SORT_DEFAULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    // get the ANSI code page associated with this locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    if (GetLocaleInfo(idLocale, LOCALE_IDEFAULTANSICODEPAGE, strCodePage, sizeof(strCodePage)/sizeof(TCHAR)) > 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return _ttoi(strCodePage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return GetACP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
BOOL AwtMenuItem::CheckMenuCreation(JNIEnv *env, jobject self, HMENU hMenu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    // fix for 5088782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    // check if CreateMenu() returns not null value and if it does -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    //   create an InternalError or OutOfMemoryError based on GetLastError().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    //   This error is set to createError field of WObjectPeer and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    //   checked and thrown in WMenuPeer or WMenuItemPeer constructor. We
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    //   can't throw an error here because this code is invoked on Toolkit thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    // return TRUE if menu is created successfully, FALSE otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    if (hMenu == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        DWORD dw = GetLastError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        jobject createError = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (dw == ERROR_OUTOFMEMORY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        {
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   154
            jstring errorMsg = JNU_NewStringPlatform(env, L"too many menu handles");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            createError = JNU_NewObjectByName(env, "java/lang/OutOfMemoryError",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                                   "(Ljava/lang/String;)V",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                                   errorMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            env->DeleteLocalRef(errorMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            TCHAR *buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                (LPTSTR)&buf, 0, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            jstring s = JNU_NewStringPlatform(env, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            createError = JNU_NewObjectByName(env, "java/lang/InternalError",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                                   "(Ljava/lang/String;)V", s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            LocalFree(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            env->DeleteLocalRef(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        env->SetObjectField(self, AwtObject::createErrorID, createError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (createError != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            env->DeleteLocalRef(createError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * Link the C++, Java peer together
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
void AwtMenuItem::LinkObjects(JNIEnv *env, jobject peer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    m_peerObject = env->NewGlobalRef(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    JNI_SET_PDATA(peer, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
AwtMenuItem* AwtMenuItem::Create(jobject peer, jobject menuPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    jobject target = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    AwtMenuItem* item = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (env->EnsureLocalCapacity(1) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        PDATA pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        JNI_CHECK_PEER_RETURN_NULL(menuPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        /* target is a java.awt.MenuItem  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        target = env->GetObjectField(peer, AwtObject::targetID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        AwtMenu* menu = (AwtMenu *)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        item = new AwtMenuItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        jboolean isCheckbox =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            (jboolean)env->GetBooleanField(peer, AwtMenuItem::isCheckboxID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (isCheckbox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            item->SetCheckbox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        item->LinkObjects(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        item->SetMenuContainer(menu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        item->SetNewID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        menu->AddItem(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    } catch (...) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        throw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    return item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
MsgRouting AwtMenuItem::WmNotify(UINT notifyCode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    return mrDoDefault;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
// This function returns a local reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
jobject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
AwtMenuItem::GetFont(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    jobject self = GetPeer(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    jobject target = env->GetObjectField(self, AwtObject::targetID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    jobject font = JNU_CallMethodByName(env, 0, target, "getFont_NoClientCode", "()Ljava/awt/Font;").l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    if (font == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        font = env->NewLocalRef(GetDefaultFont(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
jobject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
AwtMenuItem::GetDefaultFont(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    if (AwtMenuItem::systemFont == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        jclass cls = env->FindClass("sun/awt/windows/WMenuItemPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        DASSERT(cls != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        AwtMenuItem::systemFont =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            env->CallStaticObjectMethod(cls, AwtMenuItem::getDefaultFontMID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        DASSERT(AwtMenuItem::systemFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        AwtMenuItem::systemFont = env->NewGlobalRef(AwtMenuItem::systemFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    return AwtMenuItem::systemFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
AwtMenuItem::DrawSelf(DRAWITEMSTRUCT& drawInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    if (env->EnsureLocalCapacity(4) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    // self is sun.awt.windows.WMenuItemPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    jobject self = GetPeer(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    //  target is java.awt.MenuItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    jobject target = env->GetObjectField(self, AwtObject::targetID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    HDC hDC = drawInfo.hDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    RECT rect = drawInfo.rcItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    RECT textRect = rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    SIZE size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    DWORD crBack,crText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    HBRUSH hbrBack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    jobject font = GetFont(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    jstring text = GetJavaString(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    size = AwtFont::getMFStringSize(hDC, font, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /* 4700350: If the font size is taller than the menubar, change to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * default font.  Otherwise, menu text is painted over the title bar and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * client area.  -bchristi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    if (IsTopMenu() && size.cy > ::GetSystemMetrics(SM_CYMENU)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        env->DeleteLocalRef(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        font = env->NewLocalRef(GetDefaultFont(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        size = AwtFont::getMFStringSize(hDC, font, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /* Fix for bug 4257944 by ssi@sparc.spb.su
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    * check state of the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    AwtMenu* menu = GetMenuContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    DASSERT(menu != NULL && GetID() >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    //Check whether the MenuItem is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    BOOL bEnabled = (jboolean)env->GetBooleanField(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                                   AwtMenuItem::enabledID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    if (menu != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        bEnabled = bEnabled && !menu->IsDisabledAndPopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    if ((drawInfo.itemState) & (ODS_SELECTED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        // Set background and text colors for selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        crBack = ::GetSysColor (COLOR_HIGHLIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        // Disabled text must be drawn in gray.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        crText = ::GetSysColor(bEnabled? COLOR_HIGHLIGHTTEXT : COLOR_GRAYTEXT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        // COLOR_MENUBAR is only defined on WindowsXP. Our binaries are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        // built on NT, hence the below ifdef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
#ifndef COLOR_MENUBAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
#define COLOR_MENUBAR 30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // Set background and text colors for unselected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (IS_WINXP && IsTopMenu() && AwtDesktopProperties::IsXPStyle()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            crBack = ::GetSysColor (COLOR_MENUBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            crBack = ::GetSysColor (COLOR_MENU);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        // Disabled text must be drawn in gray.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        crText = ::GetSysColor (bEnabled ? COLOR_MENUTEXT : COLOR_GRAYTEXT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    // Fill item rectangle with background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    hbrBack = ::CreateSolidBrush (crBack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    DASSERT(hbrBack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    VERIFY(::FillRect (hDC, &rect, hbrBack));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    VERIFY(::DeleteObject (hbrBack));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    // Set current background and text colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    ::SetBkColor (hDC, crBack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    ::SetTextColor (hDC, crText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    int nOldBkMode = ::SetBkMode(hDC, OPAQUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    DASSERT(nOldBkMode != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    //draw check mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    int checkWidth = ::GetSystemMetrics(SM_CXMENUCHECK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    // Workaround for CR#6401956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    if (IS_WINVISTA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        AdjustCheckWidth(checkWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    if (IsCheckbox()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        // means that target is a java.awt.CheckboxMenuItem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        jboolean state =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            (jboolean)env->GetBooleanField(target, AwtMenuItem::stateID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        if (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            DASSERT(drawInfo.itemState & ODS_CHECKED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            RECT checkRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            ::CopyRect(&checkRect, &textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            if (GetRTL())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                checkRect.left = checkRect.right - checkWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                checkRect.right = checkRect.left + checkWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            DrawCheck(hDC, checkRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    ::SetBkMode(hDC, TRANSPARENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    int x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    //draw string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    if (!IsTopMenu()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        textRect.left += checkWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        x = (GetRTL()) ? textRect.right - checkWidth - size.cx : textRect.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        x = textRect.left = (textRect.left + textRect.right - size.cx) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    int y = (textRect.top+textRect.bottom-size.cy)/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    // Text must be drawn in emboss if the Menu is disabled and not selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    BOOL bEmboss = !bEnabled && !(drawInfo.itemState & ODS_SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    if (bEmboss) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        ::SetTextColor(hDC, GetSysColor(COLOR_BTNHILIGHT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        AwtFont::drawMFString(hDC, font, text, x + 1, y + 1, GetCodePage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        ::SetTextColor(hDC, GetSysColor(COLOR_BTNSHADOW));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    AwtFont::drawMFString(hDC, font, text, x, y, GetCodePage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    jstring shortcutLabel =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        (jstring)env->GetObjectField(self, AwtMenuItem::shortcutLabelID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    if (!IsTopMenu() && shortcutLabel != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        UINT oldAlign = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (GetRTL()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            oldAlign = ::SetTextAlign(hDC, TA_LEFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            AwtFont::drawMFString(hDC, font, shortcutLabel, textRect.left, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                  GetCodePage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            oldAlign = ::SetTextAlign(hDC, TA_RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            AwtFont::drawMFString(hDC, font, shortcutLabel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                                  textRect.right - checkWidth, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                                  GetCodePage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        ::SetTextAlign(hDC, oldAlign);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    VERIFY(::SetBkMode(hDC,nOldBkMode));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    env->DeleteLocalRef(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    env->DeleteLocalRef(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    env->DeleteLocalRef(shortcutLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
 * This function helps us to prevent check-mark's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
 * distortion appeared due to changing of default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
 * settings on Vista
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
void AwtMenuItem::AdjustCheckWidth(int& checkWidth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    if (checkWidth == SM_CXMENUCHECK_DEFAULT_ON_VISTA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        checkWidth = SM_CXMENUCHECK_DEFAULT_ON_XP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
void AwtMenuItem::DrawItem(DRAWITEMSTRUCT& drawInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    DASSERT(drawInfo.CtlType == ODT_MENU);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    if (drawInfo.itemID != m_Id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   439
    DrawSelf(drawInfo);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
void AwtMenuItem::MeasureSelf(HDC hDC, MEASUREITEMSTRUCT& measureInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    JNIEnv *env =(JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    if (env->EnsureLocalCapacity(4) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /* self is a sun.awt.windows.WMenuItemPeer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    jobject self = GetPeer(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /* font is a java.awt.Font */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    jobject font = GetFont(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    jstring text = GetJavaString(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    SIZE size = AwtFont::getMFStringSize(hDC, font, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    /* 4700350: If the font size is taller than the menubar, change to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * default font.  Otherwise, menu text is painted over the title bar and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * client area.  -bchristi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    if (IsTopMenu() && size.cy > ::GetSystemMetrics(SM_CYMENU)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        jobject defFont = GetDefaultFont(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        env->DeleteLocalRef(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        font = env->NewLocalRef(defFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        size = AwtFont::getMFStringSize(hDC, font, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    jstring fontName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        (jstring)JNU_CallMethodByName(env, 0,font, "getName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                                      "()Ljava/lang/String;").l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /* fontMetrics is a Hsun_awt_windows_WFontMetrics */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    jobject fontMetrics =  GetFontMetrics(env, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
//     int height = env->GetIntField(fontMetrics, AwtFont::heightID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    int height = (jint)JNU_CallMethodByName(env, 0, fontMetrics, "getHeight",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                            "()I").i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    measureInfo.itemHeight = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    measureInfo.itemHeight += measureInfo.itemHeight/3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    // 3 is a heuristic number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    measureInfo.itemWidth = size.cx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    if (!IsTopMenu()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        int checkWidth = ::GetSystemMetrics(SM_CXMENUCHECK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        // Workaround for CR#6401956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        if (IS_WINVISTA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            AdjustCheckWidth(checkWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        measureInfo.itemWidth += checkWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        // Add in shortcut width, if one exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        jstring shortcutLabel =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            (jstring)env->GetObjectField(self, AwtMenuItem::shortcutLabelID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (shortcutLabel != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            size = AwtFont::getMFStringSize(hDC, font, shortcutLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            measureInfo.itemWidth += size.cx + checkWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            env->DeleteLocalRef(shortcutLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    env->DeleteLocalRef(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    env->DeleteLocalRef(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    env->DeleteLocalRef(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    env->DeleteLocalRef(fontMetrics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
void AwtMenuItem::MeasureItem(HDC hDC, MEASUREITEMSTRUCT& measureInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    DASSERT(measureInfo.CtlType == ODT_MENU);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    if (measureInfo.itemID != m_Id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    MeasureSelf(hDC, measureInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
jobject AwtMenuItem::GetFontMetrics(JNIEnv *env, jobject font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    static jobject toolkit = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    if (toolkit == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (env->PushLocalFrame(2) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        jclass cls = env->FindClass("java/awt/Toolkit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        jobject toolkitLocal =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            env->CallStaticObjectMethod(cls, AwtToolkit::getDefaultToolkitMID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        toolkit = env->NewGlobalRef(toolkitLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        DASSERT(!safe_ExceptionOccurred(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        env->PopLocalFrame(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    JNU_PrintClass(env, "toolkit", toolkit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    JNU_PrintClass(env, "font", font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    jclass cls = env->FindClass("java/awt/Toolkit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    jmethodID mid = env->GetMethodID(cls, "getFontMetrics",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                                     "(Ljava/awt/Font;)Ljava/awt/FontMetrics;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    jstring fontName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        (jstring)JNU_CallMethodByName(env, 0,font, "getName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                                      "()Ljava/lang/String;").l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    JNU_PrintString(env, "font name", fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    fprintf(stderr, "mid: %x\n", mid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    fprintf(stderr, "cached mid: %x\n", AwtToolkit::getFontMetricsMID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    DASSERT(!safe_ExceptionOccurred(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    jobject fontMetrics =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
      env->CallObjectMethod(toolkit, AwtToolkit::getFontMetricsMID, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    DASSERT(!safe_ExceptionOccurred(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    return fontMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
BOOL AwtMenuItem::IsTopMenu()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
void AwtMenuItem::DrawCheck(HDC hDC, RECT rect)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    if (bmpCheck == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        bmpCheck = ::LoadBitmap(AwtToolkit::GetInstance().GetModuleHandle(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                TEXT("CHECK_BITMAP"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        DASSERT(bmpCheck != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
#define BM_SIZE 26  /* height and width of check.bmp */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    // Square the rectangle, so the check is proportional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    int width = rect.right - rect.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    int diff = max(rect.bottom - rect.top - width, 0) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    int bottom = diff / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    rect.bottom -= bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    rect.top += diff - bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    HDC hdcBitmap = ::CreateCompatibleDC(hDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    DASSERT(hdcBitmap != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    HBITMAP hbmSave = (HBITMAP)::SelectObject(hdcBitmap, bmpCheck);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    VERIFY(::StretchBlt(hDC, rect.left, rect.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                        rect.right - rect.left, rect.bottom - rect.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                        hdcBitmap, 0, 0, BM_SIZE, BM_SIZE, SRCCOPY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    ::SelectObject(hdcBitmap, hbmSave);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    VERIFY(::DeleteDC(hdcBitmap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
void AwtMenuItem::DoCommand()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    // peer is sun.awt.windows.WMenuItemPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    jobject peer = GetPeer(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    if (IsCheckbox()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        UINT nState = ::GetMenuState(GetMenuContainer()->GetHMenu(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                                     GetID(), MF_BYCOMMAND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        DASSERT(nState != 0xFFFFFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        DoCallback("handleAction", "(Z)V", ((nState & MF_CHECKED) == 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        DoCallback("handleAction", "(JI)V", TimeHelper::getMessageTimeUTC(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                   (jint)AwtComponent::GetJavaModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
void AwtMenuItem::SetLabel(LPCTSTR sb)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    AwtMenu* menu = GetMenuContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /* Fix for bug 4257944 by ssi@sparc.spb.su
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    * check parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    if (menu == NULL) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    DASSERT(menu != NULL && GetID() >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
 * SetMenuItemInfo is replaced by this code for fix bug 4261935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    HMENU hMenu = menu->GetHMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    MENUITEMINFO mii, mii1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    // get full information about menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    memset(&mii, 0, sizeof(MENUITEMINFO));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    mii.cbSize = sizeof(MENUITEMINFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    mii.fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
              | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    ::GetMenuItemInfo(hMenu, GetID(), FALSE, &mii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    mii.fType = MFT_OWNERDRAW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    mii.dwTypeData = (LPTSTR)(*sb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    // find index by menu item id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    int nMenuItemCount = ::GetMenuItemCount(hMenu);;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    int idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    for (idx = 0; (idx < nMenuItemCount); idx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        memset(&mii1, 0, sizeof(MENUITEMINFO));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        mii1.cbSize = sizeof mii1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        mii1.fMask = MIIM_ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        ::GetMenuItemInfo(hMenu, idx, TRUE, &mii1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        if (mii.wID == mii1.wID) break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    ::RemoveMenu(hMenu, idx, MF_BYPOSITION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    ::InsertMenuItem(hMenu, idx, TRUE, &mii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    // Redraw menu bar if it was affected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    if (menu->GetMenuBar() == menu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        ::DrawMenuBar(menu->GetOwnerHWnd());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
void AwtMenuItem::Enable(BOOL isEnabled)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    AwtMenu* menu = GetMenuContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    /* Fix for bug 4257944 by ssi@sparc.spb.su
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    * check state of the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    if (menu == NULL) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    isEnabled = isEnabled && !menu->IsDisabledAndPopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    DASSERT(menu != NULL && GetID() >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    VERIFY(::EnableMenuItem(menu->GetHMenu(), GetID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                            MF_BYCOMMAND | (isEnabled ? MF_ENABLED : MF_GRAYED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
           != 0xFFFFFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    // Redraw menu bar if it was affected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    if (menu->GetMenuBar() == menu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        ::DrawMenuBar(menu->GetOwnerHWnd());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
void AwtMenuItem::SetState(BOOL isChecked)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    AwtMenu* menu = GetMenuContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    /* Fix for bug 4257944 by ssi@sparc.spb.su
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    * check parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    if (menu == NULL) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    DASSERT(menu != NULL && GetID() >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    VERIFY(::CheckMenuItem(menu->GetHMenu(), GetID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                           MF_BYCOMMAND | (isChecked ? MF_CHECKED : MF_UNCHECKED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
           != 0xFFFFFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    // Redraw menu bar if it was affected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    if (menu->GetMenuBar() == menu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        ::DrawMenuBar(menu->GetOwnerHWnd());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
LRESULT AwtMenuItem::WinThreadExecProc(ExecuteArgs * args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    switch( args->cmdId ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        case MENUITEM_SETLABEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            LPCTSTR sb = (LPCTSTR)args->param1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            DASSERT(!IsBadStringPtr(sb, 20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            this->SetLabel(sb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        case MENUITEM_ENABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            BOOL        isEnabled = (BOOL)args->param1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            this->Enable(isEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        case MENUITEM_SETSTATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            BOOL        isChecked = (BOOL)args->param1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            this->SetState(isChecked);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            AwtObject::WinThreadExecProc(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
void AwtMenuItem::_SetLabel(void *param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    SetLabelStruct *sls = (SetLabelStruct *)param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    jobject self = sls->menuitem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    jstring label = sls->label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    int badAlloc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    AwtMenuItem *m = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    PDATA pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    JNI_CHECK_PEER_GOTO(self, ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    m = (AwtMenuItem *)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
//    if (::IsWindow(m->GetOwnerHWnd()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        // fix for bug 4251036 MenuItem setLabel(null/"") behaves differently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        // under Win32 and Solaris
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        jstring empty = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        if (JNU_IsNull(env, label))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            empty = JNU_NewStringPlatform(env, TEXT(""));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        LPCTSTR labelPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        if (empty != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            labelPtr = JNU_GetStringPlatformChars(env, empty, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            labelPtr = JNU_GetStringPlatformChars(env, label, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        if (labelPtr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            badAlloc = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            ExecuteArgs args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            args.cmdId = MENUITEM_SETLABEL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            args.param1 = (LPARAM)labelPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            m->WinThreadExecProc(&args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            if (empty != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                JNU_ReleaseStringPlatformChars(env, empty, labelPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                JNU_ReleaseStringPlatformChars(env, label, labelPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        if (empty != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            env->DeleteLocalRef(empty);
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
ret:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    env->DeleteGlobalRef(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    if (label != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        env->DeleteGlobalRef(label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    delete sls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    if (badAlloc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        throw std::bad_alloc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
BOOL AwtMenuItem::IsSeparator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    if (env->EnsureLocalCapacity(2) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    jobject jitem = GetTarget(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    jstring label  =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        (jstring)(env)->GetObjectField(jitem, AwtMenuItem::labelID);
6485
5e6b2f2666ae 6480547: REG: bug 4118621 which got Integrated in 1.1.8 fails in mustang from b25 onwards.
dav
parents: 5506
diff changeset
   797
    if (label == NULL) {
5e6b2f2666ae 6480547: REG: bug 4118621 which got Integrated in 1.1.8 fails in mustang from b25 onwards.
dav
parents: 5506
diff changeset
   798
        env->DeleteLocalRef(label);
5e6b2f2666ae 6480547: REG: bug 4118621 which got Integrated in 1.1.8 fails in mustang from b25 onwards.
dav
parents: 5506
diff changeset
   799
        env->DeleteLocalRef(jitem);
5e6b2f2666ae 6480547: REG: bug 4118621 which got Integrated in 1.1.8 fails in mustang from b25 onwards.
dav
parents: 5506
diff changeset
   800
        return FALSE; //separator must has '-' as label.
5e6b2f2666ae 6480547: REG: bug 4118621 which got Integrated in 1.1.8 fails in mustang from b25 onwards.
dav
parents: 5506
diff changeset
   801
    }
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   802
    LPCWSTR labelW = JNU_GetStringPlatformChars(env, label, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    BOOL isSeparator = (labelW && (wcscmp(labelW, L"-") == 0));
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
   804
    JNU_ReleaseStringPlatformChars(env, label, labelW);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    env->DeleteLocalRef(label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    env->DeleteLocalRef(jitem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    return isSeparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
 * MenuComponent native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
Java_java_awt_MenuComponent_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    AwtMenuItem::fontID = env->GetFieldID(cls, "font", "Ljava/awt/Font;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    AwtMenuItem::appContextID = env->GetFieldID(cls, "appContext", "Lsun/awt/AppContext;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    DASSERT(AwtMenuItem::fontID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
 * MenuItem native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
Java_java_awt_MenuItem_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    AwtMenuItem::labelID = env->GetFieldID(cls, "label", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    AwtMenuItem::enabledID = env->GetFieldID(cls, "enabled", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    DASSERT(AwtMenuItem::labelID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    DASSERT(AwtMenuItem::enabledID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
 * CheckboxMenuItem fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
Java_java_awt_CheckboxMenuItem_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    AwtMenuItem::stateID = env->GetFieldID(cls, "state", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    DASSERT(AwtMenuItem::stateID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
 * WMenuItemPeer native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
 * Class:     sun_awt_windows_WMenuItemPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
 * Method:    _setLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
 * Signature: (Ljava/lang/String;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
Java_sun_awt_windows_WMenuItemPeer_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    AwtMenuItem::isCheckboxID = env->GetFieldID(cls, "isCheckbox", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    AwtMenuItem::shortcutLabelID = env->GetFieldID(cls, "shortcutLabel",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                                                   "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    AwtMenuItem::getDefaultFontMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        env->GetStaticMethodID(cls, "getDefaultFont", "()Ljava/awt/Font;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    DASSERT(AwtMenuItem::isCheckboxID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    DASSERT(AwtMenuItem::shortcutLabelID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    DASSERT(AwtMenuItem::getDefaultFontMID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
 * Class:     sun_awt_windows_WMenuItemPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
 * Method:    _setLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
 * Signature: (Ljava/lang/String;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
Java_sun_awt_windows_WMenuItemPeer__1setLabel(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                                              jstring label)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    SetLabelStruct *sls = new SetLabelStruct;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    sls->menuitem = env->NewGlobalRef(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    sls->label = (label == NULL) ? NULL : (jstring)env->NewGlobalRef(label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    AwtToolkit::GetInstance().SyncCall(AwtMenuItem::_SetLabel, sls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    // global refs and sls are deleted in _SetLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
 * Class:     sun_awt_windows_WMenuItemPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
 * Method:    create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
 * Signature: (Lsun/awt/windows/WMenuPeer;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
Java_sun_awt_windows_WMenuItemPeer_create(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                                          jobject menu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    JNI_CHECK_NULL_RETURN(menu, "null Menu");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    AwtToolkit::CreateComponent(self, menu,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                                (AwtToolkit::ComponentFactory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                                AwtMenuItem::Create);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    PDATA pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    JNI_CHECK_PEER_CREATION_RETURN(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
 * Class:     sun_awt_windows_WMenuItemPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
 * Method:    enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
 * Signature: (Z)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
Java_sun_awt_windows_WMenuItemPeer_enable(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                                          jboolean on)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    PDATA pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    JNI_CHECK_PEER_RETURN(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    AwtObject::WinThreadExec(self, AwtMenuItem::MENUITEM_ENABLE, (LPARAM)on );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
 * Class:     sun_awt_windows_WMenuItemPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
 * Method:    _dispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
Java_sun_awt_windows_WMenuItemPeer__1dispose(JNIEnv *env, jobject self)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    TRY_NO_HANG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    PDATA pData = JNI_GET_PDATA(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    AwtObject::_Dispose(pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
} /* extern "C" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
 * WCheckboxMenuItemPeer native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
 * Class:     sun_awt_windows_WCheckboxMenuItemPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
 * Method:    setState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
 * Signature: (Z)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
Java_sun_awt_windows_WCheckboxMenuItemPeer_setState(JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                                                    jboolean on)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    PDATA pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    JNI_CHECK_PEER_RETURN(self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    AwtObject::WinThreadExec(self, AwtMenuItem::MENUITEM_SETSTATE, (LPARAM)on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    CATCH_BAD_ALLOC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
} /* extern "C" */