Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcurses Add code to allow resizing of windows and the ...



details:   https://anonhg.NetBSD.org/src/rev/af7b4516aabb
branches:  trunk
changeset: 515243:af7b4516aabb
user:      blymn <blymn%NetBSD.org@localhost>
date:      Thu Sep 20 11:11:54 2001 +0000

description:
Add code to allow resizing of windows and the underlying terminal.

diffstat:

 lib/libcurses/Makefile        |   10 +-
 lib/libcurses/PSD.doc/fns.doc |   13 +
 lib/libcurses/curses.3        |    6 +-
 lib/libcurses/curses.h        |    4 +-
 lib/libcurses/refresh.c       |    6 +-
 lib/libcurses/resize.c        |  281 ++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 312 insertions(+), 8 deletions(-)

diffs (truncated from 426 to 300 lines):

diff -r 7e3cb9e93532 -r af7b4516aabb lib/libcurses/Makefile
--- a/lib/libcurses/Makefile    Thu Sep 20 10:04:10 2001 +0000
+++ b/lib/libcurses/Makefile    Thu Sep 20 11:11:54 2001 +0000
@@ -1,12 +1,14 @@
-#      $NetBSD: Makefile,v 1.32 2001/01/10 14:02:31 blymn Exp $
+#      $NetBSD: Makefile,v 1.33 2001/09/20 11:11:54 blymn Exp $
 #      @(#)Makefile    8.2 (Berkeley) 1/2/94
 
 CPPFLAGS+=#-DTFILE=\"/dev/ttyp0\"
 CPPFLAGS+=-D_CURSES_PRIVATE -I${.CURDIR} -I${.CURDIR}/../libterm
 .if defined(DEBUG_CURSES)
 CFLAGS+=-g
+.if defined(FULL_DEBUG)
 CPPFLAGS+=-DDEBUG
 .endif
+.endif
 LIB=   curses
 SRCS=  acs.c addbytes.c addch.c addnstr.c attributes.c background.c bell.c \
        border.c box.c clear.c clearok.c clrtobot.c clrtoeol.c color.c \
@@ -15,9 +17,9 @@
        getyx.c id_subwins.c idlok.c inch.c inchstr.c initscr.c insch.c \
        insdelln.c insertln.c instr.c keypad.c leaveok.c line.c longname.c \
        meta.c move.c mvwin.c newwin.c nodelay.c notimeout.c overlay.c \
-       overwrite.c pause.c printw.c putchar.c refresh.c scanw.c scroll.c \
-       scrollok.c setterm.c standout.c timeout.c toucholap.c touchwin.c \
-       tscroll.c tstp.c tty.c unctrl.c underscore.c
+       overwrite.c pause.c printw.c putchar.c refresh.c resize.c scanw.c \
+       scroll.c scrollok.c setterm.c standout.c timeout.c toucholap.c \
+       touchwin.c tscroll.c tstp.c tty.c unctrl.c underscore.c
 
 MAN=   curses.3
 INCS=  curses.h unctrl.h
diff -r 7e3cb9e93532 -r af7b4516aabb lib/libcurses/PSD.doc/fns.doc
--- a/lib/libcurses/PSD.doc/fns.doc     Thu Sep 20 10:04:10 2001 +0000
+++ b/lib/libcurses/PSD.doc/fns.doc     Thu Sep 20 11:11:54 2001 +0000
@@ -1087,6 +1087,14 @@
 .Fn endwin .
 This function should not be used by the user.
 .Ds
+.Fn resizeterm "int lines" "int columns" \(dg
+.De
+Resizes the curses terminal to the given size.  All internal curses
+structures are resized to the new dimensions and all curses windows that
+would have boundaries outside the new terminal size will be resized to fit
+within the new boundaries.  All windows will be cleared and it is expected
+that the application will redraw the window contents.
+.Ds
 .Fn savetty "" \(dg
 .De
 .Fn savetty
@@ -1337,6 +1345,11 @@
 .Fn doupdate ,
 thus allowing the screen to updated in an efficient manner.
 .Ds
+.Fn wresize "WINDOW *win" "int lines" "int columns"
+.De
+Resize the specified window to the given dimensions.  The window will be
+cleared and the application is expected to redraw the window contents.
+.Ds
 .Fn wtouchln "WINDOW *win" "int line" "int n" "int changed"
 .De
 If 
diff -r 7e3cb9e93532 -r af7b4516aabb lib/libcurses/curses.3
--- a/lib/libcurses/curses.3    Thu Sep 20 10:04:10 2001 +0000
+++ b/lib/libcurses/curses.3    Thu Sep 20 11:11:54 2001 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: curses.3,v 1.31 2001/04/20 13:06:35 jdc Exp $
+.\"    $NetBSD: curses.3,v 1.32 2001/09/20 11:11:54 blymn Exp $
 .\"
 .\" Copyright (c) 1985, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -285,6 +285,8 @@
 .It reset_prog_mode()  restore program (in curses) terminal modes
 .It reset_shell_mode() restore shell (not in curses) terminal modes
 .It resetty()  reset tty flags to stored value
+.It resizeterm(lines,cols)     resize the curses terminal, application must
+redraw the screen contents after this call
 .It savetty()  stored current tty flags
 .It scanw(fmt,arg1,arg2,...)   scanf through
 .Em stdscr
@@ -390,6 +392,8 @@
 .Em win
 .It wrefresh(win)      make screen look like
 .Em win
+.It wresize(win,lines,cols)    resize
+.Em win
 .It wscanw(win,fmt,arg1,arg2,...)\     scanf through
 .Em win
 .It wscrl(win,n)       scroll
diff -r 7e3cb9e93532 -r af7b4516aabb lib/libcurses/curses.h
--- a/lib/libcurses/curses.h    Thu Sep 20 10:04:10 2001 +0000
+++ b/lib/libcurses/curses.h    Thu Sep 20 11:11:54 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: curses.h,v 1.58 2001/09/16 16:34:25 wiz Exp $  */
+/*     $NetBSD: curses.h,v 1.59 2001/09/20 11:11:54 blymn Exp $        */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -696,6 +696,7 @@
 int     reset_prog_mode(void);
 int     reset_shell_mode(void);
 int     resetty(void);
+int      resizeterm(int, int);
 int     savetty(void);
 int     scanw(const char *, ...)
                __attribute__((__format__(__scanf__, 1, 2)));
@@ -746,6 +747,7 @@
 int     wprintw(WINDOW *, const char *, ...)
                __attribute__((__format__(__printf__, 2, 3)));
 int     wrefresh(WINDOW *);
+int      wresize(WINDOW *, int, int);
 int     wscanw(WINDOW *, const char *, ...)
                __attribute__((__format__(__scanf__, 2, 3)));
 int     wscrl(WINDOW *, int);
diff -r 7e3cb9e93532 -r af7b4516aabb lib/libcurses/refresh.c
--- a/lib/libcurses/refresh.c   Thu Sep 20 10:04:10 2001 +0000
+++ b/lib/libcurses/refresh.c   Thu Sep 20 11:11:54 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: refresh.c,v 1.41 2000/12/19 21:34:25 jdc Exp $ */
+/*     $NetBSD: refresh.c,v 1.42 2001/09/20 11:11:54 blymn Exp $       */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)refresh.c  8.7 (Berkeley) 8/13/94";
 #else
-__RCSID("$NetBSD: refresh.c,v 1.41 2000/12/19 21:34:25 jdc Exp $");
+__RCSID("$NetBSD: refresh.c,v 1.42 2001/09/20 11:11:54 blymn Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -415,6 +415,8 @@
                        if (cp-- <= win->lines[wy]->line)
                                break;
                nlsp = cp - win->lines[wy]->line;
+               if (nlsp < 0)
+                       nlsp = 0;
        }
        if (!curwin)
                ce = __tc_ce;
diff -r 7e3cb9e93532 -r af7b4516aabb lib/libcurses/resize.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libcurses/resize.c    Thu Sep 20 11:11:54 2001 +0000
@@ -0,0 +1,281 @@
+/*     $NetBSD: resize.c,v 1.1 2001/09/20 11:11:54 blymn Exp $ */
+
+/*
+ * Copyright (c) 2001
+ *     Brett Lymn.
+ *
+ * This code has been donated to The NetBSD Foundation by the Author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)resize.c   blymn 2001/08/26";
+#else
+__RCSID("$NetBSD: resize.c,v 1.1 2001/09/20 11:11:54 blymn Exp $");
+#endif
+#endif                         /* not lint */
+
+#include <stdlib.h>
+
+#include "curses.h"
+#include "curses_private.h"
+
+extern struct __winlist        *winlistp;
+
+static int __resizewin(WINDOW *win, int nlines, int ncols);
+
+/*
+ * wresize --
+ *     Resize the given window to the new size.
+ */
+int
+wresize(WINDOW *win, int nlines, int ncols)
+{
+       __LINE *lp;
+       int     i, j;
+       __LDATA *sp;
+
+       if ((win == NULL) || (nlines < 0) || (ncols < 0))
+               return ERR;
+
+       if (win->orig == NULL) {
+               if (nlines == 0)
+                       nlines = LINES - win->begy;
+               if (ncols == 0)
+                       ncols = COLS - win->begx;
+       } else {
+                 /* subwins must fit inside the parent - check this */
+               if ((nlines == 0)
+                   || (nlines > (win->orig->maxy + win->orig->begy
+                                 - win->begy)))
+                       nlines = win->orig->maxy + win->orig->begy - win->begy;
+
+               if ((ncols == 0)
+                   || (ncols > (win->orig->maxx + win->orig->begx
+                                - win->begx)))
+                       ncols = win->orig->maxx + win->orig->begx - win->begx;
+       }
+
+       if ((__resizewin(win, nlines, ncols)) == ERR)
+               return ERR;
+
+         /*
+          * we must zot the window contents otherwise lines may pick
+          * up attributes from the previous line when the window is
+          * made smaller.  The client will redraw the window anyway
+          * so this is no big deal.
+          */
+       for (i = 0; i < win->maxy; i++) {
+               lp = win->lines[i];
+               for (sp = lp->line, j = 0; j < win->maxx;
+                    j++, sp++) {
+                       sp->ch = ' ';
+                       sp->bch = ' ';
+                       sp->attr = 0;
+                       sp->battr = 0;
+               }
+               lp->hash = __hash((char *)(void *)lp->line,
+                                 (int) (ncols * __LDATASIZE));
+       }
+       
+       return OK;
+}
+
+/*
+ * resizeterm --
+ *      Resize the terminal window, resizing the dependent windows.
+ */
+int
+resizeterm(int nlines, int ncols)
+{
+       WINDOW *win;
+       struct __winlist *list;
+       int newlines, newcols, ldelta, cdelta;
+       
+         /* don't worry if things have not changed... we would like to
+            do this but some bastard programs update LINES and COLS before
+            calling resizeterm thus negating it's effect.
+       if ((nlines == LINES) && (ncols == COLS))
+       return OK;*/
+
+#ifdef DEBUG
+       __CTRACE("resizeterm: (%d, %d)\n", nlines, ncols);
+#endif
+
+       ldelta = nlines - __virtscr->maxy;
+       cdelta = ncols - __virtscr->maxx;
+       
+       for (list = __winlistp; list != NULL; list = list->nextp) {
+               win = list->winp;
+               newlines = win->maxy;
+               newcols = win->maxx;
+               
+               if (win->begy >= (nlines - 1)) {
+                       win->begy = nlines - win->maxx - 1;
+                       if (win->begy < 0)
+                               win->begy = 0;
+               }
+
+               
+               if ((newlines + win->begy + ldelta) == nlines)
+                               newlines = nlines;
+
+               if (newlines > nlines) {
+                       newlines = nlines - win->begy;
+                       if (newlines < 0)
+                               newlines = 1;



Home | Main Index | Thread Index | Old Index