;** The ShowHide demo shows how to hide and show objects.
;Based on the example ShowHide.c by Stefan Stuntz
;Adapted in Blitz Basic 2 by Erwan Fouret

INCDIR "MUI:Developer/BB2/Include/"
INCLUDE mui.bb2

#SIGBREAKF_CTRL_C=(1 LSL 12)

NEWTYPE.tags a.l:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z:End NEWTYPE

DEFTYPE.b *app,*win,*cm1,*cm2,*cm3,*cm4,*cm5,*bt1,*bt2,*bt3,*bt4,*bt5;
DEFTYPE.tags atags,wtags,vgt1,vgt2,hgt1,hgt2

*cm1 = CheckMark(MUI_TRUE)
*cm2 = CheckMark(MUI_TRUE)
*cm3 = CheckMark(MUI_TRUE)
*cm4 = CheckMark(MUI_TRUE)
*cm5 = CheckMark(MUI_TRUE)

*bt1 = SimpleButton("Button 1")
*bt2 = SimpleButton("Button 2")
*bt3 = SimpleButton("Button 3")
*bt4 = SimpleButton("Button 4")
*bt5 = SimpleButton("Button 5")

Dim t$(6),*tp(6)

t$(0)="ShowHide"
t$(1)="$VER: ShowHide 19.5 (12.02.97)"
t$(2)=Chr$(167)+"1992/93, Stefan Stuntz"
t$(3)="Stefan Stuntz"
t$(4)="Show object hiding."
t$(5)="SHOWHIDE"
t$(6)="Show & Hide"

For i=0 To 6
 t$(i)=t$(i)+Chr$(0)
 *tp(i)=&t$(i)
Next

vgt2\a=#Child,*bt1,#Child,*bt2,#Child,*bt3,#Child,*bt4,#Child,*bt5,#Child,MUI_MakeObjectA_(#MUIO_VSpace,0),0

hgt2\a=#MUIA_Group_Horiz,MUI_TRUE,#MUIA_Weight,0,#Child,*cm1,#Child,*cm2,#Child,*cm3,#Child,*cm4,#Child,*cm5,0

vgt1\a=#MUIA_Frame,#MUIV_Frame_Group,#Child,MUI_NewObjectA_("Group.mui",hgt2)
vgt1\e=#Child,MUI_NewObjectA_("Group.mui",vgt2),0

hgt1\a=#MUIA_Group_Horiz,MUI_TRUE,#Child,MUI_NewObjectA_("Group.mui",vgt1),0

wtags\a=#MUIA_Window_Title, *tp(6)
wtags\c=#MUIA_Window_ID   , $53484844   ;="SHHD"
wtags\e=#WindowContents, MUI_NewObjectA_("Group.mui",hgt1),0

*win=MUI_NewObjectA_("Window.mui",wtags)

atags\a=#MUIA_Application_Title      , *tp(0)
atags\c=#MUIA_Application_Version    , *tp(1)
atags\e=#MUIA_Application_Copyright  , *tp(2)
atags\g=#MUIA_Application_Author     , *tp(3)
atags\i=#MUIA_Application_Description, *tp(4)
atags\k=#MUIA_Application_Base       , *tp(5)
atags\m=#SubWindow, *win, 0

*app = MUI_NewObjectA_("Application.mui",atags)

If *app=0
 End
EndIf


;** Install notification events...

DoMethod *win,#MUIM_Notify,#MUIA_Window_CloseRequest,MUI_TRUE,*app,2,#MUIM_Application_ReturnID,#MUIV_Application_ReturnID_Quit

DoMethod *cm1,#MUIM_Notify,#MUIA_Selected,#MUIV_EveryTime,*bt1,3,#MUIM_Set,#MUIA_ShowMe,#MUIV_TriggerValue
DoMethod *cm2,#MUIM_Notify,#MUIA_Selected,#MUIV_EveryTime,*bt2,3,#MUIM_Set,#MUIA_ShowMe,#MUIV_TriggerValue
DoMethod *cm3,#MUIM_Notify,#MUIA_Selected,#MUIV_EveryTime,*bt3,3,#MUIM_Set,#MUIA_ShowMe,#MUIV_TriggerValue
DoMethod *cm4,#MUIM_Notify,#MUIA_Selected,#MUIV_EveryTime,*bt4,3,#MUIM_Set,#MUIA_ShowMe,#MUIV_TriggerValue
DoMethod *cm5,#MUIM_Notify,#MUIA_Selected,#MUIV_EveryTime,*bt5,3,#MUIM_Set,#MUIA_ShowMe,#MUIV_TriggerValue

MUI_set *cm3,#MUIA_Selected,False

;** This is the ideal input loop for an object oriented MUI application.
;** Everything is encapsulated in classes, no return ids need to be used,
;** we just check if the program shall terminate.
;** Note that MUIM_Application_NewInput expects sigs to contain the result
;** from Wait() (or 0). This makes the input loop significantly faster.

MUI_set *win,#MUIA_Window_Open,MUI_TRUE

                sigs.l = 0

                While DoMethod(*app,#MUIM_Application_NewInput,&sigs) <> #MUIV_Application_ReturnID_Quit

                        If (sigs)

                                sigs = Wait_(sigs | #SIGBREAKF_CTRL_C)
                                If (sigs AND #SIGBREAKF_CTRL_C)
                                 Pop While:Goto finish
                                EndIf
                        EndIf
                Wend

finish:
        MUI_set *win,#MUIA_Window_Open,False


;** Shut down...

MUI_DisposeObject_ *app

End
