1 // * this is for making emacs happy: -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright (c) 1998-2001,2002 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 * Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en *
33 ****************************************************************************/
39 MODULE_ID("$Id: cursespad.cc,v 1.6 2002/09/22 19:32:55 tom Exp $")
41 NCursesPad::NCursesPad(int lines, int cols)
43 viewWin((NCursesWindow*)0),
44 viewSub((NCursesWindow*)0),
45 h_gridsize(0), v_gridsize(0),
46 min_row(0), min_col(0)
48 w = ::newpad(lines,cols);
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 ((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 && ((NCursesWindow*)0 != viewWin)) {
174 res = (viewWin->refresh());
179 int NCursesPad::noutrefresh()
182 NCursesWindow* W = Win();
183 if ((NCursesWindow*)0 != W) {
184 res = copywin(*W,min_row,min_col,
185 0,0,W->maxy(),W->maxx(),
189 res = viewWin->noutrefresh();
195 void NCursesPad::setWindow(NCursesWindow& view,
196 int v_grid NCURSES_PARAM_INIT(1),
197 int h_grid NCURSES_PARAM_INIT(1))
200 min_row = min_col = 0;
201 if (h_grid <=0 || v_grid <= 0)
202 err_handler("Illegal Gridsize");
209 void NCursesPad::setSubWindow(NCursesWindow& sub)
211 if ((NCursesWindow*)0 == viewWin)
212 err_handler("Pad has no viewport");
213 if (!viewWin->isDescendant(sub))
214 THROW(new NCursesException("NCursesFramePad", E_SYSTEM_ERROR));
218 void NCursesFramedPad::OnOperation(int pad_req)
220 NCursesWindow* W = Win();
221 NCursesWindow* Win = getWindow();
223 if (((NCursesWindow*)0 != W) && ((NCursesWindow*)0 != Win)) {
224 int Width = W->width();
225 int Height = W->height();
226 int i, row, col, h_len, v_len;
228 h_len = (Width*Width + width() - 1)/width();
234 v_len = (Height*Height + height() - 1)/height();
240 col = (min_col * Width + width() - 1) / width();
241 if (col + h_len > Width)
244 row = (min_row * Height + height() - 1) / height();
245 if (row + v_len > Height)
246 row = Height - v_len;
248 Win->vline(1,Width+1,Height);
249 Win->attron(A_REVERSE);
251 Win->addch(row+1,Width+1,ACS_UARROW);
253 Win->addch(row+i,Width+1,' ');
254 Win->addch(row+v_len,Width+1,ACS_DARROW);
257 for(i=1;i<=v_len;i++)
258 Win->addch(row+i,Width+1,' ');
260 Win->attroff(A_REVERSE);
262 Win->hline(Height+1,1,Width);
263 Win->attron(A_REVERSE);
265 Win->addch(Height+1,col+1,ACS_LARROW);
267 Win->addch(Height+1,col+i,' ');
268 Win->addch(Height+1,col+h_len,ACS_RARROW);
271 for(i=1;i<=h_len;i++)
272 Win->addch(Height+1,col+i,' ');
274 Win->attroff(A_REVERSE);