home *** CD-ROM | disk | FTP | other *** search
/ Carousel / CAROUSEL.cdr / mactosh / code / c_bmug3.sit < prev    next >
Text File  |  1988-06-20  |  5KB  |  227 lines

  1. 18-Jun-88 14:24:14-MDT,5281;000000000000
  2. Return-Path: <u-lchoqu%sunset@cs.utah.edu>
  3. Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:24:06 MDT
  4. Received: by cs.utah.edu (5.54/utah-2.0-cs)
  5.     id AA22086; Sat, 18 Jun 88 14:24:09 MDT
  6. Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  7.     id AA24488; Sat, 18 Jun 88 14:24:06 MDT
  8. Date: Sat, 18 Jun 88 14:24:06 MDT
  9. From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  10. Message-Id: <8806182024.AA24488@sunset.utah.edu>
  11. To: rthum@simtel20.arpa
  12. Subject: BMUG3.c
  13.  
  14. /* Window - Event  Manager Example    Lesson 3 */
  15.     /* Note that DJB has enforced K&R's standard for indentation */
  16.  
  17. #include "Events.h"
  18. #include "Window.h"
  19. #include "Menu.h"
  20.  
  21. #define    TRUE        1
  22. #define    FALSE    0
  23. #define    NIL        0
  24. #define    KEYMASK    0xFF
  25.  
  26. /*  Menu Stuff  */
  27. #define    Desk_ID        100
  28. #define    File_ID        101
  29. #define    Our_ID        102
  30. #define    BMUG_ID        103
  31.  
  32. MenuHandle    DeskMenu;
  33. MenuHandle    FileMenu;
  34. MenuHandle    OurMenu;
  35. MenuHandle    BMUGMenu;
  36.  
  37. EventRecord     theEvent;
  38. WindowRecord    theWindowRec;    /* Don't Fragment the Heap */
  39. WindowPtr     theWindow,whichWindow;
  40. Rect            windowR,legalR,limitR;
  41. short        windowcode,still_InGoAway;
  42. char            c;
  43. long            newSize;
  44.  
  45. extern struct P_Str *CtoPstr();
  46.     int strlen(str)char *str;
  47.     {int i=0;while (str[i++]);return i-1;}
  48.  
  49. SetUpMenus()
  50. {
  51. /*  Desk Accessory Menu  */
  52. DeskMenu = NewMenu (Desk_ID,CtoPstr("\24"));
  53. AddResMenu (DeskMenu, 'DRVR');
  54. InsertMenu (DeskMenu, 0);
  55.  
  56. /*  File Menu  */
  57. FileMenu = NewMenu (File_ID, CtoPstr("File"));
  58. AppendMenu (FileMenu, CtoPstr("Open Window/M;Close Window/X;Quit/Q"));
  59. InsertMenu (FileMenu,0);
  60. DisableItem (FileMenu, 2);
  61.  
  62. /*  Our Menu  */
  63. OurMenu = NewMenu (Our_ID, CtoPstr("Our Menu"));
  64. AppendMenu (OurMenu, CtoPstr("Hide Window/H;Show Window/S;New Window Title;(-;Show BMUG;Hide BMUG"));
  65. InsertMenu (OurMenu, 0);
  66. DisableItem (OurMenu, 6);
  67. SetItemIcon (OurMenu, 5,1);
  68.  
  69. /*  BMUG Menu  */
  70. BMUGMenu = NewMenu (BMUG_ID, CtoPstr("BMUG"));
  71. AppendMenu (BMUGMenu, CtoPstr("<O<SDevelopers' Group"));
  72.  
  73. DrawMenuBar();
  74. }
  75.  
  76. main()                                          /* main() */
  77. {
  78.  
  79.  
  80.  
  81. InitWindows();
  82. InitCursor();
  83. InitFonts();
  84. FlushEvents(everyEvent);
  85. InitMenus();
  86. SetUpMenus();
  87. theWindow = NIL;
  88. SetRect(&windowR,50,50,300,150);
  89. SetRect(&legalR,5,5,505,335);
  90. SetRect(&limitR, 50,10,500,330);
  91.  
  92.  
  93. while (TRUE) {
  94.     if (GetNextEvent(everyEvent,&theEvent))  { 
  95.         switch (theEvent.what)  { 
  96.         
  97.             case keyDown:
  98.                 c = theEvent.message & cmdKey; 
  99.                 DoWhatTheMenuSays( MenuKey (c) );
  100.                 HiliteMenu(0);
  101.                 break;
  102.                 
  103.             case mouseDown: 
  104.                 windowcode=FindWindow(&theEvent.where,&whichWindow);
  105.                 switch (windowcode) {
  106.                     case inDesk:
  107.                         if((whichWindow = FrontWindow()) != 0)
  108.                             HiliteWindow(whichWindow, FALSE);
  109.                         break;
  110.                         
  111.                     case inMenuBar:
  112.                         DoWhatTheMenuSays(MenuSelect(&theEvent.where));
  113.                         break;
  114.                         
  115.                     case inSysWindow:
  116.                         SysBeep(1);
  117.                         break;
  118.                         
  119.                     case inContent:
  120.                         HiliteWindow(whichWindow, TRUE);
  121.                         break;
  122.                         
  123.                     case inDrag:
  124.                         DragWindow(whichWindow,&theEvent.where,&legalR);
  125.                         break;
  126.                         
  127.                     case inGrow:
  128.                         newSize = GrowWindow(whichWindow,&theEvent.where,&limitR);
  129.                         SizeWindow(whichWindow,LoWord(newSize),HiWord(newSize),FALSE);
  130.                             /* newSize is split into short ints for width and height    */
  131.                         break;
  132.                         
  133.                     case inGoAway:
  134.                         still_InGoAway = TrackGoAway(whichWindow,&theEvent.where);
  135.                         if(still_InGoAway) {
  136.                         CloseWindow(whichWindow);
  137.                         theWindow = NIL;
  138.                         EnableItem(FileMenu,1);
  139.                         DisableItem(FileMenu, 2);
  140.                         }
  141.                         break;
  142.                         
  143.                 }   /* end of switch(windowcode) */
  144.                 break;
  145.     
  146.             default:
  147.                 break;
  148.         }    /* end of switch(theEvent.what) */
  149.     }    /* end of if(GetNext...) */
  150. }    /* end of while(True) */
  151. }    /* end of procedure main() */
  152.  
  153.  
  154. DoWhatTheMenuSays(menuResult,)
  155.     long    menuResult;
  156.     {
  157.     short    menuID, itemNumber;
  158.     menuID = HiWord (menuResult);
  159.     itemNumber = LoWord (menuResult);
  160.     
  161.     switch (menuID)
  162.         {
  163.         case File_ID:
  164.             switch (itemNumber)
  165.                 {
  166.                 case 1:
  167.                     theWindow = NewWindow (&theWindowRec,&windowR,"13/BMUG Rules!",TRUE,documentProc, (WindowPtr) - 1,TRUE,0);
  168.                     DisableItem (FileMenu, 1);
  169.                     EnableItem (FileMenu, 2);
  170.                     break;
  171.                 
  172.                 case 2:
  173.                     CloseWindow (theWindow);
  174.                     theWindow = NIL;
  175.                     DisableItem (FileMenu, 2);
  176.                     EnableItem (FileMenu, 1);
  177.                     break;
  178.                     
  179.                 case 3:
  180.                     ExitToShell();
  181.                     break;
  182.                     
  183.             }  /*  end of case FileMenu  */
  184.             break;  /*  case File_ID  */
  185.                     
  186.         case Our_ID:
  187.             switch (itemNumber) {
  188.                 case 1:
  189.                     HideWindow (theWindow);
  190.                     break;
  191.                         
  192.                 case 2:
  193.                     ShowWindow (theWindow);
  194.                     break;
  195.                     
  196.                 case 3:
  197.                     SetWTitle (theWindow,CtoPstr("A New Title"));
  198.                     break;
  199.                 
  200.                 case 5:
  201.                     InsertMenu (BMUGMenu, 0);
  202.                     EnableItem (OurMenu, 6);
  203.                     DisableItem (OurMenu, 5);
  204.                     DrawMenuBar();
  205.                     break;
  206.                     
  207.                 case 6:
  208.                     DeleteMenu (BMUG_ID);
  209.                     EnableItem (OurMenu, 5);
  210.                     DisableItem (OurMenu, 6);
  211.                     DrawMenuBar();
  212.                     break;
  213.             }  /*  end of menu OurMenu  */
  214.             break;
  215.             
  216.         case Desk_ID:
  217.                     break;
  218.                     
  219.         }  /*  end of switch (menuID)  */
  220.         HiliteMenu(0);
  221.         
  222.     }  /*  end of procedure DoWhatTheMenuSays()  */
  223.  
  224.  
  225.  
  226.  
  227.