]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/input_validators.c
major GUII cleanup + Baruchs patch + Angus's patch + removed a couple of generated...
[lyx.git] / src / frontends / xforms / input_validators.c
1 /* input_validators.C
2  * A collection of input filtering and validating functions for use in
3  * XForms popups.  Mainly meant for filtering input boxes although may
4  * be extended to include other generally useful xforms-specific tools.
5  */
6
7 #include "config.h"
8 #include FORMS_H_LOCATION
9 #include "input_validators.h"
10
11 #if defined(__cplusplus)
12 extern "C"
13 {
14 #endif
15
16 int fl_unsigned_int_filter(FL_OBJECT * ob,
17                            char const * not_used,
18                            char const * unused,
19                            int c)
20 {
21         if (c == 0 /* final test before handing contents to app */
22             || strchr("0123456789", c)) {
23                 /* since we only accept numerals then it must be valid */
24                 return FL_VALID;
25         }
26         return FL_INVALID|FL_RINGBELL;
27 }
28
29
30 #if 0
31 /* I've just moved this code here and written a few comments.
32    still to complete it.  ARRae 20000518 */
33
34 void fl_print_range_filter(FL_OBJECT * ob,
35                            char const * not_used,
36                            char const * unused,
37                            int c)
38 {
39         /* Started life as changes to PrintApplyCB by Stephan Witt
40            (stephan.witt@beusen.de), 19-Jan-99
41            User may give a page (range) list */
42
43         if (strchr("0123456789", c)) {
44                 /* Numerals are always valid */
45                 return FL_VALID;
46         } else if (strchr("-,", c)) {
47                 /* make sure that the character can go there */
48         } else if (c == 0) {
49                 /* final test before handing contents to app
50                    make sure the last char isn't a "-,"
51                    That might be acceptable if there was a "to_page"
52                    entry however if you start making a page range in the "from"
53                    field you can do it all in the "from" field.  That is, a
54                    range in the "from" field immmediately blanks the "to" 
55                    field. */
56         }
57         return FL_INVALID|FL_RINGBELL;
58
59         /* The code above should do the same sort of checking as the
60            code below. */
61
62         string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
63         pages = subst(pages, '+',',');
64         pages = frontStrip(strip(pages)) ;
65         while (!pages.empty()) { // a page range was given
66                 string piece ;
67                 pages = split (pages, piece, ',') ;
68                 piece = strip(piece) ;
69                 piece = frontStrip(piece) ;
70                 if ( !stringOnlyContains (piece, "0123456789-") ) {
71                         WriteAlert(_("ERROR!  Unable to print!"),
72                                    _("Check 'range of pages'!"));
73                         return;
74                 }
75                 if (piece.find('-') == string::npos) { // not found
76                         pageflag += lyxrc.print_pagerange_flag + piece + '-' + piece + ' ' ;
77                 } else if (suffixIs(piece, "-") ) { // missing last page
78                         pageflag += lyxrc.print_pagerange_flag + piece + "1000 ";
79                 } else if (prefixIs(piece, "-") ) { // missing first page
80                         pageflag += lyxrc.print_pagerange_flag + '1' + piece + ' ' ;
81                 } else {
82                         pageflag += lyxrc.print_pagerange_flag + piece + ' ' ;
83                 }
84         }
85 }
86 #endif 
87
88 #if defined(__cplusplus)
89 }
90 #endif