libyui-ncurses
NCTree.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: NCTree.h
21 
22  Authors: Michael Andres <ma@suse.de>
23  Stefan Hundhammer <shundhammer@suse.de>
24 
25 /-*/
26 
27 #ifndef NCTree_h
28 #define NCTree_h
29 
30 #include <iosfwd>
31 
32 #include <yui/YTree.h>
33 #include "NCPadWidget.h"
34 #include "NCTreePad.h"
35 #include "NCTablePad.h"
36 
37 class NCTreeLine;
38 
46 class NCTree : public YTree, public NCPadWidget
47 {
48  friend std::ostream & operator<<( std::ostream & str, const NCTree & obj );
49 
50 public:
51 
52  NCTree( YWidget * parent,
53  const std::string & label,
54  bool multiselection = false,
55  bool recursiveselection = false );
56 
57  virtual ~NCTree();
58 
64  virtual void rebuildTree();
65 
69  virtual YTreeItem * getCurrentItem() const;
70 
76  virtual YTreeItem * currentItem();
77 
78  virtual void deselectAllItems();
79 
85  virtual void selectItem( YItem *item, bool selected );
86 
90  virtual void selectItem( int index );
91 
97  virtual void deleteAllItems();
98 
105  virtual int preferredWidth();
106 
113  virtual int preferredHeight();
114 
121  virtual void setSize( int newWidth, int newHeight );
122 
128  virtual void setLabel( const std::string & nlabel );
129 
135  virtual void setEnabled( bool do_bv );
136 
142  virtual bool setKeyboardFocus()
143  {
144  if ( !grabFocus() )
145  return YWidget::setKeyboardFocus();
146 
147  return true;
148  }
149 
156  virtual void activate();
157 
163  virtual NCursesEvent wHandleInput( wint_t key );
164 
165 
166 protected:
167 
173  virtual const char * location() const { return "NCTree"; }
174 
178  virtual NCPad * CreatePad();
179 
186  virtual NCTreePad * myPad() const
187  { return dynamic_cast<NCTreePad*>( NCPadWidget::myPad() ); }
188 
192  virtual void DrawPad();
193 
194 
199  const NCTreeLine * getTreeLine( unsigned idx ) const;
200 
206  NCTreeLine * modifyTreeLine( unsigned idx );
207 
214  virtual void startMultipleChanges() { startMultidraw(); }
215 
222  virtual void doneMultipleChanges() { stopMultidraw(); }
223 
228  void CreateTreeLines( NCTreeLine * parentLine,
229  NCTreePad * pad,
230  YItem * item );
231 
232 private:
233 
234  // Disable unwanted assignment operator and copy constructor
235 
236  NCTree & operator=( const NCTree & );
237  NCTree( const NCTree & );
238 
239 
240  //
241  // Data members
242  //
243 
244  bool _multiSelect;
245  int _nextItemIndex; // Only used in CreateTreeLines()
246 };
247 
248 
261 class NCTreeLine : public NCTableLine
262 {
263 public:
264 
265  NCTreeLine( NCTreeLine * parentLine,
266  YTreeItem * origItem,
267  bool multiSelection );
268 
269  virtual ~NCTreeLine();
270 
271 public:
272 
276  YTreeItem * YItem() const { return dynamic_cast<YTreeItem *>( _yitem ); }
277 
289  virtual bool ChangeToVisible();
290 
291  virtual unsigned Hotspot( unsigned & at ) const;
292 
297  virtual bool handleInput( wint_t key );
298 
299 
300  //
301  // Some covariants of the tree operations returning this derived class
302  //
303 
304  virtual NCTreeLine * parent() const { return dynamic_cast<NCTreeLine *>( _parent ); }
305  virtual NCTreeLine * firstChild() const { return dynamic_cast<NCTreeLine *>( _firstChild ); }
306  virtual NCTreeLine * nextSibling() const { return dynamic_cast<NCTreeLine *>( _nextSibling ); }
307 
308 
309 private:
310 
311  //
312  // Data members
313  //
314 
315  bool _multiSelect;
316 };
317 
318 
319 #endif // NCTree_h
Definition: NCPadWidget.h:39
Definition: NCurses.h:72
virtual void setSize(int newWidth, int newHeight)
Definition: NCTree.cc:106
virtual int preferredWidth()
Definition: NCTree.cc:85
virtual void startMultipleChanges()
Definition: NCTree.h:214
virtual YTreeItem * currentItem()
Definition: NCTree.cc:291
virtual void activate()
Definition: NCTree.cc:395
const NCTreeLine * getTreeLine(unsigned idx) const
Definition: NCTree.cc:66
Definition: NCTreePad.h:49
Definition: NCPad.h:112
virtual NCursesEvent wHandleInput(wint_t key)
Definition: NCTree.cc:321
NCTreeLine * modifyTreeLine(unsigned idx)
Definition: NCTree.cc:76
virtual NCPad * CreatePad()
Definition: NCTree.cc:230
virtual void selectItem(YItem *item, bool selected)
Definition: NCTree.cc:146
virtual bool handleInput(wint_t key)
Definition: NCTree.cc:484
virtual NCTreePad * myPad() const
Definition: NCTree.h:186
virtual int preferredHeight()
Definition: NCTree.cc:92
void CreateTreeLines(NCTreeLine *parentLine, NCTreePad *pad, YItem *item)
Definition: NCTree.cc:240
virtual void doneMultipleChanges()
Definition: NCTree.h:222
virtual void setLabel(const std::string &nlabel)
Definition: NCTree.cc:216
YItem * _yitem
not owned
Definition: NCTableItem.h:387
Definition: NCTree.h:261
virtual void rebuildTree()
Definition: NCTree.cc:223
virtual void deleteAllItems()
Definition: NCTree.cc:405
virtual void DrawPad()
Definition: NCTree.cc:297
virtual const char * location() const
Definition: NCTree.h:173
YTableItem * origItem() const
Definition: NCTableItem.h:127
virtual bool ChangeToVisible()
Definition: NCTree.cc:443
virtual bool setKeyboardFocus()
Definition: NCTree.h:142
virtual void setEnabled(bool do_bv)
Definition: NCTree.cc:99
Definition: NCTableItem.h:67
virtual YTreeItem * getCurrentItem() const
Definition: NCTree.cc:112
Definition: NCTree.h:46
YTreeItem * YItem() const
Definition: NCTree.h:276
virtual NCPad * myPad() const
Definition: NCPadWidget.h:64