home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / MacGS 2.5.2ß3 / (MacGSLib.π) / macEvents.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-17  |  40.5 KB  |  2,110 lines  |  [TEXT/R*ch]

  1. /* Copyright (C) 1993 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* macEvent.c */
  21. /* Macintosh graphics window event loop driver for Ghostscript library */
  22.  
  23. #include <stdio.h>
  24. #include <stddef.h>
  25. #include <string.h>
  26. #include <console.h>
  27. #include "gdevmac.h"
  28. #include "gserrors.h"
  29. #include "gp_mac.h"
  30. #include "gmacprefs.h"
  31. #include "macPrint.h"
  32. #include "gp_macui.h"
  33. #include "drvr.h"
  34.  
  35.  
  36. static void DoInit            (MenuHandle hGUIMenu, short menuOffset);
  37. static void DoCursor        (void);
  38. static void DoCut            (void);
  39. static void DoCopy            (void);
  40. static void DoClear            (void);
  41. static void DoMenu            (short menuItem);
  42. static void DoActivate        (Boolean fDoActive, CWindowPtr windowPtr);
  43. static void DoUpdate        (CWindowPtr windowPtr);
  44. static void DoMouseDown        (EventRecord *pEvent);
  45. static void DoKeyEvent        (EventRecord *pEvent);
  46. static void DoConsolePuts    (void);
  47. static void DoOpenFilePre    (void);
  48. static void DoOpenFilePost    (void);
  49. static char DoOptionsProc    (short actionValue);
  50. static void DoTerminate        (void);
  51.  
  52.  
  53. GUIProcRec macGUIProcs =
  54. {
  55.     DoInit,
  56.     DoCursor,
  57.     DoCut,
  58.     DoCopy,
  59.     (GUINoArgFunc) NULL,    //    DoPaste
  60.     DoClear,
  61.     DoMenu,
  62.     DoActivate,
  63.     DoUpdate,
  64.     DoMouseDown,
  65.     DoKeyEvent,
  66.     DoConsolePuts,
  67.     DoOpenFilePre,
  68.     DoOpenFilePost,
  69.     DoOptionsProc,    //    (GUIOptionsProc) NULL,    //    DoOptionsProc
  70.     DoTerminate
  71. };
  72.  
  73.  
  74. extern gx_device_mac    gs_mac_device;
  75. extern Boolean            gDoCheckInterrupts;
  76.  
  77.  
  78. typedef struct
  79. {
  80.     short            graphicsRefNum;            /*    window driver reference number    */
  81.  
  82.     RgnHandle        saveClipRgn;            /*    original clipping region         */
  83.     RgnHandle        clipRgn;                /*    clipping region for scrollbars    */
  84.     RgnHandle        updRgn;                    /*    update region for scrolling        */
  85.     Rect            updRect;
  86.     Boolean            fIsDirty;
  87.  
  88.     Point            origin;
  89.  
  90.     Rect            viewRect;
  91.     short            viewWidth;
  92.     short            viewHeight;
  93.  
  94.     PicHandle        hPicture;                /*    current (possibly open) picture    */
  95.     Size            pictLen;                /*    current picture size            */
  96.     Rect            pictRect;
  97.     CWindowPtr        pictWin;
  98.     Boolean            fOpenPicture;
  99.  
  100.     Rect            growRect;                /*    GrowWindow () limits            */
  101.  
  102.     ControlHandle    hScrollBar;
  103.     short            hValue;
  104.     ControlHandle    vScrollBar;
  105.     short            vValue;
  106.     short            delScroll;
  107.  
  108.     ResType            fCreator;
  109.  
  110.     GrafPtr            savePort;
  111.  
  112. } MacWinRec, *MacWinPtr, **MacWinH;
  113.  
  114.  
  115. #define mac_white_color_index        (gx_color_index) 0x00FFFFFF
  116.  
  117. enum
  118. {
  119.     iSavePicture = 1,
  120.     iSaveSelection,
  121.     iCopySelection,
  122.     _iLine1,
  123.     iPageSetUp,
  124.     iPrint,
  125.     _iLine2,
  126.     iCmdWindow,
  127.     iResume,
  128.     iStopProc,
  129.  
  130.     __iLastMacGSMenuItem
  131. };
  132.  
  133.  
  134. void        macCreatePicture (gx_device *dev);
  135. void        macClosePicture  (gx_device *dev);
  136. void        macClearPicture  (gx_device *dev);
  137. void        macCopyPicture   (gx_device *dev);
  138. PicHandle    macGetPicture     (gx_device *dev);
  139. Boolean        macSavePicture     (gx_device *dev, PicHandle hPicture);
  140. short        macCreateWindow     (gx_device *dev, short pictWidth, short pictHeight);
  141. void        macClearWindow   (gx_device *dev);
  142. short        macCloseWindow   (gx_device *dev);
  143. void        macInvalWindow   (gx_device *dev, Boolean fResetOrigin);
  144. void        macRedrawWindow  (gx_device *dev);
  145. void        macResizeWindow  (gx_device *dev);
  146. void         macBeginDraw     (gx_device *dev);
  147. void         macEndDraw       (gx_device *dev);
  148. void         macBeginPictDraw (gx_device *dev);
  149. short         macEndPictDraw      (gx_device *dev);
  150. CWindowPtr    macPictWindow     (gx_device *dev);
  151. Rect       *macViewRect         (gx_device *dev);
  152.  
  153.  
  154. static MenuHandle    hGUIMenu         = (MenuHandle) NULL;
  155. static short        numGUIMenuItems;
  156. static Str255        cmdWindowStr;
  157. static Str255        graphicsWindowStr;
  158. static Boolean        fMenuSavePicture = FALSE;
  159. static Boolean        fIsInConfirm     = FALSE;
  160. static short        old_mac_pause_atexit;
  161. static GrafPtr        openFileSavePort = (GrafPtr) NULL;
  162.  
  163.  
  164. static void        macConfirmSetup (short state);
  165. static void        doMacConfirmCB    (Boolean fIsActive);
  166. static void        swapConsoleControl (Boolean fSaveConsoleControl);
  167.  
  168.  
  169. #define MENUAPPENDSTR(index)                            \
  170. {                                                        \
  171.     GetIndString (string, MACMENUSTRS_RES_ID, index);    \
  172.     AppendMenu (hGUIMenu, string);                        \
  173. }
  174.  
  175.  
  176. /*
  177.  *
  178.  */
  179.  
  180.     static void
  181. DoInit (MenuHandle theGUIMenuH, short menuOffset)
  182.  
  183. {    
  184.     Str255        string;
  185.  
  186.  
  187.     hGUIMenu        = theGUIMenuH;
  188.     numGUIMenuItems = menuOffset;
  189.  
  190.     MENUAPPENDSTR (iSavePictureMenuStr);
  191.     MENUAPPENDSTR (iPrintMenuStr);
  192.     MENUAPPENDSTR (iCommandMenuStr);
  193.  
  194.     GetItem (hGUIMenu, iCmdWindow + numGUIMenuItems, cmdWindowStr);
  195.     GetIndString ((StringPtr) graphicsWindowStr, MACMENUSTRS_RES_ID, iGraphicsWindowStr);
  196.     SetItem (hGUIMenu, iCmdWindow + numGUIMenuItems, graphicsWindowStr);
  197.  
  198.     (void) doRunIndString (iShowpageMac);
  199. }
  200.  
  201.  
  202. /*
  203.  *
  204.  */
  205.  
  206.     static void
  207. DoCursor (void)
  208.  
  209. {
  210.     Point        where;
  211.     CWindowPtr    windowPtr = gs_mac_device.windowPtr;
  212.     MacWinH        hMacWin   = (MacWinH) GetWRefCon ((WindowPtr) windowPtr);
  213.     Rect        *pViewRect = &((*hMacWin)->viewRect);
  214.     Boolean        gp_in_check_interrupts (void);
  215.     void        macInitCursor (void);
  216.  
  217.  
  218.     if (gp_in_check_interrupts ())
  219.         return;
  220.  
  221.     SetPort ((GrafPtr) windowPtr);
  222.     GetMouse (&where);
  223.  
  224.     if (PtInRect (where, pViewRect))
  225.         SetCursor (*GetCursor (fIsInConfirm ? plusCursor : crossCursor));
  226.     else
  227.         macInitCursor ();
  228. }
  229.  
  230.  
  231.     static void
  232. DoCut (void)
  233.  
  234. {
  235.     macClosePicture ((gx_device *) &gs_mac_device);
  236.     macCopyPicture  ((gx_device *) &gs_mac_device);
  237.     macClearWindow  ((gx_device *) &gs_mac_device);
  238. }
  239.  
  240.  
  241.     static void
  242. DoCopy (void)
  243.  
  244. {
  245.     macClosePicture ((gx_device *) &gs_mac_device);
  246.     macCopyPicture  ((gx_device *) &gs_mac_device);
  247. }
  248.  
  249.  
  250.     static void
  251. DoClear (void)
  252.  
  253. {
  254.     if (fIsInConfirm)
  255.         macConfirmSetup (2);
  256.     else
  257.         macClearWindow ((gx_device *) &gs_mac_device);
  258. }
  259.  
  260.  
  261. /*
  262.  *    DoMenu -- handles MacGS menu events
  263.  *
  264.  */
  265.  
  266.     static void
  267. DoMenu (short menuItem)
  268.  
  269. {
  270.     switch (menuItem - numGUIMenuItems)
  271.     {
  272.         case iSavePicture:
  273.         {
  274.             PicHandle    hPicture = macGetPicture ((gx_device *) &gs_mac_device);
  275.  
  276.  
  277.             macClosePicture ((gx_device *) &gs_mac_device);
  278.             fMenuSavePicture = macSavePicture ((gx_device *) &gs_mac_device, hPicture);
  279.  
  280.             break;
  281.         }
  282.  
  283.         case iSaveSelection:
  284.         {
  285.             Boolean        macSavePictureSelection (gx_device *dev);
  286.  
  287.  
  288.             macClosePicture    ((gx_device *) &gs_mac_device);
  289.             fMenuSavePicture = macSavePictureSelection ((gx_device *) &gs_mac_device);
  290.  
  291.             break;
  292.         }
  293.  
  294.         case iCopySelection:
  295.         {
  296.             void    macCopyPictureSelection (gx_device *dev);
  297.  
  298.  
  299.             macClosePicture    ((gx_device *) &gs_mac_device);
  300.             macCopyPictureSelection ((gx_device *) &gs_mac_device);
  301.  
  302.             break;
  303.         }
  304.  
  305.         case iResume:
  306.         {
  307.             macConfirmSetup (2);
  308.  
  309.             break;
  310.         }
  311.  
  312.         case iStopProc:
  313.         {
  314.             macConfirmSetup (3);
  315.  
  316.             break;
  317.         }
  318.  
  319.         case iPageSetUp:
  320.         {
  321.             MacDoPrStyleDlg ();
  322.  
  323.             break;
  324.         }
  325.  
  326.         case iPrint:
  327.         {
  328.             void    doPrint (gx_device *dev);
  329.  
  330.  
  331.             doPrint ((gx_device *) &gs_mac_device);
  332.  
  333.             break;
  334.         }
  335.  
  336.         case iCmdWindow:
  337.         {
  338.             SendBehind (FrontWindow (), (WindowPtr) NULL);
  339.             break;
  340.         }
  341.     }
  342.  
  343.     HiliteMenu (0);
  344. }
  345.  
  346.  
  347.     static void
  348. DoActivate (Boolean fDoActive, CWindowPtr windowPtr)
  349.  
  350. {
  351.     MacWinH            hMacWin        = (MacWinH) GetWRefCon ((WindowPtr) windowPtr);
  352.     CWindowPtr        pictWin        = (*hMacWin)->pictWin;
  353.     MenuHandle        hEditMenu    = GetMHandle (EditMenuID);
  354.     Boolean            fDoPost        = TRUE;
  355.     short            cClear;
  356.  
  357.  
  358.     if (fDoActive)
  359.     {
  360.         DisableItem (hEditMenu, iUndo);
  361.         DisableItem (hEditMenu, iPaste);
  362.         cClear = (short) 'K';
  363.         HiliteControl ((*hMacWin)->hScrollBar, 0);
  364.         HiliteControl ((*hMacWin)->vScrollBar, 0);
  365.     }
  366.     else
  367.     {
  368.         if (!fMenuSavePicture)
  369.         {
  370.             EnableItem (hEditMenu, iUndo);
  371.             EnableItem (hEditMenu, iPaste);
  372.             cClear = (short) '\0';
  373.         }
  374.         else
  375.         {
  376.             fMenuSavePicture = FALSE;
  377.             fDoPost             = FALSE;
  378.         }
  379.  
  380.         HiliteControl ((*hMacWin)->hScrollBar, 255);
  381.         HiliteControl ((*hMacWin)->vScrollBar, 255);
  382.     }
  383.  
  384.     macConfirmSetup (0);
  385.  
  386.     if (fDoPost)
  387.     {
  388.         SetItemCmd  (hEditMenu, iClear, cClear);
  389.         DrawMenuBar ();
  390.         DrawGrowIcon ((WindowPtr) windowPtr);
  391.     }
  392.  
  393.     SetItem (hGUIMenu, iCmdWindow + numGUIMenuItems,
  394.              fDoActive ? cmdWindowStr : graphicsWindowStr);
  395. }
  396.  
  397.  
  398.     static void
  399. DoUpdate (CWindowPtr windowPtr)
  400.  
  401. {
  402.     CWindowPeek    pWindowPeek = (CWindowPeek) windowPtr;
  403.     MacWinH        hMacWin        = (MacWinH) GetWRefCon ((WindowPtr) pWindowPeek);
  404.     CWindowPtr    pictWin        = (*hMacWin)->pictWin;
  405.  
  406.  
  407.     if (!(*hMacWin)->fOpenPicture &&
  408.         (*hMacWin)->hPicture /* != (PicHandle) NULL */)
  409.     {
  410.         gx_device   *dev = (gx_device *) &gs_mac_device;
  411.  
  412.  
  413.         macBeginDraw (dev);
  414.             DrawPicture ((*hMacWin)->hPicture, &((*hMacWin)->pictRect));
  415.         macEndDraw (dev);
  416.  
  417.         (*hMacWin)->fIsDirty = FALSE;
  418.     }
  419.  
  420.     DrawControls ((WindowPtr) pWindowPeek);
  421.     DrawGrowIcon ((WindowPtr) pWindowPeek);
  422. }
  423.  
  424.  
  425. enum
  426. {
  427.     iPostDoNothing,
  428.     iPostCmdWindow,
  429.     iPostScrollKeys
  430. };
  431.  
  432.  
  433. /*
  434.  *    DoKeyEvent -- handles keyboard events
  435.  *
  436.  */
  437.  
  438.     static void
  439. DoKeyEvent (EventRecord *pEvent)
  440.  
  441. {
  442.     gx_device  *dev = (gx_device *) &gs_mac_device;
  443.  
  444.  
  445.     if (pEvent->modifiers & cmdKey)
  446.     {
  447.         char            aChar        = pEvent->message & charCodeMask;
  448.         short            flashMenuID = 0;
  449.         char            iPostAction = iPostDoNothing;
  450.  
  451.  
  452.         if ('a' <= aChar && aChar <= 'z')
  453.             aChar += 'A' - 'a';
  454.  
  455.         switch (aChar)
  456.         {
  457.             case 'R':
  458.             {
  459.                 macConfirmSetup (2);
  460.                 flashMenuID = MacGSMenuID;
  461.  
  462.                 break;
  463.             }
  464.  
  465.             case 'P':
  466.             {
  467.                 void    doPrint (gx_device *dev);
  468.  
  469.  
  470.                 FlashMenuBar (MacGSMenuID);
  471.                 flashMenuID = MacGSMenuID;
  472.                 doPrint (dev);
  473.  
  474.                 break;
  475.             }
  476.  
  477.             case 'S':
  478.             {
  479.                 FlashMenuBar (MacGSMenuID);
  480.                 flashMenuID = MacGSMenuID;
  481.  
  482.                 fMenuSavePicture = macSavePicture (dev, macGetPicture (dev));
  483.                 break;
  484.             }
  485.  
  486.             case 'W':
  487.             {
  488.                 flashMenuID = MacGSMenuID;
  489.                 iPostAction = iPostCmdWindow;
  490.                 break;
  491.             }
  492.  
  493.             case 'C':
  494.             {
  495.                 DoCopy ();
  496.                 flashMenuID = EditMenuID;
  497.                 break;
  498.             }
  499.  
  500.             case 'X':
  501.             {
  502.                 DoCut ();
  503.                 flashMenuID = EditMenuID;
  504.                 break;
  505.             }
  506.  
  507.             case 'K':
  508.             {
  509.                 macClosePicture (dev);
  510.                 if (fIsInConfirm)
  511.                     macConfirmSetup (2);
  512.                 else
  513.                     macClearWindow (dev);
  514.                 flashMenuID = EditMenuID;
  515.                 break;
  516.             }
  517.  
  518.             case 'Q':
  519.             {
  520.                 macClosePicture (dev);
  521.                 break;
  522.             }
  523.         }
  524.  
  525.         if (flashMenuID /* != 0 */)
  526.         {
  527.             FlashMenuBar (flashMenuID);
  528.             if (flashMenuID > 0)
  529.                 FlashMenuBar (flashMenuID);
  530.             HiliteMenu (0);
  531.         }
  532.  
  533.         switch (iPostAction)
  534.         {
  535.             case iPostCmdWindow:
  536.                 SendBehind (FrontWindow (), (WindowPtr) NULL);
  537.                 break;
  538.  
  539.             default:
  540.                 break;
  541.         }
  542.     }
  543.     else
  544.     {
  545.         char            aChar        = pEvent->message & charCodeMask;
  546.         short            flashMenuID = 0;
  547.         char            iPostAction = iPostDoNothing;
  548.         ControlHandle    hControl    = (ControlHandle) NULL;
  549.         short            iCtlPart;
  550.  
  551.  
  552.         if ('a' <= aChar && aChar <= 'z')
  553.             aChar += 'A' - 'a';
  554.  
  555.         switch (aChar)
  556.         {
  557.             case 0x01:                /*    home        */
  558.             case 0x04:                /*    end            */
  559.             case 0x0B:                /*    page up        */
  560.             case 0x0C:                /*    page down    */
  561.             case 0x1C:                /*  left arrow    */
  562.             case 0x1D:                /*  right arrow */
  563.             case 0x1E:                /*  up arrow    */
  564.             case 0x1F:                /*  down arrow  */
  565.             {
  566.                 MacWinH        hMacWin = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  567.  
  568.  
  569.                 switch (aChar)
  570.                 {
  571.                     case 0x1C:
  572.                     case 0x1D:
  573.                         hControl = (*hMacWin)->hScrollBar;
  574.                         break;
  575.  
  576.                     case 0x1E:
  577.                     case 0x1F:
  578.                         hControl = (*hMacWin)->vScrollBar;
  579.                         break;
  580.  
  581.                     default:
  582.                         hControl = (pEvent->modifiers & optionKey)
  583.                                        ? (*hMacWin)->hScrollBar
  584.                                        : (*hMacWin)->vScrollBar;
  585.                         break;
  586.                 }
  587.  
  588.                 switch (aChar)
  589.                 {
  590.                     case 0x1C:
  591.                     case 0x1E:
  592.                         iCtlPart = inUpButton;
  593.                         break;
  594.  
  595.                     case 0x1D:
  596.                     case 0x1F:
  597.                         iCtlPart = inDownButton;
  598.                         break;
  599.  
  600.                     case 0x0B:
  601.                         iCtlPart = inPageUp;
  602.                         break;
  603.  
  604.                     case 0x0C:
  605.                         iCtlPart = inPageDown;
  606.                         break;
  607.  
  608.                     case 0x01:
  609.                     case 0x04:
  610.                     {
  611.                         iCtlPart = inThumb;
  612.  
  613.                         if (aChar == 0x01)
  614.                             SetCtlValue (hControl, GetCtlMin (hControl));
  615.                         else
  616.                             SetCtlValue (hControl, GetCtlMax (hControl));
  617.  
  618.                         break;
  619.                     }
  620.                 }
  621.  
  622.                 iPostAction = iPostScrollKeys;
  623.  
  624.                 break;
  625.             }
  626.  
  627.             default:
  628.                 break;
  629.         }
  630.  
  631.         if (flashMenuID /* != 0 */)
  632.         {
  633.             FlashMenuBar (flashMenuID);
  634.             FlashMenuBar (flashMenuID);
  635.         }
  636.  
  637.         switch (iPostAction)
  638.         {
  639.             case iPostScrollKeys:
  640.             {
  641.                 if (hControl /* != (ControlHandle) NULL */)
  642.                 {
  643.                     pascal void    doScrollProc (ControlHandle    whichCtl, short iCtlPart);
  644.  
  645.  
  646.                     macClosePicture (dev);
  647.  
  648.                     doScrollProc (hControl, iCtlPart);
  649.                 }
  650.  
  651.                 break;
  652.             }
  653.  
  654.             default:
  655.                 break;
  656.         }
  657.     }
  658. }
  659.  
  660.  
  661. /*
  662.  *    DoMouseDown -- handles mouse down events
  663.  *
  664.  */
  665.  
  666.     static void
  667. DoMouseDown (EventRecord *pEvent)
  668.  
  669. {
  670.     gx_device  *dev        = (gx_device *) &gs_mac_device;
  671.     MacWinH        hMacWin = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  672.     WindowPtr    whichWin;
  673.     short        iWinPart;
  674.  
  675.  
  676.     ((CWindowPeek) xdev->windowPtr)->windowKind = userKind;
  677.     iWinPart = FindWindow (pEvent->where, &whichWin);
  678.     ((CWindowPeek) xdev->windowPtr)->windowKind = (*hMacWin)->graphicsRefNum;
  679.  
  680.     if (FrontWindow () != whichWin)
  681.     {
  682.         SelectWindow (whichWin);
  683.     }
  684.     else
  685.     {
  686.         GetPort (&(*hMacWin)->savePort);
  687.         SetPort (whichWin);
  688.  
  689.         switch (iWinPart)
  690.         {
  691.             case inZoomIn:
  692.             case inZoomOut:
  693.             {
  694.                 Rect   *pRect = &(((WindowPeek) whichWin)->port.portRect);
  695.  
  696.  
  697.                 InitCursor ();
  698.                 SetPort ((GrafPtr) whichWin);
  699.  
  700.                 if (TrackBox (whichWin, pEvent->where, iWinPart))
  701.                 {
  702.                     macClosePicture (dev);
  703.  
  704.                     if (iWinPart == inZoomOut)
  705.                     {
  706.                         macInvalWindow (dev, TRUE);
  707.                     }
  708.  
  709.                     ZoomWindow (whichWin, iWinPart, FALSE);
  710.  
  711.                     macRedrawWindow (dev);
  712.                 }
  713.                 
  714.                 break;
  715.             }
  716.  
  717.             case inGrow:
  718.             {
  719.                 long    newSize;
  720.  
  721.  
  722.                 InitCursor ();
  723.                 SetPort ((GrafPtr) whichWin);
  724.  
  725.                 if ((newSize = GrowWindow (whichWin, pEvent->where,
  726.                                            &(*hMacWin)->growRect))
  727.                         /* != 0L */)
  728.                 {
  729.                     macClosePicture (dev);
  730.  
  731.                     macInvalWindow (dev, FALSE);
  732.  
  733.                     SizeWindow (whichWin,
  734.                                 LoWord (newSize), HiWord (newSize), TRUE);
  735.  
  736.                     macRedrawWindow (dev);
  737.                 }
  738.                 
  739.                 break;
  740.             }
  741.  
  742.             case inDrag:
  743.             {
  744.                 Rect    limitRect;
  745.  
  746.  
  747.                 BlockMove ((Ptr) &screenBits.bounds, (Ptr) &limitRect,
  748.                            (Size) sizeof (Rect));
  749.                 InsetRect (&limitRect, 4, 4);
  750.                 DragWindow (whichWin, pEvent->where, &limitRect);
  751.  
  752.                 break;
  753.             }
  754.  
  755.             case inContent:
  756.             {
  757.                 ControlHandle    whichCtl;
  758.                 short            iCtlPart;
  759.  
  760.  
  761.                 GlobalToLocal (&pEvent->where);
  762.  
  763.                 if ((iCtlPart = FindControl (pEvent->where, whichWin, &whichCtl))
  764.                         /* > 0 */)
  765.                 {
  766.                     pascal void    doScrollProc (ControlHandle    whichCtl,
  767.                                               short iCtlPart);
  768.  
  769.  
  770.                     macClosePicture (dev);
  771.  
  772.                     iCtlPart = TrackControl (whichCtl, pEvent->where,
  773.                                              (iCtlPart != inThumb)
  774.                                                   ? doScrollProc
  775.                                                   : (ProcPtr) NULL);
  776.  
  777.                     if (iCtlPart == inThumb)
  778.                         doScrollProc (whichCtl, iCtlPart);
  779.                 }
  780.  
  781.                 break;
  782.             }
  783.         }
  784.  
  785.         SetPort ((*hMacWin)->savePort);
  786.     }
  787. }
  788.  
  789.  
  790.     static void
  791. DoConsolePuts (void)
  792.  
  793. {
  794.     if (openFileSavePort /* != (GrafPtr) NULL */)
  795.         SetPort (openFileSavePort);
  796. }
  797.  
  798.  
  799.     static void
  800. DoOpenFilePre (void)
  801.  
  802. {
  803.     macClosePicture ((gx_device *) &gs_mac_device);
  804.  
  805.     SetDoMacOpenFile (TRUE);
  806.  
  807.     openFileSavePort = (GrafPtr) FrontWindow ();
  808.     gDoCheckInterrupts    = TRUE;
  809.     swapConsoleControl (TRUE);
  810. }
  811.  
  812.  
  813.     static void
  814. DoOpenFilePost (void)
  815.  
  816. {
  817.     swapConsoleControl (FALSE);
  818.     gDoCheckInterrupts    = FALSE;
  819.     SetPort (openFileSavePort);
  820.  
  821.     SetDoMacOpenFile (FALSE);
  822.  
  823.     macClosePicture ((gx_device *) &gs_mac_device);
  824.  
  825.     openFileSavePort = (GrafPtr) NULL;
  826. }
  827.  
  828.  
  829.     static char
  830. DoOptionsProc (short actionValue)
  831.  
  832. {
  833.     char    retVal = TRUE;
  834.  
  835.  
  836.     switch (actionValue)
  837.     {
  838.         case iInitDialogAction:
  839.             retVal = FALSE;
  840.             break;
  841.  
  842.         case iDoDialogAction:
  843.             break;
  844.  
  845.         case iCommitAction:
  846.             (void) doRunIndString (iShowpageMac);
  847.             break;
  848.  
  849.         case iRetractAction:
  850.             break;
  851.  
  852.         default:
  853.             break;
  854.     }
  855.  
  856.     return retVal;
  857. }
  858.  
  859.  
  860.     static void
  861. DoTerminate (void)
  862.  
  863. {
  864.     (void) doRunIndString (iShowpageOrig);
  865. }
  866.  
  867.  
  868. /*
  869.  *    doScrollProc -- handles immediate feedback for scrollbars
  870.  *
  871.  */
  872.  
  873.     static pascal void
  874. doScrollProc (ControlHandle    whichCtl, short iCtlPart)
  875.  
  876. {
  877.     gx_device  *dev            = (gx_device *) GetCRefCon (whichCtl);
  878.     MacWinH        hMacWin        = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  879.     Boolean        fIsVertical = (whichCtl == (*hMacWin)->vScrollBar);
  880.     short       *pCtlVal        = fIsVertical
  881.                                   ? &((*hMacWin)->vValue)
  882.                                   : &((*hMacWin)->hValue);
  883.     short        ctlVal        = *pCtlVal;
  884.     short        ctlMin        = GetCtlMin (whichCtl);
  885.     short        ctlMax        = GetCtlMax (whichCtl);
  886.     short        offset        = 0;
  887.     short        dx            = 0;
  888.     short        dy            = 0;
  889.  
  890.  
  891.     if (iCtlPart == 0)
  892.         return;
  893.  
  894.     switch (iCtlPart)
  895.     {
  896.         case inUpButton:
  897.         {
  898.             offset = -(*hMacWin)->delScroll;
  899.  
  900.             break;
  901.         }
  902.  
  903.         case inDownButton:
  904.         {
  905.             offset =  (*hMacWin)->delScroll;
  906.  
  907.             break;
  908.         }
  909.  
  910.         case inThumb:
  911.         {
  912.             offset = (*pCtlVal = GetCtlValue (whichCtl)) - ctlVal;
  913.  
  914.             break;
  915.         }
  916.  
  917.         case inPageUp:
  918.         {
  919.             if (fIsVertical)
  920.                 offset = -(*hMacWin)->viewHeight;
  921.             else
  922.                 offset = -(*hMacWin)->viewWidth;
  923.  
  924.             break;
  925.         }
  926.  
  927.         case inPageDown:
  928.         {
  929.             if (fIsVertical)
  930.                 offset = (*hMacWin)->viewHeight;
  931.             else
  932.                 offset = (*hMacWin)->viewWidth;
  933.  
  934.             break;
  935.         }
  936.     }
  937.  
  938.     if        (ctlMin > ctlVal + offset)
  939.         offset = ctlMin - ctlVal;
  940.     else if (ctlMax < ctlVal + offset)
  941.         offset = ctlMax - ctlVal;
  942.  
  943.     if (fIsVertical)
  944.         dy = -offset;
  945.     else
  946.         dx = -offset;
  947.  
  948.     if (offset /* != 0 */)
  949.     {
  950.         RgnHandle    hUpdRgn = (*hMacWin)->updRgn;
  951.  
  952.  
  953.         if (iCtlPart != inThumb)
  954.         {
  955.             ctlVal = GetCtlValue (whichCtl) + offset;
  956.             SetCtlValue (whichCtl, *pCtlVal = ctlVal);
  957.         }
  958.  
  959.         GetPort (&(*hMacWin)->savePort);
  960.         SetPort ((GrafPtr) xdev->windowPtr);
  961.  
  962.         /*...Scroll the previous update region...*/
  963.  
  964.         if ((*hMacWin)->fIsDirty)
  965.         {
  966.             Rect    invalRect = (*hUpdRgn)->rgnBBox;
  967.  
  968.  
  969.             OffsetRect (&(*hMacWin)->updRect, dx, dy);
  970.             UnionRect  (&(*hMacWin)->updRect, &invalRect, &(*hMacWin)->updRect);
  971.             InvalRect  (&(*hMacWin)->updRect);
  972.         }
  973.  
  974.         /*...Scroll the image...*/
  975.  
  976.         ScrollRect (&((*hMacWin)->viewRect), dx, dy, hUpdRgn);
  977.  
  978.         InvalRgn (hUpdRgn);
  979.  
  980.         SetPort ((*hMacWin)->savePort);
  981.  
  982.         /*...Offset the origin...*/
  983.  
  984.         (*hMacWin)->origin.h -= dx;
  985.         (*hMacWin)->origin.v -= dy;
  986.  
  987.         if ((*hMacWin)->origin.h < 0)
  988.             (*hMacWin)->origin.h = 0;
  989.         if ((*hMacWin)->origin.v < 15)
  990.             (*hMacWin)->origin.v = 15;
  991.  
  992.         if (!(*hMacWin)->fIsDirty)
  993.         {
  994.             (*hMacWin)->fIsDirty = TRUE;
  995.             (*hMacWin)->updRect  = (*hUpdRgn)->rgnBBox;
  996.         }
  997.     }
  998. }
  999.  
  1000.  
  1001.     static void
  1002. doPrint (gx_device *dev)
  1003.  
  1004. {
  1005.     MacWinH        hMacWin    = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1006.  
  1007.  
  1008.     macClosePicture (dev);
  1009.     MacPrintOnePage ((*hMacWin)->hPicture, &(*hMacWin)->pictRect);
  1010. }
  1011.  
  1012.  
  1013. static Boolean        fDoConfirm = TRUE;
  1014. static char            fDoReturn;
  1015.  
  1016.  
  1017.     Boolean
  1018. doMacConfirm (void)
  1019.  
  1020. {
  1021.     Boolean    retVal = TRUE;
  1022.  
  1023.  
  1024.     if (fDoConfirm)
  1025.     {
  1026.         extern void        macForceCursorInit (void);
  1027.  
  1028.  
  1029.         SetPort (openFileSavePort);
  1030.         swapConsoleControl (FALSE);
  1031.  
  1032.         doMacConfirmCB (TRUE);
  1033.         macForceCursorInit ();
  1034.  
  1035.         fDoReturn = 0;
  1036.  
  1037.         do
  1038.         {
  1039.             EventRecord        event;
  1040.             WindowPtr        wp;
  1041.             long            choice;
  1042.             Boolean            status;
  1043.  
  1044.  
  1045.             SystemTask ();
  1046.  
  1047.             if (gWNEPresent)
  1048.                 status = WaitNextEvent (everyEvent, &event, 0xFFFFFFFF, (RgnHandle) NULL);
  1049.             else
  1050.                 status = GetNextEvent (everyEvent, &event);
  1051.  
  1052.             if (status)
  1053.             {
  1054.                 if (!SystemEvent (&event))
  1055.                     goto doEvent;
  1056.             }
  1057.             else if (event.what == nullEvent)
  1058.             {
  1059.                 if (FrontWindow () == 0)
  1060.                     InitCursor ();
  1061.             }
  1062.  
  1063.             continue;
  1064.  
  1065.         /*  handle event  */
  1066.  
  1067.         doEvent:
  1068.  
  1069.             if (event.what == mouseDown)
  1070.             {
  1071.                 switch (FindWindow (event.where, &wp))
  1072.                 {
  1073.                     case inMenuBar:
  1074.                     {
  1075.                         InitCursor ();
  1076.                         choice = MenuSelect (event.where);
  1077.                         goto doMenu;
  1078.                     }
  1079.  
  1080.                     case inSysWindow:
  1081.                     {
  1082.                         SystemClick (&event, wp);
  1083.                         break;
  1084.                     }
  1085.                 }
  1086.             }
  1087.  
  1088.             continue;
  1089.         
  1090.                 /*  handle menu choice  */
  1091.         
  1092.         doMenu:
  1093.  
  1094.             switch (HiWord (choice))
  1095.             {
  1096.                 case AppleMenuID:        /*  Apple  */
  1097.                 {
  1098.                     MenuHandle    appleMenu = GetMHandle (AppleMenuID);
  1099.                     Str255        buf;
  1100.  
  1101.  
  1102.                     GetItem (appleMenu, LoWord (choice), buf);
  1103.                     OpenDeskAcc (buf);
  1104.  
  1105.                     break;
  1106.                 }
  1107.  
  1108.                 case FileMenuID:        /*  File  */
  1109.                 {
  1110.                     extern short old_mac_pause_atexit;
  1111.                     extern void     gs_exit (int code);
  1112.  
  1113.  
  1114.                     console_options.pause_atexit = old_mac_pause_atexit;
  1115.  
  1116.                     gs_exit (0);
  1117.  
  1118.                     /* unreachable */
  1119.                 }
  1120.  
  1121.                 case EditMenuID:        /*  Edit  */
  1122.                 {
  1123.                     SystemEdit (LoWord (choice) - 1);
  1124.  
  1125.                     break;
  1126.                 }
  1127.             }
  1128.  
  1129.             HiliteMenu (0);
  1130.  
  1131.         } while (fDoReturn == 0);
  1132.  
  1133.         doMacConfirmCB (FALSE);
  1134.  
  1135.         if (GetDoMacOpenFile ())
  1136.             swapConsoleControl (TRUE);
  1137.  
  1138.         retVal = (fDoReturn == 1);
  1139.     }
  1140.  
  1141.     return retVal;
  1142. }
  1143.  
  1144.  
  1145.     static void
  1146. macConfirmSetup (short state)
  1147.  
  1148. {
  1149.     switch (state)
  1150.     {
  1151.         case 0:
  1152.             fDoConfirm = TRUE;
  1153.             break;
  1154.  
  1155.         case 1:
  1156.             fDoConfirm = FALSE;
  1157.             break;
  1158.  
  1159.         case 2:
  1160.             fDoReturn  = 1;
  1161.             break;
  1162.  
  1163.         case 3:
  1164.             fDoReturn  = -1;
  1165.             break;
  1166.     }
  1167.  
  1168.     macForceCursorInit ();
  1169.     InitCursor ();
  1170. }
  1171.  
  1172.  
  1173.     static void
  1174. doMacConfirmCB (Boolean fIsActive)
  1175.  
  1176. {
  1177.     CWindowPtr    windowPtr = gs_mac_device.windowPtr;
  1178.     MacWinH        hMacWin   = (MacWinH) GetWRefCon ((WindowPtr) windowPtr);
  1179.  
  1180.  
  1181.     HiliteMenu (0);
  1182.  
  1183.     if (fIsInConfirm = fIsActive)
  1184.     {
  1185.         EnableItem  (hGUIMenu, iResume      + numGUIMenuItems);
  1186.         EnableItem  (hGUIMenu, iStopProc  + numGUIMenuItems);
  1187.         DisableItem (hGUIMenu, iOpenFile);
  1188.         DisableItem (hGUIMenu, iLaserPrep);
  1189.     }
  1190.     else
  1191.     {
  1192.         DisableItem (hGUIMenu, iResume      + numGUIMenuItems);
  1193.         DisableItem (hGUIMenu, iStopProc  + numGUIMenuItems);
  1194.         EnableItem  (hGUIMenu, iOpenFile);
  1195.         EnableItem  (hGUIMenu, iLaserPrep);
  1196.     }
  1197.  
  1198.     if (!(*hMacWin)->fOpenPicture &&
  1199.         (*hMacWin)->hPicture /* != (PicHandle) NULL */ &&
  1200.         fIsInConfirm)
  1201.     {
  1202.         EnableItem  (hGUIMenu, iSavePicture      + numGUIMenuItems);
  1203.         EnableItem  (hGUIMenu, iSaveSelection + numGUIMenuItems);
  1204.         EnableItem  (hGUIMenu, iCopySelection + numGUIMenuItems);
  1205.     }
  1206.     else
  1207.     {
  1208.         DisableItem (hGUIMenu, iSavePicture      + numGUIMenuItems);
  1209.         DisableItem (hGUIMenu, iSaveSelection + numGUIMenuItems);
  1210.         DisableItem (hGUIMenu, iCopySelection + numGUIMenuItems);
  1211.     }
  1212.  
  1213.     SetCursor (*GetCursor (watchCursor));
  1214. }
  1215.  
  1216.  
  1217. #define RESET_SCROLLBAR_ORIGINS()                    \
  1218. {                                                    \
  1219.     /*...Define a drawing origin that avoids the    \
  1220.      *     horizontal scrollbar...*/                    \
  1221.                                                     \
  1222.     (*hMacWin)->origin.h =  0;                        \
  1223.     (*hMacWin)->origin.v = 15;                        \
  1224.                                                     \
  1225.     /*...Initialize scrollbar current values...*/    \
  1226.                                                     \
  1227.     (*hMacWin)->vValue = 0;                            \
  1228.     (*hMacWin)->hValue = 0;                            \
  1229.                                                     \
  1230.     if (hScrollBar /* != (ControlHandle) NULL */)    \
  1231.     {                                                \
  1232.         SetCtlValue (hScrollBar, 0);                \
  1233.         SetCtlValue (vScrollBar, 0);                \
  1234.     }                                                \
  1235. }
  1236.  
  1237.  
  1238.     static void
  1239. macCreatePicture (gx_device *dev)
  1240.  
  1241. {
  1242.     MacWinH            hMacWin       = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1243.     CWindowPtr        pictWin       = (*hMacWin)->pictWin;
  1244.     Rect           *pRect       = &(*hMacWin)->pictRect;
  1245.     ControlHandle    vScrollBar = (*hMacWin)->vScrollBar;
  1246.     ControlHandle    hScrollBar = (*hMacWin)->hScrollBar;
  1247.  
  1248.  
  1249.     /*...Create a new picture...*/
  1250.  
  1251.     GetPort (&(*hMacWin)->savePort);
  1252.         SetPort ((GrafPtr) pictWin);
  1253.         ClipRect (pRect);
  1254.         (*hMacWin)->hPicture     = OpenPicture (pRect);
  1255.         (*hMacWin)->fOpenPicture = TRUE;
  1256.     SetPort ((*hMacWin)->savePort);
  1257.  
  1258.     RESET_SCROLLBAR_ORIGINS ();
  1259. }
  1260.  
  1261.  
  1262.     void
  1263. macClearPicture (gx_device *dev)
  1264.  
  1265. {
  1266.     MacWinH    hMacWin = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1267.  
  1268.  
  1269.     if ((*hMacWin)->hPicture /* != (PicHandle) NULL */)
  1270.     {
  1271.         /*...Out with the old...*/
  1272.  
  1273.         KillPicture ((*hMacWin)->hPicture);
  1274.     
  1275.         /*...In with the new...*/
  1276.     
  1277.         macCreatePicture (dev);
  1278.     }
  1279. }
  1280.  
  1281.  
  1282.     static void
  1283. macCopyPicture (gx_device *dev)
  1284.  
  1285. {
  1286.     PicHandle    hPicture;
  1287.  
  1288.  
  1289.     ZeroScrap ();
  1290.  
  1291.     if ((hPicture = macGetPicture (dev)) /* != (PicHandle) NULL */)
  1292.     {
  1293.         HLock ((Handle) hPicture);
  1294.         PutScrap (GetHandleSize ((Handle) hPicture), (ResType) 'PICT', (Ptr) *hPicture);
  1295.         HUnlock ((Handle) hPicture);
  1296.     }
  1297. }
  1298.  
  1299.  
  1300.     void
  1301. macClosePicture (gx_device *dev)
  1302.  
  1303. {
  1304.     MacWinH        hMacWin = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1305.     CWindowPtr    pictWin = (*hMacWin)->pictWin;
  1306.  
  1307.  
  1308.     if ((*hMacWin)->fOpenPicture &&
  1309.         (*hMacWin)->hPicture /* != (PicHandle) NULL */)
  1310.     {
  1311.         GetPort (&(*hMacWin)->savePort);
  1312.             SetPort ((GrafPtr) pictWin);
  1313.             ClosePicture ();
  1314.             (*hMacWin)->fOpenPicture = FALSE;
  1315.         SetPort ((*hMacWin)->savePort);
  1316.     }
  1317.  
  1318.     if (openFileSavePort /* != (GrafPtr) NULL */)
  1319.         SetPort (openFileSavePort);
  1320. }
  1321.  
  1322.  
  1323.     PicHandle
  1324. macGetPicture (register gx_device *dev)
  1325.  
  1326. {
  1327.     MacWinH        hMacWin = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1328.  
  1329.  
  1330.     return (*hMacWin)->hPicture;
  1331. }
  1332.  
  1333.  
  1334.     Boolean
  1335. macSavePicture (register gx_device *dev, PicHandle hPicture)
  1336.  
  1337. {
  1338.     FILE       *fd      = (FILE *) NULL;
  1339.     char        string[256];
  1340.     short        i;
  1341.     char        aChar;
  1342.     MacWinH        hMacWin = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1343.     Boolean        retVal    = FALSE;
  1344.  
  1345.  
  1346.     /*...Create a new output file named "Picture<nn>"...*/
  1347.  
  1348.     for (i = 0; i < 999; i++)
  1349.     {
  1350.         (void) sprintf (string, "%s%d", gSFFName, i);
  1351.  
  1352.         if ((fd = fopen (string, "r")) /* != (FILE *) NULL */)
  1353.         {
  1354.             (void) fclose (fd);
  1355.             fd = (FILE *) NULL;
  1356.  
  1357.             continue;
  1358.         }
  1359.         else
  1360.         {
  1361.             SFReply        aReply;
  1362.             Point        where = {50, 50};
  1363.             Str255        pPrompt;
  1364.             Str255        pName;
  1365.             Rect       *pRect = &(((CWindowPeek) xdev->windowPtr)->port.portRect);
  1366.             StringPtr    PfromCStr (StringPtr pPstr, char *pCst);
  1367.  
  1368.  
  1369.             GetIndString (pPrompt, MACSTRS_RES_ID, iSFPutPromptStr);
  1370.  
  1371.             SFPutFile (where,
  1372.                        pPrompt, PfromCStr (pName, string),
  1373.                        (ProcPtr) NULL, &aReply);
  1374.  
  1375.             if (aReply.good)
  1376.             {
  1377.                 SetVol ((StringPtr) NULL, aReply.vRefNum);
  1378.  
  1379.                 (void) CfromPStr (string, (char *) &(aReply.fName));
  1380.  
  1381.                 fd = fopen (string, "wb");
  1382.             }
  1383.  
  1384.             /*...Refresh the screen...*/
  1385.  
  1386.             macBeginDraw (dev);
  1387.                 DrawPicture ((*hMacWin)->hPicture, &((*hMacWin)->pictRect));
  1388.             macEndDraw (dev);
  1389.  
  1390.             break;
  1391.         }
  1392.     }
  1393.  
  1394.     if (fd /* != (FILE *) NULL */)
  1395.     {
  1396.         long      **hLong     = (long **) NewHandle ((Size) 512);
  1397.         short        refnum     = fd->refnum;
  1398.         void        SetFileTypeCreator (char *fName,
  1399.                                         OSType fileType, OSType creator);
  1400.  
  1401.  
  1402.         if (hLong /* != (Handle) NULL */)
  1403.         {
  1404.             long   *pLong;
  1405.  
  1406.  
  1407.             /*...Write a 512 byte picture file header...*/
  1408.  
  1409.             for (i = 512 / sizeof (long), pLong = *hLong;
  1410.                  i /* > 0 */;
  1411.                  i--, pLong++)
  1412.             {
  1413.                 *pLong = 0L;
  1414.             }
  1415.  
  1416.             HLock ((Handle) hLong);
  1417.  
  1418.             (void) fwrite (*hLong, GetHandleSize ((Handle) hLong), 1, fd);
  1419.  
  1420.             DisposHandle ((Handle) hLong);
  1421.  
  1422.             /*...Write the picture...*/
  1423.  
  1424.             HLock ((Handle) hPicture);
  1425.  
  1426.             (void) fwrite ((char *) *hPicture,
  1427.                            GetHandleSize ((Handle) hPicture), 1, fd);
  1428.  
  1429.             HUnlock ((Handle) hPicture);
  1430.         }
  1431.  
  1432.         fclose (fd);
  1433.  
  1434.         SetFileTypeCreator (string, (OSType) 'PICT', (*hMacWin)->fCreator);
  1435.  
  1436.         retVal = TRUE;
  1437.     }
  1438.  
  1439.     return retVal;
  1440. }
  1441.  
  1442.  
  1443.     short
  1444. macCreateWindow (gx_device *dev, short pictWidth, short pictHeight)
  1445.  
  1446. {
  1447.     short        retVal        = 0;
  1448.  
  1449.  
  1450.     if (xdev->windowPtr == (CWindowPtr) NULL)
  1451.     {
  1452.         Rect            windowRect;
  1453.         WindowPtr        SavePort;
  1454.         Rect            *pRect;
  1455.         Str255            string;
  1456.         short            width        = pictWidth;
  1457.         short            height        = pictHeight;
  1458.         MacPrefsH        hPrefs        = (MacPrefsH) GetResource (MACPREFS_RES_TYPE,
  1459.                                                                MACPREFS_RES_ID);
  1460.         ResType            fCreator    = MACPREFS_DEFAULT_FCREATOR;
  1461.         short            delScroll    = MACPREFS_DEFAULT_DELSCROLL;
  1462.         short            gWidth;
  1463.         short            gHeight;
  1464.         short            screenDepth;
  1465.         short            gp_VMError (char *msg, short index);
  1466.  
  1467.  
  1468.         if (gHasColorQD)
  1469.         {
  1470.             GDHandle        hGD       = GetMainDevice ();
  1471.             PixMapHandle    gdPMap = (*hGD)->gdPMap;
  1472.  
  1473.  
  1474.             gWidth     = (*hGD)->gdRect.right  - (*hGD)->gdRect.left;
  1475.             gHeight    = (*hGD)->gdRect.bottom - (*hGD)->gdRect.top;
  1476.  
  1477.             screenDepth = (*gdPMap)->pixelSize;
  1478.         }
  1479.         else
  1480.         {
  1481.             Rect   *pScreenRect = &(*GrayRgn)->rgnBBox;
  1482.  
  1483.  
  1484.             gWidth     = pScreenRect->right  - pScreenRect->left;
  1485.             gHeight    = pScreenRect->bottom - pScreenRect->top + 20;
  1486.  
  1487.             screenDepth = 1;
  1488.         }
  1489.  
  1490.         if (screenDepth == 1)
  1491.         {
  1492.             gx_device_color_info   *pColorInfo = &dev->color_info;
  1493.  
  1494.  
  1495.             pColorInfo->num_components = 1;
  1496.             pColorInfo->depth           = 1;
  1497.             pColorInfo->max_gray       = 1;
  1498.             pColorInfo->max_rgb           = 0;
  1499.             pColorInfo->dither_gray       = 2;
  1500.             pColorInfo->dither_rgb       = 0;
  1501.         }
  1502.  
  1503.         /*...Get favorite values from the preferences resource...*/
  1504.  
  1505.         if (hPrefs /* != (MacPrefsH) NULL */)
  1506.         {
  1507.             char    fFlags = (*hPrefs)->flags;
  1508.  
  1509.  
  1510.             if (fFlags & iUseWinRes)
  1511.             {
  1512.                 width  = (*hPrefs)->winWidth;
  1513.                 height = (*hPrefs)->winHeight;
  1514.             }
  1515.             else
  1516.             {
  1517.                 width  = gWidth;
  1518.                 height = gHeight;
  1519.             }
  1520.  
  1521.             if (fFlags & iUsePageRes)
  1522.             {
  1523.                 pictWidth  = (*hPrefs)->pageWidth;
  1524.                 pictHeight = (*hPrefs)->pageHeight;
  1525.             }
  1526.  
  1527.             fCreator  = (*hPrefs)->fCreator;
  1528.             delScroll = (*hPrefs)->delScroll;
  1529.  
  1530.             ReleaseResource ((Handle) hPrefs);
  1531.         }
  1532.  
  1533.         xdev->width        = pictWidth;
  1534.         xdev->height    = pictHeight;
  1535.  
  1536.         /*...Create a color graphics window...*/
  1537.  
  1538.         GetIndString (string, MACSTRS_RES_ID, iGraphicsWinTitleStr);
  1539.  
  1540.         SetRect (&windowRect, 3, 40, width, height);
  1541.  
  1542.         GetPort (&SavePort);
  1543.  
  1544.         if (gHasColorQD)
  1545.             xdev->windowPtr = (CWindowPtr) NewCWindow (
  1546.                                                (Ptr) NULL, &windowRect,
  1547.                                                string,
  1548.                                                TRUE, zoomDocProc, (WindowPtr) NULL,
  1549.                                                FALSE, 0L);
  1550.         else
  1551.             xdev->windowPtr = (CWindowPtr) NewWindow (
  1552.                                                (Ptr) NULL, &windowRect,
  1553.                                                string,
  1554.                                                TRUE, zoomDocProc, (WindowPtr) NULL,
  1555.                                                FALSE, 0L);
  1556.  
  1557.         if (xdev->windowPtr /* != (CWindowPtr) NULL */)
  1558.         {
  1559.             MacWinH        hMacWin   = (MacWinH) NewHandle ((Size) sizeof (MacWinRec));
  1560.             Rect       *pRect      = &(*hMacWin)->pictRect;
  1561.             Boolean        fGrowPict = FALSE;
  1562.  
  1563.  
  1564.             if (hMacWin == (MacWinH) NULL)
  1565.             {
  1566.                 DisposeWindow ((WindowPtr) xdev->windowPtr);
  1567.                 xdev->windowPtr = (CWindowPtr) NULL;
  1568.                 SetPort (SavePort);
  1569.  
  1570.                 gp_VMError ("graphics window", iWindowCreationFailed);
  1571.             }
  1572.  
  1573.             /*...Stow away the keys to the kingdom...*/
  1574.  
  1575.             SetWRefCon ((WindowPtr) xdev->windowPtr, (long) hMacWin);
  1576.  
  1577.             SetPort ((GrafPtr) xdev->windowPtr);
  1578.  
  1579.             BackPat      (white);            /*    Hmm.  Is A5 still good?    */
  1580.             BackColor (whiteColor);
  1581.  
  1582.             /*...Create a clipping region that excludes the scrollbars...*/
  1583.  
  1584.             (*hMacWin)->clipRgn        = NewRgn ();
  1585.             if ((*hMacWin)->clipRgn == (RgnHandle) NULL)
  1586.                 gp_VMError ("clip region", iClipRegionCreationFailed);
  1587.  
  1588.             /*...Hold on to the original clipping region...*/
  1589.  
  1590.             (*hMacWin)->saveClipRgn = NewRgn ();
  1591.             if ((*hMacWin)->saveClipRgn == (RgnHandle) NULL)
  1592.                 gp_VMError ("save clip region", iSaveRegionCreationFailed);
  1593.  
  1594.             GetClip ((*hMacWin)->saveClipRgn);
  1595.  
  1596.             /*...Create a region to hold the areas vacated by scrolling...*/
  1597.  
  1598.             (*hMacWin)->updRgn = NewRgn ();
  1599.             if ((*hMacWin)->updRgn == (RgnHandle) NULL)
  1600.                 gp_VMError ("update region", iUpdRegionCreationFailed);
  1601.  
  1602.             /*...Initialize a few state variables and preferences...*/
  1603.  
  1604.             (*hMacWin)->fIsDirty = FALSE;
  1605.  
  1606.             (*hMacWin)->fCreator   = fCreator;
  1607.             (*hMacWin)->delScroll  = delScroll;
  1608.             (*hMacWin)->hScrollBar = (ControlHandle) NULL;
  1609.             (*hMacWin)->vScrollBar = (ControlHandle) NULL;
  1610.  
  1611.             SetRect (pRect, 0, 0, pictWidth, pictHeight);
  1612.  
  1613.             /*...Create the scrollbars...*/
  1614.  
  1615.             (*hMacWin)->hScrollBar = NewControl ((WindowPtr) xdev->windowPtr,
  1616.                                                  pRect, "\p",
  1617.                                                  FALSE, 0, 0, 0,
  1618.                                                  scrollBarProc, (long) dev);
  1619.             (*hMacWin)->hValue = 0;
  1620.             (*hMacWin)->vScrollBar = NewControl ((WindowPtr) xdev->windowPtr,
  1621.                                                  pRect, "\p",
  1622.                                                  FALSE, 0, 0, 0,
  1623.                                                  scrollBarProc, (long) dev);
  1624.             (*hMacWin)->vValue = 0;
  1625.  
  1626.             /*...Position the scrollbars and calculate the view port's size...*/
  1627.  
  1628.             macResizeWindow (dev);
  1629.  
  1630.             /*...Show, but do not activate, the scrollbars...*/
  1631.  
  1632.             ShowControl   ((*hMacWin)->hScrollBar);
  1633.             HiliteControl ((*hMacWin)->hScrollBar, 255);
  1634.             ShowControl   ((*hMacWin)->vScrollBar);
  1635.             HiliteControl ((*hMacWin)->vScrollBar, 255);
  1636.  
  1637.             /*...Establish the GrowWindow () limits...*/
  1638.  
  1639.             height -= 40;
  1640.             width  -=  3;
  1641.             (*hMacWin)->growRect.top    = height >> 1;
  1642.             (*hMacWin)->growRect.bottom = height;
  1643.             (*hMacWin)->growRect.left    = width  >> 1;
  1644.             (*hMacWin)->growRect.right  = width;
  1645.  
  1646.             /*...Make the drawing at least as large as the initial output
  1647.              *     window's view port...*/
  1648.  
  1649.             if ((*hMacWin)->viewWidth - 1 > pictWidth)
  1650.             {
  1651.                 pictWidth  = (*hMacWin)->viewWidth - 1;
  1652.                 fGrowPict  = TRUE;
  1653.             }
  1654.             if ((*hMacWin)->viewHeight - 1 > pictHeight)
  1655.             {
  1656.                 pictHeight = (*hMacWin)->viewHeight - 1;
  1657.                 fGrowPict  = TRUE;
  1658.             }
  1659.  
  1660.             /*...If necessary, reset the scrollbar's values...*/
  1661.  
  1662.             if (fGrowPict)
  1663.             {
  1664.                 SetRect (pRect, 0, 0, pictWidth, pictHeight);
  1665.                 macResizeWindow (dev);
  1666.  
  1667.                 xdev->width     = pictWidth;
  1668.                 xdev->height = pictHeight;
  1669.             }
  1670.  
  1671.             /*...Create an "offscreen" window used to capture the rendered picture...*/
  1672.  
  1673.             SetRect (&windowRect, 0, gHeight, pictWidth, gHeight + pictHeight);
  1674.  
  1675.             if (gHasColorQD)
  1676.                 (*hMacWin)->pictWin = (CWindowPtr) NewCWindow (
  1677.                                                        (Ptr) NULL, &windowRect,
  1678.                                                        "\p",
  1679.                                                        FALSE, plainDBox, (WindowPtr) NULL,
  1680.                                                        FALSE, 0L);
  1681.             else
  1682.                 (*hMacWin)->pictWin = (CWindowPtr) NewWindow (
  1683.                                                        (Ptr) NULL, &windowRect,
  1684.                                                        "\p",
  1685.                                                        FALSE, plainDBox, (WindowPtr) NULL,
  1686.                                                        FALSE, 0L);
  1687.             if ((*hMacWin)->pictWin == (CWindowPtr) NULL)
  1688.                 gp_VMError ("picture window", iPictWinCreationFailed);
  1689.  
  1690.             SetPort ((GrafPtr) (*hMacWin)->pictWin);
  1691.  
  1692.             BackPat      (white);            /*    Hmm.  Is A5 still good?    */
  1693.             BackColor (whiteColor);
  1694.  
  1695.             /*...Finally, create a picture for backing store...*/
  1696.  
  1697.             macCreatePicture (dev);
  1698.  
  1699.             /*...Install the window driver...*/
  1700.  
  1701.             (*hMacWin)->graphicsRefNum = macOpenGUIDriver (gs_mac_device.dname);
  1702.             ((CWindowPeek) xdev->windowPtr)->windowKind = (*hMacWin)->graphicsRefNum;
  1703.         }
  1704.         else
  1705.         {
  1706.             retVal = gs_error_VMerror;
  1707.         }
  1708.  
  1709.         SetPort (SavePort);
  1710.     }
  1711.  
  1712.     if (retVal /* != 0 */)
  1713.         return_error (retVal);
  1714.     else
  1715.         return retVal;
  1716. }
  1717.  
  1718.  
  1719.     static void
  1720. macClearWindow (gx_device *dev)
  1721.  
  1722. {
  1723.     (void) (*dev->procs->fill_rectangle) (dev,
  1724.                                           0, 0, xdev->width, xdev->height,
  1725.                                           mac_white_color_index);
  1726. //    gDoCheckInterrupts = FALSE;
  1727.     macForceCursorInit ();
  1728.     InitCursor ();
  1729. }
  1730.  
  1731.  
  1732.     short
  1733. macCloseWindow (gx_device *dev)
  1734.  
  1735. {
  1736.     short    retVal = gs_error_rangecheck;
  1737.  
  1738.  
  1739.     EnableItem  (hGUIMenu, iOpenFile);
  1740.     EnableItem  (hGUIMenu, iLaserPrep);
  1741.  
  1742.     if (xdev->windowPtr /* != (CWindowPtr) NULL */)
  1743.     {
  1744.         MacWinH    hMacWin = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1745.  
  1746.  
  1747.         if ((*hMacWin)->hPicture /* != (PicHandle) NULL */)
  1748.             KillPicture ((*hMacWin)->hPicture);
  1749.  
  1750.         if ((*hMacWin)->clipRgn /* != (RgnHandle) NULL */)
  1751.             DisposeRgn ((*hMacWin)->clipRgn);
  1752.  
  1753.         if ((*hMacWin)->updRgn /* != (RgnHandle) NULL */)
  1754.             DisposeRgn ((*hMacWin)->updRgn);
  1755.  
  1756.         if ((*hMacWin)->pictWin /* != (CWindowPtr) NULL */)
  1757.             DisposeWindow ((WindowPtr) (*hMacWin)->pictWin);
  1758.  
  1759.         DisposHandle ((Handle) hMacWin);
  1760.  
  1761.         DisposeWindow ((WindowPtr) xdev->windowPtr);
  1762.         xdev->windowPtr = (CWindowPtr) NULL;
  1763.  
  1764.         retVal = 0;
  1765.     }
  1766.  
  1767.     if (retVal /* != 0 */)
  1768.         return_error (retVal);
  1769.     else
  1770.         return retVal;
  1771. }
  1772.  
  1773.  
  1774. /*
  1775.  *    Invalidates the scrollbar and drag icon areas.
  1776.  */
  1777.  
  1778.     static void
  1779. macInvalWindow (gx_device *dev, Boolean fResetOrigin)
  1780.  
  1781. {
  1782.     CWindowPtr        pCWin       = xdev->windowPtr;
  1783.     Rect            invalRect  = pCWin->portRect;
  1784.     MacWinH            hMacWin       = (MacWinH) GetWRefCon ((WindowPtr) pCWin);
  1785.     ControlHandle    vScrollBar = (*hMacWin)->vScrollBar;
  1786.     ControlHandle    hScrollBar = (*hMacWin)->hScrollBar;
  1787.  
  1788.  
  1789.     GetPort (&(*hMacWin)->savePort);
  1790.     SetPort ((GrafPtr) pCWin);
  1791.         HideControl (hScrollBar);
  1792.         HideControl (vScrollBar);
  1793.  
  1794.         if (!fResetOrigin)
  1795.         {
  1796.             invalRect.left = invalRect.right  - 15;
  1797.             invalRect.top  = invalRect.bottom - 15;
  1798.             EraseRect (&invalRect);
  1799.         }
  1800.         InvalRect (&invalRect);
  1801.         EraseRect (&invalRect);
  1802.     SetPort ((*hMacWin)->savePort);
  1803.  
  1804.     if (fResetOrigin)
  1805.     {
  1806.         RESET_SCROLLBAR_ORIGINS ();
  1807.     }
  1808. }
  1809.  
  1810.  
  1811. /*
  1812.  *    Redraws the grow icon and scrollbars.
  1813.  */
  1814.  
  1815.     static void
  1816. macRedrawWindow (gx_device *dev)
  1817.  
  1818. {
  1819.     MacWinH            hMacWin       = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1820.     ControlHandle    vScrollBar = (*hMacWin)->vScrollBar;
  1821.     ControlHandle    hScrollBar = (*hMacWin)->hScrollBar;
  1822.  
  1823.  
  1824.     macResizeWindow (dev);
  1825.  
  1826.     GetPort (&(*hMacWin)->savePort);
  1827.     SetPort ((GrafPtr) xdev->windowPtr);
  1828.         DrawGrowIcon ((WindowPtr) xdev->windowPtr);
  1829.         ShowControl (vScrollBar);
  1830.         ShowControl (hScrollBar);
  1831.     SetPort ((*hMacWin)->savePort);
  1832. }
  1833.  
  1834.  
  1835.     static void
  1836. macResizeWindow (gx_device *dev)
  1837.  
  1838. {
  1839.     CWindowPtr        pCWin       = xdev->windowPtr;
  1840.     Rect            portRect   = pCWin->portRect;
  1841.     MacWinH            hMacWin       = (MacWinH) GetWRefCon ((WindowPtr) pCWin);
  1842.     ControlHandle    vScrollBar = (*hMacWin)->vScrollBar;
  1843.     ControlHandle    hScrollBar = (*hMacWin)->hScrollBar;
  1844.     short            wide;
  1845.     short            high;
  1846.     short            newCtlMax;
  1847.  
  1848.  
  1849.     /*...Reposition and resize the scrollbars...*/
  1850.  
  1851.     MoveControl (vScrollBar, portRect.right - 15, portRect.top - 1);
  1852.     wide = 16;
  1853.     high = (portRect.bottom - portRect.top) - 14;
  1854.     SizeControl (vScrollBar, wide, high);
  1855.  
  1856.     MoveControl (hScrollBar, portRect.left - 1, portRect.bottom - 15);
  1857.     wide = (portRect.right - portRect.left) - 14;
  1858.     high = 16;
  1859.     SizeControl (hScrollBar, wide, high);
  1860.  
  1861.     /*...Recalculate the view port's rectangle...*/
  1862.  
  1863.     portRect.right  -= 15;            /*    adjustment for scrollbars    */
  1864.     portRect.bottom -= 15;
  1865.     (*hMacWin)->viewRect = portRect;
  1866.  
  1867.     (*hMacWin)->viewWidth  = portRect.right     - portRect.left + 1;
  1868.     (*hMacWin)->viewHeight = portRect.bottom - portRect.top     + 1;
  1869.  
  1870.     /*...Reset the scrollbars' maxima...*/
  1871.  
  1872.     newCtlMax = (*hMacWin)->pictRect.right - (*hMacWin)->viewWidth;
  1873.     SetCtlMax ((*hMacWin)->hScrollBar, (newCtlMax > 0) ? newCtlMax : 0);
  1874.  
  1875.     newCtlMax = (*hMacWin)->pictRect.bottom - (*hMacWin)->viewHeight;
  1876.     SetCtlMax ((*hMacWin)->vScrollBar, (newCtlMax > 0) ? newCtlMax : 0);
  1877. }
  1878.  
  1879.  
  1880.     void
  1881. macBeginDraw (gx_device *dev)
  1882.  
  1883. {
  1884.     MacWinH    hMacWin  = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1885.     Rect    clipRect = (*hMacWin)->viewRect;
  1886.     Point    origin     = (*hMacWin)->origin;
  1887.  
  1888.  
  1889.     GetPort (&(*hMacWin)->savePort);
  1890.     SetPort ((GrafPtr) xdev->windowPtr);
  1891.         OffsetRect (&clipRect, origin.h, origin.v);
  1892.         RectRgn ((*hMacWin)->clipRgn, &clipRect);
  1893.         SetClip ((*hMacWin)->clipRgn);
  1894.  
  1895.         SetOrigin (origin.h, origin.v);
  1896. }
  1897.  
  1898.  
  1899.     void
  1900. macEndDraw (gx_device *dev)
  1901.  
  1902. {
  1903.     MacWinH    hMacWin  = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1904.  
  1905.  
  1906.         SetOrigin (0, 0);
  1907.  
  1908.         SetClip ((*hMacWin)->saveClipRgn);
  1909.     SetPort ((*hMacWin)->savePort);
  1910.  
  1911.     if (openFileSavePort /* != (GrafPtr) NULL */)
  1912.         SetPort (openFileSavePort);
  1913. }
  1914.  
  1915.  
  1916.     void
  1917. macBeginPictDraw (gx_device *dev)
  1918.  
  1919. {
  1920.     MacWinH        hMacWin = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1921.     CWindowPtr    pictWin = (*hMacWin)->pictWin;
  1922.     PicHandle    hPicture;
  1923.  
  1924.  
  1925.     if (pictWin /* != (CWindowPtr) NULL */ &&
  1926.         (hPicture = (*hMacWin)->hPicture) /* != (PicHandle) NULL */)
  1927.     {
  1928.         (*hMacWin)->pictLen = GetHandleSize ((Handle) hPicture);
  1929.  
  1930.         GetPort (&(*hMacWin)->savePort);
  1931.         SetPort ((GrafPtr) pictWin);
  1932.     }
  1933. }
  1934.  
  1935.  
  1936. #define    MINIMUM_PICT_LEN    10L
  1937.  
  1938.  
  1939.     short
  1940. macEndPictDraw (gx_device *dev)
  1941.  
  1942. {
  1943.     MacWinH        hMacWin  = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1944.     PicHandle    hPicture = (*hMacWin)->hPicture;
  1945.     short        retVal    = 0;
  1946.  
  1947.  
  1948.         SetPort ((*hMacWin)->savePort);
  1949.  
  1950.         if (openFileSavePort /* != (GrafPtr) NULL */)
  1951.             SetPort (openFileSavePort);
  1952.  
  1953.     /*...See if we ran out of memory rendering the picture...*/
  1954.  
  1955.     if (hPicture /* != (PicHandle) NULL */)
  1956.     {
  1957.         Size    pictLen = GetHandleSize ((Handle) hPicture);
  1958.  
  1959.  
  1960.         if ((*hMacWin)->pictLen >= pictLen && pictLen == MINIMUM_PICT_LEN)
  1961.         {
  1962. #if 0
  1963.             macInitCursor ();
  1964.             Alert (MACVMERROR, (ProcPtr) NULL);
  1965. #endif
  1966.             retVal = gs_error_VMerror;
  1967.         }
  1968.     }
  1969.  
  1970.     return retVal;
  1971. }
  1972.  
  1973.  
  1974.     CWindowPtr
  1975. macPictWindow (gx_device *dev)
  1976.  
  1977. {
  1978.     MacWinH        hMacWin = (MacWinH) GetWRefCon ((WindowPtr) xdev->windowPtr);
  1979.  
  1980.  
  1981.     return (*hMacWin)->pictWin;
  1982. }
  1983.  
  1984.  
  1985.     static StringPtr
  1986. PfromCStr (StringPtr pPstr, char *pCstr)
  1987.  
  1988. {
  1989.     short        lenstr = strlen (pCstr);
  1990.  
  1991.  
  1992.     pPstr[0] = lenstr;
  1993.  
  1994.     if (lenstr /* > 0 */)
  1995.         BlockMove ((char *) pCstr, &(pPstr[1]), lenstr);
  1996.  
  1997.     return pPstr;
  1998. }
  1999.  
  2000.  
  2001.     static void
  2002. SetFileTypeCreator (char *fName, OSType fdType, OSType fdCreator)
  2003.  
  2004. {
  2005.     OSErr        status = noErr;
  2006.     Str255        pName;
  2007.     FInfo       fndrInfo;
  2008.     FileParam    pBlock;
  2009.     short        oldVRefNum;
  2010.     StringPtr    PfromCStr (StringPtr pPstr, char *pCstr);
  2011.  
  2012.  
  2013.     if (GetVol (pName, &oldVRefNum) /* != noErr */)
  2014.         return;
  2015.  
  2016.     /*...Obtain the name for the open output file using its refnum...*/
  2017.  
  2018.     pBlock.ioNamePtr   = PfromCStr (pName, fName);
  2019.     pBlock.ioFVersNum  = 0;
  2020.     pBlock.ioVRefNum   = oldVRefNum;
  2021.     pBlock.ioFDirIndex = 0;
  2022.  
  2023.     if (PBGetFInfo ((ParmBlkPtr) &pBlock, FALSE) /* != noErr */)
  2024.         return;
  2025.  
  2026.     /*...Set file's type and creator...*/
  2027.  
  2028.     if (GetFInfo (pName, oldVRefNum, &fndrInfo) == noErr)
  2029.     {
  2030.         fndrInfo.fdType    = fdType;
  2031.         fndrInfo.fdCreator = fdCreator;
  2032.  
  2033.         (void) SetFInfo (pName, oldVRefNum, &fndrInfo);
  2034.     }
  2035. }
  2036.  
  2037.  
  2038. static int    (*pConsolePBControl) (void);
  2039. static int    gsConsolePBControl (void);
  2040.  
  2041.  
  2042.     static void
  2043. swapConsoleControl (Boolean fSaveConsoleControl)
  2044.  
  2045. {
  2046.     short                consoleRefNum = ~((WindowPeek) gConsoleWinPtr)->windowKind;
  2047.     DCtlHandle            dceH           = UTableBase[consoleRefNum];
  2048.     DrvrH                hConsoleDrvr  = (DrvrH) (*dceH)->dCtlDriver;
  2049.  
  2050.  
  2051.     if (fSaveConsoleControl)
  2052.     {
  2053.         pConsolePBControl            = (*hConsoleDrvr)->vCtl.vCode;
  2054.         (*hConsoleDrvr)->vCtl.vCode = gsConsolePBControl;
  2055.     }
  2056.     else
  2057.     {
  2058.         if (pConsolePBControl /* != (int (*) (void)) NULL */)
  2059.         {
  2060.             (*hConsoleDrvr)->vCtl.vCode = pConsolePBControl;
  2061.             pConsolePBControl            = (int (*) (void)) NULL;
  2062.         }
  2063.     }
  2064. }
  2065.  
  2066.  
  2067.     static int
  2068. gsConsolePBControl (void)
  2069.  
  2070. {
  2071.     register CntrlParam       *pb;
  2072.     DCtlPtr                    dce;
  2073.     long                    oldA5  = SetCurrentA5 ();
  2074.     int                        retVal = 0;
  2075.  
  2076.  
  2077.     asm
  2078.     {
  2079.         move.l    a0,pb
  2080.         move.l    a1,dce
  2081.     }
  2082.  
  2083.     switch (pb->csCode)
  2084.     {
  2085.         case accCursor:
  2086.         /*    do nothing    */
  2087.             break;
  2088.  
  2089.         default:
  2090.         {
  2091.             asm
  2092.             {
  2093.                 move.l    pb,a0
  2094.                 move.l    dce,a1
  2095.                 move.l    gsConsolePBControl,a2    ;    retVal = (*gsConsolePBControl) ();
  2096.                 jsr        (a2)
  2097.                 move.w    d0,retVal
  2098.             }
  2099.  
  2100.             break;
  2101.         }
  2102.     }
  2103.  
  2104.     HUnlock (RecoverHandleSys ((Ptr) dce));
  2105.     SetA5 (oldA5);
  2106.  
  2107.     return retVal;
  2108. }
  2109.  
  2110.