2
2
* STFL - The Structured Terminal Forms Language/Library
3
* Copyright (C) 2006 Clifford Wolf <clifford@clifford.at>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
3
* Copyright (C) 2006, 2007 Clifford Wolf <clifford@clifford.at>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 3 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
20
* wt_list.c: Widget type 'list'
76
78
static void wt_list_draw(struct stfl_widget *w, struct stfl_form *f, WINDOW *win)
82
int offset = stfl_widget_getkv_int(w, "offset", 0);
83
int pos = stfl_widget_getkv_int(w, "pos", 0);
84
int offset = stfl_widget_getkv_int(w, L"offset", 0);
85
int pos = stfl_widget_getkv_int(w, L"pos", 0);
85
const char *style_focus = stfl_widget_getkv_str(w, "style_focus", "");
86
const char *style_selected = stfl_widget_getkv_str(w, "style_selected", "");
87
const char *style_normal = stfl_widget_getkv_str(w, "style_normal", "");
87
const wchar_t *style_focus = stfl_widget_getkv_str(w, L"style_focus", L"");
88
const wchar_t *style_selected = stfl_widget_getkv_str(w, L"style_selected", L"");
89
const wchar_t *style_normal = stfl_widget_getkv_str(w, L"style_normal", L"");
89
91
struct stfl_widget *c;
94
if (f->current_focus_id == w->id)
95
f->cursor_x = f->cursor_y = -1;
92
97
for (i=0, c=w->first_child; c && i < offset+w->h; i++, c=c->next_sibling)
98
if (f->current_focus_id == w->id)
103
if (f->current_focus_id == w->id) {
99
104
stfl_style(win, style_focus);
105
f->cursor_y = w->y+i-offset;
101
108
stfl_style(win, style_selected);
103
stfl_widget_setkv_str(w, "pos_name", c->name ? c->name : "");
110
stfl_widget_setkv_str(w, L"pos_name", c->name ? c->name : L"");
105
112
stfl_style(win, style_normal);
107
text = stfl_widget_getkv_str(c, "text", "");
114
text = stfl_widget_getkv_str(c, L"text", L"");
109
if (strlen(text) < w->w) {
110
fillup = alloca(w->w - strlen(text) + 1);
111
for (j=0;j < w->w - strlen(text);++j) {
116
if (wcswidth(text,wcslen(text)) < w->w) {
117
fillup = alloca(sizeof(wchar_t)*(w->w - wcswidth(text,wcslen(text)) + 1));
118
for (j=0;j < w->w - wcswidth(text,wcslen(text));++j) {
114
fillup[w->w - strlen(text)] = '\0';
115
mvwaddnstr(win, w->y+i-offset, w->x + strlen(text), fillup, strlen(fillup));
121
fillup[w->w - wcswidth(text,wcslen(text))] = '\0';
122
mvwaddnwstr(win, w->y+i-offset, w->x + wcswidth(text,wcslen(text)), fillup, wcswidth(fillup,wcslen(fillup)));
118
mvwaddnstr(win, w->y+i-offset, w->x, text, w->w);
125
mvwaddnwstr(win, w->y+i-offset, w->x, text, w->w);
121
if (f->current_focus_id == w->id)
122
f->cursor_x = f->cursor_y = -1;
125
static int wt_list_process(struct stfl_widget *w, struct stfl_widget *fw, struct stfl_form *f, int ch)
129
static int wt_list_process(struct stfl_widget *w, struct stfl_widget *fw, struct stfl_form *f, wchar_t ch, int isfunckey)
127
int pos = stfl_widget_getkv_int(w, "pos", 0);
131
int pos = stfl_widget_getkv_int(w, L"pos", 0);
130
134
struct stfl_widget *c = w->first_child;
133
137
c = c->next_sibling;
136
if (ch == KEY_UP && pos > 0) {
137
stfl_widget_setkv_int(w, "pos", pos-1);
140
if (pos > 0 && stfl_matchbind(w, ch, isfunckey, L"up", L"UP")) {
141
stfl_widget_setkv_int(w, L"pos", pos-1);
138
142
fix_offset_pos(w);
142
if (ch == KEY_DOWN && pos < maxpos) {
143
stfl_widget_setkv_int(w, "pos", pos+1);
146
if (pos < maxpos && stfl_matchbind(w, ch, isfunckey, L"down", L"DOWN")) {
147
stfl_widget_setkv_int(w, L"pos", pos+1);
144
148
fix_offset_pos(w);
148
if (ch == KEY_NPAGE) {
149
if (pos < maxpos - w->h) stfl_widget_setkv_int(w, "pos", pos + w->h);
150
else stfl_widget_setkv_int(w, "pos", maxpos);
152
if (stfl_matchbind(w, ch, isfunckey, L"page_down", L"NPAGE")) {
153
if (pos < maxpos - w->h) stfl_widget_setkv_int(w, L"pos", pos + w->h);
154
else stfl_widget_setkv_int(w, L"pos", maxpos);
151
155
fix_offset_pos(w);
155
if (ch == KEY_PPAGE) {
156
if (pos > w->h) stfl_widget_setkv_int(w, "pos", pos - w->h);
157
else stfl_widget_setkv_int(w, "pos", 0);
159
if (stfl_matchbind(w, ch, isfunckey, L"page_up", L"PPAGE")) {
160
if (pos > w->h) stfl_widget_setkv_int(w, L"pos", pos - w->h);
161
else stfl_widget_setkv_int(w, L"pos", 0);
158
162
fix_offset_pos(w);