
;; Copyright (C) 2016, 2021  Tommi Höynälänmaa

;; This file is part of Theme-D-Intr.

;; You can redistribute and/or modify this file under the terms of the
;; GNU General Public License as published by the Free Software
;; Foundation, either version 3 of the License, or (at your option) any
;; later version.

;; This file is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see https://www.gnu.org/licenses/.


(define-body (intr-gtk4-examples theme-d-intr-demo button-box)

  (import (standard-library list-utilities)
	  (standard-library object-string-conversion)
	  (intr-gtk4-examples theme-d-intr-demo _intr-imports)
	  (intr-gtk4-examples theme-d-intr-demo support))

  (define-simple-method create-button-box
      (((horiz? <boolean>) (str-title <string>) (i-spacing <integer>)
	(s-layout <symbol>))
       <gtk-frame>
       nonpure)
    (let ((frame (cast <gtk-frame> (gtk-frame-new str-title)))
	  (buttonbox (cast <gtk-box>
			   (if horiz?
			       (gtk-box-new 'horizontal i-spacing)
			       (gtk-box-new 'vertical i-spacing)))))
      ;; (set-layout buttonbox s-layout)
      ;; (set-spacing buttonbox i-spacing)
      ;; (set-border-width buttonbox 5)

      (add frame buttonbox)

      (for-each1 (lambda (((s <symbol>)) <none> nonpure)
		   (add buttonbox
			(gtk-button-new-from-stock
			 (symbol->string s))))
		 '(ok cancel help))

      frame))

  (define-simple-method run-button-box-demo (((window-parent <gtk-window>))
					     <none> nonpure)

    (let ((window (cast <gtk-window> (gtk-window-new 'toplevel)))
	  (vbox-main (cast <gtk-box> (gtk-box-new 'vertical 0)))
	  (frame-horiz
	   (cast <gtk-frame> (gtk-frame-new "Horizontal Button Boxes")))
	  (vbox (cast <gtk-box> (gtk-box-new 'vertical 0)))
	  (frame-vert
	   (cast <gtk-frame> (gtk-frame-new "Vertical Button Boxes")))
	  (hbox (cast <gtk-box> (gtk-box-new 'horizontal 0))))
      (set-title window "Button Boxes")
      (set-border-width window 10)
      (set-border-width vbox 10)
      (set-border-width hbox 10)

      (add window vbox-main)

      (pack-start vbox-main frame-horiz #t #t 10)
      (add frame-horiz vbox)
      (pack-start vbox
		  (create-button-box #t "Spread" 40 'spread)
		  #t #t 0)
      (pack-start vbox
		  (create-button-box #t "Edge" 40 'edge)
		  #t #t 5)
      (pack-start vbox
		  (create-button-box #t "Start" 40 'start)
		  #t #t 5)
      (pack-start vbox
		  (create-button-box #t "End" 40 'end)
		  #t #t 5)

      (pack-start vbox-main frame-vert #t #t 10)
      (add frame-vert hbox)
      (pack-start hbox
		  (create-button-box #f "Spread" 30 'spread)
		  #t #t 0)
      (pack-start hbox
		  (create-button-box #f "Edge" 30 'edge)
		  #t #t 5)
      (pack-start hbox
		  (create-button-box #f "Start" 30 'start)
		  #t #t 5)
      (pack-start hbox
		  (create-button-box #f "End" 30 'end)
		  #t #t 5)

      (set-modal window #t)
      (set-transient-for window window-parent)

      (show-all window)))


  (define-simple-method get-button-box-demo (() <demo> force-pure)
    (let* ((str-name "Button Boxes")
	   (str-module-name "button-box")
	   (str-desc
	    "The Button Box widgets are used to arrange buttons with padding.")
	   (demo (create <demo> str-name str-module-name str-desc "" ""
		       run-button-box-demo)))
      (demo-compute-source demo)
      demo)))
