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