comparison android/dw.cpp @ 2528:03f6870bcfcc

Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 10 May 2021 09:29:51 +0000
parents d3f09b3f3703
children 060fdb2d807d
comparison
equal deleted inserted replaced
2527:eec926265888 2528:03f6870bcfcc
2 * Dynamic Windows: 2 * Dynamic Windows:
3 * A GTK like GUI implementation of the Android GUI. 3 * A GTK like GUI implementation of the Android GUI.
4 * 4 *
5 * (C) 2011-2021 Brian Smith <brian@dbsoft.org> 5 * (C) 2011-2021 Brian Smith <brian@dbsoft.org>
6 * (C) 2011-2021 Mark Hessling <mark@rexx.org> 6 * (C) 2011-2021 Mark Hessling <mark@rexx.org>
7 *
8 * Requires Android API 19 (KitKat) or higher.
7 * 9 *
8 */ 10 */
9 11
10 #include "dw.h" 12 #include "dw.h"
11 #include <stdlib.h> 13 #include <stdlib.h>
771 if(defpath) 773 if(defpath)
772 path = env->NewStringUTF(defpath); 774 path = env->NewStringUTF(defpath);
773 if(ext) 775 if(ext)
774 jext = env->NewStringUTF(defpath); 776 jext = env->NewStringUTF(defpath);
775 // First get the class that contains the method you need to call 777 // First get the class that contains the method you need to call
776 //jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 778 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
777 jclass clazz = env->FindClass(DW_CLASS_NAME);
778 // Get the method that you want to call 779 // Get the method that you want to call
779 jmethodID fileBrowse = env->GetMethodID(clazz, "fileBrowse", 780 jmethodID fileBrowse = env->GetMethodID(clazz, "fileBrowse",
780 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;"); 781 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;");
781 // Call the method on the object 782 // Call the method on the object
782 jstring jresult = (jstring)env->CallObjectMethod(_dw_obj, fileBrowse, jstr, path, jext, flags); 783 jstring jresult = (jstring)env->CallObjectMethod(_dw_obj, fileBrowse, jstr, path, jext, flags);
3121 * Returns: 3122 * Returns:
3122 * Handle to the created bitmap widget or NULL on error. 3123 * Handle to the created bitmap widget or NULL on error.
3123 */ 3124 */
3124 HWND API dw_bitmap_new(ULONG cid) 3125 HWND API dw_bitmap_new(ULONG cid)
3125 { 3126 {
3127 JNIEnv *env;
3128
3129 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3130 {
3131 // First get the class that contains the method you need to call
3132 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3133 // Get the method that you want to call
3134 jmethodID mleNew = env->GetMethodID(clazz, "bitmapNew",
3135 "(I)Landroid/widget/ImageView;");
3136 // Call the method on the object
3137 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, mleNew, (int)cid));
3138 return result;
3139 }
3126 return 0; 3140 return 0;
3127 } 3141 }
3128 3142
3129 /* 3143 /*
3130 * Creates a pixmap with given parameters. 3144 * Creates a pixmap with given parameters.
4146 * NULL if you use the id param) 4160 * NULL if you use the id param)
4147 * len: Length of data passed 4161 * len: Length of data passed
4148 */ 4162 */
4149 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long cid, const char *data, int len) 4163 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long cid, const char *data, int len)
4150 { 4164 {
4165 JNIEnv *env;
4166
4167 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
4168 {
4169 // Construct a byte array
4170 jbyteArray bytearray = NULL;
4171 if(data && len > 0) {
4172 bytearray = env->NewByteArray(len);
4173 env->SetByteArrayRegion(bytearray, 0, len, reinterpret_cast<const jbyte *>(data));
4174 }
4175 // First get the class that contains the method you need to call
4176 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
4177 // Get the method that you want to call
4178 jmethodID windowSetBitmapFromData = env->GetMethodID(clazz, "windowSetBitmapFromData",
4179 "(Landroid/view/View;I[BI)V");
4180 // Call the method on the object
4181 env->CallVoidMethod(_dw_obj, windowSetBitmapFromData, handle, (int)cid, bytearray, len);
4182 // Clean up after the array now that we are finished
4183 //env->ReleaseByteArrayElements(bytearray, (jbyte *) data, 0);
4184 }
4151 } 4185 }
4152 4186
4153 /* 4187 /*
4154 * Sets the bitmap used for a given static window. 4188 * Sets the bitmap used for a given static window.
4155 * Parameters: 4189 * Parameters:
4160 * Windows and a pixmap on Unix, pass 4194 * Windows and a pixmap on Unix, pass
4161 * NULL if you use the id param) 4195 * NULL if you use the id param)
4162 */ 4196 */
4163 void API dw_window_set_bitmap(HWND handle, unsigned long resid, const char *filename) 4197 void API dw_window_set_bitmap(HWND handle, unsigned long resid, const char *filename)
4164 { 4198 {
4199 JNIEnv *env;
4200
4201 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
4202 {
4203 // Construct a string
4204 jstring jstr = NULL;
4205 if(filename) {
4206 jstr = env->NewStringUTF(filename);
4207 }
4208 // First get the class that contains the method you need to call
4209 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
4210 // Get the method that you want to call
4211 jmethodID windowSetBitmapFromData = env->GetMethodID(clazz, "windowSetBitmap",
4212 "(Landroid/view/View;ILjava/lang/String;)V");
4213 // Call the method on the object
4214 env->CallVoidMethod(_dw_obj, windowSetBitmapFromData, handle, (int)resid, jstr);
4215 }
4165 } 4216 }
4166 4217
4167 /* 4218 /*
4168 * Sets the icon used for a given window. 4219 * Sets the icon used for a given window.
4169 * Parameters: 4220 * Parameters:
5724 case DW_FEATURE_HTML: /* Supports the HTML Widget */ 5775 case DW_FEATURE_HTML: /* Supports the HTML Widget */
5725 case DW_FEATURE_HTML_RESULT: /* Supports the DW_SIGNAL_HTML_RESULT callback */ 5776 case DW_FEATURE_HTML_RESULT: /* Supports the DW_SIGNAL_HTML_RESULT callback */
5726 case DW_FEATURE_DARK_MODE: /* Supports Dark Mode user interface */ 5777 case DW_FEATURE_DARK_MODE: /* Supports Dark Mode user interface */
5727 case DW_FEATURE_NOTIFICATION: /* Supports sending system notifications */ 5778 case DW_FEATURE_NOTIFICATION: /* Supports sending system notifications */
5728 case DW_FEATURE_UTF8_UNICODE: /* Supports UTF8 encoded Unicode text */ 5779 case DW_FEATURE_UTF8_UNICODE: /* Supports UTF8 encoded Unicode text */
5729 case DW_FEATURE_MLE_AUTO_COMPLETE: /* Supports auto completion in Multi-line Edit boxes */
5730 case DW_FEATURE_MLE_WORD_WRAP: /* Supports word wrapping in Multi-line Edit boxes */ 5780 case DW_FEATURE_MLE_WORD_WRAP: /* Supports word wrapping in Multi-line Edit boxes */
5731 case DW_FEATURE_CONTAINER_STRIPE: /* Supports striped line display in container widgets */ 5781 case DW_FEATURE_CONTAINER_STRIPE: /* Supports striped line display in container widgets */
5732 return DW_FEATURE_ENABLED; 5782 return DW_FEATURE_ENABLED;
5733 default: 5783 default:
5734 return DW_FEATURE_UNSUPPORTED; 5784 return DW_FEATURE_UNSUPPORTED;
5756 case DW_FEATURE_HTML: /* Supports the HTML Widget */ 5806 case DW_FEATURE_HTML: /* Supports the HTML Widget */
5757 case DW_FEATURE_HTML_RESULT: /* Supports the DW_SIGNAL_HTML_RESULT callback */ 5807 case DW_FEATURE_HTML_RESULT: /* Supports the DW_SIGNAL_HTML_RESULT callback */
5758 case DW_FEATURE_DARK_MODE: /* Supports Dark Mode user interface */ 5808 case DW_FEATURE_DARK_MODE: /* Supports Dark Mode user interface */
5759 case DW_FEATURE_NOTIFICATION: /* Supports sending system notifications */ 5809 case DW_FEATURE_NOTIFICATION: /* Supports sending system notifications */
5760 case DW_FEATURE_UTF8_UNICODE: /* Supports UTF8 encoded Unicode text */ 5810 case DW_FEATURE_UTF8_UNICODE: /* Supports UTF8 encoded Unicode text */
5761 case DW_FEATURE_MLE_AUTO_COMPLETE: /* Supports auto completion in Multi-line Edit boxes */
5762 case DW_FEATURE_MLE_WORD_WRAP: /* Supports word wrapping in Multi-line Edit boxes */ 5811 case DW_FEATURE_MLE_WORD_WRAP: /* Supports word wrapping in Multi-line Edit boxes */
5763 case DW_FEATURE_CONTAINER_STRIPE: /* Supports striped line display in container widgets */ 5812 case DW_FEATURE_CONTAINER_STRIPE: /* Supports striped line display in container widgets */
5764 return DW_ERROR_GENERAL; 5813 return DW_ERROR_GENERAL;
5765 /* These features are supported and configurable */ 5814 /* These features are supported and configurable */
5766 default: 5815 default: