home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- * SPLITTER.CXX
- * (c) 1992-1994 STAR DIVISION
- *******************************************************************/
-
- #include <sv.hxx>
-
- // --- class MyApp -------------------------------------------------
-
- class MyApp : public Application
- {
- public:
- virtual void Main( int, char*[] );
- };
-
- // --- class PaintWindow -------------------------------------------
-
- class PaintWindow : public Window
- {
- private:
- USHORT nWinNum;
- USHORT nX;
-
- public:
- PaintWindow( Window* pParent );
-
- virtual void Paint( const Rectangle& );
- virtual void Resize();
-
- void Scroll( ScrollBar* pScroll );
- void InitScroll( ScrollBar* pScroll );
- };
-
- // --- class AppWindow ---------------------------------------------
-
- class AppWindow : public WorkWindow
- {
- private:
- PaintWindow aPaint1;
- PaintWindow aPaint2;
- SplitBar aSplitBar;
-
- public:
- AppWindow();
-
- virtual void Resize();
-
- void ChangeSplit( SplitBar* pBar );
- };
-
- // --- PaintWindow::PaintWindow() ----------------------------------
-
- PaintWindow::PaintWindow( Window* pParent ) :
- Window( pParent, WB_BORDER )
- {
- static USHORT nWin=0;
- nWinNum = ++nWin;
- Show();
- }
-
- // --- PaintWindow::Paint() ----------------------------------------
-
- void PaintWindow::Paint( const Rectangle& )
- {
- Point aPointArray[ 4 ];
- const short nY = 480;
-
- ChangePen( Pen( Color( COL_BLACK ), 0 ) );
- ChangeFillInBrush( Brush( Color( COL_GREEN ) ) );
- DrawRect( Rectangle( Point( nX/8, nY/8 ),
- Size( nX/4, nY/4 ) ), 10, 10 );
-
- ChangePen( Pen( Color( COL_BLUE ), 3 ) );
- DrawArc( Rectangle( Point( 0, 0 ), Point( nX-nX/8, nY-nY/8 ) ),
- Point( nX/2, nY ), Point( nX, nY/2 ) );
-
- ChangePen( Pen( Color( COL_CYAN ), 2 ) );
- aPointArray[0] = Point( nX/2, nY/2 );
- aPointArray[1] = Point( 3*nX/4, nY );
- aPointArray[2] = Point( nX, 3*nY/4 );
- aPointArray[3] = Point( nX/3, 4*nY/5 );
- DrawPolyLine( Polygon( 4, aPointArray ) );
-
- ChangePen( Pen( Color( COL_LIGHTGREEN ), 1, PEN_DASH ) );
- aPointArray[0] = Point( nX/2, nY/2-nY/10 );
- aPointArray[1] = Point( 3*nX/4, nY-nY/10 );
- aPointArray[2] = Point( nX, 3*nY/4-nY/10 );
- aPointArray[3] = Point( nX/3, 4*nY/5-nY/10 );
- DrawPolyLine( Polygon( 4, aPointArray ) );
-
- Pen aNullPen( PEN_NULL );
- ChangePen( aNullPen );
- ChangeFillInBrush( Brush( Color( COL_BLACK ),
- Color( COL_WHITE ),
- BRUSH_VERT ) );
- DrawRect( Rectangle( Point( 3*nX/4, nY/6 ),
- Size( nX/5, nY/5 ) ) );
-
- ChangeFillInBrush( Brush( Color( COL_LIGHTMAGENTA ),
- BRUSH_DIAGCROSS ) );
- DrawEllipse( Rectangle( Point( 3*nX/4, nY/6 ),
- Size( nX/4, nY/4 ) ) );
-
- ChangePen( Pen( Color( COL_BLACK ), 1 ) );
- ChangeFillInBrush( Brush( Color( COL_MAGENTA ) ) );
- aPointArray[0] = Point( nX/8, nY/2 );
- aPointArray[1] = Point( nX/3, 2*nY/3 );
- aPointArray[2] = Point( 1, nY-1 ) ;
- DrawPolygon( Polygon( 3, aPointArray ) );
-
- ChangePen( Pen( Color( COL_BLACK ), 2 ) );
- ChangeFillInBrush( Brush( Color( COL_RED ), BRUSH_CROSS ) );
- DrawEllipse( Rectangle( Point( nX/2, nY/3),
- Point( nX/2+nX/5, nY/2 ) ) );
-
- Brush aNullBrush( BRUSH_NULL );
- ChangeFillInBrush( aNullBrush );
- DrawEllipse( Rectangle( Point( nX/2, nY-nY/3),
- Point( nX/2+nX/5, nY-nY/4 ) ) );
-
- MapMode aOldMode = ChangeMapMode( MapMode() );
-
- String aStr( "Window " );
- aStr += nWinNum;
- DrawText( Point(), aStr );
-
- ChangeMapMode( aOldMode );
- }
-
- // --- PaintWindow::Resize() ---------------------------------------
-
- void PaintWindow::Resize()
- {
- nX = GetOutputSizePixel().Width();
- Invalidate();
- }
-
- // --- PaintWindow::Scroll() ---------------------------------------
-
- void PaintWindow::Scroll( ScrollBar* pScroll )
- {
- MapMode aMapMode( MAP_PIXEL,
- Point( 0, (pScroll->GetThumbPos()*-1)-40 ),
- Fraction( 1, 1 ), Fraction( 1, 1 ) );
- ChangeMapMode( aMapMode );
-
- Invalidate();
- }
-
- // --- PaintWindow::InitScroll() -----------------------------------
-
- void PaintWindow::InitScroll( ScrollBar* pScroll )
- {
- pScroll->ChangeRange( Range( 0, 440 ) );
- pScroll->ChangeLineSize( 3 );
- pScroll->ChangePageSize( 48 );
- pScroll->ChangeScrollHdl( LINK( this, PaintWindow, Scroll ) );
- Scroll( pScroll );
- }
-
- // --- AppWindow::AppWindow() --------------------------------------
-
- AppWindow::AppWindow() :
- WorkWindow( NULL, WB_APP | WB_STDWORK ),
- aPaint1( this ),
- aPaint2( this ),
- aSplitBar( this, WB_DRAG | WB_VSCROLL )
- {
- SetText( "SplitBar-Demo" );
-
- Show();
-
- aSplitBar.ChangeSplitHdl( LINK( this, AppWindow,
- ChangeSplit ) );
-
- short nY = GetOutputSizePixel().Height();
- aSplitBar.ChangeSplitPosPixel( (nY-20) * 2 / 3 );
-
- aPaint1.InitScroll( aSplitBar.GetScrollBar1() );
- aPaint2.InitScroll( aSplitBar.GetScrollBar2() );
- }
-
- // --- AppWindow::Resize() -----------------------------------------
-
- void AppWindow::Resize()
- {
- short nWidth = aSplitBar.GetSizePixel().Width();
- short nX = GetOutputSizePixel().Width()-nWidth-10;
- short nY = GetOutputSizePixel().Height()-20;
-
- aSplitBar.SetPosSizePixel( Point( nX, 10 ),
- Size( nWidth, nY ) );
- aSplitBar.ChangeDragRectPixel( Rectangle( 10, 10, nX, nY ),
- this );
- short nNewY = aSplitBar.GetSplitPosPixel();
-
- if ( nNewY < 10)
- nNewY= 10;
-
- aSplitBar.Show();
-
- aSplitBar.GetScrollBar1()->ChangeVisibleSize( nNewY-13 );
- aPaint1.SetPosSizePixel( Point( 10, 10 ),
- Size( nX-12, nNewY-13 ) );
- aPaint1.Show();
-
- aSplitBar.GetScrollBar2()->ChangeVisibleSize( nY-nNewY+7 );
- aPaint2.SetPosSizePixel( Point( 10, nNewY + 3 ),
- Size( nX-12, nY-nNewY+7 ) );
- aPaint2.Show();
- }
-
- // --- AppWindow::ChangeSplit() ------------------------------------
-
- void AppWindow::ChangeSplit( SplitBar* )
- {
- Resize();
- }
-
- // --- MyApp::Main() -----------------------------------------------
-
- void MyApp::Main( int, char*[] )
- {
- AppWindow aWindow;
- Execute();
- }
-
- // --- aMyApp ------------------------------------------------------
-
- MyApp aMyApp;
-