Line data Source code
1 : /* Copyright (C) 2000-2012 by George Williams */
2 : /*
3 : * Redistribution and use in source and binary forms, with or without
4 : * modification, are permitted provided that the following conditions are met:
5 :
6 : * Redistributions of source code must retain the above copyright notice, this
7 : * list of conditions and the following disclaimer.
8 :
9 : * Redistributions in binary form must reproduce the above copyright notice,
10 : * this list of conditions and the following disclaimer in the documentation
11 : * and/or other materials provided with the distribution.
12 :
13 : * The name of the author may not be used to endorse or promote products
14 : * derived from this software without specific prior written permission.
15 :
16 : * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 : * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 : * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 : * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 : * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 : * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 : * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 : * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 : * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 : * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 : */
27 : #include <basics.h>
28 : #include <stdio.h>
29 : #include <stdlib.h>
30 : #include <ggadget.h>
31 : #include "gwidget.h"
32 : #include "ustring.h"
33 :
34 0 : void GGadgetProtest8(char *label) {
35 : char buf[80];
36 :
37 0 : snprintf( buf, sizeof(buf),_("Bad Number in %s"), label);
38 0 : if ( buf[strlen(buf)-1]==' ' )
39 0 : buf[strlen(buf)-1]='\0';
40 0 : if ( buf[strlen(buf)-1]==':' )
41 0 : buf[strlen(buf)-1]='\0';
42 0 : gwwv_post_notice(buf,buf);
43 0 : }
44 :
45 0 : double GetCalmReal8(GWindow gw,int cid,char *name,int *err) {
46 : char *txt, *end;
47 : double val;
48 :
49 0 : txt = GGadgetGetTitle8(GWidgetGetControl(gw,cid));
50 0 : val = strtod(txt,&end);
51 0 : if ( (*txt=='-' || *txt=='.') && end==txt && txt[1]=='\0' )
52 0 : end = txt+1;
53 0 : else if ( *txt=='-' && txt[1]=='.' && txt[2]=='\0' )
54 0 : end = txt+2;
55 0 : if ( *end!='\0' ) {
56 0 : GDrawBeep(NULL);
57 0 : *err = true;
58 : }
59 0 : free(txt);
60 0 : return( val );
61 : }
62 :
63 0 : double GetReal8(GWindow gw,int cid,char *name,int *err) {
64 : char *txt, *end;
65 : double val;
66 :
67 0 : txt = GGadgetGetTitle8(GWidgetGetControl(gw,cid));
68 0 : val = strtod(txt,&end);
69 0 : if ( *end!='\0' ) {
70 0 : GTextFieldSelect(GWidgetGetControl(gw,cid),0,-1);
71 0 : GGadgetProtest8(name);
72 0 : *err = true;
73 : }
74 0 : free(txt);
75 0 : return( val );
76 : }
77 :
78 0 : int GetCalmInt8(GWindow gw,int cid,char *name,int *err) {
79 : char *txt, *end;
80 : int val;
81 :
82 0 : txt = GGadgetGetTitle8(GWidgetGetControl(gw,cid));
83 0 : val = strtol(txt,&end,10);
84 0 : if ( *txt=='-' && end==txt && txt[1]=='\0' )
85 0 : end = txt+1;
86 0 : if ( *end!='\0' ) {
87 0 : GDrawBeep(NULL);
88 0 : *err = true;
89 : }
90 0 : free(txt);
91 0 : return( val );
92 : }
93 :
94 0 : int GetInt8(GWindow gw,int cid,char *name,int *err) {
95 : char *txt, *end;
96 : int val;
97 :
98 0 : txt = GGadgetGetTitle8(GWidgetGetControl(gw,cid));
99 0 : val = strtol(txt,&end,10);
100 0 : if ( *end!='\0' ) {
101 0 : GTextFieldSelect(GWidgetGetControl(gw,cid),0,-1);
102 0 : GGadgetProtest8(name);
103 0 : *err = true;
104 : }
105 0 : free(txt);
106 0 : return( val );
107 : }
108 :
109 0 : int GetUnicodeChar8(GWindow gw,int cid,char *name,int *err) {
110 : char *txt, *end, *pt;
111 : int val;
112 : const unichar_t *utxt;
113 :
114 0 : utxt = _GGadgetGetTitle(GWidgetGetControl(gw,cid));
115 0 : if ( u_strlen(utxt)==1 )
116 0 : return( utxt[0] );
117 :
118 0 : txt = GGadgetGetTitle8(GWidgetGetControl(gw,cid));
119 0 : val = strtol(txt,&end,16);
120 0 : if ( *end!='\0' ) {
121 0 : for ( pt=txt; *pt==' '; ++pt );
122 0 : if ( (*pt=='U' || *pt=='u') && pt[1]=='+' ) { /* Unicode notation */
123 0 : pt += 2;
124 0 : val = strtol(pt,&end,16);
125 0 : if ( *end!='\0' ) {
126 0 : GTextFieldSelect(GWidgetGetControl(gw,cid),0,-1);
127 0 : GGadgetProtest8(name);
128 0 : *err = true;
129 : }
130 : }
131 : }
132 0 : free(txt);
133 0 : return( val );
134 : }
|