home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / ftp.vapor.com / voyager / voyager-sdk.lzx / zapster_mcc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-15  |  6.0 KB  |  267 lines

  1. /*
  2. ** Zapster MUI custom class
  3. ** ------------------------
  4. ** - Dummy example plugin for Voyager
  5. **
  6. ** ⌐ 2000 by David Gerber <zapek@vapor.com>
  7. ** All rights reserved
  8. **
  9. ** Unregistered MUI class, serial number: 4023706747
  10. **
  11. ** $Id$
  12. **
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17.  
  18. /* OS */
  19. #include <proto/exec.h>
  20. #include <exec/execbase.h>
  21. #include <proto/dos.h>
  22. #include <dos.h>
  23. #include <dos/dostags.h>
  24. #include <proto/graphics.h>
  25. #include <proto/utility.h>
  26. #include <proto/muimaster.h>
  27.  
  28.  
  29. /* Own includes */
  30. #include "zapster_mcc.h"
  31. #include "v_plugin.h"
  32.  
  33. extern struct vplug_functable *ft;
  34. extern void Fail(STRPTR txt);
  35.  
  36. extern __stdargs DoSuperNew(struct IClass *class, APTR obj, ULONG tag1, ...);
  37.  
  38.  
  39. static ULONG handleOM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
  40. {
  41.     struct Data *data;
  42.     struct TagItem *tag;
  43.     STRPTR *argnames;
  44.     STRPTR *argvalues;
  45.     ULONG argcnt;
  46.  
  47.     if (!(obj = (Object *)DoSuperNew(cl, obj, 
  48.         InnerSpacing(0, 0),
  49.         MUIA_FillArea, FALSE,
  50.         MUIA_Font, MUIV_Font_Tiny,
  51.         TAG_MORE, msg->ops_AttrList
  52.     )))
  53.     return(0);
  54.  
  55.     data = INST_DATA(cl, obj);
  56.  
  57.     /*
  58.      * Here we get our net stream. It's the stream specified in the SRC tag of
  59.      * the <EMBED> tag. If you need to open another stream you have to use
  60.      * vplug_net_openurl()
  61.      */
  62.     if (data->nethandle = (char *)GetTagData(VPLUG_EmbedInfo_NetStream, NULL, msg->ops_AttrList))
  63.     {
  64.         data->loading = TRUE; 
  65.         
  66.         /*
  67.          * Then we need to set a target to get progress methods. Those methods are
  68.          * VPLUG_NetStream_GotInfo, VPLUG_NetStream_GotData and VPLUG_NetStream_GotDone.
  69.          */
  70.         ft->vplug_net_settomem(data->nethandle);
  71.  
  72.         /*
  73.          * And we try to get the length (may fail with servers
  74.          * not returning it)
  75.          */
  76.         data->length = ft->vplug_net_getdoclen(data->nethandle);
  77.     }
  78.  
  79.     /*
  80.      * As an example we get some options passed in the <EMBED>
  81.      */
  82.     if (tag = FindTagItem(VPLUG_EmbedInfo_ArgNames, msg->ops_AttrList))
  83.     {
  84.         argnames = (STRPTR *)tag->ti_Data;
  85.     }
  86.  
  87.     if (tag = FindTagItem(VPLUG_EmbedInfo_ArgValues, msg->ops_AttrList))
  88.     {
  89.         argvalues = (STRPTR *)tag->ti_Data;
  90.     }
  91.  
  92.     if (tag = FindTagItem(VPLUG_EmbedInfo_ArgCnt, msg->ops_AttrList))
  93.     {
  94.         argcnt = tag->ti_Data;
  95.     }
  96.  
  97.     /*
  98.      * Then we can process them as we like
  99.      */
  100.  
  101.     return((ULONG)obj);
  102. }
  103.  
  104.  
  105. static ULONG handleMUIM_AskMinMax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg)
  106. {
  107.     DoSuperMethodA(cl, obj, (Msg)msg);
  108.     msg->MinMaxInfo->MaxWidth  += MUI_MAXMAX;
  109.     msg->MinMaxInfo->MaxHeight += MUI_MAXMAX;
  110.     return(0);
  111. }
  112.  
  113.  
  114. static ULONG handleMUIM_Setup(struct IClass *cl, Object *obj, struct MUIP_Setup *msg)
  115. {
  116.     struct Data *data = INST_DATA(cl, obj);
  117.     struct ColorMap *cmap = _screen(obj)->ViewPort.ColorMap;
  118.  
  119.     if (!DoSuperMethodA(cl, obj, (Msg)msg))
  120.     {
  121.         return(FALSE);
  122.     }
  123.  
  124.     /*
  125.      * Allocate some pens
  126.      */
  127.     data->pen_bg = ObtainBestPen(cmap,
  128.         0xffffffff, 0xffffffff, 0xffffffff, TAG_DONE
  129.     );
  130.  
  131.     data->pen_fg = ObtainBestPen(cmap,
  132.         0xffffffff, 0x00000000, 0x00000000, TAG_DONE
  133.     );
  134.  
  135.     return(TRUE);
  136. }
  137.  
  138.  
  139. static ULONG handleMUIM_Cleanup(struct IClass *cl, Object *obj, struct MUIP_Cleanup *msg)
  140. {
  141.     struct Data *data = INST_DATA(cl, obj);
  142.     
  143.     struct ColorMap *cmap = _screen(obj)->ViewPort.ColorMap;
  144.  
  145.     if (data->pen_fg != -1)
  146.     {
  147.         ReleasePen(cmap, data->pen_fg);
  148.     }
  149.  
  150.     if (data->pen_bg != -1)
  151.     {
  152.         ReleasePen(cmap, data->pen_bg);
  153.     }
  154.  
  155.     return(DoSuperMethodA(cl,obj,(Msg)msg));
  156. }
  157.  
  158.  
  159. static ULONG handleVPLUG_NetStream_GotData(struct IClass *cl, Object *obj, ULONG *msg)
  160. {
  161.     struct Data *data = INST_DATA(cl, obj);    
  162.     
  163.     /*
  164.      * Here we update a progress indicator
  165.      */
  166.     if (data->length)
  167.     {
  168.         sprintf(data->status, "Got %ld/%ld bytes", ft->vplug_net_getdocptr(data->nethandle), data->length);
  169.     }
  170.     else
  171.     {
  172.         sprintf(data->status, "Got %ld bytes", ft->vplug_net_getdocptr(data->nethandle));
  173.     }
  174.     MUI_Redraw(obj, MADF_DRAWUPDATE);
  175.  
  176.     return(0);
  177. }
  178.  
  179.  
  180. static ULONG handleVPLUG_NetStream_GotDone(struct IClass *cl, Object *obj, ULONG *msg)
  181. {
  182.     struct Data *data = INST_DATA(cl, obj);    
  183.     
  184.     data->loading = FALSE;
  185.  
  186.     MUI_Redraw(obj, MADF_DRAWUPDATE);
  187.  
  188.     return(0);
  189. }
  190.  
  191.  
  192.  
  193. static ULONG handleMUIM_Draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg)
  194. {
  195.     struct Data *data = INST_DATA(cl, obj);
  196.  
  197.     DoSuperMethodA(cl, obj, (Msg)msg);
  198.  
  199.     if (data->pen_fg != -1 && data->pen_bg != -1)
  200.     {
  201.         /*
  202.          * We can do all the rendering here
  203.          */
  204.         if (data->loading)
  205.         {
  206.             APTR clip;
  207.             int y = _mtop(obj) + _font(obj)->tf_Baseline + 2;
  208.  
  209.             /*
  210.              * Displaying the loading status. Zapster doesn't do any streaming :)
  211.              */
  212.             SetFont(_rp(obj), _font(obj));
  213.             SetAPen(_rp(obj), data->pen_bg);
  214.             RectFill(_rp(obj), _mleft(obj), _mtop(obj), _mright(obj), _mbottom(obj));
  215.                 
  216.             SetAPen(_rp(obj), data->pen_fg);
  217.  
  218.             clip = MUI_AddClipping(muiRenderInfo(obj), _mleft(obj), _mtop(obj), _mwidth(obj), _mheight(obj));
  219.  
  220.             Move(_rp(obj), _mleft(obj) + 2, y);
  221.             Text(_rp(obj), data->status, strlen(data->status));
  222.  
  223.             MUI_RemoveClipping(muiRenderInfo(obj), clip);
  224.         }
  225.         else
  226.         {
  227.             /*
  228.              * Rendering...
  229.              */
  230.             SetAPen(_rp(obj), data->pen_bg);
  231.             RectFill(_rp(obj), _mleft(obj), _mtop(obj), _mright(obj), _mbottom(obj));
  232.             
  233.             SetAPen(_rp(obj), data->pen_fg);
  234.             SetBPen(_rp(obj), data->pen_bg);
  235.  
  236.             Move(_rp(obj), _mleft(obj), _mtop(obj));
  237.             Draw(_rp(obj), _mright(obj), _mtop(obj));
  238.             Draw(_rp(obj), _mleft(obj), _mbottom(obj));
  239.             Draw(_rp(obj), _mright(obj), _mbottom(obj));
  240.         }
  241.     }
  242.     return(0);
  243. }
  244.  
  245.  
  246. ULONG __asm __saveds dispatch(register __a0 struct IClass *cl, register __a2  Object *obj, register __a1 Msg msg)
  247. {
  248.     /*
  249.      * We need to restore the near data pointer.
  250.      * This *HAS* to be done in every dispatcher !
  251.      */
  252.     putreg(REG_A4, cl->cl_UserData);
  253.     
  254.     switch (msg->MethodID)
  255.     {
  256.         case OM_NEW:                    return(handleOM_NEW(cl, obj, (APTR)msg));
  257.         case MUIM_Setup:                return(handleMUIM_Setup(cl, obj, (APTR)msg));
  258.         case MUIM_Cleanup:                  return(handleMUIM_Cleanup(cl, obj, (APTR)msg));
  259.         case MUIM_AskMinMax:              return(handleMUIM_AskMinMax(cl, obj, (APTR)msg));
  260.         case MUIM_Draw:                      return(handleMUIM_Draw(cl, obj, (APTR)msg));
  261.         case VPLUG_NetStream_GotData:   return(handleVPLUG_NetStream_GotData(cl, obj, (APTR)msg));
  262.         case VPLUG_NetStream_GotDone:   return(handleVPLUG_NetStream_GotDone(cl, obj, (APTR)msg));
  263.     }
  264.     return(DoSuperMethodA(cl,obj,(Msg)msg));
  265. }
  266.  
  267.