comparison android/dw.cpp @ 2560:3da35cd91ca7

Android: Implement querying containers and ENTER and CONTEXT callbacks.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 18 May 2021 18:41:35 +0000
parents b5e8a319fde6
children f28d7d0ca5ed
comparison
equal deleted inserted replaced
2559:b5e8a319fde6 2560:3da35cd91ca7
515 void *params[8] = { nullptr, nullptr, nullptr, 515 void *params[8] = { nullptr, nullptr, nullptr,
516 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), 516 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb),
517 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr }; 517 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr };
518 518
519 _dw_event_handler(obj, params, message); 519 _dw_event_handler(obj, params, message);
520 }
521
522 JNIEXPORT void JNICALL
523 Java_org_dbsoft_dwindows_DWindows_eventHandlerContainer(JNIEnv* env, jobject obj, jobject obj1,
524 jint message, jstring jtitle, jint x, jint y, jlong data) {
525 const char *title = jtitle ? env->GetStringUTFChars(jtitle, nullptr) : nullptr;
526 void *params[8] = { nullptr, (void *)title, nullptr,
527 DW_INT_TO_POINTER(x), DW_INT_TO_POINTER(y),
528 nullptr, nullptr, (void *)data };
529
530 _dw_event_handler(obj1, params, message);
520 } 531 }
521 532
522 /* Handler for Timer events */ 533 /* Handler for Timer events */
523 JNIEXPORT jint JNICALL 534 JNIEXPORT jint JNICALL
524 Java_org_dbsoft_dwindows_DWindows_eventHandlerTimer(JNIEnv* env, jobject obj, jlong sigfunc, jlong data) { 535 Java_org_dbsoft_dwindows_DWindows_eventHandlerTimer(JNIEnv* env, jobject obj, jlong sigfunc, jlong data) {
3350 * row: Zero based row of data being set. 3361 * row: Zero based row of data being set.
3351 * title: String title of the item. 3362 * title: String title of the item.
3352 */ 3363 */
3353 void API dw_container_set_row_title(void *pointer, int row, const char *title) 3364 void API dw_container_set_row_title(void *pointer, int row, const char *title)
3354 { 3365 {
3366 HWND handle = (HWND)pointer;
3367
3368 if(handle)
3369 {
3370 int rowstart = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_rowstart"));
3371
3372 dw_container_change_row_title(handle, row + rowstart, title);
3373 }
3355 } 3374 }
3356 3375
3357 3376
3358 /* 3377 /*
3359 * Sets the title of a row in the container. 3378 * Sets the title of a row in the container.
3465 * Returns: 3484 * Returns:
3466 * Pointer to data associated with first entry or nullptr on error. 3485 * Pointer to data associated with first entry or nullptr on error.
3467 */ 3486 */
3468 char * API dw_container_query_start(HWND handle, unsigned long flags) 3487 char * API dw_container_query_start(HWND handle, unsigned long flags)
3469 { 3488 {
3489 JNIEnv *env;
3490 char *retval = nullptr;
3491
3492 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3493 {
3494 if(flags & DW_CR_RETDATA) {
3495 // First get the class that contains the method you need to call
3496 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3497 // Get the method that you want to call
3498 jmethodID containerGetDataStart = env->GetMethodID(clazz, "containerGetDataStart",
3499 "(Landroid/widget/ListView;I)J");
3500 // Call the method on the object
3501 jlong data = env->CallLongMethod(_dw_obj, containerGetDataStart, handle, (int)flags);
3502 if(!_dw_jni_check_exception(env))
3503 retval = (char *)data;
3504 } else {
3505 // First get the class that contains the method you need to call
3506 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3507 // Get the method that you want to call
3508 jmethodID containerGetDataStart = env->GetMethodID(clazz, "containerGetTitleStart",
3509 "(Landroid/widget/ListView;I)Ljava/lang/String;");
3510 // Call the method on the object
3511 jstring jstr = (jstring)_dw_jni_check_result(env, env->CallObjectMethod(_dw_obj, containerGetDataStart, handle, (int)flags), _DW_REFERENCE_NONE);
3512 if(jstr)
3513 retval = (char *)env->GetStringUTFChars(jstr, nullptr);
3514 }
3515 }
3470 return nullptr; 3516 return nullptr;
3471 } 3517 }
3472 3518
3473 /* 3519 /*
3474 * Continues an existing query of a container. 3520 * Continues an existing query of a container.
3480 * Returns: 3526 * Returns:
3481 * Pointer to data associated with next entry or nullptr on error or completion. 3527 * Pointer to data associated with next entry or nullptr on error or completion.
3482 */ 3528 */
3483 char * API dw_container_query_next(HWND handle, unsigned long flags) 3529 char * API dw_container_query_next(HWND handle, unsigned long flags)
3484 { 3530 {
3531 JNIEnv *env;
3532 char *retval = nullptr;
3533
3534 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3535 {
3536 if(flags & DW_CR_RETDATA) {
3537 // First get the class that contains the method you need to call
3538 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3539 // Get the method that you want to call
3540 jmethodID containerGetDataStart = env->GetMethodID(clazz, "containerGetDataNext",
3541 "(Landroid/widget/ListView;I)J");
3542 // Call the method on the object
3543 jlong data = env->CallLongMethod(_dw_obj, containerGetDataStart, handle, (int)flags);
3544 if(!_dw_jni_check_exception(env))
3545 retval = (char *)data;
3546 } else {
3547 // First get the class that contains the method you need to call
3548 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3549 // Get the method that you want to call
3550 jmethodID containerGetDataStart = env->GetMethodID(clazz, "containerGetTitleNext",
3551 "(Landroid/widget/ListView;I)Ljava/lang/String;");
3552 // Call the method on the object
3553 jstring jstr = (jstring)_dw_jni_check_result(env, env->CallObjectMethod(_dw_obj, containerGetDataStart, handle, (int)flags), _DW_REFERENCE_NONE);
3554 if(jstr)
3555 retval = (char *)env->GetStringUTFChars(jstr, nullptr);
3556 }
3557 }
3485 return nullptr; 3558 return nullptr;
3486 } 3559 }
3487 3560
3488 /* 3561 /*
3489 * Cursors the item with the text speficied, and scrolls to that item. 3562 * Cursors the item with the text speficied, and scrolls to that item.