]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/input_validators.C
more fixes read ChangeLog
[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 "support/lstrings.h"
10 #include "input_validators.h"
11
12 #if defined(__cplusplus)
13 extern "C"
14 {
15 #endif
16
17 int fl_unsigned_int_filter(FL_OBJECT * ob,
18                            char const * not_used,
19                            char const * unused,
20                            int c)
21 {
22         if (c == 0 /* final test before handing contents to app */
23             || strchr("0123456789", c)) {
24                 /* since we only accept numerals then it must be valid */
25                 return FL_VALID;
26         }
27         return FL_INVALID|FL_RINGBELL;
28 }
29
30
31 int fl_unsigned_float_filter(FL_OBJECT * ob,
32                              char const * not_used,
33                              char const * unused,
34                              int c)
35 {
36         if (c == 0 /* final test before handing contents to app */
37             || strchr("0123456789.", c)) {
38                 if ( isStrDbl(fl_get_input(ob)) )
39                         return FL_VALID;
40                 else
41                         return FL_INVALID|FL_RINGBELL;
42         }
43         return FL_INVALID|FL_RINGBELL;
44 }
45
46
47 int fl_lowercase_filter(FL_OBJECT * ob,
48                         char const * not_used,
49                         char const * unused,
50                         int c)
51 {
52         if (c == 0 /* final test before handing contents to app */
53             || strchr("abcdefghijklmnopqrstuvwxyz0123456789", c)) {
54                 /* since we only accept numerals then it must be valid */
55                 return FL_VALID;
56         }
57         return FL_INVALID|FL_RINGBELL;
58 }
59
60
61 #if 0
62 /* I've just moved this code here and written a few comments.
63    still to complete it.  ARRae 20000518 */
64
65 void fl_print_range_filter(FL_OBJECT * ob,
66                            char const * not_used,
67                            char const * unused,
68                            int c)
69 {
70         /* Started life as changes to PrintApplyCB by Stephan Witt
71            (stephan.witt@beusen.de), 19-Jan-99
72            User may give a page (range) list */
73
74         if (strchr("0123456789", c)) {
75                 /* Numerals are always valid */
76                 return FL_VALID;
77         } else if (strchr("-,", c)) {
78                 /* make sure that the character can go there */
79         } else if (c == 0) {
80                 /* final test before handing contents to app
81                    make sure the last char isn't a "-,"
82                    That might be acceptable if there was a "to_page"
83                    entry however if you start making a page range in the "from"
84                    field you can do it all in the "from" field.  That is, a
85                    range in the "from" field immmediately blanks the "to" 
86                    field. */
87         }
88         return FL_INVALID|FL_RINGBELL;
89
90         /* The code above should do the same sort of checking as the
91            code below. */
92
93         string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
94         pages = subst(pages, '+',',');
95         pages = frontStrip(strip(pages)) ;
96         while (!pages.empty()) { // a page range was given
97                 string piece ;
98                 pages = split (pages, piece, ',') ;
99                 piece = strip(piece) ;
100                 piece = frontStrip(piece) ;
101                 if (!stringOnlyContains (piece, "0123456789-")) {
102                         WriteAlert(_("ERROR!  Unable to print!"),
103                                    _("Check 'range of pages'!"));
104                         return;
105                 }
106                 if (piece.find('-') == string::npos) { // not found
107                         pageflag += lyxrc.print_pagerange_flag + piece + '-' + piece + ' ' ;
108                 } else if (suffixIs(piece, "-")) { // missing last page
109                         pageflag += lyxrc.print_pagerange_flag + piece + "1000 ";
110                 } else if (prefixIs(piece, "-")) { // missing first page
111                         pageflag += lyxrc.print_pagerange_flag + '1' + piece + ' ' ;
112                 } else {
113                         pageflag += lyxrc.print_pagerange_flag + piece + ' ' ;
114                 }
115         }
116 }
117 #endif 
118
119 #if defined(__cplusplus)
120 }
121 #endif