1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 1995, by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 /* 28 * prefresh.c 29 * 30 * XCurses Library 31 * 32 * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved. 33 * 34 */ 35 36 #ifdef M_RCSID 37 #ifndef lint 38 static char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/prefresh.c 1.3 1995/06/20 14:34:10 ant Exp $"; 39 #endif 40 #endif 41 42 #include <private.h> 43 44 /*f 45 * Update newscr with the given pad then display to the terminal. 46 */ 47 int 48 prefresh(w, pminr, pminc, sminr, sminc, smaxr, smaxc) 49 WINDOW *w; 50 int pminr, pminc, sminr, sminc, smaxr, smaxc; 51 { 52 int code; 53 54 #ifdef M_CURSES_TRACE 55 __m_trace( 56 "prefresh(%p, %d, %d, %d, %d, %d, %d)", 57 w, pminr, pminc, sminr, sminc, smaxr, smaxc 58 ); 59 #endif 60 61 code = pnoutrefresh(w, pminr, pminc, sminr, sminc, smaxr, smaxc); 62 if (code == OK) 63 code = doupdate(); 64 65 return __m_return_code("prefresh", code); 66 } 67 68 /*f 69 * Update newscr with the given pad. This allows newscr to 70 * be updated with several windows before doing a doupdate(). 71 * 72 * MKS extension permits windows that are not pads to be refreshed 73 * using this function. 74 */ 75 int 76 pnoutrefresh(pad, pminr, pminc, sminr, sminc, smaxr, smaxc) 77 WINDOW *pad; 78 int pminr, pminc, sminr, sminc, smaxr, smaxc; 79 { 80 WINDOW *ns; 81 int row, dy, dx; 82 83 #ifdef M_CURSES_TRACE 84 __m_trace( 85 "pnoutrefresh(%p, %d, %d, %d, %d, %d, %d)", 86 pad, pminr, pminc, sminr, sminc, smaxr, smaxc 87 ); 88 #endif 89 90 ns = __m_screen->_newscr; 91 92 /* Adjust regions to be within bounds. */ 93 if (pminr < 0) 94 pminr = 0; 95 if (pminc < 0) 96 pminc = 0; 97 if (sminr < 0) 98 sminr = 0; 99 if (sminc < 0) 100 sminc = 0; 101 if (ns->_maxy <= smaxr) 102 smaxr = ns->_maxy-1; 103 if (ns->_maxx <= smaxc) 104 smaxr = ns->_maxx-1; 105 106 if (pad->_maxy <= pminr || pad->_maxx <= pminc 107 || smaxr < sminr || smaxc < sminc) 108 return __m_return_code("pnoutrefresh", ERR); 109 110 /* Clear displayed region. */ 111 for (row = sminr; row <= smaxr; ++row) 112 (void) __m_cc_erase(ns, row, sminc, row, smaxc); 113 114 /* Determine the proper maximums in case smaxr and smaxc mapped 115 * beyond the bottom and right-hand edges of the pad. 116 */ 117 if (pad->_maxx <= pminc + smaxc-sminc+1) 118 smaxc = sminc + pad->_maxx - 1 - pminc; 119 if (pad->_maxy <= pminr + smaxr-sminr+1) 120 smaxr = sminr + pad->_maxy - 1 - pminr; 121 122 /* Remember refresh region (inclusive). */ 123 pad->_refy = (short) pminr; 124 pad->_refx = (short) pminc; 125 pad->_sminy = (short) sminr; 126 pad->_sminx = (short) sminc; 127 pad->_smaxy = (short) smaxr; 128 pad->_smaxx = (short) smaxc; 129 130 (void) copywin(pad, ns, pminr, pminc, sminr, sminc, smaxr, smaxc, 0); 131 132 /* Last refreshed window controls W_LEAVE_CURSOR flag. */ 133 ns->_flags &= ~W_LEAVE_CURSOR; 134 ns->_flags |= pad->_flags 135 & (W_CLEAR_WINDOW | W_REDRAW_WINDOW | W_LEAVE_CURSOR); 136 pad->_flags &= ~(W_CLEAR_WINDOW | W_REDRAW_WINDOW); 137 138 /* Figure out where to leave the cursor. */ 139 dy = pad->_cury - pminr + pad->_begy; 140 dx = pad->_curx - pminc + pad->_begx; 141 142 ns->_cury = dy < 0 ? 0 : ns->_maxy <= dy ? ns->_maxy-1 : dy; 143 ns->_curx = dx < 0 ? 0 : ns->_maxx <= dx ? ns->_maxx-1 : dx; 144 145 return __m_return_code("pnoutrefresh", OK); 146 } 147