home *** CD-ROM | disk | FTP | other *** search
/ PC Direkt 1995 March / PCD_395.iso / starview / pm2csci / german / metafile.cx_ / METAFILE.CXX
Encoding:
C/C++ Source or Header  |  1994-07-01  |  5.4 KB  |  218 lines

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