1 /* 2 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef AWT_MENUITEM_H 27 #define AWT_MENUITEM_H 28 29 #include "awt_Object.h" 30 #include "awt_Component.h" 31 32 #include <java_awt_MenuItem.h> 33 #include <sun_awt_windows_WMenuItemPeer.h> 34 #include <java_awt_Menu.h> 35 #include <sun_awt_windows_WMenuPeer.h> 36 #include <java_awt_MenuComponent.h> 37 #include <java_awt_FontMetrics.h> 38 39 class AwtMenu; 40 41 42 /************************************************************************ 43 * MenuItem class 44 */ 45 46 class AwtMenuItem : public AwtObject { 47 public: 48 49 /* java.awt.MenuItem fields */ 50 static jfieldID labelID; 51 static jfieldID enabledID; 52 53 /* java.awt.CheckboxMenuItem fields */ 54 static jfieldID stateID; 55 56 /* sun.awt.windows.WMenuItemPeer fields */ 57 static jfieldID isCheckboxID; 58 static jfieldID shortcutLabelID; 59 60 static jmethodID getDefaultFontMID; 61 62 AwtMenuItem(); 63 virtual ~AwtMenuItem(); 64 65 virtual void Dispose(); 66 67 virtual LPCTSTR GetClassName(); 68 69 static AwtMenuItem* Create(jobject self, jobject menu); 70 71 INLINE AwtMenu* GetMenuContainer() { return m_menuContainer; } 72 INLINE void SetMenuContainer(AwtMenu* menu) { m_menuContainer = menu; } 73 INLINE UINT GetID() { return m_Id; } 74 INLINE void SetID(UINT id) { m_Id = id; } 75 INLINE void SetNewID() { 76 DASSERT(!m_freeId); 77 m_Id = AwtToolkit::GetInstance().CreateCmdID(this); 78 m_freeId = TRUE; 79 } 80 81 // Convert Language ID to CodePage 82 static UINT LangToCodePage(LANGID idLang); 83 /* Execute the command associated with this item. */ 84 virtual void DoCommand(); 85 86 void LinkObjects(JNIEnv *env, jobject peer); 87 88 /* for multifont menuitem */ 89 INLINE jstring GetJavaString(JNIEnv *env) { 90 if (env->EnsureLocalCapacity(2) < 0) { 91 return NULL; 92 } 93 jobject target = GetTarget(env); 94 jstring res = (jstring)env->GetObjectField(target, 95 AwtMenuItem::labelID); 96 env->DeleteLocalRef(target); 97 return res; 98 } 99 // Added by waleed for BIDI Support 100 // returns the right to left status 101 INLINE static BOOL GetRTLReadingOrder() { 102 return sm_rtlReadingOrder; 103 } 104 // returns the right to left status 105 INLINE static BOOL GetRTL() { 106 return sm_rtl; 107 } 108 INLINE static LANGID GetSubLanguage() { 109 return SUBLANGID(m_idLang); 110 } 111 // returns the current code page that should be used in 112 // all MultiByteToWideChar and WideCharToMultiByte calls. 113 // This code page should also be use in IsDBCSLeadByteEx. 114 INLINE static UINT GetCodePage() { 115 return m_CodePage; 116 } 117 INLINE static LANGID GetInputLanguage() { 118 return m_idLang; 119 } 120 // end waleed 121 122 virtual void DrawItem(DRAWITEMSTRUCT& drawInfo); 123 void DrawSelf(DRAWITEMSTRUCT& drawInfo); 124 static void AdjustCheckWidth(int& checkWidth); 125 126 virtual void MeasureItem(HDC hDC, MEASUREITEMSTRUCT& measureInfo); 127 void MeasureSelf(HDC hDC, MEASUREITEMSTRUCT& measureInfo); 128 129 jobject GetFont(JNIEnv *env); 130 jobject GetFontMetrics(JNIEnv *env, jobject font); 131 jobject GetDefaultFont(JNIEnv *env); 132 133 virtual BOOL IsTopMenu(); 134 void DrawCheck(HDC hDC, RECT rect); 135 136 void SetLabel(LPCTSTR sb); 137 virtual void Enable(BOOL isEnabled); 138 virtual void UpdateContainerLayout(); 139 virtual void RedrawMenuBar(); 140 void SetState(BOOL isChecked); 141 142 /* 143 * Windows message handler functions 144 */ 145 MsgRouting WmNotify(UINT notifyCode); 146 147 virtual BOOL IsDisabledAndPopup() { 148 return FALSE; 149 } 150 virtual BOOL IsSeparator(); 151 152 // invoked on Toolkit thread 153 static void _SetState(void *param); 154 static void _SetEnable(void *param); 155 static void _SetLabel(void *param); 156 static void _UpdateLayout(void *param); 157 158 protected: 159 AwtMenu* m_menuContainer; /* The menu object containing this item */ 160 UINT m_Id; /* The id of this item */ 161 162 static BOOL CheckMenuCreation(JNIEnv *env, jobject self, HMENU hMenu); 163 virtual void RemoveCmdID(); 164 165 private: 166 INLINE BOOL IsCheckbox() { return m_isCheckbox; } 167 INLINE void SetCheckbox() { m_isCheckbox = TRUE; } 168 BOOL m_isCheckbox; 169 BOOL m_freeId; 170 171 // Added for bi-di support By Waleed 172 static UINT m_CodePage; 173 // Current input language (=low word of keyboardlayout handle) 174 // m_idLang is shared by all instance of AwtComponent because 175 // keyboardlayout is shared. 176 static LANGID m_idLang; 177 static BOOL m_isWin95; 178 179 static BOOL sm_rtl; 180 static BOOL sm_rtlReadingOrder; 181 182 public: 183 static HBITMAP bmpCheck; 184 static jobject systemFont; 185 }; 186 187 #endif /* AWT_MENUITEM_H */