[yast-commit] r38324 - /branches/tmp/sh/mod-ui/core/libyui/src/
Author: sh-sh-sh Date: Wed Jun 6 16:55:02 2007 New Revision: 38324 URL: http://svn.opensuse.org/viewcvs/yast?rev=38324&view=rev Log: parent management Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCheckBoxFrame.cc branches/tmp/sh/mod-ui/core/libyui/src/YChildrenManager.h branches/tmp/sh/mod-ui/core/libyui/src/YContainerWidget.cc branches/tmp/sh/mod-ui/core/libyui/src/YContainerWidget.h branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCheckBoxFrame.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCheckBoxFrame.cc?rev=38324&r1=38323&r2=38324&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCheckBoxFrame.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCheckBoxFrame.cc Wed Jun 6 16:55:02 2007 @@ -63,7 +63,7 @@ enabled ? "Enabling" : "Diabling", widgetClass(), debugLabel().c_str() ); - setChildrenEnabling( enabled ); + setChildrenEnabled( enabled ); } } Modified: branches/tmp/sh/mod-ui/core/libyui/src/YChildrenManager.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YChildrenManager.h?rev=38324&r1=38323&r2=38324&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YChildrenManager.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YChildrenManager.h Wed Jun 6 16:55:02 2007 @@ -30,7 +30,7 @@ **/ template<class T> class YChildrenManager { -protected: +public: /** * Constructor. @@ -46,8 +46,7 @@ **/ virtual ~YChildrenManager() {} -public: - + typedef std::list<T *> ChildrenList; /** Modified: branches/tmp/sh/mod-ui/core/libyui/src/YContainerWidget.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YContainerWidget.cc?rev=38324&r1=38323&r2=38324&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YContainerWidget.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YContainerWidget.cc Wed Jun 6 16:55:02 2007 @@ -91,12 +91,20 @@ void YContainerWidget::dumpDialogWidgetTree() { - YContainerWidget *dialog = dynamic_cast <YContainerWidget *> ( yDialog() ); +#if 0 + // FIXME + // FIXME + // FIXME + YDialog * dialog = findDialog(); if ( dialog ) dialog->dumpWidgetTree(); else dumpWidgetTree(); + // FIXME + // FIXME + // FIXME +#endif } @@ -152,7 +160,7 @@ } -void YContainerWidget::setChildrenEnabling( bool enabled ) +void YContainerWidget::setChildrenEnabled( bool enabled ) { for ( int i = 0; i < numChildren(); i++ ) { @@ -163,14 +171,14 @@ if ( container ) { // y2debug( "Recursing into %s", container->debugLabel().c_str() ); - container->setEnabling( enabled ); - container->setChildrenEnabling( enabled ); + container->setEnabled( enabled ); + container->setChildrenEnabled( enabled ); } } else { // y2debug( "%s %s", enabled ? "Enabling" : "Disabling", children[i]->debugLabel().c_str() ); - children[i]->setEnabling( enabled ); + children[i]->setEnabled( enabled ); } } } Modified: branches/tmp/sh/mod-ui/core/libyui/src/YContainerWidget.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YContainerWidget.h?rev=38324&r1=38323&r2=38324&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YContainerWidget.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YContainerWidget.h Wed Jun 6 16:55:02 2007 @@ -151,7 +151,7 @@ /** * Enable or disable all widgets in this widget tree. **/ - void setChildrenEnabling( bool enabled ); + void setChildrenEnabled( bool enabled ); /** * Returns a (possibly translated) text describing this dialog for 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=38324&r1=38323&r2=38324&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc Wed Jun 6 16:55:02 2007 @@ -146,16 +146,16 @@ YRadioButtonGroup * YRadioButton::findRadioButtonGroup() const { - YWidget * parent = yParent(); + YWidget * widget = parent(); - while ( parent ) + while ( widget ) { - YRadioButtonGroup * radioButtonGroup = dynamic_cast<YRadioButtonGroup *> (parent); + YRadioButtonGroup * radioButtonGroup = dynamic_cast<YRadioButtonGroup *> (widget); if ( radioButtonGroup ) return radioButtonGroup; else - parent = parent->yParent(); + widget = widget->parent(); } return 0; 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=38324&r1=38323&r2=38324&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h Wed Jun 6 16:55:02 2007 @@ -143,13 +143,43 @@ #define YUI_CHECK_NEW( PTR ) \ do \ { \ - if ( ! ( PTR ) ) \ + if ( ! (PTR) ) \ { \ YUI_THROW( YUIOutOfMemoryException() ); \ } \ } while( 0 ) + +/** + * Check for null pointer. + * Throws YUINullPointerException if the pointer is 0. + **/ +#define YUI_CHECK_PTR( PTR ) \ + do \ + { \ + if ( ! (PTR) ) \ + { \ + YUI_THROW( YUINullPointerException() ); \ + } \ + } while( 0 ) + + +/** + * Check if a widget pointer is valid. + * Throws YUIInvalidWidgetException if it is 0 or invalid (already deleted). + **/ +#define YUI_CHECK_WIDGET( WIDGET ) \ + do \ + { \ + if ( ! (WIDGET) || ! (WIDGET)->isValid() ) \ + { \ + YUI_THROW( YUIInvalidWidgetException() ); \ + } \ + } while( 0 ) + + + /** * Helper class for UI exceptions: Store _FILE_, _FUNCTION_ and _LINE_. * Construct this using the YUI_EXCEPTION_CODE_LOCATION macro. @@ -323,6 +353,22 @@ /** + * Exception class for generic null pointer exceptions. + * When available, a more specialized exception class should be used. + **/ +class YUINullPointerException: public YUIException +{ +public: + YUINullPointerException() + : YUIException( "Null pointer" ) + {} + + virtual ~YUINullPointerException() throw() + {} +}; + + +/** * Exception class for "out of memory". * Typically used if operator new returned 0. **/ @@ -336,7 +382,23 @@ virtual ~YUIOutOfMemoryException() throw() {} -}; // class YUIOutOfMemoryException +}; + +/** + * Exception class vor invalid widgets. + * This is typically caused by widget pointers that continue living after the + * corresponding widget has already been deleted. + **/ +class YUIInvalidWidgetException: public YUIException +{ +public: + YUIInvalidWidgetException() + : YUIException( "Invalid widget" ) + {} + + virtual ~YUIInvalidWidgetException() throw() + {} +}; /** @@ -538,7 +600,7 @@ * Returns the child widget. **/ YWidget * child() const { return _child; } - + protected: /** @@ -560,7 +622,7 @@ << containerWidgetClass << std::endl; } - + private: YWidget * _container; 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=38324&r1=38323&r2=38324&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 Wed Jun 6 16:55:02 2007 @@ -633,7 +633,7 @@ return 0; } - if ( widgetEvent->widget()->yDialog() != currentDialog() ) + if ( widgetEvent->widget()->findDialog() != currentDialog() ) { /** * Silently discard events from all but the current (topmost) dialog. @@ -1809,7 +1809,7 @@ YContainerWidget * container = dynamic_cast<YContainerWidget *>( widget ); if ( ! container ) - container = dynamic_cast<YContainerWidget *>( widget->yParent() ); + container = dynamic_cast<YContainerWidget *>( widget->parent() ); if ( container ) { Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc?rev=38324&r1=38323&r2=38324&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc Wed Jun 6 16:55:02 2007 @@ -292,7 +292,7 @@ } if ( opt.isDisabled.value() ) - w->setEnabling( false ); + w->setDisabled(); w->setParent(p); } 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=38324&r1=38323&r2=38324&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc Wed Jun 6 16:55:02 2007 @@ -12,8 +12,7 @@ File: YWidget.cc - Author: Mathias Kettner <kettner@suse.de> - Maintainer: Stefan Hundhammer <sh@suse.de> + Author: Stefan Hundhammer <sh@suse.de> /-*/ @@ -30,6 +29,7 @@ #include "YUISymbols.h" #include "YShortcut.h" #include "YWidget.h" +#include "YDialog.h" #include "YUIComponent.h" #include "YUI.h" #include "YDialog.h" @@ -37,26 +37,38 @@ #include "YChildrenManager.h" -using std::string; - #define MAX_DEBUG_LABEL_LEN 50 +#define YWIDGET_MAGIC 42 + + +using std::string; struct YWidgetPrivate { /** * Constructor **/ - YWidgetPrivate( YWidget * widget ) - : childrenRejector( widget ) - , childrenManager( childrenRejector ) + YWidgetPrivate( YWidgetChildrenManager * manager ) + : magic( YWIDGET_MAGIC ) + , childrenManager( manager ) + , parent( 0 ) + , beingDestroyed( false ) + , enabled( true ) + , notify( false ) + , toolkitWidgetRep( 0 ) {} // // Data members // - - YWidgetChildrenRejector childrenRejector; // default: no children - YWidgetChildrenManager & childrenManager; + + int magic; + YWidgetChildrenManager * childrenManager; + YWidget * parent; + bool beingDestroyed; + bool enabled; + bool notify; + void * toolkitWidgetRep; }; @@ -64,11 +76,8 @@ YWidget::YWidget( const YWidgetOpt & opt ) - : priv( new YWidgetPrivate( this ) ) - , magic( YWIDGET_MAGIC ) + : priv( new YWidgetPrivate( new YWidgetChildrenRejector( this ) ) ) , user_widget_id( YCPNull() ) - , yparent(0) - , rep(0) , windowID( -1 ) { internal_widget_id = next_internal_widget_id++; @@ -82,27 +91,27 @@ _weight[ YD_HORIZ ] = opt.hWeight.value(); _weight[ YD_VERT ] = opt.vWeight.value(); - if ( ! enabled ) setEnabling( false ); + if ( ! enabled ) setDisabled(); if ( notify ) setNotify( notify ); } YWidget::~YWidget() { - if ( ! isValid() ) - { - y2error( "ERROR: Trying to destroy invalid widget" ); - return; - } + YUI_CHECK_WIDGET( this ); + setBeingDestroyed(); - if ( yparent && yparent->isValid() ) - yparent->childDeleted( this ); + deleteChildren(); + if ( parent() && ! parent()->isBeingDestroyed() ) + parent()->removeChild( this ); + + delete priv->childrenManager; invalidate(); } -YChildrenManager & +YWidgetChildrenManager * YWidget::childrenManager() const { return priv->childrenManager; @@ -110,8 +119,11 @@ void -YWidget::setChildrenManager( YChildrenManager & newChildrenManager ) +YWidget::setChildrenManager( YWidgetChildrenManager * newChildrenManager ) { + YUI_CHECK_PTR( newChildrenManager ); + + delete priv->childrenManager; priv->childrenManager = newChildrenManager; } @@ -119,14 +131,29 @@ void YWidget::addChild( YWidget * child ) { - childrenManager().addChild( child ); + childrenManager()->add( child ); } void YWidget::removeChild( YWidget * child ) { - childrenManager().removeChild( child ); + childrenManager()->remove( child ); +} + + +void +YWidget::deleteChildren() +{ + for ( YWidgetList::const_iterator it = childrenBegin(); + it != childrenEnd(); + ++it ) + { + if ( (*it)->isValid() ) + delete *it; + } + + childrenManager()->clear(); } @@ -145,60 +172,62 @@ } -void YWidget::setId( const YCPValue & id ) +bool +YWidget::isValid() const { - user_widget_id = id; + return priv->magic == YWIDGET_MAGIC; } -bool YWidget::hasId() const +void +YWidget::invalidate() { - return ( ! user_widget_id.isNull() && ! user_widget_id->isVoid() ); + priv->magic = 0; } -YCPValue YWidget::id() const +bool +YWidget::isBeingDestroyed() const { - if ( ! isValid() ) - { - y2error( "YWidget::id(): Invalid widget" ); - return YCPString( "<invalid widget>" ); - } + return priv->beingDestroyed; +} - if ( user_widget_id.isNull() ) - return YCPVoid(); - else - return user_widget_id; +void +YWidget::setBeingDestroyed() +{ + priv->beingDestroyed = true; } -void YWidget::setParent( YWidget *parent ) +YWidget * +YWidget::parent() const { - yparent = parent; + return priv->parent; } -YWidget * YWidget::yParent() const +void +YWidget::setParent( YWidget * newParent ) { - return yparent; + priv->parent = newParent; } -YWidget * YWidget::yDialog() +YDialog * YWidget::findDialog() { - YWidget *parent = this; + YWidget * widget = this; - while ( parent && ! parent->isDialog() ) + while ( widget ) { - parent = parent->yParent(); - } + YDialog * dialog = dynamic_cast<YDialog *> (widget); - if ( ! parent ) - { - y2warning( "Warning: No dialog parent for %s", widgetClass() ); + if ( dialog ) + return dialog; + else + widget = widget->parent(); } - return parent; + return 0; } @@ -234,8 +263,8 @@ throw; } - if ( propertyName == YUIProperty_Enabled ) setEnabling( val.boolVal() ); - else if ( propertyName == YUIProperty_Notify ) setNotify ( val.boolVal() ); + if ( propertyName == YUIProperty_Enabled ) setEnabled( val.boolVal() ); + else if ( propertyName == YUIProperty_Notify ) setNotify ( val.boolVal() ); } @@ -252,115 +281,87 @@ throw; } - if ( propertyName == YUIProperty_Enabled ) return YPropertyValue( getEnabling() ); + if ( propertyName == YUIProperty_Enabled ) return YPropertyValue( isEnabled() ); 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() ); + if ( propertyName == YUIProperty_DialogDebugLabel ) + { + YDialog * dialog = findDialog(); + + if ( dialog ) + return YPropertyValue( dialog->debugLabel() ); + else + return YPropertyValue( debugLabel() ); + } return YPropertyValue( false ); // NOTREACHED } - -YCPValue YWidget::changeWidget( const YCPSymbol & property, const YCPValue & newvalue ) +void * +YWidget::widgetRep() const { - string symbol = property->symbol(); + return priv->toolkitWidgetRep; +} - if ( ! isValid() ) - { - y2error( "YWidget::changeWidget( %s ): ERROR: Invalid widget", symbol.c_str() ); - return YCPBoolean( false ); // Error - } +void +YWidget::setWidgetRep( void * rep ) +{ + priv->toolkitWidgetRep = rep; +} - /* - * @property boolean Enabled the current enabled/disabled state - */ - if ( symbol == YUIProperty_Enabled ) - { - if ( newvalue->isBoolean() ) - { - bool e = newvalue->asBoolean()->value(); - setEnabling(e); - enabled = e; - return YCPBoolean( true ); - } - else y2error( "Wrong argument %s for widget property `Enabled - boolean expected.", - newvalue->toString().c_str() ); - } - /* - * @property boolean Notify the current notify state (see also `opt( `notify )) - */ - if ( symbol == YUIProperty_Notify ) - { - if ( newvalue->isBoolean() ) - { - setNotify( newvalue->asBoolean()->value() ); - return YCPBoolean( true ); - } - else y2error( "Wrong argument %s for widget property `Notify - boolean expected.", - newvalue->toString().c_str() ); - } +void +YWidget::setEnabled( bool enabled ) +{ + priv->enabled = enabled; +} - return YCPBoolean( false ); + +bool +YWidget::isEnabled() const +{ + return priv->enabled; } -YCPValue YWidget::changeWidgetTerm( const YCPTerm & property, const YCPValue & newvalue ) +void YWidget::setShortcutString( const std::string & str ) { - y2warning( "Widget %s: Couldn't change unknown widget property %s to %s", - id()->toString().c_str(), property->toString().c_str(), newvalue->toString().c_str() ); - return YCPVoid(); + y2error( "Default setShortcutString() method called - " + "should be reimplemented in %s", widgetClass() ); } -YCPValue YWidget::queryWidget( const YCPSymbol & property ) + + + +void YWidget::setId( const YCPValue & id ) { - string symbol = property->symbol(); - if ( symbol == YUIProperty_Enabled ) return YCPBoolean( getEnabling() ); - if ( symbol == YUIProperty_Notify ) return YCPBoolean( getNotify() ); - if ( symbol == YUIProperty_WindowID ) return YCPInteger( windowID ); - /** - * @property string WidgetClass the widget class of this widget (YLabel, YPushButton, ...) - */ - if ( symbol == YUIProperty_WidgetClass ) return YCPString( widgetClass() ); - /** - * @property string DebugLabel a (possibly translated) text describing this widget for debugging - */ - if ( symbol == YUIProperty_DebugLabel ) return YCPString( debugLabel() ); - /** - * @property string DialogDebugLabel a (possibly translated) text describing this dialog for debugging - */ - if ( symbol == YUIProperty_DialogDebugLabel ) - { - return YUIComponent::ui()->currentDialog()->queryWidget( property ); - } - else - { - y2error( "Widget %s: Couldn't query unkown widget property %s", - id()->toString().c_str(), symbol.c_str() ); - return YCPVoid(); - } + user_widget_id = id; } -YCPValue YWidget::queryWidgetTerm( const YCPTerm & property ) +bool YWidget::hasId() const { - y2warning( "Widget %s: Couldn't query unkown widget property %s", - id()->toString().c_str(), property->toString().c_str() ); - return YCPVoid(); + return ( ! user_widget_id.isNull() && ! user_widget_id->isVoid() ); } -void YWidget::setShortcutString( const std::string & str ) +YCPValue YWidget::id() const { - y2error( "Default setShortcutString() method called - " - "should be reimplemented in %s", widgetClass() ); + YUI_CHECK_WIDGET( this ); + + if ( user_widget_id.isNull() ) + return YCPVoid(); + else + return user_widget_id; } + + void YWidget::setNotify( bool notify ) { this->notify = notify; @@ -373,12 +374,6 @@ } -bool YWidget::getEnabling() const -{ - return enabled; -} - - long YWidget::nicesize( YUIDimension dim ) { y2error( "YWidget::nicesize( YUIDimension dim ) called - " @@ -424,25 +419,6 @@ } -void YWidget::setEnabling( bool ) -{ - // Default implementation for widgets that can't be enabled - // or disabled -} - - -void *YWidget::widgetRep() -{ - return rep; -} - - -void YWidget::setWidgetRep( void *r ) -{ - rep = r; -} - - bool YWidget::isDialog() const { return false; @@ -487,3 +463,113 @@ */ } + + + + + + + + + + +// FIXME: Obsolete +// FIXME: Obsolete +// FIXME: Obsolete + + +YCPValue YWidget::changeWidget( const YCPSymbol & property, const YCPValue & newvalue ) +{ + string symbol = property->symbol(); + + if ( ! isValid() ) + { + y2error( "YWidget::changeWidget( %s ): ERROR: Invalid widget", symbol.c_str() ); + + return YCPBoolean( false ); // Error + } + + /* + * @property boolean Enabled the current enabled/disabled state + */ + if ( symbol == YUIProperty_Enabled ) + { + if ( newvalue->isBoolean() ) + { + bool e = newvalue->asBoolean()->value(); + setEnabled(e); + enabled = e; + return YCPBoolean( true ); + } + else y2error( "Wrong argument %s for widget property `Enabled - boolean expected.", + newvalue->toString().c_str() ); + } + + /* + * @property boolean Notify the current notify state (see also `opt( `notify )) + */ + if ( symbol == YUIProperty_Notify ) + { + if ( newvalue->isBoolean() ) + { + setNotify( newvalue->asBoolean()->value() ); + return YCPBoolean( true ); + } + else y2error( "Wrong argument %s for widget property `Notify - boolean expected.", + newvalue->toString().c_str() ); + } + + return YCPBoolean( false ); +} + + +YCPValue YWidget::changeWidgetTerm( const YCPTerm & property, const YCPValue & newvalue ) +{ + y2warning( "Widget %s: Couldn't change unknown widget property %s to %s", + id()->toString().c_str(), property->toString().c_str(), newvalue->toString().c_str() ); + return YCPVoid(); +} + + +YCPValue YWidget::queryWidget( const YCPSymbol & property ) +{ + string symbol = property->symbol(); + if ( symbol == YUIProperty_Enabled ) return YCPBoolean( isEnabled() ); + if ( symbol == YUIProperty_Notify ) return YCPBoolean( getNotify() ); + if ( symbol == YUIProperty_WindowID ) return YCPInteger( windowID ); + /** + * @property string WidgetClass the widget class of this widget (YLabel, YPushButton, ...) + */ + if ( symbol == YUIProperty_WidgetClass ) return YCPString( widgetClass() ); + /** + * @property string DebugLabel a (possibly translated) text describing this widget for debugging + */ + if ( symbol == YUIProperty_DebugLabel ) return YCPString( debugLabel() ); + /** + * @property string DialogDebugLabel a (possibly translated) text describing this dialog for debugging + */ + if ( symbol == YUIProperty_DialogDebugLabel ) + { + return YUIComponent::ui()->currentDialog()->queryWidget( property ); + } + else + { + y2error( "Widget %s: Couldn't query unkown widget property %s", + id()->toString().c_str(), symbol.c_str() ); + return YCPVoid(); + } +} + + +YCPValue YWidget::queryWidgetTerm( const YCPTerm & property ) +{ + y2warning( "Widget %s: Couldn't query unkown widget property %s", + id()->toString().c_str(), property->toString().c_str() ); + return YCPVoid(); +} + + +// FIXME: Obsolete +// FIXME: Obsolete +// FIXME: Obsolete + 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=38324&r1=38323&r2=38324&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h Wed Jun 6 16:55:02 2007 @@ -30,10 +30,10 @@ #include "YChildrenManager.h" #include "ImplPtr.h" -#define YWIDGET_MAGIC 42 // what else? ;- ) class YCPSymbol; class YMacroRecorder; +class YDialog; #define YUIAllDimensions 2 @@ -51,26 +51,27 @@ class YWidgetPrivate; + /** - * @short Abstract base class of all ui widgets + * Abstract base class of all UI widgets */ class YWidget { public: /** - * Constructor - */ + * Constructor. + **/ YWidget( const YWidgetOpt & opt ); /** * Destructor - */ + **/ virtual ~YWidget(); /** * Returns a descriptive name of this widget class for logging, * debugging etc. - */ + **/ virtual const char * widgetClass() { return "YWidget"; } /** @@ -176,31 +177,31 @@ * Returns 'true' if this widget has any children. **/ bool hasChildren() const - { return childrenManager().hasChildren(); } + { return childrenManager()->hasChildren(); } /** * Returns the first child or 0 if there is none. * Useful mostly for children managers that handle only one child. **/ YWidget * firstChild() const - { return childrenManager().firstChild(); } + { return childrenManager()->firstChild(); } /** * Return an iterator that points to the first child or to childrenEnd() if * there are no children. **/ YWidgetListConstIterator childrenBegin() const - { return childrenManager().begin(); } + { return childrenManager()->begin(); } /** * Returns the current number of children. **/ - int childrenCount() const { return childrenManager().count(); } + int childrenCount() const { return childrenManager()->count(); } /** * Return an interator that points after the last child. **/ YWidgetListConstIterator childrenEnd() const - { return childrenManager().end(); } + { return childrenManager()->end(); } /** * Add a new child. @@ -216,21 +217,86 @@ **/ virtual void removeChild( YWidget * child ); + /** + * Delete all children and remove them from the children manager's list. + **/ + void deleteChildren(); + + /** + * Return this widget's parent or 0 if it doesn't have a parent. + **/ + YWidget * parent() const; + + /** + * Set this widget's parent. + **/ + void setParent( YWidget * newParent ); + + /** + * Traverse up the widget hierarchy and find the dialog this widget belongs + * to. Returns 0 if there is none. + **/ + YDialog * findDialog(); + // // Misc // - /** * 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 ). + * dangling pointer error checking (i.e. this object is already + * deallocated, but a pointer to it is still in use). + * + * See also the YUI_CHECK_WIDGET() macro in YUIException.h + **/ + bool isValid() const; + + /** + * Check if this widget is in the process of being destroyed. + **/ + bool isBeingDestroyed() const; + + /** + * Return a pointer to the underlying toolkit's (Qt, ...) widget + * representing this abstract UI widget. + **/ + void *widgetRep() const; + + /** + * set the pointer to the underlying toolkit's (Qt, ...) widget + * representing this abstract UI widget. + **/ + void setWidgetRep( void * toolkitWidgetRep ); + + /** + * Enable or disable this widget, i.e. make it accept or reject user input. + * + * Derived classes should call the base class method to update the internal + *"enabled" flag. */ - bool isValid() const { return magic == YWIDGET_MAGIC; } + virtual void setEnabled( bool enabled = true ); /** + * Disable this widget (overloaded for better readability). + **/ + void setDisabled() { setEnabled( false); } + + /** + * Returns 'true' if this widget is enabled. + **/ + virtual bool isEnabled() const; + + + + + + + + + + /** * Return the widget serial number (the internal widget ID). */ int internalId() const { return internal_widget_id; } @@ -251,22 +317,6 @@ YCPValue id() const; /** - * Set the parent YWidget of this widget. - */ - void setParent( YWidget *parent ); - - /** - * Return the parent YWidget of this widget. - */ - YWidget * yParent() const; - - /** - * Return the YDialog this widget belongs to. - * Returns 0 if there is no dialog parent. - */ - YWidget * yDialog(); - - /** * Notify a widget that can have children that a child has been deleted. * This is called in the YWidget destructor for the parent widget. * All container widgets should overwrite this function and update @@ -372,17 +422,6 @@ virtual void setSize( long newwidth, long newheight ); /** - * Sets the enabled state of the widget. All new widgets are enabled per - * definition. Only enabled widgets can take user input. - */ - virtual void setEnabling( bool enabled ); - - /** - * Queries the enabled of a widget. - */ - bool getEnabling() const; - - /** * Sets the Notify property */ void setNotify( bool notify ); @@ -448,16 +487,6 @@ virtual YCPValue queryWidgetTerm( const YCPTerm & property ); /** - * Returns a pointer to the ui specific widget implementation. - */ - void *widgetRep(); - - /** - * Sets the pointer to the ui specific widget implementation. - */ - void setWidgetRep( void * ); - - /** * Set the keyboard focus to this widget. * The default implementation just emits a warning message. * Overwrite this function for all widgets that can accept the @@ -539,10 +568,12 @@ /** * Returns this widget's children manager. **/ - YWidgetChildrenManager & childrenManager() const; + YWidgetChildrenManager * childrenManager() const; /** - * Sets a new children manager for this widget. + * Sets a new children manager for this widget. The widget assumes + * ownership of this children manager and will delete it when appropriate. + * * The default children manager (a YWidgetChildrenRejector) rejects all * children. This is useful for leaf widgets such as PushButton, ComboBox * etc. @@ -552,7 +583,17 @@ * children) or to a YSingleWidgetChildManager (the class that handles * exactly one child widget). **/ - void setChildrenManager( YWidgetChildrenManager & manager ); + void setChildrenManager( YWidgetChildrenManager * manager ); + + /** + * Set the "being destroyed" flag, i.e. indicate that this widget is in the + * process of being destroyed. The base class method already sets this, but + * sometimes it might be useful to call this in a derived class's + * destructor so certain optimizations work better. + * + * This status intentionally cannot be reverted to "not being destroyed". + **/ + void setBeingDestroyed(); private: @@ -560,13 +601,24 @@ /** * Make this widget invalid. This operation cannot be reversed. */ - void invalidate() { magic=0; } + void invalidate(); + + +private: + + ImplPtr<YWidgetPrivate> priv; + static YPropertySet _propertySet; - /** - * This object is only valid if this magic number is - * YWIDGET_MAGIC. Use YWidget::isValid() to check this. - */ - int magic; + + + + + + + + + + protected: @@ -590,11 +642,6 @@ static int next_internal_widget_id; /** - * The parent YWidget. - */ - YWidget *yparent; - - /** * Flag: Can this widget currently receive user input? */ bool enabled; @@ -616,12 +663,6 @@ bool _autoShortcut; /** - * Pointer to the UI specific widget representation that belongs to this - * widget. For Qt, this will be a pointer to a QWidget (subclass). - **/ - void * rep; - - /** * Stretchability in both dimensions. */ bool _stretch [ YUIAllDimensions ]; @@ -637,11 +678,20 @@ long windowID; -private: - ImplPtr<YWidgetPrivate *> priv; - static YPropertySet _propertySet; + + + + + + + + + // FIXME: Get this stuff out of here - it is utterly out of place + // FIXME: Get this stuff out of here - it is utterly out of place + // FIXME: Get this stuff out of here - it is utterly out of place + public: /** * Helper class that calls startMultipleChanges() in its constructor -- 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