home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 May / cica_0595_4.zip / cica_0595_4 / UTIL / MSWSRC35 / MAIN.CPP < prev    next >
C/C++ Source or Header  |  1993-10-12  |  39KB  |  1,463 lines

  1. #include "allwind.h"
  2.  
  3. CUTMAP *CutBmp;           /* Pointer to Bit Cut memory array malloc on init */
  4. int CutIndex = 0;       /* Pointer into CutBmp initially "ClipBoard" */
  5.  
  6. HANDLE HashHandle=0;       /* Handle to Hashtable */
  7. HANDLE StackHandle=0;      /* Handle to Gargebage Collector Stack */
  8.  
  9. HBITMAP MemoryBitMap;      /* Backing store bitmap */
  10. HBITMAP AreaMemoryBitMap;  /* Used to store active area of backing store */
  11.  
  12. HICON hCursor;             /* handle for saved cursor */
  13. HICON hCursorWait;         /* handle for hour glass cursor */
  14.  
  15. HPALETTE ThePalette;       /* Handle for the single color palette */
  16.  
  17. LPLOGPALETTE MyLogPalette; /* Handle for the single logical color palette */
  18.  
  19. NUMBER the_zoom = 1.0;     /* current zoom factor */
  20. NUMBER ibmoldx;            /* global store for x "From" routine */
  21. NUMBER ibmoldy;            /* global store for y "From" routine */
  22.  
  23. NODE *current_line = NIL;  /* current line to be parsed */
  24.  
  25. char LibPathName[EXE_NAME_MAX_SIZE+1];       /* path to library */
  26. char TempPathName[EXE_NAME_MAX_SIZE+1];      /* path to temp file */
  27. char szHelpFileName[EXE_NAME_MAX_SIZE+1];    /* path to help file */
  28. char MCIHelpFileName[EXE_NAME_MAX_SIZE+1];   /* path to MCI help file */
  29. char SelectedText[MAX_BUFFER_SIZE];          /* buffer for selected text */ 
  30. char YABuffer[MAX_BUFFER_SIZE];              /* Yet Another buffer */
  31. char commandarg[MAX_BUFFER_SIZE];            /* Routine to exec on start */
  32.  
  33. // holds callback code
  34.  
  35. char edit_editexit[MAX_BUFFER_SIZE];         /* callable editor cb */
  36. char mci_callback[MAX_BUFFER_SIZE];          /* MCI callback code */
  37. char *timer_callback[MAX_TIMERS];            /* timer cb malloc'd as needed */
  38. char *mouse_lbuttondown = NULL;              /* Mouse Left button down cb */
  39. char *mouse_lbuttonup = NULL;                /* Mouse Right button up cb */
  40. char *mouse_rbuttondown = NULL;              /* Mouse Left button down cb */
  41. char *mouse_rbuttonup = NULL;                /* Mouse Right button up cb */
  42. char *mouse_mousemove = NULL;                /* Mouse Move cb */
  43. char *keyboard_keydown = NULL;               /* KeyBoard key down */
  44. char *keyboard_keyup = NULL;                 /* KeyBoard key up */
  45.  
  46. HINSTANCE ModulehInstance;                   /* About box instance handle */
  47.  
  48. HWND MainHWindow;                            /* Handle to Main(screen) window */
  49. HWND CmdHWindow;                             /* Handle to commander window */
  50. HWND StatusHWindow;                 /* Handle to status window */
  51. HWND EdtHWindow;                             /* Handle to editor window */
  52.  
  53. /* Handles to each child windows of of the command window */
  54.  
  55. HWND ListHWindow;                         
  56. HWND EditHWindow;                        
  57. HWND ExecuteHWindow;
  58. HWND HaltHWindow;
  59. HWND TraceHWindow;
  60. HWND PauseHWindow;
  61. HWND StatHWindow;
  62. HWND YieldHWindow;
  63. HWND ResetHWindow;
  64.  
  65. /* place holders for windows resources */
  66.  
  67. HBITMAP OldBitmap;
  68. HBITMAP OldBitmap2;
  69.  
  70. HPALETTE OldPalette;
  71. HPALETTE OldPalette2;
  72.  
  73. HPEN OldPen;
  74.  
  75. HBRUSH OldBrush;
  76.  
  77. HFONT OldFont;
  78.  
  79. LOGFONT FontRec;
  80.  
  81. LOGPEN NormalPen;                 /* Handle to "Normal" logical Pen */
  82. LOGPEN ErasePen;                  /* Handle to "Erase" logical Pen */
  83.  
  84. LOGBRUSH FloodBrush;              /* Handle to the "floodfill" brush */
  85. LOGBRUSH ScreenBrush;             /* Handle to the "screen" background brush */
  86.  
  87. RECT FullRect;                    /* Ready rectangle of Full bitmap */
  88. RECT TempRect;                    /* Temp rectangle */
  89.  
  90. PTWindowsObject MainWindowx;      /* Pointer to the Main window */
  91.  
  92. /* Active area dimensions (real and temp) */
  93.  
  94. int PrinterAreaXLow;
  95. int PrinterAreaXHigh;
  96. int PrinterAreaYLow;
  97. int PrinterAreaYHigh;
  98. int TPrinterAreaXLow;
  99. int TPrinterAreaXHigh;
  100. int TPrinterAreaYLow;
  101. int TPrinterAreaYHigh;
  102.  
  103. int GCMAX = 8192;           /* Garbage Collector STack Size (Logo.ini) */
  104. int MAX_PHYS_LINE = 8192;   /* Maximum Physical Line Size (Logo.ini) */
  105. int dpenr;                  /* Current draw pen color red */
  106. int dpeng;                  /* Current draw pen color green */
  107. int dpenb;                  /* Current draw pen color blue */
  108. int dfldr;                  /* Current flood pen color red */
  109. int dfldg;                  /* Current flood pen color green */
  110. int dfldb;                  /* Current flood pen color blue */
  111. int dscnr;                  /* Current screen pen color red */
  112. int dscng;                  /* Current screen pen color green */
  113. int dscnb;                  /* Current screen pen color blue */
  114. int IsDirty = 0;            /* Flag to signal to query user ok to quit */
  115. int NumFonts;               /* Number of system fonts available */
  116. int BitMapWidth  = 1000;    /* Current bitmap size in X */
  117. int BitMapHeight = 1000;    /* Current bitmap size in Y */
  118. int EnablePalette;          /* Flag to signal 256 color mode with palette */
  119. int CustomFlag = 0;         /* Flag to signal Active area is active */
  120. int TCustomFlag = 0;        /* Dynamic copy of CustomFlag */
  121. int Command_OK = 0;         /* Flag to signal it's OK to write to recall box */
  122. int halt_flag = 0;          /* Flag to signal it's OK to halt */
  123. int traceflag = 0;          /* Flag to signal trace button is active */
  124. int pause_flag = 0;         /* Flag to signal pause button is pushed */
  125. int yield_flag = 1;         /* Flag to signal yield state */
  126. int status_flag = 0;        /* Flag to signal status box is poped up */
  127. int MaxWidth = 0;           /* Actual Main window size x */
  128. int MaxHeight = 0;          /* Actual Main window size y */
  129. int xoffset = 0;            /* Used to go from logo to windows coords x */
  130. int yoffset = 0;            /* Used to go from logo to windows coords y */
  131. int JustDidEdit = 0;        /* Flag to signal last command was edit (like) */
  132. int MaxX;                   /* Yet another window size x */
  133. int MaxY;            /* Yet another window size y */
  134. int Time_To_Exit = 0;        /* Flag to signal it's time to exit */
  135. int Time_To_Pause = 0;      /* UCBLOGO? pause flag */
  136. int Time_To_Halt = 0;       /* UCBLOGO? halt flag */
  137. int error_happen;        /* FLag to signal Error happened on edit reload */
  138. int keyboard_on = 0;        /* Flag to signal Keyboard is enabled */
  139. int keyboard_value = 0;     /* Value of Keyboard key */
  140. int mouse_on = 0;           /* Flag to signal Mouse is enabled */
  141. int mouse_posx = 0;         /* Value of Mouse position x */
  142. int mouse_posy = 0;         /* Value of Mouse position y */
  143. int memory_count = 0;       /* Current amount of logo segments malloc'd */
  144. int BaseUnitsx = 0;        /* X Units Windows uses to for units in dialog */
  145. int BaseUnitsy = 0;         /* Y Units Windows uses to for units in dialog */
  146.  
  147. long eval_count = 0;        /* current count of "evaluations" calls */
  148. long scolor = 1;            /* screen color */
  149. long fcolor = 1;            /* flood color */
  150. long pcolor = 1;        /* pen color */
  151. long width = 1;            /* pen width */
  152. long zoom_flag = 0;         /* flag to signal in zoomed state */
  153. long MaxColors = 0;        /* The maximum # of colors available */
  154. long first_init = 0;        /* hack flag to signal one time initialization */
  155.  
  156. LINEX TurtlePoints[3];      /* used to store 3 vertices of turtle */
  157.  
  158. /* File editor members */
  159.  
  160. TMyFileEditWindow::TMyFileEditWindow(PTWindowsObject AParent, LPSTR ATitle)
  161. : TDialog(AParent, ATitle)
  162.    {
  163.    }
  164.  
  165. TMyFileEditWindow::~TMyFileEditWindow()
  166.    {
  167.    }
  168.  
  169. void TMyFileEditWindow::DoAll(RTMessage Msg)
  170.    { 
  171.    
  172.    FileEditAll = 1;
  173.    CloseWindow(TRUE);
  174.    
  175.    }
  176.  
  177. void TMyFileEditWindow::DoCombo(RTMessage Msg)
  178.    { 
  179.    
  180.    if ( Msg.LP.Hi == CBN_DBLCLK )
  181.       {
  182.       CloseWindow(TRUE);
  183.       }
  184.    }
  185.  
  186. BOOL TMyFileEditWindow::CanClose()
  187.    {
  188.    SendDlgItemMsg(ID_FILEEDITCOMBO, WM_GETTEXT, MAX_BUFFER_SIZE, (LONG)SelectedText);
  189.    
  190.    return TRUE;
  191.    }
  192.  
  193. void TMyFileEditWindow::WMInitDialog(RTMessage Msg)
  194.    { 
  195.    NODE *proclst;
  196.    char tempbuff[MAX_BUFFER_SIZE];
  197.    
  198.    // get procedures
  199.    
  200.    proclst = lprocedures();
  201.    
  202.    // pop them into the list box
  203.    
  204.    while (proclst != NIL)
  205.       {
  206.       cnv_strnode_string(tempbuff, proclst);
  207.       SendDlgItemMsg(ID_FILEEDITCOMBO, CB_ADDSTRING, 0, (LONG)tempbuff);
  208.       proclst = cdr(proclst);
  209.       }
  210.    }
  211.  
  212. void putfileeditcombo(char *str) /*routine*/
  213.    {
  214.    
  215.    ((TMyFileEditWindow *)((TMyWindow *)MainWindowx)->
  216.    FileEditWindow)->SendDlgItemMsg(ID_FILEEDITCOMBO, CB_ADDSTRING, 0, (LONG)str);
  217.    
  218.    }
  219.  
  220. void cnv_strnode_string(char *textbuf,NODE *arg) /*routine*/
  221.    {
  222.    print_stringptr = textbuf;
  223.    print_stringlen = MAX_BUFFER_SIZE;
  224.    ndprintf((FILE *)NULL,"%p",car(arg));
  225.    *print_stringptr = '\0';
  226.    }
  227.  
  228. long LoadColor(int dpenr, int dpeng, int dpenb) /*routine*/
  229.    {
  230.    
  231.    /* adds color to palette */
  232.    
  233.    int Index;
  234.    long color;
  235.    
  236.    /* convert to color and find nearest match */
  237.    
  238.    color = PALETTERGB(dpenr,dpeng,dpenb);
  239.    
  240.    Index = GetNearestPaletteIndex(ThePalette,color);
  241.    
  242.    /* if not exact and room for more then allocate it */
  243.    
  244.    if ((PALETTERGB(
  245.    MyLogPalette->palPalEntry[Index].peRed,
  246.    MyLogPalette->palPalEntry[Index].peGreen,
  247.    MyLogPalette->palPalEntry[Index].peBlue) != color) && (MyLogPalette->palNumEntries < (MaxColors-1)))
  248.       {
  249.       
  250.       /* Why do check again? */
  251.       
  252.       if (MyLogPalette->palNumEntries < 255)
  253.          {
  254.          
  255.          /* kill old palette */
  256.          
  257.          DeleteObject(ThePalette);
  258.          
  259.          MyLogPalette->palPalEntry[MyLogPalette->palNumEntries].peRed = dpenr;
  260.          MyLogPalette->palPalEntry[MyLogPalette->palNumEntries].peGreen = dpeng;
  261.          MyLogPalette->palPalEntry[MyLogPalette->palNumEntries].peBlue = dpenb;
  262.          MyLogPalette->palPalEntry[MyLogPalette->palNumEntries].peFlags = 0;
  263.          MyLogPalette->palNumEntries++;
  264.          
  265.          /* if status window then update palette usage */
  266.          
  267.          if (status_flag) update_status_paletteuse();
  268.          
  269.          /* make new palette with added color */
  270.          
  271.          ThePalette = CreatePalette(MyLogPalette);
  272.          }
  273.       }
  274.    
  275.    /* return color new, matched or close */
  276.    
  277.    return(color);
  278.    }   
  279.  
  280. /* __ahIncr, ordinal 114, is a 'magic' function. Defining this
  281. function causes Windows to patch the value into the passed
  282. reference.  This makes it a type of global variable. To use
  283. the value of AHIncr, use FP_OFF(AHIncr). */
  284.  
  285.    extern "C" {
  286.    void FAR PASCAL  __ahIncr();
  287.    }
  288.  
  289. /* this routine is here to allow a non object call */
  290.  
  291. int TMyWindow_MyPopupEdit(char *FileName, NODE *args) /*routine*/
  292.    {
  293.    FILE *edfd;
  294.    
  295.    /* If no file (or empty) create template */
  296.    
  297.    if ((edfd = fopen(FileName,"r")) == NULL)
  298.       {
  299.       if ((edfd = fopen(FileName,"w")) != NULL)
  300.          {
  301.          if (args != NULL)
  302.             {
  303.             fwrite("to\n",1,3,edfd);
  304.             fwrite("end\n",1,4,edfd);
  305.             }
  306.          else
  307.             {
  308.             fwrite("\n",1,1,edfd);
  309.             }
  310.          fclose(edfd);
  311.          }
  312.       }
  313.    else
  314.       {
  315.       if (getc(edfd) == EOF)
  316.          {
  317.          fclose(edfd);
  318.          edfd = fopen(FileName,"w");
  319.          if (args != NULL)
  320.             {
  321.             fwrite("to\n",1,3,edfd);
  322.             fwrite("end\n",1,4,edfd);
  323.             }
  324.          else
  325.             {
  326.             fwrite("\n",1,1,edfd);
  327.             }
  328.          }
  329.       fclose(edfd);
  330.       }
  331.    
  332.    ((TMyWindow *)MainWindowx)->MyPopupEdit(FileName,args);
  333.    return(0);
  334.    }
  335.  
  336. void clearcombobox() /*routine*/
  337.    {
  338.    
  339.    /* clear the recall box */
  340.    
  341.    ((TMyCommandWindow *)((TMyWindow *)MainWindowx)->
  342.    CommandWindow)->SendDlgItemMsg(ID_LISTBOX, LB_RESETCONTENT, 0, 0);
  343.    }
  344.  
  345. void putcombobox(char *str) /*routine*/
  346.    {
  347.    DWORD Idx;
  348.    DWORD Err;
  349.    
  350.    /* only if OK to write to recall box do we do it */
  351.    
  352.    if (Command_OK)
  353.       {
  354.       
  355.       /* output to list box */
  356.       
  357.       Err = ((TMyCommandWindow *)((TMyWindow *)MainWindowx)->
  358.       CommandWindow)->SendDlgItemMsg(ID_LISTBOX, LB_ADDSTRING, 0, (LONG)str);
  359.       
  360.       /* while out of space delete of top and try again */
  361.       
  362.       while (Err == LB_ERRSPACE)
  363.          {
  364.          ((TMyCommandWindow *)((TMyWindow *)MainWindowx)->
  365.          CommandWindow)->SendDlgItemMsg(ID_LISTBOX, LB_DELETESTRING, (WORD)0, 0);
  366.          
  367.          Err = ((TMyCommandWindow *)((TMyWindow *)MainWindowx)->
  368.          CommandWindow)->SendDlgItemMsg(ID_LISTBOX, LB_ADDSTRING, 0, (LONG)str);
  369.          }
  370.       
  371.       /* make sure thumb wheel left at bottom */
  372.       
  373.       Idx = ((TMyCommandWindow *)((TMyWindow *)MainWindowx)->
  374.       CommandWindow)->SendDlgItemMsg(ID_LISTBOX, LB_GETCOUNT, 0, 0);
  375.       
  376.       ((TMyCommandWindow *)((TMyWindow *)MainWindowx)->
  377.       CommandWindow)->SendDlgItemMsg(ID_LISTBOX, LB_SETCURSEL, (WORD)Idx-1, 0);
  378.       
  379.       ((TMyCommandWindow *)((TMyWindow *)MainWindowx)->
  380.       CommandWindow)->SendDlgItemMsg(ID_LISTBOX, LB_SETCURSEL, -1, 0);
  381.       }
  382.    }
  383.  
  384. void promptuser(char *str,char *pmt) /*routine*/
  385.    {
  386.    *str = '\0';
  387.    if (((TMyWindow *)MainWindowx)->MyPopupInput(str,pmt) == 0)
  388.       {
  389.       //     if (halt_flag) Time_To_Halt = 1;
  390.       }
  391.    }
  392.  
  393. void single_step_box(NODE *the_line) /*routine*/
  394.    {
  395.    char textbuf[MAX_BUFFER_SIZE];
  396.    
  397.    // pop up single step box showing line of code
  398.    
  399.    print_stringptr = textbuf;
  400.    print_stringlen = MAX_BUFFER_SIZE;
  401.    ndprintf((FILE *)NULL,"%p",the_line);
  402.    *print_stringptr = '\0';
  403.    
  404.    MessageBox(MainHWindow, textbuf, "Single Step", MB_OK);
  405.    
  406.    }
  407.  
  408. void getcombobox(char *str) /*routine*/
  409.    {
  410.    
  411.    /* get it and clear it */
  412.    
  413.    ((TMyCommandWindow *)((TMyWindow *)MainWindowx)->CommandWindow)->SendDlgItemMsg(ID_EDITINPUT, WM_GETTEXT, MAX_BUFFER_SIZE, (LONG)str);
  414.    
  415.    SelectedText[0] = '\0';
  416.    
  417.    ((TMyCommandWindow *)((TMyWindow *)MainWindowx)->CommandWindow)->SendDlgItemMsg(ID_EDITINPUT, WM_SETTEXT, 0, (DWORD)SelectedText);
  418.    }
  419.  
  420. int minx(int v1, int v2)
  421.    {
  422.    return ((v1 < v2) ? v1 : v2);
  423.    }
  424.  
  425. int maxx(int v1, int v2)
  426.    {
  427.    return ((v1 > v2) ? v1 : v2);
  428.    }
  429.  
  430. BOOL TMyApp::ProcessAppMsg( LPMSG msg )
  431.    {
  432.    if( ProcessAccels( msg ) )
  433.    return( TRUE );
  434.    return( TApplication::ProcessAppMsg( msg ) );
  435.    }
  436.  
  437. void TMyApp::InitInstance()
  438.    {
  439.    TApplication::InitInstance();
  440.    HAccTable = LoadAccelerators(hInstance, "LogoAcc");
  441.    }
  442.  
  443. void TMyApp::IdleAction()
  444.    {
  445.    
  446.    // this is the time to exit, when things are settled down
  447.    
  448.    if (Time_To_Exit)
  449.       {
  450.       Time_To_Exit = 0;
  451.       PostMessage(MainHWindow, WM_CLOSE, 0, 0);
  452.       }
  453.    
  454.    // if command arg loaded then execute
  455.    
  456.    if (commandarg[0] != '\0')
  457.       {
  458.       silent_load(NIL,commandarg);
  459.       commandarg[0] = '\0';
  460.       }
  461.    
  462.    checkqueue();
  463.    }
  464.  
  465. void TMyApp::InitMainWindow()
  466.    {
  467.    
  468.    /* Init the main window */
  469.    
  470.    char      *cp;
  471.    char       szWinLocStr[WININISIZ];
  472.    char       dfWinLocStr[WININISIZ];
  473.    int        x, y, w, h;
  474.    
  475.    /* Get video mode parameters */
  476.    
  477.    TempDC = GetDC(0);
  478.    
  479.    MaxWidth = GetDeviceCaps(TempDC,HORZRES);
  480.    MaxHeight = GetDeviceCaps(TempDC,VERTRES);
  481.    MaxColors = pow(2,(GetDeviceCaps(TempDC,BITSPIXEL)+GetDeviceCaps(TempDC,PLANES)));
  482.    BaseUnitsx = LOWORD(GetDialogBaseUnits());   
  483.    BaseUnitsy = HIWORD(GetDialogBaseUnits());   
  484.    
  485.    ReleaseDC(0, TempDC);
  486.    
  487.    /* create the window */
  488.    
  489.    MainWindow = new TMyWindow(NULL, Name);
  490.    
  491.    /* save global handles */
  492.    
  493.    MainWindowx = MainWindow;
  494.    
  495.    /* turtle coords are in center */
  496.    
  497.    xoffset = BitMapWidth/2;
  498.    yoffset = BitMapHeight/2;
  499.    
  500.    /* set appropriate default colors */
  501.    
  502.    pcolor = 0x00000000;
  503.    scolor = 0x00ffffffL;
  504.    fcolor = 0x00000000L;
  505.    
  506.    dpenr = 0x00;
  507.    dpeng = 0x00;
  508.    dpenb = 0x00;
  509.    
  510.    dfldr = 0x00;
  511.    dfldg = 0x00;
  512.    dfldb = 0x00;
  513.    
  514.    dscnr = 0xff;
  515.    dscng = 0xff;
  516.    dscnb = 0xff;
  517.    
  518.    // init the font structure
  519.    
  520.    FontRec.lfHeight         = 24;
  521.    FontRec.lfWidth          = 0;
  522.    FontRec.lfOrientation    = 0;
  523.    FontRec.lfWeight         = 400;
  524.    FontRec.lfItalic         = 0;
  525.    FontRec.lfUnderline      = 0;
  526.    FontRec.lfStrikeOut      = 0;
  527.    FontRec.lfCharSet        = ANSI_CHARSET;
  528.    FontRec.lfOutPrecision   = OUT_DEFAULT_PRECIS;
  529.    FontRec.lfClipPrecision  = CLIP_DEFAULT_PRECIS;
  530.    FontRec.lfQuality        = DEFAULT_QUALITY;
  531.    FontRec.lfPitchAndFamily = DEFAULT_PITCH;
  532.    FontRec.lfFaceName[0]    = '\0';
  533.    
  534.    /* init all the pens based on the color */
  535.    
  536.    NormalPen.lopnStyle   = PS_INSIDEFRAME;
  537.    NormalPen.lopnWidth.x = width;
  538.    NormalPen.lopnColor   = pcolor;
  539.    
  540.    ErasePen.lopnStyle   = PS_INSIDEFRAME;
  541.    ErasePen.lopnWidth.x = width;
  542.    ErasePen.lopnColor   = scolor;
  543.    
  544.    FloodBrush.lbStyle = BS_SOLID;
  545.    FloodBrush.lbColor = fcolor;
  546.    FloodBrush.lbHatch = HS_VERTICAL;
  547.    
  548.    ScreenBrush.lbStyle = BS_SOLID;
  549.    ScreenBrush.lbColor = scolor;
  550.    ScreenBrush.lbHatch = HS_VERTICAL;
  551.    
  552.    /* build default coords */
  553.    
  554.    x = 000;
  555.    y = 000;
  556.    w = minx(MaxWidth,BitMapWidth);
  557.    h = minx((int)(MaxHeight*ScreenSz),BitMapHeight);
  558.    
  559.    /* convert */
  560.    
  561.    sprintf(dfWinLocStr, "%d,%d,%d,%d", x, y, w, h);
  562.    szWinLocStr[0] = '\0';
  563.    
  564.    // Get last location and size of screen window from WIN.INI file.
  565.    
  566.    GetPrivateProfileString(
  567.    "LOGO",
  568.    "Screen",
  569.    dfWinLocStr,
  570.    szWinLocStr,
  571.    sizeof(szWinLocStr),
  572.    "LOGO.INI");
  573.    
  574.    // Decode location and size of window from profile string.
  575.    
  576.    cp = szWinLocStr;
  577.    x = (int) strtol(cp, &cp, 10);
  578.    cp++;
  579.    y = (int) strtol(cp, &cp, 10);
  580.    cp++;
  581.    w = (int) strtol(cp, &cp, 10);
  582.    cp++;
  583.    h = (int) strtol(cp, &cp, 10);
  584.    
  585.    checkwindow(&x, &y, &w, &h);
  586.    
  587.    w = minx(w,BitMapWidth);
  588.    h = minx(h,BitMapHeight);
  589.    
  590.    // set parameters
  591.    
  592.    ((TMyWindow *)MainWindow)->Attr.X = x;
  593.    ((TMyWindow *)MainWindow)->Attr.Y = y;
  594.    ((TMyWindow *)MainWindow)->Attr.W = w;
  595.    ((TMyWindow *)MainWindow)->Attr.H = h;
  596.    
  597.    ModulehInstance = hInstance;
  598.    
  599.    /* init paths to library and help files based on locaation of .EXE */
  600.    
  601.    MakeHelpPathName(LibPathName,"logolib\\");
  602.    logolib = LibPathName;
  603.    MakeHelpPathName(szHelpFileName,"logo.hlp");
  604.    if (getenv("TEMP") != NULL)
  605.       {
  606.       strcpy(TempPathName,getenv("TEMP"));
  607.       }
  608.    else
  609.       {
  610.       MessageBox(0, "The Environment variable TEMP is not defined\nUsing C:\\ as TEMP","Warning", MB_OK);
  611.       strcpy(TempPathName,"C:");
  612.       }
  613.    strcat(TempPathName,"\\temp.txt");
  614.    //   MakeHelpPathName(TempPathName,"temp.txt");
  615.    MakeHelpPathName(MCIHelpFileName,"mcistrwh.hlp");
  616.    
  617.    }
  618.  
  619. void MyMessageScan()
  620.    {
  621.    MSG msg;
  622.    
  623.    /* depending on yield flag check for messages */
  624.    
  625.    if (yield_flag)
  626.       {
  627.       while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  628.          {
  629.          TranslateMessage(&msg);
  630.          DispatchMessage(&msg);
  631.          }
  632.       }
  633.    }
  634.  
  635. // Print page (or pages)
  636.  
  637. void TRulerOut::PrintPage(HDC DC, WORD, POINT, LPRECT, WORD)
  638.    {
  639.    ((TMyWindow *)MainWindowx)->Printit(DC);
  640.    }
  641.  
  642. // Yes the MAIN is really burried in the Main :-)
  643.  
  644. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  645.    {
  646.    int i;
  647.    char *ptr;
  648.    
  649.    if (hPrevInstance) return FALSE;
  650.    
  651.    // parse -h height -w width as being the biymap size
  652.    
  653.    commandarg[0]='\0';
  654.    
  655.    for (ptr=lpCmdLine;*ptr!='\0';ptr++)
  656.       {
  657.       if (*ptr++ == '-')
  658.          {
  659.          switch (*ptr++)
  660.             {
  661.             case 'h':
  662.                {
  663.                i=0;
  664.                for (;((*ptr==' ') || ((*ptr>='0') && (*ptr <='9')));ptr++) commandarg[i++]=*ptr;
  665.                ptr--;
  666.                commandarg[i]='\0';
  667.                sscanf(commandarg,"%d",&BitMapHeight);
  668.                commandarg[0]='\0';
  669.                break;
  670.                }
  671.             case 'w':
  672.                {
  673.                i=0;
  674.                for (;((*ptr==' ') || ((*ptr>='0') && (*ptr <='9')));ptr++) commandarg[i++]=*ptr;
  675.                ptr--;
  676.                commandarg[i]='\0';
  677.                sscanf(commandarg,"%d",&BitMapWidth);
  678.                commandarg[0]='\0';
  679.                break;
  680.                }
  681.             case 'l':
  682.                {
  683.                i=0;
  684.                for (;(*ptr==' ');ptr++);
  685.                for (;(*ptr!='\0');ptr++) commandarg[i++]=*ptr;
  686.                break;
  687.                }
  688.             }
  689.          }
  690.       }
  691.    
  692.    // Get garbage collector stack size from logo.ini
  693.    
  694.    GCMAX = GetPrivateProfileInt("LOGO", "GCStackSize", 8192, "LOGO.INI");
  695.    
  696.    // Get Max Physical line from logo.ini
  697.    
  698.    MAX_PHYS_LINE = GetPrivateProfileInt("LOGO", "MaxPhysLine", 8192, "LOGO.INI");
  699.    
  700.    // Init active area even if off
  701.    
  702.    PrinterAreaXLow  = -BitMapWidth/2;
  703.    PrinterAreaXHigh = +BitMapWidth/2;
  704.    PrinterAreaYLow  = -BitMapHeight/2;
  705.    PrinterAreaYHigh = +BitMapHeight/2;
  706.    
  707.    //   SetMessageQueue(120);
  708.    
  709.    TMyApp MyApp("MswLogo Screen", hInstance, hPrevInstance, lpCmdLine, nCmdShow);
  710.    
  711.    srand(1);
  712.    
  713.    // Set two (historical reasons) handy rectangles of full bitmap
  714.    
  715.    SetRect(&TempRect,0,0,BitMapWidth+1,BitMapHeight+1);
  716.    SetRect(&FullRect,0,0,BitMapWidth+1,BitMapHeight+1);
  717.    
  718.    // malloc and init hash table
  719.    
  720.    hash_table = (NODE **)malloc(sizeof(NODE *)*HASH_LEN);
  721.    
  722.    for (i=0;i<HASH_LEN;i++) hash_table[i] = NIL;
  723.    
  724.    // malloc garbage collector stack
  725.    
  726.    gcstack = (NODE **)malloc(sizeof(NODE *)*GCMAX);
  727.    
  728.    gctop = gcstack;
  729.    
  730.    // init the timer callback array
  731.    
  732.    for (i=0;i<MAX_TIMERS;i++) timer_callback[i] = NULL;
  733.    
  734.    // malloc init the the bitmap cut array
  735.    
  736.    CutBmp = (CUTMAP *)malloc(sizeof(CUTMAP)*MaxBitCuts);
  737.    
  738.    memset(CutBmp,0,sizeof(CUTMAP)*MaxBitCuts);
  739.    
  740.    // init logo kernel
  741.    
  742.    init();
  743.    
  744.    /* get an hourglass cursor */
  745.    
  746.    hCursorWait = LoadCursor(NULL, IDC_WAIT);
  747.    
  748.    // go for it
  749.    
  750.    MyApp.Run();
  751.    
  752.    return MyApp.Status;
  753.    }
  754.  
  755. void transline(long modex,long fromx,long fromy,long tox,long toy) /*routine*/
  756.    {
  757.    HDC ScreenDC;
  758.    HDC MemDC;
  759.    
  760.    HPEN JunkPen;
  761.    
  762.    fromx= fromx+xoffset;
  763.    fromy=-fromy+yoffset;
  764.    tox  = tox  +xoffset;
  765.    toy  =-toy  +yoffset;
  766.    
  767.    JunkPen = CreatePenIndirect(&NormalPen);
  768.    
  769.    ScreenDC = GetDC(MainHWindow);
  770.    
  771.    // memory
  772.    
  773.    MemDC = CreateCompatibleDC(ScreenDC);
  774.    OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  775.    if (EnablePalette)
  776.       {
  777.       OldPalette = SelectPalette(MemDC, ThePalette, FALSE);
  778.       RealizePalette(MemDC);
  779.       }
  780.    
  781.    SetROP2(MemDC, modex);
  782.    
  783.    OldPen = (HPEN)SelectObject(MemDC, JunkPen);
  784.    
  785.    MoveTo(MemDC,fromx,fromy);
  786.    
  787.    LineTo(MemDC,tox,toy);
  788.    
  789.    if (EnablePalette) SelectPalette(MemDC, OldPalette, FALSE);
  790.    SelectObject(MemDC, OldPen);
  791.    SelectObject(MemDC, OldBitmap);
  792.    DeleteDC(MemDC);
  793.    
  794.    // screen
  795.    
  796.    if (zoom_flag)
  797.       {
  798.       SetMapMode(ScreenDC, MM_ANISOTROPIC);
  799.       SetWindowOrg(ScreenDC, 0, 0);
  800.       SetWindowExt(ScreenDC, BitMapWidth, BitMapHeight);
  801.       SetViewportOrg(ScreenDC, 0, 0);
  802.       SetViewportExt(ScreenDC, (int)(BitMapWidth*the_zoom), (int)(BitMapHeight*the_zoom));
  803.       }
  804.    
  805.    //   SetCapture(MainHWindow);
  806.    SetROP2(ScreenDC, modex);
  807.    
  808.    if (EnablePalette)
  809.       {
  810.       OldPalette = SelectPalette(ScreenDC, ThePalette, FALSE);
  811.       RealizePalette(ScreenDC);
  812.       }
  813.    
  814.    OldPen = (HPEN)SelectObject(ScreenDC, JunkPen);
  815.    
  816.    MoveTo(ScreenDC,
  817.    fromx-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom,
  818.    fromy-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom);
  819.    
  820.    LineTo(ScreenDC,
  821.    tox  -((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom,
  822.    toy  -((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom);
  823.    
  824.    if (EnablePalette) SelectPalette(ScreenDC, OldPalette, FALSE);
  825.    SelectObject(ScreenDC, OldPen);
  826.    
  827.    DeleteObject(JunkPen);
  828.    //   ReleaseCapture();
  829.    ReleaseDC(MainHWindow, ScreenDC);
  830.    }
  831.  
  832. void translineDC(HDC ScreenDC, long modex,long fromx,long fromy,long tox,long toy) /*routine*/
  833.    {
  834.    HDC MemDC;
  835.    HPEN JunkPen;
  836.    
  837.    fromx= fromx+xoffset;
  838.    fromy=-fromy+yoffset;
  839.    tox  = tox  +xoffset;
  840.    toy  =-toy  +yoffset;
  841.    
  842.    JunkPen = CreatePenIndirect(&NormalPen);
  843.    
  844.    // memory
  845.    
  846.    MemDC = CreateCompatibleDC(ScreenDC);
  847.    OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  848.    
  849.    SetROP2(MemDC, modex);
  850.    
  851.    OldPen = (HPEN)SelectObject(MemDC, JunkPen);
  852.    
  853.    MoveTo(MemDC,fromx,fromy);
  854.    
  855.    LineTo(MemDC,tox,toy);
  856.    
  857.    SelectObject(MemDC, OldPen);
  858.    SelectObject(MemDC, OldBitmap);
  859.    DeleteDC(MemDC);
  860.    
  861.    // screen
  862.    
  863.    SetROP2(ScreenDC, modex);
  864.    
  865.    OldPen = (HPEN)SelectObject(ScreenDC, JunkPen);
  866.    
  867.    MoveTo(ScreenDC,
  868.    fromx-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom,
  869.    fromy-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom);
  870.    
  871.    LineTo(ScreenDC,
  872.    tox  -((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom,
  873.    toy  -((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom);
  874.    
  875.    SelectObject(ScreenDC, OldPen);
  876.    
  877.    DeleteObject(JunkPen);
  878.    }
  879.  
  880. void eraseline(long modex,long fromx,long fromy,long tox,long toy) /*routine*/
  881.    {
  882.    HDC ScreenDC;
  883.    HDC MemDC;
  884.    HPEN JunkPen;
  885.    
  886.    fromx= fromx+xoffset;
  887.    fromy=-fromy+yoffset;
  888.    tox  = tox  +xoffset;
  889.    toy  =-toy  +yoffset;
  890.    
  891.    JunkPen = CreatePenIndirect(&ErasePen);
  892.    
  893.    ScreenDC = GetDC(MainHWindow);
  894.    
  895.    // memory
  896.    
  897.    MemDC = CreateCompatibleDC(ScreenDC);
  898.    OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  899.    
  900.    SetROP2(MemDC, modex);
  901.    
  902.    OldPen = (HPEN)SelectObject(MemDC, JunkPen);
  903.    
  904.    MoveTo(MemDC,fromx,fromy);
  905.    
  906.    LineTo(MemDC,tox,toy);
  907.    
  908.    SelectObject(MemDC, OldPen);
  909.    SelectObject(MemDC, OldBitmap);
  910.    DeleteDC(MemDC);
  911.    
  912.    // screen
  913.    
  914.    if (zoom_flag)
  915.       {
  916.       SetMapMode(ScreenDC, MM_ANISOTROPIC);
  917.       SetWindowOrg(ScreenDC, 0, 0);
  918.       SetWindowExt(ScreenDC, BitMapWidth, BitMapHeight);
  919.       SetViewportOrg(ScreenDC, 0, 0);
  920.       SetViewportExt(ScreenDC, (int)(BitMapWidth*the_zoom), (int)(BitMapHeight*the_zoom));
  921.       }
  922.    
  923.    //   SetCapture(MainHWindow);
  924.    SetROP2(ScreenDC, modex);
  925.    
  926.    OldPen = (HPEN)SelectObject(ScreenDC, JunkPen);
  927.    
  928.    MoveTo(ScreenDC,
  929.    fromx-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom,
  930.    fromy-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom);
  931.    
  932.    LineTo(ScreenDC,
  933.    tox  -((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom,
  934.    toy  -((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom);
  935.    
  936.    SelectObject(ScreenDC, OldPen);
  937.    
  938.    DeleteObject(JunkPen);
  939.    //   ReleaseCapture();
  940.    ReleaseDC(MainHWindow, ScreenDC);
  941.    }
  942.  
  943. void ibmturt(long hide) /*routine*/
  944. /* nonzero to erase turtle */
  945.    {
  946.    
  947.    HDC     ScreenDC;
  948.    
  949.    NUMBER angle;
  950.    NUMBER ang;
  951.    
  952.    long j;
  953.    long oldx;
  954.    long oldy;
  955.    long newx;
  956.    long newy;
  957.    long fromx;
  958.    long fromy;
  959.    long tox;
  960.    long toy;
  961.    
  962.    hide = hide;
  963.    
  964.    newx = 0.0;
  965.    newy = 0.0;
  966.    
  967.    ScreenDC = GetDC(MainHWindow);
  968.    
  969.    //   SetCapture(MainHWindow);
  970.    SetROP2(ScreenDC, R2_NOT);
  971.    
  972.    OldPen = (HPEN)SelectObject(ScreenDC, CreatePen(PS_INSIDEFRAME, 1, scolor));
  973.    
  974.    for (j=0;j<4;j++)
  975.       {
  976.       switch (j)
  977.          {
  978.          case 0:ang = -90.0;break;
  979.          case 1:ang =   0.0;break;
  980.          case 2:ang =  90.0;break;
  981.          case 3:ang = -90.0;break;
  982.          }
  983.       oldx = newx;
  984.       oldy = newy;
  985.       angle = (turtle_heading+ang)*RADCVT;
  986.       
  987.       newx = (long)turtle_x + (long)(15.0*sin(angle));
  988.       newy = (long)turtle_y + (long)(15.0*cos(angle));
  989.       if (j != 0)
  990.          {
  991.          fromx=          oldx+xoffset;
  992.          fromy=         -oldy+yoffset;
  993.          tox  =          newx+xoffset;
  994.          toy  =         -newy+yoffset;
  995.          
  996.          MoveTo(ScreenDC,
  997.          (fromx-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom)*the_zoom,
  998.          (fromy-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom)*the_zoom);
  999.          
  1000.          LineTo(ScreenDC,
  1001.          (tox  -((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom)*the_zoom,
  1002.          (toy  -((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom)*the_zoom);
  1003.          
  1004.          TurtlePoints[j-1].from.x = fromx;
  1005.          TurtlePoints[j-1].from.y = fromy;
  1006.          TurtlePoints[j-1].to.x = tox;
  1007.          TurtlePoints[j-1].to.y = toy;
  1008.          }
  1009.       }
  1010.    
  1011.    DeleteObject(SelectObject(ScreenDC, OldPen));
  1012.    //   ReleaseCapture();
  1013.    ReleaseDC(MainHWindow, ScreenDC);
  1014.    
  1015.    }
  1016.  
  1017. void ibmfrom(NUMBER x,NUMBER y) /*routine*/
  1018.    {
  1019.    ibmoldx = x;
  1020.    ibmoldy = y;
  1021.    }
  1022.  
  1023. void ibmto(NUMBER x,NUMBER y) /*routine*/
  1024.    {
  1025.    if (pen_vis == 0)
  1026.       {
  1027.       if (in_erase_mode)
  1028.          {
  1029.          eraseline(R2_COPYPEN,(long)ibmoldx,(long)ibmoldy,(long)x,(long)y);
  1030.          }
  1031.       else if (current_write_mode==XOR_PUT)
  1032.          {
  1033.          transline(R2_NOT,(long)ibmoldx,(long)ibmoldy,(long)x,(long)y);
  1034.          }
  1035.       else
  1036.          {
  1037.          transline(R2_COPYPEN,(long)ibmoldx,(long)ibmoldy,(long)x,(long)y);
  1038.          }  
  1039.       }
  1040.    }
  1041.  
  1042. void MakeHelpPathName(char *szFileName, char *TheFileName)
  1043.    {
  1044.    char *  pcFileName;
  1045.    int     nFileNameLen;
  1046.    
  1047.    nFileNameLen = GetModuleFileName(ModulehInstance,szFileName,EXE_NAME_MAX_SIZE);
  1048.    pcFileName = szFileName + nFileNameLen;
  1049.    
  1050.    while (pcFileName > szFileName)
  1051.       {
  1052.       if (*pcFileName == '\\' || *pcFileName == ':')
  1053.          {
  1054.          *(++pcFileName) = '\0';
  1055.          break;
  1056.          }
  1057.       nFileNameLen--;
  1058.       pcFileName--;
  1059.       }
  1060.    
  1061.    if ((nFileNameLen+13) < EXE_NAME_MAX_SIZE)
  1062.       {
  1063.       lstrcat(szFileName, TheFileName);
  1064.       }
  1065.    else
  1066.       {
  1067.       lstrcat(szFileName, "?");
  1068.       }
  1069.    
  1070.    return;
  1071.    }
  1072.  
  1073. BOOL FAR PASCAL About(HWND hDlg, unsigned message, WORD wParam, LONG lParam)
  1074.    {
  1075.    switch (message)
  1076.       {
  1077.       case WM_INITDIALOG:
  1078.       return (TRUE);
  1079.       
  1080.       case WM_COMMAND:
  1081.       if (wParam == IDOK)
  1082.          {
  1083.          EndDialog(hDlg, TRUE);
  1084.          return (TRUE);
  1085.          }
  1086.       break;
  1087.       }
  1088.    
  1089.    return (FALSE);
  1090.    }
  1091.  
  1092. /* File edit Window members */
  1093.  
  1094. TMyFileWindow::TMyFileWindow(PTWindowsObject AParent, LPSTR ATitle,
  1095. LPSTR AFileName, NODE *args) : TxFileWindow(AParent, ATitle, AFileName)
  1096.    {
  1097.    args_list = args;
  1098.    
  1099.    AssignMenu("FileCommands");
  1100.    }
  1101.  
  1102. TMyFileWindow::~TMyFileWindow()
  1103.    {
  1104.    GlobalFree(hEditHeap);
  1105.    }
  1106.  
  1107. void TMyFileWindow::CMExit(RTMessage Msg)
  1108.    { 
  1109.    
  1110.    /* here on FILE-EXIT in editor */
  1111.    
  1112.    //   SendMessage(Editor->HWindow, EM_FMTLINES, 0, 0);
  1113.    //   SendMessage(HWindow, EM_FMTLINES, 0, 0);
  1114.    SendMessage(HWindow, WM_CLOSE, 0, 0);
  1115.    }
  1116.  
  1117. void TMyFileWindow::CMHelpEdit(RTMessage Msg)
  1118.    { 
  1119.    do_help("Editor");
  1120.    }
  1121.  
  1122. void TMyFileWindow::CMHelpEditTopic(RTMessage Msg)
  1123.    { 
  1124.    ContextHelp();
  1125.    }
  1126.  
  1127. void TMyFileWindow::ContextHelp(void)
  1128.    {
  1129.    char theText[80];
  1130.    char *ptr;
  1131.    int start, end;
  1132.    int i;
  1133.    
  1134.    // get the keyword selected
  1135.    
  1136.    Editor->GetSelection(start,end);
  1137.    Editor->GetSubText( (LPSTR) theText, start, end );
  1138.    
  1139.    // clean up line before passing to help
  1140.    
  1141.    i=strlen(theText)-1;
  1142.    while ((theText[i]==' ') && (i > 0)) theText[i--]='\0';
  1143.    
  1144.    i=0;
  1145.    while ((theText[i]==' ') && (i < 80)) i++;
  1146.    
  1147.    ptr = theText+i;
  1148.    
  1149.    do_help(ptr);
  1150.    }
  1151.  
  1152. void TMyFileWindow::CMTest(RTMessage Msg)
  1153.    {
  1154.    char *theText;
  1155.    char *ptr;
  1156.    char *ptr2;
  1157.    char *ptr3;
  1158.    int start, end;
  1159.    int more;
  1160.    
  1161.    // get the code selected
  1162.    
  1163.    Editor->GetSelection(start,end);
  1164.    theText = (char *)malloc(abs(end-start)+1);
  1165.    Editor->GetSubText( (LPSTR) theText, start, end );
  1166.    ptr = theText;
  1167.    
  1168.    // strip comments
  1169.    
  1170.    more = 1;
  1171.    while (more)
  1172.       {
  1173.       ptr2 = strchr(ptr,';');
  1174.       
  1175.       if (ptr2 != NULL)
  1176.          {
  1177.          *ptr2 = ' ';
  1178.          while ((*ptr2 != 10) && (*ptr2 != 13) && (*ptr2 != '~') && (*ptr2 != 10))
  1179.             {
  1180.             *ptr2++ = ' ';
  1181.             } 
  1182.          }
  1183.       else
  1184.          {
  1185.          more = 0;
  1186.          }
  1187.       }
  1188.    
  1189.    // paste continuation
  1190.    
  1191.    more = 1;
  1192.    while (more)
  1193.       {
  1194.       ptr2 = strchr(ptr,'~');
  1195.       
  1196.       if (ptr2 != NULL)
  1197.          {
  1198.          *ptr2 = ' ';
  1199.          ptr3 = strchr(ptr2,'\n');
  1200.          if (ptr3 != NULL)
  1201.             {
  1202.             *ptr3 = ' ';
  1203.             *(ptr3-1) = ' ';
  1204.             }
  1205.          }
  1206.       else
  1207.          {
  1208.          more = 0;
  1209.          }
  1210.       }
  1211.    
  1212.    // for each real line left execute it
  1213.    
  1214.    more = 1;
  1215.    while (more)
  1216.       {
  1217.       ptr2 = strchr(ptr,'\n');
  1218.       
  1219.       if (ptr2 != NULL)
  1220.          {
  1221.          *ptr2 = '\0';
  1222.          *(ptr2-1) = '\0';
  1223.          }
  1224.       
  1225.       putcombobox(ptr);
  1226.       do_execution(ptr);
  1227.       
  1228.       if (ptr2 != NULL)
  1229.          {
  1230.          ptr = ptr2+1;
  1231.          }
  1232.       else
  1233.          {
  1234.          more = 0;
  1235.          }
  1236.       }
  1237.    
  1238.    free(theText);
  1239.    
  1240.    }
  1241.  
  1242. void TMyFileWindow::DefWndProc( RTMessage msg )
  1243.    {
  1244.    int i;
  1245.    RECT  wrect;
  1246.    char  szWinLocStr[WININISIZ];
  1247.    int   w, h;
  1248.    int   realsave;
  1249.    callthing *callevent;
  1250.    
  1251.    // if right button do context sensitive help
  1252.    
  1253.    if (msg.WParam == WM_RBUTTONDOWN)
  1254.       {
  1255.       if (args_list != NULL) ContextHelp();
  1256.       }
  1257.    
  1258.    // if closing do the right thing
  1259.    
  1260.    if (msg.Message == WM_DESTROY)
  1261.       {
  1262.       
  1263.       // if args_list specified no user callabled editor
  1264.       
  1265.       if (args_list != NULL)
  1266.          {
  1267.          realsave = lendedit();
  1268.          }
  1269.       
  1270.       // else execute callback for user callable editor
  1271.       
  1272.       else
  1273.          {
  1274.          callevent = new callthing;
  1275.          
  1276.          callevent->func = edit_editexit;
  1277.          callevent->kind = 3;
  1278.          
  1279.          calllists.insert(callevent,3);
  1280.          }
  1281.       
  1282.       // Get location and size of our window on the screen so we can
  1283.       // come back up in the same spot next time we are invoked.
  1284.       
  1285.       if (!IsIconic(HWindow))
  1286.          {
  1287.          GetWindowRect(HWindow, (LPRECT) &wrect);
  1288.          w = wrect.right - wrect.left;
  1289.          h = wrect.bottom - wrect.top;
  1290.          
  1291.          // Make a string with our window location and size.
  1292.          
  1293.          sprintf(szWinLocStr, "%d,%d,%d,%d", wrect.left, wrect.top, w, h);
  1294.          
  1295.          // Save in WIN.INI file.
  1296.          
  1297.          WritePrivateProfileString(
  1298.          "LOGO",
  1299.          "Editor",
  1300.          szWinLocStr,
  1301.          "LOGO.INI");
  1302.          }
  1303.       
  1304.       if (args_list != NULL)
  1305.          {
  1306.          
  1307.          // an "endedit" has already occured check for error
  1308.          
  1309.          error_happen = 0;
  1310.          
  1311.          for (i=0;i<1;i++)
  1312.             {
  1313.             if (stopping_flag == THROWING)
  1314.                {
  1315.                if (compare_node(throw_node, Error, TRUE) == 0)
  1316.                   {
  1317.                   err_print();
  1318.                   error_happen = 1;
  1319.                   }
  1320.                else if (compare_node(throw_node, System, TRUE) == 0) break;
  1321.                else if (compare_node(throw_node, Toplevel, TRUE) != 0)
  1322.                   {
  1323.                   err_logo(NO_CATCH_TAG, throw_node);
  1324.                   err_print();
  1325.                   error_happen = 1;
  1326.                   }
  1327.                stopping_flag = RUN;
  1328.                }
  1329.             if (stopping_flag == STOP || stopping_flag == OUTPUT)
  1330.                {
  1331.                print_node(stdout, make_static_strnode("You must be in a procedure to use OUTPUT or STOP.\n"));
  1332.                stopping_flag = RUN;
  1333.                }
  1334.             }
  1335.          
  1336.          // if error the ask user to reedit
  1337.          
  1338.          if (error_happen)
  1339.             {
  1340.             if (MessageBox(MainHWindow, "Your edit cannot be loaded\nReturn to EDIT?","Reload error", MB_YESNO | MB_ICONQUESTION) == IDYES)
  1341.                {
  1342.                //          ledit(NULL);
  1343.                if (TMyWindow_MyPopupEdit(TempPathName,args_list))
  1344.                   {
  1345.                   MessageBox(MainHWindow, "Cannot restart editor","Fatal", MB_OK | MB_ICONQUESTION);
  1346.                   }
  1347.                else
  1348.                   {
  1349.                   unlink(TempPathName);
  1350.                   IsDirty = 1;
  1351.                   }
  1352.                }
  1353.             }
  1354.          else
  1355.             {
  1356.             // check for quit before erasing
  1357.             
  1358.             if (realsave)
  1359.                {
  1360.                lerase(args_list);
  1361.                
  1362.                // Since we erased we must load again, but no errors
  1363.                
  1364.                lendedit();
  1365.                }
  1366.             
  1367.             // free up args_list
  1368.             
  1369.             args_list = reref(args_list, NIL);
  1370.             
  1371.             unlink(TempPathName);
  1372.             }
  1373.          SetFocus(EditHWindow);
  1374.          }
  1375.       }
  1376.    
  1377.    TxFileWindow::DefWndProc( msg );
  1378.    }
  1379.  
  1380. /* Editbox members */
  1381.  
  1382. TMyEditboxWindow::TMyEditboxWindow(PTWindowsObject AParent, int AId, WORD Alen)
  1383. : TEdit(AParent, AId, Alen)
  1384.    {
  1385.    }
  1386.  
  1387. TMyEditboxWindow::~TMyEditboxWindow()
  1388.    {
  1389.    }
  1390.  
  1391. void TMyEditboxWindow::WMGetDlgCode( RTMessage msg )
  1392.    {
  1393.    TEdit::DefWndProc( msg );
  1394.    msg.Result |= DLGC_WANTARROWS;
  1395.    }
  1396.  
  1397. void TMyEditboxWindow::WMKeyDown(RTMessage Msg)
  1398.    { 
  1399.    
  1400.    // if up/down arrow keys then focus to list box
  1401.    
  1402.    if ((Msg.WParam == VK_UP) || (Msg.WParam == VK_DOWN))
  1403.       {
  1404.       SetFocus(ListHWindow);
  1405.       }
  1406.    else
  1407.       {
  1408.       DefWndProc( Msg );
  1409.       }
  1410.    }
  1411.  
  1412. /* Listbox members */
  1413.  
  1414. TMyListboxWindow::TMyListboxWindow(PTWindowsObject AParent, int AId)
  1415. : TListBox(AParent, AId)
  1416.    {
  1417.    }
  1418.  
  1419. TMyListboxWindow::~TMyListboxWindow()
  1420.    {
  1421.    }
  1422.  
  1423. void TMyListboxWindow::WMGetDlgCode( RTMessage msg )
  1424.    {
  1425.    TListBox::DefWndProc( msg );
  1426.    msg.Result |= DLGC_WANTARROWS;
  1427.    }
  1428.  
  1429. void TMyListboxWindow::WMKeyDown(RTMessage Msg)
  1430.    { 
  1431.    
  1432.    // if left/right arrow keys then focus to edit box
  1433.    
  1434.    if ((Msg.WParam == VK_LEFT) || (Msg.WParam == VK_RIGHT))
  1435.       {
  1436.       SetFocus(EditHWindow);
  1437.       }
  1438.    else
  1439.       {
  1440.       DefWndProc( Msg );
  1441.       }
  1442.    }
  1443.  
  1444. BOOL TMyFileWindow::CanClose()
  1445.    { 
  1446.    char S[MAXPATH+28];
  1447.    int Rslt;
  1448.    
  1449.    // if changed better ask user
  1450.    
  1451.    if ( Editor->IsModified() )
  1452.       {
  1453.       _fstrcpy(S, "Contents have changed.  Save?");
  1454.       
  1455.       Rslt = MessageBox(HWindow, S, "Contents Changed", MB_YESNOCANCEL | MB_ICONQUESTION);
  1456.       if ( Rslt == IDYES )
  1457.       return Save();
  1458.       else
  1459.       return Rslt != IDCANCEL;
  1460.       }
  1461.    return TRUE;
  1462.    }
  1463.