/*
** $Id: Demo.c,v 1.5 1999/08/05 16:56:11 wiz Exp $
*/

/// Include
#include <exec/types.h>             //  exec
#include <exec/libraries.h>
#include <exec/memory.h>
#include <dos/dos.h>                //  dos
#include <libraries/mui.h>          //  libraries
#include <clib/muimaster_protos.h>  //  clib
#include <clib/alib_protos.h>
#include <proto/exec.h>             //  proto
#include <proto/dos.h>
#include <proto/muimaster.h>

#include <string.h>
#include <stdio.h>

#include "/SpeedBar_mcc.h"
#include "MyBrush.h"
///
/// Data
struct Library *MUIMasterBase;
///


/// MakeLabel1
Object *MakeLabel1( STRPTR str )
{
    return( MUI_MakeObject( MUIO_Label, str, MUIO_Label_SingleFrame ));
}
///
/// MakeCheck
Object *MakeCheck( STRPTR str )
{
    Object *obj = MUI_MakeObject( MUIO_Checkmark, str );

    if( obj )
        set( obj, MUIA_CycleChain, TRUE );

    return( obj );
}
///
/// MakeCycle
Object *MakeCycle( STRPTR *array, STRPTR txt )
{
    Object *obj = MUI_MakeObject( MUIO_Cycle, txt, array );

    if( obj )
        set( obj, MUIA_CycleChain, TRUE );

    return( obj );
}
///


int main( int argc, char *argv[] )
{
    Object                             *AppObj, *MainWin, *SpeedBar;
    Object                             *viewmode, *borderless, *raising, *small, *sunny;
    static struct MUIS_SpeedBar_Button  buttons[] = {
                                            { 0, "Toggle",    "Toggle mode example",      MUIV_SpeedBar_ButtonFlag_Toggle,    NULL },
                                            { 1, "Immediate", "Immediate mode example",   MUIV_SpeedBar_ButtonFlag_Immediate, NULL },
                                            { MUIV_SpeedBar_Spacer },
                                            { 2, "Quit",      "This will quit the program", 0, NULL },
                                            { 2, "Disabled",  "This does nothing at all",   MUIV_SpeedBar_ButtonFlag_Disabled, NULL },
                                            { MUIV_SpeedBar_End },
                                        };
    static STRPTR                       Modes[] = {
                                            "Text + Graphics",
                                            "Graphics only",
                                            "Text only",
                                            NULL
                                        };
    static STRPTR                       Files[] = {
                                            "Pic1.iff",
                                            "Pic2.iff",
                                            "Pic3.iff",
                                            "Spacer.iff"
                                        };
    ULONG                               i;
    struct MyBrush                     *Brushes[4] = { 0 };

    if(!( MUIMasterBase = OpenLibrary( "muimaster.library", 19 )))
        return( 20 );

    for( i = 0; i < 4; i++ )
        Brushes[ i ] = LoadBrush( Files[ i ]);

    if( AppObj = ApplicationObject,

                        MUIA_Application_Title,         "SpeedBar Test",
                        MUIA_Application_Version,       "$VER: SpeedBarTest 1.0 (31.7.99)",
                        MUIA_Application_Copyright,     "Copyright ©1999 by Simone Tellini",
                        MUIA_Application_Author,        "Simone Tellini <wiz@vapor.com>",
                        MUIA_Application_Description,   "Speed(Bar|Button).mcc test program",
                        MUIA_Application_Base,          "SPEEDBARTEST",

                        SubWindow, MainWin = WindowObject,

                            MUIA_Window_ID,             MAKE_ID( 'M', 'A', 'I', 'N' ),
                            MUIA_Window_Title,          "SpeedBarTest - ©1999 Simone Tellini",

                            WindowContents, VGroup,

                                Child, HGroup,

                                    Child, SpeedBar = SpeedBarObject,
                                        MUIA_Group_Horiz,           TRUE,
                                        MUIA_SpeedBar_Images,       Brushes,
                                        MUIA_SpeedBar_Borderless,   FALSE,
                                        MUIA_SpeedBar_ViewMode,     MUIV_SpeedBar_ViewMode_TextGfx,
                                        MUIA_SpeedBar_RaisingFrame, FALSE,
                                        MUIA_SpeedBar_Buttons,      buttons,
                                        MUIA_SpeedBar_SpacerIndex,  3, // -1,
                                        MUIA_SpeedBar_Spread,       FALSE, //TRUE,
                                    End,

                                    Child, HSpace( 0 ),
                                End,

                                Child, ColGroup( 2 ),

                                    Child, MakeLabel1( "_Borderless" ),
                                    Child, HGroup,
                                        Child, borderless = MakeCheck( "_Borderless" ),
                                        Child, HSpace( 0 ),
                                    End,

                                    Child, MakeLabel1( "_Raising frames" ),
                                    Child, HGroup,
                                        Child, raising = MakeCheck( "_Raising frames" ),
                                        Child, HSpace( 0 ),
                                    End,

                                    Child, MakeLabel1( "_View Mode" ),
                                    Child, HGroup,
                                        Child, viewmode = MakeCycle( Modes, "_View Mode" ),
                                        Child, HSpace( 0 ),
                                    End,

                                    Child, MakeLabel1( "Small _images" ),
                                    Child, HGroup,
                                        Child, small = MakeCheck( "Small _images" ),
                                        Child, HSpace( 0 ),
                                    End,

                                    Child, MakeLabel1( "_Sunny" ),
                                    Child, HGroup,
                                        Child, sunny = MakeCheck( "_Sunny" ),
                                        Child, HSpace( 0 ),
                                    End,
                                End,
                            End,
                        End,
                   End ) {
        ULONG   sigs = 0;

        DoMethod( MainWin, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Application, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit );

        DoMethod( buttons[ 0 ].Object, MUIM_Notify, MUIA_Selected, FALSE, SpeedBar, 5, MUIM_SpeedBar_DoOnButton, 1, MUIM_Set, MUIA_Selected, FALSE );
        DoMethod( buttons[ 3 ].Object, MUIM_Notify, MUIA_Pressed, FALSE, AppObj, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit );

        DoMethod( borderless, MUIM_Notify, MUIA_Selected,     MUIV_EveryTime, SpeedBar, 3, MUIM_Set, MUIA_SpeedBar_Borderless,   MUIV_TriggerValue );
        DoMethod( raising,    MUIM_Notify, MUIA_Selected,     MUIV_EveryTime, SpeedBar, 3, MUIM_Set, MUIA_SpeedBar_RaisingFrame, MUIV_TriggerValue );
        DoMethod( viewmode,   MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, SpeedBar, 3, MUIM_Set, MUIA_SpeedBar_ViewMode,     MUIV_TriggerValue );
        DoMethod( small,      MUIM_Notify, MUIA_Selected,     MUIV_EveryTime, SpeedBar, 3, MUIM_Set, MUIA_SpeedBar_SmallImages,  MUIV_TriggerValue );
        DoMethod( sunny,      MUIM_Notify, MUIA_Selected,     MUIV_EveryTime, SpeedBar, 3, MUIM_Set, MUIA_SpeedBar_Sunny,        MUIV_TriggerValue );

        set( MainWin, MUIA_Window_Open, TRUE );

        while( DoMethod( AppObj, MUIM_Application_NewInput, &sigs ) != MUIV_Application_ReturnID_Quit ) {
            if( sigs ) {

                sigs = Wait( sigs | SIGBREAKF_CTRL_C );

                if( sigs & SIGBREAKF_CTRL_C )
                    break;
            }
        }

        MUI_DisposeObject( AppObj );
    }

    for( i = 0; i < 4; i++ )
        FreeBrush( Brushes[ i ]);

    CloseLibrary( MUIMasterBase );

    return( 0 );
}
