diff android/dw.cpp @ 2545:f803f3b164cf

Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy(). Also enable checkbox handling.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 13 May 2021 22:03:48 +0000
parents dbfcc0e357d6
children dbd15c13f5bb
line wrap: on
line diff
--- 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);
+    }
 }
 
 /*