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

  1. #include "allwind.h"
  2.  
  3. extern HBITMAP DIBToBitmap (HANDLE hDIB, HPALETTE hPal);
  4. extern HANDLE BitmapToDIB (HBITMAP hBitmap, HPALETTE hPal);
  5.  
  6. char *tempfont;
  7. int found;
  8. int printflag;
  9. long bitmode = SRCCOPY;
  10.  
  11. NODE *lbitsave(NODE *arg)
  12.    {
  13.    char textbuf[MAX_BUFFER_SIZE];
  14.    
  15.    /* same as BITMAP-SAVE but gets file name from logo command */
  16.    
  17.    cnv_strnode_string(textbuf,arg);
  18.    
  19.    ((TMyWindow *)MainWindowx)->DumpBitmapFile(textbuf);
  20.    
  21.    return(UNBOUND);
  22.    }
  23.  
  24. NODE *lbitload(NODE *arg)
  25.    {
  26.    char textbuf[MAX_BUFFER_SIZE];
  27.    
  28.    /* same as BITMAP-LOAD except callable from logo command */
  29.    
  30.    cnv_strnode_string(textbuf,arg);
  31.    
  32.    ((TMyWindow *)MainWindowx)->LoadBitmapFile(textbuf);
  33.    
  34.    return(UNBOUND);
  35.    }
  36.  
  37. // function that returns the RGB vector of the pixel the turtle is on top of
  38.  
  39. NODE *lpixel()
  40.    {
  41.    HDC MemDC;
  42.    HDC ScreenDC;
  43.    COLORREF the_color;
  44.    
  45.    ScreenDC = GetDC(MainHWindow);
  46.    
  47.    // memory
  48.    
  49.    MemDC = CreateCompatibleDC(ScreenDC);
  50.    OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  51.    
  52.    if (EnablePalette)
  53.       {
  54.       OldPalette = SelectPalette(MemDC, ThePalette, FALSE);
  55.       RealizePalette(MemDC);
  56.       }
  57.    
  58.    the_color = GetPixel(MemDC,turtle_x+xoffset,-turtle_y+yoffset);
  59.    
  60.    if (EnablePalette) SelectPalette(MemDC, OldPalette, FALSE);
  61.    
  62.    DeleteDC(MemDC);
  63.    ReleaseDC(MainHWindow, ScreenDC);
  64.    
  65.    return(
  66.    cons(make_intnode((FIXNUM)GetRValue(the_color)),
  67.    cons(make_intnode((FIXNUM)GetGValue(the_color)),
  68.    cons(make_intnode((FIXNUM)GetBValue(the_color)),
  69.    NIL
  70.    ))));
  71.    }
  72.  
  73. void logofill()
  74.    {
  75.    HDC ScreenDC;
  76.    HDC MemDC;
  77.    HBRUSH JunkBrush;
  78.    
  79.    ScreenDC = GetDC(MainHWindow);
  80.    
  81.    JunkBrush = CreateBrushIndirect(&FloodBrush);
  82.    
  83.    // memory
  84.    
  85.    MemDC = CreateCompatibleDC(ScreenDC);
  86.    OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  87.    
  88.    if (EnablePalette)
  89.       {
  90.       OldPalette = SelectPalette(MemDC, ThePalette, FALSE);
  91.       RealizePalette(MemDC);
  92.       }
  93.    
  94.    SetTextColor(MemDC,pcolor);
  95.    
  96.    OldBrush = (HBRUSH)SelectObject(MemDC, JunkBrush);
  97.    
  98.    FloodFill(MemDC,turtle_x+xoffset,-turtle_y+yoffset,pcolor);
  99.    
  100.    if (EnablePalette) SelectPalette(MemDC, OldPalette, FALSE);
  101.    SelectObject(MemDC, OldBrush);
  102.    SelectObject(MemDC, OldBitmap);
  103.    
  104.    DeleteDC(MemDC);
  105.    
  106.    //screen
  107.    
  108.    if (zoom_flag)
  109.       {
  110.       SetMapMode(ScreenDC, MM_ANISOTROPIC);
  111.       SetWindowOrg(ScreenDC, 0, 0);
  112.       SetWindowExt(ScreenDC, BitMapWidth, BitMapHeight);
  113.       SetViewportOrg(ScreenDC, 0, 0);
  114.       SetViewportExt(ScreenDC, (int)(BitMapWidth*the_zoom), (int)(BitMapHeight*the_zoom));
  115.       }
  116.    
  117.    //   SetCapture(MainHWindow);
  118.    
  119.    SetTextColor(ScreenDC,pcolor);
  120.    
  121.    if (EnablePalette)
  122.       {
  123.       OldPalette = SelectPalette(ScreenDC, ThePalette, FALSE);
  124.       RealizePalette(ScreenDC);
  125.       }
  126.    
  127.    OldBrush = (HBRUSH)SelectObject(ScreenDC, JunkBrush);
  128.    
  129.    FloodFill(ScreenDC,
  130.    +turtle_x-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom+xoffset,
  131.    -turtle_y-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom+yoffset,
  132.    pcolor);
  133.    
  134.    SelectObject(ScreenDC, OldBrush);
  135.    if (EnablePalette) SelectPalette(ScreenDC, OldPalette, FALSE);
  136.    
  137.    DeleteObject(JunkBrush);
  138.    //   ReleaseCapture();
  139.    ReleaseDC(MainHWindow, ScreenDC);
  140.    
  141.    }
  142.  
  143. NODE *lpencolor()
  144.    {
  145.    return(
  146.    cons(make_intnode((FIXNUM)dpenr),
  147.    cons(make_intnode((FIXNUM)dpeng),
  148.    cons(make_intnode((FIXNUM)dpenb),
  149.    NIL
  150.    ))));
  151.    }
  152.  
  153. // funtion to set the pen color while updating palette if need be
  154.  
  155. void thepencolor(int r, int g, int b) /*routine*/
  156.    {
  157.    
  158.    dpenr = r;
  159.    dpeng = g;
  160.    dpenb = b;
  161.    
  162.    if (EnablePalette)
  163.       {
  164.       pcolor = LoadColor((int)dpenr,(int)dpeng,(int)dpenb);
  165.       }
  166.    else
  167.       {
  168.       pcolor = RGB(dpenr,dpeng,dpenb);
  169.       }   
  170.    
  171.    NormalPen.lopnStyle   = PS_INSIDEFRAME;
  172.    NormalPen.lopnWidth.x = width;
  173.    NormalPen.lopnColor   = pcolor;
  174.    }
  175.  
  176. // function to return flood color as a RGB list
  177.  
  178. NODE *lfloodcolor()
  179.    {
  180.    return(
  181.    cons(make_intnode((FIXNUM)dfldr),
  182.    cons(make_intnode((FIXNUM)dfldg),
  183.    cons(make_intnode((FIXNUM)dfldb),
  184.    NIL
  185.    ))));
  186.    }
  187.  
  188. // funtion to set the flood color while updating palette if need be
  189.  
  190. void thefloodcolor(int r, int g, int b) /*routine*/
  191.    {
  192.    
  193.    dfldr = r;
  194.    dfldg = g;
  195.    dfldb = b;
  196.    
  197.    if (EnablePalette)
  198.       {
  199.       fcolor = LoadColor((int)dfldr,(int)dfldg,(int)dfldb);
  200.       }
  201.    else
  202.       {
  203.       fcolor = RGB(dfldr,dfldg,dfldb);
  204.       }
  205.    
  206.    FloodBrush.lbStyle = BS_SOLID;
  207.    FloodBrush.lbColor = fcolor;
  208.    FloodBrush.lbHatch = HS_VERTICAL;
  209.    }
  210.  
  211. // function to return screen color as a RGB list
  212.  
  213. NODE *lscreencolor()
  214.    {
  215.    return(
  216.    cons(make_intnode((FIXNUM)dscnr),
  217.    cons(make_intnode((FIXNUM)dscng),
  218.    cons(make_intnode((FIXNUM)dscnb),
  219.    NIL
  220.    ))));
  221.    }
  222.  
  223. // funtion to set the screen color while updating palette if need be
  224.  
  225. void thescreencolor(int r, int g, int b) /*routine*/
  226.    {
  227.    HDC ScreenDC;
  228.    HDC MemDC;
  229.    
  230.    HBRUSH TempBrush;
  231.    
  232.    dscnr = r;
  233.    dscng = g;
  234.    dscnb = b;
  235.    
  236.    if (EnablePalette)
  237.       {
  238.       scolor = LoadColor((int)dscnr,(int)dscng,(int)dscnb);
  239.       }
  240.    else
  241.       {
  242.       scolor = RGB(dscnr,dscng,dscnb);
  243.       }
  244.    
  245.    ScreenBrush.lbStyle = BS_SOLID;
  246.    ScreenBrush.lbColor = scolor;
  247.    ScreenBrush.lbHatch = HS_VERTICAL;
  248.    
  249.    // When the screen changes we change the erase pen which basically
  250.    // writes the screen color
  251.    
  252.    ErasePen.lopnStyle   = PS_INSIDEFRAME;
  253.    ErasePen.lopnWidth.x = width;
  254.    ErasePen.lopnColor   = scolor;
  255.    
  256.    TempBrush = CreateBrushIndirect(&ScreenBrush);
  257.    
  258.    ScreenDC = GetDC(MainHWindow);
  259.    
  260.    // memory
  261.    
  262.    MemDC = CreateCompatibleDC(ScreenDC);
  263.    OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  264.    
  265.    if (EnablePalette)
  266.       {
  267.       OldPalette = SelectPalette(MemDC, ThePalette, FALSE);
  268.       RealizePalette(MemDC);
  269.       }
  270.    
  271.    FillRect(MemDC, &FullRect, TempBrush);
  272.    
  273.    if (EnablePalette) SelectPalette(MemDC, OldPalette, FALSE);
  274.    
  275.    SelectObject(MemDC, OldBitmap);
  276.    DeleteDC(MemDC);
  277.    
  278.    // screen
  279.    
  280.    if (zoom_flag)
  281.       {
  282.       SetMapMode(ScreenDC, MM_ANISOTROPIC);
  283.       SetWindowOrg(ScreenDC, 0, 0);
  284.       SetWindowExt(ScreenDC, BitMapWidth, BitMapHeight);
  285.       SetViewportOrg(ScreenDC, 0, 0);
  286.       SetViewportExt(ScreenDC, (int)(BitMapWidth*the_zoom), (int)(BitMapHeight*the_zoom));
  287.       }
  288.    
  289.    if (EnablePalette)
  290.       {
  291.       OldPalette = SelectPalette(ScreenDC, ThePalette, FALSE);
  292.       RealizePalette(ScreenDC);
  293.       }
  294.    
  295.    FillRect(ScreenDC, &TempRect, TempBrush);
  296.    
  297.    SetBkColor(ScreenDC, scolor);
  298.    SetBkMode(ScreenDC, TRANSPARENT);
  299.    
  300.    if (EnablePalette) SelectPalette(ScreenDC, OldPalette, FALSE);
  301.    
  302.    ReleaseDC(MainHWindow, ScreenDC);
  303.    DeleteObject(TempBrush);
  304.    
  305.    InvalidateRect(MainHWindow, NULL, TRUE);
  306.    }
  307.  
  308. int get_ibm_pen_width()
  309.    {
  310.    int w;
  311.    
  312.    w = width;
  313.    
  314.    return (w);
  315.    }
  316.  
  317. //int get_ibm_pen_height()
  318.    //{
  319.    //  int w;
  320.    //
  321.    //  w = width;
  322.    //
  323.    //  return (w);
  324.    //}
  325.  
  326. void set_ibm_pen_width(int w)
  327.    {
  328.    width = w;
  329.    
  330.    // we erase with the same pen width as we write
  331.    
  332.    NormalPen.lopnStyle   = PS_INSIDEFRAME;
  333.    NormalPen.lopnWidth.x = width;
  334.    NormalPen.lopnColor   = pcolor;
  335.    
  336.    ErasePen.lopnStyle   = PS_INSIDEFRAME;
  337.    ErasePen.lopnWidth.x = width;
  338.    ErasePen.lopnColor   = scolor;
  339.    }
  340.  
  341. NODE *lclearpalette(void) /*routine*/
  342.    {
  343.    
  344.    // kill the palette and recreate it with just black and white
  345.    
  346.    if (NOT_THROWING)
  347.       {
  348.       if (EnablePalette)
  349.          {
  350.          DeleteObject(ThePalette);
  351.          
  352.          MyLogPalette->palNumEntries = 2;
  353.          
  354.          if (status_flag) update_status_paletteuse();
  355.          
  356.          ThePalette = CreatePalette(MyLogPalette);
  357.          
  358.          InvalidateRect(MainHWindow, NULL, TRUE);
  359.          }
  360.       }
  361.    
  362.    return(UNBOUND);
  363.    }
  364.  
  365. NODE *lstatus(void) /*routine*/
  366.    {
  367.    
  368.    // if status not running then run it
  369.    
  370.    if (!status_flag)
  371.       {
  372.       ((TMyWindow *)MainWindowx)->MyPopupStatus();
  373.       JustDidEdit = 1;
  374.       }
  375.    return(UNBOUND);
  376.    }
  377.  
  378. NODE *lnostatus(void) /*routine*/
  379.    {
  380.    
  381.    // if running then kill it
  382.    
  383.    if (status_flag)
  384.       {
  385.       ((TMyWindow *)MainWindowx)->MyPopupStatusKill();
  386.       }
  387.    return(UNBOUND);
  388.    }
  389.  
  390. // The real work of zooming is done in Paint this just adjusts the scroller
  391. // to something reasonable so that what was basically in the center of the
  392. // screen still is. It also readjusts the ranges on the scrollers.
  393.  
  394. NODE *lzoom(NODE *arg) /*routine*/
  395.    {
  396.    NUMBER temp_zoom;
  397.    NUMBER XRatio;
  398.    NUMBER YRatio;
  399.    
  400.    int Xr;
  401.    int Yr;
  402.    
  403.    RECT MainRect;
  404.    
  405.    NODE *val;
  406.    
  407.    // get arg
  408.    
  409.    val = numeric_arg(arg);
  410.    
  411.    if (nodetype(val) == INT) temp_zoom = (NUMBER)getint(val);
  412.    else temp_zoom = getfloat(val);
  413.    
  414.    // only if different do something
  415.    
  416.    if (the_zoom != temp_zoom)
  417.       {
  418.       
  419.       the_zoom = temp_zoom;
  420.       
  421.       GetClientRect(MainHWindow,&MainRect);
  422.       
  423.       // calculate new scroller ranges
  424.       
  425.       Xr = (BitMapWidth*the_zoom)-MainRect.right;
  426.       Yr = (BitMapHeight*the_zoom)-MainRect.bottom;
  427.       
  428.       if (Xr < 0) Xr = 0;
  429.       if (Yr < 0) Yr = 0;
  430.       
  431.       // find out where we are (percentage of pos/range for x and y)
  432.       
  433.       if (((TMyWindow *)MainWindowx)->Scroller->XRange <= 0)
  434.          {
  435.          XRatio = 0.5;
  436.          }
  437.       else
  438.          {
  439.          XRatio = (NUMBER)((TMyWindow *)MainWindowx)->Scroller->XPos/(NUMBER)((TMyWindow *)MainWindowx)->Scroller->XRange;
  440.          }
  441.       
  442.       if (((TMyWindow *)MainWindowx)->Scroller->YRange <= 0)
  443.          {
  444.          YRatio = 0.5;
  445.          }
  446.       else
  447.          {
  448.          YRatio = (NUMBER)((TMyWindow *)MainWindowx)->Scroller->YPos/(NUMBER)((TMyWindow *)MainWindowx)->Scroller->YRange;
  449.          }
  450.       
  451.       // set the new ranges
  452.       
  453.       ((TMyWindow *)MainWindowx)->Scroller->SetRange(Xr,Yr);
  454.       
  455.       // Position to the same percentage down the scroll bars as before
  456.       
  457.       ((TMyWindow *)MainWindowx)->Scroller->ScrollTo(XRatio*Xr,YRatio*Yr);
  458.       
  459.       // hide turtle while we do this
  460.       
  461.       if (turtle_shown) ibmturt(0);
  462.       
  463.       // if returning to 1:1 turn TrackMode on
  464.       
  465.       if (zoom_flag)
  466.          {
  467.          zoom_flag = 0;
  468.          
  469.          ((TMyWindow *)MainWindowx)->Scroller->TrackMode = TRUE;
  470.          }
  471.       
  472.       // if leaving 1:1 turn TrackMode off (paint is too slow)
  473.       
  474.       if (temp_zoom != 1.0)
  475.          {
  476.          zoom_flag = 1;
  477.          
  478.          ((TMyWindow *)MainWindowx)->Scroller->TrackMode = FALSE;
  479.          }
  480.       
  481.       if (turtle_shown) ibmturt(0);
  482.       
  483.       // paint
  484.       
  485.       InvalidateRect(MainHWindow, NULL, TRUE);
  486.       
  487.       }
  488.    
  489.    return (UNBOUND);
  490.    }
  491.  
  492. NODE *lbitblock(NODE *arg) /*routine*/
  493.    {
  494.    HDC ScreenDC;
  495.    HDC MemDC;
  496.    HBRUSH TempBrush;
  497.    RECT TempRect;
  498.    int CutWidth;
  499.    int CutHeight;   
  500.    
  501.    // get args
  502.    
  503.    CutWidth  = getint(pos_int_arg(arg));
  504.    CutHeight = getint(pos_int_arg(cdr(arg)));
  505.    
  506.    if (NOT_THROWING)
  507.       {
  508.       
  509.       // only if a surface was specified continue or UAEs big time
  510.       
  511.       if ((CutWidth != 0) && (CutHeight != 0))
  512.          {
  513.          
  514.          TempBrush = CreateBrushIndirect(&FloodBrush);
  515.          
  516.          ScreenDC = GetDC(MainHWindow);
  517.          
  518.          // memory
  519.          
  520.          MemDC = CreateCompatibleDC(ScreenDC);
  521.          OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  522.          
  523.          if (EnablePalette)
  524.             {
  525.             OldPalette2 = SelectPalette(ScreenDC, ThePalette, FALSE);
  526.             RealizePalette(ScreenDC);
  527.             
  528.             OldPalette = SelectPalette(MemDC, ThePalette, FALSE);
  529.             RealizePalette(MemDC);
  530.             }
  531.          
  532.          SetRect(&TempRect,
  533.          +turtle_x+xoffset,
  534.          -turtle_y+yoffset-CutHeight,
  535.          +turtle_x+xoffset+CutWidth,
  536.          -turtle_y+yoffset);
  537.          
  538.          FillRect(MemDC, &TempRect, TempBrush);
  539.          
  540.          SelectObject(MemDC, OldBitmap);
  541.          if (EnablePalette) SelectPalette(MemDC, OldPalette, FALSE);
  542.          DeleteDC(MemDC);
  543.          
  544.          //screen
  545.          
  546.          if (turtle_shown) ibmturt(0);
  547.          
  548.          if (zoom_flag)
  549.             {
  550.             SetMapMode(ScreenDC, MM_ANISOTROPIC);
  551.             SetWindowOrg(ScreenDC, 0, 0);
  552.             SetWindowExt(ScreenDC, BitMapWidth, BitMapHeight);
  553.             SetViewportOrg(ScreenDC, 0, 0);
  554.             SetViewportExt(ScreenDC, (int)(BitMapWidth*the_zoom), (int)(BitMapHeight*the_zoom));
  555.             }
  556.          
  557.          //         SetCapture(MainHWindow);
  558.          
  559.          SetRect(&TempRect,
  560.          +turtle_x-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom+xoffset,
  561.          -turtle_y-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom+yoffset-CutHeight,
  562.          +turtle_x-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom+xoffset+CutWidth,
  563.          -turtle_y-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom+yoffset);
  564.          
  565.          FillRect(ScreenDC, &TempRect, TempBrush);
  566.          
  567.          //         ReleaseCapture();
  568.          if (EnablePalette) SelectPalette(ScreenDC, OldPalette2, FALSE);
  569.          ReleaseDC(MainHWindow, ScreenDC);
  570.          
  571.          DeleteObject(TempBrush);
  572.          
  573.          if (turtle_shown) ibmturt(0);
  574.          
  575.          }
  576.       
  577.       }
  578.    return(UNBOUND);
  579.    }
  580.  
  581. NODE *lbitmode(void) /*routine*/
  582.    {
  583.    int temp;
  584.    
  585.    // return the logo "code" for the bit mode
  586.    
  587.    switch (bitmode)
  588.       {
  589.       case SRCCOPY: temp = 1; break;
  590.       case SRCPAINT: temp = 2; break;
  591.       case SRCAND: temp = 3; break;
  592.       case SRCINVERT: temp = 4; break;
  593.       case SRCERASE: temp = 5; break;
  594.       case NOTSRCCOPY: temp = 6; break;
  595.       case NOTSRCERASE: temp = 7; break;
  596.       case MERGEPAINT: temp = 8; break;
  597.       case DSTINVERT: temp = 9; break;
  598.       }
  599.    
  600.    return(make_intnode((FIXNUM)temp));
  601.    }
  602.  
  603. NODE *lsetbitmode(NODE *arg) /*routine*/
  604.    {
  605.    
  606.    // convert from logo "code" to Windows constants
  607.    
  608.    switch (int_arg(arg))
  609.       {
  610.       case 1: bitmode = SRCCOPY; break;
  611.       case 2: bitmode = SRCPAINT; break;
  612.       case 3: bitmode = SRCAND; break;
  613.       case 4: bitmode = SRCINVERT; break;
  614.       case 5: bitmode = SRCERASE; break;
  615.       case 6: bitmode = NOTSRCCOPY; break;
  616.       case 7: bitmode = NOTSRCERASE; break;
  617.       case 8: bitmode = MERGEPAINT; break;
  618.       case 9: bitmode = DSTINVERT; break;
  619.       default: MessageBox(MainHWindow, "Illegal Bitmode", "Error", MB_OK | MB_ICONEXCLAMATION);
  620.       }
  621.    
  622.    return(UNBOUND);
  623.    }
  624.  
  625. NODE *lbitindex(void) /*routine*/
  626.    {
  627.    // return the current bitmap index
  628.    
  629.    return(make_intnode((FIXNUM)CutIndex));
  630.    }
  631.  
  632. NODE *lsetbitindex(NODE *arg) /*routine*/
  633.    {
  634.    int i;
  635.    
  636.    // set the current bitmap index if within range
  637.    
  638.    i = getint(pos_int_arg(arg));
  639.    
  640.    if (i < MaxBitCuts)
  641.       {
  642.       CutIndex = i;
  643.       }
  644.    else
  645.       {
  646.       MessageBox(MainHWindow, "BitMap Index out of range", "Error", MB_OK | MB_ICONEXCLAMATION);
  647.       }
  648.    
  649.    return(UNBOUND);
  650.    }
  651.  
  652. NODE *lbitcut(NODE *arg) /*routine*/
  653.    {
  654.    HDC ScreenDC;
  655.    HDC MemDC;
  656.    HDC TempMemDC;
  657.    
  658.    HBRUSH TempBrush;
  659.    
  660.    RECT TempRect;
  661.    
  662.    int TempWidth;
  663.    int TempHeight;
  664.    int havebitmap;
  665.    
  666.    havebitmap = 0;
  667.    
  668.    TempWidth  = getint(pos_int_arg(arg));
  669.    TempHeight = getint(pos_int_arg(cdr(arg)));
  670.    
  671.    if (NOT_THROWING)
  672.       {
  673.       
  674.       // if we had a old cut get rid of it, we won't go in for clipboard
  675.       
  676.       if (CutBmp[CutIndex].CutFlag)
  677.          {
  678.          
  679.          // if same size reuse the bitmap
  680.          
  681.          if ((TempWidth == CutBmp[CutIndex].CutWidth) && (TempHeight == CutBmp[CutIndex].CutHeight))
  682.             {
  683.             havebitmap = 1;
  684.             }
  685.          
  686.          // else get rid of it and make a new one later
  687.          
  688.          else
  689.             {
  690.             DeleteObject(CutBmp[CutIndex].CutMemoryBitMap);
  691.             }
  692.          CutBmp[CutIndex].CutFlag = 0;
  693.          }
  694.       
  695.       CutBmp[CutIndex].CutWidth = TempWidth;
  696.       CutBmp[CutIndex].CutHeight = TempHeight;
  697.       
  698.       // only if we have a surface continue
  699.       
  700.       if ((CutBmp[CutIndex].CutWidth != 0) && (CutBmp[CutIndex].CutHeight != 0))
  701.          {
  702.          
  703.          // flag it so we will delete it
  704.          
  705.          CutBmp[CutIndex].CutFlag = 1;
  706.          
  707.          ScreenDC = GetDC(MainHWindow);
  708.          
  709.          MemDC = CreateCompatibleDC(ScreenDC);
  710.          OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  711.          
  712.          if (!havebitmap) CutBmp[CutIndex].CutMemoryBitMap = CreateCompatibleBitmap(ScreenDC, (int)(CutBmp[CutIndex].CutWidth), (int)(CutBmp[CutIndex].CutHeight));
  713.          if (!CutBmp[CutIndex].CutMemoryBitMap) MessageBox(MainHWindow, "Cut failed, Possibly not enough Memory", "Error", MB_OK | MB_ICONEXCLAMATION);
  714.          
  715.          TempMemDC = CreateCompatibleDC(ScreenDC);
  716.          OldBitmap2 = (HBITMAP)SelectObject(TempMemDC, CutBmp[CutIndex].CutMemoryBitMap);
  717.          
  718.          BitBlt(TempMemDC, 0, 0, (int)(CutBmp[CutIndex].CutWidth), (int)(CutBmp[CutIndex].CutHeight), MemDC, 
  719.          +turtle_x+xoffset,
  720.          -turtle_y+yoffset-CutBmp[CutIndex].CutHeight, SRCCOPY);
  721.          
  722.          SelectObject(TempMemDC, OldBitmap2);
  723.          DeleteDC(TempMemDC);
  724.          
  725.          // memory
  726.          
  727.          SetRect(&TempRect,
  728.          +turtle_x+xoffset,
  729.          -turtle_y+yoffset-CutBmp[CutIndex].CutHeight,
  730.          +turtle_x+xoffset+CutBmp[CutIndex].CutWidth,
  731.          -turtle_y+yoffset);
  732.          
  733.          TempBrush = CreateBrushIndirect(&ScreenBrush);
  734.          
  735.          FillRect(MemDC, &TempRect, TempBrush);
  736.          
  737.          SelectObject(MemDC, OldBitmap);
  738.          DeleteDC(MemDC);
  739.          
  740.          //screen
  741.          
  742.          if (turtle_shown) ibmturt(0);
  743.          
  744.          if (zoom_flag)
  745.             {
  746.             SetMapMode(ScreenDC, MM_ANISOTROPIC);
  747.             SetWindowOrg(ScreenDC, 0, 0);
  748.             SetWindowExt(ScreenDC, BitMapWidth, BitMapHeight);
  749.             SetViewportOrg(ScreenDC, 0, 0);
  750.             SetViewportExt(ScreenDC, (int)(BitMapWidth*the_zoom), (int)(BitMapHeight*the_zoom));
  751.             }
  752.          
  753.          //         SetCapture(MainHWindow);
  754.          
  755.          SetRect(&TempRect,
  756.          +turtle_x-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom+xoffset,
  757.          -turtle_y-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom+yoffset-CutBmp[CutIndex].CutHeight,
  758.          +turtle_x-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom+xoffset+CutBmp[CutIndex].CutWidth,
  759.          -turtle_y-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom+yoffset);
  760.          
  761.          FillRect(ScreenDC, &TempRect, TempBrush);
  762.          
  763.          //         ReleaseCapture();
  764.          ReleaseDC(MainHWindow, ScreenDC);
  765.          
  766.          DeleteObject(TempBrush);
  767.          
  768.          if (turtle_shown) ibmturt(0);
  769.          
  770.          // if CutIndex == 0 then do Clipboard 
  771.          
  772.          if (CutIndex == 0)
  773.             {
  774.             
  775.             // Open, dump what's in there and give him the Bitmap
  776.             
  777.             OpenClipboard(MainHWindow);
  778.             EmptyClipboard();
  779.             SetClipboardData(CF_BITMAP, CutBmp[CutIndex].CutMemoryBitMap);
  780.             
  781.             // If we have a palette given him a DIB and a palette too
  782.             
  783.             if (EnablePalette)
  784.                {
  785.                SetClipboardData(CF_DIB, BitmapToDIB(CutBmp[CutIndex].CutMemoryBitMap,ThePalette));
  786.                SetClipboardData(CF_PALETTE, CreatePalette(MyLogPalette));
  787.                }
  788.             
  789.             // else give hime a DIB using system palette
  790.             
  791.             else
  792.                {
  793.                SetClipboardData(CF_DIB, BitmapToDIB(CutBmp[CutIndex].CutMemoryBitMap,NULL));
  794.                }
  795.             CloseClipboard();
  796.             
  797.             // Never mung with bitmaps that belong to ClipBoard
  798.             
  799.             CutBmp[CutIndex].CutFlag = 0;
  800.             }
  801.          
  802.          }
  803.       
  804.       }
  805.    return(UNBOUND);
  806.    }
  807.  
  808. NODE *lbitcopy(NODE *arg) /*routine*/
  809.    {
  810.    HDC ScreenDC;
  811.    HDC MemDC;
  812.    HDC TempMemDC;
  813.    HBRUSH TempBrush;
  814.    RECT TempRect;
  815.    int TempWidth;
  816.    int TempHeight;
  817.    int havebitmap;
  818.    
  819.    havebitmap = 0;
  820.    
  821.    TempWidth  = getint(pos_int_arg(arg));
  822.    TempHeight = getint(pos_int_arg(cdr(arg)));
  823.    
  824.    if (NOT_THROWING)
  825.       {
  826.       
  827.       // if we had a old cut get rid of it, we won't go in for clipboard
  828.       
  829.       if (CutBmp[CutIndex].CutFlag)
  830.          {
  831.          
  832.          // if same size reuse the bitmap
  833.          
  834.          if ((TempWidth == CutBmp[CutIndex].CutWidth) && (TempHeight == CutBmp[CutIndex].CutHeight))
  835.             {
  836.             havebitmap = 1;
  837.             }
  838.          
  839.          // else get rid of it and make a new one later
  840.          
  841.          else
  842.             {
  843.             DeleteObject(CutBmp[CutIndex].CutMemoryBitMap);
  844.             }
  845.          CutBmp[CutIndex].CutFlag = 0;
  846.          }
  847.       
  848.       CutBmp[CutIndex].CutWidth = TempWidth;
  849.       CutBmp[CutIndex].CutHeight = TempHeight;
  850.       
  851.       // only if we have a surface continue
  852.       
  853.       if ((CutBmp[CutIndex].CutWidth != 0) && (CutBmp[CutIndex].CutHeight != 0))
  854.          {
  855.          
  856.          // flag it so we will delete it
  857.          
  858.          CutBmp[CutIndex].CutFlag = 1;
  859.          
  860.          ScreenDC = GetDC(MainHWindow);
  861.          
  862.          MemDC = CreateCompatibleDC(ScreenDC);
  863.          OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  864.          
  865.          if (!havebitmap) CutBmp[CutIndex].CutMemoryBitMap = CreateCompatibleBitmap(ScreenDC, (int)(CutBmp[CutIndex].CutWidth), (int)(CutBmp[CutIndex].CutHeight));
  866.          if (!CutBmp[CutIndex].CutMemoryBitMap) MessageBox(MainHWindow, "Cut failed, Possibly not enough Memory", "Error", MB_OK | MB_ICONEXCLAMATION);
  867.          
  868.          TempMemDC = CreateCompatibleDC(ScreenDC);
  869.          OldBitmap2 = (HBITMAP)SelectObject(TempMemDC, CutBmp[CutIndex].CutMemoryBitMap);
  870.          
  871.          BitBlt(TempMemDC, 0, 0, (int)(CutBmp[CutIndex].CutWidth), (int)(CutBmp[CutIndex].CutHeight), MemDC, 
  872.          +turtle_x+xoffset,
  873.          -turtle_y+yoffset-CutBmp[CutIndex].CutHeight, SRCCOPY);
  874.          
  875.          SelectObject(TempMemDC, OldBitmap2);
  876.          DeleteDC(TempMemDC);
  877.          
  878.          SelectObject(MemDC, OldBitmap);
  879.          DeleteDC(MemDC);         
  880.          
  881.          ReleaseDC(MainHWindow, ScreenDC);
  882.          
  883.          // if CutIndex == 0 then do Clipboard 
  884.          
  885.          if (CutIndex == 0)
  886.             {
  887.             
  888.             // Open, dump what's in there and give him the Bitmap
  889.             
  890.             OpenClipboard(MainHWindow);
  891.             EmptyClipboard();
  892.             SetClipboardData(CF_BITMAP, CutBmp[CutIndex].CutMemoryBitMap);
  893.             
  894.             // If we have a palette given him a DIB and a palette too
  895.             
  896.             if (EnablePalette)
  897.                {
  898.                SetClipboardData(CF_DIB, BitmapToDIB(CutBmp[CutIndex].CutMemoryBitMap,ThePalette));
  899.                SetClipboardData(CF_PALETTE, CreatePalette(MyLogPalette));
  900.                }
  901.             
  902.             // else give hime a DIB using system palette
  903.             
  904.             else
  905.                {
  906.                SetClipboardData(CF_DIB, BitmapToDIB(CutBmp[CutIndex].CutMemoryBitMap,NULL));
  907.                }
  908.             CloseClipboard();
  909.             
  910.             // Never mung with bitmaps that belong to ClipBoard
  911.             
  912.             CutBmp[CutIndex].CutFlag = 0;
  913.             }
  914.          }
  915.       }
  916.    return(UNBOUND);
  917.    }
  918.  
  919. NODE *lbitfit(NODE *arg) /*routine*/
  920.    {
  921.    HDC      ScreenDC;
  922.    HDC      MemDC;
  923.    HDC      TempMemDC;
  924.    
  925.    NUMBER   FitHeight;
  926.    NUMBER   FitWidth;
  927.    
  928.    HBITMAP  TempMemoryBitMap;
  929.    
  930.    BITMAP temp;
  931.    HANDLE TempDIB;
  932.    HPALETTE TempPal;
  933.    
  934.    FitWidth  = getint(pos_int_arg(arg));
  935.    FitHeight = getint(pos_int_arg(cdr(arg)));
  936.    
  937.    if (NOT_THROWING)
  938.       {
  939.       
  940.       // If ClipBoard check with ClipBoard only
  941.       
  942.       if (CutIndex == 0)
  943.          {
  944.          OpenClipboard(MainHWindow);
  945.          
  946.          // Try a DIB first
  947.          
  948.          TempDIB = (HBITMAP) GetClipboardData(CF_DIB);
  949.          
  950.          // If Success try for a palette too
  951.          
  952.          if (TempDIB != NULL)
  953.             {
  954.             TempPal = (HPALETTE) GetClipboardData(CF_PALETTE);
  955.             
  956.             // we have everything we need
  957.             
  958.             CloseClipboard();
  959.             
  960.             // we work in bmps here
  961.             
  962.             CutBmp[CutIndex].CutMemoryBitMap = DIBToBitmap (TempDIB, TempPal);
  963.             
  964.             // Fill our logical palette with the Palette from the clipboard
  965.             
  966.             if (EnablePalette && (TempPal != NULL))
  967.                {
  968.                GetPaletteEntries(TempPal, 0, 255, &(MyLogPalette->palPalEntry[0]));
  969.                
  970.                // now rebuild palette
  971.                
  972.                DeleteObject(ThePalette);
  973.                ThePalette = CreatePalette(MyLogPalette);
  974.                if (status_flag) update_status_paletteuse();
  975.                }
  976.             
  977.             // Let code know below that we have something
  978.             
  979.             CutBmp[CutIndex].CutFlag = 1;
  980.             
  981.             // note we do not have to delete bitmap here because we
  982.             // going to immediately give it back to clipboard.
  983.             }
  984.          
  985.          // else try for a bitmap
  986.          
  987.          else
  988.             {
  989.             
  990.             CutBmp[CutIndex].CutMemoryBitMap = (HBITMAP) GetClipboardData(CF_BITMAP);
  991.             
  992.             // where done whether they have it or not
  993.             
  994.             CloseClipboard();
  995.             
  996.             // flag that we have one if it exists, no need to delete the
  997.             // bitmap here because clipboard still owns it.
  998.             
  999.             if (CutBmp[CutIndex].CutMemoryBitMap != NULL)
  1000.                {
  1001.                CutBmp[CutIndex].CutFlag = 1;
  1002.                }
  1003.             else
  1004.                {
  1005.                CutBmp[CutIndex].CutFlag = 0;
  1006.                }
  1007.             }
  1008.          
  1009.          // if we have something fetch its size
  1010.          
  1011.          if (CutBmp[CutIndex].CutFlag)
  1012.             {
  1013.             GetObject(CutBmp[CutIndex].CutMemoryBitMap, sizeof (BITMAP), (LPSTR)&temp);
  1014.             CutBmp[CutIndex].CutWidth = temp.bmWidth;
  1015.             CutBmp[CutIndex].CutHeight = temp.bmHeight;
  1016.             }
  1017.          }
  1018.       
  1019.       // only if we have a surface to fit to and from continue
  1020.       
  1021.       if ((FitWidth != 0) && (FitHeight != 0) && CutBmp[CutIndex].CutFlag)
  1022.          {
  1023.          
  1024.          ScreenDC = GetDC(MainHWindow);
  1025.          
  1026.          MemDC = CreateCompatibleDC(ScreenDC);
  1027.          OldBitmap = (HBITMAP)SelectObject(MemDC, CutBmp[CutIndex].CutMemoryBitMap);
  1028.          
  1029.          if (EnablePalette)
  1030.             {
  1031.             OldPalette2 = SelectPalette(ScreenDC, ThePalette, FALSE);
  1032.             RealizePalette(ScreenDC);
  1033.             
  1034.             OldPalette = SelectPalette(MemDC, ThePalette, FALSE);
  1035.             RealizePalette(MemDC);
  1036.             }
  1037.          
  1038.          TempMemoryBitMap = CreateCompatibleBitmap(ScreenDC, (int)(FitWidth), (int)(FitHeight));
  1039.          if (!TempMemoryBitMap) MessageBox(MainHWindow, "Fit failed, Possibly not enough Memory", "Error", MB_OK | MB_ICONEXCLAMATION);
  1040.          
  1041.          TempMemDC = CreateCompatibleDC(ScreenDC);
  1042.          OldBitmap2 = (HBITMAP)SelectObject(TempMemDC, TempMemoryBitMap);
  1043.          
  1044.          if (EnablePalette) SelectPalette(ScreenDC, OldPalette2, FALSE);
  1045.          ReleaseDC(MainHWindow,ScreenDC);
  1046.          
  1047.          if (EnablePalette)
  1048.             {
  1049.             OldPalette2 = SelectPalette(TempMemDC, ThePalette, FALSE);
  1050.             RealizePalette(TempMemDC);
  1051.             }
  1052.          
  1053.          SetStretchBltMode(TempMemDC,COLORONCOLOR);
  1054.          
  1055.          // Load hour-glass cursor.
  1056.          hCursor = SetCursor(hCursorWait);
  1057.          
  1058.          StretchBlt(TempMemDC,
  1059.          0,
  1060.          0,
  1061.          FitWidth,
  1062.          FitHeight,
  1063.          MemDC,
  1064.          0,
  1065.          0,
  1066.          CutBmp[CutIndex].CutWidth,
  1067.          CutBmp[CutIndex].CutHeight,
  1068.          SRCCOPY);
  1069.          
  1070.          // Reload arrow cursor.
  1071.          SetCursor(hCursor);
  1072.          
  1073.          if (EnablePalette)
  1074.             {
  1075.             SelectPalette(MemDC, OldPalette, FALSE);
  1076.             SelectPalette(TempMemDC, OldPalette2, FALSE);
  1077.             }
  1078.          
  1079.          SelectObject(TempMemDC, OldBitmap2);
  1080.          DeleteDC(TempMemDC);
  1081.          
  1082.          SelectObject(MemDC, OldBitmap);
  1083.          DeleteDC(MemDC);
  1084.          
  1085.          DeleteObject(CutBmp[CutIndex].CutMemoryBitMap);
  1086.          CutBmp[CutIndex].CutMemoryBitMap = TempMemoryBitMap;
  1087.          
  1088.          CutBmp[CutIndex].CutWidth  = FitWidth;
  1089.          CutBmp[CutIndex].CutHeight = FitHeight;
  1090.          
  1091.          if (CutIndex == 0)
  1092.             {
  1093.             OpenClipboard(MainHWindow);
  1094.             EmptyClipboard();
  1095.             SetClipboardData(CF_BITMAP, CutBmp[CutIndex].CutMemoryBitMap);
  1096.             if (EnablePalette)
  1097.                {
  1098.                SetClipboardData(CF_DIB, BitmapToDIB(CutBmp[CutIndex].CutMemoryBitMap,ThePalette));
  1099.                SetClipboardData(CF_PALETTE, CreatePalette(MyLogPalette));
  1100.                }
  1101.             else
  1102.                {
  1103.                SetClipboardData(CF_DIB, BitmapToDIB(CutBmp[CutIndex].CutMemoryBitMap,NULL));
  1104.                }
  1105.             CloseClipboard();
  1106.             CutBmp[CutIndex].CutFlag = 0;
  1107.             }
  1108.          }
  1109.       }
  1110.    return(UNBOUND);
  1111.    }
  1112.  
  1113. NODE *lbitpaste(void) /*routine*/
  1114.    {
  1115.    HDC ScreenDC;
  1116.    HDC MemDC;
  1117.    HDC TempMemDC;
  1118.    
  1119.    RECT TempRect;
  1120.    
  1121.    BITMAP temp;
  1122.    
  1123.    HANDLE TempDIB;
  1124.    
  1125.    HPALETTE TempPal;
  1126.    
  1127.    int DeleteBitMapWhenDone;
  1128.    
  1129.    if (NOT_THROWING)
  1130.       {
  1131.       
  1132.       DeleteBitMapWhenDone = 0;
  1133.       
  1134.       // If ClipBoard check with ClipBoard only
  1135.       
  1136.       if (CutIndex == 0)
  1137.          {
  1138.          
  1139.          OpenClipboard(MainHWindow);
  1140.          
  1141.          // Try a DIB first
  1142.          
  1143.          TempDIB = (HBITMAP) GetClipboardData(CF_DIB);
  1144.          
  1145.          // If Success try for a palette too
  1146.          
  1147.          if (TempDIB != NULL)
  1148.             {
  1149.             TempPal = (HPALETTE) GetClipboardData(CF_PALETTE);
  1150.             
  1151.             // we have everything we need
  1152.             
  1153.             CloseClipboard();
  1154.             
  1155.             // we work in bmps here
  1156.             
  1157.             CutBmp[CutIndex].CutMemoryBitMap = DIBToBitmap(TempDIB, TempPal);
  1158.             
  1159.             // Fill our logical palette with the Palette from the clipboard
  1160.             
  1161.             if (EnablePalette && (TempPal != NULL))
  1162.                {
  1163.                GetPaletteEntries(TempPal, 0, 255, &(MyLogPalette->palPalEntry[0]));
  1164.                
  1165.                // now rebuild palette
  1166.                
  1167.                DeleteObject(ThePalette);
  1168.                ThePalette = CreatePalette(MyLogPalette);
  1169.                if (status_flag) update_status_paletteuse();
  1170.                }
  1171.             
  1172.             // Let code know below that we have something
  1173.             
  1174.             CutBmp[CutIndex].CutFlag = 1;
  1175.             
  1176.             // We created a BitMap from the DIB that we only need for the
  1177.             // purpose of this "paste", next paste could be something new.
  1178.             // so get rid of it once we have pasted it here.
  1179.             
  1180.             DeleteBitMapWhenDone = 1;
  1181.             }
  1182.          
  1183.          // else try for a bitmap
  1184.          
  1185.          else
  1186.             {
  1187.             CutBmp[CutIndex].CutMemoryBitMap = (HBITMAP) GetClipboardData(CF_BITMAP);
  1188.             
  1189.             // where done whether they have it or not
  1190.             
  1191.             CloseClipboard();
  1192.             
  1193.             // flag that we have one if it exists, no need to delete the
  1194.             // bitmap here because clipboard still owns it.
  1195.             
  1196.             if (CutBmp[CutIndex].CutMemoryBitMap != NULL)
  1197.                {
  1198.                CutBmp[CutIndex].CutFlag = 1;
  1199.                }
  1200.             else
  1201.                {
  1202.                CutBmp[CutIndex].CutFlag = 0;
  1203.                }
  1204.             }
  1205.          
  1206.          // if we have something fetch its size
  1207.          
  1208.          if (CutBmp[CutIndex].CutFlag)
  1209.             {
  1210.             GetObject(CutBmp[CutIndex].CutMemoryBitMap, sizeof (BITMAP), (LPSTR)&temp);
  1211.             CutBmp[CutIndex].CutWidth = temp.bmWidth;
  1212.             CutBmp[CutIndex].CutHeight = temp.bmHeight;
  1213.             }
  1214.          }
  1215.       
  1216.       // only if we have something to paste
  1217.       
  1218.       if (CutBmp[CutIndex].CutFlag)
  1219.          {
  1220.          
  1221.          // if clipboard then never leave Cut Flag true
  1222.          
  1223.          if (CutIndex == 0) CutBmp[CutIndex].CutFlag = 0;
  1224.          
  1225.          ScreenDC = GetDC(MainHWindow);
  1226.          
  1227.          TempMemDC = CreateCompatibleDC(ScreenDC);
  1228.          OldBitmap2 = (HBITMAP)SelectObject(TempMemDC, CutBmp[CutIndex].CutMemoryBitMap);
  1229.          
  1230.          //memory
  1231.          
  1232.          MemDC = CreateCompatibleDC(ScreenDC);
  1233.          OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  1234.          
  1235.          BitBlt(MemDC,
  1236.          +turtle_x+xoffset,
  1237.          -turtle_y+yoffset-CutBmp[CutIndex].CutHeight,
  1238.          (int)(CutBmp[CutIndex].CutWidth),
  1239.          (int)(CutBmp[CutIndex].CutHeight),
  1240.          TempMemDC, 0, 0, bitmode);
  1241.          
  1242.          SelectObject(MemDC, OldBitmap);
  1243.          DeleteDC(MemDC);
  1244.          
  1245.          //screen
  1246.          
  1247.          if (turtle_shown) ibmturt(0);
  1248.          
  1249.          if (zoom_flag)
  1250.             {
  1251.             SetMapMode(ScreenDC, MM_ANISOTROPIC);
  1252.             SetWindowOrg(ScreenDC, 0, 0);
  1253.             SetWindowExt(ScreenDC, BitMapWidth, BitMapHeight);
  1254.             SetViewportOrg(ScreenDC, 0, 0);
  1255.             SetViewportExt(ScreenDC, (int)(BitMapWidth*the_zoom), (int)(BitMapHeight*the_zoom));
  1256.             }
  1257.          
  1258.          //         SetCapture(MainHWindow);
  1259.          
  1260.          //         SetRect(&TempRect,
  1261.          //         +turtle_x-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom+xoffset,
  1262.          //         -turtle_y-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom+yoffset-CutBmp[CutIndex].CutHeight,
  1263.          //         +turtle_x-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom+xoffset+CutBmp[CutIndex].CutWidth,
  1264.          //         -turtle_y-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom+yoffset);
  1265.          
  1266.          BitBlt(ScreenDC,
  1267.          +turtle_x-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom+xoffset,
  1268.          -turtle_y-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom+yoffset-CutBmp[CutIndex].CutHeight,
  1269.          (int)(CutBmp[CutIndex].CutWidth),
  1270.          (int)(CutBmp[CutIndex].CutHeight),
  1271.          TempMemDC, 0, 0, bitmode);
  1272.          
  1273.          //         ReleaseCapture();
  1274.          ReleaseDC(MainHWindow, ScreenDC);
  1275.          
  1276.          if (turtle_shown) ibmturt(0);
  1277.          
  1278.          SelectObject(TempMemDC, OldBitmap2);
  1279.          DeleteDC(TempMemDC);
  1280.          
  1281.          // Clipboard owns what we paste in not what we converted
  1282.          
  1283.          if (DeleteBitMapWhenDone) DeleteObject(CutBmp[CutIndex].CutMemoryBitMap);
  1284.          }
  1285.       else
  1286.          {
  1287.          MessageBox(MainHWindow, "Nothing to Paste", "Error", MB_OK | MB_ICONEXCLAMATION);
  1288.          }
  1289.       }
  1290.    return(UNBOUND);
  1291.    }
  1292.  
  1293. NODE *lscrollx(NODE *arg) /*routine*/
  1294.    {
  1295.    int delta;
  1296.    
  1297.    // get args and scroll the scroller
  1298.    
  1299.    delta = getint(numeric_arg(arg));
  1300.    
  1301.    ((TMyWindow *)MainWindowx)->Scroller->ScrollTo(
  1302.    ((TMyWindow *)MainWindowx)->Scroller->XPos+delta,
  1303.    ((TMyWindow *)MainWindowx)->Scroller->YPos);
  1304.    
  1305.    return(UNBOUND);
  1306.    }
  1307.  
  1308. NODE *lscrolly(NODE *arg) /*routine*/
  1309.    {
  1310.    int delta;
  1311.    
  1312.    // get args and scroll the scroller
  1313.    
  1314.    delta = getint(numeric_arg(arg));
  1315.    
  1316.    ((TMyWindow *)MainWindowx)->Scroller->ScrollTo(
  1317.    ((TMyWindow *)MainWindowx)->Scroller->XPos,
  1318.    ((TMyWindow *)MainWindowx)->Scroller->YPos+delta);
  1319.    
  1320.    return(UNBOUND);
  1321.    }
  1322.  
  1323. NODE *lsetfocus(NODE *arg) /*routine*/
  1324.    {
  1325.    char textbuf[MAX_BUFFER_SIZE];
  1326.    
  1327.    HWND EditH;
  1328.    
  1329.    cnv_strnode_string(textbuf,arg);
  1330.    
  1331.    // get handle to Window with arg as Caption   
  1332.    
  1333.    EditH = FindWindow(NULL, textbuf);
  1334.    
  1335.    // Now set focus to it, if it exists
  1336.    
  1337.    if (EditH != NULL)
  1338.       {
  1339.       SetFocus(EditH);
  1340.       }
  1341.    
  1342.    JustDidEdit = 1;
  1343.    
  1344.    return(UNBOUND);
  1345.    }
  1346.  
  1347. NODE *lgetfocus(void) /*routine*/
  1348.    {
  1349.    NODE *arg, *val = UNBOUND;
  1350.    char textbuf[MAX_BUFFER_SIZE];
  1351.    
  1352.    int i;
  1353.    
  1354.    HWND TempH;
  1355.    
  1356.    //??
  1357.    
  1358.    for (i=0;i<MAX_BUFFER_SIZE;i++) textbuf[i] = '\0';
  1359.    
  1360.    // Get handle to active window
  1361.    
  1362.    TempH = GetActiveWindow();
  1363.    
  1364.    // It better exist, get it's caption
  1365.    
  1366.    if (TempH != NULL)
  1367.       {
  1368.       GetWindowText(TempH, textbuf, MAX_BUFFER_SIZE);
  1369.       }
  1370.    
  1371.    JustDidEdit = 1;
  1372.    
  1373.    // Return caption as a list
  1374.    
  1375.    arg = make_strnode(textbuf, NULL, strlen(textbuf), STRING, strnzcpy);
  1376.    val = parser(arg, FALSE);
  1377.    return(val);
  1378.    
  1379.    }
  1380.  
  1381. NODE *licon(NODE *arg) /*routine*/
  1382.    {
  1383.    char textbuf[MAX_BUFFER_SIZE];
  1384.    
  1385.    HWND EditH;
  1386.    
  1387.    cnv_strnode_string(textbuf,arg);
  1388.    
  1389.    // get handle to Window with arg as Caption   
  1390.    
  1391.    EditH = FindWindow(NULL, textbuf);
  1392.    
  1393.    // if it exists icon it.
  1394.    
  1395.    if (EditH != NULL)
  1396.       {
  1397.       CloseWindow(EditH);
  1398.       }
  1399.    
  1400.    JustDidEdit = 1;
  1401.    
  1402.    return(UNBOUND);
  1403.    }
  1404.  
  1405. NODE *lunicon(NODE *arg) /*routine*/
  1406.    {
  1407.    char textbuf[MAX_BUFFER_SIZE];
  1408.    
  1409.    HWND EditH;
  1410.    
  1411.    cnv_strnode_string(textbuf,arg);
  1412.    
  1413.    // get handle to Window with arg as Caption   
  1414.    
  1415.    EditH = FindWindow(NULL, textbuf);
  1416.    
  1417.    // if it exists unicon it.
  1418.    
  1419.    if (EditH != NULL)
  1420.       {
  1421.       OpenIcon(EditH);
  1422.       }
  1423.    
  1424.    JustDidEdit = 1;
  1425.    
  1426.    return(UNBOUND);
  1427.    }
  1428.  
  1429. void ibm_clear_screen(void) /*routine*/
  1430.    {
  1431.    HDC TempDC;
  1432.    HDC MemDC;
  1433.    
  1434.    HBRUSH TempBrush;
  1435.    
  1436.    TempBrush = CreateBrushIndirect(&ScreenBrush);
  1437.    TempDC = GetDC(MainHWindow);
  1438.    
  1439.    // screen
  1440.    
  1441.    if (zoom_flag)
  1442.       {
  1443.       SetMapMode(TempDC, MM_ANISOTROPIC);
  1444.       SetWindowOrg(TempDC, 0, 0);
  1445.       SetWindowExt(TempDC, BitMapWidth, BitMapHeight);
  1446.       SetViewportOrg(TempDC, 0, 0);
  1447.       SetViewportExt(TempDC, (int)(BitMapWidth*the_zoom), (int)(BitMapHeight*the_zoom));
  1448.       }
  1449.    
  1450.    FillRect(TempDC, &TempRect, TempBrush);
  1451.    SetBkColor(TempDC, scolor);
  1452.    SetBkMode(TempDC, TRANSPARENT);
  1453.    
  1454.    // memory
  1455.    
  1456.    MemDC = CreateCompatibleDC(TempDC);
  1457.    OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  1458.    
  1459.    FillRect(MemDC, &FullRect, TempBrush);
  1460.    
  1461.    SetBkColor(MemDC, scolor);
  1462.    SetBkMode(MemDC, TRANSPARENT);
  1463.    
  1464.    SelectObject(MemDC, OldBitmap);
  1465.    DeleteDC(MemDC);
  1466.    
  1467.    ReleaseDC(MainHWindow, TempDC);
  1468.    DeleteObject(TempBrush);
  1469.    }
  1470.  
  1471. void option_helper(short *var, NODE *arg)
  1472.    {
  1473.    NODE *val;
  1474.    
  1475.    val = integer_arg(arg);
  1476.    if (NOT_THROWING)
  1477.    *var = (short)getint(val);
  1478.    }
  1479.  
  1480. int FAR PASCAL _export EnumerateFont( LPLOGFONT LogFont, LPTEXTMETRIC, short, LPSTR)
  1481.    {
  1482.    
  1483.    // if printflag just print the enumerated font
  1484.    
  1485.    if (printflag == 1)
  1486.       {
  1487.       printfx("[%s]\n",LogFont->lfFaceName);
  1488.       }
  1489.    
  1490.    // else chcek for a match
  1491.    
  1492.    else
  1493.       {
  1494.       if (stricmp(tempfont,LogFont->lfFaceName) == 0)
  1495.          {
  1496.          
  1497.          // take a copy, flag one was found and return
  1498.          
  1499.          memcpy(&FontRec,LogFont,sizeof(FontRec));
  1500.          found = 1;
  1501.          return 0;
  1502.          }
  1503.       }
  1504.    
  1505.    NumFonts++;
  1506.    
  1507.    if (NumFonts > MaxNumFonts)
  1508.       {
  1509.       return 0;  /* Don't send any more information */
  1510.       }
  1511.    else
  1512.       {
  1513.       return 1; /* Send more information if available */
  1514.       }
  1515.    
  1516.    };
  1517.  
  1518. /* Collect all of the system fonts */
  1519.  
  1520. void GetFontInfo()
  1521.    {
  1522.    HDC TheDC;
  1523.    
  1524.    OLDFONTENUMPROC EnumProc;
  1525.    
  1526.    TheDC = GetDC(GetFocus());
  1527.    NumFonts = 0;
  1528.    
  1529.    /* Create an instance of the call back function.  This allows
  1530.    our program to refer to an exported function.  Otherwise the
  1531.    Data segment will not be correct. */
  1532.    
  1533.    EnumProc = (OLDFONTENUMPROC)MakeProcInstance((FARPROC) EnumerateFont, GetApplicationObject()->hInstance);
  1534.    
  1535.    /* Gather information about all fonts that are allowable in our window (DC) */
  1536.    
  1537.    EnumFonts(TheDC, NULL, EnumProc, NULL);
  1538.    
  1539.    /* Free the instance of our call back function */
  1540.    
  1541.    FreeProcInstance((FARPROC)EnumProc);
  1542.    ReleaseDC(GetFocus(), TheDC);
  1543.    
  1544.    };
  1545.  
  1546. void setfont(char *s)
  1547.    {
  1548.    found = 0;
  1549.    printflag = 0;
  1550.    
  1551.    // set global font to compare to (FontRec will get filled if found)
  1552.    
  1553.    tempfont=s;
  1554.    
  1555.    GetFontInfo();
  1556.    
  1557.    // if not found enumerate again with printing enabled
  1558.    
  1559.    if (!found)
  1560.       {
  1561.       printfx("Sorry, %s Font does not exist, choose one of the following:\n\n",s);
  1562.       printflag = 1;
  1563.       GetFontInfo();
  1564.       }
  1565.    
  1566.    }
  1567.  
  1568. void do_help(char *arg)
  1569.    { 
  1570.    
  1571.    /* if arg NULL then jump to index else try to lookup key */
  1572.    
  1573.    if (arg == NULL) WinHelp(MainHWindow,szHelpFileName,HELP_INDEX,0L);
  1574.    else WinHelp(MainHWindow,szHelpFileName,HELP_KEY,(DWORD)arg);
  1575.    JustDidEdit = 1;
  1576.    }
  1577.  
  1578. NODE *lhelp(NODE *arg)
  1579.    {
  1580.    char textbuf[MAX_BUFFER_SIZE];
  1581.    
  1582.    // if arg then pass to do_help
  1583.    
  1584.    if (arg != NIL)
  1585.       {
  1586.       cnv_strnode_string(textbuf,arg);
  1587.       
  1588.       do_help(textbuf);
  1589.       }
  1590.    
  1591.    // else just pop up help
  1592.    
  1593.    else
  1594.       {
  1595.       do_help(NULL);
  1596.       }
  1597.    
  1598.    return (UNBOUND);
  1599.    }
  1600.  
  1601. NODE *lwinhelp(NODE *arg)
  1602.    {
  1603.    char textbuf[MAX_BUFFER_SIZE];
  1604.    char textbuf2[MAX_BUFFER_SIZE];
  1605.    
  1606.    cnv_strnode_string(textbuf,arg);
  1607.    
  1608.    // if 2nd arg then pass to winhelp
  1609.    
  1610.    if (cdr(arg) != NIL)
  1611.       {
  1612.       cnv_strnode_string(textbuf2,cdr(arg));
  1613.       WinHelp(MainHWindow,textbuf,HELP_KEY,(DWORD)textbuf2);
  1614.       }
  1615.    
  1616.    // else just give help on file (arg 1)
  1617.    
  1618.    else
  1619.       {   
  1620.       WinHelp(MainHWindow,textbuf,HELP_INDEX,0L);
  1621.       }
  1622.    
  1623.    return (UNBOUND);
  1624.    }
  1625.  
  1626. NODE *lsettextfont(NODE *arg)
  1627.    {
  1628.    NODE *args;
  1629.    char textbuf[MAX_BUFFER_SIZE];
  1630.    
  1631.    args = car(arg);
  1632.    
  1633.    if (is_list(args))
  1634.       {
  1635.       cnv_strnode_string(textbuf,args);
  1636.       
  1637.       // Get the FontRec filled with a match to textbuff
  1638.       
  1639.       setfont(textbuf);
  1640.       
  1641.       // now fill in the rest of the fields if given
  1642.       
  1643.       if (cdr(args) != NIL)
  1644.       FontRec.lfHeight         = int_arg(args=cdr(args));
  1645.       if (cdr(args) != NIL)
  1646.       FontRec.lfWeight         = getint(pos_int_arg(args=cdr(args)));
  1647.       if (cdr(args) != NIL)
  1648.       FontRec.lfItalic         = getint(pos_int_arg(args=cdr(args)));
  1649.       if (cdr(args) != NIL)
  1650.       FontRec.lfUnderline      = getint(pos_int_arg(args=cdr(args)));
  1651.       if (cdr(args) != NIL)
  1652.       FontRec.lfStrikeOut      = getint(pos_int_arg(args=cdr(args)));
  1653.       
  1654.       // update status window
  1655.       
  1656.       if (status_flag)
  1657.          {
  1658.          update_status_fontwieght();
  1659.          update_status_fontsize();
  1660.          update_status_fontname();
  1661.          }
  1662.       }
  1663.    
  1664.    return(UNBOUND);
  1665.    }
  1666.  
  1667. NODE *ltextfont(void)
  1668.    {
  1669.    NODE *targ, *val = UNBOUND;
  1670.    
  1671.    // put the Font name in a list
  1672.    
  1673.    targ = make_strnode(FontRec.lfFaceName, NULL, strlen(FontRec.lfFaceName), STRING, strnzcpy);
  1674.    val = parser(targ, FALSE);
  1675.    
  1676.    // now return the whole thing as a list
  1677.    
  1678.    return(
  1679.    cons(val,
  1680.    cons(make_intnode((FIXNUM)FontRec.lfHeight),
  1681.    cons(make_intnode((FIXNUM)FontRec.lfWeight),
  1682.    cons(make_intnode((FIXNUM)FontRec.lfItalic),
  1683.    cons(make_intnode((FIXNUM)FontRec.lfUnderline),
  1684.    cons(make_intnode((FIXNUM)FontRec.lfStrikeOut),
  1685.    NIL
  1686.    )))))));
  1687.    
  1688.    }
  1689.  
  1690. NODE *lmachine(void)
  1691.    {
  1692.    NODE *targ, *val = UNBOUND;
  1693.    
  1694.    // build list with system specific information
  1695.    
  1696.    return(
  1697.    cons(make_intnode((FIXNUM)1),
  1698. #ifdef ISWIN31
  1699.    cons(make_intnode((FIXNUM)31),
  1700. #else
  1701.    cons(make_intnode((FIXNUM)30),
  1702. #endif
  1703.    cons(make_intnode((FIXNUM)BitMapWidth),
  1704.    cons(make_intnode((FIXNUM)BitMapHeight),
  1705.    cons(make_intnode((FIXNUM)EnablePalette),
  1706.    NIL
  1707.    ))))));
  1708.    
  1709.    }
  1710.  
  1711. void label(char *s)
  1712.    {
  1713.    HDC ScreenDC;
  1714.    HDC MemDC;
  1715.    
  1716.    HFONT TempFont;
  1717.    
  1718.    ScreenDC = GetDC(MainHWindow);
  1719.    
  1720.    FontRec.lfEscapement = (360.0-(turtle_heading-90.0))*10;
  1721.    TempFont = CreateFontIndirect(&FontRec);
  1722.    
  1723.    // memory
  1724.    
  1725.    MemDC = CreateCompatibleDC(ScreenDC);
  1726.    OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  1727.    
  1728.    if (EnablePalette)
  1729.       {
  1730.       OldPalette = SelectPalette(MemDC, ThePalette, FALSE);
  1731.       RealizePalette(MemDC);
  1732.       }
  1733.    
  1734.    SetBkColor(MemDC, scolor);
  1735.    SetBkMode(MemDC, TRANSPARENT);
  1736.    SetTextColor(MemDC,pcolor);
  1737.    
  1738.    OldFont = (HFONT)SelectObject(MemDC,TempFont);
  1739.    
  1740.    TextOut(MemDC,
  1741.    +turtle_x+xoffset,
  1742.    -turtle_y+yoffset,
  1743.    s,strlen(s));
  1744.    
  1745.    if (EnablePalette) SelectPalette(MemDC, OldPalette, FALSE);
  1746.    SelectObject(MemDC, OldFont);
  1747.    SelectObject(MemDC, OldBitmap);
  1748.    DeleteDC(MemDC);
  1749.    
  1750.    //screen
  1751.    
  1752.    if (zoom_flag)
  1753.       {
  1754.       SetMapMode(ScreenDC, MM_ANISOTROPIC);
  1755.       SetWindowOrg(ScreenDC, 0, 0);
  1756.       SetWindowExt(ScreenDC, BitMapWidth, BitMapHeight);
  1757.       SetViewportOrg(ScreenDC, 0, 0);
  1758.       SetViewportExt(ScreenDC, (int)(BitMapWidth*the_zoom), (int)(BitMapHeight*the_zoom));
  1759.       }
  1760.    
  1761.    //   SetCapture(MainHWindow);
  1762.    
  1763.    if (EnablePalette)
  1764.       {
  1765.       OldPalette = SelectPalette(ScreenDC, ThePalette, FALSE);
  1766.       RealizePalette(ScreenDC);
  1767.       }
  1768.    
  1769.    SetBkColor(ScreenDC, scolor);
  1770.    SetBkMode(ScreenDC, TRANSPARENT);
  1771.    SetTextColor(ScreenDC,pcolor);
  1772.    
  1773.    OldFont = (HFONT)SelectObject(ScreenDC,TempFont);
  1774.    
  1775.    TextOut(ScreenDC,
  1776.    +turtle_x-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom+xoffset,
  1777.    -turtle_y-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom+yoffset,
  1778.    s,strlen(s));
  1779.    
  1780.    SelectObject(ScreenDC, OldFont);
  1781.    if (EnablePalette) SelectPalette(ScreenDC, OldPalette, FALSE);
  1782.    
  1783.    DeleteObject(TempFont);
  1784.    
  1785.    //   ReleaseCapture();
  1786.    ReleaseDC(MainHWindow, ScreenDC);
  1787.    
  1788.    }
  1789.  
  1790. void exit_program(void)
  1791.    { 
  1792.    if (halt_flag != 0) Time_To_Halt = 1;
  1793.    Time_To_Exit = 1;
  1794.    }
  1795.  
  1796. NODE *lpeek(NODE *arg) /*routine*/
  1797.    {
  1798.    int seg;
  1799.    int off;
  1800.    int dat;   
  1801.    
  1802.    seg = getint(pos_int_arg(arg));
  1803.    off = getint(pos_int_arg(cdr(arg)));
  1804.    
  1805.    if (seg == 1) dat = peek(seg,off);
  1806.    //   if (seg == 2) dat = lpeek(seg,off);
  1807. #undef peek
  1808.    if (seg == 2) dat = peek(seg,off);
  1809.    //   if (seg == 4) dat = lpeek(seg,off);
  1810.    
  1811.    return(make_intnode((FIXNUM)dat));
  1812.    }
  1813.  
  1814. NODE *lpoke(NODE *arg) /*routine*/
  1815.    {
  1816.    int seg;
  1817.    int off;
  1818.    int dat;   
  1819.    
  1820.    seg = getint(pos_int_arg(arg));
  1821.    off = getint(pos_int_arg(arg=cdr(arg)));
  1822.    dat = getint(pos_int_arg(cdr(arg)));
  1823.    
  1824.    poke(seg,off,dat);
  1825.    
  1826.    return(UNBOUND);
  1827.    }
  1828.