home *** CD-ROM | disk | FTP | other *** search
/ PC Direkt 1995 March / PCD_395.iso / starview / pm2csci / german / dlgdemo.cx_ / DLGDEMO.CXX
Encoding:
C/C++ Source or Header  |  1994-06-06  |  10.0 KB  |  354 lines

  1. /*******************************************************************
  2. *  DLGDEMO.CXX
  3. *  (c) 1992-1994 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include <sv.hxx>
  7.  
  8. #include "dlgdemo.hrc"
  9.  
  10. class ShapeDialog;
  11.  
  12. // --- class ShowShape ---------------------------------------------
  13.  
  14. enum Shape { SHAPE_RECT, SHAPE_ELLIPSE };
  15.  
  16. class ShapeView : public Control
  17. {
  18. private:
  19.     Shape           eShape;
  20.     Color           aColor;
  21.  
  22. public:
  23.                     ShapeView( Window* pParent );
  24.                     ShapeView( Window* pParent,
  25.                                const ResId& rResId );
  26.  
  27.     virtual void    Paint( const Rectangle& rRect );
  28.     virtual void    Resize();
  29.  
  30.     Shape           ChangeShape( Shape eNewShape );
  31.     Shape           GetShape() const { return eShape; }
  32.     Color           ChangeColor( const Color& rNewColor );
  33.     Color           GetColor() const { return aColor; }
  34. };
  35.  
  36. // --- ShapeView::ShapeView() --------------------------------------
  37.  
  38. ShapeView::ShapeView( Window* pParent ) :
  39.             Control( pParent ),
  40.             eShape( SHAPE_ELLIPSE ),
  41.             aColor( COL_CYAN )
  42. {
  43.     ChangeFillInBrush( Brush( aColor ) );
  44. }
  45.  
  46. // --- ShapeView::ShapeView() --------------------------------------
  47.  
  48. ShapeView::ShapeView( Window* pParent, const ResId& rResId ) :
  49.             Control( pParent, rResId ),
  50.             eShape( SHAPE_ELLIPSE ),
  51.             aColor( COL_CYAN )
  52. {
  53.     ChangeFillInBrush( Brush( aColor ) );
  54. }
  55.  
  56. // --- ShapeView::Paint() ------------------------------------------
  57.  
  58. void ShapeView::Paint( const Rectangle& )
  59. {
  60.     if ( eShape == SHAPE_RECT )
  61.         DrawRect( Rectangle( Point(), GetOutputSize() ) );
  62.     else
  63.         DrawEllipse( Rectangle( Point(), GetOutputSize() ) );
  64. }
  65.  
  66. // --- ShapeView::Resize() -----------------------------------------
  67.  
  68. void ShapeView::Resize()
  69. {
  70.     Invalidate();
  71. }
  72.  
  73. // --- ShapeView::ChangeShape() ------------------------------------
  74.  
  75. Shape ShapeView::ChangeShape( Shape eNewShape )
  76. {
  77.     Shape eOldShape = eShape;
  78.     eShape = eNewShape;
  79.     Invalidate();
  80.     return eOldShape;
  81. }
  82.  
  83. // --- ShapeView::ChangeColor() ------------------------------------
  84.  
  85. Color ShapeView::ChangeColor( const Color& rNewColor )
  86. {
  87.     Color aOldColor = aColor;
  88.     aColor = rNewColor;
  89.     ChangeFillInBrush( Brush( aColor ) );
  90.     Invalidate();
  91.     return aOldColor;
  92. }
  93.  
  94. // --- class ShapeButton -------------------------------------------
  95.  
  96. class ShapeButton : public RadioButton
  97. {
  98. private:
  99.     Shape   eShape;
  100.  
  101. public:
  102.             ShapeButton( ShapeDialog* pParent,
  103.                          const ResId& rResId,
  104.                          Shape eShape );
  105.  
  106.     Shape   GetShape() const { return eShape; }
  107. };
  108.  
  109. // --- class ColorButton -------------------------------------------
  110.  
  111. class ColorButton : public RadioButton
  112. {
  113. private:
  114.     Color   aColor;
  115.  
  116. public:
  117.             ColorButton( ShapeDialog* pParent,
  118.                          const ResId& rResId,
  119.                          const Color& rColor );
  120.  
  121.     Color   GetColor() const { return aColor; }
  122. };
  123.  
  124. // --- class ShapeDialog -------------------------------------------
  125.  
  126. class ShapeDialog : public ModalDialog
  127. {
  128. private:
  129.     ColorButton     aBlackButton;
  130.     ColorButton     aBlueButton;
  131.     ColorButton     aGreenButton;
  132.     ColorButton     aCyanButton;
  133.     ColorButton     aRedButton;
  134.     ColorButton     aMagentaButton;
  135.     ColorButton     aYellowButton;
  136.     ColorButton     aWhiteButton;
  137.     GroupBox        aColorGroup;
  138.     ShapeView       aShapeView;
  139.     ShapeButton     aRectangleButton;
  140.     ShapeButton     aEllipseButton;
  141.     GroupBox        aShapeGroup;
  142.     OKButton        aOKButton;
  143.     CancelButton    aCancelButton;
  144.  
  145. public:
  146.                     ShapeDialog( Window* pWindow );
  147.  
  148.     void            ShapeHdl( ShapeButton* pShapeButton );
  149.     void            SetShape( Shape eNewShape );
  150.     Shape           GetShape() const
  151.                         { return aShapeView.GetShape(); }
  152.  
  153.     void            ColorHdl( ColorButton* pColorButton );
  154.     void            SetColor( const Color& rNewColor );
  155.     Color           GetColor() const
  156.                         { return aShapeView.GetColor(); }
  157. };
  158.  
  159. // --- ShapeButton::ShapeButton() ----------------------------------
  160.  
  161. ShapeButton::ShapeButton( ShapeDialog* pParent,
  162.                           const ResId& rResId,
  163.                           Shape eShape ) :
  164.                  RadioButton( pParent, rResId )
  165. {
  166.     ShapeButton::eShape = eShape;
  167.     ChangeClickHdl( LINK( pParent, ShapeDialog, ShapeHdl ) );
  168. }
  169.  
  170. // --- ColorButton::ColorButton() ----------------------------------
  171.  
  172. ColorButton::ColorButton( ShapeDialog* pParent,
  173.                           const ResId& rResId,
  174.                           const Color& rColor ) :
  175.                  RadioButton( pParent, rResId ),
  176.                  aColor( rColor )
  177. {
  178.     ChangeClickHdl( LINK( pParent, ShapeDialog, ColorHdl ) );
  179. }
  180.  
  181. // --- ShapeDialog::ShapeDialog() ----------------------------------
  182.  
  183. ShapeDialog::ShapeDialog( Window* pWindow ) :
  184.                 ModalDialog( pWindow, ResId( DLG_SHAPE ) ),
  185.                 aBlackButton( this, ResId( DLG_BLACK ),
  186.                               Color( (ColorName)COL_BLACK ) ),
  187.                 aBlueButton( this, ResId( DLG_BLUE ),
  188.                              Color( (ColorName)COL_BLUE ) ),
  189.                 aGreenButton( this, ResId( DLG_GREEN ),
  190.                               Color( (ColorName)COL_GREEN ) ),
  191.                 aCyanButton( this, ResId( DLG_CYAN ),
  192.                              Color( (ColorName)COL_CYAN ) ),
  193.                 aRedButton( this, ResId( DLG_RED ),
  194.                             Color( (ColorName)COL_RED ) ),
  195.                 aMagentaButton( this, ResId( DLG_MAGENTA ),
  196.                                 Color((ColorName)COL_MAGENTA )),
  197.                 aYellowButton( this, ResId( DLG_YELLOW ),
  198.                                Color( (ColorName)COL_YELLOW ) ),
  199.                 aWhiteButton( this, ResId( DLG_WHITE ),
  200.                               Color( (ColorName)COL_WHITE ) ),
  201.                 aColorGroup( this, ResId( DLG_GB1 ) ),
  202.                 aShapeView( this, ResId( DLG_VIEW ) ),
  203.                 aRectangleButton( this, ResId( DLG_RECT ),
  204.                                   SHAPE_RECT ),
  205.                 aEllipseButton( this, ResId( DLG_ELL  ),
  206.                                 SHAPE_ELLIPSE ),
  207.                 aShapeGroup( this, ResId( DLG_GB2 ) ),
  208.                 aOKButton( this, ResId( DLG_OK ) ),
  209.                 aCancelButton( this, ResId( DLG_CANCEL ) )
  210. {
  211.     FreeResource();
  212. }
  213.  
  214. // --- ShapeDialog::ShapeHdl() -------------------------------------
  215.  
  216. void ShapeDialog::ShapeHdl( ShapeButton* pShapeButton )
  217. {
  218.     aShapeView.ChangeShape( pShapeButton->GetShape() );
  219. }
  220.  
  221. // --- ShapeDialog::SetShape() -------------------------------------
  222.  
  223. void ShapeDialog::SetShape( Shape eNewShape )
  224. {
  225.     switch ( eNewShape )
  226.     {
  227.         case SHAPE_RECT:
  228.             aRectangleButton.Check();
  229.             break;
  230.         case SHAPE_ELLIPSE:
  231.             aEllipseButton.Check();
  232.             break;
  233.     }
  234.  
  235.     aShapeView.ChangeShape( eNewShape );
  236. }
  237.  
  238. // --- ShapeDialog::ColorHdl() -------------------------------------
  239.  
  240. void ShapeDialog::ColorHdl( ColorButton* pColorButton )
  241. {
  242.     aShapeView.ChangeColor( pColorButton->GetColor() );
  243. }
  244.  
  245. // --- ShapeDialog::SetColor() -------------------------------------
  246.  
  247. void ShapeDialog::SetColor( const Color& rNewColor )
  248. {
  249.     if ( aBlackButton.GetColor() == rNewColor )
  250.         aBlackButton.Check();
  251.     else if ( aBlueButton.GetColor() == rNewColor )
  252.         aBlueButton.Check();
  253.     else if ( aGreenButton.GetColor() == rNewColor )
  254.         aGreenButton.Check();
  255.     else if ( aCyanButton.GetColor() == rNewColor )
  256.         aCyanButton.Check();
  257.     else if ( aRedButton.GetColor() == rNewColor )
  258.         aRedButton.Check();
  259.     else if ( aMagentaButton.GetColor() == rNewColor )
  260.         aMagentaButton.Check();
  261.     else if ( aYellowButton.GetColor() == rNewColor )
  262.         aYellowButton.Check();
  263.     else if ( aWhiteButton.GetColor() == rNewColor )
  264.         aWhiteButton.Check();
  265.  
  266.     aShapeView.ChangeColor( rNewColor );
  267. }
  268.  
  269. // --- class MyWindow ----------------------------------------------
  270.  
  271. class MyWindow : public WorkWindow
  272. {
  273. private:
  274.     ShapeView       aShapeView;
  275.  
  276. public:
  277.                     MyWindow();
  278.  
  279.     virtual void    Resize();
  280.  
  281.     long            SelectHdl( Menu* );
  282. };
  283.  
  284. // --- MyWindow::MyWindow() ----------------------------------------
  285.  
  286. MyWindow::MyWindow() :
  287.               WorkWindow( NULL, WB_APP | WB_STDWORK ),
  288.               aShapeView( this )
  289. {
  290.     SetText( "Dialog Example" );
  291.  
  292.     aShapeView.Show();
  293. }
  294.  
  295. // --- MyWindow::Resize() ------------------------------------------
  296.  
  297. void MyWindow::Resize()
  298. {
  299.     aShapeView.SetPosSizePixel( Point(), GetOutputSizePixel() );
  300. }
  301.  
  302. // --- MyWindow::SelectHdl() ---------------------------------------
  303.  
  304. long MyWindow::SelectHdl( Menu* pMenu )
  305. {
  306.     if ( pMenu->GetCurItemId() == MI_EXAMPLE )
  307.     {
  308.         ShapeDialog* pDlgBox = new ShapeDialog( this );
  309.         pDlgBox->SetShape( aShapeView.GetShape() );
  310.         pDlgBox->SetColor( aShapeView.GetColor() );
  311.  
  312.         if ( pDlgBox->Execute() )
  313.         {
  314.             aShapeView.ChangeShape( pDlgBox->GetShape() );
  315.             aShapeView.ChangeColor( pDlgBox->GetColor() );
  316.         }
  317.  
  318.         delete pDlgBox;
  319.     }
  320.     else
  321.         Close();
  322.  
  323.     return TRUE;
  324. }
  325.  
  326. // --- class MyApp -------------------------------------------------
  327.  
  328. class MyApp : public Application
  329. {
  330. public:
  331.     virtual void Main( int, char*[] );
  332. };
  333.  
  334. // --- MyApp::Main() -----------------------------------------------
  335.  
  336. void MyApp::Main( int, char*[] )
  337. {
  338.     EnableSVLook();
  339.  
  340.     MyWindow aWindow;
  341.     MenuBar  aMenu( ResId( APP_MENUBAR ) );
  342.  
  343.     aMenu.PushSelectHdl( LINK( &aWindow, MyWindow, SelectHdl ) );
  344.     ChangeAppMenu( &aMenu );
  345.  
  346.     aWindow.Show();
  347.  
  348.     Execute();
  349. }
  350.  
  351. // --- aMyApp ------------------------------------------------------
  352.  
  353. MyApp aMyApp;
  354.