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