Author: kmachalkova Date: Wed Nov 7 16:04:08 2007 New Revision: 41857 URL: http://svn.opensuse.org/viewcvs/yast?rev=41857&view=rev Log: - selectItem and deselectAllItems added (so that QueryWidget does not return nonsense) - adjusted user input handling accordingly Modified: branches/tmp/sh/mod-ui/ncurses/src/NCMultiSelectionBox.cc branches/tmp/sh/mod-ui/ncurses/src/NCMultiSelectionBox.h Modified: branches/tmp/sh/mod-ui/ncurses/src/NCMultiSelectionBox.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/ncurses/src/NCMultiSelectionBox.cc?rev=41857&r1=41856&r2=41857&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/ncurses/src/NCMultiSelectionBox.cc (original) +++ branches/tmp/sh/mod-ui/ncurses/src/NCMultiSelectionBox.cc Wed Nov 7 16:04:08 2007 @@ -51,20 +51,6 @@ WIDDBG << endl; } -/////////////////////////////////////////////////////////////////// -// -// -// METHOD NAME : NCMultiSelectionBox::nicesize -// METHOD TYPE : long -// -// DESCRIPTION : -// -long NCMultiSelectionBox::nicesize( YUIDimension dim ) -{ - wsze sze = wsze::max( defsze, wsze( 0, labelWidht()+2 ) ); - return dim == YD_HORIZ ? wGetDefsze().W : wGetDefsze().H; -} - int NCMultiSelectionBox::preferredWidth() { return wGetDefsze().W; @@ -166,8 +152,10 @@ if ( item ) { YMultiSelectionBox::addItem( item ); - Items[0] = new NCTableTag( item->selected() ); - Items[1] = new NCTableCol( item->label(), NCTableCol::PLAIN ); + Items[0] = new NCTableTag( item, item->selected() ); + //Do not set style to NCTableCol::PLAIN here, otherwise current + //item will not be highlighted if cursor is not over the widget + Items[1] = new NCTableCol( item->label() ); myPad()->Append( Items ); DrawPad(); } @@ -228,10 +216,9 @@ // // DESCRIPTION : // -bool NCMultiSelectionBox::isItemSelected( int index ) const +bool NCMultiSelectionBox::isItemSelected( YItem *item ) { - const NCTableTag * citem = tagCell( index ); - return citem ? citem->Selected() : false; + return item->selected(); } /////////////////////////////////////////////////////////////////// @@ -244,8 +231,8 @@ // void NCMultiSelectionBox::setAllItemsSelected( bool val ) { - for ( int i = 0; setItemSelected( i, val, false ); ++i ) - ; + // for ( int i = 0; setItemSelected( i, val, false ); ++i ) + // ; DrawPad(); } @@ -257,19 +244,36 @@ // // DESCRIPTION : // -bool NCMultiSelectionBox::setItemSelected( int index, bool val, bool update ) +void NCMultiSelectionBox::selectItem( YItem *yitem, bool selected ) { - NCTableTag * citem = tagCell( index ); - if ( !citem ) - return false; - - if ( citem->Selected() != val ) { - citem->SetSelected( val ); - if ( update ) - DrawPad(); - } + YMultiSelectionBox::selectItem ( yitem, selected ); + + NCTableTag * tag = (NCTableTag *)yitem->data(); + YUI_CHECK_PTR( tag ); + + tag->SetSelected( selected ); + //if ( !citem ) + // return false; - return true; + //if ( citem->Selected() != val ) { + // citem->SetSelected( val ); + // if ( update ) + DrawPad(); + //} + + //return true; +} + +void NCMultiSelectionBox::deselectAllItems() +{ + YMultiSelectionBox::deselectAllItems(); + + for ( unsigned int i = 0; i < getNumLines(); i++) + { + NCTableTag *t = tagCell( i ); + t->SetSelected( false ); + } + DrawPad(); } /////////////////////////////////////////////////////////////////// @@ -282,19 +286,21 @@ // void NCMultiSelectionBox::toggleCurrentItem() { - int index = getCurrentItem(); - if ( index == -1 ) - return; - - NCTableTag * citem = tagCell( index ); - if ( !citem ) - return; + YItem *it = currentItem(); + selectItem( it, !( it->selected()) ); + //int index = getCurrentItem(); + //if ( index == -1 ) + // return; - citem->SetSelected( !citem->Selected() ); - DrawPad(); + //NCTableTag * citem = tagCell( index ); + //if ( !citem ) + // return; + + //citem->SetSelected( !citem->Selected() ); + //DrawPad(); } -/////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// // // // METHOD NAME : NCMultiSelectionBox::setLabel @@ -350,10 +356,12 @@ { NCursesEvent ret; bool valueChanged = false; - int oldCurrentItem = getCurrentItem(); + YItem *oldCurrentItem = currentItem(); if ( ! handleInput( key ) ) { + YItem *citem = currentItem(); + switch ( key ) { case KEY_SPACE: case KEY_RETURN: @@ -361,15 +369,15 @@ valueChanged = true; break; case '+': - if ( !itemIsSelected( getCurrentItem() ) ) { - setItemSelected( getCurrentItem(), true, false ); + if ( !isItemSelected( citem ) ) { + selectItem( citem, true ); valueChanged = true; } myPad()->ScrlDown(); break; case '-': - if ( itemIsSelected( getCurrentItem() ) ) { - setItemSelected( getCurrentItem(), false, false ); + if ( isItemSelected( citem ) ) { + selectItem( citem, false); valueChanged = true; } myPad()->ScrlDown(); @@ -381,7 +389,7 @@ { if ( valueChanged ) ret = NCursesEvent::ValueChanged; - else if ( oldCurrentItem != getCurrentItem() ) + else if ( oldCurrentItem != currentItem() ) ret = NCursesEvent::SelectionChanged; } Modified: branches/tmp/sh/mod-ui/ncurses/src/NCMultiSelectionBox.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/ncurses/src/NCMultiSelectionBox.h?rev=41857&r1=41856&r2=41857&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/ncurses/src/NCMultiSelectionBox.h (original) +++ branches/tmp/sh/mod-ui/ncurses/src/NCMultiSelectionBox.h Wed Nov 7 16:04:08 2007 @@ -40,14 +40,18 @@ private: + YItem *yitem; bool selected; public: - NCTableTag( const bool sel = false ) + NCTableTag( YItem *item, const bool sel = false ) : NCTableCol( NCstring( "[ ]" ), SEPARATOR ) + , yitem (item) , selected( sel ) - {} + { + yitem->setData( this ); + } virtual ~NCTableTag() {} virtual void SetLabel( const NCstring & ) { /*NOOP*/; } @@ -65,6 +69,7 @@ void SetSelected( const bool sel ) { selected = sel; } bool Selected() const { return selected; } + YItem *origItem() { return yitem; } }; @@ -92,8 +97,7 @@ NCTableTag * tagCell( int index ); const NCTableTag * tagCell( int index ) const; - bool isItemSelected( int index ) const; - bool setItemSelected( int index, bool val, bool update = true ); + bool isItemSelected( YItem *item ); void setAllItemsSelected( bool val ); void toggleCurrentItem(); @@ -103,8 +107,8 @@ virtual void startMultipleChanges() { startMultidraw(); } virtual void doneMultipleChanges() { stopMultidraw(); } - virtual void selectItem( int index ) { setItemSelected( index, true ); } - virtual void deselectItem( int index ){ setItemSelected( index, false ); } + //virtual void selectItem( int index ) { setItemSelected( index, true ); } + virtual void deselectItem( int index ){ }//setItemSelected( index, false ); } protected: @@ -118,13 +122,11 @@ virtual void deleteAllItems(); - virtual bool itemIsSelected( int index ) { return isItemSelected( index ); } - - virtual void selectItem( YItem * item, bool selected ) - { setItemSelected( item->index(), selected ); } + virtual void selectItem( YItem * item, bool selected ); +// { setItemSelected( item->index(), selected ); } virtual void selectAllItems() { setAllItemsSelected( true ); } - virtual void deselectAllItems() { setAllItemsSelected( false ); } + virtual void deselectAllItems(); // { setAllItemsSelected( false ); } virtual int getCurrentItem(); @@ -133,8 +135,6 @@ NCMultiSelectionBox( YWidget * parent, const string & label ); virtual ~NCMultiSelectionBox(); - virtual long nicesize( YUIDimension dim ); - virtual int preferredWidth(); virtual int preferredHeight(); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org