OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [generic/] [tixGrUtl.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tixGrUtl.c --
3
 *
4
 *      Utility functions for Grid
5
 *
6
 * Copyright (c) 1996, Expert Interface Technologies
7
 *
8
 * See the file "license.terms" for information on usage and redistribution
9
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
 *
11
 */
12
 
13
#include <tixPort.h>
14
#include <tixInt.h>
15
#include <tixDef.h>
16
#include <tixGrid.h>
17
 
18
#ifndef UCHAR
19
#define UCHAR(c) ((unsigned char) (c))
20
#endif
21
 
22
/* string must be a real number plus "char". E.g, "3.0char" */
23
int
24
Tix_GetChars(interp, string, doublePtr)
25
    Tcl_Interp *interp;         /* Use this for error reporting. */
26
    char *string;               /* String describing a justification style. */
27
    double *doublePtr;          /* Place to store converted result. */
28
{
29
    char *end;
30
    double d;
31
 
32
    d = strtod(string, &end);
33
    if (end == string) {
34
        goto error;
35
    }
36
    while ((*end != '\0') && isspace(*end)) {
37
        end++;
38
    }
39
    if (strncmp(end, "char", 4) != 0) {
40
        goto error;
41
    }
42
    for (end+=4; (*end != '\0') && isspace(UCHAR(*end)); end++) {
43
        ;
44
    }
45
    if (*end != '\0') {
46
        goto error;
47
    }
48
    if (d < 0) {
49
        goto error;
50
    }
51
 
52
    *doublePtr = d;
53
    return TCL_OK;
54
 
55
  error:
56
    Tcl_AppendResult(interp, "bad screen distance \"", string,
57
        "\"", (char *) NULL);
58
    return TCL_ERROR;
59
}
60
 
61
 
62
int Tix_GrConfigSize(interp, wPtr, argc, argv, sizePtr, argcErrorMsg,
63
        changed_ret)
64
    Tcl_Interp *interp;
65
    WidgetPtr wPtr;
66
    int argc;
67
    char **argv;
68
    TixGridSize *sizePtr;
69
    char * argcErrorMsg;
70
    int *changed_ret;
71
{
72
    int pixels;
73
    double chars;
74
    int i;
75
    TixGridSize newSize;
76
    int changed = 0;
77
 
78
    if (argc == 0) {
79
        char buff[40];
80
 
81
        Tcl_AppendResult(interp, "-size ", NULL);
82
 
83
        switch (sizePtr->sizeType) {
84
          case TIX_GR_AUTO:
85
            Tcl_AppendResult(interp, "auto", NULL);
86
            break;
87
 
88
          case TIX_GR_DEFAULT:
89
            Tcl_AppendResult(interp, "default", NULL);
90
            break;
91
 
92
          case TIX_GR_DEFINED_PIXEL:
93
            sprintf(buff, "%d", sizePtr->sizeValue);
94
            Tcl_AppendResult(interp, buff, NULL);
95
            break;
96
 
97
          case TIX_GR_DEFINED_CHAR:
98
            sprintf(buff, "%fchar", sizePtr->charValue);
99
            Tcl_AppendResult(interp, buff, NULL);
100
            break;
101
 
102
          default:
103
            Tcl_AppendResult(interp, "default", NULL);
104
            break;
105
        }
106
 
107
        Tcl_AppendResult(interp, " -pad0 ", NULL);
108
        sprintf(buff, "%d", sizePtr->pad0);
109
        Tcl_AppendResult(interp, buff, NULL);
110
 
111
        Tcl_AppendResult(interp, " -pad1 ", NULL);
112
        sprintf(buff, "%d", sizePtr->pad1);
113
        Tcl_AppendResult(interp, buff, NULL);
114
 
115
        return TCL_OK;
116
    }
117
 
118
    if ((argc %2) != 0) {
119
        Tcl_AppendResult(interp, "value missing for option \"",
120
            argv[argc-1], "\"", NULL);
121
        return TCL_ERROR;
122
    }
123
 
124
    newSize = *sizePtr;
125
 
126
    for (i=0; i<argc; i+=2) {
127
 
128
        if (strncmp("-size", argv[i], strlen(argv[i])) == 0) {
129
            if (strcmp(argv[i+1], "auto")==0) {
130
                newSize.sizeType  = TIX_GR_AUTO;
131
                newSize.sizeValue = 0;
132
            }
133
            else if (strcmp(argv[i+1], "default")==0) {
134
                newSize.sizeType  = TIX_GR_DEFAULT;
135
                newSize.sizeValue = 0;
136
            }
137
            else if (Tk_GetPixels(interp, wPtr->dispData.tkwin, argv[i+1],
138
                 &pixels) == TCL_OK) {
139
 
140
                newSize.sizeType  = TIX_GR_DEFINED_PIXEL;
141
                newSize.sizeValue = pixels;
142
            }
143
            else {
144
                Tcl_ResetResult(interp);
145
                if (Tix_GetChars(interp, argv[i+1], &chars) == TCL_OK) {
146
                    newSize.sizeType  = TIX_GR_DEFINED_CHAR;
147
                    newSize.charValue = chars;
148
                }
149
                else {
150
                    return TCL_ERROR;
151
                }
152
            }
153
        }
154
        else if (strcmp("-pad0", argv[i]) == 0) {
155
            if (Tk_GetPixels(interp, wPtr->dispData.tkwin, argv[i+1],
156
                 &pixels) == TCL_OK) {
157
 
158
                newSize.pad0 = pixels;
159
            }
160
            else {
161
                return TCL_ERROR;
162
            }
163
        }
164
        else if (strcmp("-pad1", argv[i]) == 0) {
165
            if (Tk_GetPixels(interp, wPtr->dispData.tkwin, argv[i+1],
166
                 &pixels) == TCL_OK) {
167
 
168
                newSize.pad1 = pixels;
169
            }
170
            else {
171
                return TCL_ERROR;
172
            }
173
        }
174
        else {
175
            Tcl_AppendResult(interp, "Unknown option \"", argv[i],
176
                "\"; must be -pad0, -pad1 or -size", NULL);
177
            return TCL_ERROR;
178
        }
179
    }
180
 
181
    if (changed_ret) {
182
        if (sizePtr->sizeType  != newSize.sizeType) {
183
            changed = 1;
184
        }
185
        if (sizePtr->sizeValue != newSize.sizeValue) {
186
            changed = 1;
187
        }
188
        if (sizePtr->charValue != newSize.charValue) {
189
            changed = 1;
190
        }
191
        if (sizePtr->pad1      != newSize.pad0) {
192
            changed = 1;
193
        }
194
        if (sizePtr->pad1      != newSize.pad1) {
195
            changed = 1;
196
        }
197
        *changed_ret = changed;
198
    }
199
 
200
    *sizePtr = newSize;
201
    return TCL_OK;
202
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.