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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [tix/] [generic/] [tixHLCol.c] - Blame information for rev 578

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

Line No. Rev Author Line
1 578 markom
/*
2
 *  tixHLCol.c ---
3
 *
4
 *
5
 *      Implements columns inside tixHList widgets
6
 *
7
 * Copyright (c) 1996, Expert Interface Technologies
8
 *
9
 * See the file "license.terms" for information on usage and redistribution
10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
 *
12
 */
13
 
14
#include <tixPort.h>
15
#include <tixInt.h>
16
#include <tixHList.h>
17
 
18
static TIX_DECLARE_SUBCMD(Tix_HLItemCreate);
19
static TIX_DECLARE_SUBCMD(Tix_HLItemConfig);
20
static TIX_DECLARE_SUBCMD(Tix_HLItemCGet);
21
static TIX_DECLARE_SUBCMD(Tix_HLItemDelete);
22
static TIX_DECLARE_SUBCMD(Tix_HLItemExists);
23
 
24
static TIX_DECLARE_SUBCMD(Tix_HLColWidth);
25
 
26
static HListElement *   Tix_HLGetColumn _ANSI_ARGS_((Tcl_Interp *interp,
27
                            WidgetPtr wPtr, char ** argv, int * column_ret,
28
                            int mustExist));
29
 
30
HListColumn *
31
Tix_HLAllocColumn(wPtr, chPtr)
32
    WidgetPtr wPtr;
33
    HListElement * chPtr;
34
{
35
    HListColumn * column;
36
    int i;
37
 
38
    column =
39
      (HListColumn*)ckalloc(sizeof(HListColumn)*wPtr->numColumns);
40
    for (i=0; i<wPtr->numColumns; i++) {
41
        column[i].type = HLTYPE_COLUMN;
42
        column[i].self = (char*)&column[i];
43
        column[i].chPtr = chPtr;
44
        column[i].iPtr = NULL;
45
        column[i].iPtr = NULL;
46
        column[i].width = UNINITIALIZED;
47
    }
48
    return column;
49
}
50
 
51
static HListElement *
52
Tix_HLGetColumn(interp, wPtr, argv, column_ret, mustExist)
53
    Tcl_Interp *interp;
54
    WidgetPtr wPtr;
55
    char ** argv;
56
    int * column_ret;
57
    int mustExist;
58
{
59
    HListElement * chPtr;
60
    int column;
61
 
62
    if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[0])) == NULL) {
63
        return NULL;
64
    }
65
    if (Tcl_GetInt(interp, argv[1], &column) != TCL_OK) {
66
        return NULL;
67
    }
68
    if (column >= wPtr->numColumns || column < 0) {
69
        Tcl_AppendResult(interp, "Column \"", argv[1],
70
            "\" does not exist", (char*)NULL);
71
        return NULL;
72
    }
73
    if (mustExist && chPtr->col[column].iPtr == NULL) {
74
        Tcl_AppendResult(interp, "entry \"", argv[0],
75
            "\" does not have an item at column ", argv[1], NULL);
76
        return NULL;
77
    }
78
 
79
    * column_ret = column;
80
    return chPtr;
81
}
82
 
83
/*----------------------------------------------------------------------
84
 * "item" sub command
85
 *----------------------------------------------------------------------
86
 */
87
int
88
Tix_HLItem(clientData, interp, argc, argv)
89
    ClientData clientData;
90
    Tcl_Interp *interp;         /* Current interpreter. */
91
    int argc;                   /* Number of arguments. */
92
    char **argv;                /* Argument strings. */
93
{
94
    static Tix_SubCmdInfo subCmdInfo[] = {
95
        {TIX_DEFAULT_LEN, "cget", 3, 3, Tix_HLItemCGet,
96
           "entryPath column option"},
97
        {TIX_DEFAULT_LEN, "configure", 2, TIX_VAR_ARGS, Tix_HLItemConfig,
98
           "entryPath column ?option? ?value ...?"},
99
        {TIX_DEFAULT_LEN, "create", 2, TIX_VAR_ARGS, Tix_HLItemCreate,
100
           "entryPath column ?option value ...?"},
101
        {TIX_DEFAULT_LEN, "delete", 2, 2, Tix_HLItemDelete,
102
           "entryPath column"},
103
        {TIX_DEFAULT_LEN, "exists", 2, 2, Tix_HLItemExists,
104
           "entryPath column"},
105
    };
106
    static Tix_CmdInfo cmdInfo = {
107
        Tix_ArraySize(subCmdInfo), 1, TIX_VAR_ARGS, "?option? ?arg ...?",
108
    };
109
 
110
    return Tix_HandleSubCmds(&cmdInfo, subCmdInfo, clientData,
111
        interp, argc+1, argv-1);
112
}
113
 
114
/*----------------------------------------------------------------------
115
 * "item cget" sub command
116
 *----------------------------------------------------------------------
117
 */
118
static int
119
Tix_HLItemCGet(clientData, interp, argc, argv)
120
    ClientData clientData;
121
    Tcl_Interp *interp;         /* Current interpreter. */
122
    int argc;                   /* Number of arguments. */
123
    char **argv;                /* Argument strings. */
124
{
125
    WidgetPtr wPtr = (WidgetPtr) clientData;
126
    HListElement * chPtr;
127
    int column;
128
 
129
    if ((chPtr=Tix_HLGetColumn(interp, wPtr, argv, &column, 1)) == NULL) {
130
        return TCL_ERROR;
131
    }
132
 
133
    return Tk_ConfigureValue(interp, wPtr->dispData.tkwin,
134
        chPtr->col[column].iPtr->base.diTypePtr->itemConfigSpecs,
135
        (char *)chPtr->col[column].iPtr, argv[2], 0);
136
}
137
 
138
/*----------------------------------------------------------------------
139
 * "item configure" sub command
140
 *----------------------------------------------------------------------
141
 */
142
static int
143
Tix_HLItemConfig(clientData, interp, argc, argv)
144
    ClientData clientData;
145
    Tcl_Interp *interp;         /* Current interpreter. */
146
    int argc;                   /* Number of arguments. */
147
    char **argv;                /* Argument strings. */
148
{
149
    WidgetPtr wPtr = (WidgetPtr) clientData;
150
    HListElement * chPtr;
151
    int column;
152
 
153
    if ((chPtr=Tix_HLGetColumn(interp, wPtr, argv, &column, 1)) == NULL) {
154
        return TCL_ERROR;
155
    }
156
 
157
    if (argc == 2) {
158
        return Tk_ConfigureInfo(interp, wPtr->dispData.tkwin,
159
            chPtr->col[column].iPtr->base.diTypePtr->itemConfigSpecs,
160
            (char *)chPtr->col[column].iPtr, NULL, 0);
161
    } else if (argc == 3) {
162
        return Tk_ConfigureInfo(interp, wPtr->dispData.tkwin,
163
            chPtr->col[column].iPtr->base.diTypePtr->itemConfigSpecs,
164
            (char *)chPtr->col[column].iPtr, argv[2], 0);
165
    } else {
166
        Tix_HLMarkElementDirty(wPtr, chPtr);
167
        Tix_HLResizeWhenIdle(wPtr);
168
 
169
        return Tix_DItemConfigure(chPtr->col[column].iPtr,
170
            argc-2, argv+2, TK_CONFIG_ARGV_ONLY);
171
    }
172
}
173
 
174
/*----------------------------------------------------------------------
175
 * "item create" sub command
176
 *----------------------------------------------------------------------
177
 */
178
static int
179
Tix_HLItemCreate(clientData, interp, argc, argv)
180
    ClientData clientData;
181
    Tcl_Interp *interp;         /* Current interpreter. */
182
    int argc;                   /* Number of arguments. */
183
    char **argv;                /* Argument strings. */
184
{
185
    WidgetPtr wPtr = (WidgetPtr) clientData;
186
    HListElement * chPtr;
187
    int column, i;
188
    size_t len;
189
    Tix_DItem * iPtr;
190
    char * ditemType = NULL;
191
 
192
    if ((chPtr=Tix_HLGetColumn(interp, wPtr, argv, &column, 0)) == NULL) {
193
        return TCL_ERROR;
194
    }
195
 
196
    if (argc %2) {
197
        Tcl_AppendResult(interp, "value for \"", argv[argc-1],
198
            "\" missing", NULL);
199
        return TCL_ERROR;
200
    }
201
    for (i=2; i<argc; i+=2) {
202
        len = strlen(argv[i]);
203
        if (strncmp(argv[i], "-itemtype", len) == 0) {
204
            ditemType = argv[i+1];
205
        }
206
    }
207
    if (ditemType == NULL) {
208
        ditemType = wPtr->diTypePtr->name;
209
    }
210
 
211
    iPtr = Tix_DItemCreate(&wPtr->dispData, ditemType);
212
    if (iPtr == NULL) {
213
        return TCL_ERROR;
214
    }
215
 
216
    iPtr->base.clientData = (ClientData)&chPtr->col[column];
217
    if (Tix_DItemConfigure(iPtr, argc-2, argv+2, 0) != TCL_OK) {
218
        return TCL_ERROR;
219
    }
220
 
221
    if (chPtr->col[column].iPtr != NULL) {
222
        if (Tix_DItemType(chPtr->col[column].iPtr) == TIX_DITEM_WINDOW) {
223
            Tix_WindowItemListRemove(&wPtr->mappedWindows,
224
                chPtr->col[column].iPtr);
225
        }
226
        Tix_DItemFree(chPtr->col[column].iPtr);
227
    }
228
    chPtr->col[column].iPtr = iPtr;
229
    Tix_HLMarkElementDirty(wPtr, chPtr);
230
    Tix_HLResizeWhenIdle(wPtr);
231
 
232
    return TCL_OK;
233
}
234
/*----------------------------------------------------------------------
235
 * "item delete" sub command
236
 *----------------------------------------------------------------------
237
 */
238
static int
239
Tix_HLItemDelete(clientData, interp, argc, argv)
240
    ClientData clientData;
241
    Tcl_Interp *interp;         /* Current interpreter. */
242
    int argc;                   /* Number of arguments. */
243
    char **argv;                /* Argument strings. */
244
{
245
    WidgetPtr wPtr = (WidgetPtr) clientData;
246
    HListElement * chPtr;
247
    int column;
248
 
249
    if ((chPtr=Tix_HLGetColumn(interp, wPtr, argv, &column, 1)) == NULL) {
250
        return TCL_ERROR;
251
    }
252
 
253
    if (column == 0) {
254
        Tcl_AppendResult(interp,"Cannot delete item at column 0",(char*)NULL);
255
        return TCL_ERROR;
256
    }
257
 
258
    if (Tix_DItemType(chPtr->col[column].iPtr) == TIX_DITEM_WINDOW) {
259
        Tix_WindowItemListRemove(&wPtr->mappedWindows,
260
            chPtr->col[column].iPtr);
261
    }
262
 
263
    /* Free the item and leave a blank */
264
    Tix_DItemFree(chPtr->col[column].iPtr);
265
    chPtr->col[column].iPtr = NULL;
266
 
267
    Tix_HLMarkElementDirty(wPtr, chPtr);
268
    Tix_HLResizeWhenIdle(wPtr);
269
 
270
    return TCL_OK;
271
}
272
 
273
/*----------------------------------------------------------------------
274
 * "item exists" sub command
275
 *----------------------------------------------------------------------
276
 */
277
static int
278
Tix_HLItemExists(clientData, interp, argc, argv)
279
    ClientData clientData;
280
    Tcl_Interp *interp;         /* Current interpreter. */
281
    int argc;                   /* Number of arguments. */
282
    char **argv;                /* Argument strings. */
283
{
284
    WidgetPtr wPtr = (WidgetPtr) clientData;
285
    HListElement * chPtr;
286
    int column;
287
 
288
    if ((chPtr=Tix_HLGetColumn(interp, wPtr, argv, &column, 0)) == NULL) {
289
        return TCL_ERROR;
290
    }
291
 
292
    if (chPtr->col[column].iPtr == NULL) {
293
        Tcl_AppendResult(interp, "0", NULL);
294
    } else {
295
        Tcl_AppendResult(interp, "1", NULL);
296
    }
297
 
298
    return TCL_OK;
299
}
300
/*----------------------------------------------------------------------
301
 * "column" sub command
302
 *----------------------------------------------------------------------
303
 */
304
int
305
Tix_HLColumn(clientData, interp, argc, argv)
306
    ClientData clientData;
307
    Tcl_Interp *interp;         /* Current interpreter. */
308
    int argc;                   /* Number of arguments. */
309
    char **argv;                /* Argument strings. */
310
{
311
    static Tix_SubCmdInfo subCmdInfo[] = {
312
        {TIX_DEFAULT_LEN, "width", 1, 3, Tix_HLColWidth,
313
           "column ?-char? ?size?"},
314
    };
315
    static Tix_CmdInfo cmdInfo = {
316
        Tix_ArraySize(subCmdInfo), 1, TIX_VAR_ARGS, "?option? ?arg ...?",
317
    };
318
 
319
    return Tix_HandleSubCmds(&cmdInfo, subCmdInfo, clientData,
320
        interp, argc+1, argv-1);
321
}
322
 
323
/*----------------------------------------------------------------------
324
 * "column width" sub command
325
 *----------------------------------------------------------------------
326
 */
327
static int
328
Tix_HLColWidth(clientData, interp, argc, argv)
329
    ClientData clientData;
330
    Tcl_Interp *interp;         /* Current interpreter. */
331
    int argc;                   /* Number of arguments. */
332
    char **argv;                /* Argument strings. */
333
{
334
    WidgetPtr wPtr = (WidgetPtr) clientData;
335
    int column;
336
    char buff[128];
337
    int newWidth;
338
 
339
    if (Tcl_GetInt(interp, argv[0], &column) != TCL_OK) {
340
        return TCL_ERROR;
341
    }
342
    if (column >= wPtr->numColumns || column < 0) {
343
        Tcl_AppendResult(interp, "Column \"", argv[0],
344
            "\" does not exist", (char*)NULL);
345
        return TCL_ERROR;
346
    }
347
    if (argc == 1) {            /* Query */
348
        if (wPtr->root->dirty || wPtr->allDirty) {
349
            /* We must update the geometry NOW otherwise we will get a wrong
350
             * width
351
             */
352
            Tix_HLCancelResizeWhenIdle(wPtr);
353
            Tix_HLComputeGeometry((ClientData)wPtr);
354
        }
355
        sprintf(buff, "%d", wPtr->actualSize[column].width);
356
        Tcl_AppendResult(interp, buff, NULL);
357
        return TCL_OK;
358
    }
359
    else if (argc == 2) {
360
        if (argv[1][0] == '\0') {
361
            newWidth = UNINITIALIZED;
362
            goto setwidth;
363
        }
364
        if (Tk_GetPixels(interp, wPtr->dispData.tkwin, argv[1],
365
                 &newWidth) != TCL_OK) {
366
            return TCL_ERROR;
367
        }
368
        if (newWidth < 0) {
369
            newWidth = 0;
370
        }
371
    }
372
    else if (argc == 3 && strcmp(argv[1], "-char")==0) {
373
        if (argv[2][0] == '\0') {
374
            newWidth = UNINITIALIZED;
375
            goto setwidth;
376
        }
377
        if (Tcl_GetInt(interp, argv[2], &newWidth) != TCL_OK) {
378
            return TCL_ERROR;
379
        }
380
        if (newWidth < 0) {
381
            newWidth = 0;
382
        }
383
        newWidth *= wPtr->scrollUnit[0];
384
    }
385
    else {
386
        return Tix_ArgcError(interp, argc+3, argv-3, 3,
387
            "column ?-char? ?size?");
388
    }
389
 
390
  setwidth:
391
 
392
    if (wPtr->reqSize[column].width == newWidth) {
393
        return TCL_OK;
394
    } else {
395
        wPtr->reqSize[column].width = newWidth;
396
    }
397
 
398
    if (wPtr->actualSize[column].width == newWidth) {
399
        return TCL_OK;
400
    } else {
401
        wPtr->allDirty = 1;
402
        Tix_HLResizeWhenIdle(wPtr);
403
        return TCL_OK;
404
    }
405
}

powered by: WebSVN 2.1.0

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