~ubuntu-branches/ubuntu/lucid/stfl/lucid

« back to all changes in this revision

Viewing changes to widgets/wt_list.c

  • Committer: Bazaar Package Importer
  • Author(s): Nico Golde
  • Date: 2007-08-07 13:06:54 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070807130654-fmvsraotulj0nbri
Tags: 0.15-3
Again added fPIC to CFLAGS. Hopefully all build issues
are fixed now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  STFL - The Structured Terminal Forms Language/Library
3
 
 *  Copyright (C) 2006  Clifford Wolf <clifford@clifford.at>
4
 
 *
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.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
 
3
 *  Copyright (C) 2006, 2007  Clifford Wolf <clifford@clifford.at>
 
4
 *
 
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.
 
9
 *  
 
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.
14
 
 *
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.
 
14
 *  
 
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,
 
18
 *  MA 02110-1301 USA
18
19
 *
19
20
 *  wt_list.c: Widget type 'list'
20
21
 */
26
27
 
27
28
static void fix_offset_pos(struct stfl_widget *w)
28
29
{
29
 
        int offset = stfl_widget_getkv_int(w, "offset", 0);
30
 
        int pos = stfl_widget_getkv_int(w, "pos", 0);
 
30
        int offset = stfl_widget_getkv_int(w, L"offset", 0);
 
31
        int pos = stfl_widget_getkv_int(w, L"pos", 0);
31
32
 
32
33
        int orig_offset = offset;
33
34
        int orig_pos = pos;
50
51
                pos = maxpos;
51
52
 
52
53
        if (offset != orig_offset)
53
 
                stfl_widget_setkv_int(w, "offset", offset);
 
54
                stfl_widget_setkv_int(w, L"offset", offset);
54
55
 
55
56
        if (pos != orig_pos)
56
 
                stfl_widget_setkv_int(w, "pos", pos);
 
57
                stfl_widget_setkv_int(w, L"pos", pos);
57
58
}
58
59
 
59
60
static void wt_list_prepare(struct stfl_widget *w, struct stfl_form *f)
67
68
                w->allow_focus = 1;
68
69
 
69
70
        while (c) {
70
 
                int len = strlen(stfl_widget_getkv_str(c, "text", ""));
 
71
                const wchar_t * text = stfl_widget_getkv_str(c, L"text", L"");
 
72
                int len = wcswidth(text,wcslen(text));
71
73
                w->min_w = len > w->min_w ? len : w->min_w;
72
74
                c = c->next_sibling;
73
75
        }
75
77
 
76
78
static void wt_list_draw(struct stfl_widget *w, struct stfl_form *f, WINDOW *win)
77
79
{
78
 
        const char * text;
79
 
        char * fillup;
 
80
        const wchar_t * text;
 
81
        wchar_t * fillup;
80
82
        fix_offset_pos(w);
81
83
 
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);
84
86
 
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"");
88
90
 
89
91
        struct stfl_widget *c;
90
92
        int i, j;
91
93
 
 
94
        if (f->current_focus_id == w->id)
 
95
                f->cursor_x = f->cursor_y = -1;
 
96
 
92
97
        for (i=0, c=w->first_child; c && i < offset+w->h; i++, c=c->next_sibling)
93
98
        {
94
99
                if (i < offset)
95
100
                        continue;
96
101
 
97
102
                if (i == pos) {
98
 
                        if (f->current_focus_id == w->id)
 
103
                        if (f->current_focus_id == w->id) {
99
104
                                stfl_style(win, style_focus);
100
 
                        else
 
105
                                f->cursor_y = w->y+i-offset;
 
106
                                f->cursor_x = w->x;
 
107
                        } else
101
108
                                stfl_style(win, style_selected);
102
109
 
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""); 
104
111
                } else
105
112
                        stfl_style(win, style_normal);
106
113
 
107
 
                text = stfl_widget_getkv_str(c, "text", "");
 
114
                text = stfl_widget_getkv_str(c, L"text", L"");
108
115
                
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) {
112
119
                                fillup[j] = ' ';
113
120
                        }
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)));
116
123
                }
117
124
 
118
 
                mvwaddnstr(win, w->y+i-offset, w->x, text, w->w);
 
125
                mvwaddnwstr(win, w->y+i-offset, w->x, text, w->w);
119
126
        }
120
 
 
121
 
        if (f->current_focus_id == w->id)
122
 
                f->cursor_x = f->cursor_y = -1;
123
127
}
124
128
 
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)
126
130
{
127
 
        int pos = stfl_widget_getkv_int(w, "pos", 0);
 
131
        int pos = stfl_widget_getkv_int(w, L"pos", 0);
128
132
        int maxpos = -1;
129
133
 
130
134
        struct stfl_widget *c = w->first_child;
133
137
                c = c->next_sibling;
134
138
        }
135
139
 
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);
139
143
                return 1;
140
144
        }
141
145
                
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);
145
149
                return 1;
146
150
        }
147
151
        
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);
152
156
                return 1;
153
157
        }
154
158
 
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);
159
163
                return 1;
160
164
        }
163
167
}
164
168
 
165
169
struct stfl_widget_type stfl_widget_type_list = {
166
 
        "list",
 
170
        L"list",
167
171
        0, // f_init
168
172
        0, // f_done
169
173
        0, // f_enter 
175
179
 
176
180
static void wt_listitem_init(struct stfl_widget *w)
177
181
{
178
 
        if (w->parent && !strcmp(w->parent->type->name, "list"))
 
182
        if (w->parent && !wcscmp(w->parent->type->name, L"list"))
179
183
                w->parent->allow_focus = 1;
180
184
}
181
185
 
182
186
static void wt_listitem_done(struct stfl_widget *w)
183
187
{
184
 
        if (w->parent && !strcmp(w->parent->type->name, "list") &&
 
188
        if (w->parent && !wcscmp(w->parent->type->name, L"list") &&
185
189
            w->parent->first_child == w && w->parent->last_child == w)
186
190
                w->parent->allow_focus = 0;
187
191
}
190
194
static void wt_listitem_draw(struct stfl_widget *w, struct stfl_form *f, WINDOW *win) { }
191
195
 
192
196
struct stfl_widget_type stfl_widget_type_listitem = {
193
 
        "listitem",
 
197
        L"listitem",
194
198
        wt_listitem_init,
195
199
        wt_listitem_done,
196
200
        0, // f_enter