comparison android/dw.cpp @ 2556:d2d8c66ad062

Android: Initial container implementation... getting a NullPointerException crash in dwtest... But I wanted to get this code committed while I work on it more.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 16 May 2021 22:41:50 +0000
parents 127779860ac1
children 756331246f94
comparison
equal deleted inserted replaced
2555:d7d163d70763 2556:d2d8c66ad062
80 80
81 81
82 /* Call the dwmain entry point, Android has no args, so just pass the app path */ 82 /* Call the dwmain entry point, Android has no args, so just pass the app path */
83 void _dw_main_launch(char *arg) 83 void _dw_main_launch(char *arg)
84 { 84 {
85 static HEV startup = 0; 85 static HEV startup = nullptr;
86 86
87 /* Safety check to prevent multiple initializations... */ 87 /* Safety check to prevent multiple initializations... */
88 if(startup) 88 if(startup)
89 { 89 {
90 /* If we are called a second time.. post the event... 90 /* If we are called a second time.. post the event...
317 case 14: 317 case 14:
318 { 318 {
319 int (* API valuechangedfunc)(HWND, int, void *) = (int (* API)(HWND, int, void *))handler->signalfunction; 319 int (* API valuechangedfunc)(HWND, int, void *) = (int (* API)(HWND, int, void *))handler->signalfunction;
320 int selected = DW_POINTER_TO_INT(params[3]); 320 int selected = DW_POINTER_TO_INT(params[3]);
321 321
322 return valuechangedfunc(handler->window, selected, handler->data);; 322 return valuechangedfunc(handler->window, selected, handler->data);
323 } 323 }
324 /* Tree class selection event */ 324 /* Tree class selection event */
325 case 12: 325 case 12:
326 { 326 {
327 int (* API treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = (int (* API)(HWND, HTREEITEM, char *, void *, void *))handler->signalfunction; 327 int (* API treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = (int (* API)(HWND, HTREEITEM, char *, void *, void *))handler->signalfunction;
417 /* Handlers for HTML events */ 417 /* Handlers for HTML events */
418 JNIEXPORT void JNICALL 418 JNIEXPORT void JNICALL
419 Java_org_dbsoft_dwindows_DWindows_eventHandlerHTMLResult(JNIEnv* env, jobject obj, jobject obj1, 419 Java_org_dbsoft_dwindows_DWindows_eventHandlerHTMLResult(JNIEnv* env, jobject obj, jobject obj1,
420 jint message, jstring htmlResult, jlong data) { 420 jint message, jstring htmlResult, jlong data) {
421 const char *result = env->GetStringUTFChars(htmlResult, nullptr); 421 const char *result = env->GetStringUTFChars(htmlResult, nullptr);
422 void *params[8] = { nullptr, DW_POINTER(result), nullptr, 0, 0, 0, 0, DW_INT_TO_POINTER(data) }; 422 void *params[8] = { nullptr, DW_POINTER(result), nullptr, nullptr, nullptr, nullptr, nullptr, DW_INT_TO_POINTER(data) };
423 423
424 _dw_event_handler(obj1, params, message); 424 _dw_event_handler(obj1, params, message);
425 } 425 }
426 426
427 JNIEXPORT void JNICALL 427 JNIEXPORT void JNICALL
428 Java_org_dbsoft_dwindows_DWWebViewClient_eventHandlerHTMLChanged(JNIEnv* env, jobject obj, jobject obj1, 428 Java_org_dbsoft_dwindows_DWWebViewClient_eventHandlerHTMLChanged(JNIEnv* env, jobject obj, jobject obj1,
429 jint message, jstring URI, jint status) { 429 jint message, jstring URI, jint status) {
430 const char *uri = env->GetStringUTFChars(URI, nullptr); 430 const char *uri = env->GetStringUTFChars(URI, nullptr);
431 void *params[8] = { nullptr, DW_POINTER(uri), nullptr, DW_INT_TO_POINTER(status), 0, 0, 0, 0 }; 431 void *params[8] = { nullptr, DW_POINTER(uri), nullptr, DW_INT_TO_POINTER(status), nullptr, nullptr, nullptr, nullptr };
432 432
433 _dw_event_handler(obj1, params, message); 433 _dw_event_handler(obj1, params, message);
434 } 434 }
435 435
436 JNIEXPORT void JNICALL 436 JNIEXPORT void JNICALL
866 jmethodID fileBrowse = env->GetMethodID(clazz, "fileBrowse", 866 jmethodID fileBrowse = env->GetMethodID(clazz, "fileBrowse",
867 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;"); 867 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;");
868 // Call the method on the object 868 // Call the method on the object
869 jstring jresult = (jstring)env->CallObjectMethod(_dw_obj, fileBrowse, jstr, path, jext, flags); 869 jstring jresult = (jstring)env->CallObjectMethod(_dw_obj, fileBrowse, jstr, path, jext, flags);
870 if(jresult) 870 if(jresult)
871 return strdup(env->GetStringUTFChars(jresult, 0)); 871 return strdup(env->GetStringUTFChars(jresult, nullptr));
872 } 872 }
873 return nullptr; 873 return nullptr;
874 } 874 }
875 875
876 /* 876 /*
896 "()Ljava/lang/String;"); 896 "()Ljava/lang/String;");
897 // Call the method on the object 897 // Call the method on the object
898 jstring result = (jstring)env->CallObjectMethod(_dw_obj, clipboardGetText); 898 jstring result = (jstring)env->CallObjectMethod(_dw_obj, clipboardGetText);
899 // Get the UTF8 string result 899 // Get the UTF8 string result
900 if(result) 900 if(result)
901 utf8 = env->GetStringUTFChars(result, 0); 901 utf8 = env->GetStringUTFChars(result, nullptr);
902 return utf8 ? strdup(utf8) : nullptr; 902 return utf8 ? strdup(utf8) : nullptr;
903 } 903 }
904 return nullptr; 904 return nullptr;
905 } 905 }
906 906
1937 // Call the method on the object 1937 // Call the method on the object
1938 jstring result = (jstring)env->CallObjectMethod(_dw_obj, listOrComboBoxGetText, handle, index); 1938 jstring result = (jstring)env->CallObjectMethod(_dw_obj, listOrComboBoxGetText, handle, index);
1939 // Get the UTF8 string result 1939 // Get the UTF8 string result
1940 if(result) 1940 if(result)
1941 { 1941 {
1942 const char *utf8 = env->GetStringUTFChars(result, 0); 1942 const char *utf8 = env->GetStringUTFChars(result, nullptr);
1943 1943
1944 strncpy(buffer, utf8, length); 1944 strncpy(buffer, utf8, length);
1945 } 1945 }
1946 } 1946 }
1947 } 1947 }
2541 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 2541 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2542 // Get the method that you want to call 2542 // Get the method that you want to call
2543 jmethodID drawPoint = env->GetMethodID(clazz, "drawPoint", 2543 jmethodID drawPoint = env->GetMethodID(clazz, "drawPoint",
2544 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;II)V"); 2544 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;II)V");
2545 // Call the method on the object 2545 // Call the method on the object
2546 env->CallVoidMethod(_dw_obj, drawPoint, handle, pixmap ? pixmap->bitmap : NULL, x, y); 2546 env->CallVoidMethod(_dw_obj, drawPoint, handle, pixmap ? pixmap->bitmap : nullptr, x, y);
2547 } 2547 }
2548 } 2548 }
2549 2549
2550 /* Draw a line on a window (preferably a render window). 2550 /* Draw a line on a window (preferably a render window).
2551 * Parameters: 2551 * Parameters:
2566 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 2566 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2567 // Get the method that you want to call 2567 // Get the method that you want to call
2568 jmethodID drawLine = env->GetMethodID(clazz, "drawLine", 2568 jmethodID drawLine = env->GetMethodID(clazz, "drawLine",
2569 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)V"); 2569 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)V");
2570 // Call the method on the object 2570 // Call the method on the object
2571 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : NULL, x1, y1, x2, y2); 2571 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x1, y1, x2, y2);
2572 } 2572 }
2573 } 2573 }
2574 2574
2575 /* Draw text on a window (preferably a render window). 2575 /* Draw text on a window (preferably a render window).
2576 * Parameters: 2576 * Parameters:
2658 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 2658 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2659 // Get the method that you want to call 2659 // Get the method that you want to call
2660 jmethodID drawPolygon = env->GetMethodID(clazz, "drawPolygon", 2660 jmethodID drawPolygon = env->GetMethodID(clazz, "drawPolygon",
2661 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;II[I[I)V"); 2661 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;II[I[I)V");
2662 // Call the method on the object 2662 // Call the method on the object
2663 env->CallVoidMethod(_dw_obj, drawPolygon, handle, pixmap ? pixmap->bitmap : NULL, flags, npoints, jx, jy); 2663 env->CallVoidMethod(_dw_obj, drawPolygon, handle, pixmap ? pixmap->bitmap : nullptr, flags, npoints, jx, jy);
2664 } 2664 }
2665 } 2665 }
2666 } 2666 }
2667 2667
2668 /* Draw a rectangle on a window (preferably a render window). 2668 /* Draw a rectangle on a window (preferably a render window).
2685 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 2685 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2686 // Get the method that you want to call 2686 // Get the method that you want to call
2687 jmethodID drawLine = env->GetMethodID(clazz, "drawRect", 2687 jmethodID drawLine = env->GetMethodID(clazz, "drawRect",
2688 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)V"); 2688 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)V");
2689 // Call the method on the object 2689 // Call the method on the object
2690 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : NULL, x, y, width, height); 2690 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x, y, width, height);
2691 } 2691 }
2692 } 2692 }
2693 2693
2694 /* Draw an arc on a window (preferably a render window). 2694 /* Draw an arc on a window (preferably a render window).
2695 * Parameters: 2695 * Parameters:
2714 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 2714 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2715 // Get the method that you want to call 2715 // Get the method that you want to call
2716 jmethodID drawLine = env->GetMethodID(clazz, "drawArc", 2716 jmethodID drawLine = env->GetMethodID(clazz, "drawArc",
2717 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIIII)V"); 2717 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIIII)V");
2718 // Call the method on the object 2718 // Call the method on the object
2719 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : NULL, flags, xorigin, yorigin, x1, y1, x2, y2); 2719 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, flags, xorigin, yorigin, x1, y1, x2, y2);
2720 } 2720 }
2721 } 2721 }
2722 2722
2723 /* 2723 /*
2724 * Create a tree object to be packed. 2724 * Create a tree object to be packed.
2745 * Returns: 2745 * Returns:
2746 * A handle to a tree item or nullptr on failure. 2746 * A handle to a tree item or nullptr on failure.
2747 */ 2747 */
2748 HTREEITEM API dw_tree_insert_after(HWND handle, HTREEITEM item, const char *title, HICN icon, HTREEITEM parent, void *itemdata) 2748 HTREEITEM API dw_tree_insert_after(HWND handle, HTREEITEM item, const char *title, HICN icon, HTREEITEM parent, void *itemdata)
2749 { 2749 {
2750 return 0; 2750 return nullptr;
2751 } 2751 }
2752 2752
2753 /* 2753 /*
2754 * Inserts an item into a tree window (widget). 2754 * Inserts an item into a tree window (widget).
2755 * Parameters: 2755 * Parameters:
2885 * Returns: 2885 * Returns:
2886 * A handle to a container window or nullptr on failure. 2886 * A handle to a container window or nullptr on failure.
2887 */ 2887 */
2888 HWND API dw_container_new(ULONG cid, int multi) 2888 HWND API dw_container_new(ULONG cid, int multi)
2889 { 2889 {
2890 JNIEnv *env;
2891
2892 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2893 {
2894 // First get the class that contains the method you need to call
2895 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2896 // Get the method that you want to call
2897 jmethodID containerNew = env->GetMethodID(clazz, "containerNew",
2898 "(II)Landroid/widget/ListView;");
2899 // Call the method on the object
2900 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, containerNew, (int)cid, multi));
2901 return result;
2902 }
2890 return nullptr; 2903 return nullptr;
2891 } 2904 }
2892 2905
2893 /* 2906 /*
2894 * Sets up the container columns. 2907 * Sets up the container columns.
2902 * Returns: 2915 * Returns:
2903 * DW_ERROR_NONE (0) on success. 2916 * DW_ERROR_NONE (0) on success.
2904 */ 2917 */
2905 int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator) 2918 int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator)
2906 { 2919 {
2920 if(handle && flags && titles && count > 0)
2921 {
2922 int z;
2923
2924 for(z=0;z<count;z++)
2925 {
2926 JNIEnv *env;
2927
2928 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2929 {
2930 // Generate a string
2931 jstring jstr = env->NewStringUTF(titles[z]);
2932 // First get the class that contains the method you need to call
2933 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2934 // Get the method that you want to call
2935 jmethodID containerNew = env->GetMethodID(clazz, "containerAddColumn",
2936 "(Landroid/widget/ListView;Ljava/lang/String;I)V");
2937 // Call the method on the object
2938 env->CallVoidMethod(_dw_obj, containerNew, handle, jstr, (int)flags[z]);
2939 }
2940 }
2941 }
2907 return DW_ERROR_GENERAL; 2942 return DW_ERROR_GENERAL;
2908 } 2943 }
2909 2944
2910 /* 2945 /*
2911 * Configures the main filesystem column title for localization. 2946 * Configures the main filesystem column title for localization.
2927 * Returns: 2962 * Returns:
2928 * DW_ERROR_NONE (0) on success. 2963 * DW_ERROR_NONE (0) on success.
2929 */ 2964 */
2930 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count) 2965 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count)
2931 { 2966 {
2967 unsigned long fsflags[2] = { DW_CFA_BITMAPORICON, DW_CFA_STRING };
2968 char *fstitles[2] = { "Icon", "Filename" };
2969 dw_container_setup(handle, fsflags, fstitles, 2, 0);
2970 dw_container_setup(handle, flags, titles, count, 0);
2932 return DW_ERROR_GENERAL; 2971 return DW_ERROR_GENERAL;
2933 } 2972 }
2934 2973
2935 /* 2974 /*
2936 * Allocates memory used to populate a container. 2975 * Allocates memory used to populate a container.
2940 * Returns: 2979 * Returns:
2941 * Handle to container items allocated or nullptr on error. 2980 * Handle to container items allocated or nullptr on error.
2942 */ 2981 */
2943 void * API dw_container_alloc(HWND handle, int rowcount) 2982 void * API dw_container_alloc(HWND handle, int rowcount)
2944 { 2983 {
2984 JNIEnv *env;
2985
2986 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2987 {
2988 // First get the class that contains the method you need to call
2989 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2990 // Get the method that you want to call
2991 jmethodID containerAlloc = env->GetMethodID(clazz, "containerAlloc",
2992 "(Landroid/widget/ListView;I)Landroid/widget/ListView;");
2993 // Call the method on the object
2994 return (void *)env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, containerAlloc, handle, rowcount));
2995 }
2945 return nullptr; 2996 return nullptr;
2946 } 2997 }
2947 2998
2948 /* 2999 /*
2949 * Sets an item in specified row and column to the given data. 3000 * Sets an item in specified row and column to the given data.
2954 * row: Zero based row of data being set. 3005 * row: Zero based row of data being set.
2955 * data: Pointer to the data to be added. 3006 * data: Pointer to the data to be added.
2956 */ 3007 */
2957 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) 3008 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data)
2958 { 3009 {
3010 int rowstart = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_rowstart"));
3011
3012 dw_container_change_item(handle, column, row + rowstart, data);
2959 } 3013 }
2960 3014
2961 /* 3015 /*
2962 * Changes an existing item in specified row and column to the given data. 3016 * Changes an existing item in specified row and column to the given data.
2963 * Parameters: 3017 * Parameters:
2966 * row: Zero based row of data being set. 3020 * row: Zero based row of data being set.
2967 * data: Pointer to the data to be added. 3021 * data: Pointer to the data to be added.
2968 */ 3022 */
2969 void API dw_container_change_item(HWND handle, int column, int row, void *data) 3023 void API dw_container_change_item(HWND handle, int column, int row, void *data)
2970 { 3024 {
3025 JNIEnv *env;
3026
3027 if(handle && data && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3028 {
3029 int columntype = dw_container_get_column_type(handle, column);
3030
3031 if((columntype & DW_CFA_BITMAPORICON))
3032 {
3033 jobject icon = *((jobject *)data);
3034
3035 if(icon)
3036 {
3037 // First get the class that contains the method you need to call
3038 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3039 // Get the method that you want to call
3040 jmethodID containerChangeItem = env->GetMethodID(clazz, "containerChangeItemIcon",
3041 "(Landroid/widget/ListView;IILandroid/graphics/drawable/Drawable;)V");
3042 // Call the method on the object
3043 env->CallVoidMethod(_dw_obj, containerChangeItem, handle, column, row, icon);
3044 }
3045 }
3046 else if((columntype & DW_CFA_STRING))
3047 {
3048 const char *tmp = *((const char **)data);
3049
3050 if(tmp)
3051 {
3052 jstring jstr = env->NewStringUTF(tmp);
3053 // First get the class that contains the method you need to call
3054 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3055 // Get the method that you want to call
3056 jmethodID containerChangeItem = env->GetMethodID(clazz, "containerChangeItemString",
3057 "(Landroid/widget/ListView;IILjava/lang/String;)V");
3058 // Call the method on the object
3059 env->CallVoidMethod(_dw_obj, containerChangeItem, handle, column, row, jstr);
3060 }
3061 }
3062 else if((columntype & DW_CFA_ULONG))
3063 {
3064 ULONG num = *((ULONG *)data);
3065 // First get the class that contains the method you need to call
3066 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3067 // Get the method that you want to call
3068 jmethodID containerChangeItem = env->GetMethodID(clazz, "containerChangeItemInt",
3069 "(Landroid/widget/ListView;III)V");
3070 // Call the method on the object
3071 env->CallVoidMethod(_dw_obj, containerChangeItem, handle, column, row, (int)num);
3072 }
3073 // TODO: Handle DATE and TIME
3074 }
2971 } 3075 }
2972 3076
2973 /* 3077 /*
2974 * Changes an existing item in specified row and column to the given data. 3078 * Changes an existing item in specified row and column to the given data.
2975 * Parameters: 3079 * Parameters:
2978 * row: Zero based row of data being set. 3082 * row: Zero based row of data being set.
2979 * data: Pointer to the data to be added. 3083 * data: Pointer to the data to be added.
2980 */ 3084 */
2981 void API dw_filesystem_change_item(HWND handle, int column, int row, void *data) 3085 void API dw_filesystem_change_item(HWND handle, int column, int row, void *data)
2982 { 3086 {
3087 dw_container_change_item(handle, column + 2, row, data);
2983 } 3088 }
2984 3089
2985 /* 3090 /*
2986 * Changes an item in specified row and column to the given data. 3091 * Changes an item in specified row and column to the given data.
2987 * Parameters: 3092 * Parameters:
2991 * row: Zero based row of data being set. 3096 * row: Zero based row of data being set.
2992 * data: Pointer to the data to be added. 3097 * data: Pointer to the data to be added.
2993 */ 3098 */
2994 void API dw_filesystem_change_file(HWND handle, int row, const char *filename, HICN icon) 3099 void API dw_filesystem_change_file(HWND handle, int row, const char *filename, HICN icon)
2995 { 3100 {
3101 dw_container_change_item(handle, 0, row, (void *)&icon);
3102 dw_container_change_item(handle, 1, row, (void *)&filename);
2996 } 3103 }
2997 3104
2998 /* 3105 /*
2999 * Sets an item in specified row and column to the given data. 3106 * Sets an item in specified row and column to the given data.
3000 * Parameters: 3107 * Parameters:
3004 * row: Zero based row of data being set. 3111 * row: Zero based row of data being set.
3005 * data: Pointer to the data to be added. 3112 * data: Pointer to the data to be added.
3006 */ 3113 */
3007 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, const char *filename, HICN icon) 3114 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, const char *filename, HICN icon)
3008 { 3115 {
3116 dw_container_set_item(handle, pointer, 0, row, (void *)&icon);
3117 dw_container_set_item(handle, pointer, 1, row, (void *)&filename);
3009 } 3118 }
3010 3119
3011 /* 3120 /*
3012 * Sets an item in specified row and column to the given data. 3121 * Sets an item in specified row and column to the given data.
3013 * Parameters: 3122 * Parameters:
3017 * row: Zero based row of data being set. 3126 * row: Zero based row of data being set.
3018 * data: Pointer to the data to be added. 3127 * data: Pointer to the data to be added.
3019 */ 3128 */
3020 void API dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data) 3129 void API dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data)
3021 { 3130 {
3131 dw_container_set_item(handle, pointer, column + 2, row, data);
3022 } 3132 }
3023 3133
3024 /* 3134 /*
3025 * Sets the data of a row in the container. 3135 * Sets the data of a row in the container.
3026 * Parameters: 3136 * Parameters:
3051 * Returns: 3161 * Returns:
3052 * Constant identifying the the column type. 3162 * Constant identifying the the column type.
3053 */ 3163 */
3054 int API dw_container_get_column_type(HWND handle, int column) 3164 int API dw_container_get_column_type(HWND handle, int column)
3055 { 3165 {
3166 JNIEnv *env;
3167
3168 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3169 {
3170 // First get the class that contains the method you need to call
3171 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3172 // Get the method that you want to call
3173 jmethodID containerGetColumnType = env->GetMethodID(clazz, "containerGetColumnType",
3174 "(Landroid/widget/ListView;I)I");
3175 // Call the method on the object
3176 return env->CallIntMethod(_dw_obj, containerGetColumnType, handle, column);
3177 }
3056 return 0; 3178 return 0;
3057 } 3179 }
3058 3180
3059 /* 3181 /*
3060 * Gets column type for a filesystem container column. 3182 * Gets column type for a filesystem container column.
3064 * Returns: 3186 * Returns:
3065 * Constant identifying the the column type. 3187 * Constant identifying the the column type.
3066 */ 3188 */
3067 int API dw_filesystem_get_column_type(HWND handle, int column) 3189 int API dw_filesystem_get_column_type(HWND handle, int column)
3068 { 3190 {
3069 return 0; 3191 return dw_container_get_column_type(handle, column + 2);
3070 } 3192 }
3071 3193
3072 /* 3194 /*
3073 * Sets the alternating row colors for container window (widget) handle. 3195 * Sets the alternating row colors for container window (widget) handle.
3074 * Parameters: 3196 * Parameters:
3123 * pointer: Pointer to the allocated memory in dw_container_alloc(). 3245 * pointer: Pointer to the allocated memory in dw_container_alloc().
3124 * rowcount: The number of rows to be inserted. 3246 * rowcount: The number of rows to be inserted.
3125 */ 3247 */
3126 void API dw_container_insert(HWND handle, void *pointer, int rowcount) 3248 void API dw_container_insert(HWND handle, void *pointer, int rowcount)
3127 { 3249 {
3250 JNIEnv *env;
3251
3252 if(pointer && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3253 env->DeleteWeakGlobalRef((jobject)pointer);
3254 dw_window_set_data(handle, "_dw_rowstart", NULL);
3128 } 3255 }
3129 3256
3130 /* 3257 /*
3131 * Removes all rows from a container. 3258 * Removes all rows from a container.
3132 * Parameters: 3259 * Parameters:
3133 * handle: Handle to the window (widget) to be cleared. 3260 * handle: Handle to the window (widget) to be cleared.
3134 * redraw: TRUE to cause the container to redraw immediately. 3261 * redraw: TRUE to cause the container to redraw immediately.
3135 */ 3262 */
3136 void API dw_container_clear(HWND handle, int redraw) 3263 void API dw_container_clear(HWND handle, int redraw)
3137 { 3264 {
3265 JNIEnv *env;
3266
3267 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3268 {
3269 // First get the class that contains the method you need to call
3270 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3271 // Get the method that you want to call
3272 jmethodID containerClear = env->GetMethodID(clazz, "containerClear",
3273 "(Landroid/widget/ListView;)V");
3274 // Call the method on the object
3275 env->CallVoidMethod(_dw_obj, containerClear, handle);
3276 }
3138 } 3277 }
3139 3278
3140 /* 3279 /*
3141 * Removes the first x rows from a container. 3280 * Removes the first x rows from a container.
3142 * Parameters: 3281 * Parameters:
3302 * Returns: 3441 * Returns:
3303 * Handle to the created icon or nullptr on error. 3442 * Handle to the created icon or nullptr on error.
3304 */ 3443 */
3305 HICN API dw_icon_load(unsigned long module, unsigned long resid) 3444 HICN API dw_icon_load(unsigned long module, unsigned long resid)
3306 { 3445 {
3307 return _dw_icon_load(NULL, NULL, 0, resid); 3446 return _dw_icon_load(nullptr, nullptr, 0, resid);
3308 } 3447 }
3309 3448
3310 /* 3449 /*
3311 * Obtains an icon from a file. 3450 * Obtains an icon from a file.
3312 * Parameters: 3451 * Parameters:
3316 * Returns: 3455 * Returns:
3317 * Handle to the created icon or nullptr on error. 3456 * Handle to the created icon or nullptr on error.
3318 */ 3457 */
3319 HICN API dw_icon_load_from_file(const char *filename) 3458 HICN API dw_icon_load_from_file(const char *filename)
3320 { 3459 {
3321 return _dw_icon_load(filename, NULL, 0, 0); 3460 return _dw_icon_load(filename, nullptr, 0, 0);
3322 } 3461 }
3323 3462
3324 /* 3463 /*
3325 * Obtains an icon from data. 3464 * Obtains an icon from data.
3326 * Parameters: 3465 * Parameters:
3329 * Returns: 3468 * Returns:
3330 * Handle to the created icon or nullptr on error. 3469 * Handle to the created icon or nullptr on error.
3331 */ 3470 */
3332 HICN API dw_icon_load_from_data(const char *data, int len) 3471 HICN API dw_icon_load_from_data(const char *data, int len)
3333 { 3472 {
3334 return _dw_icon_load(NULL, data, len, 0); 3473 return _dw_icon_load(nullptr, data, len, 0);
3335 } 3474 }
3336 3475
3337 /* 3476 /*
3338 * Frees a loaded icon resource. 3477 * Frees a loaded icon resource.
3339 * Parameters: 3478 * Parameters:
3718 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 3857 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3719 // Get the method that you want to call 3858 // Get the method that you want to call
3720 jmethodID pixmapBitBlt = env->GetMethodID(clazz, "pixmapBitBlt", 3859 jmethodID pixmapBitBlt = env->GetMethodID(clazz, "pixmapBitBlt",
3721 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIILorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)I"); 3860 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIILorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)I");
3722 // Call the method on the object 3861 // Call the method on the object
3723 retval = env->CallIntMethod(_dw_obj, pixmapBitBlt, dest, destp ? destp->bitmap : NULL, xdest, ydest, width, height, src, srcp ? srcp->bitmap : NULL, xsrc, ysrc, srcwidth, srcheight); 3862 retval = env->CallIntMethod(_dw_obj, pixmapBitBlt, dest, destp ? destp->bitmap : nullptr, xdest, ydest, width, height, src, srcp ? srcp->bitmap : nullptr, xsrc, ysrc, srcwidth, srcheight);
3724 } 3863 }
3725 return retval; 3864 return retval;
3726 } 3865 }
3727 3866
3728 /* 3867 /*
4654 "(Landroid/view/View;)Ljava/lang/String;"); 4793 "(Landroid/view/View;)Ljava/lang/String;");
4655 // Call the method on the object 4794 // Call the method on the object
4656 jstring result = (jstring)env->CallObjectMethod(_dw_obj, windowGetText, handle); 4795 jstring result = (jstring)env->CallObjectMethod(_dw_obj, windowGetText, handle);
4657 // Get the UTF8 string result 4796 // Get the UTF8 string result
4658 if(result) 4797 if(result)
4659 utf8 = env->GetStringUTFChars(result, 0); 4798 utf8 = env->GetStringUTFChars(result, nullptr);
4660 return utf8 ? strdup(utf8) : nullptr; 4799 return utf8 ? strdup(utf8) : nullptr;
4661 } 4800 }
4662 return nullptr; 4801 return nullptr;
4663 } 4802 }
4664 4803
5014 { 5153 {
5015 static char osName[_DW_ENV_STRING_SIZE+1] = { 0 }; 5154 static char osName[_DW_ENV_STRING_SIZE+1] = { 0 };
5016 5155
5017 if(!osName[0]) 5156 if(!osName[0])
5018 { 5157 {
5019 JNIEnv *env; 5158 JNIEnv *jenv;
5020 const char *release = nullptr; 5159 const char *release = nullptr;
5021 5160
5022 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 5161 if((jenv = (JNIEnv *)pthread_getspecific(_dw_env_key)))
5023 { 5162 {
5024 // First get the class that contains the method you need to call 5163 // First get the class that contains the method you need to call
5025 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 5164 jclass clazz = _dw_find_class(jenv, DW_CLASS_NAME);
5026 // Get the method that you want to call 5165 // Get the method that you want to call
5027 jmethodID androidGetRelease = env->GetMethodID(clazz, "androidGetRelease", 5166 jmethodID androidGetRelease = jenv->GetMethodID(clazz, "androidGetRelease",
5028 "()Ljava/lang/String;"); 5167 "()Ljava/lang/String;");
5029 // Call the method on the object 5168 // Call the method on the object
5030 jstring jstr = (jstring)env->CallObjectMethod(_dw_obj, androidGetRelease); 5169 jstring jstr = (jstring)jenv->CallObjectMethod(_dw_obj, androidGetRelease);
5031 5170
5032 if(jstr) 5171 if(jstr)
5033 release = env->GetStringUTFChars(jstr, 0); 5172 release = jenv->GetStringUTFChars(jstr, nullptr);
5034 } 5173 }
5035 snprintf(osName, _DW_ENV_STRING_SIZE-1, "Android%s%s", 5174 snprintf(osName, _DW_ENV_STRING_SIZE-1, "Android%s%s",
5036 release ? " " : "", release ? release : ""); 5175 release ? " " : "", release ? release : "");
5037 } 5176 }
5038 memset(env, '\0', sizeof(DWEnv)); 5177 memset(env, '\0', sizeof(DWEnv));
5631 if(timeout != -1) 5770 if(timeout != -1)
5632 { 5771 {
5633 struct timeval now; 5772 struct timeval now;
5634 struct timespec timeo; 5773 struct timespec timeo;
5635 5774
5636 gettimeofday(&now, 0); 5775 gettimeofday(&now, nullptr);
5637 timeo.tv_sec = now.tv_sec + (timeout / 1000); 5776 timeo.tv_sec = now.tv_sec + (timeout / 1000);
5638 timeo.tv_nsec = now.tv_usec * 1000; 5777 timeo.tv_nsec = now.tv_usec * 1000;
5639 rc = pthread_cond_timedwait(&(eve->event), &(eve->mutex), &timeo); 5778 rc = pthread_cond_timedwait(&(eve->event), &(eve->mutex), &timeo);
5640 } 5779 }
5641 else 5780 else
5723 } 5862 }
5724 5863
5725 if(FD_ISSET(listenfd, &rd)) 5864 if(FD_ISSET(listenfd, &rd))
5726 { 5865 {
5727 struct _dw_seminfo *newarray; 5866 struct _dw_seminfo *newarray;
5728 int newfd = accept(listenfd, 0, 0); 5867 int newfd = accept(listenfd, nullptr, nullptr);
5729 5868
5730 if(newfd > -1) 5869 if(newfd > -1)
5731 { 5870 {
5732 /* Add new connections to the set */ 5871 /* Add new connections to the set */
5733 newarray = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)*(connectcount+1)); 5872 newarray = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)*(connectcount+1));
5831 * name: Name given to semaphore which can be opened 5970 * name: Name given to semaphore which can be opened
5832 * by other processes. 5971 * by other processes.
5833 */ 5972 */
5834 HEV API dw_named_event_new(const char *name) 5973 HEV API dw_named_event_new(const char *name)
5835 { 5974 {
5836 struct sockaddr_un un; 5975 struct sockaddr_un un = {0};
5837 int ev, *tmpsock = (int *)malloc(sizeof(int)*2); 5976 int ev, *tmpsock = (int *)malloc(sizeof(int)*2);
5838 DWTID dwthread; 5977 DWTID dwthread;
5839 5978
5840 if(!tmpsock) 5979 if(!tmpsock)
5841 return nullptr; 5980 return nullptr;
5842 5981
5843 tmpsock[0] = socket(AF_UNIX, SOCK_STREAM, 0); 5982 tmpsock[0] = socket(AF_UNIX, SOCK_STREAM, 0);
5844 ev = socket(AF_UNIX, SOCK_STREAM, 0); 5983 ev = socket(AF_UNIX, SOCK_STREAM, 0);
5845 memset(&un, 0, sizeof(un));
5846 un.sun_family=AF_UNIX; 5984 un.sun_family=AF_UNIX;
5847 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); 5985 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH);
5848 strcpy(un.sun_path, "/tmp/.dw/"); 5986 strcpy(un.sun_path, "/tmp/.dw/");
5849 strcat(un.sun_path, name); 5987 strcat(un.sun_path, name);
5850 5988
5854 remove(un.sun_path); 5992 remove(un.sun_path);
5855 5993
5856 bind(tmpsock[0], (struct sockaddr *)&un, sizeof(un)); 5994 bind(tmpsock[0], (struct sockaddr *)&un, sizeof(un));
5857 listen(tmpsock[0], 0); 5995 listen(tmpsock[0], 0);
5858 connect(ev, (struct sockaddr *)&un, sizeof(un)); 5996 connect(ev, (struct sockaddr *)&un, sizeof(un));
5859 tmpsock[1] = accept(tmpsock[0], 0, 0); 5997 tmpsock[1] = accept(tmpsock[0], nullptr, nullptr);
5860 5998
5861 if(tmpsock[0] < 0 || tmpsock[1] < 0 || ev < 0) 5999 if(tmpsock[0] < 0 || tmpsock[1] < 0 || ev < 0)
5862 { 6000 {
5863 if(tmpsock[0] > -1) 6001 if(tmpsock[0] > -1)
5864 close(tmpsock[0]); 6002 close(tmpsock[0]);
6365 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Landroidx/core/app/NotificationCompat$Builder;"); 6503 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Landroidx/core/app/NotificationCompat$Builder;");
6366 // Call the method on the object 6504 // Call the method on the object
6367 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, notificationNew, ntitle, image, ndesc, appid)); 6505 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, notificationNew, ntitle, image, ndesc, appid));
6368 return result; 6506 return result;
6369 } 6507 }
6370 return 0; 6508 return nullptr;
6371 } 6509 }
6372 6510
6373 /* 6511 /*
6374 * Sends a notification created by dw_notification_new() after attaching signal handler. 6512 * Sends a notification created by dw_notification_new() after attaching signal handler.
6375 * Parameters: 6513 * Parameters: