27 #define YUILogComponent "ncurses"
28 #include <yui/YUILog.h>
30 #include "YNCursesUI.h"
32 #include <yui/TreeItem.h>
33 #include <yui/YSelectionWidget.h>
39 NCTree::NCTree( YWidget * parent,
40 const string & nlabel,
42 bool recursiveselection )
43 : YTree( parent, nlabel, multiselection, recursiveselection )
45 , _multiSelect( multiselection )
50 if ( multiselection && recursiveselection )
51 yuiDebug() <<
"NCTree recursive multi selection ON" << endl;
52 else if ( multiselection )
53 yuiDebug() <<
"NCTree multi selection ON" << endl;
87 wsze sze = wsze::max( defsze,
wsze( 0, labelWidth() + 2 ) );
94 wsze sze = wsze::max( defsze,
wsze( 0, labelWidth() + 2 ) );
102 YWidget::setEnabled( do_bv );
108 wRelocate(
wpos( 0 ),
wsze( newheight, newwidth ) );
114 YTreeItem * yitem = 0;
121 yitem = currentLine->
YItem();
130 void NCTree::deselectAllItems()
134 YItemCollection selectedItems = YTree::selectedItems();
136 for ( YItemConstIterator it = selectedItems.begin(); it != selectedItems.end(); ++it )
142 YTree::deselectAllItems();
151 YTreeItem * treeItem =
dynamic_cast<YTreeItem *
>( item );
152 YUI_CHECK_PTR( treeItem );
157 int at = treeItem->index();
168 currentCol = currentLine->
GetCol(0);
174 if ( !_multiSelect && ( treeItem ==
currentItem ) )
176 YTree::deselectAllItems();
180 YTree::selectItem( treeItem,
false );
190 YTree::selectItem( treeItem, selected );
192 if ( _multiSelect && currentCol )
207 YItem * item = YTree::itemAt( index );
212 YUI_THROW( YUIException(
"Can't find selected item" ) );
218 YTree::setLabel( nlabel );
219 NCPadWidget::setLabel(
NCstring( nlabel ) );
232 wsze psze( defPadSze() );
234 npad->
bkgd( listStyle().item.plain );
247 item->setIndex( _nextItemIndex++ );
249 YTreeItem * treeItem =
dynamic_cast<YTreeItem *
>( item );
250 YUI_CHECK_PTR( treeItem );
255 if ( item->selected() )
258 int at = treeItem->index();
268 currentCol = currentLine->
GetCol(0);
284 for ( YItemIterator it = item->childrenBegin(); it < item->childrenEnd(); ++it )
301 yuiWarning() <<
"PadWidget not yet created" << endl;
309 for ( YItemIterator it = itemsBegin(); it < itemsEnd(); ++it )
317 NCPadWidget::DrawPad();
337 bool handled = handleInput( key );
360 return NCursesEvent::ValueChanged;
376 return NCursesEvent::Activated;
382 YTree::selectItem(
const_cast<YItem *
>(
currentItem ),
true );
385 if ( notify() && immediateMode() && ( oldCurrentItem !=
currentItem ) )
386 ret = NCursesEvent::SelectionChanged;
407 YTree::deleteAllItems();
417 NCTreeLine::NCTreeLine(
NCTreeLine * parentLine,
419 bool multiSelection )
423 item ? item->index() : -1,
426 , _multiSelect( multiSelection )
429 _prefixPlaceholder += item->selected() ?
"[x] " :
"[ ] ";
432 cell->setPrefix( prefixPlaceholder() );
437 NCTreeLine::~NCTreeLine()
453 parent()->ChangeToVisible();
458 for (
NCTreeLine * sibling = parent()->firstChild();
460 sibling = sibling->nextSibling() )
462 sibling->ClearState( S_HIDDEN );
463 sibling->YItem()->setOpen(
true );
470 ClearState( S_HIDDEN );
471 YItem()->setOpen(
true );
478 unsigned NCTreeLine::Hotspot(
unsigned & at )
const
486 bool handled =
false;
Screen dimension (screen size) in the order height, width: (H, W)
A string with an optional hot key.
const NCTreeLine * getTreeLine(unsigned idx) const
Return a const pointer to the tree line at the specified index for read-only operations.
virtual bool handleInput(wint_t key)
Handle keyboard input.
static YNCursesUI * ui()
Access the global Y2NCursesUI.
void sendEvent(NCursesEvent event)
Send an event to the UI.
void ClearTable()
Clear all content.
One cell in an NCTableLine with a label and a cell-specific style.
virtual bool ChangeToVisible()
Change a line that may have been invisible until now to be visible.
virtual void setLabel(const std::string &nlabel)
Set the label (the caption) above the tree.
NCTableLine * GetCurrentLine() const
Return the current line (the line at the cursor position) or 0 if there is none.
virtual void deleteAllItems()
Delete all items and clear the TreePad.
void Append(NCTableLine *item)
Add one item to the end of _items.
YTreeItem * YItem() const
Return the corresponding YTreeItem.
std::string indentationStr() const
Return a string of a number of blanks suitable for the indentation of this tree level.
virtual NCTreePad * myPad() const
Return the TreePad that belongs to this widget.
NCTableLine * ModifyLine(unsigned idx)
Return line at idx for read-write operations and mark it as modified.
const NCTableLine * GetLine(unsigned idx) const
Return the line at idx for read-only operations.
A virtual window with a real viewport (which is NCursesWindow) and a scrolling mechanism.
virtual void selectItem(YItem *item, bool selected)
Select or deselect an item.
One line in a tree widdget.
virtual void DrawPad()
Fill the TreePad with lines (using CreateTreeLines to create them)
Screen position pair in the order line, column: (L, C)
virtual void rebuildTree()
Recursively build the tree in this widget according to the items.
virtual int preferredWidth()
libyui geometry management: Return the preferred width for this widget.
virtual YTreeItem * currentItem()
Get the current item.
virtual void setSize(int newWidth, int newHeight)
libyui geometry management: Apply the width and height assigned from the parent layout widget.
int bkgd(const chtype ch)
Set the background property and apply it to the window.
virtual void activate()
Activate the item selected in the tree.
NCTableCol * GetCol(unsigned idx)
Return a non-const pointer for read/write operations to the column (the cell) with the specified inde...
virtual YTreeItem * getCurrentItem() const
Return a pointer to the current item (the item under the cursor).
void CreateTreeLines(NCTreeLine *parentLine, NCTreePad *pad, YItem *item)
Create TreeLines and append them to the TreePad.
One line in a NCTable with multiple cells and an optional tree hierarchy.
virtual void setEnabled(bool do_bv)
Enable or disable this widget.
virtual NCursesEvent wHandleInput(wint_t key)
Keyboard input handler.
virtual NCPad * CreatePad()
Create an empty pad.
virtual bool handleInput(wint_t key)
Handle keyboard input.
NCTreeLine * modifyTreeLine(unsigned idx)
Return a non-const pointer to the tree line at the specified index for read-write operations.
virtual int preferredHeight()
libyui geometry management: Return the preferred height for this widget.