libyui-ncurses
Loading...
Searching...
No Matches
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{
37public:
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
60class NCScrollHint : protected NCSchrollCB
61{
62private:
63
64 NCSchrollCB * redirect;
65
66protected:
67
68 NCScrollHint() : redirect( this ) {}
69
70 virtual ~NCScrollHint() {}
71
72protected:
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
94public:
95
97 void SendSchrollCB( NCSchrollCB * dest ) { redirect = ( dest ? dest : this ); }
98
99 virtual void SendHead() {}
100};
101
102
112class NCPad : public NCursesPad, public NCScrollHint
113{
114private:
115
129 int _vheight;
130
131protected:
132
133 const NCWidget & parw;
134
137 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
175public:
176
178 NCPad( int lines, int cols, const NCWidget & p );
179 virtual ~NCPad() {}
180
181public:
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
Definition NCPad.h:113
int adjpos(const wpos &offset)
Adjust CurPos relatively by offset
Definition NCPad.h:157
int vheight() const
Definition NCPad.h:146
bool dclear
should destwin be cleared before contents is copied there
Definition NCPad.h:142
int ScrlLine(int line)
Scroll to a line, keeping the column.
Definition NCPad.h:206
wrect srect
Source rectangle: the visible part of this pad.
Definition NCPad.h:138
NCursesWindow * destwin
Destination rectangle: (Pos is always 0, 0)
Definition NCPad.h:135
virtual int setpos(const wpos &newpos)
Set the visible position to newpos (but clamp by maxspos), then update.
Definition NCPad.cc:158
bool paging() const
Definition NCPad.h:149
virtual void directDraw(NCursesWindow &w, const wrect at, unsigned lineno)
Definition NCPad.h:173
int ScrlCol(int col)
Scroll to a column, keeping the line.
Definition NCPad.h:212
Interface for scroll callbacks.
Definition NCPad.h:36
virtual void HScroll(unsigned total, unsigned visible, unsigned start)
Definition NCPad.h:44
virtual void VScroll(unsigned total, unsigned visible, unsigned start)
Definition NCPad.h:49
Definition NCPad.h:61
void SendSchrollCB(NCSchrollCB *dest)
Set the receiver of callbacks to dest
Definition NCPad.h:97
Definition NCWidget.h:46
Definition ncursesw.h:1832
C++ class for windows.
Definition ncursesw.h:907
WINDOW * w
Definition ncursesw.h:949
static int lines()
Definition ncursesw.h:1044
static int cols()
Definition ncursesw.h:1049
int height() const
Definition ncursesw.h:1072
Screen position pair in the order line, column: (L, C)
Definition position.h:110
A rectangle is defined by its position and size: wpos Pos, wsze Sze.
Definition position.h:194
Screen dimension (screen size) in the order height, width: (H, W)
Definition position.h:154