Esempio n. 1
0
/*---------------------------------------------------------------------------
|   Facility      :  libnmenu
|   Function      :  pos_menu_cursor
|
|   Description   :  Position logical cursor to current item in menu
|
|   Return Values :  E_OK            - success
|                    E_BAD_ARGUMENT  - invalid menu
|                    E_NOT_POSTED    - Menu is not posted
+--------------------------------------------------------------------------*/
int pos_menu_cursor(const MENU * menu)
{
  WINDOW *win, *sub;
  int x, y;
  int err = _nc_menu_cursor_pos(menu,(ITEM*)0,&y,&x);

  if (E_OK==err)
    {
      win = menu->userwin ? menu->userwin : stdscr;
      sub = menu->usersub ? menu->usersub : win;
      assert(win && sub);

      if ((menu->opt & O_SHOWMATCH) && (menu->pindex > 0))
	x += ( menu->pindex + menu->marklen - 1);

      wmove(sub,y,x);

      if ( win != sub )
	{
	  wcursyncup(sub);
	  wsyncup(sub);
	  untouchwin(sub);
	}
    }
  RETURN(err);
}
Esempio n. 2
0
mvderwin(WINDOW *win, int y, int x)
/* move a derived window */
{
    WINDOW *orig;
    int i;

    T((T_CALLED("mvderwin(%p,%d,%d)"), win, y, x));

    if (win && (orig = win->_parent)) {
	if (win->_parx == x && win->_pary == y)
	    returnCode(OK);
	if (x < 0 || y < 0)
	    returnCode(ERR);
	if ((x + getmaxx(win) > getmaxx(orig)) ||
	    (y + getmaxy(win) > getmaxy(orig)))
	    returnCode(ERR);
    } else
	returnCode(ERR);
    wsyncup(win);
    win->_parx = x;
    win->_pary = y;
    for (i = 0; i < getmaxy(win); i++)
	win->_line[i].text = &(orig->_line[y++].text[x]);
    returnCode(OK);
}
Esempio n. 3
0
unpost_menu(MENU * menu)
{
  WINDOW *win;

  T((T_CALLED("unpost_menu(%p)"), (void *)menu));

  if (!menu)
    RETURN(E_BAD_ARGUMENT);

  if (menu->status & _IN_DRIVER)
    RETURN(E_BAD_STATE);

  if (!(menu->status & _POSTED))
    RETURN(E_NOT_POSTED);

  Call_Hook(menu, itemterm);
  Call_Hook(menu, menuterm);

  win = Get_Menu_Window(menu);
  werase(win);
  wsyncup(win);

  assert(menu->sub);
  delwin(menu->sub);
  menu->sub = (WINDOW *)0;

  assert(menu->win);
  delwin(menu->win);
  menu->win = (WINDOW *)0;

  menu->status &= ~_POSTED;

  RETURN(E_OK);
}
Esempio n. 4
0
pos_menu_cursor(const MENU * menu)
{
  WINDOW *win, *sub;
  int x = 0, y = 0;
  int err = _nc_menu_cursor_pos(menu, (ITEM *) 0, &y, &x);

  T((T_CALLED("pos_menu_cursor(%p)"), (const void *)menu));

  if (E_OK == err)
    {
      win = Get_Menu_UserWin(menu);
      sub = menu->usersub ? menu->usersub : win;
      assert(win && sub);

      if ((menu->opt & O_SHOWMATCH) && (menu->pindex > 0))
	x += (menu->pindex + menu->marklen - 1);

      wmove(sub, y, x);

      if (win != sub)
	{
	  wcursyncup(sub);
	  wsyncup(sub);
	  untouchwin(sub);
	}
    }
  RETURN(err);
}
Esempio n. 5
0
int
wdelch(WINDOW *win)
{
	chtype	*temp1, *temp2;
	chtype	*end;
	int	cury = win->_cury;
	short	curx = win->_curx;
	chtype	*cp;
	int	s;

	end = &win->_y[cury][win->_maxx - 1];
	temp2 = &win->_y[cury][curx + 1];
	temp1 = temp2 - 1;

	s = 1;
	win->_nbyte = -1;
	if (_scrmax > 1) {
		if (ISMBIT(*temp1)) {
			win->_insmode = TRUE;
			if (_mbvalid(win) == ERR)
				return (ERR);
			curx = win->_curx;
			temp1 = &win->_y[cury][curx];
		}
		if (ISMBIT(*end)) {
			for (cp = end; cp >= temp1; --cp)
				if (!ISCBIT(*cp))
					break;
			if (cp + _curs_scrwidth[TYPE(*cp)] > end+1)
				end = cp - 1;
		}
		if (ISMBIT(*temp1))
			s = _curs_scrwidth[TYPE(RBYTE(*temp1))];
		end -= s - 1;
		temp2 = &win->_y[cury][curx+s];
	}

	while (temp1 < end)
		*temp1++ = *temp2++;

	while (s--)
		*temp1++ = win->_bkgd;

#ifdef	_VR3_COMPAT_CODE
	if (_y16update)
		(*_y16update)(win, 1, win->_maxx - curx, cury, curx);
#endif	/* _VR3_COMPAT_CODE */

	win->_lastch[cury] = win->_maxx - 1;
	if (win->_firstch[cury] > curx)
		win->_firstch[cury] = curx;

	win->_flags |= _WINCHANGED;

	if (win->_sync)
		wsyncup(win);

	return (win->_immed ? wrefresh(win) : OK);
}
Esempio n. 6
0
_nc_synchook(WINDOW *win)
/* hook to be called after each window change */
{
    if (win->_immed)
	wrefresh(win);
    if (win->_sync)
	wsyncup(win);
}
Esempio n. 7
0
void PDC_sync(WINDOW *win)
{
    PDC_LOG(("PDC_sync() - called:\n"));

    if (win->_immed)
        wrefresh(win);
    if (win->_sync)
        wsyncup(win);
}
Esempio n. 8
0
void cCursesOsd::DrawRectangle(int x1, int y1, int x2, int y2, tColor Color)
{
  SetColor(Color, Color);
  for (int y = y1; y <= y2; y++) {
      wmove(window, y, x1); // ncurses wants 'y' before 'x'!
      whline(window, ' ', x2 - x1 + 1);
      }
  wsyncup(window); // shouldn't be necessary because of 'syncok()', but w/o it doesn't work
}
Esempio n. 9
0
/*
 * Add ncols worth of data to win, using string as input.
 * Return the number of chtypes copied.
 */
int
waddchnstr(WINDOW *win, chtype *string, int ncols)
{
	short		my_x = win->_curx;
	short		my_y = win->_cury;
	int		remcols;
	int		b;
	int		sw;
	int		ew;

	if (ncols < 0) {
		remcols = win->_maxx - my_x;
		while (*string && remcols) {
			sw = mbscrw((int)(_CHAR(*string)));
			ew = mbeucw((int)(_CHAR(*string)));
			if (remcols < sw)
				break;
			for (b = 0; b < ew; b++) {
				if (waddch(win, *string++) == ERR)
					goto out;
			}
			remcols -= sw;
		}
	} else {
		remcols = win->_maxx - my_x;
		while ((*string) && (remcols > 0) && (ncols > 0)) {
			sw = mbscrw((int)(_CHAR(*string)));
			ew = mbeucw((int)(_CHAR(*string)));
			if ((remcols < sw) || (ncols < ew))
				break;
			for (b = 0; b < ew; b++) {
				if (waddch(win, *string++) == ERR)
					goto out;
			}
			remcols -= sw;
			ncols -= ew;
		}
	}
out:
	/* restore cursor position */
	win->_curx = my_x;
	win->_cury = my_y;

	win->_flags |= _WINCHANGED;

	/* sync with ancestor structures */
	if (win->_sync)
		wsyncup(win);

	return (win->_immed ? wrefresh(win) : OK);
}
Esempio n. 10
0
void hexedit_set_cursor(struct hexedit *buf)
{
	wmove(buf->win, max_rows(buf->win), 0);
	wattron(buf->win, A_REVERSE | A_STANDOUT);
	wclrtoeol(buf->win);
	if (buf->cursor_offset < buf->len) {
		wprintw(buf->win, "Len:%lu Off:%lu Val:0x%X", buf->len,
			buf->cursor_offset, buf->data[buf->cursor_offset]);
	} else {
		wprintw(buf->win, "Len:%lu Off:%lu", buf->len,
			buf->cursor_offset);
	}
	wattroff(buf->win, A_REVERSE | A_STANDOUT);
	wmove(buf->win, buf->cursor_y, buf->cursor_x);
	wcursyncup(buf->win);
	wsyncup(buf->win);
	untouchwin(buf->win);
}
Esempio n. 11
0
/* Scroll the given window up/down n lines. */
int
wscrl(WINDOW *win, int n)
{
	short	curx, cury;
	bool	 savimmed, savsync;

#ifdef	DEBUG
	if (outf)
		if (win == stdscr)
			fprintf(outf, "scroll(stdscr, %d)\n", n);
		else
			if (win == curscr)
				fprintf(outf, "scroll(curscr, %d)\n", n);
			else
				fprintf(outf, "scroll(%x, %d)\n", win, n);
#endif	/* DEBUG */
	if (!win->_scroll || (win->_flags & _ISPAD))
		return (ERR);

	savimmed = win->_immed;
	savsync = win->_sync;
	win->_immed = win->_sync = FALSE;

	curx = win->_curx; cury = win->_cury;

	if (cury >= win->_tmarg && cury <= win->_bmarg)
		win->_cury = win->_tmarg;
	else
		win->_cury = 0;

	(void) winsdelln(win, -n);
	win->_curx = curx;
	win->_cury = cury;

	win->_sync = savsync;

	if (win->_sync)
		wsyncup(win);

	return ((win->_immed = savimmed) ? wrefresh(win) : OK);
}
Esempio n. 12
0
mvderwin(WINDOW *win, int y, int x)
/* move a derived window */
{
    WINDOW *orig;
    int i;
    int rc = ERR;

    T((T_CALLED("mvderwin(%p,%d,%d)"), (void *) win, y, x));

    if (win != 0
	&& (orig = win->_parent) != 0
	&& (x >= 0 && y >= 0)
	&& (x + getmaxx(win) <= getmaxx(orig))
	&& (y + getmaxy(win) <= getmaxy(orig))) {
	wsyncup(win);
	win->_parx = x;
	win->_pary = y;
	for (i = 0; i < getmaxy(win); i++)
	    win->_line[i].text = &(orig->_line[y++].text[x]);
	rc = OK;
    }
    returnCode(rc);
}
Esempio n. 13
0
/*
 * Add ncols worth of data to win, using string as input.
 * Return the number of chtypes copied.
 * Note: chtype contains 32/16 bit process code.
 */
int
waddwchnstr(WINDOW *win, chtype *string, int ncols)
{
	int		my_x = win->_curx;
	int		my_y = win->_cury;
	short		my_maxx;
	int		counter;
	chtype		*ptr = &(win->_y[my_y][my_x]);
	chtype		*sptr = ptr;
	char		mbbuf[CSMAX+1];
	int		mp, s, scrw;
	chtype		rawc;
	chtype		attr;
	short		my_x1 = win->_curx;


	while (ISCBIT(*ptr)) {
		ptr--;
		my_x1--;
	}
	while (ptr < sptr)
		*ptr++ = win->_bkgd;

	if (ncols == -1)
		ncols = MAXINT;

	counter = win->_maxx - my_x;
	while ((ncols > 0) && (*string) && (counter > 0)) {
		attr = *string & A_WATTRIBUTES;
		rawc = *string & A_WCHARTEXT;

		/* conver wchar_t to mbuti byte string */
		for (mp = 0; mp < sizeof (mbbuf); mp++)
			mbbuf[mp] = '\0';
		if (_curs_wctomb(mbbuf, rawc) <= 0)
			goto out;

		/* if there are no cols on screen, end */
		if ((scrw = wcscrw(rawc)) > counter)
			goto out;

		if (rawc & WCHAR_CSMASK) {
			/* store multi-byte string into chtype */
			for (s = 0, mp = 0; s < scrw; s++, mp += 2) {
				*ptr = _CHAR(RBYTE(mbbuf[mp]) |
				    RBYTE(mbbuf[mp + 1]) << 8) | CBIT;
				SETMBIT(*ptr);
				if (mp > 0)
					SETCBIT(*ptr);
				else
					CLRCBIT(*ptr);
				*ptr |= attr;
				ptr++;
			}
		} else {
		/* store single-byte string into chtype */
			*ptr = mbbuf[0];
			*ptr |= attr;
			ptr++;
		}

		ncols--;
		string++;
		counter -= scrw;
	}
out :

	while (ISCBIT(*ptr))
		*ptr++ = win->_bkgd;

	/* LINTED */
	my_maxx = (short) (ptr - sptr + my_x);

	if (my_x1 < win->_firstch[my_y])
		win->_firstch[my_y] = my_x1;

	if (my_maxx > win->_lastch[my_y])
		win->_lastch[my_y] = my_maxx;

	win->_flags |= _WINCHANGED;

	/* sync with ancestor structures */
	if (win->_sync)
		wsyncup(win);

	return (win->_immed ? wrefresh(win) : OK);
}
Esempio n. 14
0
void c_ecurses_wsyncup (EIF_POINTER w)
{
    wsyncup ((WINDOW *) w)  ;
};
Esempio n. 15
0
mvwin(WINDOW *win, int by, int bx)
{
    T((T_CALLED("mvwin(%p,%d,%d)"), win, by, bx));

    if (!win || (win->_flags & _ISPAD))
	returnCode(ERR);

    /*
     * mvwin() should only modify the indices.  See test/demo_menus.c and
     * test/movewindow.c for examples.
     */
#if 0
    /* Copying subwindows is allowed, but it is expensive... */
    if (win->_flags & _SUBWIN) {
	int err = ERR;
	WINDOW *parent = win->_parent;
	if (parent) {		/* Now comes the complicated and costly part, you should really
				 * try to avoid to move subwindows. Because a subwindow shares
				 * the text buffers with its parent, one can't do a simple
				 * memmove of the text buffers. One has to create a copy, then
				 * to relocate the subwindow and then to do a copy.
				 */
	    if ((by - parent->_begy == win->_pary) &&
		(bx - parent->_begx == win->_parx))
		err = OK;	/* we don't actually move */
	    else {
		WINDOW *clone = dupwin(win);
		if (clone) {
		    /* now we have the clone, so relocate win */

		    werase(win);	/* Erase the original place     */
		    /* fill with parents background */
		    wbkgrnd(win, CHREF(parent->_nc_bkgd));
		    wsyncup(win);	/* Tell the parent(s)           */

		    err = mvderwin(win,
				   by - parent->_begy,
				   bx - parent->_begx);
		    if (err != ERR) {
			err = copywin(clone, win,
				      0, 0, 0, 0, win->_maxy, win->_maxx, 0);
			if (ERR != err)
			    wsyncup(win);
		    }
		    if (ERR == delwin(clone))
			err = ERR;
		}
	    }
	}
	returnCode(err);
    }
#endif

    if (by + win->_maxy > screen_lines - 1
	|| bx + win->_maxx > screen_columns - 1
	|| by < 0
	|| bx < 0)
	returnCode(ERR);

    /*
     * Whether or not the window is moved, touch the window's contents so
     * that a following call to 'wrefresh()' will paint the window at the
     * new location.  This ensures that if the caller has refreshed another
     * window at the same location, that this one will be displayed.
     */
    win->_begy = by;
    win->_begx = bx;
    returnCode(touchwin(win));
}
Esempio n. 16
0
static int sirf_command(char line[])
{
    unsigned char buf[BUFSIZ];
    int v;

    switch (line[0]) {
    case 'A':			/* toggle 50bps subframe data */
	(void)memset(buf, '\0', sizeof(buf));
	putbyte(buf, 0, 0x80);
	putbyte(buf, 23, 0x0c);
	putbyte(buf, 24, subframe_enabled ? 0x00 : 0x10);
	(void)monitor_control_send(buf, 25);
	/*
	 * The subframe_enabled off because we're counting on receipt of
	 * a subframe packet to turn it on if the command succeeds.
	 */
	subframe_enabled = false;
	return COMMAND_MATCH;

    case 'M':			/* static navigation */
	putbyte(buf, 0, 0x8f);	/* id */
	putbyte(buf, 1, atoi(line + 1));
	(void)monitor_control_send(buf, 2);
	return COMMAND_MATCH;

    case 'D':			/* MID 4 rate change (undocumented) */
	v = atoi(line + 1);
	if (v > 30)
	    return COMMAND_MATCH;
	putbyte(buf, 0, 0xa6);
	putbyte(buf, 1, 0);
	putbyte(buf, 2, 4);	/* satellite picture */
	putbyte(buf, 3, v);
	putbyte(buf, 4, 0);
	putbyte(buf, 5, 0);
	putbyte(buf, 6, 0);
	putbyte(buf, 7, 0);
	(void)monitor_control_send(buf, 8);
	return COMMAND_MATCH;

    case 'P':			/* poll navigation params */
	dispmode = !dispmode;
	if (dispmode) {
	    (void)syncok(mid6win, false);
	    (void)syncok(mid7win, false);
	    (void)syncok(mid9win, false);
	    (void)syncok(mid13win, false);
	    (void)syncok(mid27win, false);
	} else {
	    (void)syncok(mid6win, true);
	    (void)wsyncup(mid6win);
	    (void)syncok(mid7win, true);
	    (void)wsyncup(mid7win);
	    (void)syncok(mid9win, true);
	    (void)wsyncup(mid9win);
	    (void)syncok(mid13win, true);
	    (void)wsyncup(mid13win);
	    (void)syncok(mid27win, true);
	    (void)wsyncup(mid27win);
	}
	return COMMAND_MATCH;
    }

    return COMMAND_UNKNOWN;	/* no match */
}
Esempio n. 17
0
int
wbkgd(WINDOW *win, chtype nbkgd)
{
	short	maxx;
	int	x, y;
	chtype	*wcp, obkgda, obkgdc, nbkgda,
		nbkgdc, acolor, c;
	short	*begch, *endch;

	/* if 'nbkgd' contains color information, but this is not a color   */
	/* terminal, erase that information.				*/

	if ((nbkgd & A_COLOR) && (cur_term->_pairs_tbl == NULL))
		nbkgd &= ~A_COLOR;

	if (nbkgd == win->_bkgd)
		return (OK);

	obkgdc = _CHAR(win->_bkgd);
	obkgda = _ATTR(win->_bkgd);

	nbkgdc = _CHAR(nbkgd);
	nbkgda = _ATTR(nbkgd);

	/* switch byte order if necessary */
	if (ISCBIT(nbkgdc))
		nbkgdc = _CHAR((RBYTE(nbkgdc) << 8) | (LBYTE(nbkgdc)|MBIT)) |
		    CBIT;
	c = RBYTE(nbkgdc);
	if ((nbkgdc < ' ' || nbkgdc == _CTRL('?')) ||
	    _curs_scrwidth[TYPE(c)] > 1)
		nbkgdc = obkgdc;
	nbkgd = (nbkgdc & ~CBIT) | nbkgda;

	win->_bkgd = nbkgd;

	/* delete the old background from the attribute field and replace    */
	/* it with the new background.  Note: if the same attribute was	*/
	/* first set by wbkgd() and then by wattron(), or vice versa, it */
	/* will be deleted, so the effect of wattron() will be lost.	 */
	/* This applies to both video and color attributes.		 */

	if ((acolor = (win->_attrs & A_COLOR)) != 0) {
		if (acolor == (obkgda & A_COLOR)) {
			win->_attrs = _ATTR((win->_attrs & ~obkgda) | nbkgda);
		} else {
			win->_attrs = _ATTR((win->_attrs &
			    (~obkgda | A_COLOR)) | (nbkgda & ~A_COLOR));
		}
	} else
		win->_attrs = _ATTR((win->_attrs & ~obkgda) | nbkgda);

	maxx = win->_maxx - 1;
	begch = win->_firstch;
	endch = win->_lastch;
	for (y = win->_maxy-1; y >= 0; --y, ++begch, ++endch) {
		for (x = maxx, wcp = win->_y[y]; x-- >= 0; ++wcp) {
			if ((c = _CHAR(*wcp)) == obkgdc)
				c = nbkgdc;
			if ((acolor = (*wcp & A_COLOR)) != 0) {
				if (acolor == (obkgda & A_COLOR))
					*wcp = c | _ATTR((*wcp & ~obkgda) |
					    nbkgda);
				else
					*wcp = c | _ATTR((*wcp & (~obkgda |
					    A_COLOR)) | (nbkgda & ~A_COLOR));
			} else
				*wcp = c | _ATTR((*wcp & ~obkgda) | nbkgda);
		}
		*begch = 0;
		*endch = maxx;
	}

	win->_flags |= _WINCHANGED;
	if (win->_sync)
		wsyncup(win);

	return (win->_immed ? wrefresh(win) : OK);
}
Esempio n. 18
0
int
waddch(WINDOW *win, chtype c)
{
	short	x = win->_curx;
	short	y = win->_cury;
	chtype	rawc = _CHAR(c);
	chtype	rawattrs = _ATTR(c);
	int	rv = OK;
	bool	savimmed = win->_immed;
	bool	savsync = win->_sync;

	win->_immed = win->_sync = FALSE;

#ifdef	DEBUG
	if (outf)
		if (c == rawc)
			fprintf(outf, "'%c'", rawc);
		else
			fprintf(outf, "'%c' %o, raw %o", c, c, rawc);
#endif	/* DEBUG */

	win->_insmode = FALSE;
	if (_scrmax > 1 && _mbvalid(win) == ERR)
		goto next;
	if (_mbtrue && ISMBIT(rawc)) {
		rv = _mbaddch(win, rawattrs, RBYTE(rawc));
		win->_immed = savimmed;
		win->_sync = savsync;
		goto nextw;
	}

	switch (rawc) {
		case '\n':
			(void) wclrtoeol(win);
			goto new_line;
		case '\r':
			goto move_to_begin_line;
		case '\b':
			if (--x < 0)
move_to_begin_line:
				x = 0;
			win->_curx = x;
			win->_flags |= _WINMOVED;
			goto out_move_only;
		default:
			if (rawc < ' ' || rawc == _CTRL('?')) {
				if (rawc == '\t') {
					int	newx;
					chtype	space = ' ' | rawattrs;

					if ((newx = x + (TABSIZE -
					    (x % TABSIZE))) > win->_maxx)
						newx = win->_maxx;
						for (; x < newx; x++)
							if (waddch(win,
							    space) == ERR)
								goto next;
				} else {
					if ((waddch(win, (chtype)
					    '^'|rawattrs) == ERR) ||
					    (waddch(win, (chtype)
					    _UNCTRL(rawc)|rawattrs) == ERR)) {
next :
						rv = ERR;
				}
			}
			x = win->_curx;
			y = win->_cury;
			win->_immed = savimmed;
			win->_sync = savsync;
			break;
		}
#ifdef	DEBUG
		if ((win->_attrs) && outf)
			fprintf(outf, "(attrs %o, %o=>%o)", win->_attrs,
			    c, c | win->_attrs);
#endif	/* DEBUG */

		/* clear any partial multi-column character */
		if (_scrmax > 1 && ISMBIT(win->_y[y][x]) &&
		    (rv = _mbclrch(win, y, x)) == ERR) {
			x = win->_curx;
			y = win->_cury;
			win->_immed = savimmed;
			win->_sync = savsync;
			break;
		}

		if ((c = _WCHAR(win, c)|rawattrs) != win->_y[y][x]) {
			if (x < win->_firstch[y])
				win->_firstch[y] = x;
			if (x > win->_lastch[y])
				win->_lastch[y] = x;
			win->_y[y][x] = c;
#ifdef	_VR3_COMPAT_CODE
			if (_y16update)
				/* LINTED */
				win->_y16[y][x] = _TO_OCHTYPE(c);
#endif	/* _VR3_COMPAT_CODE */
		}
		if (++x == win->_maxx) {
new_line:
			if (y == win->_bmarg) {
				if (wscrl(win, 1) == ERR) {
					rv = ERR;
					if (x == win->_maxx)
						--x;
#ifdef	DEBUG
					if (outf) {
						int	i;

						fprintf(outf, "ERR because "
						    "(%d, %d) > (%d, %d)\n",
						    x, y, win->_maxx,
						    win->_maxy);
						fprintf(outf, "line: '");
						for (i = 0; i < win->_maxy;
						    i++)
							fprintf(outf, "%c",
							    win->_y[y-1][i]);
						fprintf(outf, "'\n");
					}
#endif	/* DEBUG */
					break;
				} else
					savimmed = 1;
			} else
				y++;
				x = 0;
		} else
			savimmed += 2;
#ifdef	FULLDEBUG
		if (outf)
			fprintf(outf, "ADDCH: 2: y = %d, x = %d, "
			    "firstch = %d, lastch = %d\n", y, x,
			    win->_firstch[y], win->_lastch[y]);
#endif	/* FULLDEBUG */
		break;
	}
	win->_cury = y;
	win->_curx = x;

nextw:
	/* sync with ancestor structures */
	if (win->_sync)
		wsyncup(win);

	if (savimmed == 3)
		return ((*_quick_ptr)(win, c));

	win->_flags |= _WINCHANGED;

out_move_only:

	return ((savimmed == 1) ? wrefresh(win) : rv);
}
Esempio n. 19
0
int
copywin(WINDOW *Srcwin, WINDOW *Dstwin,
	int minRowSrc, int minColSrc, int minRowDst,
	int minColDst, int maxRowDst, int maxColDst,
	int over_lay)
{
	int		ySrc, yDst, which_copy, t;
	int		height = (maxRowDst - minRowDst) + 1,
			width = (maxColDst - minColDst) + 1;
	chtype		**_yDst = Dstwin->_y, **_ySrc = Srcwin->_y,
			bkSrc = Srcwin->_bkgd, atDst = Dstwin->_attrs,
			*spSrc, *spDst, *epSrc, *epDst, *savepS,
			*savepD, width_bytes, numcopied;

#ifdef	DEBUG
	if (outf)
		fprintf(outf, "copywin(%0.2o, %0.2o);\n", Srcwin, Dstwin);
#endif	/* DEBUG */

	/*
	 * If we are going to be copying from curscr,
	 * first offset into curscr the offset the Dstwin knows about.
	 */
	if (Srcwin == curscr)
		minRowSrc += Dstwin->_yoffset;

	/*
	 * There are three types of copy.
	 * 0 - Straight memcpy allowed
	 * 1 - We have to first check to see if the source character is a blank
	 * 2 - Dstwin has attributes or bkgd that must changed
	 * on a char-by-char basis.
	 */
	if ((which_copy = (over_lay) ? 1 :
	    (2 * ((Dstwin->_attrs != A_NORMAL) ||
	    (Dstwin->_bkgd != _BLNKCHAR)))) == 0)
		width_bytes = width * (int)sizeof (chtype);

	/* for each Row */
	for (ySrc = minRowSrc, yDst = minRowDst; height-- > 0; ySrc++, yDst++) {
		if (which_copy) {
			spSrc = &_ySrc[ySrc][minColSrc];
			spDst = &_yDst[yDst][minColDst];
			numcopied = width;

			epSrc = savepS = &_ySrc[ySrc][maxColDst];
			epDst = savepD = &_yDst[yDst][maxColDst];
		/* only copy into an area bounded by whole characters */
			for (; spDst <= epDst; spSrc++, spDst++)
				if (!ISCBIT(*spDst))
					break;
			if (spDst > epDst)
				continue;
			for (; epDst >= spDst; --epDst, --epSrc)
				if (!ISCBIT(*epDst))
					break;
			t = _curs_scrwidth[TYPE(RBYTE(*epDst))] - 1;
			if (epDst+t <= savepD)
				epDst += t, epSrc += t;
			else
				epDst -= 1, epSrc -= 1;
			if (epDst < spDst)
				continue;
			/* don't copy partial characters */
			for (; spSrc <= epSrc; ++spSrc, ++spDst)
				if (!ISCBIT(*spSrc))
					break;
			if (spSrc > epSrc)
				continue;
			for (; epSrc >= spSrc; --epSrc, --epDst)
				if (!ISCBIT(*epSrc))
					break;
			t = _curs_scrwidth[TYPE(RBYTE(*epSrc))] - 1;
			if (epSrc+t <= savepS)
				epSrc += t, epDst += t;
			else
				epSrc -= 1, epDst -= 1;
			if (epSrc < spSrc)
				continue;
		/* make sure that the copied-to place is clean */
			if (ISCBIT(*spDst))
				(void) _mbclrch(Dstwin, minRowDst,
				    /*LINTED*/
				    (intptr_t)(spDst - *_yDst[yDst]));
			if (ISCBIT(*epDst))
				(void) _mbclrch(Dstwin, minRowDst,
				    /*LINTED*/
				    (intptr_t)(epDst - *_yDst[yDst]));
			/*LINTED*/
			numcopied = (chtype) (epDst - spDst + 1);

			if (which_copy == 1) {		/* overlay */
				for (; numcopied-- > 0; spSrc++, spDst++)
			/* Check to see if the char is a "blank/bkgd". */
					if (*spSrc != bkSrc)
						*spDst = *spSrc | atDst;
			} else {
				for (; numcopied-- > 0; spSrc++, spDst++)
					*spDst = *spSrc | atDst;
			}
		} else {
			/* ... copy all chtypes */
			(void) memcpy((char *)&_yDst[yDst][minColDst],
			    (char *)&_ySrc[ySrc][minColSrc], width_bytes);
		}

		/* note that the line has changed */
		if (minColDst < Dstwin->_firstch[yDst])
			/*LINTED*/
			Dstwin->_firstch[yDst] = (short)minColDst;
		if (maxColDst > Dstwin->_lastch[yDst])
			/*LINTED*/
			Dstwin->_lastch[yDst] = (short)maxColDst;
	}

#ifdef	_VR3_COMPAT_CODE
	if (_y16update) {
		(*_y16update)(Dstwin, (maxRowDst - minRowDst) + 1,
		    (maxColDst - minColDst) + 1, minRowDst, minColDst);
	}
#endif	/* _VR3_COMPAT_CODE */

	/* note that something in Dstwin has changed */
	Dstwin->_flags |= _WINCHANGED;

	if (Dstwin->_sync)
		wsyncup(Dstwin);

	return (Dstwin->_immed ? wrefresh(Dstwin) : OK);
}
Esempio n. 20
0
//------------------------------------------------------------------------------
int waddch( WINDOW* win, const chtype ch )
{
	__QCS_FCONTEXT( "waddch" );

    int x, y;
    chtype text, attr;
    bool xlat;

    PDC_LOG(("waddch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
             win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES));

    if( !win )
	{
        return ERR;
	}

    x = win->_curx;
    y = win->_cury;

    if( y > win->_maxy || x > win->_maxx || y < 0 || x < 0 )
	{
        return ERR;
	}

    xlat = !SP->raw_out && !(ch & A_ALTCHARSET);
    text = ch & A_CHARTEXT;
    attr = ch & A_ATTRIBUTES;

    if( xlat && ( text < ' ' || text == 0x7f ) )
    {
        int x2;

        switch( text )
        {
        case '\t':
            for( x2 = ( ( x / TABSIZE ) + 1 ) * TABSIZE; x < x2; x++ )
            {
                if( waddch( win, attr | ' ' ) == ERR )
				{
                    return ERR;
				}

                // if tab to next line, exit the loop

                if( !win->_curx )
				{
                    break;
				}
            }
            return 0;

        case '\n':
            // if lf -> crlf

            if( !SP->raw_out )
			{
                x = 0;
			}

            wclrtoeol( win );

            if( ++y > win->_bmarg )
            {
                y--;

                if( wscrl( win, 1 ) == ERR )
				{
                    return ERR;
				}
            }

            break;

        case '\b':
            // don't back over left margin

            if( --x < 0 )
        case '\r':
			{
                x = 0;
			}
            break;

        case 0x7f:

            if( waddch( win, attr | '^' ) == ERR )
			{
                return ERR;
			}

            return waddch( win, attr | '?' );

        default:
            // handle control chars

            if( waddch( win, attr | '^' ) == ERR )
			{
                return ERR;
			}

            return waddch( win, ch + '@' );
        }
    }
    else
    {
        /* If the incoming character doesn't have its own attribute,
           then use the current attributes for the window. If it has
           attributes but not a color component, OR the attributes to
           the current attributes for the window. If it has a color
           component, use the attributes solely from the incoming
           character. */

        if( !( attr & A_COLOR ) )
		{
            attr |= win->_attrs;
		}

        /* wrs (4/10/93): Apply the same sort of logic for the window 
           background, in that it only takes precedence if other color 
           attributes are not there and that the background character 
           will only print if the printing character is blank. */

        if( !( attr & A_COLOR ) )
		{
            attr |= win->_bkgd & A_ATTRIBUTES;
		}
        else
		{
            attr |= win->_bkgd & ( A_ATTRIBUTES ^ A_COLOR );
		}

        if( text == ' ' )
		{
            text = win->_bkgd & A_CHARTEXT;
		}

        // Add the attribute back into the character.

        text |= attr;

        /* Only change _firstch/_lastch if the character to be added is
           different from the character/attribute that is already in
           that position in the window. */

        if( win->_y[ y ][ x ] != text )
        {
            if( win->_firstch[ y ] == _NO_CHANGE )
			{
                win->_firstch[ y ] = win->_lastch[ y ] = x;
			}
            else
			{
                if( x < win->_firstch[ y ] )
				{
                    win->_firstch[ y ] = x;
				}
                else
				{
                    if( x > win->_lastch[ y ] )
					{
                        win->_lastch[ y ] = x;
					}
				}
			}

            win->_y[ y ][ x ] = text;
        }

        if( ++x >= win->_maxx )
        {
            // wrap around test

            x = 0;

            if( ++y > win->_bmarg )
            {
                y--;

                if( wscrl( win, 1 ) == ERR )
                {
                    PDC_sync( win );
                    return ERR;
                }
            }
        }
    }

    win->_curx = x;
    win->_cury = y;

    if( win->_immed )
	{
        wrefresh( win );
	}

    if( win->_sync )
	{
        wsyncup( win );
	}

    return 0;
}