00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef NCPad_h
00020 #define NCPad_h
00021
00022 #include <iosfwd>
00023
00024 #include "NCurses.h"
00025 #include "NCWidget.h"
00026
00028
00029
00030
00031
00032
00033 class NCSchrollCB {
00034
00035 public:
00036
00037 virtual ~NCSchrollCB () {}
00038
00039
00040 virtual void HScroll( unsigned total, unsigned visible, unsigned start ) {}
00041 virtual void VScroll( unsigned total, unsigned visible, unsigned start ) {}
00042
00043 virtual void ScrollHead( NCursesWindow & w, unsigned ccol ) {}
00044
00045
00046 virtual void AdjustPadSize( wsze & minsze ) {}
00047 };
00048
00050
00051
00052
00053
00054
00055 class NCScrollHint : protected NCSchrollCB {
00056
00057 private:
00058
00059 NCSchrollCB * redirect;
00060
00061 protected:
00062
00063 NCScrollHint() : redirect( this ) {}
00064 virtual ~NCScrollHint() {}
00065
00066 protected:
00067
00068 virtual void SetHead( NCursesWindow & w, unsigned ccol ) {
00069 redirect->ScrollHead( w, ccol );
00070 }
00071
00072 void VSet( unsigned total, unsigned visible, unsigned start ) {
00073 redirect->VScroll( total, visible, start );
00074 }
00075
00076 void HSet( unsigned total, unsigned visible, unsigned start ) {
00077 redirect->HScroll( total, visible, start );
00078 }
00079
00080 virtual void SetPadSize( wsze & minsze ) {
00081 redirect->AdjustPadSize( minsze );
00082 }
00083
00084 public:
00085
00086
00087 void SendSchrollCB( NCSchrollCB * to ) { redirect = ( to ? to : this ); }
00088
00089 virtual void SendHead() {}
00090 };
00091
00093
00094
00095
00096
00097
00098 class NCPad : public NCursesPad, public NCScrollHint {
00099
00100 protected:
00101
00102 const NCWidget & parw;
00103
00104 NCursesWindow * destwin;
00105 wrect drect;
00106 wrect srect;
00107 wpos maxdpos;
00108 wpos maxspos;
00109
00110 bool dclear;
00111 bool dirty;
00112
00113 protected:
00114
00115 virtual int dirtyPad() { dirty = false; return setpos( CurPos() ); }
00116 virtual int setpos( const wpos & newpos );
00117
00118 int adjpos( const wpos & offset ) {
00119 return setpos( CurPos() + offset );
00120 }
00121
00122 virtual void updateScrollHint();
00123
00124 public:
00125
00126 NCPad( int lines, int cols, const NCWidget & p )
00127 : NCursesPad( lines, cols )
00128 , parw( p )
00129 , destwin ( 0 )
00130 , maxdpos ( 0 )
00131 , maxspos ( 0 )
00132 , dclear ( false )
00133 , dirty ( false )
00134 {}
00135 virtual ~NCPad() {}
00136
00137 public:
00138
00139 NCursesWindow * Destwin() { return destwin; }
00140 virtual void Destwin( NCursesWindow * dwin );
00141
00142 virtual void resize( wsze nsze );
00143 virtual void wRecoded();
00144 virtual void setDirty() { dirty = true; }
00145
00146 int update();
00147 virtual int setpos() { return setpos( CurPos() ); }
00148
00149 virtual wpos CurPos() const { return srect.Pos; }
00150
00151 int ScrlTo( const wpos & newpos ) {
00152 return setpos( newpos );
00153 }
00154
00155 int ScrlLine( const int line ) {
00156 return setpos( wpos( line, srect.Pos.C ) );
00157 }
00158
00159 int ScrlCol( const int col ) {
00160 return setpos( wpos( srect.Pos.L, col ) );
00161 }
00162
00163 int ScrlDown( const int lines = 1 ) {
00164 return adjpos( wpos( lines, 0 ) );
00165 }
00166
00167 int ScrlUp( const int lines = 1 ) {
00168 return adjpos( wpos( -lines, 0 ) );
00169 }
00170
00171 int ScrlRight( const int cols = 1 ) {
00172 return adjpos( wpos( 0, cols ) );
00173 }
00174
00175 int ScrlLeft( const int cols = 1 ) {
00176 return adjpos( wpos( 0, -cols ) );
00177 }
00178
00179 virtual bool handleInput( wint_t key );
00180 };
00181
00183
00184 #endif // NCPad_h