| 1 | /* |
| 2 | * $Id: MENUITEMINFO.java,v 1.2 2004/11/03 22:18:24 hastings Exp $ |
| 3 | * |
| 4 | * (c) Copyright, Moebius Solutions, Inc., 2004 |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This material may be reproduced by or for the U. S. Government |
| 9 | * pursuant to the copyright license under the clause at |
| 10 | * DFARS 252.227-7014 (OCT 2001). |
| 11 | */ |
| 12 | |
| 13 | package com.moesol.bindings.platform_sdk.windows_api; |
| 14 | |
| 15 | import java.nio.*; |
| 16 | |
| 17 | /** |
| 18 | * Wraps a java class around a Win32 MENUITEMINFO structure, see the |
| 19 | * Win32 documentation for more information about the properties. |
| 20 | * TODO: Refactor to use com.moesol.nio.NativeStructure (uses a non-direct ByteBuffer). |
| 21 | */ |
| 22 | public class MENUITEMINFO { |
| 23 | public MENUITEMINFO() { |
| 24 | m_native_mii = ByteBuffer.allocateDirect(sizeof()); |
| 25 | m_native_mii.order(ByteOrder.nativeOrder()); |
| 26 | zero(); |
| 27 | set_cbSize(sizeof()); |
| 28 | } |
| 29 | |
| 30 | private void set_cbSize(int size) { |
| 31 | m_native_mii.putInt(0, size); |
| 32 | } |
| 33 | /** package access for testing */ |
| 34 | int get_cbSize() { |
| 35 | return m_native_mii.getInt(0); |
| 36 | } |
| 37 | boolean verify_cbSize() { |
| 38 | return jni_verify_cbSize(m_native_mii); |
| 39 | } |
| 40 | |
| 41 | public void set_fMask(int mask) { |
| 42 | m_native_mii.putInt(4, mask); |
| 43 | } |
| 44 | public int get_fMask() { |
| 45 | return m_native_mii.getInt(4); |
| 46 | } |
| 47 | boolean verify_fMask(int value) { |
| 48 | return jni_verify_fMask(m_native_mii, value); |
| 49 | } |
| 50 | |
| 51 | public void set_fType(int type) { |
| 52 | m_native_mii.putInt(8, type); |
| 53 | } |
| 54 | public int get_fType() { |
| 55 | return m_native_mii.getInt(8); |
| 56 | } |
| 57 | boolean verify_fType(int value) { |
| 58 | return jni_verify_fType(m_native_mii, value); |
| 59 | } |
| 60 | |
| 61 | public void set_fState(int state) { |
| 62 | m_native_mii.putInt(12, state); |
| 63 | } |
| 64 | public int get_fState() { |
| 65 | return m_native_mii.getInt(12); |
| 66 | } |
| 67 | boolean verify_fState(int value) { |
| 68 | return jni_verify_fState(m_native_mii, value); |
| 69 | } |
| 70 | |
| 71 | public void set_wID(int id) { |
| 72 | m_native_mii.putInt(16, id); |
| 73 | } |
| 74 | public int get_wID() { |
| 75 | return m_native_mii.getInt(16); |
| 76 | } |
| 77 | boolean verify_wID(int value) { |
| 78 | return jni_verify_wID(m_native_mii, value); |
| 79 | } |
| 80 | |
| 81 | public void set_hSubMenu(HMENU submenu) { |
| 82 | m_native_mii.putInt(20, (int)HMENU._safeGetHandle(submenu)); |
| 83 | } |
| 84 | public HMENU get_hSubMenu() { |
| 85 | return new HMENU(m_native_mii.getInt(20), true); |
| 86 | } |
| 87 | boolean verify_hSubMenu(int value) { |
| 88 | return jni_verify_hSubMenu(m_native_mii, value); |
| 89 | } |
| 90 | |
| 91 | public void set_hbmpChecked(HBITMAP bitmap) { |
| 92 | m_native_mii.putInt(24, (int)HBITMAP._safeGetHandle(bitmap)); |
| 93 | } |
| 94 | public HBITMAP get_hbmpChecked() { |
| 95 | return new HBITMAP(m_native_mii.getInt(24), true); |
| 96 | } |
| 97 | boolean verify_hbmpChecked(int value) { |
| 98 | return jni_verify_hbmpChecked(m_native_mii, value); |
| 99 | } |
| 100 | |
| 101 | public void set_hbmpUnchecked(HBITMAP bitmap) { |
| 102 | m_native_mii.putInt(28, (int)HBITMAP._safeGetHandle(bitmap)); |
| 103 | } |
| 104 | public HBITMAP get_hbmpUnchecked() { |
| 105 | return new HBITMAP(m_native_mii.getInt(28), true); |
| 106 | } |
| 107 | boolean verify_hbmpUnchecked(int value) { |
| 108 | return jni_verify_hbmpUnchecked(m_native_mii, value); |
| 109 | } |
| 110 | |
| 111 | public void set_dwItemData(int item_data) { |
| 112 | m_native_mii.putInt(32, item_data); |
| 113 | } |
| 114 | public int get_dwItemData() { |
| 115 | return m_native_mii.getInt(32); |
| 116 | } |
| 117 | boolean verify_dwItemData(int value) { |
| 118 | return jni_verify_dwItemData(m_native_mii, value); |
| 119 | } |
| 120 | |
| 121 | public void set_dwTypeData(String type_data) { |
| 122 | // Only support strings for now, and you |
| 123 | // have to convert from String to UTF |
| 124 | // in InsertMenuItem |
| 125 | m_type_data = type_data; |
| 126 | // offset of 36 |
| 127 | } |
| 128 | public String get_dwTypeData() { |
| 129 | return m_type_data; |
| 130 | } |
| 131 | boolean verify_dwTypeData(String value) { |
| 132 | return jni_verify_dwTypeData(m_native_mii, value); |
| 133 | } |
| 134 | |
| 135 | public void set_cch(int cch) { |
| 136 | m_native_mii.putInt(40, cch); |
| 137 | } |
| 138 | public int get_cch() { |
| 139 | return m_native_mii.getInt(40); |
| 140 | } |
| 141 | boolean verify_cch(int value) { |
| 142 | return jni_verify_cch(m_native_mii, value); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Note that the hbmpItem member of MENUITEMINFO only appears if |
| 147 | * the JNI side is compiled with _WIN32_WINNT >= 0x0500. Therefore |
| 148 | * this method may throw a IndexOutOfBoundsException. |
| 149 | * |
| 150 | * @throws IndexOutOfBoundsException If JNI side is missing this |
| 151 | * member. |
| 152 | */ |
| 153 | public void set_hbmpItem(HBITMAP bitmap) { |
| 154 | m_native_mii.putInt(44, (int)HBITMAP._safeGetHandle(bitmap)); |
| 155 | } |
| 156 | /** |
| 157 | * @throws IndexOutOfBoundsException If JNI side is missing this |
| 158 | * member. |
| 159 | */ |
| 160 | public HBITMAP get_hbmpItem() { |
| 161 | return new HBITMAP(m_native_mii.getInt(44)); |
| 162 | } |
| 163 | boolean verify_hbmpItem(int value) { |
| 164 | return jni_verify_hbmpItem(m_native_mii, value); |
| 165 | } |
| 166 | |
| 167 | private void zero() { |
| 168 | for (int i = 0; i < sizeof(); i++) { |
| 169 | m_native_mii.put(i, (byte)0); |
| 170 | } |
| 171 | } |
| 172 | static int sizeof() { |
| 173 | return jni_sizeof(); |
| 174 | } |
| 175 | |
| 176 | public static final int MIIM_STATE = 0x00000001; |
| 177 | public static final int MIIM_ID = 0x00000002; |
| 178 | public static final int MIIM_SUBMENU = 0x00000004; |
| 179 | public static final int MIIM_CHECKMARKS = 0x00000008; |
| 180 | public static final int MIIM_TYPE = 0x00000010; |
| 181 | public static final int MIIM_DATA = 0x00000020; |
| 182 | |
| 183 | public static final int MFT_STRING = 0x00000000; |
| 184 | public static final int MFT_BITMAP = 0x00000004; |
| 185 | public static final int MFT_MENUBARBREAK = 0x00000020; |
| 186 | public static final int MFT_MENUBREAK = 0x00000040; |
| 187 | public static final int MFT_OWNERDRAW = 0x00000100; |
| 188 | public static final int MFT_RADIOCHECK = 0x00000200; |
| 189 | public static final int MFT_SEPARATOR = 0x00000800; |
| 190 | public static final int MFT_RIGHTORDER = 0x00002000; |
| 191 | public static final int MFT_RIGHTJUSTIFY = 0x00004000; |
| 192 | |
| 193 | public static final int MFS_GRAYED = 0x00000003; |
| 194 | public static final int MFS_DISABLED = MFS_GRAYED; |
| 195 | public static final int MFS_CHECKED = 0x00000008; |
| 196 | public static final int MFS_HILITE = 0x00000080; |
| 197 | public static final int MFS_ENABLED = 0x00000000; |
| 198 | public static final int MFS_UNCHECKED = 0x00000000; |
| 199 | public static final int MFS_UNHILITE = 0x00000000; |
| 200 | public static final int MFS_DEFAULT = 0x00001000; |
| 201 | |
| 202 | private static native int jni_sizeof(); |
| 203 | private native boolean jni_verify_cbSize(ByteBuffer native_mmi); |
| 204 | private native boolean jni_verify_fMask(ByteBuffer native_mmi, int value); |
| 205 | private native boolean jni_verify_fType(ByteBuffer native_mmi, int value); |
| 206 | private native boolean jni_verify_fState(ByteBuffer native_mmi, int value); |
| 207 | private native boolean jni_verify_wID(ByteBuffer native_mmi, int value); |
| 208 | private native boolean jni_verify_hSubMenu(ByteBuffer native_mmi, int value); |
| 209 | private native boolean jni_verify_hbmpChecked(ByteBuffer native_mmi, int value); |
| 210 | private native boolean jni_verify_hbmpUnchecked(ByteBuffer native_mmi, int value); |
| 211 | private native boolean jni_verify_dwItemData(ByteBuffer native_mmi, int value); |
| 212 | private native boolean jni_verify_dwTypeData(ByteBuffer native_mmi, String value); |
| 213 | private native boolean jni_verify_cch(ByteBuffer native_mmi, int value); |
| 214 | private native boolean jni_verify_hbmpItem(ByteBuffer native_mmi, int value); |
| 215 | |
| 216 | ByteBuffer m_native_mii; |
| 217 | String m_type_data; |
| 218 | } |