Mailinglist Archive: yast-commit (759 mails)

< Previous Next >
[yast-commit] r45664 - in /trunk/libyui: examples/SelectionBox2.cc src/YEvent.h
  • From: sh-sh-sh@xxxxxxxxxxxxxxxx
  • Date: Thu, 20 Mar 2008 19:15:41 -0000
  • Message-id: <20080320191541.E597B34C27@xxxxxxxxxxxxxxxx>
Author: sh-sh-sh
Date: Thu Mar 20 20:15:41 2008
New Revision: 45664

URL: http://svn.opensuse.org/viewcvs/yast?rev=45664&view=rev
Log:
simpler handling for common event usage

Modified:
trunk/libyui/examples/SelectionBox2.cc
trunk/libyui/src/YEvent.h

Modified: trunk/libyui/examples/SelectionBox2.cc
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/libyui/examples/SelectionBox2.cc?rev=45664&r1=45663&r2=45664&view=diff
==============================================================================
--- trunk/libyui/examples/SelectionBox2.cc (original)
+++ trunk/libyui/examples/SelectionBox2.cc Thu Mar 20 20:15:41 2008
@@ -129,78 +129,73 @@
if ( event->eventType() == YEvent::CancelEvent ) // window manager
"close window" button
break; // leave event loop

- YWidgetEvent * widgetEvent = dynamic_cast<YWidgetEvent *> (event);
+ valueField->setValue( "???" );

- if ( widgetEvent )
+ if ( event->widget() == closeButton )
+ break; // leave event loop
+ else if ( event->widget() == pastaButton )
+ {
+ selBox->deleteAllItems();
+ selBox->addItems( pastaItems() );
+ }
+ else if ( event->widget() == pizzaButton )
+ {
+ selBox->deleteAllItems();
+ selBox->addItems( pizzaItems() );
+ }
+ else if ( event->widget() == clearButton )
+ {
+ selBox->deleteAllItems();
+ }
+ else if ( event->widget() == deselectButton )
{
- valueField->setValue( "???" );
+ selBox->deselectAllItems();
+ }
+ else if ( event->widget() == notifyCheckBox )
+ {
+ bool notify = notifyCheckBox->isChecked();

- if ( widgetEvent->widget() == closeButton )
- break; // leave event loop
- else if ( widgetEvent->widget() == pastaButton )
- {
- selBox->deleteAllItems();
- selBox->addItems( pastaItems() );
- }
- else if ( widgetEvent->widget() == pizzaButton )
- {
- selBox->deleteAllItems();
- selBox->addItems( pizzaItems() );
- }
- else if ( widgetEvent->widget() == clearButton )
- {
- selBox->deleteAllItems();
- }
- else if ( widgetEvent->widget() == deselectButton )
+ if ( ! notify )
{
- selBox->deselectAllItems();
- }
- else if ( widgetEvent->widget() == notifyCheckBox )
- {
- bool notify = notifyCheckBox->isChecked();
+ // immediateMode implicitly includes notify, so set
+ // immediateMode off if the user wants to set notify off

- if ( ! notify )
- {
- // immediateMode implicitly includes notify, so set
- // immediateMode off if the user wants to set notify off
-
- selBox->setImmediateMode( false );
- immediateCheckBox->setChecked( false );
- }
-
- selBox->setNotify( notify );
+ selBox->setImmediateMode( false );
+ immediateCheckBox->setChecked( false );
}
- else if ( widgetEvent->widget() == immediateCheckBox )
- {
- bool immediate = immediateCheckBox->isChecked();
- selBox->setImmediateMode( immediate );

- // immediateMode implicitly includes notify;
- // reflect this in the notify check box
+ selBox->setNotify( notify );
+ }
+ else if ( event->widget() == immediateCheckBox )
+ {
+ bool immediate = immediateCheckBox->isChecked();
+ selBox->setImmediateMode( immediate );

- if ( immediate )
- notifyCheckBox->setChecked( true );
- }
- else if ( widgetEvent->widget() == selBox ||
- widgetEvent->widget() == valueButton )
- {
- YItem * item = selBox->selectedItem();
+ // immediateMode implicitly includes notify;
+ // reflect this in the notify check box

- if ( item )
- valueField->setValue( item->label() );
- else
- valueField->setValue( "<none>" );
- }
+ if ( immediate )
+ notifyCheckBox->setChecked( true );
}
+ else if ( event->widget() == selBox ||
+ event->widget() == valueButton )
+ {
+ YItem * item = selBox->selectedItem();

+ if ( item )
+ valueField->setValue( item->label() );
+ 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;
- }
+ // 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/src/YEvent.h
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YEvent.h?rev=45664&r1=45663&r2=45664&view=diff
==============================================================================
--- trunk/libyui/src/YEvent.h (original)
+++ trunk/libyui/src/YEvent.h Thu Mar 20 20:15:41 2008
@@ -80,6 +80,23 @@
unsigned long serial() const { return _serial; }

/**
+ * Returns the widget that caused this event or 0 if there is none.
+ *
+ * This default implementation always returns 0.
+ * Subclasses that actually return widgets should overwrite this method.
+ **/
+ virtual YWidget * widget() const { return 0; }
+
+ /**
+ * Return the YItem that corresponds to this event or 0 if there is none.
+ *
+ * This default implementation always returns 0.
+ * Subclasses that actually return items should overwrite this method.
+ **/
+ virtual YItem * item() const { return 0; }
+
+
+ /**
* Returns the character representation of an event type.
**/
static const char * toString( EventType eventType );
@@ -113,10 +130,10 @@
EventType eventType = WidgetEvent );

/**
- * Returns the widget that caused this event. This might as well be 0 if
- * this is not a widget event.
+ * Returns the widget that caused this event.
+ * Reimplemented from YEvent.
**/
- YWidget * widget() const { return _widget; }
+ virtual YWidget * widget() const { return _widget; }

/**
* Returns the reason for this event. This very much like an event
sub-type.
@@ -183,8 +200,10 @@
/**
* Return the YItem that corresponds to this event or 0 if the event was
* constructed with a string ID.
+ *
+ * Reimplemented from YEvent.
**/
- YItem * item() const { return _item; }
+ virtual YItem * item() const { return _item; }

/**
* Return the string ID of this event. This will be an empty string if the

--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages