--- sbbs/src/uifc/uifc32.c 2018/04/24 16:41:24 1.1.1.1 +++ sbbs/src/uifc/uifc32.c 2018/04/24 16:45:49 1.1.1.2 @@ -2,13 +2,13 @@ /* Curses implementation of UIFC (user interface) library based on uifc.c */ -/* $Id: uifc32.c,v 1.1.1.1 2018/04/24 16:41:24 root Exp $ */ +/* $Id: uifc32.c,v 1.1.1.2 2018/04/24 16:45:49 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -94,6 +94,8 @@ static int save_menu_cur=-1; static int save_menu_bar=-1; static int save_menu_opts=-1; +char* uifcYesNoOpts[]={"Yes","No",NULL}; + static void reset_dynamic(void) { last_menu_cur=NULL; last_menu_bar=NULL; @@ -140,7 +142,7 @@ int inkey(void) int c; c=getch(); - if(!c || c==0xff) + if(!c || c==0xe0) c|=(getch()<<8); return(c); } @@ -236,7 +238,8 @@ int uifcini32(uifcapi_t* uifcapi) || txtinfo.currmode==MONO28 || txtinfo.currmode==BW40X28 || txtinfo.currmode==BW80X28 || txtinfo.currmode==MONO43 || txtinfo.currmode==BW40X43 || txtinfo.currmode==BW80X43 || txtinfo.currmode==MONO50 || txtinfo.currmode==BW40X50 || txtinfo.currmode==BW80X50 - || txtinfo.currmode==MONO60 || txtinfo.currmode==BW40X60 || txtinfo.currmode==BW80X60)) + || txtinfo.currmode==MONO60 || txtinfo.currmode==BW40X60 || txtinfo.currmode==BW80X60 + || txtinfo.currmode==ATARI_40X24 || txtinfo.currmode==ATARI_80X25)) { api->bclr=BLACK; api->hclr=WHITE; @@ -287,10 +290,11 @@ int uifcini32(uifcapi_t* uifcapi) if(cio_api.ESCDELAY) *(cio_api.ESCDELAY)=api->esc_delay; - api->initialized=TRUE; - for(i=0; isavnum=0; + + api->initialized=TRUE; return(0); } @@ -312,7 +316,7 @@ void docopy(void) gettext(1,1,api->scrn_width,api->scrn_len+1,screen); while(1) { key=getch(); - if(key==0 || key==0xff) + if(key==0 || key==0xe0) key|=getch()<<8; switch(key) { case CIO_KEY_MOUSE: @@ -340,9 +344,9 @@ void docopy(void) for(x=startx-1;xscrn_width+x; if((sbuffer[pos*2+1]&0x70)!=0x10) - sbuffer[pos*2+1]=sbuffer[pos*2+1]&0x8F|0x10; + sbuffer[pos*2+1]=(sbuffer[pos*2+1]&0x8F)|0x10; else - sbuffer[pos*2+1]=sbuffer[pos*2+1]&0x8F|0x60; + sbuffer[pos*2+1]=(sbuffer[pos*2+1]&0x8F)|0x60; if(((sbuffer[pos*2+1]&0x70)>>4) == (sbuffer[pos*2+1]&0x0F)) { sbuffer[pos*2+1]|=0x08; } @@ -358,7 +362,9 @@ void docopy(void) for(x=startx-1;xscrn_width+x)*2]; } - copybuf[outpos++]='\r'; + #ifdef _WIN32 + copybuf[outpos++]='\r'; + #endif copybuf[outpos++]='\n'; } copybuf[outpos]=0; @@ -407,6 +413,8 @@ static int uifc_getmouse(struct mouse_ev void uifcbail(void) { + int i; + _setcursortype(_NORMALCURSOR); textattr(LIGHTGRAY); uifc_mouse_disable(); @@ -415,6 +423,8 @@ void uifcbail(void) FREE_AND_NULL(tmp_buffer); FREE_AND_NULL(tmp_buffer2); api->initialized=FALSE; + for(i=0; i< MAX_BUFS; i++) + FREE_AND_NULL(sav[i].buf); } /****************************************************************************/ @@ -483,7 +493,7 @@ static void truncsp(char *str) int ulist(int mode, int left, int top, int width, int *cur, int *bar , char *initial_title, char **option) { - uchar line[256],shade[256],*ptr + uchar line[MAX_COLS*2],shade[MAX_LINES*4],*ptr ,search[MAX_OPLN],bline=0,*win; int height,y; int i,j,opts=0,s=0; /* s=search index into options */ @@ -503,6 +513,7 @@ int ulist(int mode, int left, int top, i char *title=NULL; int a,b,c,longopt; int optheight=0; + int gotkey; uchar hclr,lclr,bclr,cclr,lbclr; hclr=api->hclr; @@ -519,7 +530,8 @@ int ulist(int mode, int left, int top, i } title=strdup(initial_title==NULL?"":initial_title); - uifc_mouse_disable(); + if(!(api->mode&UIFC_NHM)) + uifc_mouse_disable(); title_len=strlen(title); @@ -658,7 +670,8 @@ int ulist(int mode, int left, int top, i cprintf("UIFC line %d: error allocating %u bytes." ,__LINE__,(width+3)*(height+2)*2); free(title); - uifc_mouse_enable(); + if(!(api->mode&UIFC_NHM)) + uifc_mouse_enable(); return(-1); } gettext(s_left+left,s_top+top,s_left+left+width+1 @@ -682,7 +695,8 @@ int ulist(int mode, int left, int top, i cprintf("UIFC line %d: error allocating %u bytes." ,__LINE__,(width+3)*(height+2)*2); free(title); - uifc_mouse_enable(); + if(!(api->mode&UIFC_NHM)) + uifc_mouse_enable(); return(-1); } gettext(s_left+left,s_top+top,s_left+left+width+1 @@ -942,7 +956,8 @@ int ulist(int mode, int left, int top, i last_menu_cur=cur; last_menu_bar=bar; - uifc_mouse_enable(); + if(!(api->mode&UIFC_NHM)) + uifc_mouse_enable(); if(mode&WIN_IMM) { return(-2); @@ -961,11 +976,16 @@ int ulist(int mode, int left, int top, i #endif if(api->timedisplay != NULL) api->timedisplay(/* force? */FALSE); - i=0; - if(kbwait()) { - i=inkey(); - if(i==CIO_KEY_MOUSE) { - if((i=uifc_getmouse(&mevnt))==0) { + gotkey=0; + if(kbwait() || (mode&(WIN_POP|WIN_SEL))) { + if(mode&WIN_POP) + gotkey=ESC; + else if(mode&WIN_SEL) + gotkey=CR; + else + gotkey=inkey(); + if(gotkey==CIO_KEY_MOUSE) { + if((gotkey=uifc_getmouse(&mevnt))==0) { /* Clicked in menu */ if(mevnt.startx>=s_left+left+lbrdrwidth+2 && mevnt.startx<=s_left+left+width-rbrdrwidth-1 @@ -984,7 +1004,8 @@ int ulist(int mode, int left, int top, i if(mode&WIN_SAV) api->savnum++; if(mode&WIN_ACT) { - uifc_mouse_disable(); + if(!(api->mode&UIFC_NHM)) + uifc_mouse_disable(); if((win=(char *)alloca((width+3)*(height+2)*2))==NULL) { cprintf("UIFC line %d: error allocating %u bytes." ,__LINE__,(width+3)*(height+2)*2); @@ -1000,15 +1021,18 @@ int ulist(int mode, int left, int top, i puttext(s_left+left,s_top+top,s_left +left+width-1,s_top+top+height-1,win); - uifc_mouse_enable(); + if(!(api->mode&UIFC_NHM)) + uifc_mouse_enable(); } else if(mode&WIN_SAV) { api->savnum--; - uifc_mouse_disable(); + if(!(api->mode&UIFC_NHM)) + uifc_mouse_disable(); puttext(sav[api->savnum].left,sav[api->savnum].top ,sav[api->savnum].right,sav[api->savnum].bot ,sav[api->savnum].buf); - uifc_mouse_enable(); + if(!(api->mode&UIFC_NHM)) + uifc_mouse_enable(); FREE_AND_NULL(sav[api->savnum].buf); } if(mode&WIN_XTR && (*cur)==opts-1) @@ -1019,13 +1043,13 @@ int ulist(int mode, int left, int top, i else if(mevnt.startx==s_left+left+lbrdrwidth && mevnt.starty==s_top+top+tbrdrwidth && mevnt.event==CIOLIB_BUTTON_1_CLICK) { - i=CIO_KEY_PPAGE; + gotkey=CIO_KEY_PPAGE; } /* Clicked Scroll Down */ else if(mevnt.startx==s_left+left+lbrdrwidth && mevnt.starty==(s_top+top+height)-bbrdrwidth-1 && mevnt.event==CIOLIB_BUTTON_1_CLICK) { - i=CIO_KEY_NPAGE; + gotkey=CIO_KEY_NPAGE; } /* Clicked Outside of Window */ else if((mevnt.startxmode&UIFC_NOCTRL)) - i=CIO_KEY_HOME; + gotkey=CIO_KEY_HOME; break; case CTRL_E: if(!(api->mode&UIFC_NOCTRL)) - i=CIO_KEY_END; + gotkey=CIO_KEY_END; break; case CTRL_U: if(!(api->mode&UIFC_NOCTRL)) - i=CIO_KEY_PPAGE; + gotkey=CIO_KEY_PPAGE; break; case CTRL_D: if(!(api->mode&UIFC_NOCTRL)) - i=CIO_KEY_NPAGE; + gotkey=CIO_KEY_NPAGE; break; case CTRL_Z: if(!(api->mode&UIFC_NOCTRL)) - i=CIO_KEY_F(1); /* help */ + gotkey=CIO_KEY_F(1); /* help */ break; case CTRL_C: if(!(api->mode&UIFC_NOCTRL)) - i=CIO_KEY_F(5); /* copy */ + gotkey=CIO_KEY_F(5); /* copy */ break; case CTRL_V: if(!(api->mode&UIFC_NOCTRL)) - i=CIO_KEY_F(6); /* paste */ + gotkey=CIO_KEY_F(6); /* paste */ + break; + case CIO_KEY_ABORTED: + gotkey=ESC; break; } - if(i>255) { + if(gotkey>255) { s=0; - switch(i) { + switch(gotkey) { /* ToDo extended keys */ case CIO_KEY_HOME: /* home */ if(!opts) @@ -1204,12 +1231,12 @@ int ulist(int mode, int left, int top, i y=top+tbrdrwidth; gotoxy(s_left+left+lbrdrwidth,s_top+top+tbrdrwidth); textattr(lclr|(bclr<<4)); - if(*cur && opts>height-tbrdrwidth) /* Scroll mode */ + if(*cur) /* Scroll mode */ putch(30); /* put the up arrow */ else putch(' '); /* delete the up arrow */ gotoxy(s_left+left+lbrdrwidth,s_top+top+height-bbrdrwidth-1); - if(opts > height-tbrdrwidth && *cur + height - vbrdrsize < opts) + if(opts >= height-tbrdrwidth && *cur + height - vbrdrsize < opts) putch(31); /* put the down arrow */ else putch(' '); /* delete the down arrow */ @@ -1364,7 +1391,9 @@ int ulist(int mode, int left, int top, i if(mode&WIN_XTR && (*cur)==opts-1) /* can't edit */ break; /* extra line */ if(mode&WIN_EDIT) { - if(mode&WIN_EDITACT) { + if(mode&WIN_SAV) + api->savnum++; + if(mode&WIN_ACT) { gettext(s_left+left,s_top+top,s_left +left+width-1,s_top+top+height-1,tmp_buffer); for(i=1;i<(width*height*2);i+=2) @@ -1372,9 +1401,17 @@ int ulist(int mode, int left, int top, i j=(((y-top)*width)*2)+7+((width-hbrdrsize-2)*2); for(i=(((y-top)*width)*2)+7;isavnum--; + puttext(sav[api->savnum].left,sav[api->savnum].top + ,sav[api->savnum].right,sav[api->savnum].bot + ,sav[api->savnum].buf); + FREE_AND_NULL(sav[api->savnum].buf); + } return((*cur)|MSK_EDIT); } break; @@ -1388,19 +1425,27 @@ int ulist(int mode, int left, int top, i break; case CIO_KEY_IC: /* insert */ if(mode&WIN_INS) { + if(mode&WIN_SAV) + api->savnum++; if(mode&WIN_INSACT) { gettext(s_left+left,s_top+top,s_left +left+width-1,s_top+top+height-1,tmp_buffer); for(i=1;i<(width*height*2);i+=2) tmp_buffer[i]=lclr|(cclr<<4); - if(opts) { - j=(((y-top)*width)*2)+7+((width-hbrdrsize-2)*2); - for(i=(((y-top)*width)*2)+7;isavnum--; + puttext(sav[api->savnum].left,sav[api->savnum].top + ,sav[api->savnum].right,sav[api->savnum].bot + ,sav[api->savnum].buf); + FREE_AND_NULL(sav[api->savnum].buf); + } if(!opts) { return(MSK_INS); } @@ -1411,6 +1456,8 @@ int ulist(int mode, int left, int top, i if(mode&WIN_XTR && (*cur)==opts-1) /* can't delete */ break; /* extra line */ if(mode&WIN_DEL) { + if(mode&WIN_SAV) + api->savnum++; if(mode&WIN_DELACT) { gettext(s_left+left,s_top+top,s_left +left+width-1,s_top+top+height-1,tmp_buffer); @@ -1419,22 +1466,30 @@ int ulist(int mode, int left, int top, i j=(((y-top)*width)*2)+7+((width-hbrdrsize-2)*2); for(i=(((y-top)*width)*2)+7;isavnum--; + puttext(sav[api->savnum].left,sav[api->savnum].top + ,sav[api->savnum].right,sav[api->savnum].bot + ,sav[api->savnum].buf); + FREE_AND_NULL(sav[api->savnum].buf); + } return((*cur)|MSK_DEL); } break; default: if(mode&WIN_EXTKEYS) - return(-2-i); + return(-2-gotkey); break; } } else { - i&=0xff; - if(isalnum(i) && opts>1 && option[0][0]) { - search[s]=i; + gotkey&=0xff; + if(isalnum(gotkey) && opts>1 && option[0][0]) { + search[s]=gotkey; search[s+1]=0; for(j=(*cur)+1,a=b=0;a<2;j++) { /* a = search count */ if(j==opts) { /* j = option count */ @@ -1454,7 +1509,7 @@ int ulist(int mode, int left, int top, i if(option[j]!=NULL && strlen(option[j])>(size_t)b && ((!a && s && !strnicmp(option[j]+b,search,s+1)) - || ((a || !s) && toupper(option[j][b])==toupper(i)))) { + || ((a || !s) && toupper(option[j][b])==toupper(gotkey)))) { if(a) s=0; else s++; if(y+(j-(*cur))+2>height+top) { @@ -1527,7 +1582,7 @@ int ulist(int mode, int left, int top, i s=0; } else - switch(i) { + switch(gotkey) { case CR: if(!opts) break; @@ -1577,7 +1632,7 @@ int ulist(int mode, int left, int top, i return(-1); default: if(mode&WIN_EXTKEYS) - return(-2-i); + return(-2-gotkey); } } } @@ -1587,7 +1642,7 @@ int ulist(int mode, int left, int top, i save_menu_cur=*cur; save_menu_bar=*bar; save_menu_opts=opts; - return(-2-i); + return(-2-gotkey); } } } @@ -1599,8 +1654,8 @@ int ulist(int mode, int left, int top, i int uinput(int mode, int left, int top, char *inprompt, char *str, int max, int kmode) { - unsigned char save_buf[2048],in_win[2048] - ,shade[160]; + unsigned char save_buf[MAX_COLS*8],in_win[MAX_COLS*6] + ,shade[MAX_COLS*2]; int width; int height=3; int i,plen,slen,j; @@ -2030,6 +2085,7 @@ int ugetstr(int left, int top, int width continue; } case CIO_KEY_DC: /* delete */ + case DEL: /* sdl_getch() is returning 127 when keypad "Del" is hit */ if(iscrn_len+1,api->bclr|(api->cclr<<4)," "); i+=4; @@ -2533,7 +2590,7 @@ void showbuf(int mode, int left, int top textbuf[i]=hbuf[j]; textbuf[i+1]=inverse ? (api->bclr|(api->cclr<<4)) : high ? (api->hclr|(api->bclr<<4)) : (api->lclr|(api->bclr<<4)); - if((i+2)%((width-2-pad-pad)*2)==0 && (hbuf[j+1]==LF) || (hbuf[j+1]==CR && hbuf[j+2]==LF)) + if(((i+2)%((width-2-pad-pad)*2)==0 && (hbuf[j+1]==LF)) || (hbuf[j+1]==CR && hbuf[j+2]==LF)) i-=2; } else @@ -2579,6 +2636,9 @@ void showbuf(int mode, int left, int top p=p+(width-2-pad-pad)*2*(height-5); continue; } + /* Non-click events (drag, move, multiclick, etc) */ + else if(mevnt.event!=CIOLIB_BUTTON_CLICK(CIOLIB_BUTTON_NUMBER(mevnt.event))) + continue; i=1; } continue;