#!/usr/local/bin/wwlisp
(use "kdialog")
(defclass dialog1(kdialog))
(defun dialog1-callback(widget msg msgvalue)
    (prog(dlg2)
        (cond((= widget 0)
                (princ "dialog own message: ")
                (print msg)
                (cond((= msg 'dismiss)(return))
                    ((= msg 'ok)
                        (setcurrent this 8 0)
                        (setvalue this 9 0)
                        (setvalue this 13 50)
                        )
                    )
                )
            ((= widget 1)
                (princ "button 1 has been clicked =")
                (print(getvalue this 6))
                )
            ((= widget 2)
                (princ "button 2 has been clicked =")
                (print(getlist this 7))
                )
            ((= widget 3)
                (princ "button 3 has been clicked =")
                (print(getcurrent this 7))
                )
            ((= widget 4)
                (princ "button 4 has been clicked, dialog will be dismissed")
                (terpri)
                (dismiss this)
                )
            ((= widget 8)
                (princ "radio button has been changed")
                (terpri)
                (print(getcurrent this 8))
                (print(list widget msg msgvalue))
                )
            ((= widget 9)
                (princ "checkbox 9 has been changed:")
                (terpri)
                (print(getvalue this 9))
                (print(list widget msg msgvalue))
                )
            ((= widget 10)
                (princ "checkbox 10 has been changed:")
                (terpri)
                (print(getvalue this 10))
                (print(list widget msg msgvalue))
                )
            ((= widget 11)
                (princ "checkbox 11 has been changed:")
                (terpri)
                (print(getvalue this 11))
                (print(list widget msg msgvalue))
                )
            ((= widget 12)
                (princ "button 12 has been clicked; report:")
                (terpri)
                (princ "status check box 1 =")
                (print(getvalue this 9))
                (princ "status check box 2 =")
                (print(getvalue this 10))
                (princ "status check box 3 =")
                (print(getvalue this 11))
                (princ "position spinedit =")
                (print(getvalue this 13))
                (princ "position hscrollbar =")
                (print(getvalue this 14))
                (princ "position vscrollbar =")
                (print(getvalue this 15))
                )
            ((= widget 18)
                (princ "combo box has given a message")
                (terpri)
                (print(list widget msg msgvalue))
                (cond((= msg 'selected)
                        (prog(name wk)
                            (setq name(nth(1+ msgvalue)(getprop this 'biglist)))
                            (setq wk(mapcar '(lambda fexpr(zz)(prin1-to-string(car zz)))
                                    (plist name)
                                    )
                                )
                            (setlist this 21 wk)
                            )
                        )
                    )
                )
            ((= widget 19)(print(list widget msg msgvalue)))
            ((= widget 22)(dialogtest))
            ((= widget 23)
                (princ "other dialog called")
                (terpri)
                (setq dlg2(make-instance dialog2))
                (display dlg2)
                (destroy-instance dlg2)
                )
            ((= widget 24)
                (princ "LED dialog called")
                (terpri)
                (setq dlg3(make-instance dialog3))
                (display dlg3)
                (destroy-instance dlg3)
                )
            )
        )
    )
(defun dialog1-constructor(x y)
    (prog(wk BIGLIST)
        (kdialog-constructor x y 500 350 "wwlispkdialog Demo Dialog")
        (addbutton this 1 220 10 70 25 "Get Edit")
        (addbutton this 2 220 40 70 25 "Get List")
        (addbutton this 3 220 70 70 25 "Current")
        (addbutton this 4 220 100 70 25 "Cancel")
        (addlabel this 5 10 10 190 18 'text "Enter the data here:")
        (addedit this 6 10 30 190 22 "example")
        (setq wk(mapcar '(lambda fexpr(zz)(string(car zz)))(backtrace))
            )
        (addlistboxmulti this 7 10 60 190 130 wk)
        (addradiobuttongroup this 8 220 130 70 70 '("user" "system" "kernel")
            )
        (addgroupbox this 24 10 195 190 100 "Check Group")
        (addcheckbox this 9 25 210 70 25 "user" t)
        (addcheckbox this 10 25 235 70 25 "system")
        (addcheckbox this 11 25 260 70 25 "kernel")
        (addbutton this 12 100 220 70 25 "Get Check")
        (addspinedit this 13 100 260 50 22 0 100 1 33)
        (addhscrollbar this 14 220 310 260 17 0 150 1 10 75)
        (addvscrollbar this 15 480 10 17 260 0 150 1 10 75)
        (addhslider this 16 220 280 260 17 0 150 1 75)
        (addvslider this 17 450 10 17 260 0 150 1 75)
        (setq BIGLIST(sort(listdata)))
        (setq wk(mapcar '(lambda fexpr(zz)(string(car zz))) BIGLIST)
            )
        (addcombobox this 18 300 10 135 22 wk)
        (adddial this 19 300 40 70 70 0 150 1 75)
        (addvslider this 20 220 220 30 50 0 50 1 25)
        (setq wk(mapcar '(lambda fexpr(zz)(prin1-to-string(car zz)))
                (plist(car BIGLIST))
                )
            )
        (addlistview this 21 300 120 135 150 '("name" "value")
             wk)
        (addbutton this 22 380 40 50 70(concat "Other"(chr '(10))"Dialog")
            )
        (addbutton this 23 10 300 50 40(concat "Small"(chr '(10))"Dialog")
            )
        (addbutton this 24 70 300 50 40(concat "LED"(chr '(10))"Dialog")
            )
        (putprop this BIGLIST 'biglist)
        (return t)
        )
    )
(defclass dialog2(kdialog))
(defun dialog2-callback(widget msg msgvalue)
    (prog nil
        (cond((= widget 0)
                (princ "dialog2 own message: ")
                (print(cdr message))
                (cond((= msg 'dismiss)(return)))
                )
            ((= widget 1)
                (princ "button 2-1 has been clicked =")
                (print(getvalue this 5))
                )
            ((= widget 2)
                (princ "button 2-2 has been clicked")
                (terpri)
                (if(isenabled this 5)(disable this 5)(enable this 5))
                )
            ((= widget 3)
                (princ "button 2-3 has been clicked, dialog2 will be dismissed")
                (terpri)
                (dismiss this)
                )
            )
        )
    )
(defun dialog2-constructor nil
    (prog nil
        (kdialog-constructor nil nil 200 200 "Test Dialog2")
        (addbutton this 1 120 10 70 25 "OK")
        (addbutton this 2 120 50 70 25 "disable")
        (addbutton this 3 120 90 70 25 "Cancel")
        (addlabel this 4 10 10 110 17 'text "Test data:")
        (addedit this 5 10 27 100 22 "Here...")
        (return t)
        )
    )
(defclass dialog3(kdialog))
(defun dialog3-callback(widget msg msgvalue)
    (prog nil
        (cond((= widget 0)
                (princ "dialog3 own message: ")
                (print(cdr message))
                (cond((= msg 'dismiss)(return)))
                )
            ((= widget 1)
                (princ "button 3-1 has been clicked")
                (terpri)
                (dismiss this)
                )
            ((= widget 2)
                (princ "button 3-2 has been clicked")
                (terpri)
                (if(getvalue this 4)
                    (setvalue this 4 nil)
                    (setvalue this 4 t)
                    )
                )
            ((= widget 5)
                (if(getvalue this 3)
                    (setvalue this 3 nil)
                    (setvalue this 3 t)
                    )
                )
            )
        )
    )
(defun dialog3-constructor nil
    (prog nil
        (kdialog-constructor nil nil 200 200 "Test Dialog3")
        (addbutton this 1 120 10 70 25 "OK")
        (addbutton this 2 120 50 70 25 "toggle")
        (addled this 3 10 10 25 25 'on 'blue 'circular 'sunken)
        (addled this 4 10 50 25 25 'on 'red 'circular 'sunken)
        (addtimer this 5 500)
        (return t)
        )
    )
(defun dialogmini nil
    (prog(dlg result)
        (setq dlg(make-instance kdialog nil nil 310 110 "Any Value")
            )
        (addlabel dlg 1 10 7 200 17 'text "String Value:")
        (addedit dlg 2 10 25 210 22 "")
        (addbutton dlg 3 230 10 70 25 "OK")
        (addbutton dlg 4 230 40 70 25 "Cancel")
        (addbutton dlg 5 230 70 70 25 "test")
        (display dlg)
        (setq result(getvalue dlg 2))
        (destroy-instance dlg)
        (return result)
        )
    )
(defun dialogtest nil
    (prog(dlg)
        (setq dlg(make-instance dialog1 x y))
        (display dlg)
        (destroy-instance dlg)
        )
    )
(dialogtest)