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