Back to index

tetex-bin  3.0
lib_bkgd.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998,2001-2002 Free Software Foundation, Inc.              *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /****************************************************************************
00030  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
00031  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
00032  ****************************************************************************/
00033 
00034 #include <curses.priv.h>
00035 
00036 MODULE_ID("$Id: lib_bkgd.c,v 1.30 2003/07/05 16:46:49 tom Exp $")
00037 
00038 /*
00039  * Set the window's background information.
00040  */
00041 #if USE_WIDEC_SUPPORT
00042 NCURSES_EXPORT(void)
00043 #else
00044 static inline void
00045 #endif
00046 wbkgrndset(WINDOW *win, const ARG_CH_T ch)
00047 {
00048     T((T_CALLED("wbkgdset(%p,%s)"), win, _tracech_t(ch)));
00049 
00050     if (win) {
00051        attr_t off = AttrOf(win->_nc_bkgd);
00052        attr_t on = AttrOf(CHDEREF(ch));
00053 
00054        toggle_attr_off(win->_attrs, off);
00055        toggle_attr_on(win->_attrs, on);
00056 
00057        if (CharOf(CHDEREF(ch)) == L('\0'))
00058            SetChar(win->_nc_bkgd, BLANK_TEXT, AttrOf(CHDEREF(ch)));
00059        else
00060            win->_nc_bkgd = CHDEREF(ch);
00061 #if USE_WIDEC_SUPPORT
00062        /*
00063         * If we're compiled for wide-character support, _bkgrnd is the
00064         * preferred location for the background information since it stores
00065         * more than _bkgd.  Update _bkgd each time we modify _bkgrnd, so the
00066         * macro getbkgd() will work.
00067         */
00068        {
00069            cchar_t wch;
00070            int tmp;
00071 
00072            wgetbkgrnd(win, &wch);
00073            tmp = _nc_to_char(CharOf(wch));
00074 
00075            win->_bkgd = ((tmp == EOF) ? ' ' : (chtype) tmp) | AttrOf(wch);
00076        }
00077 #endif
00078     }
00079     returnVoid;
00080 }
00081 
00082 NCURSES_EXPORT(void)
00083 wbkgdset(WINDOW *win, chtype ch)
00084 {
00085     NCURSES_CH_T wch;
00086     SetChar2(wch, ch);
00087     wbkgrndset(win, CHREF(wch));
00088 }
00089 
00090 /*
00091  * Set the window's background information and apply it to each cell.
00092  */
00093 #if USE_WIDEC_SUPPORT
00094 NCURSES_EXPORT(int)
00095 #else
00096 static inline int
00097 #undef wbkgrnd
00098 #endif
00099 wbkgrnd(WINDOW *win, const ARG_CH_T ch)
00100 {
00101     int code = ERR;
00102     int x, y;
00103     NCURSES_CH_T new_bkgd = CHDEREF(ch);
00104 
00105     T((T_CALLED("wbkgd(%p,%s)"), win, _tracech_t(ch)));
00106 
00107     if (win) {
00108        NCURSES_CH_T old_bkgrnd;
00109        wgetbkgrnd(win, &old_bkgrnd);
00110 
00111        wbkgrndset(win, CHREF(new_bkgd));
00112        wattrset(win, AttrOf(win->_nc_bkgd));
00113 
00114        for (y = 0; y <= win->_maxy; y++) {
00115            for (x = 0; x <= win->_maxx; x++) {
00116               if (CharEq(win->_line[y].text[x], old_bkgrnd))
00117                   win->_line[y].text[x] = win->_nc_bkgd;
00118               else {
00119                   NCURSES_CH_T wch = win->_line[y].text[x];
00120                   RemAttr(wch, (~A_ALTCHARSET));
00121                   win->_line[y].text[x] = _nc_render(win, wch);
00122               }
00123            }
00124        }
00125        touchwin(win);
00126        _nc_synchook(win);
00127        code = OK;
00128     }
00129     returnCode(code);
00130 }
00131 
00132 NCURSES_EXPORT(int)
00133 wbkgd(WINDOW *win, chtype ch)
00134 {
00135     NCURSES_CH_T wch;
00136     SetChar2(wch, ch);
00137     return wbkgrnd(win, CHREF(wch));
00138 }