/** * listitemicon was clicked */ static int listitemicon_click(liqcell *self,liqcellclickeventargs *args, void *context) { liqcell *c = liqcell_quickcreatevis(liqcell_getcaption(self),liqcell_getcaption(self),0,0,-1,-1); if(c) { if(liqcell_getvisible(c)) { liqcell_easyrun(c); } liqcell_release(c); liqcell_setimage(self,NULL); } return 1; }
int desktopmanage_live_gettick(liqcell *desktopmanage,char *namebuf,int namelen) { liqapp_log("desktopmanage: updating ticks"); snprintf(namebuf,namelen,""); liqcell *list1 = liqcell_child_lookup( desktopmanage,"list1"); //############################# backplane:picturebox liqcell *backplane =liqcell_child_lookup( list1,"backplane"); //############################# listitem:picturebox liqcell *listitem = liqcell_getlinkchild_visual(backplane); while(listitem) { //if(liqcell_getflagvisual(listitem)) { char *key=listitem->name; liqcell *listitemlive = liqcell_child_lookup( listitem,"listitemlive"); char *cap = liqcell_getcaption(listitemlive); if( (strcasecmp(cap,"Y")==0) ) { snprintf(namebuf,namelen,"%s",key); return 0; } } listitem=liqcell_getlinknext_visual(listitem); } return -1; }
/** * listitemlive was clicked */ static int listitemlive_click(liqcell *self,liqcellclickeventargs *args, void *context) { // code required // 20090421_191821 lcuk : switch between yes and no, eventually make into icons char *cap = liqcell_getcaption(self); if( (strcasecmp(cap,"Y")==0) ) { //liqcell_setcaption(self,"N"); //liqcell_propsets( self, "textcolor", "rgb(255,0,0)" ); liqcell_setcaption(self,"N"); liqcell_propsets( self, "textcolor", "rgb(255,0,0)" ); desktopmanage_live_untickall(context); } else { // disable all others then set this one. desktopmanage_live_untickall(context); liqcell_setcaption(self,"Y"); liqcell_propsets( self, "textcolor", "rgb(0,255,0)" ); } return 1; }
/** * oneconfigure.cmdsave clicked */ static int cmdsave_click(liqcell *self,liqcelleventargs *args, liqcell *oneconfigure) { liqcell *twitterusername = liqcell_child_lookup(oneconfigure, "twitterusername"); liqcell *twitterpassword = liqcell_child_lookup(oneconfigure, "twitterpassword"); liqcell *scsserver = liqcell_child_lookup(oneconfigure, "scsserver"); liqapp_pref_setvalue( "scsserver", liqcell_getcaption(scsserver) ); liqapp_pref_setvalue( "twitname", liqcell_getcaption(twitterusername) ); liqapp_pref_setvalue( "twitpass", liqcell_getcaption(twitterpassword) ); liqapp_prefs_save(); liqcell_propseti(oneconfigure,"dialog_running",0); return 0; }
static int search_click(liqcell *self, liqcelleventargs *args, liqcell *sheepdrawing_pictureselect) { // try to add this tag :) //liqcell *body = liqcell_child_lookup(sheepdrawing_pictureselect,"body"); char *searchterm = liqcell_getcaption(self); if(!searchterm || !*searchterm) return 1; liqcell_setcaption(self,""); return 1; }
static int search_change(liqcell *self, liqcelleventargs *args, liqcell *sheepdrawing_pictureselect) { // examine each tag and if matches the search show it, otherwise dont.. char *searchterm = liqcell_getcaption(self); liqcell *sheepdrawing_picturegrid=liqcell_child_lookup(sheepdrawing_pictureselect,"sheepdrawing_picturegrid"); liqcell_filter_run(sheepdrawing_picturegrid,searchterm); return 1; }
/** Ip Submit Button Action */ static int ip_submit_click(liqcell *self, liqcelleventargs *args, liqcell *ipbar) { // get ip liqcell *ip_textbox = liqcell_child_lookup(ipbar, "ip_textbox"); char *ip_addr = liqcell_getcaption(ip_textbox); // create new monitor cell liqcell *zachmon = liqcell_getlinkparent(ipbar); Monitor_Cell_Init(zachmon, ip_addr); return 1; }
/** Simplebar Submit Button Action */ static int simplebar_submit_click(liqcell *self, liqcelleventargs *args, liqcell *simplebar) { // get textbox caption liqcell *textbox = liqcell_child_lookup(simplebar, "simple_textbox"); char *caption = liqcell_getcaption(textbox); // set the caption of body liqcell *app = liqcell_getlinkparent(simplebar); liqcell *body = liqcell_child_lookup(app, "body"); liqcell_setcaption(body, caption); return 1; }
int liqcalc_add_op(liqcell *self,const char operation) { // check stack for pending operation // perform opeation on lcd,op,stack2 // push the current lcd caption to the stack // push the new operation to the stack // reset lcd ready for next operation liqcell *calclcd = liqcell_child_lookup(self, "calclcd"); liqcell *calcstack = liqcell_child_lookup(self, "calcstack"); char *cap = liqcell_getcaption(calclcd); return 0; }
static int keyboard_show_button_click(liqcell *self,liqcellclickeventargs *args, liqcell *textbox) { liqcell *vkbd = liqcell_quickcreatevis("vkbd", "liqkeyboard", 0, 0, -1, -1); liqcell *vkbd_textbox = liqcell_child_lookup(vkbd, "liqkeyboard_textbox"); if(vkbd) { // 20090814_203451 lcuk : make sure the * follow into the vkb :) liqcell_propseti(vkbd_textbox,"textispassword", liqcell_propgeti(textbox,"textispassword",0) ); char *caption = liqcell_getcaption(textbox); liqcell_setcaption(vkbd_textbox, caption); liqcell_setdata(vkbd, textbox); liqcell_easyrun(vkbd); liqcell_release(vkbd); } return 1; }
int desktopmanage_updateticks(liqcell *desktopmanage) { liqapp_log("desktopmanage: updating ticks"); desktopmanage_live_untickall(desktopmanage); char *liveback = liqapp_pref_getvalue("liveback"); if(liveback && *liveback) { desktopmanage_live_tickone(desktopmanage,liveback); } liqcell *list1 = liqcell_child_lookup( desktopmanage,"list1"); //############################# backplane:picturebox liqcell *backplane =liqcell_child_lookup( list1,"backplane"); //############################# listitem:picturebox liqcell *listitem = liqcell_getlinkchild_visual(backplane); while(listitem) { //if(liqcell_getflagvisual(listitem)) { char *key=listitem->name; liqcell *listitemicon = liqcell_child_lookup( listitem,"listitemtick"); char *cap = liqcell_getcaption(listitemicon); if( !liqbase_playground_check_if_class_shown(key) ) { liqcell_setcaption(listitemicon,"N"); liqcell_propsets( listitemicon, "textcolor", "rgb(255,0,0)" ); } else { //liqapp_log("desktopmanage: tick yes '%s'",key); liqcell_setcaption(listitemicon,"Y"); liqcell_propsets( listitemicon, "textcolor", "rgb(0,255,0)" ); } } listitem=liqcell_getlinknext_visual(listitem); } liqapp_log("desktopmanage: updated ticks"); }
/** * listitemname was clicked */ static int listitemname_click(liqcell *self,liqcellclickeventargs *args, void *context) { // code required //args->newdialogtoopen = desktopmanageitem_create(); liqcell *c = liqcell_quickcreatevis("c",liqcell_getcaption(self),0,0,-1,-1); if(c) { if(liqcell_getvisible(c)) { liqcell_easyrun(c); } liqcell_release(c); } return 1; }
/** * uitxtmsgbox.captionchange clicked */ static int uitxtmsgbox_captionchange(liqcell *self,liqcelleventargs *args, liqcell *uitxtmsgbox) { int tl = strlen(liqcell_getcaption(self)); //liqcell *messageremain = liqcell_child_lookup(uitxtmsgbox, "messageremain"); //liqcell_setcaption_printf(messageremain,"%i",50-tl); if(tl>100) { liqcell_setfont( self, liqfont_cache_getttf("/usr/share/fonts/nokia/nosnb.ttf", (29), 0) ); } else if(tl>80) { liqcell_setfont( self, liqfont_cache_getttf("/usr/share/fonts/nokia/nosnb.ttf", (34), 0) ); } else if(tl>60) { liqcell_setfont( self, liqfont_cache_getttf("/usr/share/fonts/nokia/nosnb.ttf", (40), 0) ); } else if(tl>40) { liqcell_setfont( self, liqfont_cache_getttf("/usr/share/fonts/nokia/nosnb.ttf", (48), 0) ); } else if(tl>20) { liqcell_setfont( self, liqfont_cache_getttf("/usr/share/fonts/nokia/nosnb.ttf", (56), 0) ); } else { liqcell_setfont( self, liqfont_cache_getttf("/usr/share/fonts/nokia/nosnb.ttf", (64), 0) ); } return 0; }
/** * listitemtick was clicked */ static int listitemtick_click(liqcell *self,liqcellclickeventargs *args, void *context) { // code required // 20090421_191821 lcuk : switch between yes and no, eventually make into icons char *cap = liqcell_getcaption(self); if( (strcasecmp(cap,"Y")==0) ) { liqcell_setcaption(self,"N"); liqcell_propsets( self, "textcolor", "rgb(255,0,0)" ); } else { liqcell_setcaption(self,"Y"); liqcell_propsets( self, "textcolor", "rgb(0,255,0)" ); } return 1; }
int liqcalc_adddot(liqcell *self) { // append a . to the current caption // ensure its valid numerically first // if its "0", just use the new cap // if its blank, use "0." liqcell *calclcd = liqcell_child_lookup(self, "calclcd"); char *cap = liqcell_getcaption(calclcd); if(!cap)cap=""; if(*cap && !isdigit(*cap))cap=""; if(strcmp(cap,"0")==0)cap=""; if(strlen(cap)<9 && strstr(cap,".")==NULL) { if(!*cap)cap="0"; char newcap[32]; snprintf(newcap,sizeof(newcap),"%s%c",cap,'.'); liqcell_setcaption(calclcd,newcap); } return 0; }
int liqcalc_adddigit(liqcell *self,const char digit) { // append a digit to the current caption // ensure its valid numerically first // if its "0", just use the new cap // 8 DIGITS allowed, though length maybe 9 including . liqcell *calclcd = liqcell_child_lookup(self, "calclcd"); char *cap = liqcell_getcaption(calclcd); if(!cap)cap=""; if(*cap && !isdigit(*cap))cap=""; if(strcmp(cap,"0")==0)cap=""; int max=9; if(strstr(cap,".")==NULL)max--; if( (strlen(cap)<max) ) { char newcap[32]; snprintf(newcap,sizeof(newcap),"%s%c",cap,digit); liqcell_setcaption(calclcd,newcap); } return 0; }
/** * liqpostcard.cmdsend clicked */ static int cmdsend_click(liqcell *self,liqcelleventargs *args, liqcell *liqpostcard) { liqcell *picfront = liqcell_child_lookup(liqpostcard, "picfront"); liqcell *messageback = liqcell_child_lookup(liqpostcard, "messageback"); liqcell *tweetmessage = liqcell_child_lookup(liqpostcard, "tweetmessage"); liqimage *imgfront = liqcell_getimage(picfront); liqimage *imgback = liqcell_getimage(messageback); liqsketch *sketch = liqcell_getsketch(messageback); char *tweet = liqcell_getcaption(tweetmessage); if(!imgfront) { liqapp_log("cmdsend_click need imgfront"); return -1; } if(!imgback) { liqapp_log("cmdsend_click need imgback"); return -1; } if(!sketch) { liqapp_log("cmdsend_click need sketch"); return -1; } if(!tweet || !*tweet) { liqapp_log("cmdsend_click need tweet"); return -1; } //liqpostcard_sendnow(liqpostcard,imgfront,imgback,sketch, tweet); liqpostcard_master = liqpostcard; liqcell * progress = liqcell_quickcreatevis("liqpostcard.liqpostcard_sendprogress","liqpostcard.liqpostcard_sendprogress",0,0,-1,-1); if(progress) { liqcell_easyrun(progress); int sentok = liqcell_propgeti(progress,"sentok",0); liqcell_release(progress); if(!sentok) { //return 0; } if(sentok) { liqcell_setcaption(tweetmessage,""); liqsketch_clear(sketch); } } liqpostcard_master = NULL; return 0; }
/** * buttonaccept was clicked */ static int buttonaccept_click(liqcell *self,liqcellclickeventargs *args, liqcell *desktopmanage) { // save the selections and make sure the main playground knows :) //args->newdialogtoopen = desktopmanageitem_create(); char resultset[2048]={0}; liqapp_log("desktopmanage: accepting"); // 20090421_191821 lcuk : enumerate the listitems and store the results // 20090421_193449 lcuk : not finished yet liqcell *base = desktopmanage;//liqcell_getbasewidget(self); liqcell *list1 = liqcell_child_lookup( base,"list1"); //############################# backplane:picturebox liqcell *backplane =liqcell_child_lookup( list1,"backplane"); //############################# listitem:picturebox liqcell *listitem = liqcell_getlinkchild(backplane); while(listitem) { if(liqcell_getflagvisual(listitem)) { char *key=listitem->name; liqcell *listitemicon = liqcell_child_lookup( listitem,"listitemtick"); char *cap = liqcell_getcaption(listitemicon); if( (strcasecmp(cap,"Y")==0) ) { // mark this as wanted next time if(strlen(resultset)+1+strlen(key) < sizeof(resultset)) { if(strlen(resultset)>0) strcat(resultset,","); strcat(resultset,key); } } else { // mark this as explicitly removed } } listitem=liqcell_getlinknext(listitem); } liqapp_log("desktopmanage: saving '%s'",resultset); liqapp_pref_setvalue( "liqbase_playground_contents", resultset ); char live[128]=""; desktopmanage_live_gettick(desktopmanage,live,128); if(live[0]) { liqapp_pref_setvalue( "liveback", live ); } else liqapp_pref_setvalue( "liveback", "" ); liqapp_prefs_save(); liqbase_playground_refresh_desktop_contents(); liqcell_propseti(desktopmanage,"dialog_running",0); return 1; }
static int desktopmanage_filter(liqcell *self, liqcellfiltereventargs *args, liqcell *desktopmanage) { // using the filter provided (which might be blank) //liqapp_log("deep filter"); int islike = 1;//liqcell_propgeti( self, "filterlike", 1 ); char *searchterm = NULL; if(args) args->resultoutof=0; if(args) args->resultshown=0; if(args) searchterm = args->searchterm; //liqapp_log("deep filter2"); // examine each tag and if matches the search show it, otherwise dont.. liqcell *list1 = liqcell_child_lookup( desktopmanage,"list1"); //############################# backplane:picturebox liqcell *backplane =liqcell_child_lookup( list1,"backplane"); //liqapp_log("deep filter3 %i",backplane==NULL); liqcell *c = liqcell_getlinkchild_visual(backplane); while(c) { if(searchterm && *searchterm) { //struct pagefilename pfn; //pagefilename_breakapart(&pfn,c->name); char *key = c->name; // liqapp_log("checking '%s' in '%s'",searchterm,key); int isok = (key!=NULL) && (*key |= 0); if(isok) { if(islike) { // anywhere in string isok = ( stristr(key,searchterm) != NULL ); } else { // only from the start isok = ( c->name == stristr(key,searchterm) ); } } if(!isok) { // see if we can show it anyway //if(liqcell_getselected(c)) isok=1; liqcell *listitemicon = liqcell_child_lookup( c,"listitemicon"); char *cap = liqcell_getcaption(listitemicon); if( (strcasecmp(cap,"Y")==0) ) isok=1; } if( isok ) // strstr(c->name,searchterm) ) { // found a match! liqcell_setvisible(c,1); if(args) args->resultshown++; } else { // no match :( liqcell_setvisible(c,0); } if(args) args->resultoutof++; } else { // nothing to search for, show it liqcell_setvisible(c,1); if(args) args->resultoutof++; if(args) args->resultshown++; } c=liqcell_getlinknext_visual(c); } liqcell_setrect(backplane, 0,0,self->w,self->h); liqcell_child_arrange_autoflow( backplane ); backplane->h+=40; return 1; }
static int textbox_keypress(liqcell *self, liqcellkeyeventargs *args,void *context) { //liqcell *base = liqcell_getbasewidget(self); // i can then use my base to access members as defined by the widget itself //liqcell_setcaption(self,args->keystring); int selstart = liqcell_propgeti( self,"selstart",-1); int sellength = liqcell_propgeti( self,"sellength",0); int cursorpos = liqcell_propgeti( self,"cursorpos",-1); char *caption = liqcell_getcaption(self); int captionlen = strlen(caption); char *key = args->keystring; int keylen = strlen(key); if(selstart>captionlen){ selstart=captionlen;sellength=0; } if(selstart+sellength>captionlen) { sellength = captionlen-selstart; } if(selstart>=0 && (keylen>0)) { liqapp_log("keypress: %3i '%c'",(int)(*key),*key,args->keycode); if(*key==8) { // delete ;) key=""; keylen=0; if(selstart>0 && sellength==0) { selstart--; sellength++; } } if(*key==13) { // click event! liqapp_log("keypress return! click event firing!"); key=""; keylen=0; liqcell_handlerrun(self,"click",NULL); return 1; } // //liqcell_setcaption(self,args->keystring); char *aftersel=&caption[selstart+sellength]; int aftersellen = strlen(aftersel); // then the result is start..selstart // newbit // selstart+sellen..end int reqd = selstart + keylen + aftersellen + 1; char *buff=malloc(reqd); char *block=buff; if(buff) { if(selstart>0) { strncpy(block,caption,selstart); block+=selstart; } if(keylen>0) { strncpy(block,key,keylen); block+=keylen; } if(aftersellen>0) { strncpy(block,aftersel,aftersellen); block+=aftersellen; } *block=0; liqcell_setcaption(self,buff); free(buff); } liqcell_propseti( self, "selstart", selstart + keylen); liqcell_propseti( self, "sellength", 0 ); liqcell_propseti( self, "cursorpos", selstart + keylen); liqcell_handlerrun(self,"selchange",NULL); } }
// damn, this should be taken care of by the OS itself // this is because the hitpoint will not always match with where I think it will be // this is bad and good in practice static int textbox_mouse(liqcell *self, liqcellmouseeventargs *args,void *context) { // if i have a font on my cell, surely it will have been rendered correctly first.. // infact, thats right i think //liqcell *base = liqcell_getbasewidget(self); liqcell *body = self; liqfont *font = liqcell_getfont( self); if(!font)return 0; char *cap = liqcell_getcaption(self); if(!cap)return 0; int caplen = strlen(cap); int mx = args->mex - liqcell_getx(self); int chpos = liqfont_textfitinside(font,cap,mx); // neat :) i know where the mouse clicked (left aligned text only...) // todo: handle other alignments if(args->mcnt==1) { // start of selection.. liqcell_propseti( self, "selfirst", chpos ); liqcell_propseti( self, "selstart", chpos ); liqcell_propseti( self, "sellength", 0 ); liqcell_propseti( self, "cursorpos", chpos ); } else { // extending selection int selfirst = liqcell_propgeti( self,"selfirst",chpos); int selstart; int sellength; if(chpos<selfirst) { // got to invert selstart=chpos; sellength=selfirst-chpos; } else { selstart=selfirst; sellength=chpos-selfirst; } liqcell_propseti( self, "selstart", selstart ); liqcell_propseti( self, "sellength", sellength ); liqcell_propseti( self, "cursorpos", chpos ); } liqcell_handlerrun(self,"selchange",NULL); return 1; }
static int textbox_mouse(liqcell *self, liqcellmouseeventargs *args,void *context) { // if i have a font on my cell, surely it will have been rendered correctly first.. // infact, thats right i think //liqcell *base = liqcell_getbasewidget(self); //liqcell *body = self; liqfont *font = liqcell_getfont( self); if(!font)return 0; char *cap = liqcell_getcaption(self); if(!cap)return 0; // 20090814_184437 lcuk : if password, replace cap with string("*",len(cap)) for selection purposes char passbuff[1024]; if(liqcell_propgeti(self,"textispassword",0)) { int clen = strlen(cap); if(clen>=sizeof(passbuff)-1)clen=sizeof(passbuff)-1; int x; for(x=0;x<clen;x++)passbuff[x]='*'; passbuff[x]=0; cap=passbuff; } //int caplen = strlen(cap); //########################## // this tells me where abouts I am on a single line int mx = args->mex - liqcell_getx(self) - 8; // available space per line int my = args->mey - liqcell_gety(self) - 4; int chpos = liqfont_textfitinside(font,cap,mx); // char pos of selection //########################## // count all the lines #define linemax 128 char *linestarts[linemax]; int lineheight = liqfont_textheight(font); int lineoffsets[linemax]; int linelengths[linemax]; int linecount=0; char *c = cap; while(c && *c) { int tl = strlen(c); // total length remaining int lc = liqfont_textfitinside(font, c, liqcell_getw(self)-4 ); if(lc<tl) { int le = lc; while(le>0) { switch(c[le-1]) { case ' ': case ',': case ';': case ':': case '.': le--; break; default: goto fin; } } fin: if(le>0)lc=le; while(c[lc]==' ')lc++; } linestarts[linecount] = c; lineoffsets[linecount] = c-cap; linelengths[linecount] = lc; linecount++; c=&c[lc]; } //########################## // work out which line the mouse has hit int lx=mx; int ly=0; ly = my / lineheight; //liqapp_log("mx=%3i, my=%3i, chpos=%3i lx=%3i, ly=%3i",mx,my,chpos, lx,ly); if(ly>=linecount)ly=linecount-1; if(ly>=0) { // adjust chpos to make sure now we are selecting from the correct line chpos = lineoffsets[ly] + liqfont_textfitinside(font, linestarts[ly] ,mx); } // neat :) i know where the mouse clicked (left aligned text only...) // todo: handle other alignments if(args->mcnt==1) { // start of selection.. liqcell_propseti( self, "selfirst", chpos ); liqcell_propseti( self, "selstart", chpos ); liqcell_propseti( self, "sellength", 0 ); liqcell_propseti( self, "cursorpos", chpos ); } else { // extending selection int selfirst = liqcell_propgeti( self,"selfirst",chpos); int selstart; int sellength; if(chpos<selfirst) { // got to invert selstart=chpos; sellength=selfirst-chpos; } else { selstart=selfirst; sellength=chpos-selfirst; } liqcell_propseti( self, "selstart", selstart ); liqcell_propseti( self, "sellength", sellength ); liqcell_propseti( self, "cursorpos", chpos ); } return 1; }
static int textbox_keypress(liqcell *self, liqcellkeyeventargs *args,void *context) { //liqcell *base = liqcell_getbasewidget(self); // i can then use my base to access members as defined by the widget itself //liqcell_setcaption(self,args->keystring); int selstart = liqcell_propgeti( self,"selstart",-1); int sellength = liqcell_propgeti( self,"sellength",0); int cursorpos = liqcell_propgeti( self,"cursorpos",-1); char *caption = liqcell_getcaption(self); int captionlen = strlen(caption); char *key =strdup( args->keystring ? args->keystring : ""); //if(!key)key=""; if(*key && *key<32) { if(*key==10) { // Wed Aug 19 00:17:53 2009 lcuk : change this now to send a different event :) // Wed Aug 19 00:18:00 2009 lcuk : easier to get a special "keypress_enter" message and know what to do // Wed Aug 19 00:23:07 2009 lcuk : lots of things do stuff when you press enter // Wed Aug 19 00:23:17 2009 lcuk : alternative is a default button as in visual basic // Wed Aug 19 00:23:41 2009 lcuk : how do i find the related default button though within the system liqcell_handlerrun(self,"keypress_enter",NULL); free(key); key=strdup(""); } if(*key==8 || *key==9) { // bs and tab } else { // ack! ignore these in single line textbox! free(key); key=strdup(""); } } int keylen = strlen(key); if(selstart>captionlen){ selstart=captionlen;sellength=0; } if(selstart+sellength>captionlen) { sellength = captionlen-selstart; } if(selstart>=0)// && (keylen>0)) { liqapp_log("keypress: %3i '%c' %i %i",(int)(*key),*key,args->keycode,args->keymodifierstate); if(cursorpos<0)cursorpos=0; if(keylen==0) { // special keys if(args->keycode==XK_Left) { selstart--; if(selstart<0)selstart=0; if(args->keymodifierstate==0) sellength=0; else sellength++; cursorpos=selstart; liqcell_propseti( self, "selstart", selstart); liqcell_propseti( self, "sellength", sellength); liqcell_propseti( self, "cursorpos", cursorpos); } else if(args->keycode==XK_Right) { if(args->keymodifierstate==0) { selstart+=sellength+1; if(selstart>captionlen)selstart=captionlen; sellength=0; //cursorpos=selstart; } else { sellength++; //cursorpos=selstart+sellength; //if(cursorpos>captionlen)cursorpos=captionlen; } if(selstart+sellength>captionlen) { sellength = captionlen-selstart; } cursorpos=selstart+sellength; liqcell_propseti( self, "selstart", selstart); liqcell_propseti( self, "sellength", sellength); liqcell_propseti( self, "cursorpos", cursorpos); } else { if(args->keycode==120 && (args->keymodifierstate&4)) { liqapp_log("key CTRL X :: CUT"); if(liqclip){free(liqclip);liqclip=NULL;} liqclip = strndup(&caption[selstart],sellength); free(key); key=strdup(""); keylen = strlen(key); goto selch; } if(args->keycode==99 && (args->keymodifierstate&4)) { liqapp_log("key CTRL C :: COPY"); if(liqclip){free(liqclip);liqclip=NULL;} liqclip = strndup(&caption[selstart],sellength); free(key); return 0; } if(args->keycode==118 && (args->keymodifierstate&4)) { liqapp_log("key CTRL V :: PASTE"); free(key); key=strdup(liqclip?liqclip:""); keylen = strlen(key); goto selch; } } } else { // regular keypress if(*key==8) { // delete ;) free(key); key=strdup(""); keylen = strlen(key); if(selstart>0 && sellength==0) { selstart--; sellength++; } } selch: { } // //liqcell_setcaption(self,args->keystring); char *aftersel=&caption[selstart+sellength]; int aftersellen = strlen(aftersel); // then the result is start..selstart // newbit // selstart+sellen..end int maxlen = liqcell_propgeti( self,"maxlength",0); if(maxlen>0) { if( (selstart + keylen + aftersellen)>maxlen ) keylen = maxlen-(selstart+aftersellen); if(keylen<0)keylen=0; } // !-- BUG FIX BY ZACH HABERSANG -- ! // ---------------------------------- // Program would segfault when 25 or so characters were entered // Fix: + 1 fix to reqd! :D // note: used gdb with backtrace to find this bug // 20090615_210659 lcuk : and me to explain why it was wrong ;) damn those +1 adjustments.. int reqd = selstart + keylen + aftersellen + 1; char *buff=malloc(reqd); char *block=buff; if(buff) { if(selstart>0) { strncpy(block,caption,selstart); block+=selstart; } if(keylen>0) { strncpy(block,key,keylen); block+=keylen; } if(aftersellen>0) { strncpy(block,aftersel,aftersellen); block+=aftersellen; } *block=0; liqcell_setcaption(self,buff); free(buff); } liqcell_propseti( self, "selstart", selstart + keylen); liqcell_propseti( self, "sellength", 0 ); liqcell_propseti( self, "cursorpos", selstart + keylen); } } if(key)free(key); return 0; }