| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "tkPort.h" |
| 18 |
#include "default.h" |
| 19 |
#include "tkInt.h" |
| 20 |
|
| 21 |
#ifdef WIN32 |
| 22 |
#include "tkWinInt.h" |
| 23 |
#endif |
| 24 |
|
| 25 |
#include "tkVMacro.h" |
| 26 |
|
| 27 |
typedef struct { |
| 28 |
Tk_OptionTable listboxOptionTable; |
| 29 |
|
| 30 |
Tk_OptionTable itemAttrOptionTable; |
| 31 |
|
| 32 |
|
| 33 |
} ListboxOptionTables; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
typedef struct { |
| 41 |
Tk_Window tkwin; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
Display *display; |
| 46 |
|
| 47 |
|
| 48 |
Tcl_Interp *interp; |
| 49 |
Tcl_Command widgetCmd; |
| 50 |
Tk_OptionTable optionTable; |
| 51 |
|
| 52 |
Tk_OptionTable itemAttrOptionTable; |
| 53 |
|
| 54 |
|
| 55 |
Tcl_Obj *listVarName; |
| 56 |
Tcl_Obj *listObj; |
| 57 |
int nElements; |
| 58 |
Tcl_HashTable *selection; |
| 59 |
Tcl_HashTable *itemAttrTable; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
Tk_3DBorder normalBorder; |
| 66 |
|
| 67 |
int borderWidth; |
| 68 |
int relief; |
| 69 |
int highlightWidth; |
| 70 |
|
| 71 |
|
| 72 |
XColor *highlightBgColorPtr; |
| 73 |
|
| 74 |
|
| 75 |
XColor *highlightColorPtr; |
| 76 |
int inset; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
Tk_Font tkfont; |
| 82 |
XColor *fgColorPtr; |
| 83 |
XColor *dfgColorPtr; |
| 84 |
GC textGC; |
| 85 |
Tk_3DBorder selBorder; |
| 86 |
|
| 87 |
int selBorderWidth; |
| 88 |
XColor *selFgColorPtr; |
| 89 |
GC selTextGC; |
| 90 |
int width; |
| 91 |
int height; |
| 92 |
int lineHeight; |
| 93 |
|
| 94 |
int topIndex; |
| 95 |
|
| 96 |
int fullLines; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
int partialLine; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
int setGrid; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
int maxWidth; |
| 112 |
|
| 113 |
int xScrollUnit; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
int xOffset; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
Tk_Uid selectMode; |
| 127 |
|
| 128 |
|
| 129 |
int numSelected; |
| 130 |
int selectAnchor; |
| 131 |
|
| 132 |
int exportSelection; |
| 133 |
|
| 134 |
int active; |
| 135 |
|
| 136 |
|
| 137 |
int activeStyle; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
int scanMarkX; |
| 145 |
|
| 146 |
int scanMarkY; |
| 147 |
|
| 148 |
int scanMarkXOffset; |
| 149 |
|
| 150 |
int scanMarkYIndex; |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
Tk_Cursor cursor; |
| 158 |
char *takeFocus; |
| 159 |
|
| 160 |
|
| 161 |
LangCallback *yScrollCmd; |
| 162 |
|
| 163 |
|
| 164 |
LangCallback *xScrollCmd; |
| 165 |
|
| 166 |
|
| 167 |
int state; |
| 168 |
Pixmap gray; |
| 169 |
int flags; |
| 170 |
|
| 171 |
} Listbox; |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
typedef struct { |
| 178 |
Tk_3DBorder border; |
| 179 |
Tk_3DBorder selBorder; |
| 180 |
XColor *fgColor; |
| 181 |
XColor *selFgColor; |
| 182 |
} ItemAttr; |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
#define REDRAW_PENDING 1 |
| 201 |
#define UPDATE_V_SCROLLBAR 2 |
| 202 |
#define UPDATE_H_SCROLLBAR 4 |
| 203 |
#define GOT_FOCUS 8 |
| 204 |
#define MAXWIDTH_IS_STALE 16 |
| 205 |
#define LISTBOX_DELETED 32 |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
enum state { |
| 214 |
STATE_DISABLED, STATE_NORMAL |
| 215 |
}; |
| 216 |
|
| 217 |
static char *stateStrings[] = { |
| 218 |
"disabled", "normal", (char *) NULL |
| 219 |
}; |
| 220 |
|
| 221 |
enum activeStyle { |
| 222 |
ACTIVE_STYLE_DOTBOX, ACTIVE_STYLE_NONE, ACTIVE_STYLE_UNDERLINE |
| 223 |
}; |
| 224 |
|
| 225 |
static char *activeStyleStrings[] = { |
| 226 |
"dotbox", "none", "underline", (char *) NULL |
| 227 |
}; |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
static Tk_OptionSpec optionSpecs[] = { |
| 234 |
{TK_OPTION_STRING_TABLE, "-activestyle", "activeStyle", "ActiveStyle", |
| 235 |
DEF_LISTBOX_ACTIVE_STYLE, -1, Tk_Offset(Listbox, activeStyle), |
| 236 |
0, (ClientData) activeStyleStrings, 0}, |
| 237 |
{TK_OPTION_BORDER, "-background", "background", "Background", |
| 238 |
DEF_LISTBOX_BG_COLOR, -1, Tk_Offset(Listbox, normalBorder), |
| 239 |
0, (ClientData) DEF_LISTBOX_BG_MONO, 0}, |
| 240 |
{TK_OPTION_SYNONYM, "-bd", (char *) NULL, (char *) NULL, |
| 241 |
(char *) NULL, 0, -1, 0, (ClientData) "-borderwidth", 0}, |
| 242 |
{TK_OPTION_SYNONYM, "-bg", (char *) NULL, (char *) NULL, |
| 243 |
(char *) NULL, 0, -1, 0, (ClientData) "-background", 0}, |
| 244 |
{TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", |
| 245 |
DEF_LISTBOX_BORDER_WIDTH, -1, Tk_Offset(Listbox, borderWidth), |
| 246 |
0, 0, 0}, |
| 247 |
{TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", |
| 248 |
DEF_LISTBOX_CURSOR, -1, Tk_Offset(Listbox, cursor), |
| 249 |
TK_OPTION_NULL_OK, 0, 0}, |
| 250 |
{TK_OPTION_COLOR, "-disabledforeground", "disabledForeground", |
| 251 |
"DisabledForeground", DEF_LISTBOX_DISABLED_FG, -1, |
| 252 |
Tk_Offset(Listbox, dfgColorPtr), TK_OPTION_NULL_OK, 0, 0}, |
| 253 |
{TK_OPTION_BOOLEAN, "-exportselection", "exportSelection", |
| 254 |
"ExportSelection", DEF_LISTBOX_EXPORT_SELECTION, -1, |
| 255 |
Tk_Offset(Listbox, exportSelection), 0, 0, 0}, |
| 256 |
{TK_OPTION_SYNONYM, "-fg", "foreground", (char *) NULL, |
| 257 |
(char *) NULL, 0, -1, 0, (ClientData) "-foreground", 0}, |
| 258 |
{TK_OPTION_FONT, "-font", "font", "Font", |
| 259 |
DEF_LISTBOX_FONT, -1, Tk_Offset(Listbox, tkfont), 0, 0, 0}, |
| 260 |
{TK_OPTION_COLOR, "-foreground", "foreground", "Foreground", |
| 261 |
DEF_LISTBOX_FG, -1, Tk_Offset(Listbox, fgColorPtr), 0, 0, 0}, |
| 262 |
{TK_OPTION_INT, "-height", "height", "Height", |
| 263 |
DEF_LISTBOX_HEIGHT, -1, Tk_Offset(Listbox, height), 0, 0, 0}, |
| 264 |
{TK_OPTION_COLOR, "-highlightbackground", "highlightBackground", |
| 265 |
"HighlightBackground", DEF_LISTBOX_HIGHLIGHT_BG, -1, |
| 266 |
Tk_Offset(Listbox, highlightBgColorPtr), 0, 0, 0}, |
| 267 |
{TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor", |
| 268 |
DEF_LISTBOX_HIGHLIGHT, -1, Tk_Offset(Listbox, highlightColorPtr), |
| 269 |
0, 0, 0}, |
| 270 |
{TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness", |
| 271 |
"HighlightThickness", DEF_LISTBOX_HIGHLIGHT_WIDTH, -1, |
| 272 |
Tk_Offset(Listbox, highlightWidth), 0, 0, 0}, |
| 273 |
{TK_OPTION_RELIEF, "-relief", "relief", "Relief", |
| 274 |
DEF_LISTBOX_RELIEF, -1, Tk_Offset(Listbox, relief), 0, 0, 0}, |
| 275 |
{TK_OPTION_BORDER, "-selectbackground", "selectBackground", "Foreground", |
| 276 |
DEF_LISTBOX_SELECT_COLOR, -1, Tk_Offset(Listbox, selBorder), |
| 277 |
0, (ClientData) DEF_LISTBOX_SELECT_MONO, 0}, |
| 278 |
{TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth", |
| 279 |
"BorderWidth", DEF_LISTBOX_SELECT_BD, -1, |
| 280 |
Tk_Offset(Listbox, selBorderWidth), 0, 0, 0}, |
| 281 |
{TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background", |
| 282 |
DEF_LISTBOX_SELECT_FG_COLOR, -1, Tk_Offset(Listbox, selFgColorPtr), |
| 283 |
0, (ClientData) DEF_LISTBOX_SELECT_FG_MONO, 0}, |
| 284 |
{TK_OPTION_STRING, "-selectmode", "selectMode", "SelectMode", |
| 285 |
DEF_LISTBOX_SELECT_MODE, -1, Tk_Offset(Listbox, selectMode), |
| 286 |
TK_OPTION_NULL_OK, 0, 0}, |
| 287 |
{TK_OPTION_BOOLEAN, "-setgrid", "setGrid", "SetGrid", |
| 288 |
DEF_LISTBOX_SET_GRID, -1, Tk_Offset(Listbox, setGrid), 0, 0, 0}, |
| 289 |
{TK_OPTION_STRING_TABLE, "-state", "state", "State", |
| 290 |
DEF_LISTBOX_STATE, -1, Tk_Offset(Listbox, state), |
| 291 |
0, (ClientData) stateStrings, 0}, |
| 292 |
{TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus", |
| 293 |
DEF_LISTBOX_TAKE_FOCUS, -1, Tk_Offset(Listbox, takeFocus), |
| 294 |
TK_OPTION_NULL_OK, 0, 0}, |
| 295 |
{TK_OPTION_INT, "-width", "width", "Width", |
| 296 |
DEF_LISTBOX_WIDTH, -1, Tk_Offset(Listbox, width), 0, 0, 0}, |
| 297 |
{TK_OPTION_CALLBACK, "-xscrollcommand", "xScrollCommand", "ScrollCommand", |
| 298 |
DEF_LISTBOX_SCROLL_COMMAND, -1, Tk_Offset(Listbox, xScrollCmd), |
| 299 |
TK_OPTION_NULL_OK, 0, 0}, |
| 300 |
{TK_OPTION_CALLBACK, "-yscrollcommand", "yScrollCommand", "ScrollCommand", |
| 301 |
DEF_LISTBOX_SCROLL_COMMAND, -1, Tk_Offset(Listbox, yScrollCmd), |
| 302 |
TK_OPTION_NULL_OK, 0, 0}, |
| 303 |
{TK_OPTION_OBJ, "-listvariable", "listVariable", "Variable", |
| 304 |
DEF_LISTBOX_LIST_VARIABLE, -1, Tk_Offset(Listbox, listVarName), |
| 305 |
TK_OPTION_NULL_OK, 0, 0}, |
| 306 |
{TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 307 |
(char *) NULL, 0, -1, 0, 0, 0} |
| 308 |
}; |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
static Tk_OptionSpec itemAttrOptionSpecs[] = { |
| 315 |
{TK_OPTION_BORDER, "-background", "background", "Background", |
| 316 |
(char *)NULL, -1, Tk_Offset(ItemAttr, border), |
| 317 |
TK_OPTION_NULL_OK|TK_OPTION_DONT_SET_DEFAULT, |
| 318 |
(ClientData) DEF_LISTBOX_BG_MONO, 0}, |
| 319 |
{TK_OPTION_SYNONYM, "-bg", (char *) NULL, (char *) NULL, |
| 320 |
(char *) NULL, 0, -1, 0, (ClientData) "-background", 0}, |
| 321 |
{TK_OPTION_SYNONYM, "-fg", "foreground", (char *) NULL, |
| 322 |
(char *) NULL, 0, -1, 0, (ClientData) "-foreground", 0}, |
| 323 |
{TK_OPTION_COLOR, "-foreground", "foreground", "Foreground", |
| 324 |
(char *) NULL, -1, Tk_Offset(ItemAttr, fgColor), |
| 325 |
TK_OPTION_NULL_OK|TK_OPTION_DONT_SET_DEFAULT, 0, 0}, |
| 326 |
{TK_OPTION_BORDER, "-selectbackground", "selectBackground", "Foreground", |
| 327 |
(char *) NULL, -1, Tk_Offset(ItemAttr, selBorder), |
| 328 |
TK_OPTION_NULL_OK|TK_OPTION_DONT_SET_DEFAULT, |
| 329 |
(ClientData) DEF_LISTBOX_SELECT_MONO, 0}, |
| 330 |
{TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background", |
| 331 |
(char *) NULL, -1, Tk_Offset(ItemAttr, selFgColor), |
| 332 |
TK_OPTION_NULL_OK|TK_OPTION_DONT_SET_DEFAULT, |
| 333 |
(ClientData) DEF_LISTBOX_SELECT_FG_MONO, 0}, |
| 334 |
{TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 335 |
(char *) NULL, 0, -1, 0, 0, 0} |
| 336 |
}; |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
static CONST char *commandNames[] = { |
| 344 |
"activate", "bbox", "cget", "configure", "curselection", "delete", "get", |
| 345 |
"index", "insert", "itemcget", "itemconfigure", "nearest", "scan", |
| 346 |
"see", "selection", "size", "xview", "yview", |
| 347 |
(char *) NULL |
| 348 |
}; |
| 349 |
|
| 350 |
enum command { |
| 351 |
COMMAND_ACTIVATE, COMMAND_BBOX, COMMAND_CGET, COMMAND_CONFIGURE, |
| 352 |
COMMAND_CURSELECTION, COMMAND_DELETE, COMMAND_GET, COMMAND_INDEX, |
| 353 |
COMMAND_INSERT, COMMAND_ITEMCGET, COMMAND_ITEMCONFIGURE, |
| 354 |
COMMAND_NEAREST, COMMAND_SCAN, COMMAND_SEE, COMMAND_SELECTION, |
| 355 |
COMMAND_SIZE, COMMAND_XVIEW, COMMAND_YVIEW |
| 356 |
}; |
| 357 |
|
| 358 |
static CONST char *selCommandNames[] = { |
| 359 |
"anchor", "clear", "includes", "set", (char *) NULL |
| 360 |
}; |
| 361 |
|
| 362 |
enum selcommand { |
| 363 |
SELECTION_ANCHOR, SELECTION_CLEAR, SELECTION_INCLUDES, SELECTION_SET |
| 364 |
}; |
| 365 |
|
| 366 |
static CONST char *scanCommandNames[] = { |
| 367 |
"mark", "dragto", (char *) NULL |
| 368 |
}; |
| 369 |
|
| 370 |
enum scancommand { |
| 371 |
SCAN_MARK, SCAN_DRAGTO |
| 372 |
}; |
| 373 |
|
| 374 |
static CONST char *indexNames[] = { |
| 375 |
"active", "anchor", "end", (char *)NULL |
| 376 |
}; |
| 377 |
|
| 378 |
enum indices { |
| 379 |
INDEX_ACTIVE, INDEX_ANCHOR, INDEX_END |
| 380 |
}; |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
static void ChangeListboxOffset _ANSI_ARGS_((Listbox *listPtr, |
| 385 |
int offset)); |
| 386 |
static void ChangeListboxView _ANSI_ARGS_((Listbox *listPtr, |
| 387 |
int index)); |
| 388 |
static int ConfigureListbox _ANSI_ARGS_((Tcl_Interp *interp, |
| 389 |
Listbox *listPtr, int objc, Tcl_Obj *CONST objv[], |
| 390 |
int flags)); |
| 391 |
static int ConfigureListboxItem _ANSI_ARGS_ ((Tcl_Interp *interp, |
| 392 |
Listbox *listPtr, ItemAttr *attrs, int objc, |
| 393 |
Tcl_Obj *CONST objv[], int index)); |
| 394 |
static int ListboxDeleteSubCmd _ANSI_ARGS_((Listbox *listPtr, |
| 395 |
int first, int last)); |
| 396 |
static void DestroyListbox _ANSI_ARGS_((char *memPtr)); |
| 397 |
static void DestroyListboxOptionTables _ANSI_ARGS_ ( |
| 398 |
(ClientData clientData, Tcl_Interp *interp)); |
| 399 |
static void DisplayListbox _ANSI_ARGS_((ClientData clientData)); |
| 400 |
static int GetListboxIndex _ANSI_ARGS_((Tcl_Interp *interp, |
| 401 |
Listbox *listPtr, Tcl_Obj *index, int endIsSize, |
| 402 |
int *indexPtr)); |
| 403 |
static int ListboxInsertSubCmd _ANSI_ARGS_((Listbox *listPtr, |
| 404 |
int index, int objc, Tcl_Obj *CONST objv[])); |
| 405 |
static void ListboxCmdDeletedProc _ANSI_ARGS_(( |
| 406 |
ClientData clientData)); |
| 407 |
static void ListboxComputeGeometry _ANSI_ARGS_((Listbox *listPtr, |
| 408 |
int fontChanged, int maxIsStale, int updateGrid)); |
| 409 |
static void ListboxEventProc _ANSI_ARGS_((ClientData clientData, |
| 410 |
XEvent *eventPtr)); |
| 411 |
static int ListboxFetchSelection _ANSI_ARGS_(( |
| 412 |
ClientData clientData, int offset, char *buffer, |
| 413 |
int maxBytes)); |
| 414 |
static void ListboxLostSelection _ANSI_ARGS_(( |
| 415 |
ClientData clientData)); |
| 416 |
static void EventuallyRedrawRange _ANSI_ARGS_((Listbox *listPtr, |
| 417 |
int first, int last)); |
| 418 |
static void ListboxScanTo _ANSI_ARGS_((Listbox *listPtr, |
| 419 |
int x, int y)); |
| 420 |
static int ListboxSelect _ANSI_ARGS_((Listbox *listPtr, |
| 421 |
int first, int last, int select)); |
| 422 |
static void ListboxUpdateHScrollbar _ANSI_ARGS_( |
| 423 |
(Listbox *listPtr)); |
| 424 |
static void ListboxUpdateVScrollbar _ANSI_ARGS_( |
| 425 |
(Listbox *listPtr)); |
| 426 |
static int ListboxWidgetObjCmd _ANSI_ARGS_((ClientData clientData, |
| 427 |
Tcl_Interp *interp, int objc, |
| 428 |
Tcl_Obj *CONST objv[])); |
| 429 |
static int ListboxBboxSubCmd _ANSI_ARGS_ ((Tcl_Interp *interp, |
| 430 |
Listbox *listPtr, int index)); |
| 431 |
static int ListboxSelectionSubCmd _ANSI_ARGS_ ( |
| 432 |
(Tcl_Interp *interp, Listbox *listPtr, int objc, |
| 433 |
Tcl_Obj *CONST objv[])); |
| 434 |
static int ListboxXviewSubCmd _ANSI_ARGS_ ((Tcl_Interp *interp, |
| 435 |
Listbox *listPtr, int objc, |
| 436 |
Tcl_Obj *CONST objv[])); |
| 437 |
static int ListboxYviewSubCmd _ANSI_ARGS_ ((Tcl_Interp *interp, |
| 438 |
Listbox *listPtr, int objc, |
| 439 |
Tcl_Obj *CONST objv[])); |
| 440 |
static ItemAttr * ListboxGetItemAttributes _ANSI_ARGS_ ( |
| 441 |
(Tcl_Interp *interp, Listbox *listPtr, int index)); |
| 442 |
static void ListboxWorldChanged _ANSI_ARGS_(( |
| 443 |
ClientData instanceData)); |
| 444 |
static int NearestListboxElement _ANSI_ARGS_((Listbox *listPtr, |
| 445 |
int y)); |
| 446 |
static char * ListboxListVarProc _ANSI_ARGS_ ((ClientData clientData, |
| 447 |
Tcl_Interp *interp, Tcl_Obj *name1, |
| 448 |
CONST char *name2, int flags)); |
| 449 |
static void MigrateHashEntries _ANSI_ARGS_ ((Tcl_HashTable *table, |
| 450 |
int first, int last, int offset)); |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
static Tk_ClassProcs listboxClass = { |
| 457 |
sizeof(Tk_ClassProcs), |
| 458 |
ListboxWorldChanged, |
| 459 |
}; |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
int |
| 481 |
Tk_ListboxObjCmd(clientData, interp, objc, objv) |
| 482 |
ClientData clientData; |
| 483 |
Tcl_Interp *interp; |
| 484 |
int objc; |
| 485 |
Tcl_Obj *CONST objv[]; |
| 486 |
{ |
| 487 |
register Listbox *listPtr; |
| 488 |
Tk_Window tkwin; |
| 489 |
ListboxOptionTables *optionTables; |
| 490 |
|
| 491 |
if (objc < 2) { |
| 492 |
Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?"); |
| 493 |
return TCL_ERROR; |
| 494 |
} |
| 495 |
|
| 496 |
tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), |
| 497 |
Tcl_GetString(objv[1]), (char *) NULL); |
| 498 |
if (tkwin == NULL) { |
| 499 |
return TCL_ERROR; |
| 500 |
} |
| 501 |
|
| 502 |
optionTables = (ListboxOptionTables *) |
| 503 |
Tcl_GetAssocData(interp, "ListboxOptionTables", NULL); |
| 504 |
if (optionTables == NULL) { |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
optionTables = (ListboxOptionTables *) |
| 512 |
ckalloc(sizeof(ListboxOptionTables)); |
| 513 |
|
| 514 |
Tcl_SetAssocData(interp, "ListboxOptionTables", |
| 515 |
DestroyListboxOptionTables, (ClientData) optionTables); |
| 516 |
|
| 517 |
|
| 518 |
optionTables->listboxOptionTable = |
| 519 |
Tk_CreateOptionTable(interp, optionSpecs); |
| 520 |
optionTables->itemAttrOptionTable = |
| 521 |
Tk_CreateOptionTable(interp, itemAttrOptionSpecs); |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
listPtr = (Listbox *) ckalloc(sizeof(Listbox)); |
| 530 |
memset((void *) listPtr, 0, (sizeof(Listbox))); |
| 531 |
|
| 532 |
listPtr->tkwin = tkwin; |
| 533 |
listPtr->display = Tk_Display(tkwin); |
| 534 |
listPtr->interp = interp; |
| 535 |
listPtr->widgetCmd = Tcl_CreateObjCommand(interp, |
| 536 |
Tk_PathName(listPtr->tkwin), ListboxWidgetObjCmd, |
| 537 |
(ClientData) listPtr, ListboxCmdDeletedProc); |
| 538 |
listPtr->optionTable = optionTables->listboxOptionTable; |
| 539 |
listPtr->itemAttrOptionTable = optionTables->itemAttrOptionTable; |
| 540 |
listPtr->selection = |
| 541 |
(Tcl_HashTable *) ckalloc(sizeof(Tcl_HashTable)); |
| 542 |
Tcl_InitHashTable(listPtr->selection, TCL_ONE_WORD_KEYS); |
| 543 |
listPtr->itemAttrTable = |
| 544 |
(Tcl_HashTable *) ckalloc(sizeof(Tcl_HashTable)); |
| 545 |
Tcl_InitHashTable(listPtr->itemAttrTable, TCL_ONE_WORD_KEYS); |
| 546 |
listPtr->relief = TK_RELIEF_RAISED; |
| 547 |
listPtr->textGC = None; |
| 548 |
listPtr->selFgColorPtr = None; |
| 549 |
listPtr->selTextGC = None; |
| 550 |
listPtr->fullLines = 1; |
| 551 |
listPtr->xScrollUnit = 1; |
| 552 |
listPtr->exportSelection = 1; |
| 553 |
listPtr->cursor = None; |
| 554 |
listPtr->state = STATE_NORMAL; |
| 555 |
listPtr->gray = None; |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
Tcl_Preserve((ClientData) listPtr->tkwin); |
| 563 |
|
| 564 |
Tk_SetClass(listPtr->tkwin, "Listbox"); |
| 565 |
Tk_SetClassProcs(listPtr->tkwin, &listboxClass, (ClientData) listPtr); |
| 566 |
Tk_CreateEventHandler(listPtr->tkwin, |
| 567 |
ExposureMask|StructureNotifyMask|FocusChangeMask, |
| 568 |
ListboxEventProc, (ClientData) listPtr); |
| 569 |
Tk_CreateSelHandler(listPtr->tkwin, XA_PRIMARY, XA_STRING, |
| 570 |
ListboxFetchSelection, (ClientData) listPtr, XA_STRING); |
| 571 |
if (Tk_InitOptions(interp, (char *)listPtr, |
| 572 |
optionTables->listboxOptionTable, tkwin) != TCL_OK) { |
| 573 |
Tk_DestroyWindow(listPtr->tkwin); |
| 574 |
return TCL_ERROR; |
| 575 |
} |
| 576 |
|
| 577 |
if (ConfigureListbox(interp, listPtr, objc-2, objv+2, 0) != TCL_OK) { |
| 578 |
Tk_DestroyWindow(listPtr->tkwin); |
| 579 |
return TCL_ERROR; |
| 580 |
} |
| 581 |
|
| 582 |
Tcl_SetResult(interp, Tk_PathName(listPtr->tkwin), TCL_STATIC); |
| 583 |
return TCL_OK; |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
static int |
| 605 |
ListboxWidgetObjCmd(clientData, interp, objc, objv) |
| 606 |
ClientData clientData; |
| 607 |
Tcl_Interp *interp; |
| 608 |
int objc; |
| 609 |
Tcl_Obj *CONST objv[]; |
| 610 |
{ |
| 611 |
register Listbox *listPtr = (Listbox *) clientData; |
| 612 |
int cmdIndex, index; |
| 613 |
int result = TCL_OK; |
| 614 |
|
| 615 |
if (objc < 2) { |
| 616 |
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?"); |
| 617 |
return TCL_ERROR; |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
result = Tcl_GetIndexFromObj(interp, objv[1], commandNames, |
| 625 |
"option", 0, &cmdIndex); |
| 626 |
if (result != TCL_OK) { |
| 627 |
return result; |
| 628 |
} |
| 629 |
|
| 630 |
Tcl_Preserve((ClientData)listPtr); |
| 631 |
|
| 632 |
switch (cmdIndex) { |
| 633 |
case COMMAND_ACTIVATE: { |
| 634 |
if (objc != 3) { |
| 635 |
Tcl_WrongNumArgs(interp, 2, objv, "index"); |
| 636 |
result = TCL_ERROR; |
| 637 |
break; |
| 638 |
} |
| 639 |
result = GetListboxIndex(interp, listPtr, objv[2], 0, &index); |
| 640 |
if (result != TCL_OK) { |
| 641 |
break; |
| 642 |
} |
| 643 |
|
| 644 |
if (!(listPtr->state & STATE_NORMAL)) { |
| 645 |
break; |
| 646 |
} |
| 647 |
|
| 648 |
if (index >= listPtr->nElements) { |
| 649 |
index = listPtr->nElements-1; |
| 650 |
} |
| 651 |
if (index < 0) { |
| 652 |
index = 0; |
| 653 |
} |
| 654 |
listPtr->active = index; |
| 655 |
EventuallyRedrawRange(listPtr, listPtr->active, listPtr->active); |
| 656 |
result = TCL_OK; |
| 657 |
break; |
| 658 |
} |
| 659 |
|
| 660 |
case COMMAND_BBOX: { |
| 661 |
if (objc != 3) { |
| 662 |
Tcl_WrongNumArgs(interp, 2, objv, "index"); |
| 663 |
result = TCL_ERROR; |
| 664 |
break; |
| 665 |
} |
| 666 |
result = GetListboxIndex(interp, listPtr, objv[2], 0, &index); |
| 667 |
if (result != TCL_OK) { |
| 668 |
break; |
| 669 |
} |
| 670 |
|
| 671 |
result = ListboxBboxSubCmd(interp, listPtr, index); |
| 672 |
break; |
| 673 |
} |
| 674 |
|
| 675 |
case COMMAND_CGET: { |
| 676 |
Tcl_Obj *objPtr; |
| 677 |
if (objc != 3) { |
| 678 |
Tcl_WrongNumArgs(interp, 2, objv, "option"); |
| 679 |
result = TCL_ERROR; |
| 680 |
break; |
| 681 |
} |
| 682 |
|
| 683 |
objPtr = Tk_GetOptionValue(interp, (char *)listPtr, |
| 684 |
listPtr->optionTable, objv[2], listPtr->tkwin); |
| 685 |
if (objPtr == NULL) { |
| 686 |
result = TCL_ERROR; |
| 687 |
break; |
| 688 |
} |
| 689 |
Tcl_SetObjResult(interp, objPtr); |
| 690 |
result = TCL_OK; |
| 691 |
break; |
| 692 |
} |
| 693 |
|
| 694 |
case COMMAND_CONFIGURE: { |
| 695 |
Tcl_Obj *objPtr; |
| 696 |
if (objc <= 3) { |
| 697 |
objPtr = Tk_GetOptionInfo(interp, (char *) listPtr, |
| 698 |
listPtr->optionTable, |
| 699 |
(objc == 3) ? objv[2] : (Tcl_Obj *) NULL, |
| 700 |
listPtr->tkwin); |
| 701 |
if (objPtr == NULL) { |
| 702 |
result = TCL_ERROR; |
| 703 |
break; |
| 704 |
} else { |
| 705 |
Tcl_SetObjResult(interp, objPtr); |
| 706 |
result = TCL_OK; |
| 707 |
} |
| 708 |
} else { |
| 709 |
result = ConfigureListbox(interp, listPtr, objc-2, objv+2, 0); |
| 710 |
} |
| 711 |
break; |
| 712 |
} |
| 713 |
|
| 714 |
case COMMAND_CURSELECTION: { |
| 715 |
char indexStringRep[TCL_INTEGER_SPACE]; |
| 716 |
int i; |
| 717 |
if (objc != 2) { |
| 718 |
Tcl_WrongNumArgs(interp, 2, objv, NULL); |
| 719 |
result = TCL_ERROR; |
| 720 |
break; |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
for (i = 0; i < listPtr->nElements; i++) { |
| 730 |
if (Tcl_FindHashEntry(listPtr->selection, (char *)i) != NULL) { |
| 731 |
sprintf(indexStringRep, "%d", i); |
| 732 |
Tcl_AppendElement(interp, indexStringRep); |
| 733 |
} |
| 734 |
} |
| 735 |
result = TCL_OK; |
| 736 |
break; |
| 737 |
} |
| 738 |
|
| 739 |
case COMMAND_DELETE: { |
| 740 |
int first, last; |
| 741 |
if ((objc < 3) || (objc > 4)) { |
| 742 |
Tcl_WrongNumArgs(interp, 2, objv, |
| 743 |
"firstIndex ?lastIndex?"); |
| 744 |
result = TCL_ERROR; |
| 745 |
break; |
| 746 |
} |
| 747 |
|
| 748 |
result = GetListboxIndex(interp, listPtr, objv[2], 0, &first); |
| 749 |
if (result != TCL_OK) { |
| 750 |
break; |
| 751 |
} |
| 752 |
|
| 753 |
if (!(listPtr->state & STATE_NORMAL)) { |
| 754 |
break; |
| 755 |
} |
| 756 |
|
| 757 |
if (first < listPtr->nElements) { |
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
if (objc == 4) { |
| 763 |
result = GetListboxIndex(interp, listPtr, |
| 764 |
objv[3], 0, &last); |
| 765 |
if (result != TCL_OK) { |
| 766 |
break; |
| 767 |
} |
| 768 |
} else { |
| 769 |
last = first; |
| 770 |
} |
| 771 |
if (last >= listPtr->nElements) { |
| 772 |
last = listPtr->nElements - 1; |
| 773 |
} |
| 774 |
result = ListboxDeleteSubCmd(listPtr, first, last); |
| 775 |
} else { |
| 776 |
result = TCL_OK; |
| 777 |
} |
| 778 |
break; |
| 779 |
} |
| 780 |
|
| 781 |
case COMMAND_GET: { |
| 782 |
int first, last; |
| 783 |
Tcl_Obj **elemPtrs; |
| 784 |
int listLen; |
| 785 |
if (objc != 3 && objc != 4) { |
| 786 |
Tcl_WrongNumArgs(interp, 2, objv, "firstIndex ?lastIndex?"); |
| 787 |
result = TCL_ERROR; |
| 788 |
break; |
| 789 |
} |
| 790 |
result = GetListboxIndex(interp, listPtr, objv[2], 0, &first); |
| 791 |
if (result != TCL_OK) { |
| 792 |
break; |
| 793 |
} |
| 794 |
last = first; |
| 795 |
if (objc == 4) { |
| 796 |
result = GetListboxIndex(interp, listPtr, objv[3], 0, &last); |
| 797 |
if (result != TCL_OK) { |
| 798 |
break; |
| 799 |
} |
| 800 |
} |
| 801 |
if (first >= listPtr->nElements) { |
| 802 |
result = TCL_OK; |
| 803 |
break; |
| 804 |
} |
| 805 |
if (last >= listPtr->nElements) { |
| 806 |
last = listPtr->nElements - 1; |
| 807 |
} |
| 808 |
if (first < 0) { |
| 809 |
first = 0; |
| 810 |
} |
| 811 |
if (first > last) { |
| 812 |
result = TCL_OK; |
| 813 |
break; |
| 814 |
} |
| 815 |
result = Tcl_ListObjGetElements(interp, listPtr->listObj, &listLen, |
| 816 |
&elemPtrs); |
| 817 |
if (result != TCL_OK) { |
| 818 |
break; |
| 819 |
} |
| 820 |
if (objc == 3) { |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
Tcl_IncrRefCount(elemPtrs[first]); |
| 825 |
Tcl_SetObjResult(interp, elemPtrs[first]); |
| 826 |
} else { |
| 827 |
Tcl_SetListObj(Tcl_GetObjResult(interp), (last - first + 1), |
| 828 |
&(elemPtrs[first])); |
| 829 |
} |
| 830 |
result = TCL_OK; |
| 831 |
break; |
| 832 |
} |
| 833 |
|
| 834 |
case COMMAND_INDEX:{ |
| 835 |
char buf[TCL_INTEGER_SPACE]; |
| 836 |
if (objc != 3) { |
| 837 |
Tcl_WrongNumArgs(interp, 2, objv, "index"); |
| 838 |
result = TCL_ERROR; |
| 839 |
break; |
| 840 |
} |
| 841 |
result = GetListboxIndex(interp, listPtr, objv[2], 1, &index); |
| 842 |
if (result != TCL_OK) { |
| 843 |
break; |
| 844 |
} |
| 845 |
sprintf(buf, "%d", index); |
| 846 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 847 |
result = TCL_OK; |
| 848 |
break; |
| 849 |
} |
| 850 |
|
| 851 |
case COMMAND_INSERT: { |
| 852 |
if (objc < 3) { |
| 853 |
Tcl_WrongNumArgs(interp, 2, objv, |
| 854 |
"index ?element element ...?"); |
| 855 |
result = TCL_ERROR; |
| 856 |
break; |
| 857 |
} |
| 858 |
|
| 859 |
result = GetListboxIndex(interp, listPtr, objv[2], 1, &index); |
| 860 |
if (result != TCL_OK) { |
| 861 |
break; |
| 862 |
} |
| 863 |
|
| 864 |
if (!(listPtr->state & STATE_NORMAL)) { |
| 865 |
break; |
| 866 |
} |
| 867 |
|
| 868 |
result = ListboxInsertSubCmd(listPtr, index, objc-3, objv+3); |
| 869 |
break; |
| 870 |
} |
| 871 |
|
| 872 |
case COMMAND_ITEMCGET: { |
| 873 |
Tcl_Obj *objPtr; |
| 874 |
ItemAttr *attrPtr; |
| 875 |
if (objc != 4) { |
| 876 |
Tcl_WrongNumArgs(interp, 2, objv, "index option"); |
| 877 |
result = TCL_ERROR; |
| 878 |
break; |
| 879 |
} |
| 880 |
|
| 881 |
result = GetListboxIndex(interp, listPtr, objv[2], 0, &index); |
| 882 |
if (result != TCL_OK) { |
| 883 |
break; |
| 884 |
} |
| 885 |
|
| 886 |
if (index < 0 || index >= listPtr->nElements) { |
| 887 |
Tcl_AppendResult(interp, "item number \"", |
| 888 |
Tcl_GetString(objv[2]), "\" out of range", |
| 889 |
(char *)NULL); |
| 890 |
result = TCL_ERROR; |
| 891 |
break; |
| 892 |
} |
| 893 |
|
| 894 |
attrPtr = ListboxGetItemAttributes(interp, listPtr, index); |
| 895 |
|
| 896 |
objPtr = Tk_GetOptionValue(interp, (char *)attrPtr, |
| 897 |
listPtr->itemAttrOptionTable, objv[3], listPtr->tkwin); |
| 898 |
if (objPtr == NULL) { |
| 899 |
result = TCL_ERROR; |
| 900 |
break; |
| 901 |
} |
| 902 |
Tcl_SetObjResult(interp, objPtr); |
| 903 |
result = TCL_OK; |
| 904 |
break; |
| 905 |
} |
| 906 |
|
| 907 |
case COMMAND_ITEMCONFIGURE: { |
| 908 |
Tcl_Obj *objPtr; |
| 909 |
ItemAttr *attrPtr; |
| 910 |
if (objc < 3) { |
| 911 |
Tcl_WrongNumArgs(interp, 2, objv, |
| 912 |
"index ?option? ?value? ?option value ...?"); |
| 913 |
result = TCL_ERROR; |
| 914 |
break; |
| 915 |
} |
| 916 |
|
| 917 |
result = GetListboxIndex(interp, listPtr, objv[2], 0, &index); |
| 918 |
if (result != TCL_OK) { |
| 919 |
break; |
| 920 |
} |
| 921 |
|
| 922 |
if (index < 0 || index >= listPtr->nElements) { |
| 923 |
Tcl_AppendResult(interp, "item number \"", |
| 924 |
Tcl_GetString(objv[2]), "\" out of range", |
| 925 |
(char *)NULL); |
| 926 |
result = TCL_ERROR; |
| 927 |
break; |
| 928 |
} |
| 929 |
|
| 930 |
attrPtr = ListboxGetItemAttributes(interp, listPtr, index); |
| 931 |
if (objc <= 4) { |
| 932 |
objPtr = Tk_GetOptionInfo(interp, (char *)attrPtr, |
| 933 |
listPtr->itemAttrOptionTable, |
| 934 |
(objc == 4) ? objv[3] : (Tcl_Obj *) NULL, |
| 935 |
listPtr->tkwin); |
| 936 |
if (objPtr == NULL) { |
| 937 |
result = TCL_ERROR; |
| 938 |
break; |
| 939 |
} else { |
| 940 |
Tcl_SetObjResult(interp, objPtr); |
| 941 |
result = TCL_OK; |
| 942 |
} |
| 943 |
} else { |
| 944 |
result = ConfigureListboxItem(interp, listPtr, attrPtr, |
| 945 |
objc-3, objv+3, index); |
| 946 |
} |
| 947 |
break; |
| 948 |
} |
| 949 |
|
| 950 |
case COMMAND_NEAREST: { |
| 951 |
char buf[TCL_INTEGER_SPACE]; |
| 952 |
int y; |
| 953 |
if (objc != 3) { |
| 954 |
Tcl_WrongNumArgs(interp, 2, objv, "y"); |
| 955 |
result = TCL_ERROR; |
| 956 |
break; |
| 957 |
} |
| 958 |
|
| 959 |
result = Tcl_GetIntFromObj(interp, objv[2], &y); |
| 960 |
if (result != TCL_OK) { |
| 961 |
break; |
| 962 |
} |
| 963 |
index = NearestListboxElement(listPtr, y); |
| 964 |
sprintf(buf, "%d", index); |
| 965 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 966 |
result = TCL_OK; |
| 967 |
break; |
| 968 |
} |
| 969 |
|
| 970 |
case COMMAND_SCAN: { |
| 971 |
int x, y, scanCmdIndex; |
| 972 |
|
| 973 |
if (objc != 5) { |
| 974 |
Tcl_WrongNumArgs(interp, 2, objv, "mark|dragto x y"); |
| 975 |
result = TCL_ERROR; |
| 976 |
break; |
| 977 |
} |
| 978 |
|
| 979 |
if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK |
| 980 |
|| Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK) { |
| 981 |
result = TCL_ERROR; |
| 982 |
break; |
| 983 |
} |
| 984 |
|
| 985 |
result = Tcl_GetIndexFromObj(interp, objv[2], scanCommandNames, |
| 986 |
"option", 0, &scanCmdIndex); |
| 987 |
if (result != TCL_OK) { |
| 988 |
break; |
| 989 |
} |
| 990 |
switch (scanCmdIndex) { |
| 991 |
case SCAN_MARK: { |
| 992 |
listPtr->scanMarkX = x; |
| 993 |
listPtr->scanMarkY = y; |
| 994 |
listPtr->scanMarkXOffset = listPtr->xOffset; |
| 995 |
listPtr->scanMarkYIndex = listPtr->topIndex; |
| 996 |
break; |
| 997 |
} |
| 998 |
case SCAN_DRAGTO: { |
| 999 |
ListboxScanTo(listPtr, x, y); |
| 1000 |
break; |
| 1001 |
} |
| 1002 |
} |
| 1003 |
result = TCL_OK; |
| 1004 |
break; |
| 1005 |
} |
| 1006 |
|
| 1007 |
case COMMAND_SEE: { |
| 1008 |
int diff; |
| 1009 |
if (objc != 3) { |
| 1010 |
Tcl_WrongNumArgs(interp, 2, objv, "index"); |
| 1011 |
result = TCL_ERROR; |
| 1012 |
break; |
| 1013 |
} |
| 1014 |
result = GetListboxIndex(interp, listPtr, objv[2], 0, &index); |
| 1015 |
if (result != TCL_OK) { |
| 1016 |
break; |
| 1017 |
} |
| 1018 |
if (index >= listPtr->nElements) { |
| 1019 |
index = listPtr->nElements - 1; |
| 1020 |
} |
| 1021 |
if (index < 0) { |
| 1022 |
index = 0; |
| 1023 |
} |
| 1024 |
diff = listPtr->topIndex - index; |
| 1025 |
if (diff > 0) { |
| 1026 |
if (diff <= (listPtr->fullLines/3)) { |
| 1027 |
ChangeListboxView(listPtr, index); |
| 1028 |
} else { |
| 1029 |
ChangeListboxView(listPtr, |
| 1030 |
index - (listPtr->fullLines-1)/2); |
| 1031 |
} |
| 1032 |
} else { |
| 1033 |
diff = index - (listPtr->topIndex + listPtr->fullLines - 1); |
| 1034 |
if (diff > 0) { |
| 1035 |
if (diff <= (listPtr->fullLines/3)) { |
| 1036 |
ChangeListboxView(listPtr, listPtr->topIndex + diff); |
| 1037 |
} else { |
| 1038 |
ChangeListboxView(listPtr, |
| 1039 |
index - (listPtr->fullLines-1)/2); |
| 1040 |
} |
| 1041 |
} |
| 1042 |
} |
| 1043 |
result = TCL_OK; |
| 1044 |
break; |
| 1045 |
} |
| 1046 |
|
| 1047 |
case COMMAND_SELECTION: { |
| 1048 |
result = ListboxSelectionSubCmd(interp, listPtr, objc, objv); |
| 1049 |
break; |
| 1050 |
} |
| 1051 |
|
| 1052 |
case COMMAND_SIZE: { |
| 1053 |
char buf[TCL_INTEGER_SPACE]; |
| 1054 |
if (objc != 2) { |
| 1055 |
Tcl_WrongNumArgs(interp, 2, objv, NULL); |
| 1056 |
result = TCL_ERROR; |
| 1057 |
break; |
| 1058 |
} |
| 1059 |
sprintf(buf, "%d", listPtr->nElements); |
| 1060 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 1061 |
result = TCL_OK; |
| 1062 |
break; |
| 1063 |
} |
| 1064 |
|
| 1065 |
case COMMAND_XVIEW: { |
| 1066 |
result = ListboxXviewSubCmd(interp, listPtr, objc, objv); |
| 1067 |
break; |
| 1068 |
} |
| 1069 |
|
| 1070 |
case COMMAND_YVIEW: { |
| 1071 |
result = ListboxYviewSubCmd(interp, listPtr, objc, objv); |
| 1072 |
break; |
| 1073 |
} |
| 1074 |
} |
| 1075 |
Tcl_Release((ClientData)listPtr); |
| 1076 |
return result; |
| 1077 |
} |
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
static int |
| 1098 |
ListboxBboxSubCmd(interp, listPtr, index) |
| 1099 |
Tcl_Interp *interp; |
| 1100 |
Listbox *listPtr; |
| 1101 |
int index; |
| 1102 |
{ |
| 1103 |
int lastVisibleIndex; |
| 1104 |
|
| 1105 |
lastVisibleIndex = listPtr->topIndex + listPtr->fullLines |
| 1106 |
+ listPtr->partialLine; |
| 1107 |
if (listPtr->nElements < lastVisibleIndex) { |
| 1108 |
lastVisibleIndex = listPtr->nElements; |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
if ((listPtr->topIndex <= index) && (index < lastVisibleIndex)) { |
| 1113 |
char buf[TCL_INTEGER_SPACE * 4]; |
| 1114 |
Tcl_Obj *el; |
| 1115 |
char *stringRep; |
| 1116 |
int pixelWidth, stringLen, x, y, result; |
| 1117 |
Tk_FontMetrics fm; |
| 1118 |
|
| 1119 |
|
| 1120 |
result = Tcl_ListObjIndex(interp, listPtr->listObj, index, &el); |
| 1121 |
if (result != TCL_OK) { |
| 1122 |
return result; |
| 1123 |
} |
| 1124 |
|
| 1125 |
stringRep = Tcl_GetStringFromObj(el, &stringLen); |
| 1126 |
Tk_GetFontMetrics(listPtr->tkfont, &fm); |
| 1127 |
pixelWidth = Tk_TextWidth(listPtr->tkfont, stringRep, stringLen); |
| 1128 |
|
| 1129 |
x = listPtr->inset + listPtr->selBorderWidth - listPtr->xOffset; |
| 1130 |
y = ((index - listPtr->topIndex)*listPtr->lineHeight) |
| 1131 |
+ listPtr->inset + listPtr->selBorderWidth; |
| 1132 |
el = Tcl_GetObjResult(interp); |
| 1133 |
Tcl_ListObjAppendElement(interp,el,Tcl_NewIntObj(x)); |
| 1134 |
Tcl_ListObjAppendElement(interp,el,Tcl_NewIntObj(y)); |
| 1135 |
Tcl_ListObjAppendElement(interp,el,Tcl_NewIntObj(pixelWidth)); |
| 1136 |
Tcl_ListObjAppendElement(interp,el,Tcl_NewIntObj(fm.linespace)); |
| 1137 |
} |
| 1138 |
return TCL_OK; |
| 1139 |
} |
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
static int |
| 1159 |
ListboxSelectionSubCmd(interp, listPtr, objc, objv) |
| 1160 |
Tcl_Interp *interp; |
| 1161 |
Listbox *listPtr; |
| 1162 |
int objc; |
| 1163 |
Tcl_Obj *CONST objv[]; |
| 1164 |
{ |
| 1165 |
int selCmdIndex, first, last; |
| 1166 |
int result = TCL_OK; |
| 1167 |
if (objc != 4 && objc != 5) { |
| 1168 |
Tcl_WrongNumArgs(interp, 2, objv, "option index ?index?"); |
| 1169 |
return TCL_ERROR; |
| 1170 |
} |
| 1171 |
result = GetListboxIndex(interp, listPtr, objv[3], 0, &first); |
| 1172 |
if (result != TCL_OK) { |
| 1173 |
return result; |
| 1174 |
} |
| 1175 |
last = first; |
| 1176 |
if (objc == 5) { |
| 1177 |
result = GetListboxIndex(interp, listPtr, objv[4], 0, &last); |
| 1178 |
if (result != TCL_OK) { |
| 1179 |
return result; |
| 1180 |
} |
| 1181 |
} |
| 1182 |
result = Tcl_GetIndexFromObj(interp, objv[2], selCommandNames, |
| 1183 |
"option", 0, &selCmdIndex); |
| 1184 |
if (result != TCL_OK) { |
| 1185 |
return result; |
| 1186 |
} |
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
if ((listPtr->state == STATE_DISABLED) |
| 1193 |
&& (selCmdIndex != SELECTION_INCLUDES)) { |
| 1194 |
return TCL_OK; |
| 1195 |
} |
| 1196 |
|
| 1197 |
switch (selCmdIndex) { |
| 1198 |
case SELECTION_ANCHOR: { |
| 1199 |
if (objc != 4) { |
| 1200 |
Tcl_WrongNumArgs(interp, 3, objv, "index"); |
| 1201 |
return TCL_ERROR; |
| 1202 |
} |
| 1203 |
if (first >= listPtr->nElements) { |
| 1204 |
first = listPtr->nElements - 1; |
| 1205 |
} |
| 1206 |
if (first < 0) { |
| 1207 |
first = 0; |
| 1208 |
} |
| 1209 |
listPtr->selectAnchor = first; |
| 1210 |
result = TCL_OK; |
| 1211 |
break; |
| 1212 |
} |
| 1213 |
case SELECTION_CLEAR: { |
| 1214 |
result = ListboxSelect(listPtr, first, last, 0); |
| 1215 |
break; |
| 1216 |
} |
| 1217 |
case SELECTION_INCLUDES: { |
| 1218 |
if (objc != 4) { |
| 1219 |
Tcl_WrongNumArgs(interp, 3, objv, "index"); |
| 1220 |
return TCL_ERROR; |
| 1221 |
} |
| 1222 |
Tcl_SetObjResult(interp, |
| 1223 |
Tcl_NewBooleanObj((Tcl_FindHashEntry(listPtr->selection, |
| 1224 |
(char *)first) != NULL))); |
| 1225 |
result = TCL_OK; |
| 1226 |
break; |
| 1227 |
} |
| 1228 |
case SELECTION_SET: { |
| 1229 |
result = ListboxSelect(listPtr, first, last, 1); |
| 1230 |
break; |
| 1231 |
} |
| 1232 |
} |
| 1233 |
return result; |
| 1234 |
} |
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
static int |
| 1253 |
ListboxXviewSubCmd(interp, listPtr, objc, objv) |
| 1254 |
Tcl_Interp *interp; |
| 1255 |
Listbox *listPtr; |
| 1256 |
int objc; |
| 1257 |
Tcl_Obj *CONST objv[]; |
| 1258 |
{ |
| 1259 |
|
| 1260 |
int index, count, type, windowWidth, windowUnits; |
| 1261 |
int offset = 0; |
| 1262 |
double fraction, fraction2; |
| 1263 |
|
| 1264 |
windowWidth = Tk_Width(listPtr->tkwin) |
| 1265 |
- 2*(listPtr->inset + listPtr->selBorderWidth); |
| 1266 |
if (objc == 2) { |
| 1267 |
if (listPtr->maxWidth == 0) { |
| 1268 |
fraction = 0; |
| 1269 |
fraction2 = 1; |
| 1270 |
} else { |
| 1271 |
fraction = listPtr->xOffset/((double) listPtr->maxWidth); |
| 1272 |
fraction2 = (listPtr->xOffset + windowWidth) |
| 1273 |
/((double) listPtr->maxWidth); |
| 1274 |
if (fraction2 > 1.0) { |
| 1275 |
fraction2 = 1.0; |
| 1276 |
} |
| 1277 |
} |
| 1278 |
Tcl_DoubleResults(interp,2,0, fraction, fraction2); |
| 1279 |
} else if (objc == 3) { |
| 1280 |
if (Tcl_GetIntFromObj(interp, objv[2], &index) != TCL_OK) { |
| 1281 |
return TCL_ERROR; |
| 1282 |
} |
| 1283 |
ChangeListboxOffset(listPtr, index*listPtr->xScrollUnit); |
| 1284 |
} else { |
| 1285 |
type = Tk_GetScrollInfoObj(interp, objc, objv, &fraction, &count); |
| 1286 |
switch (type) { |
| 1287 |
case TK_SCROLL_ERROR: |
| 1288 |
return TCL_ERROR; |
| 1289 |
case TK_SCROLL_MOVETO: |
| 1290 |
offset = (int) (fraction*listPtr->maxWidth + 0.5); |
| 1291 |
break; |
| 1292 |
case TK_SCROLL_PAGES: |
| 1293 |
windowUnits = windowWidth/listPtr->xScrollUnit; |
| 1294 |
if (windowUnits > 2) { |
| 1295 |
offset = listPtr->xOffset |
| 1296 |
+ count*listPtr->xScrollUnit*(windowUnits-2); |
| 1297 |
} else { |
| 1298 |
offset = listPtr->xOffset + count*listPtr->xScrollUnit; |
| 1299 |
} |
| 1300 |
break; |
| 1301 |
case TK_SCROLL_UNITS: |
| 1302 |
offset = listPtr->xOffset + count*listPtr->xScrollUnit; |
| 1303 |
break; |
| 1304 |
} |
| 1305 |
ChangeListboxOffset(listPtr, offset); |
| 1306 |
} |
| 1307 |
return TCL_OK; |
| 1308 |
} |
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
static int |
| 1327 |
ListboxYviewSubCmd(interp, listPtr, objc, objv) |
| 1328 |
Tcl_Interp *interp; |
| 1329 |
Listbox *listPtr; |
| 1330 |
int objc; |
| 1331 |
Tcl_Obj *CONST objv[]; |
| 1332 |
{ |
| 1333 |
int index, count, type; |
| 1334 |
double fraction, fraction2; |
| 1335 |
|
| 1336 |
if (objc == 2) { |
| 1337 |
if (listPtr->nElements == 0) { |
| 1338 |
fraction = 0; |
| 1339 |
fraction2 = 1; |
| 1340 |
} else { |
| 1341 |
fraction = listPtr->topIndex/((double) listPtr->nElements); |
| 1342 |
fraction2 = (listPtr->topIndex+listPtr->fullLines) |
| 1343 |
/((double) listPtr->nElements); |
| 1344 |
if (fraction2 > 1.0) { |
| 1345 |
fraction2 = 1.0; |
| 1346 |
} |
| 1347 |
} |
| 1348 |
Tcl_DoubleResults(interp,2,0, fraction, fraction2); |
| 1349 |
} else if (objc == 3) { |
| 1350 |
if (GetListboxIndex(interp, listPtr, objv[2], 0, &index) != TCL_OK) { |
| 1351 |
return TCL_ERROR; |
| 1352 |
} |
| 1353 |
ChangeListboxView(listPtr, index); |
| 1354 |
} else { |
| 1355 |
type = Tk_GetScrollInfoObj(interp, objc, objv, &fraction, &count); |
| 1356 |
switch (type) { |
| 1357 |
case TK_SCROLL_ERROR: |
| 1358 |
return TCL_ERROR; |
| 1359 |
case TK_SCROLL_MOVETO: |
| 1360 |
index = (int) (listPtr->nElements*fraction + 0.5); |
| 1361 |
break; |
| 1362 |
case TK_SCROLL_PAGES: |
| 1363 |
if (listPtr->fullLines > 2) { |
| 1364 |
index = listPtr->topIndex |
| 1365 |
+ count*(listPtr->fullLines-2); |
| 1366 |
} else { |
| 1367 |
index = listPtr->topIndex + count; |
| 1368 |
} |
| 1369 |
break; |
| 1370 |
case TK_SCROLL_UNITS: |
| 1371 |
index = listPtr->topIndex + count; |
| 1372 |
break; |
| 1373 |
} |
| 1374 |
ChangeListboxView(listPtr, index); |
| 1375 |
} |
| 1376 |
return TCL_OK; |
| 1377 |
} |
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
static ItemAttr * |
| 1397 |
ListboxGetItemAttributes(interp, listPtr, index) |
| 1398 |
Tcl_Interp *interp; |
| 1399 |
Listbox *listPtr; |
| 1400 |
int index; |
| 1401 |
|
| 1402 |
{ |
| 1403 |
int new; |
| 1404 |
Tcl_HashEntry *entry; |
| 1405 |
ItemAttr *attrs; |
| 1406 |
|
| 1407 |
entry = Tcl_CreateHashEntry(listPtr->itemAttrTable, (char *)index, &new); |
| 1408 |
if (new) { |
| 1409 |
attrs = (ItemAttr *) ckalloc(sizeof(ItemAttr)); |
| 1410 |
attrs->border = NULL; |
| 1411 |
attrs->selBorder = NULL; |
| 1412 |
attrs->fgColor = NULL; |
| 1413 |
attrs->selFgColor = NULL; |
| 1414 |
Tk_InitOptions(interp, (char *)attrs, listPtr->itemAttrOptionTable, |
| 1415 |
listPtr->tkwin); |
| 1416 |
Tcl_SetHashValue(entry, (ClientData) attrs); |
| 1417 |
} |
| 1418 |
attrs = (ItemAttr *)Tcl_GetHashValue(entry); |
| 1419 |
return attrs; |
| 1420 |
} |
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
static void |
| 1441 |
DestroyListbox(memPtr) |
| 1442 |
char *memPtr; |
| 1443 |
{ |
| 1444 |
register Listbox *listPtr = (Listbox *) memPtr; |
| 1445 |
Tcl_HashEntry *entry; |
| 1446 |
Tcl_HashSearch search; |
| 1447 |
|
| 1448 |
|
| 1449 |
if (listPtr->listObj != NULL) { |
| 1450 |
Tcl_DecrRefCount(listPtr->listObj); |
| 1451 |
listPtr->listObj = NULL; |
| 1452 |
} |
| 1453 |
|
| 1454 |
if (listPtr->listVarName != NULL) { |
| 1455 |
Lang_UntraceVar(listPtr->interp, listPtr->listVarName, |
| 1456 |
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, |
| 1457 |
ListboxListVarProc, (ClientData) listPtr); |
| 1458 |
} |
| 1459 |
|
| 1460 |
|
| 1461 |
Tcl_DeleteHashTable(listPtr->selection); |
| 1462 |
ckfree((char *)listPtr->selection); |
| 1463 |
|
| 1464 |
|
| 1465 |
for (entry = Tcl_FirstHashEntry(listPtr->itemAttrTable, &search); |
| 1466 |
entry != NULL; entry = Tcl_NextHashEntry(&search)) { |
| 1467 |
ckfree((char *)Tcl_GetHashValue(entry)); |
| 1468 |
} |
| 1469 |
Tcl_DeleteHashTable(listPtr->itemAttrTable); |
| 1470 |
ckfree((char *)listPtr->itemAttrTable); |
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
if (listPtr->textGC != None) { |
| 1479 |
Tk_FreeGC(listPtr->display, listPtr->textGC); |
| 1480 |
} |
| 1481 |
if (listPtr->selTextGC != None) { |
| 1482 |
Tk_FreeGC(listPtr->display, listPtr->selTextGC); |
| 1483 |
} |
| 1484 |
if (listPtr->gray != None) { |
| 1485 |
Tk_FreeBitmap(Tk_Display(listPtr->tkwin), listPtr->gray); |
| 1486 |
} |
| 1487 |
|
| 1488 |
Tk_FreeConfigOptions((char *)listPtr, listPtr->optionTable, |
| 1489 |
listPtr->tkwin); |
| 1490 |
Tcl_Release((ClientData) listPtr->tkwin); |
| 1491 |
listPtr->tkwin = NULL; |
| 1492 |
ckfree((char *) listPtr); |
| 1493 |
} |
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
static void |
| 1514 |
DestroyListboxOptionTables(clientData, interp) |
| 1515 |
ClientData clientData; |
| 1516 |
Tcl_Interp *interp; |
| 1517 |
{ |
| 1518 |
ckfree((char *)clientData); |
| 1519 |
return; |
| 1520 |
} |
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
static int |
| 1544 |
ConfigureListbox(interp, listPtr, objc, objv, flags) |
| 1545 |
Tcl_Interp *interp; |
| 1546 |
register Listbox *listPtr; |
| 1547 |
|
| 1548 |
int objc; |
| 1549 |
Tcl_Obj *CONST objv[]; |
| 1550 |
int flags; |
| 1551 |
{ |
| 1552 |
Tk_SavedOptions savedOptions; |
| 1553 |
Tcl_Obj *oldListObj = NULL; |
| 1554 |
Tcl_Obj *errorResult = NULL; |
| 1555 |
int oldExport, error; |
| 1556 |
|
| 1557 |
oldExport = listPtr->exportSelection; |
| 1558 |
if (listPtr->listVarName != NULL) { |
| 1559 |
Lang_UntraceVar(interp, listPtr->listVarName, |
| 1560 |
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, |
| 1561 |
ListboxListVarProc, (ClientData) listPtr); |
| 1562 |
} |
| 1563 |
|
| 1564 |
for (error = 0; error <= 1; error++) { |
| 1565 |
if (!error) { |
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
if (Tk_SetOptions(interp, (char *) listPtr, |
| 1571 |
listPtr->optionTable, objc, objv, |
| 1572 |
listPtr->tkwin, &savedOptions, (int *) NULL) != TCL_OK) { |
| 1573 |
continue; |
| 1574 |
} |
| 1575 |
} else { |
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
errorResult = Tcl_GetObjResult(interp); |
| 1581 |
Tcl_IncrRefCount(errorResult); |
| 1582 |
Tk_RestoreSavedOptions(&savedOptions); |
| 1583 |
} |
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
Tk_SetBackgroundFromBorder(listPtr->tkwin, listPtr->normalBorder); |
| 1591 |
|
| 1592 |
if (listPtr->highlightWidth < 0) { |
| 1593 |
listPtr->highlightWidth = 0; |
| 1594 |
} |
| 1595 |
listPtr->inset = listPtr->highlightWidth + listPtr->borderWidth; |
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
if (listPtr->exportSelection && !oldExport |
| 1603 |
&& (listPtr->numSelected != 0)) { |
| 1604 |
Tk_OwnSelection(listPtr->tkwin, XA_PRIMARY, ListboxLostSelection, |
| 1605 |
(ClientData) listPtr); |
| 1606 |
} |
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
oldListObj = listPtr->listObj; |
| 1624 |
if (listPtr->listVarName != NULL) { |
| 1625 |
Tcl_Obj *listVarObj = Tcl_ObjGetVar2(interp, listPtr->listVarName, |
| 1626 |
(char *) NULL, TCL_GLOBAL_ONLY); |
| 1627 |
int dummy; |
| 1628 |
if (listVarObj == NULL) { |
| 1629 |
listVarObj = (oldListObj ? oldListObj : Tcl_NewObj()); |
| 1630 |
if (Tcl_ObjSetVar2(interp, listPtr->listVarName, (char *) NULL, |
| 1631 |
listVarObj, TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG) |
| 1632 |
== NULL) { |
| 1633 |
if (oldListObj == NULL) { |
| 1634 |
Tcl_DecrRefCount(listVarObj); |
| 1635 |
} |
| 1636 |
continue; |
| 1637 |
} |
| 1638 |
} |
| 1639 |
|
| 1640 |
if (Tcl_ListObjLength(listPtr->interp, listVarObj, &dummy) |
| 1641 |
!= TCL_OK) { |
| 1642 |
Tcl_AppendResult(listPtr->interp, |
| 1643 |
": invalid -listvariable value", (char *) NULL); |
| 1644 |
continue; |
| 1645 |
} |
| 1646 |
|
| 1647 |
listPtr->listObj = listVarObj; |
| 1648 |
Lang_TraceVar(listPtr->interp, listPtr->listVarName, |
| 1649 |
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, |
| 1650 |
ListboxListVarProc, (ClientData) listPtr); |
| 1651 |
} else if (listPtr->listObj == NULL) { |
| 1652 |
listPtr->listObj = Tcl_NewObj(); |
| 1653 |
} |
| 1654 |
Tcl_IncrRefCount(listPtr->listObj); |
| 1655 |
if (oldListObj != NULL) { |
| 1656 |
Tcl_DecrRefCount(oldListObj); |
| 1657 |
} |
| 1658 |
break; |
| 1659 |
} |
| 1660 |
if (!error) { |
| 1661 |
Tk_FreeSavedOptions(&savedOptions); |
| 1662 |
} |
| 1663 |
|
| 1664 |
|
| 1665 |
Tcl_ListObjLength(listPtr->interp, listPtr->listObj, &listPtr->nElements); |
| 1666 |
|
| 1667 |
if (error) { |
| 1668 |
Tcl_SetObjResult(interp, errorResult); |
| 1669 |
Tcl_DecrRefCount(errorResult); |
| 1670 |
return TCL_ERROR; |
| 1671 |
} else { |
| 1672 |
ListboxWorldChanged((ClientData) listPtr); |
| 1673 |
return TCL_OK; |
| 1674 |
} |
| 1675 |
} |
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
static int |
| 1699 |
ConfigureListboxItem(interp, listPtr, attrs, objc, objv, index) |
| 1700 |
Tcl_Interp *interp; |
| 1701 |
register Listbox *listPtr; |
| 1702 |
|
| 1703 |
ItemAttr *attrs; |
| 1704 |
int objc; |
| 1705 |
Tcl_Obj *CONST objv[]; |
| 1706 |
int index; |
| 1707 |
{ |
| 1708 |
Tk_SavedOptions savedOptions; |
| 1709 |
|
| 1710 |
if (Tk_SetOptions(interp, (char *)attrs, |
| 1711 |
listPtr->itemAttrOptionTable, objc, objv, listPtr->tkwin, |
| 1712 |
&savedOptions, (int *)NULL) != TCL_OK) { |
| 1713 |
Tk_RestoreSavedOptions(&savedOptions); |
| 1714 |
return TCL_ERROR; |
| 1715 |
} |
| 1716 |
Tk_FreeSavedOptions(&savedOptions); |
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
EventuallyRedrawRange(listPtr, index, index); |
| 1722 |
return TCL_OK; |
| 1723 |
} |
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
static void |
| 1744 |
ListboxWorldChanged(instanceData) |
| 1745 |
ClientData instanceData; |
| 1746 |
{ |
| 1747 |
XGCValues gcValues; |
| 1748 |
GC gc; |
| 1749 |
unsigned long mask; |
| 1750 |
Listbox *listPtr; |
| 1751 |
|
| 1752 |
listPtr = (Listbox *) instanceData; |
| 1753 |
|
| 1754 |
if (listPtr->state & STATE_NORMAL) { |
| 1755 |
gcValues.foreground = listPtr->fgColorPtr->pixel; |
| 1756 |
gcValues.graphics_exposures = False; |
| 1757 |
mask = GCForeground | GCFont | GCGraphicsExposures; |
| 1758 |
} else { |
| 1759 |
if (listPtr->dfgColorPtr != NULL) { |
| 1760 |
gcValues.foreground = listPtr->dfgColorPtr->pixel; |
| 1761 |
gcValues.graphics_exposures = False; |
| 1762 |
mask = GCForeground | GCFont | GCGraphicsExposures; |
| 1763 |
} else { |
| 1764 |
gcValues.foreground = listPtr->fgColorPtr->pixel; |
| 1765 |
mask = GCForeground | GCFont; |
| 1766 |
if (listPtr->gray == None) { |
| 1767 |
listPtr->gray = Tk_GetBitmap(NULL, listPtr->tkwin, "gray50"); |
| 1768 |
} |
| 1769 |
if (listPtr->gray != None) { |
| 1770 |
gcValues.fill_style = FillStippled; |
| 1771 |
gcValues.stipple = listPtr->gray; |
| 1772 |
mask |= GCFillStyle | GCStipple; |
| 1773 |
} |
| 1774 |
} |
| 1775 |
} |
| 1776 |
|
| 1777 |
gcValues.font = Tk_FontId(listPtr->tkfont); |
| 1778 |
gc = Tk_GetGC(listPtr->tkwin, mask, &gcValues); |
| 1779 |
if (listPtr->textGC != None) { |
| 1780 |
Tk_FreeGC(listPtr->display, listPtr->textGC); |
| 1781 |
} |
| 1782 |
listPtr->textGC = gc; |
| 1783 |
|
| 1784 |
gcValues.foreground = listPtr->selFgColorPtr->pixel; |
| 1785 |
gcValues.font = Tk_FontId(listPtr->tkfont); |
| 1786 |
mask = GCForeground | GCFont; |
| 1787 |
gc = Tk_GetGC(listPtr->tkwin, mask, &gcValues); |
| 1788 |
if (listPtr->selTextGC != None) { |
| 1789 |
Tk_FreeGC(listPtr->display, listPtr->selTextGC); |
| 1790 |
} |
| 1791 |
listPtr->selTextGC = gc; |
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
ListboxComputeGeometry(listPtr, 1, 1, 1); |
| 1799 |
listPtr->flags |= UPDATE_V_SCROLLBAR|UPDATE_H_SCROLLBAR; |
| 1800 |
EventuallyRedrawRange(listPtr, 0, listPtr->nElements-1); |
| 1801 |
} |
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
static void |
| 1820 |
DisplayListbox(clientData) |
| 1821 |
ClientData clientData; |
| 1822 |
{ |
| 1823 |
register Listbox *listPtr = (Listbox *) clientData; |
| 1824 |
register Tk_Window tkwin = listPtr->tkwin; |
| 1825 |
GC gc; |
| 1826 |
int i, limit, x, y, width, prevSelected, freeGC; |
| 1827 |
Tk_FontMetrics fm; |
| 1828 |
Tcl_Obj *curElement; |
| 1829 |
Tcl_HashEntry *entry; |
| 1830 |
char *stringRep; |
| 1831 |
int stringLen; |
| 1832 |
ItemAttr *attrs; |
| 1833 |
Tk_3DBorder selectedBg; |
| 1834 |
XGCValues gcValues; |
| 1835 |
unsigned long mask; |
| 1836 |
int left, right; |
| 1837 |
|
| 1838 |
|
| 1839 |
Pixmap pixmap; |
| 1840 |
|
| 1841 |
listPtr->flags &= ~REDRAW_PENDING; |
| 1842 |
if (listPtr->flags & LISTBOX_DELETED) { |
| 1843 |
return; |
| 1844 |
} |
| 1845 |
|
| 1846 |
if (listPtr->flags & MAXWIDTH_IS_STALE) { |
| 1847 |
ListboxComputeGeometry(listPtr, 0, 1, 0); |
| 1848 |
listPtr->flags &= ~MAXWIDTH_IS_STALE; |
| 1849 |
listPtr->flags |= UPDATE_H_SCROLLBAR; |
| 1850 |
} |
| 1851 |
|
| 1852 |
Tcl_Preserve((ClientData) listPtr); |
| 1853 |
if (listPtr->flags & UPDATE_V_SCROLLBAR) { |
| 1854 |
ListboxUpdateVScrollbar(listPtr); |
| 1855 |
if ((listPtr->flags & LISTBOX_DELETED) || !Tk_IsMapped(tkwin)) { |
| 1856 |
Tcl_Release((ClientData) listPtr); |
| 1857 |
return; |
| 1858 |
} |
| 1859 |
} |
| 1860 |
if (listPtr->flags & UPDATE_H_SCROLLBAR) { |
| 1861 |
ListboxUpdateHScrollbar(listPtr); |
| 1862 |
if ((listPtr->flags & LISTBOX_DELETED) || !Tk_IsMapped(tkwin)) { |
| 1863 |
Tcl_Release((ClientData) listPtr); |
| 1864 |
return; |
| 1865 |
} |
| 1866 |
} |
| 1867 |
listPtr->flags &= ~(REDRAW_PENDING|UPDATE_V_SCROLLBAR|UPDATE_H_SCROLLBAR); |
| 1868 |
Tcl_Release((ClientData) listPtr); |
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
pixmap = Tk_GetPixmap(listPtr->display, Tk_WindowId(tkwin), |
| 1879 |
Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); |
| 1880 |
Tk_Fill3DRectangle(tkwin, pixmap, listPtr->normalBorder, 0, 0, |
| 1881 |
Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); |
| 1882 |
|
| 1883 |
|
| 1884 |
limit = listPtr->topIndex + listPtr->fullLines + listPtr->partialLine - 1; |
| 1885 |
if (limit >= listPtr->nElements) { |
| 1886 |
limit = listPtr->nElements-1; |
| 1887 |
} |
| 1888 |
left = right = 0; |
| 1889 |
if (listPtr->xOffset > 0) { |
| 1890 |
left = listPtr->selBorderWidth+1; |
| 1891 |
} |
| 1892 |
if ((listPtr->maxWidth - listPtr->xOffset) > (Tk_Width(listPtr->tkwin) |
| 1893 |
- 2*(listPtr->inset + listPtr->selBorderWidth))) { |
| 1894 |
right = listPtr->selBorderWidth+1; |
| 1895 |
} |
| 1896 |
prevSelected = 0; |
| 1897 |
|
| 1898 |
for (i = listPtr->topIndex; i <= limit; i++) { |
| 1899 |
x = listPtr->inset; |
| 1900 |
y = ((i - listPtr->topIndex) * listPtr->lineHeight) |
| 1901 |
+ listPtr->inset; |
| 1902 |
gc = listPtr->textGC; |
| 1903 |
freeGC = 0; |
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
entry = Tcl_FindHashEntry(listPtr->itemAttrTable, (char *)i); |
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
if (listPtr->state & STATE_NORMAL) { |
| 1916 |
if (Tcl_FindHashEntry(listPtr->selection, (char *)i) != NULL) { |
| 1917 |
|
| 1918 |
gc = listPtr->selTextGC; |
| 1919 |
width = Tk_Width(tkwin) - 2*listPtr->inset; |
| 1920 |
selectedBg = listPtr->selBorder; |
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
if (entry != NULL) { |
| 1925 |
attrs = (ItemAttr *)Tcl_GetHashValue(entry); |
| 1926 |
|
| 1927 |
gcValues.foreground = listPtr->selFgColorPtr->pixel; |
| 1928 |
gcValues.font = Tk_FontId(listPtr->tkfont); |
| 1929 |
gcValues.graphics_exposures = False; |
| 1930 |
mask = GCForeground | GCFont | GCGraphicsExposures; |
| 1931 |
|
| 1932 |
if (attrs->selBorder != NULL) { |
| 1933 |
selectedBg = attrs->selBorder; |
| 1934 |
} |
| 1935 |
|
| 1936 |
if (attrs->selFgColor != NULL) { |
| 1937 |
gcValues.foreground = attrs->selFgColor->pixel; |
| 1938 |
gc = Tk_GetGC(listPtr->tkwin, mask, &gcValues); |
| 1939 |
freeGC = 1; |
| 1940 |
} |
| 1941 |
} |
| 1942 |
|
| 1943 |
Tk_Fill3DRectangle(tkwin, pixmap, selectedBg, x, y, |
| 1944 |
width, listPtr->lineHeight, 0, TK_RELIEF_FLAT); |
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
if (left == 0) { |
| 1964 |
Tk_3DVerticalBevel(tkwin, pixmap, selectedBg, |
| 1965 |
x, y, listPtr->selBorderWidth, listPtr->lineHeight, |
| 1966 |
1, TK_RELIEF_RAISED); |
| 1967 |
} |
| 1968 |
|
| 1969 |
if (right == 0) { |
| 1970 |
Tk_3DVerticalBevel(tkwin, pixmap, selectedBg, |
| 1971 |
x + width - listPtr->selBorderWidth, y, |
| 1972 |
listPtr->selBorderWidth, listPtr->lineHeight, |
| 1973 |
0, TK_RELIEF_RAISED); |
| 1974 |
} |
| 1975 |
|
| 1976 |
if (!prevSelected) { |
| 1977 |
Tk_3DHorizontalBevel(tkwin, pixmap, selectedBg, |
| 1978 |
x-left, y, width+left+right, |
| 1979 |
listPtr->selBorderWidth, |
| 1980 |
1, 1, 1, TK_RELIEF_RAISED); |
| 1981 |
} |
| 1982 |
|
| 1983 |
if (i + 1 == listPtr->nElements || |
| 1984 |
Tcl_FindHashEntry(listPtr->selection, |
| 1985 |
(char *)(i + 1)) == NULL ) { |
| 1986 |
Tk_3DHorizontalBevel(tkwin, pixmap, selectedBg, x-left, |
| 1987 |
y + listPtr->lineHeight - listPtr->selBorderWidth, |
| 1988 |
width+left+right, listPtr->selBorderWidth, 0, 0, 0, |
| 1989 |
TK_RELIEF_RAISED); |
| 1990 |
} |
| 1991 |
prevSelected = 1; |
| 1992 |
} else { |
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
if (entry != NULL) { |
| 1998 |
attrs = (ItemAttr *)Tcl_GetHashValue(entry); |
| 1999 |
gcValues.foreground = listPtr->fgColorPtr->pixel; |
| 2000 |
gcValues.font = Tk_FontId(listPtr->tkfont); |
| 2001 |
gcValues.graphics_exposures = False; |
| 2002 |
mask = GCForeground | GCFont | GCGraphicsExposures; |
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
if (attrs->border != NULL) { |
| 2009 |
width = Tk_Width(tkwin) - 2*listPtr->inset; |
| 2010 |
Tk_Fill3DRectangle(tkwin, pixmap, attrs->border, x, y, |
| 2011 |
width, listPtr->lineHeight, 0, TK_RELIEF_FLAT); |
| 2012 |
} |
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
if ((listPtr->state & STATE_NORMAL) |
| 2020 |
&& attrs->fgColor != NULL) { |
| 2021 |
gcValues.foreground = attrs->fgColor->pixel; |
| 2022 |
gc = Tk_GetGC(listPtr->tkwin, mask, &gcValues); |
| 2023 |
freeGC = 1; |
| 2024 |
} |
| 2025 |
} |
| 2026 |
prevSelected = 0; |
| 2027 |
} |
| 2028 |
} |
| 2029 |
|
| 2030 |
|
| 2031 |
Tk_GetFontMetrics(listPtr->tkfont, &fm); |
| 2032 |
y += fm.ascent + listPtr->selBorderWidth; |
| 2033 |
x = listPtr->inset + listPtr->selBorderWidth - listPtr->xOffset; |
| 2034 |
Tcl_ListObjIndex(listPtr->interp, listPtr->listObj, i, &curElement); |
| 2035 |
stringRep = Tcl_GetStringFromObj(curElement, &stringLen); |
| 2036 |
Tk_DrawChars(listPtr->display, pixmap, gc, listPtr->tkfont, |
| 2037 |
stringRep, stringLen, x, y); |
| 2038 |
|
| 2039 |
|
| 2040 |
if ((i == listPtr->active) && (listPtr->flags & GOT_FOCUS)) { |
| 2041 |
if (listPtr->activeStyle == ACTIVE_STYLE_UNDERLINE) { |
| 2042 |
|
| 2043 |
Tk_UnderlineChars(listPtr->display, pixmap, gc, |
| 2044 |
listPtr->tkfont, stringRep, x, y, 0, stringLen); |
| 2045 |
} else if (listPtr->activeStyle == ACTIVE_STYLE_DOTBOX) { |
| 2046 |
#ifdef WIN32 |
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
TkWinDCState state; |
| 2051 |
HDC dc; |
| 2052 |
RECT rect; |
| 2053 |
|
| 2054 |
dc = TkWinGetDrawableDC(listPtr->display, pixmap, &state); |
| 2055 |
rect.left = listPtr->inset; |
| 2056 |
rect.top = ((i - listPtr->topIndex) * listPtr->lineHeight) |
| 2057 |
+ listPtr->inset; |
| 2058 |
rect.right = rect.left + width; |
| 2059 |
rect.bottom = rect.top + listPtr->lineHeight; |
| 2060 |
DrawFocusRect(dc, &rect); |
| 2061 |
TkWinReleaseDrawableDC(pixmap, dc, &state); |
| 2062 |
#else |
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
x = listPtr->inset; |
| 2067 |
y = ((i - listPtr->topIndex) * listPtr->lineHeight) |
| 2068 |
+ listPtr->inset; |
| 2069 |
width = Tk_Width(tkwin) - 2*listPtr->inset - 1; |
| 2070 |
|
| 2071 |
gcValues.line_style = LineOnOffDash; |
| 2072 |
gcValues.line_width = listPtr->selBorderWidth; |
| 2073 |
if (gcValues.line_width <= 0) { |
| 2074 |
gcValues.line_width = 1; |
| 2075 |
} |
| 2076 |
gcValues.dash_offset = 0; |
| 2077 |
gcValues.dashes = 1; |
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
mask = GCLineWidth | GCLineStyle | GCDashList | GCDashOffset; |
| 2087 |
XChangeGC(listPtr->display, gc, mask, &gcValues); |
| 2088 |
XDrawRectangle(listPtr->display, pixmap, gc, x, y, |
| 2089 |
(unsigned) width, (unsigned) listPtr->lineHeight - 1); |
| 2090 |
if (!freeGC) { |
| 2091 |
|
| 2092 |
gcValues.line_style = LineSolid; |
| 2093 |
XChangeGC(listPtr->display, gc, GCLineStyle, &gcValues); |
| 2094 |
} |
| 2095 |
#endif |
| 2096 |
} |
| 2097 |
} |
| 2098 |
|
| 2099 |
if (freeGC) { |
| 2100 |
Tk_FreeGC(listPtr->display, gc); |
| 2101 |
} |
| 2102 |
} |
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
Tk_Draw3DRectangle(tkwin, pixmap, listPtr->normalBorder, |
| 2110 |
listPtr->highlightWidth, listPtr->highlightWidth, |
| 2111 |
Tk_Width(tkwin) - 2*listPtr->highlightWidth, |
| 2112 |
Tk_Height(tkwin) - 2*listPtr->highlightWidth, |
| 2113 |
listPtr->borderWidth, listPtr->relief); |
| 2114 |
if (listPtr->highlightWidth > 0) { |
| 2115 |
GC fgGC, bgGC; |
| 2116 |
|
| 2117 |
bgGC = Tk_GCForColor(listPtr->highlightBgColorPtr, pixmap); |
| 2118 |
if (listPtr->flags & GOT_FOCUS) { |
| 2119 |
fgGC = Tk_GCForColor(listPtr->highlightColorPtr, pixmap); |
| 2120 |
TkpDrawHighlightBorder(tkwin, fgGC, bgGC, |
| 2121 |
listPtr->highlightWidth, pixmap); |
| 2122 |
} else { |
| 2123 |
TkpDrawHighlightBorder(tkwin, bgGC, bgGC, |
| 2124 |
listPtr->highlightWidth, pixmap); |
| 2125 |
} |
| 2126 |
} |
| 2127 |
XCopyArea(listPtr->display, pixmap, Tk_WindowId(tkwin), |
| 2128 |
listPtr->textGC, 0, 0, (unsigned) Tk_Width(tkwin), |
| 2129 |
(unsigned) Tk_Height(tkwin), 0, 0); |
| 2130 |
Tk_FreePixmap(listPtr->display, pixmap); |
| 2131 |
} |
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
static void |
| 2154 |
ListboxComputeGeometry(listPtr, fontChanged, maxIsStale, updateGrid) |
| 2155 |
Listbox *listPtr; |
| 2156 |
|
| 2157 |
int fontChanged; |
| 2158 |
|
| 2159 |
|
| 2160 |
int maxIsStale; |
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
int updateGrid; |
| 2165 |
|
| 2166 |
|
| 2167 |
{ |
| 2168 |
int width, height, pixelWidth, pixelHeight; |
| 2169 |
Tk_FontMetrics fm; |
| 2170 |
Tcl_Obj *element; |
| 2171 |
int textLength; |
| 2172 |
char *text; |
| 2173 |
int i, result; |
| 2174 |
|
| 2175 |
if (fontChanged || maxIsStale) { |
| 2176 |
listPtr->xScrollUnit = Tk_TextWidth(listPtr->tkfont, "0", 1); |
| 2177 |
if (listPtr->xScrollUnit == 0) { |
| 2178 |
listPtr->xScrollUnit = 1; |
| 2179 |
} |
| 2180 |
listPtr->maxWidth = 0; |
| 2181 |
for (i = 0; i < listPtr->nElements; i++) { |
| 2182 |
|
| 2183 |
result = Tcl_ListObjIndex(listPtr->interp, listPtr->listObj, i, |
| 2184 |
&element); |
| 2185 |
if (result != TCL_OK) { |
| 2186 |
continue; |
| 2187 |
} |
| 2188 |
text = Tcl_GetStringFromObj(element, &textLength); |
| 2189 |
Tk_GetFontMetrics(listPtr->tkfont, &fm); |
| 2190 |
pixelWidth = Tk_TextWidth(listPtr->tkfont, text, textLength); |
| 2191 |
if (pixelWidth > listPtr->maxWidth) { |
| 2192 |
listPtr->maxWidth = pixelWidth; |
| 2193 |
} |
| 2194 |
} |
| 2195 |
} |
| 2196 |
|
| 2197 |
Tk_GetFontMetrics(listPtr->tkfont, &fm); |
| 2198 |
listPtr->lineHeight = fm.linespace + 1 + 2*listPtr->selBorderWidth; |
| 2199 |
width = listPtr->width; |
| 2200 |
if (width <= 0) { |
| 2201 |
width = (listPtr->maxWidth + listPtr->xScrollUnit - 1) |
| 2202 |
/listPtr->xScrollUnit; |
| 2203 |
if (width < 1) { |
| 2204 |
width = 1; |
| 2205 |
} |
| 2206 |
} |
| 2207 |
pixelWidth = width*listPtr->xScrollUnit + 2*listPtr->inset |
| 2208 |
+ 2*listPtr->selBorderWidth; |
| 2209 |
height = listPtr->height; |
| 2210 |
if (listPtr->height <= 0) { |
| 2211 |
height = listPtr->nElements; |
| 2212 |
if (height < 1) { |
| 2213 |
height = 1; |
| 2214 |
} |
| 2215 |
} |
| 2216 |
pixelHeight = height*listPtr->lineHeight + 2*listPtr->inset; |
| 2217 |
Tk_GeometryRequest(listPtr->tkwin, pixelWidth, pixelHeight); |
| 2218 |
Tk_SetInternalBorder(listPtr->tkwin, listPtr->inset); |
| 2219 |
if (updateGrid) { |
| 2220 |
if (listPtr->setGrid) { |
| 2221 |
Tk_SetGrid(listPtr->tkwin, width, height, listPtr->xScrollUnit, |
| 2222 |
listPtr->lineHeight); |
| 2223 |
} else { |
| 2224 |
Tk_UnsetGrid(listPtr->tkwin); |
| 2225 |
} |
| 2226 |
} |
| 2227 |
} |
| 2228 |
|
| 2229 |
|
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
static int |
| 2248 |
ListboxInsertSubCmd(listPtr, index, objc, objv) |
| 2249 |
register Listbox *listPtr; |
| 2250 |
|
| 2251 |
int index; |
| 2252 |
|
| 2253 |
int objc; |
| 2254 |
Tcl_Obj *CONST objv[]; |
| 2255 |
{ |
| 2256 |
int i, oldMaxWidth; |
| 2257 |
Tcl_Obj *newListObj; |
| 2258 |
int pixelWidth; |
| 2259 |
int result; |
| 2260 |
char *stringRep; |
| 2261 |
int length; |
| 2262 |
#ifdef _LANG |
| 2263 |
int refFlag = 0; |
| 2264 |
#endif |
| 2265 |
|
| 2266 |
oldMaxWidth = listPtr->maxWidth; |
| 2267 |
for (i = 0; i < objc; i++) { |
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
stringRep = Tcl_GetStringFromObj(objv[i], &length); |
| 2273 |
pixelWidth = Tk_TextWidth(listPtr->tkfont, stringRep, length); |
| 2274 |
if (pixelWidth > listPtr->maxWidth) { |
| 2275 |
listPtr->maxWidth = pixelWidth; |
| 2276 |
} |
| 2277 |
} |
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
MigrateHashEntries(listPtr->selection, index, listPtr->nElements-1, objc); |
| 2282 |
MigrateHashEntries(listPtr->itemAttrTable, index, listPtr->nElements-1, |
| 2283 |
objc); |
| 2284 |
|
| 2285 |
|
| 2286 |
if (Tcl_IsShared(listPtr->listObj)) { |
| 2287 |
newListObj = Tcl_DuplicateObj(listPtr->listObj); |
| 2288 |
#ifdef _LANG |
| 2289 |
refFlag = 1; |
| 2290 |
#endif |
| 2291 |
} else { |
| 2292 |
newListObj = listPtr->listObj; |
| 2293 |
} |
| 2294 |
result = |
| 2295 |
Tcl_ListObjReplace(listPtr->interp, newListObj, index, 0, objc, objv); |
| 2296 |
if (result != TCL_OK) { |
| 2297 |
#ifdef _LANG |
| 2298 |
if (refFlag) { |
| 2299 |
Tcl_DecrRefCount(newListObj); |
| 2300 |
} |
| 2301 |
#endif |
| 2302 |
return result; |
| 2303 |
} |
| 2304 |
|
| 2305 |
#ifdef _LANG |
| 2306 |
if (!refFlag) { |
| 2307 |
#endif |
| 2308 |
Tcl_IncrRefCount(newListObj); |
| 2309 |
#ifdef _LANG |
| 2310 |
} |
| 2311 |
#endif |
| 2312 |
|
| 2313 |
Tcl_DecrRefCount(listPtr->listObj); |
| 2314 |
|
| 2315 |
|
| 2316 |
listPtr->listObj = newListObj; |
| 2317 |
|
| 2318 |
|
| 2319 |
if (listPtr->listVarName != NULL) { |
| 2320 |
if (Tcl_ObjSetVar2(listPtr->interp, listPtr->listVarName, |
| 2321 |
(char *)NULL, newListObj, TCL_GLOBAL_ONLY) == NULL) { |
| 2322 |
Tcl_DecrRefCount(newListObj); |
| 2323 |
return TCL_ERROR; |
| 2324 |
} |
| 2325 |
} |
| 2326 |
|
| 2327 |
|
| 2328 |
Tcl_ListObjLength(listPtr->interp, listPtr->listObj, &listPtr->nElements); |
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
if (index <= listPtr->selectAnchor) { |
| 2337 |
listPtr->selectAnchor += objc; |
| 2338 |
} |
| 2339 |
if (index < listPtr->topIndex) { |
| 2340 |
listPtr->topIndex += objc; |
| 2341 |
} |
| 2342 |
if (index <= listPtr->active) { |
| 2343 |
listPtr->active += objc; |
| 2344 |
if ((listPtr->active >= listPtr->nElements) && |
| 2345 |
(listPtr->nElements > 0)) { |
| 2346 |
listPtr->active = listPtr->nElements-1; |
| 2347 |
} |
| 2348 |
} |
| 2349 |
listPtr->flags |= UPDATE_V_SCROLLBAR; |
| 2350 |
if (listPtr->maxWidth != oldMaxWidth) { |
| 2351 |
listPtr->flags |= UPDATE_H_SCROLLBAR; |
| 2352 |
} |
| 2353 |
ListboxComputeGeometry(listPtr, 0, 0, 0); |
| 2354 |
EventuallyRedrawRange(listPtr, index, listPtr->nElements-1); |
| 2355 |
return TCL_OK; |
| 2356 |
} |
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
static int |
| 2376 |
ListboxDeleteSubCmd(listPtr, first, last) |
| 2377 |
register Listbox *listPtr; |
| 2378 |
int first; |
| 2379 |
int last; |
| 2380 |
{ |
| 2381 |
int count, i, widthChanged; |
| 2382 |
Tcl_Obj *newListObj; |
| 2383 |
Tcl_Obj *element; |
| 2384 |
int length; |
| 2385 |
char *stringRep; |
| 2386 |
int result; |
| 2387 |
int pixelWidth; |
| 2388 |
Tcl_HashEntry *entry; |
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
if (first < 0) { |
| 2396 |
first = 0; |
| 2397 |
} |
| 2398 |
if (last >= listPtr->nElements) { |
| 2399 |
last = listPtr->nElements-1; |
| 2400 |
} |
| 2401 |
count = last + 1 - first; |
| 2402 |
if (count <= 0) { |
| 2403 |
return TCL_OK; |
| 2404 |
} |
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
|
| 2409 |
|
| 2410 |
|
| 2411 |
|
| 2412 |
|
| 2413 |
widthChanged = 0; |
| 2414 |
for (i = first; i <= last; i++) { |
| 2415 |
|
| 2416 |
entry = Tcl_FindHashEntry(listPtr->selection, (char *)i); |
| 2417 |
if (entry != NULL) { |
| 2418 |
listPtr->numSelected--; |
| 2419 |
Tcl_DeleteHashEntry(entry); |
| 2420 |
} |
| 2421 |
|
| 2422 |
entry = Tcl_FindHashEntry(listPtr->itemAttrTable, (char *)i); |
| 2423 |
if (entry != NULL) { |
| 2424 |
ckfree((char *)Tcl_GetHashValue(entry)); |
| 2425 |
Tcl_DeleteHashEntry(entry); |
| 2426 |
} |
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
if (widthChanged == 0) { |
| 2433 |
Tcl_ListObjIndex(listPtr->interp, listPtr->listObj, i, &element); |
| 2434 |
stringRep = Tcl_GetStringFromObj(element, &length); |
| 2435 |
pixelWidth = Tk_TextWidth(listPtr->tkfont, stringRep, length); |
| 2436 |
if (pixelWidth == listPtr->maxWidth) { |
| 2437 |
widthChanged = 1; |
| 2438 |
} |
| 2439 |
} |
| 2440 |
} |
| 2441 |
|
| 2442 |
|
| 2443 |
MigrateHashEntries(listPtr->selection, last+1, |
| 2444 |
listPtr->nElements-1, count*-1); |
| 2445 |
MigrateHashEntries(listPtr->itemAttrTable, last+1, |
| 2446 |
listPtr->nElements-1, count*-1); |
| 2447 |
|
| 2448 |
|
| 2449 |
if (Tcl_IsShared(listPtr->listObj)) { |
| 2450 |
newListObj = Tcl_DuplicateObj(listPtr->listObj); |
| 2451 |
} else { |
| 2452 |
newListObj = listPtr->listObj; |
| 2453 |
} |
| 2454 |
result = Tcl_ListObjReplace(listPtr->interp, |
| 2455 |
newListObj, first, count, 0, NULL); |
| 2456 |
if (result != TCL_OK) { |
| 2457 |
return result; |
| 2458 |
} |
| 2459 |
|
| 2460 |
Tcl_IncrRefCount(newListObj); |
| 2461 |
|
| 2462 |
Tcl_DecrRefCount(listPtr->listObj); |
| 2463 |
|
| 2464 |
|
| 2465 |
listPtr->listObj = newListObj; |
| 2466 |
|
| 2467 |
|
| 2468 |
Tcl_ListObjLength(listPtr->interp, listPtr->listObj, &listPtr->nElements); |
| 2469 |
|
| 2470 |
|
| 2471 |
if (listPtr->listVarName != NULL) { |
| 2472 |
if (Tcl_ObjSetVar2(listPtr->interp, listPtr->listVarName, |
| 2473 |
(char *)NULL, newListObj, TCL_GLOBAL_ONLY) == NULL) { |
| 2474 |
Tcl_DecrRefCount(newListObj); |
| 2475 |
return TCL_ERROR; |
| 2476 |
} |
| 2477 |
} |
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
if (first <= listPtr->selectAnchor) { |
| 2486 |
listPtr->selectAnchor -= count; |
| 2487 |
if (listPtr->selectAnchor < first) { |
| 2488 |
listPtr->selectAnchor = first; |
| 2489 |
} |
| 2490 |
} |
| 2491 |
if (first <= listPtr->topIndex) { |
| 2492 |
listPtr->topIndex -= count; |
| 2493 |
if (listPtr->topIndex < first) { |
| 2494 |
listPtr->topIndex = first; |
| 2495 |
} |
| 2496 |
} |
| 2497 |
if (listPtr->topIndex > (listPtr->nElements - listPtr->fullLines)) { |
| 2498 |
listPtr->topIndex = listPtr->nElements - listPtr->fullLines; |
| 2499 |
if (listPtr->topIndex < 0) { |
| 2500 |
listPtr->topIndex = 0; |
| 2501 |
} |
| 2502 |
} |
| 2503 |
if (listPtr->active > last) { |
| 2504 |
listPtr->active -= count; |
| 2505 |
} else if (listPtr->active >= first) { |
| 2506 |
listPtr->active = first; |
| 2507 |
if ((listPtr->active >= listPtr->nElements) && |
| 2508 |
(listPtr->nElements > 0)) { |
| 2509 |
listPtr->active = listPtr->nElements-1; |
| 2510 |
} |
| 2511 |
} |
| 2512 |
listPtr->flags |= UPDATE_V_SCROLLBAR; |
| 2513 |
ListboxComputeGeometry(listPtr, 0, widthChanged, 0); |
| 2514 |
if (widthChanged) { |
| 2515 |
listPtr->flags |= UPDATE_H_SCROLLBAR; |
| 2516 |
} |
| 2517 |
EventuallyRedrawRange(listPtr, first, listPtr->nElements-1); |
| 2518 |
return TCL_OK; |
| 2519 |
} |
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
static void |
| 2540 |
ListboxEventProc(clientData, eventPtr) |
| 2541 |
ClientData clientData; |
| 2542 |
XEvent *eventPtr; |
| 2543 |
{ |
| 2544 |
Listbox *listPtr = (Listbox *) clientData; |
| 2545 |
|
| 2546 |
if (eventPtr->type == Expose) { |
| 2547 |
EventuallyRedrawRange(listPtr, |
| 2548 |
NearestListboxElement(listPtr, eventPtr->xexpose.y), |
| 2549 |
NearestListboxElement(listPtr, eventPtr->xexpose.y |
| 2550 |
+ eventPtr->xexpose.height)); |
| 2551 |
} else if (eventPtr->type == DestroyNotify) { |
| 2552 |
if (!(listPtr->flags & LISTBOX_DELETED)) { |
| 2553 |
listPtr->flags |= LISTBOX_DELETED; |
| 2554 |
Tcl_DeleteCommandFromToken(listPtr->interp, listPtr->widgetCmd); |
| 2555 |
if (listPtr->setGrid) { |
| 2556 |
Tk_UnsetGrid(listPtr->tkwin); |
| 2557 |
} |
| 2558 |
if (listPtr->flags & REDRAW_PENDING) { |
| 2559 |
Tcl_CancelIdleCall(DisplayListbox, clientData); |
| 2560 |
} |
| 2561 |
Tcl_EventuallyFree(clientData, DestroyListbox); |
| 2562 |
} |
| 2563 |
} else if (eventPtr->type == ConfigureNotify) { |
| 2564 |
int vertSpace; |
| 2565 |
|
| 2566 |
vertSpace = Tk_Height(listPtr->tkwin) - 2*listPtr->inset; |
| 2567 |
listPtr->fullLines = vertSpace / listPtr->lineHeight; |
| 2568 |
if ((listPtr->fullLines*listPtr->lineHeight) < vertSpace) { |
| 2569 |
listPtr->partialLine = 1; |
| 2570 |
} else { |
| 2571 |
listPtr->partialLine = 0; |
| 2572 |
} |
| 2573 |
listPtr->flags |= UPDATE_V_SCROLLBAR|UPDATE_H_SCROLLBAR; |
| 2574 |
ChangeListboxView(listPtr, listPtr->topIndex); |
| 2575 |
ChangeListboxOffset(listPtr, listPtr->xOffset); |
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
EventuallyRedrawRange(listPtr, 0, listPtr->nElements-1); |
| 2585 |
} else if (eventPtr->type == FocusIn) { |
| 2586 |
if (eventPtr->xfocus.detail != NotifyInferior) { |
| 2587 |
listPtr->flags |= GOT_FOCUS; |
| 2588 |
EventuallyRedrawRange(listPtr, 0, listPtr->nElements-1); |
| 2589 |
} |
| 2590 |
} else if (eventPtr->type == FocusOut) { |
| 2591 |
if (eventPtr->xfocus.detail != NotifyInferior) { |
| 2592 |
listPtr->flags &= ~GOT_FOCUS; |
| 2593 |
EventuallyRedrawRange(listPtr, 0, listPtr->nElements-1); |
| 2594 |
} |
| 2595 |
} |
| 2596 |
} |
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
static void |
| 2617 |
ListboxCmdDeletedProc(clientData) |
| 2618 |
ClientData clientData; |
| 2619 |
{ |
| 2620 |
Listbox *listPtr = (Listbox *) clientData; |
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
|
| 2628 |
|
| 2629 |
if (!(listPtr->flags & LISTBOX_DELETED)) { |
| 2630 |
Tk_DestroyWindow(listPtr->tkwin); |
| 2631 |
} |
| 2632 |
} |
| 2633 |
|
| 2634 |
|
| 2635 |
|
| 2636 |
|
| 2637 |
|
| 2638 |
|
| 2639 |
|
| 2640 |
|
| 2641 |
|
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
static int |
| 2654 |
GetListboxIndex(interp, listPtr, indexObj, endIsSize, indexPtr) |
| 2655 |
Tcl_Interp *interp; |
| 2656 |
Listbox *listPtr; |
| 2657 |
|
| 2658 |
Tcl_Obj *indexObj; |
| 2659 |
int endIsSize; |
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
int *indexPtr; |
| 2664 |
{ |
| 2665 |
int result; |
| 2666 |
int index; |
| 2667 |
char *stringRep; |
| 2668 |
|
| 2669 |
|
| 2670 |
result = Tcl_GetIndexFromObj(NULL, indexObj, indexNames, "", 0, &index); |
| 2671 |
if (result == TCL_OK) { |
| 2672 |
switch (index) { |
| 2673 |
case INDEX_ACTIVE: { |
| 2674 |
|
| 2675 |
*indexPtr = listPtr->active; |
| 2676 |
break; |
| 2677 |
} |
| 2678 |
|
| 2679 |
case INDEX_ANCHOR: { |
| 2680 |
|
| 2681 |
*indexPtr = listPtr->selectAnchor; |
| 2682 |
break; |
| 2683 |
} |
| 2684 |
|
| 2685 |
case INDEX_END: { |
| 2686 |
|
| 2687 |
if (endIsSize) { |
| 2688 |
*indexPtr = listPtr->nElements; |
| 2689 |
} else { |
| 2690 |
*indexPtr = listPtr->nElements - 1; |
| 2691 |
} |
| 2692 |
break; |
| 2693 |
} |
| 2694 |
} |
| 2695 |
return TCL_OK; |
| 2696 |
} |
| 2697 |
|
| 2698 |
|
| 2699 |
stringRep = Tcl_GetString(indexObj); |
| 2700 |
if (stringRep[0] == '@') { |
| 2701 |
|
| 2702 |
int y; |
| 2703 |
char *start, *end; |
| 2704 |
start = stringRep + 1; |
| 2705 |
strtol(start, &end, 0); |
| 2706 |
if ((start == end) || (*end != ',')) { |
| 2707 |
Tcl_AppendResult(interp, "bad listbox index \"", stringRep, |
| 2708 |
"\": must be active, anchor, end, @x,y, or a number", |
| 2709 |
(char *)NULL); |
| 2710 |
return TCL_ERROR; |
| 2711 |
} |
| 2712 |
start = end+1; |
| 2713 |
y = strtol(start, &end, 0); |
| 2714 |
if ((start == end) || (*end != '\0')) { |
| 2715 |
Tcl_AppendResult(interp, "bad listbox index \"", stringRep, |
| 2716 |
"\": must be active, anchor, end, @x,y, or a number", |
| 2717 |
(char *)NULL); |
| 2718 |
return TCL_ERROR; |
| 2719 |
} |
| 2720 |
*indexPtr = NearestListboxElement(listPtr, y); |
| 2721 |
return TCL_OK; |
| 2722 |
} |
| 2723 |
|
| 2724 |
|
| 2725 |
if (Tcl_GetIntFromObj(interp, indexObj, indexPtr) == TCL_OK) { |
| 2726 |
return TCL_OK; |
| 2727 |
} |
| 2728 |
|
| 2729 |
|
| 2730 |
Tcl_ResetResult(interp); |
| 2731 |
Tcl_AppendResult(interp, "bad listbox index \"", |
| 2732 |
Tcl_GetString(indexObj), "\": must be active, anchor, ", |
| 2733 |
"end, @x,y, or a number", (char *) NULL); |
| 2734 |
return TCL_ERROR; |
| 2735 |
} |
| 2736 |
|
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
|
| 2748 |
|
| 2749 |
|
| 2750 |
|
| 2751 |
|
| 2752 |
|
| 2753 |
|
| 2754 |
|
| 2755 |
|
| 2756 |
static void |
| 2757 |
ChangeListboxView(listPtr, index) |
| 2758 |
register Listbox *listPtr; |
| 2759 |
int index; |
| 2760 |
|
| 2761 |
|
| 2762 |
{ |
| 2763 |
if (index >= (listPtr->nElements - listPtr->fullLines)) { |
| 2764 |
index = listPtr->nElements - listPtr->fullLines; |
| 2765 |
} |
| 2766 |
if (index < 0) { |
| 2767 |
index = 0; |
| 2768 |
} |
| 2769 |
if (listPtr->topIndex != index) { |
| 2770 |
listPtr->topIndex = index; |
| 2771 |
EventuallyRedrawRange(listPtr, 0, listPtr->nElements-1); |
| 2772 |
listPtr->flags |= UPDATE_V_SCROLLBAR; |
| 2773 |
} |
| 2774 |
} |
| 2775 |
|
| 2776 |
|
| 2777 |
|
| 2778 |
|
| 2779 |
|
| 2780 |
|
| 2781 |
|
| 2782 |
|
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
static void |
| 2794 |
ChangeListboxOffset(listPtr, offset) |
| 2795 |
register Listbox *listPtr; |
| 2796 |
int offset; |
| 2797 |
|
| 2798 |
{ |
| 2799 |
int maxOffset; |
| 2800 |
|
| 2801 |
|
| 2802 |
|
| 2803 |
|
| 2804 |
|
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
offset += listPtr->xScrollUnit / 2; |
| 2810 |
maxOffset = listPtr->maxWidth - (Tk_Width(listPtr->tkwin) - |
| 2811 |
2*listPtr->inset - 2*listPtr->selBorderWidth) |
| 2812 |
+ listPtr->xScrollUnit - 1; |
| 2813 |
if (offset > maxOffset) { |
| 2814 |
offset = maxOffset; |
| 2815 |
} |
| 2816 |
if (offset < 0) { |
| 2817 |
offset = 0; |
| 2818 |
} |
| 2819 |
offset -= offset % listPtr->xScrollUnit; |
| 2820 |
if (offset != listPtr->xOffset) { |
| 2821 |
listPtr->xOffset = offset; |
| 2822 |
listPtr->flags |= UPDATE_H_SCROLLBAR; |
| 2823 |
EventuallyRedrawRange(listPtr, 0, listPtr->nElements-1); |
| 2824 |
} |
| 2825 |
} |
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
|
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
static void |
| 2845 |
ListboxScanTo(listPtr, x, y) |
| 2846 |
register Listbox *listPtr; |
| 2847 |
int x; |
| 2848 |
|
| 2849 |
int y; |
| 2850 |
|
| 2851 |
{ |
| 2852 |
int newTopIndex, newOffset, maxIndex, maxOffset; |
| 2853 |
|
| 2854 |
maxIndex = listPtr->nElements - listPtr->fullLines; |
| 2855 |
maxOffset = listPtr->maxWidth + (listPtr->xScrollUnit - 1) |
| 2856 |
- (Tk_Width(listPtr->tkwin) - 2*listPtr->inset |
| 2857 |
- 2*listPtr->selBorderWidth - listPtr->xScrollUnit); |
| 2858 |
|
| 2859 |
|
| 2860 |
|
| 2861 |
|
| 2862 |
|
| 2863 |
|
| 2864 |
|
| 2865 |
|
| 2866 |
|
| 2867 |
|
| 2868 |
|
| 2869 |
|
| 2870 |
newTopIndex = listPtr->scanMarkYIndex |
| 2871 |
- (10*(y - listPtr->scanMarkY))/listPtr->lineHeight; |
| 2872 |
if (newTopIndex > maxIndex) { |
| 2873 |
newTopIndex = listPtr->scanMarkYIndex = maxIndex; |
| 2874 |
listPtr->scanMarkY = y; |
| 2875 |
} else if (newTopIndex < 0) { |
| 2876 |
newTopIndex = listPtr->scanMarkYIndex = 0; |
| 2877 |
listPtr->scanMarkY = y; |
| 2878 |
} |
| 2879 |
ChangeListboxView(listPtr, newTopIndex); |
| 2880 |
|
| 2881 |
|
| 2882 |
|
| 2883 |
|
| 2884 |
|
| 2885 |
|
| 2886 |
|
| 2887 |
newOffset = listPtr->scanMarkXOffset - (10*(x - listPtr->scanMarkX)); |
| 2888 |
if (newOffset > maxOffset) { |
| 2889 |
newOffset = listPtr->scanMarkXOffset = maxOffset; |
| 2890 |
listPtr->scanMarkX = x; |
| 2891 |
} else if (newOffset < 0) { |
| 2892 |
newOffset = listPtr->scanMarkXOffset = 0; |
| 2893 |
listPtr->scanMarkX = x; |
| 2894 |
} |
| 2895 |
ChangeListboxOffset(listPtr, newOffset); |
| 2896 |
} |
| 2897 |
|
| 2898 |
|
| 2899 |
|
| 2900 |
|
| 2901 |
|
| 2902 |
|
| 2903 |
|
| 2904 |
|
| 2905 |
|
| 2906 |
|
| 2907 |
|
| 2908 |
|
| 2909 |
|
| 2910 |
|
| 2911 |
|
| 2912 |
|
| 2913 |
|
| 2914 |
|
| 2915 |
|
| 2916 |
|
| 2917 |
static int |
| 2918 |
NearestListboxElement(listPtr, y) |
| 2919 |
register Listbox *listPtr; |
| 2920 |
int y; |
| 2921 |
{ |
| 2922 |
int index; |
| 2923 |
|
| 2924 |
index = (y - listPtr->inset)/listPtr->lineHeight; |
| 2925 |
if (index >= (listPtr->fullLines + listPtr->partialLine)) { |
| 2926 |
index = listPtr->fullLines + listPtr->partialLine - 1; |
| 2927 |
} |
| 2928 |
if (index < 0) { |
| 2929 |
index = 0; |
| 2930 |
} |
| 2931 |
index += listPtr->topIndex; |
| 2932 |
if (index >= listPtr->nElements) { |
| 2933 |
index = listPtr->nElements-1; |
| 2934 |
} |
| 2935 |
return index; |
| 2936 |
} |
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
|
| 2941 |
|
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
|
| 2947 |
|
| 2948 |
|
| 2949 |
|
| 2950 |
|
| 2951 |
|
| 2952 |
|
| 2953 |
|
| 2954 |
|
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
static int |
| 2959 |
ListboxSelect(listPtr, first, last, select) |
| 2960 |
register Listbox *listPtr; |
| 2961 |
int first; |
| 2962 |
|
| 2963 |
int last; |
| 2964 |
|
| 2965 |
int select; |
| 2966 |
|
| 2967 |
{ |
| 2968 |
int i, firstRedisplay, increment, oldCount; |
| 2969 |
Tcl_HashEntry *entry; |
| 2970 |
int new; |
| 2971 |
|
| 2972 |
if (last < first) { |
| 2973 |
i = first; |
| 2974 |
first = last; |
| 2975 |
last = i; |
| 2976 |
} |
| 2977 |
if ((last < 0) || (first >= listPtr->nElements)) { |
| 2978 |
return TCL_OK; |
| 2979 |
} |
| 2980 |
if (first < 0) { |
| 2981 |
first = 0; |
| 2982 |
} |
| 2983 |
if (last >= listPtr->nElements) { |
| 2984 |
last = listPtr->nElements - 1; |
| 2985 |
} |
| 2986 |
oldCount = listPtr->numSelected; |
| 2987 |
firstRedisplay = -1; |
| 2988 |
increment = select ? 1 : -1; |
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
|
| 2993 |
|
| 2994 |
|
| 2995 |
for (i = first; i <= last; i++) { |
| 2996 |
entry = Tcl_FindHashEntry(listPtr->selection, (char *)i); |
| 2997 |
if (entry != NULL) { |
| 2998 |
if (!select) { |
| 2999 |
Tcl_DeleteHashEntry(entry); |
| 3000 |
listPtr->numSelected--; |
| 3001 |
if (firstRedisplay < 0) { |
| 3002 |
firstRedisplay = i; |
| 3003 |
} |
| 3004 |
} |
| 3005 |
} else { |
| 3006 |
if (select) { |
| 3007 |
entry = Tcl_CreateHashEntry(listPtr->selection, |
| 3008 |
(char *)i, &new); |
| 3009 |
Tcl_SetHashValue(entry, (ClientData) NULL); |
| 3010 |
listPtr->numSelected++; |
| 3011 |
if (firstRedisplay < 0) { |
| 3012 |
firstRedisplay = i; |
| 3013 |
} |
| 3014 |
} |
| 3015 |
} |
| 3016 |
} |
| 3017 |
|
| 3018 |
if (firstRedisplay >= 0) { |
| 3019 |
EventuallyRedrawRange(listPtr, first, last); |
| 3020 |
} |
| 3021 |
if ((oldCount == 0) && (listPtr->numSelected > 0) |
| 3022 |
&& (listPtr->exportSelection)) { |
| 3023 |
Tk_OwnSelection(listPtr->tkwin, XA_PRIMARY, ListboxLostSelection, |
| 3024 |
(ClientData) listPtr); |
| 3025 |
} |
| 3026 |
return TCL_OK; |
| 3027 |
} |
| 3028 |
|
| 3029 |
|
| 3030 |
|
| 3031 |
|
| 3032 |
|
| 3033 |
|
| 3034 |
|
| 3035 |
|
| 3036 |
|
| 3037 |
|
| 3038 |
|
| 3039 |
|
| 3040 |
|
| 3041 |
|
| 3042 |
|
| 3043 |
|
| 3044 |
|
| 3045 |
|
| 3046 |
|
| 3047 |
|
| 3048 |
|
| 3049 |
|
| 3050 |
|
| 3051 |
|
| 3052 |
static int |
| 3053 |
ListboxFetchSelection(clientData, offset, buffer, maxBytes) |
| 3054 |
ClientData clientData; |
| 3055 |
int offset; |
| 3056 |
|
| 3057 |
char *buffer; |
| 3058 |
|
| 3059 |
int maxBytes; |
| 3060 |
|
| 3061 |
|
| 3062 |
{ |
| 3063 |
register Listbox *listPtr = (Listbox *) clientData; |
| 3064 |
Tcl_DString selection; |
| 3065 |
int length, count, needNewline; |
| 3066 |
Tcl_Obj *curElement; |
| 3067 |
char *stringRep; |
| 3068 |
int stringLen; |
| 3069 |
Tcl_HashEntry *entry; |
| 3070 |
int i; |
| 3071 |
|
| 3072 |
if (!listPtr->exportSelection) { |
| 3073 |
return -1; |
| 3074 |
} |
| 3075 |
|
| 3076 |
|
| 3077 |
|
| 3078 |
|
| 3079 |
|
| 3080 |
needNewline = 0; |
| 3081 |
Tcl_DStringInit(&selection); |
| 3082 |
for (i = 0; i < listPtr->nElements; i++) { |
| 3083 |
entry = Tcl_FindHashEntry(listPtr->selection, (char *)i); |
| 3084 |
if (entry != NULL) { |
| 3085 |
if (needNewline) { |
| 3086 |
Tcl_DStringAppend(&selection, "\n", 1); |
| 3087 |
} |
| 3088 |
Tcl_ListObjIndex(listPtr->interp, listPtr->listObj, i, |
| 3089 |
&curElement); |
| 3090 |
stringRep = Tcl_GetStringFromObj(curElement, &stringLen); |
| 3091 |
Tcl_DStringAppend(&selection, stringRep, stringLen); |
| 3092 |
needNewline = 1; |
| 3093 |
} |
| 3094 |
} |
| 3095 |
|
| 3096 |
length = Tcl_DStringLength(&selection); |
| 3097 |
if (length == 0) { |
| 3098 |
return -1; |
| 3099 |
} |
| 3100 |
|
| 3101 |
|
| 3102 |
|
| 3103 |
|
| 3104 |
|
| 3105 |
count = length - offset; |
| 3106 |
if (count <= 0) { |
| 3107 |
count = 0; |
| 3108 |
} else { |
| 3109 |
if (count > maxBytes) { |
| 3110 |
count = maxBytes; |
| 3111 |
} |
| 3112 |
memcpy((VOID *) buffer, |
| 3113 |
(VOID *) (Tcl_DStringValue(&selection) + offset), |
| 3114 |
(size_t) count); |
| 3115 |
} |
| 3116 |
buffer[count] = '\0'; |
| 3117 |
Tcl_DStringFree(&selection); |
| 3118 |
return count; |
| 3119 |
} |
| 3120 |
|
| 3121 |
|
| 3122 |
|
| 3123 |
|
| 3124 |
|
| 3125 |
|
| 3126 |
|
| 3127 |
|
| 3128 |
|
| 3129 |
|
| 3130 |
|
| 3131 |
|
| 3132 |
|
| 3133 |
|
| 3134 |
|
| 3135 |
|
| 3136 |
|
| 3137 |
|
| 3138 |
|
| 3139 |
static void |
| 3140 |
ListboxLostSelection(clientData) |
| 3141 |
ClientData clientData; |
| 3142 |
{ |
| 3143 |
register Listbox *listPtr = (Listbox *) clientData; |
| 3144 |
|
| 3145 |
if ((listPtr->exportSelection) && (listPtr->nElements > 0)) { |
| 3146 |
ListboxSelect(listPtr, 0, listPtr->nElements-1, 0); |
| 3147 |
} |
| 3148 |
} |
| 3149 |
|
| 3150 |
|
| 3151 |
|
| 3152 |
|
| 3153 |
|
| 3154 |
|
| 3155 |
|
| 3156 |
|
| 3157 |
|
| 3158 |
|
| 3159 |
|
| 3160 |
|
| 3161 |
|
| 3162 |
|
| 3163 |
|
| 3164 |
|
| 3165 |
|
| 3166 |
|
| 3167 |
static void |
| 3168 |
EventuallyRedrawRange(listPtr, first, last) |
| 3169 |
register Listbox *listPtr; |
| 3170 |
int first; |
| 3171 |
|
| 3172 |
int last; |
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
{ |
| 3177 |
|
| 3178 |
|
| 3179 |
if ((listPtr->flags & REDRAW_PENDING) |
| 3180 |
|| (listPtr->flags & LISTBOX_DELETED) |
| 3181 |
|| !Tk_IsMapped(listPtr->tkwin)) { |
| 3182 |
return; |
| 3183 |
} |
| 3184 |
listPtr->flags |= REDRAW_PENDING; |
| 3185 |
Tcl_DoWhenIdle(DisplayListbox, (ClientData) listPtr); |
| 3186 |
} |
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
|
| 3192 |
|
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
|
| 3197 |
|
| 3198 |
|
| 3199 |
|
| 3200 |
|
| 3201 |
|
| 3202 |
|
| 3203 |
|
| 3204 |
|
| 3205 |
|
| 3206 |
|
| 3207 |
|
| 3208 |
static void |
| 3209 |
ListboxUpdateVScrollbar(listPtr) |
| 3210 |
register Listbox *listPtr; |
| 3211 |
{ |
| 3212 |
char string[TCL_DOUBLE_SPACE * 2]; |
| 3213 |
double first, last; |
| 3214 |
int result; |
| 3215 |
Tcl_Interp *interp; |
| 3216 |
|
| 3217 |
if (listPtr->yScrollCmd == NULL) { |
| 3218 |
return; |
| 3219 |
} |
| 3220 |
if (listPtr->nElements == 0) { |
| 3221 |
first = 0.0; |
| 3222 |
last = 1.0; |
| 3223 |
} else { |
| 3224 |
first = listPtr->topIndex/((double) listPtr->nElements); |
| 3225 |
last = (listPtr->topIndex+listPtr->fullLines) |
| 3226 |
/((double) listPtr->nElements); |
| 3227 |
if (last > 1.0) { |
| 3228 |
last = 1.0; |
| 3229 |
} |
| 3230 |
} |
| 3231 |
|
| 3232 |
|
| 3233 |
|
| 3234 |
|
| 3235 |
|
| 3236 |
interp = listPtr->interp; |
| 3237 |
Tcl_Preserve((ClientData) interp); |
| 3238 |
result = LangDoCallback(interp, listPtr->yScrollCmd, 0, 2, " %g %g", first, last); |
| 3239 |
if (result != TCL_OK) { |
| 3240 |
Tcl_AddErrorInfo(interp, |
| 3241 |
"\n (vertical scrolling command executed by listbox)"); |
| 3242 |
Tcl_BackgroundError(interp); |
| 3243 |
} |
| 3244 |
Tcl_Release((ClientData) interp); |
| 3245 |
} |
| 3246 |
|
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
|
| 3254 |
|
| 3255 |
|
| 3256 |
|
| 3257 |
|
| 3258 |
|
| 3259 |
|
| 3260 |
|
| 3261 |
|
| 3262 |
|
| 3263 |
|
| 3264 |
|
| 3265 |
|
| 3266 |
|
| 3267 |
static void |
| 3268 |
ListboxUpdateHScrollbar(listPtr) |
| 3269 |
register Listbox *listPtr; |
| 3270 |
{ |
| 3271 |
char string[TCL_DOUBLE_SPACE * 2]; |
| 3272 |
int result, windowWidth; |
| 3273 |
double first, last; |
| 3274 |
Tcl_Interp *interp; |
| 3275 |
|
| 3276 |
if (listPtr->xScrollCmd == NULL) { |
| 3277 |
return; |
| 3278 |
} |
| 3279 |
windowWidth = Tk_Width(listPtr->tkwin) - 2*(listPtr->inset |
| 3280 |
+ listPtr->selBorderWidth); |
| 3281 |
if (listPtr->maxWidth == 0) { |
| 3282 |
first = 0; |
| 3283 |
last = 1.0; |
| 3284 |
} else { |
| 3285 |
first = listPtr->xOffset/((double) listPtr->maxWidth); |
| 3286 |
last = (listPtr->xOffset + windowWidth) |
| 3287 |
/((double) listPtr->maxWidth); |
| 3288 |
if (last > 1.0) { |
| 3289 |
last = 1.0; |
| 3290 |
} |
| 3291 |
} |
| 3292 |
|
| 3293 |
|
| 3294 |
|
| 3295 |
|
| 3296 |
|
| 3297 |
interp = listPtr->interp; |
| 3298 |
Tcl_Preserve((ClientData) interp); |
| 3299 |
result = LangDoCallback(interp, listPtr->xScrollCmd, 0, 2, " %g %g",first, last); |
| 3300 |
if (result != TCL_OK) { |
| 3301 |
Tcl_AddErrorInfo(interp, |
| 3302 |
"\n (horizontal scrolling command executed by listbox)"); |
| 3303 |
Tcl_BackgroundError(interp); |
| 3304 |
} |
| 3305 |
Tcl_Release((ClientData) interp); |
| 3306 |
} |
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
|
| 3315 |
|
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
|
| 3320 |
|
| 3321 |
|
| 3322 |
|
| 3323 |
|
| 3324 |
static char * |
| 3325 |
ListboxListVarProc(clientData, interp, name1, name2, flags) |
| 3326 |
ClientData clientData; |
| 3327 |
Tcl_Interp *interp; |
| 3328 |
Tcl_Obj *name1; |
| 3329 |
CONST char *name2; |
| 3330 |
int flags; |
| 3331 |
{ |
| 3332 |
Listbox *listPtr = (Listbox *)clientData; |
| 3333 |
Tcl_Obj *oldListObj, *varListObj; |
| 3334 |
int oldLength; |
| 3335 |
int i; |
| 3336 |
Tcl_HashEntry *entry; |
| 3337 |
|
| 3338 |
|
| 3339 |
if (flags & TCL_TRACE_UNSETS) { |
| 3340 |
if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) { |
| 3341 |
Tcl_ObjSetVar2(interp, listPtr->listVarName, |
| 3342 |
(char *)NULL, listPtr->listObj, TCL_GLOBAL_ONLY); |
| 3343 |
Lang_TraceVar(interp, listPtr->listVarName, |
| 3344 |
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, |
| 3345 |
ListboxListVarProc, clientData); |
| 3346 |
return (char *)NULL; |
| 3347 |
} |
| 3348 |
} else { |
| 3349 |
oldListObj = listPtr->listObj; |
| 3350 |
varListObj = Tcl_ObjGetVar2(listPtr->interp, listPtr->listVarName, |
| 3351 |
(char *)NULL, TCL_GLOBAL_ONLY); |
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
if (Tcl_ListObjLength(listPtr->interp, varListObj, &i) != TCL_OK) { |
| 3358 |
Tcl_ObjSetVar2(interp, listPtr->listVarName, (char *)NULL, |
| 3359 |
oldListObj, TCL_GLOBAL_ONLY); |
| 3360 |
return("invalid listvar value"); |
| 3361 |
} |
| 3362 |
|
| 3363 |
listPtr->listObj = varListObj; |
| 3364 |
|
| 3365 |
Tcl_IncrRefCount(listPtr->listObj); |
| 3366 |
|
| 3367 |
Tcl_DecrRefCount(oldListObj); |
| 3368 |
} |
| 3369 |
|
| 3370 |
|
| 3371 |
|
| 3372 |
|
| 3373 |
|
| 3374 |
oldLength = listPtr->nElements; |
| 3375 |
Tcl_ListObjLength(listPtr->interp, listPtr->listObj, &listPtr->nElements); |
| 3376 |
if (listPtr->nElements < oldLength) { |
| 3377 |
for (i = listPtr->nElements; i < oldLength; i++) { |
| 3378 |
|
| 3379 |
entry = Tcl_FindHashEntry(listPtr->selection, (char *)i); |
| 3380 |
if (entry != NULL) { |
| 3381 |
listPtr->numSelected--; |
| 3382 |
Tcl_DeleteHashEntry(entry); |
| 3383 |
} |
| 3384 |
|
| 3385 |
|
| 3386 |
entry = Tcl_FindHashEntry(listPtr->itemAttrTable, (char *)i); |
| 3387 |
if (entry != NULL) { |
| 3388 |
ckfree((char *)Tcl_GetHashValue(entry)); |
| 3389 |
Tcl_DeleteHashEntry(entry); |
| 3390 |
} |
| 3391 |
} |
| 3392 |
} |
| 3393 |
|
| 3394 |
if (oldLength != listPtr->nElements) { |
| 3395 |
listPtr->flags |= UPDATE_V_SCROLLBAR; |
| 3396 |
if (listPtr->topIndex > (listPtr->nElements - listPtr->fullLines)) { |
| 3397 |
listPtr->topIndex = listPtr->nElements - listPtr->fullLines; |
| 3398 |
if (listPtr->topIndex < 0) { |
| 3399 |
listPtr->topIndex = 0; |
| 3400 |
} |
| 3401 |
} |
| 3402 |
} |
| 3403 |
|
| 3404 |
|
| 3405 |
|
| 3406 |
|
| 3407 |
|
| 3408 |
|
| 3409 |
|
| 3410 |
|
| 3411 |
listPtr->flags |= MAXWIDTH_IS_STALE; |
| 3412 |
|
| 3413 |
EventuallyRedrawRange(listPtr, 0, listPtr->nElements-1); |
| 3414 |
return (char*)NULL; |
| 3415 |
} |
| 3416 |
|
| 3417 |
|
| 3418 |
|
| 3419 |
|
| 3420 |
|
| 3421 |
|
| 3422 |
|
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
|
| 3427 |
|
| 3428 |
|
| 3429 |
|
| 3430 |
|
| 3431 |
|
| 3432 |
|
| 3433 |
|
| 3434 |
|
| 3435 |
|
| 3436 |
static void |
| 3437 |
MigrateHashEntries(table, first, last, offset) |
| 3438 |
Tcl_HashTable *table; |
| 3439 |
int first; |
| 3440 |
int last; |
| 3441 |
int offset; |
| 3442 |
{ |
| 3443 |
int i, new; |
| 3444 |
Tcl_HashEntry *entry; |
| 3445 |
ClientData clientData; |
| 3446 |
|
| 3447 |
if (offset == 0) { |
| 3448 |
return; |
| 3449 |
} |
| 3450 |
|
| 3451 |
|
| 3452 |
|
| 3453 |
if (offset > 0) { |
| 3454 |
for (i = last; i >= first; i--) { |
| 3455 |
entry = Tcl_FindHashEntry(table, (char *)i); |
| 3456 |
if (entry != NULL) { |
| 3457 |
clientData = Tcl_GetHashValue(entry); |
| 3458 |
Tcl_DeleteHashEntry(entry); |
| 3459 |
entry = Tcl_CreateHashEntry(table, (char *)(i + offset), &new); |
| 3460 |
Tcl_SetHashValue(entry, clientData); |
| 3461 |
} |
| 3462 |
} |
| 3463 |
} else { |
| 3464 |
for (i = first; i <= last; i++) { |
| 3465 |
entry = Tcl_FindHashEntry(table, (char *)i); |
| 3466 |
if (entry != NULL) { |
| 3467 |
clientData = Tcl_GetHashValue(entry); |
| 3468 |
Tcl_DeleteHashEntry(entry); |
| 3469 |
entry = Tcl_CreateHashEntry(table, (char *)(i + offset), &new); |
| 3470 |
Tcl_SetHashValue(entry, clientData); |
| 3471 |
} |
| 3472 |
} |
| 3473 |
} |
| 3474 |
return; |
| 3475 |
} |
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
|