Beispiel #1
0
WINDOW *newpad(int nlines, int ncols)
{
    WINDOW *win;

    PDC_LOG(("newpad() - called: lines=%d cols=%d\n", nlines, ncols));

    if ( !(win = PDC_makenew(nlines, ncols, -1, -1))
        || !(win = PDC_makelines(win)) )
        return (WINDOW *)NULL;

    werase(win);

    win->_flags = _PAD;

    /* save default values in case pechochar() is the first call to 
       prefresh(). */

    save_pminrow = 0;
    save_pmincol = 0;
    save_sminrow = 0;
    save_smincol = 0;
    save_smaxrow = min(LINES, nlines) - 1;
    save_smaxcol = min(COLS, ncols) - 1;

    return win;
}
Beispiel #2
0
WINDOW *dupwin(WINDOW *win)
{
    WINDOW *new_;
    chtype *ptr, *ptr1;
    int nlines, ncols, begy, begx, i;

    if (!win)
        return (WINDOW *)NULL;

    nlines = win->_maxy;
    ncols = win->_maxx;
    begy = win->_begy;
    begx = win->_begx;

    if ( !(new_ = PDC_makenew(nlines, ncols, begy, begx))
        || !(new_ = PDC_makelines(new_)) )
        return (WINDOW *)NULL;

    /* copy the contents of win into new_ */

    for (i = 0; i < nlines; i++)
    {
        for (ptr = new_->_y[i], ptr1 = win->_y[i];
             ptr < new_->_y[i] + ncols; ptr++, ptr1++)
            *ptr = *ptr1;

        new_->_firstch[i] = 0;
        new_->_lastch[i] = ncols - 1;
    }

    new_->_curx = win->_curx;
    new_->_cury = win->_cury;
    new_->_maxy = win->_maxy;
    new_->_maxx = win->_maxx;
    new_->_begy = win->_begy;
    new_->_begx = win->_begx;
    new_->_flags = win->_flags;
    new_->_attrs = win->_attrs;
    new_->_clear = win->_clear;
    new_->_leaveit = win->_leaveit;
    new_->_scroll = win->_scroll;
    new_->_nodelay = win->_nodelay;
    new_->_delayms = win->_delayms;
    new_->_use_keypad = win->_use_keypad;
    new_->_tmarg = win->_tmarg;
    new_->_bmarg = win->_bmarg;
    new_->_parx = win->_parx;
    new_->_pary = win->_pary;
    new_->_parent = win->_parent;
    new_->_bkgd = win->_bkgd;
    new_->_flags = win->_flags;

    return new_;
}
Beispiel #3
0
WINDOW *newwin(int nlines, int ncols, int begy, int begx)
{
    WINDOW *win;

    PDC_LOG(("newwin() - called:lines=%d cols=%d begy=%d begx=%d\n",
             nlines, ncols, begy, begx));

    if (!nlines)
        nlines = LINES - begy;
    if (!ncols)
        ncols  = COLS  - begx;

    if ( (begy + nlines > SP->lines || begx + ncols > SP->cols)
        || !(win = PDC_makenew(nlines, ncols, begy, begx))
        || !(win = PDC_makelines(win)) )
        return (WINDOW *)NULL;

    werase(win);

    return win;
}
Beispiel #4
0
WINDOW *getwin(FILE *filep)
{
	WINDOW *win;
	char marker[4];
	int i, nlines, ncols;

        PDC_LOG(("getwin() - called\n"));

	if ((win = malloc(sizeof(WINDOW))) == (WINDOW *)NULL)
		return (WINDOW *)NULL;

	/* check for the marker, and load the WINDOW struct */

	if (!filep || !fread(marker, 4, 1, filep) ||
	    strncmp(marker, "PDC", 3) || marker[3] != DUMPVER ||
	    !fread(win, sizeof(WINDOW), 1, filep))
	{
		free(win);
		return (WINDOW *)NULL;
	}

	nlines = win->_maxy;
	ncols = win->_maxx;

	/* allocate the line pointer array */
        	
	if ((win->_y = malloc(nlines * sizeof(chtype *))) == NULL)
	{
		free(win);
		return (WINDOW *)NULL;
	}

	/* allocate the minchng and maxchng arrays */

	if ((win->_firstch = malloc(nlines * sizeof(int))) == NULL)
	{
		free(win->_y);
		free(win);
		return (WINDOW *)NULL;
	}

	if ((win->_lastch = malloc(nlines * sizeof(int))) == NULL)
	{
		free(win->_firstch);
		free(win->_y);
		free(win);
		return (WINDOW *)NULL;
	}

	/* allocate the lines */

	if ((win = PDC_makelines(win)) == (WINDOW *)NULL)
		return (WINDOW *)NULL;

	/* read them */

	for (i = 0; i < nlines; i++)
	{
		if (!fread(win->_y[i], ncols * sizeof(chtype), 1, filep))
		{
			delwin(win);
			return (WINDOW *)NULL;
		}
	}

	touchwin(win);

	return win;
}
Beispiel #5
0
WINDOW *resize_window(WINDOW *win, int nlines, int ncols)
{
    WINDOW *new_;
    int i, save_cury, save_curx, new_begy, new_begx;

    PDC_LOG(("resize_window() - called: nlines %d ncols %d\n",
             nlines, ncols));

    if (!win)
        return (WINDOW *)NULL;

    if (win->_flags & _SUBPAD)
    {
        if ( !(new_ = subpad(win->_parent, nlines, ncols,
                            win->_begy, win->_begx)) )
            return (WINDOW *)NULL;
    }
    else if (win->_flags & _SUBWIN)
    {
        if ( !(new_ = subwin(win->_parent, nlines, ncols,
                            win->_begy, win->_begx)) )
            return (WINDOW *)NULL;
    }
    else
    {
        if (win == SP->slk_winptr)
        {
            new_begy = SP->lines - SP->slklines;
            new_begx = 0;
        }
        else
        {
            new_begy = win->_begy;
            new_begx = win->_begx;
        }

        if ( !(new_ = PDC_makenew(nlines, ncols, new_begy, new_begx)) )
            return (WINDOW *)NULL;
    }

    save_curx = min(win->_curx, (new_->_maxx - 1));
    save_cury = min(win->_cury, (new_->_maxy - 1));

    if (!(win->_flags & (_SUBPAD|_SUBWIN)))
    {
        if ( !(new_ = PDC_makelines(new_)) )
            return (WINDOW *)NULL;

        werase(new_);

        copywin(win, new_, 0, 0, 0, 0, min(win->_maxy, new_->_maxy) - 1,
                min(win->_maxx, new_->_maxx) - 1, FALSE);

        for (i = 0; i < win->_maxy && win->_y[i]; i++)
            if (win->_y[i])
                free(win->_y[i]);
    }

    new_->_flags = win->_flags;
    new_->_attrs = win->_attrs;
    new_->_clear = win->_clear;
    new_->_leaveit = win->_leaveit;
    new_->_scroll = win->_scroll;
    new_->_nodelay = win->_nodelay;
    new_->_delayms = win->_delayms;
    new_->_use_keypad = win->_use_keypad;
    new_->_tmarg = (win->_tmarg > new_->_maxy - 1) ? 0 : win->_tmarg;
    new_->_bmarg = (win->_bmarg == win->_maxy - 1) ?
                  new_->_maxy - 1 : min(win->_bmarg, (new_->_maxy - 1));
    new_->_parent = win->_parent;
    new_->_immed = win->_immed;
    new_->_sync = win->_sync;
    new_->_bkgd = win->_bkgd;

    new_->_curx = save_curx;
    new_->_cury = save_cury;

    free(win->_firstch);
    free(win->_lastch);
    free(win->_y);

    *win = *new_;
    free(new_);

    return win;
}