home *** CD-ROM | disk | FTP | other *** search
/ back2roots/filegate / filegate.zip / filegate / ads / adsutils / PMDEV.LHA / PopupMenuDeveloper / C / Demos / PullDownMenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-03  |  5.4 KB  |  184 lines

  1. //
  2. // $VER: PullDownMenu.c 2.2 (20.07.00)
  3. //
  4. // Popup Menu example program
  5. //
  6. // ⌐1996-1997 Henrik Isaksson
  7. //
  8. // This code is public domain.
  9. //
  10. // Changes:
  11. //
  12. // 2.2    Added support for PM_Toggle
  13. //
  14.  
  15. #include <intuition/intuition.h>
  16. #include <exec/memory.h>
  17.  
  18. #include <proto/intuition.h>
  19. #include <proto/exec.h>
  20.  
  21. #include <clib/alib_protos.h>
  22.  
  23. #include <string.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26.  
  27. #include <libraries/pm.h>
  28. #include <proto/pm.h>
  29.  
  30. struct IntuitionBase    *IntuitionBase;
  31. struct GfxBase        *GfxBase;
  32. struct PopupMenuBase    *PopupMenuBase;
  33.  
  34. struct Window *w;    // This window is only needed to find out when and where the menu should appear.
  35.             // The font in this window's rastport will be used for the menu.
  36.  
  37. ULONG __saveds __asm MenuHandlerFunc(register __a0 struct Hook *hook,
  38.                      register __a2 APTR object,
  39.                      register __a1 APTR msg)
  40. {
  41.     struct PopupMenu *pm=(struct PopupMenu *)object;
  42.  
  43.     printf("---\n");
  44.     printf("Title:      \"%s\"\n", pm->Title);
  45.     printf("UserData: %lx\n", pm->UserData);
  46.     printf("ID:      %lx\n", pm->ID);
  47.  
  48.     // This is one (the fastest) way of finding out if the item is checked or not:
  49.     // 0x40000000 = CHECKIT
  50.     // 0x80000000 = CHECKED
  51.     if(pm->Flags&0x40000000)
  52.         printf("Checked?  %s\n", pm->Flags&0x80000000?"Yes":"No");
  53.  
  54.     if((int)pm->UserData==5) *((BOOL *)hook->h_Data)=FALSE;
  55. }
  56.  
  57. struct PopupMenu *MakeTestMenu(void);
  58.  
  59. void main()
  60. {
  61.     BOOL r=TRUE;
  62.     struct IntuiMessage *im,imsg;
  63.     struct PopupMenu *p;
  64.     struct Hook MenuHandler;
  65.  
  66.     MenuHandler.h_Entry=(HOOKFUNC)MenuHandlerFunc;
  67.     MenuHandler.h_Data=&r;
  68.  
  69.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  70.     if(PopupMenuBase) {
  71.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  72.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  73.  
  74.         p=MakeTestMenu(); // Declared at the end of this file.
  75.  
  76.         if(p) {
  77.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_VANILLAKEY,    // Open a little window
  78.                     WA_RMBTrap,    TRUE,
  79.                     WA_DragBar,    TRUE,
  80.                     WA_Width,    150,
  81.                     WA_Height,    100,
  82.                     WA_Left,    0,
  83.                     WA_Top,        100,
  84.                     WA_Title,    "PullDown Menus",
  85.                     WA_CloseGadget,    TRUE,
  86.                     TAG_DONE);
  87.             if(w) {
  88.                 while(r) {
  89.                     WaitPort(w->UserPort);                        // Wait for a message
  90.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  91.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  92.                         ReplyMsg((struct Message *)im);                // Reply the message
  93.  
  94.                         PM_FilterIMsg(w, p, &imsg,                // Send the message to pmlib
  95.                             PM_AutoPullDown,    TRUE,            // We want the menu to open automatically
  96.                             PM_MenuHandler,        &MenuHandler,        // Our menuhandler function
  97.                             TAG_DONE);
  98.  
  99.                         if(imsg.Class==IDCMP_CLOSEWINDOW) r=FALSE;        // See if the user wants to quit
  100.                     }
  101.                 }
  102.                 CloseWindow(w);
  103.             } else printf("Window error!\n");
  104.             PM_FreePopupMenu(p);
  105.         } else printf("Menu error!\n");
  106.         CloseLibrary((struct Library *)PopupMenuBase);
  107.     }
  108. }
  109.  
  110. struct PopupMenu *MakeTestMenu()
  111. {
  112.     struct PopupMenu *p;
  113.  
  114.     p=PM_MakeMenu(
  115.         PMItem("Workbench"),
  116.             PMSimpleSub,
  117.                 PMCheckItem("Backdrop?", 1),        PM_CommKey,    "B",    End,
  118.                 PMItem("Execute Command..."),        PM_CommKey,    "E",    End,
  119.                 PMItem("Redraw All"),    End,
  120.                 PMItem("Update All"),    End,
  121.                 PMItem("Last Message"),    End,
  122.                 PMItem("About..."),    PM_CommKey,    "?",    End,
  123.                 PMItem("Quit"),        PM_UserData,    5,    PM_CommKey,    "Q",    End,
  124.             End,
  125.             PM_NoSelect,    FALSE,  // A little trick that will make the menu selectable...
  126.         End,
  127.         PMItem("Window"),
  128.             PMSimpleSub,
  129.                 PMItem("New Drawer"),        PM_CommKey,    "N",    PM_Disabled,    TRUE,    End,
  130.                 PMItem("Open Parent"),                    PM_Disabled,    TRUE,    End,
  131.                 PMItem("Close"),        PM_CommKey,    "K",    PM_Disabled,    TRUE,    End,
  132.                 PMItem("Update"),                    PM_Disabled,    TRUE,    End,
  133.                 PMItem("Select Contents"),    PM_CommKey,    "A",                End,
  134.                 PMItem("Clean Up"),        PM_CommKey,    ".",                End,
  135.                 PMItem("Snapshot"),
  136.                     PMSimpleSub,
  137.                         PMItem("Window"),    End,
  138.                         PMItem("All"),        End,
  139.                     End,
  140.                 End,
  141.                 PMItem("Show"),
  142.                     PMSimpleSub,
  143.                         PMCheckItem("Only Icons", 2),    PM_Toggle, FALSE,    PM_Exclude,    PM_ExLst(3, 0),    PM_Checked,    TRUE,    End,
  144.                         PMCheckItem("All Files", 3),    PM_Toggle, FALSE,    PM_Exclude,    PM_ExLst(2, 0),    End,
  145.                     End,
  146.                     PM_Disabled,    TRUE,
  147.                     //PM_BuiltInIcon,    PMIMG_SHOW,
  148.                 End,
  149.                 PMItem("View By"),
  150.                     PMSimpleSub,
  151.                         PMCheckItem("Icon", 4),        PM_Toggle, FALSE,    PM_Exclude,    PM_ExLst(5, 6, 7, 0),    PM_Checked,    TRUE,    End,
  152.                         PMCheckItem("Name", 5),        PM_Toggle, FALSE,    PM_Exclude,    PM_ExLst(4, 6, 7, 0),    End,
  153.                         PMCheckItem("Date", 6),        PM_Toggle, FALSE,    PM_Exclude,    PM_ExLst(4, 5, 7, 0),    End,
  154.                         PMCheckItem("Size", 7),        PM_Toggle, FALSE,    PM_Exclude,    PM_ExLst(4, 5, 6, 0),    End,
  155.                     End,
  156.                     PM_Disabled,    FALSE,
  157.                 End,
  158.             End,
  159.         End,
  160.         PMItem("Icons"),
  161.             PMSimpleSub,
  162.                 PMItem("Open"),            PM_CommKey,    "O",    End,
  163.                 PMItem("Copy"),            PM_CommKey,    "C",    End,
  164.                 PMItem("Rename..."),        PM_CommKey,    "R",    End,
  165.                 PMItem("Information..."),    PM_CommKey,    "I",    End,
  166.                 PMItem("Snapshot"),        PM_CommKey,    "S",    End,
  167.                 PMItem("UnSnapshot"),        PM_CommKey,    "U",    End,
  168.                 PMItem("Leave Out"),        PM_CommKey,    "L",    End,
  169.                 PMItem("Put Away"),        PM_CommKey,    "P",    End,
  170.                 PMBar,                            End,
  171.                 PMItem("Delete..."),        PM_Disabled,    TRUE,    End,
  172.                 PMItem("FormatDisk..."),                End,
  173.                 PMItem("Empty Trash"),        PM_Disabled,    TRUE,    End,
  174.             End,
  175.         End,
  176.         PMItem("Tools"),
  177.             PMSimpleSub,
  178.                 PMItem("ResetWB"),    End,
  179.             End,
  180.         End,
  181.     End;
  182.  
  183.     return p;
  184. }