Author: kmachalkova
Date: Mon Oct 15 14:25:03 2007
New Revision: 41427
URL: http://svn.opensuse.org/viewcvs/yast?rev=41427&view=rev
Log:
Documenting and commenting the whole stuff
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/README_mod-ui
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=41427&r1=41426&r2=41427&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/ncurses/src/NCTable.cc (original)
+++ branches/tmp/sh/mod-ui/ncurses/src/NCTable.cc Mon Oct 15 14:25:03 2007
@@ -47,7 +47,7 @@
header.assign( columns, NCstring("") );
}
-///////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
//
//
// METHOD NAME : NCTable::~NCTable
@@ -55,6 +55,7 @@
//
// DESCRIPTION :
//
+
NCTable::~NCTable()
{
WIDDBG << endl;
@@ -63,60 +64,59 @@
///////////////////////////////////////////////////////////////////
//
//
-// METHOD NAME : NCTable::nicesize
-// METHOD TYPE : long
-//
-// DESCRIPTION :
+// METHOD NAME : NCTable::cellChanged
+// METHOD TYPE : void
//
-long NCTable::nicesize( YUIDimension dim )
-{
- wsze sze = ( biglist ) ? myPad()->tableSize() + 2 : wGetDefsze();
- return dim == YD_HORIZ ? sze.W : sze.H;
-}
-
-int NCTable::preferredWidth()
-{
- wsze sze = ( biglist ) ? myPad()->tableSize() + 2 : wGetDefsze();
- return sze.W;
-}
-
-int NCTable::preferredHeight()
-{
- wsze sze = ( biglist ) ? myPad()->tableSize() + 2 : wGetDefsze();
- return sze.H;
-}
+// DESCRIPTION : Change individual cell of a table line (to newtext)
+// provided for backwards compatibility
+//
-void NCTable::setEnabled( bool do_bv )
+void NCTable::cellChanged( int index, int colnum, const string & newtext )
{
- NCWidget::setEnabled( do_bv );
- YTable::setEnabled( do_bv );
+ NCTableLine * cl = myPad()->ModifyLine( index );
+ if ( !cl ) {
+ NCINT << "No such line: " << wpos( index, colnum ) << newtext << endl;
+ } else {
+ NCTableCol * cc = cl->GetCol( colnum );
+ if ( !cc ) {
+ NCINT << "No such colnum: " << wpos( index, colnum ) << newtext << endl;
+ } else {
+ // use NCtring to enforce recoding from 'utf8'
+ cc->SetLabel( NCstring( newtext ) );
+ DrawPad();
+ }
+ }
}
///////////////////////////////////////////////////////////////////
//
//
-// METHOD NAME : NCTable::setSize
+// METHOD NAME : NCTable::cellChanged
// METHOD TYPE : void
//
-// DESCRIPTION :
+// DESCRIPTION : Change individual cell of a table line (to newtext)
//
-void NCTable::setSize( int newwidth, int newheight )
+
+void NCTable::cellChanged( const YTableCell *cell )
{
- wRelocate( wpos( 0 ), wsze( newheight, newwidth ) );
+
+ cellChanged( cell->itemIndex(), cell->column(), cell->label() );
+
}
-///////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
//
//
-// METHOD NAME : NCTable::setLabel
+// METHOD NAME : NCTable::setKeepSorting
// METHOD TYPE : void
//
-// DESCRIPTION :
+// DESCRIPTION : set flag according to `opt(`keepSorting)
//
-void NCTable::setLabel( const YCPString & nlabel )
+
+void NCTable::setKeepSorting ( bool keepSorting )
{
- // not implemented: YTable::setLabel( nlabel );
- NCPadWidget::setLabel( NCstring( nlabel ) );
+ YTable::setKeepSorting( keepSorting );
+ sortable = keepSorting;
}
///////////////////////////////////////////////////////////////////
@@ -125,8 +125,9 @@
// METHOD NAME : NCTable::setHeader
// METHOD TYPE : void
//
-// DESCRIPTION :
+// DESCRIPTION : Set i-th table column header to 'text'
//
+
void NCTable::setHeader( int col, const string & text )
{
YTable::setHeader( col, text );
@@ -138,6 +139,16 @@
hasHeadline = myPad()->SetHeadline( header );
}
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : NCTable::setHeader
+// METHOD TYPE : void
+//
+// DESCRIPTION : Set table header all at once
+// (left here for backwards compatibility sake)
+//
+
void NCTable::setHeader( vector<string> head )
{
for (unsigned int i = 0; i < head.size(); i++) {
@@ -145,6 +156,17 @@
}
}
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : NCTable::setAlignment
+// METHOD TYPE : void
+//
+// DESCRIPTION : Set alignment of i-th table column (left, right,
+// center). Create temp. header consisting of single
+// letter - setHeader will append the rest
+//
+
void NCTable::setAlignment ( int col, YTable::Alignment al )
{
string s;
@@ -159,65 +181,19 @@
YTable::setAlignment( col, al );
}
-void NCTable::setKeepSorting ( bool keepSorting )
-{
- YTable::setKeepSorting( keepSorting );
- sortable = keepSorting;
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : NCTable::getCurrentItem
-// METHOD TYPE : int
-//
-// DESCRIPTION :
-//
-int NCTable::getCurrentItem()
-{
- if ( !myPad()->Lines() )
- return -1;
- return sortable ? myPad()->GetLine( myPad()->CurPos().L )->getIndex ()
- : myPad()->CurPos().L;
-
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : NCTable::setCurrentItem
-// METHOD TYPE : void
-//
-// DESCRIPTION :
-//
-void NCTable::setCurrentItem( int index )
-{
- myPad()->ScrlLine( index );
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : NCTable::setItemByKey
-// METHOD TYPE : bool
-//
-// DESCRIPTION :
-//
-bool NCTable::setItemByKey( int key )
-{
- return myPad()->setItemByKey( key );
-}
-
///////////////////////////////////////////////////////////////////
//
//
// METHOD NAME : NCTable::addItem
// METHOD TYPE : void
//
-// DESCRIPTION :
+// DESCRIPTION : Append item (as pointed to by 'yitem') to a table
+// (create new table line consisting of individual cells)
//
+
void NCTable::addItem( YItem *yitem )
{
+ //static counter - to remember last inserted item
static int idx = 0;
YTableItem *item = dynamic_cast(yitem);
@@ -226,14 +202,15 @@
vector Items( item->cellCount() );
unsigned int i = 0;
+ //Iterate over cells to create columns
for ( YTableCellIterator it = item->cellsBegin();
it != item->cellsEnd();
++it ){
- // use YCPString to enforce recoding from 'utf8'
Items[i] = new NCTableCol( NCstring( (*it)->label() ) );
i++;
}
+ //Insert @idx
NCTableLine *newline = new NCTableLine( Items, idx++ );
YUI_CHECK_PTR(newline);
newline->setOrigItem( item );
@@ -245,7 +222,9 @@
setCurrentItem( myPad()->Lines() ) ;
}
+ //Do not forget to redraw whole stuff at the end
DrawPad();
+
}
///////////////////////////////////////////////////////////////////
@@ -254,8 +233,9 @@
// METHOD NAME : NCTable::deleteAllItems
// METHOD TYPE : void
//
-// DESCRIPTION :
+// DESCRIPTION : Clear the table (in terms of YTable and visually)
//
+
void NCTable::deleteAllItems()
{
myPad()->ClearTable();
@@ -263,6 +243,47 @@
YTable::deleteAllItems();
}
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : NCTable::getCurrentItem
+// METHOD TYPE : int
+//
+// DESCRIPTION : Return index of currently selected table item
+//
+
+int NCTable::getCurrentItem()
+{
+ if ( !myPad()->Lines() )
+ return -1;
+ return sortable ? myPad()->GetLine( myPad()->CurPos().L )->getIndex ()
+ : myPad()->CurPos().L;
+
+}
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : NCTable::setCurrentItem
+// METHOD TYPE : void
+//
+// DESCRIPTION : Highlight item at 'index'
+//
+
+void NCTable::setCurrentItem( int index )
+{
+ myPad()->ScrlLine( index );
+}
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : NCTable::selectItem
+// METHOD TYPE : void
+//
+// DESCRIPTION : Mark table item (as pointed to by 'yitem') as selected
+//
+
void NCTable::selectItem( YItem *yitem, bool selected )
{
YTableItem *item = dynamic_cast(yitem);
@@ -280,13 +301,39 @@
}
else
{
+ //first highlight only, then select
setCurrentItem( line->getIndex() );
YTable::selectItem( item, selected);
}
+ //and redraw
DrawPad();
}
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : NCTable::selectCurrentItem
+// METHOD TYPE : void
+//
+// DESCRIPTION : Mark currently highlighted table item as selected
+//
+
+void NCTable::selectCurrentItem()
+{
+ const NCTableLine *cline = myPad()->GetLine( myPad()->CurPos().L );
+ YTable::selectItem( cline->origItem() );
+}
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : NCTable::deselectAllItems
+// METHOD TYPE : void
+//
+// DESCRIPTION : Mark all items as deselected
+//
+
void NCTable::deselectAllItems()
{
setCurrentItem( -1 );
@@ -294,50 +341,103 @@
DrawPad();
}
-void NCTable::selectCurrentItem()
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : NCTable::preferredWidth
+// METHOD TYPE : int
+//
+// DESCRIPTION : return preferred size
+//
+
+int NCTable::preferredWidth()
{
- const NCTableLine *cline = myPad()->GetLine( myPad()->CurPos().L );
- YTable::selectItem( cline->origItem() );
+ wsze sze = ( biglist ) ? myPad()->tableSize() + 2 : wGetDefsze();
+ return sze.W;
}
///////////////////////////////////////////////////////////////////
//
//
-// METHOD NAME : NCTable::cellChanged
+// METHOD NAME : NCTable::preferredHeight
+// METHOD TYPE : int
+//
+// DESCRIPTION : return preferred size
+//
+
+int NCTable::preferredHeight()
+{
+ wsze sze = ( biglist ) ? myPad()->tableSize() + 2 : wGetDefsze();
+ return sze.H;
+}
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : NCTable::setSize
+// METHOD TYPE : void
+//
+// DESCRIPTION : Set new size of the widget
+//
+
+void NCTable::setSize( int newwidth, int newheight )
+{
+ wRelocate( wpos( 0 ), wsze( newheight, newwidth ) );
+}
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : NCTable::setLabel
// METHOD TYPE : void
//
// DESCRIPTION :
//
-void NCTable::cellChanged( int index, int colnum, const string & newtext )
+
+void NCTable::setLabel( const YCPString & nlabel )
{
- NCTableLine * cl = myPad()->ModifyLine( index );
- if ( !cl ) {
- NCINT << "No such line: " << wpos( index, colnum ) << newtext << endl;
- } else {
- NCTableCol * cc = cl->GetCol( colnum );
- if ( !cc ) {
- NCINT << "No such colnum: " << wpos( index, colnum ) << newtext << endl;
- } else {
- // use YCPString to enforce recoding from 'utf8'
- cc->SetLabel( NCstring( newtext ) );
- DrawPad();
- }
- }
+ // not implemented: YTable::setLabel( nlabel );
+ NCPadWidget::setLabel( NCstring( nlabel ) );
}
-void NCTable::cellChanged( const YTableCell *cell ) {
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : NCTable::setEnabled
+// METHOD TYPE : void
+//
+// DESCRIPTION : Set widget state (enabled vs. disabled)
+//
- cellChanged( cell->itemIndex(), cell->column(), cell->label() );
+void NCTable::setEnabled( bool do_bv )
+{
+ NCWidget::setEnabled( do_bv );
+ YTable::setEnabled( do_bv );
+}
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : NCTable::setItemByKey
+// METHOD TYPE : bool
+//
+// DESCRIPTION :
+//
+bool NCTable::setItemByKey( int key )
+{
+ return myPad()->setItemByKey( key );
}
+
+
///////////////////////////////////////////////////////////////////
//
//
// METHOD NAME : NCTable::CreatePad
// METHOD TYPE : NCPad *
//
-// DESCRIPTION :
+// DESCRIPTION : Create new NCTablePad, set its background
//
NCPad * NCTable::CreatePad()
{
@@ -354,7 +454,9 @@
// METHOD NAME : NCTable::wHandleInput
// METHOD TYPE : NCursesEvent
//
-// DESCRIPTION :
+// DESCRIPTION : Handle 'special' keys i.e those not handled
+// by parent NCPad class (space, return). Set
+// items to selected, if appropriate
//
NCursesEvent NCTable::wHandleInput( wint_t key )
{
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=41427&r1=41426&r2=41427&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/ncurses/src/NCTable.h (original)
+++ branches/tmp/sh/mod-ui/ncurses/src/NCTable.h Mon Oct 15 14:25:03 2007
@@ -81,11 +81,11 @@
bool bigList() const { return biglist; }
bool isImmediate() const { return immediate; } // addey by gs
+ void setKeepSorting( bool keepSorting );
+
void setHeader( int col, const string & text ); // added by gs
void setHeader ( vector<string> header );
- void setAlignment ( int col, YTable::Alignment al );
- void setKeepSorting( bool keepSorting );
- virtual void deleteAllItems( );
+ virtual void setAlignment ( int col, YTable::Alignment al );
void setBigList( const bool big ) { biglist = big; }
void SetSepChar( const chtype colSepchar ) { myPad()->SetSepChar( colSepchar ); }
@@ -93,11 +93,13 @@
void SetHotCol( const int hcol ) { myPad()->SetHotCol( hcol ); }
virtual void addItem( YItem *yitem );
+ virtual void deleteAllItems( );
+
+ virtual int getCurrentItem();
+ virtual void setCurrentItem( int index );
virtual void selectItem( YItem *yitem, bool selected );
- virtual void deselectAllItems();
void selectCurrentItem();
-
- virtual long nicesize( YUIDimension dim );
+ virtual void deselectAllItems();
virtual int preferredWidth();
virtual int preferredHeight();
@@ -108,18 +110,14 @@
* Reimplemented from YWidget.
**/
virtual void setSize( int newWidth, int newHeight );
-
virtual void setLabel( const YCPString & nlabel );
-
- virtual int getCurrentItem();
- virtual void setCurrentItem( int index );
+ virtual void setEnabled( bool do_bv );
bool setItemByKey( int key );
virtual NCursesEvent wHandleInput( wint_t key );
//virtual void setEnabling( bool do_bv ) { NCWidget::setEnabling( enabled=do_bv ); }
- virtual void setEnabled( bool do_bv );
virtual bool setKeyboardFocus() {
if ( !grabFocus() )
Modified: branches/tmp/sh/mod-ui/ncurses/src/README_mod-ui
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/ncurses/src/README_mod-ui?rev=41427&r1=41426&r2=41427&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/ncurses/src/README_mod-ui (original)
+++ branches/tmp/sh/mod-ui/ncurses/src/README_mod-ui Mon Oct 15 14:25:03 2007
@@ -43,6 +43,8 @@
FIXME: entries are added twice -> see FileSelection examples
check setValue() (not used ???)
+TODO: Do something with adding items into NCPopupList, so that
+they can be read back.
NCPopupMenu/NCMenuButton
@@ -117,11 +119,10 @@
NCTable/NCPkgTable
------------------
-as long as NCTable isn't migrated it is necessary to call addChild() and setParent()
-TODO: remove this after migration !!!!!
+TODO: initialize header in constructor, set each header item separately
- Use WidgetFactory create methods, e.g. in NCAskForDirectory/File
- remove NCSpacing 0.x which are without effect for ncurses (NCAskFor..,
NCPkgPopup..)
-- call YUI_CHECK_NEW(() for all with 'new' created widgets, e.g. NCPopuptextEntryx
\ No newline at end of file
+- call YUI_CHECK_NEW(() for all with 'new' created widgets, e.g. NCPopuptextEntryx
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org