<commit_before>#lang racket/base
(require racket/class
         racket/draw
         ffi/unsafe
         "../../syntax.rkt"
         "../../lock.rkt"
         "../common/event.rkt"
         "item.rkt"
	 "utils.rkt"
	 "const.rkt"
	 "window.rkt"
	 "wndclass.rkt"
         "hbitmap.rkt"
         "types.rkt")

(provide
 (protect-out radio-box%))

(define SEP 4)
(define BM_SETCHECK #x00F1)

(define radio-box% 
  (class item%
    (init parent cb label
          x y w h
          labels
          val
          style
          font)

    (inherit auto-size set-control-font
             is-enabled-to-root?
             set-focus)

    (define callback cb)
    (define current-value val)

    (define hwnd
      (CreateWindowExW 0
                       "PLTTabPanel"
                       #f
                       (bitwise-ior WS_CHILD)
                       0 0 w h
                       (send parent get-client-hwnd)
                       #f
                       hInstance
                       #f))

    (define label-bitmaps null)

    (define radio-hwnds
      (let loop ([y 0] [w 0] [labels labels])
        (if (null? labels)
            (begin
              (MoveWindow hwnd 0 0 w y #t)
              null)
            (let* ([label (car labels)]
                   [bitmap? (label . is-a? . bitmap%)]
                   [radio-hwnd 
                    (CreateWindowExW/control 0
                                             "PLTBUTTON"
                                             (if (string? label)
                                                 label
                                                 "<image>")
                                             (bitwise-ior BS_RADIOBUTTON WS_CHILD WS_CLIPSIBLINGS
                                                          (if bitmap?
                                                              BS_BITMAP
                                                              0))
                                             0 0 0 0
                                             hwnd
                                             #f
                                             hInstance
                                             #f)])
              (when bitmap?
                (let ([hbitmap (bitmap->hbitmap label)])
                  (set! label-bitmaps (cons hbitmap label-bitmaps))
                  (SendMessageW radio-hwnd BM_SETIMAGE IMAGE_BITMAP 
                                (cast hbitmap _HBITMAP _LPARAM))))
              (ShowWindow radio-hwnd SW_SHOW)
              (set-control-font font radio-hwnd)
              (let-values ([(w1 h) 
                            (auto-size font label 0 0 20 4
                                       (lambda (w h)
                                         (MoveWindow radio-hwnd 0 (+ y SEP) w h #t)
                                         (values w h)))])
                (cons radio-hwnd
                      (loop (+ y SEP h) (max w1 w) (cdr labels))))))))

    (unless (= val -1)
      (SendMessageW (list-ref radio-hwnds val) BM_SETCHECK 1 0))
    
    (super-new [callback cb]
               [parent parent]<commit_msg>win32: fix horizontal `radio-box%'  Merge to 5.1<commit_after>#lang racket/base
(require racket/class
         racket/draw
         ffi/unsafe
         "../../syntax.rkt"
         "../../lock.rkt"
         "../common/event.rkt"
         "item.rkt"
	 "utils.rkt"
	 "const.rkt"
	 "window.rkt"
	 "wndclass.rkt"
         "hbitmap.rkt"
         "types.rkt")

(provide
 (protect-out radio-box%))

(define SEP 4)
(define BM_SETCHECK #x00F1)

(define radio-box% 
  (class item%
    (init parent cb label
          x y w h
          labels
          val
          style
          font)

    (inherit auto-size set-control-font
             is-enabled-to-root?
             set-focus)

    (define callback cb)
    (define current-value val)

    (define hwnd
      (CreateWindowExW 0
                       "PLTTabPanel"
                       #f
                       (bitwise-ior WS_CHILD)
                       0 0 w h
                       (send parent get-client-hwnd)
                       #f
                       hInstance
                       #f))

    (define label-bitmaps null)

    (define radio-hwnds
      (let ([horiz? (memq 'horizontal style)])
        (let loop ([y 0] [w 0] [labels labels])
          (if (null? labels)
              (begin
                (MoveWindow hwnd 0 0 w y #t)
                null)
              (let* ([label (car labels)]
                     [bitmap? (label . is-a? . bitmap%)]
                     [radio-hwnd 
                      (CreateWindowExW/control 0
                                               "PLTBUTTON"
                                               (if (string? label)
                                                   label
                                                   "<image>")
                                               (bitwise-ior BS_RADIOBUTTON WS_CHILD WS_CLIPSIBLINGS
                                                            (if bitmap?
                                                                BS_BITMAP
                                                                0))
                                               0 0 0 0
                                               hwnd
                                               #f
                                               hInstance
                                               #f)])
                (when bitmap?
                  (let ([hbitmap (bitmap->hbitmap label)])
                    (set! label-bitmaps (cons hbitmap label-bitmaps))
                    (SendMessageW radio-hwnd BM_SETIMAGE IMAGE_BITMAP 
                                  (cast hbitmap _HBITMAP _LPARAM))))
                (ShowWindow radio-hwnd SW_SHOW)
                (set-control-font font radio-hwnd)
                (let-values ([(w1 h) 
                              (auto-size font label 0 0 20 4
                                         (lambda (w1 h1)
                                           (if horiz?
                                               (MoveWindow radio-hwnd (+ w SEP) 0 w1 h1 #t)
                                               (MoveWindow radio-hwnd 0 (+ y SEP) w1 h1 #t))
                                           (values w1 h1)))])
                  (cons radio-hwnd
                        (loop (if horiz? (max y h) (+ y SEP h))
                              (if horiz? (+ w SEP w1) (max w1 w))
                              (cdr labels)))))))))

    (unless (= val -1)
      (SendMessageW (list-ref radio-hwnds val) BM_SETCHECK 1 0))
    
    (super-new [callback cb]
               [parent parent]
{'fraction_non_alphanumeric': 0.08439133681852129, 'fraction_numerical': 0.010455563853622106, 'mean_word_length': 0.7392207792207792, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 69, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '242934', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1589, 'n_words': 436}