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

  1. /*******************************************************************
  2. *  SPLITTER.CXX
  3. *  (c) 1992-1994 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include <sv.hxx>
  7.  
  8. // --- class MyApp -------------------------------------------------
  9.  
  10. class MyApp : public Application
  11. {
  12. public:
  13.     virtual void Main( int, char*[] );
  14. };
  15.  
  16. // --- class PaintWindow -------------------------------------------
  17.  
  18. class PaintWindow : public Window
  19. {
  20. private:
  21.     USHORT          nWinNum;
  22.     USHORT          nX;
  23.  
  24. public:
  25.                     PaintWindow( Window* pParent );
  26.  
  27.     virtual void    Paint( const Rectangle& );
  28.     virtual void    Resize();
  29.  
  30.     void            Scroll( ScrollBar* pScroll );
  31.     void            InitScroll( ScrollBar* pScroll );
  32. };
  33.  
  34. // --- class AppWindow ---------------------------------------------
  35.  
  36. class AppWindow : public WorkWindow
  37. {
  38. private:
  39.     PaintWindow     aPaint1;
  40.     PaintWindow     aPaint2;
  41.     SplitBar        aSplitBar;
  42.  
  43. public:
  44.                     AppWindow();
  45.  
  46.     virtual void    Resize();
  47.  
  48.     void            ChangeSplit( SplitBar* pBar );
  49. };
  50.  
  51. // --- PaintWindow::PaintWindow() ----------------------------------
  52.  
  53. PaintWindow::PaintWindow( Window* pParent ) :
  54.                  Window( pParent, WB_BORDER )
  55. {
  56.     static USHORT nWin=0;
  57.     nWinNum = ++nWin;
  58.     Show();
  59. }
  60.  
  61. // --- PaintWindow::Paint() ----------------------------------------
  62.  
  63. void PaintWindow::Paint( const Rectangle& )
  64. {
  65.     Point aPointArray[ 4 ];
  66.     const short nY = 480;
  67.  
  68.     ChangePen( Pen( Color( COL_BLACK ), 0 ) );
  69.     ChangeFillInBrush( Brush( Color( COL_GREEN ) ) );
  70.     DrawRect( Rectangle( Point( nX/8, nY/8 ),
  71.                          Size( nX/4, nY/4 ) ), 10, 10 );
  72.  
  73.     ChangePen( Pen( Color( COL_BLUE ), 3 ) );
  74.     DrawArc( Rectangle( Point( 0, 0 ), Point( nX-nX/8, nY-nY/8 ) ),
  75.                         Point( nX/2, nY ), Point( nX, nY/2 ) );
  76.  
  77.     ChangePen( Pen( Color( COL_CYAN ), 2 ) );
  78.     aPointArray[0] = Point( nX/2, nY/2 );
  79.     aPointArray[1] = Point( 3*nX/4, nY );
  80.     aPointArray[2] = Point( nX, 3*nY/4 );
  81.     aPointArray[3] = Point( nX/3, 4*nY/5 );
  82.     DrawPolyLine( Polygon( 4, aPointArray ) );
  83.  
  84.     ChangePen( Pen( Color( COL_LIGHTGREEN ), 1, PEN_DASH ) );
  85.     aPointArray[0] = Point( nX/2, nY/2-nY/10 );
  86.     aPointArray[1] = Point( 3*nX/4, nY-nY/10 );
  87.     aPointArray[2] = Point( nX, 3*nY/4-nY/10 );
  88.     aPointArray[3] = Point( nX/3, 4*nY/5-nY/10 );
  89.     DrawPolyLine( Polygon( 4, aPointArray ) );
  90.  
  91.     Pen aNullPen( PEN_NULL );
  92.     ChangePen( aNullPen );
  93.     ChangeFillInBrush( Brush( Color( COL_BLACK ),
  94.                               Color( COL_WHITE ),
  95.                               BRUSH_VERT ) );
  96.     DrawRect( Rectangle( Point( 3*nX/4, nY/6 ),
  97.                          Size( nX/5, nY/5 ) ) );
  98.  
  99.     ChangeFillInBrush( Brush( Color( COL_LIGHTMAGENTA ),
  100.                               BRUSH_DIAGCROSS ) );
  101.     DrawEllipse( Rectangle( Point( 3*nX/4, nY/6 ),
  102.                             Size( nX/4, nY/4 ) ) );
  103.  
  104.     ChangePen( Pen( Color( COL_BLACK ), 1 ) );
  105.     ChangeFillInBrush( Brush( Color( COL_MAGENTA ) ) );
  106.     aPointArray[0] = Point( nX/8, nY/2 );
  107.     aPointArray[1] = Point( nX/3, 2*nY/3 );
  108.     aPointArray[2] = Point( 1, nY-1 ) ;
  109.     DrawPolygon( Polygon( 3, aPointArray ) );
  110.  
  111.     ChangePen( Pen( Color( COL_BLACK ), 2 ) );
  112.     ChangeFillInBrush( Brush( Color( COL_RED ), BRUSH_CROSS ) );
  113.     DrawEllipse( Rectangle( Point( nX/2, nY/3),
  114.                             Point( nX/2+nX/5, nY/2 ) ) );
  115.  
  116.     Brush aNullBrush( BRUSH_NULL );
  117.     ChangeFillInBrush( aNullBrush );
  118.     DrawEllipse( Rectangle( Point( nX/2, nY-nY/3),
  119.                             Point( nX/2+nX/5, nY-nY/4 ) ) );
  120.  
  121.     MapMode aOldMode = ChangeMapMode( MapMode() );
  122.  
  123.     String aStr( "Window " );
  124.     aStr += nWinNum;
  125.     DrawText( Point(), aStr );
  126.  
  127.     ChangeMapMode( aOldMode );
  128. }
  129.  
  130. // --- PaintWindow::Resize() ---------------------------------------
  131.  
  132. void PaintWindow::Resize()
  133. {
  134.     nX = GetOutputSizePixel().Width();
  135.     Invalidate();
  136. }
  137.  
  138. // --- PaintWindow::Scroll() ---------------------------------------
  139.  
  140. void PaintWindow::Scroll( ScrollBar* pScroll )
  141. {
  142.     MapMode aMapMode( MAP_PIXEL,
  143.                       Point( 0, (pScroll->GetThumbPos()*-1)-40 ),
  144.                       Fraction( 1, 1 ), Fraction( 1, 1 ) );
  145.     ChangeMapMode( aMapMode );
  146.  
  147.     Invalidate();
  148. }
  149.  
  150. // --- PaintWindow::InitScroll() -----------------------------------
  151.  
  152. void PaintWindow::InitScroll( ScrollBar* pScroll )
  153. {
  154.     pScroll->ChangeRange( Range( 0, 440 ) );
  155.     pScroll->ChangeLineSize( 3 );
  156.     pScroll->ChangePageSize( 48 );
  157.     pScroll->ChangeScrollHdl( LINK( this, PaintWindow, Scroll ) );
  158.     Scroll( pScroll );
  159. }
  160.  
  161. // --- AppWindow::AppWindow() --------------------------------------
  162.  
  163. AppWindow::AppWindow() :
  164.                 WorkWindow( NULL, WB_APP | WB_STDWORK ),
  165.                 aPaint1( this ),
  166.                 aPaint2( this ),
  167.                 aSplitBar( this, WB_DRAG | WB_VSCROLL )
  168. {
  169.     SetText( "SplitBar-Demo" );
  170.  
  171.     Show();
  172.  
  173.     aSplitBar.ChangeSplitHdl( LINK( this, AppWindow,
  174.                                     ChangeSplit ) );
  175.  
  176.     short nY = GetOutputSizePixel().Height();
  177.     aSplitBar.ChangeSplitPosPixel( (nY-20) * 2 / 3 );
  178.  
  179.     aPaint1.InitScroll( aSplitBar.GetScrollBar1() );
  180.     aPaint2.InitScroll( aSplitBar.GetScrollBar2() );
  181. }
  182.  
  183. // --- AppWindow::Resize() -----------------------------------------
  184.  
  185. void AppWindow::Resize()
  186. {
  187.     short nWidth = aSplitBar.GetSizePixel().Width();
  188.     short nX = GetOutputSizePixel().Width()-nWidth-10;
  189.     short nY = GetOutputSizePixel().Height()-20;
  190.  
  191.     aSplitBar.SetPosSizePixel( Point( nX, 10 ),
  192.                                Size( nWidth, nY ) );
  193.     aSplitBar.ChangeDragRectPixel( Rectangle( 10, 10, nX, nY ),
  194.                                    this );
  195.     short nNewY = aSplitBar.GetSplitPosPixel();
  196.  
  197.     if ( nNewY < 10)
  198.         nNewY= 10;
  199.  
  200.     aSplitBar.Show();
  201.  
  202.     aSplitBar.GetScrollBar1()->ChangeVisibleSize( nNewY-13 );
  203.     aPaint1.SetPosSizePixel( Point( 10, 10 ),
  204.                              Size( nX-12, nNewY-13 ) );
  205.     aPaint1.Show();
  206.  
  207.     aSplitBar.GetScrollBar2()->ChangeVisibleSize( nY-nNewY+7 );
  208.     aPaint2.SetPosSizePixel( Point( 10, nNewY + 3 ),
  209.                              Size( nX-12, nY-nNewY+7 ) );
  210.     aPaint2.Show();
  211. }
  212.  
  213. // --- AppWindow::ChangeSplit() ------------------------------------
  214.  
  215. void AppWindow::ChangeSplit( SplitBar* )
  216. {
  217.     Resize();
  218. }
  219.  
  220. // --- MyApp::Main() -----------------------------------------------
  221.  
  222. void MyApp::Main( int, char*[] )
  223. {
  224.    AppWindow aWindow;
  225.    Execute();
  226. }
  227.  
  228. // --- aMyApp ------------------------------------------------------
  229.  
  230. MyApp aMyApp;
  231.