Mercurial > dwindows
comparison android/dw.cpp @ 2492:e2ca6c1a4661
Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
and entryfield_set_limit().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 01 May 2021 00:41:53 +0000 |
parents | 62e124eecd82 |
children | bca7e0ab0ccc |
comparison
equal
deleted
inserted
replaced
2491:bf4fe6bb512b | 2492:e2ca6c1a4661 |
---|---|
886 * Returns: | 886 * Returns: |
887 * Handle to the removed item on success, 0 on failure or padding. | 887 * Handle to the removed item on success, 0 on failure or padding. |
888 */ | 888 */ |
889 HWND API dw_box_unpack_at_index(HWND box, int index) | 889 HWND API dw_box_unpack_at_index(HWND box, int index) |
890 { | 890 { |
891 return 0; | 891 JNIEnv *env; |
892 HWND retval = 0; | |
893 | |
894 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) { | |
895 // First get the class that contains the method you need to call | |
896 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
897 // Get the method that you want to call | |
898 jmethodID boxUnpackAtIndex = env->GetMethodID(clazz, "boxUnpackAtIndex", | |
899 "(Landroid/widget/LinearLayout;I)Landroid/view/View;"); | |
900 // Call the method on the object | |
901 retval = env->CallObjectMethod(_dw_obj, boxUnpackAtIndex, box, index); | |
902 } | |
903 return retval; | |
892 } | 904 } |
893 | 905 |
894 /* | 906 /* |
895 * Pack windows (widgets) into a box at an arbitrary location. | 907 * Pack windows (widgets) into a box at an arbitrary location. |
896 * Parameters: | 908 * Parameters: |
1022 * handle: Handle to the spinbutton to be set. | 1034 * handle: Handle to the spinbutton to be set. |
1023 * limit: Number of characters the entryfield will take. | 1035 * limit: Number of characters the entryfield will take. |
1024 */ | 1036 */ |
1025 void API dw_entryfield_set_limit(HWND handle, ULONG limit) | 1037 void API dw_entryfield_set_limit(HWND handle, ULONG limit) |
1026 { | 1038 { |
1039 JNIEnv *env; | |
1040 | |
1041 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1042 { | |
1043 // First get the class that contains the method you need to call | |
1044 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1045 // Get the method that you want to call | |
1046 jmethodID entryfieldSetLimit = env->GetMethodID(clazz, "entryfieldSetLimit", | |
1047 "(Landroid/widget/EditText;J)V"); | |
1048 // Call the method on the object | |
1049 env->CallVoidMethod(_dw_obj, entryfieldSetLimit, handle, (jlong)limit); | |
1050 } | |
1027 } | 1051 } |
1028 | 1052 |
1029 /* | 1053 /* |
1030 * Create a new bitmap button window (widget) to be packed. | 1054 * Create a new bitmap button window (widget) to be packed. |
1031 * Parameters: | 1055 * Parameters: |
1154 * Returns: | 1178 * Returns: |
1155 * A handle to a slider window or NULL on failure. | 1179 * A handle to a slider window or NULL on failure. |
1156 */ | 1180 */ |
1157 HWND API dw_slider_new(int vertical, int increments, ULONG cid) | 1181 HWND API dw_slider_new(int vertical, int increments, ULONG cid) |
1158 { | 1182 { |
1183 JNIEnv *env; | |
1184 | |
1185 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1186 { | |
1187 // First get the class that contains the method you need to call | |
1188 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1189 // Get the method that you want to call | |
1190 jmethodID sliderNew = env->GetMethodID(clazz, "sliderNew", "(III)Landroid/widget/SeekBar;"); | |
1191 // Call the method on the object | |
1192 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, sliderNew, vertical, increments, (jint)cid)); | |
1193 return result; | |
1194 } | |
1159 return 0; | 1195 return 0; |
1160 } | 1196 } |
1161 | 1197 |
1162 /* | 1198 /* |
1163 * Returns the position of the slider. | 1199 * Returns the position of the slider. |
1166 * Returns: | 1202 * Returns: |
1167 * Position of the slider in the set range. | 1203 * Position of the slider in the set range. |
1168 */ | 1204 */ |
1169 unsigned int API dw_slider_get_pos(HWND handle) | 1205 unsigned int API dw_slider_get_pos(HWND handle) |
1170 { | 1206 { |
1207 JNIEnv *env; | |
1208 | |
1209 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1210 { | |
1211 // First get the class that contains the method you need to call | |
1212 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1213 // Get the method that you want to call | |
1214 jmethodID percentGetPos = env->GetMethodID(clazz, "percentGetPos", | |
1215 "(Landroid/widget/ProgressBar;)I"); | |
1216 // Call the method on the object | |
1217 return env->CallIntMethod(_dw_obj, percentGetPos, handle); | |
1218 } | |
1171 return 0; | 1219 return 0; |
1172 } | 1220 } |
1173 | 1221 |
1174 /* | 1222 /* |
1175 * Sets the slider position. | 1223 * Sets the slider position. |
1177 * handle: Handle to the slider to be set. | 1225 * handle: Handle to the slider to be set. |
1178 * position: Position of the slider withing the range. | 1226 * position: Position of the slider withing the range. |
1179 */ | 1227 */ |
1180 void API dw_slider_set_pos(HWND handle, unsigned int position) | 1228 void API dw_slider_set_pos(HWND handle, unsigned int position) |
1181 { | 1229 { |
1230 dw_percent_set_pos(handle, position); | |
1182 } | 1231 } |
1183 | 1232 |
1184 /* | 1233 /* |
1185 * Create a new scrollbar window (widget) to be packed. | 1234 * Create a new scrollbar window (widget) to be packed. |
1186 * Parameters: | 1235 * Parameters: |
1189 * Returns: | 1238 * Returns: |
1190 * A handle to a scrollbar window or NULL on failure. | 1239 * A handle to a scrollbar window or NULL on failure. |
1191 */ | 1240 */ |
1192 HWND API dw_scrollbar_new(int vertical, ULONG cid) | 1241 HWND API dw_scrollbar_new(int vertical, ULONG cid) |
1193 { | 1242 { |
1194 return 0; | 1243 return dw_slider_new(vertical, 100, cid); |
1195 } | 1244 } |
1196 | 1245 |
1197 /* | 1246 /* |
1198 * Returns the position of the scrollbar. | 1247 * Returns the position of the scrollbar. |
1199 * Parameters: | 1248 * Parameters: |
1201 * Returns: | 1250 * Returns: |
1202 * Position of the scrollbar in the set range. | 1251 * Position of the scrollbar in the set range. |
1203 */ | 1252 */ |
1204 unsigned int API dw_scrollbar_get_pos(HWND handle) | 1253 unsigned int API dw_scrollbar_get_pos(HWND handle) |
1205 { | 1254 { |
1206 return 0; | 1255 return dw_slider_get_pos(handle); |
1207 } | 1256 } |
1208 | 1257 |
1209 /* | 1258 /* |
1210 * Sets the scrollbar position. | 1259 * Sets the scrollbar position. |
1211 * Parameters: | 1260 * Parameters: |
1212 * handle: Handle to the scrollbar to be set. | 1261 * handle: Handle to the scrollbar to be set. |
1213 * position: Position of the scrollbar withing the range. | 1262 * position: Position of the scrollbar withing the range. |
1214 */ | 1263 */ |
1215 void API dw_scrollbar_set_pos(HWND handle, unsigned int position) | 1264 void API dw_scrollbar_set_pos(HWND handle, unsigned int position) |
1216 { | 1265 { |
1266 dw_percent_set_pos(handle, position); | |
1217 } | 1267 } |
1218 | 1268 |
1219 /* | 1269 /* |
1220 * Sets the scrollbar range. | 1270 * Sets the scrollbar range. |
1221 * Parameters: | 1271 * Parameters: |
1223 * range: Maximum range value. | 1273 * range: Maximum range value. |
1224 * visible: Visible area relative to the range. | 1274 * visible: Visible area relative to the range. |
1225 */ | 1275 */ |
1226 void API dw_scrollbar_set_range(HWND handle, unsigned int range, unsigned int visible) | 1276 void API dw_scrollbar_set_range(HWND handle, unsigned int range, unsigned int visible) |
1227 { | 1277 { |
1278 JNIEnv *env; | |
1279 | |
1280 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1281 { | |
1282 // First get the class that contains the method you need to call | |
1283 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1284 // Get the method that you want to call | |
1285 jmethodID percentSetRange = env->GetMethodID(clazz, "percentSetRange", | |
1286 "(Landroid/widget/ProgressBar;I)V"); | |
1287 // Call the method on the object | |
1288 env->CallVoidMethod(_dw_obj, percentSetRange, handle, (jint)range); | |
1289 } | |
1228 } | 1290 } |
1229 | 1291 |
1230 /* | 1292 /* |
1231 * Create a new percent bar window (widget) to be packed. | 1293 * Create a new percent bar window (widget) to be packed. |
1232 * Parameters: | 1294 * Parameters: |
1234 * Returns: | 1296 * Returns: |
1235 * A handle to a percent bar window or NULL on failure. | 1297 * A handle to a percent bar window or NULL on failure. |
1236 */ | 1298 */ |
1237 HWND API dw_percent_new(ULONG cid) | 1299 HWND API dw_percent_new(ULONG cid) |
1238 { | 1300 { |
1301 JNIEnv *env; | |
1302 | |
1303 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1304 { | |
1305 // First get the class that contains the method you need to call | |
1306 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1307 // Get the method that you want to call | |
1308 jmethodID percentNew = env->GetMethodID(clazz, "percentNew", | |
1309 "(I)Landroid/widget/ProgressBar;"); | |
1310 // Call the method on the object | |
1311 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, percentNew, (jint)cid)); | |
1312 return result; | |
1313 } | |
1239 return 0; | 1314 return 0; |
1240 } | 1315 } |
1241 | 1316 |
1242 /* | 1317 /* |
1243 * Sets the percent bar position. | 1318 * Sets the percent bar position. |
1245 * handle: Handle to the percent bar to be set. | 1320 * handle: Handle to the percent bar to be set. |
1246 * position: Position of the percent bar withing the range. | 1321 * position: Position of the percent bar withing the range. |
1247 */ | 1322 */ |
1248 void API dw_percent_set_pos(HWND handle, unsigned int position) | 1323 void API dw_percent_set_pos(HWND handle, unsigned int position) |
1249 { | 1324 { |
1325 JNIEnv *env; | |
1326 | |
1327 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1328 { | |
1329 // First get the class that contains the method you need to call | |
1330 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1331 // Get the method that you want to call | |
1332 jmethodID percentSetPos = env->GetMethodID(clazz, "percentSetPos", | |
1333 "(Landroid/widget/ProgressBar;I)V"); | |
1334 // Call the method on the object | |
1335 env->CallVoidMethod(_dw_obj, percentSetPos, handle, (jint)position); | |
1336 } | |
1250 } | 1337 } |
1251 | 1338 |
1252 /* | 1339 /* |
1253 * Create a new checkbox window (widget) to be packed. | 1340 * Create a new checkbox window (widget) to be packed. |
1254 * Parameters: | 1341 * Parameters: |
1284 * Returns: | 1371 * Returns: |
1285 * State of checkbox (TRUE or FALSE). | 1372 * State of checkbox (TRUE or FALSE). |
1286 */ | 1373 */ |
1287 int API dw_checkbox_get(HWND handle) | 1374 int API dw_checkbox_get(HWND handle) |
1288 { | 1375 { |
1376 JNIEnv *env; | |
1377 | |
1378 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1379 { | |
1380 // First get the class that contains the method you need to call | |
1381 //jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1382 jclass clazz = env->FindClass(DW_CLASS_NAME); | |
1383 // Get the method that you want to call | |
1384 jmethodID checkOrRadioGetChecked = env->GetMethodID(clazz, "checkOrRadioGetChecked", | |
1385 "(Landroid/view/View;)Z"); | |
1386 // Call the method on the object | |
1387 return env->CallBooleanMethod(_dw_obj, checkOrRadioGetChecked, handle); | |
1388 } | |
1289 return FALSE; | 1389 return FALSE; |
1290 } | 1390 } |
1291 | 1391 |
1292 /* | 1392 /* |
1293 * Sets the state of the checkbox. | 1393 * Sets the state of the checkbox. |
1295 * handle: Handle to the checkbox to be queried. | 1395 * handle: Handle to the checkbox to be queried. |
1296 * value: TRUE for checked, FALSE for unchecked. | 1396 * value: TRUE for checked, FALSE for unchecked. |
1297 */ | 1397 */ |
1298 void API dw_checkbox_set(HWND handle, int value) | 1398 void API dw_checkbox_set(HWND handle, int value) |
1299 { | 1399 { |
1400 JNIEnv *env; | |
1401 | |
1402 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1403 { | |
1404 // First get the class that contains the method you need to call | |
1405 //jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1406 jclass clazz = env->FindClass(DW_CLASS_NAME); | |
1407 // Get the method that you want to call | |
1408 jmethodID checkOrRadioSetChecked = env->GetMethodID(clazz, "checkOrRadioSetChecked", | |
1409 "(Landroid/view/View;I)V"); | |
1410 // Call the method on the object | |
1411 env->CallVoidMethod(_dw_obj, checkOrRadioSetChecked, handle, value); | |
1412 } | |
1300 } | 1413 } |
1301 | 1414 |
1302 /* | 1415 /* |
1303 * Create a new listbox window (widget) to be packed. | 1416 * Create a new listbox window (widget) to be packed. |
1304 * Parameters: | 1417 * Parameters: |