home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.09 Sep 90 / LSObjectShell / ObjectShell.p < prev    next >
Encoding:
Text File  |  1989-10-15  |  6.9 KB  |  341 lines  |  [TEXT/PJMM]

  1. PROGRAM ObjectShell;
  2. {***********************************}
  3.     USES
  4.         MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, MacPrint, ObjIntf, GlobalStuff, StdWindows, StdMenus, MyMenus;
  5.  
  6. {========================================}
  7.     PROCEDURE Escape;
  8.     BEGIN
  9.         ExitToShell
  10.     END; {Escape}
  11.  
  12. {========================================}
  13.     PROCEDURE InitToolbox (vMasters: Integer);
  14.         VAR
  15.             i: Integer;
  16.  
  17.     BEGIN
  18.         MaxApplZone;
  19.         FOR i := 1 TO vMasters DO
  20.             MoreMasters;
  21.         InitGraf(@thePort);
  22.         InitFonts;
  23.         InitWindows;
  24.         InitMenus;
  25.         TEInit;
  26.         InitDialogs(@Escape);
  27.         InitCursor;
  28.         FlushEvents(everyEvent, 0);
  29.     END; {InitToolbox}
  30.  
  31. {----------------------------------------}
  32.     PROCEDURE InitGlobals;
  33.         TYPE
  34.             tShortPointer = ^Integer;
  35.  
  36.         VAR
  37.             vShortPtr: tShortPointer;
  38.  
  39.     BEGIN
  40.         IF BitTst(Ptr(ROM85), 0) THEN
  41.             gMBarHeight := 20
  42.         ELSE
  43.             BEGIN
  44.                 vShortPtr := tShortPointer(MBarHeight);
  45.                 gMBarHeight := vShortPtr^;
  46.             END;
  47.  
  48.         IF BitTst(Ptr(ROM85), 0) THEN
  49.             gMFEvent := FALSE
  50.         ELSE
  51.             gMFEvent := (NGetTrapAddress($60, ToolTrap) <> NGetTrapAddress($9F, ToolTrap));
  52.         gSleep := 10;
  53.         gMouseRgn := NewRgn;
  54.         gMouseRgn := NIL;
  55.  
  56.         gWatch := GetCursor(watchCursor)^^;
  57.         gCross := GetCursor(crossCursor)^^;
  58.         gIBeam := GetCursor(iBeamCursor)^^;
  59.  
  60.         gWCount := 0;
  61.         gCloseFlag := FALSE;
  62.         gDone := FALSE;
  63.     END;    {InitGlobals}
  64.  
  65. {----------------------------------------}
  66.     PROCEDURE InitRects;
  67.     BEGIN
  68.         gMinWidth := 108;
  69.         gMinHeight := 72;
  70.         WITH ScreenBits.Bounds DO
  71.             BEGIN
  72.                 SetRect(gDeskTopRect, left, top + gMBarHeight, right, bottom);
  73.                 gDragRect := gDeskTopRect;
  74.                 InsetRect(gDragRect, kScreenMargin, kScreenMargin);
  75.                 SetRect(gGrowRect, gMinWidth, gMinHeight, right - kScreenMargin, bottom - kScreenMargin);
  76.             END;
  77.     END;    {InitRects}
  78.  
  79. {----------------------------------------}
  80.     PROCEDURE InitPrint;
  81.     BEGIN
  82.         gPrintHdl := THPrint(NewHandle(SizeOf(TPrint)));
  83.         PrOpen;
  84.         IF OSError(PrError) THEN
  85.             gPrintHdl := NIL;
  86.         PrintDefault(gPrintHdl);
  87.         IF OSError(PrError) THEN
  88.             gPrintHdl := NIL;
  89.         PrClose;
  90.         IF OSError(PrError) THEN
  91.             gPrintHdl := NIL;
  92.     END;    {InitPrint}
  93.  
  94. {----------------------------------------}
  95.     PROCEDURE CheckFinder;
  96.         VAR
  97.             vMessage: Integer;
  98.             vDocMax: Integer;
  99.             vIndex: Integer;
  100.             vInfo: AppFile;
  101.  
  102.     BEGIN
  103.         CountAppFiles(vMessage, vDocMax);
  104.         IF vDocMax > 0 THEN
  105.             IF vMessage = appOpen THEN
  106.                 FOR vIndex := 1 TO vDocMax DO
  107.                     BEGIN
  108.                         IF FrontWindow <> NIL THEN
  109.                             BEGIN
  110.                                 gEvent.message := GetWRefCon(oWindow.fWPtr);
  111.                                 BitClr(@gEvent.modifiers, 15);
  112.                                 oWindow.Activate;
  113.                             END;
  114.                         GetAppFiles(vIndex, vInfo);
  115.                         WITH vInfo DO
  116.                             BEGIN
  117.                                 DoNew(kWindowKind, fType);
  118.                                 oWindow.DoOpen(fName, vRefNum);
  119.                             END;
  120.                         ClrAppFiles(vIndex);
  121.                     END;
  122.     END; {CheckFinder}
  123.  
  124. {========================================}
  125.     PROCEDURE DoApplTasks;
  126.     BEGIN
  127.         IF IsAppWindow(FrontWindow) THEN
  128.             BEGIN
  129.                 oWindow := TWindow(GetWRefCon(FrontWindow));
  130.                 oWindow.ApplTask;
  131.             END;
  132.         IF gCloseFlag THEN
  133.             BEGIN
  134.                 SetMyMenuBar;
  135.                 gCloseFlag := FALSE;
  136.             END;
  137.     END; {DoApplTasks}
  138.  
  139. {========================================}
  140.     PROCEDURE DoMenuClick (vMenuCode: LongInt);
  141.         VAR
  142.             vMenu: Integer;
  143.             vItem: Integer;
  144.  
  145.     BEGIN
  146.         vMenu := HiWord(vMenuCode);
  147.         vItem := LoWord(vMenuCode);
  148.         CASE vMenu OF
  149.             kAppleID..kEditID: 
  150.                 ClickInStdMenus(vMenu, vItem);
  151.             OTHERWISE
  152.                 ClickInMyMenus(vMenu, vItem);
  153.         END;
  154.         HiliteMenu(0);
  155.     END; {DoMenuClick}
  156.  
  157. {----------------------------------------}
  158.     PROCEDURE DoWindowClick (vPart: Integer;
  159.                                     vWPtr: WindowPtr);
  160.     BEGIN
  161.         oWindow := TWindow(GetWRefCon(vWPtr));
  162.         oWindow.ClickInWindow(vPart);
  163.     END;        {DoWindowClick}
  164.  
  165. {----------------------------------------}
  166.     PROCEDURE DoMouseDown;
  167.         VAR
  168.             vPart: Integer;
  169.             vWhichWindow: WindowPtr;
  170.  
  171.     BEGIN
  172.         WITH gEvent DO
  173.             BEGIN
  174.                 vPart := FindWindow(where, vWhichWindow);
  175.                 CASE vPart OF
  176.                     inDesk: 
  177.                         SysBeep(1);
  178.                     inMenuBar: 
  179.                         BEGIN
  180.                             SetStdMenuItems;
  181.                             SetMyMenuItems;
  182.                             DoMenuClick(MenuSelect(where));
  183.                         END;
  184.                     inSysWindow: 
  185.                         SystemClick(gEvent, vWhichWindow);
  186.                     OTHERWISE
  187.                         DoWindowClick(vPart, vWhichWindow);
  188.                 END;
  189.             END;
  190.     END; {DoMouseDown}
  191.  
  192. {========================================}
  193.     PROCEDURE DoKeyPress (vChar: CHAR);
  194.     BEGIN
  195.         oWindow.KeyPress(vChar);
  196.     END;    {DoKeyPress}
  197.  
  198. {----------------------------------------}
  199.     PROCEDURE DoKeyDown;
  200.         VAR
  201.             vCharCode: CHAR;
  202.  
  203.     BEGIN
  204.         WITH gEvent DO
  205.             BEGIN
  206.                 vCharCode := CHR(BitAnd(message, charCodeMask));
  207.                 IF BitAnd(modifiers, CmdKey) = CmdKey THEN
  208.                     BEGIN
  209.                         SetStdMenuItems;
  210.                         SetMyMenuItems;
  211.                         DoMenuClick(MenuKey(vCharCode));
  212.                     END
  213.                 ELSE
  214.                     DoKeyPress(vCharCode);
  215.             END;
  216.     END; {DoKeyDown}
  217.  
  218. {========================================}
  219.     PROCEDURE DoUpdate;
  220.         VAR
  221.             vWhichWindow: WindowPtr;
  222.  
  223.     BEGIN
  224.         vWhichWindow := WindowPtr(gEvent.message);
  225.         oWindow := TWindow(GetWRefCon(vWhichWindow));
  226.         oWindow.Update;
  227.     END; {DoUpdate}
  228.  
  229. {========================================}
  230.     PROCEDURE DoActivate;
  231.         VAR
  232.             vWhichWindow: WindowPtr;
  233.  
  234.     BEGIN
  235.         vWhichWindow := WindowPtr(gEvent.message);
  236.         oWindow := TWindow(GetWRefCon(vWhichWindow));
  237.         oWindow.fWPtr := vWhichWindow;
  238.         oWindow.Activate;
  239.  
  240.         SetMyMenuBar;
  241.     END; {DoActivate}
  242.  
  243. {========================================}
  244.     PROCEDURE DoDiskEvent;
  245.         VAR
  246.             vPt: Point;
  247.             vErr: OSErr;
  248.  
  249.     BEGIN
  250.         IF HiWrd(gEvent.message) <> noErr THEN
  251.             BEGIN
  252.                 CenterDialogBox(290, 100, vPt);
  253.                 vErr := DIBadMount(vPt, gEvent.message);
  254.                 IF vErr IN [1, 2, noErr, ioErr, badMDBErr, noMacDskErr] THEN
  255.                 ELSE IF OSError(vErr) THEN
  256.             END;
  257.     END; {DoDiskEvent}
  258.  
  259. {========================================}
  260.     PROCEDURE DoMFEvent;
  261.         VAR
  262.             vWhichWindow: WindowPtr;
  263.  
  264.     BEGIN
  265.         IF Odd(gEvent.message) THEN
  266.             BitSet(@gEvent.modifiers, 15)
  267.         ELSE
  268.             BitClr(@gEvent.modifiers, 15);
  269.         IF IsAppWindow(FrontWindow) THEN
  270.             BEGIN
  271.                 oWindow := TWindow(GetWRefCon(FrontWindow));
  272.                 oWindow.fWPtr := FrontWindow;
  273.                 oWindow.Activate;
  274.             END;
  275.     END; {DoMFEvent}
  276.  
  277. {========================================}
  278.     PROCEDURE ShutDown;
  279.     BEGIN
  280.         DisposHandle(Handle(gPrintHdl));
  281.         DisposeRgn(gMouseRgn);
  282.         DisposeStdMenus;
  283.         DisposeMyMenus;
  284.     END; {ShutDown}
  285.  
  286. {========================================}
  287. {$I-}
  288. BEGIN {main}
  289.     InitToolbox(kMasters);
  290.     InitGlobals;
  291.     InitRects;
  292.     InitPrint;
  293.     InitStdMenus;
  294.     InitMyMenus;
  295.     DrawMenuBar;
  296.     CheckFinder;
  297.  
  298.     REPEAT
  299.         DoApplTasks;
  300.         IF gMFEvent THEN
  301.             gNextEvent := WaitNextEvent(everyEvent, gEvent, gSleep, gMouseRgn)
  302.         ELSE
  303.             BEGIN
  304.                 SystemTask;
  305.                 gNextEvent := GetNextEvent(everyEvent, gEvent);
  306.             END;
  307.         IF gNextEvent THEN
  308.             CASE gEvent.what OF
  309.                 NullEvent: 
  310.                     ;
  311.                 MouseDown: 
  312.                     DoMouseDown;
  313.                 KeyDown: 
  314.                     DoKeyDown;
  315.                 AutoKey: 
  316.                     DoKeyDown;
  317.                 UpdateEvt: 
  318.                     DoUpdate;
  319.                 ActivateEvt: 
  320.                     DoActivate;
  321.                 DiskEvt: 
  322.                     DoDiskEvent;
  323.                 NetworkEvt: 
  324.                     ;
  325.                 DriverEvt: 
  326.                     ;
  327.                 App1Evt: 
  328.                     ;
  329.                 App2Evt: 
  330.                     ;
  331.                 App3Evt: 
  332.                     ;
  333.                 App4Evt: 
  334.                     DoMFEvent;
  335.                 OTHERWISE
  336.             END;
  337.     UNTIL gDone;
  338.  
  339.     ShutDown;
  340. END. {main}
  341. {***********************************}