[yast-commit] r38254 - in /branches/tmp/sh/mod-ui/core/libyui/src: YPushButton.cc YPushButton.h YRadioButton.h YTextEntry.h YWidget.h
Author: sh-sh-sh Date: Fri Jun 1 18:06:58 2007 New Revision: 38254 URL: http://svn.opensuse.org/viewcvs/yast?rev=38254&view=rev Log: ported PushButton Modified: branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.cc branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.h branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.h branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h Modified: branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.cc?rev=38254&r1=38253&r2=38254&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.cc Fri Jun 1 18:06:58 2007 @@ -12,72 +12,104 @@ File: YPushButton.cc - Author: Mathias Kettner <kettner@suse.de> - Maintainer: Stefan Hundhammer <sh@suse.de> + Author: Stefan Hundhammer <sh@suse.de> /-*/ -#include <ycp/YCPSymbol.h> -#include <ycp/YCPBoolean.h> #define y2log_component "ui" #include <ycp/y2log.h> #include "YUISymbols.h" #include "YPushButton.h" +struct YPushButtonPrivate +{ + std::string label; + bool isDefaultButton; + + /** + * Constructor. + **/ + YPushButtonPrivate( const std::string & label, bool isDefaultButton ) + : label( label ) + , isDefaultButton( isDefaultButton ) + {} +} + -YPushButton::YPushButton( const YWidgetOpt & opt, YCPString label ) +YPushButton::YPushButton( const YWidgetOpt & opt, const std::string & label ) : YWidget( opt ) - , label( label ) + , priv( new YPushButtonPrivate( label, opt.isDefaultButton.value() ) ) +{ +} + + +YPushButton::~YPushButton() { + // NOP } +void YPushButton::setLabel( const std::string & label ) +{ + priv->label = label; +} -void YPushButton::setLabel( const YCPString & label ) +std::string YPushButton::label() const { - this->label = label; + return priv->label; } -YCPString YPushButton::getLabel() +bool YPushButton::isDefaultButton() const { - return label; + return priv->isDefaultButton; } -YCPValue YPushButton::changeWidget( const YCPSymbol & property, const YCPValue & newvalue ) +const YPropertySet & +YPushButton::propertySet() { - string s = property->symbol(); + static YPropertySet propSet; - /** - * @property string Label the text on the PushButton - */ - if ( s == YUIProperty_Label ) + if ( propSet.isEmpty() ) { - if ( newvalue->isString() ) - { - setLabel( newvalue->asString() ); - return YCPBoolean( true ); - } - else - { - y2error( "PushButton: Invalid parameter %s for Label property. Must be string", - newvalue->toString().c_str() ); - return YCPBoolean( false ); - } + /* + * @property string Label text on the button + */ + propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); + propSet.add( YWidget::propertySet() ); } - else return YWidget::changeWidget( property, newvalue ); + + return propSet; } +void +YPushButton::setProperty( const std::string & propertyName, const YPropertyValue & val ) +{ + propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch + + if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); + else + { + YWidget::setProperty( propertyName, val ); + } +} -YCPValue YPushButton::queryWidget( const YCPSymbol & property ) + +YPropertyValue +YPushButton::getProperty( const std::string & propertyName ) { - string s = property->symbol(); - if ( s == YUIProperty_Label ) return getLabel(); - else return YWidget::queryWidget( property ); + propertySet().check( propertyName ); // throws exceptions if not found + + if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() ); + else + { + return YWidget::getProperty( propertyName ); + } } + Modified: branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.h?rev=38254&r1=38253&r2=38254&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.h Fri Jun 1 18:06:58 2007 @@ -12,8 +12,7 @@ File: YPushButton.h - Author: Mathias Kettner <kettner@suse.de> - Maintainer: Stefan Hundhammer <sh@suse.de> + Author: Stefan Hundhammer <sh@suse.de> /-*/ @@ -21,75 +20,102 @@ #define YPushButton_h #include "YWidget.h" -#include <ycp/YCPString.h> -/** - * @short Implementation of the PushButton widget - * Derived classes need to check opt.isDefaultButton! - */ +class YPushButtonPrivate; + + class YPushButton : public YWidget { public: /** - * Creates a new YPushButton - * @param label the button label - * @param opt widget options - */ - YPushButton( const YWidgetOpt & opt, YCPString label ); + * Constructor. + **/ + YPushButton( const YWidgetOpt & opt, const std::string & label ); + + /** + * Destructor. + **/ + ~YPushButton(); /** * Returns a descriptive name of this widget class for logging, * debugging etc. */ - virtual char *widgetClass() { return "YPushButton"; } + virtual const char *widgetClass() { return "YPushButton"; } /** - * Implements the ui command changeWidget for the widget specific - * properties. - */ - YCPValue changeWidget( const YCPSymbol & property, const YCPValue & newvalue ); + * Get the label (the text on the RadioButton). + **/ + std::string label() const; /** - * Implements the ui command changeWidget for the widget specific - * properties. - */ - YCPValue queryWidget( const YCPSymbol & property ); + * Set the label (the text on the button). + * + * Derived classes are free to reimplement this, but they should call this + * base class method at the end of the overloaded function. + **/ + virtual void setLabel( const std::string & label ); /** - * change the label of the push button. Overload this, but call - * YPushButton::setLabel at the end of your own function. - */ - virtual void setLabel( const YCPString & label ); + * Returns 'true' if this is the dialog's default button, i.e. the one + * button that gets activated if the user hits the [Return] key anywhere in + * the dialog. + **/ + bool isDefaultButton() const; /** - * Get the current label of the text entry. 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. - */ - YCPString getLabel(); - - /** - * Set this button's icon from an icon file in the UI's default icon directory. - * Clear the icon if the name is empty. + * Set this button's icon from an icon file in the UI's default icon + * directory. Clear the icon if the name is empty. * * This default implementation does nothing. * UIs that can handle icons can choose to overwrite this method. **/ - virtual void setIcon( const YCPString & icon_name ) {} + virtual void setIcon( const std::string & iconName ) {} /** - * The name of the widget property that holds the keyboard shortcut. - * Inherited from YWidget. - */ - const char *shortcutProperty() { return YUIProperty_Label; } + * Set a property. + * Reimplemented from YWidget. + * + * This method may throw YUIPropertyExceptions. + **/ + virtual void setProperty( const std::string & propertyName, + const YPropertyValue & val ); + /** + * Get a property. + * Reimplemented from YWidget. + * + * This method may throw YUIPropertyExceptions. + **/ + virtual YPropertyValue getProperty( const std::string & propertyName ); -protected: /** - * The button label - */ - YCPString label; + * Return this class's property set. + * This also initializes the property upon the first call. + * + * Reimplemented from YWidget. + **/ + virtual const YPropertySet & propertySet(); + + /** + * Get the string of this widget that holds the keyboard shortcut. + * + * Reimplemented from YWidget. + **/ + virtual std::string shortcutString() { return label(); } + + /** + * Set the string of this widget that holds the keyboard shortcut. + * + * Reimplemented from YWidget. + **/ + virtual void setShortcutString( const std::string & str ) + { setLabel( str ); } + + +private: + + ImplPtr<YPushButtonPrivate> priv; }; 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=38254&r1=38253&r2=38254&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.h Fri Jun 1 18:06:58 2007 @@ -12,15 +12,13 @@ File: YRadioButton.h - Author: Mathias Kettner <kettner@suse.de> - Maintainer: Stefan Hundhammer <sh@suse.de> + Author: Stefan Hundhammer <sh@suse.de> /-*/ #ifndef YRadioButton_h #define YRadioButton_h -#include "ImplPtr.h" #include "YWidget.h" class YRadioButtonGroup; @@ -61,25 +59,37 @@ virtual ~YRadioButton(); /** - * Set the radio button to a new value - check or uncheck it + * Returns a descriptive name of this widget class for logging, + * debugging etc. */ - virtual void setValue( bool checked ) = 0; + virtual char *widgetClass() { return "YRadioButton"; } /** - * Returns the current value of the radio button: + * Get the current on/off value: * 'true' if checked, 'false' if unchecked. + * + * Derived classes are required to implement this. */ virtual bool value() = 0; /** - * Returns the user-visible label (the text on the RadioButton). + * Set the radio button value (on/off). + * + * Derived classes are required to implement this. + */ + virtual void setValue( bool checked ) = 0; + + /** + * Get the label (the text on the RadioButton). **/ std::string label() const; /** - * Change the label. Overload this, but call - * YRadioButton::setLabel at the end of your own function. - */ + * Set the label (the text on the RadioButton). + * + * Derived classes are free to reimplement this, but they should call this + * base class method at the end of the overloaded function. + **/ virtual void setLabel( const std::string & label ); /** @@ -94,12 +104,6 @@ void buttonGroupIsDead(); /** - * Returns a descriptive name of this widget class for logging, - * debugging etc. - */ - virtual char *widgetClass() { return "YRadioButton"; } - - /** * Set a property. * Reimplemented from YWidget. * Modified: branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.h?rev=38254&r1=38253&r2=38254&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YTextEntry.h Fri Jun 1 18:06:58 2007 @@ -20,7 +20,6 @@ #define YTextEntry_h #include <string> -#include "ImplPtr.h" #include "YWidget.h" class YMacroRecorder; @@ -46,6 +45,12 @@ virtual ~YTextEntry(); /** + * Returns a descriptive name of this widget class for logging, + * debugging etc. + */ + virtual char *widgetClass() { return "YTextEntry"; } + + /** * Get the current value (the text entered by the user or set from the * outside) of this input field. * @@ -70,8 +75,7 @@ * Set the label (the caption above the input field). * * Derived classes are free to reimplement this, but they should call this - * base class method (YTextEntry::setLabel() at the end of the overloaded - * function. + * base class method at the end of the overloaded function. **/ virtual void setLabel( const std::string & label ); @@ -113,14 +117,6 @@ **/ virtual void setInputMaxLength( int numberOfChars ); - - /** - * Returns a descriptive name of this widget class for logging, - * debugging etc. - */ - virtual char *widgetClass() { return "YTextEntry"; } - - /** * Set a property. * Reimplemented from YWidget. 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=38254&r1=38253&r2=38254&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h Fri Jun 1 18:06:58 2007 @@ -27,6 +27,7 @@ #include "YWidgetOpt.h" #include "YUISymbols.h" #include "YUIException.h" +#include "ImplPtr.h" #define YWIDGET_MAGIC 42 // what else? ;- ) -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
sh-sh-sh@svn.opensuse.org