home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / luschsrc.sit / context.c < prev    next >
Text File  |  1990-05-23  |  5KB  |  205 lines

  1. /********************************************************************************
  2.  *    context.c
  3.  *
  4.  *    Context Management Package
  5.  *
  6.  *    Written by Paco Xander Nathan
  7.  *    ⌐1990, Motorola Inc.  Public domain source code.
  8.  ********************************************************************************/
  9.  
  10. #include "applic.h"
  11. #include "window.h"
  12. #include "dialog.h"
  13. #include "context.h"
  14. #include "edit.h"
  15. #include "document.h"
  16. #include "ascii.h"
  17. #include "about.h"
  18. #include "noise.h"
  19. #include "help.h"
  20.  
  21. #include "test.h"
  22. #include "gnosis.h"
  23.  
  24.  
  25. /* External Data Structures
  26.  */
  27. MenuHandle
  28.     menu[MAXMENU];
  29.     
  30.  
  31. /* Enable/Disable a menu item... should have been in the MenuMgr Toolbox
  32.  */
  33. void
  34. ContMenuItem (theMenu, theItem, flag)
  35.     register MenuHandle theMenu;
  36.     register short theItem;
  37.     register short flag;
  38. {
  39.     if (flag)
  40.         EnableItem(theMenu, theItem);
  41.     else
  42.         DisableItem(theMenu, theItem);
  43. }
  44.  
  45.  
  46. /* Enable and disable menus based on the current state of the application.  This is
  47.  * called just before MenuSelect() or MenuKey(), so it can set up everything for the
  48.  * Menu Manager.  Since these are the times when the user can select menu items,
  49.  * you only need to enable/disable items then.
  50.  */
  51. void
  52. ContAdjMenu ()
  53. {
  54.     register Boolean closeFlag, viewFlag;
  55.  
  56.     /* Adjust the file menu options
  57.      */
  58.     closeFlag = ((WindowPeek) wPtrGnos)->visible;
  59.     viewFlag = ((WindowPeek) dPtrAnal)->visible;
  60.  
  61.     ContMenuItem(menu[fileM], fmNew, !closeFlag);
  62.     ContMenuItem(menu[fileM], fmOpen, !closeFlag);
  63.     ContMenuItem(menu[fileM], fmClose, closeFlag);
  64.     ContMenuItem(menu[fileM], fmSave, !testUser && closeFlag);
  65.     ContMenuItem(menu[fileM], fmSaveAs, !testUser && closeFlag);
  66.     ContMenuItem(menu[fileM], fmRevert, closeFlag);
  67.     ContMenuItem(menu[fileM], fmPrint, viewFlag);
  68.  
  69.     /* Adjust the test menu options
  70.      */
  71.     SetItemMark(menu[testM], testUserMode, testUser ? asciiCheckMark : asciiNoMark);
  72.     ContMenuItem(menu[testM], testUserMode, testUser);
  73.  
  74.     SetItemMark(menu[testM], testBorderless, testBCraig ? asciiNoMark : asciiCheckMark);
  75.  
  76.     SetItemMark(menu[testM], testInColor, testJDavis ? asciiNoMark : asciiCheckMark);
  77.     ContMenuItem(menu[testM], testInColor, laMachine.hasColor);
  78.  
  79.     /* Adjust the prognosis menu options
  80.      */
  81.     ContMenuItem(menu[gnosM], gnosNew, !testUser && closeFlag);
  82.     ContMenuItem(menu[gnosM], gnosDelete, !testUser && gnosList.open);
  83.     ContMenuItem(menu[gnosM], gnosAnalyze, viewFlag);
  84.     ContMenuItem(menu[gnosM], gnosLearn, !testUser && closeFlag && viewFlag);
  85.     ContMenuItem(menu[gnosM], gnosRecall, closeFlag && viewFlag);
  86. }
  87.  
  88.  
  89. /* Change the cursor's shape, depending on its position.  This also calculates
  90.  * a region that includes the cursor for WaitNextEvent()
  91.  */
  92. void
  93. ContAdjCurs (thePoint, theRgn)
  94.     register Point thePoint;
  95.     register RgnHandle theRgn;
  96. {
  97.     register WindowPtr theWindow = FrontWindow();
  98.     register InfoPtr infoPtr = (InfoPtr) GetWRefCon(theWindow);
  99.     register RgnHandle arrowRgn;
  100.     register RgnHandle iBeamRgn;
  101.     Rect iBeamRect;
  102.     GrafPtr savePort;
  103.  
  104.     GetPort(&savePort);
  105.     SetPort(theWindow);
  106.  
  107.     if (!laMachine.inBackground && !WindIsDA(theWindow)) {
  108.         /* calculate regions for different cursor shapes, start arrowRgn wide-open 
  109.          */
  110.         arrowRgn = NewRgn();
  111.         iBeamRgn = NewRgn();
  112.         SetRectRgn(arrowRgn, -32768, -32768, 32767, 32767);
  113.         
  114.         /* calculate iBeamRgn
  115.          */
  116.         if (WindIsApp(theWindow) && (infoPtr->kind == wkText)) {
  117.             iBeamRect = (*(infoPtr->item.text.teHdl))->viewRect;
  118.  
  119.             LocalToGlobal(&TopLeft(iBeamRect));
  120.             LocalToGlobal(&BotRight(iBeamRect));
  121.             RectRgn(iBeamRgn, &iBeamRect);
  122.         }
  123.  
  124.         /* subtract other regions from arrowRgn
  125.          */
  126.         DiffRgn(arrowRgn, iBeamRgn, arrowRgn);
  127.         
  128.         /* change the cursor and the region parameter 
  129.          */
  130.         if (PtInRgn(thePoint, iBeamRgn)) {
  131.             SetCursor(*GetCursor(iBeamCursor));
  132.             CopyRgn(iBeamRgn, theRgn);
  133.         }
  134.         else {
  135.             SetCursor(&arrow);
  136.             CopyRgn(arrowRgn, theRgn);
  137.         }
  138.         
  139.         /* get rid of local regions
  140.          */
  141.         DisposeRgn(arrowRgn);
  142.         DisposeRgn(iBeamRgn);
  143.     }
  144.  
  145.     SetPort(savePort);
  146. }
  147.  
  148.  
  149. /* Route the various menu and keyboard commands to the appropriate modules
  150.  */
  151. short
  152. ContDispatch (theResult)
  153.     register long theResult;
  154. {
  155.     register WindowPtr theWindow = FrontWindow();
  156.     register short theItem = LoWord(theResult);
  157.     Str255 itemName;
  158.     GrafPtr savePort;
  159.  
  160.     switch(HiWord(theResult)) {
  161.     case appleM + RSRCBASE:
  162.         switch (theItem) {
  163.         case appleAbout:
  164.             NoisePlay(noisePaco);
  165.             AboutAppl();
  166.             break;
  167.  
  168.         case appleHelp:
  169.             HelpAppl();
  170.             break;
  171.  
  172.         default:
  173.             GetItem(menu[appleM], theItem, &itemName);
  174.             GetPort(&savePort);
  175.             OpenDeskAcc(&itemName);
  176.             SetPort(savePort);
  177.             break;
  178.         }
  179.         break;
  180.  
  181.     case fileM + RSRCBASE:
  182.         DocMenu(theItem); 
  183.         break;
  184.  
  185.     case editM + RSRCBASE:
  186.         if (!SystemEdit(theItem - 1))
  187.             EditMenu(theItem);
  188.         break;
  189.     
  190.     case testM + RSRCBASE:
  191.         TestMenu(theItem);
  192.         break;
  193.  
  194.     case gnosM + RSRCBASE:
  195.         GnosMenu(theItem);
  196.         break;
  197.  
  198.     default:
  199.         break;
  200.     }
  201.  
  202.     HiliteMenu(FALSE);
  203.     return TRUE;
  204. }
  205.