10e3d5408SPeter Wemm /**************************************************************************** 24a1a9510SRong-En Fan * Copyright (c) 1998-2001,2006 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 434a1a9510SRong-En Fan MODULE_ID("$Id: lib_mvwin.c,v 1.14 2006/02/25 22:53:46 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 534a1a9510SRong-En Fan /* 544a1a9510SRong-En Fan * mvwin() should only modify the indices. See test/demo_menus.c and 554a1a9510SRong-En Fan * test/movewindow.c for examples. 564a1a9510SRong-En Fan */ 574a1a9510SRong-En Fan #if 0 580e3d5408SPeter Wemm /* Copying subwindows is allowed, but it is expensive... */ 590e3d5408SPeter Wemm if (win->_flags & _SUBWIN) { 600e3d5408SPeter Wemm int err = ERR; 610e3d5408SPeter Wemm WINDOW *parent = win->_parent; 627a69bbfbSPeter Wemm if (parent) { /* Now comes the complicated and costly part, you should really 630e3d5408SPeter Wemm * try to avoid to move subwindows. Because a subwindow shares 640e3d5408SPeter Wemm * the text buffers with its parent, one can't do a simple 650e3d5408SPeter Wemm * memmove of the text buffers. One has to create a copy, then 660e3d5408SPeter Wemm * to relocate the subwindow and then to do a copy. 670e3d5408SPeter Wemm */ 680e3d5408SPeter Wemm if ((by - parent->_begy == win->_pary) && 690e3d5408SPeter Wemm (bx - parent->_begx == win->_parx)) 700e3d5408SPeter Wemm err = OK; /* we don't actually move */ 710e3d5408SPeter Wemm else { 720e3d5408SPeter Wemm WINDOW *clone = dupwin(win); 730e3d5408SPeter Wemm if (clone) { 740e3d5408SPeter Wemm /* now we have the clone, so relocate win */ 750e3d5408SPeter Wemm 760e3d5408SPeter Wemm werase(win); /* Erase the original place */ 7739f2269fSPeter Wemm /* fill with parents background */ 7839f2269fSPeter Wemm wbkgrnd(win, CHREF(parent->_nc_bkgd)); 790e3d5408SPeter Wemm wsyncup(win); /* Tell the parent(s) */ 800e3d5408SPeter Wemm 810e3d5408SPeter Wemm err = mvderwin(win, 820e3d5408SPeter Wemm by - parent->_begy, 830e3d5408SPeter Wemm bx - parent->_begx); 840e3d5408SPeter Wemm if (err != ERR) { 850e3d5408SPeter Wemm err = copywin(clone, win, 860e3d5408SPeter Wemm 0, 0, 0, 0, win->_maxy, win->_maxx, 0); 870e3d5408SPeter Wemm if (ERR != err) 880e3d5408SPeter Wemm wsyncup(win); 890e3d5408SPeter Wemm } 900e3d5408SPeter Wemm if (ERR == delwin(clone)) 910e3d5408SPeter Wemm err = ERR; 920e3d5408SPeter Wemm } 930e3d5408SPeter Wemm } 940e3d5408SPeter Wemm } 950e3d5408SPeter Wemm returnCode(err); 960e3d5408SPeter Wemm } 974a1a9510SRong-En Fan #endif 980e3d5408SPeter Wemm 990e3d5408SPeter Wemm if (by + win->_maxy > screen_lines - 1 1000e3d5408SPeter Wemm || bx + win->_maxx > screen_columns - 1 1010e3d5408SPeter Wemm || by < 0 1020e3d5408SPeter Wemm || bx < 0) 1030e3d5408SPeter Wemm returnCode(ERR); 1040e3d5408SPeter Wemm 1050e3d5408SPeter Wemm /* 1060e3d5408SPeter Wemm * Whether or not the window is moved, touch the window's contents so 1070e3d5408SPeter Wemm * that a following call to 'wrefresh()' will paint the window at the 1080e3d5408SPeter Wemm * new location. This ensures that if the caller has refreshed another 1090e3d5408SPeter Wemm * window at the same location, that this one will be displayed. 1100e3d5408SPeter Wemm */ 1110e3d5408SPeter Wemm win->_begy = by; 1120e3d5408SPeter Wemm win->_begx = bx; 1130e3d5408SPeter Wemm returnCode(touchwin(win)); 1140e3d5408SPeter Wemm } 115