1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: printer.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basic.hxx"
34 #ifndef _PRINT_HXX //autogen
35 #include <vcl/print.hxx>
37 #ifndef _DIALOG_HXX //autogen
38 #include <vcl/dialog.hxx>
40 #ifndef _FIXED_HXX //autogen
41 #include <vcl/fixed.hxx>
43 #ifndef _BUTTON_HXX //autogen
44 #include <vcl/button.hxx>
46 #ifndef _BASIC_TTRESHLP_HXX
47 #include <basic/ttstrhlp.hxx>
53 #include "printer.hxx"
58 class PrintingDialog
: public ModelessDialog
{
63 PrintingDialog( Window
*, BasicPrinter
*, ResId
&, String
& );
64 void ChangeMessage( short );
67 BasicPrinter::BasicPrinter() : Printer()
69 nPage
= 0; nLine
= 9999;
70 SetMapMode( MapMode( MAP_POINT
) );
71 Size
s( GetOutputSize() );
73 Font
aFont( FAMILY_MODERN
, Size( 0, 10 ) );
74 aFont
.SetPitch( PITCH_FIXED
);
76 // Output: 6 Lines/Inch = 12 Point
77 nLines
= (short) s
.Height() / 12;
79 SetStartPrintHdl( LINK( this, BasicPrinter
, StartPrintHdl
) );
80 SetEndPrintHdl( LINK( this, BasicPrinter
, EndPrintHdl
) );
81 SetPrintPageHdl( LINK( this, BasicPrinter
, PrintPageHdl
) );
84 void BasicPrinter::Header()
86 if( nPage
) EndPage();
90 String
aPage( SttResId( IDS_PAGE
) );
91 aPage
.Append( String::CreateFromInt32(nPage
) );
92 aHdr
= aFile
.Copy( 0, 80 - aPage
.Len() );
93 aHdr
.Expand( 80 - aPage
.Len(), ' ' );
95 DrawText( Point( 0, 0 ), aHdr
);
99 void BasicPrinter::Print( const String
& rFile
, const String
& rText
, BasicFrame
*pFrame
)
101 nPage
= 0; nLine
= 9999;
104 SttResId
aResId( IDD_PRINT_DIALOG
);
105 pDlg
= new PrintingDialog
106 ( aBasicApp
.pFrame
, this, aResId
, aFile
);
107 // Set position of dialog
108 Size s1
= aBasicApp
.pFrame
->GetSizePixel();
109 Size s2
= pDlg
->GetSizePixel();
110 pDlg
->SetPosPixel( Point( (s1
.Width() - s2
.Width() ) / 2,
111 (s1
.Height()- s2
.Height() ) / 2 ) );
112 // Disable PRINT-Menu
113 MenuBar
* pBar
= pFrame
->GetMenuBar();
114 Menu
* pFileMenu
= pBar
->GetPopupMenu( RID_APPFILE
);
115 pFileMenu
->EnableItem( RID_FILEPRINT
, FALSE
);
117 pDlg
->ChangeMessage( 1 );
122 while( nDone
< rText
.Len() )
124 if( nLine
>= nLines
) Header();
125 xub_StrLen nLineEnd
= std::min( rText
.Search( '\n', nDone
), rText
.Search( '\r', nDone
) );
126 DrawText( Point( 0, nLine
* nYoff
), rText
, nDone
, nLineEnd
-nDone
-1 );
128 if( nDone
<= rText
.Len() && rText
.GetChar(nDone
) == '\r' ) nDone
++;
129 if( nDone
<= rText
.Len() && rText
.GetChar(nDone
) == '\n' ) nDone
++;
131 Application::Reschedule();
136 while( IsPrinting() ) Application::Reschedule();
137 delete pDlg
; pDlg
= NULL
;
138 pFileMenu
->EnableItem( RID_FILEPRINT
, TRUE
);
141 IMPL_LINK_INLINE_START( BasicPrinter
, StartPrintHdl
, Printer
*, pPrinter
)
143 (void) pPrinter
; /* avoid warning about unused parameter */
148 IMPL_LINK_INLINE_END( BasicPrinter
, StartPrintHdl
, Printer
*, pPrinter
)
150 IMPL_LINK_INLINE_START( BasicPrinter
, EndPrintHdl
, Printer
*, pPrinter
)
152 (void) pPrinter
; /* avoid warning about unused parameter */
157 IMPL_LINK_INLINE_END( BasicPrinter
, EndPrintHdl
, Printer
*, pPrinter
)
159 IMPL_LINK_INLINE_START( BasicPrinter
, PrintPageHdl
, Printer
*, pPrinter
)
161 (void) pPrinter
; /* avoid warning about unused parameter */
163 pDlg
->ChangeMessage( nPage
);
166 IMPL_LINK_INLINE_END( BasicPrinter
, PrintPageHdl
, Printer
*, pPrinter
)
168 IMPL_LINK_INLINE( BasicPrinter
, Abort
, void *, EMPTYARG
,
175 /////////////////////////////////////////////////////////////////////////
177 PrintingDialog::PrintingDialog
178 ( Window
* pParent
, BasicPrinter
* pPrn
, ResId
& rId
, String
& rName
)
179 : ModelessDialog( pParent
, rId
)
181 , aText ( this, ResId( RID_TEXT
, *rId
.GetResMgr() ) )
182 , aCancel( this, ResId( RID_CANCEL
, *rId
.GetResMgr() ) )
185 aCancel
.SetClickHdl( LINK( pPrn
, BasicPrinter
, Abort
) );
188 void PrintingDialog::ChangeMessage( short nPage
)
190 String
aMsg( SttResId( IDS_PRINTMSG
) );
192 aMsg
+= CUniString("\n");
193 aMsg
+= String( SttResId( IDS_PAGE
) );
194 aMsg
+= String::CreateFromInt32( nPage
);
195 aText
.SetText( aMsg
);