Tk Source Code

Check-in [3736983e]
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:Fixed bug [3102228] - <<ListboxSelect>> doesn't fire when selection lost
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3736983e96802c090f7957208789ee7890cc110a
User & Date: fvogel 2016-01-06 20:30:24
Context
2016-01-07
17:20
Prefix "system" of all Windows System Colors was documented check-in: 28b2e86a user: oehhar tags: trunk
13:08
rebase "tip-438" branch to latest trunk. Closed-Leaf check-in: 9f400abe user: jan.nijtmans tags: tip-438
2016-01-06
20:30
Fixed bug [3102228] - <<ListboxSelect>> doesn't fire when selection lost check-in: 3736983e user: fvogel tags: trunk
20:28
Fixed bug [3102228] - <<ListboxSelect>> doesn't fire when selection lost check-in: 142932e3 user: fvogel tags: core-8-5-branch
20:18
Fixed bug [1288433] - LisboxSelect event triggers when listbox state is disabled check-in: 087e635d user: fvogel tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tkListbox.c.

404
405
406
407
408
409
410

411
412
413
414
415
416
417
....
3166
3167
3168
3169
3170
3171
3172

3173
3174

































3175
3176
3177
3178
3179
3180
3181
static void		ListboxComputeGeometry(Listbox *listPtr,
			    int fontChanged, int maxIsStale, int updateGrid);
static void		ListboxEventProc(ClientData clientData,
			    XEvent *eventPtr);
static int		ListboxFetchSelection(ClientData clientData,
			    int offset, char *buffer, int maxBytes);
static void		ListboxLostSelection(ClientData clientData);

static void		EventuallyRedrawRange(Listbox *listPtr,
			    int first, int last);
static void		ListboxScanTo(Listbox *listPtr, int x, int y);
static int		ListboxSelect(Listbox *listPtr,
			    int first, int last, int select);
static void		ListboxUpdateHScrollbar(Listbox *listPtr);
static void		ListboxUpdateVScrollbar(Listbox *listPtr);
................................................................................
ListboxLostSelection(
    ClientData clientData)	/* Information about listbox widget. */
{
    register Listbox *listPtr = clientData;

    if ((listPtr->exportSelection) && (listPtr->nElements > 0)) {
	ListboxSelect(listPtr, 0, listPtr->nElements-1, 0);

    }
}

































 
/*
 *----------------------------------------------------------------------
 *
 * EventuallyRedrawRange --
 *
 *	Ensure that a given range of elements is eventually redrawn on the







>







 







>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
....
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
static void		ListboxComputeGeometry(Listbox *listPtr,
			    int fontChanged, int maxIsStale, int updateGrid);
static void		ListboxEventProc(ClientData clientData,
			    XEvent *eventPtr);
static int		ListboxFetchSelection(ClientData clientData,
			    int offset, char *buffer, int maxBytes);
static void		ListboxLostSelection(ClientData clientData);
static void		GenerateListboxSelectEvent(Listbox *listPtr);
static void		EventuallyRedrawRange(Listbox *listPtr,
			    int first, int last);
static void		ListboxScanTo(Listbox *listPtr, int x, int y);
static int		ListboxSelect(Listbox *listPtr,
			    int first, int last, int select);
static void		ListboxUpdateHScrollbar(Listbox *listPtr);
static void		ListboxUpdateVScrollbar(Listbox *listPtr);
................................................................................
ListboxLostSelection(
    ClientData clientData)	/* Information about listbox widget. */
{
    register Listbox *listPtr = clientData;

    if ((listPtr->exportSelection) && (listPtr->nElements > 0)) {
	ListboxSelect(listPtr, 0, listPtr->nElements-1, 0);
        GenerateListboxSelectEvent(listPtr);
    }
}
 
/*
 *----------------------------------------------------------------------
 *
 * GenerateListboxSelectEvent --
 *
 *	Send an event that the listbox selection was updated. This is
 *	equivalent to event generate $listboxWidget <<ListboxSelect>>
 *
 * Results:
 *	None
 *
 * Side effects:
 *	Any side effect possible, depending on bindings to this event.
 *
 *----------------------------------------------------------------------
 */

static void
GenerateListboxSelectEvent(
    Listbox *listPtr)		/* Information about widget. */
{
    union {XEvent general; XVirtualEvent virtual;} event;

    memset(&event, 0, sizeof(event));
    event.general.xany.type = VirtualEvent;
    event.general.xany.serial = NextRequest(Tk_Display(listPtr->tkwin));
    event.general.xany.send_event = False;
    event.general.xany.window = Tk_WindowId(listPtr->tkwin);
    event.general.xany.display = Tk_Display(listPtr->tkwin);
    event.virtual.name = Tk_GetUid("ListboxSelect");
    Tk_HandleEvent(&event.general);
}
 
/*
 *----------------------------------------------------------------------
 *
 * EventuallyRedrawRange --
 *
 *	Ensure that a given range of elements is eventually redrawn on the

Changes to tests/listbox.test.

3087
3088
3089
3090
3091
3092
3093















3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
    .l selection clear 0 end         ; # <<ListboxSelect>> does NOT fire
    .l selection set 1 1             ; # <<ListboxSelect>> does NOT fire
    lappend res [.l curselection]
} -cleanup {
    destroy .l
    unset -nocomplain res
} -result {0 2 1}
















resetGridInfo
deleteWindows
option clear

# cleanup
cleanupTests
return












>
>
>
>
>
>
>
>
>
>
>
>
>
>
>













3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
    .l selection clear 0 end         ; # <<ListboxSelect>> does NOT fire
    .l selection set 1 1             ; # <<ListboxSelect>> does NOT fire
    lappend res [.l curselection]
} -cleanup {
    destroy .l
    unset -nocomplain res
} -result {0 2 1}

test listbox-31.2 {<<ListboxSelect>> event on lost selection} -setup {
    destroy .l
} -body {
    pack [listbox .l -exportselection true]
    update
    bind .l <<ListboxSelect>> {lappend res [list [selection own] [%W curselection]]}
    .l insert end a b c
    focus -force .l
    event generate .l <1> -x 5 -y 5  ; # <<ListboxSelect>> fires
    selection clear                  ; # <<ListboxSelect>> fires again
    set res
} -cleanup {
    destroy .l
} -result {{.l 0} {{} {}}}

resetGridInfo
deleteWindows
option clear

# cleanup
cleanupTests
return