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