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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [generic/] [tixGrSel.c] - Blame information for rev 1780

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

Line No. Rev Author Line
1 578 markom
/*
2
 * tixGrSel.c --
3
 *
4
 *      This module handles the selection
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
EXTERN TIX_DECLARE_SUBCMD(Tix_GrSelection);
19
static TIX_DECLARE_SUBCMD(Tix_GrSelIncludes);
20
static TIX_DECLARE_SUBCMD(Tix_GrSelModify);
21
 
22
static int              Tix_GrSelIncludes _ANSI_ARGS_((ClientData clientData,
23
                            Tcl_Interp *interp, int argc, char **argv));
24
static void             Tix_GrAdjustSelection _ANSI_ARGS_((
25
                            WidgetPtr wPtr, SelectBlock * sbPtr));
26
static void             Tix_GrMergeSelection _ANSI_ARGS_((
27
                            WidgetPtr wPtr, SelectBlock * sbPtr));
28
static int              Intersect _ANSI_ARGS_((SelectBlock * s1,
29
                            SelectBlock * s2));
30
static int              Include _ANSI_ARGS_((SelectBlock * s1,
31
                            SelectBlock * s2));
32
 
33
int
34
Tix_GrSelection(clientData, interp, argc, argv)
35
    ClientData clientData;
36
    Tcl_Interp *interp;         /* Current interpreter. */
37
    int argc;                   /* Number of arguments. */
38
    char **argv;                /* Argument strings. */
39
{
40
    static Tix_SubCmdInfo subCmdInfo[] = {
41
        {TIX_DEFAULT_LEN, "adjust",   2, 4, Tix_GrSelModify,
42
           "x1 y1 ?x2 y2?"},
43
        {TIX_DEFAULT_LEN, "clear",    2, 4, Tix_GrSelModify,
44
           "x1 y1 ?x2 y2?"},
45
        {TIX_DEFAULT_LEN, "includes", 2, 4, Tix_GrSelIncludes,
46
           "x1 y1 ?x2 y2?"},
47
        {TIX_DEFAULT_LEN, "set",      2, 4, Tix_GrSelModify,
48
           "x1 y1 ?x2 y2?"},
49
        {TIX_DEFAULT_LEN, "toggle",   2, 4, Tix_GrSelModify,
50
           "x1 y1 ?x2 y2?"},
51
    };
52
    static Tix_CmdInfo cmdInfo = {
53
        Tix_ArraySize(subCmdInfo), 1, TIX_VAR_ARGS, "?option? ?arg ...?",
54
    };
55
 
56
    return Tix_HandleSubCmds(&cmdInfo, subCmdInfo, clientData,
57
        interp, argc+1, argv-1);
58
}
59
 
60
static int
61
Tix_GrSelIncludes(clientData, interp, argc, argv)
62
    ClientData clientData;
63
    Tcl_Interp *interp;         /* Current interpreter. */
64
    int argc;                   /* Number of arguments. */
65
    char **argv;                /* Argument strings. */
66
{
67
#if 0
68
    WidgetPtr wPtr = (WidgetPtr) clientData;
69
#endif
70
    return TCL_OK;
71
}
72
 
73
static int Intersect(s1, s2)
74
    SelectBlock * s1;
75
    SelectBlock * s2;
76
{
77
    return 0;
78
}
79
 
80
static int Include(s1, s2)
81
    SelectBlock * s1;
82
    SelectBlock * s2;
83
{
84
    return 0;
85
}
86
 
87
static void
88
Tix_GrMergeSelection(wPtr, sbPtr)
89
    WidgetPtr wPtr;
90
    SelectBlock * sbPtr;
91
{
92
    Tix_ListIterator li;
93
 
94
    switch (sbPtr->type) {
95
      case TIX_GR_SET:
96
      case TIX_GR_CLEAR:
97
        if (sbPtr->range[0][0] == 0 &&
98
            sbPtr->range[1][0] == 0 &&
99
            sbPtr->range[0][1] == TIX_GR_MAX &&
100
            sbPtr->range[1][1] == TIX_GR_MAX) {
101
 
102
            /* clear everything else from the list
103
             */
104
            Tix_SimpleListIteratorInit(&li);
105
 
106
            for (Tix_SimpleListStart(&wPtr->selList, &li);
107
                 !Tix_SimpleListDone(&li);
108
                 Tix_SimpleListNext (&wPtr->selList, &li)) {
109
 
110
                SelectBlock *ptr = (SelectBlock *)li.curr;
111
                Tix_SimpleListDelete(&wPtr->selList, &li);
112
                ckfree((char*)ptr);
113
            }
114
        }
115
        if (sbPtr->type == TIX_GR_SET) {
116
            Tix_SimpleListAppend(&wPtr->selList, (char*)sbPtr, 0);
117
        }
118
        goto done;
119
    }
120
 
121
#if 0
122
 
123
    switch (sbPtr->type) {
124
        case TIX_GR_TOGGLE: {
125
        }
126
        break;
127
        case TIX_GR_SET: {
128
          Tix_SimpleListAppend(&wPtr->selList, (char*)sbPtr, 0);
129
        }
130
        break;
131
        case TIX_GR_CLEAR: {
132
            Tix_SimpleListIteratorInit(&li);
133
 
134
            for (Tix_SimpleListStart(&wPtr->selList, &li);
135
                 !Tix_SimpleListDone(&li);
136
                 Tix_SimpleListNext (&wPtr->selList, &li)) {
137
            }
138
        }
139
 
140
    }
141
#else
142
 
143
    Tix_SimpleListAppend(&wPtr->selList, (char*)sbPtr, 0);
144
 
145
#endif
146
 
147
  done:
148
    Tix_GrAddChangedRect(wPtr, sbPtr->range, 0);
149
}
150
 
151
static void
152
Tix_GrAdjustSelection(wPtr, sbPtr)
153
    WidgetPtr wPtr;
154
    SelectBlock * sbPtr;
155
{
156
    int changed[2][2];
157
    SelectBlock * current;
158
 
159
    current = (SelectBlock*)wPtr->selList.tail;
160
 
161
    /*
162
     * The changed region is the union of the area of the current selection
163
     * and the adjusted selection.
164
     */
165
    changed[TIX_X][0] = sbPtr->range[TIX_X][0];
166
    changed[TIX_X][1] = sbPtr->range[TIX_X][1];
167
    changed[TIX_Y][0] = sbPtr->range[TIX_Y][0];
168
    changed[TIX_Y][1] = sbPtr->range[TIX_Y][1];
169
 
170
    if (changed[TIX_X][0] > current->range[TIX_X][0]) {
171
        changed[TIX_X][0] = current->range[TIX_X][0];
172
    }
173
    if (changed[TIX_X][1] < current->range[TIX_X][1]) {
174
        changed[TIX_X][1] = current->range[TIX_X][1];
175
    }
176
    if (changed[TIX_Y][0] > current->range[TIX_Y][0]) {
177
        changed[TIX_Y][0] = current->range[TIX_Y][0];
178
    }
179
    if (changed[TIX_Y][1] < current->range[TIX_Y][1]) {
180
        changed[TIX_Y][1] = current->range[TIX_Y][1];
181
    }
182
 
183
    /* Adjust the current selection according to sbPtr */
184
    current->range[TIX_X][0] = sbPtr->range[TIX_X][0];
185
    current->range[TIX_X][1] = sbPtr->range[TIX_X][1];
186
    current->range[TIX_Y][0] = sbPtr->range[TIX_Y][0];
187
    current->range[TIX_Y][1] = sbPtr->range[TIX_Y][1];
188
 
189
    /* Set the changed area */
190
    Tix_GrAddChangedRect(wPtr, changed, 0);
191
 
192
    /* sbPtr is no longer needed */
193
    ckfree((char*)sbPtr);
194
}
195
 
196
static int
197
Tix_GrSelModify(clientData, interp, argc, argv)
198
    ClientData clientData;
199
    Tcl_Interp *interp;         /* Current interpreter. */
200
    int argc;                   /* Number of arguments. */
201
    char **argv;                /* Argument strings. */
202
{
203
    WidgetPtr wPtr = (WidgetPtr) clientData;
204
    int type, adjust = 0;
205
    SelectBlock * sbPtr = NULL;
206
    int tmp;
207
 
208
    if (argc != 2 && argc != 4) {
209
        return Tix_ArgcError(interp, argc+2, argv-2, 2, "x1 y1 ?x2 y2?");
210
    }
211
 
212
    /*
213
     * (1) find out the type of operation.
214
     */
215
    if (argv[-1][0] == 'a') {
216
        if (wPtr->selList.numItems <= 0) {
217
            /*
218
             * There is nothing in the selection list to adjust!
219
             */
220
            Tcl_AppendResult(interp, "selection list is empty", NULL);
221
            return TCL_ERROR;
222
        }
223
        adjust = 1;
224
    }
225
    else if (argv[-1][0] == 'c') {
226
        type = TIX_GR_CLEAR;
227
    }
228
    else if (argv[-1][0] == 's') {
229
        type = TIX_GR_SET;
230
    }
231
    else {
232
        type = TIX_GR_TOGGLE;
233
    }
234
 
235
    sbPtr = (SelectBlock*)ckalloc(sizeof(SelectBlock));
236
    sbPtr->type = type;
237
 
238
    if (Tcl_GetInt(interp, argv[0], &sbPtr->range[0][0]) != TCL_OK) {
239
        goto error;
240
    }
241
    if (Tcl_GetInt(interp, argv[1], &sbPtr->range[1][0]) != TCL_OK) {
242
        goto error;
243
    }
244
    if (argc == 4) {
245
        if (Tcl_GetInt(interp, argv[2], &sbPtr->range[0][1]) != TCL_OK) {
246
            if (strcmp(argv[2], "max") == 0) {
247
                Tcl_ResetResult(interp);
248
                sbPtr->range[0][1] = TIX_GR_MAX;
249
            } else {
250
                goto error;
251
            }
252
        }
253
        if (Tcl_GetInt(interp, argv[3], &sbPtr->range[1][1]) != TCL_OK) {
254
            if (strcmp(argv[3], "max") == 0) {
255
                Tcl_ResetResult(interp);
256
                sbPtr->range[1][1] = TIX_GR_MAX;
257
            } else {
258
                goto error;
259
            }
260
        }
261
    } else {
262
        sbPtr->range[0][1] = sbPtr->range[0][0];
263
        sbPtr->range[1][1] = sbPtr->range[1][0];
264
    }
265
 
266
    if (wPtr->selectUnit != tixRowUid) {
267
        if (sbPtr->range[0][0] > sbPtr->range[0][1]) {
268
            tmp = sbPtr->range[0][1];
269
            sbPtr->range[0][1] = sbPtr->range[0][0];
270
            sbPtr->range[0][0] = tmp;
271
        }
272
    } else {
273
        sbPtr->range[0][0] = 0;
274
        sbPtr->range[0][1] = TIX_GR_MAX;
275
    }
276
 
277
    if (wPtr->selectUnit != tixColumnUid) {
278
        if (sbPtr->range[1][0] > sbPtr->range[1][1]) {
279
            tmp = sbPtr->range[1][1];
280
            sbPtr->range[1][1] = sbPtr->range[1][0];
281
            sbPtr->range[1][0] = tmp;
282
        }
283
    } else {
284
        sbPtr->range[1][0] = 0;
285
        sbPtr->range[1][1] = TIX_GR_MAX;
286
    }
287
 
288
    if (adjust) {
289
        Tix_GrAdjustSelection(wPtr, sbPtr);
290
        sbPtr = NULL;
291
    } else {
292
        Tix_GrMergeSelection(wPtr, sbPtr);
293
    }
294
    wPtr->toComputeSel = 1;
295
    return TCL_OK;
296
 
297
  error:
298
    if (sbPtr) {
299
        ckfree((char*)sbPtr);
300
    }
301
    return TCL_ERROR;
302
}

powered by: WebSVN 2.1.0

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