@@ -263,7 +263,7 @@ static int umsgbox (lua_State *L)
263
263
} // end of umsgbox
264
264
265
265
266
- static int get_extra_field (lua_State *L, const int narg, const char * name)
266
+ static int get_extra_integer (lua_State *L, const int narg, const char * name)
267
267
{
268
268
int iResult;
269
269
@@ -272,7 +272,18 @@ static int get_extra_field (lua_State *L, const int narg, const char * name)
272
272
lua_pop (L, 1 );
273
273
274
274
return iResult;
275
- } // end of get_extra_field
275
+ } // end of get_extra_integer
276
+
277
+ static CString get_extra_string (lua_State *L, const int narg, const char * name)
278
+ {
279
+ CString strResult;
280
+
281
+ lua_getfield (L, narg, name);
282
+ strResult = luaL_optstring (L, -1 , " " );
283
+ lua_pop (L, 1 );
284
+
285
+ return strResult;
286
+ } // end of get_extra_string
276
287
277
288
// input-box display routine
278
289
// arg1 = message to display
@@ -281,13 +292,16 @@ static int get_extra_field (lua_State *L, const int narg, const char * name)
281
292
// arg4 = input font
282
293
// arg5 = input font size
283
294
// arg6 = table of extra stuff:
284
- // box_width --> width of message box in pixels (min 180)
285
- // box_height --> height of message box in pixels (min 125)
286
- // prompt_width --> width of prompt text in pixels (min 10)
287
- // prompt_height --> height of prompt text in pixels (min 12)
288
- // reply_width --> width of reply in pixels (min 10)
289
- // reply_height --> height of reply in pixels (min 10)
290
- // max_length --> max characters they can type (min 1)
295
+ // box_width --> width of message box in pixels (min 180)
296
+ // box_height --> height of message box in pixels (min 125)
297
+ // prompt_width --> width of prompt text in pixels (min 10)
298
+ // prompt_height --> height of prompt text in pixels (min 12)
299
+ // reply_width --> width of reply in pixels (min 10)
300
+ // reply_height --> height of reply in pixels (min 10)
301
+ // max_length --> max characters they can type (min 1)
302
+ // validate --> validation function
303
+ // ok_button --> what to put on the OK button (default: OK)
304
+ // cancel_button --> what to put on the Cancel button (default: Cancel)
291
305
//
292
306
// returns: what they typed, or nil if cancelled
293
307
@@ -309,18 +323,38 @@ static int gen_inputbox (lua_State *L, T & msg)
309
323
int iReplyWidth = 0 ;
310
324
int iReplyHeight = 0 ;
311
325
int iMaxReplyLength = 0 ;
326
+ CString strOKbuttonLabel;
327
+ CString strCancelbuttonLabel;
328
+
329
+
312
330
313
331
// if arg6 present, and a table, grab extra stuff
314
332
if (lua_istable (L, nExtraStuffArg))
315
333
{
316
- iBoxWidth = get_extra_field (L, nExtraStuffArg, " box_width" );
317
- iBoxHeight = get_extra_field (L, nExtraStuffArg, " box_height" );
318
- iPromptWidth = get_extra_field (L, nExtraStuffArg, " prompt_width" );
319
- iPromptHeight = get_extra_field (L, nExtraStuffArg, " prompt_height" );
320
- iReplyWidth = get_extra_field (L, nExtraStuffArg, " reply_width" );
321
- iReplyHeight = get_extra_field (L, nExtraStuffArg, " reply_height" );
322
- iMaxReplyLength = get_extra_field (L, nExtraStuffArg, " max_length" );
323
- }
334
+ iBoxWidth = get_extra_integer (L, nExtraStuffArg, " box_width" );
335
+ iBoxHeight = get_extra_integer (L, nExtraStuffArg, " box_height" );
336
+ iPromptWidth = get_extra_integer (L, nExtraStuffArg, " prompt_width" );
337
+ iPromptHeight = get_extra_integer (L, nExtraStuffArg, " prompt_height" );
338
+ iReplyWidth = get_extra_integer (L, nExtraStuffArg, " reply_width" );
339
+ iReplyHeight = get_extra_integer (L, nExtraStuffArg, " reply_height" );
340
+ iMaxReplyLength = get_extra_integer (L, nExtraStuffArg, " max_length" );
341
+ strOKbuttonLabel = get_extra_string (L, nExtraStuffArg, " ok_button" );
342
+ strCancelbuttonLabel = get_extra_string (L, nExtraStuffArg, " cancel_button" );
343
+
344
+
345
+ // see if validation function there - do this last so we can leave it on the stack
346
+ lua_getfield (L, nExtraStuffArg, " validate" );
347
+
348
+ if (!lua_isnil (L, -1 ))
349
+ {
350
+ if (!lua_isfunction (L, -1 ))
351
+ luaL_error (L, " inputbox argument 6 value for 'validate' must be a function" );
352
+
353
+ lua_pushvalue (L, -1 ); // function is now on top of stack
354
+ msg.m_L = L; // non-NULL indicates we have function there
355
+ } // validate function there
356
+
357
+ } // table of extra stuff there
324
358
325
359
// if we leave in & it will make the next letter underlined
326
360
string sInputMsg = FindAndReplace (inputmsg, " &" , " &&" );
@@ -338,13 +372,15 @@ static int gen_inputbox (lua_State *L, T & msg)
338
372
msg.m_iFontSize = inputsize;
339
373
340
374
// extra stuff from table which is argument 6 (if present)
341
- msg.m_iBoxWidth = iBoxWidth ;
342
- msg.m_iBoxHeight = iBoxHeight ;
343
- msg.m_iPromptWidth = iPromptWidth ;
344
- msg.m_iPromptHeight = iPromptHeight;
345
- msg.m_iReplyWidth = iReplyWidth ;
346
- msg.m_iReplyHeight = iReplyHeight ;
347
- msg.m_iMaxReplyLength = iMaxReplyLength;
375
+ msg.m_iBoxWidth = iBoxWidth ;
376
+ msg.m_iBoxHeight = iBoxHeight ;
377
+ msg.m_iPromptWidth = iPromptWidth ;
378
+ msg.m_iPromptHeight = iPromptHeight;
379
+ msg.m_iReplyWidth = iReplyWidth ;
380
+ msg.m_iReplyHeight = iReplyHeight ;
381
+ msg.m_iMaxReplyLength = iMaxReplyLength;
382
+ msg.m_strOKbuttonLabel = strOKbuttonLabel ;
383
+ msg.m_strCancelbuttonLabel = strCancelbuttonLabel;
348
384
349
385
if (msg.DoModal () != IDOK)
350
386
lua_pushnil (L);
0 commit comments