comparison android/dw.cpp @ 2558:ebc6a4ff5f1f

Android: Implement container row data and titles, required for the callbacks.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 18 May 2021 01:04:52 +0000
parents 756331246f94
children b5e8a319fde6
comparison
equal deleted inserted replaced
2557:756331246f94 2558:ebc6a4ff5f1f
103 { 103 {
104 jobject result = nullptr; 104 jobject result = nullptr;
105 105
106 if(!_dw_jni_check_exception(env) && obj) 106 if(!_dw_jni_check_exception(env) && obj)
107 { 107 {
108 if(reference == 1) 108 if(reference == _DW_REFERENCE_WEAK)
109 result = env->NewWeakGlobalRef(obj); 109 result = env->NewWeakGlobalRef(obj);
110 else if(reference == 2) 110 else if(reference == _DW_REFERENCE_STRONG)
111 result = env->NewGlobalRef(obj); 111 result = env->NewGlobalRef(obj);
112 else 112 else
113 result = obj; 113 result = obj;
114 } 114 }
115 return result; 115 return result;
3027 // Get the method that you want to call 3027 // Get the method that you want to call
3028 jmethodID containerNew = env->GetMethodID(clazz, "containerAddColumn", 3028 jmethodID containerNew = env->GetMethodID(clazz, "containerAddColumn",
3029 "(Landroid/widget/ListView;Ljava/lang/String;I)V"); 3029 "(Landroid/widget/ListView;Ljava/lang/String;I)V");
3030 // Call the method on the object 3030 // Call the method on the object
3031 env->CallVoidMethod(_dw_obj, containerNew, handle, jstr, (int)flags[z]); 3031 env->CallVoidMethod(_dw_obj, containerNew, handle, jstr, (int)flags[z]);
3032 _dw_jni_check_exception(env); 3032 if(!_dw_jni_check_exception(env))
3033 return DW_ERROR_NONE;
3033 } 3034 }
3034 } 3035 }
3035 } 3036 }
3036 return DW_ERROR_GENERAL; 3037 return DW_ERROR_GENERAL;
3037 } 3038 }
3058 */ 3059 */
3059 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count) 3060 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count)
3060 { 3061 {
3061 unsigned long fsflags[2] = { DW_CFA_BITMAPORICON, DW_CFA_STRING }; 3062 unsigned long fsflags[2] = { DW_CFA_BITMAPORICON, DW_CFA_STRING };
3062 char *fstitles[2] = { (char *)"Icon", (char *)"Filename" }; 3063 char *fstitles[2] = { (char *)"Icon", (char *)"Filename" };
3063 dw_container_setup(handle, fsflags, fstitles, 2, 0); 3064 int retval = dw_container_setup(handle, fsflags, fstitles, 2, 0);
3064 dw_container_setup(handle, flags, titles, count, 0); 3065
3065 return DW_ERROR_GENERAL; 3066 if(retval == DW_ERROR_NONE)
3067 retval = dw_container_setup(handle, flags, titles, count, 0);
3068 return retval;
3066 } 3069 }
3067 3070
3068 /* 3071 /*
3069 * Allocates memory used to populate a container. 3072 * Allocates memory used to populate a container.
3070 * Parameters: 3073 * Parameters:
3235 * row: Zero based row of data being set. 3238 * row: Zero based row of data being set.
3236 * data: Data pointer. 3239 * data: Data pointer.
3237 */ 3240 */
3238 void API dw_container_set_row_data(void *pointer, int row, void *data) 3241 void API dw_container_set_row_data(void *pointer, int row, void *data)
3239 { 3242 {
3243 HWND handle = (HWND)pointer;
3244
3245 if(handle)
3246 {
3247 int rowstart = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_rowstart"));
3248
3249 dw_container_change_row_data(handle, row + rowstart, data);
3250 }
3240 } 3251 }
3241 3252
3242 /* 3253 /*
3243 * Changes the data of a row already inserted in the container. 3254 * Changes the data of a row already inserted in the container.
3244 * Parameters: 3255 * Parameters:
3246 * row: Zero based row of data being set. 3257 * row: Zero based row of data being set.
3247 * data: Data pointer. 3258 * data: Data pointer.
3248 */ 3259 */
3249 void API dw_container_change_row_data(HWND handle, int row, void *data) 3260 void API dw_container_change_row_data(HWND handle, int row, void *data)
3250 { 3261 {
3262 JNIEnv *env;
3263
3264 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3265 {
3266 // First get the class that contains the method you need to call
3267 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3268 // Get the method that you want to call
3269 jmethodID containerChangeRowData = env->GetMethodID(clazz, "containerChangeRowData",
3270 "(Landroid/widget/ListView;IJ)V");
3271 // Call the method on the object
3272 env->CallVoidMethod(_dw_obj, containerChangeRowData, handle, row, (jlong)data);
3273 _dw_jni_check_exception(env);
3274 }
3251 } 3275 }
3252 3276
3253 /* 3277 /*
3254 * Gets column type for a container column. 3278 * Gets column type for a container column.
3255 * Parameters: 3279 * Parameters:
3334 * row: Zero based row of data being set. 3358 * row: Zero based row of data being set.
3335 * title: String title of the item. 3359 * title: String title of the item.
3336 */ 3360 */
3337 void API dw_container_change_row_title(HWND handle, int row, const char *title) 3361 void API dw_container_change_row_title(HWND handle, int row, const char *title)
3338 { 3362 {
3363 JNIEnv *env;
3364
3365 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3366 {
3367 // Generate a string
3368 jstring jstr = title ? env->NewStringUTF(title) : nullptr;
3369 // First get the class that contains the method you need to call
3370 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3371 // Get the method that you want to call
3372 jmethodID containerChangeRowTitle = env->GetMethodID(clazz, "containerChangeRowTitle",
3373 "(Landroid/widget/ListView;ILjava/lang/String;)V");
3374 // Call the method on the object
3375 env->CallVoidMethod(_dw_obj, containerChangeRowTitle, handle, row, jstr);
3376 _dw_jni_check_exception(env);
3377 }
3339 } 3378 }
3340 3379
3341 /* 3380 /*
3342 * Sets the title of a row in the container. 3381 * Sets the title of a row in the container.
3343 * Parameters: 3382 * Parameters:
3383 * handle: Handle to the window (widget) to be deleted from. 3422 * handle: Handle to the window (widget) to be deleted from.
3384 * rowcount: The number of rows to be deleted. 3423 * rowcount: The number of rows to be deleted.
3385 */ 3424 */
3386 void API dw_container_delete(HWND handle, int rowcount) 3425 void API dw_container_delete(HWND handle, int rowcount)
3387 { 3426 {
3427 JNIEnv *env;
3428
3429 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3430 {
3431 // First get the class that contains the method you need to call
3432 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3433 // Get the method that you want to call
3434 jmethodID containerDelete = env->GetMethodID(clazz, "containerDelete",
3435 "(Landroid/widget/ListView;I)V");
3436 // Call the method on the object
3437 env->CallVoidMethod(_dw_obj, containerDelete, handle, rowcount);
3438 _dw_jni_check_exception(env);
3439 }
3388 } 3440 }
3389 3441
3390 /* 3442 /*
3391 * Scrolls container up or down. 3443 * Scrolls container up or down.
3392 * Parameters: 3444 * Parameters:
3455 * handle: Handle to the window (widget). 3507 * handle: Handle to the window (widget).
3456 * text: Text usually returned by dw_container_query(). 3508 * text: Text usually returned by dw_container_query().
3457 */ 3509 */
3458 void API dw_container_delete_row(HWND handle, const char *text) 3510 void API dw_container_delete_row(HWND handle, const char *text)
3459 { 3511 {
3512 JNIEnv *env;
3513
3514 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3515 {
3516 // Generate a string
3517 jstring jstr = text ? env->NewStringUTF(text) : nullptr;
3518 // First get the class that contains the method you need to call
3519 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3520 // Get the method that you want to call
3521 jmethodID containerRowDeleteByTitle = env->GetMethodID(clazz, "containerRowDeleteByTitle",
3522 "(Landroid/widget/ListView;Ljava/lang/String;)V");
3523 // Call the method on the object
3524 env->CallVoidMethod(_dw_obj, containerRowDeleteByTitle, handle, jstr);
3525 _dw_jni_check_exception(env);
3526 }
3460 } 3527 }
3461 3528
3462 /* 3529 /*
3463 * Deletes the item with the data speficied. 3530 * Deletes the item with the data speficied.
3464 * Parameters: 3531 * Parameters:
3465 * handle: Handle to the window (widget). 3532 * handle: Handle to the window (widget).
3466 * data: Data usually returned by dw_container_query(). 3533 * data: Data usually returned by dw_container_query().
3467 */ 3534 */
3468 void API dw_container_delete_row_by_data(HWND handle, void *data) 3535 void API dw_container_delete_row_by_data(HWND handle, void *data)
3469 { 3536 {
3537 JNIEnv *env;
3538
3539 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3540 {
3541 // First get the class that contains the method you need to call
3542 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3543 // Get the method that you want to call
3544 jmethodID containerRowDeleteByData = env->GetMethodID(clazz, "containerRowDeleteByData",
3545 "(Landroid/widget/ListView;J)V");
3546 // Call the method on the object
3547 env->CallVoidMethod(_dw_obj, containerRowDeleteByData, handle, (jlong)data);
3548 _dw_jni_check_exception(env);
3549 }
3470 } 3550 }
3471 3551
3472 /* 3552 /*
3473 * Optimizes the column widths so that all data is visible. 3553 * Optimizes the column widths so that all data is visible.
3474 * Parameters: 3554 * Parameters: