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