home *** CD-ROM | disk | FTP | other *** search
/ PC Direkt 1995 March / PCD_395.iso / starview / pm2csci / german / helpdemo.cx_ / HELPDEMO.CXX
Encoding:
C/C++ Source or Header  |  1994-01-18  |  13.8 KB  |  471 lines

  1. /*******************************************************************
  2. *  HELPDEMO.CXX
  3. *  (c) 1992-1994 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include <sv.hxx>
  7.  
  8. #include "helpdemo.hrc"
  9. #include "helpdemo.hhc"
  10.  
  11. #define RECT       0
  12. #define ELLIPSE    1
  13.  
  14. class MyWindow;
  15. class ShapeDialog;
  16.  
  17. // --- class MyApp -------------------------------------------------
  18.  
  19. class MyApp : public Application
  20. {
  21. private:
  22.     MyWindow*       pAppWindow;
  23.  
  24. public:
  25.     virtual void    ActivateExtHelp();
  26.     virtual void    DeactivateExtHelp();
  27.  
  28.     virtual void    Main( int, char*[] );
  29. };
  30.  
  31. // --- class ShowShape ---------------------------------------------
  32.  
  33. enum Shape { SHAPE_RECT, SHAPE_ELLIPSE };
  34.  
  35. class ShapeView : public Control
  36. {
  37. private:
  38.     Shape           eShape;
  39.     Color           aColor;
  40.  
  41. public:
  42.                     ShapeView( Window* pParent );
  43.                     ShapeView( Window* pParent,
  44.                                const ResId& rResId );
  45.  
  46.     virtual void    Paint( const Rectangle& rRect );
  47.     virtual void    Resize();
  48.  
  49.     Shape           ChangeShape( Shape eNewShape );
  50.     Shape           GetShape() const { return eShape; }
  51.     Color           ChangeColor( const Color& rNewColor );
  52.     Color           GetColor() const { return aColor; }
  53. };
  54.  
  55. // --- ShapeView::ShapeView() --------------------------------------
  56.  
  57. ShapeView::ShapeView( Window* pParent ) :
  58.             Control( pParent ),
  59.             eShape( SHAPE_ELLIPSE ),
  60.             aColor( COL_CYAN )
  61. {
  62.     ChangeFillInBrush( Brush( aColor ) );
  63. }
  64.  
  65. // --- ShapeView::ShapeView() --------------------------------------
  66.  
  67. ShapeView::ShapeView( Window* pParent, const ResId& rResId ) :
  68.             Control( pParent, rResId ),
  69.             eShape( SHAPE_ELLIPSE ),
  70.             aColor( COL_CYAN )
  71. {
  72.     ChangeFillInBrush( Brush( aColor ) );
  73. }
  74.  
  75. // --- ShapeView::Paint() ------------------------------------------
  76.  
  77. void ShapeView::Paint( const Rectangle& )
  78. {
  79.     if ( eShape == SHAPE_RECT )
  80.         DrawRect( Rectangle( Point(), GetOutputSize() ) );
  81.     else
  82.         DrawEllipse( Rectangle( Point(), GetOutputSize() ) );
  83. }
  84.  
  85. // --- ShapeView::Resize() -----------------------------------------
  86.  
  87. void ShapeView::Resize()
  88. {
  89.     Invalidate();
  90. }
  91.  
  92. // --- ShapeView::ChangeShape() ------------------------------------
  93.  
  94. Shape ShapeView::ChangeShape( Shape eNewShape )
  95. {
  96.     Shape eOldShape = eShape;
  97.     eShape = eNewShape;
  98.     Invalidate();
  99.     return eOldShape;
  100. }
  101.  
  102. // --- ShapeView::ChangeColor() ------------------------------------
  103.  
  104. Color ShapeView::ChangeColor( const Color& rNewColor )
  105. {
  106.     Color aOldColor = aColor;
  107.     aColor = rNewColor;
  108.     ChangeFillInBrush( Brush( aColor ) );
  109.     Invalidate();
  110.     return aOldColor;
  111. }
  112.  
  113. // --- class ShapeButton -------------------------------------------
  114.  
  115. class ShapeButton : public RadioButton
  116. {
  117. private:
  118.     Shape   eShape;
  119.  
  120. public:
  121.             ShapeButton( ShapeDialog* pParent,
  122.                          const ResId& rResId,
  123.                          Shape eShape );
  124.  
  125.     Shape   GetShape() const { return eShape; }
  126. };
  127.  
  128. // --- class ColorButton -------------------------------------------
  129.  
  130. class ColorButton : public RadioButton
  131. {
  132. private:
  133.     Color   aColor;
  134.  
  135. public:
  136.             ColorButton( ShapeDialog* pParent,
  137.                          const ResId& rResId,
  138.                          const Color& rColor );
  139.  
  140.     Color   GetColor() const { return aColor; }
  141. };
  142.  
  143. // --- class MyWindow ----------------------------------------------
  144.  
  145. class MyWindow : public WorkWindow
  146. {
  147. private:
  148.     ShapeView       aShapeView;
  149.     StatusBar       aStatus;
  150.  
  151. public:
  152.                     MyWindow();
  153.  
  154.     virtual void    Resize();
  155.  
  156.     long            HighlightMenuHdl( Menu* pMenu );
  157.     long            SelectMenuHdl( Menu* pMenu );
  158.     void            ControlHdl( Control* pControl );
  159.  
  160.     StatusBar&      GetStatus() { return aStatus; }
  161. };
  162.  
  163. // --- class ShapeDialog -------------------------------------------
  164.  
  165. class ShapeDialog : public ModalDialog
  166. {
  167. private:
  168.     ColorButton     aBlackButton;
  169.     ColorButton     aBlueButton;
  170.     ColorButton     aGreenButton;
  171.     ColorButton     aCyanButton;
  172.     ColorButton     aRedButton;
  173.     ColorButton     aMagentaButton;
  174.     ColorButton     aYellowButton;
  175.     ColorButton     aWhiteButton;
  176.     GroupBox        aColorGroup;
  177.     ShapeView       aShapeView;
  178.     ShapeButton     aRectangleButton;
  179.     ShapeButton     aEllipseButton;
  180.     GroupBox        aShapeGroup;
  181.     OKButton        aOKButton;
  182.     CancelButton    aCancelButton;
  183.     HelpButton      aHelpButton;
  184.  
  185. public:
  186.                     ShapeDialog( Window* pWindow );
  187.  
  188.     void            ShapeHdl( ShapeButton* pShapeButton );
  189.     void            SetShape( Shape eNewShape );
  190.     Shape           GetShape() const
  191.                         { return aShapeView.GetShape(); }
  192.  
  193.     void            ColorHdl( ColorButton* pColorButton );
  194.     void            SetColor( const Color& rNewColor );
  195.     Color           GetColor() const
  196.                         { return aShapeView.GetColor(); }
  197. };
  198.  
  199. // --- ShapeButton::ShapeButton() ----------------------------------
  200.  
  201. ShapeButton::ShapeButton( ShapeDialog* pParent,
  202.                           const ResId& rResId,
  203.                           Shape eShape ) :
  204.                  RadioButton( pParent, rResId )
  205. {
  206.     ShapeButton::eShape = eShape;
  207.     ChangeClickHdl( LINK( pParent, ShapeDialog, ShapeHdl ) );
  208.     ChangeGetFocusHdl( LINK( pApp->GetAppWindow(),
  209.                              MyWindow, ControlHdl ) );
  210. }
  211.  
  212. // --- ColorButton::ColorButton() ----------------------------------
  213.  
  214. ColorButton::ColorButton( ShapeDialog* pParent,
  215.                           const ResId& rResId,
  216.                           const Color& rColor ) :
  217.                  RadioButton( pParent, rResId ),
  218.                  aColor( rColor )
  219. {
  220.     ChangeClickHdl( LINK( pParent, ShapeDialog, ColorHdl ) );
  221.     ChangeGetFocusHdl( LINK( pApp->GetAppWindow(),
  222.                              MyWindow, ControlHdl ) );
  223. }
  224.  
  225. // --- ShapeDialog::ShapeDialog() ----------------------------------
  226.  
  227. ShapeDialog::ShapeDialog( Window* pWindow ) :
  228.                 ModalDialog( pWindow, ResId( DLG_SHAPE ) ),
  229.                 aBlackButton( this, ResId( DLG_BLACK ),
  230.                               Color( (ColorName)COL_BLACK ) ),
  231.                 aBlueButton( this, ResId( DLG_BLUE ),
  232.                              Color( (ColorName)COL_BLUE ) ),
  233.                 aGreenButton( this, ResId( DLG_GREEN ),
  234.                               Color( (ColorName)COL_GREEN ) ),
  235.                 aCyanButton( this, ResId( DLG_CYAN ),
  236.                              Color( (ColorName)COL_CYAN ) ),
  237.                 aRedButton( this, ResId( DLG_RED ),
  238.                             Color( (ColorName)COL_RED ) ),
  239.                 aMagentaButton( this, ResId( DLG_MAGENTA ),
  240.                                 Color((ColorName)COL_MAGENTA )),
  241.                 aYellowButton( this, ResId( DLG_YELLOW ),
  242.                                Color( (ColorName)COL_YELLOW ) ),
  243.                 aWhiteButton( this, ResId( DLG_WHITE ),
  244.                               Color( (ColorName)COL_WHITE ) ),
  245.                 aColorGroup( this, ResId( DLG_GB1 ) ),
  246.                 aShapeView( this, ResId( DLG_VIEW ) ),
  247.                 aRectangleButton( this, ResId( DLG_RECT ),
  248.                                   SHAPE_RECT ),
  249.                 aEllipseButton( this, ResId( DLG_ELL  ),
  250.                                 SHAPE_ELLIPSE ),
  251.                 aShapeGroup( this, ResId( DLG_GB2 ) ),
  252.                 aOKButton( this, ResId( DLG_OK ) ),
  253.                 aCancelButton( this, ResId( DLG_CANCEL ) ),
  254.                 aHelpButton( this, ResId( DLG_HELP ) )
  255. {
  256.     FreeResource();
  257.  
  258.     aOKButton.ChangeGetFocusHdl( LINK( pApp->GetAppWindow(),
  259.                                        MyWindow, ControlHdl ) );
  260.     aCancelButton.ChangeGetFocusHdl( LINK( pApp->GetAppWindow(),
  261.                                            MyWindow, ControlHdl ) );
  262.     aHelpButton.ChangeGetFocusHdl( LINK( pApp->GetAppWindow(),
  263.                                          MyWindow, ControlHdl ) );
  264. }
  265.  
  266. // --- ShapeDialog::ShapeHdl() -------------------------------------
  267.  
  268. void ShapeDialog::ShapeHdl( ShapeButton* pShapeButton )
  269. {
  270.     aShapeView.ChangeShape( pShapeButton->GetShape() );
  271. }
  272.  
  273. // --- ShapeDialog::SetShape() -------------------------------------
  274.  
  275. void ShapeDialog::SetShape( Shape eNewShape )
  276. {
  277.     switch ( eNewShape )
  278.     {
  279.         case SHAPE_RECT:
  280.             aRectangleButton.Check();
  281.             break;
  282.         case SHAPE_ELLIPSE:
  283.             aEllipseButton.Check();
  284.             break;
  285.     }
  286.  
  287.     aShapeView.ChangeShape( eNewShape );
  288. }
  289.  
  290. // --- ShapeDialog::ColorHdl() -------------------------------------
  291.  
  292. void ShapeDialog::ColorHdl( ColorButton* pColorButton )
  293. {
  294.     aShapeView.ChangeColor( pColorButton->GetColor() );
  295. }
  296.  
  297. // --- ShapeDialog::SetColor() -------------------------------------
  298.  
  299. void ShapeDialog::SetColor( const Color& rNewColor )
  300. {
  301.     if ( aBlackButton.GetColor() == rNewColor )
  302.         aBlackButton.Check();
  303.     else if ( aBlueButton.GetColor() == rNewColor )
  304.         aBlueButton.Check();
  305.     else if ( aGreenButton.GetColor() == rNewColor )
  306.         aGreenButton.Check();
  307.     else if ( aCyanButton.GetColor() == rNewColor )
  308.         aCyanButton.Check();
  309.     else if ( aRedButton.GetColor() == rNewColor )
  310.         aRedButton.Check();
  311.     else if ( aMagentaButton.GetColor() == rNewColor )
  312.         aMagentaButton.Check();
  313.     else if ( aYellowButton.GetColor() == rNewColor )
  314.         aYellowButton.Check();
  315.     else if ( aWhiteButton.GetColor() == rNewColor )
  316.         aWhiteButton.Check();
  317.  
  318.     aShapeView.ChangeColor( rNewColor );
  319. }
  320.  
  321. // --- MyWindow::MyWindow() ----------------------------------------
  322.  
  323. MyWindow::MyWindow() :
  324.               WorkWindow( NULL, WB_APP | WB_STDWORK ),
  325.               aShapeView( this ),
  326.               aStatus( this, WB_BORDER | WB_SVLOOK )
  327. {
  328.     SetText( "Help Demonstration" );
  329.  
  330.     aShapeView.Show();
  331.  
  332.     aStatus.SetText( String( ResId( WINHELP ) ) );
  333.     aStatus.SetHelpText( String( ResId( HELPSTATUS ) ) );
  334.     aStatus.ChangeHelpId( HELPID_STATUSLINE );
  335.     aStatus.Show();
  336. }
  337.  
  338. // --- MyWindow::Resize() ------------------------------------------
  339.  
  340. void MyWindow::Resize()
  341. {
  342.     Size   aSize = GetOutputSizePixel();
  343.     USHORT nHeight = aStatus.GetOutputSizePixel().Height();
  344.  
  345.     aShapeView.SetPosSizePixel( Point(),
  346.                                 Size( aSize.Width(),
  347.                                       aSize.Height()-nHeight ) );
  348.     aStatus.SetPosSizePixel( Point( 0, aSize.Height()-nHeight ),
  349.                              Size( aSize.Width(), nHeight ) );
  350. }
  351.  
  352. // --- MyWindow::SelectMenuHdl() -----------------------------------
  353.  
  354. long MyWindow::SelectMenuHdl( Menu* pMenu )
  355. {
  356.     USHORT nItemId = pMenu->GetCurItemId();
  357.  
  358.     switch ( nItemId )
  359.     {
  360.         case MI_DRAW:
  361.             {
  362.             ShapeDialog aDlgBox( this );
  363.             aDlgBox.SetShape( aShapeView.GetShape() );
  364.             aDlgBox.SetColor( aShapeView.GetColor() );
  365.  
  366.             if ( aDlgBox.Execute() )
  367.             {
  368.                 aShapeView.ChangeShape( aDlgBox.GetShape() );
  369.                 aShapeView.ChangeColor( aDlgBox.GetColor() );
  370.             }
  371.             aStatus.SetText( String( ResId( WINHELP ) ) );
  372.             }
  373.             break;
  374.  
  375.         case MI_EXIT:
  376.             Close();
  377.             break;
  378.  
  379.         case MI_INDEX:
  380.             pApp->GetHelp()->Start( HELP_INDEX );
  381.             break;
  382.         case MI_HELPONHELP:
  383.             pApp->GetHelp()->Start( HELP_HELPONHELP );
  384.             break;
  385.         case MI_DRAWHELP:
  386.             pApp->GetHelp()->Start( HELPID_COLORSHAPE );
  387.             break;
  388.         case MI_COLORHELP:
  389.             pApp->GetHelp()->Start( HELPID_COLORS );
  390.             break;
  391.         case MI_SHAPEHELP:
  392.             pApp->GetHelp()->Start( HELPID_SHAPE );
  393.             break;
  394.         case MI_ABOUT:
  395.             {
  396.             InfoBox aAboutBox( this, ResId( ABOUTBOX ) );
  397.             aStatus.SetText( String( ResId( ABOUTHELP ) ) );
  398.             aAboutBox.Execute();
  399.             aStatus.SetText( String( ResId( WINHELP ) ) );
  400.             }
  401.             break;
  402.     }
  403.  
  404.     return TRUE;
  405. }
  406.  
  407. // --- MyWindow::ControlHdl() --------------------------------------
  408.  
  409. void MyWindow::ControlHdl( Control* pControl )
  410. {
  411.     aStatus.SetText( pControl->GetHelpText() );
  412. }
  413.  
  414. // --- MyWindow::HighlightMenuHdl() --------------------------------
  415.  
  416. long MyWindow::HighlightMenuHdl( Menu* pMenu )
  417. {
  418.     String aText = pMenu->GetHelpText( pMenu->GetCurItemId() );
  419.  
  420.     if ( !aText )
  421.          aStatus.SetText( String( ResId( WINHELP ) ) );
  422.     else
  423.          aStatus.SetText( aText );
  424.  
  425.     return TRUE;
  426. }
  427.  
  428. // --- MyApp::ActivateExtHelp() ------------------------------------
  429.  
  430. void MyApp::ActivateExtHelp()
  431. {
  432.     pAppWindow->GetStatus().SetText( String( ResId( EXTHELP ) ) );
  433. }
  434.  
  435. // --- MyApp::DeactivateExtHelp() ----------------------------------
  436.  
  437. void MyApp::DeactivateExtHelp()
  438. {
  439.     pAppWindow->GetStatus().SetText( String( ResId( WINHELP ) ) );
  440. }
  441.  
  442. // --- MyApp::Main() -----------------------------------------------
  443.  
  444. void MyApp::Main( int, char*[] )
  445. {
  446.     EnableSVLook();
  447.  
  448.     MyWindow  aAppWindow;
  449.     MenuBar   aAppMenu( ResId( APP_MENUBAR ) );
  450.  
  451.     Help aHelp;
  452.     ChangeHelp( &aHelp );
  453.     EnableHelp( HELPMODE_ALL );
  454.  
  455.     pAppWindow = &aAppWindow;
  456.  
  457.     aAppMenu.PushHighlightHdl( LINK( &aAppWindow,
  458.                                      MyWindow, HighlightMenuHdl ) );
  459.     aAppMenu.PushSelectHdl( LINK( &aAppWindow,
  460.                                   MyWindow, SelectMenuHdl ) );
  461.     ChangeAppMenu( &aAppMenu );
  462.  
  463.     aAppWindow.Show();
  464.  
  465.     Execute();
  466. }
  467.  
  468. // --- aMyApp ------------------------------------------------------
  469.  
  470. MyApp aMyApp;
  471.