home *** CD-ROM | disk | FTP | other *** search
/ PC Direkt 1995 March / PCD_395.iso / starview / winblci / german / example4.cx_ / EXAMPLE4.CXX
Encoding:
C/C++ Source or Header  |  1994-01-18  |  4.4 KB  |  184 lines

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