Mercurial > dwindows
comparison android/dw.cpp @ 2520:167af4b0004b
Android: Implement spinbuttons and callbacks.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 08 May 2021 23:22:52 +0000 |
parents | 551313c064f2 |
children | 5f92284e2b08 |
comparison
equal
deleted
inserted
replaced
2519:551313c064f2 | 2520:167af4b0004b |
---|---|
432 | 432 |
433 _dw_event_handler(obj, params, message); | 433 _dw_event_handler(obj, params, message); |
434 } | 434 } |
435 | 435 |
436 JNIEXPORT void JNICALL | 436 JNIEXPORT void JNICALL |
437 Java_org_dbsoft_dwindows_DWSpinButton_eventHandlerInt(JNIEnv* env, jobject obj, jint message, | |
438 jint inta, jint intb, jint intc, jint intd) { | |
439 void *params[8] = { NULL, NULL, NULL, | |
440 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), | |
441 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), NULL }; | |
442 | |
443 _dw_event_handler(obj, params, message); | |
444 } | |
445 | |
446 JNIEXPORT void JNICALL | |
437 Java_org_dbsoft_dwindows_DWListBox_eventHandlerInt(JNIEnv* env, jobject obj, jint message, | 447 Java_org_dbsoft_dwindows_DWListBox_eventHandlerInt(JNIEnv* env, jobject obj, jint message, |
438 jint inta, jint intb, jint intc, jint intd) { | 448 jint inta, jint intb, jint intc, jint intd) { |
439 void *params[8] = { NULL, NULL, NULL, | 449 void *params[8] = { NULL, NULL, NULL, |
440 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), | 450 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), |
441 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), NULL }; | 451 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), NULL }; |
1210 * Returns: | 1220 * Returns: |
1211 * A handle to a spinbutton window or NULL on failure. | 1221 * A handle to a spinbutton window or NULL on failure. |
1212 */ | 1222 */ |
1213 HWND API dw_spinbutton_new(const char *text, ULONG cid) | 1223 HWND API dw_spinbutton_new(const char *text, ULONG cid) |
1214 { | 1224 { |
1225 JNIEnv *env; | |
1226 | |
1227 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1228 { | |
1229 // Construct a String | |
1230 jstring jstr = env->NewStringUTF(text); | |
1231 // First get the class that contains the method you need to call | |
1232 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1233 // Get the method that you want to call | |
1234 jmethodID spinButtonNew = env->GetMethodID(clazz, "spinButtonNew", | |
1235 "(Ljava/lang/String;I)Lorg/dbsoft/dwindows/DWSpinButton;"); | |
1236 // Call the method on the object | |
1237 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, spinButtonNew, jstr, (int)cid)); | |
1238 return result; | |
1239 } | |
1215 return 0; | 1240 return 0; |
1216 } | 1241 } |
1217 | 1242 |
1218 /* | 1243 /* |
1219 * Sets the spinbutton value. | 1244 * Sets the spinbutton value. |
1221 * handle: Handle to the spinbutton to be set. | 1246 * handle: Handle to the spinbutton to be set. |
1222 * position: Current value of the spinbutton. | 1247 * position: Current value of the spinbutton. |
1223 */ | 1248 */ |
1224 void API dw_spinbutton_set_pos(HWND handle, long position) | 1249 void API dw_spinbutton_set_pos(HWND handle, long position) |
1225 { | 1250 { |
1251 JNIEnv *env; | |
1252 | |
1253 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1254 { | |
1255 // First get the class that contains the method you need to call | |
1256 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1257 // Get the method that you want to call | |
1258 jmethodID spinButtonSetPos = env->GetMethodID(clazz, "spinButtonSetPos", | |
1259 "(Lorg/dbsoft/dwindows/DWSpinButton;J)V"); | |
1260 // Call the method on the object | |
1261 env->CallVoidMethod(_dw_obj, spinButtonSetPos, handle, (jlong)position); | |
1262 } | |
1226 } | 1263 } |
1227 | 1264 |
1228 /* | 1265 /* |
1229 * Sets the spinbutton limits. | 1266 * Sets the spinbutton limits. |
1230 * Parameters: | 1267 * Parameters: |
1232 * upper: Upper limit. | 1269 * upper: Upper limit. |
1233 * lower: Lower limit. | 1270 * lower: Lower limit. |
1234 */ | 1271 */ |
1235 void API dw_spinbutton_set_limits(HWND handle, long upper, long lower) | 1272 void API dw_spinbutton_set_limits(HWND handle, long upper, long lower) |
1236 { | 1273 { |
1274 JNIEnv *env; | |
1275 | |
1276 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1277 { | |
1278 // First get the class that contains the method you need to call | |
1279 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1280 // Get the method that you want to call | |
1281 jmethodID spinButtonSetLimits = env->GetMethodID(clazz, "spinButtonSetLimits", | |
1282 "(Lorg/dbsoft/dwindows/DWSpinButton;JJ)V"); | |
1283 // Call the method on the object | |
1284 env->CallVoidMethod(_dw_obj, spinButtonSetLimits, handle, (jlong)upper, (jlong)lower); | |
1285 } | |
1237 } | 1286 } |
1238 | 1287 |
1239 /* | 1288 /* |
1240 * Returns the current value of the spinbutton. | 1289 * Returns the current value of the spinbutton. |
1241 * Parameters: | 1290 * Parameters: |
1243 * Returns: | 1292 * Returns: |
1244 * Number value displayed in the spinbutton. | 1293 * Number value displayed in the spinbutton. |
1245 */ | 1294 */ |
1246 long API dw_spinbutton_get_pos(HWND handle) | 1295 long API dw_spinbutton_get_pos(HWND handle) |
1247 { | 1296 { |
1248 return 0; | 1297 JNIEnv *env; |
1298 long retval = 0; | |
1299 | |
1300 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1301 { | |
1302 // First get the class that contains the method you need to call | |
1303 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1304 // Get the method that you want to call | |
1305 jmethodID spinButtonGetPos = env->GetMethodID(clazz, "spinButtonGetPos", | |
1306 "(Lorg/dbsoft/dwindows/DWSpinButton;)J"); | |
1307 // Call the method on the object | |
1308 retval = env->CallLongMethod(_dw_obj, spinButtonGetPos, handle); | |
1309 } | |
1310 return retval; | |
1249 } | 1311 } |
1250 | 1312 |
1251 /* | 1313 /* |
1252 * Create a new radiobutton window (widget) to be packed. | 1314 * Create a new radiobutton window (widget) to be packed. |
1253 * Parameters: | 1315 * Parameters: |