/*
   *
   * $Id: interface.c,v 1.3 1998/06/03 14:02:11 Giambattista_Bloisi Exp $
   *
 */

#define INTERFACE_C

#include "common/extern.h"
#include "common/subtasksupp.h"
#include "common/Grab_mcc.h"
#include "asl.h"

#include <workbench/startup.h>
#include <clib/wb_protos.h>

#include <MUI/NListview_mcc.h>
#include <MUI/NFloattext_mcc.h>

extern struct SubTask *SpawnNetTask (char *name, BPTR func, APTR data);

/// "Images stuff"
extern const struct BitMapHeader Clear_header;
extern const UBYTE Clear_body[];
extern const ULONG Clear_colors[];

extern const struct BitMapHeader Editing_header;
extern const UBYTE Editing_body[];
extern const ULONG Editing_colors[];

extern const struct BitMapHeader Grabbing_header;
extern const UBYTE Grabbing_body[];
extern const ULONG Grabbing_colors[];

extern const struct BitMapHeader Grabbed_header;
extern const UBYTE Grabbed_body[];
extern const ULONG Grabbed_colors[];

extern const struct BitMapHeader Decoding_header;
extern const UBYTE Decoding_body[];
extern const ULONG Decoding_colors[];

extern const struct BitMapHeader Interrupted_header;
extern const UBYTE Interrupted_body[];
extern const ULONG Interrupted_colors[];

extern const struct BitMapHeader Error_header;
extern const UBYTE Error_body[];
extern const ULONG Error_colors[];
///

/*** arexx list ***/

/// "about_win"

SAVEDS (LONG)
about_win (void)
{
  APTR win = NULL;

  if (!oa->about_win)
    {
      win = AboutWinObject, End;
    }

  return ((LONG) win);
}
///

/// "Close Project function: closeproject()"
SAVEDS (LONG)
closeproject (REG (a2, Object * obj), REG (a1, LONG ** arg))
{
  struct WindowNode *wnd = NULL;

  if (oa->main_win)
    {
      get (oa->main_win, MUIA_Main_CurrentProj, &wnd);
      if (wnd)
	set (wnd->wnd_win, MUIA_Window_CloseRequest, TRUE);
    }
  return (NULL);
}
///

/// "Open project Function: openproject()"
SAVEDS (LONG)
openproject (REG (a2, Object * obj), REG (a1, LONG ** arg))
{
  DoMethod ((Object *) oa->main_win, MUIM_Main_Open, *arg, NULL, NULL);
  return (NULL);
}
///

/// "Save Project function: saveproject()"
SAVEDS (LONG)
saveproject (REG (a2, Object * obj), REG (a1, LONG ** arg))
{
  DoMethod ((Object *) oa->main_win, MUIM_Main_Save, *arg, NULL, NULL);
  return (NULL);
}
///

/// "Open Local Prefs Window: localprefs ()"
SAVEDS (LONG)
localprefs_win (REG (a2, Object * obj), REG (a1, LONG ** arg))
{
  struct WindowNode *wnd = NULL;

  if (oa->main_win)
    {
      get (oa->main_win, MUIA_Main_CurrentProj, &wnd);

      if (wnd)
	{
	  set (wnd->wnd_win, MUIA_ProjWin_Sleep, TRUE);
	  LPrefsWinObject,
	    MUIA_LPrefsWin_ProjWin, wnd->wnd_win,
	    End;
	}
    }
  return (NULL);

}
///

/// "req_msg"
SAVEDS (LONG)
req_msg (REG (a2, Object * obj), REG (a1, STRPTR * errmsg))
{
  return (MUI_RequestA (oa->App, NULL, 0,
			NULL, *errmsg, *(errmsg + 1), errmsg + 2));
}
///

/// "AppMsgFunc"
SAVEDS (LONG)
AppMsgFunc (REG (a2, Object * obj), REG (a1, struct AppMessage ** x))
{
  struct WBArg *ap;
  struct AppMessage *amsg = *x;
  int i;
  char buf[512];
  char *tmp;

  for (ap = amsg->am_ArgList, i = 0; i < amsg->am_NumArgs; i++, ap++)
    {
      if (ap->wa_Lock)
	{
	  NameFromLock (ap->wa_Lock, buf, sizeof (buf));

	  if (s_strlen (ap->wa_Name) > 0)
	    {
	      if ((tmp = strrchr (buf, '/')))
		*tmp = '\0';
	      DoMethod ((Object *) oa->main_win, MUIM_Main_Open, FALSE, ap->wa_Name, buf);
	    }
	  else			// Dovrei mandare dei dati non sullo stack...

	    {
	      DoMethod ((Object *) oa->main_win, MUIM_Main_Open, TRUE, NULL, buf);
	    }
	}
    }

  return (0);
}

///

/// "Hook func"
SAVEDS (LONG)
openrecent (REG (a2, Object * obj), REG (a1, LONG ** arg))
{
  char *filename, *dirname = NULL, *tmp = NULL;
  Object *item = (Object *) * arg;

  get (item, MUIA_Menuitem_Title, &dirname);

  if (dirname)
    {
      filename = FilePart (dirname);

      if (filename == dirname)
	dirname = NULL;
      else if (filename > dirname)
	{
	  if ((tmp = (STRPTR) AllocVecPooled (gd.gd_pool, filename - dirname + 1)))
	    {
	      strncpy (tmp, dirname, filename - dirname);
	      tmp[filename - dirname] = '\0';
	    }
	}

      DoMethod ((Object *) oa->main_win, MUIM_Main_Open, FALSE, filename, tmp);

      if (tmp)
	FreeVecPooled (gd.gd_pool, tmp);
    }

  return (NULL);
}


SAVEDS (LONG)
add_url (void)
{
  struct WindowNode *wnd = NULL;

  if (oa->main_win)
    get (oa->main_win, MUIA_Main_CurrentProj, &wnd);

  if (wnd)
    DoMethod ((Object *) wnd->wnd_win, MUIM_ProjWin_SetUrl, NULL);

  return (NULL);
}

SAVEDS (LONG)
grab (REG (a2, Object * obj), REG (a1, LONG ** p))
{
  struct WindowNode *wnd = NULL;

  if (oa->main_win)
    get (oa->main_win, MUIA_Main_CurrentProj, &wnd);

  if (wnd)
    DoMethod ((Object *) wnd->wnd_win, MUIM_ProjWin_Grab, NULL);

  return (NULL);
}

SAVEDS (LONG)
update (REG (a2, Object * obj), REG (a1, LONG ** p))
{
  struct WindowNode *wnd = NULL;

  if (oa->main_win)
    get (oa->main_win, MUIA_Main_CurrentProj, &wnd);

  if (wnd)
    DoMethod ((Object *) wnd->wnd_win, MUIM_ProjWin_Update, NULL);

  return (NULL);
}

SAVEDS (LONG)
stopgrab (REG (a2, Object * obj), REG (a1, LONG ** p))
{
  struct WindowNode *wnd = NULL;

  if (oa->main_win)
    get (oa->main_win, MUIA_Main_CurrentProj, &wnd);

  if (wnd)
    DoMethod ((Object *) wnd->wnd_win, MUIM_ProjWin_StopGrab, NULL);

  return (NULL);
}

SAVEDS (LONG)
prefs_win (REG (a2, Object * obj), REG (a1, LONG ** p))
{

  if (!oa->prefs_win)
    oa->prefs_win = PrefsWinObject, End;

  return ((LONG) oa->prefs_win);
}



struct TagItem generictags[] =
{

  //{ ASLFR_TitleText, (ULONG) STRING (MSG_OpenRequest, "Select a Project file...") },

  {ASLFR_InitialDrawer, NULL},
  {ASLFR_InitialFile, NULL},
  {ASLFR_InitialPattern, NULL},

  {ASLFR_DoPatterns, TRUE},
  {ASLFR_RejectIcons, TRUE},

  {TAG_DONE, NULL},

};

SAVEDS (LONG)
insert_gnp (REG (a2, Object * obj), REG (a1, ULONG ** sendtag))
{
  struct WindowNode *wnd = NULL;
  struct AslMessage *asl_msg;
  struct SubTask *st;

  if (oa->main_win)
    get (oa->main_win, MUIA_Main_CurrentProj, &wnd);

  if (wnd)
    {
      if ((asl_msg = (struct AslMessage *) AllocSPooled (gd.gd_pool, sizeof (struct AslMessage))))
	{
	  if ((asl_msg->aslfunc = LoadSeg ("PROGDIR:modules/asl")))
	    {

	      if ((st = SpawnNetTask ("asl", asl_msg->aslfunc, &asldata)))
		{
		  asl_counter++;

		  generictags[0].ti_Data = (ULONG) wnd->dir;
		  generictags[1].ti_Data = (ULONG) wnd->title;

		  if (((ULONG) * sendtag) == MUIM_ProjWin_Insert)
		    generictags[2].ti_Data = (ULONG) "#?.gnp";
		  else if (((ULONG) * sendtag) == MUIM_ProjWin_Inserthtml)
		    generictags[2].ti_Data = (ULONG) "#?.(html|htm)";

		  asl_msg->obj = wnd->wnd_win;
		  asl_msg->rmsg = (ULONG) * sendtag;
		  asl_msg->tags = generictags;

		  set ((Object *) wnd->wnd_win, MUIA_ProjWin_Sleep, TRUE);
		  SendSubTaskMsg (st, STC_START, asl_msg);
		}
	      else
		{
		  UnLoadSeg (asl_msg->aslfunc);
		  FreeSPooled (gd.gd_pool, asl_msg, sizeof (struct AslMessage));
		  error_req (STRING (MSG_OK, "*_OK"), "%s", STRING (ERR_NOFILEREQ, "Cannot open file requester"));
		}
	    }
	  else
	    {
	      FreeSPooled (gd.gd_pool, asl_msg, sizeof (struct AslMessage));
	      error_req (STRING (MSG_OK, "*_OK"), "\033c%s", STRING (ERR_NOASL, "Failed to load\nasl requester module"));
	    }
	}
      else
	error_req (STRING (MSG_OK, "*_OK"), "%s", STRING (ERR_NOMEM, "Out of Memory"));
    }

  return (NULL);
}

SAVEDS (LONG)
save_gnp (REG (a2, Object * obj), REG (a1, LONG ** req))
{
  struct WindowNode *wnd = NULL;

  if (oa->main_win)
    get (oa->main_win, MUIA_Main_CurrentProj, &wnd);

  if (wnd)
    DoMethod ((Object *) wnd->wnd_win, MUIM_ProjWin_Save, *req, NULL, NULL);

  return (NULL);
}

SAVEDS (LONG)
quitprog (REG (a2, Object * obj), REG (a1, LONG ** req))
{
  struct WindowNode *wnd = NULL;

  if (asl_counter < 1)
    {
      if (error_req (STRING (ERR_OKCANCEL, "*_OK|_Cancel"), STRING (MSG_QUITPROG, "\033c Do you want really exit \n from this program ? ")) > 0)
	DoMethod ((Object *) oa->App, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
    }
  else
    error_req (STRING (MSG_OK, "*_OK"), STRING (MSG_CLOSEASLREQ, "\033c First close all \n file requesters "));

  return (NULL);
}

///
// *INDENT-OFF*
extern SAVEDS (LONG) copy_url (void);
extern SAVEDS (LONG) cut_url (void);
extern SAVEDS (LONG) paste_url (void);
extern SAVEDS (LONG) erase_url (void);
// *INDENT-ON*


/// "Hook vars"
struct Hook AppMsgHook =
{
  {NULL, NULL}, (HOOKFUNC) AppMsgFunc, NULL, NULL};

struct Hook OpenHook =
{
  {NULL, NULL}, (HOOKFUNC) openproject, NULL, NULL};

struct Hook OpenRecentHook =
{
  {NULL, NULL}, (HOOKFUNC) openrecent, NULL, NULL};

struct Hook SaveHook =
{
  {NULL, NULL}, (HOOKFUNC) saveproject, NULL, NULL};

struct Hook CloseHook =
{
  {NULL, NULL}, (HOOKFUNC) closeproject, NULL, NULL};

struct Hook GrabHook =
{
  {NULL, NULL}, (HOOKFUNC) grab, NULL, NULL};

struct Hook UpdateHook =
{
  {NULL, NULL}, (HOOKFUNC) update, NULL, NULL};

struct Hook StopGrabHook =
{
  {NULL, NULL}, (HOOKFUNC) stopgrab, NULL, NULL};

struct Hook CopyHook =
{
  {NULL, NULL}, (HOOKFUNC) copy_url, NULL, NULL};

struct Hook CutHook =
{
  {NULL, NULL}, (HOOKFUNC) cut_url, NULL, NULL};

struct Hook PasteHook =
{
  {NULL, NULL}, (HOOKFUNC) paste_url, NULL, NULL};

struct Hook EraseHook =
{
  {NULL, NULL}, (HOOKFUNC) erase_url, NULL, NULL};

struct Hook AddHook =
{
  {NULL, NULL}, (HOOKFUNC) add_url, NULL, NULL};

struct Hook InsertHook =
{
  {NULL, NULL}, (HOOKFUNC) insert_gnp, NULL, NULL};

struct Hook AboutHook =
{
  {NULL, NULL}, (HOOKFUNC) about_win, NULL, NULL};

struct Hook PrefsHook =
{
  {NULL, NULL}, (HOOKFUNC) prefs_win, NULL, NULL};

struct Hook LocalPrefsHook =
{
  {NULL, NULL}, (HOOKFUNC) localprefs_win, NULL, NULL};

struct Hook ExitHook =
{
  {NULL, NULL}, (HOOKFUNC) req_msg, NULL, NULL};

struct Hook QuitHook =
{
  {NULL, NULL}, (HOOKFUNC) quitprog, NULL, NULL};

///

const struct MUI_Command arexx_list[] =
{

  {"open", NULL, 0, &OpenHook},
  {"close", NULL, 0, &CloseHook},
  {"save", NULL, 0, &SaveHook},
  {"about", NULL, 0, &AboutHook},

     // Project hooks
  {"addurl", NULL, 0, &AddHook},
  {"editurl", NULL, 0, &AddHook},
  {"remurl", NULL, 0, &AddHook},

  {NULL, NULL, 0, NULL}

};


/// "CreateApp"
extern unsigned char *vstring;

struct ObjApp *
CreateApp (void)
{
  struct ObjApp *GObject;
  int i;

  APTR Main_Menu;
  APTR MN_Project, MN_New, MN_Open, MN_OpenRecent, MN_Save;
  APTR MN_SaveAs, MN_Close, MN_Inuse;
  APTR MN_About, MN_AboutMUI, MN_Quit, MN_Edit, MN_Cut;
  APTR MN_Copy, MN_Paste, MN_Erase;
  APTR MN_URL, MN_Add;		// Continue for now...

  APTR MN_Insert, MN_Insert_gnp, MN_Insert_html, MN_Preferences, MN_Settings,
    MN_MuiSettings, MN_LocalPrefs;

  if ((GObject = (struct ObjApp *) AllocSPooled (gd.gd_pool, sizeof (struct ObjApp))))
    {
      GObject->edit_win = NULL;
      GObject->about_win = NULL;
      GObject->prefs_win = NULL;
// *INDENT-OFF*

      if (
           (GObject->proj_stimg[0] = ImageIFFObject,
                MUIA_ImageIFF_Filename, "PROGDIR:images/Clear.img",
                MUIA_ImageIFF_BitMapHeader, &Clear_header,
                MUIA_ImageIFF_Body, Clear_body,
                MUIA_ImageIFF_SourceColors, Clear_colors,
                MUIA_FillArea, FALSE,
            End) &&

           (GObject->proj_stimg[1] = ImageIFFObject,
                MUIA_ImageIFF_Filename, "PROGDIR:images/Grabbing.img",
                MUIA_ImageIFF_BitMapHeader, &Grabbing_header,
                MUIA_ImageIFF_Body, Grabbing_body,
                MUIA_ImageIFF_SourceColors, Grabbing_colors,
                MUIA_FillArea, FALSE,
            End) &&

           (GObject->proj_stimg[2] = ImageIFFObject,
                MUIA_ImageIFF_Filename, "PROGDIR:images/Grabbed.img",
                MUIA_ImageIFF_BitMapHeader, &Grabbed_header,
                MUIA_ImageIFF_Body, Grabbed_body,
                MUIA_ImageIFF_SourceColors, Grabbed_colors,
                MUIA_FillArea, FALSE,
            End) &&

           (GObject->proj_stimg[3] = ImageIFFObject,
               MUIA_ImageIFF_Filename, "PROGDIR:images/Decoding.img",
               MUIA_ImageIFF_BitMapHeader, &Decoding_header,
               MUIA_ImageIFF_Body, Decoding_body,
               MUIA_ImageIFF_SourceColors, Decoding_colors,
               MUIA_FillArea, FALSE,
            End) &&

           (GObject->proj_stimg[4] = ImageIFFObject,
               MUIA_ImageIFF_Filename, "PROGDIR:images/Editing.img",
               MUIA_ImageIFF_BitMapHeader, &Editing_header,
               MUIA_ImageIFF_Body, Editing_body,
               MUIA_ImageIFF_SourceColors, Editing_colors,
               MUIA_FillArea, FALSE,
            End) &&

           (GObject->proj_stimg[5] = ImageIFFObject,
               MUIA_ImageIFF_Filename, "PROGDIR:images/Interrupted.img",
               MUIA_ImageIFF_BitMapHeader, &Interrupted_header,
               MUIA_ImageIFF_Body, Interrupted_body,
               MUIA_ImageIFF_SourceColors, Interrupted_colors,
               MUIA_FillArea, FALSE,
            End) &&

           (GObject->proj_stimg[6] = ImageIFFObject,
               MUIA_ImageIFF_Filename, "PROGDIR:images/Error.img",
               MUIA_ImageIFF_BitMapHeader, &Error_header,
               MUIA_ImageIFF_Body, Error_body,
               MUIA_ImageIFF_SourceColors, Error_colors,
               MUIA_FillArea, FALSE,
            End))
// *INDENT-ON*



      {
// *INDENT-OFF*
          MN_New = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_New, "New"),
            MUIA_Menuitem_Shortcut, STRING (Menu_New_Char, "N"),
            End;

          MN_Open = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_Open, "Open"),
            MUIA_Menuitem_Shortcut, STRING (Menu_Open_Char, "O"),
            End;

          GObject->menu_recent = MN_OpenRecent = MN_OpenRecent = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_OpenRecent, "Open Recent..."),
            End;

          // Now create recent list
          for (i=0; (i < 5); i++)
             {
              GObject->menus_recent[i] = MenuitemObject,
                MUIA_Menuitem_Title, prefs->recents[i],
                MUIA_Menuitem_Enabled, (prefs->recents[i]) ? TRUE : FALSE,
               End;

                DoMethod ((Object *) MN_OpenRecent, OM_ADDMEMBER, GObject->menus_recent[i]);
             }

          GObject->menus[0] = MN_Save = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_Save, "Save"),
            MUIA_Menuitem_Shortcut, STRING (Menu_Save_Char, "S"),
            MUIA_Menuitem_Enabled, FALSE,
            End;

          GObject->menus[1] = MN_SaveAs = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_SaveAs, "Save As"),
            MUIA_Menuitem_Shortcut, STRING (Menu_SaveAs_Char, "A"),
            MUIA_Menuitem_Enabled, FALSE,
            End;

          GObject->menus[2] = MN_Close = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_Close, "Close"),
            MUIA_Menuitem_Shortcut, STRING (Menu_Close_Char, "W"),
            MUIA_Menuitem_Enabled, FALSE,
            End;

          GObject->menus[3] = GObject->menu_inuse = MN_Inuse = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_Inuse, "In use..."),
            MUIA_Menuitem_Enabled, FALSE,
            End;

          MN_About = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_About, "About..."),
            MUIA_Menuitem_Shortcut, STRING (Menu_About_Char, "?"),
            End;

          MN_AboutMUI = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_AboutMUI, "About MUI..."),
            End;


          MN_Quit = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_Quit, "Quit"),
            MUIA_Menuitem_Shortcut, STRING (Menu_Quit_Char, "Q"),
            End;

          MN_Project = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_Project, "Project"),
            MUIA_Family_Child, MN_New,
            MUIA_Family_Child, MN_Open,
            MUIA_Family_Child, MN_OpenRecent,
            MUIA_Family_Child, MUI_MakeObject (MUIO_Menuitem, NM_BARLABEL, 0, 0, 0),
            MUIA_Family_Child, MN_Save,
            MUIA_Family_Child, MN_SaveAs,
            MUIA_Family_Child, MN_Close,
            MUIA_Family_Child, MUI_MakeObject (MUIO_Menuitem, NM_BARLABEL, 0, 0, 0),
            MUIA_Family_Child, MN_Inuse,
            MUIA_Family_Child, MUI_MakeObject (MUIO_Menuitem, NM_BARLABEL, 0, 0, 0),
            MUIA_Family_Child, MN_About,
            MUIA_Family_Child, MN_AboutMUI,
            MUIA_Family_Child, MUI_MakeObject (MUIO_Menuitem, NM_BARLABEL, 0, 0, 0),
            MUIA_Family_Child, MN_Quit,
            End;

          MN_Cut = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_Cut, "Cut"),
            MUIA_Menuitem_Shortcut, STRING (Menu_Cut_Char, "X"),
            End;

          MN_Copy = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_Copy, "Copy"),
            MUIA_Menuitem_Shortcut, STRING (Menu_Copy_Char, "C"),
            End;

          MN_Paste = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_Paste, "Paste"),
            MUIA_Menuitem_Shortcut, STRING (Menu_Paste_Char, "V"),
            End;

          MN_Erase = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_Erase, "Erase"),
            MUIA_Menuitem_Shortcut, STRING (Menu_Erase_Char, "E"),
            End;

          GObject->menus[6] = MN_Edit = MenuObject,
            MUIA_Menu_Title, STRING (Menu_Edit, "Edit"),
            MUIA_Menu_Enabled, FALSE,
            MUIA_Family_Child, MN_Cut,
            MUIA_Family_Child, MN_Copy,
            MUIA_Family_Child, MN_Paste,
            MUIA_Family_Child, MN_Erase,
            End;

          MN_Add = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_Add, "Add"),
            MUIA_Menuitem_Shortcut, STRING (Menu_Add_Char, "+"),
            End;

          MN_Insert = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_InsertFrom, "Insert from"),
            Child, MN_Insert_gnp = MenuitemObject,
              MUIA_Menuitem_Title, STRING (Menu_Insert_gnp, "GNetGrabber file..."),
              //MUIA_Menuitem_Shortcut, STRING (Menu_Add_Char, "+"),
              End,
            Child, MN_Insert_html = MenuitemObject,
              MUIA_Menuitem_Title, STRING (Menu_Insert_html, "HTML document..."),
              //MUIA_Menuitem_Shortcut, STRING (Menu_Add_Char, "+"),
            End,
          End;

          MN_Preferences = MenuitemObject,
            MUIA_Menuitem_Title, STRING (Menu_Preferences, "Preferences"),

            MUIA_Family_Child, MN_Settings = MenuitemObject,
              MUIA_Menuitem_Title, STRING (Menu_GlobalSettings, "Global Settings..."),
              MUIA_Menuitem_Shortcut, STRING (Menu_GlobalSettings_Char, "G"),
            End,

            MUIA_Family_Child, MN_LocalPrefs = GObject->menus[4] = MenuitemObject,
              MUIA_Menuitem_Title, STRING (Menu_ProjSettings, "Project Settings..."),
              MUIA_Menuitem_Shortcut, STRING (Menu_ProjSettings_Char, "P"),
              MUIA_Menuitem_Enabled, FALSE,
            End,

            MUIA_Family_Child, MUI_MakeObject (MUIO_Menuitem, NM_BARLABEL, 0, 0, 0),

            MUIA_Family_Child, MN_MuiSettings = MenuitemObject,
              MUIA_Menuitem_Title, STRING (Menu_MUISettings, "MUI Settings..."),
              MUIA_Menuitem_Shortcut, STRING (Menu_MUISettings_Char, "J"),
            End,

          End;

          GObject->menu = Main_Menu = MenustripObject,
            MUIA_Family_Child, MN_Project,
            MUIA_Family_Child, MN_Edit,

            MUIA_Family_Child, GObject->menus[7] = MN_URL = MenuObject,
              MUIA_Menu_Enabled, FALSE,
              MUIA_Menu_Title, STRING (Menu_URL, "URL"),
              MUIA_Family_Child, MN_Add,
              MUIA_Family_Child, MN_Insert,
            End,

            MUIA_Family_Child, MN_Preferences,
            End;


          GObject->menus[5] = NULL;
          GObject->menus[8] = NULL;

          /***/

          GObject->App = ApplicationObject,
            MUIA_Application_Author, "Giambattista Bloisi",
            MUIA_Application_Base, "GNETGRABBER",
            MUIA_Application_Title, "GiambyNetGrabber",
            MUIA_Application_Version, vstring,
            MUIA_Application_Copyright, "© 1997 by Giambattista Bloisi",
            MUIA_Application_Description, STRING (App_Description, "The Amiga internet mirroring tool"),
            MUIA_Application_HelpFile, STRING (App_HelpFileName, "Docs/GNetGrabber_eng.guide"),
            MUIA_Application_Menustrip, Main_Menu,
            MUIA_Application_SingleTask, TRUE,
            MUIA_Application_Commands, arexx_list,
          End;

// *INDENT-ON*




	if (GObject->App)
	  {
	    oa = GObject;

	    if ((GObject->main_win = MainWinObject, End))
	      {

		DoMethod ((Object *) GObject->App,
			  MUIM_Notify, MUIA_Application_DoubleStart, TRUE,
			  GObject->App,
			  5,
		    MUIM_CallHook, &ExitHook, STRING (MSG_OK, "*_OK"), "%s",
		STRING (ERR_DoubleStart, "GNetGrabber is already running"));


		DoMethod ((Object *) MN_About,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  MUIV_Notify_Application,
			  2, MUIM_CallHook, &AboutHook);

		DoMethod ((Object *) MN_Settings,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  MUIV_Notify_Application,
			  2, MUIM_CallHook, &PrefsHook);

		DoMethod ((Object *) MN_LocalPrefs,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  MUIV_Notify_Application,
			  2, MUIM_CallHook, &LocalPrefsHook);

		DoMethod ((Object *) MN_Close,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  MUIV_Notify_Application,
			  2, MUIM_CallHook, &CloseHook);


		DoMethod ((Object *) MN_AboutMUI,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  MUIV_Notify_Application,
			  2, MUIM_Application_AboutMUI, GObject->main_win);

		DoMethod ((Object *) MN_Quit,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  GObject->App,
			  2, MUIM_CallHook, &QuitHook);

		DoMethod ((Object *) MN_Open,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  GObject->App,
			  3, MUIM_CallHook, &OpenHook, TRUE);


		for (i = 0; (i < 5); i++)
		  {
		    DoMethod ((Object *) GObject->menus_recent[i],
			 MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			      GObject->App,
			      3, MUIM_CallHook, &OpenRecentHook, GObject->menus_recent[i]);
		  }

		DoMethod ((Object *) MN_Save,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  GObject->App,
			  3, MUIM_CallHook, &SaveHook, FALSE);

		DoMethod ((Object *) MN_SaveAs,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  GObject->App,
			  3, MUIM_CallHook, &SaveHook, TRUE);

		DoMethod ((Object *) MN_New,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  GObject->App,
			  3, MUIM_CallHook, &OpenHook, FALSE);

		DoMethod ((Object *) MN_Copy,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  GObject->App,
			  2, MUIM_CallHook, &CopyHook);

		DoMethod ((Object *) MN_Cut,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  GObject->App,
			  2, MUIM_CallHook, &CutHook);

		DoMethod ((Object *) MN_Paste,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  GObject->App,
			  2, MUIM_CallHook, &PasteHook);

		DoMethod ((Object *) MN_Erase,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  GObject->App,
			  2, MUIM_CallHook, &EraseHook);

		DoMethod ((Object *) MN_Add,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  GObject->App,
			  2, MUIM_CallHook, &AddHook);

		DoMethod ((Object *) MN_Insert_gnp,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  GObject->App,
			3, MUIM_CallHook, &InsertHook, MUIM_ProjWin_Insert);

		DoMethod ((Object *) MN_Insert_html,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  GObject->App,
		    3, MUIM_CallHook, &InsertHook, MUIM_ProjWin_Inserthtml);

		DoMethod ((Object *) MN_MuiSettings,
			  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
			  MUIV_Notify_Application,
			  3, MUIM_Application_OpenConfigWindow, 0);

		return (GObject);
	      }

	    MUI_DisposeObject ((Object *) GObject->App);
	  }

	MUI_DisposeObject ((Object *) GObject->proj_stimg[6]);
	MUI_DisposeObject ((Object *) GObject->proj_stimg[5]);
	MUI_DisposeObject ((Object *) GObject->proj_stimg[4]);
	MUI_DisposeObject ((Object *) GObject->proj_stimg[3]);
	MUI_DisposeObject ((Object *) GObject->proj_stimg[2]);
	MUI_DisposeObject ((Object *) GObject->proj_stimg[1]);
	MUI_DisposeObject ((Object *) GObject->proj_stimg[0]);
      }

      FreeSPooled (gd.gd_pool, GObject, sizeof (struct ObjApp));
    }

  return (NULL);
}

///
