misc_gui.c
changeset 911 bde79514283f
parent 910 00fae04bd8d3
child 926 bd4312619522
equal deleted inserted replaced
910:00fae04bd8d3 911:bde79514283f
   770 	num -= w->hscroll.cap;
   770 	num -= w->hscroll.cap;
   771 	if (num < 0) num = 0;
   771 	if (num < 0) num = 0;
   772 	if (num < w->hscroll.pos) w->hscroll.pos = num;
   772 	if (num < w->hscroll.pos) w->hscroll.pos = num;
   773 }
   773 }
   774 
   774 
       
   775 /* Get the count of characters in the string as well as the width in pixels
       
   776  * [IN]buf: string to be checked
       
   777  * [OUT]count: gets set to the count of characters
       
   778  * [OUT]width: gets set to the pixels width */
       
   779 static void GetCurrentStringSize(const byte *buf, int *count, int *width)
       
   780 {
       
   781 	*count = 0;
       
   782 	*width = -1;
       
   783 
       
   784 	do {
       
   785 		if (*++buf == 0)
       
   786 			break;
       
   787 		(*count)++;
       
   788 		(*width) += _stringwidth_table[*buf - 32];
       
   789 	} while (1);
       
   790 }
       
   791 
   775 int HandleEditBoxKey(Window *w, int wid, WindowEvent *we)
   792 int HandleEditBoxKey(Window *w, int wid, WindowEvent *we)
   776 {
   793 {
   777 	byte *p;
       
   778 	int width,count;
   794 	int width,count;
   779 	int key = we->keypress.ascii;
   795 	int key = we->keypress.ascii;
   780 
   796 
   781 	we->keypress.cont = false;
   797 	we->keypress.cont = false;
   782 
   798 
   783 	if (we->keypress.keycode == WKC_ESC) {
   799 	if (we->keypress.keycode == WKC_ESC) {
   784 		return 2;
   800 		return 2;
   785 	} else if (we->keypress.keycode == WKC_RETURN) {
   801 	} else if (we->keypress.keycode == WKC_RETURN) {
   786 		return 1;
   802 		return 1;
       
   803 #ifdef WIN32
       
   804 	} else if (we->keypress.keycode == (WKC_CTRL | 'V')) {
       
   805 		if (IsClipboardFormatAvailable(CF_TEXT)) {
       
   806 			const byte* data;
       
   807 			HGLOBAL cbuf;
       
   808 
       
   809 			OpenClipboard(NULL);
       
   810 			cbuf = GetClipboardData(CF_TEXT);
       
   811 			data = GlobalLock(cbuf); // clipboard data
       
   812 
       
   813 			GetCurrentStringSize(WP(w,querystr_d).buf - 1, &count, &width);
       
   814 
       
   815 			/* IS_INT_INSIDE = filter for ascii-function codes like BELL and so on [we need an special filter here later] */
       
   816 			for (; (IS_INT_INSIDE(*data, ' ', 256)) && // valid ASCII char
       
   817 					(count < WP(w,querystr_d).maxlen - 1 && // max charcount; always allow for terminating '\0'
       
   818 					width + _stringwidth_table[(int)(*data) - 32] <= WP(w,querystr_d).maxwidth); ++data) { // max screensize
       
   819 
       
   820 				// append data and update size parameters
       
   821 				WP(w,querystr_d).buf[count] = *data;
       
   822 				count++;
       
   823 				width += _stringwidth_table[*data - 32];
       
   824 			}
       
   825 			WP(w,querystr_d).buf[count + 1] = '\0';
       
   826 
       
   827 			GlobalUnlock(cbuf);
       
   828 			CloseClipboard();
       
   829 			InvalidateWidget(w, wid);
       
   830 		}
       
   831 #endif
   787 	} else {
   832 	} else {
   788 		width = -1;
   833 		GetCurrentStringSize(WP(w,querystr_d).buf - 1, &count, &width);
   789 		p = WP(w,querystr_d).buf - 1;
       
   790 		count = 0;
       
   791 		do {
       
   792 			if (*++p == 0)
       
   793 				break;
       
   794 			count++;
       
   795 			width += _stringwidth_table[*p - 32];
       
   796 		} while (1);
       
   797 
   834 
   798 		if (we->keypress.keycode == WKC_BACKSPACE) {
   835 		if (we->keypress.keycode == WKC_BACKSPACE) {
   799 			if (count != 0) {
   836 			if (count != 0) {
   800 				WP(w,querystr_d).buf[count-1] = 0;
   837 				WP(w,querystr_d).buf[count-1] = 0;
   801 				InvalidateWidget(w, wid);
   838 				InvalidateWidget(w, wid);
   802 			}
   839 			}
   803 		} else if (IS_INT_INSIDE((key = we->keypress.ascii), 32, 256)) {
   840 		} else if (IS_INT_INSIDE((key = we->keypress.ascii), 32, 256)) {
   804 			if (count < WP(w,querystr_d).maxlen && width + _stringwidth_table[key-32] <= WP(w,querystr_d).maxwidth) {
   841 			if (count < WP(w,querystr_d).maxlen && width + _stringwidth_table[key - 32] <= WP(w,querystr_d).maxwidth) {
   805 				WP(w,querystr_d).buf[count] = key;
   842 				WP(w,querystr_d).buf[count] = key;
   806 				WP(w,querystr_d).buf[count+1] = 0;
   843 				WP(w,querystr_d).buf[count + 1] = '\0';
   807 				InvalidateWidget(w, wid);
   844 				InvalidateWidget(w, wid);
   808 			}
   845 			}
   809 		} else {
   846 		} else // key wasn't caught
   810 			// key wasn't caught
       
   811 			we->keypress.cont = true;
   847 			we->keypress.cont = true;
   812 		}
       
   813 	}
   848 	}
   814 
   849 
   815 	return 0;
   850 	return 0;
   816 }
   851 }
   817 
   852