00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00036
00037
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
00117
00119
00120
00121
00122
00123
00124 class NCTableCol {
00125
00126 friend std::ostream & operator<<( std::ostream & STREAM, const NCTableCol & OBJ );
00127
00128 public:
00129
00130 enum STYLE {
00131 NONE = 0,
00132 PLAIN,
00133 DATA,
00134 ACTIVEDATA,
00135 HINT,
00136 SEPARATOR
00137 };
00138
00139 private:
00140
00141 NClabel label;
00142 STYLE style;
00143
00144 public:
00145
00146 NCTableCol( const NCstring & l = "", const STYLE & st = ACTIVEDATA );
00147 virtual ~NCTableCol();
00148
00149 const NClabel & Label() const { return label; }
00150 virtual void SetLabel( const NClabel & l ) { label = l; }
00151
00152 protected:
00153
00154 chtype setBkgd( NCursesWindow & w,
00155 NCTableStyle & tableStyle,
00156 NCTableLine::STATE linestate,
00157 STYLE colstyle ) const ;
00158
00159 public:
00160
00161 virtual wsze Size() const { return wsze( 1, label.width() ); }
00162
00163 virtual void DrawAt( NCursesWindow & w, const wrect at,
00164 NCTableStyle & tableStyle,
00165 NCTableLine::STATE linestate,
00166 unsigned colidx ) const;
00167
00168 bool hasHotkey() const { return label.hasHotkey(); }
00169 unsigned char hotkey() const { return label.hotkey(); }
00170 };
00171
00173
00175
00176
00177
00178
00179
00180 class NCTableHead : public NCTableLine {
00181
00182 public:
00183
00184 NCTableHead( unsigned cols ) : NCTableLine( cols ) {}
00185 NCTableHead( vector<NCTableCol*> & nItems ) : NCTableLine( nItems ) {}
00186 virtual ~NCTableHead() {}
00187
00188 public:
00189
00190 virtual void DrawAt( NCursesWindow & w, const wrect at,
00191 NCTableStyle & tableStyle,
00192 bool active ) const;
00193 };
00194
00196
00198
00199
00200
00201
00202
00203 class NCTableStyle {
00204
00205 friend std::ostream & operator<<( std::ostream & STREAM, const NCTableStyle & OBJ );
00206
00207 private:
00208
00209 NCTableHead headline;
00210 vector<unsigned> colWidht;
00211 vector<NC::ADJUST> colAdjust;
00212
00213 const NCWidget & parw;
00214
00215 unsigned colSepwidht;
00216 chtype colSepchar;
00217 unsigned hotCol;
00218
00219 public:
00220
00221 static const chtype currentBG = (chtype)-1;
00222
00223 NCTableStyle( const NCWidget & p );
00224 ~NCTableStyle() {}
00225
00226 bool SetStyleFrom( const vector<NCstring> & head );
00227 void SetSepChar( const chtype sepchar ) { colSepchar = sepchar; }
00228 void SetSepWidht( const unsigned sepwidth ) { colSepwidht = sepwidth; }
00229 void SetHotCol( const int hcol ) {
00230 hotCol = (hcol < 0 || Cols() <= (unsigned)hcol) ? -1 : hcol;
00231 }
00232
00233 void ResetToMinCols() {
00234 colWidht.clear();
00235 AssertMinCols( headline.Cols() );
00236 headline.UpdateFormat( *this );
00237 }
00238
00239 void AssertMinCols( unsigned num ) {
00240 if ( colWidht.size() < num ) {
00241 colWidht.resize( num, 0 );
00242 colAdjust.resize( colWidht.size(), NC::LEFT );
00243 }
00244 }
00245
00246 void MinColWidht( unsigned num, unsigned val ) {
00247 AssertMinCols( num );
00248 if ( val > colWidht[num] )
00249 colWidht[num] = val;
00250 }
00251
00252 NC::ADJUST ColAdjust( unsigned num ) const { return colAdjust[num]; }
00253
00254 unsigned Cols() const { return colWidht.size(); }
00255 unsigned ColWidht( unsigned num ) const { return colWidht[num]; }
00256 unsigned ColSepwidht() const { return colSepwidht; }
00257 chtype ColSepchar() const { return colSepchar; }
00258 unsigned HotCol() const { return hotCol; }
00259
00260 const NCstyle::StList & listStyle() const { return parw.listStyle(); }
00261
00262 chtype getBG() const { return listStyle().item.plain; }
00263
00264 chtype getBG( const NCTableLine::STATE lstate,
00265 const NCTableCol::STYLE cstyle = NCTableCol::PLAIN ) const;
00266
00267 chtype highlightBG( const NCTableLine::STATE lstate,
00268 const NCTableCol::STYLE cstyle,
00269 const NCTableCol::STYLE dstyle = NCTableCol::PLAIN ) const ;
00270
00271 chtype hotBG( const NCTableLine::STATE lstate, unsigned colidx ) const {
00272 return (colidx == hotCol) ? getBG( lstate, NCTableCol::HINT ) : currentBG;
00273 }
00274
00275 const NCTableLine & Headline() const { return headline; }
00276
00277 unsigned TableWidth() const {
00278 unsigned twidth = 0;
00279 for( unsigned i = 0; i < Cols(); ++i )
00280 twidth += colWidht[i];
00281 if ( Cols() > 1 )
00282 twidth += colSepwidht * (Cols()-1);
00283 return twidth;
00284 }
00285 };
00286
00288
00289 #endif // NCTableItem_h