|
162 | 162 | ;; .... |
163 | 163 | )) |
164 | 164 |
|
| 165 | +(define suppress-callback (make-parameter #f)) |
| 166 | + |
165 | 167 | ;; ------------------------------------------------------------ |
166 | 168 |
|
167 | 169 | (define list-box% |
|
282 | 284 |
|
283 | 285 | (define pending-changed (box #f)) |
284 | 286 | (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)])))))))) |
306 | 309 |
|
307 | 310 | (define/override (do-command-ex cmd control-hwnd nmhdr) |
308 | 311 | (if (and (not single-column?) |
|
520 | 523 | (not (zero? (SendMessageW hwnd LVM_GETITEMSTATE i LVIS_SELECTED))))) |
521 | 524 |
|
522 | 525 | (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?)))))) |
540 | 544 |
|
541 | 545 | (define/public (set-selection i) |
542 | 546 | (void (select i #t #f))) |
|
0 commit comments