1*0c3ae37fSLionel Sambuc /* $NetBSD: chgat.c,v 1.5 2012/09/28 06:05:19 blymn Exp $ */
251ffecc1SBen Gras
351ffecc1SBen Gras /*
451ffecc1SBen Gras * Copyright (c) 2009 The NetBSD Foundation, Inc.
551ffecc1SBen Gras * All rights reserved.
651ffecc1SBen Gras *
751ffecc1SBen Gras * This code is derived from software contributed to The NetBSD Foundation
851ffecc1SBen Gras * by Joerg Sonnenberger.
951ffecc1SBen Gras *
1051ffecc1SBen Gras * Redistribution and use in source and binary forms, with or without
1151ffecc1SBen Gras * modification, are permitted provided that the following conditions
1251ffecc1SBen Gras * are met:
1351ffecc1SBen Gras * 1. Redistributions of source code must retain the above copyright
1451ffecc1SBen Gras * notice, this list of conditions and the following disclaimer.
1551ffecc1SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
1651ffecc1SBen Gras * notice, this list of conditions and the following disclaimer in the
1751ffecc1SBen Gras * documentation and/or other materials provided with the distribution.
1851ffecc1SBen Gras *
1951ffecc1SBen Gras * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2051ffecc1SBen Gras * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2151ffecc1SBen Gras * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2251ffecc1SBen Gras * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2351ffecc1SBen Gras * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2451ffecc1SBen Gras * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2551ffecc1SBen Gras * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2651ffecc1SBen Gras * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2751ffecc1SBen Gras * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2851ffecc1SBen Gras * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2951ffecc1SBen Gras * POSSIBILITY OF SUCH DAMAGE.
3051ffecc1SBen Gras */
3151ffecc1SBen Gras
3251ffecc1SBen Gras #include <sys/cdefs.h>
33*0c3ae37fSLionel Sambuc __RCSID("$NetBSD: chgat.c,v 1.5 2012/09/28 06:05:19 blymn Exp $");
3451ffecc1SBen Gras
3551ffecc1SBen Gras #include "curses.h"
3651ffecc1SBen Gras #include "curses_private.h"
3751ffecc1SBen Gras
3851ffecc1SBen Gras int
chgat(int n,attr_t attr,short color,const void * opts)3951ffecc1SBen Gras chgat(int n, attr_t attr, short color, const void *opts)
4051ffecc1SBen Gras {
4151ffecc1SBen Gras return wchgat(stdscr, n, attr, color, opts);
4251ffecc1SBen Gras }
4351ffecc1SBen Gras
4451ffecc1SBen Gras int
mvchgat(int y,int x,int n,attr_t attr,short color,const void * opts)4551ffecc1SBen Gras mvchgat(int y, int x, int n, attr_t attr, short color,
4651ffecc1SBen Gras const void *opts)
4751ffecc1SBen Gras {
4851ffecc1SBen Gras return mvwchgat(stdscr, y, x, n, attr, color, opts);
4951ffecc1SBen Gras }
5051ffecc1SBen Gras
5151ffecc1SBen Gras int
wchgat(WINDOW * win,int n,attr_t attr,short color,const void * opts)5251ffecc1SBen Gras wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts)
5351ffecc1SBen Gras {
5451ffecc1SBen Gras return mvwchgat(win, win->cury, win->curx, n, attr, color, opts);
5551ffecc1SBen Gras }
5651ffecc1SBen Gras
5751ffecc1SBen Gras int
mvwchgat(WINDOW * win,int y,int x,int count,attr_t attr,short color,const void * opts)5851ffecc1SBen Gras mvwchgat(WINDOW *win , int y, int x, int count, attr_t attr, short color,
5951ffecc1SBen Gras const void *opts)
6051ffecc1SBen Gras {
6151ffecc1SBen Gras __LINE *lp;
6251ffecc1SBen Gras __LDATA *lc;
6351ffecc1SBen Gras
6451ffecc1SBen Gras if (x < 0 || y < 0)
6551ffecc1SBen Gras return (ERR);
6651ffecc1SBen Gras if (x >= win->maxx || y >= win->maxy)
6751ffecc1SBen Gras return (ERR);
6851ffecc1SBen Gras
6951ffecc1SBen Gras attr = (attr & ~__COLOR) | COLOR_PAIR(color);
7051ffecc1SBen Gras
7151ffecc1SBen Gras if (count < 0 || count > win->maxx - x)
7251ffecc1SBen Gras count = win->maxx - x;
7351ffecc1SBen Gras
74*0c3ae37fSLionel Sambuc #ifdef DEBUG
75*0c3ae37fSLionel Sambuc __CTRACE(__CTRACE_ATTR, "mvwchgat: x: %d y: %d count: %d attr: 0x%x "
76*0c3ae37fSLionel Sambuc "color pair %d\n", x, y, count, (attr & ~__COLOR),
77*0c3ae37fSLionel Sambuc PAIR_NUMBER(color));
78*0c3ae37fSLionel Sambuc #endif
7951ffecc1SBen Gras lp = win->alines[y];
8051ffecc1SBen Gras lc = &lp->line[x];
8151ffecc1SBen Gras
8251ffecc1SBen Gras if (x + win->ch_off < *lp->firstchp)
8351ffecc1SBen Gras *lp->firstchp = x + win->ch_off;
8451ffecc1SBen Gras if (x + win->ch_off + count > *lp->lastchp)
8551ffecc1SBen Gras *lp->lastchp = x + win->ch_off + count;
8651ffecc1SBen Gras
8751ffecc1SBen Gras while (count-- > 0) {
8851ffecc1SBen Gras lp->flags |= __ISDIRTY;
8951ffecc1SBen Gras #ifdef HAVE_WCHAR
9051ffecc1SBen Gras lc->attr = (lc->attr & ~WA_ATTRIBUTES) | attr;
9151ffecc1SBen Gras #else
9251ffecc1SBen Gras lc->attr = attr;
9351ffecc1SBen Gras #endif
9451ffecc1SBen Gras ++lc;
9551ffecc1SBen Gras }
9651ffecc1SBen Gras
9751ffecc1SBen Gras return OK;
9851ffecc1SBen Gras }
99