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 / MultiMain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-09  |  9.2 KB  |  347 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. /*  this program demostrates the MultiProcessing windows.  The source
  10.     was generated with the ALL option set.  I also added two additional
  11.     lines in order to link to the sub program.
  12.     
  13.     extern void MultiSub(void);  //our sub program
  14.     
  15.     MultiSub();  //at the main which called to open the window
  16.  
  17.  
  18.     Note: when you select the CLOSEGADGET codes are executed to close
  19.     down the multiprocessing windows.  If you exist the event handling
  20.     loop with a return, the window will lock up and will not be closed.
  21.     If you have a button for existing, you should duplicate the codes
  22.     in the IDCMP_CLOSEWINDOW and place it where you would exit the loop.
  23.     This will ensure that the window with be closed.  You could make this
  24.     a function for existing where you can easily be called.  This will be
  25.     fixed for registed users.
  26. */    
  27.  
  28.  
  29. #include <exec/types.h>
  30. #include <exec/memory.h>
  31. #include <exec/lists.h>
  32. #include <exec/nodes.h>
  33. #include <intuition/intuitionbase.h>
  34. #include <intuition/intuition.h>
  35. #include <intuition/gadgetclass.h>
  36. #include <graphics/displayinfo.h>
  37. #include <graphics/gfxbase.h>
  38. #include <graphics/gfxmacros.h>
  39. #include <libraries/gadtools.h>
  40. #include <libraries/dos.h>
  41.  
  42. #include <clib/exec_protos.h>
  43. #include <clib/intuition_protos.h>
  44. #include <clib/gadtools_protos.h>
  45. #include <clib/graphics_protos.h>
  46. #include <clib/utility_protos.h>
  47. #include <clib/alib_protos.h>
  48. #include <clib/dos_protos.h>
  49. #include <clib/asl_protos.h>
  50. #include "string.h" 
  51. #include "stdlib.h" 
  52.  
  53. #define ID_models                                     0
  54.  
  55. #define ModelsNumGads            1
  56. #include "MultiMain.h" 
  57.  
  58. extern void MultiSub(void);     //extern program
  59.  
  60. int modelsObj(struct VAobject VAObject);
  61.  
  62. int GetPubScreen(void);
  63. void ClosePubScreen(void);
  64. int OpenModelsWindow(char windtitle[80]);
  65. void CloseModelsWindow(void);
  66. int ModelsHandler(void);
  67. int ModelsMainHandler(void);
  68. void DrawModelsObjs(void);
  69. int main(int argc, char *argv[]);
  70.  
  71. UBYTE                *PubScrName = NULL;
  72. APTR                 VisualInfo = NULL;
  73. struct Screen            *Scr = NULL;
  74. struct WindowNode        *ModelsActiveWind = NULL;
  75. struct Gadget            *ModelsGList = NULL;
  76. struct Gadget            *ModelsGadgets[1];
  77. struct IntuiMessage         ModelsMsg;
  78. UWORD                 ModelsLeft = 30;
  79. UWORD                 ModelsTop = 29;
  80. UWORD                 ModelsWidth = 186;
  81. UWORD                 ModelsHeight = 93;
  82. struct IntuitionBase        *IntuitionBase = NULL;
  83. struct List            *ModelsWindList;
  84. UWORD                 ModelsTotalWindows = 0;
  85. UWORD                 ModelsNumWindows = 0;
  86. struct TextAttr topaz800 = { (STRPTR)"topaz.font", 8, 0x00, 0x00 };
  87. struct TextAttr topaz8465 = { (STRPTR)"topaz.font", 8, 4, 65 };
  88.  
  89. UBYTE *ModelsLabels[] = {
  90.     (UBYTE *)"Amiga 500", 
  91.     (UBYTE *)"Amiga 600", 
  92.     (UBYTE *)"Amiga 1000", 
  93.     (UBYTE *)"Amiga 1200", 
  94.     (UBYTE *)"Amiga 2000", 
  95.     (UBYTE *)"Amiga 2500", 
  96.     (UBYTE *)"Amiga 2500HD", 
  97.     (UBYTE *)"Amiga 3000", 
  98.     (UBYTE *)"Amiga Unix", 
  99.     (UBYTE *)"Amiga 4000", 
  100.     (UBYTE *)"Amiga 4000T", 
  101.     (UBYTE *)"Amiga CDTV", 
  102.     (UBYTE *)"Amiga CD32", 
  103.     NULL
  104. };
  105.  
  106. WORD ModelsGadTypes[] = {
  107.     LISTVIEW_KIND,
  108. };
  109.  
  110. struct NewGadget ModelsNGads[] = {
  111.     6, 2, 163, 76, (UBYTE *)"", &topaz8465, ID_models, PLACETEXT_ABOVE, NULL, (APTR)modelsObj,
  112. };
  113.  
  114. ULONG ModelsNTags[] = {
  115.     (GTLV_Labels), NULL, (GTLV_Top), 0, (GTLV_ScrollWidth), 16, (LAYOUTA_Spacing), 0, TAG_DONE,
  116. };
  117.  
  118.  
  119. int GetPubScreen(void)
  120. {
  121.   if (!(Scr = LockPubScreen(PubScrName)))
  122.     return(1L);
  123.  
  124.   if (!(VisualInfo = GetVisualInfo(Scr, TAG_DONE)))
  125.     return(2L);
  126.   return(0L);
  127. }
  128.  
  129. void ClosePubScreen(void)
  130. {
  131.   if (VisualInfo)
  132.     FreeVisualInfo(VisualInfo);
  133.   if (Scr)
  134.     UnlockPubScreen(NULL,  Scr);
  135. }
  136.  
  137. int OpenModelsWindow(char windtitle[80])
  138. {
  139.   struct NewGadget    NewGad;
  140.   struct Gadget       *Gad;
  141.   register UWORD i, j;
  142.   UWORD offsetx = Scr->WBorLeft;
  143.   UWORD offsety = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  144.  
  145.  if (ModelsNumWindows == 0)
  146.  {
  147.   if (!(Gad = CreateContext(&ModelsGList)))
  148.       return(1L);
  149.  
  150.   for (i=0, j=0; i < ModelsNumGads; i++)
  151.   {
  152.     CopyMem((char *)&ModelsNGads[i], (char *)&NewGad, (long)sizeof(struct NewGadget));
  153.  
  154.     NewGad.ng_VisualInfo = VisualInfo;
  155.     NewGad.ng_LeftEdge += offsetx;
  156.     NewGad.ng_TopEdge  += offsety;
  157.  
  158.     ModelsGadgets[i] = Gad = CreateGadgetA((ULONG)ModelsGadTypes[i], Gad,&NewGad,
  159.     (struct TagItem *)&ModelsNTags[j]);
  160.     while (ModelsNTags[j])
  161.         j +=2;
  162.     j++;
  163.     if (!Gad)
  164.        return(2L);
  165.   }
  166.  }
  167.   if (!(ModelsActiveWind = AddWindowNode(ModelsWindList, windtitle, ModelsHandler)))
  168.      return(1);
  169.   if (!(ModelsActiveWind->nn_Window = OpenWindowTags(NULL,
  170.       WA_Left,    ModelsLeft,
  171.       WA_Top,     ModelsTop,
  172.       WA_Width,    ModelsWidth,
  173.       WA_Height,    ModelsHeight - Scr->WBorTop,
  174.       WA_IDCMP,    IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_VANILLAKEY | IDCMP_INTUITICKS | IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW ,
  175.       WA_Flags,    WFLG_CLOSEGADGET  |  WFLG_SMART_REFRESH |  WFLG_RMBTRAP |  WFLG_ACTIVATE |  WFLG_DRAGBAR ,
  176.       WA_Gadgets,    ModelsGList,
  177.       WA_Title,    windtitle,
  178.       WA_ScreenTitle,    "Visual Arts V1.0 Copyright 1994 Danny Y. Wong  All Rights Reserved.",
  179.       WA_PubScreen,    Scr,
  180.       WA_MinWidth,    20,
  181.       WA_MinHeight,    10,
  182.       WA_MaxWidth,    640,
  183.       WA_MaxHeight,    200,
  184.       TAG_DONE)))
  185.           return(3L);
  186.  
  187.   GT_RefreshWindow(ModelsActiveWind->nn_Window, NULL);
  188.   if (++ModelsNumWindows == 1)
  189.     CreateModelsLists();
  190.   GT_SetGadgetAttrs(ModelsGadgets[0], ModelsActiveWind->nn_Window, NULL,
  191.      GTLV_Labels, ModelsLists[0], TAG_END);
  192.   RefreshGadgets(ModelsGadgets[0], ModelsActiveWind->nn_Window, NULL);
  193.   return(0L);
  194. }
  195.  
  196. void CloseModelsWindow(void)
  197. {
  198.   struct WindowNode *WindNode;
  199.   struct Node *tempNode;
  200.  
  201.   if (tempNode = FindName(ModelsWindList, ModelsActiveWind->nn_Window->Title))
  202.   {
  203.     if (WindNode = FindWindowNode(ModelsWindList, ModelsActiveWind->nn_Window->Title))
  204.     {
  205.     if (ModelsTotalWindows == 1)
  206.       WindNode = NULL;
  207.     else
  208.     {
  209.       if (WindNode->ID == 1)
  210.         WindNode = FindWindowNode(ModelsWindList, tempNode->ln_Succ->ln_Name);
  211.       else
  212.         WindNode = FindWindowNode(ModelsWindList, tempNode->ln_Pred->ln_Name);
  213.     }
  214.     DelWindowNode(ModelsWindList, ModelsActiveWind->nn_Window->Title);
  215.     if (ModelsActiveWind->nn_Window)
  216.       CloseWindow(ModelsActiveWind->nn_Window);
  217.     if (WindNode)
  218.     {
  219.       ModelsActiveWind = WindNode;
  220.       ReMakeWindowID(ModelsWindList);
  221.       WindowToFront(ModelsActiveWind->nn_Window);
  222.       ActivateWindow(ModelsActiveWind->nn_Window);
  223.     }
  224.     }
  225.   }
  226. }
  227.  
  228. int ModelsHandler(void)
  229. {
  230.   struct IntuiMessage    *msg;
  231.   struct VAobject    VAObject;
  232.   int running    = 1;
  233.   int (*func)(struct VAobject VAObject);
  234.   struct WindowNode *WindNode;
  235.   ULONG class;
  236.   UWORD code;
  237.  
  238.   while (msg=GT_GetIMsg(ModelsActiveWind->nn_Window->UserPort))
  239.   {
  240.     CopyMem((char *)msg, (char *)&ModelsMsg, (long)sizeof(struct IntuiMessage));
  241.     class = msg->Class;
  242.     code  = msg->Code;
  243.  
  244.     GT_ReplyIMsg(msg);
  245.     switch(class)
  246.     {
  247.  
  248.       case IDCMP_MOUSEBUTTONS :
  249.         break;
  250.  
  251.       case IDCMP_MOUSEMOVE :
  252.         break;
  253.  
  254.       case IDCMP_GADGETDOWN :
  255.         break;
  256.  
  257.       case IDCMP_INTUITICKS :
  258.         break;
  259.  
  260.       case IDCMP_CLOSEWINDOW:
  261.          CloseModelsWindow();
  262.          if (--ModelsNumWindows == 0)
  263.          {
  264.              if (ModelsGList)
  265.                 FreeGadgets(ModelsGList);
  266.          }
  267.          return(1);
  268.          break;
  269.  
  270.       case IDCMP_ACTIVEWINDOW:
  271.       case IDCMP_INACTIVEWINDOW:
  272.         if (!IntuitionBase->ActiveWindow)
  273.         {
  274.         ActivateWindow(ModelsActiveWind->nn_Window);
  275.         break;
  276.         }
  277.         WindNode = FindWindowNode(ModelsWindList, IntuitionBase->ActiveWindow->Title);
  278.         if (WindNode)
  279.         ModelsActiveWind = WindNode;
  280.         break;
  281.  
  282.       case IDCMP_GADGETUP:
  283.         VAObject.va_Window = (struct Window *)ModelsActiveWind->nn_Window ;
  284.         VAObject.va_Gadget = (struct Gadget *)msg->IAddress;
  285.         VAObject.va_IntuiMsg = (struct IntuiMessage *)msg;
  286.         VAObject.va_Flags = 0;
  287.         VAObject.va_UserData = 0;
  288.         func = (void *)((struct Gadget *)ModelsMsg.IAddress)->UserData;
  289.         running =  func(VAObject);
  290.         break;
  291.  
  292.     }
  293.   }
  294.   return(running);
  295. }
  296.  
  297. int ModelsMainHandler(void)
  298. {
  299.   int running = 1;
  300.   ULONG windsig, signals;
  301.  
  302.   struct WindowNode *WindNode;
  303.   int (*func)(void);
  304.   while (running == 1)
  305.   {
  306.     windsig = 1L << ModelsActiveWind->nn_Window->UserPort->mp_SigBit;
  307.     signals = Wait( windsig );
  308.     if (signals & windsig)
  309.     {
  310.         if (WindNode = FindWindowNode(ModelsWindList, ModelsActiveWind->nn_Window->Title))
  311.         {
  312.           func = (void *)WindNode->UserData;
  313.           running = func();
  314.           if (ModelsTotalWindows == 0)
  315.           running = 0;
  316.         }
  317.     }
  318.   }
  319.   return(running);
  320. }
  321.  
  322. int main(int argc, char *argv[])
  323. {
  324.   int rc;
  325.  
  326.   IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0);
  327.   if (IntuitionBase == NULL)
  328.     exit(0);
  329.   if (!(GetPubScreen()))
  330.   {
  331.     ModelsWindList = GetNewList();
  332.     for (rc=0; rc < 1; rc++)
  333.       ModelsLists[rc]=GetNewList();
  334.           
  335.         MultiSub();     //call sub program to open its window
  336.         
  337.     if (!(OpenModelsWindow("MultiProcess Demo")))
  338.       rc = ModelsMainHandler();
  339.     for (rc=0; rc < 1; rc++)
  340.       FreeList(ModelsLists[rc]);
  341.     FreeWindowList(ModelsWindList);
  342.     ClosePubScreen();
  343.   }
  344.   if (IntuitionBase)
  345.     CloseLibrary((struct Library *)IntuitionBase);
  346. }
  347.