home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Programming / MR_Classes / Dev / Examples / SuperModel / Test.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-04  |  5.4 KB  |  202 lines

  1. #define DEBUG
  2. #include <debug.h>
  3.  
  4. #include <clib/alib_protos.h>
  5. #include <intuition/classusr.h>
  6.  
  7. #include <intuition/gadgetclass.h>
  8.  
  9. #include <intuition/icclass.h>
  10. #include <proto/intuition.h>
  11. #include <proto/exec.h>
  12. #include <proto/utility.h>
  13. #include <proto/dos.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16.  
  17. #include <string.h>
  18.  
  19. #include <tagitemmacros.h>
  20.  
  21. #include <proto/classes/supermodel.h>
  22. #include <classes/supermodel.h>
  23.  
  24. #define APP_Number    (TAG_USER + 1)
  25. #define APP_Something (TAG_USER + 2)
  26.  
  27. struct Library *SuperModelBase;
  28.  
  29. ULONG __asm __saveds GlueCode(register __a0 struct  smaGlueData *GD,
  30.                               register __a1 struct  TagItem *TagList, 
  31.                               register __a2 APTR    UserData);
  32.  
  33.  
  34. void main(void)
  35. {
  36.   Object *model;
  37.   struct Gadget *prop,*str1,*str2;
  38.   struct Window *win;
  39.   ULONG go;
  40.   
  41.   if(SuperModelBase=OpenLibrary("supermodel.class",44))
  42.   {
  43.     prop=(APTR)NewObject(0,"propgclass", 
  44.                 GA_Top, 30, 
  45.                 GA_Left, 10, 
  46.                 GA_Height, 10, 
  47.                 GA_Width, 100, 
  48.                 GA_Immediate, 1,
  49.                 PGA_Total, 100,
  50.                 PGA_Visible,1,
  51.                 PGA_Freedom, FREEHORIZ,
  52.                 TAG_DONE);
  53.     str1=(APTR)NewObject(0,"strgclass", 
  54.                 GA_Top, 60, 
  55.                 GA_Left, 10, 
  56.                 GA_Height, 10, 
  57.                 GA_Width, 100, 
  58.                 STRINGA_LongVal, 0, 
  59.                 STRINGA_MaxChars, 7,
  60.                 STRINGA_Pens, 0x00000100,
  61.                 STRINGA_ActivePens, 0x00000302,
  62.                 GA_Previous,  prop,
  63.                 TAG_DONE);
  64.     str2=(APTR)NewObject(0,"strgclass", 
  65.                 GA_Top, 80, 
  66.                 GA_Left, 10, 
  67.                 GA_Height, 10, 
  68.                 GA_Width, 100, 
  69.                 STRINGA_TextVal, "0",
  70.                 STRINGA_MaxChars, 24,
  71.                 STRINGA_Pens, 0x00000100,
  72.                 STRINGA_ActivePens, 0x00000302,
  73.                 GA_Previous,  str1,
  74.                 TAG_DONE);
  75.  
  76.     model=SM_NewSuperModel(
  77.             ICA_TARGET,    ICTARGET_IDCMP,
  78.             
  79.             SMA_CacheStringTag, APP_Something,
  80.   
  81.             SMA_GlueFunc,         GlueCode,
  82.             
  83.             SMA_AddMember, SM_SICMAP((APTR)prop, PGA_Top,         APP_Number, TAG_DONE),
  84.             SMA_AddMember, SM_SICMAP((APTR)str1, STRINGA_LongVal, APP_Number, TAG_DONE),
  85.             SMA_AddMember, SM_SICMAP((APTR)str2, STRINGA_TextVal, APP_Something, TAG_DONE),
  86.             
  87.             TAG_DONE);
  88.             
  89.  
  90.     /* By setting the attributes on the model, all gadgets get updated */
  91.     SetAttrs(model, APP_Number,25, TAG_DONE);
  92.     
  93.     win=OpenWindowTags(0, WA_InnerWidth,        120, 
  94.                           WA_InnerHeight,       100, 
  95.                           WA_DragBar,           1,
  96.                           WA_CloseGadget,       1,
  97.                           WA_Gadgets,           prop,
  98.                           WA_IDCMP,             IDCMP_CLOSEWINDOW | IDCMP_IDCMPUPDATE,
  99.                           TAG_DONE);
  100.  
  101.     printf("Gadgets added\n");
  102.  
  103.     go=1;
  104.     while(go)
  105.     {
  106.       struct IntuiMessage *imsg;
  107.       
  108.       WaitPort(win->UserPort);
  109.       
  110.       while(imsg=(APTR)GetMsg(win->UserPort))
  111.       {
  112.         switch(imsg->Class)
  113.         {
  114.           case IDCMP_CLOSEWINDOW:
  115.             go=0;
  116.             break;
  117.           case IDCMP_IDCMPUPDATE:
  118.             {
  119.               struct TagItem *tag,*taglist,*tstate;
  120.               
  121.               taglist=imsg->IAddress;
  122.               
  123.               ProcessTagList(taglist,tag,tstate)
  124.               {
  125.                 switch(tag->ti_Tag)
  126.                 {
  127.                   case APP_Number:
  128.                     printf("APP_Number %d\n",tag->ti_Data);
  129.                     break;
  130.                   case APP_Something: // this tag isn't always safe to read
  131.                     printf("APP_Something %08lx %s  (This tag can't always be read!)\n",tag->ti_Data,tag->ti_Data);
  132.                     break;
  133.                 }
  134.               }
  135.               
  136.             }
  137.             break;
  138.         }
  139.       }
  140.     }
  141.  
  142.     CloseWindow(win);
  143.     DisposeObject(model);
  144.     DisposeObject(prop);
  145.     DisposeObject(str1);
  146.     DisposeObject(str2);
  147.     CloseLibrary(SuperModelBase); 
  148.   }
  149. }
  150.  
  151. // runs on input.device!
  152. ULONG __asm __saveds GlueCode(register __a0 struct  smaGlueData *GD,
  153.                               register __a1 struct  TagItem *TagList, 
  154.                               register __a2 APTR    UserData)
  155. {
  156.   ULONG id,retval=0;
  157.   struct TagItem *tstate,*tag, *mytags;
  158.   char buf[8];
  159.   
  160.   id=GetTagData(GA_ID, 0, TagList);
  161.   
  162.   if(mytags=SMTAG_AllocTags(10))
  163.   {
  164.     ProcessTagList(TagList,tag,tstate)
  165.     {
  166.       ULONG t,d;
  167.       
  168.       t=tag->ti_Tag;
  169.       d=tag->ti_Data;
  170.       
  171.       switch(t)
  172.       {
  173.         case APP_Number:
  174.           {
  175.             // Convert APP_Number to hex string, and add APP_Something
  176.             // Note that the buffer is on the stack, and that when 
  177.             // the task tries to print this string, it is bad.
  178.             stci_h(buf,d); 
  179.             SMTAG_AddTag(mytags, APP_Something, (ULONG)buf);
  180.           }
  181.           break;
  182.         
  183.         case APP_Something:
  184.           if(d)
  185.           {
  186.             ULONG i;
  187.             
  188.             stch_i(d,&i);
  189.             SMTAG_AddTag(mytags, APP_Number,      i);
  190.           }        
  191.           break;
  192.       }
  193.     }
  194.     SMTAG_TagMore(mytags, TagList);
  195.     retval=SM_SendGlueAttrsA(GD, mytags);
  196.     SMTAG_FreeTags(mytags);
  197.   }
  198.   return(retval);
  199. }
  200.  
  201.  
  202.