1 // * this is for making emacs happy: -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright (c) 1998-2002,2003 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 ****************************************************************************/
38 MODULE_ID("$Id: cursespad.cc,v 1.7 2003/10/25 15:04:46 tom Exp $")
40 NCursesPad::NCursesPad(int lines, int cols)
42 viewWin((NCursesWindow*)0),
43 viewSub((NCursesWindow*)0),
44 h_gridsize(0), v_gridsize(0),
45 min_row(0), min_col(0)
47 w = ::newpad(lines,cols);
50 err_handler("Cannot construct window");
56 int NCursesPad::driver (int key)
58 // Default implementation
83 void NCursesPad::operator()(void)
85 NCursesWindow* W = Win();
87 if ((NCursesWindow*)0 != W) {
88 int Width = W->width();
89 int Height = W->height();
91 int req = REQ_PAD_REFRESH;
101 case REQ_PAD_REFRESH:
109 if (min_col < h_gridsize)
112 min_col -= h_gridsize;
115 OnNavigationError(req);
119 if (min_col < (width() - Width - 1)) {
121 if (min_col > (width() - Width - h_gridsize - 1))
122 min_col = width() - Width - 1;
124 min_col += h_gridsize;
127 OnNavigationError(req);
133 if (min_row < v_gridsize)
136 min_row -= v_gridsize;
139 OnNavigationError(req);
143 if (min_row < (height() - Height - 1)) {
145 if (min_row > (height() - Height - v_gridsize - 1))
146 min_row = height() - Height - 1;
148 min_row += v_gridsize;
151 OnNavigationError(req);
155 OnUnknownOperation(req);
164 } while( (req=driver(W->getch())) != REQ_PAD_EXIT );
169 int NCursesPad::refresh()
171 int res = noutrefresh();
172 if (res==OK && ((NCursesWindow*)0 != viewWin)) {
173 res = (viewWin->refresh());
178 int NCursesPad::noutrefresh()
181 NCursesWindow* W = Win();
182 if ((NCursesWindow*)0 != W) {
183 res = copywin(*W,min_row,min_col,
184 0,0,W->maxy(),W->maxx(),
188 res = viewWin->noutrefresh();
194 void NCursesPad::setWindow(NCursesWindow& view,
195 int v_grid NCURSES_PARAM_INIT(1),
196 int h_grid NCURSES_PARAM_INIT(1))
199 min_row = min_col = 0;
200 if (h_grid <=0 || v_grid <= 0)
201 err_handler("Illegal Gridsize");
208 void NCursesPad::setSubWindow(NCursesWindow& sub)
210 if ((NCursesWindow*)0 == viewWin)
211 err_handler("Pad has no viewport");
212 if (!viewWin->isDescendant(sub))
213 THROW(new NCursesException("NCursesFramePad", E_SYSTEM_ERROR));
217 void NCursesFramedPad::OnOperation(int pad_req)
219 NCursesWindow* W = Win();
220 NCursesWindow* Win = getWindow();
222 if (((NCursesWindow*)0 != W) && ((NCursesWindow*)0 != Win)) {
223 int Width = W->width();
224 int Height = W->height();
225 int i, row, col, h_len, v_len;
227 h_len = (Width*Width + width() - 1)/width();
233 v_len = (Height*Height + height() - 1)/height();
239 col = (min_col * Width + width() - 1) / width();
240 if (col + h_len > Width)
243 row = (min_row * Height + height() - 1) / height();
244 if (row + v_len > Height)
245 row = Height - v_len;
247 Win->vline(1,Width+1,Height);
248 Win->attron(A_REVERSE);
250 Win->addch(row+1,Width+1,ACS_UARROW);
252 Win->addch(row+i,Width+1,' ');
253 Win->addch(row+v_len,Width+1,ACS_DARROW);
256 for(i=1;i<=v_len;i++)
257 Win->addch(row+i,Width+1,' ');
259 Win->attroff(A_REVERSE);
261 Win->hline(Height+1,1,Width);
262 Win->attron(A_REVERSE);
264 Win->addch(Height+1,col+1,ACS_LARROW);
266 Win->addch(Height+1,col+i,' ');
267 Win->addch(Height+1,col+h_len,ACS_RARROW);
270 for(i=1;i<=h_len;i++)
271 Win->addch(Height+1,col+i,' ');
273 Win->attroff(A_REVERSE);