Hello community, here is the log from the commit of package libstfl for openSUSE:Factory checked in at 2015-05-15 07:44:14 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/libstfl (Old) and /work/SRC/openSUSE:Factory/.libstfl.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "libstfl" Changes: -------- --- /work/SRC/openSUSE:Factory/libstfl/libstfl.changes 2012-03-06 13:38:43.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.libstfl.new/libstfl.changes 2015-05-15 07:44:41.000000000 +0200 @@ -1,0 +2,7 @@ +Wed May 13 15:01:26 UTC 2015 - mplus...@suse.com + +- Update to 0.23 + * no upstream changelog provided +- Cleanup spec file with spec-cleaner + +------------------------------------------------------------------- Old: ---- stfl-0.21.tar.gz New: ---- stfl-0.23.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ libstfl.spec ++++++ --- /var/tmp/diff_new_pack.KqlIc7/_old 2015-05-15 07:44:42.000000000 +0200 +++ /var/tmp/diff_new_pack.KqlIc7/_new 2015-05-15 07:44:42.000000000 +0200 @@ -1,7 +1,7 @@ # # spec file for package libstfl # -# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,31 +17,26 @@ %define soname 0 - Name: libstfl -Version: 0.21 +Version: 0.23 Release: 0 Summary: Structured Terminal Forms Library License: LGPL-3.0+ Group: System/Libraries +Url: http://www.clifford.at/stfl/ Source: http://www.clifford.at/stfl/stfl-%{version}.tar.gz Source99: libstfl-rpmlintrc Patch1: stfl-optflags.patch Patch2: stfl-ncurses.patch -Url: http://www.clifford.at/stfl/ -BuildRoot: %{_tmppath}/%{name}-%{version}-build #BuildRequires: swig perl python python-devel ruby ruby-devel -BuildRequires: gcc -BuildRequires: glibc-devel -BuildRequires: make BuildRequires: ncurses-devel -BuildRequires: pkgconfig +BuildRequires: pkg-config +BuildRoot: %{_tmppath}/%{name}-%{version}-build %description ............................................................................. %package -n libstfl%{soname} - Summary: Structured Terminal Forms Library Group: System/Libraries @@ -57,11 +52,10 @@ GUI and can concentrate on the more interesting programming tasks. %package -n libstfl-devel - Summary: Structured Terminal Forms Library Group: Development/Libraries/C and C++ -Requires: ncurses-devel Requires: libstfl%{soname} = %{version} +Requires: ncurses-devel %description -n libstfl-devel STFL is a library which implements a curses-based widget set for text @@ -83,7 +77,7 @@ make %{?_smp_mflags} \ prefix="%{_prefix}" \ libdir="%{_lib}" \ - CC="%__cc" \ + CC="gcc" \ OPTFLAGS="%{optflags}" \ FOUND_SPL=0 \ FOUND_SWIG=0 \ @@ -92,7 +86,7 @@ FOUND_PYTHON=0 %install -%makeinstall \ +make DESTDIR=%{buildroot} install %{?_smp_mflags} \ prefix="%{_prefix}" \ libdir="%{_lib}" \ FOUND_SPL=0 \ @@ -103,7 +97,7 @@ [ -e "%{buildroot}%{_libdir}/libstfl.so.%{soname}" ] || { pushd "%{buildroot}%{_libdir}/" - %__ln_s libstfl.so.*.* libstfl.so.%{soname} + ln -s libstfl.so.*.* libstfl.so.%{soname} popd } ++++++ stfl-0.21.tar.gz -> stfl-0.23.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/Makefile new/stfl-0.23/Makefile --- old/stfl-0.21/Makefile 2009-06-19 19:30:52.000000000 +0200 +++ new/stfl-0.23/Makefile 2014-10-13 20:13:08.000000000 +0200 @@ -25,7 +25,7 @@ export LDLIBS += -lncursesw SONAME := libstfl.so.0 -VERSION := 0.21 +VERSION := 0.23 all: libstfl.so.$(VERSION) libstfl.a example @@ -39,7 +39,7 @@ libstfl.so.$(VERSION): public.o base.o parser.o dump.o style.o binding.o iconv.o \ $(patsubst %.c,%.o,$(wildcard widgets/*.c)) - $(CC) -shared -Wl,-soname,$(SONAME) -o $@ $^ + $(CC) -shared -Wl,-soname,$(SONAME) -o $@ $(LDLIBS) $^ clean: rm -f libstfl.a example core core.* *.o Makefile.deps diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/README new/stfl-0.23/README --- old/stfl-0.21/README 2009-05-06 09:46:36.000000000 +0200 +++ new/stfl-0.23/README 2014-04-25 13:51:13.000000000 +0200 @@ -411,6 +411,40 @@ The offset of the text displayed in the input box (when the text is larger then the input box). +checkbox +~~~~~~~~ + +Implementation of a checkbox. The following variables are supported +by this widget: + + bind_toggle + The keys used to toggle the checkbox value. Default value is + "ENTER SPACE", meaning the ENTER and SPACE keys. + + style_normal + The style of this widget when it does not have the + focus. + + style_focus + The style of this widget when it does have the focus. + + text_0 + The text displayed when the checkbox' value is 0. Default value + is "[ ]". + + text_1 + The text displayed when the checkbox' value is 1. Default value + is "[X]". + + pos + The cursor position within text_0/text_1. The default value is + 1, which works fine for "[ ]" and "[X]". But for example for + text_0:"--> <--" and text_1:"==>X<==" you would want to set it + to 3 instead. + + value + The checkbox' state (0 or 1). + table ~~~~~ @@ -536,6 +570,26 @@ be used to restore the style_normal settings. this variables are only used if the 'richtext' variable is set. +textedit +~~~~~~~~ + +A widget for editing multiline text. The text itself is stored within +listitem child widgets. + + bind_up, bind_down, bind_left, bind_right, bind_page_up, bind_page_down + Key bindings for navigating the text + + style_normal + The style the text itself is displayed. + + style_end + The style used for the EOT-Markers. + + cursor_x, cursor_y + Cursor position within the text + + scroll_x, scroll_y + Current offset for horizontal and vertical scrolling Common Variables ---------------- @@ -567,6 +621,14 @@ of the on_* variables is a key description. E.g. "on_^X:foobar" will let stfl_run() return the string "foobar" when Ctrl-X is beeing pressed. +can_focus +~~~~~~~~~ + +Setting can_focus to '0' on a widget will make it non-focusable, even if +it is a widget that could otherwise have focus (input, listitem, etc.). +The widget is still focusable manually by prefixing it with a '!' or +using stfl_set_focus(). + The Common STFL Scripting Language API -------------------------------------- @@ -590,7 +652,7 @@ All strings passed to STFL functions are considered read-only by STFL and are neither modified nor freed by STFL. -The functions which may return an undefined value will return a null-pointer +The functions which may return an null value will return a null-pointer in C. All string parameters which are null-pointers are interpreted as they where empty strings. @@ -668,8 +730,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~ Return the next event. If no more prior generated events are waiting display -the form and process one input character. The event string can be an undefined -value when something chaned in the form (e.g. the user changed the focus of +the form and process one input character. The event string can be an null +value when something changed in the form (e.g. the user changed the focus of the current widget) but all inputs have been handled internally inside of STFL. The event string can be "TIMEOUT" when the timeout has been reached, a key description is key has been pressed that is not beeing hadled internally in @@ -683,10 +745,10 @@ When the timeout parameter is set to -1 the form is displayed independent of the current status of the event queue and the function returns right after displaying the form without handling any input characters. In this mode always -an undefined value is returned. +an null value is returned. When the timeout parameter is set to -2 the displayed is not updated and the -next pending event is returned. If there are no pending events an undefined +next pending event is returned. If there are no pending events an null value is returned. When the timeout parameter is set to -3, rendering (and setting the :x, :y, :w @@ -705,7 +767,7 @@ ~~~~~~~~~~~~~~~~~~~~ Returns the current value of the specified variable. When the variable does not -exist this function returns an undefined value. +exist this function returns an null value. stfl_set(form, name, value) ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -715,7 +777,7 @@ stfl_get_focus(form) ~~~~~~~~~~~~~~~~~~~~ -Returns the name of the widget which currently has the focus or an undefined +Returns the name of the widget which currently has the focus or an null value when the widget having the focus has no name. stfl_set_focus(form, name) @@ -733,12 +795,12 @@ Return the subtree starting with the widget specified in the 2nd parameter as STFL code fragment. The entire form is return when the 2nd parameter is an -empty string or undefined. All widget and variable names in the dump are +empty string or null. All widget and variable names in the dump are prefixed with the string in the 3rd parameter. The information which widget has the focus is also included in the dump when the 4th parameter is an integer not equal 0. -The function returns an undefined value when there was an error. +The function returns an null value when there was an error. stfl_modify(form, name, mode, text) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -799,7 +861,7 @@ stfl_error() ~~~~~~~~~~~~ -Return the error status of the last STFL call. This is undefined when no error +Return the error status of the last STFL call. This is null when no error occoured and the error message otherwise. An error could e.g. be a parser error for broken STFL code. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/base.c new/stfl-0.23/base.c --- old/stfl-0.21/base.c 2009-06-19 19:27:33.000000000 +0200 +++ new/stfl-0.23/base.c 2014-09-29 09:04:41.000000000 +0200 @@ -39,6 +39,8 @@ &stfl_widget_type_list, &stfl_widget_type_listitem, &stfl_widget_type_textview, + &stfl_widget_type_textedit, + &stfl_widget_type_checkbox, 0 }; @@ -336,14 +338,17 @@ extern struct stfl_widget *stfl_find_first_focusable(struct stfl_widget *w) { - if (w->allow_focus) + if (w->allow_focus && stfl_widget_getkv_int(w, L"can_focus", 1) && + stfl_widget_getkv_int(w, L".display", 1)) return w; struct stfl_widget *c = w->first_child; while (c) { - struct stfl_widget *r = stfl_find_first_focusable(c); - if (r) - return r; + if (stfl_widget_getkv_int(w, L".display", 1)) { + struct stfl_widget *r = stfl_find_first_focusable(c); + if (r) + return r; + } c = c->next_sibling; } @@ -502,6 +507,10 @@ if (timeout == -3) { WINDOW *dummywin = newwin(0, 0, 0, 0); + if (dummywin == NULL) { + fprintf(stderr, "STFL Fatal Error: stfl_form_run() got a NULL pointer from newwin(0, 0, 0, 0).\n"); + abort(); + } f->root->type->f_draw(f->root, f, dummywin); delwin(dummywin); pthread_mutex_unlock(&f->mtx); @@ -510,6 +519,9 @@ werase(stdscr); f->root->type->f_draw(f->root, f, stdscr); + if (timeout == -1 && f->root->cur_y != -1 && f->root->cur_x != -1) { + wmove(stdscr, f->root->cur_y, f->root->cur_x); + } refresh(); if (timeout < 0) { @@ -580,7 +592,7 @@ if (!fw && old_fw) fw = f->root; - } while (fw && !fw->allow_focus); + } while (fw && !(fw->allow_focus && stfl_widget_getkv_int(fw, L"can_focus", 1))); if (old_fw != fw) { @@ -595,6 +607,50 @@ goto unshift_next_event; } + else if (rc == KEY_CODE_YES && wch == KEY_BTAB) + { + struct stfl_widget *old_fw = stfl_widget_by_id(f->root, f->current_focus_id); + struct stfl_widget *tmp_fw = f->root; + struct stfl_widget *fw = 0; + +focus_wrap_around: + while (tmp_fw && tmp_fw != old_fw) + { + if (tmp_fw->allow_focus && stfl_widget_getkv_int(tmp_fw, L"can_focus", 1)) + fw = tmp_fw; + + if (tmp_fw->first_child) + tmp_fw = tmp_fw->first_child; + else + if (tmp_fw->next_sibling) + tmp_fw = tmp_fw->next_sibling; + else + { + while (tmp_fw->parent && !tmp_fw->parent->next_sibling) + tmp_fw = tmp_fw->parent; + tmp_fw = tmp_fw->parent ? tmp_fw->parent->next_sibling : 0; + } + } + + if (!fw && old_fw) + { + old_fw = f->root->last_child; + goto focus_wrap_around; + } + + if (fw && old_fw != fw) + { + if (old_fw && old_fw->type->f_leave) + old_fw->type->f_leave(old_fw, f); + + if (fw && fw->type->f_enter) + fw->type->f_enter(fw, f); + + f->current_focus_id = fw ? fw->id : 0; + } + + goto unshift_next_event; + } generate_event: stfl_form_event(f, stfl_keyname(wch, rc == KEY_CODE_YES)); @@ -681,7 +737,7 @@ len = p1 - p; mvwaddnwstr(win, y, x, p, len); retval += len; - x += len; + x += wcswidth(p, len); if (p2) { wchar_t stylename[p2 - p1]; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/example.stfl new/stfl-0.23/example.stfl --- old/stfl-0.21/example.stfl 2008-04-22 17:56:13.000000000 +0200 +++ new/stfl-0.23/example.stfl 2014-04-25 13:51:13.000000000 +0200 @@ -99,6 +99,37 @@ label .tie:r text:"Short (right)" + table + .expand:0 + + @input#style_focus:bg=blue,fg=white,attr=bold + @input#style_normal:bg=blue,fg=white + @input#.border:rtb + + @checkbox#style_focus:bg=blue,fg=white,attr=bold + @checkbox#style_normal:bg=blue,fg=white + @checkbox#.border:rtb + + @L#style_normal:fg=red + @L#.expand:0 + @L#.border:ltb + @L#.spacer:r + + label#L + text:'Field D:' + .expand:0 + input + .colspan:2 + text[value_a]:'Non-focusable!' + .expand:h + can_focus:0 + checkbox + pos:3 + text_0:"--> <-- Checkbox" + text_1:"==>X<== Checkbox" + value:1 + bind_toggle:"ENTER SPACE BACKSPACE" + textview[textview] .expand:0 @style_blue_normal:fg=blue diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/parser.c new/stfl-0.23/parser.c --- old/stfl-0.21/parser.c 2007-07-24 13:54:01.000000000 +0200 +++ new/stfl-0.23/parser.c 2011-03-07 20:51:03.000000000 +0100 @@ -448,7 +448,7 @@ fprintf(stderr, " "); else if (*text < 32) - fprintf(stderr, "\\%03lo", *text); + fprintf(stderr, "\\%03lo", (long unsigned int)*text); else fprintf(stderr, "%lc", (wint_t)*text); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/public.c new/stfl-0.23/public.c --- old/stfl-0.21/public.c 2008-05-17 15:51:40.000000000 +0200 +++ new/stfl-0.23/public.c 2010-11-24 14:59:06.000000000 +0100 @@ -300,19 +300,19 @@ w = stfl_widget_by_name(f->root, name ? name : L""); if (!w) - goto finish; + goto unlock; mode = mode ? mode : L""; if (!wcscmp(mode, L"delete") && w != f->root) { stfl_widget_free(w); - goto finish; + goto unlock; } n = stfl_parser(text ? text : L""); if (!n) - goto finish; + goto unlock; if (!wcscmp(mode, L"replace")) { if (w == f->root) @@ -329,6 +329,7 @@ stfl_modify_insert(w, n->first_child); n->first_child = n->last_child = 0; stfl_widget_free(n); + n = w; goto finish; } @@ -341,6 +342,7 @@ stfl_modify_insert(w, n->first_child); n->first_child = n->last_child = 0; stfl_widget_free(n); + n = w; goto finish; } @@ -353,6 +355,7 @@ stfl_modify_append(w, n->first_child); n->first_child = n->last_child = 0; stfl_widget_free(n); + n = w; goto finish; } @@ -365,6 +368,7 @@ stfl_modify_before(w, n->first_child); n->first_child = n->last_child = 0; stfl_widget_free(n); + n = w; goto finish; } @@ -377,11 +381,13 @@ stfl_modify_after(w, n->first_child); n->first_child = n->last_child = 0; stfl_widget_free(n); + n = w; goto finish; } finish: - stfl_check_setfocus(f, f->root); + stfl_check_setfocus(f, n); +unlock: pthread_mutex_unlock(&f->mtx); return; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/spl/example.spl new/stfl-0.23/spl/example.spl --- old/stfl-0.21/spl/example.spl 2007-07-24 13:54:01.000000000 +0200 +++ new/stfl-0.23/spl/example.spl 2011-05-23 15:06:04.000000000 +0200 @@ -1,4 +1,4 @@ -#!/usr/bin/env splrun +#!/usr/bin/env splrun_norl /* * STFL - The Structured Terminal Forms Language/Library diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/spl/mod_stfl.c new/stfl-0.23/spl/mod_stfl.c --- old/stfl-0.21/spl/mod_stfl.c 2007-07-24 13:54:01.000000000 +0200 +++ new/stfl-0.23/spl/mod_stfl.c 2011-05-23 15:06:04.000000000 +0200 @@ -80,7 +80,7 @@ { struct spl_node *n = SPL_NEW_STRING_DUP("STFL Form"); n->hnode_name = strdup("stfl_form"); - n->hnode_data = stfl_create(stfl_ipool_towc(ipool, spl_clib_get_string(task)));; + n->hnode_data = stfl_create(stfl_ipool_towc(ipool, spl_clib_get_string(task))); stfl_ipool_flush(ipool); return n; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/stfl_internals.h new/stfl-0.23/stfl_internals.h --- old/stfl-0.21/stfl_internals.h 2009-06-19 19:27:33.000000000 +0200 +++ new/stfl-0.23/stfl_internals.h 2014-04-25 13:36:07.000000000 +0200 @@ -63,7 +63,7 @@ struct stfl_widget *last_child; struct stfl_kv *kv_list; struct stfl_widget_type *type; - int id, x, y, w, h, min_w, min_h; + int id, x, y, w, h, min_w, min_h, cur_x, cur_y; int parser_indent, allow_focus; int setfocus; void *internal_data; @@ -97,6 +97,8 @@ extern struct stfl_widget_type stfl_widget_type_list; extern struct stfl_widget_type stfl_widget_type_listitem; extern struct stfl_widget_type stfl_widget_type_textview; +extern struct stfl_widget_type stfl_widget_type_textedit; +extern struct stfl_widget_type stfl_widget_type_checkbox; extern struct stfl_widget *stfl_widget_new(const wchar_t *type); extern void stfl_widget_free(struct stfl_widget *w); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/widgets/wt_checkbox.c new/stfl-0.23/widgets/wt_checkbox.c --- old/stfl-0.21/widgets/wt_checkbox.c 1970-01-01 01:00:00.000000000 +0100 +++ new/stfl-0.23/widgets/wt_checkbox.c 2014-04-25 13:51:13.000000000 +0200 @@ -0,0 +1,98 @@ +/* + * STFL - The Structured Terminal Forms Language/Library + * Copyright (C) 2006, 2007 Clifford Wolf <cliff...@clifford.at> + * Copyright (C) 2014 Davor Ocelic <doce...@spinlocksolutions.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * wt_checkbox.c: Widget type 'checkbox' + */ + +#include "stfl_internals.h" + +#include <string.h> +#include <stdlib.h> + +static void wt_checkbox_init(struct stfl_widget *w) +{ + w->allow_focus = 1; +} + +static void wt_checkbox_prepare(struct stfl_widget *w, struct stfl_form *f) +{ + const wchar_t * text = stfl_widget_getkv_int(w, L"value", 0) ? + stfl_widget_getkv_str(w, L"text_1", L"[X]") : + stfl_widget_getkv_str(w, L"text_0", L"[ ]"); + + w->min_w = wcswidth(text, wcslen(text)); + w->min_h = 1; +} + +static void wt_checkbox_draw(struct stfl_widget *w, struct stfl_form *f, WINDOW *win) +{ + const wchar_t * text; + unsigned int i; + + int is_richtext = stfl_widget_getkv_int(w, L"richtext", 0); + + const wchar_t * style = stfl_widget_getkv_str(w, L"style_normal", L""); + + stfl_widget_style(w, f, win); + + text = stfl_widget_getkv_int(w, L"value", 0) ? + stfl_widget_getkv_str(w, L"text_1", L"[X]") : + stfl_widget_getkv_str(w, L"text_0", L"[ ]"); + + wchar_t *fillup = malloc(sizeof(wchar_t)*(w->w + 1)); + for (i=0;i < w->w;++i) + fillup[i] = L' '; + fillup[w->w] = L'\0'; + mvwaddnwstr(win, w->y, w->x, fillup, wcswidth(fillup,wcslen(fillup))); + free(fillup); + + if (is_richtext) + stfl_print_richtext(w, win, w->y, w->x, text, w->w, style, 0); + else + mvwaddnwstr(win, w->y, w->x, text, w->w); + + if (f->current_focus_id == w->id) { + f->root->cur_x = f->cursor_x = w->x + stfl_widget_getkv_int(w, L"pos", 1); + f->root->cur_y = f->cursor_y = w->y; + } +} + +static int wt_checkbox_process(struct stfl_widget *w, struct stfl_widget *fw, struct stfl_form *f, wchar_t ch, int isfunckey) +{ + if (stfl_matchbind(w, ch, isfunckey, L"toggle", L"ENTER SPACE")) { + int value = stfl_widget_getkv_int(w, L"value", 0); + stfl_widget_setkv_int(w, L"value", !value); + return 1; + } + + return 0; +} + +struct stfl_widget_type stfl_widget_type_checkbox = { + L"checkbox", + wt_checkbox_init, + 0, // f_done + 0, // f_enter + 0, // f_leave + wt_checkbox_prepare, + wt_checkbox_draw, + wt_checkbox_process, +}; + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/widgets/wt_input.c new/stfl-0.23/widgets/wt_input.c --- old/stfl-0.21/widgets/wt_input.c 2007-10-13 09:45:09.000000000 +0200 +++ new/stfl-0.23/widgets/wt_input.c 2011-10-24 07:52:06.000000000 +0200 @@ -38,32 +38,21 @@ const wchar_t* text = stfl_widget_getkv_str(w, L"text", L""); int text_len = wcslen(text); int changed = 0; - int pos_width = 0; - int offset_width = 0; - int i; + int width; if (pos > text_len) { pos = text_len; changed = 1; } - if (offset > text_len) { - offset = text_len; - changed = 1; - } - if (offset > pos) { offset = pos; changed = 1; } - for (i=0;i<pos;++i) { - pos_width += wcwidth(text[i]); - } - - while (text[offset] && pos-offset >= w->w && pos_width-offset_width >= w->w && w->w > 0) { - offset_width += wcwidth(text[offset]); - offset++; + width = wcswidth(text + offset, pos - offset); + while (width >= w->w && pos > offset) { + width -= wcwidth(text[offset++]); changed = 1; } @@ -88,27 +77,31 @@ int pos = stfl_widget_getkv_int(w, L"pos", 0); int blind = stfl_widget_getkv_int(w, L"blind", 0); int offset = stfl_widget_getkv_int(w, L"offset", 0); - const wchar_t *text = stfl_widget_getkv_str(w, L"text", L""); - int pos_width = 0, offset_width = 0, i; + const wchar_t * const text_off = stfl_widget_getkv_str(w, L"text", L"") + offset; + int i; stfl_widget_style(w, f, win); for (i=0; i<w->w; i++) mvwaddwstr(win, w->y, w->x+i, L" "); - if (!blind) - mvwaddnwstr(win, w->y, w->x, text+offset, wcswidth(text+offset,w->w)); - - for (i=0;i<pos;++i) { - pos_width += wcwidth(text[i]); - } - for (i=0;i<offset;++i) { - offset_width += wcwidth(text[i]); + if (!blind) { + const int off_len = wcslen(text_off); + int width, len; + + width = wcswidth(text_off, w->w); + if (w->w > off_len) + len = off_len; + else + len = w->w; + while (width > w->w) + width -= wcwidth(text_off[--len]); + mvwaddnwstr(win, w->y, w->x, text_off, len); } if (f->current_focus_id == w->id) { - f->cursor_x = w->x + pos_width - offset_width; - f->cursor_y = w->y; + f->root->cur_x = f->cursor_x = w->x + wcswidth(text_off, pos - offset); + f->root->cur_y = f->cursor_y = w->y; } } @@ -150,8 +143,7 @@ return 0; wchar_t newtext[text_len]; wmemcpy(newtext, text, pos); - wmemcpy(newtext+pos, text+pos+1, text_len-(pos+1)); - newtext[text_len-1] = 0; + wcscpy(newtext + pos, text + pos + 1); stfl_widget_setkv_str(w, L"text", newtext); fix_offset_pos(w); return 1; @@ -163,8 +155,7 @@ return 0; wchar_t newtext[text_len]; wmemcpy(newtext, text, pos-1); - wmemcpy(newtext+pos-1, text+pos, text_len-pos); - newtext[text_len-1] = 0; + wcscpy(newtext + pos - 1, text + pos); stfl_widget_setkv_str(w, L"text", newtext); stfl_widget_setkv_int(w, L"pos", pos-1); fix_offset_pos(w); @@ -176,8 +167,7 @@ wchar_t newtext[text_len + 2]; wmemcpy(newtext, text, pos); newtext[pos] = ch; - wmemcpy(newtext+pos+1, text+pos, text_len - pos); - newtext[text_len + 1] = 0; + wcscpy(newtext + pos + 1, text + pos); stfl_widget_setkv_str(w, L"text", newtext); stfl_widget_setkv_int(w, L"pos", pos+1); fix_offset_pos(w); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/widgets/wt_list.c new/stfl-0.23/widgets/wt_list.c --- old/stfl-0.21/widgets/wt_list.c 2009-03-30 20:33:37.000000000 +0200 +++ new/stfl-0.23/widgets/wt_list.c 2014-09-29 09:04:41.000000000 +0200 @@ -25,10 +25,38 @@ #include <string.h> #include <stdlib.h> +struct stfl_widget *first_focusable_child(struct stfl_widget *w) +{ + int i; + struct stfl_widget *c; + + for (i=0, c=w->first_child; c; i++, c=c->next_sibling) + { + if (stfl_widget_getkv_int(c, L"can_focus", 1) && + stfl_widget_getkv_int(c, L".display", 1)) + return c; + } + return 0; +} + +static int first_focusable_pos(struct stfl_widget *w) +{ + int i; + struct stfl_widget *c; + + for (i=0, c=w->first_child; c; i++, c=c->next_sibling) + { + if (stfl_widget_getkv_int(c, L"can_focus", 1) && + stfl_widget_getkv_int(c, L".display", 1)) + return i; + } + return 0; +} + static void fix_offset_pos(struct stfl_widget *w) { int offset = stfl_widget_getkv_int(w, L"offset", 0); - int pos = stfl_widget_getkv_int(w, L"pos", 0); + int pos = stfl_widget_getkv_int(w, L"pos", first_focusable_pos(w)); int orig_offset = offset; int orig_pos = pos; @@ -40,11 +68,13 @@ while (pos >= offset+w->h) offset++; + int i; int maxpos = -1; - struct stfl_widget *c = w->first_child; - while (c) { - maxpos++; - c = c->next_sibling; + struct stfl_widget *c; + for (i=0, c=w->first_child; c; i++, c=c->next_sibling) { + if (stfl_widget_getkv_int(c, L"can_focus", 1) && + stfl_widget_getkv_int(c, L".display", 1)) + maxpos= i; } if (maxpos >= 0 && pos > maxpos) @@ -57,9 +87,45 @@ stfl_widget_setkv_int(w, L"pos", pos); } +static void stfl_focus_prev_pos(struct stfl_widget *w) +{ + int i; + struct stfl_widget *c; + int pos = stfl_widget_getkv_int(w, L"pos", first_focusable_pos(w)); + + for (i=0, c=w->first_child; c; i++, c=c->next_sibling) + { + if (i >= pos) + break; + if (stfl_widget_getkv_int(c, L"can_focus", 1) && + stfl_widget_getkv_int(c, L".display", 1)) + stfl_widget_setkv_int(w, L"pos", i); + } + fix_offset_pos(w); +} + +static void stfl_focus_next_pos(struct stfl_widget *w) +{ + int i; + struct stfl_widget *c; + int pos = stfl_widget_getkv_int(w, L"pos", first_focusable_pos(w)); + + for (i=0, c=w->first_child; c; i++, c=c->next_sibling) + { + if (i <= pos) + continue; + if (stfl_widget_getkv_int(c, L"can_focus", 1) && + stfl_widget_getkv_int(c, L".display", 1)) { + stfl_widget_setkv_int(w, L"pos", i); + break; + } + } + fix_offset_pos(w); +} + static void wt_list_prepare(struct stfl_widget *w, struct stfl_form *f) { - struct stfl_widget *c = w->first_child; + struct stfl_widget *c = first_focusable_child(w); w->min_w = 1; w->min_h = 5; @@ -81,7 +147,7 @@ fix_offset_pos(w); int offset = stfl_widget_getkv_int(w, L"offset", 0); - int pos = stfl_widget_getkv_int(w, L"pos", 0); + int pos = stfl_widget_getkv_int(w, L"pos", first_focusable_pos(w)); int is_richtext = stfl_widget_getkv_int(w, L"richtext", 0); @@ -143,28 +209,33 @@ } } + + if (f->current_focus_id == w->id) { + f->root->cur_y = f->cursor_y; + f->root->cur_x = f->cursor_x; + } } static int wt_list_process(struct stfl_widget *w, struct stfl_widget *fw, struct stfl_form *f, wchar_t ch, int isfunckey) { - int pos = stfl_widget_getkv_int(w, L"pos", 0); - int maxpos = -1; + int pos = stfl_widget_getkv_int(w, L"pos", first_focusable_pos(w)); - struct stfl_widget *c = w->first_child; - while (c) { - maxpos++; - c = c->next_sibling; + int i; + int maxpos = -1; + struct stfl_widget *c; + for (i=0, c=w->first_child; c; i++, c=c->next_sibling) { + if (stfl_widget_getkv_int(c, L"can_focus", 1) && + stfl_widget_getkv_int(c, L".display", 1)) + maxpos= i; } if (pos > 0 && stfl_matchbind(w, ch, isfunckey, L"up", L"UP")) { - stfl_widget_setkv_int(w, L"pos", pos-1); - fix_offset_pos(w); + stfl_focus_prev_pos(w); return 1; } if (pos < maxpos && stfl_matchbind(w, ch, isfunckey, L"down", L"DOWN")) { - stfl_widget_setkv_int(w, L"pos", pos+1); - fix_offset_pos(w); + stfl_focus_next_pos(w); return 1; } @@ -177,13 +248,13 @@ if (stfl_matchbind(w, ch, isfunckey, L"page_up", L"PPAGE")) { if (pos > w->h) stfl_widget_setkv_int(w, L"pos", pos - w->h); - else stfl_widget_setkv_int(w, L"pos", 0); + else stfl_widget_setkv_int(w, L"pos", first_focusable_pos(w)); fix_offset_pos(w); return 1; } if (stfl_matchbind(w, ch, isfunckey, L"home", L"HOME")) { - stfl_widget_setkv_int(w, L"pos", 0); + stfl_widget_setkv_int(w, L"pos", first_focusable_pos(w)); fix_offset_pos(w); return 1; } @@ -210,7 +281,9 @@ static void wt_listitem_init(struct stfl_widget *w) { - if (w->parent && !wcscmp(w->parent->type->name, L"list")) + if (w->parent && !wcscmp(w->parent->type->name, L"list") && + stfl_widget_getkv_int(w, L"can_focus", 1) && + stfl_widget_getkv_int(w, L".display", 1)) w->parent->allow_focus = 1; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/widgets/wt_textedit.c new/stfl-0.23/widgets/wt_textedit.c --- old/stfl-0.21/widgets/wt_textedit.c 1970-01-01 01:00:00.000000000 +0100 +++ new/stfl-0.23/widgets/wt_textedit.c 2014-03-09 18:04:00.000000000 +0100 @@ -0,0 +1,323 @@ +/* + * STFL - The Structured Terminal Forms Language/Library + * Copyright (C) 2006, 2007, 2014 Clifford Wolf <cliff...@clifford.at> + * Copyright (C) 2006 Andreas Krennmair <a...@synflood.at> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * wt_textedit.c: Widget type 'textedit' + */ + +#include "stfl_internals.h" + +#include <string.h> +#include <stdlib.h> +#include <wctype.h> + +static void wt_textedit_prepare(struct stfl_widget *w, struct stfl_form *f) +{ + struct stfl_widget *c = w->first_child; + + w->min_w = 1; + w->min_h = 5; + + if (c) + w->allow_focus = 1; + + while (c) { + const wchar_t * text = stfl_widget_getkv_str(c, L"text", L""); + int len = wcswidth(text, wcslen(text)); + w->min_w = len > w->min_w ? len : w->min_w; + c = c->next_sibling; + } +} + +static void wt_textedit_draw(struct stfl_widget *w, struct stfl_form *f, WINDOW *win) +{ + int cursor_x = stfl_widget_getkv_int(w, L"cursor_x", 0); + int cursor_y = stfl_widget_getkv_int(w, L"cursor_y", 0); + + int scroll_x = stfl_widget_getkv_int(w, L"scroll_x", 0); + int scroll_y = stfl_widget_getkv_int(w, L"scroll_y", 0); + + if (cursor_x < scroll_x) { + scroll_x = cursor_x; + stfl_widget_setkv_int(w, L"scroll_x", scroll_x); + } + + if (cursor_x >= scroll_x + w->w - 1) { + scroll_x = cursor_x - w->w + 1; + stfl_widget_setkv_int(w, L"scroll_x", scroll_x); + } + + if (cursor_y < scroll_y) { + scroll_y = cursor_y; + stfl_widget_setkv_int(w, L"scroll_y", scroll_y); + } + + if (cursor_y >= scroll_y + w->h - 1) { + scroll_y = cursor_y - w->h + 1; + stfl_widget_setkv_int(w, L"scroll_y", scroll_y); + } + + const wchar_t *style_normal = stfl_widget_getkv_str(w, L"style_normal", L""); + const wchar_t *style_end = stfl_widget_getkv_str(w, L"style_end", L""); + + struct stfl_widget *c; + int clipped_cursor_x = cursor_x; + int i, j; + + stfl_style(win, style_normal); + for (i = 0, c = w->first_child; c && i < scroll_y + w->h; i++, c = c->next_sibling) + { + if (i < scroll_y) + continue; + + const wchar_t *text = stfl_widget_getkv_str(c, L"text", L""); + + if (i == cursor_y) + clipped_cursor_x = wcslen(text) < clipped_cursor_x ? wcslen(text) : clipped_cursor_x; + + for (j = 0; j < scroll_x && *text; j += wcwidth(*(text++))) { } + mvwaddnwstr(win, w->y + i - scroll_y, w->x, text, w->w); + } + + stfl_style(win, style_end); + for (; i < scroll_y + w->h; i++) + mvwaddnwstr(win, w->y + i - scroll_y, w->x, L"~",w->w); + + if (f->current_focus_id == w->id) { + f->root->cur_x = f->cursor_x = w->x + clipped_cursor_x - scroll_x; + f->root->cur_y = f->cursor_y = w->y + cursor_y - scroll_y; + } +} + +static int wt_textedit_process(struct stfl_widget *w, struct stfl_widget *fw, struct stfl_form *f, wchar_t ch, int isfunckey) +{ + int cursor_x = stfl_widget_getkv_int(w, L"cursor_x", 0); + int cursor_y = stfl_widget_getkv_int(w, L"cursor_y", 0); + int num_lines = 0, line_length = 0; + + struct stfl_widget *c_current_line = NULL; + struct stfl_widget *c = w->first_child; + while (c) { + if (num_lines == cursor_y) { + line_length = wcslen(stfl_widget_getkv_str(c, L"text", L"")); + c_current_line = c; + } + c = c->next_sibling; + num_lines++; + } + + if (c_current_line == NULL) { + c_current_line = w->last_child; + cursor_y = num_lines-1 > 0 ? num_lines-1 : 0; + } + + if (c_current_line == NULL) { + c_current_line = stfl_widget_new(L"listitem"); + w->last_child = c_current_line; + w->first_child = c_current_line; + num_lines = 1; + } + + if (cursor_y > 0 && stfl_matchbind(w, ch, isfunckey, L"up", L"UP")) { + stfl_widget_setkv_int(w, L"cursor_y", cursor_y-1); + return 1; + } + + if (cursor_y+1 < num_lines && stfl_matchbind(w, ch, isfunckey, L"down", L"DOWN")) { + stfl_widget_setkv_int(w, L"cursor_y", cursor_y+1); + return 1; + } + + if (stfl_matchbind(w, ch, isfunckey, L"left", L"LEFT")) { + cursor_x = cursor_x-1 < line_length-1 ? cursor_x-1 : line_length-1; + stfl_widget_setkv_int(w, L"cursor_x", cursor_x > 0 ? cursor_x : 0); + return 1; + } + + if (stfl_matchbind(w, ch, isfunckey, L"right", L"RIGHT")) { + cursor_x = cursor_x+1 < line_length ? cursor_x+1 : line_length; + stfl_widget_setkv_int(w, L"cursor_x", cursor_x > 0 ? cursor_x : 0); + return 1; + } + + if (stfl_matchbind(w, ch, isfunckey, L"page_up", L"PPAGE")) { + cursor_y = cursor_y - w->h + 1; + cursor_y = cursor_y > 0 ? cursor_y : 0; + cursor_y = cursor_y < num_lines ? cursor_y : num_lines-1; + stfl_widget_setkv_int(w, L"cursor_y", cursor_y); + return 1; + } + + if (stfl_matchbind(w, ch, isfunckey, L"page_down", L"NPAGE")) { + cursor_y = cursor_y + w->h - 1; + cursor_y = cursor_y > 0 ? cursor_y : 0; + cursor_y = cursor_y < num_lines ? cursor_y : num_lines-1; + stfl_widget_setkv_int(w, L"cursor_y", cursor_y); + return 1; + } + + if (stfl_matchbind(w, ch, isfunckey, L"home", L"HOME ^A")) { + stfl_widget_setkv_int(w, L"cursor_x", 0); + return 1; + } + + if (stfl_matchbind(w, ch, isfunckey, L"end", L"END ^E")) { + stfl_widget_setkv_int(w, L"cursor_x", line_length); + return 1; + } + + if (stfl_matchbind(w, ch, isfunckey, L"delete", L"DC")) + { + if (c_current_line == NULL) + return 0; + + if (cursor_x >= line_length) { + if (c_current_line->next_sibling == NULL) + return 0; + const wchar_t *this_text = stfl_widget_getkv_str(c_current_line, L"text", L""); + const wchar_t *next_text = stfl_widget_getkv_str(c_current_line->next_sibling, L"text", L""); + wchar_t newtext[wcslen(this_text) + wcslen(next_text) + 1]; + wcscpy(newtext, this_text); + wcscat(newtext, next_text); + stfl_widget_setkv_int(w, L"cursor_x", line_length); + stfl_widget_setkv_str(c_current_line, L"text", newtext); + stfl_widget_free(c_current_line->next_sibling); + return 1; + } + + wchar_t newtext[line_length]; + const wchar_t *text = stfl_widget_getkv_str(c_current_line, L"text", L""); + wmemcpy(newtext, text, cursor_x); + wcscpy(newtext + cursor_x, text + cursor_x + 1); + stfl_widget_setkv_str(c_current_line, L"text", newtext); + return 1; + } + + if (stfl_matchbind(w, ch, isfunckey, L"backspace", L"BACKSPACE")) + { + if (c_current_line == NULL) + return 0; + + if (cursor_x > line_length) + cursor_x = line_length; + + if (cursor_x == 0) { + struct stfl_widget *c = w->first_child; + while (c && c->next_sibling != c_current_line) + c = c->next_sibling; + if (c == NULL) + return 0; + const wchar_t *prev_text = stfl_widget_getkv_str(c, L"text", L""); + const wchar_t *this_text = stfl_widget_getkv_str(c_current_line, L"text", L""); + wchar_t newtext[wcslen(prev_text) + wcslen(this_text) + 1]; + wcscpy(newtext, prev_text); + wcscat(newtext, this_text); + stfl_widget_setkv_int(w, L"cursor_x", wcslen(prev_text)); + stfl_widget_setkv_int(w, L"cursor_y", cursor_y - 1); + stfl_widget_setkv_str(c, L"text", newtext); + stfl_widget_free(c_current_line); + return 1; + } + + wchar_t newtext[line_length]; + const wchar_t *text = stfl_widget_getkv_str(c_current_line, L"text", L""); + wmemcpy(newtext, text, cursor_x-1); + wcscpy(newtext + cursor_x - 1, text + cursor_x); + stfl_widget_setkv_str(c_current_line, L"text", newtext); + stfl_widget_setkv_int(w, L"cursor_x", cursor_x - 1); + return 1; + } + + if (stfl_matchbind(w, ch, isfunckey, L"enter", L"ENTER")) + { + if (c_current_line == NULL) { + c_current_line = stfl_widget_new(L"listitem"); + c_current_line->parent = w; + if (w->last_child) + w->last_child->next_sibling = c_current_line; + else + w->first_child = c_current_line; + w->last_child = c_current_line; + return 1; + } + + if (cursor_x > line_length) + cursor_x = line_length; + + c = stfl_widget_new(L"listitem"); + c->parent = w; + c->next_sibling = c_current_line->next_sibling; + c_current_line->next_sibling = c; + + if (w->last_child == c_current_line) + w->last_child = c; + + const wchar_t *text = stfl_widget_getkv_str(c_current_line, L"text", L""); + stfl_widget_setkv_str(c, L"text", text + cursor_x); + + wchar_t newtext[cursor_x+1]; + wmemcpy(newtext, text, cursor_x); + newtext[cursor_x] = 0; + stfl_widget_setkv_str(c_current_line, L"text", newtext); + + stfl_widget_setkv_int(w, L"cursor_x", 0); + stfl_widget_setkv_int(w, L"cursor_y", cursor_y + 1); + return 1; + } + + if (!isfunckey && iswprint(ch)) + { + if (c_current_line == NULL) { + c_current_line = stfl_widget_new(L"listitem"); + c_current_line->parent = w; + if (w->last_child) + w->last_child->next_sibling = c_current_line; + else + w->first_child = c_current_line; + w->last_child = c_current_line; + } + + if (cursor_x > line_length) + cursor_x = line_length; + + wchar_t newtext[line_length + 1]; + const wchar_t *text = stfl_widget_getkv_str(c_current_line, L"text", L""); + wmemcpy(newtext, text, cursor_x); + newtext[cursor_x] = ch; + wcscpy(newtext + cursor_x + 1, text + cursor_x); + + stfl_widget_setkv_int(w, L"cursor_x", cursor_x+1); + stfl_widget_setkv_str(c_current_line, L"text", newtext); + return 1; + } + + return 0; +} + +struct stfl_widget_type stfl_widget_type_textedit = { + L"textedit", + 0, // f_init + 0, // f_done + 0, // f_enter + 0, // f_leave + wt_textedit_prepare, + wt_textedit_draw, + wt_textedit_process, +}; + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/stfl-0.21/widgets/wt_textview.c new/stfl-0.23/widgets/wt_textview.c --- old/stfl-0.21/widgets/wt_textview.c 2009-03-30 21:20:00.000000000 +0200 +++ new/stfl-0.23/widgets/wt_textview.c 2011-10-24 07:52:06.000000000 +0200 @@ -118,7 +118,7 @@ } if (f->current_focus_id == w->id) - f->cursor_x = f->cursor_y = -1; + f->root->cur_x = f->root->cur_y = f->cursor_x = f->cursor_y = -1; } static int wt_textview_process(struct stfl_widget *w, struct stfl_widget *fw, struct stfl_form *f, wchar_t ch, int isfunckey) ++++++ stfl-optflags.patch ++++++ --- /var/tmp/diff_new_pack.KqlIc7/_old 2015-05-15 07:44:42.000000000 +0200 +++ /var/tmp/diff_new_pack.KqlIc7/_new 2015-05-15 07:44:42.000000000 +0200 @@ -1,5 +1,7 @@ ---- Makefile.orig 2010-06-25 00:59:31.000000000 +0200 -+++ Makefile 2010-06-25 01:01:34.000000000 +0200 +Index: Makefile +=================================================================== +--- Makefile.orig ++++ Makefile @@ -20,9 +20,10 @@ include Makefile.cfg @@ -13,4 +15,4 @@ +export LDLIBS += -pthread -lncursesw SONAME := libstfl.so.0 - VERSION := 0.21 + VERSION := 0.23