1 // * this is for making emacs happy: -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Juergen Pfeifer, 1999 *
32 ****************************************************************************/
39 MODULE_ID("$Id: cursespad.cc,v 1.12 2007/04/07 18:43:54 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 if (!viewWin->isDescendant(sub))
216 THROW(new NCursesException("NCursesFramePad", E_SYSTEM_ERROR));
220 void NCursesFramedPad::OnOperation(int pad_req)
222 NCursesWindow* W = Win();
223 NCursesWindow* W2 = getWindow();
225 if ((static_cast<NCursesWindow*>(0) != W) && (static_cast<NCursesWindow*>(0) != W2)) {
226 int Width = W->width();
227 int Height = W->height();
228 int i, row, col, h_len, v_len;
230 h_len = (Width*Width + width() - 1)/width();
236 v_len = (Height*Height + height() - 1)/height();
242 col = (min_col * Width + width() - 1) / width();
243 if (col + h_len > Width)
246 row = (min_row * Height + height() - 1) / height();
247 if (row + v_len > Height)
248 row = Height - v_len;
250 W2->vline(1,Width+1,Height);
251 W2->attron(A_REVERSE);
253 W2->addch(row+1,Width+1,ACS_UARROW);
255 W2->addch(row+i,Width+1,' ');
256 W2->addch(row+v_len,Width+1,ACS_DARROW);
259 for(i=1;i<=v_len;i++)
260 W2->addch(row+i,Width+1,' ');
262 W2->attroff(A_REVERSE);
264 W2->hline(Height+1,1,Width);
265 W2->attron(A_REVERSE);
267 W2->addch(Height+1,col+1,ACS_LARROW);
269 W2->addch(Height+1,col+i,' ');
270 W2->addch(Height+1,col+h_len,ACS_RARROW);
273 for(i=1;i<=h_len;i++)
274 W2->addch(Height+1,col+i,' ');
276 W2->attroff(A_REVERSE);