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

NCTableItem.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:       NCTableItem.h
00014 
00015    Author:     Michael Andres <ma@suse.de>
00016    Maintainer: Michael Andres <ma@suse.de>
00017 
00018 /-*/
00019 #ifndef NCTableItem_h
00020 #define NCTableItem_h
00021 
00022 #include <iosfwd>
00023 
00024 #include <vector>
00025 using namespace std;
00026 
00027 #include "position.h"
00028 #include "NCWidget.h"
00029 
00030 class NCTableStyle;
00031 class NCTableCol;
00032 
00034 //
00035 //      CLASS NAME : NCTableLine
00036 //
00037 //      DESCRIPTION :
00038 //
00039 class NCTableLine {
00040 
00041   friend std::ostream & operator<<( std::ostream & STREAM, const NCTableLine & OBJ );
00042 
00043   NCTableLine & operator=( const NCTableLine & );
00044   NCTableLine            ( const NCTableLine & );
00045 
00046   public:
00047 
00048     enum STATE {
00049       S_NORMAL    = 0x00,
00050       S_ACTIVE    = 0x01,
00051       S_DISABELED = 0x10,
00052       S_HIDDEN    = 0x20,
00053       S_HEADLINE  = 0x40
00054     };
00055 
00056   private:
00057 
00058     vector<NCTableCol*> Items;
00059     void assertCol( unsigned idx );
00060 
00061     unsigned state;
00062 
00063   protected:
00064 
00065     mutable STATE vstate;
00066     virtual void DrawItems( NCursesWindow & w, const wrect at,
00067                             NCTableStyle & tableStyle,
00068                             bool active ) const;
00069 
00070   public:
00071 
00072     NCTableLine( unsigned cols, const unsigned s = S_NORMAL );
00073     NCTableLine( vector<NCTableCol*> & nItems, const unsigned s = S_NORMAL );
00074     virtual ~NCTableLine();
00075 
00076     unsigned Cols() const { return Items.size(); }
00077     void     SetCols( unsigned idx );
00078     void     SetCols( vector<NCTableCol*> & nItems );
00079     void     ClearLine()  { SetCols( 0 ); }
00080     vector<NCTableCol*> GetItems() const { return Items; }
00081     
00082     void Append( NCTableCol * item ) { AddCol( Cols(), item ); }
00083     void AddCol( unsigned idx, NCTableCol * item );
00084     void DelCol( unsigned idx );
00085 
00086     NCTableCol *       GetCol( unsigned idx );
00087     const NCTableCol * GetCol( unsigned idx ) const {
00088       return const_cast<NCTableLine*>(this)->GetCol( idx );
00089     }
00090 
00091     void  SetState  ( const STATE s ) { state |= s; }
00092     void  ClearState( const STATE s ) { state &= ~s; }
00093 
00094     bool  isHidden() const    { return (state & S_HIDDEN); }
00095     bool  isDisabeled() const { return (state & S_DISABELED); }
00096     bool  isSpecial() const   { return (state & (S_HIDDEN | S_DISABELED)); }
00097     bool  isActive() const    { return (state & S_ACTIVE); }
00098 
00099     virtual bool isVisible() const  { return !isHidden(); }
00100     virtual bool isEnabeled() const { return isVisible() && !isDisabeled(); }
00101 
00102   public:
00103 
00104     virtual int  handleInput( wint_t key ) { return 0; }
00105     virtual int  ChangeToVisible()      { return 0; }
00106 
00107     virtual unsigned Hotspot( unsigned & at ) const { at = 0; return 0; }
00108 
00109     virtual void UpdateFormat( NCTableStyle & TableStyle );
00110 
00111     virtual void DrawAt( NCursesWindow & w, const wrect at,
00112                          NCTableStyle & tableStyle,
00113                          bool active ) const;
00114 
00115     void stripHotkeys();
00116 };
00117 
00119 
00121 //
00122 //      CLASS NAME : NCTableCol
00123 //
00124 //      DESCRIPTION :
00125 //
00126 class NCTableCol {
00127 
00128   friend std::ostream & operator<<( std::ostream & STREAM, const NCTableCol & OBJ );
00129 
00130   public:
00131 
00132     enum STYLE {
00133       NONE = 0,    // use current bg
00134       PLAIN,       // plain text
00135       DATA,        // data style
00136       ACTIVEDATA,  // data style if line active, else plain
00137       HINT,        // hint
00138       SEPARATOR    // separator
00139     };
00140 
00141   private:
00142 
00143     NClabel label;
00144     STYLE   style;
00145 
00146   public:
00147 
00148     NCTableCol( const NCstring & l = "", const STYLE & st = ACTIVEDATA );
00149     virtual ~NCTableCol();
00150 
00151     const NClabel & Label() const { return label; }
00152     virtual void SetLabel( const NClabel & l ) { label = l; }
00153     
00154     void stripHotkey(){ label.stripHotkey(); }
00155 
00156   protected:
00157 
00158     chtype setBkgd( NCursesWindow & w,
00159                     NCTableStyle & tableStyle,
00160                     NCTableLine::STATE linestate,
00161                     STYLE colstyle ) const ;
00162 
00163   public:
00164 
00165     virtual wsze Size() const { return wsze( 1, label.width()  ); }
00166 
00167     virtual void DrawAt( NCursesWindow & w, const wrect at,
00168                          NCTableStyle & tableStyle,
00169                          NCTableLine::STATE linestate,
00170                          unsigned colidx ) const;
00171 
00172     bool          hasHotkey() const { return label.hasHotkey(); }
00173     unsigned char hotkey()    const { return label.hotkey(); }
00174 };
00175 
00177 
00179 //
00180 //      CLASS NAME : NCTableHead
00181 //
00182 //      DESCRIPTION :
00183 //
00184 class NCTableHead : public NCTableLine {
00185 
00186   public:
00187 
00188     NCTableHead( unsigned cols )                : NCTableLine( cols )   {}
00189     NCTableHead( vector<NCTableCol*> & nItems ) : NCTableLine( nItems ) {}
00190     virtual ~NCTableHead() {}
00191 
00192   public:
00193 
00194     virtual void DrawAt( NCursesWindow & w, const wrect at,
00195                          NCTableStyle & tableStyle,
00196                          bool active ) const;
00197 };
00198 
00200 
00202 //
00203 //      CLASS NAME : NCTableStyle
00204 //
00205 //      DESCRIPTION :
00206 //
00207 class NCTableStyle {
00208 
00209   friend std::ostream & operator<<( std::ostream & STREAM, const NCTableStyle & OBJ );
00210 
00211   private:
00212 
00213     NCTableHead         headline;
00214     vector<unsigned>    colWidht;
00215     vector<NC::ADJUST>  colAdjust;
00216 
00217     const NCWidget & parw;
00218 
00219     unsigned colSepwidht;
00220     chtype   colSepchar;
00221     unsigned hotCol;
00222 
00223   public:
00224 
00225     static const chtype currentBG = (chtype)-1;
00226 
00227     NCTableStyle( const NCWidget & p );
00228     ~NCTableStyle() {}
00229 
00230     bool SetStyleFrom( const vector<NCstring> & head );
00231     void SetSepChar( const chtype sepchar )     { colSepchar = sepchar; }
00232     void SetSepWidht( const unsigned sepwidth ) { colSepwidht = sepwidth; }
00233     void SetHotCol( const int hcol )            {
00234       hotCol = (hcol < 0 || Cols() <= (unsigned)hcol) ? -1 : hcol;
00235     }
00236 
00237     void ResetToMinCols() {
00238       colWidht.clear();
00239       AssertMinCols( headline.Cols() );
00240       headline.UpdateFormat( *this );
00241     }
00242 
00243     void AssertMinCols( unsigned num ) {
00244       if ( colWidht.size() < num ) {
00245         colWidht.resize( num, 0 );
00246         colAdjust.resize( colWidht.size(), NC::LEFT );
00247       }
00248     }
00249 
00250     void MinColWidht( unsigned num, unsigned val ) {
00251       AssertMinCols( num );
00252       if ( val > colWidht[num] )
00253         colWidht[num] = val;
00254     }
00255 
00256     NC::ADJUST ColAdjust( unsigned num ) const { return colAdjust[num]; }
00257 
00258     unsigned Cols()                   const { return colWidht.size(); }
00259     unsigned ColWidht( unsigned num ) const { return colWidht[num]; }
00260     unsigned ColSepwidht()            const { return colSepwidht; }
00261     chtype   ColSepchar()             const { return colSepchar; }
00262     unsigned HotCol()                 const { return hotCol; }
00263 
00264     const NCstyle::StList & listStyle() const { return parw.listStyle(); }
00265 
00266     chtype getBG() const { return listStyle().item.plain; }
00267 
00268     chtype getBG( const NCTableLine::STATE lstate,
00269                   const NCTableCol::STYLE  cstyle = NCTableCol::PLAIN ) const;
00270 
00271     chtype highlightBG( const NCTableLine::STATE lstate,
00272                         const NCTableCol::STYLE  cstyle,
00273                         const NCTableCol::STYLE  dstyle = NCTableCol::PLAIN ) const ;
00274 
00275     chtype hotBG( const NCTableLine::STATE lstate, unsigned colidx ) const {
00276       return (colidx == hotCol) ? getBG( lstate, NCTableCol::HINT ) : currentBG;
00277     }
00278 
00279     const NCTableLine & Headline() const { return headline; }
00280 
00281     unsigned TableWidth() const {
00282       unsigned twidth = 0;
00283       for( unsigned i = 0; i < Cols(); ++i )
00284         twidth += colWidht[i];
00285       if ( Cols() > 1 )
00286         twidth += colSepwidht * (Cols()-1);
00287       return twidth;
00288     }
00289 };
00290 
00292 
00293 #endif // NCTableItem_h

Generated on Wed Sep 14 10:52:54 2005 for yast2-ncurses by  doxygen 1.4.4