~ubuntu-branches/ubuntu/intrepid/stfl/intrepid

« back to all changes in this revision

Viewing changes to widgets/wt_label.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_label.c: Widget type 'label'
20
21
 */
26
27
 
27
28
static void wt_label_prepare(struct stfl_widget *w, struct stfl_form *f)
28
29
{
29
 
        w->min_w = strlen(stfl_widget_getkv_str(w, "text", ""));
 
30
        const wchar_t * text = stfl_widget_getkv_str(w, L"text", L"");
 
31
        w->min_w = wcswidth(text, wcslen(text));
30
32
        w->min_h = 1;
31
33
}
32
34
 
33
35
static void wt_label_draw(struct stfl_widget *w, struct stfl_form *f, WINDOW *win)
34
36
{
35
 
        const char * text;
36
 
        char * fillup;
 
37
        const wchar_t * text;
 
38
        wchar_t * fillup;
37
39
        unsigned int i;
38
40
 
39
41
 
40
42
        stfl_widget_style(w, f, win);
41
43
 
42
 
        text = stfl_widget_getkv_str(w,"text","");
 
44
        text = stfl_widget_getkv_str(w,L"text",L"");
43
45
 
44
 
        if (strlen(text) < w->w) {
45
 
                fillup = alloca(w->w - strlen(text) + 1);
46
 
                for (i=0;i < w->w - strlen(text);++i) {
47
 
                        fillup[i] = ' ';
 
46
        if (wcswidth(text,wcslen(text)) < w->w) {
 
47
                fillup = alloca(sizeof(wchar_t)*(w->w - wcswidth(text,wcslen(text)) + 1));
 
48
                for (i=0;i < w->w - wcswidth(text,wcslen(text));++i) {
 
49
                        fillup[i] = L' ';
48
50
                }
49
 
                fillup[w->w - strlen(text)] = '\0';
50
 
                mvwaddnstr(win, w->y, w->x + strlen(text), fillup, strlen(fillup));
 
51
                fillup[w->w - wcswidth(text,wcslen(text))] = L'\0';
 
52
                mvwaddnwstr(win, w->y, w->x + wcswidth(text,wcslen(text)), fillup, wcswidth(fillup,wcslen(fillup)));
51
53
        }
52
54
 
53
 
        mvwaddnstr(win, w->y, w->x, text, w->w);
 
55
        mvwaddnwstr(win, w->y, w->x, text, w->w);
54
56
}
55
57
 
56
58
struct stfl_widget_type stfl_widget_type_label = {
57
 
        "label",
 
59
        L"label",
58
60
        0, // f_init
59
61
        0, // f_done
60
62
        0, // f_enter