Tk Source Code

Check-in [33195408]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Addressed questions 3 and 5 (see artifact [9d48a9c212] of ticket [3f456a5bb9]). It is not desirable to make the listbox xview jump on resizing.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-441
Files: files | file ages | folders
SHA1:33195408d675e4dc5fe86d905f3bbbb9af7140b2
User & Date: fvogel 2016-01-17 20:40:01
Original Comment: Addressed questions 3 and 5 (see artifact [9d48a9c212] of ticket [3f456a5bb9]).
Context
2016-01-17
21:09
Addressed question 4 (see artifact [9d48a9c212] of ticket [3f456a5bb9]). check-in: ae788ecf user: fvogel tags: tip-441
20:40
Addressed questions 3 and 5 (see artifact [9d48a9c212] of ticket [3f456a5bb9]). It is not desirable to make the listbox xview jump on resizing. check-in: 33195408 user: fvogel tags: tip-441
2016-01-16
15:45
Removed test listbox-3.18c since it is irrelevant (the rendering of the selected items is made in a code that depends on existence of a selection but this is untestable by bboxing since bbox is independent from the presence of a selection in the listbox) check-in: 7bc53e6b user: fvogel tags: tip-441
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tkListbox.c.

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
....
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
....
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
				 * horizontal scrollbar. NULL means no command
				 * to issue. Malloc'ed. */
    int state;			/* Listbox state. */
    Pixmap gray;		/* Pixmap for displaying disabled text. */
    int flags;			/* Various flag bits: see below for
				 * definitions. */
    Tk_Justify justify;         /* Justification. */
    int oldMaxOffset;           /* Used in scrolling for right/center
                                 * justification. */
} Listbox;

/*
 * How to encode the keys for the hash tables used to store what items are
 * selected and what the attributes are.
 */

................................................................................
    listPtr->fullLines		 = 1;
    listPtr->xScrollUnit	 = 1;
    listPtr->exportSelection	 = 1;
    listPtr->cursor		 = None;
    listPtr->state		 = STATE_NORMAL;
    listPtr->gray		 = None;
    listPtr->justify             = TK_JUSTIFY_LEFT;
    listPtr->oldMaxOffset        = 0;

    /*
     * Keep a hold of the associated tkwin until we destroy the listbox,
     * otherwise Tk might free it while we still need it.
     */

    Tcl_Preserve(listPtr->tkwin);
................................................................................
 */

static void
ListboxEventProc(
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    int tmpOffset, tmpOffset2, maxOffset;
    Listbox *listPtr = clientData;

    if (eventPtr->type == Expose) {
	EventuallyRedrawRange(listPtr,
		NearestListboxElement(listPtr, eventPtr->xexpose.y),
		NearestListboxElement(listPtr, eventPtr->xexpose.y
		+ eventPtr->xexpose.height));
................................................................................
	if ((listPtr->fullLines*listPtr->lineHeight) < vertSpace) {
	    listPtr->partialLine = 1;
	} else {
	    listPtr->partialLine = 0;
	}
	listPtr->flags |= UPDATE_V_SCROLLBAR|UPDATE_H_SCROLLBAR;
	ChangeListboxView(listPtr, listPtr->topIndex);
        if (listPtr->justify == TK_JUSTIFY_RIGHT) {
            maxOffset = GetMaxOffset(listPtr);
            if (maxOffset != listPtr->oldMaxOffset && listPtr->oldMaxOffset > 0) {

                /*
                 * Window has shrunk.
                 */

                if (maxOffset > listPtr->oldMaxOffset) {
                    tmpOffset = maxOffset - listPtr->oldMaxOffset;
                } else {
                    tmpOffset = listPtr->oldMaxOffset - maxOffset;
                }
                tmpOffset -= tmpOffset % listPtr->xScrollUnit;
                if ((tmpOffset + listPtr->xOffset) > maxOffset) {
                    tmpOffset = maxOffset - listPtr->xOffset;
                }
                if (tmpOffset < 0) {
                    tmpOffset = 0;
                }
                listPtr->xOffset += tmpOffset;
            } else {
                listPtr->xOffset = maxOffset;
            }
            listPtr->oldMaxOffset = maxOffset;
        } else if (listPtr->justify == TK_JUSTIFY_CENTER) {
            maxOffset = GetMaxOffset(listPtr);
            if (maxOffset != listPtr->oldMaxOffset && listPtr->oldMaxOffset > 0) {

                /*
                 * Window has shrunk.
                 */

                tmpOffset2 = maxOffset / 2;
                if (maxOffset > listPtr->oldMaxOffset) {
                    tmpOffset = maxOffset/2 - listPtr->oldMaxOffset/2;
                } else {
                    tmpOffset = listPtr->oldMaxOffset/2 - maxOffset/2;
                }
                tmpOffset -= tmpOffset % listPtr->xScrollUnit;
                if ((tmpOffset + listPtr->xOffset) > maxOffset) {
                    tmpOffset = maxOffset - listPtr->xOffset;
                }
                if (tmpOffset < 0) {
                    tmpOffset = 0;
                }
                if (listPtr->xOffset < tmpOffset2) {
                    listPtr->xOffset += tmpOffset;
                } else {
                    listPtr->xOffset -= tmpOffset;
                }
            } else {
                listPtr->xOffset = maxOffset/2;
                listPtr->xOffset -= listPtr->xOffset % listPtr->xScrollUnit;
            }
            listPtr->oldMaxOffset = maxOffset;
        }
	ChangeListboxOffset(listPtr, listPtr->xOffset);

	/*
	 * Redraw the whole listbox. It's hard to tell what needs to be
	 * redrawn (e.g. if the listbox has shrunk then we may only need to
	 * redraw the borders), so just redraw everything for safety.
	 */







<
<







 







<







 







<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







163
164
165
166
167
168
169


170
171
172
173
174
175
176
...
548
549
550
551
552
553
554

555
556
557
558
559
560
561
....
2616
2617
2618
2619
2620
2621
2622

2623
2624
2625
2626
2627
2628
2629
....
2647
2648
2649
2650
2651
2652
2653

























































2654
2655
2656
2657
2658
2659
2660
				 * horizontal scrollbar. NULL means no command
				 * to issue. Malloc'ed. */
    int state;			/* Listbox state. */
    Pixmap gray;		/* Pixmap for displaying disabled text. */
    int flags;			/* Various flag bits: see below for
				 * definitions. */
    Tk_Justify justify;         /* Justification. */


} Listbox;

/*
 * How to encode the keys for the hash tables used to store what items are
 * selected and what the attributes are.
 */

................................................................................
    listPtr->fullLines		 = 1;
    listPtr->xScrollUnit	 = 1;
    listPtr->exportSelection	 = 1;
    listPtr->cursor		 = None;
    listPtr->state		 = STATE_NORMAL;
    listPtr->gray		 = None;
    listPtr->justify             = TK_JUSTIFY_LEFT;


    /*
     * Keep a hold of the associated tkwin until we destroy the listbox,
     * otherwise Tk might free it while we still need it.
     */

    Tcl_Preserve(listPtr->tkwin);
................................................................................
 */

static void
ListboxEventProc(
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{

    Listbox *listPtr = clientData;

    if (eventPtr->type == Expose) {
	EventuallyRedrawRange(listPtr,
		NearestListboxElement(listPtr, eventPtr->xexpose.y),
		NearestListboxElement(listPtr, eventPtr->xexpose.y
		+ eventPtr->xexpose.height));
................................................................................
	if ((listPtr->fullLines*listPtr->lineHeight) < vertSpace) {
	    listPtr->partialLine = 1;
	} else {
	    listPtr->partialLine = 0;
	}
	listPtr->flags |= UPDATE_V_SCROLLBAR|UPDATE_H_SCROLLBAR;
	ChangeListboxView(listPtr, listPtr->topIndex);

























































	ChangeListboxOffset(listPtr, listPtr->xOffset);

	/*
	 * Redraw the whole listbox. It's hard to tell what needs to be
	 * redrawn (e.g. if the listbox has shrunk then we may only need to
	 * redraw the borders), so just redraw everything for safety.
	 */