#ifndef MAKE_ID
#define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
#endif

#ifdef _DCC
#define __inline
#endif

#include "Gui.h"
#include "GuiExtern.h"


struct ObjApp * CreateApp(void)
{
   struct ObjApp * Object;

   APTR  Main_Group, User_Name_StringLabel, Serial_Number_StringLabel;
   static const struct Hook Make_KeyFileHook = { { NULL,NULL },(VOID *)Make_KeyFile,NULL,NULL };


   if (!(Object = AllocVec(sizeof(struct ObjApp), MEMF_PUBLIC|MEMF_CLEAR)))
      return(NULL);

   User_Name_StringLabel = StringObject,
      MUIA_FramePhantomHoriz, TRUE,
      MUIA_Frame, MUIV_Frame_String,
      MUIA_String_Contents, "User Name:",
      MUIA_String_Format, MUIV_String_Format_Right,
   End;

   Object->User_Name_String = StringObject,
      MUIA_Frame, MUIV_Frame_String,
      MUIA_String_Format, MUIV_String_Format_Right,
   End;

   Serial_Number_StringLabel = StringObject,
      MUIA_FramePhantomHoriz, TRUE,
      MUIA_Frame, MUIV_Frame_String,
      MUIA_String_Contents, "Serial Number:",
      MUIA_String_Accept, "-0123456789",
      MUIA_String_Format, MUIV_String_Format_Right,
   End;

   Object->Serial_Number_String = StringObject,
      MUIA_Frame, MUIV_Frame_String,
      MUIA_String_Accept, "-0123456789",
      MUIA_String_Format, MUIV_String_Format_Right,
   End;

   Object->Layout_Group = GroupObject,
      MUIA_Frame, MUIV_Frame_Group,
      MUIA_Group_Columns, 2,
      Child, User_Name_StringLabel,
      Child, Object->User_Name_String,
      Child, Serial_Number_StringLabel,
      Child, Object->Serial_Number_String,
   End;

   Object->Make_Key = SimpleButton("Make KeyFile");

   Main_Group = GroupObject,
      Child, Object->Layout_Group,
      Child, Object->Make_Key,
   End;

   Object->Main_Window = WindowObject,
      MUIA_Window_Title, "DASMod KeyFile Maker",
      MUIA_Window_ID, MAKE_ID('0', 'W', 'I', 'N'),
      MUIA_Window_NoMenus, TRUE,
      WindowContents, Main_Group,
   End;

   Object->App = ApplicationObject,
      MUIA_Application_Author, "CRAY",
      MUIA_Application_Base, "KeyFileMaker",
      MUIA_Application_Title, "DAS KeyFiler",
      MUIA_Application_Version, "$VER: KeyFile 01.01 (20.05.96)",
      MUIA_Application_Copyright, "Access International",
      MUIA_Application_Description, "A KeyFile Maker For DAS ModPlayer",

      SubWindow, Object->Main_Window,
   End;


   if (!Object->App)
   {
      FreeVec(Object);
      return(NULL);
   }

   DoMethod(Object->Main_Window,
      MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
      Object->App,
      2,
      MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
      );

   DoMethod(Object->Make_Key,
      MUIM_Notify, MUIA_Pressed, FALSE,
      Object->Main_Window,
      2,
      MUIM_CallHook, &Make_KeyFileHook
      );

   DoMethod(Object->Main_Window,
      MUIM_Window_SetCycleChain, Object->Layout_Group,
      Object->User_Name_String,
      Object->Serial_Number_String,
      Object->Make_Key,
      0
      );

   set(Object->Main_Window,
      MUIA_Window_Open, TRUE
      );


   return(Object);
}

void DisposeApp(struct ObjApp * Object)
{
   MUI_DisposeObject(Object->App);
   FreeVec(Object);
}
