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 CheckCursor(void *n)
- {
- State *s;
- //int cursorrow;
- int sum, flag = 0;
- s = (State *)n;
- if(s -> ischildwindow)
- return;
- sum = (s -> edity2 - s -> edity1) / 16 + 1;
- while(s -> currentrow - s -> pagemovecount > sum)
- {
- //PageDown(n);
- s -> pagemovecount ++;
- flag = 1;
- }
- while(s -> currentrow - s -> pagemovecount == 0)
- {
- //PageUp(n);
- s -> pagemovecount --;
- flag = 1;
- }
- if(flag)
- {
- 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 DrawCur(void *n)
- /* draw the cursor */
- {
- State *s;
- s = (State *)n;
- setwritemode(1);
- setlinestyle(0,0,1);
- setcolor(15);
- CheckCursor(n);
- //printf("%d",!s -> ischildwindow ? s -> pagemovecount : 0);
- if(s -> currentcolumn >= 79)
- {
- s -> cursorx = (s -> currentcolumn - 78 - 1)*8 + s -> editx1;
- s -> cursory = (s -> currentrow - (!s -> ischildwindow ? s -> pagemovecount : 0)+ 1 - 1)*16 + s -> edity1;
- }
- /* change the row in the end but currentcolumn remain */
- else
- {
- s -> cursorx = (s -> currentcolumn - 1)*8 + s -> editx1;
- s -> cursory = (s -> currentrow - (!s -> ischildwindow ? s -> pagemovecount : 0) - 1)*16 + s -> edity1;
- }
- /* caculate the cursor position from current(row&column) */
- MouseAway(n);
- line(s -> cursorx ,s -> cursory,s -> cursorx ,s -> cursory + 16);
- MouseAway(n);
- s -> iscursor = !s -> iscursor;
- GetCurPos(n);
- /* caculate the currentrow & the currentcolumn of the cursor */
- //printf("%d,%d\t",s -> cursorx,s -> cursory);
- }
- void ClrCur(void *n)
- {
- State *s;
- s = (State *)n;
- if(!(s -> iscursor))
- return;
- CheckCursor(n);
- if(s -> currentcolumn >= 79)
- {
- s -> cursorx = (s -> currentcolumn - 78 - 1)*8 + s -> editx1;
- s -> cursory = (s -> currentrow - (!s -> ischildwindow ? s -> pagemovecount : 0) + 1 - 1)*16 + s -> edity1;
- }
- /* change the row in the end but currentcolumn remain */
- else
- {
- s -> cursorx = (s -> currentcolumn - 1)*8 + s -> editx1;
- s -> cursory = (s -> currentrow - (!s -> ischildwindow ? s -> pagemovecount : 0) - 1)*16 + s -> edity1;
- }
- /* caculate the cursor position from current(row&column) */
- setlinestyle(0,0,1);
- setcolor(15);
- setwritemode(1);
- line(s -> cursorx ,s -> cursory,s -> cursorx ,s -> cursory + 16);
- s -> iscursor = 0;
- }
- void FlashCur(void *n)
- {
- State *s;
- static int last_x = 0, last_y = 0, last_edit = 1;
- s = (State *)n;
- CheckCursor(n);
- if(s -> currentcolumn >= 79)
- {
- s -> cursorx = (s -> currentcolumn - 78 - 1)*8 + s -> editx1;
- s -> cursory = (s -> currentrow - (!s -> ischildwindow ? s -> pagemovecount : 0) + 1 - 1)*16 + s -> edity1;
- }
- /* change the row in the end but currentcolumn remain */
- else
- {
- s -> cursorx = (s -> currentcolumn - 1)*8 + s -> editx1;
- s -> cursory = (s -> currentrow - (!s -> ischildwindow ? s -> pagemovecount : 0) - 1)*16 + s -> edity1;
- }
- /* caculate the cursor position from current(row&column) */
- if(s -> cursortime == -1)
- s -> cursortime = biostime(0, 0);
- /* it means 1/18.4 second */
- if(!s -> isedit)
- {
- ClrCur(n);
- last_edit = 0;
- return;
- }
- setwritemode(1);
- if(last_x != s -> editx1 || last_y != s -> edity1 || last_edit != s -> isedit)
- {
- ClrCur(n);
- s -> cursorx = s -> editx1;
- s -> cursory = s -> edity1;
- if(!s -> ischildwindow && (s -> currentcolumn != 1 || s -> currentrow -(s -> pagemovecount) != 1))
- {
- //(s -> cursory - (s -> edity1))/16 + 1;
- //(s -> cursorx - (s -> editx1 ))/8 + 1;
- s -> cursorx += (s -> currentcolumn - 1) * 8 ;
- s -> cursory += (s -> currentrow - (s -> pagemovecount) - 1) * 16;
- /* caculate back from currentcolumn & currentrow to cursor(x,y) */
- }
- s -> cursortime = biostime(0, 0) - 12;
- DrawCur(n);
- last_x = s -> editx1, last_y = s -> edity1;
- }
- if(biostime(0, 0) - s -> cursortime >= 12)
- {
- DrawCur(n);
- s -> cursortime = biostime(0, 0);
- }
- last_edit = 1;
- /*if(time(0) - t >= 2)
- {
- ClrCur(s);
- t = time(0);
- }*/
- }
- void CursorUp(void *n)
- /* move cursor up by a row */
- {
- Row *headline;
- Char *ch;
- State *s;
- int num,sum,k,i,j;
- /* avoid to use editx2, that maybe error */
- /* avoid to use edity2, that maybe error */
- int flag;
- int p;
- /* store the HZ position in the front row */
- s = (State *)n;
- //printf("%d",s -> pagemovecount);
- 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);
- }
- }
- num = (s -> editx2 - s -> editx1)/8;
- sum = (s -> edity2 - s -> edity1)/16 + 1;
- //printf("%d",sum);
- if(!s -> ischildwindow)
- {
- if(!s -> isedit )
- return;
- //if(s -> cursory == s -> edity1)
- //if(s -> currentrow - s -> pagemovecount == 1) //&& s -> pagemovecount != 0)
- if(s -> currentrow == -1)
- {
- //if(s -> filehead != NULL)
- if(s -> pagemovecount != 0)
- /* PageUp when in front row */
- {
- ClrCur(n);
- CleanUp(n);
- PageUp(n);
- //s -> currentrow -= 1;
- OutTextxy(n);
- CleanUp(n);
- DrawCur(n);
- }
- /* page up */
- else
- {
- ClrCur(n);
- s -> currentcolumn = 1;
- s -> currentrow = 1;
- DrawCur(n);
- }
- /* deal the situation of the row is the first one */
- }
- /*if(s -> cursory >= s -> edity1 + 16)
- {
- ClrCur(n);
- s -> cursory -= 16;
- DrawCur(n);
- }*/
- //if(s -> cursory > s -> edity1)
- if( s -> currentrow > 1)
- {
- headline = s -> filehead;
- for(k = 1;k < s -> currentrow - 1;k++)
- {
- headline = headline -> next;
- }
- ch = headline -> ch;
- for(i = 1;ch != NULL;i++)
- {
- ch = ch ->next;
- }
- /* calculate the whole num of the front row */
- /*if(s -> currentrow == 1)
- {
- ClrCur(n);
- s -> currentcolumn = 1;
- DrawCur(n);
- }*/
- headline = headline -> next;
- ch = headline -> ch;
- for(j = 1;ch != NULL;j++)
- {
- ch = ch ->next;
- }
- /* calculate the whole num of the current row */
- //if((i >= j) || (s -> cursorx < i*8 + s -> editx1 - 8))
- if((i >= j) || (s -> currentcolumn < i - 1))
- /* current row is shorter than the front row */
- {
- //flag = UpHZ(n);
- if(UpHZ(n) == 1 && s -> currentcolumn != 1)
- {
- p = FindUpHZPosition(n);
- ClrCur(n);
- s -> currentcolumn = p;
- s -> currentrow -= 1;
- DrawCur(n);
- }
- else
- {
- ClrCur(n);
- //s -> cursory -= 16;
- s -> currentrow -= 1;
- DrawCur(n);
- }
- }
- /* deal the situation of the cursor whose cursor(x) is smaller then the end of front row */
- else
- /* current row is longer than the front row */
- {
- ClrCur(n);
- //s -> cursorx = i*8 + s -> editx1 - 16;
- //s -> cursory -= 16;
- s -> currentcolumn = i - 1;
- s -> currentrow -= 1;
- DrawCur(n);
- }
- /* deal the situation of the cursor whose cursor(x) is larger then the end of front row */
- }
- else if(s -> currentrow == 1)
- {
- ClrCur(n);
- s -> currentcolumn = 1;
- DrawCur(n);
- }
- }
- else if(s -> ischildwindow && s -> isedit)
- {
- ClrCur(n);
- s -> currentcolumn = 1;
- DrawCur(n);
- }
- s -> cursortime = biostime(0, 0) - 12;
- }
- void CursorDown(void *n)
- /* move cursor down by a row */
- {
- Row *headline;
- Char *ch;
- State *s;
- int num,sum,i,j,k;
- /* avoid to use editx2, that maybe error */
- /* avoid to use edity2, that maybe error */
- 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);
- }
- }
- num = (s -> editx2 - s -> editx1)/8;
- sum = (s -> edity2 - s -> edity1)/16 + 1 + s -> pagemovecount;
- if(!s -> ischildwindow)
- {
- if(!s -> isedit )
- return;
- //if(s -> cursory == sum * 16 + s -> edity1)
- //if(s -> currentrow == s -> rowcount || s -> currentrow == sum)
- if(s -> currentrow == -1)
- /*movement in last row */
- {
- //printf("%d,%d,%d",s -> currentrow,s -> rowcount,s -> pagemovecount);
- //if(s -> filehead != NULL)
- //if(s -> pagemovecount < s -> rowcount - sum - 1)
- if(s -> currentrow == sum && s -> currentrow != s -> rowcount)
- /* pagedown */
- {
- //printf("inside");
- headline = s -> filehead;
- for(i = 1;i <= s -> currentrow && headline != NULL;i++)
- {
- headline = headline -> next;
- }
- /* nextrow */
- ch = headline -> ch;
- for(j = 1;ch -> ch != '\0' && ch -> next != NULL;j++)
- {
- ch = ch -> next;
- }
- if(j < s -> currentcolumn)
- {
- s -> currentcolumn = j;
- }
- //ClrCur(n);
- //CleanUp(n);
- PageDown(n);
- //s -> currentrow += 1;
- OutPutXY(n);
- //CleanUp(n);
- //DrawCur(n);
- /* in stead of MouseAway(n) */
- }
- else if(s -> currentrow == s -> rowcount)
- {
- headline = s -> filehead;
- for(i = 1;i < s -> rowcount && headline -> next != NULL;i++)
- {
- headline = headline -> next;
- }
- /* nextrow */
- ch = headline -> ch;
- for(j = 1;ch -> ch != '\0' && ch -> next != NULL;j++)
- {
- ch = ch -> next;
- }
- ClrCur(n);
- s -> currentcolumn = j;
- DrawCur(n);
- }
- //printf("%d",s -> rowcount);
- }
- else if(s -> currentrow < s -> rowcount)
- /* is not in the last row */
- {
- headline = s -> filehead;
- for(k = 1;k < s -> currentrow && headline != NULL;k++)
- {
- headline = headline -> next;
- }
- ch = headline -> ch;
- for(i = 1;ch != NULL;i++)
- {
- ch = ch ->next;
- }
- headline = headline -> next;
- ch = headline -> ch;
- for(j = 1;ch != NULL;j++)
- {
- ch = ch ->next;
- }
- //if((i <= j) || (s -> cursorx < j*8 + s -> editx1 - 8))
- if((i <= j) || (s -> currentcolumn < j - 1))
- {
- if(DownHZ(n) == 1 && s -> currentcolumn != 1)
- {
- k = FindDownHZPosition(n);
- ClrCur(n);
- s -> currentrow += 1;
- s -> currentcolumn = k;
- DrawCur(n);
- }
- else
- {
- if(s -> currentrow == sum && s -> currentrow <= s -> rowcount)
- {
- //printf("1");
- ClrCur(n);
- s -> currentrow += 1;
- DrawCur(n);
- }
- else
- {
- ClrCur(n);
- s -> currentrow += 1;
- DrawCur(n);
- }
- }
- }
- /* deal the situation of the cursor whose cursor(x) is smaller then the end of next row */
- else
- {
- ClrCur(n);
- //s -> cursorx = j*8 + s -> editx1 - 16;
- //s -> cursory += 16;
- s -> currentcolumn = j - 1;
- s -> currentrow += 1;
- DrawCur(n);
- }
- /* deal the situation of the cursor whose cursor(x) is larger then the end of next row */
- }
- else if(s -> currentrow == s -> rowcount)
- {
- headline = s -> filehead;
- for(i = 1;i < s -> rowcount;i++)
- {
- headline = headline -> next;
- }
- ch = headline -> ch;
- for(j = 1;ch != '\0' && ch -> next != NULL;j++)
- {
- ch = ch -> next;
- }
- ClrCur(n);
- s -> currentcolumn = j;
- DrawCur(n);
- }
- }
- else if(s -> ischildwindow && s -> isedit)
- {
- headline = s -> childhead;
- ch = headline -> ch;
- for(i = 1;ch -> next != NULL;i++)
- {
- ch = ch -> next;
- }
- ClrCur(n);
- s -> currentcolumn = i;
- DrawCur(n);
- }
- s -> cursortime = biostime(0, 0) - 12;
- }
- void CursorLeft(void *n)
- {
- int i,j;
- Row *headline;
- Char *ch;
- State *s;
- int num,sum;
- /* avoid to use editx2, that maybe error */
- /* avoid to use edity2, that maybe error */
- s = (State *)n;
- headline = s -> filehead;
- if((s -> startchar == 1&&s -> startrow == 1) || (s -> endchar ==1 && s -> endrow == 1)&&s -> ischosen)
- {
- CleanUp(n);
- s -> pagemovecount = 0;
- s -> currentcolumn = s -> currentrow = 1;
- s -> startchar = s -> startrow = s -> endchar = s -> endrow = 1;
- 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;
- }
- if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
- {
- if(s -> startrow > s -> endrow)
- {
- s -> currentrow = s -> startrow = s -> endrow;
- s -> currentcolumn = s -> startchar = s -> endchar;
- }
- if(s -> endrow > s -> startrow)
- {
- s -> currentrow = s -> endrow = s -> startrow;
- s -> currentcolumn = s -> endchar = s -> startchar;
- }
- if(s -> endrow == s -> startrow)
- {
- s -> currentrow = s -> endrow = s -> startrow;
- s -> currentcolumn = (s -> startchar < s -> endchar ? s -> startchar : s -> endchar);
- s -> endchar = s -> startchar = s -> currentcolumn;
- }
- /* 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);
- }
- return;
- }
- num = (s -> editx2 - s -> editx1)/8;
- sum = (s -> edity2 - s -> edity1)/16;
- //printf("%d",LeftHZ(n));
- if(!s -> ischildwindow)
- {
- if(!s -> isedit )
- return;
- //if((s -> cursorx <= s -> editx1) && (s -> cursory <= s -> rowcount *16 + s -> edity1))
- if((s -> currentcolumn <= 1) && (s -> currentrow <= s -> rowcount))
- /* movement in the head of the row */
- {
- /*if(s -> currentrow - s -> pagemovecount == 1 && s -> pagemovecount != 0)
- {
- //printf("inside");
- for(i = 1;i < s -> currentrow - 1;i++)
- / find the front row /
- {
- headline = headline -> next;
- }
- ch = headline -> ch;
- for(j = 1;ch != NULL;j++)
- / caculate the num of the char /
- {
- ch = ch -> next;
- }
- ClrCur(n);
- CleanUp(n);
- PageUp(n);
- s -> currentcolumn = j - 1;
- s -> currentrow -= 1;
- OutTextxy(n);
- CleanUp(n);
- DrawCur(n);
- }
- else */
- if(s -> currentrow > 1)
- {
- for(i = 1;i < s -> currentrow - 1 ;i++)
- /* find the front row */
- {
- headline = headline -> next;
- }
- ch = headline -> ch;
- for(j = 1;ch != NULL;j++)
- /* caculate the num of the char */
- {
- ch = ch -> next;
- }
- //if(s -> cursory > s -> edity1)
- if(s -> currentrow > 1)
- {
- ClrCur(n);
- /*s -> cursorx = j * 8 + s -> editx1 - 16;
- s -> cursory -= 16;*/
- s -> currentcolumn = j - 1;
- s -> currentrow -= 1;
- DrawCur(n);
- }
- }
- }
- /*else if(s -> cursorx >= s -> editx1 + 8)
- {
- ClrCur(n);
- s -> cursorx -= 8;
- DrawCur(n);
- }*/
- else if(s -> currentcolumn >= 2)
- {
- //ClrCur(n);
- if(LeftHZ(n) == 1)
- {
- ClrCur(n);
- s -> currentcolumn -= 2;
- DrawCur(n);
- }
- else
- {
- ClrCur(n);
- s -> currentcolumn -= 1;
- DrawCur(n);
- }
- //DrawCur(n);
- }
- s -> cursortime = biostime(0, 0) - 12;
- }
- else if(s -> ischildwindow && s -> isedit)
- {
- /*if((s -> cursorx >= s -> editx1 + 8)&&(s -> cursorx <= s -> editx2 ))
- {
- ClrCur(n);
- s -> cursorx -= 8;
- DrawCur(n);
- }*/
- if((s -> currentcolumn >= 2) && (s -> currentcolumn <= num))
- {
- //ClrCur(n);
- if(LeftHZ(n) == 1)
- {
- s -> currentcolumn -= 2;
- }
- else
- {
- s -> currentcolumn -= 1;
- }
- //DrawCur(n);
- }
- //s -> cursortime = biostime(0, 0) - 12;
- }
- }
- void CursorRight(void *n)
- {
- int i,j;
- Row *headline;
- Row *line;
- Char *ch;
- State *s;
- int num,sum;
- /* avoid to use editx2, that maybe error */
- /* avoid to use edity2, that maybe error */
- s = (State *)n;
- //printf("%d",RightHZ(n));
- num = (s -> editx2 - s -> editx1)/8;
- sum = (s -> edity2 - s -> edity1)/16 + 1 + s -> pagemovecount;
- //printf("%d|%d\t",s -> cursorx,num);
- if((s -> startchar != s -> endchar) || (s -> startrow != s -> endrow))
- {
- if(s -> startrow < s -> endrow)
- {
- s -> currentrow = s -> startrow = s -> endrow;
- s -> currentcolumn = s -> startchar = s -> endchar;
- }
- if(s -> endrow < s -> startrow)
- {
- s -> currentrow = s -> endrow = s -> startrow;
- s -> currentcolumn = s -> endchar = s -> startchar;
- }
- if(s -> endrow == s -> startrow)
- {
- s -> currentrow = s -> endrow = s -> startrow;
- s -> currentcolumn = (s -> startchar > s -> endchar ? s -> startchar : s -> endchar);
- s -> endchar = s -> startchar = s -> currentcolumn;
- }
- /* 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);
- }
- return;
- }
- if(!s -> ischildwindow)
- {
- if(!s -> isedit )
- return;
- /*if((s -> cursorx == (num * 8 + s -> editx1)) && (s -> cursory <= (sum * 16 + s -> edity1) - 16))
- {
- ClrCur(n);
- s -> cursorx = s -> editx1;
- s -> cursory += 16;
- DrawCur(n);
- }*/
- if((s -> currentcolumn == num + 1) && (s -> currentrow <= sum - 1))
- {
- //printf("inside");
- if(RightHZ(n) == 1)
- {
- ClrCur(n);
- s -> currentcolumn += 2;
- DrawCur(n);
- }
- else
- {
- ClrCur(n);
- s -> currentcolumn += 1;
- DrawCur(n);
- }
- //s -> currentrow += 1;
- }
- if(s -> currentcolumn <= num)
- /* in the whole row */
- {
- headline = s -> filehead;
- /* judge the childwindow mode */
- //printf("%d",s -> currentrow + s -> pagemovecount);
- for(i = 1;i < s -> currentrow && headline != NULL ;i++)
- {
- headline = headline -> next;
- }
- ch = headline -> ch;
- for(j = 1;/*j <= s -> currentcolumn*/ch -> ch != '\0' && ch -> next != NULL;j++)
- /* find the last char of the row */
- {
- ch = ch -> next;
- }
- if(s -> currentcolumn < j)
- {
- //ClrCur(n);
- /*s -> cursorx += 8;*/
- if(RightHZ(n) == 1)
- {
- ClrCur(n);
- s -> currentcolumn += 2;
- DrawCur(n);
- }
- else
- {
- ClrCur(n);
- s -> currentcolumn += 1;
- DrawCur(n);
- }
- //DrawCur(n);
- }
- /*else if(s -> cursory <= ((s -> rowcount - 1) *16 + s -> edity1))
- {
- ClrCur(n);
- s -> cursorx = s -> editx1;
- s -> cursory += 16;
- DrawCur(n);
- }*/
- else if(s -> currentcolumn >= j && s -> currentrow < s -> rowcount)//if(s -> currentrow <= (s -> rowcount - 1)*/
- {
- ClrCur(n);
- s -> currentcolumn = 1;
- s -> currentrow += 1;
- DrawCur(n);
- }
- /*else if(s -> currentcolumn >= j && s -> currentrow == sum)
- {
- ClrCur(n);
- CleanUp(n);
- PageDown(n);
- s -> currentcolumn = 1;
- s -> currentrow += 1;
- CleanUp(n);
- DrawCur(n);
- }*/
- }
- /* move the cursor from the right to the front char in next row */
- s -> cursortime = biostime(0, 0) - 12;
- }
- else if(s -> ischildwindow && s -> isedit)
- {
- line = s -> childhead;
- ch = line -> ch;
- for(j = 1;ch -> next != NULL;j++)
- {
- ch = ch -> next;
- }
- if((s -> currentcolumn >= 1)&&(s -> currentcolumn < j))
- {
- ClrCur(n);
- s -> currentcolumn += 1;
- DrawCur(n);
- }
- //s -> cursortime = biostime(0, 0) - 12;
- }
- }
- void GetCurPos(void *n)
- /* caculate the currentrow & the currentcolumn of the cursor */
- {
- int testrow;
- State *s;
- s = (State *)n;
- if(!s -> isedit || s -> ischildwindow)
- return;
- //s -> currentrow = (s -> cursory - (s -> edity1))/16 + 1;
- //s -> currentcolumn = (s -> cursorx - (s -> editx1 ))/8 + 1;
- //testrow = (s -> cursory - (s -> edity1))/16;
- }
- void MousetoCursor(void *n)
- /* left click mouse and then move the cursor to the current position */
- {
- Row *headline;
- Char *ch;
- State *s;
- int x,y,key,i,j;
- int k;
- Row *line;
- Char *tmpch;
- s = (State *)n;
- if(!s -> isedit || !PinRA(s -> mouse.x, s->mouse.y, s->editx1, s->edity1,s->editx2,s->edity2))
- return;
- if(!s -> ischildwindow)
- {
- headline = s -> filehead;
- if(headline == NULL)
- return;
- x = (s -> mouse . x - s -> editx1) / 8 + 1;
- /* the currentcolumn the Mouse in */
- y = (s -> mouse . y - s -> edity1) / 16 + 1 + s -> pagemovecount;
- /* the currentrow the Mouse in */
- key = s -> mouse . key;
- if(1 || key == 1)
- {
- /*ClrCur(n);
- s -> cursortime = biostime(0, 0) - 12;
- s -> cursorx = x*8 + s -> editx1;
- s -> cursory = y*16 + s -> edity1;
- DrawCur(n);*/
- if(y > s -> rowcount)
- /* mouse is under the bottom of the text */
- {
- ClrCur(n);
- s -> cursortime = biostime(0, 0) - 12;
- //s -> cursory = s -> rowcount * 16 + s -> edity1;
- //s -> cursorx = s -> editx1;
- s -> currentrow = s -> rowcount;
- line = s -> filehead;
- for(i = 1;i < s -> rowcount && line != NULL;i++)
- {
- line = line -> next;
- }
- if(line == NULL)
- return;
- tmpch = line -> ch;
- for(i = 1;tmpch != NULL && tmpch -> next != NULL;i++)
- {
- tmpch = tmpch -> next;
- }
- k = i ;
- s -> currentcolumn = k;
- DrawCur(n);
- }
- else
- {
- for(i = 1; i < y && headline != NULL; i++)
- {
- headline = headline -> next;
- }
- if(headline == NULL)
- return;
- ch = headline -> ch;
- for(j = 1; ch != NULL;j++)
- {
- ch = ch -> next;
- }
- if(x > j - 2)
- /* Mouse is in the right of the row */
- {
- ClrCur(n);
- s -> cursortime = biostime(0, 0) - 12;
- //s -> cursorx = (j - 1)*8 + s -> editx1 - 8;
- //s -> cursory = y*16 + s -> edity1;
- s -> currentcolumn = j - 1;
- s -> currentrow = y;
- DrawCur(n);
- }
- else
- {
- if(MouseHZ(n) == 1)
- {
- ClrCur(n);
- s -> cursortime = biostime(0, 0) - 12;
- //s -> cursorx = x*8 + s -> editx1;
- //s -> cursory = y*16 + s -> edity1;
- s -> currentcolumn = FindMouseHZPosition(n);
- s -> currentrow = y;
- DrawCur(n);
- }
- else
- {
- ClrCur(n);
- s -> cursortime = biostime(0, 0) - 12;
- //s -> cursorx = x*8 + s -> editx1;
- //s -> cursory = y*16 + s -> edity1;
- s -> currentcolumn = x ;
- s -> currentrow = y;
- DrawCur(n);
- }
- }
- }
- }
- }
- else if(s -> ischildwindow && s -> isedit)
- {
- x = (s -> mouse . x - s -> editx1) / 8 + 1;
- /* the currentcolumn the Mouse in */
- key = s -> mouse . key;
- //printf("%d",key);
- if( key == 1)
- {
- //printf("inside");
- line = s -> childhead;
- if(line == NULL)
- return;
- ch = line -> ch;
- for(i = 1;ch != NULL && ch -> next != NULL;i++)
- {
- ch = ch -> next;
- }
- if(x > i)
- {
- ClrCur(n);
- s -> currentcolumn = i;
- DrawCur(n);
- }
- else if(x <= i)
- {
- ClrCur(n);
- s -> currentcolumn = x;
- DrawCur(n);
- }
- }
- }
- }
- int LeftHZ(void *n)
- /* there is a HZ on the left side of the cursor */
- {
- State *s;
- int m,k;
- int i;
- char p;
- Char *ch;
- Row *row;
- //int Q1 = 0xa1,Q2 = 0xfe;
- s = (State *)n;
- m = s -> currentrow;
- k = s -> currentcolumn;
- k -= 1;
- row = s -> filehead;
- for(i = 1;i < m;i++)
- {
- row = row -> next;
- }
- ch = row -> ch;
- for(i = 1;i < k ;i++)
- {
- ch = ch -> next;
- }
- p = ch -> ch;
- //printf("%c|%d|%d|%d\t",p,Q2,(unsigned char)p,Q1);
- if((unsigned char)(p) >= 0xa1 && (unsigned char)(p) <= 0xfe)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int RightHZ(void *n)
- /* there is a HZ on the right side of the cursor */
- {
- State *s;
- int m,k;
- int i;
- char p;
- Char *ch;
- Row *row;
- //int Q1 = 0xa1,Q2 = 0xfe;
- s = (State *)n;
- m = s -> currentrow;
- k = s -> currentcolumn;
- k -= 1;
- row = s -> filehead;
- for(i = 1;i < m;i++)
- {
- row = row -> next;
- }
- ch = row -> ch;
- for(i = 1;i < k + 1 ;i++)
- {
- ch = ch -> next;
- }
- p = ch -> ch;
- //printf("%c|%d|%d|%d\t",p,Q2,(unsigned char)p,Q1);
- if((unsigned char)(p) >= 0xa1 && (unsigned char)(p) <= 0xfe)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int UpHZ(void *n)
- /* there is a HZ on the top side of the cursor */
- {
- State *s;
- int m,k;
- int i;
- char q,p;
- Char *ch;
- Row *row;
- //int Q1 = 0xa1,Q2 = 0xfe;
- s = (State *)n;
- m = s -> currentrow;
- k = s -> currentcolumn;
- k -= 1;
- row = s -> filehead;
- for(i = 1;i < m - 1 && row != NULL;i++)
- {
- row = row -> next;
- }
- ch = row -> ch;
- for(i = 1;i < k && ch != NULL;i++)
- {
- ch = ch -> next;
- }
- q = ch -> ch;
- p = ch -> next -> ch;
- //printf("%d|%d|%d|%d\t",(unsigned char)q,(unsigned char)p,0xa1,0xfe);
- //printf("%c|%d|%d|%d\t",p,Q2,(unsigned char)p,Q1);
- if(((unsigned char)q >= 0xa1 && (unsigned char)q <= 0xfe)
- &&(unsigned char)(p) >= 0xa1 && (unsigned char)(p) <= 0xfe)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int DownHZ(void *n)
- /* there is a HZ on the bottom side of the cursor */
- {
- State *s;
- int m,k;
- int i;
- char q,p;
- Char *ch;
- Row *row;
- //int Q1 = 0xa1,Q2 = 0xfe;
- s = (State *)n;
- m = s -> currentrow;
- k = s -> currentcolumn;
- m += 1;
- row = s -> filehead;
- for(i = 1;i < m && row != NULL;i++)
- {
- row = row -> next;
- }
- ch = row -> ch;
- for(i = 1;i < k - 1 && ch != NULL;i++)
- {
- ch = ch -> next;
- }
- q = ch -> ch;
- p = ch -> next -> ch;
- //printf("%c|%c\t",q,p);
- //printf("%c|%d|%d|%d\t",p,Q2,(unsigned char)p,Q1);
- if(((unsigned char)q >= 0xa1 && (unsigned char)q <= 0xfe)
- &&(unsigned char)(p) >= 0xa1 && (unsigned char)(p) <= 0xfe)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int MouseHZ(void *n)
- /* there is a HZ under the Mouse */
- {
- State *s;
- int m,k;
- int i;
- char q,p;
- Char *ch;
- Row *row;
- //int Q1 = 0xa1,Q2 = 0xfe;
- s = (State *)n;
- m = (s -> mouse . y - s -> edity1) / 16 + 1 + s -> pagemovecount;
- k = (s -> mouse . x - s -> editx1) / 8 + 1;;
- row = s -> filehead;
- for(i = 1;i < m && row != NULL;i++)
- {
- row = row -> next;
- }
- ch = row -> ch;
- for(i = 1;i < k - 1 && ch != NULL;i++)
- {
- ch = ch -> next;
- }
- q = ch -> ch;
- p = ch -> next -> ch;
- //printf("%c|%c\t",q,p);
- //printf("%c|%d|%d|%d\t",p,Q2,(unsigned char)p,Q1);
- if(((unsigned char)q >= 0xa1 && (unsigned char)q <= 0xfe)
- &&(unsigned char)(p) >= 0xa1 && (unsigned char)(p) <= 0xfe)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int FindMouseHZPosition(void *n)
- /* calculate the HZ positon under the Mouse */
- {
- State *s;
- Row *line;
- Char *ch;
- int i;
- int m,k;
- s = (State *)n;
- s = (State *)n;
- line = s -> filehead;
- m = (s -> mouse . y - s -> edity1) / 16 + 1 + s -> pagemovecount;
- k = (s -> mouse . x - s -> editx1) / 8 + 1;;
- for(i = 1;i < m && line != NULL;i++)
- {
- line = line -> next;
- }
- ch = line -> ch;
- for(i = 1;i < k && ch != NULL;i++)
- {
- if((unsigned char)(ch -> ch) >= 0xa1
- && (unsigned char)(ch -> ch) <= 0xfe)
- {
- ch = ch -> next;
- i += 1;
- ch = ch -> next;
- //i += 1;
- }
- else
- {
- ch = ch -> next;
- }
- }
- return (i - 2);
- }
- int FindUpHZPosition(void *n)
- /* calculate the HZ positon in the front row */
- {
- State *s;
- Row *line;
- Char *ch;
- int i;
- int m,k;
- s = (State *)n;
- s = (State *)n;
- line = s -> filehead;
- m = s -> currentrow;
- k = s -> currentcolumn;
- m = m - 1;
- for(i = 1;i < m && line != NULL;i++)
- {
- line = line -> next;
- }
- ch = line -> ch;
- for(i = 1;i < k && ch != NULL;i++)
- {
- if((unsigned char)(ch -> ch) >= 0xa1
- && (unsigned char)(ch -> ch) <= 0xfe)
- {
- ch = ch -> next;
- i += 1;
- ch = ch -> next;
- //i += 1;
- }
- else
- {
- ch = ch -> next;
- }
- }
- return (i - 2);
- }
- int FindDownHZPosition(void *n)
- /* calculate the HZ positon in the next row */
- {
- State *s;
- Row *line;
- Char *ch;
- int i;
- int m,k;
- s = (State *)n;
- s = (State *)n;
- line = s -> filehead;
- m = s -> currentrow;
- k = s -> currentcolumn;
- m = m + 1;
- for(i = 1;i < m && line != NULL;i++)
- {
- line = line -> next;
- }
- ch = line -> ch;
- for(i = 1;i < k && ch != NULL;i++)
- {
- if((unsigned char)(ch -> ch) >= 0xa1
- && (unsigned char)(ch -> ch) <= 0xfe)
- {
- ch = ch -> next;
- i += 1;
- ch = ch -> next;
- //i += 1;
- }
- else
- {
- ch = ch -> next;
- }
- }
- return (i - 2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement