libyui-ncurses
NCItemSelector.h
1 /*
2  Copyright (C) 2019 SUSE LLC
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: NCItemSelector.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 #ifndef NCItemSelector_h
26 #define NCItemSelector_h
27 
28 #include <iosfwd>
29 #include <string>
30 #include <vector>
31 
32 #include <yui/YItemSelector.h>
33 #include "NCPadWidget.h"
34 #include "NCTablePad.h"
35 
36 
37 class NCItemSelectorBase : public YItemSelector, public NCPadWidget
38 {
39  friend std::ostream & operator<<( std::ostream & str, const NCItemSelectorBase & obj );
40 
41 protected:
42 
46  NCItemSelectorBase( YWidget * parent, bool enforceSingleSelection );
47 
51  NCItemSelectorBase( YWidget * parent,
52  const YItemCustomStatusVector & customStates );
53 
54 public:
55 
59  virtual ~NCItemSelectorBase();
60 
64  virtual NCursesEvent wHandleInput( wint_t key );
65 
70  virtual int preferredWidth();
71 
76  virtual int preferredHeight();
77 
82  virtual void setSize( int newWidth, int newHeight );
83 
88  virtual YItem * currentItem() const;
89 
94  virtual void setCurrentItem( YItem * item );
95 
100  virtual void setEnabled( bool do_bv );
101 
106  virtual bool setKeyboardFocus();
107 
112  virtual void setVisibleItems( int newVal );
113 
120  int linesCount() const { return (int) myPad()->Lines(); }
121 
126  int currentLine() const { return myPad()->CurPos().L; }
127 
132  virtual void addItem( YItem * item );
133 
138  virtual void deleteAllItems();
139 
144  virtual void selectItem( YItem * item, bool selected );
145 
149  virtual void deselectAllItems();
150 
155  const NCTableLine * getLine( int lineNo ) { return myPad()->GetLine( lineNo ); }
156 
157 
158  virtual void startMultipleChanges() { startMultidraw(); }
159 
160  virtual void doneMultipleChanges() { stopMultidraw(); }
161 
162  virtual const char * location() const { return "NCItemSelectorBase"; }
163 
167  virtual void activateItem( YItem * item );
168 
174  virtual void shortcutChanged();
175 
180  virtual bool HasHotkey( int key ) ;
181 
182 protected:
183 
187  void createItemWidget( YItem * item );
188 
196  virtual NCTableTag * createTagCell( YItem * item ) = 0;
197 
204  virtual void cycleCurrentItemStatus() = 0;
205 
210  virtual bool statusChangeAllowed( int fromStatus, int toStatus )
211  { return false; }
212 
222  virtual NCursesEvent valueChangedNotify( YItem * item ) = 0;
223 
227  std::string description( YItem * item ) const;
228 
232  std::vector<std::string> descriptionLines( YItem * item ) const;
233 
239  YItem * scrollDownToNextItem();
240 
246  YItem * scrollUpToPreviousItem();
247 
251  virtual wsze preferredSize();
252 
257  virtual NCTableTag * tagCell( int index ) const;
258 
263  int findItemLine( YItem * item ) const;
264 
268  virtual NCPad * CreatePad();
269 
273  virtual NCTablePad * myPad() const
274  { return dynamic_cast<NCTablePad*>( NCPadWidget::myPad() ); }
275 
276  virtual void wRecoded() { NCPadWidget::wRecoded(); }
277 
278 private:
279 
280  // Disable assignment operator and copy constructor
281 
282  NCItemSelectorBase & operator=( const NCItemSelectorBase & );
284 
285  YItem* findItemWithHotkey( int key ) const;
286 
287 protected:
288 
289  // Data members
290 
291  wsze _prefSize;
292  bool _prefSizeDirty;
293  int _selectorWidth;
294  int _hotKey;
295 
296 
297 }; // class NCItemSelectorBase
298 
299 
300 
302 {
303 public:
307  NCItemSelector( YWidget * parent, bool enforceSingleSelection );
308 
312  virtual ~NCItemSelector();
313 
314  virtual const char * location() const { return "NCItemSelector"; }
315 
316 protected:
317 
323  virtual NCTableTag * createTagCell( YItem * item );
324 
329  virtual NCursesEvent valueChangedNotify( YItem * item );
330 
335  virtual void cycleCurrentItemStatus();
336 
341  virtual bool statusChangeAllowed( int fromStatus, int toStatus );
342 
347  void deselectAllItemsExcept( YItem * exceptItem );
348 
349 
350 private:
351 
352  // Disable assignment operator and copy constructor
353 
354  NCItemSelector & operator=( const NCItemSelector & );
355  NCItemSelector( const NCItemSelector & );
356 
357 }; // class NCItemSelector
358 
359 
360 #endif // NCItemSelector_h
Definition: NCPadWidget.h:39
Definition: NCurses.h:72
void createItemWidget(YItem *item)
Definition: NCItemSelector.cc:201
YItem * scrollUpToPreviousItem()
Definition: NCItemSelector.cc:375
virtual int preferredHeight()
Definition: NCItemSelector.cc:101
int linesCount() const
Definition: NCItemSelector.h:120
virtual ~NCItemSelector()
Definition: NCItemSelector.cc:594
virtual NCTableTag * createTagCell(YItem *item)=0
std::vector< std::string > descriptionLines(YItem *item) const
Definition: NCItemSelector.cc:297
NCItemSelectorBase(YWidget *parent, bool enforceSingleSelection)
Definition: NCItemSelector.cc:39
virtual void deleteAllItems()
Definition: NCItemSelector.cc:311
YItem * scrollDownToNextItem()
Definition: NCItemSelector.cc:352
std::string description(YItem *item) const
Definition: NCItemSelector.cc:280
virtual int preferredWidth()
Definition: NCItemSelector.cc:95
virtual void cycleCurrentItemStatus()
Definition: NCItemSelector.cc:622
virtual wpos CurPos() const
CurPos().L is the index of the selected item.
Definition: NCTablePadBase.cc:188
Definition: NCTablePad.h:61
virtual void activateItem(YItem *item)
Definition: NCItemSelector.cc:543
Definition: NCPad.h:112
virtual NCursesEvent valueChangedNotify(YItem *item)=0
void deselectAllItemsExcept(YItem *exceptItem)
Definition: NCItemSelector.cc:656
virtual void setSize(int newWidth, int newHeight)
Definition: NCItemSelector.cc:142
virtual void selectItem(YItem *item, bool selected)
Definition: NCItemSelector.cc:319
virtual void deselectAllItems()
Definition: NCItemSelector.cc:335
virtual NCPad * CreatePad()
Definition: NCItemSelector.cc:82
virtual void setVisibleItems(int newVal)
Definition: NCItemSelector.cc:164
virtual NCTableTag * createTagCell(YItem *item)
Definition: NCItemSelector.cc:601
const NCTableLine * getLine(int lineNo)
Definition: NCItemSelector.h:155
virtual ~NCItemSelectorBase()
Definition: NCItemSelector.cc:76
virtual NCursesEvent wHandleInput(wint_t key)
Definition: NCItemSelector.cc:397
virtual bool statusChangeAllowed(int fromStatus, int toStatus)
Definition: NCItemSelector.cc:641
virtual wsze preferredSize()
Definition: NCItemSelector.cc:107
virtual NCTablePad * myPad() const
Definition: NCItemSelector.h:273
int currentLine() const
Definition: NCItemSelector.h:126
unsigned Lines() const
Definition: NCTablePadBase.h:122
NCItemSelector(YWidget *parent, bool enforceSingleSelection)
Definition: NCItemSelector.cc:587
virtual void cycleCurrentItemStatus()=0
virtual void setCurrentItem(YItem *item)
Definition: NCItemSelector.cc:182
virtual bool setKeyboardFocus()
Definition: NCItemSelector.cc:148
virtual NCursesEvent valueChangedNotify(YItem *item)
Definition: NCItemSelector.cc:611
virtual void addItem(YItem *item)
Definition: NCItemSelector.cc:191
int findItemLine(YItem *item) const
Definition: NCItemSelector.cc:266
Screen dimension (screen size) in the order height, width: (H, W)
Definition: position.h:153
Definition: NCTableItem.h:67
virtual void shortcutChanged()
Definition: NCItemSelector.cc:556
Definition: NCTableItem.h:646
Definition: NCItemSelector.h:37
Definition: NCItemSelector.h:301
virtual YItem * currentItem() const
Definition: NCItemSelector.cc:171
virtual bool statusChangeAllowed(int fromStatus, int toStatus)
Definition: NCItemSelector.h:210
const NCTableLine * GetLine(unsigned idx) const
Definition: NCTablePadBase.cc:87
virtual NCTableTag * tagCell(int index) const
Definition: NCItemSelector.cc:255
virtual bool HasHotkey(int key)
Definition: NCItemSelector.cc:572
virtual NCPad * myPad() const
Definition: NCPadWidget.h:64
virtual void setEnabled(bool do_bv)
Definition: NCItemSelector.cc:157