jdk/src/windows/native/sun/windows/awt_MenuItem.h
author erikj
Thu, 07 Jun 2012 18:05:09 -0700
changeset 12813 c10ab96dcf41
parent 10098 0674614189ba
child 23010 6dadb192ad81
permissions -rw-r--r--
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI Reviewed-by: ohair, ohrstrom, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1996, 2006, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#ifndef AWT_MENUITEM_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#define AWT_MENUITEM_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "awt_Object.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <java_awt_MenuItem.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <sun_awt_windows_WMenuItemPeer.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <java_awt_Menu.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <sun_awt_windows_WMenuPeer.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <java_awt_MenuComponent.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <java_awt_FontMetrics.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
class AwtMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * MenuItem class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
class AwtMenuItem : public AwtObject {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    // id's for methods executed on toolkit thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        MENUITEM_ENABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        MENUITEM_SETSTATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        MENUITEM_LAST
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /* java.awt.MenuComponent fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static jfieldID fontID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static jfieldID appContextID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /* java.awt.MenuItem fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static jfieldID labelID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static jfieldID enabledID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /* java.awt.CheckboxMenuItem fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static jfieldID stateID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /* sun.awt.windows.WMenuItemPeer fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static jfieldID isCheckboxID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    static jfieldID shortcutLabelID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    static jmethodID getDefaultFontMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    AwtMenuItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    virtual ~AwtMenuItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    virtual void Dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    virtual LPCTSTR GetClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static AwtMenuItem* Create(jobject self, jobject menu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    INLINE AwtMenu* GetMenuContainer() { return m_menuContainer; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    INLINE void SetMenuContainer(AwtMenu* menu) { m_menuContainer = menu; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    INLINE UINT GetID() { return m_Id; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    INLINE void SetID(UINT id) { m_Id = id; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    INLINE void SetNewID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        DASSERT(!m_freeId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        m_Id = AwtToolkit::GetInstance().CreateCmdID(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        m_freeId = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // Convert Language ID to CodePage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    static UINT LangToCodePage(LANGID idLang);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /* Execute the command associated with this item. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    virtual void DoCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    void LinkObjects(JNIEnv *env, jobject peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /* for multifont menuitem */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    INLINE jstring GetJavaString(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (env->EnsureLocalCapacity(2) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        jobject target = GetTarget(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        jstring res = (jstring)env->GetObjectField(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                                   AwtMenuItem::labelID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        env->DeleteLocalRef(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
// Added by waleed for BIDI Support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // returns the right to left status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    INLINE static BOOL GetRTLReadingOrder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return sm_rtlReadingOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    // returns the right to left status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    INLINE static BOOL GetRTL() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return sm_rtl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    INLINE static LANGID GetSubLanguage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return SUBLANGID(m_idLang);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // returns the current code page that should be used in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    // all MultiByteToWideChar and WideCharToMultiByte calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    // This code page should also be use in IsDBCSLeadByteEx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    INLINE static UINT GetCodePage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return m_CodePage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    INLINE static LANGID GetInputLanguage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return m_idLang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
// end waleed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    virtual void DrawItem(DRAWITEMSTRUCT& drawInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    void DrawSelf(DRAWITEMSTRUCT& drawInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    static void AdjustCheckWidth(int& checkWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    virtual void MeasureItem(HDC hDC, MEASUREITEMSTRUCT& measureInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    void MeasureSelf(HDC hDC, MEASUREITEMSTRUCT& measureInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    jobject GetFont(JNIEnv *env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    jobject GetFontMetrics(JNIEnv *env, jobject font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    jobject GetDefaultFont(JNIEnv *env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    virtual BOOL IsTopMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    void DrawCheck(HDC hDC, RECT rect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    void SetLabel(LPCTSTR sb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    virtual void Enable(BOOL isEnabled);
10098
0674614189ba 4717864: setFont() does not update Fonts of Menus already on screen
serb
parents: 5506
diff changeset
   148
    virtual void UpdateContainerLayout();
0674614189ba 4717864: setFont() does not update Fonts of Menus already on screen
serb
parents: 5506
diff changeset
   149
    virtual void RedrawMenuBar();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    void SetState(BOOL isChecked);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Windows message handler functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    MsgRouting WmNotify(UINT notifyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    virtual LRESULT WinThreadExecProc(ExecuteArgs * args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    virtual BOOL IsDisabledAndPopup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    virtual BOOL IsSeparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    // invoked on Toolkit thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    static void _SetLabel(void *param);
10098
0674614189ba 4717864: setFont() does not update Fonts of Menus already on screen
serb
parents: 5506
diff changeset
   165
    static void _UpdateLayout(void *param);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
protected:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    AwtMenu* m_menuContainer;  /* The menu object containing this item */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    UINT m_Id;                 /* The id of this item */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    static BOOL CheckMenuCreation(JNIEnv *env, jobject self, HMENU hMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    virtual void RemoveCmdID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
private:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    INLINE BOOL IsCheckbox() { return m_isCheckbox; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    INLINE void SetCheckbox() { m_isCheckbox = TRUE; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    BOOL m_isCheckbox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    BOOL m_freeId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    // Added for bi-di support By Waleed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    static UINT m_CodePage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    // Current input language (=low word of keyboardlayout handle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    // m_idLang is shared by all instance of AwtComponent because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    // keyboardlayout is shared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    static LANGID m_idLang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    static BOOL m_isWin95;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    static BOOL sm_rtl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    static BOOL sm_rtlReadingOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
public:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    static HBITMAP bmpCheck;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    static jobject systemFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
#endif /* AWT_MENUITEM_H */