libyui-ncurses  2.44.1
 All Classes Functions Variables
NCPad.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: NCPad.cc
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
27 #include "NCPad.h"
28 
29 
30 // PAD_PAGESIZE needs to be large enough to feed any destwin. We
31 // get in throuble here if the terminal has more than 1024 lines.
32 #define PAD_PAGESIZE 1024
33 
34 // Maximum height of the NCursesPad (e.g. in case it can't hold more
35 // than 32768 lines). Larger pads need to page.
36 //#define MAX_PAD_HEIGHT 100
37 #define MAX_PAD_HEIGHT NCursesWindow::maxcoord()
38 
39 
40 NCPad::NCPad( int lines, int cols, const NCWidget & p )
41  : NCursesPad( lines > MAX_PAD_HEIGHT ? PAD_PAGESIZE : lines, cols )
42  , _vheight( lines > MAX_PAD_HEIGHT ? lines : 0 )
43  , parw( p )
44  , destwin ( 0 )
45  , maxdpos ( 0 )
46  , maxspos ( 0 )
47  , dclear ( false )
48  , dirty ( false )
49 {}
50 
51 
52 void NCPad::Destwin( NCursesWindow * dwin )
53 {
54  if ( dwin != destwin )
55  {
56  destwin = dwin;
57 
58  if ( destwin )
59  {
60  wsze mysze( vheight(), width() );
61 
62  drect = wrect( 0, wsze( destwin->height(), destwin->width() ) );
63  srect = wrect( 0, wsze::min( mysze, drect.Sze ) );
64  maxdpos = drect.Pos + srect.Sze - 1;
65  maxspos = mysze - srect.Sze;
66 
67  dclear = ( drect.Sze != srect.Sze );
68  setpos( CurPos() );
69  }
70  else
71  {
72  drect = srect = wrect();
73  maxdpos = maxspos = 0;
74  }
75  }
76 }
77 
78 
79 void NCPad::resize( wsze nsze )
80 {
81  SetPadSize( nsze ); // might be enlarged by NCPadWidget if redirected
82 
83  if ( nsze.H != vheight()
84  || nsze.W != width() )
85  {
86  NCursesWindow * odest = Destwin();
87 
88  if ( odest )
89  Destwin( 0 );
90 
91  if ( nsze.H > MAX_PAD_HEIGHT )
92  {
93  yuiDebug() << "TRUCNATE PAD: " << nsze.H << " > " << MAX_PAD_HEIGHT << std::endl;
94  NCursesPad::resize( PAD_PAGESIZE, nsze.W );
95  _vheight = nsze.H;
96  }
97  else
98  {
99  NCursesPad::resize( nsze.H, nsze.W );
100  _vheight = 0;
101  }
102 
103  yuiDebug() << "Pageing ?: " << pageing() << std::endl;
104 
105  if ( odest )
106  Destwin( odest );
107  }
108 }
109 
110 
111 void NCPad::updateScrollHint()
112 {
113  NCScrollHint::VSet( srect.Sze.H + maxspos.L, srect.Sze.H, srect.Pos.L );
114  NCScrollHint::HSet( srect.Sze.W + maxspos.C, srect.Sze.W, srect.Pos.C );
115 }
116 
117 
118 int NCPad::update()
119 {
120  if ( destwin )
121  {
122  if ( dirty )
123  {
124  return dirtyPad();
125  }
126 
127  if ( dclear )
128  destwin->clear();
129 
130  updateScrollHint();
131 
132  if ( ! pageing() )
133  {
134  return copywin( *destwin,
135  srect.Pos.L, srect.Pos.C,
136  drect.Pos.L, drect.Pos.C,
137  maxdpos.L, maxdpos.C,
138  false );
139  }
140 
141  // Here: Table is pageing, so we must prepare the visible lines
142  // on the Pad before we're copying them to the destwin:
143  wsze lSze( 1, width() );
144  for ( int i = 0; i <= maxdpos.L; ++i )
145  {
146  directDraw( *this, wrect( wpos( i, 0 ), lSze ), srect.Pos.L+i );
147  }
148  return copywin( *destwin,
149  0, srect.Pos.C,
150  drect.Pos.L, drect.Pos.C,
151  maxdpos.L, maxdpos.C,
152  false );
153  }
154  return OK;
155 }
156 
157 
158 int NCPad::setpos( const wpos & newpos )
159 {
160  srect.Pos = newpos.between( 0, maxspos );
161  return update();
162 }
163 
164 
165 void NCPad::wRecoded()
166 {
167  yuiDebug() << "NCPad::wRecoded" << std::endl;
168 }
169 
170 
171 bool NCPad::handleInput( wint_t key )
172 {
173  bool handled = true;
174 
175  switch ( key )
176  {
177  case KEY_UP:
178  ScrlUp();
179  break;
180 
181  case KEY_PPAGE:
182  ScrlUp( destwin->maxy() );
183  break;
184 
185  case KEY_HOME:
186  ScrlUp( vheight() );
187  break;
188 
189  case KEY_DOWN:
190  ScrlDown();
191  break;
192 
193  case KEY_NPAGE:
194  ScrlDown( destwin->maxy() );
195  break;
196 
197  case KEY_END:
198  ScrlDown( vheight() );
199  break;
200 
201  case KEY_LEFT:
202  case KEY_SLEFT:
203  ScrlLeft();
204  break;
205 
206  case KEY_RIGHT:
207  case KEY_SRIGHT:
208  ScrlRight();
209  break;
210 
211  default:
212  handled = false;
213  break;
214  }
215 
216  return handled;
217 }
C++ class for windows.
Definition: ncursesw.h:904
virtual void directDraw(NCursesWindow &w, const wrect at, unsigned lineno)
Definition: NCPad.h:151
Definition: position.h:109
int copywin(NCursesWindow &win, int sminrow, int smincol, int dminrow, int dmincol, int dmaxrow, int dmaxcol, bool overlay=TRUE)
Definition: ncursesw.h:1740
int height() const
Definition: ncursesw.h:1070
int maxy() const
Definition: ncursesw.h:1095
int vheight() const
Definition: NCPad.h:126
Definition: position.h:154
int width() const
Definition: ncursesw.h:1075
bool pageing() const
Definition: NCPad.h:129