1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5efeef26fSAndrew Rist * distributed with this work for additional information
6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist * software distributed under the License is distributed on an
15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17efeef26fSAndrew Rist * specific language governing permissions and limitations
18efeef26fSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20efeef26fSAndrew Rist *************************************************************/
21efeef26fSAndrew Rist
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_sw.hxx"
24cdf0e10cSrcweir
25cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <hintids.hxx>
28cdf0e10cSrcweir #include <vcl/window.hxx>
29cdf0e10cSrcweir #include <vcl/oldprintadaptor.hxx>
30cdf0e10cSrcweir #include <sfx2/printer.hxx>
31cdf0e10cSrcweir #include <sfx2/progress.hxx>
32cdf0e10cSrcweir #include <pvprtdat.hxx>
33cdf0e10cSrcweir #include <viewsh.hxx>
34cdf0e10cSrcweir #include <pagefrm.hxx>
35cdf0e10cSrcweir #include <rootfrm.hxx>
36cdf0e10cSrcweir #include <viewimp.hxx>
37cdf0e10cSrcweir #include <viewopt.hxx>
38cdf0e10cSrcweir #include <printdata.hxx>
39cdf0e10cSrcweir #include <fldbas.hxx>
40cdf0e10cSrcweir #include <ptqueue.hxx>
41cdf0e10cSrcweir #include <swregion.hxx>
42cdf0e10cSrcweir #include <hints.hxx>
43cdf0e10cSrcweir #include <fntcache.hxx>
44cdf0e10cSrcweir
458873b33aSmseidel #include <statstr.hrc> // Text for SfxProgress
46cdf0e10cSrcweir #include <comcore.hrc>
47cdf0e10cSrcweir
48cdf0e10cSrcweir #include <IDocumentFieldsAccess.hxx>
49cdf0e10cSrcweir #include <IDocumentDeviceAccess.hxx>
50cdf0e10cSrcweir
51cdf0e10cSrcweir
52cdf0e10cSrcweir using namespace ::com::sun::star;
53cdf0e10cSrcweir
54cdf0e10cSrcweir
55cdf0e10cSrcweir // OD 12.12.2002 #103492#
PagePreviewLayout()56cdf0e10cSrcweir SwPagePreviewLayout* ViewShell::PagePreviewLayout()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir return Imp()->PagePreviewLayout();
59cdf0e10cSrcweir }
60cdf0e10cSrcweir
ShowPreViewSelection(sal_uInt16 nSelPage)61cdf0e10cSrcweir void ViewShell::ShowPreViewSelection( sal_uInt16 nSelPage )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir Imp()->InvalidateAccessiblePreViewSelection( nSelPage );
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
66cdf0e10cSrcweir /** adjust view options for page preview
67cdf0e10cSrcweir
68cdf0e10cSrcweir OD 09.01.2003 #i6467#
69cdf0e10cSrcweir */
AdjustOptionsForPagePreview(SwPrintData const & rPrintOptions)70cdf0e10cSrcweir void ViewShell::AdjustOptionsForPagePreview(SwPrintData const& rPrintOptions)
71cdf0e10cSrcweir {
72cdf0e10cSrcweir if ( !IsPreView() )
73cdf0e10cSrcweir {
748873b33aSmseidel ASSERT( false, "view shell doesn't belong to a page preview - no adjustment of its view options");
75cdf0e10cSrcweir return;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
78cdf0e10cSrcweir PrepareForPrint( rPrintOptions );
79cdf0e10cSrcweir
80cdf0e10cSrcweir return;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
83cdf0e10cSrcweir // print brochure
84cdf0e10cSrcweir // OD 05.05.2003 #i14016# - consider empty pages on calculation of the scaling
85cdf0e10cSrcweir // for a page to be printed.
PrintProspect(OutputDevice * pOutDev,const SwPrintData & rPrintData,sal_Int32 nRenderer)86cdf0e10cSrcweir void ViewShell::PrintProspect(
87cdf0e10cSrcweir OutputDevice *pOutDev,
88cdf0e10cSrcweir const SwPrintData &rPrintData,
89cdf0e10cSrcweir sal_Int32 nRenderer // the index in the vector of prospect pages to be printed
90cdf0e10cSrcweir )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir const sal_Int32 nMaxRenderer = rPrintData.GetRenderData().GetPagePairsForProspectPrinting().size() - 1;
93cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
94cdf0e10cSrcweir DBG_ASSERT( 0 <= nRenderer && nRenderer <= nMaxRenderer, "nRenderer out of bounds");
95cdf0e10cSrcweir #endif
96cdf0e10cSrcweir Printer *pPrinter = dynamic_cast< Printer * >(pOutDev);
97cdf0e10cSrcweir if (!pPrinter || nMaxRenderer < 0 || nRenderer < 0 || nRenderer > nMaxRenderer)
98cdf0e10cSrcweir return;
99cdf0e10cSrcweir
100cdf0e10cSrcweir // save settings of OutputDevice (should be done always since the
101cdf0e10cSrcweir // output device is now provided by a call from outside the Writer)
102cdf0e10cSrcweir pPrinter->Push();
103cdf0e10cSrcweir
104cdf0e10cSrcweir std::pair< sal_Int32, sal_Int32 > rPagesToPrint =
105cdf0e10cSrcweir rPrintData.GetRenderData().GetPagePairsForProspectPrinting()[ nRenderer ];
106cdf0e10cSrcweir // const sal_uInt16 nPageMax = static_cast< sal_uInt16 >(rPagesToPrint.first > rPagesToPrint.second ?
107cdf0e10cSrcweir // rPagesToPrint.first : rPagesToPrint.second);
108cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
109cdf0e10cSrcweir DBG_ASSERT( rPagesToPrint.first == -1 || rPrintData.GetRenderData().GetValidPagesSet().count( rPagesToPrint.first ) == 1, "first Page not valid" );
110cdf0e10cSrcweir DBG_ASSERT( rPagesToPrint.second == -1 || rPrintData.GetRenderData().GetValidPagesSet().count( rPagesToPrint.second ) == 1, "second Page not valid" );
111cdf0e10cSrcweir #endif
112cdf0e10cSrcweir
1138873b33aSmseidel // create new shell for printer
114cdf0e10cSrcweir ViewShell aShell( *this, 0, pPrinter );
115cdf0e10cSrcweir
116cdf0e10cSrcweir SET_CURR_SHELL( &aShell );
117cdf0e10cSrcweir
118cdf0e10cSrcweir aShell.PrepareForPrint( rPrintData );
119cdf0e10cSrcweir
1208873b33aSmseidel //!! applying view options and formatting the document should now only be done in getRendererCount!
121cdf0e10cSrcweir
122cdf0e10cSrcweir MapMode aMapMode( MAP_TWIP );
123cdf0e10cSrcweir Size aPrtSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), aMapMode ) );
124cdf0e10cSrcweir
125cdf0e10cSrcweir SwTwips nMaxRowSz, nMaxColSz;
126cdf0e10cSrcweir
127cdf0e10cSrcweir const SwPageFrm *pStPage = 0;
128cdf0e10cSrcweir const SwPageFrm *pNxtPage = 0;
129cdf0e10cSrcweir const SwRenderData::ValidStartFramesMap_t &rFrms = rPrintData.GetRenderData().GetValidStartFrames();
130cdf0e10cSrcweir if (rPagesToPrint.first > 0)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir SwRenderData::ValidStartFramesMap_t::const_iterator aIt( rFrms.find( rPagesToPrint.first ) );
133cdf0e10cSrcweir DBG_ASSERT( aIt != rFrms.end(), "failed to find start frame" );
134cdf0e10cSrcweir pStPage = aIt->second;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir if (rPagesToPrint.second > 0)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir SwRenderData::ValidStartFramesMap_t::const_iterator aIt( rFrms.find( rPagesToPrint.second ) );
139cdf0e10cSrcweir DBG_ASSERT( aIt != rFrms.end(), "failed to find start frame" );
140cdf0e10cSrcweir pNxtPage = aIt->second;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
143cdf0e10cSrcweir // OD 05.05.2003 #i14016# - consider empty pages on calculation
144cdf0e10cSrcweir // of page size, used for calculation of scaling.
145cdf0e10cSrcweir Size aSttPageSize;
146cdf0e10cSrcweir if ( pStPage )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir if ( pStPage->IsEmptyPage() )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir if ( pStPage->GetPhyPageNum() % 2 == 0 )
151cdf0e10cSrcweir aSttPageSize = pStPage->GetPrev()->Frm().SSize();
152cdf0e10cSrcweir else
153cdf0e10cSrcweir aSttPageSize = pStPage->GetNext()->Frm().SSize();
154cdf0e10cSrcweir }
155cdf0e10cSrcweir else
156cdf0e10cSrcweir {
157cdf0e10cSrcweir aSttPageSize = pStPage->Frm().SSize();
158cdf0e10cSrcweir }
159cdf0e10cSrcweir }
160cdf0e10cSrcweir Size aNxtPageSize;
161cdf0e10cSrcweir if ( pNxtPage )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir if ( pNxtPage->IsEmptyPage() )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir if ( pNxtPage->GetPhyPageNum() % 2 == 0 )
166cdf0e10cSrcweir aNxtPageSize = pNxtPage->GetPrev()->Frm().SSize();
167cdf0e10cSrcweir else
168cdf0e10cSrcweir aNxtPageSize = pNxtPage->GetNext()->Frm().SSize();
169cdf0e10cSrcweir }
170cdf0e10cSrcweir else
171cdf0e10cSrcweir {
172cdf0e10cSrcweir aNxtPageSize = pNxtPage->Frm().SSize();
173cdf0e10cSrcweir }
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir if( !pStPage )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir nMaxColSz = 2 * aNxtPageSize.Width();
179cdf0e10cSrcweir nMaxRowSz = aNxtPageSize.Height();
180cdf0e10cSrcweir }
181cdf0e10cSrcweir else if( !pNxtPage )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir nMaxColSz = 2 * aSttPageSize.Width();
184cdf0e10cSrcweir nMaxRowSz = aSttPageSize.Height();
185cdf0e10cSrcweir }
186cdf0e10cSrcweir else
187cdf0e10cSrcweir {
188cdf0e10cSrcweir nMaxColSz = aNxtPageSize.Width() + aSttPageSize.Width();
189cdf0e10cSrcweir nMaxRowSz = Max( aNxtPageSize.Height(), aSttPageSize.Height() );
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir // den MapMode einstellen
193cdf0e10cSrcweir aMapMode.SetOrigin( Point() );
194cdf0e10cSrcweir {
195cdf0e10cSrcweir Fraction aScX( aPrtSize.Width(), nMaxColSz );
196cdf0e10cSrcweir Fraction aScY( aPrtSize.Height(), nMaxRowSz );
197cdf0e10cSrcweir if( aScX < aScY )
198cdf0e10cSrcweir aScY = aScX;
199cdf0e10cSrcweir
200cdf0e10cSrcweir {
201*20a4bcffSmseidel // für Drawing, damit diese ihre Objekte vernünftig Painten
202*20a4bcffSmseidel // können, auf "glatte" Prozentwerte setzen
203cdf0e10cSrcweir aScY *= Fraction( 1000, 1 );
204cdf0e10cSrcweir long nTmp = (long)aScY;
205cdf0e10cSrcweir if( 1 < nTmp )
206cdf0e10cSrcweir --nTmp;
207cdf0e10cSrcweir else
208cdf0e10cSrcweir nTmp = 1;
209cdf0e10cSrcweir aScY = Fraction( nTmp, 1000 );
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
212cdf0e10cSrcweir aMapMode.SetScaleY( aScY );
213cdf0e10cSrcweir aMapMode.SetScaleX( aScY );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir
216cdf0e10cSrcweir Size aTmpPrtSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), aMapMode ) );
217cdf0e10cSrcweir
218cdf0e10cSrcweir // calculate start point for equal border on all sides
219cdf0e10cSrcweir Point aSttPt( (aTmpPrtSize.Width() - nMaxColSz) / 2,
220cdf0e10cSrcweir (aTmpPrtSize.Height() - nMaxRowSz) / 2 );
221cdf0e10cSrcweir for( int nC = 0; nC < 2; ++nC )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir if( pStPage )
224cdf0e10cSrcweir {
225cdf0e10cSrcweir aShell.Imp()->SetFirstVisPageInvalid();
226cdf0e10cSrcweir aShell.aVisArea = pStPage->Frm();
227cdf0e10cSrcweir
228cdf0e10cSrcweir Point aPos( aSttPt );
229cdf0e10cSrcweir aPos -= aShell.aVisArea.Pos();
230cdf0e10cSrcweir // aPos -= aPrtOff;
231cdf0e10cSrcweir aMapMode.SetOrigin( aPos );
232cdf0e10cSrcweir pPrinter->SetMapMode( aMapMode );
233cdf0e10cSrcweir pStPage->GetUpper()->Paint( pStPage->Frm() );
234cdf0e10cSrcweir }
235cdf0e10cSrcweir
236cdf0e10cSrcweir pStPage = pNxtPage;
237cdf0e10cSrcweir aSttPt.X() += aTmpPrtSize.Width() / 2;
238cdf0e10cSrcweir }
239cdf0e10cSrcweir
240cdf0e10cSrcweir SwPaintQueue::Repaint();
241cdf0e10cSrcweir
2428873b33aSmseidel //!! applying/modifying view options and formatting the document should now only be done in getRendererCount!
243cdf0e10cSrcweir
244cdf0e10cSrcweir pFntCache->Flush();
245cdf0e10cSrcweir
246cdf0e10cSrcweir // restore settings of OutputDevice (should be done always now since the
247cdf0e10cSrcweir // output device is now provided by a call from outside the Writer)
248cdf0e10cSrcweir pPrinter->Pop();
249cdf0e10cSrcweir }
250*20a4bcffSmseidel
251*20a4bcffSmseidel /* vim: set noet sw=4 ts=4: */
252