Skip to content

Commit ebf4cba

Browse files
committed
win32: no list-box callback from the select method
Closes #3030
1 parent f6caa2a commit ebf4cba

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

gui-lib/mred/private/wx/win32/list-box.rkt

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@
162162
;; ....
163163
))
164164

165+
(define suppress-callback (make-parameter #f))
166+
165167
;; ------------------------------------------------------------
166168

167169
(define list-box%
@@ -282,27 +284,28 @@
282284

283285
(define pending-changed (box #f))
284286
(define/override (do-command cmd control-hwnd)
285-
;; LVN_ITEMCHANGED notifications, in particular, get
286-
;; set for each item that changes in a selection change.
287-
;; Use a box to cancel pending callbacks to collapse the
288-
;; multiple callbacks into one.
289-
(set-box! pending-changed #f)
290-
(let ([b (box #t)]
291-
[t (if (if single-column?
292-
(= cmd LBN_SELCHANGE)
293-
(= cmd LVN_ITEMCHANGED))
294-
'list-box
295-
'list-box-dclick)])
296-
(unless (eq? t 'list-box-dclick)
297-
(set! pending-changed b))
298-
(queue-window-event
299-
this
300-
(lambda ()
301-
(when (unbox b)
302-
(callback this
303-
(new control-event%
304-
[event-type t]
305-
[time-stamp (current-milliseconds)])))))))
287+
(unless (suppress-callback)
288+
;; LVN_ITEMCHANGED notifications, in particular, get
289+
;; set for each item that changes in a selection change.
290+
;; Use a box to cancel pending callbacks to collapse the
291+
;; multiple callbacks into one.
292+
(set-box! pending-changed #f)
293+
(let ([b (box #t)]
294+
[t (if (if single-column?
295+
(= cmd LBN_SELCHANGE)
296+
(= cmd LVN_ITEMCHANGED))
297+
'list-box
298+
'list-box-dclick)])
299+
(unless (eq? t 'list-box-dclick)
300+
(set! pending-changed b))
301+
(queue-window-event
302+
this
303+
(lambda ()
304+
(when (unbox b)
305+
(callback this
306+
(new control-event%
307+
[event-type t]
308+
[time-stamp (current-milliseconds)]))))))))
306309

307310
(define/override (do-command-ex cmd control-hwnd nmhdr)
308311
(if (and (not single-column?)
@@ -520,23 +523,24 @@
520523
(not (zero? (SendMessageW hwnd LVM_GETITEMSTATE i LVIS_SELECTED)))))
521524

522525
(define/public (select i [on? #t] [one? #t])
523-
(void
524-
(if single-column?
525-
(if single?
526-
(SendMessageW hwnd LB_SETCURSEL (if on? i -1) 0)
527-
(begin
528-
(unless one?
529-
(SendMessageW hwnd LB_SELITEMRANGE 0 (MAKELPARAM 0 num)))
530-
(SendMessageW hwnd LB_SETSEL (if on? 1 0) i)))
531-
(let ([lv (make-lvitem 0 0 0 #f)])
532-
(define (set-one i on?)
533-
(set-LVITEM-stateMask! lv LVIS_SELECTED)
534-
(set-LVITEM-state! lv (if on? LVIS_SELECTED 0))
535-
(SendMessageW/ptr hwnd LVM_SETITEMSTATE i lv))
536-
(when (and on? (not single?) (not one?))
537-
(for ([i (in-list (get-selections))])
538-
(set-one i #f)))
539-
(set-one i on?)))))
526+
(parameterize ([suppress-callback #t])
527+
(void
528+
(if single-column?
529+
(if single?
530+
(SendMessageW hwnd LB_SETCURSEL (if on? i -1) 0)
531+
(begin
532+
(unless one?
533+
(SendMessageW hwnd LB_SELITEMRANGE 0 (MAKELPARAM 0 num)))
534+
(SendMessageW hwnd LB_SETSEL (if on? 1 0) i)))
535+
(let ([lv (make-lvitem 0 0 0 #f)])
536+
(define (set-one i on?)
537+
(set-LVITEM-stateMask! lv LVIS_SELECTED)
538+
(set-LVITEM-state! lv (if on? LVIS_SELECTED 0))
539+
(SendMessageW/ptr hwnd LVM_SETITEMSTATE i lv))
540+
(when (and on? (not single?) (not one?))
541+
(for ([i (in-list (get-selections))])
542+
(set-one i #f)))
543+
(set-one i on?))))))
540544

541545
(define/public (set-selection i)
542546
(void (select i #t #f)))

0 commit comments

Comments
 (0)