home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Programming / MR_Classes / Dev / Source / supermodel / model_SuperIC.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-29  |  7.3 KB  |  363 lines

  1. #include <tagitemmacros.h>
  2. //#define DEBUG
  3. #include <debug.h>
  4.  
  5. #include "supermodel.h"
  6. #include "protos.h"
  7. #include <classes/supermodel.h>
  8. #include <clib/alib_protos.h>
  9.  
  10. #include <intuition/gadgetclass.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/classes.h>
  13. #include <intuition/icclass.h>
  14.  
  15. #include <proto/utility.h>
  16. #include <proto/intuition.h>
  17.  
  18. Class *SuperICClass;
  19. LONG  GadgetIDKludge=-1;
  20.  
  21. BOOL i_SuperICInit(void)
  22. {
  23.   if(SuperICClass=i_MakeClass(0,(STRPTR)"icclass", 0,sizeof(struct SuperICData), 0, SuperIC_Dispatch))
  24.   {
  25.     return(1);
  26.   }
  27.   return(0);
  28. }
  29.  
  30.  
  31. void i_SuperICTerm(void)
  32. {
  33.   if(SuperICClass)
  34.   {
  35.     FreeClass(SuperICClass);
  36.     SuperICClass=0;
  37.   }
  38. }
  39.  
  40.  
  41.  
  42.  
  43. /****** supermodel.class/SM_NewSuperIC ******************************************
  44. *
  45. *   NAME
  46. *       SM_NewSuperIC -- Allocare SuperIC object
  47. *
  48. *   SYNOPSIS
  49. *
  50. *
  51. *
  52. *
  53. *
  54. *
  55. *   FUNCTION
  56. *
  57. *
  58. *   INPUTS
  59. *
  60. *   RESULT
  61. *
  62. *   EXAMPLE
  63. *
  64. *   NOTES
  65. *
  66. *   BUGS
  67. *
  68. *   SEE ALSO
  69. *
  70. ******************************************************************************
  71. *
  72. */
  73.  
  74.  
  75. Object __asm *LIB_SM_NewSuperICA(register __a0 struct TagItem *TagList)
  76. {
  77.   return(NewObjectA(SuperICClass, 0, (APTR)TagList));
  78. }
  79.  
  80.  
  81.  
  82. Object __asm *LIB_SM_SICMAPA(register __a0 Object *Target, register __a1 struct TagItem *MapList)
  83. {
  84.  return(NewObject(SuperICClass, 0, ICA_TARGET,        Target,
  85.                                    ICA_MAP,           MapList,
  86.                                    TAG_DONE));
  87. }
  88.  
  89. ULONG SuperIC_Set(Class *CL, Object *O, struct opSet *Set);
  90. void SuperIC_ClearMaps(Class *CL, Object *O);
  91. void SuperIC_SetMaps(Class *CL, Object *O);
  92.  
  93. ULONG __asm __saveds SuperIC_Dispatch(register __a0 Class *CL, register __a2 Object *O, register __a1 Msg M, register __a6 struct Library *LibBase)
  94. {
  95.   ULONG retval=0;
  96.   struct SuperICData *data;
  97.  
  98.   data=INST_DATA(CL,O);
  99.  
  100. //  kprintf("Disp\n");
  101.  
  102.  
  103. //  DKP("{ SuperIC-----------\n");
  104.   NEST  
  105.   
  106.   switch(M->MethodID)
  107.   {
  108.     case OM_NEW:
  109.       {
  110.         retval=DoSuperMethodA(CL,O,M);
  111.         O=(APTR)retval;
  112.         
  113.         //data=INST_DATA(CL,O);
  114.         SuperIC_Set(CL,O,(APTR)M);
  115.       }
  116.       break;
  117.  
  118.     case OM_DISPOSE:
  119. //    DKP("OM_DISPOSE\n");
  120.       SuperIC_ClearMaps(CL,O);
  121.       FreeTagItems(data->Map);
  122.       FreeTagItems(data->TMap);
  123.       
  124.       retval=DoSuperMethodA(CL,O,M);
  125.       break;
  126.     
  127.     case OM_SET:
  128.     case OM_UPDATE:
  129. //    DKP("OM_SET/UPDATE\n");
  130.         SuperIC_Set(CL,O,(APTR)M);
  131.         if(data->Notify)
  132.         {
  133.           struct TagItem *ntags;
  134.           struct opSet *s,ns;
  135.  
  136.           data->Notify=0;          
  137.  
  138. //          DKP("1\n");
  139.           
  140.           s=(APTR)M;
  141.           
  142.           if(ntags=CloneTagItems(s->ops_AttrList))
  143.           {
  144. //              DKP("  tags cloned\n");
  145.             ns=*s;
  146. //            kprintf("  updating id %ld from %ld\n",data->ID.ti_Data, GetTagData(GA_ID, 0, s->ops_AttrList));
  147.             if(data->Map)
  148.             {
  149. //              DKP("  mapping tags\n");              
  150.               MapTags(ntags, data->Map, MAP_REMOVE_NOT_FOUND);
  151.             }
  152.             ns.ops_AttrList=ntags;
  153.             
  154.           
  155.             retval=DoSuperMethodA(CL,O,(Msg)&ns);
  156.             FreeTagItems(ntags);
  157.           }
  158.  
  159.         }
  160.         else
  161.           retval=0;
  162.         break;
  163.     default:
  164.       retval=DoSuperMethodA(CL,O,M);
  165.   }
  166.   
  167.   UNNEST
  168. //  DKP("} SuperIC-----------\n");
  169.   
  170.   
  171.   return(retval);
  172. }
  173.  
  174. #define ISOBJECT(x) ( (x) && (ICTARGET_IDCMP!=(ULONG)(x)) )
  175.  
  176. ULONG SuperIC_Set(Class *CL, Object *O, struct opSet *Set)
  177. {
  178.   struct SuperICData *data;
  179.   struct TagItem *tag, *tstate;
  180.   ULONG d;
  181.  
  182.   data=INST_DATA(CL,O);
  183.  
  184.   tstate=Set->ops_AttrList;
  185.   while(tag=NextTagItem(&tstate))
  186.   {
  187.     d=tag->ti_Data;
  188.     switch(tag->ti_Tag)
  189.     {
  190.       case SICA_Model:
  191. //        DKP("SICA_Model %8lx\n",d);
  192.         data->Model=(Object *)d;
  193.         if(data->Target)
  194.         {
  195.           SetAttrs(data->Target, ICA_TARGET, data->Model, TAG_DONE);
  196.         }
  197.         break;
  198.       
  199.       case ICA_TARGET:
  200. //        DKP("ICA_TARGET %lx\n",d);
  201.         if(data->Target)
  202.         {
  203.           SetAttrs(data->Target, 
  204.               ICA_MAP,    0, 
  205.               ICA_TARGET, 0,
  206.               TAG_DONE);
  207.         }
  208.         
  209.         data->Target=(APTR)d;
  210.  
  211.         if(ISOBJECT(data->Target))
  212.         {
  213.           // Gadget Targets Model
  214.           // IC Targets Gadget
  215.           
  216.           SetSuperAttrs(CL,O,ICA_TARGET, data->Target, 0);
  217.           
  218.           if(SM_IsMemberOf((Object *)d,0,(APTR)"gadgetclass"))
  219.           {
  220.             struct Gadget *g;
  221.             
  222.             g=(APTR)d;
  223.           
  224.             if(g->GadgetID==0)
  225.             {
  226.               g->GadgetID=GadgetIDKludge;
  227.               GadgetIDKludge--;
  228.             }
  229.           
  230.             data->ID.ti_Data=g->GadgetID;
  231.             data->ID.ti_Tag=GA_ID;
  232.           }
  233.           
  234.           SetAttrs(data->Target, 
  235.                 ICA_MAP,    data->TMap, 
  236.                 ICA_TARGET, data->Model,
  237.                 TAG_DONE);
  238.         }
  239.         break;
  240.         
  241.       case ICA_MAP:
  242. //      DKP("ICA_MAP %lx\n",d);
  243.         /* dereference old maps */
  244.         SuperIC_ClearMaps(CL,O);
  245.  
  246.         /* Dump old tags */
  247.         FreeTagItems(data->Map);  // Safe w/NULL
  248.         FreeTagItems(data->TMap);  
  249.         data->Map=data->TMap=0;
  250.  
  251.         if(d)
  252.         {
  253.           data->TMap=CloneTagItems((APTR)d);
  254.           if(data->Map=CloneTagItems((APTR)d))
  255.           {
  256.             struct TagItem  *ctag, 
  257.                             *ctstate;
  258.             
  259.             ctstate=data->Map;
  260.             
  261.              /* flip tag map */            
  262.             while(ctag=NextTagItem(&ctstate))
  263.             {
  264.               ULONG d;
  265.               
  266.               d             = ctag->ti_Tag;
  267.               ctag->ti_Tag  = ctag->ti_Data;
  268.               ctag->ti_Data = d;
  269.             }
  270.           }
  271.         }   
  272.         // 
  273.         SuperIC_SetMaps(CL,O);
  274.         break;
  275.       
  276.       case SICA_InMap:
  277.         SuperIC_ClearMaps(CL,O);
  278.         FreeTagItems(data->Map);  // Safe w/NULL
  279.         data->Map=(APTR)d;
  280.         SuperIC_SetMaps(CL,O);
  281.         break;
  282.         
  283.       case SICA_OutMap:
  284.         SuperIC_ClearMaps(CL,O);
  285.         FreeTagItems(data->TMap);  // Safe w/NULL
  286.         data->TMap=(APTR)d;
  287.         SuperIC_SetMaps(CL,O);
  288.         break;
  289.         
  290.       default:
  291. //        DKP("Unknown Tag %08lx\n",tag->ti_Tag);
  292.         if(FindTagItem(tag->ti_Tag, data->Map))
  293.         {
  294. //          DKP("Notify set\n");
  295.           data->Notify=1;
  296.         }
  297.         break;
  298.     }
  299.   }
  300.   
  301.   if(tag=FindTagItem(data->ID.ti_Tag, Set->ops_AttrList))
  302.   { 
  303.     if(tag->ti_Data==data->ID.ti_Data) /* don't notify object that started update */
  304.     {
  305.       data->Notify=0;
  306. //      return(0);
  307.     }
  308.   }
  309.         
  310.    /* see if there's a match in the Map list */            
  311. /*  tstate=data->Map;
  312.   while(tag=NextTagItem(&tstate))
  313.   {
  314.     if(FindTagItem(tag->ti_Tag, Set->ops_AttrList))
  315.       break;
  316.   }
  317.   if(!tag) return(0);
  318.   */
  319.   
  320.   return(1);
  321. }
  322.  
  323.  
  324. void SuperIC_ClearMaps(Class *CL, Object *O)
  325. {
  326.   struct SuperICData *data;
  327.  
  328.   data=INST_DATA(CL,O);
  329.  
  330.   if(ISOBJECT(data->Target))
  331.   {
  332.     SetAttrs(data->Target, 
  333.               ICA_MAP,      0, 
  334.               TAG_DONE);
  335.   }
  336.   
  337.   SetSuperAttrs(CL,O,
  338.             ICA_MAP,      0, 
  339.             0);
  340.  
  341. }
  342.  
  343. void SuperIC_SetMaps(Class *CL, Object *O)
  344. {
  345.   struct SuperICData *data;
  346.  
  347.   data=INST_DATA(CL,O);
  348.  
  349.   if(ISOBJECT(data->Target))
  350.   {
  351.     SetAttrs(data->Target, 
  352.               ICA_MAP,      data->TMap, 
  353.               TAG_DONE);
  354.   }
  355.               
  356.    SetSuperAttrs(CL,O,
  357.             ICA_MAP,    data->Map, 
  358.             TAG_DONE);
  359.  
  360. }
  361.  
  362.  
  363.