Author: sh-sh-sh Date: Wed Apr 16 12:29:19 2008 New Revision: 46706 URL: http://svn.opensuse.org/viewcvs/yast?rev=46706&view=rev Log: Events are now automatically deleted by YDialog Modified: trunk/libyui/VERSION trunk/libyui/examples/HelloWorld.cc trunk/libyui/examples/SelectionBox1.cc trunk/libyui/examples/SelectionBox2.cc trunk/libyui/package/yast2-libyui.changes trunk/libyui/src/YDialog.cc trunk/libyui/src/YDialog.h trunk/libyui/src/YEvent.cc trunk/libyui/src/YEvent.h trunk/libyui/src/YSimpleEventHandler.cc trunk/libyui/src/YSimpleEventHandler.h trunk/libyui/src/YUI.h trunk/ycp-ui-bindings/package/yast2-ycp-ui-bindings.changes trunk/ycp-ui-bindings/src/YCP_UI.cc trunk/ycp-ui-bindings/yast2-ycp-ui-bindings.spec.in Modified: trunk/libyui/VERSION URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/VERSION?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/libyui/VERSION (original) +++ trunk/libyui/VERSION Wed Apr 16 12:29:19 2008 @@ -1 +1 @@ -2.16.44 +2.16.45 Modified: trunk/libyui/examples/HelloWorld.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/examples/HelloWorld.cc?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/libyui/examples/HelloWorld.cc (original) +++ trunk/libyui/examples/HelloWorld.cc Wed Apr 16 12:29:19 2008 @@ -17,8 +17,6 @@ YUI::widgetFactory()->createLabel ( vbox, "Hello, World!" ); YUI::widgetFactory()->createPushButton( vbox, "&OK" ); - YEvent * event = dialog->waitForEvent(); - delete event; - + dialog->waitForEvent(); dialog->destroy(); } Modified: trunk/libyui/examples/SelectionBox1.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/examples/SelectionBox1.cc?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/libyui/examples/SelectionBox1.cc (original) +++ trunk/libyui/examples/SelectionBox1.cc Wed Apr 16 12:29:19 2008 @@ -83,14 +83,6 @@ else valueField->setValue( "<none>" ); } - - - // YDialog::waitForEvent() allocates a new YEvent and transfers - // ownership of the event to the caller, so the caller has to make - // sure the memory for the event is deallocated after use. - // Otherwise there will be a memory leak. - - delete event; } } Modified: trunk/libyui/examples/SelectionBox2.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/examples/SelectionBox2.cc?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/libyui/examples/SelectionBox2.cc (original) +++ trunk/libyui/examples/SelectionBox2.cc Wed Apr 16 12:29:19 2008 @@ -66,7 +66,7 @@ // depends on other widgets in the layout. YAlignment * minSize = YUI::widgetFactory()->createMinSize( vbox, 40, 8 ); // minWidth, minHeight - + // The SelectionBox. This is what this example all about. // The other widgets are just here to allow some experimenting. @@ -84,7 +84,7 @@ YUI::widgetFactory()->createVSpacing( vbox, 0.5 ); - + // Check boxes to allow toogling "notify" and "immediate" for the SelectionBox YAlignment * leftAlignment = YUI::widgetFactory()->createLeft( vbox ); @@ -109,7 +109,7 @@ YUI::widgetFactory()->createVSpacing( vbox, 0.7 ); - + // "Close" button YAlignment * rightAlignment = YUI::widgetFactory()->createRight( vbox ); @@ -188,14 +188,6 @@ valueField->setValue( "<none>" ); } } - - - // YDialog::waitForEvent() allocates a new YEvent and transfers - // ownership of the event to the caller, so the caller has to make - // sure the memory for the event is deallocated after use. - // Otherwise there will be a memory leak. - - delete event; } Modified: trunk/libyui/package/yast2-libyui.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/package/yast2-libyui.changes?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/libyui/package/yast2-libyui.changes (original) +++ trunk/libyui/package/yast2-libyui.changes Wed Apr 16 12:29:19 2008 @@ -1,4 +1,11 @@ ------------------------------------------------------------------- +Wed Apr 16 12:24:44 CEST 2008 - sh@suse.de + +- Deleting events is now automatically handled by YDialog. + Simply remove all "delete event" calls. +- V 2.16.45 + +------------------------------------------------------------------- Mon Apr 14 16:38:12 CEST 2008 - sh@suse.de - Added dialog type YWizardDialog for main dialogs that will Modified: trunk/libyui/src/YDialog.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YDialog.cc?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/libyui/src/YDialog.cc (original) +++ trunk/libyui/src/YDialog.cc Wed Apr 16 12:29:19 2008 @@ -21,6 +21,7 @@ #include "YUILog.h" #include "YDialog.h" +#include "YEvent.h" #include "YShortcutManager.h" #include "YPushButton.h" @@ -48,6 +49,7 @@ , shortcutCheckPostponed( false ) , defaultButton( 0 ) , isOpen( false ) + , lastEvent( 0 ) {} YDialogType dialogType; @@ -55,6 +57,7 @@ bool shortcutCheckPostponed; YPushButton * defaultButton; bool isOpen; + YEvent * lastEvent; }; @@ -79,6 +82,9 @@ yuiDebug() << "Destroying " << this << endl; #endif + if ( priv->lastEvent ) + deleteEvent( priv->lastEvent ); + if ( ! _dialogStack.empty() && _dialogStack.top() == this ) { _dialogStack.pop(); @@ -163,7 +169,7 @@ case YPopupDialog: return false; // Intentionally omitting the 'default' case so the compiler can - // catch unhandled enum values + // catch unhandled enum values } /*NOTREACHED*/ @@ -272,6 +278,9 @@ checkShortcuts( true ); } + if ( priv->lastEvent ) + deleteEvent( priv->lastEvent ); + YEvent * event = 0; do @@ -308,7 +317,7 @@ // Don't return the event from this help button - // get back into event loop - delete event; + deleteEvent( event ); event = 0; yuiMilestone() << "Help dialog closed" << endl; @@ -369,7 +378,7 @@ // yuiDebug() << "Discarding event for widget that has become invalid" << endl; - delete widgetEvent; + deleteEvent( widgetEvent ); return 0; } @@ -401,7 +410,7 @@ activate(); // try to force this dialog to the foreground - delete widgetEvent; + deleteEvent( widgetEvent ); return 0; } @@ -411,6 +420,18 @@ } +void +YDialog::deleteEvent( YEvent * event ) +{ + if ( event == priv->lastEvent ) + priv->lastEvent = 0; + + if ( event ) + delete event; +} + + + @@ -496,10 +517,7 @@ YPushButton * okButton = YUI::widgetFactory()->createPushButton( vbox, "&OK" ); okButton->setDefaultButton(); - YEvent * event = dialog->waitForEvent(); - - if ( event ) - delete event; + dialog->waitForEvent(); dialog->destroy(); } catch ( YUIException exception ) Modified: trunk/libyui/src/YDialog.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YDialog.h?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/libyui/src/YDialog.h (original) +++ trunk/libyui/src/YDialog.h Wed Apr 16 12:29:19 2008 @@ -21,12 +21,12 @@ #define YDialog_h #include "YSingleChildContainerWidget.h" -#include "YEvent.h" #include <stack> class YShortcutManager; class YPushButton; class YDialogPrivate; +class YEvent; // See YTypes.h for enum YDialogType and enum YDialogColorMode @@ -92,8 +92,10 @@ * If open() has not been called for this dialog until now, * it is called now. * - * Ownership of the event is transferred to the caller, i.e. the caller is - * responsible for deleting it after use. + * The dialog retains ownership of the event and will delete it upon the + * next call to waitForEvent() or pollEvent() or when the dialog is + * deleted. This also means that the return value of this function can + * safely be ignored without fear of memory leaks. * * If this dialog is not the topmost dialog, an exception is thrown. **/ @@ -106,11 +108,13 @@ * If open() has not been called for this dialog until now, * it is called now. * - * Ownership of the event is transferred to the caller, i.e. the caller is - * responsible for deleting it after use. + * The dialog retains ownership of the event and will delete it upon the + * next call to waitForEvent() or pollEvent() or when the dialog is + * deleted. This also means that the return value of this function can + * safely be ignored without fear of memory leaks. * * If this dialog is not the topmost dialog, an exception is thrown. - **/ + **/ YEvent * pollEvent(); /** @@ -204,7 +208,7 @@ /** * Return 'true' if this dialog is a dialog of main dialog size: - * YMainDialog or YWizardDialog. + * YMainDialog or YWizardDialog. **/ bool isMainDialog(); @@ -243,6 +247,11 @@ YPushButton * defaultButton() const; /** + * Delete an event. + **/ + void deleteEvent( YEvent * event ); + + /** * Set this dialog's default button (the button that is activated when * the user hits [Return] anywhere in this dialog). 0 means no default * button. @@ -287,7 +296,7 @@ * Derived classes are required to implement this. **/ virtual YEvent * waitForEventInternal( int timeout_millisec ) = 0; - + /** * Check if a user event is pending. If there is one, return it. * If there is none, do not wait for one - return 0. Modified: trunk/libyui/src/YEvent.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YEvent.cc?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/libyui/src/YEvent.cc (original) +++ trunk/libyui/src/YEvent.cc Wed Apr 16 12:29:19 2008 @@ -23,6 +23,7 @@ #include "YWidget.h" #include "YEvent.h" +#include "YDialog.h" using std::string; @@ -34,6 +35,7 @@ YEvent::YEvent( EventType eventType ) : _eventType( eventType ) { + _dialog = YDialog::currentDialog( false ); // don't throw _serial = _nextSerial++; if ( ++_activeEvents > 3 ) @@ -102,6 +104,8 @@ , _widget( widget ) , _reason( reason ) { + if ( widget ) + setDialog( widget->findDialog() ); } Modified: trunk/libyui/src/YEvent.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YEvent.h?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/libyui/src/YEvent.h (original) +++ trunk/libyui/src/YEvent.h Wed Apr 16 12:29:19 2008 @@ -21,10 +21,13 @@ #include <string> +#include "YDialog.h" +#include "YSimpleEventHandler.h" using std::string; class YWidget; class YItem; +class YDialog; /** @@ -63,12 +66,6 @@ YEvent( EventType eventType = UnknownEvent ); /** - * Virtual desctructor to force a polymorph object - * so dynamic_cast<> can be used. - **/ - virtual ~YEvent(); - - /** * Returns the event type. **/ EventType eventType() const { return _eventType; } @@ -95,7 +92,11 @@ **/ virtual YItem * item() const { return 0; } - + /** + * Return the dialog this event belongs to or 0 if no dialog was set yet. + **/ + YDialog * dialog() const { return _dialog; } + /** * Returns the character representation of an event type. **/ @@ -108,9 +109,35 @@ protected: + + /** + * Set the dialog this event belongs to. + **/ + void setDialog( YDialog * dia ) { _dialog = dia; } + + /** + * Protected destructor - events can only be deleted via + * YDialog::deleteEvent(). The associated dialog will take care of this + * event and delete it when appropriate. + * + * This desctructor is virtual to force a polymorph object + * so dynamic_cast<> can be used. + **/ + virtual ~YEvent(); + +private: + + friend void YDialog::deleteEvent( YEvent * event ); + friend void YSimpleEventHandler::deleteEvent( YEvent * event ); + + + // + // Data members + // EventType _eventType; unsigned long _serial; + YDialog * _dialog; static unsigned long _nextSerial; static int _activeEvents; @@ -142,6 +169,18 @@ protected: + /** + * Protected destructor - events can only be deleted via + * YDialog::deleteEvent(). The associated dialog will take care of this + * event and delete it when appropriate. + **/ + virtual ~YWidgetEvent() {} + + + // + // Data members + // + YWidget * _widget; EventReason _reason; }; @@ -176,6 +215,18 @@ YWidget * focusWidget() const { return _focusWidget; } protected: + + /** + * Protected destructor - events can only be deleted via + * YDialog::deleteEvent(). The associated dialog will take care of this + * event and delete it when appropriate. + **/ + virtual ~YKeyEvent() {} + + + // + // Data members + // string _keySymbol; YWidget * _focusWidget; @@ -212,6 +263,18 @@ string id() const { return _id; } protected: + + /** + * Protected destructor - events can only be deleted via + * YDialog::deleteEvent(). The associated dialog will take care of this + * event and delete it when appropriate. + **/ + virtual ~YMenuEvent() {} + + + // + // Data members + // YItem * _item; string _id; @@ -227,6 +290,15 @@ public: YCancelEvent() : YEvent( CancelEvent ) {} + + +protected: + /** + * Protected destructor - events can only be deleted via + * YDialog::deleteEvent(). The associated dialog will take care of this + * event and delete it when appropriate. + **/ + virtual ~YCancelEvent() {} }; @@ -239,6 +311,14 @@ public: YDebugEvent() : YEvent( DebugEvent ) {} + +protected: + /** + * Protected destructor - events can only be deleted via + * YDialog::deleteEvent(). The associated dialog will take care of this + * event and delete it when appropriate. + **/ + virtual ~YDebugEvent() {} }; @@ -251,6 +331,14 @@ public: YTimeoutEvent() : YEvent( TimeoutEvent ) {} + +protected: + /** + * Protected destructor - events can only be deleted via + * YDialog::deleteEvent(). The associated dialog will take care of this + * event and delete it when appropriate. + **/ + virtual ~YTimeoutEvent() {} }; Modified: trunk/libyui/src/YSimpleEventHandler.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YSimpleEventHandler.cc?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/libyui/src/YSimpleEventHandler.cc (original) +++ trunk/libyui/src/YSimpleEventHandler.cc Wed Apr 16 12:29:19 2008 @@ -50,7 +50,7 @@ #if VERBOSE_EVENTS yuiDebug() << "Clearing pending event: " << YEvent::toString( _pendingEvent->eventType() ) << endl; #endif - delete _pendingEvent; + deleteEvent( _pendingEvent ); } } @@ -79,7 +79,7 @@ #endif // Avoid memory leak: The event handler assumes ownership of the newly // created event, so we have to clean it up here. - delete event; + deleteEvent( event ); return; } @@ -96,7 +96,7 @@ * processed) by the generic UI. **/ - delete _pendingEvent; + deleteEvent( _pendingEvent ); } #if VERBOSE_EVENTS @@ -128,3 +128,13 @@ _eventsBlocked = block; } + + +void YSimpleEventHandler::deleteEvent( YEvent * event ) +{ + if ( event == _pendingEvent ) + _pendingEvent = 0; + + if ( event ) + delete event; +} Modified: trunk/libyui/src/YSimpleEventHandler.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YSimpleEventHandler.h?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/libyui/src/YSimpleEventHandler.h (original) +++ trunk/libyui/src/YSimpleEventHandler.h Wed Apr 16 12:29:19 2008 @@ -108,6 +108,12 @@ **/ bool eventsBlocked() const { return _eventsBlocked; } + /** + * Delete an event. Don't call this from the outside; this is public only + * because of limitations of C++ . + **/ + void deleteEvent( YEvent * event ); + protected: Modified: trunk/libyui/src/YUI.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YUI.h?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/libyui/src/YUI.h (original) +++ trunk/libyui/src/YUI.h Wed Apr 16 12:29:19 2008 @@ -205,6 +205,11 @@ * UI-specific runPkgSelection method. * * Derived classes are required to implement this. + * + * The packageSelector's dialog will take care of the event and delete it + * when appropriate. The returned pointer is valid until the next call to + * YDialog::userInput(), YDialog::pollInput(), or YUI::runPkgSelection() or + * until the dialog with the packageSelector is destroyed. **/ virtual YEvent * runPkgSelection( YWidget * packageSelector ) = 0; Modified: trunk/ycp-ui-bindings/package/yast2-ycp-ui-bindings.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/ycp-ui-bindings/package/yast2-ycp-ui-bindings.changes?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/ycp-ui-bindings/package/yast2-ycp-ui-bindings.changes (original) +++ trunk/ycp-ui-bindings/package/yast2-ycp-ui-bindings.changes Wed Apr 16 12:29:19 2008 @@ -1,4 +1,10 @@ ------------------------------------------------------------------- +Wed Apr 16 12:27:51 CEST 2008 - sh@suse.de + +- Let YDialog take care of deleting events +- V 2.16.45 + +------------------------------------------------------------------- Mon Apr 14 16:39:51 CEST 2008 - sh@suse.de - Added `opt(`wizardDialog) to UI::OpenDialog(): Modified: trunk/ycp-ui-bindings/src/YCP_UI.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ycp-ui-bindings/src/YCP_UI.cc?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/ycp-ui-bindings/src/YCP_UI.cc (original) +++ trunk/ycp-ui-bindings/src/YCP_UI.cc Wed Apr 16 12:29:19 2008 @@ -477,15 +477,6 @@ YUI_RETHROW( exception ); } - // Clean up. - // - // The generic UI interpreter assumes ownership of events delivered by - // userInput() / pollInput(), so now (after it is processed) is the time to - // delete that event. - - if ( event ) - delete event; - return input; } @@ -1404,8 +1395,6 @@ result = YCPSymbol( result->asString()->value() ); // "accept" -> `accept yuiMilestone() << "Package selection done. Returning with " << result << endl; - - delete event; } } catch ( YUIException & exception ) Modified: trunk/ycp-ui-bindings/yast2-ycp-ui-bindings.spec.in URL: http://svn.opensuse.org/viewcvs/yast/trunk/ycp-ui-bindings/yast2-ycp-ui-bindings.spec.in?rev=46706&r1=46705&r2=46706&view=diff ============================================================================== --- trunk/ycp-ui-bindings/yast2-ycp-ui-bindings.spec.in (original) +++ trunk/ycp-ui-bindings/yast2-ycp-ui-bindings.spec.in Wed Apr 16 12:29:19 2008 @@ -19,8 +19,8 @@ # libycp includes crypto built-ins BuildRequires: libxcrypt-devel -Requires: yast2-libyui >= 2.16.44 -BuildRequires: yast2-libyui-devel >= 2.16.44 +Requires: yast2-libyui >= 2.16.45 +BuildRequires: yast2-libyui-devel >= 2.16.45 # libyui ImplPtr BuildRequires: boost-devel -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org