comparison android/dw.cpp @ 2530:b9923432cb1f

Android: Implement View based render widget and icon support with Drawable. Return nullptr instead of 0 on any functions using jobject.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 10 May 2021 22:34:52 +0000
parents 060fdb2d807d
children f45ebd96ebe5
comparison
equal deleted inserted replaced
2529:060fdb2d807d 2530:b9923432cb1f
469 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr }; 469 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr };
470 470
471 _dw_event_handler(obj, params, message); 471 _dw_event_handler(obj, params, message);
472 } 472 }
473 473
474 JNIEXPORT void JNICALL
475 Java_org_dbsoft_dwindows_DWRender_eventHandlerInt(JNIEnv* env, jobject obj, jint message,
476 jint inta, jint intb, jint intc, jint intd) {
477 void *params[8] = { nullptr, nullptr, nullptr,
478 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb),
479 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), nullptr };
480
481 _dw_event_handler(obj, params, message);
482 }
483
474 /* Handler for Timer events */ 484 /* Handler for Timer events */
475 JNIEXPORT jint JNICALL 485 JNIEXPORT jint JNICALL
476 Java_org_dbsoft_dwindows_DWindows_eventHandlerTimer(JNIEnv* env, jobject obj, jlong sigfunc, jlong data) { 486 Java_org_dbsoft_dwindows_DWindows_eventHandlerTimer(JNIEnv* env, jobject obj, jlong sigfunc, jlong data) {
477 int (*timerfunc)(void *) = (int (* API)(void *))sigfunc; 487 int (*timerfunc)(void *) = (int (* API)(void *))sigfunc;
478 488
923 jmethodID boxNew = env->GetMethodID(clazz, "boxNew", "(II)Landroid/widget/LinearLayout;"); 933 jmethodID boxNew = env->GetMethodID(clazz, "boxNew", "(II)Landroid/widget/LinearLayout;");
924 // Call the method on the object 934 // Call the method on the object
925 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, boxNew, type, pad)); 935 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, boxNew, type, pad));
926 return result; 936 return result;
927 } 937 }
928 return 0; 938 return nullptr;
929 } 939 }
930 940
931 /* 941 /*
932 * Create a new Group Box to be packed. 942 * Create a new Group Box to be packed.
933 * Parameters: 943 * Parameters:
964 "(II)Landroid/widget/ScrollView;"); 974 "(II)Landroid/widget/ScrollView;");
965 // Call the method on the object 975 // Call the method on the object
966 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, scrollBoxNew, type, pad)); 976 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, scrollBoxNew, type, pad));
967 return result; 977 return result;
968 } 978 }
969 return 0; 979 return nullptr;
970 } 980 }
971 981
972 /* 982 /*
973 * Returns the position of the scrollbar in the scrollbox. 983 * Returns the position of the scrollbar in the scrollbox.
974 * Parameters: 984 * Parameters:
1044 * Handle to the removed item on success, 0 on failure or padding. 1054 * Handle to the removed item on success, 0 on failure or padding.
1045 */ 1055 */
1046 HWND API dw_box_unpack_at_index(HWND box, int index) 1056 HWND API dw_box_unpack_at_index(HWND box, int index)
1047 { 1057 {
1048 JNIEnv *env; 1058 JNIEnv *env;
1049 HWND retval = 0; 1059 HWND retval = nullptr;
1050 1060
1051 if(box && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) { 1061 if(box && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) {
1052 // First get the class that contains the method you need to call 1062 // First get the class that contains the method you need to call
1053 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 1063 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
1054 // Get the method that you want to call 1064 // Get the method that you want to call
1135 "(Ljava/lang/String;I)Landroid/widget/Button;"); 1145 "(Ljava/lang/String;I)Landroid/widget/Button;");
1136 // Call the method on the object 1146 // Call the method on the object
1137 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, buttonNew, jstr, (int)cid)); 1147 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, buttonNew, jstr, (int)cid));
1138 return result; 1148 return result;
1139 } 1149 }
1140 return 0; 1150 return nullptr;
1141 } 1151 }
1142 1152
1143 HWND _dw_entryfield_new(const char *text, ULONG cid, int password) 1153 HWND _dw_entryfield_new(const char *text, ULONG cid, int password)
1144 { 1154 {
1145 JNIEnv *env; 1155 JNIEnv *env;
1155 "(Ljava/lang/String;II)Landroid/widget/EditText;"); 1165 "(Ljava/lang/String;II)Landroid/widget/EditText;");
1156 // Call the method on the object 1166 // Call the method on the object
1157 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, entryfieldNew, jstr, (int)cid, password)); 1167 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, entryfieldNew, jstr, (int)cid, password));
1158 return result; 1168 return result;
1159 } 1169 }
1160 return 0; 1170 return nullptr;
1161 } 1171 }
1162 /* 1172 /*
1163 * Create a new Entryfield window (widget) to be packed. 1173 * Create a new Entryfield window (widget) to be packed.
1164 * Parameters: 1174 * Parameters:
1165 * text: The default text to be in the entryfield widget. 1175 * text: The default text to be in the entryfield widget.
1230 "(Ljava/lang/String;I)Landroid/widget/ImageButton;"); 1240 "(Ljava/lang/String;I)Landroid/widget/ImageButton;");
1231 // Call the method on the object 1241 // Call the method on the object
1232 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, bitmapButtonNew, jstr, (int)resid)); 1242 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, bitmapButtonNew, jstr, (int)resid));
1233 return result; 1243 return result;
1234 } 1244 }
1235 return 0; 1245 return nullptr;
1236 } 1246 }
1237 1247
1238 /* 1248 /*
1239 * Create a new bitmap button window (widget) to be packed from a file. 1249 * Create a new bitmap button window (widget) to be packed from a file.
1240 * Parameters: 1250 * Parameters:
1262 "(Ljava/lang/String;ILjava/lang/String;)Landroid/widget/ImageButton;"); 1272 "(Ljava/lang/String;ILjava/lang/String;)Landroid/widget/ImageButton;");
1263 // Call the method on the object 1273 // Call the method on the object
1264 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, bitmapButtonNewFromFile, jstr, (int)cid, path)); 1274 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, bitmapButtonNewFromFile, jstr, (int)cid, path));
1265 return result; 1275 return result;
1266 } 1276 }
1267 return 0; 1277 return nullptr;
1268 } 1278 }
1269 1279
1270 /* 1280 /*
1271 * Create a new bitmap button window (widget) to be packed from data. 1281 * Create a new bitmap button window (widget) to be packed from data.
1272 * Parameters: 1282 * Parameters:
1298 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, bitmapButtonNewFromData, jstr, (int)cid, bytearray, len)); 1308 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, bitmapButtonNewFromData, jstr, (int)cid, bytearray, len));
1299 // Clean up after the array now that we are finished 1309 // Clean up after the array now that we are finished
1300 //env->ReleaseByteArrayElements(bytearray, (jbyte *) data, 0); 1310 //env->ReleaseByteArrayElements(bytearray, (jbyte *) data, 0);
1301 return result; 1311 return result;
1302 } 1312 }
1303 return 0; 1313 return nullptr;
1304 } 1314 }
1305 1315
1306 /* 1316 /*
1307 * Create a new spinbutton window (widget) to be packed. 1317 * Create a new spinbutton window (widget) to be packed.
1308 * Parameters: 1318 * Parameters:
1326 "(Ljava/lang/String;I)Lorg/dbsoft/dwindows/DWSpinButton;"); 1336 "(Ljava/lang/String;I)Lorg/dbsoft/dwindows/DWSpinButton;");
1327 // Call the method on the object 1337 // Call the method on the object
1328 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, spinButtonNew, jstr, (int)cid)); 1338 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, spinButtonNew, jstr, (int)cid));
1329 return result; 1339 return result;
1330 } 1340 }
1331 return 0; 1341 return nullptr;
1332 } 1342 }
1333 1343
1334 /* 1344 /*
1335 * Sets the spinbutton value. 1345 * Sets the spinbutton value.
1336 * Parameters: 1346 * Parameters:
1424 "(Ljava/lang/String;I)Landroid/widget/RadioButton;"); 1434 "(Ljava/lang/String;I)Landroid/widget/RadioButton;");
1425 // Call the method on the object 1435 // Call the method on the object
1426 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, radioButtonNew, jstr, (int)cid)); 1436 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, radioButtonNew, jstr, (int)cid));
1427 return result; 1437 return result;
1428 } 1438 }
1429 return 0; 1439 return nullptr;
1430 } 1440 }
1431 1441
1432 /* 1442 /*
1433 * Create a new slider window (widget) to be packed. 1443 * Create a new slider window (widget) to be packed.
1434 * Parameters: 1444 * Parameters:
1450 jmethodID sliderNew = env->GetMethodID(clazz, "sliderNew", "(III)Landroid/widget/SeekBar;"); 1460 jmethodID sliderNew = env->GetMethodID(clazz, "sliderNew", "(III)Landroid/widget/SeekBar;");
1451 // Call the method on the object 1461 // Call the method on the object
1452 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, sliderNew, vertical, increments, (jint)cid)); 1462 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, sliderNew, vertical, increments, (jint)cid));
1453 return result; 1463 return result;
1454 } 1464 }
1455 return 0; 1465 return nullptr;
1456 } 1466 }
1457 1467
1458 /* 1468 /*
1459 * Returns the position of the slider. 1469 * Returns the position of the slider.
1460 * Parameters: 1470 * Parameters:
1569 "(I)Landroid/widget/ProgressBar;"); 1579 "(I)Landroid/widget/ProgressBar;");
1570 // Call the method on the object 1580 // Call the method on the object
1571 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, percentNew, (jint)cid)); 1581 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, percentNew, (jint)cid));
1572 return result; 1582 return result;
1573 } 1583 }
1574 return 0; 1584 return nullptr;
1575 } 1585 }
1576 1586
1577 /* 1587 /*
1578 * Sets the percent bar position. 1588 * Sets the percent bar position.
1579 * Parameters: 1589 * Parameters:
1619 "(Ljava/lang/String;I)Landroid/widget/CheckBox;"); 1629 "(Ljava/lang/String;I)Landroid/widget/CheckBox;");
1620 // Call the method on the object 1630 // Call the method on the object
1621 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, checkboxNew, jstr, (int)cid)); 1631 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, checkboxNew, jstr, (int)cid));
1622 return result; 1632 return result;
1623 } 1633 }
1624 return 0; 1634 return nullptr;
1625 } 1635 }
1626 1636
1627 /* 1637 /*
1628 * Returns the state of the checkbox. 1638 * Returns the state of the checkbox.
1629 * Parameters: 1639 * Parameters:
1691 "(II)Lorg/dbsoft/dwindows/DWListBox;"); 1701 "(II)Lorg/dbsoft/dwindows/DWListBox;");
1692 // Call the method on the object 1702 // Call the method on the object
1693 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, listBoxNew, (int)cid, multi)); 1703 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, listBoxNew, (int)cid, multi));
1694 return result; 1704 return result;
1695 } 1705 }
1696 return 0; 1706 return nullptr;
1697 } 1707 }
1698 1708
1699 /* 1709 /*
1700 * Appends the specified text to the listbox's (or combobox) entry list. 1710 * Appends the specified text to the listbox's (or combobox) entry list.
1701 * Parameters: 1711 * Parameters:
2004 "(Ljava/lang/String;I)Lorg/dbsoft/dwindows/DWComboBox;"); 2014 "(Ljava/lang/String;I)Lorg/dbsoft/dwindows/DWComboBox;");
2005 // Call the method on the object 2015 // Call the method on the object
2006 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, comboBoxNew, jstr, (int)cid)); 2016 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, comboBoxNew, jstr, (int)cid));
2007 return result; 2017 return result;
2008 } 2018 }
2009 return 0; 2019 return nullptr;
2010 } 2020 }
2011 2021
2012 /* 2022 /*
2013 * Create a new Multiline Editbox window (widget) to be packed. 2023 * Create a new Multiline Editbox window (widget) to be packed.
2014 * Parameters: 2024 * Parameters:
2029 "(I)Landroid/widget/EditText;"); 2039 "(I)Landroid/widget/EditText;");
2030 // Call the method on the object 2040 // Call the method on the object
2031 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, mleNew, (int)cid)); 2041 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, mleNew, (int)cid));
2032 return result; 2042 return result;
2033 } 2043 }
2034 return 0; 2044 return nullptr;
2035 } 2045 }
2036 2046
2037 /* 2047 /*
2038 * Adds text to an MLE box and returns the current point. 2048 * Adds text to an MLE box and returns the current point.
2039 * Parameters: 2049 * Parameters:
2302 "(Ljava/lang/String;II)Landroid/widget/TextView;"); 2312 "(Ljava/lang/String;II)Landroid/widget/TextView;");
2303 // Call the method on the object 2313 // Call the method on the object
2304 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, textNew, jstr, (int)cid, status)); 2314 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, textNew, jstr, (int)cid, status));
2305 return result; 2315 return result;
2306 } 2316 }
2307 return 0; 2317 return nullptr;
2308 } 2318 }
2309 2319
2310 /* 2320 /*
2311 * Create a new status text window (widget) to be packed. 2321 * Create a new status text window (widget) to be packed.
2312 * Parameters: 2322 * Parameters:
2340 * Returns: 2350 * Returns:
2341 * A handle to the widget or nullptr on failure. 2351 * A handle to the widget or nullptr on failure.
2342 */ 2352 */
2343 HWND API dw_render_new(unsigned long cid) 2353 HWND API dw_render_new(unsigned long cid)
2344 { 2354 {
2345 return 0; 2355 JNIEnv *env;
2356
2357 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2358 {
2359 // First get the class that contains the method you need to call
2360 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2361 // Get the method that you want to call
2362 jmethodID renderNew = env->GetMethodID(clazz, "renderNew",
2363 "(I)Lorg/dbsoft/dwindows/DWRender;");
2364 // Call the method on the object
2365 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, renderNew, (int)cid));
2366 return result;
2367 }
2368 return nullptr;
2346 } 2369 }
2347 2370
2348 /* 2371 /*
2349 * Invalidate the render widget triggering an expose event. 2372 * Invalidate the render widget triggering an expose event.
2350 * Parameters: 2373 * Parameters:
2351 * handle: A handle to a render widget to be redrawn. 2374 * handle: A handle to a render widget to be redrawn.
2352 */ 2375 */
2353 void API dw_render_redraw(HWND handle) 2376 void API dw_render_redraw(HWND handle)
2354 { 2377 {
2378 JNIEnv *env;
2379
2380 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2381 {
2382 // First get the class that contains the method you need to call
2383 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2384 // Get the method that you want to call
2385 jmethodID renderRedraw = env->GetMethodID(clazz, "renderRedraw",
2386 "(Lorg/dbsoft/dwindows/DWRender;)V");
2387 // Call the method on the object
2388 env->CallVoidMethod(_dw_obj, renderRedraw, handle);
2389 }
2355 } 2390 }
2356 2391
2357 /* Sets the current foreground drawing color. 2392 /* Sets the current foreground drawing color.
2358 * Parameters: 2393 * Parameters:
2359 * red: red value. 2394 * red: red value.
2485 * Returns: 2520 * Returns:
2486 * A handle to a tree window or nullptr on failure. 2521 * A handle to a tree window or nullptr on failure.
2487 */ 2522 */
2488 HWND API dw_tree_new(ULONG cid) 2523 HWND API dw_tree_new(ULONG cid)
2489 { 2524 {
2490 return 0; 2525 return nullptr;
2491 } 2526 }
2492 2527
2493 /* 2528 /*
2494 * Inserts an item into a tree window (widget) after another item. 2529 * Inserts an item into a tree window (widget) after another item.
2495 * Parameters: 2530 * Parameters:
2518 * Returns: 2553 * Returns:
2519 * A handle to a tree item or nullptr on failure. 2554 * A handle to a tree item or nullptr on failure.
2520 */ 2555 */
2521 HTREEITEM API dw_tree_insert(HWND handle, const char *title, HICN icon, HTREEITEM parent, void *itemdata) 2556 HTREEITEM API dw_tree_insert(HWND handle, const char *title, HICN icon, HTREEITEM parent, void *itemdata)
2522 { 2557 {
2523 return 0; 2558 return nullptr;
2524 } 2559 }
2525 2560
2526 /* 2561 /*
2527 * Gets the text an item in a tree window (widget). 2562 * Gets the text an item in a tree window (widget).
2528 * Parameters: 2563 * Parameters:
2544 * Returns: 2579 * Returns:
2545 * A handle to a tree item or nullptr on failure. 2580 * A handle to a tree item or nullptr on failure.
2546 */ 2581 */
2547 HTREEITEM API dw_tree_get_parent(HWND handle, HTREEITEM item) 2582 HTREEITEM API dw_tree_get_parent(HWND handle, HTREEITEM item)
2548 { 2583 {
2549 return 0; 2584 return nullptr;
2550 } 2585 }
2551 2586
2552 /* 2587 /*
2553 * Sets the text and icon of an item in a tree window (widget). 2588 * Sets the text and icon of an item in a tree window (widget).
2554 * Parameters: 2589 * Parameters:
2642 * Returns: 2677 * Returns:
2643 * A handle to a container window or nullptr on failure. 2678 * A handle to a container window or nullptr on failure.
2644 */ 2679 */
2645 HWND API dw_container_new(ULONG cid, int multi) 2680 HWND API dw_container_new(ULONG cid, int multi)
2646 { 2681 {
2647 return 0; 2682 return nullptr;
2648 } 2683 }
2649 2684
2650 /* 2685 /*
2651 * Sets up the container columns. 2686 * Sets up the container columns.
2652 * Parameters: 2687 * Parameters:
3014 */ 3049 */
3015 void API dw_taskbar_delete(HWND handle, HICN icon) 3050 void API dw_taskbar_delete(HWND handle, HICN icon)
3016 { 3051 {
3017 } 3052 }
3018 3053
3054 HICN _dw_icon_load(const char *filename, const char *data, int len, int resid)
3055 {
3056 JNIEnv *env;
3057
3058 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3059 {
3060 // Construct a string
3061 jstring file = nullptr;
3062 if(filename)
3063 file = env->NewStringUTF(filename);
3064 // Construct a byte array
3065 jbyteArray bytearray = nullptr;
3066 if(data && len > 0)
3067 {
3068 bytearray = env->NewByteArray(len);
3069 env->SetByteArrayRegion(bytearray, 0, len, reinterpret_cast<const jbyte *>(data));
3070 }
3071 // First get the class that contains the method you need to call
3072 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3073 // Get the method that you want to call
3074 jmethodID iconNew = env->GetMethodID(clazz, "iconNew",
3075 "(Ljava/lang/String;[BII)Landroid/graphics/drawable/Drawable;");
3076 // Call the method on the object
3077 jobject result = env->NewGlobalRef(env->CallObjectMethod(_dw_obj, iconNew,
3078 file, bytearray, len, resid));
3079 // Clean up after the array now that we are finished
3080 //if(bytearray)
3081 //env->ReleaseByteArrayElements(bytearray, (jbyte *) data, 0);
3082 return result;
3083 }
3084 return nullptr;
3085 }
3086
3019 /* 3087 /*
3020 * Obtains an icon from a module (or header in GTK). 3088 * Obtains an icon from a module (or header in GTK).
3021 * Parameters: 3089 * Parameters:
3022 * module: Handle to module (DLL) in OS/2 and Windows. 3090 * module: Handle to module (DLL) in OS/2 and Windows.
3023 * id: A unsigned long id int the resources on OS/2 and 3091 * id: A unsigned long id int the resources on OS/2 and
3026 * Returns: 3094 * Returns:
3027 * Handle to the created icon or nullptr on error. 3095 * Handle to the created icon or nullptr on error.
3028 */ 3096 */
3029 HICN API dw_icon_load(unsigned long module, unsigned long resid) 3097 HICN API dw_icon_load(unsigned long module, unsigned long resid)
3030 { 3098 {
3031 return 0; 3099 return _dw_icon_load(NULL, NULL, 0, resid);
3032 } 3100 }
3033 3101
3034 /* 3102 /*
3035 * Obtains an icon from a file. 3103 * Obtains an icon from a file.
3036 * Parameters: 3104 * Parameters:
3040 * Returns: 3108 * Returns:
3041 * Handle to the created icon or nullptr on error. 3109 * Handle to the created icon or nullptr on error.
3042 */ 3110 */
3043 HICN API dw_icon_load_from_file(const char *filename) 3111 HICN API dw_icon_load_from_file(const char *filename)
3044 { 3112 {
3045 return 0; 3113 return _dw_icon_load(filename, NULL, 0, 0);
3046 } 3114 }
3047 3115
3048 /* 3116 /*
3049 * Obtains an icon from data. 3117 * Obtains an icon from data.
3050 * Parameters: 3118 * Parameters:
3053 * Returns: 3121 * Returns:
3054 * Handle to the created icon or nullptr on error. 3122 * Handle to the created icon or nullptr on error.
3055 */ 3123 */
3056 HICN API dw_icon_load_from_data(const char *data, int len) 3124 HICN API dw_icon_load_from_data(const char *data, int len)
3057 { 3125 {
3058 return 0; 3126 return _dw_icon_load(NULL, data, len, 0);
3059 } 3127 }
3060 3128
3061 /* 3129 /*
3062 * Frees a loaded icon resource. 3130 * Frees a loaded icon resource.
3063 * Parameters: 3131 * Parameters:
3064 * handle: Handle to icon returned by dw_icon_load(). 3132 * handle: Handle to icon returned by dw_icon_load().
3065 */ 3133 */
3066 void API dw_icon_free(HICN handle) 3134 void API dw_icon_free(HICN handle)
3067 { 3135 {
3136 if(handle)
3137 {
3138 JNIEnv *env;
3139
3140 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3141 {
3142 env->DeleteGlobalRef(handle);
3143 }
3144 }
3068 } 3145 }
3069 3146
3070 /* 3147 /*
3071 * Create a new MDI Frame to be packed. 3148 * Create a new MDI Frame to be packed.
3072 * Parameters: 3149 * Parameters:
3423 "(I)Landroid/widget/CalendarView;"); 3500 "(I)Landroid/widget/CalendarView;");
3424 // Call the method on the object 3501 // Call the method on the object
3425 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, calendarNew, (int)cid)); 3502 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, calendarNew, (int)cid));
3426 return result; 3503 return result;
3427 } 3504 }
3428 return 0; 3505 return nullptr;
3429 } 3506 }
3430 3507
3431 /* 3508 /*
3432 * Sets the current date of a calendar. 3509 * Sets the current date of a calendar.
3433 * Parameters: 3510 * Parameters:
3623 "(I)Landroid/webkit/WebView;"); 3700 "(I)Landroid/webkit/WebView;");
3624 // Call the method on the object 3701 // Call the method on the object
3625 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, htmlNew, (int)cid)); 3702 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, htmlNew, (int)cid));
3626 return result; 3703 return result;
3627 } 3704 }
3628 return 0; 3705 return nullptr;
3629 } 3706 }
3630 3707
3631 /* 3708 /*
3632 * Returns the current X and Y coordinates of the mouse pointer. 3709 * Returns the current X and Y coordinates of the mouse pointer.
3633 * Parameters: 3710 * Parameters:
3655 * Returns: 3732 * Returns:
3656 * Handle to the created menu or nullptr on error. 3733 * Handle to the created menu or nullptr on error.
3657 */ 3734 */
3658 HMENUI API dw_menu_new(ULONG cid) 3735 HMENUI API dw_menu_new(ULONG cid)
3659 { 3736 {
3660 return 0; 3737 return nullptr;
3661 } 3738 }
3662 3739
3663 /* 3740 /*
3664 * Create a menubar on a window. 3741 * Create a menubar on a window.
3665 * Parameters: 3742 * Parameters:
3667 * Returns: 3744 * Returns:
3668 * Handle to the created menu bar or nullptr on error. 3745 * Handle to the created menu bar or nullptr on error.
3669 */ 3746 */
3670 HMENUI API dw_menubar_new(HWND location) 3747 HMENUI API dw_menubar_new(HWND location)
3671 { 3748 {
3672 return 0; 3749 return nullptr;
3673 } 3750 }
3674 3751
3675 /* 3752 /*
3676 * Destroys a menu created with dw_menubar_new or dw_menu_new. 3753 * Destroys a menu created with dw_menubar_new or dw_menu_new.
3677 * Parameters: 3754 * Parameters:
3719 * Returns: 3796 * Returns:
3720 * Handle to the created menu item or nullptr on error. 3797 * Handle to the created menu item or nullptr on error.
3721 */ 3798 */
3722 HWND API dw_menu_append_item(HMENUI menux, const char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux) 3799 HWND API dw_menu_append_item(HMENUI menux, const char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux)
3723 { 3800 {
3724 return 0; 3801 return nullptr;
3725 } 3802 }
3726 3803
3727 /* 3804 /*
3728 * Sets the state of a menu item check. 3805 * Sets the state of a menu item check.
3729 * Deprecated; use dw_menu_item_set_state() 3806 * Deprecated; use dw_menu_item_set_state()
3769 "(II)Landroid/widget/RelativeLayout;"); 3846 "(II)Landroid/widget/RelativeLayout;");
3770 // Call the method on the object 3847 // Call the method on the object
3771 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, notebookNew, (int)cid, top)); 3848 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, notebookNew, (int)cid, top));
3772 return result; 3849 return result;
3773 } 3850 }
3774 return 0; 3851 return nullptr;
3775 } 3852 }
3776 3853
3777 /* 3854 /*
3778 * Adds a new page to specified notebook. 3855 * Adds a new page to specified notebook.
3779 * Parameters: 3856 * Parameters:
3951 "(Ljava/lang/String;I)Landroid/widget/LinearLayout;"); 4028 "(Ljava/lang/String;I)Landroid/widget/LinearLayout;");
3952 // Call the method on the object 4029 // Call the method on the object
3953 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, windowNew, jstr, (int)flStyle)); 4030 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, windowNew, jstr, (int)flStyle));
3954 return result; 4031 return result;
3955 } 4032 }
3956 return 0; 4033 return nullptr;
3957 } 4034 }
3958 4035
3959 /* 4036 /*
3960 * Call a function from the window (widget)'s context (typically the message loop thread). 4037 * Call a function from the window (widget)'s context (typically the message loop thread).
3961 * Parameters: 4038 * Parameters:
4361 * HWND of window with ID or nullptr on error. 4438 * HWND of window with ID or nullptr on error.
4362 */ 4439 */
4363 HWND API dw_window_from_id(HWND handle, int id) 4440 HWND API dw_window_from_id(HWND handle, int id)
4364 { 4441 {
4365 JNIEnv *env; 4442 JNIEnv *env;
4366 HWND retval = 0; 4443 HWND retval = nullptr;
4367 4444
4368 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 4445 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
4369 { 4446 {
4370 // First get the class that contains the method you need to call 4447 // First get the class that contains the method you need to call
4371 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 4448 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
4939 pthread_mutex_destroy(mutex); 5016 pthread_mutex_destroy(mutex);
4940 free(mutex); 5017 free(mutex);
4941 } 5018 }
4942 } 5019 }
4943 5020
5021 /* Check if we are on the UI thread */
5022 int _dw_is_ui_thread(void)
5023 {
5024 JNIEnv *env;
5025
5026 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
5027 {
5028 // First get the class that contains the method you need to call
5029 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
5030 // Get the method that you want to call
5031 jmethodID isUIThread = env->GetMethodID(clazz, "isUIThread",
5032 "()Z");
5033 // Call the method on the object
5034 return env->CallBooleanMethod(_dw_obj, isUIThread);
5035 }
5036 return FALSE;
5037 }
5038
4944 /* 5039 /*
4945 * Tries to gain access to the semaphore, if it can't it blocks. 5040 * Tries to gain access to the semaphore, if it can't it blocks.
4946 * Parameters: 5041 * Parameters:
4947 * mutex: The handle to the mutex returned by dw_mutex_new(). 5042 * mutex: The handle to the mutex returned by dw_mutex_new().
4948 */ 5043 */
4951 /* We need to handle locks from the main thread differently... 5046 /* We need to handle locks from the main thread differently...
4952 * since we can't stop message processing... otherwise we 5047 * since we can't stop message processing... otherwise we
4953 * will deadlock... so try to acquire the lock and continue 5048 * will deadlock... so try to acquire the lock and continue
4954 * processing messages in between tries. 5049 * processing messages in between tries.
4955 */ 5050 */
4956 #if 0 /* TODO: Not sure how to do this on Android yet */ 5051 if(_dw_is_ui_thread())
4957 if(_dw_thread == pthread_self())
4958 { 5052 {
4959 while(pthread_mutex_trylock(mutex) != 0) 5053 while(pthread_mutex_trylock(mutex) != 0)
4960 { 5054 {
4961 /* Process any pending events */ 5055 /* Process any pending events */
4962 if(g_main_context_pending(nullptr)) 5056 dw_main_iteration();
4963 { 5057 sched_yield();
4964 do
4965 {
4966 g_main_context_iteration(nullptr, FALSE);
4967 }
4968 while(g_main_context_pending(nullptr));
4969 }
4970 else
4971 sched_yield();
4972 } 5058 }
4973 } 5059 }
4974 else 5060 else
4975 #endif
4976 { 5061 {
4977 pthread_mutex_lock(mutex); 5062 pthread_mutex_lock(mutex);
4978 } 5063 }
4979 } 5064 }
4980 5065