home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / MUI / MCCHTMLT.LHA / MCC_HTMLtext / Developer / C / Examples / HTMLtext-DEMO.c
Encoding:
C/C++ Source or Header  |  1997-04-02  |  5.5 KB  |  222 lines

  1. // **********************************
  2. // HTMLtext-DEMO
  3. // (C)opyright by Dirk Holtwick, 1997
  4. // **********************************
  5.  
  6. // This demo is kind of a WYSIWYG editor for HTML.
  7. // Just edit the string in the gadget and you will
  8. // see the effect in the same moment.
  9.  
  10. // If you have problems, please report me the bug
  11. // and send me the text that leaded to confusion.
  12.  
  13. /// Includes
  14. #include <workbench/startup.h>
  15. #include <clib/alib_protos.h>
  16. #include <proto/dos.h>
  17. #include <proto/exec.h>
  18. #include <proto/intuition.h>
  19. #include <proto/graphics.h>
  20. #include <proto/asl.h>
  21. #include <proto/utility.h>
  22. #include <proto/muimaster.h>
  23. #include <proto/icon.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26.  
  27. // #include <mui/html_mcc.h>
  28. #include "include/HTMLtext_mcc.h"
  29.  
  30. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  31.  
  32. extern struct Library *SysBase;
  33.  
  34. /*  ATTENTION !!!
  35. **  HTMLtext.mcc makes use of recursion and so you
  36. **  have to take care, that there is always
  37. **  enough space on the stack. The more the better!
  38. */
  39.  
  40. LONG __stack = 8192;
  41. ///
  42.  
  43. /// Demotext
  44. #define DEMOTEXT \
  45.     "<html>This <i>is a <small>small</small> <big>Demo</big></i> of " \
  46.     "the <b>HTMLtext class.</b><br> "\
  47.     "Try to drop a HTML file in this window! " \
  48.     "<p align=right>Yours Dirk</html>"
  49. ///
  50. /// Pointers
  51. APTR app;
  52. APTR window;
  53. APTR str;
  54. APTR html;
  55. APTR scroll;
  56. APTR url;
  57. ///
  58.  
  59. /// AppMsgFunc
  60. __saveds __asm LONG AppMsgFunc(register __a2 APTR obj, register __a1 struct AppMessage **x)
  61. {
  62.     /*
  63.      *   Very simple functions to parse the
  64.      *   AppMessage and set URL
  65.      *   (Taken from AppWindow.c)
  66.      */
  67.  
  68.     struct WBArg *ap;
  69.     struct AppMessage *amsg = *x;
  70.     static char buf[256];
  71.  
  72.     if(amsg->am_NumArgs)
  73.     {
  74.         ap=amsg->am_ArgList;
  75.         NameFromLock(ap->wa_Lock,buf,sizeof(buf));
  76.         AddPart(buf,ap->wa_Name,sizeof(buf));
  77.         set(obj,MUIA_HTMLtext_URL,buf);
  78.     }
  79.  
  80.     return(0);
  81. }
  82. ///
  83. /// Main
  84. int main(int argc,char *argv[])
  85. {
  86.     struct   Library *IntuitionBase;
  87.     int      ret=RETURN_ERROR;
  88.     static   const struct Hook AppMsgHook = { { NULL,NULL },(VOID *)AppMsgFunc,NULL,NULL };
  89.  
  90.     if(IntuitionBase = OpenLibrary("intuition.library", 36))
  91.     {
  92.         struct Library *MUIMasterBase;
  93.  
  94.         if(MUIMasterBase = OpenLibrary(MUIMASTER_NAME, 13))
  95.         {
  96.             ULONG signals;
  97.             BOOL running = TRUE;
  98.  
  99.             // Load the text
  100.             app = ApplicationObject,
  101.                 MUIA_Application_Title      , "HTMLtext-DEMO",
  102.                 MUIA_Application_Version    , "$VER: HTMLtext-DEMO 1.0 " __AMIGADATE__,
  103.                 MUIA_Application_Copyright  , "(C)opyright by Dirk Holtwick 1997",
  104.                 MUIA_Application_Author     , "Dirk Holtwick",
  105.                 MUIA_Application_Description, "Uses the HTMLtext.mcc to display text.",
  106.                 MUIA_Application_Base       , "HTMLTEXTDEMO",
  107.  
  108.                 SubWindow, window = WindowObject,
  109.                     MUIA_Window_Title, "HTMLtext-Demo © Dirk Holtwick, 1997",
  110.                     MUIA_Window_ID   , MAKE_ID('D','E','M','O'),
  111.                     MUIA_Window_UseRightBorderScroller, TRUE,
  112.                     MUIA_Window_UseBottomBorderScroller, TRUE,
  113.                     MUIA_Window_AppWindow, TRUE,
  114.  
  115.                     WindowContents, VGroup,
  116.  
  117.                         Child, url = TextObject,
  118.                             TextFrame,
  119.                             MUIA_Font, MUIV_Font_Tiny,
  120.                             MUIA_Background, MUII_TextBack,
  121.                             MUIA_Text_Contents, ">>> No URL <<<",
  122.                             End,
  123.  
  124.                         Child, scroll = ScrollgroupObject,
  125.                             MUIA_CycleChain, 1,
  126.                             MUIA_Scrollgroup_UseWinBorder, TRUE,
  127.                             MUIA_Scrollgroup_Contents, html = HTMLtextObject,
  128.                                 TextFrame,
  129.                                 MUIA_HTMLtext_Contents, DEMOTEXT,
  130.                                 End,
  131.                             End,
  132.  
  133.                         Child, str = StringObject,
  134.                             StringFrame,
  135.                             MUIA_CycleChain, 1,
  136.                             MUIA_String_MaxLen, 1024,
  137.                             End,
  138.                         End,
  139.                     End,
  140.                 End;
  141.  
  142.             if(app)
  143.             {
  144.                 /*** generate notifies ***/
  145.  
  146.                 DoMethod(window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  147.                     app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  148.  
  149.                 /*** after modification of string contents refresh HTML object ***/
  150.                 DoMethod(str,MUIM_Notify,MUIA_String_Contents,MUIV_EveryTime,
  151.                     html,3,MUIM_Set,MUIA_HTMLtext_Contents,MUIV_TriggerValue);
  152.  
  153.                 /*** string gadgets will always be active ***/
  154.                 DoMethod(str,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  155.                     window,3,MUIM_Set,MUIA_Window_ActiveObject,str);
  156.  
  157.                 /*** react if someone droped an icon on the HTML object ***/
  158.                 DoMethod(html,MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,
  159.                     html,3,MUIM_CallHook,&AppMsgHook,MUIV_TriggerValue);
  160.  
  161.                 /*** display title in windows title bar ***/
  162.                 DoMethod(html,MUIM_Notify,MUIA_HTMLtext_Title,MUIV_EveryTime,
  163.                     window,3,MUIM_Set,MUIA_Window_Title,MUIV_TriggerValue);
  164.  
  165.                 /*** display current URL ***/
  166.                 DoMethod(html,MUIM_Notify,MUIA_HTMLtext_URL,MUIV_EveryTime,
  167.                     url,3,MUIM_Set,MUIA_Text_Contents,MUIV_TriggerValue);
  168.  
  169.                 /*** ready to open the window ... ***/
  170.                 set(window,MUIA_Window_ActiveObject,str);
  171.                 set(window,MUIA_Window_DefaultObject,str);
  172.  
  173.                 set(window,MUIA_Window_Open,TRUE);
  174.  
  175.                 set(str, MUIA_String_Contents, DEMOTEXT);
  176.  
  177.                 while (running)
  178.                 {
  179.                     switch(DoMethod(app,MUIM_Application_Input,&signals))
  180.                     {
  181.                         case MUIV_Application_ReturnID_Quit:
  182.                             running = FALSE;
  183.                             break;
  184.                     }
  185.  
  186.                     if(running && signals)
  187.                         Wait(signals);
  188.                 }
  189.  
  190.                 set(window, MUIA_Window_Open, FALSE);
  191.  
  192.                 MUI_DisposeObject(app);
  193.  
  194.                 ret = RETURN_OK;
  195.             }
  196.             else
  197.             {
  198.                 puts("Could not open application!");
  199.                 ret = RETURN_FAIL;
  200.             }
  201.  
  202.             CloseLibrary(MUIMasterBase);
  203.         }
  204.         else
  205.         {
  206.             puts("Could not open muimaster.library v13!");
  207.             ret = RETURN_FAIL;
  208.         }
  209.  
  210.         CloseLibrary(IntuitionBase);
  211.     }
  212.     else
  213.     {
  214.         puts("Could not open intuition.library v36!");
  215.         ret = RETURN_FAIL;
  216.     }
  217.  
  218.     return(ret);
  219. }
  220. ///
  221.  
  222.