Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 28.90 KB | None | 0 0
  1. #include "common.h"
  2. #include "ui.h"
  3. #include "edit.h"
  4. #include "dialog.h"
  5. #include "search.h"
  6.  
  7. void MsgBox(void *n, char *title, char *message)
  8. /* Message Box function */
  9. {
  10.     State *s;
  11.     s = (State *)n;
  12.     if(s -> ischildwindow > 0)
  13.         return;
  14.     InitChildhead(n);
  15.     s -> ischildwindow = 99;
  16.     CleanUp(n);
  17.     if(!s -> dotted)
  18.     {
  19.         setactivepage(!s -> page);
  20.         DrawMainWindow(n);
  21.         DrawStatusBox(n);
  22.         DoEvent(s -> redraw, n);
  23.         CleanUp(n);
  24.         setvisualpage(!s -> page);
  25.         s -> page = !s -> page;
  26.     }
  27.     else
  28.     {
  29.         DrawMainWindow(n);
  30.         DrawStatusBox(n);
  31.         s -> isedit = 0;
  32.         CheckStatus(n);
  33.         s -> isedit = 1;
  34.         DoEvent(s -> redraw, n);
  35.         CleanUp(n);
  36.     }
  37.     /* Do a redraw before draw it */
  38.    
  39.     CleanUp(n);
  40.     s -> childx1 = 120, s -> childy1 = 120;
  41.     s -> childx2 = 360, s -> childy2 = 200;
  42.     DrawWindow(n, s -> childx1, s -> childy1, s -> childx2, s -> childy2, title);
  43.     OutTextxy(n, s -> childx1 + 7, s -> childy1 + 27, message, 0);
  44.     DrawButton(n, s -> childx1 + 25, s -> childy2 - 30,
  45.                   s -> childx1 + 120, s -> childy2 - 5, "确定(Enter)");
  46.     /* Only one button to close the message box */
  47.    
  48.     CleanUp(n);
  49.     /* Restore the mouse */
  50.    
  51.     s -> isedit = 0;
  52.     /* Message Box does not allow editing operations */
  53. }
  54.  
  55. void DrawOpenWindow(void *n)
  56. /* Draw "Open" window */
  57. {
  58.     State *s;
  59.     s = (State *)n;
  60.     if(s -> ischildwindow > 0)
  61.         return;
  62.    
  63.     InitChildhead(n);
  64.     /* Hide mouse to solve some bugs */
  65.    
  66.     s -> isedit = 1;
  67.     if(!s -> ischildwindow)
  68.     {
  69.         s -> childx1 = 120, s -> childy1 = 120;
  70.         s -> childx2 = 360, s -> childy2 = 200;
  71.         /* Set the position of the window */
  72.        
  73.         s -> editx1 = s -> childx1 + 77, s -> edity1 = s -> childy1 + 27;
  74.         s -> editx2 = s -> childx2 - 10, s -> edity2 = s -> childy1 + 43;
  75.         if(s -> filehead == NULL)
  76.         {
  77.             s -> cursorx = s -> editx1;
  78.             s -> cursory = s -> edity1;
  79.         }
  80.     }
  81.     s -> ischildwindow = 1;
  82.     CleanUp(n);
  83.     if(!s -> dotted)
  84.     {
  85.         setactivepage(!s -> page);
  86.         DrawMainWindow(n);
  87.         DrawStatusBox(n);
  88.         DoEvent(s -> redraw, n);
  89.         CleanUp(n);
  90.         setvisualpage(!s -> page);
  91.         s -> page = !s -> page;
  92.     }
  93.     else
  94.     {
  95.         DrawMainWindow(n);
  96.         DrawStatusBox(n);
  97.         s -> isedit = 0;
  98.         CheckStatus(n);
  99.         s -> isedit = 1;
  100.         DoEvent(s -> redraw, n);
  101.         CleanUp(n);
  102.     }
  103.     /* Do a redraw before draw it */
  104.    
  105.     CleanUp(n);
  106.    
  107.     DrawWindow(n, s -> childx1, s -> childy1, s -> childx2, s -> childy2, "打开文件...");
  108.     OutTextxy(n, s -> childx1 + 7, s -> childy1 + 27, "文件名:", 0);
  109.     DrawTextBox(s -> childx1 + 75, s -> childy1 + 25,
  110.                 s -> childx2 - 7, s -> childy1 + 45);
  111.     DrawButton(n, s -> childx1 + 5, s -> childy2 - 30,
  112.                   s -> childx1 + 65, s -> childy2 - 5, "打开(O)");
  113.     DrawButton(n, s -> childx1 + 70, s -> childy2 - 30,
  114.                   s -> childx1 + 130, s -> childy2 - 5, "取消(C)");
  115.     /* Draw all form elements */
  116.    
  117.     CleanUp(n);
  118.     /* Restore the mouse */
  119. }
  120.  
  121. void DrawSaveWindow(void *n)
  122. /* Draw "Save" window */
  123. {
  124.     State *s;
  125.     s = (State *)n;
  126.     if(s -> ischildwindow > 0)
  127.         return;
  128.        
  129.     if(s -> filename[0] != 0)
  130.     {
  131.         //SaveFile(n);
  132.         return;
  133.     }
  134.    
  135.     InitChildhead(n);
  136.    
  137.     s -> isedit = 1;
  138.     if(!s -> ischildwindow)
  139.     {
  140.         s -> childx1 = 120, s -> childy1 = 120;
  141.         s -> childx2 = 360, s -> childy2 = 200;
  142.        
  143.         s -> editx1 = s -> childx1 + 77, s -> edity1 = s -> childy1 + 27;
  144.         s -> editx2 = s -> childx2 - 10, s -> edity2 = s -> childy1 + 43;
  145.         if(s -> filehead == NULL)
  146.         {  
  147.             s -> cursorx = s -> editx1;
  148.             s -> cursory = s -> edity1;
  149.         }
  150.     }    
  151.     s -> ischildwindow = 2;
  152.     CleanUp(n);
  153.     if(!s -> dotted)
  154.     {
  155.         setactivepage(!s -> page);
  156.         DrawMainWindow(n);
  157.         DrawStatusBox(n);
  158.         DoEvent(s -> redraw, n);
  159.         CleanUp(n);
  160.         setvisualpage(!s -> page);
  161.         s -> page = !s -> page;
  162.     }
  163.     else
  164.     {
  165.         DrawMainWindow(n);
  166.         DrawStatusBox(n);
  167.         s -> isedit = 0;
  168.         CheckStatus(n);
  169.         s -> isedit = 1;
  170.         DoEvent(s -> redraw, n);
  171.         CleanUp(n);
  172.     }
  173.     /* Do a redraw before draw it */
  174.    
  175.     CleanUp(n);
  176.    
  177.     DrawWindow(n, s -> childx1, s -> childy1, s -> childx2, s -> childy2, "保存文件...");
  178.     OutTextxy(n, s -> childx1 + 7, s -> childy1 + 27, "文件名:", 0);
  179.     DrawTextBox(s -> childx1 + 75, s -> childy1 + 25,
  180.                 s -> childx2 - 7, s -> childy1 + 45);
  181.     DrawButton(n, s -> childx1 + 5, s -> childy2 - 30,
  182.                   s -> childx1 + 65, s -> childy2 - 5, "保存(S)");
  183.     DrawButton(n, s -> childx1 + 70, s -> childy2 - 30,
  184.                   s -> childx1 + 130, s -> childy2 - 5, "取消(C)");
  185.     CleanUp(n);
  186. }
  187.  
  188. void DrawSaveAsWindow(void *n)
  189. /* Draw "Save as" window */
  190. {
  191.     State *s;
  192.     s = (State *)n;
  193.     if(s -> ischildwindow > 0)
  194.         return;
  195.    
  196.     InitChildhead(n);
  197.    
  198.     s -> isedit = 1;
  199.     if(!s -> ischildwindow)
  200.     {
  201.         s -> childx1 = 120, s -> childy1 = 120;
  202.         s -> childx2 = 360, s -> childy2 = 200;
  203.        
  204.         s -> editx1 = s -> childx1 + 77, s -> edity1 = s -> childy1 + 27;
  205.         s -> editx2 = s -> childx2 - 10, s -> edity2 = s -> childy1 + 43;
  206.         if(s -> filehead == NULL)
  207.         {  
  208.             s -> cursorx = s -> editx1;
  209.             s -> cursory = s -> edity1;
  210.         }
  211.     }
  212.     s -> ischildwindow = 3;
  213.     CleanUp(n);
  214.     if(!s -> dotted)
  215.     {
  216.         setactivepage(!s -> page);
  217.         DrawMainWindow(n);
  218.         DrawStatusBox(n);
  219.         DoEvent(s -> redraw, n);
  220.         CleanUp(n);
  221.         setvisualpage(!s -> page);
  222.         s -> page = !s -> page;
  223.     }
  224.     else
  225.     {
  226.         DrawMainWindow(n);
  227.         DrawStatusBox(n);
  228.         s -> isedit = 0;
  229.         CheckStatus(n);
  230.         s -> isedit = 1;
  231.         DoEvent(s -> redraw, n);
  232.         CleanUp(n);
  233.     }
  234.     /* Do a redraw before draw it */
  235.    
  236.     CleanUp(n);
  237.    
  238.     DrawWindow(n, s -> childx1, s -> childy1, s -> childx2, s -> childy2, "文件另存为...");
  239.     OutTextxy(n, s -> childx1 + 7, s -> childy1 + 27, "文件名:", 0);
  240.     DrawTextBox(s -> childx1 + 75, s -> childy1 + 25,
  241.                 s -> childx2 - 7, s -> childy1 + 45);
  242.     DrawButton(n, s -> childx1 + 5, s -> childy2 - 30,
  243.                   s -> childx1 + 65, s -> childy2 - 5, "保存(S)");
  244.     DrawButton(n, s -> childx1 + 70, s -> childy2 - 30,
  245.                   s -> childx1 + 130, s -> childy2 - 5, "取消(C)");
  246.    
  247.     CleanUp(n);
  248. }
  249.  
  250. void DrawFindWindow(void *n)
  251. /* Draw "Find" window */
  252. {
  253.     State *s;
  254.     s = (State *)n;
  255.     if(s -> ischildwindow > 0)
  256.         return;
  257.    
  258.     InitChildhead(n);
  259.    
  260.     s -> isedit = 1;
  261.     if(!s -> ischildwindow)
  262.     {
  263.         s -> childx1 = 120, s -> childy1 = 120;
  264.         s -> childx2 = 360, s -> childy2 = 200;
  265.        
  266.         s -> editx1 = s -> childx1 + 92, s -> edity1 = s -> childy1 + 27;
  267.         s -> editx2 = s -> childx2 - 10, s -> edity2 = s -> childy1 + 43;
  268.         if(s -> filehead == NULL)
  269.         {  
  270.             s -> cursorx = s -> editx1;
  271.             s -> cursory = s -> edity1;
  272.         }
  273.     }
  274.     s -> ischildwindow = 4;
  275.     CleanUp(n);
  276.     if(!s -> dotted)
  277.     {
  278.         setactivepage(!s -> page);
  279.         DrawMainWindow(n);
  280.         DrawStatusBox(n);
  281.         DoEvent(s -> redraw, n);
  282.         CleanUp(n);
  283.         setvisualpage(!s -> page);
  284.         s -> page = !s -> page;
  285.     }
  286.     else
  287.     {
  288.         DrawMainWindow(n);
  289.         DrawStatusBox(n);
  290.         s -> isedit = 0;
  291.         CheckStatus(n);
  292.         s -> isedit = 1;
  293.         DoEvent(s -> redraw, n);
  294.         CleanUp(n);
  295.     }
  296.     /* Do a redraw before draw it */
  297.    
  298.     CleanUp(n);
  299.    
  300.     DrawWindow(n, s -> childx1, s -> childy1, s -> childx2, s -> childy2, "查找...");
  301.     OutTextxy(n, s -> childx1 + 7, s -> childy1 + 27, "查找内容:", 0);
  302.     DrawTextBox(s -> childx1 + 90, s -> childy1 + 25,
  303.                 s -> childx2 - 7, s -> childy1 + 45);
  304.     DrawButton(n, s -> childx1 + 5, s -> childy2 - 30,
  305.                   s -> childx1 + 65, s -> childy2 - 5, "查找(F)");
  306.     DrawButton(n, s -> childx1 + 70, s -> childy2 - 30,
  307.                   s -> childx1 + 130, s -> childy2 - 5, "取消(C)");
  308.    
  309.     CleanUp(n);
  310. }
  311.  
  312. void DrawReplaceWindow(void *n)
  313. /* Draw "Replace" window */
  314. {
  315.     State *s;
  316.     s = (State *)n;
  317.     if(s -> ischildwindow > 0)
  318.         return;
  319.    
  320.     InitChildhead(n);
  321.     InitChildhead2(n);
  322.    
  323.     s -> isedit = 1;
  324.     if(!s -> ischildwindow)
  325.     {
  326.         s -> childx1 = 120, s -> childy1 = 120;
  327.         s -> childx2 = 360, s -> childy2 = 225;
  328.        
  329.         s -> editx1 = s -> childx1 + 92, s -> edity1 = s -> childy1 + 27;
  330.         s -> editx2 = s -> childx2 - 10, s -> edity2 = s -> childy1 + 43;
  331.         if(s -> filehead == NULL)
  332.         {  
  333.             s -> cursorx = s -> editx1;
  334.             s -> cursory = s -> edity1;
  335.         }
  336.     }
  337.     s -> ischildwindow = 5;
  338.    
  339.     CleanUp(n);
  340.     if(!s -> dotted)
  341.     {
  342.         setactivepage(!s -> page);
  343.         DrawMainWindow(n);
  344.         DrawStatusBox(n);
  345.         DoEvent(s -> redraw, n);
  346.         CleanUp(n);
  347.         setvisualpage(!s -> page);
  348.         s -> page = !s -> page;
  349.     }
  350.     else
  351.     {
  352.         DrawMainWindow(n);
  353.         DrawStatusBox(n);
  354.         s -> isedit = 0;
  355.         CheckStatus(n);
  356.         s -> isedit = 1;
  357.         DoEvent(s -> redraw, n);
  358.         CleanUp(n);
  359.     }
  360.     /* Do a redraw before draw it */
  361.    
  362.     CleanUp(n);
  363.    
  364.     DrawWindow(n, s -> childx1, s -> childy1, s -> childx2, s -> childy2, "替换...");
  365.     OutTextxy(n, s -> childx1 + 7, s -> childy1 + 27, "查找内容:", 0);
  366.     OutTextxy(n, s -> childx1 + 7, s -> childy1 + 52, "替换为:", 0);
  367.     DrawTextBox(s -> childx1 + 90, s -> childy1 + 25,
  368.                 s -> childx2 - 7, s -> childy1 + 45);
  369.     DrawTextBox(s -> childx1 + 90, s -> childy1 + 50,
  370.                 s -> childx2 - 7, s -> childy1 + 70);
  371.     DrawButton(n, s -> childx1 + 5, s -> childy2 - 30,
  372.                   s -> childx1 + 65, s -> childy2 - 5, "替换(R)");
  373.     DrawButton(n, s -> childx1 + 70, s -> childy2 - 30,
  374.                   s -> childx1 + 130, s -> childy2 - 5, "取消(C)");
  375.    
  376.     CleanUp(n);
  377. }
  378.  
  379. void SwitchTextBox(void *n)
  380. /* Switch text box for replace window */
  381. {
  382.     Row *tmp;
  383.     State *s;
  384.     s = (State *)n;
  385.     if(s -> ischildwindow != 5)
  386.     /* Not in replace window, exiting */
  387.         return;
  388.     ClrCur(n);
  389.    
  390.     /* Move the currently edit box */
  391.     if(s -> edity1 == s -> childy1 + 27)
  392.     {
  393.         s -> edity1 += 25;
  394.         s -> edity2 += 25;
  395.     }
  396.     else
  397.     {
  398.         s -> edity1 -= 25;
  399.         s -> edity2 -= 25;
  400.     }
  401.    
  402.     /* Exchange the childhead pointers */
  403.     tmp = s -> childhead;
  404.     s -> childhead = s -> childhead2;
  405.     s -> childhead2 = tmp;
  406.    
  407.     s -> currentcolumn = 1;
  408.     s -> currentrow = 1;
  409.     End(n);
  410.     /* Call a end function to go to the last character */
  411. }
  412.  
  413. void CloseChildWindow(void *n)
  414. /* Close the child window */
  415. {
  416.     State *s;
  417.     s = (State *)n;
  418.    
  419.     FreeChildhead(n);
  420.     if(s -> ischildwindow == 5)
  421.         FreeChildhead2(n);
  422.    
  423.     CleanUp(n);
  424.     ClrCur(n);
  425.    
  426.     s -> ischildwindow = 0;
  427.     s -> isedit = 1;
  428.    
  429.     if(!s -> dotted)
  430.     {
  431.         setactivepage(!s -> page);
  432.         DrawMainWindow(n);
  433.         DrawStatusBox(n);
  434.         DoEvent(s -> redraw, n);
  435.         CleanUp(n);
  436.         setvisualpage(!s -> page);
  437.         s -> page = !s -> page;
  438.     }
  439.     else
  440.     {
  441.         if(RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  442.             0, getmaxy() - 25, getmaxx(), getmaxy()))
  443.         /* Status box redrawing needed */
  444.         {
  445.             DrawStatusBox(n);
  446.         }
  447.         DrawMainWindow(n);
  448.         DrawStatusBox(n);
  449.         DoEvent(s -> redraw, n);
  450.         CleanUp(n);
  451.     }
  452.    
  453.     /* Unset the flag and redraw specific area */
  454. }
  455.  
  456. void CheckChildButton(void *n)
  457. /* Check if clicked an button on child window */
  458. {
  459.     State *s;
  460.     s = (State *)n;
  461.    
  462.     if(!s -> ischildwindow)
  463.     /* No child window opened, exiting */
  464.         return;
  465.        
  466.     if(s -> mouse . key && PinRA(s -> mouse . x, s -> mouse . y,
  467.                                             s -> childx1 + 70, s -> childy2 - 30,
  468.                                             s -> childx1 + 130, s -> childy2 - 5))
  469.     /* Clicked "Cancel", just close the child window */
  470.     {
  471.         s -> mouse . key = 0;
  472.         CancelButton(n);
  473.     }
  474.    
  475.     if(s -> mouse . key && PinRA(s -> mouse . x, s -> mouse . y,
  476.                                             s -> childx1 + 5, s -> childy2 - 30,
  477.                                             s -> childx1 + 65, s -> childy2 - 5))
  478.     /* Clicked the operational button */
  479.     {
  480.         s -> mouse . key = 0;
  481.         SubmitButton(n);
  482.     }
  483.    
  484.     if(s -> ischildwindow == 99 && s -> mouse . key && PinRA(s -> mouse . x, s -> mouse . y,
  485.                                             s -> childx1 + 25, s -> childy2 - 30,
  486.                                             s -> childx1 + 120, s -> childy2 - 5))
  487.     {
  488.         s -> mouse . key = 0;
  489.         MsgBoxButton(n);
  490.     }
  491.    
  492.     if(s -> ischildwindow == 5 && s -> mouse . key )
  493.     {
  494.         if(s -> edity1 == s -> childy1 + 27 && PinRA(s -> mouse . x, s -> mouse . y,
  495.                                             s -> childx1 + 92, s -> childy1 + 52,
  496.                                             s -> childx2 - 10, s -> childy1 + 68))
  497.         {
  498.             //s -> isdrag = 1;
  499.             //RedrawMouse(n);
  500.             SwitchTextBox(n);
  501.             //s -> mouse . key = 0;
  502.             //s -> isdrag = 1;
  503.             //RedrawMouse(n);
  504.             //s -> isdrag = 0;
  505.             RedrawMouse(n);
  506.         }
  507.         else if(s -> edity1 == s -> childy1 + 52 && PinRA(s -> mouse . x, s -> mouse . y,
  508.                                             s -> childx1 + 92, s -> childy1 + 27,
  509.                                             s -> childx2 - 10, s -> childy1 + 43))
  510.         {
  511.             //s -> isdrag = 1;
  512.             //RedrawMouse(n);
  513.             SwitchTextBox(n);
  514.             //s -> mouse . key = 0;
  515.             //s -> isdrag = -1;
  516.             //RedrawMouse(n);
  517.             //s -> isdrag = 0;
  518.             RedrawMouse(n);
  519.         }
  520.     }
  521. }
  522.  
  523. void MoveChildWindow(void *n)
  524. /* Check and move the child window */
  525. {
  526.     State *s;
  527.     static void *buf, *buf2;
  528.     /* Saving the child window and the contents he covered */
  529.    
  530.     static int last_x, last_y;
  531.     /* Saving the last place of mouse pointer */
  532.    
  533.     static int deltax, deltay;
  534.     /* Saving the margin between the mouse pointer and the window */
  535.      
  536.     static origx1, origy1;
  537.     /* Saving original coordinate for the window */
  538.    
  539.     static redraw = 0;
  540.    
  541.     int i, j;
  542.     void *buftmp;
  543.    
  544.     int tx, ty;
  545.     /* Width and Height of the child window */
  546.    
  547.     s = (State *)n;
  548.     if(!s -> ischildwindow)
  549.         return;
  550.    
  551.     if((!s -> isdrag) && s -> mouse . key == 1 && PinRA(
  552.                     s -> mouse . x, s -> mouse . y,
  553.                     s -> childx1, s -> childy1,
  554.                     s -> childx2 - 23, s -> childy1 + 20))
  555.     /* Dragging start! */
  556.     {
  557.         s -> isdrag = 1;
  558.         /* Set the flag for dragging */
  559.        
  560.         buf = ALLOC(imagesize(s -> childx1, s -> childy1,
  561.                               s -> childx2, s -> childy2));
  562.         /* Memory allocation for saving the child window pixels */
  563.         CheckAlloc((void *)buf);
  564.        
  565.         CleanUp(n);
  566.        
  567.         if(s -> ischildwindow == 5 && s -> edity1 == s -> childy1 + 52)
  568.             SwitchTextBox(n);
  569.        
  570.         getimage(s -> childx1, s -> childy1, s -> childx2, s -> childy2, buf);
  571.         /* Get the child window pixels */
  572.        
  573.         if(!s -> dotted)
  574.         {
  575.             setactivepage(!s -> page);
  576.             DrawMainWindow(n);
  577.             DrawStatusBox(n);
  578.             DoEvent(s -> redraw, n);
  579.             putimage(s -> childx1, s -> childy1, buf, COPY_PUT);
  580.             setvisualpage(!s -> page);
  581.             setactivepage(s -> page);
  582.             DrawMainWindow(n);
  583.             DrawStatusBox(n);
  584.             DoEvent(s -> redraw, n);
  585.             setactivepage(!s -> page);
  586.             s -> page = !s -> page;
  587.         }
  588.         else
  589.         {
  590.             if(RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  591.                       0, 0, getmaxx(), 20) ||
  592.                RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  593.                       0, 0, 7, getmaxy()) ||
  594.                RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  595.                       getmaxx() - 7, 0, getmaxx(), getmaxy()) ||
  596.                RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  597.                       0, getmaxy() - 25, getmaxx(), getmaxy()))
  598.             {
  599.                 DrawMainWindow(n);
  600.                 DrawStatusBox(n);
  601.             }
  602.             DoEvent(s -> redraw, n);
  603.         }
  604.         /* Redraw the original main window to save original pixels */
  605.        
  606.         //else
  607.         /*if(!s -> dotted)
  608.         {
  609.             //setactivepage(!page);
  610.             buf2 = ALLOC(imagesize(0, 0, getmaxx() / PART, getmaxy() / PART));
  611.             if(buf2 == NULL)exit(1);
  612.             for(i = 0; i < PART; i ++)
  613.                 for(j = 0; j < PART; j ++)
  614.                 {
  615.                     getimage(i * getmaxx() / PART, j * getmaxy() / PART,
  616.                             (i + 1) * getmaxx() / PART, (j + 1) * getmaxy() / PART, buf2);
  617.                     putimage(i * getmaxx() / PART, j * getmaxy() / PART, buf2, COPY_PUT);
  618.                 }
  619.             FREEMEM(buf2);
  620.         }*/
  621.         //if(s -> dotted)
  622.         {
  623.             buf2 = ALLOC(imagesize(s -> childx1, s -> childy1,
  624.                                    s -> childx2, s -> childy2));
  625.             /* Memory allocation for saving the original main window pixels */
  626.             CheckAlloc((void *)buf2);
  627.        
  628.             getimage(s -> childx1, s -> childy1, s -> childx2, s -> childy2, buf2);
  629.             /* Get the original main window pixels */
  630.         }
  631.        
  632.         origx1 = s -> childx1, origy1 = s -> childy1;
  633.         /* Saving original child window coordinate */
  634.        
  635.         if(s -> dotted)
  636.             putimage(s -> childx1, s -> childy1, buf, COPY_PUT);
  637.         /* Restore the child window */
  638.        
  639.         CleanUp(n);
  640.         deltax = s -> mouse . x - s -> childx1;
  641.         deltay = s -> mouse . y - s -> childy1;
  642.         /* Saving the margin between the mouse pointer and the window */
  643.        
  644.         tx = s -> childx2 - s -> childx1;
  645.         ty = s -> childy2 - s -> childy1;
  646.         SetXRange(deltax, getmaxx() - 1 + deltax - tx);
  647.         SetYRange(deltay, getmaxy() - 22 + deltay - ty);
  648.        
  649.         last_x = s -> mouse . x, last_y = s -> mouse . y;
  650.         /* Saving the last place of mouse pointer */
  651.        
  652.         SetColor(15);    
  653.         setwritemode(1);
  654.         setlinestyle(1,0,1);
  655.         if(s -> dotted)
  656.             rectangle(s -> childx1, s -> childy1, s -> childx2, s -> childy2);
  657.             /* Draw the dotted line frame */        
  658.        
  659.         setlinestyle(0,0,1);
  660.         /* Restore the line style */
  661.     }
  662.    
  663.     if(s -> isdrag &&
  664.       (s -> mouse . x != last_x || s -> mouse . y != last_y))
  665.         if(s -> dotted)
  666.         /* Set to dotted mode */
  667.         {
  668.             SetColor(15);    
  669.             setwritemode(1);
  670.             setlinestyle(1,0,1);
  671.            
  672.             rectangle(s -> childx1, s -> childy1, s -> childx2, s -> childy2);
  673.             /* Draw an dotted rectangle at last location to erase it */
  674.            
  675.             /*if(s -> mouse . x - deltax < 0)
  676.                 s -> mouse . x = deltax;
  677.             if(s -> mouse . y - deltay < 0)
  678.                 s -> mouse . y = deltay;*/
  679.             tx = s -> childx2 - s -> childx1;
  680.             ty = s -> childy2 - s -> childy1;
  681.             /*if(s -> mouse . x - deltax + tx >= getmaxx())
  682.                 s -> mouse . x = getmaxx() - 1 + deltax - tx;
  683.             if(s -> mouse . y - deltay + ty >= getmaxy() - 21)
  684.                 s -> mouse . y = getmaxy() - 22 + deltay - ty;*/
  685.             /* Measure to ensure the window to be in the screen range */
  686.                
  687.             s -> childx1 = s -> mouse . x - deltax;
  688.             s -> childy1 = s -> mouse . y - deltay;
  689.             s -> childx2 = s -> childx1 + tx;
  690.             s -> childy2 = s -> childy1 + ty;
  691.             s -> editx1 = s -> childx1 + 77, s -> edity1 = s -> childy1 + 27;
  692.             s -> editx2 = s -> childx2 - 10, s -> edity2 = s -> childy1 + 43;
  693.             if(s -> ischildwindow > 3)
  694.                 s -> editx1 += 15;
  695.             if(s -> filehead == NULL)
  696.             {  
  697.                 s -> cursorx = s -> editx1;
  698.                 s -> cursory = s -> edity1;
  699.             }
  700.             /* Calculate the new window location */
  701.            
  702.             rectangle(s -> childx1, s -> childy1, s -> childx2, s -> childy2);
  703.             /* Draw an dotted rectangle at the new location */
  704.            
  705.             last_x = s -> mouse . x, last_y = s -> mouse . y;
  706.             /* Save the mouse location */
  707.            
  708.             setlinestyle(0, 0, 1);
  709.             /* Restore the line style */
  710.         }
  711.         else
  712.         /* Non-dotted mode */
  713.         /* FIXME: several bugs remaining */
  714.         {
  715.             setactivepage(!s -> page);
  716.             CleanUp(n);
  717.             //clearviewport();
  718.             if(RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  719.                       0, 0, getmaxx(), 20) ||
  720.                RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  721.                       0, 0, 7, getmaxy()) ||
  722.                RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  723.                       getmaxx() - 7, 0, getmaxx(), getmaxy()) ||
  724.                RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  725.                       0, getmaxy() - 25, getmaxx(), getmaxy()))
  726.                 redraw = 2;
  727.             putimage(last_x - deltax, last_y - deltay, buf2, COPY_PUT);
  728.             CleanUp(n);
  729.             /*if(s -> mouse . x - deltax < 0)
  730.                 s -> mouse . x = deltax, flag = 1;
  731.             if(s -> mouse . y - deltay < 0)
  732.                 s -> mouse . y = deltay, flag = 1;*/
  733.             tx = s -> childx2 - s -> childx1;
  734.             ty = s -> childy2 - s -> childy1;
  735.             /*if(s -> mouse . x - deltax + tx >= getmaxx())
  736.                 s -> mouse . x = getmaxx() - 1 + deltax - tx, flag = 1;
  737.             if(s -> mouse . y - deltay + ty >= getmaxy() - 21)
  738.                 s -> mouse . y = getmaxy() - 22 + deltay - ty, flag = 1;*/
  739.             s -> childx1 = s -> mouse . x - deltax;
  740.             s -> childy1 = s -> mouse . y - deltay;
  741.             s -> childx2 = s -> childx1 + tx;
  742.             s -> childy2 = s -> childy1 + ty;
  743.             s -> editx1 = s -> childx1 + 77, s -> edity1 = s -> childy1 + 27;
  744.             s -> editx2 = s -> childx2 - 10, s -> edity2 = s -> childy1 + 43;
  745.             if(s -> ischildwindow > 3)
  746.                 s -> editx1 += 15;
  747.             if(s -> filehead == NULL)
  748.             {  
  749.                 s -> cursorx = s -> editx1;
  750.                 s -> cursory = s -> edity1;
  751.             }
  752.             CleanUp(n);
  753.             if(RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  754.                       0, 0, getmaxx(), 20) ||
  755.                RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  756.                       0, 0, 7, getmaxy()) ||
  757.                RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  758.                       getmaxx() - 7, 0, getmaxx(), getmaxy()) ||
  759.                RAvsRA(s -> childx1, s -> childy1, s -> childx2, s -> childy2,
  760.                       0, getmaxy() - 25, getmaxx(), getmaxy()) || redraw)
  761.             {
  762.                 DrawMainWindow(n);
  763.                 DrawStatusBox(n);
  764.                 redraw --;
  765.             }
  766.             DoEvent(s -> redraw, n);
  767.            
  768.             getimage(s -> childx1, s -> childy1, s -> childx1 + tx, s -> childy1 + ty, buf2);
  769.             putimage(s -> childx1, s -> childy1, buf, COPY_PUT);
  770.             CleanUp(n);
  771.            
  772.             last_x = s -> mouse . x, last_y = s -> mouse . y;
  773.             setvisualpage(!s -> page);
  774.             delay(5);
  775.             s -> page = !s -> page;
  776. //            CleanUp(n);
  777.         }
  778.    
  779.     if(s -> mouse . release == 1 && s -> isdrag)
  780.     /* Mouse released */
  781.     {
  782.         /*if(s -> page == 1 && !s -> dotted)
  783.         {
  784.             CleanUp(n);
  785.             setactivepage(!s -> page);
  786.             for(i = 0; i < PART; i ++)
  787.                 for(j = 0; j < PART; j ++)
  788.                 {
  789.                     buftmp = ALLOC(imagesize(0, 0, getmaxx() / PART, getmaxy() / PART));
  790.                     if(buftmp == NULL)exit(1);
  791.                     setactivepage(s -> page);
  792.                     getimage(i * getmaxx() / PART, j * getmaxy() / PART,
  793.                             (i + 1) * getmaxx() / PART, (j + 1) * getmaxy() / PART, buftmp);
  794.                     setactivepage(!s -> page);
  795.                     putimage(i * getmaxx() / PART, j * getmaxy() / PART, buftmp, COPY_PUT);
  796.                     FREEMEM(buftmp);
  797.                 }
  798.             setvisualpage(!s -> page);
  799.             CleanUp(n);
  800.             s -> page = !s -> page;
  801.         }*/
  802.        
  803.         s -> isdrag = -1;
  804.         /*if(s -> page == 1)
  805.         {
  806.             setvisualpage(!s -> page);
  807.             s -> page = !s -> page;
  808.         }*/
  809.        
  810.         /*if(s -> childy1 < 20 || redraw)
  811.             DrawMainWindow(n);
  812.         DoEvent(s -> redraw, n);*/
  813.         if(s -> dotted)
  814.         {
  815.             MouseAway(n);
  816.             putimage(origx1, origy1, buf2, COPY_PUT);
  817.             /* Restore the original image */
  818.            
  819.             putimage(s -> childx1, s -> childy1, buf, COPY_PUT);
  820.             /* Put the child window into new place */
  821.            
  822.             MouseAway(n);
  823.         }
  824.         //CleanUp(n);
  825.        
  826.         SetXRange(0, getmaxx());
  827.         SetYRange(0, getmaxy());
  828.        
  829.         FREEMEM(buf2);
  830.         FREEMEM(buf);
  831.         /* Release any allocated memory in this procedure */
  832.        
  833.         s -> isdrag = 0;
  834.     }
  835. }
  836.  
  837. void CheckEnterSubmit(void *n)
  838. /* Check Enter key to submit the currently opened window */
  839. {
  840.     State *s;
  841.     s = (State *)n;
  842.     if(!s -> ischildwindow)
  843.     /* No child window opened, exiting */
  844.         return;
  845.        
  846.     SubmitButton(n);
  847.     /* Call the submit button functions */
  848.    
  849.     s -> keyboard . key = -1;
  850.     /* Reset the key */
  851. }
  852.  
  853. void SubmitButton(void *n)
  854. /* Submit key functions */
  855. {
  856.     MsgBoxButton(n);
  857.     /* Check if the Msgbox button is clicked */
  858.    
  859.     OpenButton(n);
  860.     /* Check if the Open window button is clicked */
  861.    
  862.     CmdSearch(n);
  863.     /* Check if the Search button is clicked */
  864.    
  865.     CmdReplace(n);
  866.     /* Check if the Replace button is clicked */
  867. }
  868.  
  869. void OpenButton(void *n)
  870. /* Check if the Open window button is clicked */
  871. {
  872.     char *tmp;
  873.     State *s;
  874.     s = (State *)n;
  875.     if(s -> ischildwindow != 1)
  876.         return;
  877.     tmp = GetChildText(n);
  878.     //FREEMEM(tmp);
  879.     CloseChildWindow(n);
  880.     OpenFile(n, tmp);
  881. }
  882.  
  883. void MsgBoxButton(void *n)
  884. /* Check if the Message Box button is clicked */
  885. {
  886.     char *tmp;
  887.     State *s;
  888.     s = (State *)n;
  889.     if(s -> ischildwindow != 99)
  890.         return;
  891.     CloseChildWindow(n);
  892.     if(s -> filehead == NULL)
  893.         NewFile(n);
  894. }
  895.  
  896. void CancelButton(void *n)
  897. /* Cancel button is clicked */
  898. {
  899.     State *s;
  900.     s = (State *)n;
  901.     if(!s -> ischildwindow)
  902.     /* No child window opened, exiting */
  903.         return;
  904.        
  905.     CloseChildWindow(n);
  906.     /* Just close the open child window */
  907. }
  908.  
  909. void Compile(void *n)
  910. /* Compile and run the currently open C code */
  911. {
  912.     char exec[100];
  913.     /* Buffer to save system commands */
  914.    
  915.     char filename2[20];
  916.     /* Buffer to save the filename */
  917.    
  918.     int i;
  919.     State *s;
  920.     s = (State *)n;
  921.     if(s -> filename[0] == 0)
  922.     /* No file open, exiting */
  923.         return;
  924.        
  925.     ClearGraph(n);
  926.     system("cd ..\\BIN");
  927.     /* Go to the TC binary files directory */
  928.    
  929.     sprintf(exec, "TCC.EXE -I..\\INCLUDE -L..\\LIB -n..\\BIN -w ..\\EDITOR\\%s graphics.lib", s -> filename);
  930.     /* Generate compiling command */
  931.    
  932.     system(exec);
  933.     /* Run the compiling command */
  934.    
  935.     getch();
  936.     /* Pause to show the compile results */
  937.     //system("cls");
  938.    
  939.     strcpy(filename2, s -> filename);
  940.     for(i = strlen(filename2) - 1; i >= 0; i --)
  941.     /* Fetch the right file name (cutting off ".c",".cpp",etc) */
  942.         if(filename2[i] == '.')
  943.         {
  944.             filename2[i] = 0;
  945.             break;
  946.         }
  947.        
  948.     sprintf(exec, "%s.exe", filename2);
  949.     /* Generate the run command */
  950.    
  951.     system(exec);
  952.     /* Run the run command */
  953.    
  954.     getch();
  955.     /* Pause to show the run result */
  956.    
  957.     system("cd ..\\EDITOR");
  958.     /* Go back to the original directory */
  959.    
  960.     DrawMainWindow(n);
  961.     DrawStatusBox(n);
  962.     DoEvent(s -> redraw, n);
  963.     /* Redraw the editor */
  964. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement