Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "edit.h"
- #include "common.h"
- #include "mouse.h"
- #include "file.h"
- #include "cursor.h"
- void OutPutMain(void *n)
- {
- int t, tx1, tx2, ty1, ty2;
- State *s;
- s = (State *)n;
- t = s -> ischildwindow;
- tx1 = s -> editx1, tx2 = s -> editx2;
- ty1 = s -> edity1, ty2 = s -> edity2;
- s -> editx1 = 10, s -> edity1 = 50;
- s -> editx2 = getmaxx() - 10, s -> edity2 = getmaxy() - 28;
- s -> ischildwindow = 0;
- OutPutXY(n);
- s -> ischildwindow = t;
- s -> editx1 = tx1, s -> editx2 = tx2;
- s -> edity1 = ty1, s -> edity2 = ty2;
- }
- void OutPutXY(void *n)
- /* put out a txt in a rectangle */
- {
- int i=0,j=1,k,m=0,lasti;
- int count;
- char str[78];
- //char str[100];
- Char *ch;
- Row *pagehead;
- Row *rowtmp;
- State *s;
- char ischosen = 0, ishighlight, isend = 1, iscut = 0, isreverse = 0;
- int num;
- /* the most char a row can store */
- int x1, y1, x2, y2;
- x1 = 10, y1 = 50;
- x2 = getmaxx() - 10, y2 = getmaxy() - 28;
- s = (State *)n;
- num = (s -> editx2 - s -> editx1)/8 + 1;
- if(s -> startrow > s -> endrow || (s -> startrow == s -> endrow && s -> startchar > s -> endchar))
- {
- k = s -> startrow;
- s -> startrow = s -> endrow;
- s -> endrow = k;
- k = s -> startchar;
- s -> startchar = s -> endchar;
- s -> endchar = k;
- isreverse = 1;
- }
- //printf("%d,%d|",s -> pagemovecount, s -> currentrow);
- ishighlight = s -> highlight;
- if(!s -> ischildwindow)
- {
- RowCount(n);
- pagehead = s -> filehead;
- for(count = 1;count <= s -> pagemovecount && pagehead != NULL;count ++)
- {
- pagehead = pagehead -> next;
- }
- j += s -> pagemovecount;
- //rowtmp = s -> filehead;
- rowtmp = pagehead;
- if(s -> isedit == 1 && pagehead != NULL)
- /* judge the edit mode */
- {
- setfillstyle(SOLID_FILL,WHITE);
- bar(x1,y1,x2,y2);
- /* draw the txt rectangle */
- settextstyle(0,0,1);
- setcolor(BLACK);
- if(s -> startrow < j && s -> endrow >= j)
- {
- ischosen = 1;
- s -> highlight = 0;
- }
- do
- {
- if(isend)
- {
- ch = rowtmp -> ch;
- i = 1;
- lasti = 0;
- }
- else
- {
- //ch = ch -> next;
- //i ++;
- lasti = i - 1;
- }
- isend = 0;
- k = 0;
- for(;i < 78 && ((s -> endrow == s -> startrow && s -> endchar == s -> startchar) ||
- (j != s -> endrow || i != s -> endchar) && (j != s -> startrow || i != s -> startchar) || iscut)
- &&(i <= num - 1)&&(ch != NULL)&&(ch -> ch != 0); i++)
- {
- iscut = 0;
- str[k ++] = ch -> ch;
- ch = ch -> next;
- }
- if((i == num)||(ch == NULL)||(ch -> ch == 0)||(i == 78))
- isend = 1;
- str[k] = '\0';
- //iscut = 0;
- /* store the ch in the Struct */
- if(ischosen)
- {
- setfillstyle(SOLID_FILL,BLUE);
- bar(x1 + 1 + lasti * 8,y1 + m,x1 + 1 + lasti * 8 + 8 * strlen(str),y1 + m + 15);
- OutTextxy(n,x1 + 1 + lasti * 8,y1 + m + 2,str,15);
- }
- else
- {
- OutTextxy(n,x1 + 1 + lasti * 8,y1 + m + 2,str,0);
- }
- if(i == s -> startchar && j == s -> startrow)// && (i != s -> endchar || j != s -> endrow))
- {
- iscut = 1;
- ischosen = 1;
- s -> highlight = 0;
- }
- if(i == s -> endchar && j == s -> endrow)// && (i != s -> startchar || j != s -> startrow))
- {
- iscut = 1;
- ischosen = 0;
- s -> highlight = ishighlight;
- }
- /*if(i == num - 1)
- /* change the row if it is over the box
- {
- for(i = 0;ch != NULL;i++)
- {
- str[i] = ch -> ch;
- ch = ch -> next;
- }
- OutTextxy(n,x1 + 1,y1 + m + 2,str,0);
- m += 16;
- }*/
- if(isend)
- {
- m += 16;
- rowtmp = rowtmp -> next;
- j ++;
- }
- }while((rowtmp != NULL)&&(m <= y2 - y1));
- }
- }
- else if(s -> ischildwindow && s -> isedit && !s -> isdrag)
- {
- if(s -> childhead != NULL)
- {
- rowtmp = s -> childhead;
- ch = rowtmp -> ch;
- for(i = 0;ch != NULL && ch -> ch != 0;i++)
- {
- str[i] = ch -> ch;
- ch = ch -> next;
- }
- str[i] = 0;
- setfillstyle(SOLID_FILL,WHITE);
- bar(s -> editx1,s -> edity1,s -> editx2,s -> edity2);
- /* draw the txt rectangle */
- settextstyle(0,0,1);
- setcolor(BLACK);
- OutTextxy(n,s -> editx1,s -> edity1,str,0);
- }
- }
- s -> highlight = ishighlight;
- if(isreverse)
- {
- k = s -> startrow;
- s -> startrow = s -> endrow;
- s -> endrow = k;
- k = s -> startchar;
- s -> startchar = s -> endchar;
- s -> endchar = k;
- }
- if(s -> startchar != s -> endchar || s -> startrow != s -> endrow)
- {
- s -> menu -> next -> menu -> next -> next -> enabled =
- s -> menu -> next -> menu -> next -> next -> next -> enabled =
- s -> menu -> next -> menu -> next -> next -> next -> next -> next -> enabled =
- 1;
- }
- else
- {
- s -> menu -> next -> menu -> next -> next -> enabled =
- s -> menu -> next -> menu -> next -> next -> next -> enabled =
- s -> menu -> next -> menu -> next -> next -> next -> next -> next -> enabled =
- 0;
- }
- }
- char *GetChildText(void *n)
- {
- State *s;
- int i;
- Char *ch;
- char *childtext;
- childtext = (char *)ALLOC(20*sizeof(char));
- CheckAlloc((void *)childtext);
- s = (State *)n;
- if(s -> childhead == NULL)
- return NULL;
- ch = s -> childhead -> ch;
- for(i = 0;ch != NULL && ch -> ch != 0 && i < 20 ;i++)
- {
- childtext[i] = ch -> ch;
- ch = ch -> next;
- }
- childtext[i] = '\0';
- return childtext;
- }
- char *GetChildText2(void *n)
- {
- State *s;
- int i;
- Char *ch;
- char *childtext;
- childtext = (char *)ALLOC(20*sizeof(char));
- CheckAlloc((void *)childtext);
- s = (State *)n;
- if(s -> childhead2 == NULL)
- return NULL;
- ch = s -> childhead2 -> ch;
- for(i = 0;ch != NULL;i++)
- {
- childtext[i] = ch -> ch;
- ch = ch -> next;
- }
- childtext[i] = '\0';
- return childtext;
- }
- void PageDown(void *n)
- {
- State *s;
- s = (State *)n;
- s -> pagemovecount += 1;
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- }
- void PageUp(void *n)
- {
- State *s;
- s = (State *)n;
- s -> pagemovecount -= 1;
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- }
- void BackSpace(void *n)
- /*del the NO.N char in Row M*/
- {
- State *s;
- Char *q1,*q2;
- Row *q,*line,*line1;
- Row *nextrow;
- int i,j,M,N;
- Char *ch;
- Char *tmpch;
- s = (State *)n;
- if(!s -> isedit || s -> ispinyin)
- /* it is strange here... */
- return;
- if(!s -> ischildwindow)
- {
- if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
- {
- line = s -> filehead;
- line1 = s -> filehead;
- if(s -> startrow > s -> endrow ||
- ((s -> startrow == s -> endrow)&&(s -> startchar > s -> endchar)))
- {
- j = s -> endrow;
- s -> endrow = s -> startrow;
- s -> startrow = j;
- i = s -> endchar;
- s -> endchar = s -> startchar;
- s -> startchar = i;
- }
- for(i = 1;i < s -> startrow && line != NULL;i++)
- {
- line = line -> next;
- }
- q1 = line -> ch;
- for(i = 1;i < s -> startchar - 1 && q1 != NULL;i++)
- {
- q1 = q1 -> next;
- }
- for(i = 1;i < s -> endrow && line1 != NULL;i++)
- {
- line1 = line1 -> next;
- }
- q2 = line1 -> ch;
- for(i = 1;i < s -> endchar - 1 && q2 != NULL;i++)
- {
- q2 = q2 -> next;
- }
- //printf("%c|%c",q1 -> ch,q2 -> ch);
- if(s -> startchar != 1 && s -> endchar != 1)
- {
- line -> next = line1 -> next;
- q1 -> next = q2 -> next;
- }
- if(s -> startchar == 1)
- {
- line -> next = line1 -> next;
- line -> ch = q2 -> next;
- }
- if(s -> endchar == 1)
- {
- line -> next = line1 -> next;
- q1 -> next = line1 -> ch;
- }
- s -> currentrow = s -> startrow = s -> endrow = s -> startrow;;
- s -> currentcolumn = s -> endchar = s -> startchar;
- //printf("%d,%d|",s -> startchar,s -> startrow);
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- return;
- }
- q = s -> filehead;
- line = s -> filehead;
- if(s -> filehead == NULL)
- return ;
- M = s -> currentrow;//- s -> pagemovecount;
- N = s -> currentcolumn - 1;
- if(M == 1 && N == 0)
- return;
- if(M > 1 && N == 0)
- /* the first char of a row move to the end of the front row */
- {
- for(i = 1;i < s -> currentrow - 1 && line != NULL;i++)
- /* find the front row */
- {
- line = line -> next;
- }
- ch = line -> ch;
- if(ch -> ch == '\0')
- /* the front row is blink */
- {
- nextrow = line -> next;
- tmpch = nextrow -> ch;
- line -> ch = tmpch;
- line -> next = nextrow -> next;
- if(s -> currentrow >= 2)
- {
- s -> currentrow -= 1;
- }
- else if(s -> currentrow == 1 && s -> pagemovecount != 0)
- /* be able to pageup */
- {
- s -> currentrow = 1;
- }
- //s -> currentcolumn += 1;
- }
- else if(ch -> ch != '\0')
- {
- for(j = 1;ch -> next -> ch != '\0' && ch -> next != NULL;j++)
- /* caculate the num of the char */
- {
- ch = ch -> next;
- }
- nextrow = line -> next;
- tmpch = nextrow -> ch;
- ch -> next = tmpch;
- line -> next = nextrow -> next;
- //if(s -> cursory > s -> edity1)
- //printf("%d|%d",s -> currentcolumn,j);
- if(s -> currentrow >= 2)
- {
- //ClrCur(n);
- //s -> cursorx = j * 8 + s -> editx1 - 8;
- //s -> cursory -= 16;
- if(s -> currentrow >= 2)
- {
- s -> currentcolumn = j + 2;
- s -> currentrow -= 1;
- }
- else if(s -> currentrow == 1 && s -> pagemovecount != 0)
- /* be able to pageup */
- {
- s -> currentcolumn = j + 2;
- }
- //DrawCur(n);
- }
- }
- //s -> pagemovecount -= 1;
- //M = M - 1;
- //N = j;
- }
- for(i = 1; i < M && line != NULL;i++)
- {
- line = line -> next;
- }
- line1 = line -> next;
- q1 = line -> ch;
- if(LeftHZ(n) == 1 && s -> currentcolumn != 1)
- /* BACKSPACE the left char of the cursor when it is a HZ */
- {
- for(i = 1;i < N - 2 && q1 != NULL;i++)
- {
- q1 = q1 -> next;
- }
- q2 = q1 -> next;
- q2 = q2 -> next;
- if(N == 2)
- {
- line -> ch = q2;
- }
- else
- {
- q1 -> next = q2 -> next;
- }
- s -> filehead = q;
- //s -> cursorx -= 8;
- s -> currentcolumn -= 2;
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- /* Do a redraw before draw it */
- }
- else
- {
- for(i = 1;i < N-1 && q1 != NULL;i++)
- {
- q1 = q1 -> next;
- }
- q2 = q1 -> next;
- if(N == 1)
- {
- line -> ch = q1 -> next;
- }
- else if(N > 1)
- {
- q1 -> next = q2 -> next;
- }
- s -> filehead = q;
- if(s -> currentcolumn != 1)
- s -> currentcolumn --;
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- }
- }
- else if(s -> ischildwindow && s -> isedit)
- /* deal with the childwindow edit mode */
- {
- line = s -> childhead;
- q2 = line -> ch;
- N = s -> currentcolumn;
- //printf("%d",N);
- if(N == 1)
- return ;
- else
- {
- if(N == 2)
- {
- q1 = q2 -> next;
- line -> ch = q1;
- }
- else if(N > 2)
- {
- for(i = 1;i < N - 2 && q2 != NULL;i++)
- {
- q2 = q2 -> next;
- }
- //printf("%c",q -> ch);
- q1 = q2 -> next;
- //printf("%c",q1 -> ch);
- q2 -> next = q1 -> next;
- }
- s -> childhead = line;
- s -> currentcolumn -= 1;
- CleanUp(n);
- /*if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {*/
- OutPutXY(n);
- CleanUp(n);
- //}
- }
- }
- }
- void Delete(void *n)
- /*del the NO.N char in Row M*/
- {
- State *s;
- Char *q1,*q2;
- Row *q,*line,*line1;
- Row *nextrow;
- int i,j,M,N;
- Char *ch,*tmpch;
- Char *nextch;
- Char *nextch1;
- s = (State *)n;
- if(!s -> isedit || s -> ispinyin)
- /* it is strange here...it has been solved */
- return;
- if(!s -> ischildwindow)
- {
- if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
- {
- line = s -> filehead;
- line1 = s -> filehead;
- if(s -> startrow > s -> endrow ||
- ((s -> startrow == s -> endrow)&&(s -> startchar > s -> endchar)))
- {
- j = s -> endrow;
- s -> endrow = s -> startrow;
- s -> startrow = j;
- i = s -> endchar;
- s -> endchar = s -> startchar;
- s -> startchar = i;
- }
- for(i = 1;i < s -> startrow;i++)
- {
- line = line -> next;
- }
- q1 = line -> ch;
- for(i = 1;i < s -> startchar - 1;i++)
- {
- q1 = q1 -> next;
- }
- for(i = 1;i < s -> endrow;i++)
- {
- line1 = line1 -> next;
- }
- q2 = line1 -> ch;
- for(i = 1;i < s -> endchar - 1;i++)
- {
- q2 = q2 -> next;
- }
- //printf("%c|%c",q1 -> ch,q2 -> ch);
- if(s -> startchar != 1 && s -> endchar != 1)
- {
- line -> next = line1 -> next;
- q1 -> next = q2 -> next;
- }
- if(s -> startchar == 1)
- {
- line -> next = line1 -> next;
- line -> ch = q2 -> next;
- }
- if(s -> endchar == 1)
- {
- line -> next = line1 -> next;
- q1 -> next = line1 -> ch;
- }
- s -> currentrow = s -> endrow = s -> startrow;
- s -> currentcolumn = s -> endchar = s -> startchar;
- //printf("%d,%d|",s -> startchar,s -> startrow);
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- return;
- }
- q = s -> filehead;
- line = s -> filehead;
- M = s -> currentrow ;
- N = s -> currentcolumn;
- for(i = 1; i <= M - 1 && line != NULL && line -> next != NULL;i++)
- /* find the current row */
- {
- line = line -> next;
- }
- q1 = line -> ch;
- line1 = line -> next;
- /* the nextrow */
- ch = line -> ch;
- if(ch -> ch == '\0' && line1 != NULL)
- /* current row is blink */
- {
- //printf("n");
- tmpch = line1 -> ch;
- line -> ch = tmpch;
- nextrow = line1 -> next;
- line -> next = nextrow;
- }
- else if(ch -> ch != '\0')
- {
- for(j = 2;ch -> next -> next != NULL;j++)
- {
- ch = ch -> next;
- }
- /* calculate the num of the char in current row */
- if((M == s -> rowcount) && (N == j))
- return;
- /* if it is the last chat in a text */
- if(N == j && ch -> next != NULL)
- /* put the first char of next row in the end of the current row */
- {
- nextch = ch -> next;
- tmpch = line1 -> ch;
- //nextch1 = tmpch -> next;
- //printf("%c",tmpch -> next -> ch);
- ch -> next = tmpch;
- nextrow = line1 -> next;
- line -> next = nextrow;
- //tmpch -> next = nextch;
- //line1 -> ch = nextch1;
- //printf("%c",nextch1 -> ch);
- }
- else
- {
- if(RightHZ(n) == 1)
- {
- //printf("n");
- for(i = 1;i < N - 1 && q1 != NULL;i++)
- {
- q1 = q1 -> next;
- }
- q2 = q1 -> next;
- q2 = q2 -> next;
- if(N == 1 && q1 -> next != NULL)
- {
- line -> ch = q2;
- }
- else if(q1 -> next != NULL)
- {
- q1 -> next = q2 -> next;
- }
- }
- else
- {
- for(i = 1;i < N - 1 && q1 != NULL;i++)
- {
- q1 = q1 -> next;
- }
- q2 = q1 -> next;
- if(N == 1 && q1 -> next != NULL)
- {
- line -> ch = q1 -> next;
- }
- else
- {
- q1 -> next = q2 -> next;
- }
- }
- }
- }
- s -> filehead = q;
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- }
- else if(s -> ischildwindow && s -> isedit)
- {
- line = s -> childhead;
- q2 = line -> ch;
- N = s -> currentcolumn;
- ch = line -> ch;
- for(j = 1;ch -> ch != '\0' && ch != NULL;j++)
- {
- ch = ch -> next;
- }
- //printf("%d",N);
- if(j == N)
- return ;
- if(N == 1)
- {
- q1 = q2 -> next;
- line -> ch = q1;
- }
- else if(N > 1)
- {
- for(i = 1;i < N - 1 && q2 != NULL;i++)
- {
- q2 = q2 -> next;
- }
- q1 = q2 -> next;
- q2 -> next = q1 -> next;
- }
- s -> childhead = line;
- CleanUp(n);
- /*if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- */
- OutPutXY(n);
- CleanUp(n);
- //}
- }
- }
- void SwitchCurrent(int *column, int *row, int save)
- /* switch the big text and the childwindow */
- {
- static int column2 = 1, row2 = 1;
- if(save)
- {
- column2 = *column;
- row2 = *row;
- *column = 1;
- *row = 1;
- }
- else
- {
- *column = column2;
- *row = row2;
- }
- }
- void InitChildhead(void *n)
- {
- State *s;
- Char *ch;
- Row *head;
- s = (State *)n;
- SwitchCurrent(&s -> currentcolumn, &s -> currentrow, 1);
- s -> childhead = ALLOC(sizeof(Row));
- CheckAlloc((void *)(s -> childhead));
- head = s -> childhead;
- head -> next = NULL;
- ch = ALLOC(sizeof(Char));
- CheckAlloc((void *)(s -> childhead));
- ch -> ch = '\0';
- ch -> next = NULL;
- head -> ch = ch;
- //s -> childhead -> ch = ALLOC(sizeof(Char));
- //CheckAlloc((void *)(s -> childhead -> ch));
- //ch = head -> ch;
- //printf("%d",ch -> ch);
- }
- void InitChildhead2(void *n)
- {
- State *s;
- Char *ch;
- Row *head;
- s = (State *)n;
- s -> childhead2 = ALLOC(sizeof(Row));
- CheckAlloc((void *)(s -> childhead2));
- head = s -> childhead2;
- s -> childhead2 -> ch = ALLOC(sizeof(Char));
- CheckAlloc((void *)(s -> childhead2 -> ch));
- ch = head -> ch;
- ch -> ch = '\0';
- //printf("%d",ch -> ch);
- ch -> next = NULL;
- }
- void FreeChildhead(void *n)
- {
- State *s;
- s = (State *)n;
- SwitchCurrent(&s -> currentcolumn, &s -> currentrow, 0);
- if(s -> childhead != NULL)
- FREEMEMRow(s -> childhead);
- s -> childhead = NULL;
- /*if(s -> startchar != s -> endchar || s -> startrow != s -> endrow)
- {
- s -> currentcolumn = s -> endchar;
- s -> currentrow = s -> endrow;
- }*/
- }
- void FreeChildhead2(void *n)
- {
- State *s;
- s = (State *)n;
- if(s -> childhead2 != NULL)
- FREEMEMRow(s -> childhead2);
- s -> childhead2 = NULL;
- }
- void RowCount(void *n)
- /* count the sum of the row */
- {
- Row *count,*tmp;
- State *s;
- s = (State *)n;
- if(!s -> isedit || s -> ischildwindow)
- return ;
- /* save the filehead in Struct State */
- count = s -> filehead;
- if( s -> filehead != NULL)
- {
- tmp = count;
- s -> rowcount = 1;
- while(count -> next != NULL)
- {
- count = count -> next;
- s -> rowcount +=1;
- }
- s -> filehead = tmp;
- }
- else
- {
- s -> rowcount = 0;
- }
- }
- void LineFeed(void *n)
- /* put the last char of the current row to the head of a new one */
- {
- State *s;
- Row *tmprow;
- /* the current row */
- Row *nextrow;
- /* the next row */
- Row *newrow;
- /* the new row */
- Char *last;
- /* the last char of current row */
- Char *tmpch;
- Char *newhead;
- int MaxColumn;
- int i,j,m;
- s = (State *)n;
- tmprow = s -> filehead;
- m = s -> currentrow;
- MaxColumn = (s -> editx2 - s -> editx1)/8 + 1;
- /* caculate the column of the row */
- for(i = 1;i <= m - 1 ;i++)
- {
- tmprow = tmprow -> next;
- }
- /* find the current row */
- tmpch = tmprow -> ch;
- for(i = 1;tmpch -> next -> next != NULL;i++)
- {
- tmpch = tmpch -> next;
- }
- /* find the last char */
- last = tmpch;
- //printf("%c",last -> ch);
- nextrow = tmprow -> next;
- //printf("%d|%d",i,MaxColumn);
- if(i == MaxColumn)
- {
- newrow = ALLOC(sizeof(Row));
- CheckAlloc((void *)newrow);
- newrow -> ch = '\0';
- newrow -> next -> ch = NULL;
- //nextrow = tmprow -> next;
- tmprow -> next = newrow;
- newrow -> next = nextrow;
- //printf("inside");
- }
- tmpch -> ch = '\0';
- tmpch -> next = NULL;
- newhead = newrow -> ch;
- newrow -> ch = last;
- last -> next = newhead;
- }
- void HZInsert(void *n)
- /*insert a char in front of the No.N char in Row M*/
- {
- State *s;
- int i,M,N;
- Row *head;
- /* the head of edit mode */
- Row *childrow;
- Char *childchar;
- /* the head of edit mode */
- Char *word,*q,*tmpchar;
- Row *line,*line1;
- s = (State *)n;
- //printf("%d",last_ischildwindow);
- /* judge the childwindow's state */
- if(!s -> isedit || s -> chinese)
- return;
- word = ALLOC(sizeof(Char));
- CheckAlloc((void *)word);
- M = s -> currentrow;
- N = s -> currentcolumn;
- /*for(i=0;i<26;i++)
- {
- if((s -> keyboard . key & 0xFF00) == s -> map . chs[i] &&
- !(s -> keyboard . modifier & CTRL) && !(s -> keyboard . modifier & ALT))
- {
- if((s->keyboard.modifier & LEFTSHIFT)||(s->keyboard.modifier & RIGHTSHIFT))
- word -> ch = 'A'+i;
- else
- word -> ch = 'a'+i;
- }
- }*/
- /* get the kb key */
- if(!s -> ischildwindow)
- /* not in the childwindow */
- {
- line = s -> filehead;
- head = s -> filehead;
- for(i = 1; i < M; i++)
- {
- line = line -> next;
- }
- line1 = line -> next;
- q = line -> ch;
- for(i = 1;i < N - 1;i++)
- {
- q = q -> next;
- }
- /* find the right position to insert the char */
- if(N == 1)
- /* insert the char in the first of a row */
- {
- line -> ch = word;
- word -> next = q;
- }
- else
- {
- tmpchar = q -> next;
- q -> next = word;
- word -> next = tmpchar;
- }
- //LineFeed(n);
- s -> filehead = head;
- CleanUp(n);
- //s -> cursorx += 8;
- s -> currentcolumn += 1;
- OutPutXY(n);
- CleanUp(n);
- }
- else if(s -> ischildwindow)
- /* in the childwindow */
- {
- /*if(s -> childhead == NULL)
- {
- childrow = ALLOC(sizeof(Row));
- s -> childhead -> ch = ALLOC(sizeof(Char));
- childrow -> ch -> ch = '\0';
- childrow -> ch -> next = NULL;
- }*/
- childrow = s -> childhead;
- childchar = childrow -> ch;
- //printf("%d",N);
- if(childchar -> ch == '\0')
- {
- childrow -> ch = word;
- word -> next = childchar;
- childchar = childrow -> ch;
- }
- else
- {
- for(i = 1;i < N - 1;i++)
- {
- //printf("%d",N);
- childchar = childchar -> next;
- }
- tmpchar = childchar -> next;
- childchar -> next = word;
- word -> next = tmpchar;
- s -> childhead = childrow;
- }
- CleanUp(n);
- //s -> cursorx += 8;
- s -> currentcolumn += 1;
- OutPutXY(n);
- CleanUp(n);
- }
- }
- void Insert(void *n,char *hz)
- /*insert a string in front of the No.N char in Row M*/
- {
- State *s;
- Row *head;
- Row *line;
- Row *line1;
- Char *ch;
- Char *tmpch;
- Char *nextch;
- Char *word1,*word2;
- Char *word;
- Char *q1,*q2;
- /* get the two char of a HZ */
- //Char *t;char test[100];/* just a test */
- int M,N;
- int i,j;
- s = (State *)n;
- if(!s -> ischildwindow)
- {
- if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
- {
- line = s -> filehead;
- line1 = s -> filehead;
- if(s -> startrow > s -> endrow ||
- ((s -> startrow == s -> endrow)&&(s -> startchar > s -> endchar)))
- {
- j = s -> endrow;
- s -> endrow = s -> startrow;
- s -> startrow = j;
- i = s -> endchar;
- s -> endchar = s -> startchar;
- s -> startchar = i;
- }
- for(i = 1;i < s -> startrow;i++)
- {
- line = line -> next;
- }
- q1 = line -> ch;
- for(i = 1;i < s -> startchar - 1;i++)
- {
- q1 = q1 -> next;
- }
- for(i = 1;i < s -> endrow;i++)
- {
- line1 = line1 -> next;
- }
- q2 = line1 -> ch;
- for(i = 1;i < s -> endchar - 1;i++)
- {
- q2 = q2 -> next;
- }
- //printf("%c|%c",q1 -> ch,q2 -> ch);
- if(s -> startchar != 1 && s -> endchar != 1)
- {
- line -> next = line1 -> next;
- q1 -> next = q2 -> next;
- }
- if(s -> startchar == 1)
- {
- line -> next = line1 -> next;
- line -> ch = q2 -> next;
- }
- if(s -> endchar == 1)
- {
- line -> next = line1 -> next;
- q1 -> next = line1 -> ch;
- }
- s -> currentrow = s -> startrow = s -> endrow = s -> startrow;;
- s -> currentcolumn = s -> endchar = s -> startchar;
- //printf("%d,%d|",s -> startchar,s -> startrow);
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- }
- M = s -> currentrow;
- N = s -> currentcolumn;
- //word = (Char *)hz;
- head = s -> filehead;
- if(head == NULL)
- return;
- line = head;
- //if(!s -> chinese)
- // return ;
- /* judge the chinese insert mode */
- for(i = 1;i < M && line != NULL ;i ++)
- {
- line = line -> next;
- }
- if(line == NULL)
- return;
- ch = line -> ch;
- for(i = 1;i < N - 1 && ch != NULL ;i++)
- {
- ch = ch -> next;
- }
- if(ch == NULL)
- return;
- nextch = ch -> next;
- tmpch = ch;
- if( N == 1 )
- /* input HZ in the head of a Row */
- {
- nextch = line -> ch;
- word1 = ALLOC(sizeof(Char));
- CheckAlloc((void *)word1);
- //word2 = ALLOC(sizeof(Char));
- word1 -> ch = hz[0];
- //word2 -> ch = hz[1];
- line -> ch = word1;
- word1 -> next = nextch;
- //word1 -> next = word2;
- //word2 -> next = nextch;
- tmpch = line -> ch;
- for(i = 1;hz[i] != '\0';i++)
- {
- word2 = ALLOC(sizeof(Char));
- CheckAlloc((void *)word2);
- word2 -> ch = hz[i];
- tmpch -> next = word2;
- word2 -> next = nextch;
- tmpch = word2;
- }
- /*for(i = 0;hz[i] != '\0';i++)
- {
- if(i == 0)
- {
- line -> ch -> ch = hz[i];
- ch = line -> ch;
- tmpch = ch;
- }
- else
- {
- word = malloc(sizeof(Char));
- word -> ch = hz[i];
- tmpch -> next = word;
- word -> next = nextch;
- tmpch = word;
- }
- }*/
- s -> filehead = head;
- s -> currentcolumn += i;
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- }
- else
- {
- for(i = 0;hz[i] != '\0';i++)
- {
- word = ALLOC(sizeof(Char));
- CheckAlloc((void *)word);
- word -> ch = hz[i];
- tmpch -> next = word;
- word -> next = nextch;
- tmpch = word;
- }
- s -> filehead = head;
- s -> currentcolumn += i;
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- }
- }
- else if(s -> ischildwindow && s -> isedit)
- /* in the childwindow */
- {
- //printf("%d ",strlen(hz));
- N = s -> currentcolumn;
- //printf("%d ",N);
- head = s -> childhead;
- if(head == NULL)
- return;
- line = head;
- ch = line -> ch;
- nextch = ch;
- if(ch == NULL)
- return;
- if(ch -> ch == '\0')
- {
- word1 = ALLOC(sizeof(Char));
- CheckAlloc((void *)word1);
- word1 -> ch = hz[0];
- s -> currentcolumn ++;
- line -> ch = word1;
- //printf("%c",hz[0]);
- word1 -> next = ch;
- for(i = 1;hz[i] != '\0';i++)
- {
- word2 = ALLOC(sizeof(Char));
- CheckAlloc((void *)word2);
- word2 -> ch = hz[i];
- s -> currentcolumn ++;
- ch -> next = word2;
- word2 -> next = nextch;
- ch = word2;
- }
- }
- else
- {
- for(i = 1;i < N - 1 && ch != NULL && ch -> ch != 0;i++)
- {
- ch = ch -> next;
- }
- if(ch == NULL)
- return;
- nextch = ch -> next;
- for(i = 0;hz[i] != '\0';i++)
- {
- word2 = ALLOC(sizeof(Char));
- CheckAlloc((void *)word2);
- word2 -> ch = hz[i];
- s -> currentcolumn ++;
- ch -> next = word2;
- word2 -> next = nextch;
- ch = word2;
- }
- }
- s -> childhead = head;
- CleanUp(n);
- OutPutXY(n);
- CleanUp(n);
- }
- }
- void EnterKey(void *n)
- /* add the function of pressing Enter Key */
- {
- State *s;
- Row *head;
- Row *line,*nextrow,*line1;
- Row *newrow;
- Char *ch;
- Char *nextch;
- Char *tmpch;
- Char *q1,*q2;
- int M,N;
- int i,j,sum;
- s = (State *)n;
- if((!s -> isedit) || (s -> ischildwindow) || s -> ispinyin)
- return ;
- if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
- {
- line = s -> filehead;
- line1 = s -> filehead;
- if(s -> startrow > s -> endrow ||
- ((s -> startrow == s -> endrow)&&(s -> startchar > s -> endchar)))
- {
- j = s -> endrow;
- s -> endrow = s -> startrow;
- s -> startrow = j;
- i = s -> endchar;
- s -> endchar = s -> startchar;
- s -> startchar = i;
- }
- for(i = 1;i < s -> startrow;i++)
- {
- line = line -> next;
- }
- q1 = line -> ch;
- for(i = 1;i < s -> startchar - 1;i++)
- {
- q1 = q1 -> next;
- }
- for(i = 1;i < s -> endrow;i++)
- {
- line1 = line1 -> next;
- }
- q2 = line1 -> ch;
- for(i = 1;i < s -> endchar - 1;i++)
- {
- q2 = q2 -> next;
- }
- //printf("%c|%c",q1 -> ch,q2 -> ch);
- if(s -> startchar != 1 && s -> endchar != 1)
- {
- line -> next = line1 -> next;
- q1 -> next = q2 -> next;
- }
- if(s -> startchar == 1)
- {
- line -> next = line1 -> next;
- line -> ch = q2 -> next;
- }
- if(s -> endchar == 1)
- {
- line -> next = line1 -> next;
- q1 -> next = line1 -> ch;
- }
- s -> currentrow = s -> startrow = s -> endrow = s -> startrow;;
- s -> currentcolumn = s -> endchar = s -> startchar;
- //printf("%d,%d|",s -> startchar,s -> startrow);
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- return;
- }
- head = s -> filehead;
- //num = (s -> editx2 - s -> editx1)/8;
- sum = (s -> edity2 - s -> edity1)/16 + 1 + s -> pagemovecount;
- M = s -> currentrow;
- /* record the current row */
- N = s -> currentcolumn;
- /* record the current column */
- line = head;
- for(i = 1;i < M && line != NULL;i++)
- {
- line = line -> next;
- }
- tmpch = line -> ch;
- for(j = 1;tmpch != NULL && tmpch -> next != NULL;j++)
- {
- tmpch = tmpch -> next;
- }
- if( N == j)
- /* press ENTER KEY in the end of a row */
- {
- if(s -> currentrow == sum)
- {
- PageDown(n);
- }
- nextrow = line -> next;
- newrow = ALLOC(sizeof(Row));
- CheckAlloc((void *)newrow);
- ch = ALLOC(sizeof(Char));
- CheckAlloc((void *)newrow);
- ch -> ch = '\0';
- ch -> next = NULL;
- newrow -> ch = ch;
- line -> next = newrow;
- newrow -> next = nextrow;
- s -> filehead = head;
- CleanUp(n);
- OutPutXY(n);
- CleanUp(n);
- }
- else if(N > 1 && N < j)
- {
- nextrow = line -> next;
- tmpch = line -> ch;
- for(i = 1;i < N && tmpch -> next != NULL;i++)
- {
- tmpch = tmpch -> next;
- }
- if(s -> currentrow == sum)
- {
- PageDown(n);
- }
- ch = ALLOC(sizeof(Char));
- CheckAlloc((void *)ch);
- ch -> ch = tmpch -> ch;
- ch -> next = tmpch -> next;
- /* store the charchain behind the cursor */
- //printf("%c|%d\t",ch -> ch,N);
- newrow = ALLOC(sizeof(Row));
- CheckAlloc((void *)newrow);
- newrow -> ch = ch;
- tmpch -> ch = '\0';
- tmpch -> next = NULL;
- /* cut down the current row */
- line -> next = newrow;
- newrow -> next = nextrow;
- s -> filehead = head;
- CleanUp(n);
- OutPutXY(n);
- CleanUp(n);
- }
- else if(N == 1)
- {
- nextrow = line -> next;
- tmpch = line -> ch;
- if(s -> currentrow == sum)
- {
- PageDown(n);
- }
- ch = ALLOC(sizeof(Char));
- CheckAlloc((void *)ch);
- ch -> ch = tmpch -> ch;
- ch -> next = tmpch -> next;
- newrow = ALLOC(sizeof(Row));
- CheckAlloc((void *)newrow);
- newrow -> ch = ch;
- tmpch -> ch = '\0';
- tmpch -> next = NULL;
- /* cut down the current row */
- line -> next = newrow;
- newrow -> next = nextrow;
- s -> filehead = head;
- CleanUp(n);
- OutPutXY(n);
- CleanUp(n);
- }
- ClrCur(n);
- s -> currentcolumn = 1;
- s -> currentrow += 1;
- DrawCur(n);
- }
- /*
- void CtrlX(void *n,void *first,void *end)
- {
- State *s;
- }
- void CtrlC(void *n,void *first,void *end)
- {
- State *s;
- }
- void CtrlV(void *n,void *first,void *end)
- {
- State *s;
- }
- */
- //if(strlen(p) > 1 && (((unsigned char)*p >= 0xa1 && (unsigned char)*p <= 0xfe)
- // && ((unsigned char) * (p + 1) >= 0xa1 && (unsigned char) * (p + 1) <= 0xfe)))
- /* 在以*p的字符串中,判断是否为汉字 */
- char LeftChar(void *n)
- {
- State *s;
- Row *row;
- Char *ch;
- int M,N;
- int i;
- s = (State *)n;
- M = s -> currentrow;
- N = s -> currentcolumn;
- row = s -> filehead;
- if(N == 1)
- return 0;
- for(i = 1;i < M;i++)
- {
- row = row -> next;
- }
- ch = row -> ch;
- for(i = 1;i < N - 1;i++)
- {
- ch = ch -> next;
- }
- //printf("%c",ch -> ch);
- return (ch -> ch);
- }
- void Home(void *n)
- /* put the cursor in the first of the currentrow */
- {
- State *s;
- s = (State *)n;
- if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
- {
- s -> startchar = s -> endchar = s -> currentcolumn;
- s -> startrow = s -> endrow = s -> currentrow;
- /* refresh the start and end */
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- }
- if(!s -> ischildwindow)
- {
- ClrCur(n);
- s -> currentcolumn = 1;
- DrawCur(n);
- }
- else if(s -> ischildwindow && s -> isedit)
- {
- ClrCur(n);
- s -> currentcolumn = 1;
- DrawCur(n);
- }
- }
- void CtrlHome(void *n)
- /* put the cursor in the first of the firstrow */
- {
- State *s;
- s = (State *)n;
- if(!s -> isedit || s -> ischildwindow)
- return;
- ClrCur(n);
- s -> startchar = s -> endchar = s -> currentcolumn = 1;
- s -> startrow = s -> endrow = s -> currentrow = 1;
- DrawCur(n);
- s -> pagemovecount = 0;
- /* refresh the start and end */
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- }
- void End(void *n)
- /* put the cursor in the end of the currentrow */
- {
- State *s;
- int i;
- Row *line;
- Char *ch;
- s = (State *)n;
- if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
- {
- s -> startchar = s -> endchar = s -> currentcolumn;
- s -> startrow = s -> endrow = s -> currentrow;
- /* refresh the start and end */
- CleanUp(n);
- if(!s -> dotted)
- {
- setactivepage(!s -> page);
- DrawMainWindow(n);
- DrawStatusBox(n);
- DoEvent(s -> redraw, n);
- CleanUp(n);
- setvisualpage(!s -> page);
- s -> page = !s -> page;
- }
- else
- {
- OutPutXY(n);
- CleanUp(n);
- }
- }
- if(!s -> ischildwindow)
- {
- line = s -> filehead;
- for(i = 1;i < s -> currentrow && line != NULL;i++)
- {
- line = line -> next;
- }
- ch = line -> ch;
- for(i = 1;ch != NULL && ch -> next != NULL;i++)
- {
- ch = ch -> next;
- }
- ClrCur(n);
- s -> currentcolumn = i;
- DrawCur(n);
- }
- else if(s -> ischildwindow && s -> isedit)
- {
- line = s -> childhead;
- ch = line -> ch;
- for(i = 1;ch != NULL && ch -> next != NULL;i++)
- {
- ch = ch -> next;
- }
- ClrCur(n);
- s -> currentcolumn = i;
- DrawCur(n);
- }
- }
- void CtrlEnd(void *n)
- /* put the cursor in the end of the currentrow */
- {
- State *s;
- int i;
- Row *line;
- Char *ch;
- s = (State *)n;
- if(!s -> isedit || s -> ischildwindow)
- return;
- line = s -> filehead;
- for(i = 1;i != s -> rowcount;i++)
- {
- line = line -> next;
- }
- ch = line -> ch;
- for(i = 1;ch != NULL && ch -> next != NULL;i++)
- {
- ch = ch -> next;
- }
- ClrCur(n);
- s -> startchar = s -> endchar = s -> currentcolumn = i;
- s -> startrow = s -> endrow = s -> currentrow = s -> rowcount;
- DrawCur(n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement