Lines Matching refs:listPtr

269 static void		ChangeListboxOffset _ANSI_ARGS_((Listbox *listPtr,
271 static void ChangeListboxView _ANSI_ARGS_((Listbox *listPtr,
274 Listbox *listPtr, int argc, char **argv,
276 static void DeleteEls _ANSI_ARGS_((Listbox *listPtr, int first,
281 Listbox *listPtr, char *string, int numElsOK,
283 static void InsertEls _ANSI_ARGS_((Listbox *listPtr, int index,
287 static void ListboxComputeGeometry _ANSI_ARGS_((Listbox *listPtr,
296 static void ListboxRedrawRange _ANSI_ARGS_((Listbox *listPtr,
298 static void ListboxScanTo _ANSI_ARGS_((Listbox *listPtr,
300 static void ListboxSelect _ANSI_ARGS_((Listbox *listPtr,
302 static void ListboxUpdateHScrollbar _ANSI_ARGS_((Listbox *listPtr));
303 static void ListboxUpdateVScrollbar _ANSI_ARGS_((Listbox *listPtr));
306 static int NearestListboxElement _ANSI_ARGS_((Listbox *listPtr,
336 register Listbox *listPtr;
357 listPtr = (Listbox *) ckalloc(sizeof(Listbox));
358 listPtr->tkwin = new;
359 listPtr->display = Tk_Display(new);
360 listPtr->interp = interp;
361 listPtr->widgetCmd = Tcl_CreateCommand(interp,
362 Tk_PathName(listPtr->tkwin), ListboxWidgetCmd,
363 (ClientData) listPtr, ListboxCmdDeletedProc);
364 listPtr->numElements = 0;
365 listPtr->firstPtr = NULL;
366 listPtr->lastPtr = NULL;
367 listPtr->normalBorder = NULL;
368 listPtr->borderWidth = 0;
369 listPtr->relief = TK_RELIEF_RAISED;
370 listPtr->highlightWidth = 0;
371 listPtr->highlightBgColorPtr = NULL;
372 listPtr->highlightColorPtr = NULL;
373 listPtr->inset = 0;
374 listPtr->fontPtr = NULL;
375 listPtr->fgColorPtr = NULL;
376 listPtr->textGC = None;
377 listPtr->selBorder = NULL;
378 listPtr->selBorderWidth = 0;
379 listPtr->selFgColorPtr = None;
380 listPtr->selTextGC = None;
381 listPtr->width = 0;
382 listPtr->height = 0;
383 listPtr->lineHeight = 0;
384 listPtr->topIndex = 0;
385 listPtr->fullLines = 1;
386 listPtr->partialLine = 0;
387 listPtr->setGrid = 0;
388 listPtr->maxWidth = 0;
389 listPtr->xScrollUnit = 0;
390 listPtr->xOffset = 0;
391 listPtr->selectMode = NULL;
392 listPtr->numSelected = 0;
393 listPtr->selectAnchor = 0;
394 listPtr->exportSelection = 1;
395 listPtr->active = 0;
396 listPtr->scanMarkX = 0;
397 listPtr->scanMarkY = 0;
398 listPtr->scanMarkXOffset = 0;
399 listPtr->scanMarkYIndex = 0;
400 listPtr->cursor = None;
401 listPtr->takeFocus = NULL;
402 listPtr->xScrollCmd = NULL;
403 listPtr->yScrollCmd = NULL;
404 listPtr->flags = 0;
406 Tk_SetClass(listPtr->tkwin, "Listbox");
407 Tk_CreateEventHandler(listPtr->tkwin,
409 ListboxEventProc, (ClientData) listPtr);
410 Tk_CreateSelHandler(listPtr->tkwin, XA_PRIMARY, XA_STRING,
411 ListboxFetchSelection, (ClientData) listPtr, XA_STRING);
412 if (ConfigureListbox(interp, listPtr, argc-2, argv+2, 0) != TCL_OK) {
416 interp->result = Tk_PathName(listPtr->tkwin);
420 Tk_DestroyWindow(listPtr->tkwin);
450 register Listbox *listPtr = (Listbox *) clientData;
460 Tcl_Preserve((ClientData) listPtr);
472 ListboxRedrawRange(listPtr, listPtr->active, listPtr->active);
473 if (GetListboxIndex(interp, listPtr, argv[2], 0, &index)
477 listPtr->active = index;
478 ListboxRedrawRange(listPtr, listPtr->active, listPtr->active);
488 if (GetListboxIndex(interp, listPtr, argv[2], 0, &index) != TCL_OK) {
491 for (i = 0, elPtr = listPtr->firstPtr; i < index;
495 if ((index >= listPtr->topIndex) && (index < listPtr->numElements)
496 && (index < (listPtr->topIndex + listPtr->fullLines
497 + listPtr->partialLine))) {
498 x = listPtr->inset - listPtr->xOffset;
499 y = ((index - listPtr->topIndex)*listPtr->lineHeight)
500 + listPtr->inset + listPtr->selBorderWidth;
502 listPtr->fontPtr->ascent + listPtr->fontPtr->descent);
512 result = Tk_ConfigureValue(interp, listPtr->tkwin, configSpecs,
513 (char *) listPtr, argv[2], 0);
517 result = Tk_ConfigureInfo(interp, listPtr->tkwin, configSpecs,
518 (char *) listPtr, (char *) NULL, 0);
520 result = Tk_ConfigureInfo(interp, listPtr->tkwin, configSpecs,
521 (char *) listPtr, argv[2], 0);
523 result = ConfigureListbox(interp, listPtr, argc-2, argv+2,
539 for (i = 0, elPtr = listPtr->firstPtr; elPtr != NULL;
547 if (count != listPtr->numSelected) {
559 if (GetListboxIndex(interp, listPtr, argv[2], 0, &first) != TCL_OK) {
565 if (GetListboxIndex(interp, listPtr, argv[3], 0, &last) != TCL_OK) {
569 DeleteEls(listPtr, first, last);
579 if (GetListboxIndex(interp, listPtr, argv[2], 0, &first) != TCL_OK) {
582 if ((argc == 4) && (GetListboxIndex(interp, listPtr, argv[3],
586 for (elPtr = listPtr->firstPtr, i = 0; i < first;
609 if (GetListboxIndex(interp, listPtr, argv[2], 1, &index)
624 if (GetListboxIndex(interp, listPtr, argv[2], 1, &index)
628 InsertEls(listPtr, index, argc-3, argv+3);
640 index = NearestListboxElement(listPtr, y);
657 listPtr->scanMarkX = x;
658 listPtr->scanMarkY = y;
659 listPtr->scanMarkXOffset = listPtr->xOffset;
660 listPtr->scanMarkYIndex = listPtr->topIndex;
663 ListboxScanTo(listPtr, x, y);
678 if (GetListboxIndex(interp, listPtr, argv[2], 0, &index) != TCL_OK) {
681 diff = listPtr->topIndex-index;
683 if (diff <= (listPtr->fullLines/3)) {
684 ChangeListboxView(listPtr, index);
686 ChangeListboxView(listPtr, index - (listPtr->fullLines-1)/2);
689 diff = index - (listPtr->topIndex + listPtr->fullLines - 1);
691 if (diff <= (listPtr->fullLines/3)) {
692 ChangeListboxView(listPtr, listPtr->topIndex + diff);
694 ChangeListboxView(listPtr,
695 index - (listPtr->fullLines-1)/2);
709 if (GetListboxIndex(interp, listPtr, argv[3], 0, &first) != TCL_OK) {
713 if (GetListboxIndex(interp, listPtr, argv[4], 0, &last) != TCL_OK) {
727 listPtr->selectAnchor = first;
729 ListboxSelect(listPtr, first, last, 0);
739 for (elPtr = listPtr->firstPtr, i = 0; i < first;
749 ListboxSelect(listPtr, first, last, 1);
763 sprintf(interp->result, "%d", listPtr->numElements);
769 windowWidth = Tk_Width(listPtr->tkwin)
770 - 2*(listPtr->inset + listPtr->selBorderWidth);
772 if (listPtr->maxWidth == 0) {
775 fraction = listPtr->xOffset/((double) listPtr->maxWidth);
776 fraction2 = (listPtr->xOffset + windowWidth)
777 /((double) listPtr->maxWidth);
787 ChangeListboxOffset(listPtr, index*listPtr->xScrollUnit);
794 offset = fraction*listPtr->maxWidth + 0.5;
797 windowUnits = windowWidth/listPtr->xScrollUnit;
799 offset = listPtr->xOffset
800 + count*listPtr->xScrollUnit*(windowUnits-2);
802 offset = listPtr->xOffset + count*listPtr->xScrollUnit;
806 offset = listPtr->xOffset + count*listPtr->xScrollUnit;
809 ChangeListboxOffset(listPtr, offset);
816 if (listPtr->numElements == 0) {
819 fraction = listPtr->topIndex/((double) listPtr->numElements);
820 fraction2 = (listPtr->topIndex+listPtr->fullLines)
821 /((double) listPtr->numElements);
828 if (GetListboxIndex(interp, listPtr, argv[2], 0, &index)
832 ChangeListboxView(listPtr, index);
839 index = listPtr->numElements*fraction + 0.5;
842 if (listPtr->fullLines > 2) {
843 index = listPtr->topIndex
844 + count*(listPtr->fullLines-2);
846 index = listPtr->topIndex + count;
850 index = listPtr->topIndex + count;
853 ChangeListboxView(listPtr, index);
863 Tcl_Release((ClientData) listPtr);
867 Tcl_Release((ClientData) listPtr);
894 register Listbox *listPtr = (Listbox *) memPtr;
901 for (elPtr = listPtr->firstPtr; elPtr != NULL; ) {
913 if (listPtr->textGC != None) {
914 Tk_FreeGC(listPtr->display, listPtr->textGC);
916 if (listPtr->selTextGC != None) {
917 Tk_FreeGC(listPtr->display, listPtr->selTextGC);
919 Tk_FreeOptions(configSpecs, (char *) listPtr, listPtr->display, 0);
920 ckfree((char *) listPtr);
939 * etc. get set for listPtr; old resources get freed,
946 ConfigureListbox(interp, listPtr, argc, argv, flags)
948 register Listbox *listPtr; /* Information about widget; may or may
958 oldExport = listPtr->exportSelection;
959 if (Tk_ConfigureWidget(interp, listPtr->tkwin, configSpecs,
960 argc, argv, (char *) listPtr, flags) != TCL_OK) {
969 Tk_SetBackgroundFromBorder(listPtr->tkwin, listPtr->normalBorder);
971 if (listPtr->highlightWidth < 0) {
972 listPtr->highlightWidth = 0;
974 listPtr->inset = listPtr->highlightWidth + listPtr->borderWidth;
976 gcValues.foreground = listPtr->fgColorPtr->pixel;
977 gcValues.font = listPtr->fontPtr->fid;
979 new = Tk_GetGC(listPtr->tkwin, GCForeground|GCFont|GCGraphicsExposures,
981 if (listPtr->textGC != None) {
982 Tk_FreeGC(listPtr->display, listPtr->textGC);
984 listPtr->textGC = new;
986 gcValues.foreground = listPtr->selFgColorPtr->pixel;
987 gcValues.font = listPtr->fontPtr->fid;
988 new = Tk_GetGC(listPtr->tkwin, GCForeground|GCFont, &gcValues);
989 if (listPtr->selTextGC != None) {
990 Tk_FreeGC(listPtr->display, listPtr->selTextGC);
992 listPtr->selTextGC = new;
999 if (listPtr->exportSelection && !oldExport
1000 && (listPtr->numSelected != 0)) {
1001 Tk_OwnSelection(listPtr->tkwin, XA_PRIMARY, ListboxLostSelection,
1002 (ClientData) listPtr);
1010 ListboxComputeGeometry(listPtr, 1, 1, 1);
1011 listPtr->flags |= UPDATE_V_SCROLLBAR|UPDATE_H_SCROLLBAR;
1012 ListboxRedrawRange(listPtr, 0, listPtr->numElements-1);
1037 register Listbox *listPtr = (Listbox *) clientData;
1038 register Tk_Window tkwin = listPtr->tkwin;
1047 listPtr->flags &= ~REDRAW_PENDING;
1048 if (listPtr->flags & UPDATE_V_SCROLLBAR) {
1049 ListboxUpdateVScrollbar(listPtr);
1051 if (listPtr->flags & UPDATE_H_SCROLLBAR) {
1052 ListboxUpdateHScrollbar(listPtr);
1054 listPtr->flags &= ~(REDRAW_PENDING|UPDATE_V_SCROLLBAR|UPDATE_H_SCROLLBAR);
1055 if ((listPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
1067 pixmap = Tk_GetPixmap(listPtr->display, Tk_WindowId(tkwin),
1069 Tk_Fill3DRectangle(tkwin, pixmap, listPtr->normalBorder, 0, 0,
1078 limit = listPtr->topIndex + listPtr->fullLines + listPtr->partialLine - 1;
1079 if (limit >= listPtr->numElements) {
1080 limit = listPtr->numElements-1;
1083 if (listPtr->xOffset > 0) {
1084 left = listPtr->selBorderWidth+1;
1086 if ((listPtr->maxWidth - listPtr->xOffset) > (Tk_Width(listPtr->tkwin)
1087 - 2*(listPtr->inset + listPtr->selBorderWidth))) {
1088 right = listPtr->selBorderWidth+1;
1091 for (elPtr = listPtr->firstPtr, i = 0; (elPtr != NULL) && (i <= limit);
1093 if (i < listPtr->topIndex) {
1096 x = listPtr->inset;
1097 y = ((i - listPtr->topIndex) * listPtr->lineHeight)
1098 + listPtr->inset;
1099 gc = listPtr->textGC;
1101 gc = listPtr->selTextGC;
1102 width = Tk_Width(tkwin) - 2*listPtr->inset;
1103 Tk_Fill3DRectangle(tkwin, pixmap, listPtr->selBorder, x, y,
1104 width, listPtr->lineHeight, 0, TK_RELIEF_FLAT);
1122 Tk_3DVerticalBevel(tkwin, pixmap, listPtr->selBorder,
1123 x, y, listPtr->selBorderWidth, listPtr->lineHeight,
1127 Tk_3DVerticalBevel(tkwin, pixmap, listPtr->selBorder,
1128 x + width - listPtr->selBorderWidth, y,
1129 listPtr->selBorderWidth, listPtr->lineHeight,
1133 Tk_3DHorizontalBevel(tkwin, pixmap, listPtr->selBorder,
1134 x-left, y, width+left+right, listPtr->selBorderWidth,
1138 Tk_3DHorizontalBevel(tkwin, pixmap, listPtr->selBorder, x-left,
1139 y + listPtr->lineHeight - listPtr->selBorderWidth,
1140 width+left+right, listPtr->selBorderWidth, 0, 0, 0,
1144 y += listPtr->fontPtr->ascent + listPtr->selBorderWidth;
1145 x = listPtr->inset + listPtr->selBorderWidth - elPtr->lBearing
1146 - listPtr->xOffset;
1147 XDrawString(listPtr->display, pixmap, gc, x, y,
1154 if ((i == listPtr->active) && (listPtr->flags & GOT_FOCUS)) {
1155 XFillRectangle(listPtr->display, pixmap, gc,
1156 listPtr->inset + listPtr->selBorderWidth
1157 - listPtr->xOffset,
1158 y + listPtr->fontPtr->descent - 1,
1168 Tk_Draw3DRectangle(tkwin, pixmap, listPtr->normalBorder,
1169 listPtr->highlightWidth, listPtr->highlightWidth,
1170 Tk_Width(tkwin) - 2*listPtr->highlightWidth,
1171 Tk_Height(tkwin) - 2*listPtr->highlightWidth,
1172 listPtr->borderWidth, listPtr->relief);
1173 if (listPtr->highlightWidth > 0) {
1176 if (listPtr->flags & GOT_FOCUS) {
1177 gc = Tk_GCForColor(listPtr->highlightColorPtr, pixmap);
1179 gc = Tk_GCForColor(listPtr->highlightBgColorPtr, pixmap);
1181 Tk_DrawFocusHighlight(tkwin, gc, listPtr->highlightWidth, pixmap);
1183 XCopyArea(listPtr->display, pixmap, Tk_WindowId(tkwin),
1184 listPtr->textGC, 0, 0, (unsigned) Tk_Width(tkwin),
1186 Tk_FreePixmap(listPtr->display, pixmap);
1211 ListboxComputeGeometry(listPtr, fontChanged, maxIsStale, updateGrid)
1212 Listbox *listPtr; /* Listbox whose geometry is to be
1230 listPtr->xScrollUnit = XTextWidth(listPtr->fontPtr, "0", 1);
1231 listPtr->maxWidth = 0;
1232 for (elPtr = listPtr->firstPtr; elPtr != NULL; elPtr = elPtr->nextPtr) {
1234 XTextExtents(listPtr->fontPtr, elPtr->text, elPtr->textLength,
1239 if (elPtr->pixelWidth > listPtr->maxWidth) {
1240 listPtr->maxWidth = elPtr->pixelWidth;
1245 fontHeight = listPtr->fontPtr->ascent + listPtr->fontPtr->descent;
1246 listPtr->lineHeight = fontHeight + 1 + 2*listPtr->selBorderWidth;
1247 width = listPtr->width;
1249 width = (listPtr->maxWidth + listPtr->xScrollUnit - 1)
1250 /listPtr->xScrollUnit;
1255 pixelWidth = width*listPtr->xScrollUnit + 2*listPtr->inset
1256 + 2*listPtr->selBorderWidth;
1257 height = listPtr->height;
1258 if (listPtr->height <= 0) {
1259 height = listPtr->numElements;
1264 pixelHeight = height*listPtr->lineHeight + 2*listPtr->inset;
1265 Tk_GeometryRequest(listPtr->tkwin, pixelWidth, pixelHeight);
1266 Tk_SetInternalBorder(listPtr->tkwin, listPtr->inset);
1268 if (listPtr->setGrid) {
1269 Tk_SetGrid(listPtr->tkwin, width, height, listPtr->xScrollUnit,
1270 listPtr->lineHeight);
1272 Tk_UnsetGrid(listPtr->tkwin);
1289 * New information gets added to listPtr; it will be redisplayed
1296 InsertEls(listPtr, index, argc, argv)
1297 register Listbox *listPtr; /* Listbox that is to get the new
1315 if (index > listPtr->numElements) {
1316 index = listPtr->numElements;
1320 } else if (index == listPtr->numElements) {
1321 prevPtr = listPtr->lastPtr;
1323 for (prevPtr = listPtr->firstPtr, i = index - 1; i > 0; i--) {
1333 oldMaxWidth = listPtr->maxWidth;
1339 XTextExtents(listPtr->fontPtr, newPtr->text, newPtr->textLength,
1343 if (newPtr->pixelWidth > listPtr->maxWidth) {
1344 listPtr->maxWidth = newPtr->pixelWidth;
1348 newPtr->nextPtr = listPtr->firstPtr;
1349 listPtr->firstPtr = newPtr;
1356 listPtr->lastPtr = prevPtr;
1358 listPtr->numElements += argc;
1366 if (index <= listPtr->selectAnchor) {
1367 listPtr->selectAnchor += argc;
1369 if (index < listPtr->topIndex) {
1370 listPtr->topIndex += argc;
1372 if (index <= listPtr->active) {
1373 listPtr->active += argc;
1374 if ((listPtr->active >= listPtr->numElements)
1375 && (listPtr->numElements > 0)) {
1376 listPtr->active = listPtr->numElements-1;
1379 listPtr->flags |= UPDATE_V_SCROLLBAR;
1380 if (listPtr->maxWidth != oldMaxWidth) {
1381 listPtr->flags |= UPDATE_H_SCROLLBAR;
1383 ListboxComputeGeometry(listPtr, 0, 0, 0);
1384 ListboxRedrawRange(listPtr, index, listPtr->numElements-1);
1406 DeleteEls(listPtr, first, last)
1407 register Listbox *listPtr; /* Listbox widget to modify. */
1422 if (last >= listPtr->numElements) {
1423 last = listPtr->numElements-1;
1437 for (i = first-1, prevPtr = listPtr->firstPtr; i > 0; i--) {
1449 elPtr = listPtr->firstPtr;
1450 listPtr->firstPtr = elPtr->nextPtr;
1451 if (listPtr->firstPtr == NULL) {
1452 listPtr->lastPtr = NULL;
1458 listPtr->lastPtr = prevPtr;
1461 if (elPtr->pixelWidth == listPtr->maxWidth) {
1465 listPtr->numSelected -= 1;
1469 listPtr->numElements -= count;
1477 if (first <= listPtr->selectAnchor) {
1478 listPtr->selectAnchor -= count;
1479 if (listPtr->selectAnchor < first) {
1480 listPtr->selectAnchor = first;
1483 if (first <= listPtr->topIndex) {
1484 listPtr->topIndex -= count;
1485 if (listPtr->topIndex < first) {
1486 listPtr->topIndex = first;
1489 if (listPtr->topIndex > (listPtr->numElements - listPtr->fullLines)) {
1490 listPtr->topIndex = listPtr->numElements - listPtr->fullLines;
1491 if (listPtr->topIndex < 0) {
1492 listPtr->topIndex = 0;
1495 if (listPtr->active > last) {
1496 listPtr->active -= count;
1497 } else if (listPtr->active >= first) {
1498 listPtr->active = first;
1499 if ((listPtr->active >= listPtr->numElements)
1500 && (listPtr->numElements > 0)) {
1501 listPtr->active = listPtr->numElements-1;
1504 listPtr->flags |= UPDATE_V_SCROLLBAR;
1505 ListboxComputeGeometry(listPtr, 0, widthChanged, 0);
1507 listPtr->flags |= UPDATE_H_SCROLLBAR;
1509 ListboxRedrawRange(listPtr, first, listPtr->numElements-1);
1536 Listbox *listPtr = (Listbox *) clientData;
1539 ListboxRedrawRange(listPtr,
1540 NearestListboxElement(listPtr, eventPtr->xexpose.y),
1541 NearestListboxElement(listPtr, eventPtr->xexpose.y
1544 if (listPtr->tkwin != NULL) {
1545 if (listPtr->setGrid) {
1546 Tk_UnsetGrid(listPtr->tkwin);
1548 listPtr->tkwin = NULL;
1549 Tcl_DeleteCommand(listPtr->interp,
1550 Tcl_GetCommandName(listPtr->interp, listPtr->widgetCmd));
1552 if (listPtr->flags & REDRAW_PENDING) {
1553 Tcl_CancelIdleCall(DisplayListbox, (ClientData) listPtr);
1555 Tcl_EventuallyFree((ClientData) listPtr, DestroyListbox);
1559 vertSpace = Tk_Height(listPtr->tkwin) - 2*listPtr->inset;
1560 listPtr->fullLines = vertSpace / listPtr->lineHeight;
1561 if ((listPtr->fullLines*listPtr->lineHeight) < vertSpace) {
1562 listPtr->partialLine = 1;
1564 listPtr->partialLine = 0;
1566 listPtr->flags |= UPDATE_V_SCROLLBAR|UPDATE_H_SCROLLBAR;
1567 ChangeListboxView(listPtr, listPtr->topIndex);
1568 ChangeListboxOffset(listPtr, listPtr->xOffset);
1577 ListboxRedrawRange(listPtr, 0, listPtr->numElements-1);
1580 listPtr->flags |= GOT_FOCUS;
1581 ListboxRedrawRange(listPtr, 0, listPtr->numElements-1);
1585 listPtr->flags &= ~GOT_FOCUS;
1586 ListboxRedrawRange(listPtr, 0, listPtr->numElements-1);
1614 Listbox *listPtr = (Listbox *) clientData;
1615 Tk_Window tkwin = listPtr->tkwin;
1625 if (listPtr->setGrid) {
1626 Tk_UnsetGrid(listPtr->tkwin);
1628 listPtr->tkwin = NULL;
1644 * filled in with the index (into listPtr) corresponding to
1654 GetListboxIndex(interp, listPtr, string, numElsOK, indexPtr)
1656 Listbox *listPtr; /* Listbox for which the index is being
1672 *indexPtr = listPtr->active;
1675 *indexPtr = listPtr->selectAnchor;
1677 *indexPtr = listPtr->numElements;
1692 *indexPtr = NearestListboxElement(listPtr, y);
1700 if (*indexPtr > listPtr->numElements) {
1701 *indexPtr = listPtr->numElements;
1703 } else if (*indexPtr >= listPtr->numElements) {
1704 *indexPtr = listPtr->numElements-1;
1739 ChangeListboxView(listPtr, index)
1740 register Listbox *listPtr; /* Information about widget. */
1741 int index; /* Index of element in listPtr
1745 if (index >= (listPtr->numElements - listPtr->fullLines)) {
1746 index = listPtr->numElements - listPtr->fullLines;
1751 if (listPtr->topIndex != index) {
1752 listPtr->topIndex = index;
1753 if (!(listPtr->flags & REDRAW_PENDING)) {
1754 Tcl_DoWhenIdle(DisplayListbox, (ClientData) listPtr);
1755 listPtr->flags |= REDRAW_PENDING;
1757 listPtr->flags |= UPDATE_V_SCROLLBAR;
1780 ChangeListboxOffset(listPtr, offset)
1781 register Listbox *listPtr; /* Information about widget. */
1792 maxOffset = listPtr->maxWidth + (listPtr->xScrollUnit-1)
1793 - (Tk_Width(listPtr->tkwin) - 2*listPtr->inset
1794 - 2*listPtr->selBorderWidth - listPtr->xScrollUnit);
1801 offset -= offset%listPtr->xScrollUnit;
1802 if (offset != listPtr->xOffset) {
1803 listPtr->xOffset = offset;
1804 listPtr->flags |= UPDATE_H_SCROLLBAR;
1805 ListboxRedrawRange(listPtr, 0, listPtr->numElements);
1828 ListboxScanTo(listPtr, x, y)
1829 register Listbox *listPtr; /* Information about widget. */
1837 maxIndex = listPtr->numElements - listPtr->fullLines;
1838 maxOffset = listPtr->maxWidth + (listPtr->xScrollUnit-1)
1839 - (Tk_Width(listPtr->tkwin) - 2*listPtr->inset
1840 - 2*listPtr->selBorderWidth - listPtr->xScrollUnit);
1853 newTopIndex = listPtr->scanMarkYIndex
1854 - (10*(y - listPtr->scanMarkY))/listPtr->lineHeight;
1856 newTopIndex = listPtr->scanMarkYIndex = maxIndex;
1857 listPtr->scanMarkY = y;
1859 newTopIndex = listPtr->scanMarkYIndex = 0;
1860 listPtr->scanMarkY = y;
1862 ChangeListboxView(listPtr, newTopIndex);
1870 newOffset = listPtr->scanMarkXOffset - (10*(x - listPtr->scanMarkX));
1872 newOffset = listPtr->scanMarkXOffset = maxOffset;
1873 listPtr->scanMarkX = x;
1875 newOffset = listPtr->scanMarkXOffset = 0;
1876 listPtr->scanMarkX = x;
1878 ChangeListboxOffset(listPtr, newOffset);
1892 * The return value is an index of an element of listPtr. If
1893 * listPtr has no elements, then 0 is always returned.
1902 NearestListboxElement(listPtr, y)
1903 register Listbox *listPtr; /* Information about widget. */
1904 int y; /* Y-coordinate in listPtr's window. */
1908 index = (y - listPtr->inset)/listPtr->lineHeight;
1909 if (index >= (listPtr->fullLines + listPtr->partialLine)) {
1910 index = listPtr->fullLines + listPtr->partialLine - 1;
1915 index += listPtr->topIndex;
1916 if (index >= listPtr->numElements) {
1917 index = listPtr->numElements-1;
1944 ListboxSelect(listPtr, first, last, select)
1945 register Listbox *listPtr; /* Information about widget. */
1961 if (first >= listPtr->numElements) {
1964 oldCount = listPtr->numSelected;
1967 for (i = 0, elPtr = listPtr->firstPtr; i < first;
1975 listPtr->numSelected += increment;
1982 ListboxRedrawRange(listPtr, first, last);
1984 if ((oldCount == 0) && (listPtr->numSelected > 0)
1985 && (listPtr->exportSelection)) {
1986 Tk_OwnSelection(listPtr->tkwin, XA_PRIMARY, ListboxLostSelection,
1987 (ClientData) listPtr);
2026 register Listbox *listPtr = (Listbox *) clientData;
2031 if (!listPtr->exportSelection) {
2041 for (elPtr = listPtr->firstPtr; elPtr != NULL; elPtr = elPtr->nextPtr) {
2099 register Listbox *listPtr = (Listbox *) clientData;
2101 if ((listPtr->exportSelection) && (listPtr->numElements > 0)) {
2102 ListboxSelect(listPtr, 0, listPtr->numElements-1, 0);
2126 ListboxRedrawRange(listPtr, first, last)
2127 register Listbox *listPtr; /* Information about widget. */
2135 if ((listPtr->tkwin == NULL) || !Tk_IsMapped(listPtr->tkwin)
2136 || (listPtr->flags & REDRAW_PENDING)) {
2139 Tcl_DoWhenIdle(DisplayListbox, (ClientData) listPtr);
2140 listPtr->flags |= REDRAW_PENDING;
2165 ListboxUpdateVScrollbar(listPtr)
2166 register Listbox *listPtr; /* Information about widget. */
2173 if (listPtr->yScrollCmd == NULL) {
2176 if (listPtr->numElements == 0) {
2180 first = listPtr->topIndex/((double) listPtr->numElements);
2181 last = (listPtr->topIndex+listPtr->fullLines)
2182 /((double) listPtr->numElements);
2190 * We must hold onto the interpreter from the listPtr because the data
2191 * at listPtr might be freed as a result of the Tcl_VarEval.
2194 interp = listPtr->interp;
2196 result = Tcl_VarEval(interp, listPtr->yScrollCmd, string,
2228 ListboxUpdateHScrollbar(listPtr)
2229 register Listbox *listPtr; /* Information about widget. */
2236 if (listPtr->xScrollCmd == NULL) {
2239 windowWidth = Tk_Width(listPtr->tkwin) - 2*(listPtr->inset
2240 + listPtr->selBorderWidth);
2241 if (listPtr->maxWidth == 0) {
2245 first = listPtr->xOffset/((double) listPtr->maxWidth);
2246 last = (listPtr->xOffset + windowWidth)
2247 /((double) listPtr->maxWidth);
2256 * listPtr might be freed as a result of the call to Tcl_VarEval.
2259 interp = listPtr->interp;
2261 result = Tcl_VarEval(interp, listPtr->xScrollCmd, string,