]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/movewindow.c
ncurses 5.9 - patch 20150307
[ncurses.git] / test / movewindow.c
index 5244e8aeb5f4f8bd08dfbae1a03dcdf581518882..9effda41a4da145f421aa376aa04f7f48d12cad1 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 2006-2010,2012 Free Software Foundation, Inc.              *
+ * Copyright (c) 2006-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -26,7 +26,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: movewindow.c,v 1.35 2012/06/09 20:30:32 tom Exp $
+ * $Id: movewindow.c,v 1.39 2013/05/04 19:41:02 tom Exp $
  *
  * Demonstrate move functions for windows and derived windows from the curses
  * library.
  *
  * Demonstrate move functions for windows and derived windows from the curses
  * library.
@@ -79,6 +79,14 @@ static void tail_line(CONST_FMT char *fmt,...) GCC_PRINTFLIKE(1, 2);
 static unsigned num_windows;
 static FRAME *all_windows;
 
 static unsigned num_windows;
 static FRAME *all_windows;
 
+static void
+failed(const char *s)
+{
+    perror(s);
+    endwin();
+    ExitProgram(EXIT_FAILURE);
+}
+
 static void
 message(int lineno, CONST_FMT char *fmt, va_list argp)
 {
 static void
 message(int lineno, CONST_FMT char *fmt, va_list argp)
 {
@@ -198,7 +206,6 @@ selectcell(WINDOW *parent,
                        i = event.y - uli;
                        j = event.x - ulj;
                    }
                        i = event.y - uli;
                        j = event.x - ulj;
                    }
-                   moved = TRUE;
                } else {
                    beep();
                    break;
                } else {
                    beep();
                    break;
@@ -211,8 +218,16 @@ selectcell(WINDOW *parent,
            res.x = ulj + j;
            return (&res);
        }
            res.x = ulj + j;
            return (&res);
        }
-       i %= si;
-       j %= sj;
+
+       if (si <= 0)
+           i = 0;
+       else
+           i %= si;
+
+       if (sj <= 0)
+           j = 0;
+       else
+           j %= sj;
 
        /*
         * If the caller can handle continuous movement, return the result.
 
        /*
         * If the caller can handle continuous movement, return the result.
@@ -306,6 +321,8 @@ add_window(WINDOW *parent, WINDOW *child)
     keypad(child, TRUE);
     if (need > have) {
        all_windows = typeRealloc(FRAME, need, all_windows);
     keypad(child, TRUE);
     if (need > have) {
        all_windows = typeRealloc(FRAME, need, all_windows);
+       if (!all_windows)
+           failed("add_window");
     }
     all_windows[num_windows].parent = parent;
     all_windows[num_windows].child = child;
     }
     all_windows[num_windows].parent = parent;
     all_windows[num_windows].child = child;
@@ -477,34 +494,32 @@ move_derwin(WINDOW *win)
 
     if (parent != 0) {
        bool top = (parent == stdscr);
 
     if (parent != 0) {
        bool top = (parent == stdscr);
-       if (!top) {
-           int min_col = top ? COL_MIN : 0;
-           int max_col = top ? COL_MAX : getmaxx(parent);
-           int min_line = top ? LINE_MIN : 0;
-           int max_line = top ? LINE_MAX : getmaxy(parent);
-           PAIR *tmp;
-           bool more;
-
-           show_derwin(win);
-           while ((tmp = selectcell(parent,
-                                    win,
-                                    min_line, min_col,
-                                    max_line, max_col,
-                                    TRUE,
-                                    &more)) != 0) {
-               if (mvderwin(win, tmp->y, tmp->x) != ERR) {
-                   refresh_all(win);
-                   doupdate();
-                   repaint_one(win);
-                   doupdate();
-                   result = TRUE;
-                   show_derwin(win);
-               } else {
-                   flash();
-               }
-               if (!more)
-                   break;
+       int min_col = top ? COL_MIN : 0;
+       int max_col = top ? COL_MAX : getmaxx(parent);
+       int min_line = top ? LINE_MIN : 0;
+       int max_line = top ? LINE_MAX : getmaxy(parent);
+       PAIR *tmp;
+       bool more;
+
+       show_derwin(win);
+       while ((tmp = selectcell(parent,
+                                win,
+                                min_line, min_col,
+                                max_line, max_col,
+                                TRUE,
+                                &more)) != 0) {
+           if (mvderwin(win, tmp->y, tmp->x) != ERR) {
+               refresh_all(win);
+               doupdate();
+               repaint_one(win);
+               doupdate();
+               result = TRUE;
+               show_derwin(win);
+           } else {
+               flash();
            }
            }
+           if (!more)
+               break;
        }
     }
     head_line("done");
        }
     }
     head_line("done");