1 // * this is for making emacs happy: -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright (c) 1998-2003,2005 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 ****************************************************************************/
41 MODULE_ID("$Id: cursespad.cc,v 1.11 2005/07/23 20:51:23 tom Exp $")
43 NCursesPad::NCursesPad(int nlines, int ncols)
45 viewWin(static_cast<NCursesWindow*>(0)),
46 viewSub(static_cast<NCursesWindow*>(0)),
47 h_gridsize(0), v_gridsize(0),
48 min_row(0), min_col(0)
50 w = ::newpad(nlines, ncols);
51 if (static_cast<WINDOW*>(0) == w) {
53 err_handler("Cannot construct window");
59 int NCursesPad::driver (int key)
61 // Default implementation
86 void NCursesPad::operator()(void)
88 NCursesWindow* W = Win();
90 if (static_cast<NCursesWindow*>(0) != W) {
91 int Width = W->width();
92 int Height = W->height();
94 int req = REQ_PAD_REFRESH;
101 bool changed = FALSE;
104 case REQ_PAD_REFRESH:
112 if (min_col < h_gridsize)
115 min_col -= h_gridsize;
118 OnNavigationError(req);
122 if (min_col < (width() - Width - 1)) {
124 if (min_col > (width() - Width - h_gridsize - 1))
125 min_col = width() - Width - 1;
127 min_col += h_gridsize;
130 OnNavigationError(req);
136 if (min_row < v_gridsize)
139 min_row -= v_gridsize;
142 OnNavigationError(req);
146 if (min_row < (height() - Height - 1)) {
148 if (min_row > (height() - Height - v_gridsize - 1))
149 min_row = height() - Height - 1;
151 min_row += v_gridsize;
154 OnNavigationError(req);
158 OnUnknownOperation(req);
167 } while( (req=driver(W->getch())) != REQ_PAD_EXIT );
172 int NCursesPad::refresh()
174 int res = noutrefresh();
175 if (res==OK && (static_cast<NCursesWindow*>(0) != viewWin)) {
176 res = (viewWin->refresh());
181 int NCursesPad::noutrefresh()
184 NCursesWindow* W = Win();
185 if (static_cast<NCursesWindow*>(0) != W) {
186 int high = W->maxy();
187 int wide = W->maxx();
188 res = copywin(*W, min_row, min_col,
193 res = viewWin->noutrefresh();
199 void NCursesPad::setWindow(NCursesWindow& view,
200 int v_grid NCURSES_PARAM_INIT(1),
201 int h_grid NCURSES_PARAM_INIT(1))
204 min_row = min_col = 0;
205 if (h_grid <=0 || v_grid <= 0)
206 err_handler("Illegal Gridsize");
213 void NCursesPad::setSubWindow(NCursesWindow& sub)
215 if (static_cast<NCursesWindow*>(0) == viewWin)
216 err_handler("Pad has no viewport");
217 if (!viewWin->isDescendant(sub))
218 THROW(new NCursesException("NCursesFramePad", E_SYSTEM_ERROR));
222 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 h_len = (Width*Width + width() - 1)/width();
238 v_len = (Height*Height + height() - 1)/height();
244 col = (min_col * Width + width() - 1) / width();
245 if (col + h_len > Width)
248 row = (min_row * Height + height() - 1) / height();
249 if (row + v_len > Height)
250 row = Height - v_len;
252 W2->vline(1,Width+1,Height);
253 W2->attron(A_REVERSE);
255 W2->addch(row+1,Width+1,ACS_UARROW);
257 W2->addch(row+i,Width+1,' ');
258 W2->addch(row+v_len,Width+1,ACS_DARROW);
261 for(i=1;i<=v_len;i++)
262 W2->addch(row+i,Width+1,' ');
264 W2->attroff(A_REVERSE);
266 W2->hline(Height+1,1,Width);
267 W2->attron(A_REVERSE);
269 W2->addch(Height+1,col+1,ACS_LARROW);
271 W2->addch(Height+1,col+i,' ');
272 W2->addch(Height+1,col+h_len,ACS_RARROW);
275 for(i=1;i<=h_len;i++)
276 W2->addch(Height+1,col+i,' ');
278 W2->attroff(A_REVERSE);