home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- * PRINT.CXX
- * (c) 1992-1994 STAR DIVISION
- *******************************************************************/
-
- #include <sv.hxx>
-
- #include "prvdlg.hxx"
- #include "print.hrc"
-
- Printer* pPrinter;
-
- // --- class MyApp -------------------------------------------------
-
- class MyApp : public Application
- {
- public:
- virtual void Main( int, char*[] );
- };
-
- // --- class AbortDialog -------------------------------------------
-
- class AbortDialog : public ModelessDialog
- {
- private:
- FixedText aText;
- CancelButton aAbort;
-
- public:
- AbortDialog( Window* pParent );
- void AbortHdl( CancelButton* );
- };
-
- // --- class InfoDialog --------------------------------------------
-
- class InfoDialog : public ModalDialog
- {
- private:
- FixedText aPrinterName;
- FixedText aPaperSize;
- FixedText aOutputSize;
- FixedText aPageOffset;
- FixedText aPaperBins;
- OKButton aOKButton;
-
- public:
- InfoDialog( Window* pParent );
- };
-
- // --- class AppWin ------------------------------------------------
-
- class AppWin : public WorkWindow
- {
- protected:
- AbortDialog aAbortDialog;
-
- public:
- AppWin();
-
- virtual void Paint( const Rectangle& );
- virtual void Resize();
-
- long MenuSelect( Menu* pMenu );
-
- void DoPrint();
- void DoSetup();
- void DoInfo();
- void DoPreview();
-
- void Print( OutputDevice* pOutDev, USHORT nPage );
- void PrintPageHdl( Preview* pPreview );
- void StartPrintHdl( Printer* pPrn );
- void EndPrintHdl( Printer* pPrn );
- };
-
- // --- AppWin::AppWin() --------------------------------------------
-
- AppWin::AppWin() :
- WorkWindow( NULL, WB_APP | WB_STDWORK ),
- aAbortDialog( this )
- {
- SetText( "Printer Demo" );
- }
-
- // --- AppWin::Paint() ---------------------------------------------
-
- void AppWin::Paint( const Rectangle& )
- {
- Print( this, 1 );
- }
-
- // --- AppWin::Resize() --------------------------------------------
-
- void AppWin::Resize()
- {
- Invalidate();
- }
-
- // --- AppWin::MenuSelect() ----------------------------------------
-
- long AppWin::MenuSelect( Menu* pMenu )
- {
- switch ( pMenu->GetCurItemId() )
- {
- case MI_SETUP:
- DoSetup();
- break;
-
- case MI_PRINT:
- DoPrint();
- break;
-
- case MI_INFO:
- DoInfo();
- break;
-
- case MI_PREVIEW:
- DoPreview();
- break;
-
- case MI_EXIT:
- Close();
- break;
- }
-
- return TRUE;
- }
-
- // --- AppWin::DoPrint() -------------------------------------------
-
- void AppWin::DoPrint()
- {
- PrintDialog aPrintDlg( this, WB_SVLOOK );
-
- aPrintDlg.ChangePrinter( pPrinter );
- aPrintDlg.ChangeCopyCount( 1 );
- aPrintDlg.ChangeFirstPage( 1 );
- aPrintDlg.ChangeLastPage( 5 );
- aPrintDlg.EnablePageFields( TRUE );
- aPrintDlg.EnableSelection( FALSE );
- aPrintDlg.EnableCollate( TRUE );
- aPrintDlg.CheckCollate( FALSE );
-
- if ( aPrintDlg.Execute() )
- {
- pPrinter->SetCopyCount( aPrintDlg.GetCopyCount(),
- aPrintDlg.IsCollateChecked() );
-
- if ( !pPrinter->StartJob( "StarView-Print" ) )
- {
- ErrorBox( NULL, WB_OK, "StartJob Error" ).Execute();
- return;
- }
- Disable();
-
- USHORT nFirstPage = aPrintDlg.GetFirstPage();
- USHORT nLastPage = aPrintDlg.GetLastPage();
-
- for ( USHORT i = nFirstPage; i <= nLastPage; i++ )
- {
- pPrinter->StartPage();
- Print( pPrinter, i );
- pPrinter->EndPage();
- }
- pPrinter->EndJob();
-
- Enable();
- }
- }
-
- // --- AppWin::DoSetup() -------------------------------------------
-
- void AppWin::DoSetup()
- {
- PrinterSetupDialog aSetupDlg( this, WB_SVLOOK );
- aSetupDlg.ChangePrinter( pPrinter );
- aSetupDlg.Execute();
- }
-
- // --- AppWin::DoInfo() --------------------------------------------
-
- void AppWin::DoInfo()
- {
- InfoDialog( this ).Execute();
- }
-
- // --- AppWin::DoPreview() -----------------------------------------
-
- void AppWin::DoPreview()
- {
- JobSetup* pSetup;
-
- pSetup = (JobSetup*)new char[ pPrinter->GetJobSetupSize() ];
- pPrinter->GetJobSetup( pSetup );
-
- PreviewDialog aDialog( this, pSetup );
- aDialog.ChangeRequestPageHdl( LINK( this,
- AppWin, PrintPageHdl ) );
- aDialog.Execute();
- delete pSetup;
- }
-
- // --- AppWin::Print() ---------------------------------------------
-
- void AppWin::Print( OutputDevice* pOutDev, USHORT nPage )
- {
- pOutDev->Push();
- MapMode aMapMode( MAP_10TH_MM );
- pOutDev->ChangeMapMode( aMapMode );
-
- Size aOutputSize = pOutDev->GetOutputSize();
-
- Font aFont;
- aFont.ChangeFamily( FAMILY_SWISS );
- aFont.ChangePitch( PITCH_VARIABLE );
- aFont.ChangeSize( Size( 0, 180 ) );
- aFont.ChangeName( "Helvetica" );
- pOutDev->ChangeFont( aFont );
-
- // Geometrische Objeke zeichnen
- Size aSize( (aOutputSize.Width()-100)/3, 500 );
- Color aRedColor( COL_RED );
- Brush aBrush( aRedColor );
- pOutDev->ChangeFillInBrush( aBrush );
- pOutDev->DrawRect( Rectangle( Point( 25, 0 ), aSize ) );
- aBrush.ChangeColor( Color( COL_GREEN ) );
- pOutDev->ChangeFillInBrush( aBrush );
- pOutDev->DrawEllipse( Rectangle( Point( aSize.Width()+50, 0 ),
- aSize ) );
- aBrush.ChangeColor( Color( COL_BLUE ) );
- pOutDev->ChangeFillInBrush( aBrush );
- Point aPtAry[ 3 ];
- aPtAry[0] = Point( aSize.Width()*2+75 + aSize.Width()/2, 0 );
- aPtAry[1] = Point( aSize.Width()*3+75, aSize.Height() );
- aPtAry[2] = Point( aSize.Width()*2+75, aSize.Height() );
- pOutDev->DrawPolygon( Polygon( 3, aPtAry ) );
-
-
- aSize.Height() += 100;
- String aText( "StarView Printdemo" );
- Size aTextSize = pOutDev->GetTextSize( aText );
- pOutDev->DrawText( Point( (aOutputSize.Width()>>1) -
- (aTextSize.Width()>>1),
- aSize.Height() ),
- aText );
- aSize.Height() += aTextSize.Height() + 50;
-
- aText = String( "Page : " ) + String( nPage );
- aTextSize = pOutDev->GetTextSize( aText );
- pOutDev->DrawText( Point( (aOutputSize.Width()>>1) -
- (aTextSize.Width()>>1),
- aSize.Height() ),
- aText );
- aSize.Height() += aTextSize.Height() + 50;
-
- Pen aPen;
- aPen.ChangeWidth( 15 );
- pOutDev->ChangePen( aPen );
- pOutDev->DrawLine( Point( 300, aSize.Height() ),
- Point( aOutputSize.Width()-300,
- aSize.Height() ) );
-
- if ( aOutputSize.Height() > (aSize.Height() + 150) )
- {
- aFont.ChangeSize( Size( 0, 40 ) );
- pOutDev->ChangeFont( aFont );
- aSize.Height() = aOutputSize.Height()-100;
-
- aText = "This is the end of the page.";
- aTextSize = pOutDev->GetTextSize( aText );
- pOutDev->DrawText( Point( (aOutputSize.Width()>>1) -
- (aTextSize.Width()>>1),
- aSize.Height() ),
- aText );
- aSize.Height() += aTextSize.Height() + 50;
-
- pOutDev->DrawLine( Point( 0, aSize.Height() ),
- Point( aOutputSize.Width(),
- aSize.Height() ) );
- }
-
- pOutDev->Pop();
- }
-
- // --- AppWin::PrintPageHdl() --------------------------------------
-
- void AppWin::PrintPageHdl( Preview* pPreview )
- {
- Print( (Printer*)pPreview, pPreview->GetCurPage() );
- }
-
- // --- AppWin::StartPrintHdl() -------------------------------------
-
- void AppWin::StartPrintHdl( Printer* )
- {
- pApp->GetAppMenu()->GetPopupMenu( POPUP_PRINTER )->
- EnableItem( MI_PRINT, FALSE );
- aAbortDialog.Show();
- }
-
- // --- AppWin::EndPrintHdl() ---------------------------------------
-
- void AppWin::EndPrintHdl( Printer* )
- {
- pApp->GetAppMenu()->GetPopupMenu( POPUP_PRINTER )->
- EnableItem( MI_PRINT, TRUE );
- aAbortDialog.Hide();
- }
-
- // --- AbortDialog::AbortDialog() ----------------------------------
-
- AbortDialog::AbortDialog( Window* pParent ) :
- ModelessDialog( pParent, ResId( DLG_ABORT ) ),
- aText( this, ResId( DA_ABORTTEXT ) ),
- aAbort( this, ResId( DA_ABORT ) )
- {
- FreeResource();
-
- aAbort.ChangeClickHdl( LINK( this, AbortDialog, AbortHdl ) );
- }
-
- // --- AbortDialog::AbortHdl() -------------------------------------
-
- void AbortDialog::AbortHdl( CancelButton* )
- {
- pPrinter->AbortJob();
- }
-
- // --- InfoDialog::InfoDialog() ------------------------------------
-
- InfoDialog::InfoDialog( Window* pParent ) :
- ModalDialog( pParent, ResId( DLG_INFO ) ),
- aOKButton(this, ResId( DI_OK ) ),
- aPrinterName( this, ResId( DI_PRINTERNAME ) ),
- aPaperSize( this, ResId( DI_PAPERSIZE ) ),
- aOutputSize( this, ResId( DI_OUTPUTSIZE ) ),
- aPageOffset( this, ResId( DI_PAGEOFFSET ) ),
- aPaperBins( this, ResId( DI_PAPERBINS ) )
- {
- FreeResource();
-
- String aStr;
-
- aPrinterName.SetText( pPrinter->GetName() );
-
- Size aSize = pPrinter->GetPaperSizePixel();
- aStr = aPaperSize.GetText();
- aStr += aSize.Width();
- aStr += " ; ";
- aStr += aSize.Height();
- aPaperSize.SetText( aStr );
-
- aSize = pPrinter->GetOutputSizePixel();
- aStr = aOutputSize.GetText();
- aStr += aSize.Width();
- aStr += " ; ";
- aStr += aSize.Height();
- aOutputSize.SetText( aStr );
-
- Point aOffset = pPrinter->GetPageOffsetPixel();
- aStr = aPageOffset.GetText();
- aStr += aOffset.X();
- aStr += " ; ";
- aStr += aOffset.Y();
- aPageOffset.SetText( aStr );
-
- aStr = aPaperBins.GetText();
- aStr.Insert( String( pPrinter->GetPaperBinCount() ), 0 );
- aPaperBins.SetText( aStr );
- }
-
- // --- MyApp::Main() -----------------------------------------------
-
- void MyApp::Main( int, char*[] )
- {
- EnableSVLook();
-
- AppWin aAppWin;
- MenuBar aAppMenu( ResId( MENU_APPMENU ) );
-
- aAppMenu.PushSelectHdl( LINK( &aAppWin,
- AppWin, MenuSelect ) );
- ChangeAppMenu( &aAppMenu );
-
- aAppWin.Show();
-
- pPrinter = new Printer();
- pPrinter->ChangeStartPrintHdl( LINK( &aAppWin,
- AppWin, StartPrintHdl ) );
- pPrinter->ChangeEndPrintHdl( LINK( &aAppWin,
- AppWin, EndPrintHdl ) );
-
- Execute();
-
- delete pPrinter;
- }
-
- // --- aMyApp ------------------------------------------------------
-
- MyApp aMyApp;
-