home *** CD-ROM | disk | FTP | other *** search
/ PC Direkt 1995 March / PCD_395.iso / starview / wntmsci / german / example3.cx_ / EXAMPLE3.CXX
Encoding:
C/C++ Source or Header  |  1994-01-18  |  5.8 KB  |  224 lines

  1. /*******************************************************************
  2. *  EXAMPLE3.CXX
  3. *  (c) 1992-1994 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include <sv.hxx>
  7.  
  8. #include "about3.hxx"
  9.  
  10. #define MID_PENCOLOR  10
  11. #define MID_PENRED    11
  12. #define MID_PENBLUE   12
  13. #define MID_PENYELLOW 13
  14. #define MID_PENWIDTH  20
  15. #define MID_PENSMALL  21
  16. #define MID_PENMEDIUM 22
  17. #define MID_PENTHICK  23
  18. #define MID_FILE      30
  19. #define MID_QUIT      31
  20. #define MID_ABOUT     32
  21.  
  22. // --- class MyApp -------------------------------------------------
  23.  
  24. class MyApp : public Application
  25. {
  26. public:
  27.     virtual void Main( int, char*[] );
  28. };
  29.  
  30. // --- class MyWin -------------------------------------------------
  31.  
  32. class MyWin : public WorkWindow
  33. {
  34. private:
  35.     USHORT          nColor;
  36.     USHORT          nWidth;
  37.     Point           aLastPoint;
  38.  
  39. public:
  40.                     MyWin();
  41.  
  42.     virtual BOOL    Close();
  43.     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
  44.     virtual void    MouseButtonUp( const MouseEvent& rMEvt );
  45.     virtual void    MouseMove( const MouseEvent& rMEvt );
  46.     long            FileSelect( Menu* pMenu );
  47.     long            ColorSelect( Menu* pMenu );
  48.     long            WidthSelect( Menu* pMenu );
  49. };
  50.  
  51. // --- MyWin::MyWin() ----------------------------------------------
  52.  
  53. MyWin::MyWin() : WorkWindow( NULL, WB_STDWORK | WB_APP )
  54. {
  55.     nColor = 0;
  56.     nWidth = 0;
  57. }
  58.  
  59. // --- MyWin::Close() ----------------------------------------------
  60.  
  61. BOOL MyWin::Close()
  62. {
  63.     QueryBox aBox( this, WB_OK_CANCEL | WB_DEF_OK, "Exit Paint" );
  64.  
  65.     if ( aBox.Execute() == RET_OK )
  66.         return WorkWindow::Close();
  67.     else
  68.         return FALSE;
  69. }
  70.  
  71. // --- MyWin::MouseButtonDown() ------------------------------------
  72.  
  73. void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
  74. {
  75.     CaptureMouse();
  76.     aLastPoint = rMEvt.GetPosPixel();
  77. }
  78.  
  79. // --- MyWin::MouseButtonUp() --------------------------------------
  80.  
  81. void MyWin::MouseButtonUp( const MouseEvent& )
  82. {
  83.     ReleaseMouse();
  84. }
  85.  
  86. // --- MyWin::MouseMove() ------------------------------------------
  87.  
  88. void MyWin::MouseMove( const MouseEvent& rMEvt )
  89. {
  90.     if ( rMEvt.IsLeft() )
  91.     {
  92.         DrawLine( aLastPoint, rMEvt.GetPosPixel() );
  93.         aLastPoint = rMEvt.GetPosPixel();
  94.     }
  95. }
  96.  
  97. // --- MyWin::FileSelect() -----------------------------------------
  98.  
  99. long MyWin::FileSelect( Menu* pMenu )
  100. {
  101.     switch ( pMenu->GetCurItemId() )
  102.     {
  103.         case MID_ABOUT:
  104.             {
  105.                 AboutBox( this ).Execute();
  106.             }
  107.             break;
  108.         case MID_QUIT:
  109.             Close();
  110.             break;
  111.     }
  112.  
  113.     return TRUE;
  114. }
  115.  
  116. // --- MyWin::ColorSelect() ----------------------------------------
  117.  
  118. long MyWin::ColorSelect( Menu* pMenu )
  119. {
  120.     if ( nColor )
  121.         pMenu->CheckItem( nColor, FALSE );
  122.     nColor = pMenu->GetCurItemId();
  123.     pMenu->CheckItem( nColor );
  124.  
  125.     Pen aPen = GetPen();
  126.     switch( nColor )
  127.     {
  128.         case MID_PENRED:
  129.              aPen.ChangeColor( Color( COL_RED ) );
  130.              break;
  131.         case MID_PENBLUE:
  132.              aPen.ChangeColor( Color( COL_BLUE ) );
  133.              break;
  134.         case MID_PENYELLOW:
  135.              aPen.ChangeColor( Color( COL_YELLOW ) );
  136.              break;
  137.     }
  138.     ChangePen( aPen );
  139.  
  140.     return TRUE;
  141. }
  142.  
  143. // --- MyWin::WidthSelect() ----------------------------------------
  144.  
  145. long MyWin::WidthSelect( Menu* pMenu )
  146. {
  147.     if ( nWidth )
  148.         pMenu->CheckItem( nWidth, FALSE );
  149.     nWidth = pMenu->GetCurItemId();
  150.     pMenu->CheckItem( nWidth );
  151.  
  152.     Pen aPen = GetPen();
  153.     switch ( nWidth )
  154.     {
  155.         case MID_PENSMALL:
  156.             aPen.ChangeWidth( 1 );
  157.             break;
  158.         case MID_PENMEDIUM:
  159.             aPen.ChangeWidth( 4 );
  160.             break;
  161.         case MID_PENTHICK:
  162.             aPen.ChangeWidth( 8 );
  163.             break;
  164.     }
  165.     ChangePen( aPen );
  166.  
  167.     return TRUE;
  168. }
  169.  
  170. // --- MyApp::Main() -----------------------------------------------
  171.  
  172. void MyApp::Main( int, char*[] )
  173. {
  174.     MyWin       aMainWin;
  175.     PopupMenu   aFileMenu;
  176.     PopupMenu   aColorMenu;
  177.     PopupMenu   aWidthMenu;
  178.     MenuBar     aMenuBar;
  179.  
  180.     aMenuBar.InsertItem( MID_FILE, "~File" );
  181.     aMenuBar.InsertItem( MID_PENCOLOR, "~Color" );
  182.     aMenuBar.InsertItem( MID_PENWIDTH, "~Width" );
  183.  
  184.     aMenuBar.ChangePopupMenu( MID_FILE,     &aFileMenu );
  185.     aMenuBar.ChangePopupMenu( MID_PENCOLOR, &aColorMenu );
  186.     aMenuBar.ChangePopupMenu( MID_PENWIDTH, &aWidthMenu );
  187.  
  188.     aFileMenu.InsertItem( MID_ABOUT, "~About...", MENU_APPEND, MIB_ABOUT );
  189.     aFileMenu.InsertSeparator();
  190.     aFileMenu.InsertItem( MID_QUIT, "~Exit..." );
  191.  
  192.     aColorMenu.InsertItem( MID_PENRED, "~Red",
  193.                            MENU_APPEND, MIB_CHECKABLE );
  194.     aColorMenu.InsertItem( MID_PENBLUE, "~Blue",
  195.                            MENU_APPEND, MIB_CHECKABLE );
  196.     aColorMenu.InsertItem( MID_PENYELLOW, "~Yellow",
  197.                            MENU_APPEND, MIB_CHECKABLE );
  198.  
  199.     aWidthMenu.InsertItem( MID_PENSMALL, "~Small",
  200.                            MENU_APPEND, MIB_CHECKABLE );
  201.     aWidthMenu.InsertItem( MID_PENMEDIUM, "~Medium",
  202.                            MENU_APPEND, MIB_CHECKABLE );
  203.     aWidthMenu.InsertItem( MID_PENTHICK, "~Large",
  204.                            MENU_APPEND, MIB_CHECKABLE );
  205.  
  206.     aFileMenu.PushSelectHdl( LINK( &aMainWin,
  207.                                    MyWin, FileSelect ) );
  208.     aColorMenu.PushSelectHdl( LINK( &aMainWin,
  209.                                     MyWin, ColorSelect ) );
  210.     aWidthMenu.PushSelectHdl( LINK( &aMainWin,
  211.                                     MyWin, WidthSelect ) );
  212.  
  213.     ChangeAppMenu( &aMenuBar );
  214.  
  215.     aMainWin.SetText( "StarView Paint" );
  216.     aMainWin.Show();
  217.  
  218.     Execute();
  219. }
  220.  
  221. // --- aMyApp ------------------------------------------------------
  222.  
  223. MyApp aMyApp;
  224.