10e3d5408SPeter Wemm /**************************************************************************** 27a69bbfbSPeter Wemm * Copyright (c) 1998,2000 Free Software Foundation, Inc. * 30e3d5408SPeter Wemm * * 40e3d5408SPeter Wemm * Permission is hereby granted, free of charge, to any person obtaining a * 50e3d5408SPeter Wemm * copy of this software and associated documentation files (the * 60e3d5408SPeter Wemm * "Software"), to deal in the Software without restriction, including * 70e3d5408SPeter Wemm * without limitation the rights to use, copy, modify, merge, publish, * 80e3d5408SPeter Wemm * distribute, distribute with modifications, sublicense, and/or sell * 90e3d5408SPeter Wemm * copies of the Software, and to permit persons to whom the Software is * 100e3d5408SPeter Wemm * furnished to do so, subject to the following conditions: * 110e3d5408SPeter Wemm * * 120e3d5408SPeter Wemm * The above copyright notice and this permission notice shall be included * 130e3d5408SPeter Wemm * in all copies or substantial portions of the Software. * 140e3d5408SPeter Wemm * * 150e3d5408SPeter Wemm * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 160e3d5408SPeter Wemm * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 170e3d5408SPeter Wemm * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 180e3d5408SPeter Wemm * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 190e3d5408SPeter Wemm * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 200e3d5408SPeter Wemm * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 210e3d5408SPeter Wemm * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 220e3d5408SPeter Wemm * * 230e3d5408SPeter Wemm * Except as contained in this notice, the name(s) of the above copyright * 240e3d5408SPeter Wemm * holders shall not be used in advertising or otherwise to promote the * 250e3d5408SPeter Wemm * sale, use or other dealings in this Software without prior written * 260e3d5408SPeter Wemm * authorization. * 270e3d5408SPeter Wemm ****************************************************************************/ 280e3d5408SPeter Wemm 290e3d5408SPeter Wemm /**************************************************************************** 300e3d5408SPeter Wemm * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 310e3d5408SPeter Wemm * and: Eric S. Raymond <esr@snark.thyrsus.com> * 320e3d5408SPeter Wemm ****************************************************************************/ 330e3d5408SPeter Wemm 340e3d5408SPeter Wemm /* 350e3d5408SPeter Wemm ** lib_mvwin.c 360e3d5408SPeter Wemm ** 370e3d5408SPeter Wemm ** The routine mvwin(). 380e3d5408SPeter Wemm ** 390e3d5408SPeter Wemm */ 400e3d5408SPeter Wemm 410e3d5408SPeter Wemm #include <curses.priv.h> 420e3d5408SPeter Wemm 437a69bbfbSPeter Wemm MODULE_ID("$Id: lib_mvwin.c,v 1.9 2000/12/10 02:43:27 tom Exp $") 440e3d5408SPeter Wemm 457a69bbfbSPeter Wemm NCURSES_EXPORT(int) 467a69bbfbSPeter Wemm mvwin(WINDOW *win, int by, int bx) 470e3d5408SPeter Wemm { 480e3d5408SPeter Wemm T((T_CALLED("mvwin(%p,%d,%d)"), win, by, bx)); 490e3d5408SPeter Wemm 500e3d5408SPeter Wemm if (!win || (win->_flags & _ISPAD)) 510e3d5408SPeter Wemm returnCode(ERR); 520e3d5408SPeter Wemm 530e3d5408SPeter Wemm /* Copying subwindows is allowed, but it is expensive... */ 540e3d5408SPeter Wemm if (win->_flags & _SUBWIN) { 550e3d5408SPeter Wemm int err = ERR; 560e3d5408SPeter Wemm WINDOW *parent = win->_parent; 577a69bbfbSPeter Wemm if (parent) { /* Now comes the complicated and costly part, you should really 580e3d5408SPeter Wemm * try to avoid to move subwindows. Because a subwindow shares 590e3d5408SPeter Wemm * the text buffers with its parent, one can't do a simple 600e3d5408SPeter Wemm * memmove of the text buffers. One has to create a copy, then 610e3d5408SPeter Wemm * to relocate the subwindow and then to do a copy. 620e3d5408SPeter Wemm */ 630e3d5408SPeter Wemm if ((by - parent->_begy == win->_pary) && 640e3d5408SPeter Wemm (bx - parent->_begx == win->_parx)) 650e3d5408SPeter Wemm err = OK; /* we don't actually move */ 660e3d5408SPeter Wemm else { 670e3d5408SPeter Wemm WINDOW *clone = dupwin(win); 680e3d5408SPeter Wemm if (clone) { 690e3d5408SPeter Wemm /* now we have the clone, so relocate win */ 700e3d5408SPeter Wemm 710e3d5408SPeter Wemm werase(win); /* Erase the original place */ 720e3d5408SPeter Wemm wbkgd(win, parent->_bkgd); /* fill with parents background */ 730e3d5408SPeter Wemm wsyncup(win); /* Tell the parent(s) */ 740e3d5408SPeter Wemm 750e3d5408SPeter Wemm err = mvderwin(win, 760e3d5408SPeter Wemm by - parent->_begy, 770e3d5408SPeter Wemm bx - parent->_begx); 780e3d5408SPeter Wemm if (err != ERR) { 790e3d5408SPeter Wemm err = copywin(clone, win, 800e3d5408SPeter Wemm 0, 0, 0, 0, win->_maxy, win->_maxx, 0); 810e3d5408SPeter Wemm if (ERR != err) 820e3d5408SPeter Wemm wsyncup(win); 830e3d5408SPeter Wemm } 840e3d5408SPeter Wemm if (ERR == delwin(clone)) 850e3d5408SPeter Wemm err = ERR; 860e3d5408SPeter Wemm } 870e3d5408SPeter Wemm } 880e3d5408SPeter Wemm } 890e3d5408SPeter Wemm returnCode(err); 900e3d5408SPeter Wemm } 910e3d5408SPeter Wemm 920e3d5408SPeter Wemm if (by + win->_maxy > screen_lines - 1 930e3d5408SPeter Wemm || bx + win->_maxx > screen_columns - 1 940e3d5408SPeter Wemm || by < 0 950e3d5408SPeter Wemm || bx < 0) 960e3d5408SPeter Wemm returnCode(ERR); 970e3d5408SPeter Wemm 980e3d5408SPeter Wemm /* 990e3d5408SPeter Wemm * Whether or not the window is moved, touch the window's contents so 1000e3d5408SPeter Wemm * that a following call to 'wrefresh()' will paint the window at the 1010e3d5408SPeter Wemm * new location. This ensures that if the caller has refreshed another 1020e3d5408SPeter Wemm * window at the same location, that this one will be displayed. 1030e3d5408SPeter Wemm */ 1040e3d5408SPeter Wemm win->_begy = by; 1050e3d5408SPeter Wemm win->_begx = bx; 1060e3d5408SPeter Wemm returnCode(touchwin(win)); 1070e3d5408SPeter Wemm } 108