comparison android/dw.cpp @ 2489:6c01b0132813

Android: Implement window and clipboard text setter and getters.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 30 Apr 2021 02:33:21 +0000
parents 666af45f33b5
children 62e124eecd82
comparison
equal deleted inserted replaced
2488:666af45f33b5 2489:6c01b0132813
412 return DWSignalTranslate[z].message; 412 return DWSignalTranslate[z].message;
413 } 413 }
414 return 0L; 414 return 0L;
415 } 415 }
416 416
417 /* Implement these to get and set the Box* pointer on the widget handle */
418 void *_dw_window_pointer_get(HWND handle)
419 {
420 return NULL;
421 }
422
423 void _dw_window_pointer_set(HWND handle, Box *box)
424 {
425 }
426
427 /* 417 /*
428 * Runs a message loop for Dynamic Windows. 418 * Runs a message loop for Dynamic Windows.
429 */ 419 */
430 void API dw_main(void) 420 void API dw_main(void)
431 { 421 {
653 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not 643 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not
654 * be converted to text. 644 * be converted to text.
655 */ 645 */
656 char * API dw_clipboard_get_text() 646 char * API dw_clipboard_get_text()
657 { 647 {
648 JNIEnv *env;
649
650 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
651 {
652 const char *utf8 = NULL;
653
654 // First get the class that contains the method you need to call
655 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
656 // Get the method that you want to call
657 jmethodID clipboardGetText = env->GetMethodID(clazz, "clipboardGetText",
658 "()Ljava/lang/String;");
659 // Call the method on the object
660 jstring result = (jstring)env->CallObjectMethod(_dw_obj, clipboardGetText);
661 // Get the UTF8 string result
662 if(result)
663 utf8 = env->GetStringUTFChars(result, 0);
664 return utf8 ? strdup(utf8) : NULL;
665 }
658 return NULL; 666 return NULL;
659 } 667 }
660 668
661 /* 669 /*
662 * Sets the contents of the default clipboard to the supplied text. 670 * Sets the contents of the default clipboard to the supplied text.
664 * str: Text to put on the clipboard. 672 * str: Text to put on the clipboard.
665 * len: Length of the text. 673 * len: Length of the text.
666 */ 674 */
667 void API dw_clipboard_set_text(const char *str, int len) 675 void API dw_clipboard_set_text(const char *str, int len)
668 { 676 {
669 } 677 JNIEnv *env;
670 678
679 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
680 {
681 // Construct a String
682 jstring jstr = env->NewStringUTF(str);
683 // First get the class that contains the method you need to call
684 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
685 // Get the method that you want to call
686 jmethodID clipboardSetText = env->GetMethodID(clazz, "clipboardSetText",
687 "(Ljava/lang/String;)V");
688 // Call the method on the object
689 env->CallVoidMethod(_dw_obj, clipboardSetText, jstr);
690 }
691 }
671 692
672 /* 693 /*
673 * Allocates and initializes a dialog struct. 694 * Allocates and initializes a dialog struct.
674 * Parameters: 695 * Parameters:
675 * data: User defined data to be passed to functions. 696 * data: User defined data to be passed to functions.
676 * Returns: 697 * Returns:
677 * A handle to a dialog or NULL on failure. 698 * A handle to a dialog or NULL on failure.
678 */ 699 */
679 DWDialog * API dw_dialog_new(void *data) 700 DWDialog * API dw_dialog_new(void *data)
680 { 701 {
681 #if 0 702 DWDialog *tmp = (DWDialog *)malloc(sizeof(DWDialog));
682 DWDialog *tmp = malloc(sizeof(DWDialog));
683 703
684 if(tmp) 704 if(tmp)
685 { 705 {
686 tmp->eve = dw_event_new(); 706 tmp->eve = dw_event_new();
687 dw_event_reset(tmp->eve); 707 dw_event_reset(tmp->eve);
688 tmp->data = data; 708 tmp->data = data;
689 tmp->done = FALSE; 709 tmp->done = FALSE;
690 tmp->result = NULL; 710 tmp->result = NULL;
691 } 711 }
692 return tmp; 712 return tmp;
693 #endif
694 return NULL;
695 } 713 }
696 714
697 /* 715 /*
698 * Accepts a dialog struct and returns the given data to the 716 * Accepts a dialog struct and returns the given data to the
699 * initial called of dw_dialog_wait(). 717 * initial called of dw_dialog_wait().
703 * Returns: 721 * Returns:
704 * DW_ERROR_NONE (0) on success. 722 * DW_ERROR_NONE (0) on success.
705 */ 723 */
706 int API dw_dialog_dismiss(DWDialog *dialog, void *result) 724 int API dw_dialog_dismiss(DWDialog *dialog, void *result)
707 { 725 {
708 #if 0
709 dialog->result = result; 726 dialog->result = result;
710 dw_event_post(dialog->eve); 727 dw_event_post(dialog->eve);
711 dialog->done = TRUE; 728 dialog->done = TRUE;
712 #endif 729 return DW_ERROR_NONE;
713 return DW_ERROR_GENERAL;
714 } 730 }
715 731
716 /* 732 /*
717 * Accepts a dialog struct waits for dw_dialog_dismiss() to be 733 * Accepts a dialog struct waits for dw_dialog_dismiss() to be
718 * called by a signal handler with the given dialog struct. 734 * called by a signal handler with the given dialog struct.
723 */ 739 */
724 void * API dw_dialog_wait(DWDialog *dialog) 740 void * API dw_dialog_wait(DWDialog *dialog)
725 { 741 {
726 void *tmp = NULL; 742 void *tmp = NULL;
727 743
728 #if 0
729 while(!dialog->done) 744 while(!dialog->done)
730 { 745 {
731 dw_main_iteration(); 746 dw_main_iteration();
732 } 747 }
733 dw_event_close(&dialog->eve); 748 dw_event_close(&dialog->eve);
734 tmp = dialog->result; 749 tmp = dialog->result;
735 free(dialog); 750 free(dialog);
736 #endif
737 return tmp; 751 return tmp;
738 } 752 }
739 753
740 /* 754 /*
741 * Create a new Box to be packed. 755 * Create a new Box to be packed.
3115 * Returns: 3129 * Returns:
3116 * The text associsated with a given window or NULL on error. 3130 * The text associsated with a given window or NULL on error.
3117 */ 3131 */
3118 char * API dw_window_get_text(HWND handle) 3132 char * API dw_window_get_text(HWND handle)
3119 { 3133 {
3134 JNIEnv *env;
3135
3136 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3137 {
3138 const char *utf8 = NULL;
3139
3140 // First get the class that contains the method you need to call
3141 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3142 // Get the method that you want to call
3143 jmethodID windowGetText = env->GetMethodID(clazz, "windowGetText",
3144 "(Landroid/view/View;)Ljava/lang/String;");
3145 // Call the method on the object
3146 jstring result = (jstring)env->CallObjectMethod(_dw_obj, windowGetText, handle);
3147 // Get the UTF8 string result
3148 if(result)
3149 utf8 = env->GetStringUTFChars(result, 0);
3150 return utf8 ? strdup(utf8) : NULL;
3151 }
3120 return NULL; 3152 return NULL;
3121 } 3153 }
3122 3154
3123 /* 3155 /*
3124 * Sets the text used for a given window. 3156 * Sets the text used for a given window.
3126 * handle: Handle to the window. 3158 * handle: Handle to the window.
3127 * text: The text associsated with a given window. 3159 * text: The text associsated with a given window.
3128 */ 3160 */
3129 void API dw_window_set_text(HWND handle, const char *text) 3161 void API dw_window_set_text(HWND handle, const char *text)
3130 { 3162 {
3163 JNIEnv *env;
3164
3165 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3166 {
3167 // Construct a String
3168 jstring jstr = env->NewStringUTF(text);
3169 // First get the class that contains the method you need to call
3170 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3171 // Get the method that you want to call
3172 jmethodID windowSetText = env->GetMethodID(clazz, "windowSetText",
3173 "(Landroid/view/View;Ljava/lang/String;)V");
3174 // Call the method on the object
3175 env->CallVoidMethod(_dw_obj, windowSetText, handle, jstr);
3176 }
3131 } 3177 }
3132 3178
3133 /* 3179 /*
3134 * Sets the text used for a given window's floating bubble help. 3180 * Sets the text used for a given window's floating bubble help.
3135 * Parameters: 3181 * Parameters: