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