Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 28.49 KB | None | 0 0
  1. #include "edit.h"
  2. #include "common.h"
  3. #include "mouse.h"
  4. #include "file.h"
  5. #include "cursor.h"
  6.  
  7. void CheckCursor(void *n)
  8. {
  9.     State *s;
  10.     //int cursorrow;
  11.     int sum, flag = 0;
  12.    
  13.     s = (State *)n;
  14.     if(s -> ischildwindow)
  15.         return;
  16.     sum = (s -> edity2 - s -> edity1) / 16 + 1;
  17.    
  18.     while(s -> currentrow - s -> pagemovecount > sum)
  19.     {
  20.         //PageDown(n);
  21.         s -> pagemovecount ++;
  22.         flag = 1;
  23.     }
  24.     while(s -> currentrow - s -> pagemovecount == 0)
  25.     {
  26.         //PageUp(n);
  27.         s -> pagemovecount --;
  28.         flag = 1;
  29.     }
  30.     if(flag)
  31.     {
  32.         CleanUp(n);
  33.         if(!s -> dotted)
  34.         {
  35.             setactivepage(!s -> page);
  36.             DrawMainWindow(n);
  37.             DrawStatusBox(n);
  38.             DoEvent(s -> redraw, n);
  39.             CleanUp(n);
  40.             setvisualpage(!s -> page);
  41.             s -> page = !s -> page;
  42.         }
  43.         else
  44.         {
  45.             OutPutXY(n);
  46.             CleanUp(n);
  47.         }
  48.     }
  49. }
  50.  
  51. void DrawCur(void *n)
  52. /* draw the cursor */
  53. {
  54.     State *s;
  55.     s = (State *)n;
  56.     setwritemode(1);
  57.     setlinestyle(0,0,1);
  58.     setcolor(15);
  59.    
  60.     CheckCursor(n);
  61.     //printf("%d",!s -> ischildwindow ? s -> pagemovecount : 0);
  62.     if(s -> currentcolumn >= 79)
  63.     {
  64.         s -> cursorx = (s -> currentcolumn - 78 - 1)*8 + s -> editx1;
  65.         s -> cursory = (s -> currentrow - (!s -> ischildwindow ? s -> pagemovecount : 0)+ 1 - 1)*16 + s -> edity1;
  66.     }
  67.     /* change the row in the end but currentcolumn remain */
  68.     else
  69.     {
  70.         s -> cursorx = (s -> currentcolumn - 1)*8 + s -> editx1;
  71.         s -> cursory = (s -> currentrow - (!s -> ischildwindow ? s -> pagemovecount : 0) - 1)*16 + s -> edity1;
  72.     }
  73.     /* caculate the cursor position from current(row&column) */
  74.     MouseAway(n);
  75.     line(s -> cursorx ,s -> cursory,s -> cursorx ,s -> cursory + 16);
  76.     MouseAway(n);
  77.     s -> iscursor = !s -> iscursor;
  78.     GetCurPos(n);
  79.     /* caculate the currentrow & the currentcolumn of the cursor */
  80.     //printf("%d,%d\t",s -> cursorx,s -> cursory);
  81. }
  82.  
  83. void ClrCur(void *n)
  84. {
  85.     State *s;
  86.     s = (State *)n;
  87.     if(!(s -> iscursor))
  88.         return;
  89.        
  90.     CheckCursor(n);
  91.        
  92.     if(s -> currentcolumn >= 79)
  93.     {
  94.         s -> cursorx = (s -> currentcolumn - 78 - 1)*8 + s -> editx1;
  95.         s -> cursory = (s -> currentrow - (!s -> ischildwindow ? s -> pagemovecount : 0) + 1 - 1)*16 + s -> edity1;
  96.     }
  97.     /* change the row in the end but currentcolumn remain */
  98.     else
  99.     {
  100.         s -> cursorx = (s -> currentcolumn - 1)*8 + s -> editx1;
  101.         s -> cursory = (s -> currentrow - (!s -> ischildwindow ? s -> pagemovecount : 0) - 1)*16 + s -> edity1;
  102.     }
  103.     /* caculate the cursor position from current(row&column) */
  104.    
  105.     setlinestyle(0,0,1);
  106.     setcolor(15);
  107.     setwritemode(1);
  108.     line(s -> cursorx ,s -> cursory,s -> cursorx ,s -> cursory + 16);
  109.     s -> iscursor = 0;
  110. }
  111.  
  112. void FlashCur(void *n)
  113. {
  114.     State *s;
  115.     static int last_x = 0, last_y = 0, last_edit = 1;
  116.     s = (State *)n;
  117.    
  118.     CheckCursor(n);
  119.    
  120.     if(s -> currentcolumn >= 79)
  121.     {
  122.         s -> cursorx = (s -> currentcolumn - 78 - 1)*8 + s -> editx1;
  123.         s -> cursory = (s -> currentrow - (!s -> ischildwindow ? s -> pagemovecount : 0) + 1 - 1)*16 + s -> edity1;
  124.     }
  125.     /* change the row in the end but currentcolumn remain */
  126.     else
  127.     {
  128.         s -> cursorx = (s -> currentcolumn - 1)*8 + s -> editx1;
  129.         s -> cursory = (s -> currentrow - (!s -> ischildwindow ? s -> pagemovecount : 0) - 1)*16 + s -> edity1;
  130.     }
  131.     /* caculate the cursor position from current(row&column) */
  132.    
  133.     if(s -> cursortime == -1)
  134.         s -> cursortime = biostime(0, 0);
  135.         /* it means 1/18.4 second */
  136.     if(!s -> isedit)
  137.     {
  138.         ClrCur(n);
  139.         last_edit = 0;
  140.         return;
  141.     }
  142.     setwritemode(1);
  143.     if(last_x != s -> editx1 || last_y != s -> edity1 || last_edit != s -> isedit)
  144.     {
  145.         ClrCur(n);
  146.         s -> cursorx = s -> editx1;
  147.         s -> cursory = s -> edity1;
  148.         if(!s -> ischildwindow && (s -> currentcolumn != 1 || s -> currentrow -(s -> pagemovecount) != 1))
  149.         {
  150.             //(s -> cursory - (s -> edity1))/16 + 1;
  151.             //(s -> cursorx  - (s -> editx1 ))/8 + 1;
  152.             s -> cursorx += (s -> currentcolumn - 1) * 8 ;
  153.             s -> cursory += (s -> currentrow - (s -> pagemovecount) - 1) * 16;
  154.             /* caculate back from currentcolumn & currentrow to cursor(x,y) */
  155.         }
  156.         s -> cursortime = biostime(0, 0) - 12;
  157.         DrawCur(n);
  158.         last_x = s -> editx1, last_y = s -> edity1;
  159.     }
  160.     if(biostime(0, 0) - s -> cursortime >= 12)
  161.     {
  162.         DrawCur(n);
  163.         s -> cursortime = biostime(0, 0);
  164.     }
  165.     last_edit = 1;
  166.    
  167.     /*if(time(0) - t >= 2)
  168.     {
  169.         ClrCur(s);
  170.         t = time(0);
  171.     }*/
  172. }
  173.  
  174. void CursorUp(void *n)
  175. /* move cursor up by a row */
  176. {
  177.     Row *headline;
  178.     Char *ch;
  179.     State *s;
  180.     int num,sum,k,i,j;
  181.     /*  avoid to use editx2, that maybe error */
  182.     /*  avoid to use edity2, that maybe error */
  183.     int flag;
  184.     int p;
  185.     /* store the HZ position in the front row */
  186.     s = (State *)n;
  187.    
  188.     //printf("%d",s -> pagemovecount);
  189.     if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
  190.     {
  191.         s -> startchar = s -> endchar = s -> currentcolumn;
  192.         s -> startrow = s -> endrow = s -> currentrow;
  193.         /* refresh the start and end */
  194.         CleanUp(n);
  195.             if(!s -> dotted)
  196.             {
  197.                 setactivepage(!s -> page);
  198.                 DrawMainWindow(n);
  199.                 DrawStatusBox(n);
  200.                 DoEvent(s -> redraw, n);
  201.                 CleanUp(n);
  202.                 setvisualpage(!s -> page);
  203.                 s -> page = !s -> page;
  204.             }
  205.             else
  206.             {
  207.                 OutPutXY(n);
  208.                 CleanUp(n);
  209.             }
  210.     }
  211.    
  212.     num = (s -> editx2 - s -> editx1)/8;
  213.     sum = (s -> edity2 - s -> edity1)/16 + 1;
  214.     //printf("%d",sum);
  215.     if(!s -> ischildwindow)
  216.     {
  217.         if(!s -> isedit )
  218.             return;
  219.         //if(s -> cursory == s -> edity1)
  220.         //if(s -> currentrow - s -> pagemovecount == 1)  //&& s -> pagemovecount !=  0)
  221.         if(s -> currentrow == -1)
  222.         {
  223.             //if(s -> filehead != NULL)
  224.             if(s -> pagemovecount != 0)
  225.             /* PageUp when in front row */
  226.             {
  227.                 ClrCur(n);
  228.                 CleanUp(n);
  229.                 PageUp(n);
  230.                 //s -> currentrow -= 1;
  231.                 OutTextxy(n);
  232.                 CleanUp(n);
  233.                 DrawCur(n);
  234.             }
  235.             /* page up */
  236.             else
  237.             {
  238.                 ClrCur(n);
  239.                 s -> currentcolumn = 1;
  240.                 s -> currentrow = 1;
  241.                 DrawCur(n);
  242.             }
  243.             /* deal the situation of the row is the first one */   
  244.         }
  245.         /*if(s -> cursory >= s -> edity1 + 16)
  246.         {
  247.             ClrCur(n);
  248.             s -> cursory -= 16;
  249.             DrawCur(n);
  250.         }*/
  251.         //if(s -> cursory > s -> edity1)
  252.         if( s -> currentrow > 1)
  253.         {
  254.             headline = s -> filehead;
  255.             for(k = 1;k < s -> currentrow - 1;k++)
  256.             {
  257.                 headline = headline -> next;
  258.             }
  259.             ch = headline -> ch;
  260.             for(i = 1;ch != NULL;i++)
  261.             {
  262.                 ch = ch ->next;
  263.             }
  264.             /* calculate the whole num of the front row */
  265.            
  266.             /*if(s -> currentrow == 1)
  267.             {
  268.                 ClrCur(n);
  269.                 s -> currentcolumn = 1;
  270.                 DrawCur(n);
  271.             }*/
  272.             headline = headline -> next;
  273.             ch = headline -> ch;
  274.             for(j = 1;ch != NULL;j++)
  275.             {
  276.                 ch = ch ->next;
  277.             }
  278.             /* calculate the whole num of the current row */
  279.             //if((i >= j) || (s -> cursorx < i*8 + s -> editx1 - 8))
  280.            
  281.             if((i >= j) || (s -> currentcolumn < i - 1))
  282.             /* current row is shorter than the front row */
  283.             {
  284.                 //flag = UpHZ(n);
  285.                 if(UpHZ(n) == 1 && s -> currentcolumn != 1)
  286.                 {
  287.                     p = FindUpHZPosition(n);
  288.                     ClrCur(n);
  289.                     s -> currentcolumn = p;
  290.                     s -> currentrow -= 1;
  291.                     DrawCur(n);
  292.                 }
  293.                 else
  294.                 {
  295.                     ClrCur(n);
  296.                     //s -> cursory -= 16;
  297.                     s -> currentrow -= 1;
  298.                     DrawCur(n);
  299.                 }
  300.             }
  301.             /* deal the situation of the cursor whose cursor(x) is smaller then the end of front row  */
  302.             else
  303.             /* current row is longer than the front row */
  304.             {
  305.                 ClrCur(n);
  306.                 //s -> cursorx = i*8 + s -> editx1 - 16;
  307.                 //s -> cursory -= 16;
  308.                 s -> currentcolumn = i - 1;
  309.                 s -> currentrow -= 1;
  310.                 DrawCur(n);
  311.             }
  312.             /* deal the situation of the cursor whose cursor(x) is larger then the end of front row */
  313.            
  314.         }
  315.         else if(s -> currentrow == 1)
  316.         {
  317.             ClrCur(n);
  318.             s -> currentcolumn = 1;
  319.             DrawCur(n);
  320.         }
  321.     }
  322.     else if(s -> ischildwindow && s -> isedit)
  323.     {
  324.         ClrCur(n);
  325.         s -> currentcolumn = 1;
  326.         DrawCur(n);
  327.     }
  328.     s -> cursortime = biostime(0, 0) - 12;
  329. }
  330.  
  331. void CursorDown(void *n)
  332. /* move cursor down by a row */
  333. {
  334.     Row *headline;
  335.     Char *ch;
  336.     State *s;
  337.     int num,sum,i,j,k;
  338.     /*  avoid to use editx2, that maybe error */
  339.     /*  avoid to use edity2, that maybe error */
  340.     s = (State *)n;
  341.    
  342.     if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
  343.     {
  344.         s -> startchar = s -> endchar = s -> currentcolumn;
  345.         s -> startrow = s -> endrow = s -> currentrow;
  346.         /* refresh the start and end */
  347.         CleanUp(n);
  348.             if(!s -> dotted)
  349.             {
  350.                 setactivepage(!s -> page);
  351.                 DrawMainWindow(n);
  352.                 DrawStatusBox(n);
  353.                 DoEvent(s -> redraw, n);
  354.                 CleanUp(n);
  355.                 setvisualpage(!s -> page);
  356.                 s -> page = !s -> page;
  357.             }
  358.             else
  359.             {
  360.                 OutPutXY(n);
  361.                 CleanUp(n);
  362.             }
  363.     }
  364.     num = (s -> editx2 - s -> editx1)/8;
  365.     sum = (s -> edity2 - s -> edity1)/16 + 1 + s -> pagemovecount;
  366.    
  367.     if(!s -> ischildwindow)
  368.     {
  369.         if(!s -> isedit )
  370.             return;
  371.         //if(s -> cursory == sum * 16 + s -> edity1)
  372.         //if(s -> currentrow == s -> rowcount || s -> currentrow == sum)
  373.         if(s -> currentrow == -1)
  374.         /*movement in last row */
  375.         {
  376.             //printf("%d,%d,%d",s -> currentrow,s -> rowcount,s -> pagemovecount);
  377.             //if(s -> filehead != NULL)
  378.             //if(s -> pagemovecount < s -> rowcount - sum - 1)
  379.             if(s -> currentrow == sum && s -> currentrow != s -> rowcount)
  380.             /* pagedown */
  381.             {
  382.                 //printf("inside");
  383.                 headline = s -> filehead;
  384.                 for(i = 1;i <= s -> currentrow && headline != NULL;i++)
  385.                 {
  386.                     headline = headline -> next;
  387.                 }
  388.                 /* nextrow */
  389.                 ch = headline -> ch;
  390.                 for(j = 1;ch -> ch != '\0' && ch -> next != NULL;j++)
  391.                 {
  392.                     ch = ch -> next;
  393.                 }
  394.                 if(j < s -> currentcolumn)
  395.                 {
  396.                     s -> currentcolumn = j;
  397.                 }
  398.                 //ClrCur(n);
  399.                 //CleanUp(n);
  400.                 PageDown(n);
  401.                 //s -> currentrow += 1;
  402.                 OutPutXY(n);
  403.                 //CleanUp(n);
  404.                 //DrawCur(n);
  405.                 /* in stead of MouseAway(n) */
  406.             }
  407.             else if(s -> currentrow == s -> rowcount)
  408.             {
  409.                 headline = s -> filehead;
  410.                 for(i = 1;i < s -> rowcount && headline -> next != NULL;i++)
  411.                 {
  412.                     headline = headline -> next;
  413.                 }
  414.                 /* nextrow */
  415.                 ch = headline -> ch;
  416.                 for(j = 1;ch -> ch != '\0' && ch -> next != NULL;j++)
  417.                 {
  418.                     ch = ch -> next;
  419.                 }
  420.                 ClrCur(n);
  421.                 s -> currentcolumn = j;
  422.                 DrawCur(n);
  423.             }
  424.             //printf("%d",s -> rowcount);
  425.         }
  426.         else if(s -> currentrow < s -> rowcount)
  427.         /* is not in the last row */
  428.         {
  429.             headline = s -> filehead;
  430.            
  431.             for(k = 1;k < s -> currentrow && headline != NULL;k++)
  432.             {
  433.                 headline = headline -> next;
  434.             }
  435.             ch = headline -> ch;
  436.             for(i = 1;ch != NULL;i++)
  437.             {
  438.                 ch = ch ->next;
  439.             }
  440.            
  441.             headline = headline -> next;
  442.             ch = headline -> ch;
  443.             for(j = 1;ch != NULL;j++)
  444.             {
  445.                 ch = ch ->next;
  446.             }
  447.             //if((i <= j) || (s -> cursorx < j*8 + s -> editx1 - 8))
  448.             if((i <= j) || (s -> currentcolumn < j - 1))
  449.             {
  450.                 if(DownHZ(n) == 1 && s -> currentcolumn != 1)
  451.                 {
  452.                     k = FindDownHZPosition(n);
  453.                     ClrCur(n);
  454.                     s -> currentrow += 1;
  455.                     s -> currentcolumn = k;
  456.                     DrawCur(n);
  457.                 }
  458.                 else
  459.                 {
  460.                     if(s -> currentrow == sum && s -> currentrow <= s -> rowcount)
  461.                     {
  462.                         //printf("1");
  463.                         ClrCur(n);
  464.                         s -> currentrow += 1;
  465.                         DrawCur(n);
  466.                     }
  467.                     else
  468.                     {
  469.                         ClrCur(n);
  470.                         s -> currentrow += 1;
  471.                         DrawCur(n);
  472.                     }
  473.                 }
  474.             }
  475.             /* deal the situation of the cursor whose cursor(x) is smaller then the end of next row  */
  476.             else
  477.             {
  478.                 ClrCur(n);
  479.                 //s -> cursorx = j*8 + s -> editx1 - 16;
  480.                 //s -> cursory += 16;
  481.                 s -> currentcolumn = j - 1;
  482.                 s -> currentrow += 1;
  483.                 DrawCur(n);
  484.             }
  485.             /* deal the situation of the cursor whose cursor(x) is larger then the end of next row */
  486.         }
  487.         else if(s -> currentrow == s -> rowcount)
  488.         {
  489.             headline = s -> filehead;
  490.             for(i = 1;i < s -> rowcount;i++)
  491.             {
  492.                 headline = headline -> next;
  493.             }
  494.             ch = headline -> ch;
  495.             for(j = 1;ch != '\0' && ch -> next != NULL;j++)
  496.             {
  497.                 ch = ch -> next;
  498.             }
  499.             ClrCur(n);
  500.             s -> currentcolumn = j;
  501.             DrawCur(n);
  502.         }
  503.     }
  504.     else if(s -> ischildwindow && s -> isedit)
  505.     {
  506.         headline = s -> childhead;
  507.         ch = headline -> ch;
  508.         for(i = 1;ch -> next != NULL;i++)
  509.         {
  510.             ch = ch -> next;
  511.         }
  512.         ClrCur(n);
  513.         s -> currentcolumn = i;
  514.         DrawCur(n);
  515.     }
  516.     s -> cursortime = biostime(0, 0) - 12;
  517. }
  518.  
  519. void CursorLeft(void *n)
  520. {
  521.     int i,j;
  522.     Row *headline;
  523.     Char *ch;
  524.     State *s;
  525.     int num,sum;
  526.     /*  avoid to use editx2, that maybe error */
  527.     /*  avoid to use edity2, that maybe error */
  528.     s = (State *)n;
  529.     headline = s -> filehead;
  530.    
  531.     if((s -> startchar == 1&&s -> startrow == 1) || (s -> endchar ==1 && s -> endrow == 1)&&s -> ischosen)
  532.     {  
  533.         CleanUp(n);
  534.         s -> pagemovecount = 0;
  535.         s -> currentcolumn = s -> currentrow = 1;
  536.         s -> startchar = s -> startrow = s -> endchar = s -> endrow = 1;
  537.         if(!s -> dotted)
  538.         {
  539.             setactivepage(!s -> page);
  540.             DrawMainWindow(n);
  541.             DrawStatusBox(n);
  542.             DoEvent(s -> redraw, n);
  543.             CleanUp(n);
  544.             setvisualpage(!s -> page);
  545.             s -> page = !s -> page;
  546.         }
  547.         else
  548.         {
  549.             OutPutXY(n);
  550.             CleanUp(n);
  551.         }
  552.         return;
  553.     }
  554.    
  555.     if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
  556.     {
  557.         if(s -> startrow > s -> endrow)
  558.         {
  559.            
  560.             s -> currentrow = s -> startrow = s -> endrow;
  561.             s -> currentcolumn = s -> startchar = s -> endchar;
  562.         }
  563.         if(s -> endrow > s -> startrow)
  564.         {
  565.            
  566.             s -> currentrow = s -> endrow = s -> startrow;
  567.             s -> currentcolumn = s -> endchar = s -> startchar;
  568.         }
  569.         if(s -> endrow == s -> startrow)
  570.         {
  571.            
  572.             s -> currentrow = s -> endrow = s -> startrow;
  573.             s -> currentcolumn = (s -> startchar < s -> endchar ? s -> startchar : s -> endchar);
  574.             s -> endchar = s -> startchar = s -> currentcolumn;
  575.         }
  576.         /* refresh the start and end */
  577.         CleanUp(n);
  578.             if(!s -> dotted)
  579.             {
  580.                 setactivepage(!s -> page);
  581.                 DrawMainWindow(n);
  582.                 DrawStatusBox(n);
  583.                 DoEvent(s -> redraw, n);
  584.                 CleanUp(n);
  585.                 setvisualpage(!s -> page);
  586.                 s -> page = !s -> page;
  587.             }
  588.             else
  589.             {
  590.                 OutPutXY(n);
  591.                 CleanUp(n);
  592.             }
  593.         return;
  594.     }
  595.    
  596.    
  597.    
  598.     num = (s -> editx2 - s -> editx1)/8;
  599.     sum = (s -> edity2 - s -> edity1)/16;
  600.     //printf("%d",LeftHZ(n));
  601.     if(!s -> ischildwindow)
  602.     {
  603.         if(!s -> isedit )
  604.             return;
  605.         //if((s -> cursorx <= s -> editx1) && (s -> cursory <= s -> rowcount *16 + s -> edity1))
  606.         if((s -> currentcolumn <= 1) && (s -> currentrow <= s -> rowcount))
  607.         /* movement in the head of the row */
  608.         {
  609.             /*if(s -> currentrow - s -> pagemovecount == 1 && s -> pagemovecount != 0)
  610.             {
  611.                 //printf("inside");
  612.                 for(i = 1;i < s -> currentrow - 1;i++)
  613.                 / find the front row /
  614.                 {
  615.                     headline = headline -> next;
  616.                 }
  617.                 ch = headline -> ch;
  618.                 for(j = 1;ch != NULL;j++)
  619.                 / caculate the num of the char /
  620.                 {
  621.                     ch = ch -> next;
  622.                 }
  623.                 ClrCur(n);
  624.                 CleanUp(n);
  625.                 PageUp(n);
  626.                 s -> currentcolumn = j - 1;
  627.                 s -> currentrow -= 1;
  628.                 OutTextxy(n);
  629.                 CleanUp(n);
  630.                 DrawCur(n);
  631.             }
  632.             else */
  633.             if(s -> currentrow > 1)
  634.             {
  635.                 for(i = 1;i < s -> currentrow - 1 ;i++)
  636.                 /* find the front row */
  637.                 {
  638.                     headline = headline -> next;
  639.                 }
  640.                 ch = headline -> ch;
  641.                 for(j = 1;ch != NULL;j++)
  642.                 /* caculate the num of the char */
  643.                 {
  644.                     ch = ch -> next;
  645.                 }
  646.                 //if(s -> cursory > s -> edity1)
  647.                 if(s -> currentrow > 1)
  648.                 {
  649.                     ClrCur(n);
  650.                     /*s -> cursorx =  j * 8 + s -> editx1 - 16;
  651.                     s -> cursory -= 16;*/
  652.                     s -> currentcolumn = j - 1;
  653.                     s -> currentrow -= 1;
  654.                     DrawCur(n);
  655.                 }
  656.             }
  657.         }
  658.         /*else if(s -> cursorx >= s -> editx1 + 8)
  659.         {
  660.             ClrCur(n);
  661.             s -> cursorx -= 8;
  662.             DrawCur(n);
  663.         }*/
  664.         else if(s -> currentcolumn >= 2)
  665.         {
  666.             //ClrCur(n);
  667.             if(LeftHZ(n) == 1)
  668.             {
  669.                 ClrCur(n);
  670.                 s -> currentcolumn -= 2;
  671.                 DrawCur(n);
  672.             }
  673.             else
  674.             {
  675.                 ClrCur(n);
  676.                 s -> currentcolumn -= 1;
  677.                 DrawCur(n);
  678.             }
  679.             //DrawCur(n);
  680.         }
  681.         s -> cursortime = biostime(0, 0) - 12;
  682.     }
  683.     else if(s -> ischildwindow && s -> isedit)
  684.     {
  685.         /*if((s -> cursorx >= s -> editx1 + 8)&&(s -> cursorx <= s -> editx2 ))
  686.         {
  687.             ClrCur(n);
  688.             s -> cursorx -= 8;
  689.             DrawCur(n);
  690.         }*/
  691.         if((s -> currentcolumn >= 2) && (s -> currentcolumn <= num))
  692.         {
  693.             //ClrCur(n);
  694.             if(LeftHZ(n) == 1)
  695.             {
  696.                 s -> currentcolumn -= 2;
  697.             }
  698.             else
  699.             {
  700.                 s -> currentcolumn -= 1;
  701.             }
  702.             //DrawCur(n);
  703.         }
  704.         //s -> cursortime = biostime(0, 0) - 12;
  705.     }
  706. }
  707.  
  708. void CursorRight(void *n)
  709. {
  710.     int i,j;
  711.     Row *headline;
  712.     Row *line;
  713.     Char *ch;
  714.     State *s;
  715.     int num,sum;
  716.     /*  avoid to use editx2, that maybe error */
  717.     /*  avoid to use edity2, that maybe error */
  718.     s = (State *)n;
  719.     //printf("%d",RightHZ(n));
  720.     num = (s -> editx2 - s -> editx1)/8;
  721.     sum = (s -> edity2 - s -> edity1)/16 + 1 + s -> pagemovecount;
  722.     //printf("%d|%d\t",s -> cursorx,num);
  723.    
  724.     if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
  725.     {
  726.         if(s -> startrow < s -> endrow)
  727.         {
  728.            
  729.             s -> currentrow = s -> startrow = s -> endrow;
  730.             s -> currentcolumn = s -> startchar = s -> endchar;
  731.         }
  732.         if(s -> endrow < s -> startrow)
  733.         {
  734.            
  735.             s -> currentrow = s -> endrow = s -> startrow;
  736.             s -> currentcolumn = s -> endchar = s -> startchar;
  737.         }
  738.         if(s -> endrow == s -> startrow)
  739.         {
  740.            
  741.             s -> currentrow = s -> endrow = s -> startrow;
  742.             s -> currentcolumn = (s -> startchar > s -> endchar ? s -> startchar : s -> endchar);
  743.             s -> endchar = s -> startchar = s -> currentcolumn;
  744.         }
  745.        
  746.         /* refresh the start and end */
  747.         CleanUp(n);
  748.             if(!s -> dotted)
  749.             {
  750.                 setactivepage(!s -> page);
  751.                 DrawMainWindow(n);
  752.                 DrawStatusBox(n);
  753.                 DoEvent(s -> redraw, n);
  754.                 CleanUp(n);
  755.                 setvisualpage(!s -> page);
  756.                 s -> page = !s -> page;
  757.             }
  758.             else
  759.             {
  760.                 OutPutXY(n);
  761.                 CleanUp(n);
  762.             }
  763.         return;
  764.     }
  765.    
  766.     if(!s -> ischildwindow)
  767.     {
  768.         if(!s -> isedit )
  769.             return;
  770.         /*if((s -> cursorx  == (num * 8 + s -> editx1)) && (s -> cursory <= (sum * 16 + s -> edity1) - 16))
  771.         {
  772.             ClrCur(n);
  773.             s -> cursorx = s -> editx1;
  774.             s -> cursory += 16;
  775.             DrawCur(n);
  776.         }*/
  777.         if((s -> currentcolumn == num + 1) && (s -> currentrow <= sum - 1))
  778.         {
  779.            
  780.             //printf("inside");
  781.             if(RightHZ(n) == 1)
  782.             {
  783.                 ClrCur(n);
  784.                 s -> currentcolumn += 2;
  785.                 DrawCur(n);
  786.             }
  787.             else
  788.             {
  789.                 ClrCur(n);
  790.                 s -> currentcolumn += 1;
  791.                 DrawCur(n);
  792.             }
  793.             //s -> currentrow += 1;
  794.            
  795.         }
  796.        
  797.          if(s -> currentcolumn <= num)
  798.         /* in the whole row */
  799.         {
  800.             headline = s -> filehead;
  801.             /* judge the childwindow mode */
  802.             //printf("%d",s -> currentrow + s -> pagemovecount);
  803.             for(i = 1;i < s -> currentrow && headline != NULL ;i++)
  804.             {
  805.                 headline = headline -> next;
  806.             }
  807.             ch = headline -> ch;
  808.             for(j = 1;/*j <= s -> currentcolumn*/ch -> ch != '\0' && ch -> next != NULL;j++)
  809.             /* find the last char of the row */
  810.             {
  811.                 ch = ch -> next;
  812.             }
  813.             if(s -> currentcolumn < j)
  814.             {
  815.                 //ClrCur(n);
  816.                 /*s -> cursorx += 8;*/
  817.                 if(RightHZ(n) == 1)
  818.                 {
  819.                     ClrCur(n);
  820.                     s -> currentcolumn += 2;
  821.                     DrawCur(n);
  822.                 }
  823.                 else
  824.                 {
  825.                     ClrCur(n);
  826.                     s -> currentcolumn += 1;
  827.                     DrawCur(n);
  828.                 }
  829.                 //DrawCur(n);
  830.             }
  831.             /*else if(s -> cursory <= ((s -> rowcount - 1) *16 + s -> edity1))
  832.                 {
  833.                     ClrCur(n);
  834.                     s -> cursorx = s -> editx1;
  835.                     s -> cursory += 16;
  836.                     DrawCur(n);
  837.                 }*/
  838.             else if(s -> currentcolumn >= j && s -> currentrow < s -> rowcount)//if(s -> currentrow <= (s -> rowcount - 1)*/
  839.             {
  840.                 ClrCur(n);
  841.                 s -> currentcolumn = 1;
  842.                 s -> currentrow += 1;
  843.                 DrawCur(n);
  844.             }
  845.             /*else if(s -> currentcolumn >= j && s -> currentrow == sum)
  846.             {
  847.                 ClrCur(n);
  848.                 CleanUp(n);
  849.                 PageDown(n);
  850.                 s -> currentcolumn = 1;
  851.                 s -> currentrow += 1;
  852.                 CleanUp(n);
  853.                 DrawCur(n);
  854.             }*/
  855.         }
  856.         /* move the cursor from the right to the front char in next row */
  857.         s -> cursortime = biostime(0, 0) - 12;
  858.     }
  859.     else if(s -> ischildwindow && s -> isedit)
  860.     {
  861.         line = s -> childhead;
  862.         ch = line -> ch;
  863.         for(j = 1;ch -> next != NULL;j++)
  864.         {
  865.             ch = ch -> next;
  866.         }
  867.        
  868.         if((s -> currentcolumn >= 1)&&(s -> currentcolumn < j))
  869.         {
  870.             ClrCur(n);
  871.             s -> currentcolumn += 1;
  872.             DrawCur(n);
  873.         }
  874.         //s -> cursortime = biostime(0, 0) - 12;
  875.     }
  876. }
  877.  
  878. void GetCurPos(void *n)
  879. /* caculate the currentrow & the currentcolumn of the cursor */
  880. {
  881.     int testrow;
  882.     State *s;
  883.     s = (State *)n;
  884.     if(!s -> isedit || s -> ischildwindow)
  885.         return;
  886.     //s -> currentrow = (s -> cursory - (s -> edity1))/16 + 1;
  887.     //s -> currentcolumn = (s -> cursorx  - (s -> editx1 ))/8 + 1;
  888.     //testrow = (s -> cursory - (s -> edity1))/16;
  889. }
  890.  
  891. void MousetoCursor(void *n)
  892. /* left click mouse and then move the cursor to the current position */
  893. {
  894.     Row *headline;
  895.     Char *ch;
  896.     State *s;
  897.     int x,y,key,i,j;
  898.     int k;
  899.     Row *line;
  900.     Char *tmpch;
  901.     s = (State *)n;
  902.     if(!s -> isedit || !PinRA(s -> mouse.x, s->mouse.y, s->editx1, s->edity1,s->editx2,s->edity2))
  903.         return;
  904.     if(!s -> ischildwindow)
  905.     {
  906.         headline = s -> filehead;
  907.         if(headline == NULL)
  908.             return;
  909.         x = (s -> mouse . x - s -> editx1) / 8 + 1;
  910.         /* the currentcolumn the Mouse in */
  911.         y = (s -> mouse . y - s -> edity1) / 16 + 1 + s -> pagemovecount;
  912.         /* the currentrow the Mouse in */
  913.         key = s -> mouse . key;
  914.         if(1 || key == 1)
  915.         {
  916.             /*ClrCur(n);
  917.             s -> cursortime = biostime(0, 0) - 12;
  918.             s -> cursorx = x*8 + s -> editx1;
  919.             s -> cursory = y*16 + s -> edity1;
  920.             DrawCur(n);*/
  921.             if(y > s -> rowcount)
  922.             /* mouse is under the bottom of the text */
  923.             {
  924.                 ClrCur(n);
  925.                 s -> cursortime = biostime(0, 0) - 12;
  926.                 //s -> cursory = s -> rowcount * 16 + s -> edity1;
  927.                 //s -> cursorx = s -> editx1;
  928.                 s -> currentrow = s -> rowcount;
  929.                
  930.                 line = s -> filehead;
  931.                 for(i = 1;i < s -> rowcount && line != NULL;i++)
  932.                 {
  933.                     line = line -> next;
  934.                 }
  935.                 if(line == NULL)
  936.                     return;
  937.                 tmpch = line -> ch;
  938.                 for(i = 1;tmpch != NULL && tmpch -> next != NULL;i++)
  939.                 {
  940.                     tmpch = tmpch -> next;
  941.                 }
  942.                 k = i ;
  943.                 s -> currentcolumn = k;
  944.                 DrawCur(n);
  945.             }
  946.             else
  947.             {
  948.                 for(i = 1; i < y && headline != NULL; i++)
  949.                 {
  950.                     headline = headline -> next;
  951.                 }
  952.                 if(headline == NULL)
  953.                     return;
  954.                 ch = headline -> ch;
  955.                 for(j = 1; ch != NULL;j++)
  956.                 {
  957.                     ch = ch -> next;
  958.                 }
  959.                 if(x > j - 2)
  960.                 /* Mouse is in the right of the row */
  961.                 {
  962.                     ClrCur(n);
  963.                     s -> cursortime = biostime(0, 0) - 12;
  964.                     //s -> cursorx = (j - 1)*8 + s -> editx1 - 8;
  965.                     //s -> cursory = y*16 + s -> edity1;
  966.                     s -> currentcolumn = j - 1;
  967.                     s -> currentrow = y;
  968.                     DrawCur(n);
  969.                 }
  970.                 else
  971.                 {
  972.                     if(MouseHZ(n) == 1)
  973.                     {
  974.                         ClrCur(n);
  975.                         s -> cursortime = biostime(0, 0) - 12;
  976.                         //s -> cursorx = x*8 + s -> editx1;
  977.                         //s -> cursory = y*16 + s -> edity1;
  978.                         s -> currentcolumn = FindMouseHZPosition(n);
  979.                         s -> currentrow = y;
  980.                         DrawCur(n);
  981.                     }
  982.                     else
  983.                     {
  984.                         ClrCur(n);
  985.                         s -> cursortime = biostime(0, 0) - 12;
  986.                         //s -> cursorx = x*8 + s -> editx1;
  987.                         //s -> cursory = y*16 + s -> edity1;
  988.                         s -> currentcolumn = x ;
  989.                         s -> currentrow = y;
  990.                         DrawCur(n);
  991.                     }
  992.                 }
  993.             }
  994.         }
  995.     }
  996.     else if(s -> ischildwindow && s -> isedit)
  997.     {
  998.         x = (s -> mouse . x - s -> editx1) / 8 + 1;
  999.         /* the currentcolumn the Mouse in */
  1000.         key = s -> mouse . key;
  1001.         //printf("%d",key);
  1002.         if( key == 1)
  1003.         {
  1004.             //printf("inside");
  1005.             line = s -> childhead;
  1006.             if(line == NULL)
  1007.                 return;
  1008.             ch = line -> ch;
  1009.             for(i = 1;ch != NULL && ch -> next != NULL;i++)
  1010.             {
  1011.                 ch = ch -> next;
  1012.             }
  1013.             if(x > i)
  1014.             {
  1015.                 ClrCur(n);
  1016.                 s -> currentcolumn = i;
  1017.                 DrawCur(n);
  1018.             }
  1019.             else if(x <= i)
  1020.             {
  1021.                 ClrCur(n);
  1022.                 s -> currentcolumn = x;
  1023.                 DrawCur(n);
  1024.             }
  1025.         }
  1026.     }
  1027. }
  1028.  
  1029.  
  1030. int LeftHZ(void *n)
  1031. /* there is a HZ on the left side of the cursor */
  1032. {
  1033.     State *s;
  1034.     int m,k;
  1035.     int i;
  1036.     char p;
  1037.     Char *ch;
  1038.     Row *row;
  1039.     //int Q1 = 0xa1,Q2 = 0xfe;
  1040.     s = (State *)n;
  1041.     m = s -> currentrow;
  1042.     k = s -> currentcolumn;
  1043.     k -= 1;
  1044.     row = s -> filehead;
  1045.     for(i = 1;i < m;i++)
  1046.     {
  1047.         row = row -> next;
  1048.     }
  1049.     ch = row -> ch;
  1050.     for(i = 1;i < k ;i++)
  1051.     {
  1052.         ch = ch -> next;
  1053.     }
  1054.     p = ch -> ch;
  1055.     //printf("%c|%d|%d|%d\t",p,Q2,(unsigned char)p,Q1);
  1056.     if((unsigned char)(p) >= 0xa1 && (unsigned char)(p) <= 0xfe)
  1057.     {
  1058.         return 1;
  1059.     }
  1060.     else
  1061.     {
  1062.         return 0;
  1063.     }
  1064. }
  1065.  
  1066. int RightHZ(void *n)
  1067. /* there is a HZ on the right side of the cursor */
  1068. {
  1069.     State *s;
  1070.     int m,k;
  1071.     int i;
  1072.     char p;
  1073.     Char *ch;
  1074.     Row *row;
  1075.     //int Q1 = 0xa1,Q2 = 0xfe;
  1076.     s = (State *)n;
  1077.     m = s -> currentrow;
  1078.     k = s -> currentcolumn;
  1079.     k -= 1;
  1080.     row = s -> filehead;
  1081.     for(i = 1;i < m;i++)
  1082.     {
  1083.         row = row -> next;
  1084.     }
  1085.     ch = row -> ch;
  1086.     for(i = 1;i < k + 1 ;i++)
  1087.     {
  1088.         ch = ch -> next;
  1089.     }
  1090.     p = ch -> ch;
  1091.     //printf("%c|%d|%d|%d\t",p,Q2,(unsigned char)p,Q1);
  1092.     if((unsigned char)(p) >= 0xa1 && (unsigned char)(p) <= 0xfe)
  1093.     {
  1094.         return 1;
  1095.     }
  1096.     else
  1097.     {
  1098.         return 0;
  1099.     }
  1100. }
  1101.  
  1102. int UpHZ(void *n)
  1103. /* there is a HZ on the top side of the cursor */
  1104. {
  1105.     State *s;
  1106.     int m,k;
  1107.     int i;
  1108.     char q,p;
  1109.     Char *ch;
  1110.     Row *row;
  1111.     //int Q1 = 0xa1,Q2 = 0xfe;
  1112.     s = (State *)n;
  1113.     m = s -> currentrow;
  1114.     k = s -> currentcolumn;
  1115.     k -= 1;
  1116.     row = s -> filehead;
  1117.     for(i = 1;i < m - 1 && row != NULL;i++)
  1118.     {
  1119.         row = row -> next;
  1120.     }
  1121.     ch = row -> ch;
  1122.     for(i = 1;i < k && ch != NULL;i++)
  1123.     {
  1124.         ch = ch -> next;
  1125.     }
  1126.     q = ch -> ch;
  1127.     p = ch -> next -> ch;
  1128.     //printf("%d|%d|%d|%d\t",(unsigned char)q,(unsigned char)p,0xa1,0xfe);
  1129.     //printf("%c|%d|%d|%d\t",p,Q2,(unsigned char)p,Q1);
  1130.     if(((unsigned char)q >= 0xa1 && (unsigned char)q <= 0xfe)
  1131.         &&(unsigned char)(p) >= 0xa1 && (unsigned char)(p) <= 0xfe)
  1132.     {
  1133.         return 1;
  1134.     }
  1135.     else
  1136.     {
  1137.         return 0;
  1138.     }
  1139. }
  1140. int DownHZ(void *n)
  1141. /* there is a HZ on the bottom side of the cursor */
  1142. {
  1143.     State *s;
  1144.     int m,k;
  1145.     int i;
  1146.     char q,p;
  1147.     Char *ch;
  1148.     Row *row;
  1149.     //int Q1 = 0xa1,Q2 = 0xfe;
  1150.     s = (State *)n;
  1151.     m = s -> currentrow;
  1152.     k = s -> currentcolumn;
  1153.     m += 1;
  1154.     row = s -> filehead;
  1155.     for(i = 1;i < m && row != NULL;i++)
  1156.     {
  1157.         row = row -> next;
  1158.     }
  1159.     ch = row -> ch;
  1160.     for(i = 1;i < k - 1 && ch != NULL;i++)
  1161.     {
  1162.         ch = ch -> next;
  1163.     }
  1164.     q = ch -> ch;
  1165.     p = ch -> next -> ch;
  1166.     //printf("%c|%c\t",q,p);
  1167.     //printf("%c|%d|%d|%d\t",p,Q2,(unsigned char)p,Q1);
  1168.     if(((unsigned char)q >= 0xa1 && (unsigned char)q <= 0xfe)
  1169.         &&(unsigned char)(p) >= 0xa1 && (unsigned char)(p) <= 0xfe)
  1170.     {
  1171.         return 1;
  1172.     }
  1173.     else
  1174.     {
  1175.         return 0;
  1176.     }
  1177. }
  1178.  
  1179. int MouseHZ(void *n)
  1180. /* there is a HZ under the Mouse */
  1181. {
  1182.     State *s;
  1183.     int m,k;
  1184.     int i;
  1185.     char q,p;
  1186.     Char *ch;
  1187.     Row *row;
  1188.     //int Q1 = 0xa1,Q2 = 0xfe;
  1189.     s = (State *)n;
  1190.     m = (s -> mouse . y - s -> edity1) / 16 + 1 + s -> pagemovecount;
  1191.     k = (s -> mouse . x - s -> editx1) / 8 + 1;;
  1192.     row = s -> filehead;
  1193.     for(i = 1;i < m && row != NULL;i++)
  1194.     {
  1195.         row = row -> next;
  1196.     }
  1197.     ch = row -> ch;
  1198.     for(i = 1;i < k - 1 && ch != NULL;i++)
  1199.     {
  1200.         ch = ch -> next;
  1201.     }
  1202.     q = ch -> ch;
  1203.     p = ch -> next -> ch;
  1204.     //printf("%c|%c\t",q,p);
  1205.     //printf("%c|%d|%d|%d\t",p,Q2,(unsigned char)p,Q1);
  1206.     if(((unsigned char)q >= 0xa1 && (unsigned char)q <= 0xfe)
  1207.         &&(unsigned char)(p) >= 0xa1 && (unsigned char)(p) <= 0xfe)
  1208.     {
  1209.         return 1;
  1210.     }
  1211.     else
  1212.     {
  1213.         return 0;
  1214.     }
  1215. }
  1216.  
  1217. int FindMouseHZPosition(void *n)
  1218. /* calculate the HZ positon under the Mouse */
  1219. {
  1220.     State *s;
  1221.     Row *line;
  1222.     Char *ch;
  1223.     int i;
  1224.     int m,k;
  1225.    
  1226.     s = (State *)n;
  1227.     s = (State *)n;
  1228.     line = s -> filehead;
  1229.     m = (s -> mouse . y - s -> edity1) / 16 + 1 + s -> pagemovecount;
  1230.     k = (s -> mouse . x - s -> editx1) / 8 + 1;;
  1231.     for(i = 1;i < m && line != NULL;i++)
  1232.     {
  1233.         line = line -> next;
  1234.     }
  1235.     ch = line -> ch;
  1236.     for(i = 1;i < k && ch != NULL;i++)
  1237.     {
  1238.         if((unsigned char)(ch -> ch) >= 0xa1
  1239.             && (unsigned char)(ch -> ch) <= 0xfe)
  1240.         {
  1241.             ch = ch -> next;
  1242.             i += 1;
  1243.             ch = ch -> next;
  1244.             //i += 1;
  1245.         }
  1246.         else
  1247.         {
  1248.             ch = ch -> next;
  1249.         }
  1250.     }
  1251.     return (i - 2);
  1252. }
  1253.  
  1254. int FindUpHZPosition(void *n)
  1255. /* calculate the HZ positon in the front row */
  1256. {
  1257.     State *s;
  1258.     Row *line;
  1259.     Char *ch;
  1260.     int i;
  1261.     int m,k;
  1262.    
  1263.     s = (State *)n;
  1264.     s = (State *)n;
  1265.     line = s -> filehead;
  1266.     m = s -> currentrow;
  1267.     k = s -> currentcolumn;
  1268.     m = m - 1;
  1269.     for(i = 1;i < m && line != NULL;i++)
  1270.     {
  1271.         line = line -> next;
  1272.     }
  1273.     ch = line -> ch;
  1274.     for(i = 1;i < k && ch != NULL;i++)
  1275.     {
  1276.         if((unsigned char)(ch -> ch) >= 0xa1
  1277.             && (unsigned char)(ch -> ch) <= 0xfe)
  1278.         {
  1279.             ch = ch -> next;
  1280.             i += 1;
  1281.             ch = ch -> next;
  1282.             //i += 1;
  1283.         }
  1284.         else
  1285.         {
  1286.             ch = ch -> next;
  1287.         }
  1288.     }
  1289.     return (i - 2);
  1290. }
  1291.  
  1292. int FindDownHZPosition(void *n)
  1293. /* calculate the HZ positon in the next row */
  1294. {
  1295.     State *s;
  1296.     Row *line;
  1297.     Char *ch;
  1298.     int i;
  1299.     int m,k;
  1300.    
  1301.     s = (State *)n;
  1302.     s = (State *)n;
  1303.     line = s -> filehead;
  1304.     m = s -> currentrow;
  1305.     k = s -> currentcolumn;
  1306.     m = m + 1;
  1307.     for(i = 1;i < m && line != NULL;i++)
  1308.     {
  1309.         line = line -> next;
  1310.     }
  1311.     ch = line -> ch;
  1312.     for(i = 1;i < k && ch != NULL;i++)
  1313.     {
  1314.         if((unsigned char)(ch -> ch) >= 0xa1
  1315.             && (unsigned char)(ch -> ch) <= 0xfe)
  1316.         {
  1317.             ch = ch -> next;
  1318.             i += 1;
  1319.             ch = ch -> next;
  1320.             //i += 1;
  1321.         }
  1322.         else
  1323.         {
  1324.             ch = ch -> next;
  1325.         }
  1326.     }
  1327.     return (i - 2);
  1328. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement