home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / EEDRW23S.ZIP / EEDRAW.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-10  |  63.4 KB  |  1,791 lines

  1. /*****************************************************************************
  2. *   Program to draw EE diagrams.                         *
  3. *                                         *
  4. * Usage:                                     *
  5. *                                         *
  6. * Written by:  Gershon Elber            IBM PC Ver 2.0, Aug. 1990    *
  7. *****************************************************************************/
  8.  
  9. #include <math.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <conio.h>
  13. #include <string.h>
  14. #include <time.h>
  15. #include <dos.h>
  16. #include <dir.h>
  17. #include <alloc.h>
  18. #include <time.h>
  19. #include "Program.h"
  20. #include "EELibs.h"
  21. #include "EECreate.h"
  22. #include "EERedraw.h"
  23. #include "EEStatus.h"
  24. #include "EEString.h"
  25. #include "EEModify.h"
  26. #include "EELoad.h"
  27. #include "Director.h"
  28. #include "Ctrl-Brk.h"
  29. #include "Config.h"
  30.  
  31. #define WINDOWS_FRAME_WIDTH 8
  32. #define MAX_NUM_OF_OPEN_WINDOWS 50
  33.  
  34. #define DEFAULT_LIB_DIR "."        /* Current directory is the default. */
  35.  
  36. /* Undef DEBUG_MALLOC_TC20 iff you have TurboC 2.0. It assumes the offset    */
  37. /* part of the pointer is always 8 which is TRUE only of TC 2.0.         */
  38. /* #define DEBUG_MALLOC_TC20  /* Add debugging aid for malloc/free routines. */
  39.  
  40. /* Undef DEBUG_MALLOC_TCPP iff you have TurboC++ 1.0. It uses heap testing   */
  41. /* routines introduced in this version.                         */
  42. /* #define DEBUG_MALLOC_TCPP  /* Add debugging aid for malloc/free routines. */
  43.  
  44. #define DIRECT_CALL_INDEX_OFFSET    100
  45. #define MAX_KEY_BINDINGS    50
  46.  
  47. typedef struct {
  48.     int ScanCode;        /* Scan code to activate the following function. */
  49.     int Menu;                        /* Pull Down Menu index. */
  50.     int MenuEntry;                  /* Pull Down Menu entry index. */
  51. } KeyBindingStruct;
  52.  
  53. int EESnapDistance = DEFAULT_SNAP_DISTANCE,
  54.     EETextScale = 1,
  55.     EEWindowsFrameWidth = 8,               /* Width of all drawings. */
  56.     EEListNumDisplayed = 30,
  57.     EERootWindowID = -1,
  58.     EERootWndwFrameColor = INTR_COLOR_MAGENTA,
  59.     EERootWndwForeColor = INTR_COLOR_YELLOW,
  60.     EERootWndwBackColor = INTR_COLOR_BLUE,
  61.     EERootWndwXorColor = INTR_COLOR_CYAN,
  62.     EEPopUpFrameColor = INTR_COLOR_RED,   /* Color for pop up menus/queries. */
  63.     EEPopUpBackColor = INTR_COLOR_MAGENTA,
  64.     EEPopUpForeColor = INTR_COLOR_YELLOW,
  65.     EEPopUpXorColor = INTR_COLOR_YELLOW,
  66.     EEActvWndwFrameColor = INTR_COLOR_RED,
  67.     EEActvWndwForeColor = INTR_COLOR_YELLOW,
  68.     EEActvWndwBackColor = INTR_COLOR_BLUE,
  69.     EEPsvWndwFrameColor = INTR_COLOR_RED,
  70.     EEPsvWndwForeColor = INTR_COLOR_YELLOW,
  71.     EEPsvWndwBackColor = INTR_COLOR_BLUE,
  72.     EEHighLightColor = INTR_COLOR_RED;
  73. BooleanType
  74.     EEAutoPan = FALSE,
  75.     EEHVLineDrawing = TRUE;        /* Draw only horizontal/ vertical lines. */
  76. IntrBBoxStruct
  77.     *EEActiveBBox = NULL;
  78. EEWindowStruct
  79.     *EEActiveWindow = NULL,                   /* Pointer to active window. */
  80.     *EEWindowsList = NULL;              /* List of all open windows/files. */
  81.  
  82. static char
  83.     *VersionStr =
  84.     "EEDraw    IBMPC "
  85.     EEDRAW_VERSION
  86.     "    Gershon Elber,  "
  87.     __DATE__ ",   " __TIME__ "\n"
  88.     "(C) Copyright 1989-91 Gershon Elber, Non commercial use only.\n";
  89. static char
  90.     *UsageStr = "Usage: EEDraw [-z] *[EEDrawFile.EED]\n";
  91. static int
  92.     ActiveWindowID = -1,
  93.     HelpWindowID = -1,
  94.     ShowWindowName = FALSE,
  95.     Allow256Colors = FALSE,
  96.     AllowAsyncEvents = TRUE,
  97.     MouseExists = FALSE,
  98.     JoyStickExists = FALSE,
  99.     ATKeyboard = FALSE,
  100.     MouseSensitivity = 32,
  101.     SaveBackMethod = 0,
  102.     GraphDriver = 0,
  103.     KeyBindingCount = 0,
  104.     LastKeyStroke = -1;
  105. static char
  106.     *LoadLibraryList = NULL,
  107.     *SaveBackPath = NULL,
  108.     *BGIDriverPath = NULL,
  109.     *SVGANameMode = NULL,
  110.     *LibrariesPathPtr = NULL,
  111.     InitialPath[FULL_PATH_LEN],
  112.     LibrariesPath[FULL_PATH_LEN];
  113. static IntrCursorShapeStruct Cursor;
  114. static IntrBBoxStruct ResizeBBox;
  115. static KeyBindingStruct KeyBindingList[MAX_KEY_BINDINGS];
  116.  
  117. static ConfigStruct SetUp[] =
  118. { { "Mouse",        &MouseExists,        SU_BOOLEAN_TYPE },
  119.   { "Joystick",        &JoyStickExists,    SU_BOOLEAN_TYPE },
  120.   { "ATKeyboard",    &ATKeyboard,        SU_BOOLEAN_TYPE },
  121.   { "AutoPan",        &EEAutoPan,        SU_BOOLEAN_TYPE },
  122.   { "WindowName",    &ShowWindowName,    SU_BOOLEAN_TYPE },
  123.   { "HVLines",        &EEHVLineDrawing,    SU_BOOLEAN_TYPE },
  124.   { "Allow256Colors",   &Allow256Colors,    SU_BOOLEAN_TYPE },
  125.   { "AllowAsyncEvents", &AllowAsyncEvents,    SU_BOOLEAN_TYPE },
  126.   { "MouseSensitivity",    &MouseSensitivity,    SU_INTEGER_TYPE },
  127.   { "SnapDistance",    &EESnapDistance,    SU_INTEGER_TYPE },
  128.   { "SaveBackMethod",   &SaveBackMethod,    SU_INTEGER_TYPE },
  129.   { "GraphDriver",    &GraphDriver,        SU_INTEGER_TYPE },
  130.   { "RootFrameolor",    &EERootWndwFrameColor,  SU_INTEGER_TYPE },
  131.   { "RootForeColor",    &EERootWndwForeColor,   SU_INTEGER_TYPE },
  132.   { "RootBackColor",    &EERootWndwBackColor,   SU_INTEGER_TYPE },
  133.   { "RootXorColor",     &EERootWndwXorColor,    SU_INTEGER_TYPE },
  134.   { "ActvFrameColor",   &EEActvWndwFrameColor,  SU_INTEGER_TYPE },
  135.   { "ActvForeColor",    &EEActvWndwForeColor,   SU_INTEGER_TYPE },
  136.   { "ActvBackColor",    &EEActvWndwBackColor,   SU_INTEGER_TYPE },
  137.   { "PsvFrameColor",    &EEPsvWndwFrameColor,   SU_INTEGER_TYPE },
  138.   { "PsvForeColor",     &EEPsvWndwForeColor,    SU_INTEGER_TYPE },
  139.   { "PsvBackColor",     &EEPsvWndwBackColor,    SU_INTEGER_TYPE },
  140.   { "PopUpFrameColor",  &EEPopUpFrameColor,    SU_INTEGER_TYPE },
  141.   { "PopUpBackColor",   &EEPopUpBackColor,    SU_INTEGER_TYPE },
  142.   { "PopUpForeColor",   &EEPopUpForeColor,    SU_INTEGER_TYPE },
  143.   { "PopUpXorColor",    &EEPopUpXorColor,    SU_INTEGER_TYPE },
  144.   { "HighLightColor",   &EEHighLightColor,    SU_INTEGER_TYPE },
  145.   { "FrameWidth",    &EEWindowsFrameWidth,   SU_INTEGER_TYPE },
  146.   { "BGIDriverPath",    &BGIDriverPath,        SU_STRING_TYPE },
  147.   { "SaveBackPath",    &SaveBackPath,        SU_STRING_TYPE },
  148.   { "SVGANameMode",    &SVGANameMode,        SU_STRING_TYPE },
  149.   { "Libraries",    &LoadLibraryList,    SU_STRING_TYPE },
  150.   { "LibrariesPath",    &LibrariesPathPtr,    SU_STRING_TYPE },
  151. };
  152. #define NUM_SET_UP    (sizeof(SetUp) / sizeof(ConfigStruct))
  153.  
  154. extern unsigned int _stklen = 16384;         /* Increase default stack size. */
  155.  
  156. static void MakeWindowActive(EEWindowStruct *Window, BooleanType Refresh);
  157. static void MakeFullPathName(char *FileName);
  158. static EEWindowStruct *LoadOneEEFile(char *FileName, BooleanType IsNew);
  159. static void HandleFileMenu(int Index);
  160. static void HandleWindowMenu(int Index);
  161. static void HandleDisplayMenu(int Index);
  162. static void HandleLibsMenu(int Index);
  163. static void HandleDrawMenu(int Index);
  164. static void HandleModifyMenu(int Index);
  165. static void HandleSameAgain(int KeyStroke);
  166. static void HandleKeyBindings(int KeyStroke);
  167. static void HandleStatusMenu(int Index);
  168. static int ReadKeyBindings(char *Name);
  169. static char *GetFileName(char *FullPathName);
  170. static void RootWndwRefreshFunc(int WindowID);
  171. static void HelpWndwRefreshFunc(int WindowID);
  172. static void DataWndwRefreshFunc(int WindowID);
  173.  
  174. static IntrIntFunc PDActionFuncs[] = {   /* Pull Down Functions to activate. */
  175.     HandleFileMenu,
  176.     HandleWindowMenu,
  177.     HandleDisplayMenu,
  178.     HandleLibsMenu,
  179.     HandleDrawMenu,
  180.     HandleModifyMenu,
  181.     HandleStatusMenu
  182. };
  183. static char *PDMenuStrs[] = {              /* Pull Down Menu Entry names: */
  184.     "File",
  185.     "Window",
  186.     "Display",
  187.     "Libs",
  188.     "Draw",
  189.     "Modify",
  190.     "Status"
  191. };
  192. #define PULL_DOWN_SIZE (sizeof(PDMenuStrs) / sizeof(char *))
  193.  
  194. static char *FilePUStrs[] = {
  195.     "LoadEEDFile        ",
  196.     "NewEEDFile         ",
  197.     "SaveAllEED         ",
  198.     "SaveEEDFile        ",
  199.     "SaveEEDAsOld       ",
  200.     "SaveEEDAsNew       ",
  201.     "SaveNetList        ",
  202.     "CloseEEDFile       ",
  203.     "ClearAll           ",
  204.     "Directory          ",
  205.     "ChangeDir          ",
  206.     "ShellToDos         ",
  207.     "ExitEEdraw         ",
  208. };
  209. #define FILE_POP_UP_SIZE (sizeof(FilePUStrs) / sizeof(char *))
  210. static IntrPopUpMenuStruct *FilePUMenu = NULL;
  211. static char *WindowPUStrs[] = {
  212.     "PopWindow            ",
  213.     "PushWindow           ",
  214.     "MoveWindow           ",
  215.     "ResizeWindow         ",
  216.     "FullSize             ",
  217.     "ShowName             ",
  218.     "MakeActive           ",
  219.     "NameActive           ",
  220.     "PanWindowLeft        ",
  221.     "PanWindowRight       ",
  222.     "PanWindowUp          ",
  223.     "PanWindowDown        "
  224. };
  225. #define WINDOW_POP_UP_SIZE (sizeof(WindowPUStrs) / sizeof(char *))
  226. static IntrPopUpMenuStruct *WindowPUMenu = NULL;
  227. static char *DisplayPUStrs[] = {
  228.     "ZoomOut         ",
  229.     "ZoomIn          ",
  230.     "ZoomReset       ",
  231.     "RedrawAll       "
  232. };
  233. #define DISPLAY_POP_UP_SIZE (sizeof(DisplayPUStrs) / sizeof(char *))
  234. static IntrPopUpMenuStruct *DisplayPUMenu = NULL;
  235. static char *LibsPUStrs[] = {
  236.     "LoadLibrary         ",
  237.     "LoadLibByName       ",
  238.     "FreeLibrary         ",
  239.     "ViewLibrary         ",
  240.     "DirLibrary          ",
  241.     "ChDirLibrary        "
  242. };
  243. #define LIBS_POP_UP_SIZE (sizeof(LibsPUStrs) / sizeof(char *))
  244. static IntrPopUpMenuStruct *LibsPUMenu = NULL;
  245. static char *DrawPUStrs[] = {
  246.     "DrawLine          ",
  247.     "DrawBus           ",
  248.     "DrawConnect       ",
  249.     "DrawText          ",
  250.     "DrawLibItem       "
  251. };
  252. #define DRAW_POP_UP_SIZE (sizeof(DrawPUStrs) / sizeof(char *))
  253. static IntrPopUpMenuStruct *DrawPUMenu = NULL;
  254. static char *ModifyPUStrs[] = {
  255.     "ModifyMove         ",
  256.     "ModifyCopy         ",
  257.     "EditLibItem        ",
  258.     "ModifyDelete       ",
  259.     "ModifyUnDel        ",
  260.     "ModifyCut          ",
  261.     "ModifyPaste        ",
  262.     "ModifyDrop         "
  263. };
  264. #define MODIFY_POP_UP_SIZE (sizeof(ModifyPUStrs) / sizeof(char *))
  265. static IntrPopUpMenuStruct *ModifyPUMenu = NULL;
  266. static char *StatusPUStrs[] = {
  267.     "Help                ",
  268.     "GetMemoryFree       ",
  269.     "GetZoomFactor       ",
  270.     "SetDrawText         ",
  271.     "SetTextSize         ",
  272.     "SetAutoPan          ",
  273.     "SetHVLines          ",
  274.     "SetSnapFactor       "
  275. };
  276. #define STATUS_POP_UP_SIZE (sizeof(StatusPUStrs) / sizeof(char *))
  277. static IntrPopUpMenuStruct *StatusPUMenu = NULL;
  278.  
  279. static char **AllPUStrs[] = {
  280.     FilePUStrs,
  281.     WindowPUStrs,
  282.     DisplayPUStrs,
  283.     LibsPUStrs,
  284.     DrawPUStrs,
  285.     ModifyPUStrs,
  286.     StatusPUStrs
  287. };
  288. static int AllPUSizes[] = {
  289.     FILE_POP_UP_SIZE,
  290.     WINDOW_POP_UP_SIZE,
  291.     DISPLAY_POP_UP_SIZE,
  292.     LIBS_POP_UP_SIZE,
  293.     DRAW_POP_UP_SIZE,
  294.     MODIFY_POP_UP_SIZE,
  295.     STATUS_POP_UP_SIZE
  296. };
  297. #define ALL_POP_UP_SIZE (sizeof(AllPUStrs) / sizeof(char **))
  298.  
  299. /*****************************************************************************
  300. * Main routine - Read Parameter    line and do what you need...             *
  301. *****************************************************************************/
  302. void main(int argc, char **argv)
  303. {
  304.     int x, y;
  305.     IntrPullDownMenuStruct *MainPullDownMenu;
  306.  
  307.     getcwd(InitialPath, FULL_PATH_LEN);  /* Save where we were when started. */
  308.     strcpy(LibrariesPath, DEFAULT_LIB_DIR);
  309.  
  310.     if (strcmp(argv[1], "-z") == 0) {
  311.     fprintf(stderr, "%s%s", UsageStr, VersionStr);
  312.     MyExit(-1);
  313.     }
  314.  
  315.     SetUpCtrlBrk();
  316.     SetUpHardErr();
  317.  
  318.     Config(PROGRAM_NAME, SetUp, NUM_SET_UP); /* Read config. file if exists. */
  319.  
  320.     if (LibrariesPathPtr != NULL) {
  321.     strcpy(LibrariesPath, LibrariesPathPtr);
  322.     MyFree((VoidPtr) LibrariesPathPtr);
  323.     };
  324.  
  325.     /* Read the key binding file and initialize the main menu accordingly: */
  326.     if (!ReadKeyBindings(PROGRAM_NAME)) MyExit(-1);
  327.  
  328.     Cursor.CursorType = INTR_CURSOR_ARROW;
  329.     IntrSetCursorType(&Cursor);
  330.  
  331.     if (SVGANameMode != NULL && strlen(SVGANameMode) > 0)
  332.     GRInstallSVGA(SVGANameMode);
  333.  
  334.     if (BGIDriverPath != NULL && strlen(BGIDriverPath) > 0)
  335.         GRSetBGIPath(BGIDriverPath);
  336.  
  337.     GRSetDefaultDriver(GraphDriver);
  338.  
  339.     IntrSetSaveBackPath(SaveBackPath);
  340.     IntrSetSaveBackMethod(SaveBackMethod);
  341.  
  342.     IntrSetMouseSensitivity(MouseSensitivity);
  343.     IntrSetAtKeyboard(ATKeyboard);
  344.  
  345.     IntrAllow256Colors(Allow256Colors);
  346.     IntrSetAsyncEventMode(AllowAsyncEvents);
  347.  
  348.     IntrInit();                  /* Initialize the interaction library. */
  349.  
  350.     IntrSetInputDevice(INTR_INPT_DEVICE_KEYBOARD |
  351.                    (MouseExists ? INTR_INPT_DEVICE_MOUSE : 0) |
  352.                        (JoyStickExists ? INTR_INPT_DEVICE_JOYSTICK : 0));
  353.                
  354.     EEListNumDisplayed = GRScreenMaxY / 20;
  355.  
  356.     MainPullDownMenu = IntrPullDownMenuCreate(PDMenuStrs, 0, PULL_DOWN_SIZE,
  357.                               PDActionFuncs,
  358.                                               EERootWndwFrameColor,
  359.                                               EERootWndwBackColor,
  360.                                               EERootWndwForeColor,
  361.                                               EERootWndwXorColor,
  362.                                               EEWindowsFrameWidth);
  363.  
  364.     ResizeBBox.Xmin = EEWindowsFrameWidth;
  365.     ResizeBBox.Xmax = GRScreenMaxX - EEWindowsFrameWidth;
  366.     ResizeBBox.Ymin = IntrWndwGetHeaderHeight("M", EEWindowsFrameWidth) +
  367.                                 EEWindowsFrameWidth + 2;
  368.     ResizeBBox.Ymax = GRScreenMaxY - EEWindowsFrameWidth;
  369.  
  370.     /* Create and map to screen the root back ground window. */
  371.     EERootWindowID = IntrWndwCreate(NULL, EEWindowsFrameWidth, &ResizeBBox,
  372.                 EERootWndwFrameColor, EERootWndwBackColor, NULL,
  373.                                 MainPullDownMenu, RootWndwRefreshFunc);
  374.     IntrWndwSetZoom(EERootWindowID, DEFAULT_ZOOM_FACTOR);
  375.     IntrWndwPop(EERootWindowID, TRUE, FALSE);
  376.  
  377.     ResizeBBox.Xmin += IntrWndwScrollBarWidth();
  378.     if (ShowWindowName)
  379.     ResizeBBox.Ymin += IntrWndwGetHeaderHeight("M", EEWindowsFrameWidth) + 2;
  380.     ResizeBBox.Ymax -= IntrWndwScrollBarWidth();
  381.     IntrWndwSetResizeBBox(&ResizeBBox);       /* Set bounds to window resizing. */
  382.  
  383.     FilePUMenu = IntrPopUpMenuCreate(NULL, FilePUStrs, 0, FILE_POP_UP_SIZE,
  384.                          EERootWndwFrameColor, EERootWndwBackColor,
  385.                                      EERootWndwForeColor, EERootWndwXorColor,
  386.                                      EEWindowsFrameWidth, &Cursor);
  387.     WindowPUMenu = IntrPopUpMenuCreate(NULL, WindowPUStrs, 0, WINDOW_POP_UP_SIZE,
  388.                          EERootWndwFrameColor, EERootWndwBackColor,
  389.                                      EERootWndwForeColor, EERootWndwXorColor,
  390.                                      EEWindowsFrameWidth, &Cursor);
  391.     DisplayPUMenu = IntrPopUpMenuCreate(NULL, DisplayPUStrs, 0, DISPLAY_POP_UP_SIZE,
  392.                     EERootWndwFrameColor, EERootWndwBackColor,
  393.                                         EERootWndwForeColor, EERootWndwXorColor,
  394.                                         EEWindowsFrameWidth, &Cursor);
  395.     LibsPUMenu = IntrPopUpMenuCreate(NULL, LibsPUStrs, 0, LIBS_POP_UP_SIZE,
  396.                          EERootWndwFrameColor, EERootWndwBackColor,
  397.                                      EERootWndwForeColor, EERootWndwXorColor,
  398.                                      EEWindowsFrameWidth, &Cursor);
  399.     DrawPUMenu = IntrPopUpMenuCreate(NULL, DrawPUStrs, 0, DRAW_POP_UP_SIZE,
  400.                          EERootWndwFrameColor, EERootWndwBackColor,
  401.                                      EERootWndwForeColor, EERootWndwXorColor,
  402.                                      EEWindowsFrameWidth, &Cursor);
  403.     ModifyPUMenu = IntrPopUpMenuCreate(NULL, ModifyPUStrs, 0, MODIFY_POP_UP_SIZE,
  404.                            EERootWndwFrameColor, EERootWndwBackColor,
  405.                                        EERootWndwForeColor, EERootWndwXorColor,
  406.                                        EEWindowsFrameWidth, &Cursor);
  407.     StatusPUMenu = IntrPopUpMenuCreate(NULL, StatusPUStrs, 0, STATUS_POP_UP_SIZE,
  408.                            EERootWndwFrameColor, EERootWndwBackColor,
  409.                                        EERootWndwForeColor, EERootWndwXorColor,
  410.                                        EEWindowsFrameWidth, &Cursor);
  411.  
  412.     if (LoadLibraryList != NULL) {
  413.     LoadLibraries(LoadLibraryList);
  414.     MyFree((VoidPtr) LoadLibraryList);
  415.     LoadLibraryList = NULL;
  416.     }
  417.  
  418.     /* Load All files specified in the command line. */
  419.     while (argc-- > 1)
  420.         LoadOneEEFile(*++argv, FALSE);
  421.  
  422.     /* Query events forever. From this point everything is events driven     */
  423.     /* and we need do nothing beyond this infinite event query.             */
  424.     while (TRUE) {
  425.     GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  426.         if (IntrGetEventWait(&x, &y) == INTR_EVNT_MIDDLE_BUTTON)
  427.         HandleSameAgain(0);
  428.     }
  429. }
  430.  
  431. /*****************************************************************************
  432. * Routine to handle the FILE pull down sub menu.                 *
  433. *****************************************************************************/
  434. static void MakeWindowActive(EEWindowStruct *Window, BooleanType Refresh)
  435. {
  436.     if (EEActiveWindow == Window) return;
  437.  
  438.     /* If there is current active window - inactivate it. */
  439.     if (ActiveWindowID >= 0) {
  440.     IntrWndwSetFrameColor(EEActiveWindow -> IntrLibWindowID,
  441.                   EEPsvWndwFrameColor);
  442.     IntrWndwSetBackGroundColor(EEActiveWindow -> IntrLibWindowID,
  443.                        EEPsvWndwBackColor);
  444.         IntrWndwSetScrlBar(EEActiveWindow -> IntrLibWindowID, TRUE,
  445.                INTR_SCRLBAR_LEFT, EEPsvWndwForeColor);
  446.         IntrWndwSetScrlBar(EEActiveWindow -> IntrLibWindowID, FALSE,
  447.                INTR_SCRLBAR_BOTTOM, EEPsvWndwForeColor);
  448.     if (Refresh)
  449.             IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  450.     }
  451.  
  452.     EEActiveWindow = Window;
  453.     ActiveWindowID = EEActiveWindow -> IntrLibWindowID;
  454.     EEActiveBBox = IntrWndwGetBBox(ActiveWindowID);
  455.     IntrWndwSetFrameColor(EEActiveWindow -> IntrLibWindowID,
  456.               EEActvWndwFrameColor);
  457.     IntrWndwSetBackGroundColor(EEActiveWindow -> IntrLibWindowID,
  458.                    EEActvWndwBackColor);
  459.     IntrWndwSetScrlBar(EEActiveWindow -> IntrLibWindowID, TRUE,
  460.                INTR_SCRLBAR_LEFT, EEActvWndwForeColor);
  461.     IntrWndwSetScrlBar(EEActiveWindow -> IntrLibWindowID, FALSE,
  462.                INTR_SCRLBAR_BOTTOM, EEActvWndwForeColor);
  463.     if (Refresh)
  464.         IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  465. }
  466.  
  467. /*****************************************************************************
  468. * Routine to make sure the cursor is positioned in the active window.        *
  469. *****************************************************************************/
  470. void PutCursorInActiveWindow(void)
  471. {
  472.     if (EEActiveBBox -> Xmin > GRCurrentCursorX ||
  473.     EEActiveBBox -> Xmax < GRCurrentCursorX ||
  474.     EEActiveBBox -> Ymin > GRCurrentCursorY ||
  475.     EEActiveBBox -> Ymax < GRCurrentCursorY) {
  476.     GRCurrentCursorX = (EEActiveBBox -> Xmin + EEActiveBBox -> Xmax) / 2;
  477.     GRCurrentCursorY = (EEActiveBBox -> Ymin + EEActiveBBox -> Ymax) / 2;
  478.     }
  479. }
  480.  
  481. /*****************************************************************************
  482. * Routine to expand a file name to be a full path if necessary.             *
  483. *****************************************************************************/
  484. static void MakeFullPathName(char *FileName)
  485. {
  486.     int Mask;
  487.     char Drive[3], Dir[66], Name[9], Ext[5];
  488.  
  489.     Mask = fnsplit(FileName, Drive, Dir, Name, Ext);
  490.  
  491.     if (!(Mask & DRIVE)) {
  492.     Drive[0] = getdisk() + 'A';
  493.     Drive[1] = ':';
  494.     Drive[2] = 0;
  495.     }
  496.     if (!(Mask & DIRECTORY)) {
  497.         strcpy(Dir, "\\");
  498.         getcurdir(Drive[0] - 'A' + 1, &Dir[1]);
  499.     }
  500.  
  501.     fnmerge(FileName, Drive, Dir, Name, Ext);
  502.     strlwr(FileName);
  503. }
  504.  
  505. /*****************************************************************************
  506. * Routine to handle file loading. If given file name is NULL the name is     *
  507. * queried (within LoadEEFile).                             *
  508. * However if IsNew then no file is loaded.                     *
  509. *****************************************************************************/
  510. static EEWindowStruct *LoadOneEEFile(char *FileName, BooleanType IsNew)
  511. {
  512.     EEWindowStruct
  513.         *Window = (EEWindowStruct *) MyMalloc(sizeof(EEWindowStruct));
  514.  
  515.     if (FileName != NULL)
  516.     strcpy(Window -> FileName, FileName);
  517.     else
  518.     Window -> FileName[0] = 0;
  519.  
  520.     Window -> EEDrawList = NULL;
  521.     Window -> IntrLibWindowID = -1;
  522.     Window -> Modified = FALSE;
  523.     if (IsNew || LoadEEFile(Window)) {
  524.     if (strlen(Window -> FileName) == 0)
  525.         strcpy(Window -> FileName, "noname.eed");
  526.         /* Expand the file name to full path if necessary: */
  527.     MakeFullPathName(Window ->FileName);
  528.  
  529.         Window -> PageXSize = PAGE_A4_XSIZE;
  530.         Window -> PageYSize = PAGE_A4_YSIZE;
  531.     Window -> IsFullSize = FALSE;
  532.     Window -> IntrLibWindowID =
  533.             IntrWndwCreate(ShowWindowName ? Window -> FileName : NULL,
  534.                        EEWindowsFrameWidth, &ResizeBBox,
  535.                EEActvWndwFrameColor, EEActvWndwBackColor,
  536.                            NULL, NULL, DataWndwRefreshFunc);
  537.         IntrWndwSetStatus(Window -> IntrLibWindowID, "O", "O", FALSE);
  538.         IntrWndwSetScrlBar(Window -> IntrLibWindowID, TRUE,
  539.                INTR_SCRLBAR_LEFT, EEActvWndwForeColor);
  540.         IntrWndwSetScrlBar(Window -> IntrLibWindowID, FALSE,
  541.                INTR_SCRLBAR_BOTTOM, EEActvWndwForeColor);
  542.     IntrWndwSetZoom(Window -> IntrLibWindowID, DEFAULT_ZOOM_FACTOR);
  543.     IntrWndwSetPanning(Window -> IntrLibWindowID,
  544.                    DEFAULT_INV_ZOOM(Window -> PageXSize) / 2,
  545.                            DEFAULT_INV_ZOOM(Window -> PageYSize) / 2);
  546.         Window -> Pnext = EEWindowsList;
  547.         EEWindowsList = Window;
  548.         IntrWndwResize(Window -> IntrLibWindowID, FALSE);
  549.         MakeWindowActive(Window, TRUE);
  550.         return Window;
  551.     }
  552.     else {
  553.     MyFree((VoidPtr) Window);
  554.     return NULL;
  555.     }
  556. }
  557.  
  558. /*****************************************************************************
  559. * Routine to handle the FILE pull down sub menu.                 *
  560. *****************************************************************************/
  561. static void HandleFileMenu(int Index)
  562. {
  563.     int NumOfFiles, WindowID;
  564.     char Line[LINE_LEN], Buffer[LINE_LEN];
  565.     FileNameType *FileNames;
  566.     EEWindowStruct *TWindow, *Window;
  567.  
  568.     if (Index >= 0) {
  569.     if (IntrPopUpMenu(FilePUMenu, INTR_WNDW_PULL_DOWN))
  570.         Index = FilePUMenu -> SelectedIndex;
  571.         else
  572.             Index = -1;
  573.     }
  574.     else
  575.     Index += DIRECT_CALL_INDEX_OFFSET;
  576.  
  577.     GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  578.  
  579.     switch(Index) {
  580.         case 0: /* Load EED File */
  581.         LoadOneEEFile(NULL, FALSE);
  582.             break;
  583.         case 1: /* New EED File */
  584.         LoadOneEEFile(NULL, TRUE);
  585.             break;
  586.     case 2: /* Save All EED */
  587.             for (Window = EEWindowsList;
  588.                  Window != NULL;
  589.                  Window = Window -> Pnext)
  590.                 if (Window -> Modified) {
  591.                     IntrDrawMessage(Window -> FileName, EEPopUpForeColor,
  592.                                         EEPopUpBackColor);
  593.                     if (SaveEEFile(FILE_SAVE_AS, Window)) {
  594.                         Window -> Modified = FALSE;
  595.                         IntrWndwSetStatus(Window -> IntrLibWindowID, "S", "S",
  596.                                     FALSE);
  597.                     }
  598.             IntrEraseMessage();
  599.                 }
  600.             if (ShowWindowName)
  601.         IntrWndwRedrawAll();
  602.         break;
  603.     case 3: /* Save EED As */
  604.         if (ActiveWindowID < 0) {
  605.         IntrQueryContinue("No active window to save.",
  606.               EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  607.               EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  608.               INTR_WNDW_PLACE_CENTER);
  609.         break;
  610.         }
  611.         if (!EEActiveWindow -> Modified) {
  612.         IntrQueryContinue("Active file has not been modified",
  613.                   EEPopUpFrameColor, EEPopUpBackColor,
  614.                   EEPopUpForeColor, EEPopUpXorColor,
  615.                   EEWindowsFrameWidth, &Cursor,
  616.                   INTR_WNDW_PLACE_CENTER);
  617.         break;
  618.         }
  619.         if (SaveEEFile(FILE_SAVE_AS, EEActiveWindow)) {
  620.         EEActiveWindow -> Modified = FALSE;
  621.         IntrWndwSetStatus(EEActiveWindow -> IntrLibWindowID, "S", "S",
  622.                                   ShowWindowName);
  623.         }
  624.         break;
  625.     case 4: /* Save EED Old */
  626.         if (ActiveWindowID < 0) {
  627.         IntrQueryContinue("No active window to save.",
  628.               EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  629.               EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  630.               INTR_WNDW_PLACE_CENTER);
  631.         break;
  632.         }
  633.         if (SaveEEFile(FILE_SAVE_OLD, EEActiveWindow)) {
  634.         EEActiveWindow -> Modified = FALSE;
  635.         IntrWndwSetStatus(EEActiveWindow -> IntrLibWindowID, "S", "S",
  636.                                        FALSE);
  637.  
  638.         /* Expand the file name to full path: */
  639.         MakeFullPathName(EEActiveWindow -> FileName);
  640.  
  641.         if (ShowWindowName) {
  642.             IntrWndwSetName(EEActiveWindow -> IntrLibWindowID,
  643.                     EEActiveWindow -> FileName);
  644.             IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  645.         }
  646.         }
  647.         break;
  648.     case 5: /* Save EED New */
  649.         if (ActiveWindowID < 0) {
  650.         IntrQueryContinue("No active window to save.",
  651.               EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  652.               EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  653.               INTR_WNDW_PLACE_CENTER);
  654.         break;
  655.         }
  656.         if (SaveEEFile(FILE_SAVE_NEW, EEActiveWindow)) {
  657.         EEActiveWindow -> Modified = FALSE;
  658.         IntrWndwSetStatus(EEActiveWindow -> IntrLibWindowID, "S", "S",
  659.                                        FALSE);
  660.  
  661.         /* Expand the file name to full path: */
  662.         MakeFullPathName(EEActiveWindow -> FileName);
  663.  
  664.         if (ShowWindowName) {
  665.             IntrWndwSetName(EEActiveWindow -> IntrLibWindowID,
  666.                     EEActiveWindow -> FileName);
  667.             IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  668.         }
  669.         }
  670.         break;
  671.     case 6: /* Save Net List */
  672.         if (ActiveWindowID < 0) {
  673.         IntrQueryContinue("No active window to save.",
  674.               EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  675.               EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  676.               INTR_WNDW_PLACE_CENTER);
  677.         break;
  678.         }
  679.         SaveNetList(EEActiveWindow);
  680.         break;
  681.     case 7: /* Close EED File */
  682.         if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID) {
  683.         for (Window = EEWindowsList;
  684.              Window != NULL;
  685.              Window = Window -> Pnext)
  686.             if (Window -> IntrLibWindowID == WindowID) break;
  687.         if (Window == NULL) break;
  688.  
  689.         if (Window -> Modified &&
  690.             !IntrQueryYesNo("Window modified - delete?",
  691.             EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  692.             EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  693.             INTR_WNDW_PLACE_CENTER))
  694.             break;
  695.  
  696.         /* Delete the window from window list */
  697.         if (EEWindowsList != Window) {
  698.             for (TWindow = EEWindowsList;
  699.              TWindow -> Pnext != Window;
  700.              TWindow = TWindow -> Pnext);
  701.             TWindow -> Pnext = TWindow -> Pnext -> Pnext;
  702.         }
  703.         else
  704.             EEWindowsList = EEWindowsList -> Pnext;
  705.  
  706.         CloseEEDFile(Window);
  707.  
  708.         if (Window == EEActiveWindow) {
  709.             ActiveWindowID = -1;
  710.             EEActiveWindow = NULL;
  711.             if (EEWindowsList != NULL)
  712.             MakeWindowActive(EEWindowsList, FALSE);
  713.         }
  714.         IntrWndwRedrawAll();
  715.         }
  716.         break;
  717.     case 8: /* Clear All */
  718.         if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID) {
  719.         for (Window = EEWindowsList;
  720.              Window != NULL;
  721.              Window = Window -> Pnext)
  722.             if (Window -> IntrLibWindowID == WindowID) break;
  723.         if (Window == NULL) break;
  724.  
  725.         if (ClearDrawList(Window)) {
  726.             Window -> Modified = TRUE;
  727.             IntrWndwSetStatus(Window -> IntrLibWindowID, "M", "M",
  728.                                        FALSE);
  729.             IntrWndwPop(Window -> IntrLibWindowID, TRUE, FALSE);
  730.         }
  731.         }
  732.         break;
  733.     case 9: /* Directory */
  734.         if ((FileNames = GetFileNamesDir("*.*", ".", &NumOfFiles))
  735.                                 != NULL) {
  736.         qsort(FileNames, NumOfFiles, sizeof(FileNameType),
  737.               (int (*)(const void *, const void *)) strcmp);
  738.         IntrQueryList("Directory", (char **) FileNames,
  739.              sizeof(FileNameType), NumOfFiles, EEListNumDisplayed,
  740.              EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  741.              EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  742.              INTR_WNDW_PLACE_CENTER);
  743.         MyFree((VoidPtr) FileNames);
  744.         }
  745.         break;
  746.     case 10: /* New Dir */
  747.         getcwd(Line, LINE_LEN - 1);
  748.         sprintf(Buffer, "New dir (%s):", Line);
  749.         IntrQueryLine(Buffer, Line, LINE_LEN - 1, EEPopUpFrameColor,
  750.               EEPopUpBackColor, EEPopUpForeColor,
  751.               EEWindowsFrameWidth, INTR_WNDW_PLACE_CENTER);
  752.         if (ChangeDir(Line) != CD_OK) {
  753.         GRTone(1400, 100);             /* Do some noise... */
  754.         GRTone( 400, 100);
  755.         }
  756.         break;
  757.     case 11: /* Push to DOS */
  758.         /* Look for unsaved file and if found one - issue a warning. */
  759.         for (Window = EEWindowsList;
  760.          Window != NULL;
  761.          Window = Window -> Pnext)
  762.         if (Window -> Modified) {
  763.             if (IntrQueryYesNo("Not all files are saved, save first?",
  764.                        EEPopUpFrameColor, EEPopUpBackColor,
  765.                        EEPopUpForeColor, EEPopUpXorColor,
  766.                        EEWindowsFrameWidth, &Cursor,
  767.                        INTR_WNDW_PLACE_CENTER)) {
  768.             HandleFileMenu(2 - DIRECT_CALL_INDEX_OFFSET);
  769.             }
  770.             break;
  771.         }
  772.  
  773.         DosSystem();
  774.         break;
  775.     case 12: /* Exit */
  776.         /* Look for unsaved file and if found one - issue a warning. */
  777.         for (Window = EEWindowsList;
  778.          Window != NULL;
  779.          Window = Window -> Pnext)
  780.         if (Window -> Modified) {
  781.             if (IntrQueryYesNo("Not all files are saved, save first?",
  782.                        EEPopUpFrameColor, EEPopUpBackColor,
  783.                        EEPopUpForeColor, EEPopUpXorColor,
  784.                        EEWindowsFrameWidth, &Cursor,
  785.                        INTR_WNDW_PLACE_CENTER)) {
  786.             HandleFileMenu(2 - DIRECT_CALL_INDEX_OFFSET);
  787.             }
  788.             break;
  789.         }
  790.  
  791.         IntrInputFlush();      /* Make sure we do not exit accidentally. */
  792.         if (IntrQueryYesNo("Exit EEDRAW", EEPopUpFrameColor,
  793.                    EEPopUpBackColor, EEPopUpForeColor,
  794.                    EEPopUpXorColor, EEWindowsFrameWidth,
  795.                    &Cursor, INTR_WNDW_PLACE_CENTER))
  796.         MyExit(0);
  797.     }
  798. }
  799.  
  800. /*****************************************************************************
  801. * Routine to handle the WINDOW pull down sub menu.                 *
  802. *****************************************************************************/
  803. static void HandleWindowMenu(int Index)
  804. {
  805.     int i, WindowID;
  806.     char **Names;
  807.     EEWindowStruct *Window;
  808.     IntrBBoxStruct *BBox;
  809.  
  810.     if (ActiveWindowID < 0 && HelpWindowID < 0) {
  811.     IntrQueryContinue("No windows to work on.",
  812.                   EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  813.                           EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  814.                           INTR_WNDW_PLACE_CENTER);
  815.         return;
  816.     }
  817.  
  818.     if (Index >= 0) {
  819.     if (IntrPopUpMenu(WindowPUMenu, INTR_WNDW_PULL_DOWN))
  820.         Index = WindowPUMenu -> SelectedIndex;
  821.         else
  822.             Index = -1;
  823.     }
  824.     else
  825.     Index += DIRECT_CALL_INDEX_OFFSET;
  826.  
  827.     GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  828.  
  829.     switch(Index) {
  830.     case 0: /* Pop */
  831.             if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID)
  832.                 IntrWndwPop(WindowID, TRUE, FALSE);
  833.             break;
  834.     case 1: /* Push */
  835.             if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID) {
  836.                 IntrWndwPush(WindowID, FALSE);
  837.                 IntrWndwPush(EERootWindowID, TRUE);
  838.             }
  839.             break;
  840.         case 2: /* Move. */
  841.         if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID)
  842.          IntrWndwMove(WindowID, TRUE);
  843.             break;
  844.         case 3: /* Resize. */
  845.             if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID) {
  846.         if (WindowID == HelpWindowID) {
  847.             /* Set bounds to help window resizing (no bottom scrlbar). */
  848.                     ResizeBBox.Ymax += IntrWndwScrollBarWidth();
  849.             IntrWndwSetResizeBBox(&ResizeBBox);
  850.         }
  851.  
  852.                 IntrWndwResize(WindowID, TRUE);
  853.  
  854.         if (WindowID == HelpWindowID) {
  855.             /* Set bounds back to default window resizing. */
  856.                     ResizeBBox.Ymax -= IntrWndwScrollBarWidth();
  857.             IntrWndwSetResizeBBox(&ResizeBBox);
  858.                 }
  859.             }
  860.         break;
  861.         case 4: /* Full Size. */
  862.             if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID)
  863.             for (Window = EEWindowsList;
  864.              Window != NULL;
  865.                  Window = Window -> Pnext)
  866.                     if (WindowID == Window -> IntrLibWindowID) {
  867.                         if (Window -> IsFullSize) {
  868.                 IntrWndwSetBBox(WindowID, &Window -> BBox);
  869.                 IntrWndwRedrawAll();
  870.                         }
  871.                         else {
  872.                 BBox = IntrWndwGetBBox(WindowID);
  873.                             Window -> BBox = *BBox;
  874.                 IntrWndwSetBBox(WindowID, &ResizeBBox);
  875.                 IntrWndwPop(WindowID, TRUE, FALSE);
  876.                         }
  877.                         Window -> IsFullSize = !Window -> IsFullSize;
  878.                         break;
  879.                     }
  880.             break;
  881.         case 5: /* Show Window Name. */
  882.             /* The ! below on both sides guarantee boolean values only... */
  883.         if (!ShowWindowName !=
  884.                 !IntrQueryYesNo("Show Window Names", EEPopUpFrameColor,
  885.                            EEPopUpBackColor, EEPopUpForeColor,
  886.                                EEPopUpXorColor, EEWindowsFrameWidth,
  887.                                &Cursor, INTR_WNDW_PLACE_CENTER)) {
  888.         ShowWindowName = !ShowWindowName;
  889.  
  890.         if (ShowWindowName)
  891.             ResizeBBox.Ymin += IntrWndwGetHeaderHeight("M",
  892.                                           EEWindowsFrameWidth) + 2;
  893.         else
  894.             ResizeBBox.Ymin -= IntrWndwGetHeaderHeight("M",
  895.                               EEWindowsFrameWidth) + 2;
  896.         IntrWndwSetResizeBBox(&ResizeBBox);
  897.  
  898.             for (Window = EEWindowsList;
  899.                  Window != NULL;
  900.                  Window = Window -> Pnext) {
  901.                     /* Make sure min. Y does not cover the Pull Down Menu. */
  902.             BBox = IntrWndwGetBBox(Window -> IntrLibWindowID);
  903.                     if (BBox -> Ymin < ResizeBBox.Ymin)
  904.             BBox -> Ymin = ResizeBBox.Ymin;
  905.  
  906.             IntrWndwSetName(Window -> IntrLibWindowID,
  907.                     ShowWindowName ? Window -> FileName : NULL);
  908.         }
  909.                 if (HelpWindowID >= 0) {
  910.             BBox = IntrWndwGetBBox(HelpWindowID);
  911.                     if (BBox -> Ymin < ResizeBBox.Ymin)
  912.                 BBox -> Ymin = ResizeBBox.Ymin;
  913.  
  914.             IntrWndwSetName(HelpWindowID,
  915.                     ShowWindowName ? "Help" : NULL);
  916.                 }
  917.  
  918.                 IntrWndwRedrawAll();
  919.             }
  920.             break;
  921.         case 6: /* Make Window Active. */
  922.             if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID) {
  923.             for (Window = EEWindowsList;
  924.                  Window != NULL;
  925.                  Window = Window -> Pnext)
  926.                     if (WindowID == Window -> IntrLibWindowID) {
  927.                         MakeWindowActive(Window, TRUE);
  928.                         break;
  929.                     }
  930.         }
  931.             break;
  932.         case 7: /* Make Window Active by Name. */
  933.         for (Window = EEWindowsList, i = 0;    /* Find how many windows. */
  934.                  Window != NULL;
  935.              Window = Window -> Pnext, i++);
  936.         Names = (char **) MyMalloc(sizeof(char *) * i);
  937.         for (Window = EEWindowsList, i = 0;   /* Prepare array of names. */
  938.          Window != NULL;
  939.              Window = Window -> Pnext)
  940.                 Names[i++] = GetFileName(Window -> FileName);
  941.         i = IntrQueryList("File Names", Names, 0, i, EEListNumDisplayed,
  942.                          EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  943.                          EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  944.                          INTR_WNDW_PLACE_CENTER);
  945.             MyFree((VoidPtr) Names);
  946.             if (i >= 0) {      /* If was selection - find window and select. */
  947.         for (Window = EEWindowsList;
  948.                      i-- > 0;
  949.                  Window = Window -> Pnext);
  950.                 MakeWindowActive(Window, TRUE);
  951.             }
  952.         break;
  953.     case 8: /* Pan left */
  954.             IntrWndwUpdatePanning(EEActiveWindow -> IntrLibWindowID,
  955.                   (GRInvMapX(EEActiveBBox -> Xmin) -
  956.                                GRInvMapX(EEActiveBBox -> Xmax)) / 2, 0);
  957.         IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  958.         break;
  959.     case 9: /* Pan right */
  960.             IntrWndwUpdatePanning(EEActiveWindow -> IntrLibWindowID,
  961.                   (GRInvMapX(EEActiveBBox -> Xmax) -
  962.                                GRInvMapX(EEActiveBBox -> Xmin)) / 2, 0);
  963.         IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  964.         break;
  965.     case 10: /* Pan up */
  966.             IntrWndwUpdatePanning(EEActiveWindow -> IntrLibWindowID, 0,
  967.                   (GRInvMapX(EEActiveBBox -> Ymin) -
  968.                                GRInvMapX(EEActiveBBox -> Ymax)) / 2);
  969.  
  970.         IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  971.         break;
  972.     case 11: /* Pan down */
  973.             IntrWndwUpdatePanning(EEActiveWindow -> IntrLibWindowID, 0,
  974.                   (GRInvMapX(EEActiveBBox -> Ymax) -
  975.                                GRInvMapX(EEActiveBBox -> Ymin)) / 2);
  976.         IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  977.         break;
  978.  
  979.     }
  980. }
  981.  
  982. /*****************************************************************************
  983. * Routine to handle the DISPLAY pull down sub menu.                 *
  984. *****************************************************************************/
  985. static void HandleDisplayMenu(int Index)
  986. {
  987.     if (ActiveWindowID < 0) {
  988.     IntrQueryContinue("No active window to work on.",
  989.                   EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  990.                           EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  991.                           INTR_WNDW_PLACE_CENTER);
  992.         return;
  993.     }
  994.  
  995.     if (Index >= 0) {
  996.     if (IntrPopUpMenu(DisplayPUMenu, INTR_WNDW_PULL_DOWN))
  997.         Index = DisplayPUMenu -> SelectedIndex;
  998.         else
  999.             Index = -1;
  1000.     }
  1001.     else
  1002.     Index += DIRECT_CALL_INDEX_OFFSET;
  1003.  
  1004.     GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  1005.  
  1006.     switch(Index) {
  1007.     case 0:
  1008.         if (IntrWndwGetZoomFactor(ActiveWindowID) -
  1009.                 DEFAULT_ZOOM_FACTOR >= 4)
  1010.             IntrQueryContinue("Zoom value is out of range",
  1011.                       EEPopUpFrameColor, EEPopUpBackColor,
  1012.                                   EEPopUpForeColor, EEPopUpXorColor,
  1013.                                   EEWindowsFrameWidth, &Cursor,
  1014.                                   INTR_WNDW_PLACE_CENTER);
  1015.             else {
  1016.         IntrWndwUpdateZoom(ActiveWindowID, 1);
  1017.         IntrWndwPop(ActiveWindowID, TRUE, FALSE);
  1018.             }
  1019.         break;
  1020.         case 1:
  1021.         if (IntrWndwGetZoomFactor(ActiveWindowID) -
  1022.                 DEFAULT_ZOOM_FACTOR <= -4)
  1023.             IntrQueryContinue("Zoom value is out of range",
  1024.                       EEPopUpFrameColor, EEPopUpBackColor,
  1025.                                   EEPopUpForeColor, EEPopUpXorColor,
  1026.                   EEWindowsFrameWidth, &Cursor,
  1027.                                   INTR_WNDW_PLACE_CENTER);
  1028.             else {
  1029.         IntrWndwUpdateZoom(ActiveWindowID, -1);
  1030.         IntrWndwPop(ActiveWindowID, TRUE, FALSE);
  1031.             }
  1032.         break;
  1033.     case 2:
  1034.         IntrWndwSetZoom(ActiveWindowID, DEFAULT_ZOOM_FACTOR);
  1035.         IntrWndwPop(ActiveWindowID, TRUE, FALSE);
  1036.         break;
  1037.     case 3:
  1038.         IntrWndwRedrawAll();
  1039.         break;
  1040.     }
  1041. }
  1042.  
  1043. /*****************************************************************************
  1044. * Routine to handle the LIBS pull down sub menu.                 *
  1045. *****************************************************************************/
  1046. static void HandleLibsMenu(int Index)
  1047. {
  1048.     int NumOfFiles;
  1049.     char Line[LINE_LEN], Buffer[LINE_LEN], CrntPath[FULL_PATH_LEN];
  1050.     FileNameType *FileNames;
  1051.  
  1052.     if (Index >= 0) {
  1053.     if (IntrPopUpMenu(LibsPUMenu, INTR_WNDW_PULL_DOWN))
  1054.         Index = LibsPUMenu -> SelectedIndex;
  1055.     else
  1056.         Index = -1;
  1057.     }
  1058.     else
  1059.     Index += DIRECT_CALL_INDEX_OFFSET;
  1060.  
  1061.     GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  1062.  
  1063.     getcwd(CrntPath, FULL_PATH_LEN - 1);
  1064.     ChangeDir(LibrariesPath);
  1065.  
  1066.     switch(Index) {
  1067.     case 0:
  1068.         LoadLibrary();
  1069.         break;
  1070.     case 1:
  1071.         Line[0] = 0;
  1072.         IntrQueryLine("New library(ies) to load:", Line, LINE_LEN - 1,
  1073.               EEPopUpFrameColor,
  1074.               EEPopUpBackColor, EEPopUpForeColor,
  1075.               EEWindowsFrameWidth, INTR_WNDW_PLACE_CENTER);
  1076.         LoadLibraries(Line);
  1077.         break;
  1078.     case 2:
  1079.         FreeLibrary(NULL);
  1080.         break;
  1081.     case 3:
  1082.         ViewLibrary();
  1083.         break;
  1084.     case 4:
  1085.         if ((FileNames = GetFileNamesDir("*.lib", ".", &NumOfFiles))
  1086.                                 != NULL) {
  1087.         qsort(FileNames, NumOfFiles, sizeof(FileNameType),
  1088.               (int (*)(const void *, const void *)) strcmp);
  1089.         IntrQueryList("Directory", (char **) FileNames,
  1090.              sizeof(FileNameType), NumOfFiles, EEListNumDisplayed,
  1091.              EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  1092.              EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  1093.              INTR_WNDW_PLACE_CENTER);
  1094.         MyFree((VoidPtr) FileNames);
  1095.         }
  1096.         break;
  1097.     case 5:
  1098.         strcpy(Line, LibrariesPath);
  1099.         sprintf(Buffer, "New lib dir (%s):", LibrariesPath);
  1100.         IntrQueryLine(Buffer, Line, LINE_LEN - 1, EEPopUpFrameColor,
  1101.               EEPopUpBackColor, EEPopUpForeColor,
  1102.               EEWindowsFrameWidth, INTR_WNDW_PLACE_CENTER);
  1103.         if (ChangeDir(Line) != CD_OK) {
  1104.         GRTone(1400, 100);             /* Do some noise... */
  1105.         GRTone( 400, 100);
  1106.         }
  1107.         else
  1108.         strcpy(LibrariesPath, Line);
  1109.         break;
  1110.     }
  1111.  
  1112.     ChangeDir(CrntPath);
  1113. }
  1114.  
  1115. /*****************************************************************************
  1116. * Routine to handle the DRAW pull down sub menu.                 *
  1117. *****************************************************************************/
  1118. static void HandleDrawMenu(int Index)
  1119. {
  1120.     DrawGenericStruct
  1121.         *NewDrawStruct = NULL;
  1122.  
  1123.     if (ActiveWindowID < 0) {
  1124.     IntrQueryContinue("No active window to work on.",
  1125.                   EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  1126.                           EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  1127.                           INTR_WNDW_PLACE_CENTER);
  1128.         return;
  1129.     }
  1130.  
  1131.     if (Index >= 0) {
  1132.     if (IntrPopUpMenu(DrawPUMenu, INTR_WNDW_PULL_DOWN))
  1133.         Index = DrawPUMenu -> SelectedIndex;
  1134.     else
  1135.             Index = -1;
  1136.     }
  1137.     else
  1138.     Index += DIRECT_CALL_INDEX_OFFSET;
  1139.  
  1140.     GRSetViewPort(EEActiveBBox -> Xmin, EEActiveBBox -> Ymin,
  1141.               EEActiveBBox -> Xmax, EEActiveBBox -> Ymax);
  1142.     IntrPushCursorType();           /* Make sure cursor is IN active window. */
  1143.     PutCursorInActiveWindow();
  1144.  
  1145.     switch(Index) {
  1146.         case 0:
  1147.         NewDrawStruct = CreateNewPolylineStruct(GR_NORM_WIDTH);
  1148.         break;
  1149.     case 1:
  1150.         NewDrawStruct = CreateNewPolylineStruct(GR_THICK_WIDTH);
  1151.         break;
  1152.     case 2:
  1153.         NewDrawStruct = CreateNewConnectionStruct();
  1154.         break;
  1155.     case 3:
  1156.         NewDrawStruct = CreateNewTextStruct();
  1157.         break;
  1158.         case 4:
  1159.         NewDrawStruct = LibCreateNewPart();
  1160.     }
  1161.  
  1162.     if (NewDrawStruct != NULL) {
  1163.         NewDrawStruct -> Pnext = EEActiveWindow -> EEDrawList;
  1164.         EEActiveWindow -> EEDrawList = NewDrawStruct;
  1165.         if (!EEActiveWindow -> Modified) {
  1166.         EEActiveWindow -> Modified = TRUE;
  1167.         IntrWndwSetStatus(EEActiveWindow -> IntrLibWindowID, "M", "M",
  1168.                                     TRUE);
  1169.         }
  1170.     }
  1171.     IntrPopCursorType();
  1172. }
  1173.  
  1174. /*****************************************************************************
  1175. * Routine to handle the MODIFY pull down sub menu.                 *
  1176. *****************************************************************************/
  1177. static void HandleModifyMenu(int Index)
  1178. {
  1179.     BooleanType
  1180.     Modified = FALSE;
  1181.     DrawGenericStruct *DrawStruct;
  1182.  
  1183.     if (ActiveWindowID < 0) {
  1184.     IntrQueryContinue("No active window to work on.",
  1185.                   EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  1186.                           EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  1187.                           INTR_WNDW_PLACE_CENTER);
  1188.         return;
  1189.     }
  1190.  
  1191.     if (Index >= 0) {
  1192.     if (IntrPopUpMenu(ModifyPUMenu, INTR_WNDW_PULL_DOWN))
  1193.         Index = ModifyPUMenu -> SelectedIndex;
  1194.         else
  1195.             Index = -1;
  1196.     }
  1197.     else
  1198.     Index += DIRECT_CALL_INDEX_OFFSET;
  1199.  
  1200.     GRSetViewPort(EEActiveBBox -> Xmin, EEActiveBBox -> Ymin,
  1201.               EEActiveBBox -> Xmax, EEActiveBBox -> Ymax);
  1202.     IntrPushCursorType();           /* Make sure cursor is IN active window. */
  1203.     PutCursorInActiveWindow();
  1204.  
  1205.     switch(Index) {
  1206.         case 0: /* Move */
  1207.             Modified = (DrawStruct = PickStruct("Pick struct to move:", FALSE))
  1208.                                         != NULL &&
  1209.                 MoveStruct(DrawStruct);
  1210.             break;
  1211.         case 1: /* Copy */
  1212.         Modified = (DrawStruct = PickStruct("Pick struct to copy", FALSE))
  1213.                                         != NULL &&
  1214.             CopyStruct(DrawStruct);
  1215.             break;
  1216.         case 2: /* EditLibItem */
  1217.         Modified = EditLibraryItem();
  1218.         break;
  1219.     case 3: /* Delete */
  1220.         if ((DrawStruct = PickStruct("Pick struct to delete", FALSE))
  1221.                                         != NULL) {
  1222.         DeleteStruct(DrawStruct);
  1223.                 Modified = TRUE;
  1224.             }
  1225.             break;
  1226.         case 4: /* Undelete */
  1227.         Modified = UnDeleteStruct();
  1228.         break;
  1229.     case 5: /* Cut */
  1230.         if ((DrawStruct = PickStruct("Pick struct to cut", FALSE))
  1231.                                         != NULL) {
  1232.         CutStruct(DrawStruct);
  1233.             }
  1234.             break;
  1235.         case 6: /* Paste */
  1236.         Modified = PasteStruct();
  1237.             break;
  1238.         case 7: /* Drop */
  1239.         DropStruct();
  1240.             break;
  1241.     }
  1242.  
  1243.     if (Modified && !EEActiveWindow -> Modified) {
  1244.     EEActiveWindow -> Modified = TRUE;
  1245.     IntrWndwSetStatus(EEActiveWindow -> IntrLibWindowID, "M", "M", TRUE);
  1246.     }
  1247.     IntrPopCursorType();
  1248. }
  1249.  
  1250. /*****************************************************************************
  1251. * Routine to handle the STATUS pull down sub menu.                 *
  1252. *****************************************************************************/
  1253. static void HandleStatusMenu(int Index)
  1254. {
  1255.     int i, NumLines;
  1256.     char *FullFileName, Line[LINE_LEN];
  1257.     FILE *f;
  1258.  
  1259.     if (Index >= 0) {
  1260.     if (IntrPopUpMenu(StatusPUMenu, INTR_WNDW_PULL_DOWN))
  1261.         Index = StatusPUMenu -> SelectedIndex;
  1262.         else
  1263.             Index = -1;
  1264.     }
  1265.     else
  1266.     Index += DIRECT_CALL_INDEX_OFFSET;
  1267.  
  1268.     switch(Index) {
  1269.         case 0: /* Help */
  1270.         if (HelpWindowID >= 0) {
  1271.         IntrWndwDelete(HelpWindowID, TRUE);
  1272.         HelpWindowID = -1;
  1273.             }
  1274.             else {
  1275.         if (coreleft() < 30000L) {
  1276.                 IntrQueryContinue("Not enough memory to pop help",
  1277.                       EEPopUpFrameColor, EEPopUpBackColor,
  1278.                                   EEPopUpForeColor, EEPopUpXorColor,
  1279.                                   EEWindowsFrameWidth, &Cursor,
  1280.                                   INTR_WNDW_PLACE_CENTER);
  1281.                     break;
  1282.                 }
  1283.  
  1284.                 sprintf(Line, "%s.hlp", PROGRAM_NAME);
  1285.                 if ((FullFileName = searchpath(Line)) != NULL &&
  1286.             (f = fopen(FullFileName, "rt")) != NULL &&
  1287.                     fgets(Line, LINE_LEN - 2, f) != NULL &&
  1288.                     sscanf(Line, "%d", &NumLines) == 1) {
  1289.             IntrDrawMessage("Loading Help...", EEPopUpForeColor,
  1290.                                        EEPopUpBackColor);
  1291.  
  1292.                     /* Unlike drawing window no horizontal scroll bar. */
  1293.                     ResizeBBox.Ymax += IntrWndwScrollBarWidth();
  1294.                 HelpWindowID = IntrWndwCreate(
  1295.                         ShowWindowName ? "Help" : NULL, EEWindowsFrameWidth,
  1296.                         &ResizeBBox, EERootWndwFrameColor, EERootWndwBackColor,
  1297.                         NULL, NULL, HelpWndwRefreshFunc);
  1298.             ResizeBBox.Ymax -= IntrWndwScrollBarWidth();
  1299.  
  1300.             IntrTextInitWindow(HelpWindowID, FALSE, EERootWndwForeColor,
  1301.                    EERootWndwForeColor,
  1302.                     INTR_SCRLBAR_NONE, INTR_SCRLBAR_LEFT,
  1303.                                    NumLines, 80);
  1304.  
  1305.                 for (i = 0; i < NumLines; i++) {
  1306.                 fgets(Line, LINE_LEN - 2, f);
  1307.                 IntrPrintf(HelpWindowID, FALSE, Line);
  1308.                     }
  1309.  
  1310.                     fclose(f);
  1311.  
  1312.                     IntrEraseMessage();
  1313.  
  1314.             IntrWndwResize(HelpWindowID, FALSE);
  1315.                     IntrWndwPop(HelpWindowID, TRUE, FALSE);
  1316.                 }
  1317.                 else {
  1318.                 IntrQueryContinue("Can not open help file",
  1319.                       EEPopUpFrameColor, EEPopUpBackColor,
  1320.                                   EEPopUpForeColor, EEPopUpXorColor,
  1321.                                   EEWindowsFrameWidth, &Cursor,
  1322.                                   INTR_WNDW_PLACE_CENTER);
  1323.                 }
  1324.             }
  1325.         break;
  1326.         case 1: /* Free Mem. */
  1327.             PrintMemoryFree();
  1328.             break;
  1329.         case 2: /* Get zoom factor. */
  1330.             sprintf(Line, "Current Zoom factor is %2.5lf",
  1331.                     pow(2.0, (double) (IntrWndwGetZoomFactor(ActiveWindowID) -
  1332.                        DEFAULT_ZOOM_FACTOR)));
  1333.         IntrQueryContinue(Line, EEPopUpFrameColor, EEPopUpBackColor,
  1334.                               EEPopUpForeColor, EEPopUpXorColor,
  1335.                               EEWindowsFrameWidth, &Cursor,
  1336.                               INTR_WNDW_PLACE_CENTER);
  1337.             break;
  1338.         case 3: /* Draw Text */
  1339.             i = GRDrawText;
  1340.             GRDrawText = IntrQueryYesNo("Draw text?", EEPopUpFrameColor,
  1341.                         EEPopUpBackColor, EEPopUpForeColor,
  1342.                         EEPopUpXorColor, EEWindowsFrameWidth,
  1343.                                         &Cursor, INTR_WNDW_PLACE_CENTER);
  1344.             if (i != GRDrawText)
  1345.             RedrawAllWindows();
  1346.             break;
  1347.         case 4: /* Text Scale */
  1348.             sprintf(Line, "%d", EETextScale);
  1349.             IntrQueryLine("Text Scale size [1..7]:", Line,
  1350.               LINE_LEN_SHORT - 1, EEPopUpFrameColor,
  1351.                           EEPopUpBackColor, EEPopUpForeColor,
  1352.                           EEWindowsFrameWidth, INTR_WNDW_PLACE_CENTER);
  1353.             if (sscanf(Line, "%d", &i) != 1 || i < 1 || i > 7)
  1354.             IntrQueryContinue("Wrong format/range, ignored",
  1355.                       EEPopUpFrameColor, EEPopUpBackColor,
  1356.                                   EEPopUpForeColor, EEPopUpXorColor,
  1357.                                   EEWindowsFrameWidth, &Cursor,
  1358.                                   INTR_WNDW_PLACE_CENTER);
  1359.             else
  1360.             EETextScale = i;
  1361.         break;
  1362.         case 5: /* Set auto pan */
  1363.             EEAutoPan =
  1364.             IntrQueryYesNo("Enable automatic panning?",
  1365.                    EEPopUpFrameColor, EEPopUpBackColor,
  1366.                                    EEPopUpForeColor, EEPopUpXorColor,
  1367.                                    EEWindowsFrameWidth, &Cursor,
  1368.                                    INTR_WNDW_PLACE_CENTER);
  1369.             break;
  1370.         case 6: /* Vert. Horiz. Lines */
  1371.             EEHVLineDrawing =
  1372.             IntrQueryYesNo("Draw only vertical/horizontal lines?",
  1373.                    EEPopUpFrameColor, EEPopUpBackColor,
  1374.                                    EEPopUpForeColor, EEPopUpXorColor,
  1375.                                    EEWindowsFrameWidth, &Cursor,
  1376.                                    INTR_WNDW_PLACE_CENTER);
  1377.             break;
  1378.         case 7: /* Snap Factor */
  1379.             sprintf(Line, "%d", EESnapDistance);
  1380.             IntrQueryLine("New snap factor [0..1024]:", Line,
  1381.               LINE_LEN_SHORT - 1, EEPopUpFrameColor,
  1382.                           EEPopUpBackColor, EEPopUpForeColor,
  1383.                           EEWindowsFrameWidth, INTR_WNDW_PLACE_CENTER);
  1384.             if (sscanf(Line, "%d", &i) != 1 || i < 1 || i > 1024)
  1385.             IntrQueryContinue("Wrong format/range, ignored",
  1386.                               EEPopUpFrameColor, EEPopUpBackColor,
  1387.                                   EEPopUpForeColor, EEPopUpXorColor,
  1388.                                   EEWindowsFrameWidth, &Cursor,
  1389.                                   INTR_WNDW_PLACE_CENTER);
  1390.             else
  1391.             EESnapDistance = i;
  1392.             break;
  1393.     }
  1394. }
  1395.  
  1396. /*****************************************************************************
  1397. * Given a full path file name returns a pointer to the file name only.         *
  1398. *****************************************************************************/
  1399. static char *GetFileName(char *FullPathName)
  1400. {
  1401.     int i = strlen(FullPathName) - 1;
  1402.  
  1403.     while (i >= 0 && FullPathName[i] != '\\' &&
  1404.                  FullPathName[i] != '/' &&
  1405.              FullPathName[i] != ':') i--;
  1406.     return i > 0 ? &FullPathName[i + 1] : FullPathName;
  1407. }
  1408.  
  1409. /*****************************************************************************
  1410. * Routine to refresh root window drawing.                     *
  1411. *****************************************************************************/
  1412. static void RootWndwRefreshFunc(int WindowID)
  1413. {
  1414.     IntrBBoxStruct *BBox = IntrWndwGetBBox(WindowID);
  1415.     int x = (BBox -> Xmax - BBox -> Xmin) / 2,
  1416.         y = (BBox -> Ymax - BBox -> Ymin) / 3;
  1417.  
  1418.     GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER);
  1419.  
  1420.     GRSetSTextStyle(GRFontName, GR_HORIZ_DIR, 8);
  1421.  
  1422.     IntrAllocColor(EERootWndwForeColor, INTR_INTENSITY_HIGH);
  1423.     GRSText(x + 8, y + 8, "EEDRAW");
  1424.     IntrAllocColor(EERootWndwForeColor, INTR_INTENSITY_VHIGH);
  1425.     GRSText(x, y, "EEDRAW");
  1426.  
  1427.     GRSetSTextStyle(GRFontName, GR_HORIZ_DIR, 2);
  1428.  
  1429.     y = y * 2;
  1430.     IntrAllocColor(EERootWndwForeColor, INTR_INTENSITY_HIGH);
  1431.     GRSText(x + 2, y + 2, "(c) Copyright 1989-91 Gershon Elber");
  1432.     IntrAllocColor(EERootWndwForeColor, INTR_INTENSITY_VHIGH);
  1433.     GRSText(x, y, "(c) Copyright 1989-91 Gershon Elber");
  1434.  
  1435.     IntrWndwSetRefreshFunc(WindowID, NULL);    /* Disable further refreshes. */
  1436. }
  1437.  
  1438. /*****************************************************************************
  1439. * Routine to refresh help window drawing.                     *
  1440. *****************************************************************************/
  1441. static void HelpWndwRefreshFunc(int WindowID)
  1442. {
  1443.     IntrTextWndwRefresh(WindowID);
  1444. }
  1445.  
  1446. /*****************************************************************************
  1447. * Routine to refresh root window drawing.                     *
  1448. *****************************************************************************/
  1449. static void DataWndwRefreshFunc(int WindowID)
  1450. {
  1451.     int i, x, y;
  1452.     IntrBType IsVertical;
  1453.     IntrRType Zoom, Value, XFrac, YFrac;
  1454.     EEWindowStruct
  1455.         *Window = NULL;
  1456.     IntrBBoxStruct *BBox;
  1457.  
  1458.     /* First do the most likely thing... */
  1459.     if (WindowID == EEActiveWindow -> IntrLibWindowID)
  1460.     Window = EEActiveWindow;
  1461.     else {
  1462.     for (Window = EEWindowsList; Window != NULL; Window = Window -> Pnext)
  1463.         if (WindowID == Window -> IntrLibWindowID)
  1464.                 break;
  1465.     }
  1466.  
  1467.     if (Window == NULL) IntrFatalError("Wrong Window ID.");
  1468.  
  1469.     /* Update the scroll bars. */
  1470.     i = IntrWndwGetZoomFactor(Window -> IntrLibWindowID) - DEFAULT_ZOOM_FACTOR;
  1471.     if (i > 0)
  1472.     Zoom = 1 << i;
  1473.     else if (i < 0)
  1474.     Zoom = 1.0 / (1 << (-i));
  1475.     else
  1476.     Zoom = 1.0;
  1477.     BBox = IntrWndwGetBBox(Window -> IntrLibWindowID);
  1478.     XFrac = (BBox -> Xmax - BBox -> Xmin) /
  1479.             (Window -> PageXSize * Zoom + (BOUNDARY_WIDTH << 1));
  1480.     YFrac = (BBox -> Ymax - BBox -> Ymin) /
  1481.                (Window -> PageYSize * Zoom + (BOUNDARY_WIDTH << 1));
  1482.  
  1483.     if (IntrWndwIsScrollBarEvent(Window -> IntrLibWindowID, &IsVertical,
  1484.                                         &Value)) {
  1485.     /* This refresh is a result of a scroll bar event on the window. */
  1486.     IntrWndwGetPanFactors(Window -> IntrLibWindowID, &x, &y);
  1487.         if (IsVertical) {
  1488.         if (YFrac > 1.0)
  1489.         y = DEFAULT_INV_ZOOM(Window -> PageYSize) / 2;
  1490.             else {
  1491.         Value = Value + YFrac / 2.0;
  1492.         if (Value > 1.0 - YFrac / 2.0) Value = 1.0 - YFrac / 2.0;
  1493.         y = Value * DEFAULT_INV_ZOOM(Window -> PageYSize);
  1494.             }
  1495.         }
  1496.         else {
  1497.         if (XFrac > 1.0)
  1498.         x = DEFAULT_INV_ZOOM(Window -> PageXSize) / 2;
  1499.             else {
  1500.         Value = Value + XFrac / 2.0;
  1501.         if (Value > 1.0 - XFrac / 2.0) Value = 1.0 - XFrac / 2.0;
  1502.         x = Value * DEFAULT_INV_ZOOM(Window -> PageXSize);
  1503.         }
  1504.         }
  1505.     IntrWndwSetPanning(Window -> IntrLibWindowID, x, y);
  1506.         GRSetPanFactors(x, y);
  1507.     }
  1508.  
  1509.     IntrWndwGetPanFactors(Window -> IntrLibWindowID, &x, &y);
  1510.     if (XFrac >= 1.0)
  1511.     IntrWndwUpdateScrollBar(Window -> IntrLibWindowID, FALSE, 0.0, 1.0);
  1512.     else
  1513.         IntrWndwUpdateScrollBar(Window -> IntrLibWindowID, FALSE,
  1514.         x / ((IntrRType) DEFAULT_INV_ZOOM(Window -> PageXSize)) -
  1515.                 XFrac / 2.0,
  1516.         XFrac);
  1517.     if (YFrac >= 1.0)
  1518.     IntrWndwUpdateScrollBar(Window -> IntrLibWindowID, TRUE, 0.0, 1.0);
  1519.     else
  1520.     IntrWndwUpdateScrollBar(Window -> IntrLibWindowID, TRUE,
  1521.         y / ((IntrRType) DEFAULT_INV_ZOOM(Window -> PageYSize)) -
  1522.                 YFrac / 2.0,
  1523.         YFrac);
  1524.  
  1525.     /* Redraw the window content. */
  1526.     RedrawStructList(Window -> EEDrawList, GR_COPY_PUT, EE_DRAW_COLOR);
  1527.  
  1528.     /* Draw the window page border. */
  1529.     GRSetWriteMode(GR_COPY_PUT);
  1530.     IntrAllocColor(EEHighLightColor, INTR_INTENSITY_VHIGH);
  1531.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_THICK_WIDTH);
  1532.     GRMoveTo(0, 0);
  1533.     GRLineTo(0, DEFAULT_INV_ZOOM(Window -> PageYSize));
  1534.     GRLineTo(DEFAULT_INV_ZOOM(Window -> PageXSize),
  1535.                            DEFAULT_INV_ZOOM(Window -> PageYSize));
  1536.     GRLineTo(DEFAULT_INV_ZOOM(Window -> PageXSize), 0);
  1537.     GRLineTo(0, 0);
  1538.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_NORM_WIDTH);
  1539. }
  1540.  
  1541. /*****************************************************************************
  1542. * Routine to handle key bindings.                         *
  1543. *****************************************************************************/
  1544. static void HandleSameAgain(int KeyStroke)
  1545. {
  1546.     HandleKeyBindings(LastKeyStroke);
  1547. }
  1548.  
  1549. /*****************************************************************************
  1550. * Routine to handle key bindings.                         *
  1551. *****************************************************************************/
  1552. static void HandleKeyBindings(int KeyStroke)
  1553. {
  1554.     int i;
  1555.  
  1556.     LastKeyStroke = KeyStroke;
  1557.  
  1558.     for (i = 0; i < KeyBindingCount; i++)
  1559.     if (KeyBindingList[i].ScanCode == KeyStroke) {
  1560.         /* Activate the related function. */
  1561.         PDActionFuncs[KeyBindingList[i].Menu](KeyBindingList[i].MenuEntry -
  1562.                              DIRECT_CALL_INDEX_OFFSET);
  1563.         break;
  1564.         }
  1565. }
  1566.  
  1567. /*****************************************************************************
  1568. * Routine to read the key binding file if such exists.                 *
  1569. *****************************************************************************/
  1570. static BooleanType ReadKeyBindings(char *Name)
  1571. {
  1572.     int i, j, Len, ScanCode,
  1573.     LineNum = 0;
  1574.     IntrBType FuncFound;
  1575.     FILE *f;
  1576.     char Buffer[LINE_LEN_SHORT], *FunctionName,    *KeyName, *ScanCodeStr, *p;
  1577.  
  1578.     strcpy(Buffer, Name);            /* Remove old type if has one... */
  1579.     if ((p = strrchr(Buffer, '.')) != NULL) *p = 0;
  1580.     strcat(Buffer, ".BND");           /* ... and add the binding file type. */
  1581.  
  1582.     /* Search in path, and if fails, return silently: */
  1583.     p = searchpath(Buffer);
  1584.     if (p == NULL || (f = fopen(p, "rt")) == NULL) return TRUE;
  1585.  
  1586.     while (fgets(Buffer, LINE_LEN_SHORT - 1, f)) {
  1587.     LineNum++;
  1588.     if (Buffer[0] == ';' || Buffer[0] == '\n' || Buffer[0] == '\r')
  1589.         continue;
  1590.  
  1591.     if ((FunctionName = strtok(Buffer, " \t\n\r")) == NULL ||
  1592.         (KeyName = strtok(NULL, " \t\n\r")) == NULL ||
  1593.         (ScanCodeStr = strtok(NULL, " \t\n\r")) == NULL ||
  1594.         sscanf(ScanCodeStr, "%d", &ScanCode) != 1) {
  1595.         fprintf(stderr, "Wrong format, binding file \"%s\", line %d.\n",
  1596.                                 p, LineNum);
  1597.         fclose(f);
  1598.         return FALSE;
  1599.     }
  1600.  
  1601.     Len = strlen(FunctionName);
  1602.     FuncFound = FALSE;
  1603.         if (strncmp("SameAgain", FunctionName, Len) == 0) {
  1604.         IntrRegisterKeyStroke(ScanCode, HandleSameAgain);
  1605.             FuncFound = TRUE;
  1606.         }
  1607.     else
  1608.         for (i = 0; !FuncFound && i < ALL_POP_UP_SIZE; i++)
  1609.             for (j = 0; !FuncFound && j < AllPUSizes[i]; j++)
  1610.             if (strncmp(AllPUStrs[i][j], FunctionName, Len) == 0 &&
  1611.                 KeyBindingCount < MAX_KEY_BINDINGS) {
  1612.                 KeyBindingList[KeyBindingCount].ScanCode = ScanCode;
  1613.                         KeyBindingList[KeyBindingCount].Menu = i;
  1614.                         KeyBindingList[KeyBindingCount++].MenuEntry = j;
  1615.                 IntrRegisterKeyStroke(ScanCode, HandleKeyBindings);
  1616.                 if (strlen(KeyName) > 4) KeyName[4] = 0;
  1617.                     Len = strlen(AllPUStrs[i][j]) - strlen(KeyName) - 2;
  1618.                 sprintf(&AllPUStrs[i][j][Len], "[%s]", KeyName);
  1619.                         FuncFound = TRUE;
  1620.             }
  1621.     if (!FuncFound) {
  1622.         fprintf(stderr,
  1623.         "No such function as \"%s\", binding file \"%s\", line %d.\n",
  1624.                         FunctionName, p, LineNum);
  1625.         fclose(f);
  1626.         return FALSE;
  1627.     }
  1628.     }
  1629.  
  1630.     fclose(f);
  1631.  
  1632.     return TRUE;
  1633. }
  1634.  
  1635. /*****************************************************************************
  1636. * My Routine to    allocate dynamic memory. All program requests must call this *
  1637. * routine (no direct call to malloc). Dies if no memory.             *
  1638. *****************************************************************************/
  1639. VoidPtr MyMalloc(unsigned size)
  1640. {
  1641.     static int Unlocked = TRUE;
  1642.     static time_t LastTime = 0;
  1643.     char *p;
  1644.     time_t CrntTime;
  1645.  
  1646.  
  1647. #ifdef DEBUG_MALLOC_TC20
  1648.     unsigned int *i;
  1649.  
  1650.     size += 6;
  1651. #endif /* DEBUG_MALLOC_TC20 */
  1652.  
  1653.     p = malloc(size);
  1654.     if (p == NULL)
  1655.     FatalError("Not enough memory, exit\n");
  1656.     if (Unlocked && coreleft() < 32768L) {
  1657.     /* Unlocked is used to make sure we would not recurse from the below */
  1658.     /* Routines when it calls MyMalloc - this may cause infinite loop... */
  1659.     Unlocked = FALSE;
  1660.  
  1661.     time(&CrntTime);
  1662.     if (CrntTime - LastTime > 30) {    /* Let user know every 30 second. */
  1663.         IntrQueryContinue("Free memory too small - dangerous to continue",
  1664.                               EEPopUpFrameColor, EEPopUpBackColor,
  1665.                               EEPopUpForeColor, EEPopUpXorColor,
  1666.                               EEWindowsFrameWidth, &Cursor,
  1667.                               INTR_WNDW_PLACE_CENTER);
  1668.         LastTime = CrntTime;
  1669.     }
  1670.     Unlocked = TRUE;
  1671.     }
  1672.  
  1673. #ifdef DEBUG_MALLOC_TC20
  1674.     /* Do the following tests on the memory allocated:                 */
  1675.     /* 1. Uses TC 2.0 heuristic to make sure pointer are legal by comparing  */
  1676.     /*    their offset to the constant 8.                     */
  1677.     /* 2. Mark the end of allocated memory for over written test in MyFree.  */
  1678.     if (FP_OFF(p) != 8) {
  1679.     GetContinueQuestion(
  1680.         "Bogus pointer detected - unsafe to continue. Report it as 1.",
  1681.         CENTER_CENTER);
  1682.     }
  1683.     strcpy(&p[size-4], "ILG");             /* Put a marker at the end. */
  1684.     i = (unsigned int *) p;    /* Save size of this block at the begging and */
  1685.     *i = size;                  /* return a pointer just after it. */
  1686.     p += 2;
  1687. #endif /* DEBUG_MALLOC_TC20 */
  1688.  
  1689.     return p;
  1690. }
  1691.  
  1692. /*****************************************************************************
  1693. * My Routine to    free dynamic memory. All program requests must call this     *
  1694. * routine (no direct call free).                         *
  1695. *****************************************************************************/
  1696. void MyFree(VoidPtr p)
  1697. {
  1698. #ifdef DEBUG_MALLOC_TC20
  1699.     char *pc = (char *) p;
  1700.     unsigned int *i, size;
  1701.  
  1702.     /* Do the following tests on the memory allocated.                 */
  1703.     /* 1. Uses TC 2.0 heuristic to make sure pointer are legal by comparing  */
  1704.     /*    their offset to constant 8 (+2 as we skip the size we entered).    */
  1705.     /* 2. Test the mark at the end of the allocated memory for over written. */
  1706.     if (FP_OFF(p) != 8 + 2) {
  1707.     GetContinueQuestion(
  1708.         "Bogus pointer detected - unsafe to continue. Report it as 2.",
  1709.         CENTER_CENTER);
  1710.     return;
  1711.     }
  1712.     pc -= 2;
  1713.     i = (unsigned int *) pc;
  1714.     size = *i;
  1715.     if (strcmp(&pc[size-4], "ILG") != 0) {
  1716.     GetContinueQuestion(
  1717.         "Overwritten pointer detected - unsafe to continue. Report it as 3.",
  1718.         CENTER_CENTER);
  1719.     return;
  1720.     }
  1721.     p = pc;
  1722. #endif /* DEBUG_MALLOC_TC20 */
  1723.  
  1724. #ifdef DEBUG_MALLOC_TCPP
  1725.     int i = heapchecknode(p);
  1726.  
  1727.     switch(heapchecknode(p)) {
  1728.     case _HEAPEMPTY:
  1729.     case _HEAPCORRUPT:
  1730.     case _BADNODE:
  1731.     case _FREEENTRY:
  1732.     GetContinueQuestion(
  1733.         "Bogus pointer detected - unsafe to continue. Report it as 4.",
  1734.         CENTER_CENTER);
  1735.         return;
  1736.     }
  1737. #endif /* DEBUG_MALLOC_TCPP */
  1738.  
  1739.     free(p);
  1740. }
  1741.  
  1742. #ifdef DEBUG_MALLOC_TC20
  1743.  
  1744. /*****************************************************************************
  1745. * Define local strdup as we offset the pointers by 2 to save the size and    *
  1746. * calling to MyFree with pointers allocated via strdup will result with a    *
  1747. * fatal error...                                 *
  1748. *****************************************************************************/
  1749. char *strdup(const char *Str)
  1750. {
  1751.     char *NewStr = (char *) MyMalloc(strlen(Str) + 1);
  1752.  
  1753.     strcpy(NewStr, Str);
  1754.  
  1755.     return NewStr;
  1756. }
  1757.  
  1758. #endif /* DEBUG_MALLOC_TC20 */
  1759.  
  1760. /*****************************************************************************
  1761. * MyExit routine. Note it might call to CloseGraph without calling         *
  1762. * InitGraph(), or call MouseClose() without MouseInit() etc. and it is the   *
  1763. * responsibility of the individual modules to do nothing in these cases.     *
  1764. *****************************************************************************/
  1765. void MyExit(int ExitCode)
  1766. {
  1767.     IntrClose();               /* Close the interaction library. */
  1768.  
  1769.     RestoreCtrlBrk();
  1770.  
  1771.     ChangeDir(InitialPath);
  1772.  
  1773.     exit(ExitCode);
  1774. }
  1775.  
  1776. /*****************************************************************************
  1777. * Same as MyExit routine, but print error message to stderr.             *
  1778. *****************************************************************************/
  1779. void FatalError(char *ErrMsg)
  1780. {
  1781.     IntrClose();               /* Close the interaction library. */
  1782.  
  1783.     fprintf(stderr, "EEDRAW: %s\n", ErrMsg);
  1784.  
  1785.     RestoreCtrlBrk();
  1786.  
  1787.     ChangeDir(InitialPath);
  1788.  
  1789.     exit('F');
  1790. }
  1791.