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

  1. // Dtpic Class
  2. // (C)opyright by Stefan Stuntz
  3. // Modified by Dirk Holtwick, 1997
  4.  
  5. /// Includes
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. #include <clib/alib_protos.h>
  11. #include <clib/exec_protos.h>
  12. #include <clib/dos_protos.h>
  13. #include <clib/icon_protos.h>
  14. #include <clib/graphics_protos.h>
  15. #include <clib/intuition_protos.h>
  16. #include <clib/utility_protos.h>
  17. #include <clib/datatypes_protos.h>
  18. #include <clib/muimaster_protos.h>
  19.  
  20. #include <pragmas/exec_pragmas.h>
  21. #include <pragmas/dos_pragmas.h>
  22. #include <pragmas/icon_pragmas.h>
  23. #include <pragmas/graphics_pragmas.h>
  24. #include <pragmas/intuition_pragmas.h>
  25. #include <pragmas/utility_pragmas.h>
  26. #include <pragmas/datatypes_pragmas.h>
  27. #include <pragmas/muimaster_pragmas.h>
  28.  
  29. #include <dos/dos.h>
  30. #include <libraries/mui.h>
  31. #include <datatypes/pictureclass.h>
  32. #include <datatypes/pictureclassext.h>
  33. #include <graphics/gfxmacros.h>
  34.  
  35. #include "dtpic.h"
  36.  
  37. extern struct Library *DataTypesBase;
  38. extern struct Library *UtilityBase;
  39. extern struct Library *IntuitionBase;
  40. extern struct Library *GfxBase;
  41. ///
  42. /// New
  43. ULONG _mNew(struct IClass *cl,Object *obj,Msg msg)
  44. {
  45.    struct DtpicData *data;
  46.    char   *name;
  47.  
  48.    if (!(obj=(Object *)DoSuperMethodA(cl,obj,msg)))
  49.       return(0);
  50.  
  51.    data = INST_DATA(cl,obj);
  52.  
  53.    memset(data, 0, sizeof(struct DtpicData));
  54.  
  55.    name = (char *)GetTagData(MUIA_Dtpic_Name,NULL,((struct opSet *)msg)->ops_AttrList);
  56.  
  57.    if(name)
  58.    {
  59.       if(data->name = AllocVec(strlen(name)+1,0))
  60.          strcpy(data->name, name);
  61.    }
  62.  
  63.    set(obj,MUIA_FillArea,FALSE);
  64.  
  65.    return((ULONG)obj);
  66. }
  67. ///
  68. /// Dispose
  69. ULONG _mDispose(struct IClass *cl, Object *obj, Msg msg)
  70. {
  71.    struct DtpicData *data = INST_DATA(cl, obj);
  72.  
  73.    if(data->name)
  74.    {
  75.       FreeVec(data->name);
  76.       data->name = 0;
  77.    }
  78.  
  79.    return(DoSuperMethodA(cl,obj,msg));
  80. }
  81. ///
  82. /// freedto
  83. static VOID freedto(struct DtpicData *data)
  84. {
  85.    data->bitmap = NULL;
  86.    data->bmhd = NULL;
  87.  
  88.    if (data->dto)
  89.    {
  90.       DisposeDTObject(data->dto);
  91.       data->dto = NULL;
  92.    }
  93. }
  94. ///
  95. /// Setup
  96. ULONG _mSetup(struct IClass *cl,Object *obj,Msg msg)
  97. {
  98.    struct DtpicData *data = INST_DATA(cl,obj);
  99.  
  100.    if (!DoSuperMethodA(cl,obj,msg))
  101.       return(FALSE);
  102.  
  103.    if (data->name)
  104.    {
  105.       /* tell DOS not to bother us with requesters */
  106.       struct Process *myproc = (struct Process *)FindTask(NULL);
  107.       APTR oldwindowptr = myproc->pr_WindowPtr;
  108.       myproc->pr_WindowPtr = (APTR)-1;
  109.  
  110.       /* create the datatypes object */
  111.       data->dto = NewDTObject(data->name,
  112.          DTA_GroupID          , GID_PICTURE,
  113.          OBP_Precision        , PRECISION_EXACT,
  114.          PDTA_Screen          , _screen(obj),
  115.          PDTA_FreeSourceBitMap, TRUE,
  116.          PDTA_DestMode        , MODE_V43,
  117.          PDTA_UseFriendBitMap , TRUE,
  118.          TAG_DONE);
  119.  
  120.       myproc->pr_WindowPtr = oldwindowptr;
  121.  
  122.       /* do all the setup/layout stuff that's necessary to get a bitmap from the dto    */
  123.       /* note that when using V43 datatypes, this might not be a real "struct BitMap *" */
  124.  
  125.       if (data->dto)
  126.       {
  127.          struct FrameInfo fri = {NULL};
  128.  
  129.          DoMethod(data->dto,DTM_FRAMEBOX,NULL,&fri,&fri,sizeof(struct FrameInfo),0);
  130.  
  131.          if (fri.fri_Dimensions.Depth>0)
  132.          {
  133.             if (DoMethod(data->dto,DTM_PROCLAYOUT,NULL,1))
  134.             {
  135.                get(data->dto,PDTA_BitMapHeader,&data->bmhd);
  136.  
  137.                if (data->bmhd)
  138.                {
  139.                   GetDTAttrs(data->dto,PDTA_DestBitMap,&data->bitmap,TAG_DONE);
  140.  
  141.                   if (!data->bitmap)
  142.                      GetDTAttrs(data->dto,PDTA_BitMap,&data->bitmap,TAG_DONE);
  143.  
  144.                   if (data->bitmap)
  145.                   {
  146.                      return(TRUE);
  147.                   }
  148.                }
  149.             }
  150.          }
  151.       }
  152.    }
  153.    freedto(data);
  154.    return(TRUE);
  155. }
  156. ///
  157. /// Cleanup
  158. ULONG _mCleanup(struct IClass *cl,Object *obj,Msg msg)
  159. {
  160.    struct DtpicData *data = INST_DATA(cl,obj);
  161.    freedto(data);
  162.    return(DoSuperMethodA(cl,obj,msg));
  163. }
  164. ///
  165. /// AskMinMax
  166. ULONG _mAskMinMax(struct IClass *cl,Object *obj,struct MUIP_AskMinMax *msg)
  167. {
  168.    struct DtpicData *data = INST_DATA(cl,obj);
  169.    struct MUI_MinMax *mi;
  170.  
  171.    DoSuperMethodA(cl,obj,(void *)msg);
  172.  
  173.    mi = msg->MinMaxInfo;
  174.  
  175.    if (data->bitmap)
  176.    {
  177.       mi->MinWidth  += data->bmhd->bmh_Width ;
  178.       mi->MinHeight += data->bmhd->bmh_Height;
  179.       mi->DefWidth  += data->bmhd->bmh_Width ;
  180.       mi->DefHeight += data->bmhd->bmh_Height;
  181.       mi->MaxWidth  += data->bmhd->bmh_Width ;
  182.       mi->MaxHeight += data->bmhd->bmh_Height;
  183.    }
  184.  
  185.    /* if we have no bitmap, our object's size will be 0 */
  186.  
  187.    return(0);
  188. }
  189. ///
  190. /// Draw
  191. ULONG _mDraw(struct IClass *cl,Object *obj,struct MUIP_Draw *msg)
  192. {
  193.    struct DtpicData *data = INST_DATA(cl,obj);
  194.  
  195.    DoSuperMethodA(cl,obj,(void *)msg);
  196.  
  197.    if (msg->flags & MADF_DRAWOBJECT)
  198.    {
  199.       if (data->bitmap)
  200.       {
  201.          BltBitMapRastPort(data->bitmap,0,0,_rp(obj),_mleft(obj),_mtop(obj),_mwidth(obj),_mheight(obj),0xc0);
  202.       }
  203.    }
  204.  
  205.    return(0);
  206. }
  207. ///
  208. /// Dispatcher
  209. ULONG __saveds __asm DtpicDispatcher(register __a0 struct IClass *cl,register __a2 Object *obj,register __a1 Msg msg)
  210. {
  211.    switch (msg->MethodID)
  212.    {
  213.       case OM_NEW        : return(_mNew      (cl,obj,(APTR)msg));
  214.       case OM_DISPOSE    : return(_mDispose  (cl,obj,(APTR)msg));
  215.       case MUIM_Setup    : return(_mSetup    (cl,obj,(APTR)msg));
  216.       case MUIM_Cleanup  : return(_mCleanup  (cl,obj,(APTR)msg));
  217.       case MUIM_AskMinMax: return(_mAskMinMax(cl,obj,(APTR)msg));
  218.       case MUIM_Draw     : return(_mDraw     (cl,obj,(APTR)msg));
  219.    }
  220.  
  221.    return(DoSuperMethodA(cl,obj,msg));
  222. }
  223. ///
  224.  
  225.