home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- * DLGDEMO.CXX
- * (c) 1992-1994 STAR DIVISION
- *******************************************************************/
-
- #include <sv.hxx>
-
- #include "dlgdemo.hrc"
-
- class ShapeDialog;
-
- // --- class ShowShape ---------------------------------------------
-
- enum Shape { SHAPE_RECT, SHAPE_ELLIPSE };
-
- class ShapeView : public Control
- {
- private:
- Shape eShape;
- Color aColor;
-
- public:
- ShapeView( Window* pParent );
- ShapeView( Window* pParent,
- const ResId& rResId );
-
- virtual void Paint( const Rectangle& rRect );
- virtual void Resize();
-
- Shape ChangeShape( Shape eNewShape );
- Shape GetShape() const { return eShape; }
- Color ChangeColor( const Color& rNewColor );
- Color GetColor() const { return aColor; }
- };
-
- // --- ShapeView::ShapeView() --------------------------------------
-
- ShapeView::ShapeView( Window* pParent ) :
- Control( pParent ),
- eShape( SHAPE_ELLIPSE ),
- aColor( COL_CYAN )
- {
- ChangeFillInBrush( Brush( aColor ) );
- }
-
- // --- ShapeView::ShapeView() --------------------------------------
-
- ShapeView::ShapeView( Window* pParent, const ResId& rResId ) :
- Control( pParent, rResId ),
- eShape( SHAPE_ELLIPSE ),
- aColor( COL_CYAN )
- {
- ChangeFillInBrush( Brush( aColor ) );
- }
-
- // --- ShapeView::Paint() ------------------------------------------
-
- void ShapeView::Paint( const Rectangle& )
- {
- if ( eShape == SHAPE_RECT )
- DrawRect( Rectangle( Point(), GetOutputSize() ) );
- else
- DrawEllipse( Rectangle( Point(), GetOutputSize() ) );
- }
-
- // --- ShapeView::Resize() -----------------------------------------
-
- void ShapeView::Resize()
- {
- Invalidate();
- }
-
- // --- ShapeView::ChangeShape() ------------------------------------
-
- Shape ShapeView::ChangeShape( Shape eNewShape )
- {
- Shape eOldShape = eShape;
- eShape = eNewShape;
- Invalidate();
- return eOldShape;
- }
-
- // --- ShapeView::ChangeColor() ------------------------------------
-
- Color ShapeView::ChangeColor( const Color& rNewColor )
- {
- Color aOldColor = aColor;
- aColor = rNewColor;
- ChangeFillInBrush( Brush( aColor ) );
- Invalidate();
- return aOldColor;
- }
-
- // --- class ShapeButton -------------------------------------------
-
- class ShapeButton : public RadioButton
- {
- private:
- Shape eShape;
-
- public:
- ShapeButton( ShapeDialog* pParent,
- const ResId& rResId,
- Shape eShape );
-
- Shape GetShape() const { return eShape; }
- };
-
- // --- class ColorButton -------------------------------------------
-
- class ColorButton : public RadioButton
- {
- private:
- Color aColor;
-
- public:
- ColorButton( ShapeDialog* pParent,
- const ResId& rResId,
- const Color& rColor );
-
- Color GetColor() const { return aColor; }
- };
-
- // --- class ShapeDialog -------------------------------------------
-
- class ShapeDialog : public ModalDialog
- {
- private:
- ColorButton aBlackButton;
- ColorButton aBlueButton;
- ColorButton aGreenButton;
- ColorButton aCyanButton;
- ColorButton aRedButton;
- ColorButton aMagentaButton;
- ColorButton aYellowButton;
- ColorButton aWhiteButton;
- GroupBox aColorGroup;
- ShapeView aShapeView;
- ShapeButton aRectangleButton;
- ShapeButton aEllipseButton;
- GroupBox aShapeGroup;
- OKButton aOKButton;
- CancelButton aCancelButton;
-
- public:
- ShapeDialog( Window* pWindow );
-
- void ShapeHdl( ShapeButton* pShapeButton );
- void SetShape( Shape eNewShape );
- Shape GetShape() const
- { return aShapeView.GetShape(); }
-
- void ColorHdl( ColorButton* pColorButton );
- void SetColor( const Color& rNewColor );
- Color GetColor() const
- { return aShapeView.GetColor(); }
- };
-
- // --- ShapeButton::ShapeButton() ----------------------------------
-
- ShapeButton::ShapeButton( ShapeDialog* pParent,
- const ResId& rResId,
- Shape eShape ) :
- RadioButton( pParent, rResId )
- {
- ShapeButton::eShape = eShape;
- ChangeClickHdl( LINK( pParent, ShapeDialog, ShapeHdl ) );
- }
-
- // --- ColorButton::ColorButton() ----------------------------------
-
- ColorButton::ColorButton( ShapeDialog* pParent,
- const ResId& rResId,
- const Color& rColor ) :
- RadioButton( pParent, rResId ),
- aColor( rColor )
- {
- ChangeClickHdl( LINK( pParent, ShapeDialog, ColorHdl ) );
- }
-
- // --- ShapeDialog::ShapeDialog() ----------------------------------
-
- ShapeDialog::ShapeDialog( Window* pWindow ) :
- ModalDialog( pWindow, ResId( DLG_SHAPE ) ),
- aBlackButton( this, ResId( DLG_BLACK ),
- Color( (ColorName)COL_BLACK ) ),
- aBlueButton( this, ResId( DLG_BLUE ),
- Color( (ColorName)COL_BLUE ) ),
- aGreenButton( this, ResId( DLG_GREEN ),
- Color( (ColorName)COL_GREEN ) ),
- aCyanButton( this, ResId( DLG_CYAN ),
- Color( (ColorName)COL_CYAN ) ),
- aRedButton( this, ResId( DLG_RED ),
- Color( (ColorName)COL_RED ) ),
- aMagentaButton( this, ResId( DLG_MAGENTA ),
- Color((ColorName)COL_MAGENTA )),
- aYellowButton( this, ResId( DLG_YELLOW ),
- Color( (ColorName)COL_YELLOW ) ),
- aWhiteButton( this, ResId( DLG_WHITE ),
- Color( (ColorName)COL_WHITE ) ),
- aColorGroup( this, ResId( DLG_GB1 ) ),
- aShapeView( this, ResId( DLG_VIEW ) ),
- aRectangleButton( this, ResId( DLG_RECT ),
- SHAPE_RECT ),
- aEllipseButton( this, ResId( DLG_ELL ),
- SHAPE_ELLIPSE ),
- aShapeGroup( this, ResId( DLG_GB2 ) ),
- aOKButton( this, ResId( DLG_OK ) ),
- aCancelButton( this, ResId( DLG_CANCEL ) )
- {
- FreeResource();
- }
-
- // --- ShapeDialog::ShapeHdl() -------------------------------------
-
- void ShapeDialog::ShapeHdl( ShapeButton* pShapeButton )
- {
- aShapeView.ChangeShape( pShapeButton->GetShape() );
- }
-
- // --- ShapeDialog::SetShape() -------------------------------------
-
- void ShapeDialog::SetShape( Shape eNewShape )
- {
- switch ( eNewShape )
- {
- case SHAPE_RECT:
- aRectangleButton.Check();
- break;
- case SHAPE_ELLIPSE:
- aEllipseButton.Check();
- break;
- }
-
- aShapeView.ChangeShape( eNewShape );
- }
-
- // --- ShapeDialog::ColorHdl() -------------------------------------
-
- void ShapeDialog::ColorHdl( ColorButton* pColorButton )
- {
- aShapeView.ChangeColor( pColorButton->GetColor() );
- }
-
- // --- ShapeDialog::SetColor() -------------------------------------
-
- void ShapeDialog::SetColor( const Color& rNewColor )
- {
- if ( aBlackButton.GetColor() == rNewColor )
- aBlackButton.Check();
- else if ( aBlueButton.GetColor() == rNewColor )
- aBlueButton.Check();
- else if ( aGreenButton.GetColor() == rNewColor )
- aGreenButton.Check();
- else if ( aCyanButton.GetColor() == rNewColor )
- aCyanButton.Check();
- else if ( aRedButton.GetColor() == rNewColor )
- aRedButton.Check();
- else if ( aMagentaButton.GetColor() == rNewColor )
- aMagentaButton.Check();
- else if ( aYellowButton.GetColor() == rNewColor )
- aYellowButton.Check();
- else if ( aWhiteButton.GetColor() == rNewColor )
- aWhiteButton.Check();
-
- aShapeView.ChangeColor( rNewColor );
- }
-
- // --- class MyWindow ----------------------------------------------
-
- class MyWindow : public WorkWindow
- {
- private:
- ShapeView aShapeView;
-
- public:
- MyWindow();
-
- virtual void Resize();
-
- long SelectHdl( Menu* );
- };
-
- // --- MyWindow::MyWindow() ----------------------------------------
-
- MyWindow::MyWindow() :
- WorkWindow( NULL, WB_APP | WB_STDWORK ),
- aShapeView( this )
- {
- SetText( "Dialog Example" );
-
- aShapeView.Show();
- }
-
- // --- MyWindow::Resize() ------------------------------------------
-
- void MyWindow::Resize()
- {
- aShapeView.SetPosSizePixel( Point(), GetOutputSizePixel() );
- }
-
- // --- MyWindow::SelectHdl() ---------------------------------------
-
- long MyWindow::SelectHdl( Menu* pMenu )
- {
- if ( pMenu->GetCurItemId() == MI_EXAMPLE )
- {
- ShapeDialog* pDlgBox = new ShapeDialog( this );
- pDlgBox->SetShape( aShapeView.GetShape() );
- pDlgBox->SetColor( aShapeView.GetColor() );
-
- if ( pDlgBox->Execute() )
- {
- aShapeView.ChangeShape( pDlgBox->GetShape() );
- aShapeView.ChangeColor( pDlgBox->GetColor() );
- }
-
- delete pDlgBox;
- }
- else
- Close();
-
- return TRUE;
- }
-
- // --- class MyApp -------------------------------------------------
-
- class MyApp : public Application
- {
- public:
- virtual void Main( int, char*[] );
- };
-
- // --- MyApp::Main() -----------------------------------------------
-
- void MyApp::Main( int, char*[] )
- {
- EnableSVLook();
-
- MyWindow aWindow;
- MenuBar aMenu( ResId( APP_MENUBAR ) );
-
- aMenu.PushSelectHdl( LINK( &aWindow, MyWindow, SelectHdl ) );
- ChangeAppMenu( &aMenu );
-
- aWindow.Show();
-
- Execute();
- }
-
- // --- aMyApp ------------------------------------------------------
-
- MyApp aMyApp;
-