Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 36.46 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 OutPutMain(void *n)
  8. {
  9.     int t, tx1, tx2, ty1, ty2;
  10.     State *s;
  11.     s = (State *)n;
  12.     t = s -> ischildwindow;
  13.     tx1 = s -> editx1, tx2 = s -> editx2;
  14.     ty1 = s -> edity1, ty2 = s -> edity2;
  15.     s -> editx1 = 10, s -> edity1 = 50;
  16.     s -> editx2 = getmaxx() - 10, s -> edity2 = getmaxy() - 28;
  17.     s -> ischildwindow = 0;
  18.     OutPutXY(n);
  19.     s -> ischildwindow = t;
  20.     s -> editx1 = tx1, s -> editx2 = tx2;
  21.     s -> edity1 = ty1, s -> edity2 = ty2;
  22. }
  23.  
  24.  
  25.  
  26. void OutPutXY(void *n)
  27. /* put out a txt in a rectangle */
  28. {
  29.     int i=0,j=1,k,m=0,lasti;
  30.     int count;
  31.     char str[78];
  32.     //char str[100];
  33.     Char *ch;
  34.     Row *pagehead;
  35.     Row *rowtmp;
  36.     State *s;
  37.     char ischosen = 0, ishighlight, isend = 1, iscut = 0, isreverse = 0;
  38.     int num;
  39.     /* the most char a row can store */
  40.     int x1, y1, x2, y2;
  41.    
  42.     x1 = 10, y1 = 50;
  43.     x2 = getmaxx() - 10, y2 = getmaxy() - 28;
  44.     s = (State *)n;
  45.     num = (s -> editx2 - s -> editx1)/8 + 1;
  46.    
  47.     if(s -> startrow > s -> endrow || (s -> startrow == s -> endrow && s -> startchar > s -> endchar))
  48.     {
  49.         k = s -> startrow;
  50.         s -> startrow = s -> endrow;
  51.         s -> endrow = k;
  52.         k = s -> startchar;
  53.         s -> startchar = s -> endchar;
  54.         s -> endchar = k;
  55.         isreverse = 1;
  56.     }
  57.    
  58.     //printf("%d,%d|",s -> pagemovecount, s -> currentrow);
  59.    
  60.     ishighlight = s -> highlight;
  61.     if(!s -> ischildwindow)
  62.     {
  63.         RowCount(n);
  64.         pagehead = s -> filehead;
  65.         for(count = 1;count <= s -> pagemovecount && pagehead != NULL;count ++)
  66.         {
  67.             pagehead = pagehead -> next;
  68.         }
  69.         j += s -> pagemovecount;
  70.         //rowtmp = s -> filehead;
  71.         rowtmp = pagehead;
  72.         if(s -> isedit == 1 && pagehead != NULL)
  73.         /* judge the edit mode */
  74.         {
  75.             setfillstyle(SOLID_FILL,WHITE);
  76.             bar(x1,y1,x2,y2);
  77.             /* draw the txt rectangle */
  78.             settextstyle(0,0,1);
  79.             setcolor(BLACK);
  80.             if(s -> startrow < j && s -> endrow >= j)
  81.             {
  82.                 ischosen = 1;
  83.                 s -> highlight = 0;
  84.             }
  85.             do
  86.             {
  87.                 if(isend)
  88.                 {
  89.                     ch = rowtmp -> ch;
  90.                     i = 1;
  91.                     lasti = 0;
  92.                 }
  93.                 else
  94.                 {
  95.                     //ch = ch -> next;
  96.                     //i ++;
  97.                     lasti = i - 1;
  98.                 }
  99.                 isend = 0;
  100.                 k = 0;
  101.                 for(;i < 78 && ((s -> endrow == s -> startrow && s -> endchar == s -> startchar) ||
  102.                    (j != s -> endrow || i != s -> endchar) && (j != s -> startrow || i != s -> startchar) || iscut)
  103.                    &&(i <= num - 1)&&(ch != NULL)&&(ch -> ch != 0); i++)
  104.                 {
  105.                     iscut = 0;
  106.                     str[k ++] = ch -> ch;
  107.                     ch = ch -> next;
  108.                 }
  109.                 if((i == num)||(ch == NULL)||(ch -> ch == 0)||(i  == 78))
  110.                     isend = 1;
  111.                 str[k] = '\0';
  112.                 //iscut = 0;
  113.                 /* store the ch in the Struct */
  114.                 if(ischosen)
  115.                 {
  116.                     setfillstyle(SOLID_FILL,BLUE);
  117.                     bar(x1 + 1 + lasti * 8,y1 + m,x1 + 1 + lasti * 8 + 8 * strlen(str),y1 + m + 15);
  118.                     OutTextxy(n,x1 + 1 + lasti * 8,y1 + m + 2,str,15);
  119.                 }
  120.                 else
  121.                 {
  122.                     OutTextxy(n,x1 + 1 + lasti * 8,y1 + m + 2,str,0);
  123.                 }
  124.                 if(i == s -> startchar && j == s -> startrow)// && (i != s -> endchar || j != s -> endrow))
  125.                 {
  126.                     iscut = 1;
  127.                     ischosen = 1;
  128.                     s -> highlight = 0;
  129.                 }
  130.                 if(i == s -> endchar && j == s -> endrow)// && (i != s -> startchar || j != s -> startrow))
  131.                 {
  132.                     iscut = 1;
  133.                     ischosen = 0;
  134.                     s -> highlight = ishighlight;
  135.                 }
  136.                 /*if(i == num - 1)
  137.                 /* change the row if it is over the box
  138.                 {
  139.                     for(i = 0;ch != NULL;i++)
  140.                     {
  141.                         str[i] = ch -> ch;
  142.                         ch = ch -> next;
  143.                     }
  144.                     OutTextxy(n,x1 + 1,y1 + m + 2,str,0);
  145.                     m += 16;
  146.                 }*/
  147.                 if(isend)
  148.                 {
  149.                     m += 16;
  150.                     rowtmp = rowtmp -> next;
  151.                     j ++;
  152.                 }
  153.             }while((rowtmp != NULL)&&(m <= y2 - y1));
  154.         }
  155.     }
  156.     else if(s -> ischildwindow && s -> isedit && !s -> isdrag)
  157.     {
  158.         if(s -> childhead != NULL)
  159.         {
  160.             rowtmp = s -> childhead;
  161.             ch = rowtmp -> ch;
  162.             for(i = 0;ch != NULL && ch -> ch != 0;i++)
  163.             {
  164.                 str[i] = ch -> ch;
  165.                 ch = ch -> next;
  166.             }
  167.             str[i] = 0;
  168.             setfillstyle(SOLID_FILL,WHITE);
  169.             bar(s -> editx1,s -> edity1,s -> editx2,s -> edity2);
  170.             /* draw the txt rectangle */
  171.             settextstyle(0,0,1);
  172.             setcolor(BLACK);
  173.             OutTextxy(n,s -> editx1,s -> edity1,str,0);
  174.         }
  175.     }
  176.     s -> highlight = ishighlight;
  177.     if(isreverse)
  178.     {
  179.         k = s -> startrow;
  180.         s -> startrow = s -> endrow;
  181.         s -> endrow = k;
  182.         k = s -> startchar;
  183.         s -> startchar = s -> endchar;
  184.         s -> endchar = k;
  185.     }
  186.     if(s -> startchar != s -> endchar || s -> startrow != s -> endrow)
  187.     {
  188.         s -> menu -> next -> menu -> next -> next -> enabled =
  189.         s -> menu -> next -> menu -> next -> next -> next -> enabled =
  190.         s -> menu -> next -> menu -> next -> next -> next -> next -> next -> enabled =
  191.         1;
  192.     }
  193.     else
  194.     {
  195.         s -> menu -> next -> menu -> next -> next -> enabled =
  196.         s -> menu -> next -> menu -> next -> next -> next -> enabled =
  197.         s -> menu -> next -> menu -> next -> next -> next -> next -> next -> enabled =
  198.         0;
  199.     }
  200. }
  201.  
  202. char *GetChildText(void *n)
  203. {
  204.     State *s;
  205.     int i;
  206.     Char *ch;
  207.     char *childtext;
  208.    
  209.     childtext = (char *)ALLOC(20*sizeof(char));
  210.     CheckAlloc((void *)childtext);
  211.     s = (State *)n;
  212.     if(s -> childhead == NULL)
  213.         return NULL;
  214.     ch = s -> childhead -> ch;
  215.     for(i = 0;ch != NULL && ch -> ch != 0 && i < 20 ;i++)
  216.     {
  217.         childtext[i] = ch -> ch;
  218.         ch = ch -> next;
  219.     }
  220.    
  221.     childtext[i] = '\0';
  222.     return childtext;
  223. }
  224.  
  225. char *GetChildText2(void *n)
  226. {
  227.     State *s;
  228.     int i;
  229.     Char *ch;
  230.     char *childtext;
  231.    
  232.     childtext = (char *)ALLOC(20*sizeof(char));
  233.     CheckAlloc((void *)childtext);
  234.     s = (State *)n;
  235.     if(s -> childhead2 == NULL)
  236.         return NULL;
  237.     ch = s -> childhead2 -> ch;
  238.     for(i = 0;ch != NULL;i++)
  239.     {
  240.         childtext[i] = ch -> ch;
  241.         ch = ch -> next;
  242.     }
  243.    
  244.     childtext[i] = '\0';
  245.     return childtext;
  246. }
  247.  
  248. void PageDown(void *n)
  249. {
  250.     State *s;
  251.     s = (State *)n;
  252.     s -> pagemovecount += 1;
  253.     CleanUp(n);
  254.     if(!s -> dotted)
  255.     {
  256.         setactivepage(!s -> page);
  257.         DrawMainWindow(n);
  258.         DrawStatusBox(n);
  259.         DoEvent(s -> redraw, n);
  260.         CleanUp(n);
  261.         setvisualpage(!s -> page);
  262.         s -> page = !s -> page;
  263.     }
  264.     else
  265.     {
  266.         OutPutXY(n);
  267.         CleanUp(n);
  268.     }
  269. }
  270.  
  271. void PageUp(void *n)
  272. {
  273.     State *s;
  274.     s = (State *)n;
  275.     s -> pagemovecount -= 1;
  276.     CleanUp(n);
  277.     if(!s -> dotted)
  278.     {
  279.         setactivepage(!s -> page);
  280.         DrawMainWindow(n);
  281.         DrawStatusBox(n);
  282.         DoEvent(s -> redraw, n);
  283.         CleanUp(n);
  284.         setvisualpage(!s -> page);
  285.         s -> page = !s -> page;
  286.     }
  287.     else
  288.     {
  289.         OutPutXY(n);
  290.         CleanUp(n);
  291.     }
  292. }
  293.  
  294. void BackSpace(void *n)
  295. /*del the NO.N char in Row M*/
  296. {
  297.     State *s;
  298.     Char *q1,*q2;
  299.     Row *q,*line,*line1;
  300.     Row *nextrow;
  301.     int i,j,M,N;
  302.     Char *ch;
  303.     Char *tmpch;
  304.    
  305.     s = (State *)n;
  306.     if(!s -> isedit || s -> ispinyin)
  307.     /* it is strange here... */
  308.         return;
  309.        
  310.    
  311.        
  312.     if(!s -> ischildwindow)
  313.     {
  314.        
  315.         if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
  316.         {
  317.             line = s -> filehead;
  318.             line1 = s -> filehead;
  319.             if(s -> startrow > s -> endrow ||
  320.                 ((s -> startrow == s -> endrow)&&(s -> startchar > s -> endchar)))
  321.             {
  322.                 j = s -> endrow;
  323.                 s -> endrow = s -> startrow;
  324.                 s -> startrow = j;
  325.                
  326.                 i = s -> endchar;
  327.                 s -> endchar = s -> startchar;
  328.                 s -> startchar = i;
  329.             }
  330.             for(i = 1;i < s -> startrow && line != NULL;i++)
  331.             {
  332.                 line = line -> next;
  333.             }
  334.             q1 = line -> ch;
  335.             for(i = 1;i < s -> startchar - 1 && q1 != NULL;i++)
  336.             {
  337.                 q1 = q1 -> next;
  338.             }
  339.            
  340.             for(i = 1;i < s -> endrow && line1 != NULL;i++)
  341.             {
  342.                 line1 = line1 -> next;
  343.             }
  344.             q2 = line1 -> ch;
  345.             for(i = 1;i < s -> endchar - 1 && q2 != NULL;i++)
  346.             {
  347.                 q2 = q2 -> next;
  348.             }
  349.             //printf("%c|%c",q1 -> ch,q2 -> ch);
  350.             if(s -> startchar != 1 && s -> endchar != 1)
  351.             {
  352.                 line -> next = line1 -> next;
  353.                 q1 -> next = q2 -> next;
  354.             }
  355.             if(s -> startchar == 1)
  356.             {
  357.                 line -> next = line1 -> next;
  358.                 line -> ch = q2 -> next;
  359.             }
  360.             if(s -> endchar == 1)
  361.             {
  362.                 line -> next = line1 -> next;
  363.                 q1 -> next = line1 -> ch;
  364.             }
  365.            
  366.            
  367.             s -> currentrow = s -> startrow = s -> endrow = s -> startrow;;
  368.             s -> currentcolumn = s -> endchar = s -> startchar;
  369.             //printf("%d,%d|",s -> startchar,s -> startrow);
  370.            
  371.             CleanUp(n);
  372.             if(!s -> dotted)
  373.             {
  374.                 setactivepage(!s -> page);
  375.                 DrawMainWindow(n);
  376.                 DrawStatusBox(n);
  377.                 DoEvent(s -> redraw, n);
  378.                 CleanUp(n);
  379.                 setvisualpage(!s -> page);
  380.                 s -> page = !s -> page;
  381.             }
  382.             else
  383.             {
  384.                 OutPutXY(n);
  385.                 CleanUp(n);
  386.             }
  387.             return;
  388.         }
  389.        
  390.        
  391.        
  392.        
  393.         q = s -> filehead;
  394.         line = s -> filehead;
  395.        
  396.         if(s -> filehead == NULL)
  397.             return ;
  398.            
  399.         M = s -> currentrow;//- s -> pagemovecount;
  400.         N = s -> currentcolumn - 1;
  401.         if(M == 1 && N == 0)
  402.             return;
  403.            
  404.         if(M > 1 && N == 0)
  405.         /* the first char of a row move to the end of the front row */
  406.         {
  407.             for(i = 1;i < s -> currentrow - 1 && line != NULL;i++)
  408.             /* find the front row */
  409.             {
  410.                 line = line -> next;
  411.             }
  412.             ch = line -> ch;
  413.             if(ch -> ch == '\0')
  414.             /* the front row is blink */
  415.             {
  416.                 nextrow = line -> next;
  417.                 tmpch = nextrow -> ch;
  418.                 line -> ch = tmpch;
  419.                 line -> next = nextrow -> next;
  420.                
  421.                 if(s -> currentrow >= 2)
  422.                 {
  423.                     s -> currentrow -= 1;
  424.                 }
  425.                 else if(s -> currentrow == 1 && s -> pagemovecount != 0)
  426.                 /* be able to pageup */
  427.                 {
  428.                     s -> currentrow = 1;
  429.                 }
  430.                 //s -> currentcolumn += 1;
  431.             }
  432.             else if(ch -> ch != '\0')
  433.             {
  434.                 for(j = 1;ch -> next -> ch != '\0' && ch  -> next != NULL;j++)
  435.                 /* caculate the num of the char */
  436.                 {
  437.                     ch = ch -> next;
  438.                 }
  439.                 nextrow = line -> next;
  440.                 tmpch = nextrow -> ch;
  441.                 ch -> next = tmpch;
  442.                 line -> next = nextrow -> next;
  443.                 //if(s -> cursory > s -> edity1)
  444.                 //printf("%d|%d",s -> currentcolumn,j);
  445.                 if(s -> currentrow >= 2)
  446.                 {
  447.                     //ClrCur(n);
  448.                     //s -> cursorx =  j * 8 + s -> editx1 - 8;
  449.                     //s -> cursory -= 16;
  450.                     if(s -> currentrow >= 2)
  451.                     {
  452.                         s -> currentcolumn = j + 2;
  453.                         s -> currentrow -= 1;
  454.                     }
  455.                     else if(s -> currentrow == 1 && s -> pagemovecount != 0)
  456.                     /* be able to pageup */
  457.                     {
  458.                         s -> currentcolumn = j + 2;
  459.                     }
  460.                     //DrawCur(n);
  461.                 }
  462.             }
  463.             //s -> pagemovecount -= 1;
  464.             //M = M - 1;
  465.             //N = j;
  466.         }
  467.        
  468.         for(i = 1; i < M && line != NULL;i++)
  469.         {
  470.             line = line -> next;
  471.         }
  472.         line1 = line -> next;
  473.         q1 = line -> ch;
  474.        
  475.         if(LeftHZ(n) == 1 && s -> currentcolumn != 1)
  476.         /* BACKSPACE the left char of the cursor when it is a HZ */
  477.         {
  478.             for(i = 1;i < N - 2 && q1 != NULL;i++)
  479.             {
  480.                 q1 = q1 -> next;
  481.             }
  482.             q2 = q1 -> next;
  483.             q2 = q2 -> next;
  484.             if(N == 2)
  485.             {
  486.                 line -> ch = q2;
  487.             }
  488.             else
  489.             {
  490.                 q1 -> next = q2 -> next;
  491.             }
  492.             s -> filehead = q;
  493.             //s -> cursorx -= 8;
  494.             s -> currentcolumn -= 2;
  495.             CleanUp(n);
  496.             if(!s -> dotted)
  497.             {
  498.                 setactivepage(!s -> page);
  499.                 DrawMainWindow(n);
  500.                 DrawStatusBox(n);
  501.                 DoEvent(s -> redraw, n);
  502.                 CleanUp(n);
  503.                 setvisualpage(!s -> page);
  504.                 s -> page = !s -> page;
  505.             }
  506.             else
  507.             {
  508.                 OutPutXY(n);
  509.                 CleanUp(n);
  510.             }
  511.             /* Do a redraw before draw it */
  512.         }
  513.         else
  514.         {
  515.             for(i = 1;i < N-1 && q1 != NULL;i++)
  516.             {
  517.                 q1 = q1 -> next;
  518.             }
  519.             q2 = q1 -> next;
  520.             if(N == 1)
  521.             {
  522.                 line -> ch = q1 -> next;
  523.             }
  524.             else if(N > 1)
  525.             {
  526.                 q1 -> next = q2 -> next;
  527.             }
  528.             s -> filehead = q;
  529.             if(s -> currentcolumn != 1)
  530.                 s -> currentcolumn --;
  531.             CleanUp(n);
  532.             if(!s -> dotted)
  533.             {
  534.                 setactivepage(!s -> page);
  535.                 DrawMainWindow(n);
  536.                 DrawStatusBox(n);
  537.                 DoEvent(s -> redraw, n);
  538.                 CleanUp(n);
  539.                 setvisualpage(!s -> page);
  540.                 s -> page = !s -> page;
  541.             }
  542.             else
  543.             {
  544.                 OutPutXY(n);
  545.                 CleanUp(n);
  546.             }
  547.         }
  548.     }
  549.     else if(s -> ischildwindow && s -> isedit)
  550.     /* deal with the childwindow edit mode */
  551.     {
  552.         line = s -> childhead;
  553.         q2 = line -> ch;
  554.         N = s -> currentcolumn;
  555.         //printf("%d",N);
  556.         if(N == 1)
  557.             return ;
  558.         else
  559.         {
  560.             if(N == 2)
  561.             {
  562.                 q1 = q2 -> next;
  563.                 line -> ch = q1;
  564.             }
  565.             else if(N > 2)
  566.             {
  567.                 for(i = 1;i < N - 2 && q2 != NULL;i++)
  568.                 {
  569.                     q2 = q2 -> next;
  570.                 }
  571.                 //printf("%c",q -> ch);
  572.                 q1 = q2 -> next;
  573.                 //printf("%c",q1 -> ch);
  574.                 q2 -> next = q1 -> next;
  575.             }
  576.             s -> childhead = line;
  577.             s -> currentcolumn -= 1;
  578.             CleanUp(n);
  579.             /*if(!s -> dotted)
  580.             {
  581.                 setactivepage(!s -> page);
  582.                 DrawMainWindow(n);
  583.                 DrawStatusBox(n);
  584.                 DoEvent(s -> redraw, n);
  585.                 CleanUp(n);
  586.                 setvisualpage(!s -> page);
  587.                 s -> page = !s -> page;
  588.             }
  589.             else
  590.             {*/
  591.                 OutPutXY(n);
  592.                 CleanUp(n);
  593.             //}
  594.         }
  595.     }
  596. }
  597.  
  598. void Delete(void *n)
  599. /*del the NO.N char in Row M*/
  600. {
  601.     State *s;
  602.     Char *q1,*q2;
  603.     Row *q,*line,*line1;
  604.     Row *nextrow;
  605.     int i,j,M,N;
  606.     Char *ch,*tmpch;
  607.     Char *nextch;
  608.     Char *nextch1;
  609.    
  610.     s = (State *)n;
  611.     if(!s -> isedit || s -> ispinyin)
  612.     /* it is strange here...it has been solved */
  613.         return;
  614.        
  615.    
  616.        
  617.     if(!s -> ischildwindow)
  618.     {
  619.        
  620.        
  621.         if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
  622.         {
  623.             line = s -> filehead;
  624.             line1 = s -> filehead;
  625.             if(s -> startrow > s -> endrow ||
  626.                 ((s -> startrow == s -> endrow)&&(s -> startchar > s -> endchar)))
  627.             {
  628.                 j = s -> endrow;
  629.                 s -> endrow = s -> startrow;
  630.                 s -> startrow = j;
  631.                
  632.                 i = s -> endchar;
  633.                 s -> endchar = s -> startchar;
  634.                 s -> startchar = i;
  635.             }
  636.             for(i = 1;i < s -> startrow;i++)
  637.             {
  638.                 line = line -> next;
  639.             }
  640.             q1 = line -> ch;
  641.             for(i = 1;i < s -> startchar - 1;i++)
  642.             {
  643.                 q1 = q1 -> next;
  644.             }
  645.            
  646.             for(i = 1;i < s -> endrow;i++)
  647.             {
  648.                 line1 = line1 -> next;
  649.             }
  650.             q2 = line1 -> ch;
  651.             for(i = 1;i < s -> endchar - 1;i++)
  652.             {
  653.                 q2 = q2 -> next;
  654.             }
  655.             //printf("%c|%c",q1 -> ch,q2 -> ch);
  656.             if(s -> startchar != 1 && s -> endchar != 1)
  657.             {
  658.                 line -> next = line1 -> next;
  659.                 q1 -> next = q2 -> next;
  660.             }
  661.             if(s -> startchar == 1)
  662.             {
  663.                 line -> next = line1 -> next;
  664.                 line -> ch = q2 -> next;
  665.             }
  666.             if(s -> endchar == 1)
  667.             {
  668.                 line -> next = line1 -> next;
  669.                 q1 -> next = line1 -> ch;
  670.             }
  671.            
  672.            
  673.             s -> currentrow = s -> endrow = s -> startrow;
  674.             s -> currentcolumn = s -> endchar = s -> startchar;
  675.             //printf("%d,%d|",s -> startchar,s -> startrow);
  676.            
  677.             CleanUp(n);
  678.             if(!s -> dotted)
  679.             {
  680.                 setactivepage(!s -> page);
  681.                 DrawMainWindow(n);
  682.                 DrawStatusBox(n);
  683.                 DoEvent(s -> redraw, n);
  684.                 CleanUp(n);
  685.                 setvisualpage(!s -> page);
  686.                 s -> page = !s -> page;
  687.             }
  688.             else
  689.             {
  690.                 OutPutXY(n);
  691.                 CleanUp(n);
  692.             }
  693.             return;
  694.         }  
  695.        
  696.        
  697.         q = s -> filehead;
  698.         line = s -> filehead;
  699.        
  700.         M = s -> currentrow ;
  701.         N = s -> currentcolumn;
  702.        
  703.         for(i = 1; i <= M - 1 && line != NULL && line -> next != NULL;i++)
  704.         /* find the current row */
  705.         {
  706.             line = line -> next;
  707.         }
  708.         q1 = line -> ch;
  709.         line1 = line -> next;
  710.         /* the nextrow */
  711.        
  712.         ch = line -> ch;
  713.         if(ch -> ch == '\0' && line1 != NULL)
  714.         /* current row is blink */
  715.         {
  716.             //printf("n");
  717.             tmpch = line1 -> ch;
  718.             line -> ch = tmpch;
  719.             nextrow = line1 -> next;
  720.             line -> next = nextrow;
  721.         }
  722.         else if(ch -> ch != '\0')
  723.         {
  724.             for(j = 2;ch -> next -> next != NULL;j++)
  725.             {
  726.                 ch = ch -> next;
  727.             }
  728.             /* calculate the num of the char in current row */
  729.            
  730.             if((M == s -> rowcount) && (N == j))
  731.                 return;
  732.             /* if it is the last chat in a text */
  733.            
  734.             if(N == j && ch -> next != NULL)
  735.             /* put the first char of next row in the end of the current row */
  736.             {
  737.                 nextch = ch -> next;
  738.                 tmpch = line1 -> ch;
  739.                 //nextch1 = tmpch -> next;
  740.                 //printf("%c",tmpch -> next -> ch);
  741.                 ch -> next = tmpch;
  742.                 nextrow = line1 -> next;
  743.                 line -> next = nextrow;
  744.                 //tmpch -> next = nextch;
  745.                 //line1 -> ch = nextch1;
  746.                 //printf("%c",nextch1 -> ch);
  747.            
  748.             }
  749.             else
  750.             {
  751.                 if(RightHZ(n) == 1)
  752.                 {
  753.                     //printf("n");
  754.                     for(i = 1;i < N - 1 && q1 != NULL;i++)
  755.                     {
  756.                         q1 = q1 -> next;
  757.                     }
  758.                     q2 = q1 -> next;
  759.                     q2 = q2 -> next;
  760.                     if(N == 1 && q1 -> next != NULL)
  761.                     {
  762.                         line -> ch = q2;
  763.                     }
  764.                     else if(q1 -> next != NULL)
  765.                     {
  766.                         q1 -> next = q2 -> next;
  767.                     }
  768.                 }
  769.                 else
  770.                 {
  771.                     for(i = 1;i < N - 1 && q1 != NULL;i++)
  772.                     {
  773.                         q1 = q1 -> next;
  774.                     }
  775.                     q2 = q1 -> next;
  776.                     if(N == 1 && q1 -> next != NULL)
  777.                     {
  778.                         line -> ch = q1 -> next;
  779.                     }
  780.                     else
  781.                     {
  782.                         q1 -> next = q2 -> next;
  783.                     }
  784.                 }
  785.             }
  786.         }
  787.         s -> filehead = q;
  788.         CleanUp(n);
  789.         if(!s -> dotted)
  790.         {
  791.             setactivepage(!s -> page);
  792.             DrawMainWindow(n);
  793.             DrawStatusBox(n);
  794.             DoEvent(s -> redraw, n);
  795.             CleanUp(n);
  796.             setvisualpage(!s -> page);
  797.             s -> page = !s -> page;
  798.         }
  799.         else
  800.         {
  801.             OutPutXY(n);
  802.             CleanUp(n);
  803.         }
  804.     }
  805.     else if(s -> ischildwindow && s -> isedit)
  806.     {
  807.         line = s -> childhead;
  808.         q2 = line -> ch;
  809.         N = s -> currentcolumn;
  810.        
  811.         ch = line -> ch;
  812.         for(j = 1;ch -> ch != '\0' && ch != NULL;j++)
  813.         {
  814.             ch = ch -> next;
  815.         }
  816.         //printf("%d",N);
  817.         if(j == N)
  818.             return ;
  819.            
  820.         if(N == 1)
  821.         {
  822.             q1 = q2 -> next;
  823.             line -> ch = q1;
  824.         }
  825.         else if(N > 1)
  826.         {
  827.             for(i = 1;i < N - 1 && q2 != NULL;i++)
  828.             {
  829.                 q2 = q2 -> next;
  830.             }
  831.             q1 = q2 -> next;
  832.             q2 -> next = q1 -> next;
  833.         }
  834.         s -> childhead = line;
  835.         CleanUp(n);
  836.         /*if(!s -> dotted)
  837.         {
  838.             setactivepage(!s -> page);
  839.             DrawMainWindow(n);
  840.             DrawStatusBox(n);
  841.             DoEvent(s -> redraw, n);
  842.             CleanUp(n);
  843.             setvisualpage(!s -> page);
  844.             s -> page = !s -> page;
  845.         }
  846.         else
  847.         {
  848.             */
  849.             OutPutXY(n);
  850.             CleanUp(n);
  851.         //}
  852.     }
  853. }
  854.  
  855. void SwitchCurrent(int *column, int *row, int save)
  856. /* switch the big text and the childwindow */
  857. {
  858.     static int column2 = 1, row2 = 1;
  859.     if(save)
  860.     {
  861.         column2 = *column;
  862.         row2 = *row;
  863.         *column = 1;
  864.         *row = 1;
  865.     }
  866.     else
  867.     {
  868.         *column = column2;
  869.         *row = row2;
  870.     }
  871. }
  872.  
  873. void InitChildhead(void *n)
  874. {
  875.     State *s;
  876.     Char *ch;
  877.     Row *head;
  878.     s = (State *)n;
  879.    
  880.     SwitchCurrent(&s -> currentcolumn, &s -> currentrow, 1);
  881.    
  882.     s -> childhead = ALLOC(sizeof(Row));
  883.     CheckAlloc((void *)(s -> childhead));
  884.     head = s -> childhead;
  885.     head -> next = NULL;
  886.    
  887.     ch = ALLOC(sizeof(Char));
  888.     CheckAlloc((void *)(s -> childhead));
  889.     ch -> ch = '\0';
  890.     ch -> next = NULL;
  891.    
  892.     head -> ch = ch;
  893.     //s -> childhead -> ch = ALLOC(sizeof(Char));
  894.     //CheckAlloc((void *)(s -> childhead -> ch));
  895.     //ch = head -> ch;
  896.     //printf("%d",ch -> ch);
  897. }
  898.  
  899. void InitChildhead2(void *n)
  900. {
  901.     State *s;
  902.     Char *ch;
  903.     Row *head;
  904.     s = (State *)n;
  905.    
  906.     s -> childhead2 = ALLOC(sizeof(Row));
  907.     CheckAlloc((void *)(s -> childhead2));
  908.     head = s -> childhead2;
  909.     s -> childhead2 -> ch = ALLOC(sizeof(Char));
  910.     CheckAlloc((void *)(s -> childhead2 -> ch));
  911.     ch = head -> ch;
  912.     ch -> ch = '\0';
  913.     //printf("%d",ch -> ch);
  914.     ch -> next = NULL;
  915. }
  916.  
  917. void FreeChildhead(void *n)
  918. {
  919.     State *s;
  920.     s = (State *)n;
  921.     SwitchCurrent(&s -> currentcolumn, &s -> currentrow, 0);
  922.     if(s -> childhead != NULL)
  923.         FREEMEMRow(s -> childhead);
  924.     s -> childhead = NULL;
  925.     /*if(s -> startchar != s -> endchar || s -> startrow != s -> endrow)
  926.     {
  927.         s -> currentcolumn = s -> endchar;
  928.         s -> currentrow = s -> endrow;
  929.     }*/
  930. }
  931.  
  932. void FreeChildhead2(void *n)
  933. {
  934.     State *s;
  935.     s = (State *)n;
  936.     if(s -> childhead2 != NULL)
  937.         FREEMEMRow(s -> childhead2);
  938.     s -> childhead2 = NULL;
  939. }
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946. void RowCount(void *n)
  947. /* count the sum of the row */
  948. {
  949.     Row *count,*tmp;
  950.     State *s;
  951.     s = (State *)n;
  952.     if(!s -> isedit || s -> ischildwindow)
  953.         return ;
  954.     /* save the filehead in Struct State */
  955.     count = s -> filehead;
  956.     if( s -> filehead != NULL)
  957.     {
  958.         tmp = count;
  959.         s -> rowcount = 1;
  960.         while(count -> next != NULL)
  961.         {
  962.             count = count -> next;
  963.             s -> rowcount +=1;
  964.         }
  965.         s -> filehead = tmp;
  966.     }
  967.     else
  968.     {
  969.         s -> rowcount = 0;
  970.     }
  971. }
  972.  
  973.  
  974.  
  975. void LineFeed(void *n)
  976. /* put the last char of the current row to the head of a new one */
  977. {
  978.     State *s;
  979.     Row *tmprow;
  980.     /* the current row */
  981.     Row *nextrow;
  982.     /* the next row */
  983.     Row *newrow;
  984.     /* the new row */
  985.     Char *last;
  986.     /* the last char of current row */
  987.     Char *tmpch;
  988.     Char *newhead;
  989.     int MaxColumn;
  990.     int i,j,m;
  991.    
  992.     s = (State *)n;
  993.     tmprow = s -> filehead;
  994.     m = s -> currentrow;
  995.     MaxColumn = (s -> editx2 - s -> editx1)/8 + 1;
  996.     /* caculate the column of the row */
  997.     for(i = 1;i <= m - 1 ;i++)
  998.     {
  999.         tmprow = tmprow -> next;
  1000.     }
  1001.     /* find the current row */
  1002.     tmpch = tmprow -> ch;
  1003.     for(i = 1;tmpch -> next -> next != NULL;i++)
  1004.     {
  1005.         tmpch = tmpch -> next;
  1006.     }
  1007.     /* find the last char */
  1008.     last = tmpch;
  1009.     //printf("%c",last -> ch);
  1010.     nextrow = tmprow -> next;
  1011.     //printf("%d|%d",i,MaxColumn);
  1012.     if(i == MaxColumn)
  1013.     {
  1014.         newrow = ALLOC(sizeof(Row));
  1015.         CheckAlloc((void *)newrow);
  1016.         newrow -> ch = '\0';
  1017.         newrow -> next -> ch = NULL;
  1018.         //nextrow = tmprow -> next;
  1019.         tmprow -> next = newrow;
  1020.         newrow -> next = nextrow;
  1021.         //printf("inside");
  1022.     }
  1023.         tmpch -> ch = '\0';
  1024.         tmpch -> next = NULL;
  1025.         newhead = newrow -> ch;
  1026.         newrow -> ch = last;
  1027.         last -> next = newhead;
  1028. }
  1029.  
  1030. void HZInsert(void *n)
  1031. /*insert a char in front of the No.N char in Row M*/
  1032. {
  1033.     State *s;
  1034.     int i,M,N;
  1035.     Row *head;
  1036.     /* the head of edit mode */
  1037.     Row *childrow;
  1038.     Char *childchar;
  1039.     /* the head of edit mode */
  1040.     Char *word,*q,*tmpchar;
  1041.     Row *line,*line1;
  1042.    
  1043.     s = (State *)n;
  1044.     //printf("%d",last_ischildwindow);
  1045.     /* judge the childwindow's state */
  1046.     if(!s -> isedit || s -> chinese)
  1047.         return;
  1048.     word = ALLOC(sizeof(Char));
  1049.     CheckAlloc((void *)word);
  1050.     M = s -> currentrow;
  1051.     N = s -> currentcolumn;
  1052.    
  1053.     /*for(i=0;i<26;i++)
  1054.     {
  1055.         if((s -> keyboard . key & 0xFF00) == s -> map . chs[i] &&
  1056.             !(s -> keyboard . modifier & CTRL) && !(s -> keyboard . modifier & ALT))
  1057.         {
  1058.             if((s->keyboard.modifier & LEFTSHIFT)||(s->keyboard.modifier & RIGHTSHIFT))
  1059.                 word -> ch = 'A'+i;
  1060.             else
  1061.                 word -> ch = 'a'+i;
  1062.         }
  1063.     }*/
  1064.     /* get the kb key */
  1065.    
  1066.     if(!s -> ischildwindow)
  1067.     /* not in the childwindow */
  1068.     {
  1069.         line = s -> filehead;
  1070.         head = s -> filehead;
  1071.        
  1072.         for(i = 1; i < M; i++)
  1073.         {
  1074.             line = line -> next;
  1075.         }
  1076.         line1 = line -> next;
  1077.         q = line -> ch;
  1078.         for(i = 1;i < N - 1;i++)
  1079.         {
  1080.             q = q -> next;
  1081.         }
  1082.         /* find the right position to insert the char */
  1083.        
  1084.         if(N == 1)
  1085.         /* insert the char in the first of a row */
  1086.         {
  1087.             line -> ch = word;
  1088.             word -> next = q;
  1089.         }
  1090.         else
  1091.         {
  1092.             tmpchar = q -> next;
  1093.             q -> next = word;
  1094.             word -> next = tmpchar;
  1095.         }
  1096.         //LineFeed(n);
  1097.         s -> filehead = head;
  1098.         CleanUp(n);
  1099.         //s -> cursorx += 8;
  1100.         s -> currentcolumn += 1;
  1101.         OutPutXY(n);
  1102.         CleanUp(n);
  1103.     }
  1104.     else if(s -> ischildwindow)
  1105.     /* in the childwindow */
  1106.     {
  1107.         /*if(s -> childhead == NULL)
  1108.         {
  1109.             childrow = ALLOC(sizeof(Row));
  1110.             s -> childhead -> ch = ALLOC(sizeof(Char));
  1111.             childrow -> ch -> ch = '\0';
  1112.             childrow -> ch -> next = NULL;
  1113.         }*/
  1114.        
  1115.         childrow = s -> childhead;
  1116.         childchar = childrow -> ch;
  1117.         //printf("%d",N);
  1118.         if(childchar -> ch == '\0')
  1119.         {
  1120.             childrow -> ch = word;
  1121.             word -> next = childchar;
  1122.             childchar = childrow -> ch;
  1123.         }
  1124.         else
  1125.         {
  1126.             for(i = 1;i < N - 1;i++)
  1127.             {
  1128.                 //printf("%d",N);
  1129.                 childchar = childchar -> next;
  1130.             }
  1131.             tmpchar = childchar -> next;
  1132.             childchar -> next = word;
  1133.             word -> next = tmpchar;
  1134.             s -> childhead = childrow;
  1135.         }
  1136.        
  1137.         CleanUp(n);
  1138.         //s -> cursorx += 8;
  1139.         s -> currentcolumn += 1;
  1140.         OutPutXY(n);
  1141.         CleanUp(n);
  1142.     }
  1143. }
  1144.  
  1145. void Insert(void *n,char *hz)
  1146. /*insert a string in front of the No.N char in Row M*/
  1147. {
  1148.     State *s;
  1149.     Row *head;
  1150.     Row *line;
  1151.     Row *line1;
  1152.     Char *ch;
  1153.     Char *tmpch;
  1154.     Char *nextch;
  1155.     Char *word1,*word2;
  1156.     Char *word;
  1157.     Char *q1,*q2;
  1158.     /* get the two char of a HZ */
  1159.     //Char *t;char test[100];/* just a test */
  1160.     int M,N;
  1161.     int i,j;
  1162.    
  1163.     s = (State *)n;
  1164.    
  1165.     if(!s -> ischildwindow)
  1166.     {
  1167.         if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
  1168.         {
  1169.             line = s -> filehead;
  1170.             line1 = s -> filehead;
  1171.             if(s -> startrow > s -> endrow ||
  1172.                 ((s -> startrow == s -> endrow)&&(s -> startchar > s -> endchar)))
  1173.             {
  1174.                 j = s -> endrow;
  1175.                 s -> endrow = s -> startrow;
  1176.                 s -> startrow = j;
  1177.                
  1178.                 i = s -> endchar;
  1179.                 s -> endchar = s -> startchar;
  1180.                 s -> startchar = i;
  1181.             }
  1182.             for(i = 1;i < s -> startrow;i++)
  1183.             {
  1184.                 line = line -> next;
  1185.             }
  1186.             q1 = line -> ch;
  1187.             for(i = 1;i < s -> startchar - 1;i++)
  1188.             {
  1189.                 q1 = q1 -> next;
  1190.             }
  1191.            
  1192.             for(i = 1;i < s -> endrow;i++)
  1193.             {
  1194.                 line1 = line1 -> next;
  1195.             }
  1196.             q2 = line1 -> ch;
  1197.             for(i = 1;i < s -> endchar - 1;i++)
  1198.             {
  1199.                 q2 = q2 -> next;
  1200.             }
  1201.             //printf("%c|%c",q1 -> ch,q2 -> ch);
  1202.             if(s -> startchar != 1 && s -> endchar != 1)
  1203.             {
  1204.                 line -> next = line1 -> next;
  1205.                 q1 -> next = q2 -> next;
  1206.             }
  1207.             if(s -> startchar == 1)
  1208.             {
  1209.                 line -> next = line1 -> next;
  1210.                 line -> ch = q2 -> next;
  1211.             }
  1212.             if(s -> endchar == 1)
  1213.             {
  1214.                 line -> next = line1 -> next;
  1215.                 q1 -> next = line1 -> ch;
  1216.             }
  1217.            
  1218.            
  1219.             s -> currentrow = s -> startrow = s -> endrow = s -> startrow;;
  1220.             s -> currentcolumn = s -> endchar = s -> startchar;
  1221.             //printf("%d,%d|",s -> startchar,s -> startrow);
  1222.            
  1223.             CleanUp(n);
  1224.             if(!s -> dotted)
  1225.             {
  1226.                 setactivepage(!s -> page);
  1227.                 DrawMainWindow(n);
  1228.                 DrawStatusBox(n);
  1229.                 DoEvent(s -> redraw, n);
  1230.                 CleanUp(n);
  1231.                 setvisualpage(!s -> page);
  1232.                 s -> page = !s -> page;
  1233.             }
  1234.             else
  1235.             {
  1236.                 OutPutXY(n);
  1237.                 CleanUp(n);
  1238.             }
  1239.         }
  1240.        
  1241.         M = s -> currentrow;
  1242.         N = s -> currentcolumn;
  1243.         //word = (Char *)hz;
  1244.         head = s -> filehead;
  1245.         if(head == NULL)
  1246.             return;
  1247.         line = head;
  1248.        
  1249.         //if(!s -> chinese)
  1250.         //  return ;
  1251.         /* judge the chinese insert mode */
  1252.         for(i = 1;i < M && line != NULL ;i ++)
  1253.         {
  1254.             line = line -> next;
  1255.         }
  1256.         if(line == NULL)
  1257.             return;
  1258.         ch = line -> ch;
  1259.         for(i = 1;i < N - 1 && ch != NULL ;i++)
  1260.         {
  1261.             ch = ch -> next;
  1262.         }
  1263.         if(ch == NULL)
  1264.             return;
  1265.         nextch = ch -> next;
  1266.            
  1267.         tmpch = ch;
  1268.         if( N == 1 )
  1269.         /* input HZ in the head of a Row */
  1270.         {
  1271.             nextch = line -> ch;
  1272.             word1 = ALLOC(sizeof(Char));
  1273.             CheckAlloc((void *)word1);
  1274.             //word2 = ALLOC(sizeof(Char));
  1275.             word1 -> ch = hz[0];
  1276.             //word2 -> ch = hz[1];
  1277.             line -> ch = word1;
  1278.             word1 -> next = nextch;
  1279.             //word1 -> next = word2;
  1280.             //word2 -> next = nextch;
  1281.             tmpch = line -> ch;
  1282.             for(i = 1;hz[i] != '\0';i++)
  1283.             {
  1284.                 word2 = ALLOC(sizeof(Char));
  1285.                 CheckAlloc((void *)word2);
  1286.                 word2 -> ch = hz[i];
  1287.                 tmpch -> next = word2;
  1288.                 word2 -> next = nextch;
  1289.                 tmpch = word2;
  1290.             }
  1291.             /*for(i = 0;hz[i] != '\0';i++)
  1292.             {
  1293.                 if(i == 0)
  1294.                 {
  1295.                     line -> ch -> ch = hz[i];
  1296.                     ch = line -> ch;
  1297.                     tmpch = ch;
  1298.                 }
  1299.                 else
  1300.                 {
  1301.                     word = malloc(sizeof(Char));
  1302.                     word -> ch = hz[i];
  1303.                     tmpch -> next = word;
  1304.                     word -> next = nextch;
  1305.                     tmpch = word;
  1306.                 }
  1307.             }*/
  1308.             s -> filehead = head;
  1309.             s -> currentcolumn += i;
  1310.             CleanUp(n);
  1311.             if(!s -> dotted)
  1312.             {
  1313.                 setactivepage(!s -> page);
  1314.                 DrawMainWindow(n);
  1315.                 DrawStatusBox(n);
  1316.                 DoEvent(s -> redraw, n);
  1317.                 CleanUp(n);
  1318.                 setvisualpage(!s -> page);
  1319.                 s -> page = !s -> page;
  1320.             }
  1321.             else
  1322.             {
  1323.                 OutPutXY(n);
  1324.                 CleanUp(n);
  1325.             }
  1326.         }
  1327.         else
  1328.         {
  1329.             for(i = 0;hz[i] != '\0';i++)
  1330.             {
  1331.                 word = ALLOC(sizeof(Char));
  1332.                 CheckAlloc((void *)word);
  1333.                 word -> ch = hz[i];
  1334.                 tmpch -> next = word;
  1335.                 word -> next = nextch;
  1336.                 tmpch = word;
  1337.             }
  1338.             s -> filehead = head;
  1339.             s -> currentcolumn += i;
  1340.             CleanUp(n);
  1341.             if(!s -> dotted)
  1342.             {
  1343.                 setactivepage(!s -> page);
  1344.                 DrawMainWindow(n);
  1345.                 DrawStatusBox(n);
  1346.                 DoEvent(s -> redraw, n);
  1347.                 CleanUp(n);
  1348.                 setvisualpage(!s -> page);
  1349.                 s -> page = !s -> page;
  1350.             }
  1351.             else
  1352.             {
  1353.                 OutPutXY(n);
  1354.                 CleanUp(n);
  1355.             }
  1356.         }
  1357.    
  1358.     }
  1359.     else if(s -> ischildwindow && s -> isedit)
  1360.     /* in the childwindow */
  1361.     {
  1362.         //printf("%d ",strlen(hz));
  1363.         N = s -> currentcolumn;
  1364.         //printf("%d ",N);
  1365.         head = s -> childhead;
  1366.         if(head == NULL)
  1367.             return;
  1368.         line = head;
  1369.         ch = line -> ch;
  1370.         nextch = ch;
  1371.         if(ch == NULL)
  1372.             return;
  1373.         if(ch -> ch == '\0')
  1374.         {
  1375.             word1 = ALLOC(sizeof(Char));
  1376.             CheckAlloc((void *)word1);
  1377.             word1 -> ch = hz[0];
  1378.             s -> currentcolumn ++;
  1379.             line -> ch = word1;
  1380.             //printf("%c",hz[0]);
  1381.             word1 -> next = ch;
  1382.             for(i = 1;hz[i] != '\0';i++)
  1383.             {
  1384.                 word2 = ALLOC(sizeof(Char));
  1385.                 CheckAlloc((void *)word2);
  1386.                 word2 -> ch = hz[i];
  1387.                 s -> currentcolumn ++;
  1388.                 ch -> next = word2;
  1389.                 word2 -> next = nextch;
  1390.                 ch = word2;
  1391.             }
  1392.         }
  1393.         else
  1394.         {
  1395.             for(i = 1;i < N - 1 && ch != NULL && ch -> ch != 0;i++)
  1396.             {
  1397.                 ch = ch -> next;
  1398.             }
  1399.             if(ch == NULL)
  1400.                 return;
  1401.             nextch = ch -> next;
  1402.             for(i = 0;hz[i] != '\0';i++)
  1403.             {
  1404.                 word2 = ALLOC(sizeof(Char));
  1405.                 CheckAlloc((void *)word2);
  1406.                 word2 -> ch = hz[i];
  1407.                 s -> currentcolumn ++;
  1408.                 ch -> next = word2;
  1409.                 word2 -> next = nextch;
  1410.                 ch = word2;
  1411.             }
  1412.         }
  1413.         s -> childhead = head;
  1414.         CleanUp(n);
  1415.         OutPutXY(n);
  1416.         CleanUp(n);
  1417.     }
  1418. }
  1419.  
  1420. void EnterKey(void *n)
  1421. /* add the function of pressing Enter Key */
  1422. {
  1423.     State *s;
  1424.     Row *head;
  1425.     Row *line,*nextrow,*line1;
  1426.     Row *newrow;
  1427.     Char *ch;
  1428.     Char *nextch;
  1429.     Char *tmpch;
  1430.     Char *q1,*q2;
  1431.     int M,N;
  1432.     int i,j,sum;
  1433.    
  1434.     s = (State *)n;
  1435.    
  1436.     if((!s -> isedit) || (s -> ischildwindow) || s -> ispinyin)
  1437.         return ;
  1438.    
  1439.     if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
  1440.     {
  1441.         line = s -> filehead;
  1442.         line1 = s -> filehead;
  1443.         if(s -> startrow > s -> endrow ||
  1444.             ((s -> startrow == s -> endrow)&&(s -> startchar > s -> endchar)))
  1445.         {
  1446.             j = s -> endrow;
  1447.             s -> endrow = s -> startrow;
  1448.             s -> startrow = j;
  1449.            
  1450.             i = s -> endchar;
  1451.             s -> endchar = s -> startchar;
  1452.             s -> startchar = i;
  1453.         }
  1454.         for(i = 1;i < s -> startrow;i++)
  1455.         {
  1456.             line = line -> next;
  1457.         }
  1458.         q1 = line -> ch;
  1459.         for(i = 1;i < s -> startchar - 1;i++)
  1460.         {
  1461.             q1 = q1 -> next;
  1462.         }
  1463.        
  1464.         for(i = 1;i < s -> endrow;i++)
  1465.         {
  1466.             line1 = line1 -> next;
  1467.         }
  1468.         q2 = line1 -> ch;
  1469.         for(i = 1;i < s -> endchar - 1;i++)
  1470.         {
  1471.             q2 = q2 -> next;
  1472.         }
  1473.         //printf("%c|%c",q1 -> ch,q2 -> ch);
  1474.         if(s -> startchar != 1 && s -> endchar != 1)
  1475.         {
  1476.             line -> next = line1 -> next;
  1477.             q1 -> next = q2 -> next;
  1478.         }
  1479.         if(s -> startchar == 1)
  1480.         {
  1481.             line -> next = line1 -> next;
  1482.             line -> ch = q2 -> next;
  1483.         }
  1484.         if(s -> endchar == 1)
  1485.         {
  1486.             line -> next = line1 -> next;
  1487.             q1 -> next = line1 -> ch;
  1488.         }
  1489.        
  1490.        
  1491.         s -> currentrow = s -> startrow = s -> endrow = s -> startrow;;
  1492.         s -> currentcolumn = s -> endchar = s -> startchar;
  1493.         //printf("%d,%d|",s -> startchar,s -> startrow);
  1494.        
  1495.         CleanUp(n);
  1496.         if(!s -> dotted)
  1497.         {
  1498.             setactivepage(!s -> page);
  1499.             DrawMainWindow(n);
  1500.             DrawStatusBox(n);
  1501.             DoEvent(s -> redraw, n);
  1502.             CleanUp(n);
  1503.             setvisualpage(!s -> page);
  1504.             s -> page = !s -> page;
  1505.         }
  1506.         else
  1507.         {
  1508.             OutPutXY(n);
  1509.             CleanUp(n);
  1510.         }
  1511.         return;
  1512.     }
  1513.    
  1514.        
  1515.     head = s -> filehead;
  1516.     //num = (s -> editx2 - s -> editx1)/8;
  1517.     sum = (s -> edity2 - s -> edity1)/16 + 1 + s -> pagemovecount;
  1518.     M = s -> currentrow;
  1519.     /* record the current row */
  1520.     N = s -> currentcolumn;
  1521.     /* record the current column */
  1522.     line = head;
  1523.    
  1524.     for(i = 1;i < M && line != NULL;i++)
  1525.     {
  1526.         line = line -> next;
  1527.     }
  1528.     tmpch = line -> ch;
  1529.     for(j = 1;tmpch != NULL && tmpch -> next != NULL;j++)
  1530.     {
  1531.         tmpch = tmpch -> next;
  1532.     }
  1533.    
  1534.     if( N == j)
  1535.     /* press ENTER KEY in the end of a row */
  1536.     {
  1537.         if(s -> currentrow == sum)
  1538.         {
  1539.             PageDown(n);
  1540.         }
  1541.         nextrow = line -> next;
  1542.         newrow = ALLOC(sizeof(Row));
  1543.         CheckAlloc((void *)newrow);
  1544.        
  1545.         ch = ALLOC(sizeof(Char));
  1546.         CheckAlloc((void *)newrow);
  1547.         ch -> ch = '\0';
  1548.         ch -> next = NULL;
  1549.         newrow -> ch = ch;
  1550.        
  1551.         line -> next = newrow;
  1552.         newrow -> next = nextrow;
  1553.        
  1554.         s -> filehead = head;
  1555.         CleanUp(n);
  1556.         OutPutXY(n);
  1557.         CleanUp(n);
  1558.     }
  1559.     else if(N > 1 && N < j)
  1560.     {
  1561.         nextrow = line -> next;
  1562.        
  1563.         tmpch = line -> ch;
  1564.         for(i = 1;i < N && tmpch -> next != NULL;i++)
  1565.         {
  1566.             tmpch = tmpch -> next;
  1567.         }
  1568.         if(s -> currentrow == sum)
  1569.         {
  1570.             PageDown(n);
  1571.         }
  1572.         ch = ALLOC(sizeof(Char));
  1573.         CheckAlloc((void *)ch);
  1574.         ch -> ch = tmpch -> ch;
  1575.         ch -> next = tmpch -> next;
  1576.         /* store the charchain behind the cursor */
  1577.         //printf("%c|%d\t",ch -> ch,N);
  1578.        
  1579.         newrow = ALLOC(sizeof(Row));
  1580.         CheckAlloc((void *)newrow);
  1581.         newrow -> ch = ch;
  1582.        
  1583.         tmpch -> ch = '\0';
  1584.         tmpch -> next = NULL;
  1585.         /* cut down the current row */
  1586.        
  1587.         line -> next = newrow;
  1588.         newrow -> next = nextrow;
  1589.        
  1590.         s -> filehead = head;
  1591.         CleanUp(n);
  1592.         OutPutXY(n);
  1593.         CleanUp(n);
  1594.     }
  1595.     else if(N == 1)
  1596.     {
  1597.         nextrow = line -> next;
  1598.         tmpch = line -> ch;
  1599.        
  1600.         if(s -> currentrow == sum)
  1601.         {
  1602.             PageDown(n);
  1603.         }
  1604.        
  1605.         ch = ALLOC(sizeof(Char));
  1606.         CheckAlloc((void *)ch);
  1607.         ch -> ch = tmpch -> ch;
  1608.         ch -> next = tmpch -> next;
  1609.        
  1610.         newrow = ALLOC(sizeof(Row));
  1611.         CheckAlloc((void *)newrow);
  1612.         newrow -> ch = ch;
  1613.        
  1614.         tmpch -> ch = '\0';
  1615.         tmpch -> next = NULL;
  1616.         /* cut down the current row */
  1617.        
  1618.         line -> next = newrow;
  1619.         newrow -> next = nextrow;
  1620.        
  1621.         s -> filehead = head;
  1622.         CleanUp(n);
  1623.         OutPutXY(n);
  1624.         CleanUp(n);
  1625.     }
  1626.    
  1627.     ClrCur(n);
  1628.     s -> currentcolumn = 1;
  1629.     s -> currentrow += 1;
  1630.     DrawCur(n);
  1631. }
  1632. /*
  1633. void CtrlX(void *n,void *first,void *end)
  1634. {
  1635.     State *s;
  1636. }
  1637.  
  1638. void CtrlC(void *n,void *first,void *end)
  1639. {
  1640.     State *s;
  1641. }
  1642.  
  1643. void CtrlV(void *n,void *first,void *end)
  1644. {
  1645.     State *s;
  1646. }
  1647. */
  1648.  
  1649. //if(strlen(p) > 1 && (((unsigned char)*p >= 0xa1 && (unsigned char)*p <= 0xfe)
  1650. //     && ((unsigned char) * (p + 1) >= 0xa1 && (unsigned char) * (p + 1) <= 0xfe)))
  1651. /* 在以*p的字符串中,判断是否为汉字 */
  1652.  
  1653.  
  1654. char LeftChar(void *n)
  1655. {
  1656.     State *s;
  1657.     Row *row;
  1658.     Char *ch;
  1659.     int M,N;
  1660.     int i;
  1661.    
  1662.     s = (State *)n;
  1663.     M = s -> currentrow;
  1664.     N = s -> currentcolumn;
  1665.     row = s -> filehead;
  1666.     if(N == 1)
  1667.         return 0;
  1668.     for(i = 1;i < M;i++)
  1669.     {
  1670.         row = row -> next;
  1671.     }
  1672.     ch = row -> ch;
  1673.     for(i = 1;i < N - 1;i++)
  1674.     {
  1675.         ch = ch -> next;
  1676.     }
  1677.     //printf("%c",ch -> ch);
  1678.     return (ch -> ch);
  1679. }
  1680.  
  1681. void Home(void *n)
  1682. /* put the cursor in the first of the currentrow */
  1683. {
  1684.     State *s;
  1685.    
  1686.     s = (State *)n;
  1687.    
  1688.     if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
  1689.     {
  1690.         s -> startchar = s -> endchar = s -> currentcolumn;
  1691.         s -> startrow = s -> endrow = s -> currentrow;
  1692.         /* refresh the start and end */
  1693.         CleanUp(n);
  1694.             if(!s -> dotted)
  1695.             {
  1696.                 setactivepage(!s -> page);
  1697.                 DrawMainWindow(n);
  1698.                 DrawStatusBox(n);
  1699.                 DoEvent(s -> redraw, n);
  1700.                 CleanUp(n);
  1701.                 setvisualpage(!s -> page);
  1702.                 s -> page = !s -> page;
  1703.             }
  1704.             else
  1705.             {
  1706.                 OutPutXY(n);
  1707.                 CleanUp(n);
  1708.             }
  1709.     }
  1710.    
  1711.     if(!s -> ischildwindow)
  1712.     {
  1713.         ClrCur(n);
  1714.         s -> currentcolumn = 1;
  1715.         DrawCur(n);
  1716.     }
  1717.     else if(s -> ischildwindow && s -> isedit)
  1718.     {
  1719.         ClrCur(n);
  1720.         s -> currentcolumn = 1;
  1721.         DrawCur(n);
  1722.     }
  1723. }
  1724.  
  1725. void CtrlHome(void *n)
  1726. /* put the cursor in the first of the firstrow */
  1727. {
  1728.     State *s;
  1729.    
  1730.     s = (State *)n;
  1731.    
  1732.     if(!s -> isedit || s -> ischildwindow)
  1733.         return;
  1734.    
  1735.     ClrCur(n);
  1736.     s -> startchar = s -> endchar = s -> currentcolumn = 1;
  1737.     s -> startrow = s -> endrow = s -> currentrow = 1;
  1738.     DrawCur(n);
  1739.    
  1740.     s -> pagemovecount = 0;
  1741.    
  1742.     /* refresh the start and end */
  1743.     CleanUp(n);
  1744.         if(!s -> dotted)
  1745.         {
  1746.             setactivepage(!s -> page);
  1747.             DrawMainWindow(n);
  1748.             DrawStatusBox(n);
  1749.             DoEvent(s -> redraw, n);
  1750.             CleanUp(n);
  1751.             setvisualpage(!s -> page);
  1752.             s -> page = !s -> page;
  1753.         }
  1754.         else
  1755.         {
  1756.             OutPutXY(n);
  1757.             CleanUp(n);
  1758.         }
  1759. }
  1760.  
  1761. void End(void *n)
  1762. /* put the cursor in the end of the currentrow */
  1763. {
  1764.     State *s;
  1765.     int i;
  1766.     Row *line;
  1767.     Char *ch;
  1768.     s = (State *)n;
  1769.    
  1770.     if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
  1771.     {
  1772.         s -> startchar = s -> endchar = s -> currentcolumn;
  1773.         s -> startrow = s -> endrow = s -> currentrow;
  1774.         /* refresh the start and end */
  1775.         CleanUp(n);
  1776.             if(!s -> dotted)
  1777.             {
  1778.                 setactivepage(!s -> page);
  1779.                 DrawMainWindow(n);
  1780.                 DrawStatusBox(n);
  1781.                 DoEvent(s -> redraw, n);
  1782.                 CleanUp(n);
  1783.                 setvisualpage(!s -> page);
  1784.                 s -> page = !s -> page;
  1785.             }
  1786.             else
  1787.             {
  1788.                 OutPutXY(n);
  1789.                 CleanUp(n);
  1790.             }
  1791.     }
  1792.    
  1793.     if(!s -> ischildwindow)
  1794.     {
  1795.         line = s -> filehead;
  1796.         for(i = 1;i < s -> currentrow && line != NULL;i++)
  1797.         {
  1798.             line = line -> next;
  1799.         }
  1800.         ch = line -> ch;
  1801.         for(i = 1;ch != NULL && ch -> next != NULL;i++)
  1802.         {
  1803.             ch = ch -> next;
  1804.         }
  1805.         ClrCur(n);
  1806.         s -> currentcolumn = i;
  1807.         DrawCur(n);
  1808.     }
  1809.     else if(s -> ischildwindow && s -> isedit)
  1810.     {
  1811.         line = s -> childhead;
  1812.         ch = line -> ch;
  1813.         for(i = 1;ch != NULL && ch -> next != NULL;i++)
  1814.         {
  1815.             ch = ch -> next;
  1816.         }
  1817.         ClrCur(n);
  1818.         s -> currentcolumn = i;
  1819.         DrawCur(n);
  1820.     }
  1821. }
  1822.  
  1823. void CtrlEnd(void *n)
  1824. /* put the cursor in the end of the currentrow */
  1825. {
  1826.     State *s;
  1827.     int i;
  1828.     Row *line;
  1829.     Char *ch;
  1830.    
  1831.     s = (State *)n;
  1832.    
  1833.     if(!s -> isedit || s -> ischildwindow)
  1834.         return;
  1835.    
  1836.     line = s -> filehead;
  1837.     for(i = 1;i != s -> rowcount;i++)
  1838.     {
  1839.         line = line -> next;
  1840.     }
  1841.     ch = line -> ch;
  1842.     for(i = 1;ch != NULL && ch -> next != NULL;i++)
  1843.     {
  1844.         ch = ch -> next;
  1845.     }
  1846.     ClrCur(n);
  1847.     s -> startchar = s -> endchar = s -> currentcolumn = i;
  1848.     s -> startrow = s -> endrow = s -> currentrow = s -> rowcount;
  1849.     DrawCur(n);
  1850. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement