Author: kmachalkova Date: Thu Mar 13 12:53:18 2008 New Revision: 45421 URL: http://svn.opensuse.org/viewcvs/yast?rev=45421&view=rev Log: Set combobox text-area size to match its longest item (#367083) Modified: trunk/ncurses/src/NCComboBox.cc trunk/ncurses/src/NCComboBox.h Modified: trunk/ncurses/src/NCComboBox.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses/src/NCComboBox.cc?rev=45421&r1=45420&r2=45421&view=diff ============================================================================== --- trunk/ncurses/src/NCComboBox.cc (original) +++ trunk/ncurses/src/NCComboBox.cc Thu Mar 13 12:53:18 2008 @@ -44,6 +44,7 @@ , fldstart ( 0 ) , fldlength( 0 ) , curpos( 0 ) + , longest_line(10) , index( -1 ) , InputMaxLength( -1 ) { @@ -131,8 +132,12 @@ // void NCComboBox::setDefsze() { + // Height: label h. + 1 (text area) + // Width: longest line + 2 chars ( arrow(s) ) + // (here, we should not rely on label width only as text area may become + // unreasonably small then - #367083 ) defsze = wsze( label.height() + 1, - label.width() < 5 ? 5 : label.width() ); + (label.width() > longest_line) ? label.width() : longest_line + 2 ); } /////////////////////////////////////////////////////////////////// @@ -202,6 +207,16 @@ YComboBox::addItem( item ); deflist.push_back( item->label() ); + string::size_type this_line = item->label().size(); + + //Is this line longer than the longest one so far? + //(but no greater than 40 chars, we may have only 80x25 screen) + if ( (this_line > longest_line) && (this_line <= 40) ) + { + //yes, so let's resize the text area) + longest_line = this_line; + setDefsze(); + } if ( item->selected() ) { index = item->index(); @@ -300,7 +315,11 @@ modified = false; fldstart = 0; curpos = mayedit ? buffer.length() : 0; - setDefsze(); + + //(Maybe) no need to set default size here, it has been + //alread calculated as the items were added (see addItem() above) + //setDefsze(); + tUpdate(); Redraw(); } @@ -639,17 +658,18 @@ // int NCComboBox::listPopup() { + int idx = -1; if (!deflist.empty()) { wpos at( ScreenPos() + wpos( win->height(), -1 ) ); NCPopupList * dialog = new NCPopupList( at, "", deflist, index ); YUI_CHECK_NEW( dialog ); - int idx = dialog->post(); + idx = dialog->post(); if ( idx != -1 ) setCurrentItem( idx ); YDialog::deleteTopmostDialog(); } - - return 0; + + return idx; } /////////////////////////////////////////////////////////////////// Modified: trunk/ncurses/src/NCComboBox.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses/src/NCComboBox.h?rev=45421&r1=45420&r2=45421&view=diff ============================================================================== --- trunk/ncurses/src/NCComboBox.h (original) +++ trunk/ncurses/src/NCComboBox.h Thu Mar 13 12:53:18 2008 @@ -57,6 +57,7 @@ string::size_type fldstart; string::size_type fldlength; string::size_type curpos; + string::size_type longest_line; NCstring validChars; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org