1 // * this is for making emacs happy: -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright 2020 Thomas E. Dickey *
4 * Copyright 1999-2012,2013 Free Software Foundation, Inc. *
6 * Permission is hereby granted, free of charge, to any person obtaining a *
7 * copy of this software and associated documentation files (the *
8 * "Software"), to deal in the Software without restriction, including *
9 * without limitation the rights to use, copy, modify, merge, publish, *
10 * distribute, distribute with modifications, sublicense, and/or sell *
11 * copies of the Software, and to permit persons to whom the Software is *
12 * furnished to do so, subject to the following conditions: *
14 * The above copyright notice and this permission notice shall be included *
15 * in all copies or substantial portions of the Software. *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
25 * Except as contained in this notice, the name(s) of the above copyright *
26 * holders shall not be used in advertising or otherwise to promote the *
27 * sale, use or other dealings in this Software without prior written *
29 ****************************************************************************/
31 /****************************************************************************
32 * Author: Juergen Pfeifer, 1999 *
33 ****************************************************************************/
39 MODULE_ID("$Id: cursespad.cc,v 1.18 2020/02/02 23:34:34 tom Exp $")
41 NCursesPad::NCursesPad(int nlines, int ncols)
43 viewWin(static_cast<NCursesWindow*>(0)),
44 viewSub(static_cast<NCursesWindow*>(0)),
45 h_gridsize(0), v_gridsize(0),
46 min_row(0), min_col(0)
48 w = ::newpad(nlines, ncols);
49 if (static_cast<WINDOW*>(0) == w) {
51 err_handler("Cannot construct window");
57 int NCursesPad::driver (int key)
59 // Default implementation
84 void NCursesPad::operator()(void)
86 NCursesWindow* W = Win();
88 if (static_cast<NCursesWindow*>(0) != W) {
89 int Width = W->width();
90 int Height = W->height();
92 int req = REQ_PAD_REFRESH;
102 case REQ_PAD_REFRESH:
110 if (min_col < h_gridsize)
113 min_col -= h_gridsize;
116 OnNavigationError(req);
120 if (min_col < (width() - Width - 1)) {
122 if (min_col > (width() - Width - h_gridsize - 1))
123 min_col = width() - Width - 1;
125 min_col += h_gridsize;
128 OnNavigationError(req);
134 if (min_row < v_gridsize)
137 min_row -= v_gridsize;
140 OnNavigationError(req);
144 if (min_row < (height() - Height - 1)) {
146 if (min_row > (height() - Height - v_gridsize - 1))
147 min_row = height() - Height - 1;
149 min_row += v_gridsize;
152 OnNavigationError(req);
156 OnUnknownOperation(req);
165 } while( (req=driver(W->getch())) != REQ_PAD_EXIT );
170 int NCursesPad::refresh()
172 int res = noutrefresh();
173 if (res==OK && (static_cast<NCursesWindow*>(0) != viewWin)) {
174 res = (viewWin->refresh());
179 int NCursesPad::noutrefresh()
182 NCursesWindow* W = Win();
183 if (static_cast<NCursesWindow*>(0) != W) {
184 int high = W->maxy();
185 int wide = W->maxx();
186 res = copywin(*W, min_row, min_col,
191 res = viewWin->noutrefresh();
197 void NCursesPad::setWindow(NCursesWindow& view,
198 int v_grid NCURSES_PARAM_INIT(1),
199 int h_grid NCURSES_PARAM_INIT(1))
202 min_row = min_col = 0;
203 if (h_grid <=0 || v_grid <= 0)
204 err_handler("Illegal Gridsize");
211 void NCursesPad::setSubWindow(NCursesWindow& sub)
213 if (static_cast<NCursesWindow*>(0) == viewWin)
214 err_handler("Pad has no viewport");
215 assert(viewWin != 0);
216 if (!viewWin->isDescendant(sub))
217 THROW(new NCursesException("NCursesFramePad", E_SYSTEM_ERROR));
221 void NCursesFramedPad::OnOperation(int pad_req)
224 NCursesWindow* W = Win();
225 NCursesWindow* W2 = getWindow();
227 if ((static_cast<NCursesWindow*>(0) != W) && (static_cast<NCursesWindow*>(0) != W2)) {
228 int Width = W->width();
229 int Height = W->height();
230 int i, row, col, h_len, v_len;
232 int my_width = width();
235 h_len = (Width*Width + my_width - 1) / my_width;
244 int my_height = height();
246 if (my_height != 0) {
247 v_len = (Height*Height + my_height - 1) / my_height;
257 col = (min_col * Width + my_width - 1) / my_width;
258 if (col + h_len > Width)
264 if (my_height != 0) {
265 row = (min_row * Height + my_height - 1) / my_height;
266 if (row + v_len > Height)
267 row = Height - v_len;
272 W2->vline(1,Width+1,Height);
273 W2->attron(A_REVERSE);
275 W2->addch(row+1,Width+1,ACS_UARROW);
277 W2->addch(row+i,Width+1,' ');
278 W2->addch(row+v_len,Width+1,ACS_DARROW);
281 for(i=1;i<=v_len;i++)
282 W2->addch(row+i,Width+1,' ');
284 W2->attroff(A_REVERSE);
286 W2->hline(Height+1,1,Width);
287 W2->attron(A_REVERSE);
289 W2->addch(Height+1,col+1,ACS_LARROW);
291 W2->addch(Height+1,col+i,' ');
292 W2->addch(Height+1,col+h_len,ACS_RARROW);
295 for(i=1;i<=h_len;i++)
296 W2->addch(Height+1,col+i,' ');
298 W2->attroff(A_REVERSE);