Example #1
0
	// 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;

	}
Example #2
0
	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;

	}