Author: sh-sh-sh
Date: Wed Mar 12 19:07:45 2008
New Revision: 45405
URL: http://svn.opensuse.org/viewcvs/yast?rev=45405&view=rev
Log:
simple and advanced example
Added:
trunk/libyui/examples/SelectionBox2.cc
Modified:
trunk/libyui/examples/ (props changed)
trunk/libyui/examples/Makefile.am
trunk/libyui/examples/SelectionBox1.cc
Modified: trunk/libyui/examples/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/examples/Makefile.am?rev=45405&r1=45404&r2=45405&view=diff
==============================================================================
--- trunk/libyui/examples/Makefile.am (original)
+++ trunk/libyui/examples/Makefile.am Wed Mar 12 19:07:45 2008
@@ -6,7 +6,8 @@
noinst_PROGRAMS = \
HelloWorld \
- SelectionBox1
+ SelectionBox1 \
+ SelectionBox2
HelloWorld_SOURCES = HelloWorld.cc
@@ -14,3 +15,6 @@
SelectionBox1_SOURCES = SelectionBox1.cc
SelectionBox1_LDADD = -L$(top_srcdir)/src -lyui
+
+SelectionBox2_SOURCES = SelectionBox2.cc
+SelectionBox2_LDADD = -L$(top_srcdir)/src -lyui
Modified: trunk/libyui/examples/SelectionBox1.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/examples/SelectionBox1.cc?rev=45405&r1=45404&r2=45405&view=diff
==============================================================================
--- trunk/libyui/examples/SelectionBox1.cc (original)
+++ trunk/libyui/examples/SelectionBox1.cc Wed Mar 12 19:07:45 2008
@@ -1,4 +1,4 @@
-// SelectionBox example.
+// Simple SelectionBox example.
//
// Compile with:
//
@@ -12,41 +12,12 @@
#include "YDialog.h"
#include "YLayoutBox.h"
#include "YSelectionBox.h"
-#include "YCheckBox.h"
#include "YLabel.h"
#include "YPushButton.h"
#include "YAlignment.h"
#include "YEvent.h"
-YItemCollection pizzaItems()
-{
- YItemCollection items;
- items.push_back( new YItem( "Pizza Margherita" ) );
- items.push_back( new YItem( "Pizza Capricciosa" ) );
- items.push_back( new YItem( "Pizza Funghi" ) );
- items.push_back( new YItem( "Pizza Prosciutto" ) );
- items.push_back( new YItem( "Pizza Quattro Stagioni" ) );
- items.push_back( new YItem( "Calzone" ) );
-
- return items;
-}
-
-
-YItemCollection pastaItems()
-{
- YItemCollection items;
- items.push_back( new YItem( "Spaghetti Napoli" ) );
- items.push_back( new YItem( "Spaghetti Bolognese" ) );
- items.push_back( new YItem( "Fusili Emiliana" ) );
- items.push_back( new YItem( "Penne Calabrese" ) );
- items.push_back( new YItem( "Penne Al Forno" ) );
- items.push_back( new YItem( "Lasagne" ) );
-
- return items;
-}
-
-
int main( int argc, char **argv )
{
@@ -57,36 +28,20 @@
YDialog * dialog = YUI::widgetFactory()->createPopupDialog();
YLayoutBox * vbox = YUI::widgetFactory()->createVBox( dialog );
- // Specify larger size for the SelectionBox: It can scroll, so its size
- // depends on other widgets in the layout.
- YAlignment * minSize = YUI::widgetFactory()->createMinSize( vbox, 40, 8 ); // minWidth, minHeight
-
- //
- // This is what this example all about.
- // The other widgets are here just to allow some experimenting.
- //
-
- YSelectionBox * selBox = YUI::widgetFactory()->createSelectionBox( minSize, "&Menu" );
- selBox->addItems( pizzaItems() );
+ YSelectionBox * selBox = YUI::widgetFactory()->createSelectionBox( vbox, "&Menu" );
- YLayoutBox * buttonBox = YUI::widgetFactory()->createHBox( vbox );
- YPushButton * pastaButton = YUI::widgetFactory()->createPushButton( buttonBox, "&Pasta" );
- YPushButton * pizzaButton = YUI::widgetFactory()->createPushButton( buttonBox, "Pi&zza" );
-
- YUI::widgetFactory()->createVSpacing( vbox, 0.5 );
-
- YAlignment * leftAlignment = YUI::widgetFactory()->createLeft( vbox );
- YCheckBox * notifyCheckBox = YUI::widgetFactory()->createCheckBox( leftAlignment, "&Notify Mode" );
- notifyCheckBox->setNotify();
-
- leftAlignment = YUI::widgetFactory()->createLeft( vbox );
- YCheckBox * immediateCheckBox = YUI::widgetFactory()->createCheckBox( leftAlignment, "&Immediate Mode" );
- immediateCheckBox->setNotify();
+ YItemCollection items;
+ items.push_back( new YItem( "Pizza Margherita" ) );
+ items.push_back( new YItem( "Pizza Capricciosa" ) );
+ items.push_back( new YItem( "Pizza Funghi" ) );
+ items.push_back( new YItem( "Pizza Prosciutto" ) );
+ items.push_back( new YItem( "Pizza Quattro Stagioni" ) );
+ items.push_back( new YItem( "Calzone" ) );
+ selBox->addItems( items ); // This is more efficient than repeatedly calling selBox->addItem()
- YUI::widgetFactory()->createVSpacing( vbox, 0.3 );
YLayoutBox * hbox = YUI::widgetFactory()->createHBox( vbox );
- YLabel * valueField = YUI::widgetFactory()->createOutputField( hbox, "???" );
+ YLabel * valueField = YUI::widgetFactory()->createOutputField( hbox, "<SelectionBox value unknown>" );
valueField->setStretchable( YD_HORIZ, true ); // allow stretching over entire dialog width
YPushButton * valueButton = YUI::widgetFactory()->createPushButton( hbox, "&Value" );
@@ -118,44 +73,9 @@
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() == notifyCheckBox )
- {
- bool notify = notifyCheckBox->isChecked();
-
- 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 );
- }
- else if ( widgetEvent->widget() == immediateCheckBox )
- {
- bool immediate = immediateCheckBox->isChecked();
- selBox->setImmediateMode( immediate );
-
- // immediateMode implicitly includes notify;
- // reflect this in the notify check box
-
- if ( immediate )
- notifyCheckBox->setChecked( true );
- }
- else if ( widgetEvent->widget() == selBox ||
- widgetEvent->widget() == valueButton )
+
+ if ( widgetEvent->widget() == valueButton ||
+ widgetEvent->widget() == selBox ) // selBox will only send events with setNotify()
{
YItem * item = selBox->selectedItem();
Added: trunk/libyui/examples/SelectionBox2.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/examples/SelectionBox2.cc?rev=45405&view=auto
==============================================================================
--- trunk/libyui/examples/SelectionBox2.cc (added)
+++ trunk/libyui/examples/SelectionBox2.cc Wed Mar 12 19:07:45 2008
@@ -0,0 +1,187 @@
+// Comprehensive SelectionBox example:
+//
+// Replacing items, notify and immediate modes.
+//
+// Compile with:
+//
+// g++ -I/usr/include/YaST2/yui -lyui SelectionBox2.cc -o SelectionBox2
+
+#define YUILogComponent "example"
+#include "YUILog.h"
+
+#include "YUI.h"
+#include "YWidgetFactory.h"
+#include "YDialog.h"
+#include "YLayoutBox.h"
+#include "YSelectionBox.h"
+#include "YCheckBox.h"
+#include "YLabel.h"
+#include "YPushButton.h"
+#include "YAlignment.h"
+#include "YEvent.h"
+
+
+YItemCollection pizzaItems()
+{
+ YItemCollection items;
+ items.push_back( new YItem( "Pizza Margherita" ) );
+ items.push_back( new YItem( "Pizza Capricciosa" ) );
+ items.push_back( new YItem( "Pizza Funghi" ) );
+ items.push_back( new YItem( "Pizza Prosciutto" ) );
+ items.push_back( new YItem( "Pizza Quattro Stagioni" ) );
+ items.push_back( new YItem( "Calzone" ) );
+
+ return items;
+}
+
+
+YItemCollection pastaItems()
+{
+ YItemCollection items;
+ items.push_back( new YItem( "Spaghetti Napoli" ) );
+ items.push_back( new YItem( "Spaghetti Bolognese" ) );
+ items.push_back( new YItem( "Fusili Emiliana" ) );
+ items.push_back( new YItem( "Penne Calabrese" ) );
+ items.push_back( new YItem( "Penne Al Forno" ) );
+ items.push_back( new YItem( "Lasagne" ) );
+
+ return items;
+}
+
+
+
+int main( int argc, char **argv )
+{
+ //
+ // Create and open dialog
+ //
+
+ YDialog * dialog = YUI::widgetFactory()->createPopupDialog();
+ YLayoutBox * vbox = YUI::widgetFactory()->createVBox( dialog );
+
+ // Specify larger size for the SelectionBox: It can scroll, so its size
+ // depends on other widgets in the layout.
+ YAlignment * minSize = YUI::widgetFactory()->createMinSize( vbox, 40, 8 ); // minWidth, minHeight
+
+ //
+ // This is what this example all about.
+ // The other widgets are here just to allow some experimenting.
+ //
+
+ YSelectionBox * selBox = YUI::widgetFactory()->createSelectionBox( minSize, "&Menu" );
+ selBox->addItems( pizzaItems() );
+
+ YLayoutBox * buttonBox = YUI::widgetFactory()->createHBox( vbox );
+ YPushButton * pastaButton = YUI::widgetFactory()->createPushButton( buttonBox, "&Pasta" );
+ YPushButton * pizzaButton = YUI::widgetFactory()->createPushButton( buttonBox, "Pi&zza" );
+
+ YUI::widgetFactory()->createVSpacing( vbox, 0.5 );
+
+ YAlignment * leftAlignment = YUI::widgetFactory()->createLeft( vbox );
+ YCheckBox * notifyCheckBox = YUI::widgetFactory()->createCheckBox( leftAlignment, "&Notify Mode" );
+ notifyCheckBox->setNotify();
+
+ leftAlignment = YUI::widgetFactory()->createLeft( vbox );
+ YCheckBox * immediateCheckBox = YUI::widgetFactory()->createCheckBox( leftAlignment, "&Immediate Mode" );
+ immediateCheckBox->setNotify();
+
+ YUI::widgetFactory()->createVSpacing( vbox, 0.3 );
+
+ YLayoutBox * hbox = YUI::widgetFactory()->createHBox( vbox );
+ YLabel * valueField = YUI::widgetFactory()->createOutputField( hbox, "???" );
+ valueField->setStretchable( YD_HORIZ, true ); // allow stretching over entire dialog width
+
+ YPushButton * valueButton = YUI::widgetFactory()->createPushButton( hbox, "&Value" );
+
+ YUI::widgetFactory()->createVSpacing( vbox, 0.7 );
+
+ YAlignment * rightAlignment = YUI::widgetFactory()->createRight( vbox );
+ YPushButton * closeButton = YUI::widgetFactory()->createPushButton( rightAlignment, "&Close" );
+
+
+ //
+ // Event loop
+ //
+
+ while ( true )
+ {
+ YEvent * event = dialog->waitForEvent();
+
+ if ( event )
+ {
+ if ( event->eventType() == YEvent::CancelEvent ) // window manager "close window" button
+ break; // leave event loop
+
+ YWidgetEvent * widgetEvent = dynamic_cast