X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=c%2B%2B%2Fcursespad.cc;h=6065923bdf8c6d6033451c6b18ae38463417405e;hp=d875a815c74b70599357937bc8c8386a5174a7a2;hb=a5fe3726f7d4374e9b1551b535c8617b423996f2;hpb=55ccd2b959766810cf7db8d1c4462f338ce0afc8 diff --git a/c++/cursespad.cc b/c++/cursespad.cc index d875a815..6065923b 100644 --- a/c++/cursespad.cc +++ b/c++/cursespad.cc @@ -1,6 +1,7 @@ // * this is for making emacs happy: -*-Mode: C++;-*- /**************************************************************************** - * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * + * Copyright 2020 Thomas E. Dickey * + * Copyright 1999-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 * @@ -33,12 +34,9 @@ #include "internal.h" -#include +#include -#include "etip.h" -#include "cursesw.h" - -MODULE_ID("$Id: cursespad.cc,v 1.11 2005/07/23 20:51:23 tom Exp $") +MODULE_ID("$Id: cursespad.cc,v 1.18 2020/02/02 23:34:34 tom Exp $") NCursesPad::NCursesPad(int nlines, int ncols) : NCursesWindow(), @@ -214,6 +212,7 @@ void NCursesPad::setSubWindow(NCursesWindow& sub) { if (static_cast(0) == viewWin) err_handler("Pad has no viewport"); + assert(viewWin != 0); if (!viewWin->isDescendant(sub)) THROW(new NCursesException("NCursesFramePad", E_SYSTEM_ERROR)); viewSub = ⊂ @@ -221,6 +220,7 @@ void NCursesPad::setSubWindow(NCursesWindow& sub) void NCursesFramedPad::OnOperation(int pad_req) { + (void) pad_req; NCursesWindow* W = Win(); NCursesWindow* W2 = getWindow(); @@ -229,25 +229,45 @@ void NCursesFramedPad::OnOperation(int pad_req) int Height = W->height(); int i, row, col, h_len, v_len; - h_len = (Width*Width + width() - 1)/width(); - if (h_len==0) + int my_width = width(); + + if (my_width != 0) { + h_len = (Width*Width + my_width - 1) / my_width; + if (h_len==0) + h_len = 1; + if (h_len > Width) + h_len = Width; + } else { h_len = 1; - if (h_len > Width) - h_len = Width; + } + + int my_height = height(); - v_len = (Height*Height + height() - 1)/height(); - if (v_len==0) + if (my_height != 0) { + v_len = (Height*Height + my_height - 1) / my_height; + if (v_len==0) + v_len = 1; + if (v_len > Height) + v_len = Height; + } else { v_len = 1; - if (v_len > Height) - v_len = Height; + } - col = (min_col * Width + width() - 1) / width(); - if (col + h_len > Width) - col = Width - h_len; + if (my_width != 0) { + col = (min_col * Width + my_width - 1) / my_width; + if (col + h_len > Width) + col = Width - h_len; + } else { + col = 0; + } - row = (min_row * Height + height() - 1) / height(); - if (row + v_len > Height) - row = Height - v_len; + if (my_height != 0) { + row = (min_row * Height + my_height - 1) / my_height; + if (row + v_len > Height) + row = Height - v_len; + } else { + row = 0; + } W2->vline(1,Width+1,Height); W2->attron(A_REVERSE);