2000-06-12 11:55:12 +00:00
|
|
|
/* input_validators.C
|
|
|
|
* A collection of input filtering and validating functions for use in
|
2001-04-03 14:30:58 +00:00
|
|
|
* XForms dialogs. Mainly meant for filtering input boxes although may
|
2000-06-12 11:55:12 +00:00
|
|
|
* be extended to include other generally useful xforms-specific tools.
|
|
|
|
*/
|
|
|
|
|
2001-03-15 13:37:04 +00:00
|
|
|
#include <config.h>
|
2002-03-11 17:00:41 +00:00
|
|
|
|
|
|
|
|
2000-06-12 11:55:12 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2000-12-06 22:24:17 +00:00
|
|
|
#include "support/lstrings.h"
|
2000-06-12 11:55:12 +00:00
|
|
|
#include "input_validators.h"
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
2001-07-28 12:24:16 +00:00
|
|
|
int fl_int_filter(FL_OBJECT * ob,
|
|
|
|
char const *, char const *, int c)
|
|
|
|
{
|
|
|
|
if (c == 0 /* final test before handing contents to app */
|
|
|
|
|| strchr("0123456789+-", c)) {
|
|
|
|
if (isStrInt(fl_get_input(ob)))
|
|
|
|
return FL_VALID;
|
|
|
|
}
|
|
|
|
return FL_INVALID|FL_RINGBELL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-08 09:37:13 +00:00
|
|
|
int fl_unsigned_int_filter(FL_OBJECT * /*ob*/,
|
2001-07-28 12:24:16 +00:00
|
|
|
char const *, char const *, int c)
|
2000-06-12 11:55:12 +00:00
|
|
|
{
|
2000-06-13 17:10:47 +00:00
|
|
|
if (c == 0 /* final test before handing contents to app */
|
2000-06-12 11:55:12 +00:00
|
|
|
|| strchr("0123456789", c)) {
|
2000-06-13 17:10:47 +00:00
|
|
|
/* since we only accept numerals then it must be valid */
|
2000-11-03 09:47:02 +00:00
|
|
|
return FL_VALID;
|
|
|
|
}
|
|
|
|
return FL_INVALID|FL_RINGBELL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-28 12:24:16 +00:00
|
|
|
int fl_float_filter(FL_OBJECT * ob,
|
|
|
|
char const *, char const *, int c)
|
|
|
|
{
|
|
|
|
if (c == 0 /* final test before handing contents to app */
|
|
|
|
|| strchr("0123456789.+-", c)) {
|
|
|
|
if (isStrDbl(fl_get_input(ob)))
|
|
|
|
return FL_VALID;
|
|
|
|
}
|
|
|
|
return FL_INVALID|FL_RINGBELL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-06 22:24:17 +00:00
|
|
|
int fl_unsigned_float_filter(FL_OBJECT * ob,
|
2001-01-08 09:37:13 +00:00
|
|
|
char const * /*not_used*/,
|
|
|
|
char const * /*unused*/,
|
2000-12-06 22:24:17 +00:00
|
|
|
int c)
|
|
|
|
{
|
|
|
|
if (c == 0 /* final test before handing contents to app */
|
|
|
|
|| strchr("0123456789.", c)) {
|
2001-01-08 09:37:13 +00:00
|
|
|
if (isStrDbl(fl_get_input(ob)))
|
2000-12-06 22:24:17 +00:00
|
|
|
return FL_VALID;
|
|
|
|
}
|
|
|
|
return FL_INVALID|FL_RINGBELL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-08 09:37:13 +00:00
|
|
|
int fl_lowercase_filter(FL_OBJECT * /*ob*/,
|
|
|
|
char const * /*not_used*/,
|
|
|
|
char const * /*unused*/,
|
2000-11-03 09:47:02 +00:00
|
|
|
int c)
|
|
|
|
{
|
|
|
|
if (c == 0 /* final test before handing contents to app */
|
2000-11-08 09:39:46 +00:00
|
|
|
|| strchr("abcdefghijklmnopqrstuvwxyz0123456789", c)) {
|
2000-11-03 09:47:02 +00:00
|
|
|
/* since we only accept numerals then it must be valid */
|
2000-06-12 11:55:12 +00:00
|
|
|
return FL_VALID;
|
|
|
|
}
|
|
|
|
return FL_INVALID|FL_RINGBELL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
2000-06-13 17:10:47 +00:00
|
|
|
/* I've just moved this code here and written a few comments.
|
|
|
|
still to complete it. ARRae 20000518 */
|
|
|
|
|
2000-06-12 11:55:12 +00:00
|
|
|
void fl_print_range_filter(FL_OBJECT * ob,
|
|
|
|
char const * not_used,
|
|
|
|
char const * unused,
|
|
|
|
int c)
|
|
|
|
{
|
2000-06-13 17:10:47 +00:00
|
|
|
/* Started life as changes to PrintApplyCB by Stephan Witt
|
|
|
|
(stephan.witt@beusen.de), 19-Jan-99
|
|
|
|
User may give a page (range) list */
|
2000-06-12 11:55:12 +00:00
|
|
|
|
|
|
|
if (strchr("0123456789", c)) {
|
2000-06-13 17:10:47 +00:00
|
|
|
/* Numerals are always valid */
|
2000-06-12 11:55:12 +00:00
|
|
|
return FL_VALID;
|
|
|
|
} else if (strchr("-,", c)) {
|
2000-06-13 17:10:47 +00:00
|
|
|
/* make sure that the character can go there */
|
2000-06-12 11:55:12 +00:00
|
|
|
} else if (c == 0) {
|
2000-06-13 17:10:47 +00:00
|
|
|
/* final test before handing contents to app
|
|
|
|
make sure the last char isn't a "-,"
|
|
|
|
That might be acceptable if there was a "to_page"
|
|
|
|
entry however if you start making a page range in the "from"
|
|
|
|
field you can do it all in the "from" field. That is, a
|
2002-03-21 21:21:28 +00:00
|
|
|
range in the "from" field immmediately blanks the "to"
|
2000-06-13 17:10:47 +00:00
|
|
|
field. */
|
2000-06-12 11:55:12 +00:00
|
|
|
}
|
|
|
|
return FL_INVALID|FL_RINGBELL;
|
|
|
|
|
2000-06-13 17:10:47 +00:00
|
|
|
/* The code above should do the same sort of checking as the
|
|
|
|
code below. */
|
2000-06-12 11:55:12 +00:00
|
|
|
|
|
|
|
string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
|
2002-07-28 22:50:13 +00:00
|
|
|
pages = trim(subst(pages, '+', ','));
|
|
|
|
|
2000-06-12 11:55:12 +00:00
|
|
|
while (!pages.empty()) { // a page range was given
|
|
|
|
string piece ;
|
|
|
|
pages = split (pages, piece, ',') ;
|
2002-07-28 22:50:13 +00:00
|
|
|
piece = trim(piece);
|
2000-11-04 10:00:12 +00:00
|
|
|
if (!stringOnlyContains (piece, "0123456789-")) {
|
2002-12-27 11:08:10 +00:00
|
|
|
Alert::alert(_("ERROR! Unable to print!"),
|
|
|
|
_("Check `range of pages'!"));
|
2000-06-12 11:55:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (piece.find('-') == string::npos) { // not found
|
|
|
|
pageflag += lyxrc.print_pagerange_flag + piece + '-' + piece + ' ' ;
|
2000-11-04 10:00:12 +00:00
|
|
|
} else if (suffixIs(piece, "-")) { // missing last page
|
2000-06-12 11:55:12 +00:00
|
|
|
pageflag += lyxrc.print_pagerange_flag + piece + "1000 ";
|
2000-11-04 10:00:12 +00:00
|
|
|
} else if (prefixIs(piece, "-")) { // missing first page
|
2000-06-12 11:55:12 +00:00
|
|
|
pageflag += lyxrc.print_pagerange_flag + '1' + piece + ' ' ;
|
|
|
|
} else {
|
|
|
|
pageflag += lyxrc.print_pagerange_flag + piece + ' ' ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
#endif
|
2000-06-12 11:55:12 +00:00
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|