10e3d5408SPeter Wemm /****************************************************************************
24a1a9510SRong-En Fan  * Copyright 2020 Thomas E. Dickey                                          *
30e3d5408SPeter Wemm  * Copyright 1998-2014,2017 Free Software Foundation, Inc.                  *
40e3d5408SPeter Wemm  *                                                                          *
50e3d5408SPeter Wemm  * Permission is hereby granted, free of charge, to any person obtaining a  *
60e3d5408SPeter Wemm  * copy of this software and associated documentation files (the            *
70e3d5408SPeter Wemm  * "Software"), to deal in the Software without restriction, including      *
80e3d5408SPeter Wemm  * without limitation the rights to use, copy, modify, merge, publish,      *
90e3d5408SPeter Wemm  * distribute, distribute with modifications, sublicense, and/or sell       *
100e3d5408SPeter Wemm  * copies of the Software, and to permit persons to whom the Software is    *
110e3d5408SPeter Wemm  * furnished to do so, subject to the following conditions:                 *
120e3d5408SPeter Wemm  *                                                                          *
130e3d5408SPeter Wemm  * The above copyright notice and this permission notice shall be included  *
140e3d5408SPeter Wemm  * in all copies or substantial portions of the Software.                   *
150e3d5408SPeter Wemm  *                                                                          *
160e3d5408SPeter Wemm  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
170e3d5408SPeter Wemm  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
180e3d5408SPeter Wemm  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
190e3d5408SPeter Wemm  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
200e3d5408SPeter Wemm  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
210e3d5408SPeter Wemm  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
220e3d5408SPeter Wemm  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
230e3d5408SPeter Wemm  *                                                                          *
240e3d5408SPeter Wemm  * Except as contained in this notice, the name(s) of the above copyright   *
250e3d5408SPeter Wemm  * holders shall not be used in advertising or otherwise to promote the     *
260e3d5408SPeter Wemm  * sale, use or other dealings in this Software without prior written       *
270e3d5408SPeter Wemm  * authorization.                                                           *
280e3d5408SPeter Wemm  ****************************************************************************/
290e3d5408SPeter Wemm 
304a1a9510SRong-En Fan /****************************************************************************
314a1a9510SRong-En Fan  *  Author: Juergen Pfeifer,  1998                                          *
320e3d5408SPeter Wemm  *     and: Thomas E. Dickey, 2005-on                                       *
330e3d5408SPeter Wemm  ****************************************************************************/
340e3d5408SPeter Wemm 
350e3d5408SPeter Wemm /*
360e3d5408SPeter Wemm **	lib_colorset.c
370e3d5408SPeter Wemm **
380e3d5408SPeter Wemm **	The routine wcolor_set().
390e3d5408SPeter Wemm **
400e3d5408SPeter Wemm */
410e3d5408SPeter Wemm 
420e3d5408SPeter Wemm #include <curses.priv.h>
430e3d5408SPeter Wemm #include <ctype.h>
444a1a9510SRong-En Fan 
450e3d5408SPeter Wemm MODULE_ID("$Id: lib_colorset.c,v 1.16 2020/02/02 23:34:34 tom Exp $")
467a69bbfbSPeter Wemm 
NCURSES_EXPORT(int)474a1a9510SRong-En Fan NCURSES_EXPORT(int)
480e3d5408SPeter Wemm wcolor_set(WINDOW *win, NCURSES_PAIRS_T pair_arg, void *opts)
490e3d5408SPeter Wemm {
5018259542SPeter Wemm     int code = ERR;
5118259542SPeter Wemm     int color_pair = pair_arg;
5218259542SPeter Wemm 
5318259542SPeter Wemm     T((T_CALLED("wcolor_set(%p,%d)"), (void *) win, color_pair));
544a1a9510SRong-En Fan     set_extended_pair(opts, color_pair);
554a1a9510SRong-En Fan     if (win
564a1a9510SRong-En Fan 	&& (SP != 0)
570e3d5408SPeter Wemm 	&& (color_pair >= 0)
580e3d5408SPeter Wemm 	&& (color_pair < SP->_pair_limit)) {
590e3d5408SPeter Wemm 	TR(TRACE_ATTRS, ("... current %ld", (long) GET_WINDOW_PAIR(win)));
600e3d5408SPeter Wemm 	SET_WINDOW_PAIR(win, color_pair);
61 	if_EXT_COLORS(win->_color = color_pair);
62 	code = OK;
63     }
64     returnCode(code);
65 }
66