📄 wpickstr.c
字号:
/*---------------------------------------------------------------------------*/
/* this function will find the element number of the */
/* last element on the same line as the given element */
static int e_endline(struct r_t *r,int elem)
{
register int end;
end=(((elem/r->strsperline)+1)*r->strsperline)-1;
if(end>=r->numelems) end=r->lastelem;
return(end);
}
/*---------------------------------------------------------------------------*/
/* this function will find the last element in a */
/* window, using a given first element as input */
static int e_endwin(struct r_t *r,int felem)
{
register int end;
end=felem+r->strsperwin-1;
if(end>(r->lastelem)) end=r->lastelem;
return(end);
}
/*---------------------------------------------------------------------------*/
static void goto_item(struct r_t *r,char *strarr[],int elem)
{
int outside;
if(elem<0||elem>r->lastelem) elem=0;
if((outside=(elem<r->first||elem>r->last)?YES:NO)==NO)
update_curr(strarr,r,0);
r->curr=elem;
if(outside) {
r->first=e_begwin(r,r->last=e_endwin(r,e_begline(r,r->curr)));
update_window(strarr,r);
}
else
update_curr(strarr,r,1);
}
/*---------------------------------------------------------------------------*/
/* this function will hide the mouse cursor */
/* if mouse cursor mode is on */
static void hide_mouse_cursor(void)
{
if(_mouse&MS_CURS) mshidecur();
}
/*---------------------------------------------------------------------------*/
/* this function determines if the mouse cursor is on a item */
static int mouse_on_item(struct r_t *r,int mcrow,int mccol)
{
register int i;
int srow,scol,border,start,end,found;
found = -1;
srow = _winfo.active->srow;
scol = _winfo.active->scol;
border = _winfo.active->border;
for(i=r->first;i<=r->last;i++) {
if(mcrow==(srow+border+((i-r->first)/r->strsperline))) {
start=scol+border+r->xtraspaces+r->gapspaces+
((i%r->strsperline)*(r->maxstrlen+r->gapspaces));
end=start+r->maxstrlen-1;
if(mccol>=start&&mccol<=end) {
found=i;
break;
}
}
}
if(found==-1&&r->scrollbar&&mccol==_winfo.active->ecol) {
if(mcrow==srow+1) found=-2;
else if(mcrow==_winfo.active->erow-1) found=-3;
}
return(found);
}
/*---------------------------------------------------------------------------*/
static void page_down(char *strarr[],struct r_t *r)
{
register int i;
if(r->last!=(r->lastelem)) {
i=r->curr-r->first;
r->first=e_begwin(r,r->last=e_endwin(r,r->last+1));
if((r->curr=r->first+i)>(r->lastelem)) r->curr-=r->strsperline;
update_window(strarr,r);
}
}
/*---------------------------------------------------------------------------*/
static void page_up(char *strarr[],struct r_t *r)
{
register int i;
if(r->first) {
i=r->curr-r->first;
r->last=e_endwin(r,r->first=e_begwin(r,r->first-1));
r->curr=r->first+i;
update_window(strarr,r);
}
}
/*---------------------------------------------------------------------------*/
/* this function reads the mouse for input */
static int read_mouse(char *strarr[],struct r_t *r)
{
int i,bcount,bstat,mrow,mcol;
/* if free-floating mouse cursor support is on */
if(_mouse&MS_CURS) {
/* clear mouse button queue */
msbclear();
/* loop until a key is pressed */
while(!kbhit()&&_kbinfo.kbuf==NULL) {
/* call the keyboard loop function, if defined */
if(_kbinfo.kbloop!=NULL) (*_kbinfo.kbloop)();
/* see if the right button (Esc) was pressed */
msbreles(1,&bstat,&bcount,&mrow,&mcol);
if(bcount) return(0x011b); /* Esc */
/* see where mouse cursor is at - if it is on a scroll bar */
/* or menu item, and the left button is pressed, then scroll */
/* menu or select item */
msstatus(&bstat,&mrow,&mcol);
switch(i=mouse_on_item(r,mrow,mcol)) {
case -1:
msbclear();
break;
case -2:
if(bstat==1) {
scroll_down(strarr,r,3);
if(!_vinfo.usebios) delay_(1);
msbclear();
}
break;
case -3:
if(bstat==1) {
scroll_up(strarr,r,3);
if(!_vinfo.usebios) delay_(1);
msbclear();
}
break;
default:
msbreles(0,&bstat,&bcount,&mrow,&mcol);
if(bcount) {
r->curr=i;
return(0x1c0d); /* Enter */
}
}
}
}
/* return zero - it means a key was pressed */
return(0);
}
/*---------------------------------------------------------------------------*/
static void scroll_down(char *strarr[],struct r_t *r,int upcurr)
{
if(r->first) {
hide_mouse_cursor();
if(upcurr) update_curr(strarr,r,0);
r->first-=r->strsperline;
r->last=e_endline(r,r->last-r->strsperline);
if(upcurr>1) r->curr-=r->strsperline;
if(r->first!=e_begline(r,r->last)) wscroll(1,SDOWN);
update_line(strarr,r,0,(upcurr>2)?0:upcurr);
show_mouse_cursor();
}
}
/*---------------------------------------------------------------------------*/
static void scroll_up(char *strarr[],struct r_t *r,int upcurr)
{
if(r->last!=(r->lastelem)) {
hide_mouse_cursor();
if(upcurr) update_curr(strarr,r,0);
r->first+=r->strsperline;
r->last=e_endline(r,r->last+1);
if(upcurr>1)
if((r->curr+r->strsperline)<=r->last) r->curr+=r->strsperline;
if(r->first!=e_begline(r,r->last)) wscroll(1,SUP);
update_line(strarr,r,r->wheight-1,(upcurr>2)?0:upcurr);
show_mouse_cursor();
}
}
/*---------------------------------------------------------------------------*/
/* this function will display the mouse */
/* cursor if mouse cursor mode is on */
static void show_mouse_cursor(void)
{
if(_mouse) {
if(_mouse&MS_CURS) {
msshowcur();
mscursor(0,0xffff,((LGREY|_LGREY)<<8));
}
}
}
/*---------------------------------------------------------------------------*/
/* this function updates the current item by either */
/* displaying or erasing the selection bar on it */
static void update_curr(char *strarr[],struct r_t *r,int bar)
{
register char *p;
register int i;
int ccol,crow,temp,len;
/* calculate row and column string will be displayed */
/* at, then print out the string character-by-character */
temp=r->curr-(((crow=(r->curr-r->first)/r->strsperline)*r->strsperline)
+r->first);
wgotoxy(crow,ccol=(temp*r->maxstrlen)+((temp+1)*(r->gapspaces))
+r->xtraspaces);
len=strlen(p=strarr[r->curr]);
hide_mouse_cursor();
for(i=0;i<r->maxstrlen;i++)
wprintc(crow,ccol++,bar?r->barattr:r->winattr,(i>len)?' ':*(p+i));
show_mouse_cursor();
}
/*---------------------------------------------------------------------------*/
static void update_line(char *strarr[],struct r_t *r,int wrow,int upcurr)
{
register char *p;
register int k;
int celem,j,ccol,len,nomore=FALSE;
if((celem=(wrow*r->strsperline)+r->first)>=r->numelems) nomore=TRUE;
ccol=r->gapspaces+r->xtraspaces;
for(j=0;j<r->strsperline;j++) {
if(!nomore) len=strlen(p=strarr[celem]);
for(k=0;k<r->maxstrlen;k++)
wprintc(wrow,ccol++,(upcurr&&r->curr==celem)?r->barattr:r->winattr,
(nomore||k>len)?' ':*(p+k));
if(++celem>=r->numelems) nomore=TRUE;
ccol+=r->gapspaces;
}
}
/*---------------------------------------------------------------------------*/
/* this function will update all items in the window */
static void update_window(char *strarr[],struct r_t *r)
{
register int crow;
hide_mouse_cursor();
for(crow=0;crow<r->wheight;crow++) update_line(strarr,r,crow,1);
show_mouse_cursor();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -