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