libyui-ncurses  2.44.1
 All Classes Functions Variables
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 
35 {
36 public:
37 
38  virtual ~NCSchrollCB() {}
39 
40  virtual void HScroll( unsigned total, unsigned visible, unsigned start ) {}
41 
42  virtual void VScroll( unsigned total, unsigned visible, unsigned start ) {}
43 
44  virtual void ScrollHead( NCursesWindow & w, unsigned ccol ) {}
45 
46  virtual void AdjustPadSize( wsze & minsze ) {}
47 };
48 
49 
50 class NCScrollHint : protected NCSchrollCB
51 {
52 private:
53 
54  NCSchrollCB * redirect;
55 
56 protected:
57 
58  NCScrollHint() : redirect( this ) {}
59 
60  virtual ~NCScrollHint() {}
61 
62 protected:
63 
64  virtual void SetHead( NCursesWindow & w, unsigned ccol )
65  {
66  redirect->ScrollHead( w, ccol );
67  }
68 
69  void VSet( unsigned total, unsigned visible, unsigned start )
70  {
71  redirect->VScroll( total, visible, start );
72  }
73 
74  void HSet( unsigned total, unsigned visible, unsigned start )
75  {
76  redirect->HScroll( total, visible, start );
77  }
78 
79  virtual void SetPadSize( wsze & minsze )
80  {
81  redirect->AdjustPadSize( minsze );
82  }
83 
84 public:
85 
86  // set redirect
87  void SendSchrollCB( NCSchrollCB * to ) { redirect = ( to ? to : this ); }
88 
89  virtual void SendHead() {}
90 };
91 
92 
93 class NCPad : public NCursesPad, public NCScrollHint
94 {
95 private:
96 
97  /** The real height in case the NCursesPad is truncated, otherwise \c 0.
98  *
99  * \note Don't use _vheight directly, but \ref vheight.
100  *
101  * Up to ncurses5, ncurses uses \c short for window dimensions (can't hold
102  * more than 32768 lines). If \ref resize truncated the window, the real
103  * size is in \ref _vheight. Longer lists need to be paged.
104  *
105  * \todo Once all NCPad based types are able to page, \a maxPadHeight could be
106  * std::set to e.g \c 1024 to avoid bigger widgets in memory. Currently just
107  * \ref NCTablePad supports paging. If paging is \c ON, all content lines are
108  * written via \ref directDraw. Without pageing \ref DoRedraw is reponsible for this.
109  */
110  int _vheight;
111 
112 protected:
113 
114  const NCWidget & parw;
115 
116  NCursesWindow * destwin;
117  wrect drect;
118  wrect srect;
119  wpos maxdpos;
120  wpos maxspos;
121 
122  bool dclear;
123  bool dirty;
124 
125  /** The (virtual) height of the Pad (even if truncated). */
126  int vheight() const { return _vheight ? _vheight : height(); }
127 
128  /** Whether the Pad is truncated (we're pageing). */
129  bool pageing() const { return _vheight; }
130 
131  virtual int dirtyPad() { dirty = false; return setpos( CurPos() ); }
132 
133  virtual int setpos( const wpos & newpos );
134 
135  int adjpos( const wpos & offset )
136  {
137  return setpos( CurPos() + offset );
138  }
139 
140  virtual void updateScrollHint();
141 
142  /** Directly draw a table item at a specific location.
143  *
144  * \ref update usually copies the visible table content from the
145  * \ref NCursesPad to \ref destwin. In case the \ref NCursesPad
146  * is truncated, the visible lines are prepared immediately before
147  * they are written to \ref destwin
148  * .
149  * \see \ref _vheight.
150  */
151  virtual void directDraw( NCursesWindow & w, const wrect at, unsigned lineno ) {}
152 
153 public:
154 
155  NCPad( int lines, int cols, const NCWidget & p );
156  virtual ~NCPad() {}
157 
158 public:
159 
160  NCursesWindow * Destwin() { return destwin; }
161 
162  virtual void Destwin( NCursesWindow * dwin );
163 
164  virtual void resize( wsze nsze );
165  virtual void wRecoded();
166  virtual void setDirty() { dirty = true; }
167 
168  int update();
169  virtual int setpos() { return setpos( CurPos() ); }
170 
171  virtual wpos CurPos() const { return srect.Pos; }
172 
173  int ScrlTo( const wpos & newpos )
174  {
175  return setpos( newpos );
176  }
177 
178  int ScrlLine( const int line )
179  {
180  return setpos( wpos( line, srect.Pos.C ) );
181  }
182 
183  int ScrlCol( const int col )
184  {
185  return setpos( wpos( srect.Pos.L, col ) );
186  }
187 
188  int ScrlDown( const int lines = 1 )
189  {
190  return adjpos( wpos( lines, 0 ) );
191  }
192 
193  int ScrlUp( const int lines = 1 )
194  {
195  return adjpos( wpos( -lines, 0 ) );
196  }
197 
198  int ScrlRight( const int cols = 1 )
199  {
200  return adjpos( wpos( 0, cols ) );
201  }
202 
203  int ScrlLeft( const int cols = 1 )
204  {
205  return adjpos( wpos( 0, -cols ) );
206  }
207 
208  virtual bool handleInput( wint_t key );
209 };
210 
211 
212 #endif // NCPad_h
C++ class for windows.
Definition: ncursesw.h:904
virtual void directDraw(NCursesWindow &w, const wrect at, unsigned lineno)
Definition: NCPad.h:151
static int lines()
Definition: ncursesw.h:1042
Definition: NCPad.h:93
static int cols()
Definition: ncursesw.h:1047
Definition: position.h:109
int height() const
Definition: ncursesw.h:1070
int vheight() const
Definition: NCPad.h:126
Definition: position.h:154
WINDOW * w
Definition: ncursesw.h:947
bool pageing() const
Definition: NCPad.h:129