1 /****************************************************************************
2 * Copyright (c) 2003,2004 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Thomas E. Dickey, 2003 *
31 ****************************************************************************/
35 * Set soft label text.
37 #include <curses.priv.h>
43 MODULE_ID("$Id: lib_slk_wset.c,v 1.6 2004/01/03 21:14:03 tom Exp $")
46 slk_wset(int i, const wchar_t * astr, int format)
48 static wchar_t empty[] =
56 T((T_CALLED("slk_wset(%d, %s, %d)"), i, _nc_viswbuf(astr), format));
60 arglen = wcslen(astr);
61 while (iswspace(*astr)) {
63 ++astr; /* skip over leading spaces */
67 p++; /* The first non-print stops */
69 arglen = (size_t) (p - astr);
82 --i; /* Adjust numbering of labels */
85 * Reduce the actual number of columns to fit in the label field.
87 while (arglen != 0 && wcswidth(astr, arglen) > slk->maxlen) {
90 mycols = wcswidth(astr, arglen);
93 * translate the wide-character string to multibyte form.
95 memset(&state, 0, sizeof(state));
97 if ((new_text = (char *) _nc_doalloc(0, MB_LEN_MAX * arglen)) == 0)
100 for (n = 0; n < arglen; ++n) {
101 used += wcrtomb(new_text + used, astr[n], &state);
103 new_text[used] = '\0';
105 if (used >= (size_t) (slk->maxlen + 1)) {
106 if ((slk->ent[i].ent_text = (char *) _nc_doalloc(slk->ent[i].ent_text,
109 if ((slk->ent[i].form_text = (char *) _nc_doalloc(slk->ent[i].form_text,
114 (void) strcpy(slk->ent[i].ent_text, new_text);
117 sprintf(slk->ent[i].form_text, "%*s", (size_t) slk->maxlen, " ");
121 case 0: /* left-aligned */
124 case 1: /* centered */
125 offset = (slk->maxlen - mycols) / 2;
127 case 2: /* right-aligned */
128 offset = slk->maxlen - mycols;
133 strcpy(slk->ent[i].form_text + offset,
134 slk->ent[i].ent_text);
136 * Pad the display with blanks on the right, unless it is already
139 if (format != 2 && mycols < slk->maxlen) {
140 sprintf(slk->ent[i].form_text + offset + used,
142 slk->maxlen - (mycols - offset),
145 slk->ent[i].dirty = TRUE;