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