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 / AppWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-09  |  8.4 KB  |  331 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. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <exec/lists.h>
  12. #include <exec/nodes.h>
  13. #include <intuition/intuition.h>
  14. #include <intuition/gadgetclass.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <graphics/gfxmacros.h>
  18. #include <libraries/gadtools.h>
  19. #include <libraries/dos.h>
  20. #include <libraries/asl.h>
  21. #include <workbench/workbench.h>
  22. #include <workbench/startup.h>
  23.  
  24. #include <clib/exec_protos.h>
  25. #include <clib/intuition_protos.h>
  26. #include <clib/gadtools_protos.h>
  27. #include <clib/graphics_protos.h>
  28. #include <clib/utility_protos.h>
  29. #include <clib/alib_protos.h>
  30. #include <clib/dos_protos.h>
  31. #include <clib/asl_protos.h>
  32. #include <clib/wb_protos.h>
  33. #include "string.h" 
  34.  
  35. #define ID_clear                                      0
  36. #define ID_ok                                         1
  37. #define ID_iconlist                                   2
  38.  
  39. #define AppWindNumGads            3
  40. #include "AppWindow.h" 
  41.  
  42. int clearObj(struct VAobject VAObject);
  43. int okObj(struct VAobject VAObject);
  44. int iconlistObj(struct VAobject VAObject);
  45.  
  46. int GetPubScreen(void);
  47. void ClosePubScreen(void);
  48. int OpenAppWindWindow(char windtitle[80]);
  49. void CloseAppWindWindow(void);
  50. int AppWindHandler(void);
  51. int AppWindMainHandler(void);
  52. int AppWindAppWindHandler(struct MsgPort *appwindport);
  53. void DrawAppWindObjs(void);
  54. int main(int argc, char *argv[]);
  55.  
  56. UBYTE                *PubScrName = NULL;
  57. APTR                 VisualInfo = NULL;
  58. struct Screen            *Scr = NULL;
  59. struct Window            *AppWindWnd = NULL;
  60. struct AppWindow        *AppWindAppWind = NULL;
  61. struct MsgPort            *AppWindAppWindPort = NULL;
  62. struct Gadget            *AppWindGList = NULL;
  63. struct Gadget            *AppWindGadgets[3];
  64. struct IntuiMessage         AppWindMsg;
  65. UWORD                 AppWindLeft = 168;
  66. UWORD                 AppWindTop = 37;
  67. UWORD                 AppWindWidth = 228;
  68. UWORD                 AppWindHeight = 108;
  69. struct TextAttr topaz800 = { (STRPTR)"topaz.font", 8, 0x00, 0x00 };
  70. struct TextAttr topaz8265 = { (STRPTR)"topaz.font", 8, 2, 65 };
  71. struct TextAttr topaz8465 = { (STRPTR)"topaz.font", 8, 4, 65 };
  72.  
  73. struct IntuiText AppWindIText[] = {
  74.   1, 0, JAM2, 7, 85, &topaz8465, (UBYTE *)"Drag Icons into the Window", NULL,
  75. };
  76.  
  77. UBYTE *IconsLabels[] = {
  78.     NULL
  79. };
  80.  
  81. WORD AppWindGadTypes[] = {
  82.     BUTTON_KIND,
  83.     BUTTON_KIND,
  84.     LISTVIEW_KIND,
  85. };
  86.  
  87. struct NewGadget AppWindNGads[] = {
  88.     40, 70, 67, 12, (UBYTE *)"Clear",&topaz800, ID_clear, PLACETEXT_IN, NULL, (APTR)clearObj,
  89.     121, 70, 57, 12, (UBYTE *)"OK",&topaz800, ID_ok, PLACETEXT_IN, NULL, (APTR)okObj,
  90.     28, 14, 170, 52, (UBYTE *)"Program Names", &topaz8265, ID_iconlist, PLACETEXT_ABOVE, NULL, (APTR)iconlistObj,
  91. };
  92.  
  93. ULONG AppWindNTags[] = {
  94.     TAG_DONE,
  95.     TAG_DONE,
  96.     (GTLV_Labels), NULL, (GTLV_Top), 0, (GTLV_ScrollWidth), 16, (LAYOUTA_Spacing), 0, TAG_DONE,
  97. };
  98.  
  99.  
  100. int GetPubScreen(void)
  101. {
  102.   if (!(Scr = LockPubScreen(PubScrName)))
  103.     return(1L);
  104.  
  105.   if (!(VisualInfo = GetVisualInfo(Scr, TAG_DONE)))
  106.     return(2L);
  107.   return(0L);
  108. }
  109.  
  110. void ClosePubScreen(void)
  111. {
  112.   if (VisualInfo)
  113.     FreeVisualInfo(VisualInfo);
  114.   if (Scr)
  115.     UnlockPubScreen(NULL,  Scr);
  116. }
  117.  
  118. int OpenAppWindWindow(char windtitle[80])
  119. {
  120.   struct NewGadget    NewGad;
  121.   struct Gadget       *Gad;
  122.   register UWORD i, j;
  123.   UWORD offsetx = Scr->WBorLeft;
  124.   UWORD offsety = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  125.  
  126.   if (!(Gad = CreateContext(&AppWindGList)))
  127.       return(1L);
  128.  
  129.   for (i=0, j=0; i < AppWindNumGads; i++)
  130.   {
  131.     CopyMem((char *)&AppWindNGads[i], (char *)&NewGad, (long)sizeof(struct NewGadget));
  132.  
  133.     NewGad.ng_VisualInfo = VisualInfo;
  134.     NewGad.ng_LeftEdge += offsetx;
  135.     NewGad.ng_TopEdge  += offsety;
  136.  
  137.     AppWindGadgets[i] = Gad = CreateGadgetA((ULONG)AppWindGadTypes[i], Gad,&NewGad,
  138.     (struct TagItem *)&AppWindNTags[j]);
  139.     while (AppWindNTags[j])
  140.         j +=2;
  141.     j++;
  142.     if (!Gad)
  143.        return(2L);
  144.   }
  145.   if (!(AppWindWnd = OpenWindowTags(NULL,
  146.       WA_Left,    AppWindLeft,
  147.       WA_Top,     AppWindTop,
  148.       WA_Width,    AppWindWidth,
  149.       WA_Height,    AppWindHeight - Scr->WBorTop,
  150.       WA_IDCMP,    IDCMP_CLOSEWINDOW |  IDCMP_NEWSIZE | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_INTUITICKS ,
  151.       WA_Flags,    WFLG_CLOSEGADGET | WFLG_DEPTHGADGET  |  WFLG_SMART_REFRESH |  WFLG_RMBTRAP |  WFLG_ACTIVATE |  WFLG_DRAGBAR ,
  152.       WA_Gadgets,    AppWindGList,
  153.       WA_Title,    windtitle,
  154.       WA_ScreenTitle,    "Visual Arts V1.0 Copyright 1994 Danny Y. Wong  All Rights Reserved.",
  155.       WA_PubScreen,    Scr,
  156.       WA_MinWidth,    20,
  157.       WA_MinHeight,    10,
  158.       WA_MaxWidth,    640,
  159.       WA_MaxHeight,    200,
  160.       TAG_DONE)))
  161.           return(3L);
  162.  
  163.   if (AppWindAppWindPort = CreateMsgPort())
  164.   {
  165.     AppWindAppWind = AddAppWindow(1, 0, AppWindWnd, AppWindAppWindPort, NULL);
  166.     if (AppWindAppWind == NULL)
  167.     {
  168.       CloseAppWindWindow();
  169.       return(-1L);
  170.     }
  171.   }
  172.   else
  173.     return(-2L);
  174.   DrawAppWindObjs();
  175.   GT_RefreshWindow(AppWindWnd, NULL);
  176.   CreateAppWindLists();
  177.   GT_SetGadgetAttrs(AppWindGadgets[2], AppWindWnd, NULL,
  178.      GTLV_Labels, AppWindLists[0], TAG_END);
  179.   RefreshGadgets(AppWindGadgets[0], AppWindWnd, NULL);
  180.   return(0L);
  181. }
  182.  
  183. void CloseAppWindWindow(void)
  184. {
  185.   struct AppMessage *appwindmsg;
  186.  
  187.   if (AppWindWnd)
  188.     CloseWindow(AppWindWnd);
  189.   if (AppWindGList)
  190.     FreeGadgets(AppWindGList);
  191.   if (AppWindAppWind)
  192.   {
  193.     RemoveAppWindow(AppWindAppWind);
  194.     while (appwindmsg = (struct AppMessage *)GetMsg(AppWindAppWindPort))
  195.     ReplyMsg((struct Message *)appwindmsg);
  196.     DeleteMsgPort(AppWindAppWindPort);
  197.   }
  198. }
  199.  
  200. int AppWindHandler(void)
  201. {
  202.   struct IntuiMessage    *msg;
  203.   struct VAobject    VAObject;
  204.   int running    = 1;
  205.   int (*func)(struct VAobject VAObject);
  206.   ULONG class;
  207.   UWORD code;
  208.  
  209.   while (msg=GT_GetIMsg(AppWindWnd->UserPort))
  210.   {
  211.     CopyMem((char *)msg, (char *)&AppWindMsg, (long)sizeof(struct IntuiMessage));
  212.     class = msg->Class;
  213.     code  = msg->Code;
  214.  
  215.     GT_ReplyIMsg(msg);
  216.     switch(class)
  217.     {
  218.  
  219.       case IDCMP_MOUSEBUTTONS :
  220.         break;
  221.  
  222.       case IDCMP_MOUSEMOVE :
  223.         break;
  224.  
  225.       case IDCMP_GADGETDOWN :
  226.         break;
  227.  
  228.       case IDCMP_INTUITICKS :
  229.         break;
  230.  
  231.       case IDCMP_CLOSEWINDOW:
  232.          return(0);
  233.          break;
  234.  
  235.       case IDCMP_GADGETUP:
  236.         VAObject.va_Window = (struct Window *)AppWindWnd;
  237.         VAObject.va_Gadget = (struct Gadget *)msg->IAddress;
  238.         VAObject.va_IntuiMsg = (struct IntuiMessage *)msg;
  239.         VAObject.va_Flags = 0;
  240.         VAObject.va_UserData = 0;
  241.         func = (void *)((struct Gadget *)AppWindMsg.IAddress)->UserData;
  242.         running =  func(VAObject);
  243.         break;
  244.  
  245.     }
  246.   }
  247.   return(running);
  248. }
  249.  
  250. void DrawAppWindObjs(void)
  251. {
  252.   PrintIText(AppWindWnd->RPort, AppWindIText, AppWindWnd->BorderLeft, AppWindWnd->BorderTop);
  253.  
  254. }
  255.  
  256. int AppWindAppWindHandler(struct MsgPort *appwindport)
  257. {
  258.   struct WBArg    *wbargptr;
  259.   struct AppMessage    *appwindmsg;
  260.   int i;
  261.  
  262.   while (appwindmsg = (struct AppMessage *)GetMsg(appwindport))
  263.   {
  264.     wbargptr = appwindmsg->am_ArgList;
  265.  
  266.     /*  examine the icons dragged into the window here.   */ 
  267.     /*  wbargptr->wa_Name ---> name of the icon           */ 
  268.     /*  wbargptr->wa_Lock ---> directory this icon is in. */ 
  269.  
  270. //we must detach the list before doing modifications
  271.  
  272.         GT_SetGadgetAttrs(AppWindGadgets[ID_iconlist], AppWindWnd, NULL,
  273.           GTLV_Labels, ~0, TAG_DONE);    
  274.  
  275. //here we loop thru all the icons dragged in 
  276.     for (i=0; i < appwindmsg->am_NumArgs; i++)
  277.     {
  278. //use VAs internal list routines to add a new node to the list
  279.            AddNewNode(AppWindLists[0], wbargptr->wa_Name);
  280.        wbargptr++;
  281.     }
  282.     ReplyMsg((struct Message *)appwindmsg);
  283. //now reattach the list to the listview with update values
  284.         GT_SetGadgetAttrs(AppWindGadgets[ID_iconlist], AppWindWnd, NULL,
  285.            GTLV_Labels, AppWindLists[0], TAG_DONE);      
  286.   }
  287.   return(0);
  288. }
  289.  
  290. int AppWindMainHandler(void)
  291. {
  292.   int running = 1;
  293.   ULONG windsig, signals;
  294.  
  295.   ULONG appwindsig;
  296.  
  297.   while (running == 1)
  298.   {
  299.     appwindsig = 1L << AppWindAppWindPort->mp_SigBit;
  300.     windsig = 1L << AppWindWnd->UserPort->mp_SigBit;
  301.     signals = Wait( windsig | appwindsig );
  302.     if (signals & windsig)
  303.     {
  304.       running = AppWindHandler();
  305.     }
  306.     else
  307.     if (signals & appwindsig)
  308.       AppWindAppWindHandler(AppWindAppWindPort);
  309.   }
  310.   return(running);
  311. }
  312.  
  313. int main(int argc, char *argv[])
  314. {
  315.   int rc;
  316.  
  317.   if (!(GetPubScreen()))
  318.   {
  319.     for (rc=0; rc < 1; rc++)
  320.       AppWindLists[rc]=GetNewList();
  321.     if (!(OpenAppWindWindow("AppWindow Demo")))
  322.     {
  323.       rc = AppWindMainHandler();
  324.       CloseAppWindWindow();
  325.     }
  326.     for (rc=0; rc < 1; rc++)
  327.       FreeList(AppWindLists[rc]);
  328.     ClosePubScreen();
  329.   }
  330. }
  331.