|
From: andrew7 <bd...@us...> - 2007-06-16 20:04:36
|
Update of /cvsroot/smartwin/SmartWin/tests/HelloSmartWin In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv12334 Modified Files: hello.cpp Log Message: Adjustments for wince. Index: hello.cpp =================================================================== RCS file: /cvsroot/smartwin/SmartWin/tests/HelloSmartWin/hello.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- hello.cpp 18 Feb 2007 01:01:33 -0000 1.26 +++ hello.cpp 16 Jun 2007 20:04:30 -0000 1.27 @@ -23,6 +23,77 @@ { SINGLE_WIDGETS = 0, MULTI_WIDGETS = 1 }; // Which of 2 tabbed pages + +#define tryIconButton 1 + +#ifdef tryIconButton + +// How to generate you own widgets derived from the existing Widgets +// +// Bitmap dogmap( _T("dog.bmp") ) ) +// +class IconButton + : public WidgetButton< IconButton, SmartWin::MessageMapPolicyNormalWidget > +{ +private: + BitmapPtr itsBgBitmap; + +public: + IconButton( Widget * parent, BitmapPtr bitmap ) + // Note! + // We MUST explicitly call Widget's Constructor since it's a diamond inheritence, at least until bjarne's C++0x gives us Constructor Forwarding... ;) + : Widget( parent ), itsBgBitmap( bitmap ), + WidgetButton< IconButton, SmartWin::MessageMapPolicyNormalWidget >( parent ) + { + } + + void paintBitmapButton( WidgetButton< IconButton, SmartWin::MessageMapPolicyNormalWidget > *btn, Canvas & canvas ) + { + Brush bitmapBrush( canvas, itsBgBitmap ); + sw::Rectangle rc( btn->getClientAreaSize() ); + canvas.fillRectangle( rc, bitmapBrush ); + canvas.setTextColor( RGB( 11, 0, 11 ) ); + canvas.setBkMode( true ); + boost::shared_ptr< Font > font( btn->getFont() ); + canvas.selectFont( font ); + canvas.drawText( btn->getText(), rc, DT_CENTER | DT_VCENTER ); + } + +/* + + // Creating bgImageButton + WidgetButton::Seed buttonCS; + + buttonCS.style |= BS_OWNERDRAW; + buttonCS.caption = _T( "Piip II!" ); + buttonCS.font = createFont( _T( "Comic Sans" ), 28, 8, 4, ANSI_CHARSET, false, false, false, 0, OUT_DEFAULT_PRECIS ); + itsImgButton = createButton( buttonCS ); + itsImgButton->onPainting( & Buttons::paintBitmapButton ); + +*/ + + + // Event handler for "click" event, maark the "funny" paramater... + void click( WidgetButton< IconButton, SmartWin::MessageMapPolicyNormalWidget > * btn ) + { + WidgetMessageBox< SmartWin::Widget > dlg( btn->getParent() ); + dlg.show( btn->getText() ); + } + + void init() + { + // Doing "init" stuff + create(); + onPainting( & IconButton::paintBitmapButton ); + } +}; + +#endif + + + + + // HelloWinClass defines a window with native controls based on the Win32 API. // // For our purposes, use this pattern for simple windows: @@ -66,7 +137,7 @@ // // By convention, we prefix all member variables with "its". // - WidgetButtonPtr itsButton; + WidgetButtonPtr itsButton; WidgetCheckBoxPtr itsCheckBox; WidgetComboBoxPtr itsComboBox; WidgetDataGridPtr itsGrid, itsList; @@ -80,6 +151,10 @@ WidgetTextBoxPtr itsTextA, itsTextB; WidgetTreeViewPtr itsTree; +#ifdef tryIconButton + IconButton * itsIconButton; +#endif + // The Widgets are organized on two child windows // which correspond to the two tabs of the WidgetTabSheet // @@ -123,9 +198,13 @@ // void menuChooseFont( WidgetMenuPtr menu, unsigned item ) { -#ifndef WINCE + FontPtr font; +#ifdef WINCE + font= createFont( _T( "Comic Sans" ), 8, 6 ); +#else WidgetChooseFont widget = createChooseFont(); // Built in dialog. - FontPtr font = widget.showDialog(); + font = widget.showDialog(); +#endif if ( font.get() != 0 ) { FontPtr choosenFont( font ); @@ -147,7 +226,6 @@ updateWidget(); // Redo everything with the new font. layout(); // to show how the new Font effects the layout. } -#endif } void menuCloseEvent( WidgetMenuPtr menu, unsigned item ) @@ -301,6 +379,11 @@ itsButton->setText( _T( "Display a message" ) ); itsButton->onClicked( & HelloWinClass::buttonClicked ); +#ifdef tryIconButton + itsIconButton; +#endif + + itsCheckBox = itsSingle->createCheckBox(); itsCheckBox->setText( _T( "&Check me" ) ); itsCheckBox->onClicked( & HelloWinClass::checkclicked ); @@ -425,7 +508,8 @@ itsColor = 0x808000; // Defaulting to yellow... itsEllipseSize = Point( 100, 100 ); - // Creating main menu + + // Creating main menu. itsMainMenu = createMenu(); WidgetMenuPtr file = itsMainMenu->appendPopup( _T( "&File" ) ); int m = 1; @@ -461,8 +545,9 @@ layout(); // for the first time, and only AFTER all Widgets are created. onSized( & HelloWinClass::isResized ); - // Since tab sheet will hide underlaying controls we need to position it at the BOTTOM of the Z-order window chain - ::SetWindowPos( itsTabSheet->handle(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); +#ifdef WINCE + itsTabSheet->bringToBottom(); // To prevent tab sheet from hiding its controls. +#endif updateWidget(); setVisible( true ); } @@ -485,6 +570,10 @@ { SmartWin::Rectangle r( getClientAreaSize() ); +#ifdef WINCE + r = r.cropTop( 24 ); // WinCe does not account for the menu in the client area +#endif + r = r.left( 1.0 - itsGraphicsPart ); // The non-graphics side. itsTabSheet->setBounds( r ); @@ -647,7 +736,7 @@ SmartWin::Rectangle texArea( area.row( r++, rows ) ); c.setBkColor( background ); - c.extTextOut( _T( "Hello Graphical World" ), texArea.pos.x, texArea.pos.y ); + c.extTextOut( _T( "Graphical Hello World" ), texArea.pos.x, texArea.pos.y ); SmartWin::Rectangle ellipseArea( area.row( r++, rows ) ); { @@ -663,7 +752,7 @@ c.line( area.row( r++, rows ) ); { TextPen purplepen( c, 0x800080 ); - c.drawText( _T( "Hello Purple World" ), area.row( r++, rows ), DT_SINGLELINE | DT_CENTER | DT_VCENTER ); + c.drawText( _T( "Purple Hello" ), area.row( r++, rows ), DT_SINGLELINE | DT_CENTER | DT_VCENTER ); } // purplepen is now out of scope, so we revert to old color. c.rectangle( area.row( r++, rows ) ); |