home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- * HELPDEMO.CXX
- * (c) 1992-1994 STAR DIVISION
- *******************************************************************/
-
- #include <sv.hxx>
-
- #include "helpdemo.hrc"
- #include "helpdemo.hhc"
-
- #define RECT 0
- #define ELLIPSE 1
-
- class MyWindow;
- class ShapeDialog;
-
- // --- class MyApp -------------------------------------------------
-
- class MyApp : public Application
- {
- private:
- MyWindow* pAppWindow;
-
- public:
- virtual void ActivateExtHelp();
- virtual void DeactivateExtHelp();
-
- virtual void Main( int, char*[] );
- };
-
- // --- 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 MyWindow ----------------------------------------------
-
- class MyWindow : public WorkWindow
- {
- private:
- ShapeView aShapeView;
- StatusBar aStatus;
-
- public:
- MyWindow();
-
- virtual void Resize();
-
- long HighlightMenuHdl( Menu* pMenu );
- long SelectMenuHdl( Menu* pMenu );
- void ControlHdl( Control* pControl );
-
- StatusBar& GetStatus() { return aStatus; }
- };
-
- // --- 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;
- HelpButton aHelpButton;
-
- 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 ) );
- ChangeGetFocusHdl( LINK( pApp->GetAppWindow(),
- MyWindow, ControlHdl ) );
- }
-
- // --- ColorButton::ColorButton() ----------------------------------
-
- ColorButton::ColorButton( ShapeDialog* pParent,
- const ResId& rResId,
- const Color& rColor ) :
- RadioButton( pParent, rResId ),
- aColor( rColor )
- {
- ChangeClickHdl( LINK( pParent, ShapeDialog, ColorHdl ) );
- ChangeGetFocusHdl( LINK( pApp->GetAppWindow(),
- MyWindow, ControlHdl ) );
- }
-
- // --- 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 ) ),
- aHelpButton( this, ResId( DLG_HELP ) )
- {
- FreeResource();
-
- aOKButton.ChangeGetFocusHdl( LINK( pApp->GetAppWindow(),
- MyWindow, ControlHdl ) );
- aCancelButton.ChangeGetFocusHdl( LINK( pApp->GetAppWindow(),
- MyWindow, ControlHdl ) );
- aHelpButton.ChangeGetFocusHdl( LINK( pApp->GetAppWindow(),
- MyWindow, ControlHdl ) );
- }
-
- // --- 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 );
- }
-
- // --- MyWindow::MyWindow() ----------------------------------------
-
- MyWindow::MyWindow() :
- WorkWindow( NULL, WB_APP | WB_STDWORK ),
- aShapeView( this ),
- aStatus( this, WB_BORDER | WB_SVLOOK )
- {
- SetText( "Help Demonstration" );
-
- aShapeView.Show();
-
- aStatus.SetText( String( ResId( WINHELP ) ) );
- aStatus.SetHelpText( String( ResId( HELPSTATUS ) ) );
- aStatus.ChangeHelpId( HELPID_STATUSLINE );
- aStatus.Show();
- }
-
- // --- MyWindow::Resize() ------------------------------------------
-
- void MyWindow::Resize()
- {
- Size aSize = GetOutputSizePixel();
- USHORT nHeight = aStatus.GetOutputSizePixel().Height();
-
- aShapeView.SetPosSizePixel( Point(),
- Size( aSize.Width(),
- aSize.Height()-nHeight ) );
- aStatus.SetPosSizePixel( Point( 0, aSize.Height()-nHeight ),
- Size( aSize.Width(), nHeight ) );
- }
-
- // --- MyWindow::SelectMenuHdl() -----------------------------------
-
- long MyWindow::SelectMenuHdl( Menu* pMenu )
- {
- USHORT nItemId = pMenu->GetCurItemId();
-
- switch ( nItemId )
- {
- case MI_DRAW:
- {
- ShapeDialog aDlgBox( this );
- aDlgBox.SetShape( aShapeView.GetShape() );
- aDlgBox.SetColor( aShapeView.GetColor() );
-
- if ( aDlgBox.Execute() )
- {
- aShapeView.ChangeShape( aDlgBox.GetShape() );
- aShapeView.ChangeColor( aDlgBox.GetColor() );
- }
- aStatus.SetText( String( ResId( WINHELP ) ) );
- }
- break;
-
- case MI_EXIT:
- Close();
- break;
-
- case MI_INDEX:
- pApp->GetHelp()->Start( HELP_INDEX );
- break;
- case MI_HELPONHELP:
- pApp->GetHelp()->Start( HELP_HELPONHELP );
- break;
- case MI_DRAWHELP:
- pApp->GetHelp()->Start( HELPID_COLORSHAPE );
- break;
- case MI_COLORHELP:
- pApp->GetHelp()->Start( HELPID_COLORS );
- break;
- case MI_SHAPEHELP:
- pApp->GetHelp()->Start( HELPID_SHAPE );
- break;
- case MI_ABOUT:
- {
- InfoBox aAboutBox( this, ResId( ABOUTBOX ) );
- aStatus.SetText( String( ResId( ABOUTHELP ) ) );
- aAboutBox.Execute();
- aStatus.SetText( String( ResId( WINHELP ) ) );
- }
- break;
- }
-
- return TRUE;
- }
-
- // --- MyWindow::ControlHdl() --------------------------------------
-
- void MyWindow::ControlHdl( Control* pControl )
- {
- aStatus.SetText( pControl->GetHelpText() );
- }
-
- // --- MyWindow::HighlightMenuHdl() --------------------------------
-
- long MyWindow::HighlightMenuHdl( Menu* pMenu )
- {
- String aText = pMenu->GetHelpText( pMenu->GetCurItemId() );
-
- if ( !aText )
- aStatus.SetText( String( ResId( WINHELP ) ) );
- else
- aStatus.SetText( aText );
-
- return TRUE;
- }
-
- // --- MyApp::ActivateExtHelp() ------------------------------------
-
- void MyApp::ActivateExtHelp()
- {
- pAppWindow->GetStatus().SetText( String( ResId( EXTHELP ) ) );
- }
-
- // --- MyApp::DeactivateExtHelp() ----------------------------------
-
- void MyApp::DeactivateExtHelp()
- {
- pAppWindow->GetStatus().SetText( String( ResId( WINHELP ) ) );
- }
-
- // --- MyApp::Main() -----------------------------------------------
-
- void MyApp::Main( int, char*[] )
- {
- EnableSVLook();
-
- MyWindow aAppWindow;
- MenuBar aAppMenu( ResId( APP_MENUBAR ) );
-
- Help aHelp;
- ChangeHelp( &aHelp );
- EnableHelp( HELPMODE_ALL );
-
- pAppWindow = &aAppWindow;
-
- aAppMenu.PushHighlightHdl( LINK( &aAppWindow,
- MyWindow, HighlightMenuHdl ) );
- aAppMenu.PushSelectHdl( LINK( &aAppWindow,
- MyWindow, SelectMenuHdl ) );
- ChangeAppMenu( &aAppMenu );
-
- aAppWindow.Show();
-
- Execute();
- }
-
- // --- aMyApp ------------------------------------------------------
-
- MyApp aMyApp;
-