Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

NCPad.h

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

Generated on Wed Sep 5 17:18:55 2007 for yast2-ncurses by doxygen 1.3.6