home *** CD-ROM | disk | FTP | other *** search
/ back2roots/filegate / filegate.zip / filegate / ads / adsutils / PMDEV.LHA / PopupMenuDeveloper / C / Demos / Layout.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-23  |  4.1 KB  |  196 lines

  1. /*
  2.  *
  3.  * $VER: Layout.c 1.1 (23.08.00)
  4.  *
  5.  * Popup Menu example program
  6.  *
  7.  * ⌐1996-1998 Henrik Isaksson
  8.  * All Rights Reserved.
  9.  *
  10.  */
  11.  
  12. #include <intuition/intuition.h>
  13. #include <exec/memory.h>
  14.  
  15. #include <proto/intuition.h>
  16. #include <proto/exec.h>
  17.  
  18. #include <clib/alib_protos.h>
  19.  
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. #include <libraries/pm.h>
  25. #include <proto/pm.h>
  26.  
  27. struct IntuitionBase    *IntuitionBase;
  28. struct GfxBase        *GfxBase;
  29. struct PopupMenuBase    *PopupMenuBase;
  30.  
  31. struct Window *w;
  32.  
  33. struct PopupMenu *MakeTestMenu(void);
  34.  
  35. void main()
  36. {
  37.     struct IntuiMessage *im,imsg;
  38.     struct PopupMenu *p;
  39.     BOOL r=TRUE;
  40.  
  41.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  42.     if(PopupMenuBase) {
  43.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  44.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  45.  
  46.         p=MakeTestMenu(); // Declared at the end of this file.
  47.  
  48.         if(p) {
  49.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_VANILLAKEY,    // Open a little window
  50.                     WA_RMBTrap,    TRUE,
  51.                     WA_DragBar,    TRUE,
  52.                     WA_Width,    150,
  53.                     WA_Height,    100,
  54.                     WA_Left,    0,
  55.                     WA_Top,        100,
  56.                     WA_Title,    "Layout",
  57.                     WA_CloseGadget,    TRUE,
  58.                     TAG_DONE);
  59.             if(w) {
  60.                 while(r) {
  61.                     WaitPort(w->UserPort);                        // Wait for a message
  62.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  63.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  64.                         ReplyMsg((struct Message *)im);                // Reply the message
  65.  
  66.                         if(imsg.Class==IDCMP_MOUSEBUTTONS && imsg.Code==MENUDOWN) {
  67.                             if(PM_OpenPopupMenu(w, PM_Menu, p, TAG_DONE)==5) r=FALSE;
  68.                         }
  69.                         if(imsg.Class==IDCMP_CLOSEWINDOW) r=FALSE;        // See if the user wants to quit
  70.                     }
  71.                 }
  72.                 CloseWindow(w);
  73.             } else printf("Window error!\n");
  74.             PM_FreePopupMenu(p);
  75.         } else printf("Menu error!\n");
  76.         CloseLibrary((struct Library *)PopupMenuBase);
  77.     }
  78. }
  79.  
  80. struct PopupMenu *MakeTestMenu()
  81. {
  82.     struct PopupMenu *p;
  83.  
  84.     p=PMMenu("Group Layout"),
  85.  
  86.         PMHoriz,
  87.             PMMembers,
  88.  
  89.                 PMItem("Left"), PM_Center, TRUE, End,
  90.  
  91.                 PMVert,
  92.                     PMMembers,
  93.                         PMItem("Item 1"), PM_Center, TRUE, End,
  94.                         PMItem("Item 2"), PM_Center, TRUE, End,
  95.                         PMItem("Item 3"), PM_Center, TRUE, End,
  96.                         PMItem("Item 4"), PM_Center, TRUE, End,
  97.                         PMItem("Item 5"), PM_Center, TRUE, End,
  98.                         PMItem("Item 6"), PM_Center, TRUE, End,
  99.                     End,
  100.                 End,
  101.  
  102.                 PMItem("Right"), PM_Center, TRUE, End,
  103.  
  104.             End,
  105.         End,
  106.  
  107.         PMBar,    End,
  108.  
  109.         PMVert,
  110.             PMMembers,
  111.  
  112.                 PMHoriz,
  113.                     PMMembers,
  114.                         PMColBox(1), End,
  115.                         PMColBox(2), End,
  116.                         PMColBox(3), End,
  117.                         PMColBox(4), End,
  118.                         PMColBox(5), End,
  119.                         PMColBox(6), End,
  120.                         PMColBox(7), End,
  121.                         PMColBox(8), End,
  122.                         PMColBox(9), End,
  123.                         PMColBox(0), End,
  124.                     End,
  125.                 End,
  126.  
  127.                 PMHoriz,
  128.                     PMMembers,
  129.                         PMColBox(11), End,
  130.                         PMColBox(12), End,
  131.                         PMColBox(13), End,
  132.                         PMColBox(14), End,
  133.                         PMColBox(15), End,
  134.                         PMColBox(16), End,
  135.                         PMColBox(17), End,
  136.                         PMColBox(18), End,
  137.                         PMColBox(19), End,
  138.                         PMColBox(10), End,
  139.                     End,
  140.                 End,
  141.  
  142.                 PMHoriz,
  143.                     PMMembers,
  144.                         PMColBox(21), End,
  145.                         PMColBox(22), End,
  146.                         PMColBox(23), End,
  147.                         PMColBox(24), End,
  148.                         PMColBox(25), End,
  149.                         PMColBox(26), End,
  150.                         PMColBox(27), End,
  151.                         PMColBox(28), End,
  152.                         PMColBox(29), End,
  153.                         PMColBox(20), End,
  154.                     End,
  155.                 End,
  156.  
  157.                 PMHoriz,
  158.                     PMMembers,
  159.                         PMColBox(31), End,
  160.                         PMColBox(32), End,
  161.                         PMColBox(33), End,
  162.                         PMColBox(34), End,
  163.                         PMColBox(35), End,
  164.                         PMColBox(36), End,
  165.                         PMColBox(37), End,
  166.                         PMColBox(38), End,
  167.                         PMColBox(39), End,
  168.                         PMColBox(30), End,
  169.                     End,
  170.                 End,
  171.  
  172.                 PMHoriz,
  173.                     PMMembers,
  174.                         PMColBox(41), End,
  175.                         PMColBox(42), End,
  176.                         PMColBox(43), End,
  177.                         PMColBox(44), End,
  178.                         PMColBox(45), End,
  179.                         PMColBox(46), End,
  180.                         PMColBox(47), End,
  181.                         PMColBox(48), End,
  182.                         PMColBox(49), End,
  183.                         PMColBox(40), End,
  184.                     End,
  185.                 End,
  186.  
  187.             End,
  188.         End,
  189.  
  190.         PMBar,    End,
  191.         PMItem("Quit"), PM_UserData, 5, End,
  192.     End;
  193.     
  194.     return p;
  195. }
  196.