| 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 "tixDef.h" |
| 19 |
#include "tixGrid.h" |
| 20 |
|
| 21 |
EXTERN TIX_DECLARE_SUBCMD(Tix_GrSelection); |
| 22 |
static TIX_DECLARE_SUBCMD(Tix_GrSelIncludes); |
| 23 |
static TIX_DECLARE_SUBCMD(Tix_GrSelModify); |
| 24 |
|
| 25 |
static int Tix_GrSelIncludes _ANSI_ARGS_((ClientData clientData, |
| 26 |
Tcl_Interp *interp, int argc, char **argv)); |
| 27 |
static void Tix_GrAdjustSelection _ANSI_ARGS_(( |
| 28 |
WidgetPtr wPtr, SelectBlock * sbPtr)); |
| 29 |
static void Tix_GrMergeSelection _ANSI_ARGS_(( |
| 30 |
WidgetPtr wPtr, SelectBlock * sbPtr)); |
| 31 |
static int Intersect _ANSI_ARGS_((SelectBlock * s1, |
| 32 |
SelectBlock * s2)); |
| 33 |
static int Include _ANSI_ARGS_((SelectBlock * s1, |
| 34 |
SelectBlock * s2)); |
| 35 |
|
| 36 |
int |
| 37 |
Tix_GrSelection(clientData, interp, argc, argv) |
| 38 |
ClientData clientData; |
| 39 |
Tcl_Interp *interp; |
| 40 |
int argc; |
| 41 |
char **argv; |
| 42 |
{ |
| 43 |
static Tix_SubCmdInfo subCmdInfo[] = { |
| 44 |
{TIX_DEFAULT_LEN, "adjust", 2, 4, Tix_GrSelModify, |
| 45 |
"x1 y1 ?x2 y2?"}, |
| 46 |
{TIX_DEFAULT_LEN, "clear", 2, 4, Tix_GrSelModify, |
| 47 |
"x1 y1 ?x2 y2?"}, |
| 48 |
{TIX_DEFAULT_LEN, "includes", 2, 4, Tix_GrSelIncludes, |
| 49 |
"x1 y1 ?x2 y2?"}, |
| 50 |
{TIX_DEFAULT_LEN, "set", 2, 4, Tix_GrSelModify, |
| 51 |
"x1 y1 ?x2 y2?"}, |
| 52 |
{TIX_DEFAULT_LEN, "toggle", 2, 4, Tix_GrSelModify, |
| 53 |
"x1 y1 ?x2 y2?"}, |
| 54 |
}; |
| 55 |
static Tix_CmdInfo cmdInfo = { |
| 56 |
Tix_ArraySize(subCmdInfo), 1, TIX_VAR_ARGS, "?option? ?arg ...?", |
| 57 |
}; |
| 58 |
|
| 59 |
return Tix_HandleSubCmds(&cmdInfo, subCmdInfo, clientData, |
| 60 |
interp, argc+1, argv-1); |
| 61 |
} |
| 62 |
|
| 63 |
static int |
| 64 |
Selected(WidgetPtr wPtr, int row, int col) |
| 65 |
{ |
| 66 |
int value = 0; |
| 67 |
Tix_ListIterator li; |
| 68 |
|
| 69 |
Tix_SimpleListIteratorInit(&li); |
| 70 |
|
| 71 |
for (Tix_SimpleListStart(&wPtr->selList, &li); |
| 72 |
!Tix_SimpleListDone(&li); |
| 73 |
Tix_SimpleListNext (&wPtr->selList, &li)) { |
| 74 |
SelectBlock *ptr = (SelectBlock *)li.curr; |
| 75 |
if (ptr->range[TIX_X][0] <= col && ptr->range[TIX_X][1] >= col && |
| 76 |
ptr->range[TIX_Y][0] <= row && ptr->range[TIX_Y][1] >= row) |
| 77 |
{ |
| 78 |
switch(ptr->type) |
| 79 |
{ |
| 80 |
case TIX_GR_CLEAR: |
| 81 |
value = 0; |
| 82 |
break; |
| 83 |
case TIX_GR_SET: |
| 84 |
value = 1; |
| 85 |
break; |
| 86 |
case TIX_GR_TOGGLE: |
| 87 |
value = !value; |
| 88 |
break; |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
return value; |
| 93 |
} |
| 94 |
|
| 95 |
static int |
| 96 |
Tix_GrSelIncludes(clientData, interp, argc, argv) |
| 97 |
ClientData clientData; |
| 98 |
Tcl_Interp *interp; |
| 99 |
int argc; |
| 100 |
char **argv; |
| 101 |
{ |
| 102 |
int row; |
| 103 |
int col; |
| 104 |
int value = 1; |
| 105 |
WidgetPtr wPtr = (WidgetPtr) clientData; |
| 106 |
if (argc != 2 && argc != 4) { |
| 107 |
return Tix_ArgcError(interp, argc+2, argv-2, 2, "x1 y1 ?x2 y2?"); |
| 108 |
} |
| 109 |
if (Tcl_GetIntFromObj(interp, argv[0], &col) != TCL_OK) { |
| 110 |
return TCL_ERROR; |
| 111 |
} |
| 112 |
if (Tcl_GetIntFromObj(interp, argv[1], &row) != TCL_OK) { |
| 113 |
return TCL_ERROR; |
| 114 |
} |
| 115 |
if (argc == 2) |
| 116 |
{ |
| 117 |
value = Selected(wPtr,row,col); |
| 118 |
} |
| 119 |
else |
| 120 |
{ |
| 121 |
int row2; |
| 122 |
int col2; |
| 123 |
if (Tcl_GetIntFromObj(interp, argv[0], &col2) != TCL_OK) |
| 124 |
return TCL_ERROR; |
| 125 |
if (Tcl_GetIntFromObj(interp, argv[1], &row2) != TCL_OK) |
| 126 |
return TCL_ERROR; |
| 127 |
if (row2 < row) |
| 128 |
{ |
| 129 |
int t = row; |
| 130 |
row = row2; |
| 131 |
row2 = t; |
| 132 |
} |
| 133 |
if (col2 < col) |
| 134 |
{ |
| 135 |
int t = col; |
| 136 |
col = col2; |
| 137 |
col2 = t; |
| 138 |
} |
| 139 |
while (row <= row2) |
| 140 |
{ |
| 141 |
while (col <= col2) |
| 142 |
{ |
| 143 |
if (!Selected(wPtr,row,col)) |
| 144 |
{ |
| 145 |
value = 0; |
| 146 |
goto done; |
| 147 |
} |
| 148 |
col++; |
| 149 |
} |
| 150 |
row++; |
| 151 |
} |
| 152 |
} |
| 153 |
done: |
| 154 |
Tcl_SetIntObj(Tcl_GetObjResult(interp),value); |
| 155 |
return TCL_OK; |
| 156 |
} |
| 157 |
|
| 158 |
static int Intersect(s1, s2) |
| 159 |
SelectBlock * s1; |
| 160 |
SelectBlock * s2; |
| 161 |
{ |
| 162 |
return 0; |
| 163 |
} |
| 164 |
|
| 165 |
static int Include(s1, s2) |
| 166 |
SelectBlock * s1; |
| 167 |
SelectBlock * s2; |
| 168 |
{ |
| 169 |
return 0; |
| 170 |
} |
| 171 |
|
| 172 |
static void |
| 173 |
Tix_GrMergeSelection(wPtr, sbPtr) |
| 174 |
WidgetPtr wPtr; |
| 175 |
SelectBlock * sbPtr; |
| 176 |
{ |
| 177 |
Tix_ListIterator li; |
| 178 |
|
| 179 |
switch (sbPtr->type) { |
| 180 |
case TIX_GR_SET: |
| 181 |
case TIX_GR_CLEAR: |
| 182 |
if (sbPtr->range[0][0] == 0 && |
| 183 |
sbPtr->range[1][0] == 0 && |
| 184 |
sbPtr->range[0][1] == TIX_GR_MAX && |
| 185 |
sbPtr->range[1][1] == TIX_GR_MAX) { |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
Tix_SimpleListIteratorInit(&li); |
| 190 |
|
| 191 |
for (Tix_SimpleListStart(&wPtr->selList, &li); |
| 192 |
!Tix_SimpleListDone(&li); |
| 193 |
Tix_SimpleListNext (&wPtr->selList, &li)) { |
| 194 |
|
| 195 |
SelectBlock *ptr = (SelectBlock *)li.curr; |
| 196 |
Tix_SimpleListDelete(&wPtr->selList, &li); |
| 197 |
ckfree((char*)ptr); |
| 198 |
} |
| 199 |
} |
| 200 |
if (sbPtr->type == TIX_GR_SET) { |
| 201 |
Tix_SimpleListAppend(&wPtr->selList, (char*)sbPtr, 0); |
| 202 |
} |
| 203 |
goto done; |
| 204 |
} |
| 205 |
|
| 206 |
#if 0 |
| 207 |
|
| 208 |
switch (sbPtr->type) { |
| 209 |
case TIX_GR_TOGGLE: { |
| 210 |
} |
| 211 |
break; |
| 212 |
case TIX_GR_SET: { |
| 213 |
Tix_SimpleListAppend(&wPtr->selList, (char*)sbPtr, 0); |
| 214 |
} |
| 215 |
break; |
| 216 |
case TIX_GR_CLEAR: { |
| 217 |
Tix_SimpleListIteratorInit(&li); |
| 218 |
|
| 219 |
for (Tix_SimpleListStart(&wPtr->selList, &li); |
| 220 |
!Tix_SimpleListDone(&li); |
| 221 |
Tix_SimpleListNext (&wPtr->selList, &li)) { |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
} |
| 226 |
#else |
| 227 |
|
| 228 |
Tix_SimpleListAppend(&wPtr->selList, (char*)sbPtr, 0); |
| 229 |
|
| 230 |
#endif |
| 231 |
|
| 232 |
done: |
| 233 |
Tix_GrAddChangedRect(wPtr, sbPtr->range, 0); |
| 234 |
} |
| 235 |
|
| 236 |
static void |
| 237 |
Tix_GrAdjustSelection(wPtr, sbPtr) |
| 238 |
WidgetPtr wPtr; |
| 239 |
SelectBlock * sbPtr; |
| 240 |
{ |
| 241 |
int changed[2][2]; |
| 242 |
SelectBlock * current; |
| 243 |
|
| 244 |
current = (SelectBlock*)wPtr->selList.tail; |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
changed[TIX_X][0] = sbPtr->range[TIX_X][0]; |
| 251 |
changed[TIX_X][1] = sbPtr->range[TIX_X][1]; |
| 252 |
changed[TIX_Y][0] = sbPtr->range[TIX_Y][0]; |
| 253 |
changed[TIX_Y][1] = sbPtr->range[TIX_Y][1]; |
| 254 |
|
| 255 |
if (changed[TIX_X][0] > current->range[TIX_X][0]) { |
| 256 |
changed[TIX_X][0] = current->range[TIX_X][0]; |
| 257 |
} |
| 258 |
if (changed[TIX_X][1] < current->range[TIX_X][1]) { |
| 259 |
changed[TIX_X][1] = current->range[TIX_X][1]; |
| 260 |
} |
| 261 |
if (changed[TIX_Y][0] > current->range[TIX_Y][0]) { |
| 262 |
changed[TIX_Y][0] = current->range[TIX_Y][0]; |
| 263 |
} |
| 264 |
if (changed[TIX_Y][1] < current->range[TIX_Y][1]) { |
| 265 |
changed[TIX_Y][1] = current->range[TIX_Y][1]; |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
current->range[TIX_X][0] = sbPtr->range[TIX_X][0]; |
| 270 |
current->range[TIX_X][1] = sbPtr->range[TIX_X][1]; |
| 271 |
current->range[TIX_Y][0] = sbPtr->range[TIX_Y][0]; |
| 272 |
current->range[TIX_Y][1] = sbPtr->range[TIX_Y][1]; |
| 273 |
|
| 274 |
|
| 275 |
Tix_GrAddChangedRect(wPtr, changed, 0); |
| 276 |
|
| 277 |
|
| 278 |
ckfree((char*)sbPtr); |
| 279 |
} |
| 280 |
|
| 281 |
static int |
| 282 |
Tix_GrSelModify(clientData, interp, argc, argv) |
| 283 |
ClientData clientData; |
| 284 |
Tcl_Interp *interp; |
| 285 |
int argc; |
| 286 |
char **argv; |
| 287 |
{ |
| 288 |
WidgetPtr wPtr = (WidgetPtr) clientData; |
| 289 |
int type = 0, adjust = 0; |
| 290 |
SelectBlock * sbPtr = NULL; |
| 291 |
int tmp; |
| 292 |
|
| 293 |
if (argc != 2 && argc != 4) { |
| 294 |
return Tix_ArgcError(interp, argc+2, argv-2, 2, "x1 y1 ?x2 y2?"); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
if (argv[-1][0] == 'a') { |
| 301 |
if (wPtr->selList.numItems <= 0) { |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
Tcl_AppendResult(interp, "selection list is empty", NULL); |
| 306 |
return TCL_ERROR; |
| 307 |
} |
| 308 |
adjust = 1; |
| 309 |
} |
| 310 |
else if (argv[-1][0] == 'c') { |
| 311 |
type = TIX_GR_CLEAR; |
| 312 |
} |
| 313 |
else if (argv[-1][0] == 's') { |
| 314 |
type = TIX_GR_SET; |
| 315 |
} |
| 316 |
else { |
| 317 |
type = TIX_GR_TOGGLE; |
| 318 |
} |
| 319 |
|
| 320 |
sbPtr = (SelectBlock*)ckalloc(sizeof(SelectBlock)); |
| 321 |
sbPtr->type = type; |
| 322 |
|
| 323 |
if (Tcl_GetIntFromObj(interp, argv[0], &sbPtr->range[0][0]) != TCL_OK) { |
| 324 |
goto error; |
| 325 |
} |
| 326 |
if (Tcl_GetIntFromObj(interp, argv[1], &sbPtr->range[1][0]) != TCL_OK) { |
| 327 |
goto error; |
| 328 |
} |
| 329 |
if (argc == 4) { |
| 330 |
if (Tcl_GetIntFromObj(interp, argv[2], &sbPtr->range[0][1]) != TCL_OK) { |
| 331 |
if (strcmp(argv[2], "max") == 0) { |
| 332 |
Tcl_ResetResult(interp); |
| 333 |
sbPtr->range[0][1] = TIX_GR_MAX; |
| 334 |
} else { |
| 335 |
goto error; |
| 336 |
} |
| 337 |
} |
| 338 |
if (Tcl_GetIntFromObj(interp, argv[3], &sbPtr->range[1][1]) != TCL_OK) { |
| 339 |
if (strcmp(argv[3], "max") == 0) { |
| 340 |
Tcl_ResetResult(interp); |
| 341 |
sbPtr->range[1][1] = TIX_GR_MAX; |
| 342 |
} else { |
| 343 |
goto error; |
| 344 |
} |
| 345 |
} |
| 346 |
} else { |
| 347 |
sbPtr->range[0][1] = sbPtr->range[0][0]; |
| 348 |
sbPtr->range[1][1] = sbPtr->range[1][0]; |
| 349 |
} |
| 350 |
|
| 351 |
if (wPtr->selectUnit != tixRowUid) { |
| 352 |
if (sbPtr->range[0][0] > sbPtr->range[0][1]) { |
| 353 |
tmp = sbPtr->range[0][1]; |
| 354 |
sbPtr->range[0][1] = sbPtr->range[0][0]; |
| 355 |
sbPtr->range[0][0] = tmp; |
| 356 |
} |
| 357 |
} else { |
| 358 |
sbPtr->range[0][0] = 0; |
| 359 |
sbPtr->range[0][1] = TIX_GR_MAX; |
| 360 |
} |
| 361 |
|
| 362 |
if (wPtr->selectUnit != tixColumnUid) { |
| 363 |
if (sbPtr->range[1][0] > sbPtr->range[1][1]) { |
| 364 |
tmp = sbPtr->range[1][1]; |
| 365 |
sbPtr->range[1][1] = sbPtr->range[1][0]; |
| 366 |
sbPtr->range[1][0] = tmp; |
| 367 |
} |
| 368 |
} else { |
| 369 |
sbPtr->range[1][0] = 0; |
| 370 |
sbPtr->range[1][1] = TIX_GR_MAX; |
| 371 |
} |
| 372 |
|
| 373 |
if (adjust) { |
| 374 |
Tix_GrAdjustSelection(wPtr, sbPtr); |
| 375 |
sbPtr = NULL; |
| 376 |
} else { |
| 377 |
Tix_GrMergeSelection(wPtr, sbPtr); |
| 378 |
} |
| 379 |
wPtr->toComputeSel = 1; |
| 380 |
return TCL_OK; |
| 381 |
|
| 382 |
error: |
| 383 |
if (sbPtr) { |
| 384 |
ckfree((char*)sbPtr); |
| 385 |
} |
| 386 |
return TCL_ERROR; |
| 387 |
} |