Author: sh-sh-sh
Date: Wed May 30 18:25:05 2007
New Revision: 38210
URL: http://svn.opensuse.org/viewcvs/yast?rev=38210&view=rev
Log:
Property handling
Added:
branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc
Modified:
branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am
branches/tmp/sh/mod-ui/core/libyui/src/YCheckBox.h
branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h
branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc
branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h
branches/tmp/sh/mod-ui/core/libyui/src/YUIException.cc
branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h
branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc
branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h
branches/tmp/sh/mod-ui/core/libyui/src/YWidgetFactory.h
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=38210&r1=38209&r2=38210&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am Wed May 30 18:25:05 2007
@@ -19,6 +19,7 @@
YUI_util.cc \
YUIPlugin.cc \
YUIException.cc \
+ YProperty.cc \
\
YAlignment.cc \
YBarGraph.cc \
@@ -80,6 +81,7 @@
YUIPlugin.h \
YPackageSelectorPlugin.h \
YUIException.h \
+ YProperty.h \
ImplPtr.h \
\
YAlignment.h \
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCheckBox.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCheckBox.h?rev=38210&r1=38209&r2=38210&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCheckBox.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCheckBox.h Wed May 30 18:25:05 2007
@@ -43,6 +43,28 @@
*/
virtual char *widgetClass() { return "YCheckBox"; }
+#if 0
+ /**
+ * Set a property.
+ * Reimplemented from YWidget.
+ *
+ * This method may throw exceptions, for example
+ * - if there is no property with that name
+ * - if the expected type and the type mismatch
+ * - if the value is out of range
+ **/
+ virtual void setProperty( const YProperty & prop );
+
+ /**
+ * Get a property.
+ * Reimplemented from YWidget.
+ *
+ * This method may throw exceptions, for example
+ * - if there is no property with that name
+ **/
+ virtual YProperty getProperty( const std::string & propertyName );
+#endif
+
/**
* Implements the ui command changeWidget.
*/
Added: branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc?rev=38210&view=auto
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc (added)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc Wed May 30 18:25:05 2007
@@ -0,0 +1,120 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| |
+| (c) SuSE Linux Products GmbH |
+\----------------------------------------------------------------------/
+
+ File: YProperty.cc
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+#include "YProperty.h"
+
+
+
+#if 0
+using namespace YUI;
+#endif
+
+
+std::string
+YProperty::typeAsStr( YPropertyType type )
+{
+ switch ( type )
+ {
+ case YUnknownPropertyType: return "<Unknown>";
+ case YOtherProperty: return "<Other>";
+ case YStringProperty: return "String";
+ case YBoolProperty: return "Bool";
+ case YIntegerProperty: return "Integer";
+
+ // Intentionally omitting default branch
+ // so the compiler catches unhandled enum values
+ }
+
+ return "<Undefined property type>";
+}
+
+
+
+YPropertySet::YPropertySet()
+{
+ // NOP
+}
+
+
+YPropertySet::SearchResult
+YPropertySet::lookup( const std::string & propertyName ) const
+{
+ for ( std::vector<YProperty>::const_iterator it = _properties.begin();
+ it != _properties.end();
+ ++it )
+ {
+ if ( it->name() == propertyName )
+ return Found;
+ }
+
+ return NotFound;
+}
+
+
+YPropertySet::SearchResult
+YPropertySet::lookup( const std::string & propertyName, YPropertyType type ) const
+{
+ for ( std::vector<YProperty>::const_iterator it = _properties.begin();
+ it != _properties.end();
+ ++it )
+ {
+ if ( it->name() == propertyName )
+ {
+ if ( it->type() == type )
+ return Found;
+ else
+ return TypeMismatch;
+ }
+ }
+
+ return NotFound;
+}
+
+
+void
+YPropertySet::add( const YProperty & prop )
+{
+ _properties.push_back( prop );
+}
+
+
+void
+YPropertySet::add( const YPropertySet & otherSet )
+{
+ for ( YPropertySet::const_iterator it = otherSet.propertiesBegin();
+ it != otherSet.propertiesEnd();
+ ++it )
+ {
+ add( *it );
+ }
+}
+
+
+YPropertySet::const_iterator
+YPropertySet::propertiesBegin() const
+{
+ return _properties.begin();
+}
+
+YPropertySet::const_iterator
+YPropertySet::propertiesEnd() const
+{
+ return _properties.end();
+}
+
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h?rev=38210&r1=38209&r2=38210&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h Wed May 30 18:25:05 2007
@@ -21,123 +21,202 @@
#define YProperty_h
#include <string>
+#include <vector>
+#if 0
namespace YUI
{
+#endif
+
+ enum YPropertyType
+ {
+ YUnknownPropertyType = 0,
+ YOtherProperty, // requires futher checking
+ YStringProperty, // const std::string &
+ YBoolProperty, // bool
+ YIntegerProperty // YCP Integer == C++ long long
+
+ };
+
+ typedef long long YInteger;
+
/**
- * Base class for all property classes. Necessary to store different
- * template instances in the same container class.
+ * Description class for widget properties
**/
- class YPropertyBase
+ class YProperty
{
- protected:
+ public:
/**
* Constructor: Create a property with the specified name.
**/
- YPropertyBase( const std::string & name )
+ YProperty( const std::string & name, YPropertyType type )
: _name( name )
+ , _type( type )
{}
- virtual ~YPropertyBase() {}
-
- public:
/**
* Returns the name of this property.
**/
std::string name() const { return _name; }
+ /**
+ * Returns the type of this property.
+ **/
+ YPropertyType type() const { return _type; }
+
+ /**
+ * Returns the type of this property as string.
+ **/
+ std::string typeAsStr() const { return YProperty::typeAsStr( _type ); }
+
+ /**
+ * Returns a string description of a property type.
+ **/
+ static std::string typeAsStr( YPropertyType type );
+
private:
- std::string _name;
+ std::string _name;
+ YPropertyType _type;
};
/**
- * Template class for properties of different types for classes of type
- * Widget_T.
+ * Transport class for the value of simple properties.
+ *
+ * More complex properties (lists of items, tree descriptions, ...) have to
+ * be handled specifically someplace else, but most properties are of
+ * simple types and can be treated in similar ways.
**/
- template class YProperty:
- public YPropertyBase
+ class YPropertyValue
{
public:
/**
- * Constructor: Create a property with the specified name.
- * The value of this property will be retrieved with the specified
- * 'getMethod' and set with the specified 'setMethod'.
- *
- * Example:
- *
- * class MyWidget: public YWidget
- * {
- * private:
- * std::string _label;
- *
- * public:
- * ...
- * std::string label() const { return _label; }
- * void setLabel( std::string newLabel ) { _label = newLabel; }
- * };
- *
- * YProperty labelProp( "Label",
- * &(MyWidget::label),
- * &(MyWidget::setLabel) );
- * MyWidget w = new MyWidget(...);
- * std::string myLabel = labelProp.get( w, "Label" );
- **/
- YProperty( const std::string & name,
- Value_T (Widget_T::*getMethod)(),
- void (Widget_T::*setMethod)( Value_T ) )
- : YPropertyBase( name )
- , _getMethod( getMethod )
- , _setMethodByValue( setMethod )
- , _setMethodByConstRef( 0 )
- {}
+ * Constructor for string properties.
+ **/
+ YPropertyValue( const std::string & str ):
+ _type( YStringProperty ), _stringVal( str ) {}
/**
- * Constructor with a setMethod that accepts a const ref rather than
- * the value directly.
+ * Constructor for bool properties.
**/
- YProperty( const std::string & name,
- Value_T (Widget_T::*getMethod)(),
- void (Widget_T::*setMethod)( const Value_T & ) )
- : YPropertyBase( name )
- , _getMethod( getMethod )
- , _setMethodByValue( 0 )
- , _setMethodByConstRef( setMethod )
- {}
+ YPropertyValue( bool b ):
+ _type( YBoolProperty ), _boolVal( b ) {}
/**
- * Destructor.
+ * Constructor for numerical (YCP integer) properties.
**/
- virtual ~YProperty() {}
+ YPropertyValue( YInteger num ):
+ _type( YIntegerProperty ), _integerVal( num ) {}
/**
- * Retrieve the current value of this property from 'widget'.
+ * Returns the type of this property value.
+ * Use this to determine which xyVal() method to use.
**/
- Value_T get( Widget_T * widget ) const
- {
- return (widget->*_getMethod)();
- }
+ YPropertyType type() const { return _type; }
/**
- * Set this property in 'widget'.
+ * Returns the type of this property value as string.
**/
- void set( Widget_T * widget, Value_T newValue )
- {
- if ( _setMethodByValue )
- (widget->*_setMethodByValue)( newValue );
- else
- (widget->*_setMethodByConstRef)( newValue );
- }
+ std::string typeAsStr() const { return YProperty::typeAsStr( _type ); }
+
+ /**
+ * Methods to get the value of this property.
+ * Check with type() which one to use.
+ **/
+ std::string stringVal() const { return _stringVal; }
+ bool boolVal() const { return _boolVal; }
+ YInteger integerVal() const { return _integerVal; }
private:
- Value_T (Widget_T::*_getMethod)();
- void (Widget_T::*_setMethodByValue)( Value_T );
- void (Widget_T::*_setMethodByConstRef)( const Value_T & );
+
+ YPropertyType _type;
+ std::string _stringVal;
+ bool _boolVal;
+ YInteger _integerVal;
};
+ /**
+ * A set of properties to check names and types against.
+ **/
+ class YPropertySet
+ {
+ public:
+ /**
+ * Constructor.
+ **/
+ YPropertySet();
+
+ enum SearchResult
+ {
+ NotFound = 0, // = 0 for use like: if ( ! propSet.lookup( "Label" ) ) ...
+ Found,
+ TypeMismatch // Found, but wrong type
+ };
+
+ /**
+ * Look up a property with 'propertyName' in this property set.
+ **/
+ SearchResult lookup( const std::string & propertyName ) const;
+
+ /**
+ * Look up a property with 'propertyName' in this property set.
+ * If it contains a property with that name, check also the expected
+ * type against 'type'.
+ **/
+ SearchResult lookup( const std::string & propertyName, YPropertyType type ) const;
+
+ /**
+ * Same as above, overloaded for convenience.
+ **/
+ SearchResult lookup( const YProperty & prop ) const
+ { return lookup( prop.name(), prop.type() ); }
+
+ /**
+ * Returns 'true' if this property set does not contain anything.
+ **/
+ bool isEmpty() const { return _properties.empty(); }
+
+ /**
+ * Add a property to this property set.
+ **/
+ void add( const YProperty & prop );
+
+ /**
+ * Adds all properties of another property set.
+ *
+ * If that other set contains duplicates (properties that are already
+ * in this set), those others will never be found with lookup().
+ **/
+ void add( const YPropertySet & otherSet );
+
+ typedef std::vector<YProperty>::const_iterator const_iterator;
+
+ /**
+ * Returns an iterator that points to the first property in this set.
+ **/
+ const_iterator propertiesBegin() const;
+
+ /**
+ * Returns an iterator that points after the last property in this set.
+ **/
+ const_iterator propertiesEnd() const;
+
+ private:
+
+ /**
+ * This class uses a simple std::vector as a container to hold the
+ * properties: Normally, the number of properties for each widget is so
+ * small (2..5) that using any more sophisticated container like
+ * std::set etc. would not pay off. More likely, it would add overhead.
+ **/
+ std::vector<YProperty> _properties;
+ };
+
+#if 0
} // namespace YUI
+#endif
#endif // YProperty_h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc?rev=38210&r1=38209&r2=38210&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc Wed May 30 18:25:05 2007
@@ -35,13 +35,13 @@
struct YRadioButtonPrivate
{
- YCPString label;
+ std::string label;
YRadioButtonGroup * radioButtonGroup;
/**
* Constructor
**/
- YRadioButtonPrivate( YCPString label )
+ YRadioButtonPrivate( std::string label )
: label( label )
, radioButtonGroup( 0 )
{};
@@ -51,7 +51,7 @@
YRadioButton::YRadioButton( const YWidgetOpt & opt,
const YCPString & label )
: YWidget( opt )
- , priv( new YRadioButtonPrivate( label ) )
+ , priv( new YRadioButtonPrivate( label->value() ) )
{
YUI_CHECK_NEW( priv );
}
@@ -64,18 +64,64 @@
}
-void YRadioButton::setLabel( const YCPString & newLabel )
+void YRadioButton::setLabel( const std::string & newLabel )
{
priv->label = newLabel;
}
-YCPString YRadioButton::label() const
+std::string YRadioButton::label() const
{
return priv->label;
}
+const YPropertySet &
+YRadioButton::propertySet()
+{
+ static YPropertySet propSet;
+
+ if ( propSet.isEmpty() )
+ {
+ propSet.add( YProperty( YUIProperty_Value, YBoolProperty ) );
+ propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
+ propSet.add( YWidget::propertySet() );
+ }
+
+ return propSet;
+}
+
+
+void
+YRadioButton::setProperty( const std::string & propertyName, const YPropertyValue & val )
+{
+ YPropertySet::SearchResult result = propertySet().lookup( propertyName, val.type() );
+
+ if ( result == YPropertySet::Found )
+ {
+ if ( propertyName == YUIProperty_Value ) setValue( val.boolVal() );
+ else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
+ else
+ YWidget::setProperty( propertyName, val );
+ }
+}
+
+
+YPropertyValue
+YRadioButton::getProperty( const std::string & propertyName )
+{
+ YPropertySet::SearchResult result = propertySet().lookup( propertyName );
+
+ if ( result == YPropertySet::Found )
+ {
+ if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() );
+ if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
+ else
+ return YWidget::getProperty( propertyName );
+ }
+}
+
+
YCPValue YRadioButton::changeWidget( const YCPSymbol & property, const YCPValue & newvalue )
{
string s = property->symbol();
@@ -104,7 +150,7 @@
{
if ( newvalue->isString() )
{
- setLabel( newvalue->asString() );
+ setLabel( newvalue->asString()->value() );
return YCPBoolean( true );
}
else
@@ -123,7 +169,7 @@
{
string s = property->symbol();
if ( s == YUIProperty_Value ) return YCPBoolean( value() );
- else if ( s == YUIProperty_Label ) return label();
+ else if ( s == YUIProperty_Label ) return YCPString( label() );
else return YWidget::queryWidget( property );
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h?rev=38210&r1=38209&r2=38210&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h Wed May 30 18:25:05 2007
@@ -68,15 +68,43 @@
virtual char *widgetClass() { return "YRadioButton"; }
/**
+ * Set a property.
+ * Reimplemented from YWidget.
+ *
+ * This method may throw exceptions, for example
+ * - if there is no property with that name
+ * - if the expected type and the type mismatch
+ * - if the value is out of range
+ **/
+ virtual void setProperty( const std::string & propertyName,
+ const YPropertyValue & val );
+
+ /**
+ * Get a property.
+ * Reimplemented from YWidget.
+ *
+ * This method may throw exceptions, for example
+ * - if there is no property with that name
+ **/
+ virtual YPropertyValue getProperty( const std::string & propertyName );
+
+ /**
+ * Return this class's property set.
+ * This also initializes the property upon the first call.
+ * Reimplemented from YWidget.
+ **/
+ virtual const YPropertySet & propertySet();
+
+ /**
* Returns the user-visible label (the text on the RadioButton).
**/
- YCPString label() const;
+ std::string label() const;
/**
* Change the label. Overload this, but call
* YRadioButton::setLabel at the end of your own function.
*/
- virtual void setLabel( const YCPString & label );
+ virtual void setLabel( const std::string & label );
/**
* Implements the ui command changeWidget.
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUIException.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUIException.cc?rev=38210&r1=38209&r2=38210&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUIException.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUIException.cc Wed May 30 18:25:05 2007
@@ -26,6 +26,7 @@
#define y2log_component "ui"
#include
#include "YUIException.h"
+#include "YWidget.h"
using std::string;
@@ -42,7 +43,7 @@
sprintf( formatted_number, "%u", _line );
str += formatted_number;
-
+
return str;
}
@@ -130,3 +131,41 @@
// INT << where_r << " " << prefix_r << " " << excpt_r << endl;
}
+
+ostream &
+YUIUnknownPropertyException::dumpOn( ostream & str ) const
+{
+ if ( widget() )
+ {
+ return str << widget()->widgetClass()
+ << " has no property named \""
+ << property().name()
+ << "\""
+ << endl;
+ }
+ else
+ {
+ return str << "Unknown property name \""
+ << property().name()
+ << "\""
+ << endl;
+ }
+}
+
+
+ostream &
+YUIPropertyTypeMismatchException::dumpOn( ostream & str ) const
+{
+ const char * widgetClass = widget() ?
+ widget()->widgetClass() :
+ "<Unknown Widget Type>";
+
+ return str << "Property type mismatch: "
+ << widgetClass
+ << "::" << property().name()
+ << "is type "
+ << property().typeAsStr()
+ << ", not "
+ << value().typeAsStr()
+ << endl;
+}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h?rev=38210&r1=38209&r2=38210&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h Wed May 30 18:25:05 2007
@@ -27,9 +27,13 @@
#include <iosfwd>
#include <stdexcept>
+#include "YProperty.h"
+
using std::string;
using std::ostream;
+class YWidget;
+
//
// Macros for application use
@@ -325,22 +329,117 @@
class YUIOutOfMemoryException: public YUIException
{
public:
- /**
- * Constructor.
- **/
YUIOutOfMemoryException()
: YUIException( "Out of memory" )
{}
- /**
- * Destructor.
- **/
virtual ~YUIOutOfMemoryException() throw()
{}
}; // class YUIOutOfMemoryException
+/**
+ * Abstract base class for widget property exceptions.
+ **/
+class YUIPropertyException: public YUIException
+{
+protected:
+ YUIPropertyException( const YProperty & prop,
+ YWidget * widget = 0 )
+ : YUIException()
+ , _property( prop )
+ , _widget( widget )
+ {}
+
+ virtual ~YUIPropertyException() throw()
+ {}
+
+public:
+ /**
+ * Returns the property that caused this exception.
+ **/
+ YProperty property() const { return _property; }
+
+ /**
+ * Returns the associated widget or 0 if there was none.
+ **/
+ YWidget * widget() const { return _widget; }
+
+protected:
+
+ /**
+ * Write proper error message with all relevant data.
+ * Reimplemented from YUIException.
+ **/
+ virtual ostream & dumpOn( ostream & str ) const = 0;
+
+private:
+ YProperty _property;
+ YWidget * _widget;
+};
+
+
+/**
+ * Exception class for "unknown property name":
+ * The application tried to set (or query) a property that doesn't exist.
+ **/
+class YUIUnknownPropertyException: public YUIPropertyException
+{
+public:
+ YUIUnknownPropertyException( const std::string & propertyName, YWidget * widget )
+ : YUIPropertyException( YProperty( propertyName, YUnknownPropertyType ), widget )
+ {}
+
+ virtual ~YUIUnknownPropertyException() throw()
+ {}
+
+protected:
+
+ /**
+ * Write proper error message with all relevant data.
+ * Reimplemented from YUIException.
+ **/
+ virtual ostream & dumpOn( ostream & str ) const;
+};
+
+
+/**
+ * Exception class for "property type mismatch":
+ * The application tried to set a property with a wrong type.
+ **/
+class YUIPropertyTypeMismatchException: public YUIPropertyException
+{
+public:
+
+ YUIPropertyTypeMismatchException( const YProperty & property,
+ const YPropertyValue & value,
+ YWidget * widget )
+ : YUIPropertyException( property, widget )
+ , _val( value )
+ {}
+
+ virtual ~YUIPropertyTypeMismatchException() throw()
+ {}
+
+ /**
+ * Return the property value (and type) the application tried to set.
+ **/
+ YPropertyValue value() const { return _val; }
+
+protected:
+
+ /**
+ * Write proper error message with all relevant data.
+ * Reimplemented from YUIException.
+ **/
+ virtual ostream & dumpOn( ostream & str ) const;
+
+private:
+ YPropertyValue _val;
+};
+
+
//
// Helper templates
//
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc?rev=38210&r1=38209&r2=38210&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc Wed May 30 18:25:05 2007
@@ -152,6 +152,64 @@
}
+const YPropertySet &
+YWidget::propertySet()
+{
+ static YPropertySet propSet;
+
+ if ( propSet.isEmpty() )
+ {
+ propSet.add( YProperty( YUIProperty_Enabled, YBoolProperty ) );
+ propSet.add( YProperty( YUIProperty_Notify, YBoolProperty ) );
+ propSet.add( YProperty( YUIProperty_WindowID, YIntegerProperty) );
+ propSet.add( YProperty( YUIProperty_WidgetClass, YStringProperty ) );
+ propSet.add( YProperty( YUIProperty_DebugLabel, YStringProperty ) );
+ propSet.add( YProperty( YUIProperty_DialogDebugLabel, YStringProperty ) );
+ }
+
+ return propSet;
+}
+
+
+void
+YWidget::setProperty( const std::string & propertyName, const YPropertyValue & val )
+{
+ YPropertySet::SearchResult result = propertySet().lookup( propertyName, val.type() );
+
+ if ( result == YPropertySet::Found )
+ {
+ if ( propertyName == YUIProperty_Enabled ) setEnabling( val.boolVal() );
+ else if ( propertyName == YUIProperty_Notify ) setNotify ( val.boolVal() );
+ else
+ {
+ if ( propertyName == YUIProperty_WidgetClass ||
+ propertyName == YUIProperty_DebugLabel ||
+ propertyName == YUIProperty_DialogDebugLabel )
+ {
+ y2error( "Property \"%s\" is read-only", propertyName.c_str() );
+ }
+ }
+ }
+}
+
+
+YPropertyValue
+YWidget::getProperty( const std::string & propertyName )
+{
+ YPropertySet::SearchResult result = propertySet().lookup( propertyName );
+
+ if ( result == YPropertySet::Found )
+ {
+ if ( propertyName == YUIProperty_Enabled ) return YPropertyValue( getEnabling() );
+ if ( propertyName == YUIProperty_Notify ) return YPropertyValue( getNotify() );
+ if ( propertyName == YUIProperty_WidgetClass ) return YPropertyValue( widgetClass() );
+ if ( propertyName == YUIProperty_DebugLabel ) return YPropertyValue( debugLabel() );
+ if ( propertyName == YUIProperty_DialogDebugLabel ) return YPropertyValue( yDialog()->debugLabel() );
+ }
+}
+
+
+
YCPValue YWidget::changeWidget( const YCPSymbol & property, const YCPValue & newvalue )
{
string symbol = property->symbol();
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h?rev=38210&r1=38209&r2=38210&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h Wed May 30 18:25:05 2007
@@ -23,6 +23,7 @@
#include <string>
#include <list>
#include
+#include "YProperty.h"
#include "YWidgetOpt.h"
#include "YUISymbols.h"
@@ -41,7 +42,6 @@
typedef std::list::iterator YWidgetListIterator;
typedef std::list::const_iterator YWidgetListConstIterator;
-
/**
* @short Abstract base class of all ui widgets
*/
@@ -78,11 +78,66 @@
virtual std::string debugLabel();
/**
+ * Return this class's property set.
+ * This also initializes the property upon the first call.
+ *
+ * Derived classes should reimplement this.
+ *
+ * Remember to add the base class's property set to your own
+ * in reimplemented versions, e.g.:
+ *
+ * const YPropertySet &
+ * myWidgetClass::propertySet()
+ * {
+ * static YPropertySet propSet;
+ *
+ * if ( propSet.isEmpty() )
+ * {
+ * // Add properties for the derived class
+ * propSet.add( YProperty( YUIProperty_Value, YStringProperty ) );
+ * propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
+ *
+ * // Add base class properties
+ * propSet.add( YWidget::propertySet() );
+ * }
+ *
+ * return propSet;
+ * }
+ *
+ * Otherwise the base class's properties will not be available in the
+ * derived class. It is also important that the base class's properties
+ * are added after those of the derived class so the derived class's
+ * properties have priority over those of the base class.
+ **/
+ virtual const YPropertySet & propertySet();
+
+ /**
+ * Set a property. Derived classes need to implement this.
+ *
+ * This method may throw exceptions, for example
+ * - if there is no property with that name
+ * - if the expected type and the type mismatch
+ * - if the value is out of range
+ **/
+ virtual void setProperty( const std::string & propertyName,
+ const YPropertyValue & val );
+ // FIXME: = 0
+
+ /**
+ * Get a property. Derived classes need to implement this.
+ *
+ * This method may throw exceptions, for example
+ * - if there is no property with that name
+ **/
+ virtual YPropertyValue getProperty( const std::string & propertyName );
+ // FIXME: = 0
+
+ /**
* Checks whether or not this object is valid. This is to enable
* dangling pointer error checking ( i.e. this object is already
* deallocated, but a pointer to it is still in use ).
*/
- bool isValid() const { return magic == YWIDGET_MAGIC; }
+ bool isValid() const { return magic == YWIDGET_MAGIC; }
/**
* Return the widget serial number (the internal widget ID).
@@ -451,6 +506,10 @@
long windowID;
+private:
+ static YPropertySet _propertySet;
+
+
public:
/**
* Helper class that calls startMultipleChanges() in its constructor
@@ -461,7 +520,7 @@
{
public:
OptimizeChanges( YWidget & w ) : yw(w) { yw.startMultipleChanges(); }
- ~OptimizeChanges() { yw.doneMultipleChanges(); }
+ ~OptimizeChanges() { yw.doneMultipleChanges(); }
private:
OptimizeChanges( const OptimizeChanges & ); // no copy
void operator=( const OptimizeChanges & ); // no assign
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YWidgetFactory.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YWidgetFactory.h?rev=38210&r1=38209&r2=38210&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YWidgetFactory.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YWidgetFactory.h Wed May 30 18:25:05 2007
@@ -26,30 +26,7 @@
{
typedef double YLayoutSize_t;
-#if 0
- struct YItem
- {
- std::string label;
- std::string id;
- bool isSelected;
-
- YItem( std::string labelText )
- : label( labelText )
- , id( labelText )
- , isSelected( false )
- {}
-
- YItem( std::string labelText, std::string idText, bool sel = false )
- : label( labelText )
- , id( idText )
- , isSelected( sel )
- {}
- }; // struct YItem
-
- typedef std::list<YItem> YItemList;
-#endif
-
-
+
class YWidgetFactory
{
public:
@@ -78,7 +55,7 @@
YInputField * createInputField ( YWidget * parent, std::string label );
YCheckBox * createCheckBox ( YWidget * parent, std::string label, bool isChecked = false );
YRadioButton * createRadioButton ( YWidget * parent, std::string label, bool isChecked = false );
- YComboBox * createComboBox ( YWidget * parent, std::string label, bool editable = false );
+ YComboBox * createComboBox ( YWidget * parent, std::string label, bool editable = false );
YSelectionBox * createSelectionBox ( YWidget * parent, std::string label );
YTree * createTree ( YWidget * parent, std::string label );
YTable * createTable ( YWidget * parent );
@@ -203,6 +180,30 @@
}; // class YWidgetFactory
+#if 0
+ struct YItem
+ {
+ std::string label;
+ std::string id;
+ bool isSelected;
+
+ YItem( std::string labelText )
+ : label( labelText )
+ , id( labelText )
+ , isSelected( false )
+ {}
+
+ YItem( std::string labelText, std::string idText, bool sel = false )
+ : label( labelText )
+ , id( idText )
+ , isSelected( sel )
+ {}
+ }; // struct YItem
+
+ typedef std::list<YItem> YItemList;
+#endif
+
+
} // namespace YUI
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org