libyui-ncurses  2.54.5
NCTable.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: NCTable.h
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #ifndef NCTable_h
26 #define NCTable_h
27 
28 #include <iosfwd>
29 
30 #include <yui/YTable.h>
31 #include "NCPadWidget.h"
32 #include "NCTablePad.h"
33 
34 
35 class NCTable : public YTable, public NCPadWidget
36 {
37 public:
38 
39  NCTable( YWidget * parent, YTableHeader *tableHeader, bool multiSelection = false );
40 
41  virtual ~NCTable();
42 
43  bool bigList() const { return biglist; }
44 
45  void setHeader( const std::vector<std::string>& head );
46  std::vector<std::string> getHeader( ) const;
47 
48  virtual void setAlignment( int col, YAlignmentType al );
49 
50  void setBigList( bool big ) { biglist = big; }
51 
52  void SetSepChar( const chtype colSepchar ) { myPad()->SetSepChar( colSepchar ); }
53 
54  void SetSepWidth( const unsigned sepwidth ) { myPad()->SetSepWidth( sepwidth ); }
55 
56  void SetHotCol( int hcol ) { myPad()->SetHotCol( hcol ); }
57 
58  virtual void addItem( YItem *yitem );
59  virtual void addItems( const YItemCollection & itemCollection );
60  virtual void deleteAllItems( );
61 
62  virtual int getCurrentItem() const;
63  YItem * getCurrentItemPointer();
64 
65  virtual void setCurrentItem( int index );
66  virtual void selectItem( YItem *yitem, bool selected );
67  void selectCurrentItem();
68  virtual void deselectAllItems();
69 
70  virtual int preferredWidth();
71  virtual int preferredHeight();
72 
73  virtual void setSize( int newWidth, int newHeight );
74 
75  virtual void setLabel( const std::string & nlabel );
76 
77  virtual void setEnabled( bool do_bv );
78 
79  bool setItemByKey( int key );
80 
81  virtual NCursesEvent wHandleInput( wint_t key );
82 
83  virtual bool setKeyboardFocus()
84  {
85  if ( !grabFocus() )
86  return YWidget::setKeyboardFocus();
87 
88  return true;
89  }
90 
91  void stripHotkeys() { myPad()->stripHotkeys(); }
92 
93  void setSortStrategy( NCTableSortStrategyBase * newStrategy ) { myPad()->setSortStrategy( newStrategy ); }
94 
95 protected:
96 
97  /**
98  * Overload myPad to narrow the type
99  */
100  virtual NCTablePad * myPad() const
101  { return dynamic_cast<NCTablePad*>( NCPadWidget::myPad() ); }
102 
103  bool biglist;
104  bool multiselect;
105 
106 
107 protected:
108 
109  virtual const char * location() const { return "NCTable"; }
110 
111  virtual NCPad * CreatePad();
112 
113  virtual void cellChanged( int index, int colnum, const std::string & newtext );
114  virtual void cellChanged( const YTableCell *cell );
115 
116  virtual void startMultipleChanges() { startMultidraw(); }
117  virtual void doneMultipleChanges() { stopMultidraw(); }
118 
119  //internal overloaded version of addItem - both addItem(yitem)
120  //and addItems(itemCollection) use it, but in different mode
121  virtual void addItem( YItem *yitem, bool allAtOnce );
122  void toggleCurrentItem();
123 
124 private:
125 
126  std::vector<NCstring> _header;
127 
128  friend std::ostream & operator<<( std::ostream & str, const NCTable & obj );
129 
130  NCTable & operator=( const NCTable & );
131  NCTable( const NCTable & );
132 
133 };
134 
135 
136 #endif // NCTable_h
Definition: NCPad.h:93
virtual void setEnabled(bool do_bv)
Pure virtual to make sure every widget implements it.
Definition: NCTable.cc:479
void toggleCurrentItem()
Toggle item from selected -> deselected and vice versa.
Definition: NCTable.cc:604
virtual NCTablePad * myPad() const
Overload myPad to narrow the type.
Definition: NCTable.h:100
virtual NCPad * myPad() const
Return the current pad.
Definition: NCPadWidget.h:62