/*
** This Is Going To Be The Main GUI.. Or Should That Be MUI! ;) For The InterFace.
*/

/* MUI */
#include <libraries/mui.h>
/* System */
#include <dos/dos.h>
#include <graphics/gfxmacros.h>
#include <workbench/workbench.h>
/* Prototypes */
#include <clib/alib_protos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/icon_protos.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/utility_protos.h>
#include <clib/asl_protos.h>
#include <clib/muimaster_protos.h>
/* ANSI C */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/* LIBRARYS */
#include <pragmas/exec_sysbase_pragmas.h>
#include <pragmas/muimaster_pragmas.h>

struct Library *MUIMasterBase;			// For The MUI Library
extern struct Library *SysBase;
#define ID_CANCEL 1
#define ID_SAVE   0
#define ID_USE    2
#define ID_TASKS  4

APTR  	Main_Object,
        Main_Window,
        ListView_Object,
        Task_Address,
        Window_Address,
        Ports_Address,
        Vector_Address,
	Semaphores_Address,
        Universal_1,
        Universal_2,
        Universal_3,
        Universal_4,
        Universal_5,
        Universal_6;


/* ProtoTypes In This File */

void Open_Librarys( void );      /* Open Up The Current Version Of The MUI Master Library */
void Shut_Down(APTR ,char *);	 /* Shut Down The Current Application Because of Failure  */
int  Start_GUI( void );          /* Start The Graphical User Interface Run By MUI.        */
void Input_Handler( void );

int Start_GUI( void )
{
                   
   Open_Librarys();               
   Main_Object = ApplicationObject,
                  MUIA_Application_Title      , "Dizzer II",
                  MUIA_Application_Version    , "$VER: Settings 1.3 (20.04.95)",
                  MUIA_Application_Copyright  , "1995/96, Cray - 1",
                  MUIA_Application_Author     , "A((eSS",
                  MUIA_Application_Description, "Extracts And Uses File_ID.Diz's.",
                  MUIA_Application_Base       , "CRAY", 
                   SubWindow, Main_Window = WindowObject,
                    MUIA_Window_Title      , "Cray-1's Control",
                    MUIA_Window_ID         , "CRAY",                            
                     WindowContents, VGroup,GroupFrameT("Main Display"),
                        Child, HGroup,
                           Child, ListviewObject,
                               MUIA_Listview_Input,TRUE,
                               MUIA_Listview_List , ListView_Object = ListObject,
      		               InputListFrame,                                                                        
                               MUIA_Group_SameWidth, TRUE,
                               MUIA_Listview_Input, FALSE,
           		       MUIA_List_AdjustWidth, TRUE,
                               MUIA_List_Title, "Address    Task Name       SigAlloc  SigWait  Priority",
      			      End,
                         End,   
                                                                               
                        Child, VGroup,GroupFrameT("Functions"),
                           MUIA_Weight, 2,
                            Child, Task_Address       = SimpleButton("Tasks"),                   
                            Child, Vector_Address    = SimpleButton("Vectors"),         
                            Child, Window_Address    = SimpleButton("Windows"),
                            Child, Ports_Address      = SimpleButton("Ports"),
                            Child, Semaphores_Address = SimpleButton("Semaphores"),
                           End,
                         End,

                        Child, HGroup,GroupFrameT("Operations"),
                           MUIA_Weight, 2,
                            Child, Universal_1 = SimpleButton("Clear"),
                            Child, Universal_2 = SimpleButton("Change"),
                            Child, Universal_3 = SimpleButton("Restore"),
                            Child, Universal_4 = SimpleButton(""),
                            Child, Universal_5 = SimpleButton(""),
                            Child, Universal_6 = SimpleButton(""),
                           End,
                         End,                             
                    End,                                
                  End;
                                                                                      
                  if(!Main_Object) Shut_Down(Main_Object,"Problem Starting Up Application.");
                  if(!Main_Window) Shut_Down(Main_Window,"Problem With The Window.");                   
                         
                SetAttrs(Main_Window,MUIA_Window_Open,TRUE,TAG_DONE);  /* Open The Window */


   DoMethod(Task_Address,MUIM_Notify,				/* Tell Task Address Button to Inform You */
            MUIA_Pressed,FALSE,Main_Object,2,
              MUIM_Application_ReturnID,ID_TASKS  );         

   DoMethod(ListView_Object,MUIM_List_InsertSingle,		/* Inform List That It Has New Member */
                     "foobar",MUIV_List_Insert_Bottom);       

   DoMethod(Main_Window,MUIM_Notify,				/* Tell CloseWindow To Inform You */
             MUIA_Window_CloseRequest,TRUE,Main_Object,2,
                       MUIM_Application_ReturnID,ID_CANCEL);

  return(TRUE);
}





void Input_Handler( void )
{
  ULONG signals;
  BOOL running = TRUE;
   while (running)
      {
          switch (DoMethod(Main_Object,MUIM_Application_Input,&signals))
              {
                  case MUIV_Application_ReturnID_Quit:
                          running = FALSE;
                         break;
                        
                  case ID_CANCEL:
                          running = FALSE;
                         break;
 
                  case ID_SAVE:
                         break;
                        /* fall through */

                  case ID_USE:
                          running = FALSE;
                         break;
                        
                  case ID_TASKS:
                          printf("Hello... Lets Have Some Tasks Then\n");
                         break;
              }
        if (running && signals) Wait(signals);
      }                 
           
                 
                 
		Shut_Down(Main_Object,NULL);
}




void Open_Librarys( void )
{
 
         if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
              Shut_Down(NULL,"Failed to open "MUIMASTER_NAME"."); 
}
 
 
 
void Shut_Down(APTR app,char *str)
{
        if (app)
                MUI_DisposeObject(app);
       if (MUIMasterBase)
              CloseLibrary(MUIMasterBase);
        if (str)
            {
                puts(str);
                exit(20);
            }
        exit(0);
}
