home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM A / PD-ROM A.iso / Utility / Virus Checkers / Disinfectant 2.5.1 / Source Code for 2.4 / Source Code / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-17  |  8.3 KB  |  324 lines  |  [TEXT/MPS ]

  1. /*______________________________________________________________________
  2.  
  3.     help.c - Help Window Manager.
  4.     
  5.     Copyright © 1988, 1989, 1990 Northwestern University.  Permission is granted
  6.     to use this code in your own projects, provided you give credit to both
  7.     John Norstad and Northwestern University in your about box or document.
  8. _____________________________________________________________________*/
  9.  
  10.  
  11. #pragma load "precompile"
  12. #include "hlp.h"
  13. #include "utl.h"
  14. #include "rez.h"
  15. #include "glob.h"
  16. #include "wstm.h"
  17. #include "misc.h"
  18. #include "help.h"
  19. #include "main.h"
  20. #include "misc.h"
  21. #include "unmount.h"
  22. #include "vol.h"
  23.  
  24. #pragma segment help
  25.  
  26. /*______________________________________________________________________
  27.  
  28.     Global Variables.
  29. _____________________________________________________________________*/
  30.  
  31.  
  32. static WindowPtr            HelpWindow = nil;        /* ptr to help window */
  33. static WindowRecord        HelpWRecord;            /* help window record */
  34. static WindowObject        HelpWindObject;        /* help window object */
  35.  
  36. /*______________________________________________________________________
  37.  
  38.     Click - Process Mouse Down Event.
  39.     
  40.     Entry:        where = mouse down location, local coords.
  41.                     modifiers = modifier keys.
  42. _____________________________________________________________________*/
  43.  
  44. static void Click (Point where, short modifiers)
  45.  
  46. {
  47. #pragma unused (modifiers)
  48.  
  49.     hlp_Click(where);
  50. }
  51.  
  52. /*______________________________________________________________________
  53.  
  54.     Help - Process Mouse Down Event in Help Mode.
  55.     
  56.     Entry:        where = mouse down location, local coords.
  57. _____________________________________________________________________*/
  58.  
  59.  
  60. static void Help (Point where)
  61.  
  62. {
  63.     Rect        tcRect;            /* tcon rectangle */
  64.  
  65.     hlp_GetTconRect(&tcRect);
  66.     tcRect.top -= 15;
  67.     help_Open(PtInRect(where, &tcRect) ? tagHelpTcon : tagHelpWind);
  68. }
  69.     
  70. /*______________________________________________________________________
  71.  
  72.     Close - Close Window.
  73. _____________________________________________________________________*/
  74.  
  75.  
  76. static void Close (void)
  77.  
  78. {
  79.     Prefs.helpState.moved = HelpWindObject.moved;
  80.     wstm_Save(HelpWindow, &Prefs.helpState);
  81.     Prefs.helpScrollPos = hlp_GetScrollPos();
  82.     hlp_Close();
  83.     CloseWindow(HelpWindow);
  84.     HelpWindow = nil;
  85. }
  86.     
  87. /*______________________________________________________________________
  88.  
  89.     Save - Process Save Command.
  90.     
  91.     Exit:        function result = true (nobody cares if the user canceled!)
  92. _____________________________________________________________________*/
  93.  
  94.  
  95. static Boolean Save (void)
  96.  
  97. {
  98.     Str255            prompt;            /* SFPutFile prompt string */
  99.     Str255            defName;            /* default name for help save dlog */
  100.     OSErr                rCode;            /* result code */
  101.     Str255            rCodeStr;        /* result code as a string */
  102.     long                savedTrapAddr;    /* saved UnmountVol trap adress */
  103.     
  104.     /* Get the prompt string and default file name. */
  105.     
  106.     GetIndString(prompt, strListID, abPromptStr);
  107.     GetIndString(defName, strListID, abDefNameStr);
  108.     
  109.     /* If scanning, patch the UnmountVol trap to prevent volume unmounting. */
  110.     
  111.     if (Scanning) {
  112.         savedTrapAddr = NGetTrapAddress(_UnmountVol & 0x3ff, ToolTrap);
  113.         NSetTrapAddress((long)UNMOUNT, _UnmountVol & 0x3ff, ToolTrap);
  114.     };
  115.     
  116.     /* Call hlp_Save to save the file. */
  117.     
  118.     rCode = hlp_Save(prompt, defName, Prefs.docCreator, MenuPick);
  119.     
  120.     /* Handle errors. */
  121.     
  122.     if (rCode) {
  123.         if (rCode == dskFulErr) {
  124.             utl_StopAlert(diskFullID, nil, 0);
  125.         } else if (rCode == fLckdErr) {
  126.             utl_StopAlert(fileLockedID, nil, 0);
  127.         } else {
  128.             NumToString(rCode, rCodeStr);
  129.             ParamText(rCodeStr, nil, nil, nil);
  130.             utl_StopAlert(unexpectedSaveID, nil, 0);
  131.         };
  132.     };
  133.     
  134.     /* If scanning, restore the UnmountVol trap. */
  135.     
  136.     if (Scanning) {
  137.         NSetTrapAddress(savedTrapAddr, _UnmountVol & 0x3ff, ToolTrap);
  138.     } else {
  139.         main_SetPort();
  140.         vol_Verify();
  141.         misc_HiliteScan();
  142.     };
  143.     
  144.     return true;
  145. }
  146.     
  147. /*______________________________________________________________________
  148.  
  149.     PageSetup - Process Page Setup Command.
  150.     
  151.     Exit:        function result = error code.
  152. _____________________________________________________________________*/
  153.  
  154.  
  155. static OSErr PageSetup (void)
  156.  
  157. {
  158.     Boolean            canceled;
  159.     
  160.     misc_ValPrint(&Prefs.helpPrint, false);
  161.     Prefs.helpPrint.menuPick = MenuPick;
  162.     return rpp_StlDlog(&Prefs.helpPrint, &canceled);
  163. }
  164.     
  165. /*______________________________________________________________________
  166.  
  167.     Print - Process Print Command.
  168.     
  169.     Entry:    printOne = true if Print One command.
  170.     
  171.     Exit:        function result = error code.
  172. _____________________________________________________________________*/
  173.  
  174.  
  175. static OSErr Print (Boolean printOne)
  176.  
  177. {
  178.     Str255            titleTmpl;    /* template for date, time, pnum in headers */
  179.     Str255            docName;        /* document name */
  180.     
  181.     GetIndString(titleTmpl, strListID, hlpDocTmpl);
  182.     GetIndString(docName, strListID, hlpDocTitle);
  183.     Prefs.helpPrint.title = docName;
  184.     Prefs.helpPrint.titleTmpl = titleTmpl;
  185.     Prefs.helpPrint.docName = docName;
  186.     misc_ValPrint(&Prefs.helpPrint, false);
  187.     Prefs.helpPrint.menuPick = MenuPick;
  188.     return hlp_Print(&Prefs.helpPrint, printOne);
  189. }
  190.     
  191. /*______________________________________________________________________
  192.  
  193.     Adjust - Adjust Menus.
  194. _____________________________________________________________________*/
  195.  
  196.  
  197. static void Adjust (void)
  198.  
  199. {
  200.     MenuHandle                fileM;                    /* handle to file menu */
  201.     MenuHandle                editM;                    /* handle to edit menu */
  202.     MenuHandle                scanM;                    /* handle to scan menu */
  203.     
  204.     fileM = GetMHandle(fileMID);
  205.     editM = GetMHandle(editMID);
  206.     scanM = GetMHandle(scanMID);
  207.     EnableItem(fileM, closeCommand);
  208.     EnableItem(fileM, saveAsCommand);
  209.     EnableItem(fileM, pageSetupCommand);
  210.     EnableItem(fileM, printCommand);
  211.     EnableItem(fileM, printOneCommand);
  212.     if (Scanning) {
  213.         DisableItem(scanM, 0);
  214.     } else {
  215.         EnableItem(scanM, 0);
  216.     };
  217.     DisableItem(editM, 0);
  218. }
  219.  
  220. /*______________________________________________________________________
  221.  
  222.     DrawTconTitle - Draw Table of Contents Title.
  223. _____________________________________________________________________*/
  224.  
  225.  
  226. static void DrawTconTitle ()
  227.  
  228. {
  229.     Str255            str;                /* title */
  230.     short                h;                    /* horizontal coord of title */
  231.  
  232.     GetIndString(str, strListID, tconTitle);
  233.     TextFace(bold);
  234.     h = (RectList[tconRect].left + RectList[tconRect].right
  235.         - StringWidth(str)) >> 1;
  236.     MoveTo(h, RectList[tconRect].top-5);
  237.     DrawString(str);
  238.     TextFace(normal);
  239. }
  240.     
  241. /*______________________________________________________________________
  242.  
  243.     help_Open - Open Help Window.
  244.     
  245.     Entry:        tag = Tagged line to jump to, or 0 if none.
  246. _____________________________________________________________________*/
  247.  
  248.  
  249. void help_Open (short tag)
  250.  
  251. {
  252.     hlp_PBlock        p;                /* hlp_Open param block. */
  253.     short                fNum;            /* font number */
  254.     
  255.     HelpMode = false;
  256.     InitCursor();
  257.     
  258.     /* If the window is already open, activate it and jump to the tag. */
  259.     
  260.     if (HelpWindow) {
  261.         SelectWindow(HelpWindow);
  262.         if (tag) hlp_Jump(tag);
  263.         return;
  264.     };
  265.     
  266.     /* Get the help window and restore its state. */
  267.     
  268.     HelpWindow = wstm_Restore(false, helpWindID, (Ptr)&HelpWRecord,
  269.         &Prefs.helpState);
  270.     SetPort(HelpWindow);
  271.     
  272.     /* Initialize the window object. */
  273.     
  274.     ((WindowPeek)HelpWindow)->refCon = (long)&HelpWindObject;
  275.     HelpWindObject.windKind = helpWind;
  276.     HelpWindObject.moved = Prefs.helpState.moved;
  277.     SetRect(&HelpWindObject.sizeRect, HelpWindow->portRect.right, 
  278.         minHelpSize, HelpWindow->portRect.right, 0x7fff);
  279.     HelpWindObject.update = hlp_Update;
  280.     HelpWindObject.activate = hlp_Activate;
  281.     HelpWindObject.deactivate = hlp_Deactivate;
  282.     HelpWindObject.resume = nil;
  283.     HelpWindObject.suspend = nil;
  284.     HelpWindObject.click = Click;
  285.     HelpWindObject.help = Help;
  286.     HelpWindObject.grow = hlp_Grow;
  287.     HelpWindObject.zoom = hlp_Zoom;
  288.     HelpWindObject.key = hlp_Key;
  289.     HelpWindObject.close = Close;
  290.     HelpWindObject.disk = nil;
  291.     HelpWindObject.save = Save;
  292.     HelpWindObject.pageSetup = PageSetup;
  293.     HelpWindObject.print = Print;
  294.     HelpWindObject.edit = nil;
  295.     HelpWindObject.adjust = Adjust;
  296.     HelpWindObject.periodic = nil;
  297.     HelpWindObject.dialogPre = nil;
  298.     HelpWindObject.dialogPost = nil;
  299.     
  300.     /* Initialize hlp_Open param block. */
  301.     
  302.     if (!utl_GetFontNumber("\pGeneva", &fNum)) fNum = applFont;
  303.     p.scrollLine = Prefs.helpScrollPos;
  304.     p.firstStrID = firstDocID;
  305.     p.listDefID = lDefID;
  306.     p.textRect = RectList[docRect];
  307.     p.fontNum = fNum;
  308.     p.fontSize = 9;
  309.     p.tabConID = tconID;
  310.     p.tabConRect = RectList[tconRect];
  311.     p.tabConFNum = fNum;
  312.     p.tabConFSize = 9;
  313.     p.tabConLSep = 12;
  314.     p.tag = tag;
  315.     p.tagRezID = tagID;
  316.     p.cellRezID = cellID;
  317.     p.cellOption = 2;
  318.     p.extraUpdate = DrawTconTitle;
  319.     
  320.     /* Call hlp_Open to complete the open. */
  321.     
  322.     hlp_Open(HelpWindow, &p);
  323. }
  324.