libyui-ncurses  2.44.1
/usr/src/RPM/BUILD/libyui-ncurses-2.44.1/src/NCPad.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019    File:       NCPad.h
00020 
00021    Author:     Michael Andres <ma@suse.de>
00022 
00023 /-*/
00024 
00025 #ifndef NCPad_h
00026 #define NCPad_h
00027 
00028 #include <iosfwd>
00029 
00030 #include "NCurses.h"
00031 #include "NCWidget.h"
00032 
00033 
00034 class NCSchrollCB
00035 {
00036 public:
00037 
00038     virtual ~NCSchrollCB() {}
00039 
00040     virtual void HScroll( unsigned total, unsigned visible, unsigned start ) {}
00041 
00042     virtual void VScroll( unsigned total, unsigned visible, unsigned start ) {}
00043 
00044     virtual void ScrollHead( NCursesWindow & w, unsigned ccol ) {}
00045 
00046     virtual void AdjustPadSize( wsze & minsze ) {}
00047 };
00048 
00049 
00050 class NCScrollHint : protected NCSchrollCB
00051 {
00052 private:
00053 
00054     NCSchrollCB * redirect;
00055 
00056 protected:
00057 
00058     NCScrollHint() : redirect( this ) {}
00059 
00060     virtual ~NCScrollHint() {}
00061 
00062 protected:
00063 
00064     virtual void SetHead( NCursesWindow & w, unsigned ccol )
00065     {
00066         redirect->ScrollHead( w, ccol );
00067     }
00068 
00069     void VSet( unsigned total, unsigned visible, unsigned start )
00070     {
00071         redirect->VScroll( total, visible, start );
00072     }
00073 
00074     void HSet( unsigned total, unsigned visible, unsigned start )
00075     {
00076         redirect->HScroll( total, visible, start );
00077     }
00078 
00079     virtual void SetPadSize( wsze & minsze )
00080     {
00081         redirect->AdjustPadSize( minsze );
00082     }
00083 
00084 public:
00085 
00086     // set redirect
00087     void SendSchrollCB( NCSchrollCB * to ) { redirect = ( to ? to : this ); }
00088 
00089     virtual void SendHead() {}
00090 };
00091 
00092 
00093 class NCPad : public NCursesPad, public NCScrollHint
00094 {
00095 private:
00096 
00097     /** The real height in case the NCursesPad is truncated, otherwise \c 0.
00098      *
00099      * \note Don't use _vheight directly, but \ref vheight.
00100      *
00101      * Up to ncurses5, ncurses uses \c short for window dimensions (can't hold
00102      * more than 32768 lines). If \ref resize truncated the window, the real
00103      * size is in \ref _vheight. Longer lists need to be paged.
00104      *
00105      * \todo Once all NCPad based types are able to page, \a maxPadHeight could be
00106      * std::set to e.g \c 1024 to avoid bigger widgets in memory. Currently just
00107      * \ref NCTablePad supports paging. If paging is \c ON, all content lines are
00108      * written via \ref directDraw. Without pageing \ref DoRedraw is reponsible for this.
00109      */
00110     int   _vheight;
00111 
00112 protected:
00113 
00114     const NCWidget & parw;
00115 
00116     NCursesWindow * destwin;
00117     wrect drect;
00118     wrect srect;
00119     wpos  maxdpos;
00120     wpos  maxspos;
00121 
00122     bool  dclear;
00123     bool  dirty;
00124 
00125     /** The (virtual) height of the Pad (even if truncated). */
00126     int vheight() const        { return _vheight ? _vheight : height(); }
00127 
00128     /** Whether the Pad is truncated (we're pageing). */
00129     bool pageing() const { return _vheight; }
00130 
00131     virtual int dirtyPad() { dirty = false; return setpos( CurPos() ); }
00132 
00133     virtual int setpos( const wpos & newpos );
00134 
00135     int adjpos( const wpos & offset )
00136     {
00137         return setpos( CurPos() + offset );
00138     }
00139 
00140     virtual void updateScrollHint();
00141 
00142     /** Directly draw a table item at a specific location.
00143      *
00144      * \ref update usually copies the visible table content from the
00145      * \ref NCursesPad to \ref destwin. In case the \ref NCursesPad
00146      * is truncated, the visible lines are prepared immediately before
00147      * they are written to \ref destwin
00148      * .
00149      * \see \ref _vheight.
00150      */
00151     virtual void directDraw( NCursesWindow & w, const wrect at, unsigned lineno ) {}
00152 
00153 public:
00154 
00155     NCPad( int lines, int cols, const NCWidget & p );
00156     virtual ~NCPad() {}
00157 
00158 public:
00159 
00160     NCursesWindow * Destwin() { return destwin; }
00161 
00162     virtual void Destwin( NCursesWindow * dwin );
00163 
00164     virtual void resize( wsze nsze );
00165     virtual void wRecoded();
00166     virtual void setDirty() { dirty = true; }
00167 
00168     int update();
00169     virtual int setpos() { return setpos( CurPos() ); }
00170 
00171     virtual wpos CurPos() const { return srect.Pos; }
00172 
00173     int ScrlTo( const wpos & newpos )
00174     {
00175         return setpos( newpos );
00176     }
00177 
00178     int ScrlLine( const int line )
00179     {
00180         return setpos( wpos( line, srect.Pos.C ) );
00181     }
00182 
00183     int ScrlCol( const int col )
00184     {
00185         return setpos( wpos( srect.Pos.L, col ) );
00186     }
00187 
00188     int ScrlDown( const int lines = 1 )
00189     {
00190         return adjpos( wpos( lines, 0 ) );
00191     }
00192 
00193     int ScrlUp( const int lines = 1 )
00194     {
00195         return adjpos( wpos( -lines, 0 ) );
00196     }
00197 
00198     int ScrlRight( const int cols = 1 )
00199     {
00200         return adjpos( wpos( 0, cols ) );
00201     }
00202 
00203     int ScrlLeft( const int cols = 1 )
00204     {
00205         return adjpos( wpos( 0, -cols ) );
00206     }
00207 
00208     virtual bool handleInput( wint_t key );
00209 };
00210 
00211 
00212 #endif // NCPad_h
 All Classes Functions Variables