home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / gui / visualarts / demo / source / multimain.c < prev    next >
C/C++ Source or Header  |  1994-09-21  |  10KB  |  357 lines

  1. /* ******************************************************************** */
  2. /* C code generated by:                            */
  3. /* Visual Arts Version 2.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. #include "VisualArts.h" 
  10.  
  11. #define ID_ObjID6                                     0
  12. #define ID_ObjID7                                     1
  13. #define ID_ObjID2                                     2
  14. #define ID_ObjID5                                     3
  15. #define ID_ObjID8                                     4
  16. #define ID_ObjID4                                     5
  17. #define ID_ObjID9                                     6
  18. #define ID_ObjID1                                     7
  19. #define ID_ObjID3                                     8
  20.  
  21. #define ContextSNumGads                        9
  22.  
  23. #include "MultiMain.h" 
  24.  
  25. int ObjID6Obj(struct VAobject VAObject);
  26. int ObjID7Obj(struct VAobject VAObject);
  27. int ObjID2Obj(struct VAobject VAObject);
  28. int ObjID5Obj(struct VAobject VAObject);
  29. int ObjID8Obj(struct VAobject VAObject);
  30. int ObjID4Obj(struct VAobject VAObject);
  31. int ObjID9Obj(struct VAobject VAObject);
  32. int ObjID1Obj(struct VAobject VAObject);
  33. int ObjID3Obj(struct VAobject VAObject);
  34.  
  35. int GetPubScreen(void);
  36. void ClosePubScreen(void);
  37. int OpenContextSWindow(char windtitle[80]);
  38. void CloseContextSWindow(void);
  39. int ContextSHandler(void);
  40. int ContextSMainHandler(void);
  41. void DrawContextSObjs(void);
  42. int main(int argc, char *argv[]);
  43. extern void SubPrg(void);
  44.  
  45. UBYTE                *PubScrName = NULL;
  46. struct DrawInfo            *ScrDrawInfo = NULL;
  47. APTR                 VisualInfo = NULL;
  48. struct Screen            *Scr = NULL;
  49. struct WindowNode        *ContextSActiveWind = NULL;
  50. struct Gadget            *ContextSGList = NULL;
  51. struct Gadget            *ContextSGadgets[ContextSNumGads];
  52. struct IntuiMessage         ContextSMsg;
  53. UWORD                 ContextSLeft = 0;
  54. UWORD                 ContextSTop = 28;
  55. UWORD                 ContextSWidth = 279;
  56. UWORD                 ContextSHeight = 79;
  57. struct IntuitionBase        *IntuitionBase = NULL;
  58. struct List            *ContextSWindList;
  59. UWORD                 ContextSTotalWindows = 0;
  60. UWORD                 ContextSNumWindows = 0;
  61. struct TextAttr topaz8 = { (STRPTR)"topaz.font", 8, 0x00, 0x01 };
  62. struct TextAttr topaz800 = { (STRPTR)"topaz.font", 8, 0x00, 0x00 };
  63.  
  64. UBYTE *ModelsLabels[] = {
  65.     (UBYTE *)"Amiga 500", 
  66.     (UBYTE *)"Amiga 1000", 
  67.     (UBYTE *)"Amiga 2000", 
  68.     (UBYTE *)"Amiga 3000", 
  69.     (UBYTE *)"Amiga 4000", 
  70.     (UBYTE *)"Amiga CDTV", 
  71.     (UBYTE *)"Amiga CD32", 
  72.     NULL
  73. };
  74.  
  75. UBYTE *answerLabels[] = {
  76.     (UBYTE *)"Yes", 
  77.     (UBYTE *)"No", 
  78.     NULL
  79. };
  80.  
  81. WORD ContextSGadTypes[] = {
  82.     BUTTON_KIND,
  83.     BUTTON_KIND,
  84.     STRING_KIND,
  85.     STRING_KIND,
  86.     CHECKBOX_KIND,
  87.     MX_KIND,
  88.     CYCLE_KIND,
  89.     LISTVIEW_KIND,
  90.     PALETTE_KIND,
  91. };
  92.  
  93. struct NewGadget ContextSNGads[] = {
  94.     168, 2, 71, 12, (UBYTE *)"Button",&topaz800, ID_ObjID6, PLACETEXT_IN, NULL, (APTR)ObjID6Obj,
  95.     168, 16, 71, 12, (UBYTE *)"Toggle",&topaz800, ID_ObjID7, PLACETEXT_IN, NULL, (APTR)ObjID7Obj,
  96.     6, 30, 87, 12, (UBYTE *)"", &topaz800, ID_ObjID2, PLACETEXT_LEFT, NULL, (APTR)ObjID2Obj,
  97.     58, 50, 72, 12, (UBYTE *)"String", &topaz800, ID_ObjID5, PLACETEXT_LEFT, NULL, (APTR)ObjID5Obj,
  98.     213, 31, 26, 11, (UBYTE *)"Cool", &topaz800, ID_ObjID8, PLACETEXT_LEFT, NULL, (APTR)ObjID8Obj,
  99.     143, 30, 17, 16, (UBYTE *)"", &topaz800, ID_ObjID4, PLACETEXT_LEFT, NULL, (APTR)ObjID4Obj,
  100.     177, 50, 62, 12, (UBYTE *)"OK", &topaz800, ID_ObjID9, PLACETEXT_LEFT, NULL, (APTR)ObjID9Obj,
  101.     5, 2, 87, 28, (UBYTE *)"", &topaz800, ID_ObjID1, PLACETEXT_ABOVE, NULL, (APTR)ObjID1Obj,
  102.     99, 2, 61, 25, (UBYTE *)"", &topaz800, ID_ObjID3, PLACETEXT_ABOVE, NULL, (APTR)ObjID3Obj,
  103. };
  104.  
  105. ULONG ContextSNTags[] = {
  106.     TAG_DONE,
  107.     TAG_DONE,
  108.     GTST_MaxChars, 255, (STRINGA_Justification), GACT_STRINGLEFT, TAG_DONE,
  109.     (GTST_String), (ULONG)"Visual Arts", GTST_MaxChars, 255, (STRINGA_Justification), GACT_STRINGLEFT, TAG_DONE,
  110.     TAG_DONE,
  111.     (GTMX_Labels), (ULONG)&answerLabels[0], (GTMX_Active), 0, (GTMX_Spacing), 1, TAG_DONE,
  112.     (GTCY_Labels), (ULONG)&answerLabels[0], (GTCY_Active), 0, TAG_DONE,
  113.     (GTLV_ShowSelected), 99, (GTLV_Labels), NULL, (GTLV_Top), 0, (GTLV_ScrollWidth), 16, (LAYOUTA_Spacing), 0, TAG_DONE,
  114.     (GTPA_Depth), 2, (GTPA_Color), 1, (GTPA_ColorOffset), 0, TAG_DONE,
  115. };
  116.  
  117.  
  118. int GetPubScreen(void)
  119. {
  120.   if (!(Scr = LockPubScreen(PubScrName)))
  121.     return(1L);
  122.  
  123.   if (!(VisualInfo = GetVisualInfo(Scr, TAG_DONE)))
  124.     return(2L);
  125.  
  126.   if (!(ScrDrawInfo = GetScreenDrawInfo(Scr)))
  127.     return(3L);
  128.   return(0L);
  129. }
  130.  
  131. void ClosePubScreen(void)
  132. {
  133.   if (VisualInfo)
  134.     FreeVisualInfo(VisualInfo);
  135.   if (Scr)
  136.     UnlockPubScreen(NULL,  Scr);
  137.   if (ScrDrawInfo)
  138.     FreeScreenDrawInfo(Scr,  ScrDrawInfo);
  139. }
  140.  
  141. int OpenContextSWindow(char windtitle[80])
  142. {
  143.   struct NewGadget    NewGad;
  144.   struct Gadget       *Gad;
  145.   register UWORD i, j;
  146.   UWORD offsetx = Scr->WBorLeft;
  147.   UWORD offsety = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  148.   int k=0;
  149.   int LVStrGads[] = {ID_ObjID2, -1 };
  150.  
  151.  if (ContextSNumWindows == 0)
  152.  {
  153.   if (!(Gad = CreateContext(&ContextSGList)))
  154.       return(1L);
  155.  
  156.   for (i=0, j=0; i < ContextSNumGads; i++)
  157.   {
  158.     CopyMem((char *)&ContextSNGads[i], (char *)&NewGad, (long)sizeof(struct NewGadget));
  159.  
  160.     NewGad.ng_VisualInfo = VisualInfo;
  161.     NewGad.ng_LeftEdge += offsetx;
  162.     NewGad.ng_TopEdge  += offsety;
  163.  
  164.     if (ContextSNTags[j] == GTLV_ShowSelected && ContextSNTags[j+1] == 99)
  165.       ContextSNTags[j+1] = (ULONG)ContextSGadgets[LVStrGads[k++]];
  166.     ContextSGadgets[i] = Gad = CreateGadgetA((ULONG)ContextSGadTypes[i], Gad, &NewGad,
  167.     (struct TagItem *)&ContextSNTags[j]);
  168.     while (ContextSNTags[j])
  169.         j +=2;
  170.     j++;
  171.     if (!Gad)
  172.        return(2L);
  173.   }
  174.   ContextSGadgets[1]->Activation |= GACT_TOGGLESELECT;
  175.  }
  176.   if (!(ContextSActiveWind = AddWindowNode(ContextSWindList, windtitle, ContextSHandler)))
  177.      return(1);
  178.   if (!(ContextSActiveWind->nn_Window = OpenWindowTags(NULL,
  179.       WA_Left,    ContextSLeft,
  180.       WA_Top,     ContextSTop,
  181.       WA_Width,    ContextSWidth,
  182.       WA_Height,    ContextSHeight - Scr->WBorTop,
  183.       WA_NewLookMenus, TRUE,
  184.       WA_IDCMP,    IDCMP_CLOSEWINDOW |  IDCMP_NEWSIZE | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_INTUITICKS | IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW ,
  185.       WA_Flags,    WFLG_SIZEGADGET | WFLG_SIZEBRIGHT | WFLG_DEPTHGADGET |
  186.             WFLG_CLOSEGADGET   ,
  187.       WA_Gadgets,    ContextSGList,
  188.       WA_Title,    windtitle,
  189.       WA_ScreenTitle,    "Visual Arts V2.0 Copyright 1994 Danny Y. Wong  All Rights Reserved.",
  190.       WA_PubScreen,    Scr,
  191.       WA_MinWidth,    160,
  192.       WA_MinHeight,    50,
  193.       WA_MaxWidth,    640,
  194.       WA_MaxHeight,    200,
  195.       TAG_DONE)))
  196.           return(3L);
  197.  
  198.   if (++ContextSNumWindows == 1)
  199.     CreateContextSLists();
  200.   GT_RefreshWindow(ContextSActiveWind->nn_Window, NULL);
  201.   RefreshGadgets(ContextSGadgets[0], ContextSActiveWind->nn_Window, NULL);
  202.   GT_SetGadgetAttrs(ContextSGadgets[7], ContextSActiveWind->nn_Window, NULL,
  203.      GTLV_Labels, ContextSLists[0], TAG_END);
  204.   return(0L);
  205. }
  206.  
  207. void CloseContextSWindow(void)
  208. {
  209.   struct WindowNode *WindNode;
  210.   struct Node *tempNode;
  211.  
  212.   if (tempNode = FindName(ContextSWindList, ContextSActiveWind->nn_Window->Title))
  213.   {
  214.     if (WindNode = FindWindowNode(ContextSWindList, ContextSActiveWind->nn_Window->Title))
  215.     {
  216.     if (ContextSTotalWindows == 1)
  217.       WindNode = NULL;
  218.     else
  219.     {
  220.       if (WindNode->ID == 1)
  221.         WindNode = FindWindowNode(ContextSWindList, tempNode->ln_Succ->ln_Name);
  222.       else
  223.         WindNode = FindWindowNode(ContextSWindList, tempNode->ln_Pred->ln_Name);
  224.     }
  225.     DelWindowNode(ContextSWindList, ContextSActiveWind->nn_Window->Title);
  226.     if (ContextSActiveWind->nn_Window)
  227.       CloseWindow(ContextSActiveWind->nn_Window);
  228.     if (WindNode)
  229.     {
  230.       ContextSActiveWind = WindNode;
  231.       ReMakeWindowID(ContextSWindList);
  232.       WindowToFront(ContextSActiveWind->nn_Window);
  233.       ActivateWindow(ContextSActiveWind->nn_Window);
  234.     }
  235.     }
  236.   }
  237. }
  238.  
  239. int ContextSHandler(void)
  240. {
  241.   struct IntuiMessage    *msg;
  242.   struct VAobject    VAObject;
  243.   int running    = 1;
  244.   int (*func)(struct VAobject VAObject);
  245.   struct WindowNode *WindNode;
  246.   ULONG class;
  247.   UWORD code;
  248.  
  249.   while (msg=GT_GetIMsg(ContextSActiveWind->nn_Window->UserPort))
  250.   {
  251.     CopyMem((char *)msg, (char *)&ContextSMsg, (long)sizeof(struct IntuiMessage));
  252.     class = msg->Class;
  253.     code  = msg->Code;
  254.  
  255.     GT_ReplyIMsg(msg);
  256.     switch(class)
  257.     {
  258.  
  259.       case IDCMP_MOUSEBUTTONS :
  260.         break;
  261.  
  262.       case IDCMP_MOUSEMOVE :
  263.         break;
  264.  
  265.       case IDCMP_INTUITICKS :
  266.         break;
  267.  
  268.       case IDCMP_NEWSIZE:
  269.        break;
  270.  
  271.       case IDCMP_CLOSEWINDOW:
  272.          CloseContextSWindow();
  273.          if (--ContextSNumWindows == 0)
  274.          {
  275.              if (ContextSGList)
  276.                 FreeGadgets(ContextSGList);
  277.          }
  278.          return(1);
  279.          break;
  280.  
  281.       case IDCMP_ACTIVEWINDOW:
  282.       case IDCMP_INACTIVEWINDOW:
  283.         if (!IntuitionBase->ActiveWindow)
  284.         {
  285.         ActivateWindow(ContextSActiveWind->nn_Window);
  286.         break;
  287.         }
  288.         WindNode = FindWindowNode(ContextSWindList, IntuitionBase->ActiveWindow->Title);
  289.         if (WindNode)
  290.         ContextSActiveWind = WindNode;
  291.         break;
  292.  
  293.       case IDCMP_GADGETUP:
  294.         VAObject.va_Window = (struct Window *)ContextSActiveWind->nn_Window ;
  295.         VAObject.va_Gadget = (struct Gadget *)msg->IAddress;
  296.         VAObject.va_IntuiMsg = (struct IntuiMessage *)msg;
  297.         VAObject.va_Flags = 0;
  298.         VAObject.va_UserData = 0;
  299.         func = (void *)((struct Gadget *)ContextSMsg.IAddress)->UserData;
  300.         if (func != NULL)
  301.           running =  func(VAObject);
  302.         break;
  303.  
  304.     }
  305.   }
  306.   return(running);
  307. }
  308.  
  309. int ContextSMainHandler(void)
  310. {
  311.   int running = 1;
  312.   ULONG windsig, signals;
  313.  
  314.   struct WindowNode *WindNode;
  315.   int (*func)(void);
  316.   while (running == 1)
  317.   {
  318.     windsig = 1L << ContextSActiveWind->nn_Window->UserPort->mp_SigBit;
  319.     signals = Wait( windsig );
  320.     if (signals & windsig)
  321.     {
  322.         if (WindNode = FindWindowNode(ContextSWindList, ContextSActiveWind->nn_Window->Title))
  323.         {
  324.           func = (void *)WindNode->UserData;
  325.           running = func();
  326.           if (ContextSTotalWindows == 0)
  327.           running = 0;
  328.         }
  329.     }
  330.   }
  331.   return(running);
  332. }
  333.  
  334. int main(int argc, char *argv[])
  335. {
  336.   int rc;
  337.  
  338.   IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0);
  339.   if (IntuitionBase == NULL)
  340.     exit(0);
  341.   if (!(GetPubScreen()))
  342.   {
  343.     ContextSWindList = GetNewList();
  344.     for (rc=0; rc < 2; rc++)
  345.       ContextSLists[rc]=GetNewList();
  346.         SubPrg();                               //open subprg window
  347.     if (!(OpenContextSWindow("Visual Arts -- Context Sensitive Demo")))
  348.       rc = ContextSMainHandler();
  349.     for (rc=0; rc < 2; rc++)
  350.       FreeList(ContextSLists[rc]);
  351.     FreeWindowList(ContextSWindList);
  352.     ClosePubScreen();
  353.   }
  354.   if (IntuitionBase)
  355.     CloseLibrary((struct Library *)IntuitionBase);
  356. }
  357.