Back to index

tetex-bin  3.0
lib_window.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 /*
00035 **     lib_window.c
00036 **
00037 **
00038 */
00039 
00040 #include <curses.priv.h>
00041 
00042 MODULE_ID("$Id: lib_window.c,v 1.21 2002/09/14 23:28:02 tom Exp $")
00043 
00044 NCURSES_EXPORT(void)
00045 _nc_synchook(WINDOW *win)
00046 /* hook to be called after each window change */
00047 {
00048     if (win->_immed)
00049        wrefresh(win);
00050     if (win->_sync)
00051        wsyncup(win);
00052 }
00053 
00054 NCURSES_EXPORT(int)
00055 mvderwin(WINDOW *win, int y, int x)
00056 /* move a derived window */
00057 {
00058     WINDOW *orig;
00059     int i;
00060 
00061     T((T_CALLED("mvderwin(%p,%d,%d)"), win, y, x));
00062 
00063     if (win && (orig = win->_parent)) {
00064        if (win->_parx == x && win->_pary == y)
00065            returnCode(OK);
00066        if (x < 0 || y < 0)
00067            returnCode(ERR);
00068        if ((x + getmaxx(win) > getmaxx(orig)) ||
00069            (y + getmaxy(win) > getmaxy(orig)))
00070            returnCode(ERR);
00071     } else
00072        returnCode(ERR);
00073     wsyncup(win);
00074     win->_parx = x;
00075     win->_pary = y;
00076     for (i = 0; i < getmaxy(win); i++)
00077        win->_line[i].text = &(orig->_line[y++].text[x]);
00078     returnCode(OK);
00079 }
00080 
00081 NCURSES_EXPORT(int)
00082 syncok(WINDOW *win, bool bf)
00083 /* enable/disable automatic wsyncup() on each change to window */
00084 {
00085     T((T_CALLED("syncok(%p,%d)"), win, bf));
00086 
00087     if (win) {
00088        win->_sync = bf;
00089        returnCode(OK);
00090     } else
00091        returnCode(ERR);
00092 }
00093 
00094 NCURSES_EXPORT(void)
00095 wsyncup(WINDOW *win)
00096 /* mark changed every cell in win's ancestors that is changed in win */
00097 /* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...)      */
00098 {
00099     WINDOW *wp;
00100 
00101     T((T_CALLED("wsyncup(%p)"), win));
00102     if (win && win->_parent) {
00103        for (wp = win; wp->_parent; wp = wp->_parent) {
00104            int y;
00105            WINDOW *pp = wp->_parent;
00106 
00107            assert((wp->_pary <= pp->_maxy) &&
00108                  ((wp->_pary + wp->_maxy) <= pp->_maxy));
00109 
00110            for (y = 0; y <= wp->_maxy; y++) {
00111               int left = wp->_line[y].firstchar;
00112               if (left >= 0) {     /* line is touched */
00113                   struct ldat *line = &(pp->_line[wp->_pary + y]);
00114                   /* left & right character in parent window coordinates */
00115                   int right = wp->_line[y].lastchar + wp->_parx;
00116                   left += wp->_parx;
00117 
00118                   CHANGED_RANGE(line, left, right);
00119               }
00120            }
00121        }
00122     }
00123     returnVoid;
00124 }
00125 
00126 NCURSES_EXPORT(void)
00127 wsyncdown(WINDOW *win)
00128 /* mark changed every cell in win that is changed in any of its ancestors */
00129 /* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...)           */
00130 {
00131     T((T_CALLED("wsyncdown(%p)"), win));
00132 
00133     if (win && win->_parent) {
00134        WINDOW *pp = win->_parent;
00135        int y;
00136 
00137        /* This recursion guarantees, that the changes are propagated down-
00138           wards from the root to our direct parent. */
00139        wsyncdown(pp);
00140 
00141        /* and now we only have to propagate the changes from our direct
00142           parent, if there are any. */
00143        assert((win->_pary <= pp->_maxy) &&
00144               ((win->_pary + win->_maxy) <= pp->_maxy));
00145 
00146        for (y = 0; y <= win->_maxy; y++) {
00147            if (pp->_line[win->_pary + y].firstchar >= 0) {     /* parent changed */
00148               struct ldat *line = &(win->_line[y]);
00149               /* left and right character in child coordinates */
00150               int left = pp->_line[win->_pary + y].firstchar - win->_parx;
00151               int right = pp->_line[win->_pary + y].lastchar - win->_parx;
00152               /* The change maybe outside the childs range */
00153               if (left < 0)
00154                   left = 0;
00155               if (right > win->_maxx)
00156                   right = win->_maxx;
00157               CHANGED_RANGE(line, left, right);
00158            }
00159        }
00160     }
00161     returnVoid;
00162 }
00163 
00164 NCURSES_EXPORT(void)
00165 wcursyncup(WINDOW *win)
00166 /* sync the cursor in all derived windows to its value in the base window */
00167 {
00168     WINDOW *wp;
00169 
00170     T((T_CALLED("wcursyncup(%p)"), win));
00171     for (wp = win; wp && wp->_parent; wp = wp->_parent) {
00172        wmove(wp->_parent, wp->_pary + wp->_cury, wp->_parx + wp->_curx);
00173     }
00174     returnVoid;
00175 }
00176 
00177 NCURSES_EXPORT(WINDOW *)
00178 dupwin(WINDOW *win)
00179 /* make an exact duplicate of the given window */
00180 {
00181     WINDOW *nwin = 0;
00182     size_t linesize;
00183     int i;
00184 
00185     T((T_CALLED("dupwin(%p)"), win));
00186 
00187     if (win != 0) {
00188 
00189        if (win->_flags & _ISPAD) {
00190            nwin = newpad(win->_maxy + 1,
00191                        win->_maxx + 1);
00192        } else {
00193            nwin = newwin(win->_maxy + 1,
00194                        win->_maxx + 1,
00195                        win->_begy,
00196                        win->_begx);
00197        }
00198 
00199        if (nwin != 0) {
00200 
00201            nwin->_curx = win->_curx;
00202            nwin->_cury = win->_cury;
00203            nwin->_maxy = win->_maxy;
00204            nwin->_maxx = win->_maxx;
00205            nwin->_begy = win->_begy;
00206            nwin->_begx = win->_begx;
00207            nwin->_yoffset = win->_yoffset;
00208 
00209            nwin->_flags = win->_flags & ~_SUBWIN;
00210            /* Due to the use of newwin(), the clone is not a subwindow.
00211             * The text is really copied into the clone.
00212             */
00213 
00214            nwin->_attrs = win->_attrs;
00215            nwin->_nc_bkgd = win->_nc_bkgd;
00216 
00217            nwin->_notimeout = win->_notimeout;
00218            nwin->_clear = win->_clear;
00219            nwin->_leaveok = win->_leaveok;
00220            nwin->_scroll = win->_scroll;
00221            nwin->_idlok = win->_idlok;
00222            nwin->_idcok = win->_idcok;
00223            nwin->_immed = win->_immed;
00224            nwin->_sync = win->_sync;
00225            nwin->_use_keypad = win->_use_keypad;
00226            nwin->_delay = win->_delay;
00227 
00228            nwin->_parx = 0;
00229            nwin->_pary = 0;
00230            nwin->_parent = (WINDOW *) 0;
00231            /* See above: the clone isn't a subwindow! */
00232 
00233            nwin->_regtop = win->_regtop;
00234            nwin->_regbottom = win->_regbottom;
00235 
00236            if (win->_flags & _ISPAD)
00237               nwin->_pad = win->_pad;
00238 
00239            linesize = (win->_maxx + 1) * sizeof(NCURSES_CH_T);
00240            for (i = 0; i <= nwin->_maxy; i++) {
00241               memcpy(nwin->_line[i].text, win->_line[i].text, linesize);
00242               nwin->_line[i].firstchar = win->_line[i].firstchar;
00243               nwin->_line[i].lastchar = win->_line[i].lastchar;
00244            }
00245        }
00246     }
00247     returnWin(nwin);
00248 }