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