10e3d5408SPeter Wemm /**************************************************************************** 2*06bfebdeSXin LI * Copyright (c) 1998-2009,2010 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> * 32*06bfebdeSXin LI * and: Thomas E. Dickey 1996-on * 33*06bfebdeSXin LI * and: Juergen Pfeifer * 340e3d5408SPeter Wemm ****************************************************************************/ 350e3d5408SPeter Wemm 360e3d5408SPeter Wemm /* 370e3d5408SPeter Wemm ** lib_mvwin.c 380e3d5408SPeter Wemm ** 390e3d5408SPeter Wemm ** The routine mvwin(). 400e3d5408SPeter Wemm ** 410e3d5408SPeter Wemm */ 420e3d5408SPeter Wemm 430e3d5408SPeter Wemm #include <curses.priv.h> 440e3d5408SPeter Wemm 45*06bfebdeSXin LI MODULE_ID("$Id: lib_mvwin.c,v 1.18 2010/12/19 01:22:58 tom Exp $") 460e3d5408SPeter Wemm 477a69bbfbSPeter Wemm NCURSES_EXPORT(int) 487a69bbfbSPeter Wemm mvwin(WINDOW *win, int by, int bx) 490e3d5408SPeter Wemm { 50*06bfebdeSXin LI #if NCURSES_SP_FUNCS 51*06bfebdeSXin LI SCREEN *sp = _nc_screen_of(win); 52*06bfebdeSXin LI #endif 53*06bfebdeSXin LI 54*06bfebdeSXin LI T((T_CALLED("mvwin(%p,%d,%d)"), (void *) win, by, bx)); 550e3d5408SPeter Wemm 560e3d5408SPeter Wemm if (!win || (win->_flags & _ISPAD)) 570e3d5408SPeter Wemm returnCode(ERR); 580e3d5408SPeter Wemm 594a1a9510SRong-En Fan /* 604a1a9510SRong-En Fan * mvwin() should only modify the indices. See test/demo_menus.c and 614a1a9510SRong-En Fan * test/movewindow.c for examples. 624a1a9510SRong-En Fan */ 634a1a9510SRong-En Fan #if 0 640e3d5408SPeter Wemm /* Copying subwindows is allowed, but it is expensive... */ 650e3d5408SPeter Wemm if (win->_flags & _SUBWIN) { 660e3d5408SPeter Wemm int err = ERR; 670e3d5408SPeter Wemm WINDOW *parent = win->_parent; 687a69bbfbSPeter Wemm if (parent) { /* Now comes the complicated and costly part, you should really 690e3d5408SPeter Wemm * try to avoid to move subwindows. Because a subwindow shares 700e3d5408SPeter Wemm * the text buffers with its parent, one can't do a simple 710e3d5408SPeter Wemm * memmove of the text buffers. One has to create a copy, then 720e3d5408SPeter Wemm * to relocate the subwindow and then to do a copy. 730e3d5408SPeter Wemm */ 740e3d5408SPeter Wemm if ((by - parent->_begy == win->_pary) && 750e3d5408SPeter Wemm (bx - parent->_begx == win->_parx)) 760e3d5408SPeter Wemm err = OK; /* we don't actually move */ 770e3d5408SPeter Wemm else { 780e3d5408SPeter Wemm WINDOW *clone = dupwin(win); 790e3d5408SPeter Wemm if (clone) { 800e3d5408SPeter Wemm /* now we have the clone, so relocate win */ 810e3d5408SPeter Wemm 820e3d5408SPeter Wemm werase(win); /* Erase the original place */ 8339f2269fSPeter Wemm /* fill with parents background */ 8439f2269fSPeter Wemm wbkgrnd(win, CHREF(parent->_nc_bkgd)); 850e3d5408SPeter Wemm wsyncup(win); /* Tell the parent(s) */ 860e3d5408SPeter Wemm 870e3d5408SPeter Wemm err = mvderwin(win, 880e3d5408SPeter Wemm by - parent->_begy, 890e3d5408SPeter Wemm bx - parent->_begx); 900e3d5408SPeter Wemm if (err != ERR) { 910e3d5408SPeter Wemm err = copywin(clone, win, 920e3d5408SPeter Wemm 0, 0, 0, 0, win->_maxy, win->_maxx, 0); 930e3d5408SPeter Wemm if (ERR != err) 940e3d5408SPeter Wemm wsyncup(win); 950e3d5408SPeter Wemm } 960e3d5408SPeter Wemm if (ERR == delwin(clone)) 970e3d5408SPeter Wemm err = ERR; 980e3d5408SPeter Wemm } 990e3d5408SPeter Wemm } 1000e3d5408SPeter Wemm } 1010e3d5408SPeter Wemm returnCode(err); 1020e3d5408SPeter Wemm } 1034a1a9510SRong-En Fan #endif 1040e3d5408SPeter Wemm 105*06bfebdeSXin LI if (by + win->_maxy > screen_lines(SP_PARM) - 1 106*06bfebdeSXin LI || bx + win->_maxx > screen_columns(SP_PARM) - 1 1070e3d5408SPeter Wemm || by < 0 1080e3d5408SPeter Wemm || bx < 0) 1090e3d5408SPeter Wemm returnCode(ERR); 1100e3d5408SPeter Wemm 1110e3d5408SPeter Wemm /* 1120e3d5408SPeter Wemm * Whether or not the window is moved, touch the window's contents so 1130e3d5408SPeter Wemm * that a following call to 'wrefresh()' will paint the window at the 1140e3d5408SPeter Wemm * new location. This ensures that if the caller has refreshed another 1150e3d5408SPeter Wemm * window at the same location, that this one will be displayed. 1160e3d5408SPeter Wemm */ 117*06bfebdeSXin LI win->_begy = (NCURSES_SIZE_T) by; 118*06bfebdeSXin LI win->_begx = (NCURSES_SIZE_T) bx; 1190e3d5408SPeter Wemm returnCode(touchwin(win)); 1200e3d5408SPeter Wemm } 121