]> git.lyx.org Git - features.git/blob - src/frontends/xforms/input_validators.C
introduce namespace lyx::support
[features.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
10 #include "lyx_forms.h"
11 #include "support/lstrings.h"
12 #include "input_validators.h"
13
14 using namespace lyx::support;
15
16 #if defined(__cplusplus)
17 extern "C"
18 {
19 #endif
20
21 int fl_int_filter(FL_OBJECT * ob,
22                   char const *, char const *, int c)
23 {
24         if (c == 0 /* final test before handing contents to app */
25             || strchr("0123456789+-", c)) {
26                 if (isStrInt(fl_get_input(ob)))
27                         return FL_VALID;
28         }
29         return FL_INVALID|FL_RINGBELL;
30 }
31
32
33 int fl_unsigned_int_filter(FL_OBJECT * /*ob*/,
34                            char const *, char const *, int c)
35 {
36         if (c == 0 /* final test before handing contents to app */
37             || strchr("0123456789", c)) {
38                 /* since we only accept numerals then it must be valid */
39                 return FL_VALID;
40         }
41         return FL_INVALID|FL_RINGBELL;
42 }
43
44
45 int fl_float_filter(FL_OBJECT * ob,
46                     char const *, char const *, int c)
47 {
48         if (c == 0 /* final test before handing contents to app */
49             || strchr("0123456789.+-", c)) {
50                 if (isStrDbl(fl_get_input(ob)))
51                         return FL_VALID;
52         }
53         return FL_INVALID|FL_RINGBELL;
54 }
55
56
57 int fl_unsigned_float_filter(FL_OBJECT * ob,
58                              char const * /*not_used*/,
59                              char const * /*unused*/,
60                              int c)
61 {
62         if (c == 0 /* final test before handing contents to app */
63             || strchr("0123456789.", c)) {
64                 if (isStrDbl(fl_get_input(ob)))
65                         return FL_VALID;
66         }
67         return FL_INVALID|FL_RINGBELL;
68 }
69
70
71 int fl_lowercase_filter(FL_OBJECT * /*ob*/,
72                         char const * /*not_used*/,
73                         char const * /*unused*/,
74                         int c)
75 {
76         if (c == 0 /* final test before handing contents to app */
77             || strchr("abcdefghijklmnopqrstuvwxyz0123456789", c)) {
78                 /* since we only accept numerals then it must be valid */
79                 return FL_VALID;
80         }
81         return FL_INVALID|FL_RINGBELL;
82 }
83
84
85 #if defined(__cplusplus)
86 }
87 #endif