home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Snippets / PopupMenu Tester 1.0.2 / Tester.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-04  |  2.7 KB  |  125 lines  |  [TEXT/CWIE]

  1. /***********************************************************************
  2.  ******* PopupMenu Tester **********************************************
  3.  ***********************************************************************
  4.  Written by Paul Celestin
  5.  
  6.  Public Domain - use at your own discretion, in any way you see fit
  7.  
  8.  This simple application demonstrates the use of a System-7 popup menu,
  9.  as well as a movable modal dialog. It doesn't do much else, but maybe
  10.  it has something to offer to someone who is new to all of this.
  11.  
  12.  941103 - 1.0.0 initial version
  13.  951215 - 1.0.2 updated for CW7
  14.  **********************************************************************/
  15.  
  16. #include    <Dialogs.h>
  17. #include    <Events.h>
  18.  
  19. #define        kTestDLOG    128
  20. #define        kMenu        128
  21. #define        kItemQuit    1
  22. #define        kItemPopup    2
  23. #define        kDelay        8
  24.  
  25. Boolean        gDone = false;
  26.  
  27. pascal Boolean ModalDragProc(DialogPtr inDialog, EventRecord *inEvent, short *pItem)
  28. {
  29.     Boolean done = false;
  30.  
  31.     switch (inEvent->what)
  32.     {
  33.         case mouseDown:
  34.         {
  35.             WindowPtr    myWindow;
  36.             RgnHandle    theGrayRgn;
  37.  
  38.             short thePart = FindWindow(inEvent->where,&myWindow);
  39.             if ((thePart == inDrag) && (myWindow == inDialog))
  40.             {
  41.                 theGrayRgn = GetGrayRgn();
  42.                 DragWindow(myWindow,inEvent->where,&((**theGrayRgn).rgnBBox));
  43.                 done = true;
  44.             }
  45.         }
  46.         break;
  47.         
  48.         case keyDown:
  49.         {
  50.             char typedChar = inEvent->message & 0x00FF;
  51.  
  52.             switch (typedChar)
  53.             {
  54.                 case 0x03: /* the Enter key */
  55.                 case 0x0D: /* the Return key */
  56.                 {
  57.                     short    iType,iValue;
  58.                     long    delay;
  59.                     Handle    iHandle;
  60.                     Rect    iRect;
  61.                     
  62.                     GetDItem(inDialog,kItemQuit,&iType,&iHandle,&iRect);
  63.                     if (iHandle) /* it exists */
  64.                     {
  65.                         iValue = !GetCtlValue((ControlHandle)iHandle);
  66.                         HiliteControl((ControlHandle)iHandle,1);
  67.                         Delay(kDelay,&delay);
  68.                         HiliteControl((ControlHandle)iHandle,0);
  69.                     }
  70.                     done = true;
  71.                     gDone = true;
  72.                 }
  73.                 break;
  74.             }
  75.         }
  76.         break;
  77.  
  78.         }
  79.     return done;
  80. }
  81.  
  82. main()
  83. {
  84.     short        itemType, itemHit, myChoice;
  85.     Str255        myTitle;
  86.     DialogPtr    myDialog;
  87.     Handle        myPopHandle;
  88.     MenuHandle    myMenu;
  89.     Rect        myPopRect;
  90.  
  91.     InitGraf(&qd.thePort);
  92.     InitFonts();
  93.     InitWindows();
  94.     InitMenus();
  95.     TEInit();
  96.     InitDialogs(0);
  97.     InitCursor();
  98.  
  99.     myDialog = GetNewDialog(kTestDLOG,0,(WindowPtr) -1);
  100.     if (myDialog)
  101.     {
  102.         while (!gDone)
  103.         {
  104.             ModalDialog(ModalDragProc,&itemHit);
  105.  
  106.             switch(itemHit)
  107.             {
  108.                 case kItemQuit:
  109.                     gDone = true;
  110.                 break;
  111.  
  112.                 case kItemPopup:
  113.                     /* user selected the popup menu, let's show selection in title bar */
  114.                     GetDItem(myDialog,kItemPopup,&itemType,&myPopHandle,&myPopRect);
  115.                     myChoice = GetCtlValue((ControlHandle)myPopHandle);
  116.                     myMenu = GetMenu(kMenu);
  117.                     GetItem(myMenu,myChoice,myTitle);
  118.                     SetWTitle(myDialog,myTitle);
  119.                 break;
  120.             }
  121.         }
  122.         DisposeDialog(myDialog);
  123.     }
  124. }
  125.