libyui-ncurses
NCPad.h
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.h
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #ifndef NCPad_h
26 #define NCPad_h
27 
28 #include <iosfwd>
29 
30 #include "NCurses.h"
31 #include "NCWidget.h"
32 
33 
36 {
37 public:
38 
39  virtual ~NCSchrollCB() {}
40 
44  virtual void HScroll( unsigned total, unsigned visible, unsigned start ) {}
45 
49  virtual void VScroll( unsigned total, unsigned visible, unsigned start ) {}
50 
51  virtual void ScrollHead( NCursesWindow & w, unsigned ccol ) {}
52 
53  virtual void AdjustPadSize( wsze & minsze ) {}
54 };
55 
60 class NCScrollHint : protected NCSchrollCB
61 {
62 private:
63 
64  NCSchrollCB * redirect;
65 
66 protected:
67 
68  NCScrollHint() : redirect( this ) {}
69 
70  virtual ~NCScrollHint() {}
71 
72 protected:
73 
74  virtual void SetHead( NCursesWindow & w, unsigned ccol )
75  {
76  redirect->ScrollHead( w, ccol );
77  }
78 
79  void VSet( unsigned total, unsigned visible, unsigned start )
80  {
81  redirect->VScroll( total, visible, start );
82  }
83 
84  void HSet( unsigned total, unsigned visible, unsigned start )
85  {
86  redirect->HScroll( total, visible, start );
87  }
88 
89  virtual void SetPadSize( wsze & minsze )
90  {
91  redirect->AdjustPadSize( minsze );
92  }
93 
94 public:
95 
97  void SendSchrollCB( NCSchrollCB * dest ) { redirect = ( dest ? dest : this ); }
98 
99  virtual void SendHead() {}
100 };
101 
102 
112 class NCPad : public NCursesPad, public NCScrollHint
113 {
114 private:
115 
129  int _vheight;
130 
131 protected:
132 
133  const NCWidget & parw;
134 
136  wrect drect;
139  wpos maxdpos;
140  wpos maxspos;
141 
142  bool dclear;
143  bool dirty;
144 
146  int vheight() const { return _vheight ? _vheight : height(); }
147 
149  bool paging() const { return _vheight; }
150 
151  virtual int dirtyPad() { dirty = false; return setpos( CurPos() ); }
152 
154  virtual int setpos( const wpos & newpos );
155 
157  int adjpos( const wpos & offset )
158  {
159  return setpos( CurPos() + offset );
160  }
161 
162  virtual void updateScrollHint();
163 
173  virtual void directDraw( NCursesWindow & w, const wrect at, unsigned lineno ) {}
174 
175 public:
176 
178  NCPad( int lines, int cols, const NCWidget & p );
179  virtual ~NCPad() {}
180 
181 public:
182 
183  NCursesWindow * Destwin() { return destwin; }
184 
186  virtual void Destwin( NCursesWindow * dwin );
187 
188  virtual void resize( wsze nsze );
189  // OMFG this little overload does something completely different than
190  // the one above
191  virtual int resize( int lines, int columns ) { return NCursesWindow::resize(lines, columns );}
192  virtual void wRecoded();
193  virtual void setDirty() { dirty = true; }
194 
195  int update();
196  virtual int setpos() { return setpos( CurPos() ); }
197 
198  virtual wpos CurPos() const { return srect.Pos; }
199 
200  int ScrlTo( const wpos & newpos )
201  {
202  return setpos( newpos );
203  }
204 
206  int ScrlLine( int line )
207  {
208  return setpos( wpos( line, srect.Pos.C ) );
209  }
210 
212  int ScrlCol( int col )
213  {
214  return setpos( wpos( srect.Pos.L, col ) );
215  }
216 
217  int ScrlDown( int lines = 1 )
218  {
219  return adjpos( wpos( lines, 0 ) );
220  }
221 
222  int ScrlUp( int lines = 1 )
223  {
224  return adjpos( wpos( -lines, 0 ) );
225  }
226 
227  int ScrlRight( int cols = 1 )
228  {
229  return adjpos( wpos( 0, cols ) );
230  }
231 
232  int ScrlLeft( int cols = 1 )
233  {
234  return adjpos( wpos( 0, -cols ) );
235  }
236 
237  int ScrlToLastLine()
238  {
239  return ScrlDown( vheight() );
240  }
241 
242  virtual bool handleInput( wint_t key );
243 };
244 
245 
246 #endif // NCPad_h
C++ class for windows.
Definition: ncursesw.h:906
void SendSchrollCB(NCSchrollCB *dest)
Set the receiver of callbacks to dest
Definition: NCPad.h:97
virtual void directDraw(NCursesWindow &w, const wrect at, unsigned lineno)
Definition: NCPad.h:173
int ScrlLine(int line)
Scroll to a line, keeping the column.
Definition: NCPad.h:206
int vheight() const
Definition: NCPad.h:146
static int lines()
Definition: ncursesw.h:1044
int height() const
Definition: ncursesw.h:1072
Definition: NCPad.h:112
static int cols()
Definition: ncursesw.h:1049
int adjpos(const wpos &offset)
Adjust CurPos relatively by offset
Definition: NCPad.h:157
NCursesWindow * destwin
Destination rectangle: (Pos is always 0, 0)
Definition: NCPad.h:135
Screen position pair in the order line, column: (L, C)
Definition: position.h:109
Definition: NCPad.h:60
virtual void HScroll(unsigned total, unsigned visible, unsigned start)
Definition: NCPad.h:44
NCPad(int lines, int cols, const NCWidget &p)
Definition: NCPad.cc:40
Interface for scroll callbacks.
Definition: NCPad.h:35
virtual int setpos(const wpos &newpos)
Set the visible position to newpos (but clamp by maxspos), then update.
Definition: NCPad.cc:158
A rectangle is defined by its position and size: wpos Pos, wsze Sze.
Definition: position.h:193
wrect srect
Source rectangle: the visible part of this pad.
Definition: NCPad.h:138
virtual void VScroll(unsigned total, unsigned visible, unsigned start)
Definition: NCPad.h:49
Screen dimension (screen size) in the order height, width: (H, W)
Definition: position.h:153
Definition: NCWidget.h:45
WINDOW * w
Definition: ncursesw.h:949
bool paging() const
Definition: NCPad.h:149
Definition: ncursesw.h:1831
int ScrlCol(int col)
Scroll to a column, keeping the line.
Definition: NCPad.h:212
bool dclear
should destwin be cleared before contents is copied there
Definition: NCPad.h:142