Mercurial > dwindows
comparison android/dw.cpp @ 2901:761b7a12b079
Add va_list versions of dw_debug() and dw_messagebox() for use in C++ bindings.
dw_vdebug() and dw_vmessagebox() work similarly to the standard library versions.
DW::App:Debug() and DW::App:MessageBox() use them for variable arguments.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 25 Dec 2022 00:20:49 +0000 |
parents | de1a0cd26691 |
children | 3fe7641f027c |
comparison
equal
deleted
inserted
replaced
2900:fe31d4535270 | 2901:761b7a12b079 |
---|---|
1164 * ...: Additional variables for use in the format. | 1164 * ...: Additional variables for use in the format. |
1165 */ | 1165 */ |
1166 void API dw_debug(const char *format, ...) | 1166 void API dw_debug(const char *format, ...) |
1167 { | 1167 { |
1168 va_list args; | 1168 va_list args; |
1169 char outbuf[1025] = {0}; | |
1170 JNIEnv *env; | |
1171 | 1169 |
1172 va_start(args, format); | 1170 va_start(args, format); |
1173 vsnprintf(outbuf, 1024, format, args); | 1171 vfprintf(stderr, format, args); |
1174 va_end(args); | 1172 va_end(args); |
1173 } | |
1174 | |
1175 void API dw_vdebug(const char *format, va_list args) | |
1176 { | |
1177 JNIEnv *env; | |
1175 | 1178 |
1176 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | 1179 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
1177 { | 1180 { |
1181 char outbuf[1025] = {0}; | |
1182 | |
1183 vsnprintf(outbuf, 1024, format, args); | |
1184 | |
1178 // Construct a String | 1185 // Construct a String |
1179 jstring jstr = env->NewStringUTF(outbuf); | 1186 jstring jstr = env->NewStringUTF(outbuf); |
1180 // First get the class that contains the method you need to call | 1187 // First get the class that contains the method you need to call |
1181 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | 1188 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); |
1182 // Get the method that you want to call | 1189 // Get the method that you want to call |
1189 } | 1196 } |
1190 else { | 1197 else { |
1191 /* Output to stderr, if there is another way to send it | 1198 /* Output to stderr, if there is another way to send it |
1192 * on the implementation platform, change this. | 1199 * on the implementation platform, change this. |
1193 */ | 1200 */ |
1194 fprintf(stderr, "%s", outbuf); | 1201 vfprintf(stderr, format, args); |
1195 } | 1202 } |
1196 } | 1203 } |
1197 | 1204 |
1198 /* | 1205 /* |
1199 * Displays a Message Box with given text and title.. | 1206 * Displays a Message Box with given text and title.. |
1207 * or DW_MB_RETURN_CANCEL based on flags and user response. | 1214 * or DW_MB_RETURN_CANCEL based on flags and user response. |
1208 */ | 1215 */ |
1209 int API dw_messagebox(const char *title, int flags, const char *format, ...) | 1216 int API dw_messagebox(const char *title, int flags, const char *format, ...) |
1210 { | 1217 { |
1211 va_list args; | 1218 va_list args; |
1212 char outbuf[1025] = {0}; | 1219 int rc; |
1220 | |
1221 va_start(args, format); | |
1222 rc = dw_vmessagebox(title, flags, format, args); | |
1223 va_end(args); | |
1224 return rc; | |
1225 } | |
1226 | |
1227 int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args) | |
1228 { | |
1213 JNIEnv *env; | 1229 JNIEnv *env; |
1214 int retval = 0; | 1230 int retval = 0; |
1215 | 1231 |
1216 va_start(args, format); | |
1217 vsnprintf(outbuf, 1024, format, args); | |
1218 va_end(args); | |
1219 | |
1220 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | 1232 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
1221 { | 1233 { |
1234 char outbuf[1025] = {0}; | |
1235 | |
1236 vsnprintf(outbuf, 1024, format, args); | |
1237 | |
1222 // Construct a String | 1238 // Construct a String |
1223 jstring jstr = env->NewStringUTF(outbuf); | 1239 jstring jstr = env->NewStringUTF(outbuf); |
1224 jstring jstrtitle = env->NewStringUTF(title); | 1240 jstring jstrtitle = env->NewStringUTF(title); |
1225 // First get the class that contains the method you need to call | 1241 // First get the class that contains the method you need to call |
1226 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | 1242 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); |