libyui-ncurses  2.44.1
 All Classes Functions Variables
NCTableItem.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: NCTableItem.h
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #ifndef NCTableItem_h
26 #define NCTableItem_h
27 
28 #include <iosfwd>
29 #include <vector>
30 
31 #include "position.h"
32 #include "NCWidget.h"
33 #include <yui/YTableItem.h>
34 
35 class NCTableStyle;
36 class NCTableCol;
37 
38 
40 {
41 
42  friend std::ostream & operator<<( std::ostream & STREAM, const NCTableLine & OBJ );
43 
44  NCTableLine & operator=( const NCTableLine & );
45  NCTableLine( const NCTableLine & );
46 
47 public:
48 
49  enum STATE
50  {
51  S_NORMAL = 0x00,
52  S_ACTIVE = 0x01,
53  S_DISABELED = 0x10,
54  S_HIDDEN = 0x20,
55  S_HEADLINE = 0x40
56  };
57 
58 private:
59 
60  std::vector<NCTableCol*> Items;
61  void assertCol( unsigned idx );
62 
63  unsigned state;
64 
65  int index;
66 
67  YTableItem *yitem;
68 
69 protected:
70 
71  mutable STATE vstate;
72  virtual void DrawItems( NCursesWindow & w, const wrect at,
73  NCTableStyle & tableStyle,
74  bool active ) const;
75 
76 public:
77 
78  NCTableLine( unsigned cols, int index = -1, const unsigned s = S_NORMAL );
79  NCTableLine( std::vector<NCTableCol*> & nItems, int index = -1, const unsigned s = S_NORMAL );
80  void setOrigItem( YTableItem *it );
81  YTableItem *origItem() const { return yitem; }
82 
83  virtual ~NCTableLine();
84 
85  unsigned Cols() const { return Items.size(); }
86 
87  void SetCols( unsigned idx );
88  void SetCols( std::vector<NCTableCol*> & nItems );
89  void ClearLine() { SetCols( 0 ); }
90 
91  std::vector<NCTableCol*> GetItems() const { return Items; }
92 
93  void Append( NCTableCol * item ) { AddCol( Cols(), item ); }
94 
95  void AddCol( unsigned idx, NCTableCol * item );
96  void DelCol( unsigned idx );
97 
98  NCTableCol * GetCol( unsigned idx );
99  const NCTableCol * GetCol( unsigned idx ) const
100  {
101  return const_cast<NCTableLine*>( this )->GetCol( idx );
102  }
103 
104  void SetState( const STATE s ) { state |= s; }
105 
106  void ClearState( const STATE s ) { state &= ~s; }
107 
108  bool isHidden() const { return ( state & S_HIDDEN ); }
109 
110  bool isDisabeled() const { return ( state & S_DISABELED ); }
111 
112  bool isSpecial() const { return ( state & ( S_HIDDEN | S_DISABELED ) ); }
113 
114  bool isActive() const { return ( state & S_ACTIVE ); }
115 
116  virtual bool isVisible() const { return !isHidden(); }
117 
118  virtual bool isEnabeled() const { return isVisible() && !isDisabeled(); }
119 
120  int getIndex() const { return index; }
121 
122 public:
123 
124  virtual int handleInput( wint_t key ) { return 0; }
125 
126  virtual int ChangeToVisible() { return 0; }
127 
128  virtual unsigned Hotspot( unsigned & at ) const { at = 0; return 0; }
129 
130  virtual void UpdateFormat( NCTableStyle & TableStyle );
131 
132  virtual void DrawAt( NCursesWindow & w, const wrect at,
133  NCTableStyle & tableStyle,
134  bool active ) const;
135 
136  void stripHotkeys();
137 };
138 
139 
140 
142 {
143 
144  friend std::ostream & operator<<( std::ostream & STREAM, const NCTableCol & OBJ );
145 
146 public:
147 
148  enum STYLE
149  {
150  NONE = 0, // use current bg
151  PLAIN, // plain text
152  DATA, // data style
153  ACTIVEDATA, // data style if line active, else plain
154  HINT, // hint
155  SEPARATOR // separator
156  };
157 
158 private:
159 
160  NClabel label;
161  STYLE style;
162 
163 public:
164 
165  NCTableCol( const NCstring & l = "", const STYLE & st = ACTIVEDATA );
166  virtual ~NCTableCol();
167 
168  const NClabel & Label() const { return label; }
169 
170  virtual void SetLabel( const NClabel & l ) { label = l; }
171 
172  void stripHotkey() { label.stripHotkey(); }
173 
174 protected:
175 
176  chtype setBkgd( NCursesWindow & w,
177  NCTableStyle & tableStyle,
178  NCTableLine::STATE linestate,
179  STYLE colstyle ) const ;
180 
181 public:
182 
183  virtual wsze Size() const { return wsze( 1, label.width() ); }
184 
185  virtual void DrawAt( NCursesWindow & w, const wrect at,
186  NCTableStyle & tableStyle,
187  NCTableLine::STATE linestate,
188  unsigned colidx ) const;
189 
190  bool hasHotkey() const { return label.hasHotkey(); }
191 
192  unsigned char hotkey() const { return label.hotkey(); }
193 };
194 
195 
196 
197 class NCTableHead : public NCTableLine
198 {
199 
200 public:
201 
202  NCTableHead( unsigned cols ) : NCTableLine( cols ) {}
203 
204  NCTableHead( std::vector<NCTableCol*> & nItems ) : NCTableLine( nItems ) {}
205 
206  virtual ~NCTableHead() {}
207 
208 public:
209 
210  virtual void DrawAt( NCursesWindow & w, const wrect at,
211  NCTableStyle & tableStyle,
212  bool active ) const;
213 };
214 
215 
216 
218 {
219 
220  friend std::ostream & operator<<( std::ostream & STREAM, const NCTableStyle & OBJ );
221 
222 private:
223 
224  NCTableHead headline;
225  std::vector<unsigned> colWidth;
226  std::vector<NC::ADJUST> colAdjust;
227 
228  const NCWidget & parw;
229 
230  unsigned colSepwidth;
231  chtype colSepchar;
232  unsigned hotCol;
233 
234 public:
235 
236  static const chtype currentBG = ( chtype ) - 1;
237 
238  NCTableStyle( const NCWidget & p );
239  ~NCTableStyle() {}
240 
241  bool SetStyleFrom( const std::vector<NCstring> & head );
242  void SetSepChar( const chtype sepchar ) { colSepchar = sepchar; }
243 
244  void SetSepWidth( const unsigned sepwidth ) { colSepwidth = sepwidth; }
245 
246  void SetHotCol( const int hcol )
247  {
248  hotCol = ( hcol < 0 || Cols() <= ( unsigned )hcol ) ? -1 : hcol;
249  }
250 
251  void ResetToMinCols()
252  {
253  colWidth.clear();
254  AssertMinCols( headline.Cols() );
255  headline.UpdateFormat( *this );
256  }
257 
258  void AssertMinCols( unsigned num )
259  {
260  if ( colWidth.size() < num )
261  {
262  colWidth.resize( num, 0 );
263  colAdjust.resize( colWidth.size(), NC::LEFT );
264  }
265  }
266 
267  void MinColWidth( unsigned num, unsigned val )
268  {
269  AssertMinCols( num );
270 
271  if ( val > colWidth[num] )
272  colWidth[num] = val;
273  }
274 
275  NC::ADJUST ColAdjust( unsigned num ) const { return colAdjust[num]; }
276 
277  unsigned Cols() const { return colWidth.size(); }
278 
279  unsigned ColWidth( unsigned num ) const { return colWidth[num]; }
280 
281  unsigned ColSepwidth() const { return colSepwidth; }
282 
283  chtype ColSepchar() const { return colSepchar; }
284 
285  unsigned HotCol() const { return hotCol; }
286 
287  const NCstyle::StList & listStyle() const { return parw.listStyle(); }
288 
289  chtype getBG() const { return listStyle().item.plain; }
290 
291  chtype getBG( const NCTableLine::STATE lstate,
292  const NCTableCol::STYLE cstyle = NCTableCol::PLAIN ) const;
293 
294  chtype highlightBG( const NCTableLine::STATE lstate,
295  const NCTableCol::STYLE cstyle,
296  const NCTableCol::STYLE dstyle = NCTableCol::PLAIN ) const ;
297 
298  chtype hotBG( const NCTableLine::STATE lstate, unsigned colidx ) const
299  {
300  return ( colidx == hotCol ) ? getBG( lstate, NCTableCol::HINT ) : currentBG;
301  }
302 
303  const NCTableLine & Headline() const { return headline; }
304 
305  unsigned TableWidth() const
306  {
307  unsigned twidth = 0;
308 
309  for ( unsigned i = 0; i < Cols(); ++i )
310  twidth += colWidth[i];
311 
312  if ( Cols() > 1 )
313  twidth += colSepwidth * ( Cols() - 1 );
314 
315  return twidth;
316  }
317 };
318 
319 
320 #endif // NCTableItem_h
C++ class for windows.
Definition: ncursesw.h:904
Definition: NCtext.h:81
Definition: position.h:154