Author: kmachalkova
Date: Fri Oct 12 18:05:03 2007
New Revision: 41417
URL: http://svn.opensuse.org/viewcvs/yast?rev=41417&view=rev
Log:
Ported NCTable, part II
(selecting items, updating cells, setting column
alignment)
Modified:
branches/tmp/sh/mod-ui/ncurses/src/NCTable.cc
branches/tmp/sh/mod-ui/ncurses/src/NCTable.h
branches/tmp/sh/mod-ui/ncurses/src/NCTableItem.cc
branches/tmp/sh/mod-ui/ncurses/src/NCTableItem.h
branches/tmp/sh/mod-ui/ncurses/src/YNCursesUI.h
Modified: branches/tmp/sh/mod-ui/ncurses/src/NCTable.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/ncurses/src/NCTable.cc?rev=41417&r1=41416&r2=41417&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/ncurses/src/NCTable.cc (original)
+++ branches/tmp/sh/mod-ui/ncurses/src/NCTable.cc Fri Oct 12 18:05:03 2007
@@ -45,10 +45,6 @@
InitPad();
// !!! head is UTF8 encoded, thus should be vector<YCPstring>
header.assign( columns, NCstring("") );
- /*for ( unsigned i = 0; i < head.size(); ++i ) {
- setHeader( i, head[i] );
- }*/
- hasHeadline = myPad()->SetHeadline( header );
}
///////////////////////////////////////////////////////////////////
@@ -106,7 +102,6 @@
//
void NCTable::setSize( int newwidth, int newheight )
{
- NCMIL << "setSize() called: width: " << newwidth << " height: " << newheight << endl;
wRelocate( wpos( 0 ), wsze( newheight, newwidth ) );
}
@@ -138,9 +133,8 @@
if ( hasColumn( col ))
{
- header[ col ] = NCstring( text ) ;
+ header[ col ] += NCstring( text ) ;
}
-
hasHeadline = myPad()->SetHeadline( header );
}
@@ -153,10 +147,16 @@
void NCTable::setAlignment ( int col, YTable::Alignment al )
{
- //FIXME: need something better than just dumb calling parent
- // method - ncurses doesn't seem to support alignments natively
+ string s;
+ switch ( al )
+ {
+ case YTable::Left: s = 'L' ; break;
+ case YTable::Center: s = 'C' ; break;
+ case YTable::Right: s = 'R' ; break;
+ }
+
+ header[ col ] = NCstring( s );
YTable::setAlignment( col, al );
-
}
void NCTable::setKeepSorting ( bool keepSorting )
@@ -164,6 +164,7 @@
YTable::setKeepSorting( keepSorting );
sortable = keepSorting;
}
+
///////////////////////////////////////////////////////////////////
//
//
@@ -178,6 +179,7 @@
return -1;
return sortable ? myPad()->GetLine( myPad()->CurPos().L )->getIndex ()
: myPad()->CurPos().L;
+
}
///////////////////////////////////////////////////////////////////
@@ -216,7 +218,10 @@
//
void NCTable::addItem( YItem *yitem )
{
+ static int idx = 0;
+
YTableItem *item = dynamic_cast(yitem);
+ YUI_CHECK_PTR(item);
YTable::addItem( item );
vector Items( item->cellCount() );
@@ -228,11 +233,18 @@
Items[i] = new NCTableCol( NCstring( (*it)->label() ) );
i++;
}
- NCTableLine *newline = new NCTableLine( Items );
+
+ NCTableLine *newline = new NCTableLine( Items, idx++ );
+ YUI_CHECK_PTR(newline);
newline->setOrigItem( item );
myPad()->Append( newline );
- //myPad()->Append( Items, myPad()->Lines() );
+
+ if (item->selected() )
+ {
+ setCurrentItem( myPad()->Lines() ) ;
+ }
+
DrawPad();
}
@@ -251,6 +263,43 @@
YTable::deleteAllItems();
}
+void NCTable::selectItem( YItem *yitem, bool selected )
+{
+ YTableItem *item = dynamic_cast(yitem);
+ YUI_CHECK_PTR(item);
+
+ NCTableLine *line = (NCTableLine *)item->data();
+ YUI_CHECK_PTR(line);
+
+ const NCTableLine *current_line = myPad()->GetLine( myPad()->CurPos().L );
+ YUI_CHECK_PTR(current_line);
+
+ if ( !selected && ( line == current_line ) )
+ {
+ deselectAllItems();
+ }
+ else
+ {
+ setCurrentItem( line->getIndex() );
+ YTable::selectItem( item, selected);
+ }
+
+ DrawPad();
+}
+
+void NCTable::deselectAllItems()
+{
+ setCurrentItem( -1 );
+ YTable::deselectAllItems();
+ DrawPad();
+}
+
+void NCTable::selectCurrentItem()
+{
+ const NCTableLine *cline = myPad()->GetLine( myPad()->CurPos().L );
+ YTable::selectItem( cline->origItem() );
+}
+
///////////////////////////////////////////////////////////////////
//
//
@@ -352,8 +401,12 @@
}
}
+ selectCurrentItem();
+
if ( notify() && immediate && citem != getCurrentItem() )
+ {
ret = NCursesEvent::SelectionChanged;
+ }
return ret;
}
Modified: branches/tmp/sh/mod-ui/ncurses/src/NCTable.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/ncurses/src/NCTable.h?rev=41417&r1=41416&r2=41417&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/ncurses/src/NCTable.h (original)
+++ branches/tmp/sh/mod-ui/ncurses/src/NCTable.h Fri Oct 12 18:05:03 2007
@@ -93,6 +93,9 @@
void SetHotCol( const int hcol ) { myPad()->SetHotCol( hcol ); }
virtual void addItem( YItem *yitem );
+ virtual void selectItem( YItem *yitem, bool selected );
+ virtual void deselectAllItems();
+ void selectCurrentItem();
virtual long nicesize( YUIDimension dim );
@@ -108,7 +111,7 @@
virtual void setLabel( const YCPString & nlabel );
- virtual int getCurrentItem();
+ virtual int getCurrentItem();
virtual void setCurrentItem( int index );
bool setItemByKey( int key );
Modified: branches/tmp/sh/mod-ui/ncurses/src/NCTableItem.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/ncurses/src/NCTableItem.cc?rev=41417&r1=41416&r2=41417&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/ncurses/src/NCTableItem.cc (original)
+++ branches/tmp/sh/mod-ui/ncurses/src/NCTableItem.cc Fri Oct 12 18:05:03 2007
@@ -139,8 +139,8 @@
void NCTableLine::setOrigItem (YTableItem *it)
{
- origItem = it;
- origItem->setData(this);
+ yitem = it;
+ yitem->setData (this) ;
}
///////////////////////////////////////////////////////////////////
//
Modified: branches/tmp/sh/mod-ui/ncurses/src/NCTableItem.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/ncurses/src/NCTableItem.h?rev=41417&r1=41416&r2=41417&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/ncurses/src/NCTableItem.h (original)
+++ branches/tmp/sh/mod-ui/ncurses/src/NCTableItem.h Fri Oct 12 18:05:03 2007
@@ -63,7 +63,7 @@
int index;
- YTableItem *origItem;
+ YTableItem *yitem;
protected:
@@ -77,6 +77,7 @@
NCTableLine( unsigned cols, int index = -1, const unsigned s = S_NORMAL );
NCTableLine( vector & nItems, int index = -1, const unsigned s = S_NORMAL );
void setOrigItem( YTableItem *it);
+ YTableItem *origItem() const { return yitem; }
virtual ~NCTableLine();
unsigned Cols() const { return Items.size(); }
Modified: branches/tmp/sh/mod-ui/ncurses/src/YNCursesUI.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/ncurses/src/YNCursesUI.h?rev=41417&r1=41416&r2=41417&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/ncurses/src/YNCursesUI.h (original)
+++ branches/tmp/sh/mod-ui/ncurses/src/YNCursesUI.h Fri Oct 12 18:05:03 2007
@@ -154,11 +154,6 @@
virtual YWidget * createMenuButton( YWidget * parent, YWidgetOpt & opt,
const YCPString & label );
- /**
- * Creates a table widget
- virtual YWidget * createTable( YWidget * parent, YWidgetOpt & opt,
- vector<string> header );
-*/
/**
* Creates an IntField widget.
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org