libyui-ncurses
NCTable.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  Copyright (C) 2020 SUSE LLC
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as
6  published by the Free Software Foundation; either version 2.1 of the
7  License, or (at your option) version 3.0 of the License. This library
8  is distributed in the hope that it will be useful, but WITHOUT ANY
9  WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11  License for more details. You should have received a copy of the GNU
12  Lesser General Public License along with this library; if not, write
13  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
14  Floor, Boston, MA 02110-1301 USA
15 */
16 
17 
18 /*-/
19 
20  File: NCTable.h
21 
22  Authors: Michael Andres <ma@suse.de>
23  Stefan Hundhammer <shundhammer@suse.de>
24 
25 /-*/
26 
27 #ifndef NCTable_h
28 #define NCTable_h
29 
30 #include <yui/YTable.h>
31 #include "NCPadWidget.h"
32 #include "NCTablePad.h"
33 #include "NCTableSort.h"
34 
35 
42 class NCTable : public YTable, public NCPadWidget
43 {
44  friend std::ostream & operator<<( std::ostream & str, const NCTable & obj );
45 
46 public:
47 
48  NCTable( YWidget * parent,
49  YTableHeader * tableHeader,
50  bool multiSelection = false );
51 
52  virtual ~NCTable();
53 
57  void setHeader( const std::vector<std::string>& head );
58 
63  std::vector<std::string> getHeader() const;
64 
70  virtual void addItems( const YItemCollection & itemCollection );
71 
77  virtual void addItem( YItem *yitem )
78  { addItem( yitem, NCTableLine::S_NORMAL ); }
79 
89  virtual void addItem( YItem * yitem,
90  NCTableLine::STATE state );
91 
97  virtual void deleteAllItems();
98 
103  virtual int getCurrentIndex() const;
104 
115  virtual int getCurrentItem() const;
116 
123  YItem * getCurrentItemPointer();
124 
128  virtual void setCurrentItem( int index );
129 
133  virtual void scrollToFirstItem();
134 
140  virtual void selectItem( YItem *yitem, bool selected );
141 
145  void selectCurrentItem();
146 
152  virtual void deselectAllItems();
153 
162  virtual NCursesEvent wHandleInput( wint_t key );
163 
170  virtual int preferredWidth();
171 
178  virtual int preferredHeight();
179 
186  virtual void setSize( int newWidth, int newHeight );
187 
194  virtual void setLabel( const std::string & nlabel );
195 
201  virtual void setEnabled( bool do_bv );
202 
208  virtual bool setKeyboardFocus()
209  {
210  if ( !grabFocus() )
211  return YWidget::setKeyboardFocus();
212 
213  return true;
214  }
215 
220  bool setItemByKey( int key );
221 
226  void SetSepChar( const chtype colSepchar )
227  { myPad()->SetSepChar( colSepchar ); }
228 
233  void SetSepWidth( const unsigned sepwidth )
234  { myPad()->SetSepWidth( sepwidth ); }
235 
240  void SetHotCol( int hcol )
241  { myPad()->SetHotCol( hcol ); }
242 
246  bool bigList() const { return _bigList; }
247 
251  void setBigList( bool big ) { _bigList = big; }
252 
256  void stripHotkeys() { myPad()->stripHotkeys(); }
257 
261  void setSortStrategy( NCTableSortStrategyBase * newStrategy );
262 
266  NCTableSortStrategyBase * sortStrategy() const { return _sortStrategy; }
267 
268 
269 protected:
270 
276  virtual const char * location() const { return "NCTable"; }
277 
281  virtual NCPad * CreatePad();
282 
289  virtual NCTablePad * myPad() const
290  { return dynamic_cast<NCTablePad*>( NCPadWidget::myPad() ); }
291 
302  virtual void addItem( YItem * yitem,
303  bool preventRedraw,
304  NCTableLine::STATE state = NCTableLine::S_NORMAL );
305 
321  virtual void addPadLine( NCTableLine * parentLine,
322  YItem * yitem,
323  bool preventRedraw,
324  NCTableLine::STATE state = NCTableLine::S_NORMAL );
325 
326 
334  void rebuildPadLines();
335 
339  void rebuildHeaderLine();
340 
345  NCstring alignmentStr( int col );
346 
351  bool hasNestedItems( const YItemCollection & itemCollection ) const;
352 
353  bool hasNestedItems( YItemConstIterator begin,
354  YItemConstIterator end ) const;
355 
362  virtual void startMultipleChanges() { startMultidraw(); }
363 
370  virtual void doneMultipleChanges() { stopMultidraw(); }
371 
375  void toggleCurrentItem();
376 
381  void cellChanged( const YTableCell * cell );
382 
386  void setCell( int index, int col, const std::string & newText );
387 
403  void assignIndex( YItemConstIterator begin,
404  YItemConstIterator end );
405 
409  void assignIndex( YItem * item );
410 
417  void interactiveSort();
418 
425  void sortItems( int sortCol, bool reverse = false );
426 
431  void sortYItems( YItemIterator begin,
432  YItemIterator end );
433 
434 private:
435 
436  // Disable unwanted assignment opearator and copy constructor
437 
438  NCTable & operator=( const NCTable & );
439  NCTable( const NCTable & );
440 
441 
442  //
443  // Data members
444  //
445 
446  // Number of non-data prefix columns for things like the multi-selection
447  // indicator ("[ ]" / "[x]")
448  int _prefixCols;
449 
450  bool _nestedItems;
451  bool _bigList;
452  bool _multiSelect;
453 
454  int _lastSortCol;
455  bool _sortReverse;
456  NCTableSortStrategyBase * _sortStrategy; //< owned
457 };
458 
459 
460 std::ostream & operator<<( std::ostream & stream, const YItem * item );
461 
462 
463 #endif // NCTable_h
Definition: NCPadWidget.h:39
virtual void deselectAllItems()
Definition: NCTable.cc:472
bool bigList() const
Definition: NCTable.h:246
void interactiveSort()
Definition: NCTable.cc:644
NCTableSortStrategyBase * sortStrategy() const
Definition: NCTable.h:266
Definition: NCurses.h:72
void assignIndex(YItemConstIterator begin, YItemConstIterator end)
virtual void selectItem(YItem *yitem, bool selected)
Definition: NCTable.cc:412
Definition: NCTable.h:42
void setCell(int index, int col, const std::string &newText)
Definition: NCTable.cc:129
bool hasNestedItems(const YItemCollection &itemCollection) const
Definition: NCTable.cc:334
Definition: NCTablePad.h:61
void SetSepWidth(const unsigned sepwidth)
Definition: NCTable.h:233
virtual int preferredWidth()
Definition: NCTable.cc:500
NCstring alignmentStr(int col)
Definition: NCTable.cc:113
Definition: NCPad.h:112
Definition: NCTableSort.h:35
virtual int preferredHeight()
Definition: NCTable.cc:507
virtual void setSize(int newWidth, int newHeight)
Definition: NCTable.cc:514
void selectCurrentItem()
Definition: NCTable.cc:463
std::vector< std::string > getHeader() const
Definition: NCTable.cc:196
void SetHotCol(int hcol)
Definition: NCTable.h:240
virtual NCursesEvent wHandleInput(wint_t key)
Definition: NCTable.cc:556
void SetSepChar(const chtype colSepchar)
Definition: NCTable.h:226
void stripHotkeys()
Definition: NCTable.h:256
Definition: NCstring.h:35
void setBigList(bool big)
Definition: NCTable.h:251
void setSortStrategy(NCTableSortStrategyBase *newStrategy)
Definition: NCTable.cc:755
bool setItemByKey(int key)
Definition: NCTable.cc:534
virtual void setCurrentItem(int index)
Definition: NCTable.cc:406
virtual void setEnabled(bool do_bv)
Definition: NCTable.cc:527
virtual void addPadLine(NCTableLine *parentLine, YItem *yitem, bool preventRedraw, NCTableLine::STATE state=NCTableLine::S_NORMAL)
Definition: NCTable.cc:259
virtual void doneMultipleChanges()
Definition: NCTable.h:370
virtual const char * location() const
Definition: NCTable.h:276
virtual void setLabel(const std::string &nlabel)
Definition: NCTable.cc:520
void sortItems(int sortCol, bool reverse=false)
Definition: NCTable.cc:707
void rebuildHeaderLine()
Definition: NCTable.cc:86
void rebuildPadLines()
Definition: NCTable.cc:320
virtual int getCurrentIndex() const
Definition: NCTable.cc:391
virtual void addItem(YItem *yitem)
Definition: NCTable.h:77
void sortYItems(YItemIterator begin, YItemIterator end)
Definition: NCTable.cc:738
virtual int getCurrentItem() const
Definition: NCTable.cc:365
Definition: NCTableItem.h:67
virtual void scrollToFirstItem()
Definition: NCTable.cc:399
YItem * getCurrentItemPointer()
Definition: NCTable.cc:380
virtual void deleteAllItems()
Definition: NCTable.cc:353
void cellChanged(const YTableCell *cell)
Definition: NCTable.cc:155
virtual void startMultipleChanges()
Definition: NCTable.h:362
virtual NCPad * CreatePad()
Definition: NCTable.cc:540
void toggleCurrentItem()
Definition: NCTable.cc:635
virtual void addItems(const YItemCollection &itemCollection)
Definition: NCTable.cc:210
virtual NCTablePad * myPad() const
Definition: NCTable.h:289
virtual NCPad * myPad() const
Definition: NCPadWidget.h:64
virtual bool setKeyboardFocus()
Definition: NCTable.h:208
void setHeader(const std::vector< std::string > &head)
Definition: NCTable.cc:181