home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 100 / af100a.adf / archives / morehtml.lzx / moreHTML / Source / MAIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-18  |  49.4 KB  |  1,718 lines

  1. /*
  2.  *  moreHTML
  3.  *  © Dirk Holtwick, 1997
  4.  *  ---------------------
  5. ///
  6.     I publish this source, but that doesn't mean that it is  free.  It
  7.     still remains copyrighted by me, Dirk Holtwick, and if you want to
  8.     change the source or add some functions, you first have to get  in
  9.     contact with me and get my permission.
  10.  
  11.     I regret that the comments and the stile of  the  source  are  not
  12.     very  clear,  but  I  will try to make it more readable and better
  13.     structured. For the compilation I used SAS/C 6.57.
  14.  
  15.     I need some help reguarding ARexx and Internet Access. Please  get
  16.     in contact with me if you can help me. Thanks.
  17.  
  18. ///                                                   Yours Dirk Holtwick
  19.  */
  20.  
  21. #define VERS      "1.4"
  22. #define NAME      "moreHTML"
  23. #define TMPREXX   "T:moreHTML_temp_command.rexx"
  24. #define TMPINFO   "T:moreHTML_temp_info.rexx"
  25.  
  26. // #define DEBUG
  27.  
  28. /// DEBUG
  29. #ifdef DEBUG
  30. // char  debugstr[80];
  31.    extern void KPrintF(...);
  32.    #define DB KPrintF
  33. // #define X KPrintF("Line: %4ld, File: '%s', Press key... ",__LINE__,__FILE__); gets(debugstr);
  34. #else
  35.    #define X
  36.    #define DB ; / ## /
  37. #endif
  38. ///
  39. /// Includes
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include <stdio.h>
  43.  
  44. #include <rexx/storage.h>
  45. #include <rexx/rxslib.h>
  46.  
  47. #include <exec/memory.h>
  48. #include <prefs/prefhdr.h>
  49. #include <datatypes/pictureclass.h>
  50. #include <workbench/workbench.h>
  51. #include <libraries/locale.h>
  52. #include <libraries/asl.h>
  53. #include <libraries/gadtools.h>
  54. #include <libraries/mui.h>
  55.  
  56. #include <proto/rexxsyslib.h>
  57.  
  58. #include <clib/exec_protos.h>
  59. #include <clib/graphics_protos.h>
  60. #include <clib/intuition_protos.h>
  61. #include <clib/utility_protos.h>
  62. #include <clib/dos_protos.h>
  63. #include <clib/locale_protos.h>
  64. #include <clib/muimaster_protos.h>
  65. #include <clib/icon_protos.h>
  66. #include <clib/alib_protos.h>
  67.  
  68. #include <pragmas/exec_pragmas.h>
  69. #include <pragmas/graphics_pragmas.h>
  70. #include <pragmas/intuition_pragmas.h>
  71. #include <pragmas/utility_pragmas.h>
  72. #include <pragmas/dos_pragmas.h>
  73. #include <pragmas/locale_pragmas.h>
  74. #include <pragmas/muimaster_pragmas.h>
  75. #include <pragmas/icon_pragmas.h>
  76.  
  77. #include <dos.h>
  78.  
  79. #include <mui/htmltext_mcc.h>
  80.  
  81. #include "dtpic.h"
  82. #include "cb.h"
  83. #include "mylist.h"
  84. #include "mystring.h"
  85. ///
  86. /// Compiler Stuff
  87. #ifdef _DCC
  88. #define REG(x) __ ## x
  89. #define ASM
  90. #define SAVEDS __geta4
  91. #else
  92. #define REG(x) register __ ## x
  93. #define ASM    __asm
  94. #define SAVEDS __saveds
  95. #endif
  96. ///
  97. /// Definitions
  98. #define MUIM_MainWindow_Finish        0x90a41070
  99. #define MUIM_MainWindow_About         0x90a41071
  100. #define MUIM_MainWindow_Open          0x90a41072
  101. #define MUIM_MainWindow_Iconify       0x90a41073
  102. #define MUIM_MainWindow_Save          0x90a41074
  103. #define MUIM_MainWindow_AddURL        0x90a41075
  104. #define MUIM_MainWindow_BackURL       0x90a41076
  105. #define MUIM_MainWindow_ReloadURL     0x90a41077
  106. #define MUIM_MainWindow_Config        0x90a41078
  107. #define MUIM_MainWindow_Action        0x90a41079
  108. #define MUIM_MainWindow_Find          0x90a4107a
  109. #define MUIM_MainWindow_Rexx          0x90a4107b
  110.  
  111. #define REQ(text,but)                 MUI_Request(app,obj,0,NULL,but,(char *)text,0)
  112. ///
  113. /// Global Vars
  114. char  openurlstr[80];
  115.  
  116. LONG __stack = 2*8192;
  117.  
  118. struct Library *MUIMasterBase;
  119. struct Library *GfxBase      ;
  120. struct Library *IntuitionBase;
  121. struct Library *LocaleBase   ;
  122. struct Library *AslBase      ;
  123. struct Library *UtilityBase  ;
  124. struct Library *DataTypesBase = 0;
  125.  
  126. Object *win;
  127.  
  128. extern struct Library *DOSBase;
  129.  
  130. struct MUI_CustomClass *CL_MainWindow  ;
  131. struct MUI_CustomClass *CL_Dtpic       ;
  132. ///
  133. /// Menu
  134. #define RB CHECKIT
  135. #define TG CHECKIT|MENUTOGGLE
  136.  
  137. enum
  138. {
  139.    MEN_OPEN=1,
  140.    MEN_SAVE,
  141.    MEN_ABOUT,
  142.    MEN_AMUI,
  143.    MEN_PRINT,
  144.    MEN_EDIT,
  145.    MEN_VIEW,
  146.    MEN_HIDE,
  147.    MEN_QUIT,
  148.    MEN_CPBLOCK,
  149.    MEN_CPTEXT,
  150.    MEN_PATEXT,
  151.    MEN_BACK,
  152.    MEN_RELOAD,
  153.    MEN_CONF,
  154.    MEN_MUI,
  155.    MEN_FIND,
  156.    MEN_NEXT,
  157. };
  158.  
  159. struct NewMenu MainMenu[] =
  160. {
  161.    { NM_TITLE, (STRPTR)"Project"                 , 0 ,0,0,(APTR)0             },
  162.    { NM_ITEM , (STRPTR)"Open"                    ,"O",0,0,(APTR)MEN_OPEN      },
  163.    { NM_ITEM , (STRPTR)"Save as"                 ,"S",0,0,(APTR)MEN_SAVE      },
  164.    { NM_ITEM , (STRPTR)NM_BARLABEL               , 0 ,0,0,(APTR)0             },
  165.    { NM_ITEM , (STRPTR)"Print"                   ,"P",0,0,(APTR)MEN_PRINT     },
  166.    { NM_ITEM , (STRPTR)NM_BARLABEL               , 0 ,0,0,(APTR)0             },
  167.    { NM_ITEM , (STRPTR)"View source"             ,"V",0,0,(APTR)MEN_VIEW      },
  168.    { NM_ITEM , (STRPTR)"Edit source"             ,"E",0,0,(APTR)MEN_EDIT      },
  169.    { NM_ITEM , (STRPTR)NM_BARLABEL               , 0 ,0,0,(APTR)0             },
  170.    { NM_ITEM , (STRPTR)"About"                   ,"?",0,0,(APTR)MEN_ABOUT     },
  171.    { NM_ITEM , (STRPTR)"About MUI"               , 0 ,0,0,(APTR)MEN_AMUI      },
  172.    { NM_ITEM , (STRPTR)NM_BARLABEL               , 0 ,0,0,(APTR)0             },
  173.    { NM_ITEM , (STRPTR)"Hide"                    ,"H",0,0,(APTR)MEN_HIDE      },
  174.    { NM_ITEM , (STRPTR)"Quit"                    ,"Q",0,0,(APTR)MEN_QUIT      },
  175.  
  176.    { NM_TITLE, (STRPTR)"Edit"                    , 0 ,0,0,(APTR)0             },
  177.    { NM_ITEM , (STRPTR)"Find"                    ,"F",0,0,(APTR)MEN_FIND      },
  178.    { NM_ITEM , (STRPTR)"Find next"               ,"N",0,0,(APTR)MEN_NEXT      },
  179.    { NM_ITEM , (STRPTR)NM_BARLABEL               , 0 ,0,0,(APTR)0             },
  180.    { NM_ITEM , (STRPTR)"Copy block"              ,"C",0,0,(APTR)MEN_CPBLOCK   },
  181.    { NM_ITEM , (STRPTR)"Copy text"               , 0 ,0,0,(APTR)MEN_CPTEXT    },
  182.  
  183.    { NM_TITLE, (STRPTR)"Navigation"              , 0 ,0,0,(APTR)0             },
  184.    { NM_ITEM , (STRPTR)"Back"                    ,"B",0,0,(APTR)MEN_BACK      },
  185.    { NM_ITEM , (STRPTR)"Reload"                  ,"R",0,0,(APTR)MEN_RELOAD    },
  186.  
  187.    { NM_TITLE, (STRPTR)"Settings"                , 0 ,0,0,(APTR)0             },
  188.    { NM_ITEM , (STRPTR)"moreHTML"                , 0 ,0,0,(APTR)MEN_CONF      },
  189.    { NM_ITEM , (STRPTR)"MUI"                     , 0 ,0,0,(APTR)MEN_MUI       },
  190.  
  191.    { NM_END,NULL,0,0,0,(APTR)0 },
  192. };
  193. ///
  194. /// Misc Help Functions
  195.  
  196. LONG xget(Object *obj,ULONG attribute)
  197. {
  198.    LONG x;
  199.    get(obj,attribute,&x);
  200.    return(x);
  201. }
  202.  
  203. ULONG __stdargs DoSuperNew(struct IClass *cl,Object *obj,ULONG tag1,...)
  204. {
  205.    return(DoSuperMethod(cl,obj,OM_NEW,&tag1,NULL));
  206. }
  207.  
  208. ///
  209. /// Clipboard
  210. int WriteClip(char *string)
  211. {
  212.    struct IOClipReq *ior;
  213.  
  214.    if (string == NULL)
  215.    {
  216.       puts("No string argument given");
  217.       return(0);
  218.    }
  219.    if (ior = CBOpen(0L))
  220.    {
  221.       if (!(CBWriteFTXT(ior,string)))
  222.         printf("Error writing to clipboard: io_Error = %ld\n",ior->io_Error);
  223.       CBClose(ior);
  224.    }
  225.    else
  226.       puts("Error opening clipboard.device");
  227.    return(0);
  228. }
  229. ///
  230.  
  231. // Structures
  232.  
  233. /// struct URLlist
  234. struct URLlist
  235. {
  236.    struct   URLlist
  237.             *next;
  238.    char     *url;
  239.    ULONG    yoff;
  240. };
  241. ///
  242. /// struct Config_Data
  243. struct Config_Data
  244. {
  245.    char  viewsource[80];
  246.    char  printtext[80];
  247.    char  editsource[80];
  248.    char  openurl[80];
  249. };
  250. ///
  251. /// struct Tool_Data
  252. struct Tool_Data
  253. {
  254.    struct   Tool_Data
  255.             *next;
  256.    char     *command;
  257.    char     *help;
  258. };
  259. ///
  260. /// struct MainWindow_Data
  261. struct MainWindow_Data
  262. {
  263.    Object   *win;
  264.    Object   *file;
  265.    Object   *html;
  266.    Object   *scroll;
  267.    Object   *infoline;
  268.    Object   *toolbar;
  269.    Object   *tool[4];
  270.  
  271.    char     searchstr[256];
  272.    ULONG    searchpos;
  273.  
  274.    char     path[256];
  275.  
  276.    struct   Config_Data
  277.             cfg;
  278.  
  279.    struct   URLlist
  280.             *urllist;
  281.  
  282.    // Toolbar
  283.    struct   MyList
  284.             *tools;
  285. };
  286. ///
  287.  
  288. // Toolbar
  289.  
  290. /// CreateToolbar
  291. void CreateToolbar(struct MainWindow_Data *data)
  292. {
  293.    FILE     *f;
  294.    static   char
  295.             inbuf[1024],
  296.             buf[1024];
  297. //          *str;
  298.    struct   RDArgs
  299.             rda;
  300.    BOOL     error = TRUE,
  301.             textmode = FALSE,
  302.             virgin = TRUE,
  303.             horiz = TRUE;
  304.  
  305.    struct
  306.    {
  307.       char     *pos;
  308.       ULONG    mode;
  309.       ULONG    space;
  310.       char     *text;
  311.       char     *command;
  312.       ULONG    script;
  313.       char     *key;
  314.       char     *image;
  315.       char     *help;
  316.    } arr;
  317.  
  318.    if(!DataTypesBase) textmode = TRUE;
  319.  
  320.    data->toolbar = data->tool[0];
  321.  
  322.    if(data->tools = MyCreateList(sizeof(struct Tool_Data), 12))
  323.    if(f = fopen("PROGDIR:config/moreHTML.toolbar.config","r"))
  324.    {
  325.       while(!feof(f))
  326.       {
  327.          fgets(inbuf, sizeof(inbuf), f);
  328.          buf[strlen(inbuf)-1] = 0;
  329.  
  330.          if((*stpblk(inbuf) != '#') && (*stpblk(inbuf) != NULL))
  331.          {
  332.             error = FALSE;
  333.  
  334.             memset(&rda, 0, sizeof(struct RDArgs));
  335.             memset(&arr, 0, sizeof(arr));
  336.  
  337.             rda.RDA_Source.CS_Buffer = inbuf;
  338.             rda.RDA_Source.CS_Length = strlen(inbuf);
  339.  
  340.             ReadArgs("POS=POSITION/K,TEXTMODE/S,SPACE/S,TEXT/K,COMMAND/K,SCRIPT/S,KEY/K,IMAGE/K,HELP/K",(LONG *)&arr,&rda);
  341.  
  342.             // Some definitions that have to come before the button definitions
  343.             if(virgin)
  344.             {
  345.                if(arr.pos)
  346.                {
  347.                   if(!stricmp(arr.pos,"left"))
  348.                   {
  349.                      data->toolbar = data->tool[2];
  350.                      horiz = FALSE;
  351.                   }
  352.                   else if(!stricmp(arr.pos,"right"))
  353.                   {
  354.                      data->toolbar = data->tool[3];
  355.                      horiz = FALSE;
  356.                   }
  357.                   else if(!stricmp(arr.pos,"bottom"))
  358.                      data->toolbar = data->tool[1];
  359.                }
  360.                if(arr.mode) textmode=TRUE;
  361.             }
  362.  
  363.             // Kill old contents
  364.             if((arr.space || arr.text) && virgin)
  365.             {
  366.                struct   List
  367.                         *childlist;
  368.                Object   *cstate;
  369.                Object   *child;
  370.  
  371.                if(childlist = (void *)xget(data->toolbar, MUIA_Group_ChildList))
  372.                {
  373.                   cstate = (Object *)childlist->lh_Head;
  374.                   while (child = NextObject(&cstate))
  375.                      DoMethod(data->toolbar, OM_REMMEMBER, child);
  376.                }
  377.                virgin = FALSE;
  378.             }
  379.  
  380.             // Create space
  381.             if(arr.space)
  382.             {
  383.                if(horiz)
  384.                   DoMethod (data->toolbar, OM_ADDMEMBER, HSpace(0));
  385.                else
  386.                   DoMethod (data->toolbar, OM_ADDMEMBER, VSpace(0));
  387.             }
  388.  
  389.             // Create button
  390.             else if(arr.text)
  391.             {
  392.                Object *obj;
  393.                struct Tool_Data *t;
  394.  
  395.                // Buffer the important strings
  396.                // Uses private functions
  397.                t = MyAddItem(data->tools);
  398.                t->command = MyAllocString(arr.command);
  399.                t->help    = MyAllocString(arr.help);
  400.  
  401.                if(textmode)
  402.                {
  403.                   DoMethod (data->toolbar, OM_ADDMEMBER,
  404.                      obj = TextObject,
  405.                         ButtonFrame,
  406.                         MUIA_Text_Contents, arr.text,
  407.                         MUIA_Text_PreParse, "\33c",
  408.                         MUIA_Text_HiChar  , *arr.key,
  409.                         MUIA_ControlChar  , *arr.key,
  410.                         MUIA_InputMode    , MUIV_InputMode_RelVerify,
  411.                         MUIA_Background   , MUII_ButtonBack,
  412.                         MUIA_CycleChain   , TRUE,
  413.                         MUIA_ShortHelp    , t->help,
  414.                         End
  415.                   );
  416.                }
  417.                else
  418.                {
  419.                   DoMethod (data->toolbar, OM_ADDMEMBER,
  420.                      obj = DtpicObject,
  421.                         ImageButtonFrame,
  422.                         MUIA_CycleChain           , 1,
  423.                         MUIA_InputMode            , MUIV_InputMode_RelVerify,
  424.                         MUIA_Dtpic_Name           , arr.image,
  425.                         MUIA_ShortHelp            , t->help,
  426.                         MUIA_ControlChar          , *arr.key,
  427.                         End
  428.                   );
  429.                }
  430.  
  431.                DoMethod(obj, MUIM_Notify, MUIA_Pressed, FALSE,
  432.                   data->win,3,MUIM_MainWindow_Rexx,t->command,arr.script);
  433.             }
  434.  
  435.             FreeArgs(&rda);
  436.          }
  437.       }
  438.       fclose(f);
  439.    }
  440.    else
  441.    {
  442.       puts("Couldn't open toolbar config file.");
  443.    }
  444.  
  445.    if(error)
  446.       DoMethod (data->toolbar, OM_ADDMEMBER,
  447.          HSpace(0)
  448.       );
  449. }
  450. ///
  451. /// DisposeToolbar
  452. void DisposeToolbar(struct MainWindow_Data *data)
  453. {
  454.    struct Tool_Data *t;
  455.  
  456.    t = (void *)data->tools->first;
  457.    while(t)
  458.    {
  459.       MyFreeString(t->command);
  460.       MyFreeString(t->help);
  461.       t=t->next;
  462.    }
  463.  
  464.    MyDisposeList(data->tools);
  465. }
  466. ///
  467.  
  468. // MainWindow
  469.  
  470. /// OpenURLHook
  471. __saveds ULONG __asm OpenURL(register __a0 struct Hook *h, register __a2 Object *obj, register __a1 struct{ char *URL; char *TmpFilename; } *msg)
  472. {
  473. // struct MainWindow_Data *data = INST_DATA(OCLASS(obj), obj);
  474. // char   buf[120];
  475.  
  476. // sprintf(buf, openurlstr, msg->URL, msg->LocalFile);
  477.  
  478.    puts(msg->TmpFilename);
  479.    strcpy(msg->TmpFilename, "work:www/index.html");
  480.    puts(msg->TmpFilename);
  481. // if(buf[0]) system(buf);
  482.    return(TRUE);
  483. }
  484. ///
  485. /// AppMsgFunc
  486. SAVEDS ASM LONG AppMsgFunc(REG(a2) APTR obj, REG(a1) struct AppMessage **x)
  487. {
  488.    struct WBArg *ap;
  489.    struct AppMessage *amsg = *x;
  490.    static char buf[256];
  491.  
  492.    if(amsg->am_NumArgs)
  493.    {
  494.       ap=amsg->am_ArgList;
  495.       NameFromLock(ap->wa_Lock,buf,sizeof(buf));
  496.       AddPart(buf,ap->wa_Name,sizeof(buf));
  497.       set(obj,MUIA_HTMLtext_URL,buf);
  498.    }
  499.  
  500.    return(0);
  501. }
  502. ///
  503. /// SaveHTML
  504. void SaveHTML(struct MainWindow_Data *data, char *name)
  505. {
  506.    if(name)
  507.    {
  508.       char  *text;
  509.       FILE  *f;
  510.  
  511.       get(data->html, MUIA_HTMLtext_Contents, &text);
  512.       if(f=fopen(name,"w"))
  513.       {
  514.          fwrite(text,strlen(text),1,f);
  515.          fclose(f);
  516.       }
  517.    }
  518. }
  519. ///
  520. /// MainWindow_Rexx
  521. ULONG MainWindow_Rexx(struct IClass *cl,Object *obj,struct {ULONG MethodID; char *command; ULONG script;} *msg)
  522. {
  523. //   struct MainWindow_Data *data = INST_DATA(cl,obj);
  524.  
  525.    DB("Command: %s, Script: %ld\n",msg->command,!msg->script);
  526.  
  527.    {
  528.       char     *name, cmd[256];
  529.       FILE     *f;
  530.       Object   *app = (Object *)xget(obj,MUIA_ApplicationObject);
  531.  
  532.       name = TMPREXX;
  533.       if(f = fopen(name,"w"))
  534.       {
  535.          fprintf(f,
  536.             "/* Tmpfile */\n"
  537.             "address %s %s",
  538.             ((char *)xget(app,MUIA_Application_Base)),
  539.             msg->command
  540.          );
  541.          fclose(f);
  542.  
  543.          sprintf(cmd,"run <>nil: sys:rexxc/rx %s",name);
  544.          system(cmd);
  545.       }
  546.    }
  547.  
  548.    return(0);
  549. }
  550. ///
  551. /// MainWindow_Config
  552. ULONG MainWindow_Config(struct IClass *cl,Object *obj,struct {ULONG MethodID; ULONG justget;} *msg)
  553. {
  554.    struct   MainWindow_Data *data = INST_DATA(cl,obj);
  555.    Object   *app = (Object *)xget(obj,MUIA_ApplicationObject);
  556.    char     *h;
  557.    ULONG    d;
  558.  
  559.    Object
  560.       *win,
  561.       *showtoolbar,
  562.       *showinfoline,
  563.       *showimg,
  564.       *viewsource,
  565.       *editsource,
  566.       *printtext;
  567. //    *openurl;
  568.  
  569.    enum
  570.    {
  571.       OBJ_showtoolbar = 1,
  572.       OBJ_showinfoline,
  573.       OBJ_viewsource,
  574.       OBJ_editsource,
  575.       OBJ_printtext,
  576.       OBJ_openurl,
  577.       OBJ_showimg,
  578.    };
  579.  
  580.    static const char *titles[] =
  581.    {
  582.       "Misc",
  583.       "Commands",
  584.       NULL
  585.    };
  586.  
  587.    set(app,MUIA_Application_Sleep,TRUE);  // disable other windows
  588.  
  589.    win =
  590.       WindowObject,
  591.          MUIA_Window_Title, "Settings",
  592.          MUIA_Window_ID   , MAKE_ID('C','O','N','F'),
  593.  
  594.          WindowContents, VGroup,
  595.  
  596.             Child, RegisterObject,
  597.                MUIA_Register_Titles, titles,
  598.  
  599.                // DISPLAY
  600.                Child, ColGroup(2),
  601.                   Child, LLabel("Show _tool bar"),
  602.                   Child, showtoolbar = KeyCheckMark(TRUE,'t'),
  603.                   Child, LLabel("Show info _line"),
  604.                   Child, showinfoline = KeyCheckMark(TRUE,'l'),
  605.                   Child, LLabel("Show _images"),
  606.                   Child, showimg = KeyCheckMark(TRUE,'i'),
  607.                   End,
  608.  
  609.                // FUNCTIONS
  610.                Child, ColGroup(2),
  611.                   Child, VSpace(0),
  612.                   Child, VSpace(0),
  613. /*
  614.                   Child, LLabel("Open URL"),
  615.                   Child, openurl = StringObject,
  616.                      StringFrame,
  617.                      MUIA_CycleChain, 1,
  618.                      MUIA_ObjectID, OBJ_openurl,
  619.                      MUIA_String_Contents, "geturl %s %s",
  620.                      MUIA_ShortHelp,
  621.                         "Command to be used to load page and data\n"
  622.                         "of an to HTMLtext unknown protocol.\n"
  623.                         "First '%s' stands for the URL and the\n"
  624.                         "second '%s' for the file where to write\n"
  625.                         "data to.",
  626.                      End,
  627.                   Child, VSpace(0),
  628.                   Child, VSpace(0),
  629. */
  630.                   Child, LLabel("Print text"),
  631.                   Child, printtext = StringObject,
  632.                      StringFrame,
  633.                      MUIA_CycleChain, 1,
  634.                      MUIA_ObjectID, OBJ_printtext,
  635.                      MUIA_String_Contents, "httx %s prt: ansi",
  636.                      MUIA_ShortHelp,
  637.                         "Command to be used to print the\n"
  638.                         "contents of the current HTML file.\n"
  639.                         "One '%s' has to be used!",
  640.                      End,
  641.                   Child, LLabel("View source"),
  642.                   Child, viewsource = StringObject,
  643.                      StringFrame,
  644.                      MUIA_CycleChain, 1,
  645.                      MUIA_ObjectID, OBJ_viewsource,
  646.                      MUIA_String_Contents, "more %s",
  647.                      MUIA_ShortHelp,
  648.                         "Command to be used to display the\n"
  649.                         "source of the current HTML file.\n"
  650.                         "One '%s' has to be used!",
  651.                      End,
  652.                   Child, LLabel("Edit source"),
  653.                   Child, editsource = StringObject,
  654.                      StringFrame,
  655.                      MUIA_CycleChain, 1,
  656.                      MUIA_ObjectID, OBJ_editsource,
  657.                      MUIA_String_Contents, "ed %s",
  658.                      MUIA_ShortHelp,
  659.                         "Command to be used to edit the\n"
  660.                         "source of the current HTML file.\n"
  661.                         "One '%s' has to be used!",
  662.                      End,
  663. /*
  664.                   Child, printtext = LLabel("On Double-Click"),
  665.                   Child, StringObject,
  666.                      StringFrame,
  667.                      MUIA_CycleChain, 1,
  668.                      MUIA_ObjectID, OBJ_printtext,
  669.                      MUIA_String_Contents, "rx findword.rexx",
  670.                      MUIA_ShortHelp,
  671.                         "Command to be used to print the\n"
  672.                         "contents of the current HTML file.\n"
  673.                         "One '\%s' has to be used!",
  674.                      End,
  675. */
  676.                   Child, VSpace(0),
  677.                   Child, VSpace(0),
  678.                   End,
  679.  
  680.                End,
  681.             End,
  682.          End;
  683.  
  684.    if (win)                               // ok ?
  685.    {
  686.       DoMethod(app,OM_ADDMEMBER,win);    // add window...
  687.       DoMethod(win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE ,
  688.          app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  689.  
  690.       set(showtoolbar,   MUIA_ObjectID, OBJ_showtoolbar);
  691.       set(showtoolbar,   MUIA_CycleChain, 1);
  692.       set(showinfoline,  MUIA_ObjectID, OBJ_showinfoline);
  693.       set(showinfoline,  MUIA_CycleChain, 1);
  694.       set(showimg,       MUIA_ObjectID, OBJ_showimg);
  695.       set(showimg,       MUIA_CycleChain, 1);
  696.  
  697.       DoMethod(app,MUIM_Application_Load, MUIV_Application_Load_ENVARC);
  698.  
  699.       // Just get the config datas
  700.       if(!msg->justget)
  701.       {
  702.  
  703.          set(win,MUIA_Window_Open,TRUE);    // and open it
  704.  
  705.          {
  706.             ULONG sigs = 0;
  707.  
  708.             while (DoMethod(app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
  709.             {
  710.                if (sigs)
  711.                {
  712.                   sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  713.                   if (sigs & SIGBREAKF_CTRL_C) break;
  714.                }
  715.             }
  716.          }
  717.  
  718.          set(win,MUIA_Window_Open,FALSE);   // Close window
  719.  
  720.          DoMethod(app,MUIM_Application_Save, MUIV_Application_Save_ENVARC);
  721.       }
  722.  
  723.       // Read out the config datas
  724.       get(showtoolbar, MUIA_Selected, &d);
  725.       set(data->toolbar, MUIA_ShowMe, d);
  726.  
  727.       get(showinfoline, MUIA_Selected, &d);
  728.       set(data->infoline, MUIA_ShowMe, d);
  729.  
  730.       get(showimg, MUIA_Selected, &d);
  731.       set(data->html, MUIA_HTMLtext_LoadImages, d);
  732.  
  733.       get(viewsource, MUIA_String_Contents, &h);
  734.       strcpy(data->cfg.viewsource, h);
  735.  
  736.       get(editsource, MUIA_String_Contents, &h);
  737.       strcpy(data->cfg.editsource, h);
  738.  
  739.       get(printtext, MUIA_String_Contents, &h);
  740.       strcpy(data->cfg.printtext, h);
  741.  
  742. /*
  743.       get(openurl, MUIA_String_Contents, &h);
  744.       strcpy(data->cfg.openurl, h);
  745.       strcpy(openurlstr, h);
  746. */
  747.       // Remove window
  748.       DoMethod(app,OM_REMMEMBER,win);    // remove
  749.  
  750.       MUI_DisposeObject(win);            // and kill it
  751.    }
  752.    else puts("Couldn't open config window.");
  753.  
  754.    set(app,MUIA_Application_Sleep,FALSE); // wake up the application
  755.    return(0);
  756. }
  757. ///
  758. /// MainWindow_Iconify
  759. ULONG MainWindow_Iconify(struct IClass *cl,Object *obj,struct Msg *msg)
  760. {
  761. // struct MainWindow_Data *data = INST_DATA(cl,obj);
  762.  
  763.    set((Object *)xget(obj,MUIA_ApplicationObject),MUIA_Application_Iconified,TRUE);
  764.  
  765.    return(0);
  766. }
  767. ///
  768. /// MainWindow_Finish
  769. ULONG MainWindow_Finish(struct IClass *cl,Object *obj,struct Msg *msg)
  770. {
  771. //   struct MainWindow_Data *data = INST_DATA(cl,obj);
  772.    DoMethod((Object *)xget(obj,MUIA_ApplicationObject),MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  773.    return(0);
  774. }
  775. ///
  776. /// MainWindow_About
  777. ULONG MainWindow_About(struct IClass *cl,Object *obj,Msg msg)
  778. {
  779.    Object   *app = (Object *)xget(obj,MUIA_ApplicationObject);
  780.    struct   MainWindow_Data
  781.             *data = INST_DATA(cl,obj);
  782.    FILE     *f;
  783.  
  784.    static const char AboutText[] =
  785.       "<HTML>\n"
  786.       "<HEAD><TITLE>"NAME"</TITLE></HEAD>\n"
  787.       "<BODY>\n"
  788.       "<CENTER>\n"
  789.       "<H1>"NAME"</H1><HR>\n"
  790.       "Version %s<BR>\n"
  791.       "%s<BR>\n"
  792.       "Description: %s"
  793.       "<P>\n"
  794.       "<PRE>\n"
  795.       "This program is free software; you can redistribute it  and/or  modify\n"
  796.       "it  under  the terms of the GNU General Public License as published by\n"
  797.       "the Free Software Foundation; either version 2 of the License, or  (at\n"
  798.       "your option) any later version.\n"
  799.       "\n"
  800.       "This program is distributed in the hope that it will  be  useful,  but\n"
  801.       "WITHOUT   ANY   WARRANTY;   without   even  the  implied  warranty  of\n"
  802.       "MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PURPOSE.  See  the  GNU\n"
  803.       "General Public License for more details.\n"
  804.       "</PRE>\n"
  805.       "</P>\n"
  806.       "ARexx-Port: %s\n"
  807.       "</BODY>\n"
  808.       "</HTML>\n";
  809.  
  810.  
  811.    if(f = fopen(TMPINFO,"w"))
  812.    {
  813.       fprintf(f,
  814.          (char *)AboutText,
  815.          ((char *)xget(app,MUIA_Application_Version))+7+strlen(NAME),
  816.          ((char *)xget(app,MUIA_Application_Copyright)),
  817.          ((char *)xget(app,MUIA_Application_Description)),
  818.          ((char *)xget(app,MUIA_Application_Base)));
  819.       fclose(f);
  820.  
  821.       set(data->html, MUIA_HTMLtext_URL, TMPINFO);
  822.    }
  823.  
  824.    return(0);
  825. }
  826. ///
  827. /// MainWindow_AddURL
  828. ULONG MainWindow_AddURL(struct IClass *cl,Object *obj,struct {ULONG MethodID; char *url;} *msg)
  829. {
  830.    struct MainWindow_Data *data = INST_DATA(cl,obj);
  831.    struct URLlist *act;
  832.  
  833.    get(data->html, MUIA_HTMLtext_URL, &msg->url);
  834.    set(data->file, MUIA_String_Contents, msg->url);
  835.  
  836.    if(msg->url && *msg->url)
  837.    {
  838.       if(act = AllocVec(sizeof(struct URLlist), 0))
  839.       {
  840.          act->next = data->urllist;
  841.          data->urllist = act;
  842.          get(data->html, MUIA_Virtgroup_Top, &act->yoff);
  843.  
  844.          act->url = MyAllocString(msg->url);
  845.       }
  846.  
  847.       data->searchpos = 0;
  848.    }
  849.  
  850.    return(0);
  851. }
  852. ///
  853. /// MainWindow_BackURL
  854. ULONG MainWindow_BackURL(struct IClass *cl,Object *obj,Msg msg)
  855. {
  856.    struct MainWindow_Data *data = INST_DATA(cl,obj);
  857.    struct URLlist *next, *old;
  858.  
  859.    if(data->urllist)
  860.    {
  861.       // Skip recent
  862.       next = data->urllist->next;
  863.       MyFreeString(data->urllist->url);
  864.       FreeVec(data->urllist);
  865.       data->urllist = next;
  866.  
  867.       if(data->urllist)
  868.       {
  869.          // Kill actual, because will be readded
  870.          old = data->urllist;
  871.          data->urllist = data->urllist->next;
  872.  
  873.          set(data->html, MUIA_HTMLtext_URL,  old->url);
  874.          set(data->html, MUIA_Virtgroup_Top, old->yoff);
  875.  
  876.          MyFreeString(old->url);
  877.          FreeVec(old);
  878.       }
  879.    }
  880.    return(0);
  881. }
  882. ///
  883. /// MainWindow_ReloadURL
  884. ULONG MainWindow_ReloadURL(struct IClass *cl,Object *obj,Msg msg)
  885. {
  886.    struct MainWindow_Data *data = INST_DATA(cl,obj);
  887.  
  888.    DoMethod(data->html, MUIM_HTMLtext_Reload);
  889.    return(0);
  890. }
  891. ///
  892. /// IntuiMsgFunc
  893. SAVEDS ASM VOID IntuiMsgFunc(REG(a1) struct IntuiMessage *imsg,REG(a2) struct FileRequester *req)
  894. {
  895.    if (imsg->Class==IDCMP_REFRESHWINDOW)
  896.       DoMethod(req->fr_UserData,MUIM_Application_CheckRefresh);
  897. }
  898. ///
  899. /// getfilename
  900. char *getfilename(char *title,BOOL save, char *path)
  901. {
  902.    static char buf[512];
  903.    struct FileRequester *req;
  904.    struct Window *w;
  905.    static LONG left=-1,top=-1,width=-1,height=-1;
  906.    Object *app = (Object *)xget(win,MUIA_ApplicationObject);
  907.    char *res = NULL;
  908.    static const struct Hook IntuiMsgHook = { { 0,0 },(VOID *)IntuiMsgFunc,NULL,NULL };
  909.  
  910.    get(win,MUIA_Window_Window,&w);
  911.    if (left==-1)
  912.    {
  913.       left   = w->LeftEdge+w->BorderLeft+2;
  914.       top    = w->TopEdge+w->BorderTop+2;
  915.       width  = w->Width-w->BorderLeft-w->BorderRight-4;
  916.       height = w->Height-w->BorderTop-w->BorderBottom-4;
  917.    }
  918.  
  919.    if (req=MUI_AllocAslRequestTags(ASL_FileRequest,
  920.       ASLFR_Window, w,
  921.       ASLFR_TitleText, title,
  922.       ASLFR_InitialLeftEdge, left,
  923.       ASLFR_InitialTopEdge , top,
  924.       ASLFR_InitialWidth   , width,
  925.       ASLFR_InitialHeight  , height,
  926.       ASLFR_InitialDrawer  , path,
  927.       ASLFR_InitialPattern , "#?.(html|htm)",
  928.       ASLFR_DoSaveMode     , save,
  929.       ASLFR_DoPatterns     , TRUE,
  930.       ASLFR_RejectIcons    , TRUE,
  931.       ASLFR_UserData       , app,
  932.       ASLFR_IntuiMsgFunc   , &IntuiMsgHook,
  933.       TAG_DONE))
  934.    {
  935.       set(app,MUIA_Application_Sleep,TRUE);
  936.       if (MUI_AslRequestTags(req,TAG_DONE))
  937.       {
  938.          if (*req->fr_File)
  939.          {
  940.             res = buf;
  941.             stccpy(path,req->fr_Drawer,255);
  942.             stccpy(buf,req->fr_Drawer,sizeof(buf));
  943.             AddPart(buf,req->fr_File,sizeof(buf));
  944.          }
  945.          left   = req->fr_LeftEdge;
  946.          top    = req->fr_TopEdge;
  947.          width  = req->fr_Width;
  948.          height = req->fr_Height;
  949.       }
  950.       MUI_FreeAslRequest(req);
  951.       set(app,MUIA_Application_Sleep,FALSE);
  952.    }
  953.    return(res);
  954. }
  955. ///
  956. /// MainWindow_Action
  957. enum
  958. {
  959.    ACTION_clipblock,
  960.    ACTION_clipsrc,
  961.    ACTION_print,
  962.    ACTION_viewsrc,
  963.    ACTION_editsrc,
  964.    ACTION_geturl,
  965. };
  966.  
  967. ULONG MainWindow_Action(struct IClass *cl,Object *obj,struct {ULONG MethodID; ULONG mode;} *msg)
  968. {
  969.    struct   MainWindow_Data *data = INST_DATA(cl,obj);
  970.    char     buf[120], *text, tmpname[60];
  971.  
  972.    switch(msg->mode)
  973.    {
  974.       // Clip block
  975.       case ACTION_clipblock:
  976.          get(data->html, MUIA_HTMLtext_Block, &text);
  977.          WriteClip(text);
  978.          break;
  979.  
  980.       // Clip source
  981.       case ACTION_clipsrc:
  982.          get(data->html, MUIA_HTMLtext_Contents, &text);
  983.          WriteClip(text);
  984.          break;
  985.  
  986.       // Print text
  987.       case ACTION_print:
  988.          tmpnam(tmpname);
  989.          SaveHTML(data, tmpname);
  990.          sprintf(buf, data->cfg.printtext, tmpname);
  991.          if(buf[0]) system(buf);
  992.          remove(tmpname);
  993.          break;
  994.  
  995.       // View source
  996.       case ACTION_viewsrc:
  997.          tmpnam(tmpname);
  998.          SaveHTML(data, tmpname);
  999.          sprintf(buf, data->cfg.viewsource, tmpname);
  1000.          if(buf[0]) system(buf);
  1001.          remove(tmpname);
  1002.          break;
  1003.  
  1004.       // Edit source
  1005.       case ACTION_editsrc:
  1006.          if(data->urllist)
  1007.          {
  1008.             sprintf(buf, data->cfg.editsource, data->urllist->url);
  1009.             if(buf[0]) system(buf);
  1010.             DoMethod(obj, MUIM_MainWindow_ReloadURL, 0);
  1011.          }
  1012.          break;
  1013.  
  1014.       // Get URL
  1015.       case ACTION_geturl:
  1016.          {
  1017.             ULONG url;
  1018.  
  1019.             get(data->html, MUIA_HTMLtext_URL, &url);
  1020.             return(url);
  1021.          }
  1022.          break;
  1023.    }
  1024.    return(0);
  1025. }
  1026. ///
  1027. /// MainWindow_Find
  1028. enum
  1029. {
  1030.    FIND_new = 1,
  1031.    FIND_word,
  1032.    FIND_next,
  1033.    FIND_first
  1034. };
  1035.  
  1036. ULONG Search(struct MainWindow_Data *data, STRPTR searchstr, ULONG pos, ULONG flags)
  1037. {
  1038.    struct MUIS_HTMLtext_Element *el; //, *ell;
  1039. // Object *app = (Object *)xget(data->html,MUIA_ApplicationObject);
  1040. // char  *str;
  1041.  
  1042.    if(searchstr && *searchstr)
  1043.    {
  1044. //    set(app, MUIA_Application_Sleep, TRUE);
  1045.       get(data->html, MUIA_HTMLtext_ElementList, &el);
  1046.       while(el)
  1047.       {
  1048.          if(!strnicmp(MACRO_HTMLtext_GetText(el), searchstr, strlen(searchstr)))
  1049.          {
  1050.             if(pos)
  1051.                pos--;
  1052.             else
  1053.             {
  1054.                DoMethod(data->html, MUIM_HTMLtext_Mark, el, el);
  1055.                DoMethod(data->html, MUIM_HTMLtext_Jump, el);
  1056.                return(TRUE);
  1057.             }
  1058.          }
  1059.          el = el->next;
  1060.       }
  1061. //    set(app, MUIA_Application_Sleep, FALSE);
  1062.    }
  1063.  
  1064.    return(FALSE);
  1065. }
  1066.  
  1067. ULONG MainWindow_Find(struct IClass *cl,Object *obj,struct {ULONG MethodID; ULONG mode; char *str;} *msg)
  1068. {
  1069.    Object *app = (Object *)xget(obj,MUIA_ApplicationObject);
  1070.    struct MainWindow_Data *data = INST_DATA(cl,obj);
  1071.  
  1072.    switch(msg->mode)
  1073.    {
  1074.       case FIND_new:
  1075.          // Open window and ask
  1076.          {
  1077.             Object   *win, *searchstr, *start;
  1078.             char     *str;
  1079.  
  1080.             set(app,MUIA_Application_Sleep,TRUE);  // disable other windows
  1081.  
  1082.             win =
  1083.                WindowObject,
  1084.                   MUIA_Window_Title, "Find",
  1085.                   MUIA_Window_ID   , MAKE_ID('F','I','N','D'),
  1086.  
  1087.                   WindowContents, VGroup,
  1088.                      Child, LLabel("Find this string:"),
  1089.                      Child, searchstr = StringObject,
  1090.                         StringFrame,
  1091.                         MUIA_CycleChain, 1,
  1092.                         MUIA_String_AdvanceOnCR, TRUE,
  1093.                         MUIA_String_Contents, data->searchstr,
  1094.                         MUIA_ShortHelp, "Will find all words in the text\nbeginning with this string",
  1095.                         End,
  1096.                      Child, start = SimpleButton("_Start"),
  1097.                      End,
  1098.                   End;
  1099.  
  1100.             if (win)                               // ok ?
  1101.             {
  1102.                DoMethod(app,OM_ADDMEMBER,win);    // add window...
  1103.                DoMethod(win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE ,
  1104.                   app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  1105.                DoMethod(start, MUIM_Notify, MUIA_Pressed, FALSE,
  1106.                   app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  1107.  
  1108.                set(start,MUIA_CycleChain, 1);
  1109.                set(win,MUIA_Window_Open,TRUE);    // and open it
  1110.                set(win,MUIA_Window_ActiveObject, searchstr);
  1111.  
  1112.                {
  1113.                   ULONG sigs = 0;
  1114.  
  1115.                   while (DoMethod(app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
  1116.                   {
  1117.                      if (sigs)
  1118.                      {
  1119.                         sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  1120.                         if (sigs & SIGBREAKF_CTRL_C) break;
  1121.                      }
  1122.                   }
  1123.                }
  1124.  
  1125.                set(win,MUIA_Window_Open,FALSE);   // Close window
  1126.  
  1127.                get(searchstr, MUIA_String_Contents, &str);
  1128.                stccpy(data->searchstr, str, sizeof(data->searchstr));
  1129.  
  1130.                // Remove window
  1131.                DoMethod(app,OM_REMMEMBER,win);    // remove
  1132.  
  1133.                MUI_DisposeObject(win);            // and kill it
  1134.             }
  1135.             else puts("Couldn't open search window.");
  1136.  
  1137.             set(app,MUIA_Application_Sleep,FALSE); // wake up the application
  1138.          }
  1139.  
  1140.       case FIND_first:
  1141.          data->searchpos = 0;
  1142.          break;
  1143.  
  1144.       case FIND_word:
  1145.          // Take word from string (AREXX)
  1146.          stccpy(data->searchstr, msg->str, sizeof(data->searchstr));
  1147.          data->searchpos = 0;
  1148.          break;
  1149.  
  1150.    }
  1151.  
  1152.    // Suchen und erhöhen
  1153.    if(!Search(data, data->searchstr, data->searchpos++, 0))
  1154.    {
  1155.       // Am Ende angelang wieder das erste zeigen
  1156.       if(data->searchpos)
  1157.       {
  1158.          data->searchpos = 0;
  1159.          Search(data, data->searchstr, data->searchpos++, 0);
  1160.       }
  1161.       else REQ("String can't be found!","*_OK");
  1162.    }
  1163.  
  1164.    return(0);
  1165. }
  1166. ///
  1167. /// MainWindow_Open
  1168. ULONG MainWindow_Open(struct IClass *cl,Object *obj,struct {ULONG MethodID; char *name;} *msg)
  1169. {
  1170.    struct MainWindow_Data *data = INST_DATA(cl,obj);
  1171.    char *name;
  1172.  
  1173.    if(msg->name)
  1174.    {
  1175.       if(*msg->name == 0)
  1176.          get(data->file, MUIA_String_Contents, &name);
  1177.       else
  1178.          name = msg->name;
  1179.    }
  1180.    else
  1181.    {
  1182.       name = getfilename("Select local file",FALSE,data->path);
  1183.    }
  1184.  
  1185.    if(name)
  1186.    {
  1187.       set(data->html, MUIA_HTMLtext_URL, name);
  1188.       set(obj, MUIA_Window_ActiveObject, data->html);
  1189.    }
  1190.  
  1191.    return(0);
  1192. }
  1193. ///
  1194. /// MainWindow_Save
  1195. ULONG MainWindow_Save(struct IClass *cl,Object *obj,struct {ULONG MethodID; char *name;} *msg)
  1196. {
  1197.    struct MainWindow_Data *data = INST_DATA(cl,obj);
  1198.    char *name;
  1199.  
  1200.    if(msg->name)
  1201.    {
  1202.       name = msg->name;
  1203.    }
  1204.    else
  1205.    {
  1206.       name = getfilename("Select local file",TRUE,data->path);
  1207.    }
  1208.  
  1209.    SaveHTML(data, name);
  1210.    return(0);
  1211. }
  1212. ///
  1213. /// MainWindow_Dispose
  1214. ULONG MainWindow_Dispose(struct IClass *cl,Object *obj,Msg msg)
  1215. {
  1216.    struct MainWindow_Data *data = INST_DATA(cl,obj);
  1217.    struct URLlist *act, *next;
  1218.  
  1219.    DB("Dispose\n");
  1220.  
  1221.    // Free url list
  1222.    act = data->urllist;
  1223.    while(act)
  1224.    {
  1225.       next = act->next;
  1226.       MyFreeString(act->url);
  1227.       FreeVec(act);
  1228.       act = next;
  1229.    }
  1230.  
  1231.    DisposeToolbar(data);
  1232.  
  1233.    DB("End Dispose\n");
  1234.  
  1235.    return(DoSuperMethodA(cl,obj,msg));
  1236. }
  1237. ///
  1238. /// MainWindow_New
  1239. ULONG MainWindow_New(struct IClass *cl,Object *obj,struct opSet *msg)
  1240. {
  1241.    Object *strip;
  1242.    struct MainWindow_Data tmp = {0};
  1243. // static const struct Hook OpenURLHook = { { NULL,NULL },(VOID *)OpenURL ,NULL,NULL };
  1244.    static const struct Hook AppMsgHook = { { NULL,NULL },(VOID *)AppMsgFunc,NULL,NULL };
  1245.  
  1246.    tmp.html = HTMLtextObject,
  1247.       TextFrame,
  1248. //    MUIA_HTMLtext_OpenURLHook, &OpenURLHook,
  1249.       End;
  1250.  
  1251.    // To save the MUI custom class directory structure, we look
  1252.    // for the class also in "libs/mui" of the PROGDIR:
  1253.    if(!tmp.html)
  1254.    {
  1255.       tmp.html =  MUI_NewObject("PROGDIR:libs/mui/HTMLtext.mcc",
  1256.          TextFrame,
  1257. //       MUIA_HTMLtext_OpenURLHook, &OpenURLHook,
  1258.          End;
  1259.    }
  1260.  
  1261.    if (obj = (Object *)DoSuperNew(cl,obj,
  1262.          MUIA_Window_Title, "MoreHTML © Dirk Holtwick, 1997",
  1263.          MUIA_Window_ID   , MAKE_ID('H','T','M','L'),
  1264.          MUIA_Window_UseRightBorderScroller, TRUE,
  1265.          MUIA_Window_UseBottomBorderScroller, TRUE,
  1266.          MUIA_Window_Menustrip, strip = MUI_MakeObject(MUIO_MenustripNM,MainMenu,0),
  1267.          MUIA_Window_AppWindow, TRUE,
  1268.  
  1269.          WindowContents, HGroup,
  1270.             Child, tmp.tool[2] = VGroup,
  1271.                MUIA_VertWeight, 1,
  1272.                Child, VSpace(0),
  1273.                End,
  1274.             Child, VGroup,
  1275.                Child, tmp.tool[0] = HGroup,
  1276.                   Child, HSpace(0),
  1277.                   End,
  1278.  
  1279.                // Infoline
  1280.                Child, tmp.infoline = HGroup,
  1281.                   Child, tmp.file = StringObject,
  1282.                      StringFrame,
  1283.                      MUIA_CycleChain, 1,
  1284.                      End,
  1285.                   End,
  1286.  
  1287.                // HTML object
  1288.                Child, tmp.scroll = ScrollgroupObject,
  1289.                   MUIA_CycleChain, 1,
  1290.                   MUIA_Scrollgroup_UseWinBorder, TRUE,
  1291.                   MUIA_Scrollgroup_Contents, tmp.html,       // 'html' created above
  1292.                   End,
  1293.  
  1294.                Child, tmp.tool[1] = HGroup,
  1295.                   Child, HSpace(0),
  1296.                   End,
  1297.                End,
  1298.             Child, tmp.tool[3] = VGroup,
  1299.                MUIA_VertWeight, 1,
  1300.                Child, VSpace(0),
  1301.                End,
  1302.             End,
  1303.  
  1304.          TAG_MORE,msg->ops_AttrList))
  1305.    {
  1306.       struct MainWindow_Data *data = INST_DATA(cl,obj);
  1307.  
  1308.       *data = tmp;
  1309.  
  1310.       data->win = obj;
  1311.  
  1312.       // Add toolbar
  1313.       CreateToolbar(data);
  1314.  
  1315.       // Methods
  1316.       DoMethod(obj      ,MUIM_Notify,MUIA_Window_CloseRequest,TRUE ,obj,2,MUIM_MainWindow_Finish, 0);
  1317.  
  1318.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_ABOUT    ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1319.          obj,1,MUIM_MainWindow_About);
  1320.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_OPEN     ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1321.          obj,2,MUIM_MainWindow_Open,0);
  1322.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_SAVE     ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1323.          obj,2,MUIM_MainWindow_Save,0);
  1324.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_HIDE     ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1325.          obj,1,MUIM_MainWindow_Iconify);
  1326.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_QUIT     ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1327.          obj,2,MUIM_MainWindow_Finish,0);
  1328.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_FIND     ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1329.          obj,3,MUIM_MainWindow_Find,FIND_new,0);
  1330.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_NEXT     ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1331.          obj,3,MUIM_MainWindow_Find,FIND_next,0);
  1332.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_CPTEXT   ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1333.          obj,2,MUIM_MainWindow_Action,ACTION_clipsrc);
  1334.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_CPBLOCK  ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1335.          obj,2,MUIM_MainWindow_Action,ACTION_clipblock);
  1336.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_PRINT    ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1337.          obj,2,MUIM_MainWindow_Action,ACTION_print);
  1338.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_VIEW     ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1339.          obj,2,MUIM_MainWindow_Action,ACTION_viewsrc);
  1340.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_EDIT     ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1341.          obj,2,MUIM_MainWindow_Action,ACTION_editsrc);
  1342.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_BACK     ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1343.          obj,1,MUIM_MainWindow_BackURL);
  1344.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_RELOAD   ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1345.          obj,1,MUIM_MainWindow_ReloadURL);
  1346.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_CONF     ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1347.          obj,1,MUIM_MainWindow_Config, FALSE);
  1348.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_AMUI     ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1349.          MUIV_Notify_Application,2,MUIM_Application_AboutMUI,obj);
  1350.       DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MEN_MUI      ),MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
  1351.          MUIV_Notify_Application,2,MUIM_Application_OpenConfigWindow,0);
  1352.  
  1353.       // URL
  1354.       DoMethod(data->html,MUIM_Notify,MUIA_HTMLtext_URL,MUIV_EveryTime,
  1355.          obj,2,MUIM_MainWindow_AddURL,MUIV_TriggerValue);
  1356.  
  1357.       // Title
  1358.       DoMethod(data->html,MUIM_Notify,MUIA_HTMLtext_Title,MUIV_EveryTime,
  1359.          obj,3,MUIM_Set,MUIA_Window_Title,MUIV_TriggerValue);
  1360.  
  1361.       // String
  1362.       DoMethod(data->file, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  1363.          obj,2,MUIM_MainWindow_Open,"");
  1364.  
  1365.       // App Msg
  1366.       DoMethod(data->html,MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,
  1367.          data->html,3,MUIM_CallHook,&AppMsgHook,MUIV_TriggerValue);
  1368.  
  1369.       set(obj,MUIA_Window_ActiveObject,data->scroll);
  1370.       set(obj,MUIA_Window_DefaultObject,data->scroll);
  1371.  
  1372.       data->urllist = 0;
  1373.  
  1374.       return((ULONG)obj);
  1375.    }
  1376.    return(0);
  1377. }
  1378. ///
  1379. /// MainWindow_Dispatcher
  1380. SAVEDS ASM ULONG MainWindow_Dispatcher(REG(a0) struct IClass *cl,REG(a2) Object *obj,REG(a1) Msg msg)
  1381. {
  1382.    switch (msg->MethodID)
  1383.    {
  1384.       case OM_NEW                   : return(MainWindow_New       (cl,obj,(APTR)msg));
  1385.       case OM_DISPOSE               : return(MainWindow_Dispose   (cl,obj,(APTR)msg));
  1386.       case MUIM_MainWindow_Finish   : return(MainWindow_Finish    (cl,obj,(APTR)msg));
  1387.       case MUIM_MainWindow_Iconify  : return(MainWindow_Iconify   (cl,obj,(APTR)msg));
  1388.       case MUIM_MainWindow_About    : return(MainWindow_About     (cl,obj,(APTR)msg));
  1389.       case MUIM_MainWindow_AddURL   : return(MainWindow_AddURL    (cl,obj,(APTR)msg));
  1390.       case MUIM_MainWindow_BackURL  : return(MainWindow_BackURL   (cl,obj,(APTR)msg));
  1391.       case MUIM_MainWindow_ReloadURL: return(MainWindow_ReloadURL (cl,obj,(APTR)msg));
  1392.       case MUIM_MainWindow_Open     : return(MainWindow_Open      (cl,obj,(APTR)msg));
  1393.       case MUIM_MainWindow_Save     : return(MainWindow_Save      (cl,obj,(APTR)msg));
  1394.       case MUIM_MainWindow_Config   : return(MainWindow_Config    (cl,obj,(APTR)msg));
  1395.       case MUIM_MainWindow_Action   : return(MainWindow_Action    (cl,obj,(APTR)msg));
  1396.       case MUIM_MainWindow_Find     : return(MainWindow_Find      (cl,obj,(APTR)msg));
  1397.       case MUIM_MainWindow_Rexx     : return(MainWindow_Rexx      (cl,obj,(APTR)msg));
  1398.    }
  1399.    return(DoSuperMethodA(cl,obj,msg));
  1400. }
  1401.  
  1402. ///
  1403.  
  1404. // ARexx
  1405.  
  1406. /// Rexx_URL
  1407. SAVEDS ASM LONG Rexx_URL (REG(a2) Object *app)
  1408. {
  1409.    set(app, MUIA_Application_RexxString,
  1410.       DoMethod(win, MUIM_MainWindow_Action, ACTION_geturl));
  1411.    return(0);
  1412. }
  1413. ///
  1414. /// Rexx_Save
  1415. SAVEDS ASM LONG Rexx_Save (REG(a1) struct {char *name;} *msg)
  1416. {
  1417.    if(msg->name)
  1418.       DoMethod(win, MUIM_MainWindow_Save, msg->name);
  1419.    else
  1420.       DoMethod(win, MUIM_MainWindow_Save, 0);
  1421.  
  1422.    return(0);
  1423. }
  1424. ///
  1425. /// Rexx_Open
  1426. SAVEDS ASM LONG Rexx_Open(REG(a1) struct {char *name;} *msg)
  1427. {
  1428.    if(msg->name)
  1429.       DoMethod(win, MUIM_MainWindow_Open, msg->name);
  1430.    else
  1431.       DoMethod(win, MUIM_MainWindow_Open, 0);
  1432.  
  1433.    return(0);
  1434. }
  1435. ///
  1436. /// Rexx_Find
  1437. SAVEDS ASM LONG Rexx_Find (REG(a1) struct {char *str; LONG first; LONG next;} *msg)
  1438. {
  1439.    if(msg->str)
  1440.       DoMethod(win, MUIM_MainWindow_Find, FIND_word, msg->str);
  1441.    else if(msg->first)
  1442.       DoMethod(win, MUIM_MainWindow_Find, FIND_first, 0);
  1443.    else if(msg->next)
  1444.       DoMethod(win, MUIM_MainWindow_Find, FIND_next, 0);
  1445.    else
  1446.       DoMethod(win, MUIM_MainWindow_Find, FIND_new, 0);
  1447.    return(0);
  1448. }
  1449. ///
  1450. /// Rexx_Print
  1451. SAVEDS ASM LONG Rexx_Print(REG(a1) Msg msg)
  1452. {
  1453.    DoMethod(win, MUIM_MainWindow_Action, ACTION_print);
  1454.    return(0);
  1455. }
  1456. ///
  1457. /// Rexx_View
  1458. SAVEDS ASM LONG Rexx_View(REG(a1) Msg msg)
  1459. {
  1460.    DoMethod(win, MUIM_MainWindow_Action, ACTION_viewsrc);
  1461.    return(0);
  1462. }
  1463. ///
  1464. /// Rexx_Reload
  1465. SAVEDS ASM LONG Rexx_Reload(REG(a1) Msg msg)
  1466. {
  1467.    DoMethod(win, MUIM_MainWindow_ReloadURL);
  1468.    return(0);
  1469. }
  1470. ///
  1471. /// Rexx_Back
  1472. SAVEDS ASM LONG Rexx_Back(REG(a1) Msg msg)
  1473. {
  1474.    DoMethod(win, MUIM_MainWindow_BackURL);
  1475.    return(0);
  1476. }
  1477. ///
  1478. /// Rexx_Edit
  1479. SAVEDS ASM LONG Rexx_Edit(REG(a1) Msg msg)
  1480. {
  1481.    DoMethod(win, MUIM_MainWindow_Action, ACTION_editsrc);
  1482.    return(0);
  1483. }
  1484. ///
  1485.  
  1486. // Init
  1487.  
  1488. /// ExitLibs
  1489. VOID ExitLibs(VOID)
  1490. {
  1491.    if (IntuitionBase) CloseLibrary(IntuitionBase);
  1492.    if (GfxBase      ) CloseLibrary(GfxBase      );
  1493.    if (AslBase      ) CloseLibrary(AslBase      );
  1494.    if (UtilityBase  ) CloseLibrary(UtilityBase  );
  1495.    if (MUIMasterBase) CloseLibrary(MUIMasterBase);
  1496.    if (DataTypesBase) CloseLibrary(DataTypesBase);
  1497. }
  1498. ///
  1499. /// InitLibs
  1500. BOOL InitLibs(VOID)
  1501. {
  1502.    MUIMasterBase = OpenLibrary("muimaster.library",11);
  1503.    UtilityBase   = OpenLibrary("utility.library"  ,36);
  1504.    AslBase       = OpenLibrary("asl.library"      ,36);
  1505.    GfxBase       = OpenLibrary("graphics.library" ,36);
  1506.    IntuitionBase = OpenLibrary("intuition.library",36);
  1507.    DataTypesBase = OpenLibrary("datatypes.library",0);
  1508.  
  1509.    if (MUIMasterBase && UtilityBase && AslBase && GfxBase && IntuitionBase)
  1510.       return(TRUE);
  1511.  
  1512.    ExitLibs();
  1513.    return(FALSE);
  1514. }
  1515. ///
  1516. /// ExitClasses
  1517. VOID ExitClasses(VOID)
  1518. {
  1519.    if (CL_Dtpic       )    MUI_DeleteCustomClass(CL_Dtpic       );
  1520.    if (CL_MainWindow  )    MUI_DeleteCustomClass(CL_MainWindow  );
  1521. }
  1522. ///
  1523. /// InitClasses
  1524. BOOL InitClasses(VOID)
  1525. {
  1526.    CL_MainWindow   = MUI_CreateCustomClass(NULL,MUIC_Window    ,NULL,sizeof(struct MainWindow_Data  )    ,MainWindow_Dispatcher  );
  1527.    CL_Dtpic        = MUI_CreateCustomClass(NULL,MUIC_Area      ,NULL,sizeof(struct DtpicData  )          ,DtpicDispatcher  );
  1528.  
  1529.    if (CL_MainWindow && CL_Dtpic)
  1530.       return(TRUE);
  1531.  
  1532.    ExitClasses();
  1533.    return(FALSE);
  1534. }
  1535. ///
  1536. /// HandleArgs
  1537. const char CLITemplate[] = "URL";
  1538.  
  1539. const char CLIHelp[] =
  1540.    "\n"
  1541.    "\033[1mmoreHTML " VERS "\033[0m\n"
  1542.    "(C)opyright by Dirk Holtwick, 1997\n"
  1543.    "\n"
  1544.    "Usage: moreHTML <url>\n"
  1545.    " <url>   : filename or URL of the file to be displayed\n";
  1546.  
  1547. LONG HandleArgs(char *filename)
  1548. {
  1549.    struct RDArgs *rda,*rdas;
  1550.    LONG msg = 0;
  1551.  
  1552.    struct CLIArgs
  1553.    {
  1554.       char *url;
  1555.    } argarray = { 0 };
  1556.  
  1557.    if (rdas = AllocDosObject(DOS_RDARGS,NULL))
  1558.    {
  1559.       rdas->RDA_ExtHelp = (char *)CLIHelp;
  1560.  
  1561.       if (rda = ReadArgs((char *)CLITemplate,(LONG *)&argarray,rdas))
  1562.       {
  1563.          if (argarray.url)
  1564.          {
  1565.             strcpy(filename, argarray.url);
  1566.          }
  1567.          FreeArgs(rda);
  1568.       }
  1569.       FreeDosObject(DOS_RDARGS,rdas);
  1570.    }
  1571.    return(msg);
  1572. }
  1573. ///
  1574.  
  1575. // Main
  1576.  
  1577. /// Main Program
  1578.  
  1579. int main(int argc,char *argv[])
  1580. {
  1581.    struct   WBStartup *wbmsg;
  1582.    ULONG    sigs=0, id;
  1583.    Object   *app;
  1584.    int      res;
  1585.    int      msg=0;
  1586.    char     filename[256];
  1587.  
  1588.    static const struct Hook Rexx_URLHook       = { { NULL,NULL },(VOID *)Rexx_URL     ,NULL,NULL };
  1589.    static const struct Hook Rexx_SaveHook      = { { NULL,NULL },(VOID *)Rexx_Save    ,NULL,NULL };
  1590.    static const struct Hook Rexx_OpenHook      = { { NULL,NULL },(VOID *)Rexx_Open    ,NULL,NULL };
  1591.    static const struct Hook Rexx_PrintHook     = { { NULL,NULL },(void *)Rexx_Print   ,NULL,NULL };
  1592.    static const struct Hook Rexx_BackHook      = { { NULL,NULL },(void *)Rexx_Back    ,NULL,NULL };
  1593.    static const struct Hook Rexx_ReloadHook    = { { NULL,NULL },(void *)Rexx_Reload  ,NULL,NULL };
  1594.    static const struct Hook Rexx_ViewHook      = { { NULL,NULL },(void *)Rexx_View    ,NULL,NULL };
  1595.    static const struct Hook Rexx_FindHook      = { { NULL,NULL },(void *)Rexx_Find    ,NULL,NULL };
  1596.    static const struct Hook Rexx_EditHook      = { { NULL,NULL },(void *)Rexx_Edit    ,NULL,NULL };
  1597.  
  1598.    // ARexx commands
  1599.    static struct MUI_Command commands[] =
  1600.    {
  1601.       { "url"       ,""                    , 0        , (void *)&Rexx_URLHook     },
  1602.       { "save"      ,"file/k"              , 1        , (void *)&Rexx_SaveHook    },
  1603.       { "open"      ,"url=file/k"          , 1        , (void *)&Rexx_OpenHook    },
  1604.       { "find"      ,"string=word/k,first=top/s,next/s"
  1605.                                            , 3        , (void *)&Rexx_FindHook    },
  1606.       { "print"     ,""                    , 0        , (void *)&Rexx_PrintHook   },
  1607.       { "back"      ,""                    , 0        , (void *)&Rexx_BackHook    },
  1608.       { "reload"    ,""                    , 0        , (void *)&Rexx_ReloadHook  },
  1609.       { "view"      ,""                    , 0        , (void *)&Rexx_ViewHook    },
  1610.       { "edit"      ,""                    , 0        , (void *)&Rexx_EditHook    },
  1611.       { NULL        , NULL                 , NULL     , NULL                      }
  1612.    };
  1613.  
  1614.    DB("\n*** moreHTML ***\n");
  1615.  
  1616.    filename[0] = 0;
  1617.  
  1618.    // Starting from CLI
  1619.    if(argc!=0)
  1620.    {
  1621.       HandleArgs(filename);
  1622.    }
  1623.    // Starting from WB
  1624.    else
  1625.    {
  1626.       wbmsg = (struct WBStartup *)argv;
  1627.  
  1628.       if(wbmsg->sm_NumArgs>=2)
  1629.       {
  1630.          NameFromLock(wbmsg->sm_ArgList[1].wa_Lock,filename,255);
  1631.          AddPart(filename,wbmsg->sm_ArgList[1].wa_Name,255);
  1632.       }
  1633.    }
  1634.  
  1635. // InitLocale();
  1636.  
  1637.    if (InitLibs())
  1638.    {
  1639.  
  1640.       if (InitClasses())
  1641.       {
  1642.  
  1643.          app = ApplicationObject,
  1644.             MUIA_Application_Title      , NAME,
  1645.             MUIA_Application_Version    , "$VER: " NAME" " VERS " " __AMIGADATE__,
  1646.             MUIA_Application_Copyright  , "Copyright © Dirk Holtwick, 1997",
  1647.             MUIA_Application_Author     , "Dirk Holtwick",
  1648.             MUIA_Application_Description, "Simple HTML viewer based on HTMLtext.mcc",
  1649.             MUIA_Application_Base       , "MOREHTML",
  1650. //          MUIA_Application_SingleTask , TRUE,
  1651.             MUIA_Application_Commands   , commands,
  1652.             MUIA_Application_Window     , win  = NewObject(CL_MainWindow->mcc_Class,NULL,TAG_DONE),
  1653.             End;
  1654.  
  1655.          if (app)
  1656.          {
  1657.             // Get configuration
  1658.             DoMethod(win, MUIM_MainWindow_Config, TRUE);
  1659.  
  1660.             // Open window before a text is loaded,
  1661.             // otherwise the background is crippled
  1662.             set(win,MUIA_Window_Open,TRUE);
  1663.  
  1664.             if(filename[0]) DoMethod(win, MUIM_MainWindow_Open,filename);
  1665.  
  1666.             while ((id = DoMethod(app,MUIM_Application_NewInput,&sigs)) != MUIV_Application_ReturnID_Quit)
  1667.             {
  1668.                if (sigs)
  1669.                {
  1670.                   sigs = Wait(sigs | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_E | SIGBREAKF_CTRL_F);
  1671.  
  1672.                   /* quit when receiving break from console */
  1673.                   if (sigs & SIGBREAKF_CTRL_C)
  1674.                      break;
  1675.  
  1676.                   /* deiconify & activate on ctrl-f just like the other prefs programs */
  1677.                   if (sigs & SIGBREAKF_CTRL_F)
  1678.                   {
  1679.                      set(app,MUIA_Application_Iconified,FALSE);
  1680.                      set(win,MUIA_Window_Open,TRUE);
  1681.                   }
  1682.                }
  1683.             }
  1684.  
  1685.             // Remove temporary rexx file
  1686.             remove(TMPREXX);
  1687.             remove(TMPINFO);
  1688.  
  1689.             set(win,MUIA_Window_Open,FALSE);
  1690.          }
  1691.          MUI_DisposeObject(app);
  1692.          ExitClasses();
  1693.       }
  1694.       ExitLibs();
  1695.    }
  1696.  
  1697.    if (msg)
  1698.    {
  1699. /*
  1700.       char *str = GetStr(msg);
  1701.       char *c = strchr(str,'(');
  1702.       Write(Output(),str,strlen(str));
  1703.       res = c ? atol(c+1) : RETURN_OK;
  1704. */
  1705.       res = RETURN_OK;
  1706.    }
  1707.    else
  1708.       res = RETURN_OK;
  1709.  
  1710. //   ExitLocale();
  1711.  
  1712.    DB("*** finish ***\n");
  1713.  
  1714.    exit(res);
  1715. }
  1716. ///
  1717.  
  1718.