home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / visualarts-1.0.lha / VisualArts-1.0 / Demo / Source / MultiSub.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-09  |  6.5 KB  |  239 lines

  1. /* ******************************************************************** */
  2. /* C code generated by:                            */
  3. /* Visual Arts Version 1.0                        */
  4. /* Copyright 1994 Danny Y. Wong  All rights reserved            */
  5. /* Calgary, Alberta (CANADA)                                    */
  6. /* Partial of the code is copyright by Jaba Development            */
  7. /* ******************************************************************** */
  8.  
  9. /*
  10.    this is the sub program which the main program will call.  It will
  11.    open the window and waits for events.  Code generated with following
  12.    preference settings:
  13.    
  14.    entry name:  void MultiSub(void)
  15.    project name: Models
  16.    code options:  every option except screens
  17.    
  18.    Note that the project is the Models that given in the 'Attr' in the
  19.    window setting in the layout editor.
  20. */   
  21.  
  22. #include <exec/types.h>
  23. #include <exec/memory.h>
  24. #include <exec/lists.h>
  25. #include <exec/nodes.h>
  26. #include <intuition/intuitionbase.h>
  27. #include <intuition/intuition.h>
  28. #include <intuition/gadgetclass.h>
  29. #include <graphics/displayinfo.h>
  30. #include <graphics/gfxbase.h>
  31. #include <graphics/gfxmacros.h>
  32. #include <libraries/gadtools.h>
  33. #include <libraries/dos.h>
  34. #include <libraries/asl.h>
  35.  
  36. #include <clib/exec_protos.h>
  37. #include <clib/intuition_protos.h>
  38. #include <clib/gadtools_protos.h>
  39. #include <clib/graphics_protos.h>
  40. #include <clib/utility_protos.h>
  41. #include <clib/alib_protos.h>
  42. #include <clib/dos_protos.h>
  43. #include <clib/asl_protos.h>
  44. #include "string.h" 
  45. #include "stdlib.h" 
  46.  
  47. #define ID_numbers                                    0
  48. #define ID_numlist                                    1
  49.  
  50. #define Window2NumGads            2
  51. #include "MultiSub.h" 
  52.  
  53. int numbersObj(struct VAobject VAObject);
  54. int numlistObj(struct VAobject VAObject);
  55.  
  56. int OpenWindow2Window(char windtitle[80]);
  57. void CloseWindow2Window(void);
  58. int Window2Handler(void);
  59. int Window2MainHandler(void);
  60. void DrawWindow2Objs(void);
  61. void MultiSub(void);
  62.  
  63. extern struct WindowNode    *ModelsActiveWind;
  64. struct Gadget            *Window2GList = NULL;
  65. struct Gadget            *Window2Gadgets[2];
  66. struct IntuiMessage         Window2Msg;
  67. UWORD                 Window2Left = 238;
  68. UWORD                 Window2Top = 29;
  69. UWORD                 Window2Width = 217;
  70. UWORD                 Window2Height = 93;
  71. extern struct IntuitionBase    *IntuitionBase;
  72. extern struct List        *ModelsWindList;
  73. extern UWORD             ModelsTotalWindows;
  74. UWORD                 Window2NumWindows = 0;
  75. extern struct TextAttr topaz800;
  76.  
  77. UBYTE *NumbersLabels[] = {
  78.     (UBYTE *)"One", 
  79.     (UBYTE *)"Two", 
  80.     (UBYTE *)"Three", 
  81.     (UBYTE *)"Four", 
  82.     (UBYTE *)"Five", 
  83.     NULL
  84. };
  85.  
  86. WORD Window2GadTypes[] = {
  87.     CYCLE_KIND,
  88.     LISTVIEW_KIND,
  89. };
  90.  
  91. struct NewGadget Window2NGads[] = {
  92.     79, 2, 122, 13, (UBYTE *)"Numbers", &topaz800, ID_numbers, PLACETEXT_LEFT, NULL, (APTR)numbersObj,
  93.     19, 31, 188, 44, (UBYTE *)"Numbers", &topaz800, ID_numlist, PLACETEXT_ABOVE, NULL, (APTR)numlistObj,
  94. };
  95.  
  96. ULONG Window2NTags[] = {
  97.     (GTCY_Labels), (ULONG)&NumbersLabels[0], (GTCY_Active), 3, TAG_DONE,
  98.     (GTLV_Labels), NULL, (GTLV_Top), 0, (GTLV_ScrollWidth), 16, (GTLV_ShowSelected), NULL, (LAYOUTA_Spacing), 0, TAG_DONE,
  99. };
  100.  
  101.  
  102. int OpenWindow2Window(char windtitle[80])
  103. {
  104.   struct NewGadget    NewGad;
  105.   struct Gadget       *Gad;
  106.   register UWORD i, j;
  107.   UWORD offsetx = Scr->WBorLeft;
  108.   UWORD offsety = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  109.  
  110.  if (Window2NumWindows == 0)
  111.  {
  112.   if (!(Gad = CreateContext(&Window2GList)))
  113.       return(1L);
  114.  
  115.   for (i=0, j=0; i < Window2NumGads; i++)
  116.   {
  117.     CopyMem((char *)&Window2NGads[i], (char *)&NewGad, (long)sizeof(struct NewGadget));
  118.  
  119.     NewGad.ng_VisualInfo = VisualInfo;
  120.     NewGad.ng_LeftEdge += offsetx;
  121.     NewGad.ng_TopEdge  += offsety;
  122.  
  123.     Window2Gadgets[i] = Gad = CreateGadgetA((ULONG)Window2GadTypes[i], Gad,&NewGad,
  124.     (struct TagItem *)&Window2NTags[j]);
  125.     while (Window2NTags[j])
  126.         j +=2;
  127.     j++;
  128.     if (!Gad)
  129.        return(2L);
  130.   }
  131.  }
  132.   if (!(ModelsActiveWind = AddWindowNode(ModelsWindList, windtitle, Window2Handler)))
  133.      return(1);
  134.   if (!(ModelsActiveWind->nn_Window = OpenWindowTags(NULL,
  135.       WA_Left,    Window2Left,
  136.       WA_Top,     Window2Top,
  137.       WA_Width,    Window2Width,
  138.       WA_Height,    Window2Height - Scr->WBorTop,
  139.       WA_IDCMP,    IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_VANILLAKEY | IDCMP_INTUITICKS | IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW ,
  140.       WA_Flags,    WFLG_CLOSEGADGET  |  WFLG_SMART_REFRESH |  WFLG_RMBTRAP |  WFLG_DRAGBAR ,
  141.       WA_Gadgets,    Window2GList,
  142.       WA_Title,    windtitle,
  143.       WA_ScreenTitle,    "Visual Arts V1.0 Copyright 1994 Danny Y. Wong  All Rights Reserved.",
  144.       WA_PubScreen,    Scr,
  145.       WA_MinWidth,    20,
  146.       WA_MinHeight,    10,
  147.       WA_MaxWidth,    640,
  148.       WA_MaxHeight,    200,
  149.       TAG_DONE)))
  150.           return(3L);
  151.  
  152.   GT_RefreshWindow(ModelsActiveWind->nn_Window, NULL);
  153.   if (++Window2NumWindows == 1)
  154.     CreateWindow2Lists();
  155.   GT_SetGadgetAttrs(Window2Gadgets[1], ModelsActiveWind->nn_Window, NULL,
  156.      GTLV_Labels, Window2Lists[0], TAG_END);
  157.   RefreshGadgets(Window2Gadgets[0], ModelsActiveWind->nn_Window, NULL);
  158.   return(0L);
  159. }
  160.  
  161. int Window2Handler(void)
  162. {
  163.   struct IntuiMessage    *msg;
  164.   struct VAobject    VAObject;
  165.   int running    = 1;
  166.   int (*func)(struct VAobject VAObject);
  167.   struct WindowNode *WindNode;
  168.   ULONG class;
  169.   UWORD code;
  170.  
  171.   while (msg=GT_GetIMsg(ModelsActiveWind->nn_Window->UserPort))
  172.   {
  173.     CopyMem((char *)msg, (char *)&Window2Msg, (long)sizeof(struct IntuiMessage));
  174.     class = msg->Class;
  175.     code  = msg->Code;
  176.  
  177.     GT_ReplyIMsg(msg);
  178.     switch(class)
  179.     {
  180.  
  181.       case IDCMP_MOUSEBUTTONS :
  182.         break;
  183.  
  184.       case IDCMP_MOUSEMOVE :
  185.         break;
  186.  
  187.       case IDCMP_GADGETDOWN :
  188.         break;
  189.  
  190.       case IDCMP_INTUITICKS :
  191.         break;
  192.  
  193.       case IDCMP_CLOSEWINDOW:
  194.          CloseModelsWindow();
  195.          if (--Window2NumWindows == 0)
  196.          {
  197.              if (Window2GList)
  198.                 FreeGadgets(Window2GList);
  199.              for (running=0; running < 1; running++)
  200.                 FreeList(Window2Lists[running]);
  201.          }
  202.          return(1);
  203.          break;
  204.  
  205.       case IDCMP_ACTIVEWINDOW:
  206.       case IDCMP_INACTIVEWINDOW:
  207.         if (!IntuitionBase->ActiveWindow)
  208.         {
  209.         ActivateWindow(ModelsActiveWind->nn_Window);
  210.         break;
  211.         }
  212.         WindNode = FindWindowNode(ModelsWindList, IntuitionBase->ActiveWindow->Title);
  213.         if (WindNode)
  214.         ModelsActiveWind = WindNode;
  215.         break;
  216.  
  217.       case IDCMP_GADGETUP:
  218.         VAObject.va_Window = (struct Window *)ModelsActiveWind->nn_Window ;
  219.         VAObject.va_Gadget = (struct Gadget *)msg->IAddress;
  220.         VAObject.va_IntuiMsg = (struct IntuiMessage *)msg;
  221.         VAObject.va_Flags = 0;
  222.         VAObject.va_UserData = 0;
  223.         func = (void *)((struct Gadget *)Window2Msg.IAddress)->UserData;
  224.         running =  func(VAObject);
  225.         break;
  226.     }
  227.   }
  228.   return(running);
  229. }
  230.  
  231. void MultiSub(void)
  232. {
  233.   int rc;
  234.  
  235.     for (rc=0; rc < 1; rc++)
  236.       Window2Lists[rc]=GetNewList();
  237.     rc = OpenWindow2Window("MultiProcess");
  238. }
  239.