home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 206.lha / C-Functions / mtest.c < prev    next >
C/C++ Source or Header  |  1996-02-14  |  7KB  |  299 lines

  1.  
  2. /* Program for test of Maker.lib */
  3. /* By Lars Thuring */
  4.  
  5. /* 880920 V1.0  First */
  6.  
  7.    /****************************************************************\
  8.    *                                                                *
  9.    * Since the main purpose of this program is to demonstrate the   *
  10.    * MakeXxxx() routines very little response is given to user      *
  11.    * activities.                                                    *
  12.    *                                                                *
  13.    * It also reveals some cosmetical misshaps which will be removed *
  14.    * in the mark 2 version. Real soon now.                          *
  15.    *                                                                *
  16.    \****************************************************************/
  17.  
  18. #include <exec/types.h>
  19. #include <intuition/intuition.h>
  20. #include "MakeName.h"
  21.  
  22. extern struct Window *OpenWindow();
  23. extern VOID MakeMenu();
  24. extern int MakeAutoRequest();
  25.  
  26. struct IntuitionBase *IntuitionBase; /* libraries */
  27. struct GfxBase *GfxBase;
  28. struct Screen *CustScr;              /* graphics */
  29. struct Window *Window;
  30. struct RastPort *Rp;
  31. struct IntuiMessage *message,*GetMsg();
  32.  
  33. UBYTE gname[9][50],
  34.       bname[9][50];
  35.  
  36. struct NewWindow NewWindow = {
  37.    0,0,640,200,2,1,
  38.    MENUPICK,
  39.    ACTIVATE|WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|SMART_REFRESH,
  40.    NULL,NULL,">!<",
  41.    NULL,NULL,
  42.    200,50,640,256,WBENCHSCREEN
  43.    };
  44.  
  45. static UBYTE *What[] = {      /* What's on the menu ? */
  46.    "[M]Project",
  47.    "[ I]About",
  48.    "[ I]Quit",
  49.    "[M]Menu",
  50.    "[ I]MenuItem 1",
  51.    "[  S]SubItem 1a",
  52.    "[  S]SubItem 1b",
  53.    "[ IJ]MenuItem 2",
  54.    "[  SJ]SubItem 2a",
  55.    "[  SJ]SubItem 2b",
  56.    "[ IN]UnMoved",
  57.    "[ IJ]Alternate text",
  58.    "[ IJA]when selected!",
  59.    "[M]Another",
  60.    "[ IB]Neither mctrash",
  61.    "[ IB]nor pctrash.",
  62.    "[ IVde]  Deselect item 4 & 5",
  63.    "[ ICce]  Deselect item 3 & 5",
  64.    "[ ICcd]  Deselect item 3 & 4",
  65.    "[ I]nothing",
  66.    "[  SD]NOT ENABLED",
  67.    "[  SD]DITO",
  68.    "[ I]right amiga",
  69.    "[  SC_z]  Zap     ",
  70.    "[  SC_w]  Wam     ",
  71.    "[M]COLUMNS",
  72.    "[ I]a1",
  73.    "[ I]a2",
  74.    "[ I]a3",
  75.    "[ IH]b1",
  76.    "[ I]b2",
  77.    "[ I]b3",
  78.    "[M]Some",
  79.    "[ I]Check two:  ",              /* The following array is filled in */
  80.    &gname[0][0],                    /* later to show that nothing have  */
  81.    &gname[1][0],                    /* to be fixed at start.            */
  82.    &gname[2][0],
  83.    &gname[3][0],
  84.    &gname[4][0],
  85.    &gname[5][0],
  86.    &gname[6][0],
  87.    &gname[7][0],
  88.    &gname[8][0],
  89.    NULL
  90.    };
  91.  
  92.    /* Defines for menu op's */
  93.  
  94. #define MPROJECT     0
  95. #define IABOUT          0
  96. #define IQUIT           1
  97.  
  98.  
  99.  
  100. static struct Menu Head[9];         /* The Menu structs */
  101. static struct MenuItem Body[59],    /* and the MenuItem structs */
  102.                        *ItemAddress();
  103. static struct IntuiText Text[59];   /* The IntuiText structs */
  104. struct Menu *MenuStrip = &Head[0];
  105.  
  106.    /* Simple messages: */
  107.  
  108. UBYTE *AboutText[] = {
  109.       "[J2TB2]                                                     ",
  110.       "[] This program shows the various maker.lib functions. ",
  111.       "[]                                                     ",
  112.       "[F3] (C)Copyright 14 sep 1988 by Lars Thuring            ",
  113.       "[NB0] OK ",
  114.       NULL
  115.       };
  116.  
  117. UBYTE *QuitText[] = {
  118.       "[T]",
  119.       "[] Are you sure you really want to quit ?? ",
  120.       "[]",
  121.       "[P] sure !",
  122.       "[N] CANCEL ",
  123.       NULL
  124.       };
  125.  
  126.  
  127. ULONG mClass;          /* Returns from HandleEvent */
  128. USHORT code;
  129. APTR address;
  130. SHORT mX,mY;
  131.  
  132. VOID main(),TheEnd();
  133. VOID GetIDCMP(),
  134.      HandleMenu();
  135. int MyInit();
  136.  
  137. VOID main()
  138.    {
  139. int i;                                 /* trash */
  140. SHORT x,y;                             /* For boxes */
  141.  
  142.    for(i=0;i<9;i++)                    /* Init name arrays */
  143.       {
  144.       strcpy(&bname[i][0],"[C0F2J1C]");
  145.       MakeName(&bname[i][9], TITLENAME|FULLNAME, BOYNAME);
  146.       strcpy(&gname[i][0],"[ SC]  ");
  147.       MakeName(&gname[i][7], FIRSTNAME, GIRLNAME);
  148.       }
  149.  
  150.  
  151.    MyInit();                           /* Sets up environment */
  152.  
  153.  
  154.    /* Draw some things */
  155.  
  156.    x=11;
  157.  
  158.    MakeBox(Rp,x,20,0,0,"[JF2]MakeBox parts:");
  159.  
  160.    MakeBox(Rp,x, 35,50,10,"[C0]");
  161.    MakeBox(Rp,x, 55,50,10,"[C1]");
  162.    MakeBox(Rp,x, 75,50,10,"[C2]");
  163.    MakeBox(Rp,x, 95,50,10,"[C3]");
  164.  
  165.    MakeBox(Rp,x,115,0,0,"[JF2]combinations:");
  166.  
  167.    MakeBox(Rp,x,135,50,10,"[C0C1]");
  168.    MakeBox(Rp,x,155,50,10,"[C0C2]");
  169.    MakeBox(Rp,x,175,50,10,"[C0C3]");
  170.  
  171.    x=200;
  172.  
  173.    MakeBox(Rp,x, 20,0,0,"[JF2]and so on...");
  174.  
  175.    MakeBox(Rp,x, 45,75,35,"[SF2J0C2]");
  176.    MakeBox(Rp,x,100,75,35,"[SF1J0C3]");
  177.  
  178.    x = 370;
  179.    y = 20;
  180.  
  181.    for(i=0;i<9;i++)
  182.       {
  183.       MakeBox(Rp,x,y,0,0,&bname[i][0]);
  184.       y+=19;
  185.       }
  186.  
  187.  
  188.    while (mClass NOT= CLOSEWINDOW)
  189.       {
  190.       GetIDCMP(Window);       /* Wait for something to happen */
  191.  
  192.       switch(mClass)
  193.          {
  194.          case MENUPICK:       /* If menu selection */
  195.             HandleMenu();
  196.             break;
  197.          default:             /* If something unidentified */
  198.             break;
  199.          }
  200.       }
  201.  
  202.  
  203.    TheEnd();
  204.    }          /* E N D  O F  M A I N */
  205.  
  206. int MyInit()
  207.    {
  208.  
  209.    /* Open libs, get pointer and check if succes */
  210.  
  211.    IntuitionBase = (struct IntuitionBase *)
  212.       OpenLibrary("intuition.library",LIBRARY_VERSION);
  213.    if (IntuitionBase == NULL) exit(FALSE);
  214.  
  215.    GfxBase = (struct GfxBase *)
  216.       OpenLibrary("graphics.library",LIBRARY_VERSION);
  217.    if (GfxBase == NULL) exit(FALSE);
  218.  
  219.    /* Ok, open window */
  220.  
  221.    if ((Window = OpenWindow(&NewWindow)) == NULL)
  222.       exit(FALSE);
  223.  
  224.    Rp=Window->RPort;
  225.  
  226.    MakeMenu(&What[0], &Head[0], &Body[0], &Text[0]);
  227.    SetMenuStrip(Window, MenuStrip);
  228.  
  229.    return(NULL);
  230.    }
  231.  
  232.  
  233. VOID TheEnd()
  234.    {
  235.    if (Window) CloseWindow(Window);
  236.    if (GfxBase) CloseLibrary(GfxBase);
  237.    if (IntuitionBase) CloseLibrary(IntuitionBase);
  238.    }
  239.  
  240.  
  241. VOID GetIDCMP(w)     /* Get commo flags */
  242. struct Window *w;    /* For this window */
  243.    {
  244.    Wait(1<<w->UserPort->mp_SigBit);  /* Wait nicely */
  245.  
  246.    message = GetMsg(w->UserPort);
  247.  
  248.    mClass  = message-> Class;  /* Make copy of message description */
  249.    code    = message-> Code;
  250.    address = message-> IAddress;
  251.    mX      = message-> MouseX;
  252.    mY      = message-> MouseY;
  253.  
  254.    ReplyMsg(message);   /* Let intuition know message acknowledged */
  255.    }
  256.  
  257. VOID HandleMenu()       /* Checks for multiple selects by user */
  258.    {
  259. USHORT MenuNumber = code;  /* From IDCMP */
  260. USHORT Mnum, Inum, Snum;   /* Derived from ordinal number(s) */
  261. struct MenuItem *pItem;
  262.  
  263.    while (MenuNumber NOT= MENUNULL)   /* Untill done */
  264.       {
  265.       Mnum = MENUNUM(MenuNumber);      /* Make numbers */
  266.       Inum = ITEMNUM(MenuNumber);
  267.       Snum = SUBNUM(MenuNumber);
  268.       pItem = ItemAddress( MenuStrip, MenuNumber);
  269.  
  270.       switch (Mnum)
  271.          {
  272.          case MPROJECT:
  273.             switch (Inum)
  274.                {
  275.                case IABOUT:
  276.                   MakeAutoRequest(Window, AboutText);
  277.                   break;
  278.  
  279.                case IQUIT:
  280.                   if (MakeAutoRequest(Window, QuitText))
  281.                      mClass=CLOSEWINDOW;
  282.                   break;
  283.  
  284.                default:
  285.                   break;
  286.                }
  287.  
  288.  
  289.          default:
  290.             break;
  291.          }
  292.  
  293.       MenuNumber = pItem->NextSelect;     /* Looping */
  294.       }
  295.    }     /*  End of HandleMenu() */
  296.  
  297.  
  298.  
  299.