comparison android/dw.cpp @ 2566:4427af56eebe

Android: Add experimental event threading code, currently disabled.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 19 May 2021 20:13:11 +0000
parents f28d7d0ca5ed
children e34b627b2491
comparison
equal deleted inserted replaced
2565:5463801a888f 2566:4427af56eebe
34 34
35 #ifdef __cplusplus 35 #ifdef __cplusplus
36 extern "C" { 36 extern "C" {
37 #endif 37 #endif
38 38
39 /* Define this to enable threading for events...
40 * most Android events don't handle return values, so
41 * we can launch a new thread to handle the event.
42 * #define _DW_EVENT_THREADING
43 */
39 #define DW_CLASS_NAME "org/dbsoft/dwindows/DWindows" 44 #define DW_CLASS_NAME "org/dbsoft/dwindows/DWindows"
40 45
41 /* Dynamic Windows internal variables */ 46 /* Dynamic Windows internal variables */
42 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; 47 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0};
43 static char _dw_app_name[_DW_APP_ID_SIZE+1]= {0}; 48 static char _dw_app_name[_DW_APP_ID_SIZE+1]= {0};
248 { 17, DW_SIGNAL_COLUMN_CLICK }, 253 { 17, DW_SIGNAL_COLUMN_CLICK },
249 { 18, DW_SIGNAL_HTML_RESULT }, 254 { 18, DW_SIGNAL_HTML_RESULT },
250 { 19, DW_SIGNAL_HTML_CHANGED } 255 { 19, DW_SIGNAL_HTML_CHANGED }
251 }; 256 };
252 257
253 int _dw_event_handler(jobject object, void **params, int message) 258
254 { 259 int _dw_event_handler2(void **params)
255 SignalHandler *handler = _dw_get_handler(object, message); 260 {
261 SignalHandler *handler = (SignalHandler *)params[9];
262 int message = DW_POINTER_TO_INT(params[8]);
256 263
257 if(handler) 264 if(handler)
258 { 265 {
259 switch(message) 266 switch(message)
260 { 267 {
415 } 422 }
416 } 423 }
417 return -1; 424 return -1;
418 } 425 }
419 426
427 int _dw_event_handler(jobject object, void **params) {
428 SignalHandler *handler = _dw_get_handler(object, DW_POINTER_TO_INT(params[8]));
429
430 if (handler)
431 {
432 params[9] = (void *)handler;
433
434 #ifdef _DW_EVENT_THREADING
435 /* We can't launch a thread for draw events it won't work */
436 if(DW_POINTER_TO_INT(params[8]) != 7)
437 dw_thread_new((void *)_dw_event_handler2, (void *)params, 0);
438 else
439 #endif
440 return _dw_event_handler2(params);
441
442 }
443 return 0;
444 }
445
420 /* 446 /*
421 * Entry location for all event handlers from the Android UI 447 * Entry location for all event handlers from the Android UI
422 */ 448 */
423 JNIEXPORT jint JNICALL 449 JNIEXPORT jint JNICALL
424 Java_org_dbsoft_dwindows_DWindows_eventHandler(JNIEnv* env, jobject obj, jobject obj1, jobject obj2, 450 Java_org_dbsoft_dwindows_DWindows_eventHandler(JNIEnv* env, jobject obj, jobject obj1, jobject obj2,
425 jint message, jstring str1, jstring str2, 451 jint message, jstring str1, jstring str2,
426 jint inta, jint intb, jint intc, jint intd) { 452 jint inta, jint intb, jint intc, jint intd) {
427 const char *utf81 = str1 ? env->GetStringUTFChars(str1, nullptr) : nullptr; 453 const char *utf81 = str1 ? env->GetStringUTFChars(str1, nullptr) : nullptr;
428 const char *utf82 = str2 ? env->GetStringUTFChars(str2, nullptr) : nullptr; 454 const char *utf82 = str2 ? env->GetStringUTFChars(str2, nullptr) : nullptr;
429 void *params[8] = { (void *)obj2, (void *)utf81, (void *)utf82, 455 void *params[10] = { (void *)obj2, (void *)utf81, (void *)utf82,
430 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), 456 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb),
431 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr }; 457 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr,
432 458 DW_INT_TO_POINTER(message), nullptr };
433 return _dw_event_handler(obj1, params, message); 459
460 return _dw_event_handler(obj1, params);
434 } 461 }
435 462
436 /* A more simple method for quicker calls */ 463 /* A more simple method for quicker calls */
437 JNIEXPORT void JNICALL 464 JNIEXPORT void JNICALL
438 Java_org_dbsoft_dwindows_DWindows_eventHandlerSimple(JNIEnv* env, jobject obj, jobject obj1, jint message) { 465 Java_org_dbsoft_dwindows_DWindows_eventHandlerSimple(JNIEnv* env, jobject obj, jobject obj1, jint message) {
439 void *params[8] = { nullptr }; 466 void *params[10] = { nullptr };
440 467
441 _dw_event_handler(obj1, params, message); 468 params[8] = DW_INT_TO_POINTER(message);
469 _dw_event_handler(obj1, params);
442 } 470 }
443 471
444 /* Handler for notebook page changes */ 472 /* Handler for notebook page changes */
445 JNIEXPORT void JNICALL 473 JNIEXPORT void JNICALL
446 Java_org_dbsoft_dwindows_DWindows_eventHandlerNotebook(JNIEnv* env, jobject obj, jobject obj1, jint message, jlong pageID) { 474 Java_org_dbsoft_dwindows_DWindows_eventHandlerNotebook(JNIEnv* env, jobject obj, jobject obj1, jint message, jlong pageID) {
447 void *params[8] = { nullptr }; 475 void *params[10] = { nullptr };
448 476
449 params[3] = DW_INT_TO_POINTER(pageID); 477 params[8] = DW_INT_TO_POINTER(message);
450 _dw_event_handler(obj1, params, message); 478 _dw_event_handler(obj1, params);
451 } 479 }
452 480
453 /* Handlers for HTML events */ 481 /* Handlers for HTML events */
454 JNIEXPORT void JNICALL 482 JNIEXPORT void JNICALL
455 Java_org_dbsoft_dwindows_DWindows_eventHandlerHTMLResult(JNIEnv* env, jobject obj, jobject obj1, 483 Java_org_dbsoft_dwindows_DWindows_eventHandlerHTMLResult(JNIEnv* env, jobject obj, jobject obj1,
456 jint message, jstring htmlResult, jlong data) { 484 jint message, jstring htmlResult, jlong data) {
457 const char *result = env->GetStringUTFChars(htmlResult, nullptr); 485 const char *result = env->GetStringUTFChars(htmlResult, nullptr);
458 void *params[8] = { nullptr, DW_POINTER(result), nullptr, nullptr, nullptr, nullptr, nullptr, DW_INT_TO_POINTER(data) }; 486 void *params[10] = { nullptr, DW_POINTER(result), nullptr, nullptr, nullptr, nullptr, nullptr,
459 487 DW_INT_TO_POINTER(data), DW_INT_TO_POINTER(message), nullptr };
460 _dw_event_handler(obj1, params, message); 488
489 _dw_event_handler(obj1, params);
461 } 490 }
462 491
463 JNIEXPORT void JNICALL 492 JNIEXPORT void JNICALL
464 Java_org_dbsoft_dwindows_DWWebViewClient_eventHandlerHTMLChanged(JNIEnv* env, jobject obj, jobject obj1, 493 Java_org_dbsoft_dwindows_DWWebViewClient_eventHandlerHTMLChanged(JNIEnv* env, jobject obj, jobject obj1,
465 jint message, jstring URI, jint status) { 494 jint message, jstring URI, jint status) {
466 const char *uri = env->GetStringUTFChars(URI, nullptr); 495 const char *uri = env->GetStringUTFChars(URI, nullptr);
467 void *params[8] = { nullptr, DW_POINTER(uri), nullptr, DW_INT_TO_POINTER(status), nullptr, nullptr, nullptr, nullptr }; 496 void *params[10] = { nullptr, DW_POINTER(uri), nullptr, DW_INT_TO_POINTER(status), nullptr, nullptr,
468 497 nullptr, nullptr, DW_INT_TO_POINTER(message), nullptr };
469 _dw_event_handler(obj1, params, message); 498
499 _dw_event_handler(obj1, params);
470 } 500 }
471 501
472 JNIEXPORT void JNICALL 502 JNIEXPORT void JNICALL
473 Java_org_dbsoft_dwindows_DWindows_eventHandlerInt(JNIEnv* env, jobject obj, jobject obj1, jint message, 503 Java_org_dbsoft_dwindows_DWindows_eventHandlerInt(JNIEnv* env, jobject obj, jobject obj1, jint message,
474 jint inta, jint intb, jint intc, jint intd) { 504 jint inta, jint intb, jint intc, jint intd) {
475 void *params[8] = { nullptr, nullptr, nullptr, 505 void *params[10] = { nullptr, nullptr, nullptr,
476 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), 506 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb),
477 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr }; 507 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr,
478 508 DW_INT_TO_POINTER(message), nullptr };
479 _dw_event_handler(obj1, params, message); 509
510 _dw_event_handler(obj1, params);
480 } 511 }
481 512
482 JNIEXPORT void JNICALL 513 JNIEXPORT void JNICALL
483 Java_org_dbsoft_dwindows_DWComboBox_eventHandlerInt(JNIEnv* env, jobject obj, jint message, 514 Java_org_dbsoft_dwindows_DWComboBox_eventHandlerInt(JNIEnv* env, jobject obj, jint message,
484 jint inta, jint intb, jint intc, jint intd) { 515 jint inta, jint intb, jint intc, jint intd) {
485 void *params[8] = { nullptr, nullptr, nullptr, 516 void *params[10] = { nullptr, nullptr, nullptr,
486 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), 517 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb),
487 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr }; 518 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr,
488 519 DW_INT_TO_POINTER(message), nullptr };
489 _dw_event_handler(obj, params, message); 520
521 _dw_event_handler(obj, params);
490 } 522 }
491 523
492 JNIEXPORT void JNICALL 524 JNIEXPORT void JNICALL
493 Java_org_dbsoft_dwindows_DWSpinButton_eventHandlerInt(JNIEnv* env, jobject obj, jint message, 525 Java_org_dbsoft_dwindows_DWSpinButton_eventHandlerInt(JNIEnv* env, jobject obj, jint message,
494 jint inta, jint intb, jint intc, jint intd) { 526 jint inta, jint intb, jint intc, jint intd) {
495 void *params[8] = { nullptr, nullptr, nullptr, 527 void *params[10] = { nullptr, nullptr, nullptr,
496 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), 528 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb),
497 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr }; 529 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr,
498 530 DW_INT_TO_POINTER(message), nullptr };
499 _dw_event_handler(obj, params, message); 531
532 _dw_event_handler(obj, params);
500 } 533 }
501 534
502 JNIEXPORT void JNICALL 535 JNIEXPORT void JNICALL
503 Java_org_dbsoft_dwindows_DWListBox_eventHandlerInt(JNIEnv* env, jobject obj, jint message, 536 Java_org_dbsoft_dwindows_DWListBox_eventHandlerInt(JNIEnv* env, jobject obj, jint message,
504 jint inta, jint intb, jint intc, jint intd) { 537 jint inta, jint intb, jint intc, jint intd) {
505 void *params[8] = { nullptr, nullptr, nullptr, 538 void *params[10] = { nullptr, nullptr, nullptr,
506 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), 539 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb),
507 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr }; 540 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr,
508 541 DW_INT_TO_POINTER(message), nullptr };
509 _dw_event_handler(obj, params, message); 542
543 _dw_event_handler(obj, params);
510 } 544 }
511 545
512 JNIEXPORT void JNICALL 546 JNIEXPORT void JNICALL
513 Java_org_dbsoft_dwindows_DWRender_eventHandlerInt(JNIEnv* env, jobject obj, jint message, 547 Java_org_dbsoft_dwindows_DWRender_eventHandlerInt(JNIEnv* env, jobject obj, jint message,
514 jint inta, jint intb, jint intc, jint intd) { 548 jint inta, jint intb, jint intc, jint intd) {
515 void *params[8] = { nullptr, nullptr, nullptr, 549 void *params[10] = { nullptr, nullptr, nullptr,
516 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), 550 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb),
517 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr }; 551 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr,
518 552 DW_INT_TO_POINTER(message), nullptr };
519 _dw_event_handler(obj, params, message); 553
554 _dw_event_handler(obj, params);
520 } 555 }
521 556
522 JNIEXPORT void JNICALL 557 JNIEXPORT void JNICALL
523 Java_org_dbsoft_dwindows_DWindows_eventHandlerContainer(JNIEnv* env, jobject obj, jobject obj1, 558 Java_org_dbsoft_dwindows_DWindows_eventHandlerContainer(JNIEnv* env, jobject obj, jobject obj1,
524 jint message, jstring jtitle, jint x, jint y, jlong data) { 559 jint message, jstring jtitle, jint x, jint y, jlong data) {
525 const char *title = jtitle ? env->GetStringUTFChars(jtitle, nullptr) : nullptr; 560 const char *title = jtitle ? env->GetStringUTFChars(jtitle, nullptr) : nullptr;
526 void *params[8] = { nullptr, (void *)title, nullptr, 561 void *params[10] = { nullptr, (void *)title, nullptr,
527 DW_INT_TO_POINTER(x), DW_INT_TO_POINTER(y), 562 DW_INT_TO_POINTER(x), DW_INT_TO_POINTER(y),
528 nullptr, nullptr, (void *)data }; 563 nullptr, nullptr, (void *)data, DW_INT_TO_POINTER(message), nullptr };
529 564
530 _dw_event_handler(obj1, params, message); 565 _dw_event_handler(obj1, params);
531 } 566 }
532 567
533 /* Handler for Timer events */ 568 /* Handler for Timer events */
534 JNIEXPORT jint JNICALL 569 JNIEXPORT jint JNICALL
535 Java_org_dbsoft_dwindows_DWindows_eventHandlerTimer(JNIEnv* env, jobject obj, jlong sigfunc, jlong data) { 570 Java_org_dbsoft_dwindows_DWindows_eventHandlerTimer(JNIEnv* env, jobject obj, jlong sigfunc, jlong data) {
540 } 575 }
541 576
542 /* A more simple method for quicker calls */ 577 /* A more simple method for quicker calls */
543 JNIEXPORT void JNICALL 578 JNIEXPORT void JNICALL
544 Java_org_dbsoft_dwindows_DWMenu_eventHandlerSimple(JNIEnv* env, jobject obj, jobject obj1, jint message) { 579 Java_org_dbsoft_dwindows_DWMenu_eventHandlerSimple(JNIEnv* env, jobject obj, jobject obj1, jint message) {
545 void *params[8] = { nullptr }; 580 void *params[10] = { nullptr };
546 581
547 _dw_event_handler(obj1, params, message); 582 params[8] = DW_INT_TO_POINTER(message);
583 _dw_event_handler(obj1, params);
548 } 584 }
549 585
550 586
551 /* This function adds a signal handler callback into the linked list. 587 /* This function adds a signal handler callback into the linked list.
552 */ 588 */