# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1620943428 0 # Node ID f803f3b164cfb52a8bcc30a7cc7e802177059ea3 # Parent dbfcc0e357d61e68b76f198f2ede02b6d4112088 Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy(). Also enable checkbox handling. diff -r dbfcc0e357d6 -r f803f3b164cf android/DWindows.kt --- a/android/DWindows.kt Thu May 13 20:46:07 2021 +0000 +++ b/android/DWindows.kt Thu May 13 22:03:48 2021 +0000 @@ -437,6 +437,8 @@ group += 1 } else if(menuitem.menuitem == null) { menuitem.menuitem = menu?.add(group, menuitem.id, 0, menuitem.title) + menuitem.menuitem!!.isCheckable = menuitem.check + menuitem.menuitem!!.isChecked = menuitem.checked menuitem.menuitem!!.setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener { item: MenuItem? -> eventHandlerSimple(menuitem, 8) true @@ -564,6 +566,50 @@ return menuitem } + fun menuDestroy(menu: DWMenu) + { + menu.children.clear() + runOnUiThread { + menu.menu!!.clear() + invalidateOptionsMenu() + } + } + + fun menuDeleteItem(menu: DWMenu, cid: Int) + { + for(menuitem in menu.children) { + if(menuitem.id == cid) { + menu.children.remove(menuitem) + runOnUiThread { + menu.menu!!.removeItem(menuitem.id) + invalidateOptionsMenu() + } + } + } + } + + fun menuSetState(menu: DWMenu, cid: Int, state: Int) + { + for(menuitem in menu.children) { + if(menuitem.id == cid) { + // Handle DW_MIS_CHECKED/UNCHECKED + if((state and ((1 shl 2) or (1 shl 3))) != 0) { + var checked: Boolean = false + + // Handle DW_MIS_CHECKED + if ((state and (1 shl 2)) != 0) { + checked = true + } + menuitem.checked = checked + runOnUiThread { + menuitem.menuitem!!.isChecked = checked + invalidateOptionsMenu() + } + } + } + } + } + /* * These are the Android calls to actually create the UI... * forwarded from the C Dynamic Windows API diff -r dbfcc0e357d6 -r f803f3b164cf android/dw.cpp --- a/android/dw.cpp Thu May 13 20:46:07 2021 +0000 +++ b/android/dw.cpp Thu May 13 22:03:48 2021 +0000 @@ -3966,6 +3966,19 @@ */ void API dw_menu_destroy(HMENUI *menu) { + JNIEnv *env; + + if(menu && *menu && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID menuDestroy = env->GetMethodID(clazz, "menuDestroy", + "(Lorg/dbsoft/dwindows/DWMenu;)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, menuDestroy, *menu); + *menu = nullptr; + } } /* @@ -3978,6 +3991,19 @@ */ int API dw_menu_delete_item(HMENUI menux, unsigned long id) { + JNIEnv *env; + + if(menux && id > 0 && id < 30000 && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID menuDeleteItem = env->GetMethodID(clazz, "menuDeleteItem", + "(Lorg/dbsoft/dwindows/DWMenu;I)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, menuDeleteItem, menux, (int)id); + return DW_ERROR_NONE; + } return DW_ERROR_UNKNOWN; } @@ -4059,6 +4085,7 @@ */ void API dw_menu_item_set_check(HMENUI menux, unsigned long itemid, int check) { + dw_menu_item_set_state(menux, itemid, check ? DW_MIS_CHECKED : DW_MIS_UNCHECKED); } /* @@ -4071,6 +4098,18 @@ */ void API dw_menu_item_set_state(HMENUI menux, unsigned long itemid, unsigned long state) { + JNIEnv *env; + + if(menux && itemid > 0 && itemid < 30000 && state && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID menuSetState = env->GetMethodID(clazz, "menuSetState", + "(Lorg/dbsoft/dwindows/DWMenu;II)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, menuSetState, menux, (int)itemid, (int)state); + } } /*