|
From: andrew7 <bd...@us...> - 2007-02-18 15:07:26
|
Update of /cvsroot/smartwin/SmartWin/tests/WidgetStatic In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv18227/tests/WidgetStatic Modified Files: Main.cpp Log Message: Do an UpdateWidget after you change the color, and resizing won't give the multicolor effect. Index: Main.cpp =================================================================== RCS file: /cvsroot/smartwin/SmartWin/tests/WidgetStatic/Main.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- Main.cpp 23 Jun 2006 22:38:14 -0000 1.13 +++ Main.cpp 18 Feb 2007 15:07:22 -0000 1.14 @@ -4,8 +4,6 @@ \brief Unit test for WidgetStatic It tries to instantiate all different forms of WidgetStatic and it also tries to use all functions. - - TODO: If you resize quicly the window, the static control doesn't repaint completely ... */ #include "SmartWin.h" @@ -22,6 +20,11 @@ WidgetTest1() {} + void clicked( WidgetStaticPtr stat ) + { + setColors(); + } + void dblClicked( WidgetStaticPtr stat ) { createMessageBox().show( SmartUtil::tstring( _T( "Static Widget double clicked : " ) ) + stat->getText() ); @@ -47,36 +50,58 @@ createWindow( windowCS ); onTextChanging( & WidgetTest1::textChanged ); + onSized( & WidgetTest1::isResized ); + WidgetStatic::Seed staticCs; staticCs.caption = _T( "Initial text will be changed to test handler." ); staticCs.font = createFont( _T( "Times New Roman" ), 0, 10, 1, ANSI_CHARSET, true, false, false, 0, OUT_DEFAULT_PRECIS ); staticCs.location = SmartWin::Rectangle( getClientAreaSize() ).shrink( 50l ); - WidgetStaticPtr stat = createStatic( staticCs ); + stat = createStatic( staticCs ); srand( ( unsigned ) time( NULL ) ); stat->onBackgroundColor( & WidgetTest1::backgroundColor ); stat->onTextChanging( & WidgetTest1::textChanged ); stat->onDblClicked( & WidgetTest1::dblClicked ); + stat->onClicked( & WidgetTest1::clicked ); - stat->setText( _T( "Testing static control ... \nthe background and the font color will change...\nTry resizing the window quicly" ) ); + stat->setText( _T( "Click to change the background and the font color." ) ); //some compile tests and get/set symmetry test stat->setBounds( staticCs.location, false ); assert( stat->getBounds().pos == staticCs.location.pos && stat->getBounds().size == staticCs.location.size ); assert( stat->getPosition() == staticCs.location.pos ); assert( stat->getSize() == staticCs.location.size ); + + setColors(); } - BrushPtr bgBrush; + void isResized( const WidgetSizedEventResult & sz ) + { + + } + + void setColors() + { + itsBackgroundColor= RGB( rand()%255, rand()%255, rand()%255 ); + itsTextColor= RGB( rand()%255, rand()%255, rand()%255 ); + stat->updateWidget(); + } + boost::shared_ptr< sw::Brush > backgroundColor( WidgetStaticPtr stat, SmartWin::Canvas & canvas ) { - // tranparent background for text + // transparent background for text canvas.setBkMode( true ); - SetTextColor( canvas.getDc(), RGB( rand()%255, rand()%255, rand()%255 ) ); - bgBrush = boost::shared_ptr< sw::Brush >( new SmartWin::Brush( canvas, RGB( rand()%255, rand()%255, rand()%255 ) ) ); + SetTextColor( canvas.getDc(), itsTextColor ); + bgBrush = boost::shared_ptr< sw::Brush >( new SmartWin::Brush( canvas, itsBackgroundColor ) ); return bgBrush; } + +private: + WidgetStaticPtr stat; + COLORREF itsBackgroundColor, itsTextColor; + BrushPtr bgBrush; + }; int SmartWinMain( Application & app ) |