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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [generic/] [tixGrData.c] - Blame information for rev 1781

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

Line No. Rev Author Line
1 578 markom
/*
2
 * tixGrData.c --
3
 *
4
 *      This module manipulates the data structure for a Grid widget.
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 <tixGrid.h>
16
 
17
static int              FindRowCol _ANSI_ARGS_((TixGridDataSet * dataSet,
18
                            int x, int y, TixGridRowCol * rowcol[2],
19
                            Tcl_HashEntry * hashPtrs[2]));
20
static TixGridRowCol *  InitRowCol _ANSI_ARGS_((int index));
21
static int              RowColMaxSize _ANSI_ARGS_((WidgetPtr wPtr,
22
                            int which, TixGridRowCol *rowCol,
23
                            TixGridSize * defSize));
24
 
25
static TixGridRowCol *
26
InitRowCol(index)
27
    int index;
28
{
29
    TixGridRowCol * rowCol = (TixGridRowCol *)ckalloc(sizeof(TixGridRowCol));
30
 
31
    rowCol->dispIndex      = index;
32
    rowCol->size.sizeType  = TIX_GR_DEFAULT;
33
    rowCol->size.sizeValue = 0;
34
    rowCol->size.charValue = 0;
35
    rowCol->size.pad0      = 2;
36
    rowCol->size.pad1      = 2;
37
    rowCol->size.pixels    = 0;
38
 
39
    Tcl_InitHashTable(&rowCol->table, TCL_ONE_WORD_KEYS);
40
 
41
    return rowCol;
42
}
43
 
44
/*----------------------------------------------------------------------
45
 * TixGridDataSetInit --
46
 *
47
 *      Create an instance of the TixGridDataSet data structure.
48
 *
49
 *----------------------------------------------------------------------
50
 */
51
TixGridDataSet *
52
TixGridDataSetInit()
53
{
54
    TixGridDataSet * dataSet =(TixGridDataSet*)ckalloc(sizeof(TixGridDataSet));
55
 
56
    Tcl_InitHashTable(&dataSet->index[0], TCL_ONE_WORD_KEYS);
57
    Tcl_InitHashTable(&dataSet->index[1], TCL_ONE_WORD_KEYS);
58
 
59
    dataSet->maxIdx[0] = -1;
60
    dataSet->maxIdx[1] = -1;
61
 
62
    return dataSet;
63
}
64
 
65
/*----------------------------------------------------------------------
66
 * TixGridDataSetFree --
67
 *
68
 *      Frees an instance of the TixGridDataSet data structure.
69
 *
70
 *----------------------------------------------------------------------
71
 */
72
 
73
void
74
TixGridDataSetFree(dataSet)
75
    TixGridDataSet* dataSet;
76
{
77
    Tcl_HashSearch hashSearch;
78
    Tcl_HashEntry *hashPtr;
79
    TixGridRowCol *rcPtr;
80
    int i;
81
 
82
    for (i=0; i<2; i++) {
83
        for (hashPtr = Tcl_FirstHashEntry(&dataSet->index[i], &hashSearch);
84
                 hashPtr;
85
                 hashPtr = Tcl_NextHashEntry(&hashSearch)) {
86
            rcPtr = (TixGridRowCol *)Tcl_GetHashValue(hashPtr);
87
            if (rcPtr->table.numEntries > 0) {
88
                fprintf(stderr, "Grid hash entry leaked: %d : %d\n", i,
89
                    rcPtr->dispIndex);
90
            }
91
 
92
            Tcl_DeleteHashTable(&rcPtr->table);
93
            ckfree((char*)rcPtr);
94
        }
95
    }
96
 
97
    Tcl_DeleteHashTable(&dataSet->index[0]);
98
    Tcl_DeleteHashTable(&dataSet->index[1]);
99
    ckfree((char*)dataSet);
100
}
101
 
102
/*----------------------------------------------------------------------
103
 * TixGridDataFindEntry --
104
 *
105
 * Results:
106
 *      Return the element if it exists. Otherwise returns NULL.
107
 *
108
 * Side effects:
109
 *      None.
110
 *----------------------------------------------------------------------
111
 */
112
 
113
char *
114
TixGridDataFindEntry(dataSet, x, y)
115
    TixGridDataSet * dataSet;
116
    int x;
117
    int y;
118
{
119
    TixGridRowCol *col, *row;
120
    Tcl_HashEntry *hashPtr;
121
 
122
    /* (1) Find the row and column */
123
    if (!(hashPtr = Tcl_FindHashEntry(&dataSet->index[0], (char*)x))) {
124
        return NULL;
125
    }
126
    col = (TixGridRowCol *)Tcl_GetHashValue(hashPtr);
127
 
128
    if (!(hashPtr = Tcl_FindHashEntry(&dataSet->index[1], (char*)y))) {
129
        return NULL;
130
    }
131
    row = (TixGridRowCol *)Tcl_GetHashValue(hashPtr);
132
 
133
    /* (2) Find the entry */
134
    if (row->table.numEntries < col->table.numEntries) {
135
        if (!(hashPtr = Tcl_FindHashEntry(&row->table, (char*)col))) {
136
            return NULL;
137
        }
138
    }
139
    else {
140
        if (!(hashPtr = Tcl_FindHashEntry(&col->table, (char*)row))) {
141
            return NULL;
142
        }
143
    }
144
 
145
    return (char *)Tcl_GetHashValue(hashPtr);
146
}
147
 
148
/*----------------------------------------------------------------------
149
 * FindRowCol --
150
 *
151
 *      Internal function: finds row and column info an entry.
152
 *
153
 * Results:
154
 *      Returns true if BOTH row and column exist. If so, the row and
155
 *      column info is returned in the rowcol.
156
 *
157
 * Side effects:
158
 *      None.
159
 *----------------------------------------------------------------------
160
 */
161
 
162
static int
163
FindRowCol(dataSet, x, y, rowcol, hashPtrs)
164
    TixGridDataSet * dataSet;   /* The Grid dataset. */
165
    int x, y;                   /* Location of the cell. */
166
    TixGridRowCol * rowcol[2];  /* Returns information about the row/col. */
167
    Tcl_HashEntry * hashPtrs[2];/* Returns hash table info about the row/col.*/
168
{
169
    hashPtrs[0] = Tcl_FindHashEntry(&dataSet->index[0], (char*)x);
170
    if (hashPtrs[0] != NULL) {
171
        rowcol[0] = (TixGridRowCol *)Tcl_GetHashValue(hashPtrs[0]);
172
    } else {
173
        return 0;
174
    }
175
 
176
    hashPtrs[1] = Tcl_FindHashEntry(&dataSet->index[1], (char*)y);
177
    if (hashPtrs[1] != NULL) {
178
        rowcol[1] = (TixGridRowCol *)Tcl_GetHashValue(hashPtrs[1]);
179
    } else {
180
        return 0;
181
    }
182
 
183
    return 1;
184
}
185
 
186
/*----------------------------------------------------------------------
187
 * TixGridDataCreateEntry --
188
 *
189
 *      Find or create the entry at the specified index.
190
 *
191
 * Results:
192
 *      A handle to the entry.
193
 *
194
 * Side effects:
195
 *      A new entry is created if it is not already in the dataset.
196
 *----------------------------------------------------------------------
197
 */
198
 
199
char *
200
TixGridDataCreateEntry(dataSet, x, y, defaultEntry)
201
    TixGridDataSet * dataSet;
202
    int x;
203
    int y;
204
    char * defaultEntry;
205
{
206
    TixGridRowCol *rowcol[2];
207
    Tcl_HashEntry *hashPtr;
208
    int isNew, i, dispIndex[2];
209
 
210
    dispIndex[0] = x;
211
    dispIndex[1] = y;
212
 
213
    for (i=0; i<2; i++) {
214
        hashPtr = Tcl_CreateHashEntry(&dataSet->index[i],
215
            (char*)dispIndex[i], &isNew);
216
 
217
        if (!isNew) {
218
            rowcol[i] = (TixGridRowCol *)Tcl_GetHashValue(hashPtr);
219
        } else {
220
            rowcol[i] = InitRowCol(dispIndex[i]);
221
            Tcl_SetHashValue(hashPtr, (char*)rowcol[i]);
222
 
223
            if (dataSet->maxIdx[i] < dispIndex[i]) {
224
                dataSet->maxIdx[i] = dispIndex[i];
225
            }
226
        }
227
    }
228
 
229
    hashPtr = Tcl_CreateHashEntry(&rowcol[0]->table,
230
        (char*)rowcol[1], &isNew);
231
 
232
    if (!isNew) {
233
        return (char *) Tcl_GetHashValue(hashPtr);
234
    }
235
    else {
236
        TixGrEntry *chPtr = (TixGrEntry *)defaultEntry;
237
 
238
        Tcl_SetHashValue(hashPtr, (char*)chPtr);
239
        chPtr->entryPtr[0] = hashPtr;
240
 
241
        hashPtr = Tcl_CreateHashEntry(&rowcol[1]->table,
242
            (char*)rowcol[0], &isNew);
243
        Tcl_SetHashValue(hashPtr, (char*)defaultEntry);
244
        chPtr->entryPtr[1] = hashPtr;
245
 
246
        return defaultEntry;
247
    }
248
}
249
 
250
/*----------------------------------------------------------------------
251
 * TixGridDataDeleteEntry --
252
 *
253
 *      Deletes the entry at the specified index.
254
 *
255
 * Results:
256
 *      True iff the entry existed and was deleted.
257
 *
258
 * Side effects:
259
 *      If there is an entry at the index, it is deleted.
260
 *----------------------------------------------------------------------
261
 */
262
 
263
int
264
TixGridDataDeleteEntry(dataSet, x, y)
265
    TixGridDataSet * dataSet;   /* The Grid dataset. */
266
    int x;                      /* Column number of the entry. */
267
    int y;                      /* Row number of the entry. */
268
{
269
    TixGridRowCol *rowcol[2];
270
    Tcl_HashEntry *hashPtrs[2]; /* Hash entries of the row/col. */
271
    Tcl_HashEntry *cx, *cy;     /* Hash entries of the cell in the row/col. */
272
    int i;
273
 
274
    if (!FindRowCol(dataSet, x, y, rowcol, hashPtrs)) {
275
        /*
276
         * The row and/or the column do not exist.
277
         */
278
        return 0;
279
    }
280
 
281
    cx = Tcl_FindHashEntry(&rowcol[0]->table, (char*)rowcol[1]);
282
    cy = Tcl_FindHashEntry(&rowcol[1]->table, (char*)rowcol[0]);
283
 
284
    if (cx == NULL && cy == NULL) {
285
        return 0;
286
    }
287
    else if (cx != NULL && cy != NULL) {
288
        Tcl_DeleteHashEntry(cx);
289
        Tcl_DeleteHashEntry(cy);
290
    }
291
    else {
292
        panic("Inconsistent grid dataset: (%d,%d) : %x %x", x, y, cx, cy);
293
    }
294
 
295
#if 0
296
    /*
297
     * Can't do this, otherwise the size info of this row/col is lost.
298
     */
299
    for (i=0; i<2; i++) {
300
        if (rowcol[i]->table.numEntries == 0) {
301
            Tcl_DeleteHashEntry(hashPtrs[i]);
302
 
303
            Tcl_DeleteHashTable(&rowcol[i]->table);
304
            ckfree((char*)rowcol[i]);
305
        }
306
    }
307
#endif
308
 
309
#if 0
310
    printf("%d %d\n", dataSet->index[0].numEntries,
311
           dataSet->index[1].numEntries);
312
#endif
313
 
314
    return 1;
315
 
316
    /*
317
     * ToDo: trim down the hash table.
318
     */
319
}
320
 
321
/* return value: has the size of the grid changed as a result of sorting */
322
int
323
TixGridDataUpdateSort(dataSet, axis, start, end, items)
324
    TixGridDataSet * dataSet;
325
    int axis;
326
    int start;
327
    int end;
328
    Tix_GrSortItem *items;
329
{
330
    TixGridRowCol **ptr;
331
    Tcl_HashEntry *hashPtr;
332
    int numItems = end - start + 1;
333
    int i, k, max;
334
 
335
    if (numItems <= 0) {
336
        return 0;
337
    }
338
 
339
    ptr = (TixGridRowCol **)ckalloc(numItems * sizeof(TixGridRowCol *));
340
 
341
    for (k=0,i=start; i<=end; i++,k++) {
342
        if (!(hashPtr = Tcl_FindHashEntry(&dataSet->index[axis], (char*)i))) {
343
            /*
344
             * This row/col doesn't exist
345
             */
346
            ptr[k] = NULL;
347
        } else {
348
            ptr[k] = (TixGridRowCol *)Tcl_GetHashValue(hashPtr);
349
            Tcl_DeleteHashEntry(hashPtr);
350
        }
351
    }
352
 
353
    for (k=0,i=start; i<=end; i++,k++) {
354
        int pos, isNew;
355
        pos = items[k].index - start;
356
 
357
        if (ptr[pos] != NULL) {
358
            hashPtr = Tcl_CreateHashEntry(&dataSet->index[axis], (char*)i,
359
                &isNew);
360
            Tcl_SetHashValue(hashPtr, (char*)ptr[pos]);
361
            ptr[pos]->dispIndex = i;
362
            max = i;
363
        }
364
    }
365
 
366
    ckfree((char*)ptr);
367
 
368
    if (end+1 >= dataSet->maxIdx[axis]) {
369
        if (dataSet->maxIdx[axis] != max+1) {
370
            dataSet->maxIdx[axis] = max+1;
371
            return 1;                           /* size changed */
372
        }
373
    }
374
    return 0;                                    /* size not changed */
375
}
376
 
377
 
378
static int
379
RowColMaxSize(wPtr, which, rowCol, defSize)
380
    WidgetPtr wPtr;
381
    int which;                          /* 0=cols, 1=rows */
382
    TixGridRowCol *rowCol;
383
    TixGridSize * defSize;
384
{
385
    Tcl_HashSearch hashSearch;
386
    Tcl_HashEntry *hashPtr;
387
    TixGrEntry * chPtr;
388
    int maxSize = 1;
389
 
390
    if (rowCol->table.numEntries == 0) {
391
        return defSize->pixels;
392
    }
393
 
394
    for (hashPtr = Tcl_FirstHashEntry(&rowCol->table, &hashSearch);
395
         hashPtr;
396
         hashPtr = Tcl_NextHashEntry(&hashSearch)) {
397
 
398
        chPtr = (TixGrEntry *)Tcl_GetHashValue(hashPtr);
399
        if (maxSize < chPtr->iPtr->base.size[which]) {
400
            maxSize = chPtr->iPtr->base.size[which];
401
        }
402
    }
403
 
404
    return maxSize;
405
}
406
 
407
/*
408
 *----------------------------------------------------------------------
409
 * TixGridDataGetRowColSize --
410
 *
411
 *      Returns width of a column or height of a row.
412
 *
413
 * Results:
414
 *      The width or height.
415
 *
416
 * Side effects:
417
 *      None.
418
 *----------------------------------------------------------------------
419
 */
420
 
421
int
422
TixGridDataGetRowColSize(wPtr, dataSet, which, index, defSize, pad0, pad1)
423
    WidgetPtr wPtr;             /* Info about Grid widget */
424
    TixGridDataSet * dataSet;   /* Dataset of the Grid */
425
    int which;                  /* 0=cols, 1=rows */
426
    int index;                  /* Column or row number */
427
    TixGridSize * defSize;      /* The default size for the grid cells */
428
    int *pad0;                  /* Holds return value of horizontal padding. */
429
    int *pad1;                  /* Holds return value of vertical padding. */
430
{
431
    TixGridRowCol *rowCol;
432
    Tcl_HashEntry *hashPtr;
433
    int size;
434
 
435
    if (!(hashPtr = Tcl_FindHashEntry(&dataSet->index[which], (char*)index))) {
436
        size  = defSize->pixels;
437
        *pad0 = defSize->pad0;
438
        *pad1 = defSize->pad1;
439
    }
440
    else {
441
        rowCol = (TixGridRowCol *)Tcl_GetHashValue(hashPtr);
442
 
443
        switch (rowCol->size.sizeType) {
444
          case TIX_GR_AUTO:
445
            size  = RowColMaxSize(wPtr, which, rowCol, defSize);
446
            *pad0 = rowCol->size.pad0;
447
            *pad1 = rowCol->size.pad1;
448
            break;
449
 
450
          case TIX_GR_DEFINED_PIXEL:
451
            size  = rowCol->size.sizeValue;
452
            *pad0 = rowCol->size.pad0;
453
            *pad1 = rowCol->size.pad1;
454
            break;
455
 
456
          case TIX_GR_DEFINED_CHAR:
457
            size  = (int)(rowCol->size.charValue * wPtr->fontSize[which]);
458
            *pad0 = rowCol->size.pad0;
459
            *pad1 = rowCol->size.pad1;
460
            break;
461
 
462
          case TIX_GR_DEFAULT:
463
          default:                      /* some error ?? */
464
            if (defSize->sizeType == TIX_GR_AUTO) {
465
                size = RowColMaxSize(wPtr, which, rowCol, defSize);
466
            } else {
467
                size = defSize->pixels;
468
            }
469
            *pad0 = defSize->pad0;
470
            *pad1 = defSize->pad1;
471
        }
472
    }
473
 
474
    return size;
475
}
476
 
477
int
478
TixGridDataGetIndex(interp, wPtr, xStr, yStr, xPtr, yPtr)
479
    Tcl_Interp * interp;
480
    WidgetPtr wPtr;
481
    char * xStr;
482
    char * yStr;
483
    int * xPtr;
484
    int * yPtr;
485
{
486
    char * str[2];
487
    int * ptr[2];
488
    int i;
489
 
490
    str[0] = xStr;
491
    str[1] = yStr;
492
    ptr[0] = xPtr;
493
    ptr[1] = yPtr;
494
 
495
    for (i=0; i<2; i++) {
496
        if (str[i] == NULL) {           /* ignore this index */
497
            continue;
498
        }
499
 
500
        if (strcmp(str[i], "max") == 0) {
501
            *ptr[i] = wPtr->dataSet->maxIdx[i];
502
            if (*ptr[i] < wPtr->hdrSize[i]) {
503
                *ptr[i] = wPtr->hdrSize[i];
504
            }
505
        }
506
        else if (strcmp(str[i], "end") == 0) {
507
            *ptr[i] = wPtr->dataSet->maxIdx[i] + 1;
508
            if (*ptr[i] < wPtr->hdrSize[i]) {
509
                *ptr[i] = wPtr->hdrSize[i];
510
            }
511
        } else {
512
            if (Tcl_GetInt(interp, str[i], ptr[i]) != TCL_OK) {
513
                return TCL_ERROR;
514
            }
515
        }
516
        if (*ptr[i] < 0) {
517
            *ptr[i] = 0;
518
        }
519
    }
520
 
521
    return TCL_OK;
522
}
523
 
524
/*
525
 *----------------------------------------------------------------------
526
 * TixGridDataConfigRowColSize --
527
 *
528
 *      Configure width of column or height of rows.
529
 *
530
 * Results:
531
 *      Standard Tcl result.
532
 *
533
 * Side effects:
534
 *      The column/rows size will be changed in an idle event.
535
 *----------------------------------------------------------------------
536
 */
537
 
538
int
539
TixGridDataConfigRowColSize(interp, wPtr, dataSet, which, index, argc, argv,
540
        argcErrorMsg, changed_ret)
541
    Tcl_Interp * interp;
542
    WidgetPtr wPtr;
543
    TixGridDataSet * dataSet;
544
    int which;                  /* 0=cols, 1=rows */
545
    int index;
546
    int argc;
547
    char ** argv;
548
    char * argcErrorMsg;
549
    int *changed_ret;           /* Returns whether size has been changed. */
550
{
551
    TixGridRowCol *rowCol;
552
    Tcl_HashEntry *hashPtr;
553
    int isNew, code;
554
 
555
    hashPtr = Tcl_CreateHashEntry(&dataSet->index[which],(char*)index, &isNew);
556
 
557
    if (!isNew) {
558
        rowCol = (TixGridRowCol *)Tcl_GetHashValue(hashPtr);
559
    } else {
560
        rowCol = InitRowCol(index);
561
        Tcl_SetHashValue(hashPtr, (char*)rowCol);
562
 
563
        if (dataSet->maxIdx[which] < index) {
564
            dataSet->maxIdx[which] = index;
565
        }
566
    }
567
 
568
    code = Tix_GrConfigSize(interp, wPtr, argc, argv, &rowCol->size,
569
        argcErrorMsg, changed_ret);
570
 
571
    if (changed_ret) {
572
        *changed_ret |= isNew;
573
    }
574
 
575
    return code;
576
}
577
 
578
/*
579
 *----------------------------------------------------------------------
580
 * TixGridDataGetGridSize --
581
 *
582
 *      Returns the number of rows and columns of the grid.
583
 *
584
 * Results:
585
 *      None.
586
 *
587
 * Side effects:
588
 *      None.
589
 *----------------------------------------------------------------------
590
 */
591
 
592
/*
593
 * ToDo: maintain numCol and numRow info while adding entries.
594
 */
595
 
596
void
597
TixGridDataGetGridSize(dataSet, numCol_ret, numRow_ret)
598
    TixGridDataSet * dataSet;
599
    int *numCol_ret;
600
    int *numRow_ret;
601
{
602
    int maxSize[2], i;
603
    Tcl_HashEntry *hashPtr;
604
    Tcl_HashSearch hashSearch;
605
    TixGridRowCol * rowCol;
606
 
607
    maxSize[0] = 1;
608
    maxSize[1] = 1;
609
 
610
    if (dataSet->index[0].numEntries == 0 || dataSet->index[1].numEntries==0) {
611
        goto done;
612
    }
613
 
614
    for (i=0; i<2; i++) {
615
 
616
        for (hashPtr = Tcl_FirstHashEntry(&dataSet->index[i], &hashSearch);
617
             hashPtr;
618
             hashPtr = Tcl_NextHashEntry(&hashSearch)) {
619
 
620
            rowCol = (TixGridRowCol *)Tcl_GetHashValue(hashPtr);
621
            if (maxSize[i] < rowCol->dispIndex+1) {
622
                maxSize[i] = rowCol->dispIndex+1;
623
            }
624
        }
625
    }
626
 
627
  done:
628
    if (numCol_ret) {
629
        *numCol_ret  = maxSize[0];
630
    }
631
    if (numRow_ret) {
632
        *numRow_ret = maxSize[1];
633
    }
634
}
635
 
636
 
637
/*
638
 * the following four functions return true if done -- no more rows or cells
639
 * are left to traverse
640
 */
641
 
642
int
643
TixGrDataFirstRow(dataSet, rowSearchPtr)
644
    TixGridDataSet* dataSet;
645
    Tix_GrDataRowSearch * rowSearchPtr;
646
{
647
    rowSearchPtr->hashPtr = Tcl_FirstHashEntry(&dataSet->index[0],
648
        &rowSearchPtr->hashSearch);
649
 
650
    if (rowSearchPtr->hashPtr != NULL) {
651
        rowSearchPtr->row = (TixGridRowCol *)Tcl_GetHashValue(
652
                rowSearchPtr->hashPtr);
653
        return 0;
654
    } else {
655
        rowSearchPtr->row = NULL;
656
        return 1;
657
    }
658
}
659
 
660
int
661
TixGrDataNextRow(rowSearchPtr)
662
    Tix_GrDataRowSearch * rowSearchPtr;
663
{
664
    rowSearchPtr->hashPtr = Tcl_NextHashEntry(&rowSearchPtr->hashSearch);
665
 
666
    if (rowSearchPtr->hashPtr != NULL) {
667
        rowSearchPtr->row = (TixGridRowCol *)Tcl_GetHashValue(
668
                rowSearchPtr->hashPtr);
669
        return 0;
670
    } else {
671
        rowSearchPtr->row = NULL;
672
        return 1;
673
    }
674
}
675
 
676
int
677
TixGrDataFirstCell(rowSearchPtr, cellSearchPtr)
678
    Tix_GrDataRowSearch * rowSearchPtr;
679
    Tix_GrDataCellSearch * cellSearchPtr;
680
{
681
    cellSearchPtr->hashPtr = Tcl_FirstHashEntry(&rowSearchPtr->row->table,
682
        &cellSearchPtr->hashSearch);
683
 
684
    if (cellSearchPtr->hashPtr != NULL) {
685
        cellSearchPtr->data = (char *)Tcl_GetHashValue(
686
                cellSearchPtr->hashPtr);
687
        return 0;
688
    } else {
689
        cellSearchPtr->data = NULL;
690
        return 1;
691
    }
692
}
693
 
694
int
695
TixGrDataNextCell(cellSearchPtr)
696
    Tix_GrDataCellSearch * cellSearchPtr;
697
{
698
    cellSearchPtr->hashPtr = Tcl_NextHashEntry(&cellSearchPtr->hashSearch);
699
 
700
    if (cellSearchPtr->hashPtr != NULL) {
701
        cellSearchPtr->data = (char *)Tcl_GetHashValue(
702
                cellSearchPtr->hashPtr);
703
        return 0;
704
    } else {
705
        cellSearchPtr->data = NULL;
706
        return 1;
707
    }
708
}
709
 
710
/*----------------------------------------------------------------------
711
 * TixGridDataDeleteSearchedEntry --
712
 *
713
 *      Deletes an entry returned by one of the search functions.
714
 *
715
 * Results:
716
 *      None.
717
 *
718
 * Side effects:
719
 *      If there is an entry at the index, it is deleted.
720
 *----------------------------------------------------------------------
721
 */
722
 
723
void
724
TixGridDataDeleteSearchedEntry(cellSearchPtr)
725
    Tix_GrDataCellSearch * cellSearchPtr;
726
{
727
    TixGrEntry * chPtr = (TixGrEntry *)cellSearchPtr->data;
728
 
729
    Tcl_DeleteHashEntry(chPtr->entryPtr[0]);
730
    Tcl_DeleteHashEntry(chPtr->entryPtr[1]);
731
}
732
 
733
/*
734
 *----------------------------------------------------------------------
735
 * TixGridDataDeleteRange --
736
 *
737
 *      Deletes the rows (columns) at the given range.
738
 *
739
 * Results:
740
 *      None.
741
 *
742
 * Side effects:
743
 *      The given rows (columns) are deleted.
744
 *----------------------------------------------------------------------
745
 */
746
 
747
void
748
TixGridDataDeleteRange(wPtr, dataSet, which, from, to)
749
    WidgetPtr wPtr;             /* Info about the grid widget. */
750
    TixGridDataSet * dataSet;   /* Dataset of the Grid */
751
    int which;                  /* 0=cols, 1=rows */
752
    int from;                   /* Starting column/row. */
753
    int to;                     /* Ending column/row (inclusive). */
754
{
755
    int tmp, i, other, deleted = 0;
756
 
757
    if (from < 0 ) {
758
        from = 0;
759
    }
760
    if (to < 0 ) {
761
        to = 0;
762
    }
763
    if (from > to) {
764
        tmp  = to;
765
        to   = from;
766
        from = tmp;
767
    }
768
    if (which == 0) {
769
        other = 1;
770
    } else {
771
        other = 0;
772
    }
773
 
774
    for (i=from; i<=to; i++) {
775
        Tcl_HashEntry *hashPtr, *hp, *toDel;
776
        TixGridRowCol *rcPtr, *rcp;
777
        Tcl_HashSearch hashSearch;
778
 
779
        hashPtr = Tcl_FindHashEntry(&dataSet->index[which], (char*)i);
780
        if (hashPtr != NULL) {
781
            rcPtr = (TixGridRowCol *)Tcl_GetHashValue(hashPtr);
782
 
783
            for (hp = Tcl_FirstHashEntry(&dataSet->index[other], &hashSearch);
784
                    hp;
785
                    hp = Tcl_NextHashEntry(&hashSearch)) {
786
 
787
                rcp = (TixGridRowCol *)Tcl_GetHashValue(hp);
788
                toDel = Tcl_FindHashEntry(&rcp->table, (char*)rcPtr);
789
                if (toDel != NULL) {
790
                    TixGrEntry * chPtr;
791
 
792
                    chPtr = (TixGrEntry *)Tcl_GetHashValue(toDel);
793
                    if (chPtr) {
794
                        deleted = 1;
795
                        Tix_GrFreeElem(chPtr);
796
                    }
797
 
798
                    Tcl_DeleteHashEntry(toDel);
799
                }
800
            }
801
 
802
            Tcl_DeleteHashEntry(hashPtr);
803
            Tcl_DeleteHashTable(&rcPtr->table);
804
            ckfree((char*)rcPtr);
805
        }
806
    }
807
 
808
    if (deleted) {
809
        Tix_GrDoWhenIdle(wPtr, TIX_GR_RESIZE);
810
    }
811
}
812
 
813
/*
814
 *----------------------------------------------------------------------
815
 * TixGridDataMoveRange --
816
 *
817
 *      Moves a range of row (columns) by a given offset. E.g. move 2-4 by 2
818
 *      changes the rows 2,3,4 to 4,5,6.
819
 *
820
 * Results:
821
 *      None.
822
 *
823
 * Side effects:
824
 *      Rows (columns) at locations where the given rows will be moved
825
 *      to are deleted.
826
 *----------------------------------------------------------------------
827
 */
828
 
829
void
830
TixGridDataMoveRange(wPtr, dataSet, which, from, to, by)
831
    WidgetPtr wPtr;             /* Info about the grid widget. */
832
    TixGridDataSet * dataSet;   /* Dataset of the Grid */
833
    int which;                  /* 0=cols, 1=rows */
834
    int from;                   /* Starting column/row. */
835
    int to;                     /* Ending column/row (inclusive). */
836
    int by;                     /* The distance of the move. */
837
{
838
    int tmp, i, s, e, incr;
839
    int df, dt;                 /* Rows inside this range will be deleted
840
                                 * before the given rows are moved. */
841
 
842
    if (by == 0) {
843
        return;
844
    }
845
    if (from < 0 ) {
846
        from = 0;
847
    }
848
    if (to < 0 ) {
849
        to = 0;
850
    }
851
    if (from > to) {
852
        tmp  = to;
853
        to   = from;
854
        from = tmp;
855
    }
856
 
857
    if ((from + by) < 0) {
858
        /*
859
         * Delete the leading rows that will be moved beyond the top of grid.
860
         */
861
        int n;                  /* Number of rows to delete. */
862
 
863
        n = - (from + by);
864
        if (n > (to - from + 1)) {
865
            n =  to - from + 1;
866
        }
867
        TixGridDataDeleteRange(wPtr, dataSet, which, from, (from+n-1));
868
        from = from + n;
869
 
870
        if (from > to) {
871
            /*
872
             * All the rows have been deleted.
873
             */
874
            return;
875
        }
876
    }
877
 
878
    /*
879
     * Delete rows at locations where the given rows will be moved to.
880
     */
881
    df = from + by;
882
    dt = to   + by;
883
 
884
    if (by > 0) {
885
        if (df <= to) {
886
            df = to + 1;
887
        }
888
    } else {
889
        if (dt >= from) {
890
            dt = from - 1;
891
        }
892
    }
893
    TixGridDataDeleteRange(wPtr, dataSet, which, df, dt);
894
 
895
    /*
896
     * Rename the rows.
897
     */
898
    if (by > 0) {
899
        s    = to;
900
        e    = from-1;
901
        incr = -1;
902
    } else {
903
        s    = from;
904
        e    = to+1;
905
        incr = 1;
906
    }
907
 
908
    for (i=s; i!=e; i+=incr) {
909
        Tcl_HashEntry *hashPtr;
910
        TixGridRowCol *rcPtr;
911
        int isNew;
912
 
913
        hashPtr = Tcl_FindHashEntry(&dataSet->index[which], (char*)i);
914
        if (hashPtr != NULL) {
915
            rcPtr = (TixGridRowCol *)Tcl_GetHashValue(hashPtr);
916
            rcPtr->dispIndex = i+by;
917
            Tcl_DeleteHashEntry(hashPtr);
918
            hashPtr = Tcl_CreateHashEntry(&dataSet->index[which],(char*)(i+by),
919
                    &isNew);
920
            Tcl_SetHashValue(hashPtr, (char*)rcPtr);
921
        }
922
    }
923
}

powered by: WebSVN 2.1.0

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