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