Debian Codegraph @

gdraw/ctlvalues.c

raw symbols SCIP
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
28 #include <fontforge-config.h>
29
30 #include "basics.h"
31 #include "ggadget.h"
32 #include "gwidget.h"
33 #include "ustring.h"
34
35 void GGadgetProtest8(const char *label) {
36 char buf[80];
37
38 snprintf( buf, sizeof(buf),_("Bad Number in %s"), label);
39 if ( buf[strlen(buf)-1]==' ' )
40 buf[strlen(buf)-1]='\0';
41 if ( buf[strlen(buf)-1]==':' )
42 buf[strlen(buf)-1]='\0';
43 gwwv_post_notice(buf,buf);
44 }
45
46 double GetCalmReal8(GWindow gw,int cid,char *name,int *err) {
47 char *txt, *end;
48 double val;
49
50 txt = GGadgetGetTitle8(GWidgetGetControl(gw,cid));
51 val = strtod(txt,&end);
52 if ( (*txt=='-' || *txt=='.') && end==txt && txt[1]=='\0' )
53 end = txt+1;
54 else if ( *txt=='-' && txt[1]=='.' && txt[2]=='\0' )
55 end = txt+2;
56 if ( *end!='\0' ) {
57 GDrawBeep(NULL);
58 *err = true;
59 }
60 free(txt);
61 return( val );
62 }
63
64 double GetReal8(GWindow gw,int cid,char *name,int *err) {
65 char *txt, *end;
66 double val;
67
68 txt = GGadgetGetTitle8(GWidgetGetControl(gw,cid));
69 val = strtod(txt,&end);
70 if ( *end!='\0' ) {
71 GTextFieldSelect(GWidgetGetControl(gw,cid),0,-1);
72 GGadgetProtest8(name);
73 *err = true;
74 }
75 free(txt);
76 return( val );
77 }
78
79 int GetCalmInt8(GWindow gw,int cid,char *name,int *err) {
80 char *txt, *end;
81 int val;
82
83 txt = GGadgetGetTitle8(GWidgetGetControl(gw,cid));
84 val = strtol(txt,&end,10);
85 if ( *txt=='-' && end==txt && txt[1]=='\0' )
86 end = txt+1;
87 if ( *end!='\0' ) {
88 GDrawBeep(NULL);
89 *err = true;
90 }
91 free(txt);
92 return( val );
93 }
94
95 int GetInt8(GWindow gw,int cid,char *name,int *err) {
96 char *txt, *end;
97 int val;
98
99 txt = GGadgetGetTitle8(GWidgetGetControl(gw,cid));
100 val = strtol(txt,&end,10);
101 if ( *end!='\0' ) {
102 GTextFieldSelect(GWidgetGetControl(gw,cid),0,-1);
103 GGadgetProtest8(name);
104 *err = true;
105 }
106 free(txt);
107 return( val );
108 }
109
110 int GetUnicodeChar8(GWindow gw,int cid,char *name,int *err) {
111 char *txt, *end, *pt;
112 int val;
113 const unichar_t *utxt;
114
115 utxt = _GGadgetGetTitle(GWidgetGetControl(gw,cid));
116 if ( u_strlen(utxt)==1 )
117 return( utxt[0] );
118
119 txt = GGadgetGetTitle8(GWidgetGetControl(gw,cid));
120 val = strtol(txt,&end,16);
121 if ( *end!='\0' ) {
122 for ( pt=txt; *pt==' '; ++pt );
123 if ( (*pt=='U' || *pt=='u') && pt[1]=='+' ) { /* Unicode notation */
124 pt += 2;
125 val = strtol(pt,&end,16);
126 if ( *end!='\0' ) {
127 GTextFieldSelect(GWidgetGetControl(gw,cid),0,-1);
128 GGadgetProtest8(name);
129 *err = true;
130 }
131 }
132 }
133 free(txt);
134 return( val );
135 }