/* Libraries */
#include <libraries/mui.h>

/* protos */
#include <clib/muimaster_protos.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>

/*  Pragmas  */
#include <pragmas/muimaster_pragmas.h>
#include <pragmas/exec_pragmas.h>

/*  Ansi  */
#include <stdlib.h>
#include <stdio.h>

/* MUIBuilder */
#include "Click.h"

/* defines */
#define	ID_1ST	1
#define	ID_2ND	2
#define	ID_3RD	3

struct Library * MUIMasterBase;

/* Init function */
static void init( void )
{
	if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
	{
		printf("Can't Open MUIMaster Library");
		exit(20);
	}
}

/* main function */
main()
{
	struct ObjApp * App = NULL;	/* Application object */
	char	*STR_Message1 = "\0338\033c You pressed first button";
	char    *STR_Message2 = "\0338\033c You pressed second button";
	char    *STR_Message3 = "\0338\033c You pressed third button";
	BOOL	running = TRUE;
	ULONG	signal;
	extern struct ObjApp * CreateSmall_Example( void );

	/* Program initialisation ( you need to write it yourself) */
	init();

	/* Create Application : generated by MUIBuilder */
	App = CreateApp();

	/* Notification */
	DoMethod(App->WI_try, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, App->App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
	DoMethod( App->BT_1stbutton, MUIM_Notify, MUIA_Pressed, FALSE, App->App, 2, MUIM_Application_ReturnID, ID_1ST);
	DoMethod( App->BT_2ndbutton, MUIM_Notify, MUIA_Pressed, FALSE, App->App, 2, MUIM_Application_ReturnID, ID_2ND);
	DoMethod( App->BT_3rdbutton, MUIM_Notify, MUIA_Pressed, FALSE, App->App, 2, MUIM_Application_ReturnID, ID_3RD);
	
	/* Open Window */
	set( App->WI_try, MUIA_Window_Open, TRUE );

	while (running)
        {
                switch (DoMethod(App->App,MUIM_Application_Input,&signal))
                {
		case ID_1ST:
			set( App->TX_label_0, MUIA_Text_Contents, STR_Message1);
			break;
		case ID_2ND:
			set( App->TX_label_0, MUIA_Text_Contents, STR_Message2);
			break;
		case ID_3RD:
			set( App->TX_label_0, MUIA_Text_Contents, STR_Message3);
			break;
                case MUIV_Application_ReturnID_Quit:
                        running = FALSE;
                        break;
                }
	if (running && signal) Wait(signal);
        }
	DisposeApp(App);
	CloseLibrary(MUIMasterBase);
	exit(0);
}
