X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=c%2B%2B%2Fcursespad.cc;h=6065923bdf8c6d6033451c6b18ae38463417405e;hp=b82d39399b459f494fb411ad67120cffe9c8ed8c;hb=f67a188e71a0e6f80c1c45e50e7a7449c2d7bfb3;hpb=0eb88fc5281804773e2a0c7a488a4452463535ce diff --git a/c++/cursespad.cc b/c++/cursespad.cc index b82d3939..6065923b 100644 --- a/c++/cursespad.cc +++ b/c++/cursespad.cc @@ -1,6 +1,7 @@ // * this is for making emacs happy: -*-Mode: C++;-*- /**************************************************************************** - * Copyright (c) 1999 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 * @@ -28,24 +29,24 @@ ****************************************************************************/ /**************************************************************************** - * Author: Juergen Pfeifer 1999 * + * Author: Juergen Pfeifer, 1999 * ****************************************************************************/ -#include "etip.h" -#include "cursesw.h" #include "internal.h" -MODULE_ID("$Id: cursespad.cc,v 1.2 1999/09/11 23:25:54 tom Exp $") +#include -NCursesPad::NCursesPad(int lines, int cols) +MODULE_ID("$Id: cursespad.cc,v 1.18 2020/02/02 23:34:34 tom Exp $") + +NCursesPad::NCursesPad(int nlines, int ncols) : NCursesWindow(), - viewWin((NCursesWindow*)0), - viewSub((NCursesWindow*)0), + viewWin(static_cast(0)), + viewSub(static_cast(0)), h_gridsize(0), v_gridsize(0), min_row(0), min_col(0) { - w = ::newpad(lines,cols); - if ((WINDOW*)0==w) { + w = ::newpad(nlines, ncols); + if (static_cast(0) == w) { count--; err_handler("Cannot construct window"); } @@ -53,7 +54,8 @@ NCursesPad::NCursesPad(int lines, int cols) } -int NCursesPad::driver (int key) { +int NCursesPad::driver (int key) +{ // Default implementation switch(key) { case KEY_UP: @@ -79,10 +81,11 @@ int NCursesPad::driver (int key) { } -void NCursesPad::operator()(void) { +void NCursesPad::operator()(void) +{ NCursesWindow* W = Win(); - if ((NCursesWindow*)0 != W) { + if (static_cast(0) != W) { int Width = W->width(); int Height = W->height(); @@ -164,20 +167,24 @@ void NCursesPad::operator()(void) { } -int NCursesPad::refresh() { +int NCursesPad::refresh() +{ int res = noutrefresh(); - if (res==OK && ((NCursesWindow*)0 != viewWin)) { + if (res==OK && (static_cast(0) != viewWin)) { res = (viewWin->refresh()); } return(res); } -int NCursesPad::noutrefresh() { +int NCursesPad::noutrefresh() +{ int res = OK; NCursesWindow* W = Win(); - if ((NCursesWindow*)0 != W) { - res = copywin(*W,min_row,min_col, - 0,0,W->maxy(),W->maxx(), + if (static_cast(0) != W) { + int high = W->maxy(); + int wide = W->maxx(); + res = copywin(*W, min_row, min_col, + 0, 0, high, wide, FALSE); if (res==OK) { W->syncup(); @@ -203,68 +210,91 @@ void NCursesPad::setWindow(NCursesWindow& view, void NCursesPad::setSubWindow(NCursesWindow& sub) { - if ((NCursesWindow*)0 == viewWin) + 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 = ⊂ } -void NCursesFramedPad::OnOperation(int pad_req) { +void NCursesFramedPad::OnOperation(int pad_req) +{ + (void) pad_req; NCursesWindow* W = Win(); - NCursesWindow* Win = getWindow(); + NCursesWindow* W2 = getWindow(); - if (((NCursesWindow*)0 != W) && ((NCursesWindow*)0 != Win)) { + if ((static_cast(0) != W) && (static_cast(0) != W2)) { int Width = W->width(); 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; + } - Win->vline(1,Width+1,Height); - Win->attron(A_REVERSE); + W2->vline(1,Width+1,Height); + W2->attron(A_REVERSE); if (v_len>=2) { - Win->addch(row+1,Width+1,ACS_UARROW); + W2->addch(row+1,Width+1,ACS_UARROW); for(i=2;iaddch(row+i,Width+1,' '); - Win->addch(row+v_len,Width+1,ACS_DARROW); + W2->addch(row+i,Width+1,' '); + W2->addch(row+v_len,Width+1,ACS_DARROW); } else { for(i=1;i<=v_len;i++) - Win->addch(row+i,Width+1,' '); + W2->addch(row+i,Width+1,' '); } - Win->attroff(A_REVERSE); + W2->attroff(A_REVERSE); - Win->hline(Height+1,1,Width); - Win->attron(A_REVERSE); + W2->hline(Height+1,1,Width); + W2->attron(A_REVERSE); if (h_len >= 2) { - Win->addch(Height+1,col+1,ACS_LARROW); + W2->addch(Height+1,col+1,ACS_LARROW); for(i=2;iaddch(Height+1,col+i,' '); - Win->addch(Height+1,col+h_len,ACS_RARROW); + W2->addch(Height+1,col+i,' '); + W2->addch(Height+1,col+h_len,ACS_RARROW); } else { for(i=1;i<=h_len;i++) - Win->addch(Height+1,col+i,' '); + W2->addch(Height+1,col+i,' '); } - Win->attroff(A_REVERSE); + W2->attroff(A_REVERSE); } }