Author: sh-sh-sh
Date: Fri Jun 29 20:31:20 2007
New Revision: 39101
URL: http://svn.opensuse.org/viewcvs/yast?rev=39101&view=rev
Log:
Porting selection widgets
!!! DOES NOT COMPILE YET !!!
(pre-weekend backup checkin)
Added:
branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc
branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h
Modified:
branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog
branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am
branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc
branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.cc
branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.h
branches/tmp/sh/mod-ui/core/libyui/src/YCP_UI_Exception.h
branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.cc
branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.h
branches/tmp/sh/mod-ui/core/libyui/src/YInputField.cc
branches/tmp/sh/mod-ui/core/libyui/src/YInputField.h
branches/tmp/sh/mod-ui/core/libyui/src/YItem.h
branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.cc
branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.h
branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.cc
branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.h
branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc
branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc
branches/tmp/sh/mod-ui/qt/src/YQComboBox.h
branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc
branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog Fri Jun 29 20:31:20 2007
@@ -296,3 +296,12 @@
* added modeFlags parameter for PackageSelector etc.
* now calling the YPackagePlugin from the factory create...() functions
+
+2007-06-29 12:00 sh@suse.de
+
+* Added YSelectionBox::immediateMode() and setImmediateMode()
+ as a replacement for YWidgetOpt.immediateMode
+
+* Added YSelectionBox::shrinkable() and setShrinkable()
+ as a replacement for YWidgetOpt.shrinkable
+
Modified: branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am Fri Jun 29 20:31:20 2007
@@ -27,6 +27,7 @@
YCPValueWidgetID.cc \
YCPDialogParser.cc \
YCPItemParser.cc \
+ YCPPropertyHandler.cc \
\
YAlignment.cc \
YBarGraph.cc \
@@ -86,6 +87,7 @@
YCPDialogParser.h \
YCPItem.h \
YCPItemParser.h \
+ YCPPropertyHandler.h \
YCPValueWidgetID.h \
YCP_UI_Exception.h \
YChildrenManager.h \
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc Fri Jun 29 20:31:20 2007
@@ -32,6 +32,7 @@
#include "YUISymbols.h"
#include "YWidget.h"
#include "YCPValueWidgetID.h"
+#include "YCPItemParser.h"
#include "YDialog.h"
#include "YUI_util.h"
#include "YWidgetFactory.h"
@@ -1781,25 +1782,36 @@
return 0;
}
+ string label = term->value( argnr )->asString()->value();
+
+ bool shrinkable = false;
+ bool immediate = false;
+
for ( int o=0; o < optList->size(); o++ )
{
- if ( optList->value(o)->isSymbol() && optList->value(o)->asSymbol()->symbol() == YUIOpt_shrinkable ) opt.isShrinkable.setValue( true );
- else if ( optList->value(o)->isSymbol() && optList->value(o)->asSymbol()->symbol() == YUIOpt_immediate )
- {
- opt.notifyMode.setValue( true );
- opt.immediateMode.setValue( true );
- }
+ if ( optList->value(o)->isSymbol() && optList->value(o)->asSymbol()->symbol() == YUIOpt_shrinkable ) shrinkable = true;
+ else if ( optList->value(o)->isSymbol() && optList->value(o)->asSymbol()->symbol() == YUIOpt_immediate ) immediate = true;
else logUnknownOption( term, optList->value(o) );
}
- YSelectionBox *selbox = dynamic_cast ( YUI::ui()->createSelectionBox( parent, opt, term->value( argnr )->asString() ) );
+ YSelectionBox *selBox = YUI::widgetFactory()->createSelectionBox( parent, label );
+
+#warning TO DO: shrinkable / immediate
+#if 0
+ if ( shrinkable )
+ selBox->setShrinkable( true );
+
+ if ( immediate )
+ selBox->setImmediate( true ); // includes setNotify()
+#endif
- if ( selbox && numargs >= 2 )
+ if ( numargs >= 2 )
{
- selbox->parseItemList( term->value( argnr+1 )->asList() );
+ YCPList itemList = term->value( argnr+1 )->asList();
+ selBox->addItems( YCPItemParser::parseItemList( itemList );
}
- return selbox;
+ return selBox;
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.cc?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.cc Fri Jun 29 20:31:20 2007
@@ -26,35 +26,36 @@
#include "YUISymbols.h"
-YItemList
-YCPItemParser::parseItemList( const YCPList & ycpItemList )
+YItemCollection
+YCPItemParser::parseItemList( const YCPList & itemList )
{
- YItemList itemList;
+ YItemCollection itemCollection;
+ itemCollection.reserve( itemList.size() );
try
{
- for ( int i=0; i < ycpItemList->size(); i++ )
+ for ( int i=0; i < itemList->size(); i++ )
{
- YCPItem * item = parseItem( ycpItemList->value(i) );
- itemList.push_back( item );
+ YCPItem * item = parseItem( itemList->value(i) );
+ itemCollection.push_back( item );
}
}
catch ( YUIException & exception )
{
- YItemListIterator it = itemList.begin();
+ YItemIterator it = itemCollection.begin();
- while ( it != itemList.end() )
+ while ( it != itemCollection.end() )
{
YItem * item = *it;
++it;
delete item;
}
- itemList.clear();
+ itemCollection.clear();
YUI_RETHROW( exception );
}
- return itemList;
+ return itemCollection;
}
@@ -74,14 +75,14 @@
else // `item(...)
{
if ( rawItem->isTerm() &&
- rawItem->asTerm()->name() == YUISymbol_item ) // `item
+ rawItem->asTerm()->name() == YUISymbol_item ) // `item(...)
{
item = parseItem( rawItem->asTerm() );
}
else // not `item(...)
{
- YUI_THROW( YCPDialogSyntaxError( "Expected `item(...)", rawItem ) );
+ YUI_THROW( YCPDialogSyntaxErrorException( "Expected `item(...)", rawItem ) );
}
}
@@ -92,17 +93,14 @@
YCPItem *
YCPItemParser::parseItem( const YCPTerm & itemTerm )
{
- YCPValue id = YCPNull();
- YCPString iconName = YCPNull();
- YCPString label = YCPNull();
- YCPBoolean selected = YCPNull();
-
- YCPDialogSyntaxError syntaxError( "Expected "
- "`item(`id(`myID), "
- "`icon(\"MyIcon.png\"),"
- "\"MyItemText\","
- "boolean selected )",
- itemTerm );
+ YCPValue id = YCPNull();
+ YCPString iconName = YCPNull();
+ YCPString label = YCPNull();
+ YCPBoolean selected = YCPNull();
+
+ string usage =
+ "Expected: `item(`id(`myID), `icon(\"MyIcon.png\"), \"MyItemText\", boolean selected )";
+
for ( int i=0; i < itemTerm->size(); i++ )
{
@@ -112,43 +110,43 @@
{
YCPTerm term = arg->asTerm();
- if ( term->size() != 1 )
- YUI_THROW( syntaxError );
+ if ( term->size() != 1 ) // Both `id() and `icon() have 1 argument
+ YUI_THROW( YCPDialogSyntaxErrorException( usage, itemTerm ) );
- if ( term->name() == YUISymbol_id // `id()
+ if ( term->name() == YUISymbol_id // `id(...)
&& id.isNull() ) // and don't have an ID yet
{
id = term->value(0);
}
- else if ( term->name() == YUISymbol_icon // `icon()
- && term->value(0)->isString()
+ else if ( term->name() == YUISymbol_icon // `icon(...)
+ && term->value(0)->isString() // with a string argument
&& iconName.isNull() ) // and don't have an icon name yet
{
iconName = term->value(0)->asString();
}
else
{
- YUI_THROW( syntaxError );
+ YUI_THROW( YCPDialogSyntaxErrorException( usage, itemTerm ) );
}
}
- else if ( arg->isString() // label
- && label.isNull() ) // and don't have a label yet
+ else if ( arg->isString() // label (the user-visible text)
+ && label.isNull() ) // and don't have a label yet
{
label = arg->asString();
}
- else if ( arg->isBoolean() // "selected" flag
- && selected.isNull() ) // and don't have a "selected" flag yet
+ else if ( arg->isBoolean() // "selected" flag
+ && selected.isNull() ) // and don't have a "selected" flag yet
{
selected = arg->asBoolean();
}
else
{
- YUI_THROW( syntaxError );
+ YUI_THROW( YCPDialogSyntaxErrorException( usage, itemTerm ) );
}
}
if ( label.isNull() ) // the label is required
- YUI_THROW( syntaxError );
+ YUI_THROW( YCPDialogSyntaxErrorException( usage, itemTerm ) );
if ( iconName.isNull() )
iconName = YCPString( "" );
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.h?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.h Fri Jun 29 20:31:20 2007
@@ -43,7 +43,7 @@
*
* This function throws exceptions if there are syntax errors.
**/
- static YItemList parseItemList( const YCPList & ycpItemList );
+ static YItemCollection parseItemList( const YCPList & ycpItemList );
/**
Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc?rev=39101&view=auto
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc (added)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc Fri Jun 29 20:31:20 2007
@@ -0,0 +1,298 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YCPPropertyHandler.h
+
+ Widget property handlers for not-so-trivial properties.
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#include
+#include
+#include
+#include
+
+#include "YCPPropertyHandler.h"
+
+#include "YCheckBox.h"
+#include "YSelectionBox.h"
+#include "YComboBox.h"
+#include "YCPItem.h"
+#include "YUISymbols.h"
+
+
+
+void
+YCPPropertyHandler::setComplexProperty( YWidget * widget,
+ const string & propertyName,
+ const YCPValue & val )
+{
+ // y2debug( "%s::%s", widget->widgetClass(), propertyName.c_str() );
+
+ if ( propertyName == YUIProperty_Value )
+ {
+ if ( trySetCheckBoxValue ( widget, val ) ) return;
+ if ( trySetSelectionBoxValue ( widget, val ) ) return;
+ if ( trySetComboBoxValue ( widget, val ) ) return;
+ }
+
+ if ( propertyName == YUIProperty_CurrentItem )
+ {
+ if ( trySetSelectionBoxValue ( widget, val ) ) return;
+ }
+
+ if ( propertyName == YUIProperty_Items )
+ {
+ if ( trySetSelectionWidgetItems( widget, val ) ) return;
+ }
+
+ y2error( "Can't handle property %s::%s - not changing anything"
+ widget->widgetClass(), propertyName.c_str() );
+}
+
+
+YCPValue
+YCPPropertyHandler::getComplexProperty( YWidget * widget, const string & propertyName )
+{
+ YCPValue val = YCPNull();
+
+ if ( propertyName == YUIProperty_Value )
+ {
+ val = tryGetCheckBoxValue ( widget ); if ( ! val.isNull() ) return val;
+ val = tryGetComboBoxValue ( widget ); if ( ! val.isNull() ) return val;
+ val = tryGetSelectionBoxValue ( widget ); if ( ! val.isNull() ) return val;
+ }
+
+ if ( propertyName == YUIProperty_CurrentItem )
+ {
+ val = tryGetSelectionBoxValue ( widget ); if ( ! val.isNull() ) return val;
+ val = tryGetComboBoxValue ( widget ); if ( ! val.isNull() ) return val;
+ }
+
+ y2error( "Can't handle property %s::%s - returning 'nil'",
+ widget->widgetClass(), propertyName.c_str() );
+
+ return YCPVoid();
+}
+
+
+
+
+
+
+bool
+YCPPropertyHandler::trySetCheckBoxValue( YWidget * widget, const YCPValue & val )
+{
+ YCheckBox * checkBox = dynamic_cast (widget);
+
+ if ( ! checkBox )
+ return false;
+
+ if ( val->isBoolean() )
+ {
+ checkBox->setChecked( val->asBoolean()->value() );
+ return true;
+ }
+ else if ( val->isVoid() )
+ {
+ checkBox->setDontCare();
+ return true;
+ }
+
+ YUI_THROW( YUIBadPropertyArgException( YProperty( YUIProperty_Value,
+ YOtherProperty ),
+ checkbox ) );
+ return false;
+}
+
+
+bool
+YCPPropertyHandler::trySetSelectionBoxValue( YWidget * widget, const YCPValue & val )
+{
+ YSelectionBox * selBox = dynamic_cast (widget);
+
+ if ( ! selBox )
+ return false;
+
+ YCPItem * item = findItem( selBox, val );
+
+ if ( item )
+ {
+ selBox->selectItem( item, true );
+ }
+ else
+ {
+ y2error( "%s %s has no item with ID %s",
+ widget->widgetClass(),
+ widget->debugLabel().c_str(),
+ val->toString().c_str() );
+ }
+
+ return true;
+}
+
+
+bool
+YCPPropertyHandler::trySetComboBoxValue( YWidget * widget, const YCPValue & val )
+{
+ YSelectionBox * comboBox = dynamic_cast (widget);
+
+ if ( ! comboBox )
+ return false;
+
+ YCPItem * item = findItem( comboBox, val );
+
+ if ( item )
+ {
+ comboBox->selectItem( item, true );
+ }
+ else
+ {
+ if ( comboBox->editable() )
+ {
+ if ( val->isString() || val->isInteger() )
+ {
+ comboBox->setText( val->toString() );
+ return true;
+ }
+ }
+
+ y2error( "%s %s has no item with ID %s",
+ widget->widgetClass(),
+ widget->debugLabel().c_str(),
+ val->toString().c_str() );
+ }
+
+ return true;
+}
+
+
+YCPItem *
+YCPPropertyHandler::findItem( YSelectionWidget * selWidget, const YCPValue & val )
+{
+ YCPValue wantedId( val );
+
+ if ( val->isTerm() && val->asTerm()->name() == YUISymbol_id ) // `id(..) ?
+ {
+ wantedId = val->asTerm()->value(0);
+ }
+
+ for ( YItemIterator it = selWidget->itemsBegin();
+ it != selWidget->itemsEnd();
+ ++it )
+ {
+ YCPItem * item = dynamic_cast (*it);
+
+ if ( item && item->id() && wantedId )
+ return item;
+ }
+
+ return 0;
+}
+
+
+bool
+YCPPropertyHandler::trySetSelectionWidgetItems( YWidget * widget, const YCPValue & val )
+{
+ YSelectionWidget * selWidget = dynamic_cast (widget );
+
+ if ( ! selWidget )
+ return false;
+
+ if ( val->isList() )
+ {
+ selWidget->setItems( YCPItemParser::parseItemList( val->asList ) );
+ return true;
+ }
+
+ YUI_THROW( YUIBadPropertyArgException( YProperty( propertyName,
+ YOtherProperty ),
+ widget ) );
+ return false;
+}
+
+
+
+
+
+
+
+
+YCPValue
+YPropertyHandler::tryGetCheckBoxValue( YWidget * widget )
+{
+ YCheckBox * checkBox = dynamic_cast (widget);
+
+ if ( ! checkBox )
+ return YCPNull();
+
+ switch ( checkBox->value() )
+ {
+ case YCheckBox_on: return YCPBoolean( true );
+ case YCheckBox_off: return YCPBoolean( false );
+ case YCheckBox_dont_care: return YCPVoid(); // nil
+ }
+
+ return YCPVoid(); // shouldn't happen
+}
+
+
+
+YCPValue
+YPropertyHandler::tryGetComboBoxValue( YWidget * widget )
+{
+ YComboBox * comboBox = dynamic_cast (widget);
+
+ if ( ! comboBox )
+ return YCPNull();
+
+
+ YItem * selectedItem = comboBox->selectedItem();
+
+ if ( selectedItem )
+ {
+ YCPItem * item = dynamic_cast (selectedItem);
+
+ if ( item )
+ return item->id();
+ }
+
+ return YCPString( comboBox->text() );
+}
+
+
+YCPValue
+YPropertyHandler::tryGetSelectionBoxValue( YWidget * widget )
+{
+ YSelectionBox * selBox = dynamic_cast (widget);
+
+ if ( ! selBox )
+ return YCPNull();
+
+ YItem * selectedItem = selBox()->selectedItem();
+
+ if ( selectedItem )
+ {
+ YCPItem * item = dynamic_cast (selectedItem);
+
+ if ( item )
+ return item->id();
+ else
+ return YCPString( selectedItem->label() );
+ }
+
+ return YCPVoid();
+}
+
Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h?rev=39101&view=auto
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h (added)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h Fri Jun 29 20:31:20 2007
@@ -0,0 +1,93 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YCPPropertyHandler.h
+
+ Widget property handlers for not-so-trivial properties.
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#ifndef YCPPropertyHandler_h
+#define YCPPropertyHandler_h
+
+#include
+#include <string>
+
+using std::string;
+
+
+/**
+ * Get and set complex widget properties.
+ *
+ * Simple properties of types string, bool, int are set with
+ * YWidget::setProperty() and retrieved with YWidget::getProperty().
+ *
+ * The functions here are needed for more complex cases, either because there
+ * is no unambiguous conversion from a C++ data type to a YCPValue (or vice
+ * versa) or for historical reasons to maintain backward compatibility with
+ * existing YCP code.
+ **/
+class YPropertyHandler
+{
+public:
+ /**
+ * Set a complex property.
+ **/
+ static void setComplexProperty( YWidget * widget,
+ const string & propertyName,
+ const YCPValue & val );
+
+
+ /**
+ * Get a complex property.
+ **/
+ static YCPValue getComplexProperty( YWidget * widget,
+ const string & propertyName );
+
+ /**
+ * Find a YSelectionWidget's (YSelectionBox, YComboBox, YMultiSelectionBox)
+ * item by its ID. If the ID is wrapped in `id(...), use the inner part of that.
+ *
+ * Return the item or 0 if there is no item with that ID.
+ **/
+ static YCPItem * findItem( YSelectionWidget * selWidget, const YCPValue & id );
+
+
+protected:
+
+ /**
+ * All trySet..() functions try to dynamic_cast 'widget' to the expected
+ * widget type and then set a property.
+ *
+ * They all return 'true' upon success and 'false' upon failure.
+ **/
+ static bool trySetCheckBoxValue ( YWidget * widget, const YCPValue & val );
+ static bool trySetSelectionBoxValue ( YWidget * widget, const YCPValue & val );
+ static bool trySetComboBoxValue ( YWidget * widget, const YCPValue & val );
+ static bool trySetSelectionWidgetItems ( YWidget * widget, const YCPValue & val );
+
+ /**
+ * All trySet..() functions try to dynamic_cast 'widget' to the expected
+ * widget type and then retrieve a property.
+ *
+ * They all return YCPNull upon failure and a non-null YCPValue upon success.
+ **/
+ static YCPValue tryGetCheckBoxValue ( YWidget * widget );
+ static YCPValue tryGetComboBoxValue ( YWidget * widget );
+ static YCPValue tryGetSelectionBoxValue ( YWidget * widget );
+};
+
+
+#endif // YCPPropertyHandler_h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCP_UI_Exception.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCP_UI_Exception.h?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCP_UI_Exception.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCP_UI_Exception.h Fri Jun 29 20:31:20 2007
@@ -27,22 +27,22 @@
/**
* Exception class for "YCP dialog term syntax error"
**/
-class YCPDialogSyntaxError: public YUIException
+class YCPDialogSyntaxErrorException: public YUIException
{
public:
- YCPDialogSyntaxError( const string & msg )
+ YCPDialogSyntaxErrorException( const string & msg )
: YUIException( string( "Syntax Error:" ) + msg )
{}
- YCPDialogSyntaxError( const string & expected,
- const YCPValue & seen )
+ YCPDialogSyntaxErrorException( const string & expected,
+ const YCPValue & seen )
: YUIException( string( "Syntax Error: " )
+ expected
+ string( ", seen: " ) +
seen->toString() )
{}
- virtual ~YCPDialogSyntaxError() throw()
+ virtual ~YCPDialogSyntaxErrorException() throw()
{}
};
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.cc?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.cc Fri Jun 29 20:31:20 2007
@@ -17,191 +17,216 @@
/-*/
-#include
-#include
-#include
-#include
#define y2log_component "ui"
#include
#include "YUISymbols.h"
#include "YMacroRecorder.h"
#include "YComboBox.h"
+#include "YUIException.h"
-YComboBox::YComboBox( const YWidgetOpt & opt, YCPString label )
- : YSelectionWidget( opt, label )
- , validChars( "" )
+struct YComboBoxPrivate
+{
+ YComboBoxPrivate( bool editable )
+ , editable( editable )
+ , inputMaxLength( -1 );
+ {}
+
+ bool editable;
+ string validChars;
+ int inputMaxLength;
+};
+
+
+
+
+YComboBox::YComboBox( YWidget * parent, const string & label, bool editable )
+ : YSelectionWidget( parent, label )
+ , priv( new YComboBoxPrivate( editable )
{
- // y2debug( "YComboBox( %s )", label->value_cstr() );
- _editable = opt.isEditable.value();
}
-YCPValue YComboBox::changeWidget( const YCPSymbol & property, const YCPValue & newvalue )
+YComboBox::~YComboBox()
{
- string s = property->symbol();
+ // NOP
+}
- /**
- * @property string Label
- * The label above the ComboBox describing what it is all about
- */
- if ( s == YUIProperty_Label )
- {
- return changeLabel ( newvalue );
- }
- /**
- * @property string Value
- * The current value of the ComboBox. If this is a list item which
- * has an ID, the ID will be used rather than the corresponding text.
- * For editable ComboBox widgets it is OK to set <em>any</em> value - even
- * if it doesn't exist in the list.
- */
- else if ( s == YUIProperty_Value ) // Select item with that id
- {
- int index = itemWithId( newvalue, ! editable() ); // true: log error
+bool YComboBox::editable() const
+{
+ return priv->editable;
+}
- if ( index >= 0 ) // Item already exists in list
- {
- setCurrentItem( index );
- return YCPBoolean( true ); // OK
- }
- else // Item not in list
- {
- if ( editable() && newvalue->isString() )
- {
- setValue( newvalue->asString() );
- return YCPBoolean( true ); // OK
- }
- else // ! editable()
- {
- return YCPBoolean( false ); // Error
- }
- }
- }
- /**
- * @property id_list Items
- * The items that are displayed
- */
- else if ( s == YUIProperty_Items )
- {
- return changeItems( newvalue );
- }
+string YComboBox::validChars()
+{
+ return priv->validChars;
+}
+
- /**
- * @property string ValidChars valid input characters
- */
- else if ( s == YUIProperty_ValidChars )
+void YComboBox::setValidChars( const string & newValidChars )
+{
+ priv->validChars= newValidChars;
+}
+
+
+int YComboBox::inputMaxLength() const
+{
+ return priv->inputMaxLength;
+}
+
+
+void YComboBox::setInputMaxLength( int len )
+{
+ priv->inputMaxLength = len;
+}
+
+
+string YComboBox::value()
+{
+ return text();
+}
+
+
+void YComboBox::setValue( const string & newText )
+{
+ YItem * item = findItem( newText );
+
+ if ( item )
{
- if ( editable() )
- {
- if ( newvalue->isString() )
- {
- setValidChars( newvalue->asString() );
- return YCPBoolean( true );
- }
- else
- {
- y2error( "ComboBox: Invalid parameter %s for ValidChars property. Must be string.",
- newvalue->toString().c_str() );
- return YCPBoolean( false );
- }
- }
- else
- {
- y2error( "ComboBox: Setting the ValidChars property doesn't make sense "
- "for a non-editable ComboBox!" );
- return YCPBoolean( false );
- }
+ YSelectionWidget::deselectAllItems();
+ item->setSelected();
+ setText( item->label() );
}
- /**
- * @property integer InputMaxLength limit the number of characters which
- * can be inserted. A value of -1 means unlimited input.
- */
- else if ( s == YUIProperty_InputMaxLength )
+ else
{
- if ( newvalue->isInteger() )
- {
- setInputMaxLength( newvalue->asInteger()->value() );
- return YCPBoolean( true );
- }
+ if ( editable() )
+ setText( newText );
else
{
- y2error( "ComboBox: Invalid parameter %s for InputMaxLength property. Must be integer.",
- newvalue->toString().c_str() );
- return YCPBoolean( false );
+ YUI_THROW( YUIException( "Invalid value" ) );
}
}
- else return YWidget::changeWidget( property, newvalue ); // handle default properties
}
-YCPValue YComboBox::queryWidget( const YCPSymbol & property )
+void YComboBox::selectItem( YItem * item, bool selected )
{
- string s = property->symbol();
- if ( s == YUIProperty_Label ) return getLabel();
- else if ( s == YUIProperty_Value )
+ // Check against null pointer and if the item actually belongs to this
+ // widget, deselect any previously selected item and select the new one
+ YSelectionWidget::selectItem( item, selected );
+ setText( item->label() );
+}
+
+
+const YItem *
+YComboBox::selectedItem()
+{
+ string currentText = text();
+
+ if ( ! currentText.empty() )
{
- int current = getCurrentItem();
+ // Try to find an item with this text
- YCPString origLabel = current >= 0 && current < item_labels->size() ?
- item_labels->value( current )->asString() : YCPString( "" );
+ YItem * item = findItem( currentText );
- if ( _editable )
+ if ( item )
{
- YCPString val = getValue();
-
- if ( current < 0 || val->value() != origLabel->value() )
- {
- // If the user edited the text (if he can do that),
- // return the user's input.
-
- return val;
- }
- }
+ // Make sure exactly this item is selected (and no other)
- if ( current < 0 )
- return YCPVoid();
-
- if ( current < item_ids->size() )
- {
- // Try to find the corresponding ID.
-
- YCPValue id = item_ids->value( current );
-
- if ( ! id.isNull() && ! id->isVoid() )
- return id;
- }
+ YSelectionWidget::deselectAllItems();
+ item->setSelected( true );
- // As a last resort, fall back to the item's label text.
-
- return origLabel;
+ return item;
+ }
+ }
+ else
+ {
+ YSelectionWidget::deselectAllItems();
+ return 0;
}
- else if ( s == YUIProperty_ValidChars ) return getValidChars();
- else return YWidget::queryWidget( property );
}
-void YComboBox::setValidChars( const YCPString & newValidChars )
+YConstItemCollection
+YComboBox::selectedItems()
+{
+ YConstItemCollection selectedItems;
+
+ // There can be no more than one selected item
+ const YItem * item = selectedItem();
+
+ if ( item )
+ selectedItems.push_back( item );
+
+ return selectedItems;
+}
+
+
+const YPropertySet &
+YComboBox::propertySet()
{
- this->validChars= newValidChars;
+ static YPropertySet propSet;
+
+ if ( propSet.isEmpty() )
+ {
+ /*
+ * @property itemID | string Value ID of the selected item or the text the user entered
+ * @property string Label caption above the combo box
+ * @property string ValidChars set of valid input characters
+ * @property integer InputMaxLength maximum number of input characters
+ */
+ propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) );
+ propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
+ propSet.add( YProperty( YUIProperty_ValidChars, YStringProperty ) );
+ propSet.add( YProperty( YUIProperty_InputMaxLength, YIntegerProperty ) );
+ propSet.add( YWidget::propertySet() );
+ }
+
+ return propSet;
}
-YCPString YComboBox::getValidChars()
+bool
+YComboBox::setProperty( const string & propertyName, const YPropertyValue & val )
{
- return validChars;
+ propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
+
+ if ( propertyName == YUIProperty_Value ) return false; // Need special handling
+ else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
+ else if ( propertyName == YUIProperty_ValidChars ) setValidChars( val.stringVal() );
+ else if ( propertyName == YUIProperty_InputMaxLength ) setInputMaxLength( val.integerVal() );
+ else
+ {
+ YWidget::setProperty( propertyName, val );
+ }
+
+ return true; // success -- no special processing necessary
}
-void YComboBox::saveUserInput( YMacroRecorder *macroRecorder )
+
+YPropertyValue
+YComboBox::getProperty( const string & propertyName )
{
- macroRecorder->recordWidgetProperty( this, YUIProperty_Value );
+ propertySet().check( propertyName ); // throws exceptions if not found
+
+ if ( propertyName == YUIProperty_Value ) return YPropertyValue( YOtherProperty );
+ else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
+ else if ( propertyName == YUIProperty_ValidChars ) return YPropertyValue( validChars() );
+ else if ( propertyName == YUIProperty_InputMaxLength ) return YPropertyValue( inputMaxLength() );
+ else
+ {
+ return YWidget::getProperty( propertyName );
+ }
}
-void YComboBox::setInputMaxLength( const YCPInteger & numberOfChars )
+
+void YComboBox::saveUserInput( YMacroRecorder *macroRecorder )
{
+ macroRecorder->recordWidgetProperty( this, YUIProperty_Value );
}
+
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.h?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.h Fri Jun 29 20:31:20 2007
@@ -20,27 +20,27 @@
#define YComboBox_h
#include "YSelectionWidget.h"
-#include
-#include
class YMacroRecorder;
-/**
- * @short Implementation of the ComboBox widget
- **/
+class YComboBoxPrivate;
+
class YComboBox : public YSelectionWidget
{
-public:
+protected:
/**
- * Constructor
+ * Constructor.
+ *
+ * 'editable' means the user can freely enter any value without being
+ * restricted to the items of the ComboBox's list.
**/
- YComboBox( const YWidgetOpt & opt, YCPString label );
+ YComboBox( YWidget * parent, const string * label, bool editable );
+public:
/**
- * Returns whether or not any value ( not only from the list ) can be
- * entered.
+ * Destructor.
**/
- bool editable() const { return _editable; }
+ virtual ~YComboBox();
/**
* Returns a descriptive name of this widget class for logging,
@@ -49,67 +49,130 @@
virtual const char * widgetClass() { return "YComboBox"; }
/**
- * Implements the ui command changeWidget.
+ * Return 'true' if this ComboBox is editable, i.e. if the user can freely
+ * enter any value without being restricted to the items of the ComboBox's
+ * list.
+ *
+ * Notice that this can only be set in the constructor.
+ **/
+ bool editable() const;
+
+ /**
+ * Return the value of this combo box:
+ *
+ * The text of a list item if the user (or the appplication) selected a
+ * list item or the content of the combo box's input field if the combo box
+ * is editable and the user (or the application) entered text there.
+ *
+ * Notice that YSelectionBox::selectedItem() might not be very reliable for
+ * combo boxes. Better use this function instead.
**/
- YCPValue changeWidget( const YCPSymbol & property, const YCPValue & newvalue );
+ string value();
/**
- * Implements the ui command queryWidget
+ * Set the value of this combo box by string.
+ * For editable combo boxes, set the content of the combo box's input
+ * field.
**/
- YCPValue queryWidget( const YCPSymbol & property );
+ void setValue( const string & newText );
/**
- * Change the valid input characters.
+ * Return the (first) selected item or 0 if none is selected.
*
- * Overload this, but call YComboBox::setValidChars at the end of your own
- * method.
+ * Reimplemented from YSelectionWidget for better reliability: This will
+ * compare an editable combo box's user input against the text labels of
+ * all items and try to return an item if there is any match.
**/
- virtual void setValidChars( const YCPString & validChars );
-
+ virtual const YItem * selectedItem();
+
/**
- * Get the valid input characters.
+ * Return all selected items.
+ *
+ * This function does not transfer ownership of those items to the caller,
+ * so don't try to delete them!
+ *
+ * Reimplemented from YSelectionWidget for better reliability.
**/
- YCPString getValidChars();
+ virtual YCosntItemCollection selectedItems();
/**
- * Specify the amount of characters which can be inserted.
+ * Select or deselect an item.
*
- * Overload this to limit the input.
+ * Reimplemented from YSelectionWidget.
**/
- virtual void setInputMaxLength( const YCPInteger & numberOfChars );
+ virtual void selectItem( YItem * item, bool selected = true );
/**
- * The name of the widget property that will return user input.
- * Inherited from YWidget.
+ * Get the valid input characters. No input validation is performed (i.e.,
+ * the user can enter anything) if this is empty.
+ *
+ * This is only meaningful for if the ComboBox is editable.
**/
- const char *userInputProperty() { return YUIProperty_Value; }
+ string validChars();
+ /**
+ * Set the valid input characters. No input validation is performed (i.e.,
+ * the user can enter anything) if this is empty.
+ *
+ * This is only meaningful for if the ComboBox is editable.
+ *
+ * Derived classes are free to reimplement this, but they should call this
+ * base class method at the end of the overloaded function.
+ **/
+ virtual void setValidChars( const string & validChars );
-protected:
/**
- * Returns the ComboBox value.
+ * The maximum input length, i.e., the maximum number of characters the
+ * user can enter. -1 means no limit.
+ *
+ * This is only meaningful for if the ComboBox is editable.
+ **/
+ int inputMaxLength() const;
+
+ /**
+ * Set the maximum input length, i.e., the maximum number of characters the
+ * user can enter. -1 means no limit.
+ *
+ * This is only meaningful for if the ComboBox is editable.
+ *
+ * Derived classes are free to reimplement this, but they should call this
+ * base class method at the end of the overloaded function.
**/
- virtual YCPString getValue() const = 0;
+ virtual void setInputMaxLength( int numberOfChars );
/**
- * Sets the ComboBox value to a random value that is not already in
- * the item list. Will be called for editable ComboBox widgets only.
+ * The name of the widget property that will return user input.
+ * Inherited from YWidget.
**/
- virtual void setValue( const YCPString & new_value ) = 0;
+ const char *userInputProperty() { return YUIProperty_Value; }
+
+
+protected:
/**
- * Returns the index of the currently selected item (from 0 on)
- * or -1 if no item is selected.
+ * Return this combo box's current value as text.
+ *
+ * Called internally from value(), selectedItem() and related.
+ *
+ * Derived classes are required to implement this function.
**/
- virtual int getCurrentItem() const = 0;
+ virtual string text() = 0;
/**
- * Selects an item from the list. Notice there intentionally is no
- * corresponding getCurrentItem() method - use getValue() instead.
+ *
+ * Set this combo box's current value as text.
+ *
+ * Called internally whenever the content is to change
+ * programmatically. Don't call setValue() or selectItem() from here.
+ *
+ *
+ * Derived classes are required to implement this function.
**/
- virtual void setCurrentItem( int index ) = 0;
+ virtual void setText( const string & newText ) = 0;
+
private:
+
/**
* Save the widget's user input to a macro recorder.
* Intentionally declared as "private" so all macro recording internals are
@@ -117,15 +180,8 @@
**/
virtual void saveUserInput( YMacroRecorder *macroRecorder );
- /**
- * Valid input characters
- **/
- YCPString validChars;
- /**
- * Any input ( not only from the list ) permitted?
- **/
- bool _editable;
+ ImplPtr<YComboBoxPrivate> priv;
};
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YInputField.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YInputField.cc?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YInputField.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YInputField.cc Fri Jun 29 20:31:20 2007
@@ -46,7 +46,6 @@
: label( label )
, passwordMode( passwordMode )
, shrinkable( false )
- , validChars( "" )
, inputMaxLength( -1 )
{}
};
@@ -82,33 +81,33 @@
}
-string YInputField::validChars()
+bool YInputField::passwordMode() const
{
- return priv->validChars;
+ return priv->passwordMode;
}
-void YInputField::setValidChars( const string & newValidChars )
+bool YInputField::shrinkable() const
{
- priv->validChars= newValidChars;
+ return priv->shrinkable;
}
-bool YInputField::passwordMode() const
+void YInputField::setShrinkable( bool shrinkable )
{
- return priv->passwordMode;
+ priv->shrinkable = shrinkable;
}
-bool YInputField::shrinkable() const
+string YInputField::validChars()
{
- return priv->shrinkable;
+ return priv->validChars;
}
-void YInputField::setShrinkable( bool shrinkable )
+void YInputField::setValidChars( const string & newValidChars )
{
- priv->shrinkable = shrinkable;
+ priv->validChars= newValidChars;
}
@@ -182,14 +181,13 @@
}
-// FIXME
-// FIXME
-#include "YCPValueWidgetID.h"
-// FIXME
-// FIXME
-
void YInputField::saveUserInput( YMacroRecorder *macroRecorder )
{
+#if 0
+ // FIXME
+ // FIXME
+ // FIXME
+
if ( passwordMode() )
{
if ( hasId() )
@@ -209,5 +207,10 @@
{
macroRecorder->recordWidgetProperty( this, YUIProperty_Value );
}
+
+ // FIXME
+ // FIXME
+ // FIXME
+#endif
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YInputField.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YInputField.h?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YInputField.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YInputField.h Fri Jun 29 20:31:20 2007
@@ -82,8 +82,8 @@
virtual void setLabel( const string & label );
/**
- * Returns 'true' if this input field is in password mode, i.e. if there should
- * be no on-screen echo or only a '*' for each character typed.
+ * Returns 'true' if this input field is in password mode, i.e. if there
+ * should be no on-screen echo or only a '*' for each character typed.
*
* Notice that this can only be set in the constructor.
**/
@@ -105,7 +105,7 @@
virtual void setValidChars( const string & validChars );
/**
- * Gthe maximum input length, i.e., the maximum number of characters the
+ * The maximum input length, i.e., the maximum number of characters the
* user can enter. -1 means no limit.
**/
int inputMaxLength() const;
@@ -161,7 +161,7 @@
* Reimplemented from YWidget.
**/
virtual const YPropertySet & propertySet();
-
+
/**
* Get the string of this widget that holds the keyboard shortcut.
*
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YItem.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YItem.h?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YItem.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YItem.h Fri Jun 29 20:31:20 2007
@@ -23,7 +23,7 @@
#include <list>
using std::string;
-using std::list;
+using std::vector;
/**
* Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc. items.
@@ -38,6 +38,7 @@
YItem( const string & label, bool sel = false )
: _label( label )
, _selected( sel )
+ , _index( -1 )
{}
/**
@@ -47,6 +48,7 @@
: _label( label )
, _iconName( iconName )
, _selected( sel )
+ , _index( -1 )
{}
/**
@@ -68,11 +70,16 @@
void setLabel( const string & newLabel ) { _label = newLabel; }
/**
- * Return this icon's icon name.
+ * Return this item's icon name.
**/
string iconName() const { return _iconName; }
/**
+ * Return 'true' if this item has an icon name.
+ **/
+ bool hasIconName() const { return ! _iconName.empty(); }
+
+ /**
* Set this icon's icon name.
**/
void setIconName( const string & newIconName ) { _iconName = newIconName; }
@@ -89,17 +96,32 @@
**/
void setSelected( bool sel = true ) { _selected = sel; }
+ /**
+ * Set this item's index.
+ **/
+ void setIndex( int index ) { _index = index; }
+
+ /**
+ * Return the index of this item (as set with setIndex() ).
+ **/
+ int index() const { return _index; }
+
private:
string _label;
string _iconName;
bool _selected;
+ int _index;
};
-typedef list YItemList;
-typedef YItemList::iterator YItemListIterator;
-typedef YItemList::const_iterator YItemListConstIterator;
+typedef vector YItemCollection;
+typedef YItemCollection::iterator YItemIterator;
+typedef YItemCollection::const_iterator YItemConstIterator;
+
+typedef vector YConstItemCollection;
+typedef YConstItemCollection::iterator YConstItemIterator;
+typedef YConstItemCollection::const_iterator YConstItemConstIterator;
#endif // YItem_h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.cc?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.cc Fri Jun 29 20:31:20 2007
@@ -17,92 +17,131 @@
/-*/
-#include
-#include
-#include
#define y2log_component "ui"
#include
+#include "YSelectionBox.h"
#include "YUISymbols.h"
+#include "YUIException.h"
#include "YMacroRecorder.h"
-#include "YSelectionBox.h"
-YSelectionBox::YSelectionBox( const YWidgetOpt & opt, YCPString label )
- : YSelectionWidget( opt,label )
+struct YSelectionBoxPrivate
{
- // y2debug( "YSelectionBox( %s )", label->value_cstr() );
+ YSelectionBoxPrivate()
+ : shrinkable( false )
+ , immediate( false )
+ {}
+
+ bool shrinkable;
+ bool immediate;
+};
+
+
+
- // Derived classes need to check opt.shrinkable!
+YSelectionBox::YSelectionBox( YWidget * parent, const string & label )
+ : YSelectionWidget( parent,label,
+ true ) // enforceSingleSelection
+ , priv( new YSelectionBoxPrivate() )
+{
+ YUI_CHECK_NEW( priv );
setDefaultStretchable( YD_HORIZ, true );
setDefaultStretchable( YD_VERT, true );
}
-YCPValue YSelectionBox::changeWidget( const YCPSymbol & property, const YCPValue & newValue )
+
+YSelectionBox::~YSelectionBox
{
- string s = property->symbol();
+ // NOP
+}
- /**
- * @property string Label
- * The label above the list describing what it is all about
- */
- if ( s == YUIProperty_Label )
- {
- return changeLabel ( newValue );
- }
-
- /**
- * @property string CurrentItem
- * The currently selected item or its ID, if it has one.
- * Alias: Value
- */
- else if ( s == YUIProperty_CurrentItem ||
- s == YUIProperty_Value ) // Select item with that id
- {
- int index = itemWithId( newValue, true ); // true: log error
- if ( index < 0 ) return YCPBoolean( false );
- else
- {
- setCurrentItem( index );
- return YCPBoolean( true );
- }
- }
-
- /**
- * @property id_list Items
- * The items that are displayed
- */
- else if ( s == YUIProperty_Items )
+
+bool YSelectionBox::shrinkable() const
+{
+ return priv->shrinkable();
+}
+
+
+void YSelectionBox::setShrinkable( bool shrinkable )
+{
+ priv->shrinkable = shrinkable;
+}
+
+
+bool YSelectionBox::immediateMode() const
+{
+ return priv->immediateMode;
+}
+
+
+void YSelectionBox::setImmediateMode( bool immediateMode )
+{
+ priv->immediateMode = immediateMode;
+
+ if ( immediateMode )
+ setNotify( true );
+}
+
+
+const YPropertySet &
+YSelectionBox::propertySet()
+{
+ static YPropertySet propSet;
+
+ if ( propSet.isEmpty() )
{
- return changeItems( newValue );
+ /*
+ * @property itemID CurrentItem The currently selected item
+ * @property itemID Value The currently selected item
+ * @property itemList Items All items
+ * @property string Label caption above the input field
+ */
+ propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) );
+ propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) );
+ propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) );
+ propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
+ propSet.add( YWidget::propertySet() );
}
- else return YWidget::changeWidget( property, newValue );
-}
+ return propSet;
+}
-YCPValue YSelectionBox::queryWidget( const YCPSymbol & property )
+bool
+YSelectionBox::setProperty( const string & propertyName, const YPropertyValue & val )
{
- string s = property->symbol();
- if ( s == YUIProperty_Label ) return getLabel();
- else if ( s == YUIProperty_CurrentItem ||
- s == YUIProperty_Value )
+ propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
+
+ if ( propertyName == YUIProperty_Value ) return false; // Needs special handling
+ else if ( propertyName == YUIProperty_CurrentItem ) return false; // Needs special handling
+ else if ( propertyName == YUIProperty_Items ) return false; // Needs special handling
+ else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
+ else
{
- int index = getCurrentItem();
- // y2debug( "current item: %d", index );
- if ( index >= 0 )
- {
- if ( item_ids->value( index ).isNull() ) return item_labels->value( index );
- else return item_ids->value( index );
- }
- else return YCPVoid();
+ YWidget::setProperty( propertyName, val );
}
- else return YWidget::queryWidget( property );
+
+ return true; // success -- no special processing necessary
}
+YPropertyValue
+YSelectionBox::getProperty( const string & propertyName )
+{
+ propertySet().check( propertyName ); // throws exceptions if not found
+
+ if ( propertyName == YUIProperty_Value ) return YPropertyValue( YOtherProperty );
+ else if ( propertyName == YUIProperty_CurrentItem ) return YPropertyValue( YOtherProperty );
+ else if ( propertyName == YUIProperty_Items ) return YPropertyValue( YOtherProperty );
+ else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
+ else
+ {
+ return YWidget::getProperty( propertyName );
+ }
+}
void YSelectionBox::saveUserInput( YMacroRecorder *macroRecorder )
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.h?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.h Fri Jun 29 20:31:20 2007
@@ -20,25 +20,23 @@
#define YSelectionBox_h
#include "YSelectionWidget.h"
-#include "YCPItem.h"
-#include
-#include
class YMacroRecorder;
+class YSelectionBoxPrivate;
-/**
- * @short Implementation of the SelectionBox widget.
- **/
class YSelectionBox : public YSelectionWidget
{
public:
/**
- * Constructor
- * @param text the initial text of the SelectionBox label
- * @param opt the widget options
+ * Constructor.
**/
- YSelectionBox( const YWidgetOpt & opt, YCPString label );
+ YSelectionBox( YWidget * parent, const string & label );
+
+ /**
+ * Destructor.
+ **/
+ virtual ~YSelectionBox();
/**
* Returns a descriptive name of this widget class for logging,
@@ -47,34 +45,79 @@
virtual const char * widgetClass() { return "YSelectionBox"; }
/**
- * Implements the ui command changeWidget.
+ * Return 'true' if this SelectionBox should be very small.
**/
- YCPValue changeWidget( const YCPSymbol & property, const YCPValue & newvalue );
+ bool shrinkable() const;
/**
- * Implements the ui command queryWidget
+ * Make this SelectionBox very small. This will take effect only upon the
+ * next geometry management run.
+ *
+ * Derived classes can overwrite this, but should call this base class
+ * function in the new function.
**/
- YCPValue queryWidget( const YCPSymbol & property );
-
+ virtual void setShrinkable( bool shrinkable = true );
+
/**
- * The name of the widget property that will return user input.
- * Inherited from YWidget.
+ * Deliver even more events than with notify() set.
+ *
+ * For YSelectionBox, this is relevant mostly for the NCurses UI:
+ *
+ * In graphical UIs like the Qt UI, the user can use the mouse to select an
+ * item in a selection box. With notify() set, this will send an event
+ * right away (i.e., it will make UserInput and related return, while
+ * normally it would only return when the user clicks a PushButton).
+ *
+ * In the NCurses UI, there is no mouse, so the user has to use the cursor
+ * keys to move to the item he wants to select. In immediateMode(), every
+ * cursor key press will make the selection box send an event. Without
+ * immediateMode(), the NCSelectionBox will wait until the user hits the
+ * [Return] key until an event is sent. Depending on what the application
+ * does upon each selection box event, immediateMode() might make the
+ * application more sluggish.
**/
- const char *userInputProperty() { return YUIProperty_CurrentItem; }
-
+ bool immediateMode() const;
-protected:
/**
- * Returns the index of the currently
- * selected item or -1 if no item is selected.
+ * Set immediateMode() on or off.
+ **/
+ void setImmediateMode( bool on = true );
+
+ /**
+ * Set a property.
+ * Reimplemented from YWidget.
+ *
+ * This function may throw YUIPropertyExceptions.
+ *
+ * This function returns 'true' if the value was successfully set and
+ * 'false' if that value requires special handling (not in error cases:
+ * those are covered by exceptions).
**/
- virtual int getCurrentItem() = 0;
+ virtual bool setProperty( const string & propertyName,
+ const YPropertyValue & val );
- /**
- * Selects an item from the list.
+ /**
+ * Get a property.
+ * Reimplemented from YWidget.
+ *
+ * This method may throw YUIPropertyExceptions.
**/
- virtual void setCurrentItem( int index ) = 0;
+ virtual YPropertyValue getProperty( const string & propertyName );
+ /**
+ * Return this class's property set.
+ * This also initializes the property upon the first call.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual const YPropertySet & propertySet();
+
+ /**
+ * The name of the widget property that will return user input.
+ * Inherited from YWidget.
+ **/
+ const char *userInputProperty() { return YUIProperty_CurrentItem; }
+
private:
/**
@@ -83,6 +126,8 @@
* handled by the abstract libyui level, not by a specific UI.
**/
virtual void saveUserInput( YMacroRecorder *macroRecorder );
+
+ ImplPtr<YSelectionBoxPrivate> priv;
};
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.cc?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.cc Fri Jun 29 20:31:20 2007
@@ -12,254 +12,335 @@
File: YSelectionWidget.cc
- Author: Holger Macht
+ Author: Stefan Hundhammer
/-*/
-#include
-#include
-#include
#define y2log_component "ui"
#include
-#include "YUISymbols.h"
-#include "YMacroRecorder.h"
-#include "YSelectionBox.h"
-#include "YUI.h"
+#include <algorithm>
+#include "YSelectionWidget.h"
+#include "YUIException.h"
-YSelectionWidget::YSelectionWidget( const YWidgetOpt & opt, YCPString label )
- : YWidget( opt )
- , label( label )
- , _hasIcons( false )
+struct YSelectionWidgetPrivate
{
- // y2debug( "YSelectionWidget( %s )", label->value_cstr() );
+ YSelectionWidgetPrivate( const string & label,
+ bool enforceSingleSelection )
+ : label( label )
+ , enforceSingleSelection( enforceSingleSelection )
+ , hasIcons( false )
+ {}
+
+ string label;
+ bool enforceSingleSelection;
+ bool hasIcons;
+ string iconBasePath;
+ YItemCollection itemCollection;
+};
+
+
+
+
+YSelectionWidget::YSelectionWidget( YWidget * parent,
+ const string & label,
+ bool enforceSingleSelection )
+ : YWidget( parent )
+ , priv( new YSelectionWidgetPrivate( label, enforceSingleSelection ) )
+{
+ YUI_CHECK_NEW( priv );
+}
+
+
+YSelectionWidget::~YSelectionWidget()
+{
+ deleteAllItems();
+}
+
+
+YSelectionWidget::deleteAllItems()
+{
+ YItemIterator it = priv->itemCollection.begin();
+
+ while ( it != priv->itemCollection.end() )
+ {
+ YItem * item = *it;
+ ++it;
+ delete item;
+ }
+
+ priv->itemCollection.clear();
+ priv->hasIcons = false;
+}
+
+
+string YSelectionWidget::label() const
+{
+ return priv->label;
+}
+
+
+void YSelectionWidget::setLabel( const string & newLabel )
+{
+ priv->label = newLabel;
+}
+
+
+bool YSelectionWidget::enforceSingleSelection() const
+{
+ return priv->enforceSingleSelection;
}
-void YSelectionWidget::setLabel( const YCPString & label )
+void YSelectionWidget::setEnforceSingleSelection( bool enforceSingleSelection )
{
- this->label = label;
+ priv->enforceSingleSelection = enforceSingleSelection;
}
-YCPString YSelectionWidget::getLabel()
+
+void YSelectionWidget::setIconBasePath( const string & basePath )
{
- return label;
+ priv->iconBasePath = basePath;
}
-int YSelectionWidget::numItems() const
+string YSelectionWidget::iconBasePath() const
{
- return item_ids->size();
+ return priv->iconBasePath;
}
-int YSelectionWidget::itemWithId( const YCPValue & id, bool report_error )
+string YSelectionWidget::iconFullPath( YItem * item ) const
{
- for ( int i=0; i < numItems(); i++ )
+ string fullPath;
+
+ if ( item && ! icon->iconName().empty() )
{
- if ( ! item_ids->value(i).isNull() && item_ids->value(i)->equal( id ) ) return i;
- else if ( item_labels->value(i)->equal( id ) ) return i;
+ // FIXME
+ // FIXME
+ // FIXME
+#if 0
+ if ( priv->iconBasePath.empty() ||
+ priv->iconBasePath[0] != '/' )
+ {
+ fullPath = YUI::qApp()->iconBasePath();
+ }
+#endif
+ // FIXME
+ // FIXME
+ // FIXME
+
+ fullPath += priv->iconBasePath + "/" + icon->iconName();
}
- if ( report_error )
- y2error( "SelectionWidget: No item %s existing", id->toString().c_str() );
- return -1;
+ return fullPath;
}
-void YSelectionWidget::parseItemList( const YCPList & item_list )
+void YSelectionWidget::addItem( YItem * item )
{
- _hasIcons = false;
+ YUI_CHECK_NULL( item );
+
+ // Add the new item to the item list
+
+ priv->itemCollection.push_back( item );
+ item->setIndex( itemCollection.size() - 1 );
- for ( int i=0; i < item_list->size(); i++ )
+ if ( item->hasIconName() )
+ priv->hasIcons = true;
+
+ //
+ // Enforce single selection (if applicable)
+ //
+
+ if ( priv->enforceSingleSelection && selected )
{
- YCPValue item = item_list->value(i);
+ YItem * oldSelectedItem = selectedItem();
+
+ // This looks expensive, but it is not: Even though selectedItem()
+ // searches the complete item list until it finds a selected item, this
+ // happens only if a new item is to be inserted that has the "selected"
+ // flag on. In the normal case, this will only be one item.
+ //
+ // Only if the calling application does this systematically wrong and
+ // sets the "selected" flag for ALL items it inserts this will be more
+ // expensive. But then, this is a bug in that application that needs to
+ // be fixed.
- if ( item->isString() ) // item is just a label
- {
- addItem( YCPNull(), item->asString(), YCPNull(), false );
- }
- else if ( item->isTerm() // `item(...)
- && item->asTerm()->name() == YUISymbol_item )
+ if ( oldSelectedItem )
{
- YCPValue id = YCPNull();
- YCPString label = YCPNull();
- YCPString icon = YCPNull();
- YCPBoolean selected = YCPNull();
- YCPList subItemList = YCPNull();
-
- if ( parseItem( item->asTerm(), // in
- id, label, icon, selected, subItemList ) ) // out
- {
- if ( selected.isNull() )
- selected = YCPBoolean( false );
-
- if ( ! subItemList.isNull() )
- {
- y2error( "No sub item list permitted for %s - rejecting %s",
- widgetClass(), subItemList->toString().c_str() );
- }
-
- if ( ! icon.isNull() )
- _hasIcons = true;
-
- addItem( id, label, icon, selected->value() );
- }
- else
- {
- y2error( "%s: Invalid item arguments: %s",
- widgetClass(), item->toString().c_str() );
- }
- }
- else
- {
- y2error( "Invalid item %s: %s items must be strings or specified with `"
- YUISymbol_item "()", widgetClass(), item->toString().c_str() );
+ oldSelectedItem->setSelected( false );
+ y2warning( "Enforcing single selection: Deselecting %s",
+ oldSelectedItem->label().c_str() );
}
}
}
-bool YSelectionWidget::parseItem( const YCPTerm & itemTerm,
- YCPValue & item_id,
- YCPString & item_label,
- YCPString & item_icon,
- YCPBoolean & item_selected,
- YCPList & sub_item_list )
+void YSelectionWidget::addItem( const string & itemLabel,
+ const string & iconName,
+ bool selected )
+{
+ YItem * item = new YItem( itemLabel, iconName, selected );
+ YUI_CHECK_NEW( item );
+ additem( item );
+}
+
+
+void YSelectionWidget::addItem( const string & itemLabel, bool selected )
{
- bool ok = true;
+ addItem( itemLabel, "", selected );
+}
+
- if ( itemTerm->size() < 1 || itemTerm->size() > 4 )
+void YSelectionWidget::addItems( const YItemCollection & itemCollection )
+{
+ OptimizeChanges below( *this ); // Delay screen updates until this block is left
+ priv->itemCollection.reserve( priv->itemCollection.size() + itemCollection.size() );
+
+ for ( YItemConstIterator it = itemCollection.begin();
+ it != itemCollection.end();
+ ++it )
{
- y2error( "Invalid argument number in %s", itemTerm->toString().c_str() );
+ addItem( *it );
}
+}
- item_id = YCPNull();
- item_label = YCPNull();
- item_icon = YCPNull();
- item_selected = YCPNull();
- sub_item_list = YCPNull();
- for ( int n=0; n < itemTerm->size() && ok; n++ )
- {
- YCPValue arg = itemTerm->value( n );
+YItemConstIterator
+YSelectionWidget::itemsBegin() const
+{
+ return priv->itemCollection.begin();
+}
- if ( arg->isTerm() ) // `id(), `icon()
- {
- ok = arg->asTerm()->size() == 1;
- if ( ok )
- {
- if ( arg->asTerm()->name() == YUISymbol_id ) // `id()
- {
- item_id = arg->asTerm()->value(0);
- }
- else if ( arg->asTerm()->name() == YUISymbol_icon ) // `icon()
- {
- ok = arg->asTerm()->value(0)->isString();
-
- if ( ok )
- item_icon = arg->asTerm()->value(0)->asString();
- }
- else
- {
- ok = false;
- }
- }
- }
- else if ( arg->isString() ) // label
- {
- ok = item_label.isNull();
+YItemConstIterator
+YSelectionWidget::itemsEnd() const
+{
+ return priv->itemCollection.end();
+}
- if ( ok )
- item_label = arg->asString();
- }
- else if ( arg->isBoolean() ) // "selected" flag
- {
- ok = item_selected.isNull();
- if ( ok )
- item_selected = arg->asBoolean();
- }
- else if ( arg->isList() ) // sub item list (for tree only)
- {
- sub_item_list = arg->asList();
- }
- else
- {
- ok = false;
- }
- }
+bool YSelectionWidget::hasItems() const
+{
+ return ! priv->itemCollection.empty();
+}
- if ( ok )
- ok = ! item_label.isNull(); // the label is mandatory
- return ok;
+int YSelectionWidget::itemsCount() const
+{
+ return priv->itemCollection.size();
}
-void YSelectionWidget::addItem( const YCPValue & id,
- const YCPString & text,
- const YCPString & icon,
- bool selected )
+YItem *
+YSelectionWidget::itemAt( int index ) const
{
- item_ids->add( id );
- item_labels->add( text );
- item_icons->add( icon );
+ if ( index < 0 || index >= priv->itemCollection.size() )
+ return 0;
- itemAdded( text, numItems()-1, selected );
+ return priv->itemCollection( index );
}
-void YSelectionWidget::deleteAllItems()
+bool YSelectionWidget::hasIcons() const
{
- item_labels = YCPList();
- item_ids = YCPList();
+ return priv->hasIcons;
}
-YCPString YSelectionWidget::itemIcon( int item_no ) const
+const YItem *
+YSelectionWidget::selectedItem()
{
- if ( item_no < 0 || item_no >= item_icons.size() )
- return YCPString( "" );
+ for ( YItemConstIterator it = itemsBegin();
+ it != itemsEnd();
+ ++it )
+ {
+ if ( (*it)->selected() )
+ return *it;
+ }
- YCPString icon = item_icons->value( item_no )->asString();
+ return 0;
+}
- if ( icon.isNull() || icon->isVoid() )
- return YCPString( "" );
- return icon;
+YItemConstList
+YSelectionWidget::selectedItems()
+{
+ YItemConstList selectedItems;
+
+ for ( YItemConstIterator it = itemsBegin();
+ it != itemsEnd();
+ ++it )
+ {
+ if ( (*it)->selected() )
+ selectedItems.push_back( *it );
+ }
+
+ return selectedItems;
}
+bool YSelectionWidget::hasSelectedItems()
+{
+ return selectedItem() != 0;
+}
+
-YCPValue YSelectionWidget::changeLabel( const YCPValue & newValue )
+void YSelectionWidget::selectItem( YItem * item, bool selected )
{
- if ( newValue->isString() )
+ YUI_CHECK_NULL( item );
+
+ if ( ! itemsContain( item ) )
+ YUI_THROW( YUIException( "Item does not belong to this widget" ) );
+
+ if ( priv->enforceSingleSelection && selected )
{
- setLabel( newValue->asString() );
+ YItem * oldSelectedItem = selectedItem();
- return YCPBoolean( true );
+ if ( oldSelectedItem )
+ {
+ // Don't complain in the log etc. -- this is a perfectly legal case!
+ oldSelectedItem->setSelected( false );
+ }
}
- else
- {
- y2error( "%s: Invalid parameter %s for Label property. Must be string",
- widgetClass(), newValue->toString().c_str() );
- return YCPBoolean( false );
+ item->setSelected( selected );
+}
+
+
+bool YSelectionWidget::itemsContain( YItem * item ) const
+{
+ return ( find( priv->itemCollection.begin(), priv->itemCollection.end(), item )
+ != priv->itemCollection.end() );
+}
+
+
+void YSelectionWidget::deselectAllItems()
+{
+ for ( YItemIterator it = priv->itemCollection.begin();
+ it != priv->itemCollection.end();
+ ++it )
+ {
+ (*it)->setSelected( false );
}
}
-YCPValue YSelectionWidget::changeItems ( const YCPValue & newValue )
+
+YItem *
+YSelectionWidget::findItem( const string & wantedItemLabel )
{
- if ( newValue->isList() )
+ for ( YItemIterator it = priv->itemCollection.begin();
+ it != priv->itemCollection.end();
+ ++it )
{
- deleteAllItems();
- parseItemList( newValue->asList() );
+ if ( (*it)->label() == wantedItemLabel )
+ return *it;
}
- return YCPBoolean( true );
+ return 0;
}
+
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.h?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.h Fri Jun 29 20:31:20 2007
@@ -20,24 +20,39 @@
#define YSelectionWidget_h
#include "YWidget.h"
-#include
-#include
+#include "YItem.h"
+#include "ImplPtr.h"
+using std::string;
+class YSelectionWidgetPrivate;
/**
- * @Base class for all selection widgets like SelectionBox, Combobox and
- * MultiselectionBox
+ * Base class for selection widgets:
+ * - YSelectionBox
+ * - MultiselectionBox
+ * - YCombobox
**/
class YSelectionWidget : public YWidget
{
-public:
+protected:
/**
- * Constructor
- * @param text the initial text of the SelectionWidget label
- * @param opt the widget options
+ * Constructor.
+ *
+ * 'singleSelectionMode' indicates if this base class should enforce single
+ * selection when items are added or when items are selected from the
+ * application. Note that single selection can also mean that no item is
+ * selected.
+ **/
+ YSelectionWidget( YWidget * parent,
+ const string & label,
+ bool enforceSingleSelection );
+
+public:
+ /**
+ * Destructor.
**/
- YSelectionWidget( const YWidgetOpt & opt, YCPString label );
+ virtual ~YSelectionWidget();
/**
* Returns a descriptive name of this widget class for logging,
@@ -46,156 +61,216 @@
virtual const char * widgetClass() { return "YSelectionWidget"; }
/**
- * Get the string of this widget that holds the keyboard shortcut.
+ * Return this widget's label (the caption above the item list).
+ **/
+ string label() const;
+
+ /**
+ * Change this widget's label (the caption above the item list).
*
- * Reimplemented from YWidget.
+ * Derived classes should overwrite this function, but they should call
+ * this base class function in the new implementation.
**/
- virtual string shortcutString() { return getLabel()->value(); }
+ virtual void setLabel( const string & newLabel );
/**
- * Set the string of this widget that holds the keyboard shortcut.
+ * Add one item. This widget assumes ownership of the item object and will
+ * delete it in its destructor.
*
- * Reimplemented from YWidget.
+ * Derived classes can overwrite this function, but they should call this
+ * base class function in the new implementation.
**/
- virtual void setShortcutString( const string & str )
- { setLabel( YCPString( str ) ); }
+ virtual void addItem( YItem * item );
/**
- * Parses a given itemlist and calls addItem(...) to insert entries.
+ * Overloaded for convenience: Add an item by string.
**/
- void parseItemList( const YCPList & itemlist );
+ void addItem( const string & itemLabel, bool selected = false );
+ /**
+ * Overloaded for convenience: Add an item with a text and an icon.
+ * Note that not all UIs can display icons.
+ **/
+ void addItem( const string & itemLabel,
+ const string & iconName,
+ bool selected = false );
/**
- * Parse one `item() term with
- * `id() [optional]
- * `icon() [optional]
- * string label [MANDATORY]
- * bool selected [optional]
- * list subItemList [optional]
+ * Add multiple items. For some UIs, this can be more efficient than
+ * calling addItem() multiple times.
*
- * Example:
- *
- * `item( `id(`my_id), `icon( "colorful.png" ), "My Label", true )
+ * Derived classes can overwrite this function, but they should call this
+ * base class function in the new implementation.
+ **/
+ virtual void addItems( const YItemCollection & itemCollection );
+
+ /**
+ * Delete all items.
*
- * The order of those parameters within `item() is arbitrary.
- * The _ret Parameters are are return parameters that will be changed by
- * this function.
+ * Derived classes can overwrite this function, but they should call this
+ * base class function in the new implementation.
+ **/
+ virtual void deleteAllItems();
+
+ /**
+ * Delete all items and add new items.
+ **/
+ void setItems( const YItemCollection & itemCollection )
+ { deleteAllItems(); addItems( itemCollection ) }
+
+ /**
+ * Return an iterator that points to the first item.
*
- * If the subItemList is not desired, rejecting it is the caller's
- * responsibility (check if ! .isNull() and issue error).
+ * For YSelectionWidgets that can have tree structures, this iterator will
+ * iterate over the toplevel items.
*
- * Returns 'true' on success, 'false' on error.
+ * Important: Don't use this iterator to iterate over all items and check
+ * their "selected" state; that information might not always be up to
+ * date. Use the dedicated functions for that.
**/
- static bool parseItem( const YCPTerm & itemTerm,
- YCPValue & item_id_ret,
- YCPString & item_label_ret,
- YCPString & item_icon_ret,
- YCPBoolean & item_selected_ret,
- YCPList & sub_item_list_ret );
-
+ YItemConstIterator itemsBegin() const;
-protected:
+ /**
+ * Return an iterator that points behind the last item.
+ **/
+ YItemConstIterator itemsEnd() const;
/**
- * Called when an item has been added. Overload this to
- * fill the ui specific widget with items.
- * @param string text of the new item
- * @param index index of the new item.
- * @param selected true if the item should be selected.
+ * Return 'true' if this widget has any items.
**/
- virtual void itemAdded( const YCPString & string, int index, bool selected ) = 0;
+ bool hasItems() const;
/**
- * Searches for an item with a certain id or a certain label.
- * Returns the index of the found item or -1 if none was found
- * @param report_error set this to true, if you want me to
- * report an error if non item can be found.
+ * Return the number of items.
+ *
+ * For YSelectionWidgets that can have tree structures, this returns the
+ * number of toplevel items.
**/
- int itemWithId( const YCPValue & id, bool report_error );
+ int itemsCount() const;
/**
- * The current label of the SelectionWidget
+ * Return 'true' if any of the items has an icon.
**/
- YCPString label;
+ bool hasIcons() const;
/**
- * The current list of item ids
+ * Return the (first) selected item or 0 if none is selected.
**/
- YCPList item_ids;
+ virtual const YItem * selectedItem();
/**
- * The current list of item labels
+ * Return all selected items. This is mostly useful for derived classes
+ * that allow selecting multiple items.
+ *
+ * This function does not transfer ownership of those items to the caller,
+ * so don't try to delete them!
**/
- YCPList item_labels;
+ virtual YConstItemCollection selectedItems();
/**
- * Returns the current number of items
+ * Return 'true' if any item is selected.
**/
- int numItems() const;
+ bool hasSelectedItems();
/**
- * Change the label text. Overload this, but call
- * YSelectionWidget::setLabel at the end of your own function.
+ * Select or deselect an item.
+ *
+ * Notice that this is different from YItem::setSelected() because unlike
+ * the latter function, this function informs the parent widget of the
+ * selection change.
+ *
+ * If only one item can be selected at any time (single selection), the
+ * derived class will make sure to deselect any previous selection, if
+ * applicable.
+ *
+ * Derived classes should overwrite this function, but they should call
+ * this base class function at the new function's start (this will also
+ * check if the item really belongs to this widget and throw an exception
+ * if not).
**/
- virtual void setLabel( const YCPString & label );
+ virtual void selectItem( YItem * item, bool selected = true );
/**
- * Get the current label text. This method cannot be overidden. The value
- * of the label cannot be changed other than by calling setLabel, i.e. not
- * by the ui. Therefore setLabel stores the current label in #label.
+ * Deselect all items.
+ *
+ * Derived classes can overwrite this function, but they should call this
+ * base class function in the new implementation.
**/
- YCPString getLabel();
+ virtual void deselectAllItems();
/**
- * Adds one item
+ * Set this widget's base path where to look up icons.
+ * If this is a relative path, YUI::qApp()->iconBasePath() is prepended.
**/
- virtual void addItem( const YCPValue & id,
- const YCPString & text,
- const YCPString & icon,
- bool selected );
+ void setIconBasePath( const string & basePath );
/**
- * Cleares the two lists item_ids and item_labels. This function is
- * calles out of the corresponding YQ classes.
+ * Return this widget's base path where to look up icons
+ * as set with setIconBasePath().
**/
- virtual void deleteAllItems();
+ string iconBasePath() const;
/**
- * Changes the widgets label. Is used in every changeWidget(...)
- * function in derived classes.
+ * Return the full path + file name for the icon of the specified item.
+ *
+ * If 'item' does not have an iconName specified, this will return an empty
+ * string.
**/
- virtual YCPValue changeLabel( const YCPValue & newValue );
+ string iconFullPath( YItem * item ) const;
/**
- * Changes the widgets displayed items. Is used in every
- * changeWidget(...) function in derived classes.
+ * Return 'true' if this widget's items contain the specified item.
**/
- virtual YCPValue changeItems ( const YCPValue & newValue );
+ bool itemsContain( YItem * item ) const;
+ /**
+ * Find the (first) item with the specified label.
+ * Return 0 if there is no item with that label.
+ **/
+ YItem * findItem( const string & itemLabel );
/**
- * Returns the full path name for the icon that corresponds with item
- * number item_no or YCPVoid() if there is none.
+ * Get the string of this widget that holds the keyboard shortcut.
+ *
+ * Reimplemented from YWidget.
**/
- YCPString itemIcon( int item_no ) const;
+ virtual string shortcutString() { return label(); }
/**
- * Returns 'true' if any item of this widget has an icon
+ * Set the string of this widget that holds the keyboard shortcut.
+ *
+ * Reimplemented from YWidget.
**/
- bool hasIcons() const { return _hasIcons; }
+ virtual void setShortcutString( const string & str )
+ { setLabel( str ); }
+protected:
-private:
+ /**
+ * Set single selection mode on or off. In single selection mode, only one
+ * item can be selected at any time.
+ *
+ * If set, this base class enforces this when items are added or when items
+ * are selected from the application. Note that single selection can also
+ * mean that no item is selected.
+ **/
+ void setEnforceSingleSelection( bool on );
/**
- * The curent list of item icons. We make destructive changes to
- * this variable, so make sure only one reference to it exists!
+ * Return 'true' if this base class should enforce single selection.
**/
- YCPList item_icons;
+ bool enforceSingleSelection() const;
+
+ /**
+ * Return the item at index 'index' (from 0)
+ * or 0 if there is no such item.
+ **/
+ YItem * itemAt( int index ) const;
- bool _hasIcons;
+
+private:
+ ImplPtr<YSelectionWidgetPrivate> priv;
};
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc Fri Jun 29 20:31:20 2007
@@ -52,6 +52,7 @@
#include "YWizard.h"
#include "YCPValueWidgetID.h"
#include "YCPDialogParser.h"
+#include "YCPItemParser.h"
#include "YOptionalWidgetFactory.h"
#include "YCheckBox.h"
@@ -892,7 +893,7 @@
if ( newValue->isString() ) val = YPropertyValue( newValue->asString()->value() );
else if ( newValue->isInteger() ) val = YPropertyValue( newValue->asInteger()->value() );
else if ( newValue->isBoolean() ) val = YPropertyValue( newValue->asBoolean()->value() );
- else if ( newValue->isVoid() ) changeWidgetComplexTypes( widget, propertyName, newValue );
+ else if ( newValue->isVoid() ) YCPPropertyHandler::setComplexProperty( widget, propertyName, newValue );
else
{
y2error( "Unknown type for property %s::%s: %s",
@@ -904,10 +905,10 @@
try
{
- bool success = widget->setProperty( propertyName, val );
+ bool success = widget->setProperty( propertyName, val );
if ( ! success )
- changeWidgetComplexTypes( widget, propertyName, newValue );
+ YCPPropertyHandler::setComplexProperty( widget, propertyName, newValue );
ret = YCPBoolean( true );
}
@@ -1018,7 +1019,7 @@
case YStringProperty: return YCPString ( val.stringVal() );
case YBoolProperty: return YCPBoolean( val.boolVal() );
case YIntegerProperty: return YCPInteger( val.integerVal() );
- case YOtherProperty: return queryWidgetComplexTypes( widget, propertyName );
+ case YOtherProperty: return YCPPropertyHandler::getComplexProperty( widget, propertyName );
case YWidgetPtrProperty:
{
YWidget * widget = val.widgetPtrVal();
@@ -1057,67 +1058,6 @@
/**
- * This is the messy part of UI::QueryWidget(): Here all special cases
- * (property type YOtherProperty) are handled. It's not pretty, but at some
- * place a mapping from C++ types to YCPValues has to be done.
- **/
-YCPValue
-YUI::queryWidgetComplexTypes( YWidget * widget, const string & propertyName )
-{
- if ( propertyName == YUIProperty_Value )
- {
- YCheckBox * checkBox = dynamic_cast (widget);
-
- if ( checkBox )
- {
- switch ( checkBox->value() )
- {
- case YCheckBox_on: return YCPBoolean( true );
- case YCheckBox_off: return YCPBoolean( false );
- case YCheckBox_dont_care: return YCPVoid(); // nil
- }
- }
- }
-
- y2warning( "Can't handle property %s::%s - returning 'nil'",
- widget->widgetClass(), propertyName.c_str() );
-
- return YCPVoid();
-}
-
-
-void
-YUI::changeWidgetComplexTypes( YWidget * widget, const string & propertyName, const YCPValue & val )
-{
- // y2debug( "%s::%s", widget->widgetClass(), propertyName.c_str() );
-
- if ( propertyName == YUIProperty_Value )
- {
- YCheckBox * checkBox = dynamic_cast (widget);
-
- if ( checkBox )
- {
- if ( val->isBoolean() )
- {
- checkBox->setChecked( val->asBoolean()->value() );
- return;
- }
- else if ( val->isVoid() )
- {
- checkBox->setDontCare();
- return;
- }
-
- YUI_THROW( YUIBadPropertyArgException( YProperty( propertyName, YOtherProperty ), widget ) );
- }
- }
-
- y2warning( "Can't handle property %s::%s - returning 'nil'",
- widget->widgetClass(), propertyName.c_str() );
-}
-
-
-/**
* @builtin ReplaceWidget
*
* @description
Modified: branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc Fri Jun 29 20:31:20 2007
@@ -34,24 +34,24 @@
-YQComboBox::YQComboBox( QWidget * parent,
- const YWidgetOpt & opt,
- const YCPString & label )
- : QVBox( parent )
- , YComboBox( opt, label )
+YQComboBox::YQComboBox( YWidget * parent,
+ const string & label,
+ bool editable )
+ : QVBox( (QWidget *) parent->widgetRep() )
+ , YComboBox( parent, label, editable )
, _validator(0)
{
setWidgetRep( this );
setSpacing( YQWidgetSpacing );
- setMargin( YQWidgetMargin );
+ setMargin ( YQWidgetMargin );
- _qt_label = new QLabel( fromUTF8(label->value() ), this );
+ _qt_label = new QLabel( fromUTF8( label ), this );
_qt_label->setTextFormat( QLabel::PlainText );
if ( _qt_label->text().isEmpty() )
_qt_label->hide();
- _qt_combo_box = new QComboBox( opt.isEditable.value(), this );
+ _qt_combo_box = new QComboBox( editable, this );
_qt_label->setBuddy( _qt_combo_box );
#if SEND_SELECTION_CHANGED_EVENT
@@ -61,16 +61,22 @@
connect( _qt_combo_box, SIGNAL( activated ( const QString & ) ),
this, SLOT ( textChanged( const QString & ) ) );
-
+
connect( _qt_combo_box, SIGNAL( textChanged( const QString & ) ),
this, SLOT ( textChanged( const QString & ) ) );
}
-void YQComboBox::setLabel( const YCPString & label )
+YQComboBox::~YQComboBox()
+{
+ // NOP
+}
+
+
+void YQComboBox::setLabel( const string & label )
{
_qt_label->setText( fromUTF8(label->value() ) );
-
+
if ( _qt_label->text().isEmpty() )
{
if ( _qt_label->isVisible() )
@@ -81,12 +87,12 @@
if ( _qt_label->isHidden() )
_qt_label->show();
}
-
+
YComboBox::setLabel( label );
}
-void YQComboBox::setValidChars( const YCPString & newValidChars )
+void YQComboBox::setValidChars( const string & newValidChars )
{
if ( ! _qt_combo_box->editable() )
{
@@ -94,26 +100,26 @@
debugLabel().c_str() );
return;
}
-
+
if ( _validator )
{
- _validator->setValidChars( fromUTF8( newValidChars->value() ) );
+ _validator->setValidChars( fromUTF8( newValidChars ) );
}
else
{
- _validator = new QY2CharValidator( fromUTF8( newValidChars->value() ), this );
+ _validator = new QY2CharValidator( fromUTF8( newValidChars ), this );
_qt_combo_box->setValidator( _validator );
// No need to delete the validator in the destructor - Qt will take
// care of that since it's a QObject with a parent!
}
-
+
if ( ! isValidText( _qt_combo_box->currentText() ) )
{
y2error( "Old value \"%s\" of %s \"%s\" invalid according to ValidChars \"%s\" - deleting",
(const char *) _qt_combo_box->currentText(),
widgetClass(), debugLabel().c_str(),
- newValidChars->value().c_str() );
+ newValidChars.c_str() );
_qt_combo_box->setCurrentText( "" );
}
@@ -147,24 +153,24 @@
}
-void YQComboBox::itemAdded( const YCPString & string, int index, bool selected )
+void YQComboBox::itemAdded( const string & label, int index, bool selected )
{
- _qt_combo_box->insertItem( fromUTF8(string->value() ) );
+ _qt_combo_box->insertItem( fromUTF8( label ) );
if ( selected )
- setValue( string );
+ setValue( label );
}
-int YQComboBox::getCurrentItem() const
+int YQComboBox::currentItem() const
{
return _qt_combo_box->currentItem();
}
-YCPString YQComboBox::getValue() const
+string YQComboBox::value() const
{
- return YCPString( toUTF8( _qt_combo_box->currentText() ) );
+ return toUTF8( _qt_combo_box->currentText() );
}
@@ -175,15 +181,15 @@
int pos = 0;
QString text( txt ); // need a non-const QString &
-
+
return _validator->validate( text, pos ) == QValidator::Acceptable;
}
-void YQComboBox::setValue( const YCPString & ytext )
+void YQComboBox::setValue( const string & ytext )
{
QString text = fromUTF8( ytext->value() );
-
+
if ( isValidText( text ) )
{
_qt_combo_box->blockSignals( true );
Modified: branches/tmp/sh/mod-ui/qt/src/YQComboBox.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQComboBox.h?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQComboBox.h (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQComboBox.h Fri Jun 29 20:31:20 2007
@@ -21,7 +21,6 @@
#define YQComboBox_h
#include
-#include
#include "YComboBox.h"
@@ -37,7 +36,15 @@
public:
- YQComboBox( QWidget * parent, const YWidgetOpt & opt, const YCPString & label );
+ /**
+ * Constructor.
+ **/
+ YQComboBox( YWidget * parent, const string & label, bool editable );
+
+ /**
+ * Destructor.
+ **/
+ ~YQComboBox();
/**
* Inherited from YWidget: Sets the enabled state of the
@@ -70,14 +77,14 @@
/**
* Change the label text.
**/
- void setLabel( const YCPString & label );
+ void setLabel( const string & label );
/**
* Change the valid input characters.
*
* Reimplemented from @ref YComboBox
**/
- void setValidChars( const YCPString & validChars );
+ void setValidChars( const string & validChars );
/**
* Returns 'true' if the given text is valid according to the current
@@ -90,27 +97,27 @@
*
* Reimplemented from YComboBox.
**/
- void itemAdded( const YCPString & itemText, int itemIndex, bool selected );
+ void itemAdded( const string & itemText, int itemIndex, bool selected );
/**
* Inherited from YComboBox:
* Returns the ComboBox value.
**/
- YCPString getValue() const;
+ string value() const;
/**
* Inherited from YComboBox:
* Sets the ComboBox value to a random value that is not already in
* the item list. Will be called for editable ComboBox widgets only.
**/
- void setValue( const YCPString & new_value );
+ void setValue( const string & newValue );
/**
* Inherited from YComboBox:
* Returns the index of the currently selected item (from 0 on)
* or -1 if no item is selected.
**/
- int getCurrentItem() const;
+ int currentItem() const;
/**
* Inherited from YComboBox:
@@ -127,7 +134,7 @@
/**
* Delete all items.
*
- * Reimplemented from YSelectionWidget
+ * Reimplemented from YSelectionWidget.
**/
virtual void deleteAllItems();
Modified: branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc Fri Jun 29 20:31:20 2007
@@ -31,6 +31,7 @@
#include "YQUI.h"
#include "YQSelectionBox.h"
#include "YQDialog.h"
+#include "YUIException.h"
#define DEFAULT_VISIBLE_LINES 5
@@ -39,39 +40,35 @@
#define ICON_DIR ICONDIR "/icons/22x22/apps/"
-YQSelectionBox::YQSelectionBox( QWidget * parent,
- const YWidgetOpt & opt,
- const YCPString & label )
- : QVBox( parent )
+YQSelectionBox::YQSelectionBox( YWidget * parent, const string & label )
+ : QVBox( (QWidget *) parent->widgetRep() )
, YSelectionBox( opt, label )
{
setWidgetRep( this );
setSpacing( YQWidgetSpacing );
- setMargin( YQWidgetMargin );
+ setMargin ( YQWidgetMargin );
- _qt_label = new QLabel( fromUTF8(label->value() ), this );
+ _qt_label = new QLabel( fromUTF8( label ), this );
_qt_label->setTextFormat( QLabel::PlainText );
if ( _qt_label->text().isEmpty() )
_qt_label->hide();
- _qt_listbox = new QListBox( this );
- _qt_listbox->installEventFilter( this );
- _qt_listbox->setVariableHeight( false );
- _qt_listbox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
- _qt_listbox->setTopItem(0);
- _qt_label->setBuddy( _qt_listbox );
-
- _shrinkable = opt.isShrinkable.value();
- _immediateMode = opt.immediateMode.value();
+ _qt_listBox = new QListBox( this );
+ _qt_listBox->installEventFilter( this );
+ _qt_listBox->setVariableHeight( false );
+ _qt_listBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,
+ QSizePolicy::Expanding ) );
+ _qt_listBox->setTopItem(0);
+ _qt_label->setBuddy( _qt_listBox );
if ( notify() )
{
- connect( _qt_listbox, SIGNAL( highlighted ( int ) ),
+ connect( _qt_listBox, SIGNAL( highlighted ( int ) ),
this, SLOT ( slotSelected( int ) ) );
- connect( _qt_listbox, SIGNAL( doubleClicked( QListBoxItem * ) ),
+ connect( _qt_listBox, SIGNAL( doubleClicked( QListBoxItem * ) ),
this, SLOT ( slotActivated( QListBoxItem * ) ) );
connect( &_timer, SIGNAL( timeout() ),
@@ -80,9 +77,11 @@
}
-void YQSelectionBox::setLabel( const YCPString & label )
+void YQSelectionBox::setLabel( const string & label )
{
- _qt_label->setText( fromUTF8(label->value() ) );
+ YSelectionBox::setLabel( label );
+
+ _qt_label->setText( fromUTF8( label ) );
if ( _qt_label->text().isEmpty() )
{
@@ -94,52 +93,17 @@
if ( _qt_label->isHidden() )
_qt_label->show();
}
-
- YSelectionBox::setLabel( label );
-}
-
-
-int YQSelectionBox::preferredWidth()
-{
- int hintWidth = _qt_label->sizeHint().width() + frameWidth();
-
- return max( 80, hintWidth );
}
-int YQSelectionBox::preferredHeight()
-{
- int hintHeight = _qt_label->sizeHint().height();
- int visibleLines = _shrinkable ? SHRINKABLE_VISIBLE_LINES : DEFAULT_VISIBLE_LINES;
- hintHeight += visibleLines * _qt_listbox->fontMetrics().lineSpacing();
- hintHeight += _qt_listbox->frameWidth() * 2;
-
- return max( 80, hintHeight );
-}
-
-
-void YQSelectionBox::setSize( int newWidth, int newHeight )
-{
- resize( newWidth, newHeight );
-}
-
-
-void YQSelectionBox::setEnabled( bool enabled )
-{
- _qt_label->setEnabled( enabled );
- _qt_listbox->setEnabled( enabled );
- _qt_listbox->triggerUpdate( true );
- YWidget::setEnabled( enabled );
-}
-
-
-void YQSelectionBox::itemAdded( const YCPString & string, int index, bool selected )
+void YQSelectionBox::addItem( YItem * item )
{
+ YSelectionWidget::addItem( item );
QPixmap icon;
-
- if ( hasIcons() )
+
+ if ( hasIcons() && ! item->iconName().empty() )
{
- QString iconName( itemIcon( index )->value().c_str() );
+ QString iconName( fromUTF8( item->iconName() ) );
iconName.stripWhiteSpace();
if ( ! iconName.isEmpty() )
@@ -152,40 +116,117 @@
if ( icon.isNull() )
y2error( "Can't load icon %s", (const char *) iconName );
}
-
+
}
if ( icon.isNull() )
{
- _qt_listbox->insertItem( fromUTF8(string->value() ) );
+ _qt_listBox->insertItem( fromUTF8( item->label() ) );
}
else
{
- _qt_listbox->insertItem( icon, fromUTF8(string->value() ) );
+ _qt_listBox->insertItem( icon, fromUTF8( item->label() ) );
}
-
+
if ( selected )
- setCurrentItem( index );
+ {
+ _qt_listBox->blockSignals( true );
+ _qt_listBox->setCurrentItem( item->index() );
+ _qt_listBox->blockSignals( false );
+ }
}
-int YQSelectionBox::getCurrentItem()
+void YQSelectionBox::selectItem( YItem * item, bool selected )
{
- return _qt_listbox->currentItem();
+ YSelectionWidget::selectItem( item, selected );
+
+ _qt_listBox->blockSignals( true );
+ _qt_listBox->setCurrentItem( selected ? item->index() : -1 );
+ _qt_listBox->blockSignals( false );
}
-void YQSelectionBox::setCurrentItem( int index )
+void YQSelectionBox::selectItem( int index )
{
- _qt_listbox->blockSignals( true );
- _qt_listbox->setCurrentItem( index );
- _qt_listbox->blockSignals( false );
+ YSelectionWidget::deselectAllItems();
+
+ YItem * item = YSelectionWidget::itemAt( index );
+
+ if ( item )
+ item->setSelected( true );
+ else
+ YUI_THROW( YUIException( "Can't find selected item" ) );
+}
+
+
+void YQSelectionBox::deselectAllItems()
+{
+ YSelectionWidget::deselectAllItems();
+ _qt_listBox->clearSelection();
+
+ if ( _qt_listBox->currentItem() > -1 )
+ {
+ // Some item is selected after all; the Qt documtation says this
+ // happens if the QListBox is in single selection mode (which it is)
+ // and has the keyboard focus.
+
+ // Synchronize internal "selected" flags with what the QListBox
+ // displays. This has a small performance penalty because it calls
+ // YSelectionWidget::deselectAllItems() again which again iterates over
+ // all items.
+ selectItem( _qt_listBox->currentItem() );
+ }
+}
+
+
+void YQSelectionBox::deleteAllItems()
+{
+ _qt_listBox->blockSignals( true );
+ _qt_listBox->clear();
+ YSelectionWidget::deleteAllItems();
+ _qt_listBox->blockSignals( false );
+}
+
+
+
+int YQSelectionBox::preferredWidth()
+{
+ int hintWidth = _qt_label->sizeHint().width() + frameWidth();
+
+ return max( 80, hintWidth );
+}
+
+
+int YQSelectionBox::preferredHeight()
+{
+ int hintHeight = _qt_label->sizeHint().height();
+ int visibleLines = shrinkable() ? SHRINKABLE_VISIBLE_LINES : DEFAULT_VISIBLE_LINES;
+ hintHeight += visibleLines * _qt_listBox->fontMetrics().lineSpacing();
+ hintHeight += _qt_listBox->frameWidth() * 2;
+
+ return max( 80, hintHeight );
+}
+
+
+void YQSelectionBox::setSize( int newWidth, int newHeight )
+{
+ resize( newWidth, newHeight );
+}
+
+
+void YQSelectionBox::setEnabled( bool enabled )
+{
+ _qt_label->setEnabled( enabled );
+ _qt_listBox->setEnabled( enabled );
+ _qt_listBox->triggerUpdate( true );
+ YWidget::setEnabled( enabled );
}
bool YQSelectionBox::setKeyboardFocus()
{
- _qt_listbox->setFocus();
+ _qt_listBox->setFocus();
return true;
}
@@ -226,13 +267,16 @@
void YQSelectionBox::slotSelected( int index )
{
- if ( _immediateMode )
+ selectItem( index );
+
+ if ( immediateMode() )
returnImmediately();
else
{
if ( ! YQUI::ui()->eventsBlocked() )
{
- // Delayed event delivery - only if events are to be delivered right now.
+ // Delayed event delivery - only if events are to be delivered
+ // right now.
//
// An event block that is in effect right now may or may not affect
// events after the timer delay is expired.
@@ -248,8 +292,10 @@
}
-void YQSelectionBox::slotActivated( QListBoxItem * )
+void YQSelectionBox::slotActivated( QListBoxItem * item )
{
+ selectItem( QListBox::index( item ) );
+
YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::Activated ) );
}
@@ -258,7 +304,8 @@
{
if ( ! YQUI::ui()->eventPendingFor( this ) )
{
- // Avoid overwriting a (more important) Activated event with a SelectionChanged event
+ // Avoid overwriting a (more important) Activated event with a
+ // SelectionChanged event
y2milestone( "sending selbox event" );
YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::SelectionChanged ) );
@@ -273,15 +320,6 @@
}
-void YQSelectionBox::deleteAllItems()
-{
- _qt_listbox->blockSignals( true );
- _qt_listbox->clear();
- YSelectionWidget::deleteAllItems();
- _qt_listbox->blockSignals( false );
-}
-
-
#include "YQSelectionBox.moc"
Modified: branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.h?rev=39101&r1=39100&r2=39101&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.h (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.h Fri Jun 29 20:31:20 2007
@@ -22,76 +22,97 @@
#include
#include
-#include
#include "YSelectionBox.h"
-
class QLabel;
class QListBox;
class QListBoxItem;
+
class YQSelectionBox : public QVBox, public YSelectionBox
{
Q_OBJECT
public:
- YQSelectionBox( QWidget * parent, const YWidgetOpt & opt, const YCPString & label );
+ /**
+ * Constructor.
+ **/
+ YQSelectionBox( YWidget * parent, const string & label );
/**
- * Inherited from YWidget: Sets the enabled state of the
- * widget. All new widgets are enabled per definition. Only
- * enabled widgets can take user input.
+ * Destructor.
**/
- void setEnabled( bool enabled );
+ virtual ~YQSelectionBox();
/**
- * Preferred width of the widget.
+ * Change the label text.
*
- * Reimplemented from YWidget.
+ * Reimplemented from YSelectionWidget.
**/
- virtual int preferredWidth();
+ virtual void setLabel( const string & label );
/**
- * Preferred height of the widget.
+ * Add an item.
*
- * Reimplemented from YWidget.
+ * Reimplemented from YSelectionWidget.
**/
- virtual int preferredHeight();
+ virtual void addItem( YItem * item );
/**
- * Set the new size of the widget.
+ * Select or deselect an item.
*
- * Reimplemented from YWidget.
+ * Reimplemented from YSelectionWidget.
**/
- virtual void setSize( int newWidth, int newHeight );
+ virtual void selectItem( YItem * item, bool selected = true );
/**
- * Change the label text.
+ * Deselect all items.
+ *
+ * Reimplemented from YSelectionWidget.
**/
- void setLabel( const YCPString & label );
+ virtual void deselectAllItems();
/**
- * Notification that a new item has been added.
+ * Delete all items.
*
- * Reimplemented from YSelectionBox.
+ * Reimplemented from YSelectionWidget.
**/
- void itemAdded( const YCPString & itemText, int itemIndex, bool selected );
+ virtual void deleteAllItems();
+
+ /**
+ * Set enabled/disabled state.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual void setEnabled( bool enabled );
/**
- * Inherited from YSelectionBox. Returns the index of the currently
- * selected item or -1 if no item is selected.
+ * Preferred width of the widget.
+ *
+ * Reimplemented from YWidget.
**/
- int getCurrentItem();
+ virtual int preferredWidth();
/**
- * Inherited from YSelectionBox. Makes another item selected.
+ * Preferred height of the widget.
+ *
+ * Reimplemented from YWidget.
**/
- void setCurrentItem( int index );
+ virtual int preferredHeight();
+
+ /**
+ * Set the new size of the widget.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual void setSize( int newWidth, int newHeight );
/**
* Accept the keyboard focus.
+ *
+ * Reimplemented from YWidget.
**/
virtual bool setKeyboardFocus();
@@ -100,12 +121,6 @@
**/
bool eventFilter( QObject * obj, QEvent * ev );
- /**
- * Delete all items.
- *
- * Reimplemented from YSelectionWidget
- **/
- virtual void deleteAllItems();
protected slots:
@@ -135,24 +150,18 @@
protected:
+ /**
+ * Select an item by index.
+ **/
+ void selectItem( int index );
+
//
// Data members
//
- // Widgets
-
- QLabel * _qt_label;
- QListBox * _qt_listbox;
-
-
- // Very small default size if specified
- bool _shrinkable;
-
- // Don't use a timer to collect events
- bool _immediateMode;
-
- // Timer to collect multiple events before returning
- QTimer _timer;
+ QLabel * _qt_label;
+ QListBox * _qt_listBox;
+ QTimer _timer;
};
#endif // YQLabel_h
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org