2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1995, by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * slk.c
2N/A *
2N/A * XCurses Library
2N/A *
2N/A * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
2N/A *
2N/A */
2N/A
2N/A#if M_RCSID
2N/A#ifndef lint
2N/Astatic char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/slk.c 1.1 1995/07/19 16:38:06 ant Exp $";
2N/A#endif
2N/A#endif
2N/A
2N/A#include <private.h>
2N/A
2N/A/*
2N/A * Flag for initialisation soft label keys once setupterm() has been called.
2N/A */
2N/Aint
2N/Aslk_init(int fmt)
2N/A{
2N/A int code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_init(%d)", fmt);
2N/A#endif
2N/A
2N/A if (0 <= fmt && fmt <= 1) {
2N/A __m_slk_format = fmt;
2N/A code = OK;
2N/A }
2N/A
2N/A return __m_return_code("slk_init", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_attron(const chtype at)
2N/A{
2N/A int code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_attron(%lx)", at);
2N/A#endif
2N/A
2N/A if (__m_screen->_slk._w != (WINDOW *) 0)
2N/A code = wattron(__m_screen->_slk._w, at);
2N/A
2N/A return __m_return_code("slk_attron", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_attroff(const chtype at)
2N/A{
2N/A int code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_attroff(%lx)", at);
2N/A#endif
2N/A
2N/A if (__m_screen->_slk._w != (WINDOW *) 0)
2N/A code = wattroff(__m_screen->_slk._w, at);
2N/A
2N/A return __m_return_code("slk_attroff", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_attrset(const chtype at)
2N/A{
2N/A int code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_attrset(%lx)", at);
2N/A#endif
2N/A
2N/A if (__m_screen->_slk._w != (WINDOW *) 0)
2N/A code = wattrset(__m_screen->_slk._w, at);
2N/A
2N/A return __m_return_code("slk_attrset", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_attr_off(const attr_t at, void *opts)
2N/A{
2N/A int code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_attr_off(%x, %p)", at, opts);
2N/A#endif
2N/A
2N/A if (__m_screen->_slk._w != (WINDOW *) 0)
2N/A code = wattr_off(__m_screen->_slk._w, at, opts);
2N/A
2N/A return __m_return_code("slk_attr_off", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_attr_on(const attr_t at, void *opts)
2N/A{
2N/A int code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_attr_on(%x, %p)", at, opts);
2N/A#endif
2N/A
2N/A if (__m_screen->_slk._w != (WINDOW *) 0)
2N/A code = wattr_on(__m_screen->_slk._w, at, opts);
2N/A
2N/A return __m_return_code("slk_attr_on", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_attr_set(const attr_t at, short co, void *opts)
2N/A{
2N/A int code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_attr_set(%x, %d, %p)", at, co, opts);
2N/A#endif
2N/A
2N/A if (__m_screen->_slk._w != (WINDOW *) 0)
2N/A code = wattr_set(__m_screen->_slk._w, at, co, opts);
2N/A
2N/A return __m_return_code("slk_attr_set", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_color(short co)
2N/A{
2N/A int code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_color(%d)", co);
2N/A#endif
2N/A
2N/A if (__m_screen->_slk._w != (WINDOW *) 0)
2N/A code = wcolor_set(__m_screen->_slk._w, co, (void *) 0);
2N/A
2N/A return __m_return_code("slk_color", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_touch()
2N/A{
2N/A int code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_touch(void)");
2N/A#endif
2N/A
2N/A if (__m_screen->_slk._w != (WINDOW *) 0)
2N/A code = wtouchln(__m_screen->_slk._w, 0, 1, 1);
2N/A
2N/A return __m_return_code("slk_touch", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_clear()
2N/A{
2N/A int code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_clear(void)");
2N/A#endif
2N/A
2N/A if (__m_screen->_slk._w != (WINDOW *) 0) {
2N/A if (werase(__m_screen->_slk._w) == OK)
2N/A code = wrefresh(__m_screen->_slk._w);
2N/A } else if (label_off != (char *) 0) {
2N/A (void) tputs(label_off, 1, __m_outc);
2N/A (void) fflush(__m_screen->_of);
2N/A code = OK;
2N/A }
2N/A
2N/A return __m_return_code("slk_clear", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_restore()
2N/A{
2N/A int i, code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_clear(void)");
2N/A#endif
2N/A
2N/A if (__m_screen->_slk._w != (WINDOW *) 0) {
2N/A for (i = 0; i < 8; ++i) {
2N/A if (__m_screen->_slk._labels[i] != (char *) 0) {
2N/A (void) slk_set(
2N/A i, __m_screen->_slk._labels[i],
2N/A __m_screen->_slk._justify[i]
2N/A );
2N/A }
2N/A }
2N/A
2N/A code = slk_refresh();
2N/A } else if (label_on != (char *) 0) {
2N/A (void) tputs(label_on, 1, __m_outc);
2N/A (void) fflush(__m_screen->_of);
2N/A code = OK;
2N/A }
2N/A
2N/A return __m_return_code("slk_clear", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_noutrefresh()
2N/A{
2N/A int code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_noutrefresh(void)");
2N/A#endif
2N/A
2N/A if (__m_screen->_slk._w != (WINDOW *) 0)
2N/A code = wnoutrefresh(__m_screen->_slk._w);
2N/A
2N/A return __m_return_code("slk_noutrefresh", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_refresh()
2N/A{
2N/A int code = ERR;
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_refresh(void)");
2N/A#endif
2N/A
2N/A if ((code = slk_noutrefresh()) == OK)
2N/A code = doupdate();
2N/A
2N/A return __m_return_code("slk_refresh", code);
2N/A}
2N/A
2N/Achar *
2N/Aslk_label(int index)
2N/A{
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_label(%d)", index);
2N/A#endif
2N/A
2N/A return __m_return_pointer("slk_label", __m_screen->_slk._labels[index]);
2N/A}
2N/A
2N/Aint
2N/Aslk_set(int index, const char *label, int justify)
2N/A{
2N/A int code = ERR;
2N/A wchar_t wcs[M_CCHAR_MAX * 8 + 1];
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_set(%d, %p, %d)", index, label, justify);
2N/A#endif
2N/A
2N/A if (0 < mbstowcs(wcs, label, sizeof wcs))
2N/A code = slk_wset(index, wcs, justify);
2N/A
2N/A return __m_return_code("slk_set", code);
2N/A}
2N/A
2N/Aint
2N/Aslk_wset(int index, const wchar_t *label, int justify)
2N/A{
2N/A cchar_t cc;
2N/A short (*k)[2];
2N/A int i, width, code = ERR;
2N/A wchar_t wcs[M_CCHAR_MAX * 8 + 1], *wp;
2N/A char mbs[MB_LEN_MAX * ((1 + M_CCHAR_MAX) * 8) + 1];
2N/A
2N/A /*
2N/A * These label start columns assume 80 columns in order to
2N/A * fit 8 _slk._labels of 8 columns.
2N/A */
2N/A static short format[][8] = {
2N/A { 0, 10, 20, 31, 41, 52, 62, 72 },
2N/A { 0, 10, 20, 30, 42, 52, 62, 72 },
2N/A };
2N/A
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("slk_wset(%d, %p, %d)", index, label, justify);
2N/A#endif
2N/A
2N/A if (index < 1 || 8 < index || justify < 0 || 2 < justify)
2N/A goto error1;
2N/A
2N/A if (label == (wchar_t *) 0)
2N/A label = M_MB_L("");
2N/A
2N/A /* Copy the characters that fill the first 8 columns of the label. */
2N/A for (wp = wcs, width = 0; label != '\0'; label += i, wp += cc._n) {
2N/A if ((i = __m_wcs_cc(label, A_NORMAL, 0, &cc)) < 0)
2N/A goto error1;
2N/A
2N/A
2N/A if (8 < (width += __m_cc_width(&cc)))
2N/A break;
2N/A
2N/A (void) wcsncpy(wp, cc._wc, cc._n);
2N/A }
2N/A *wp = '\0';
2N/A
2N/A if (wcstombs(mbs, wcs, sizeof mbs) == (size_t) -1)
2N/A goto error1;
2N/A
2N/A /* Remember the new label. */
2N/A __m_screen->_slk._justify[index] = (short) justify;
2N/A if (__m_screen->_slk._labels[index] != (char *) 0)
2N/A free(__m_screen->_slk._labels[index]);
2N/A if ((__m_screen->_slk._labels[index] = m_strdup(mbs)) == (char *) 0)
2N/A goto error1;
2N/A
2N/A if (__m_screen->_slk._w != (WINDOW *) 0) {
2N/A /* Write the justified label into the slk window. */
2N/A i = format[__m_slk_format][index];
2N/A (void) __m_cc_erase(__m_screen->_slk._w, 0, i, 0, i + 7);
2N/A
2N/A switch (justify) {
2N/A case 0:
2N/A break;
2N/A case 1:
2N/A i += width / 2;
2N/A break;
2N/A case 2:
2N/A i = i + 8 - width;
2N/A break;
2N/A }
2N/A
2N/A (void) mvwaddstr(__m_screen->_slk._w, 0, i, mbs);
2N/A } else if (plab_norm != (char *) 0) {
2N/A (void) tputs(
2N/A tparm(
2N/A plab_norm, (long) index, (long) mbs,
2N/A 0L, 0L, 0L, 0L, 0L, 0L, 0L
2N/A ), 1, __m_outc
2N/A );
2N/A } else if (pkey_plab != (char *) 0) {
2N/A /* Lookup multibyte sequence for the function key. */
2N/A for (i = KEY_F(index), k = __m_keyindex; (*k)[1] != i; ++k)
2N/A ;
2N/A
2N/A if (cur_term->_str[**k] != (char *) 0) {
2N/A (void) tputs(
2N/A tparm(
2N/A pkey_plab, (long) index,
2N/A (long) cur_term->_str[**k],
2N/A (long) mbs, 0L, 0L, 0L, 0L, 0L, 0L
2N/A ), 1, __m_outc
2N/A );
2N/A }
2N/A }
2N/A
2N/A code = OK;
2N/Aerror1:
2N/A return __m_return_code("slk_wset", code);
2N/A}
2N/A