comparison 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
comparison
equal deleted inserted replaced
2544:dbfcc0e357d6 2545:f803f3b164cf
3964 * Parameters: 3964 * Parameters:
3965 * menu: Handle of a menu. 3965 * menu: Handle of a menu.
3966 */ 3966 */
3967 void API dw_menu_destroy(HMENUI *menu) 3967 void API dw_menu_destroy(HMENUI *menu)
3968 { 3968 {
3969 JNIEnv *env;
3970
3971 if(menu && *menu && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3972 {
3973 // First get the class that contains the method you need to call
3974 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3975 // Get the method that you want to call
3976 jmethodID menuDestroy = env->GetMethodID(clazz, "menuDestroy",
3977 "(Lorg/dbsoft/dwindows/DWMenu;)V");
3978 // Call the method on the object
3979 env->CallVoidMethod(_dw_obj, menuDestroy, *menu);
3980 *menu = nullptr;
3981 }
3969 } 3982 }
3970 3983
3971 /* 3984 /*
3972 * Deletes the menu item specified. 3985 * Deletes the menu item specified.
3973 * Parameters: 3986 * Parameters:
3976 * Returns: 3989 * Returns:
3977 * DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure. 3990 * DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure.
3978 */ 3991 */
3979 int API dw_menu_delete_item(HMENUI menux, unsigned long id) 3992 int API dw_menu_delete_item(HMENUI menux, unsigned long id)
3980 { 3993 {
3994 JNIEnv *env;
3995
3996 if(menux && id > 0 && id < 30000 && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3997 {
3998 // First get the class that contains the method you need to call
3999 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
4000 // Get the method that you want to call
4001 jmethodID menuDeleteItem = env->GetMethodID(clazz, "menuDeleteItem",
4002 "(Lorg/dbsoft/dwindows/DWMenu;I)V");
4003 // Call the method on the object
4004 env->CallVoidMethod(_dw_obj, menuDeleteItem, menux, (int)id);
4005 return DW_ERROR_NONE;
4006 }
3981 return DW_ERROR_UNKNOWN; 4007 return DW_ERROR_UNKNOWN;
3982 } 4008 }
3983 4009
3984 /* 4010 /*
3985 * Pops up a context menu at given x and y coordinates. 4011 * Pops up a context menu at given x and y coordinates.
4057 * id: Menuitem id. 4083 * id: Menuitem id.
4058 * check: TRUE for checked FALSE for not checked. 4084 * check: TRUE for checked FALSE for not checked.
4059 */ 4085 */
4060 void API dw_menu_item_set_check(HMENUI menux, unsigned long itemid, int check) 4086 void API dw_menu_item_set_check(HMENUI menux, unsigned long itemid, int check)
4061 { 4087 {
4088 dw_menu_item_set_state(menux, itemid, check ? DW_MIS_CHECKED : DW_MIS_UNCHECKED);
4062 } 4089 }
4063 4090
4064 /* 4091 /*
4065 * Sets the state of a menu item. 4092 * Sets the state of a menu item.
4066 * Parameters: 4093 * Parameters:
4069 * flags: DW_MIS_ENABLED/DW_MIS_DISABLED 4096 * flags: DW_MIS_ENABLED/DW_MIS_DISABLED
4070 * DW_MIS_CHECKED/DW_MIS_UNCHECKED 4097 * DW_MIS_CHECKED/DW_MIS_UNCHECKED
4071 */ 4098 */
4072 void API dw_menu_item_set_state(HMENUI menux, unsigned long itemid, unsigned long state) 4099 void API dw_menu_item_set_state(HMENUI menux, unsigned long itemid, unsigned long state)
4073 { 4100 {
4101 JNIEnv *env;
4102
4103 if(menux && itemid > 0 && itemid < 30000 && state && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
4104 {
4105 // First get the class that contains the method you need to call
4106 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
4107 // Get the method that you want to call
4108 jmethodID menuSetState = env->GetMethodID(clazz, "menuSetState",
4109 "(Lorg/dbsoft/dwindows/DWMenu;II)V");
4110 // Call the method on the object
4111 env->CallVoidMethod(_dw_obj, menuSetState, menux, (int)itemid, (int)state);
4112 }
4074 } 4113 }
4075 4114
4076 /* 4115 /*
4077 * Create a notebook object to be packed. 4116 * Create a notebook object to be packed.
4078 * Parameters: 4117 * Parameters: