1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 32 #include <vcl/window.hxx> 33 34 #include "hintids.hxx" 35 #include "viewsh.hxx" 36 #include "virtoutp.hxx" 37 #include "viewopt.hxx" 38 #include "rootfrm.hxx" 39 // OD 12.11.2002 #96272# - include declaration for <SetMappingForVirtDev> 40 #include "setmapvirtdev.hxx" 41 42 #ifdef DBG_UTIL 43 44 /************************************************************************* 45 * class DbgRect 46 *************************************************************************/ 47 48 class DbgRect 49 { 50 OutputDevice *pOut; 51 public: 52 DbgRect( OutputDevice *pOut, const Rectangle &rRect, 53 const ColorData eColor = COL_LIGHTBLUE ); 54 }; 55 56 inline DbgRect::DbgRect( OutputDevice *pOutDev, const Rectangle &rRect, 57 const ColorData eColor ) 58 :pOut( pOutDev ) 59 { 60 if( pOut ) 61 { 62 pOut->Push( PUSH_FILLCOLOR|PUSH_LINECOLOR ); 63 pOut->SetLineColor( eColor ); 64 pOut->SetFillColor(); 65 pOut->DrawRect( rRect ); 66 pOut->Pop(); 67 } 68 } 69 70 #endif 71 72 /* class SwLayVout verwaltet das virtuelle Outputdevice 73 * Es gibt von dieser Klasse einen statischen Member am RootFrm, 74 * dieser wird in _FrmInit angelegt und in _FrmFinit zerstoert. 75 * */ 76 77 sal_Bool SwRootFrm::FlushVout() 78 { 79 if( SwRootFrm::pVout->IsFlushable() ) 80 { 81 SwRootFrm::pVout->_Flush(); 82 return sal_True; 83 } 84 return sal_False; 85 } 86 87 sal_Bool SwRootFrm::HasSameRect( const SwRect& rRect ) 88 { 89 if( SwRootFrm::pVout->IsFlushable() ) 90 return ( rRect == SwRootFrm::pVout->GetOrgRect() ); 91 return sal_False; 92 } 93 94 /** method to set mapping/pixel offset for virtual output device 95 96 OD 12.11.2002 #96272# - method implements two solutions for the mapping of 97 the virtual output device: 98 The old solution set the origin of the mapping mode, which will be used in 99 the virtual output device. This causes several paint errors, because of the 100 different roundings in the virtual output device and the original output device. 101 The new solution avoids the rounding differences between virtual and original 102 output device by setting a pixel offset at the virtual output device. 103 A define controls, which solution is used, in order to switch in escalation 104 back to old solution. 105 106 @author OD 107 108 @param _pOrgOutDev 109 input parameter - constant instance of the original output device, for which 110 the virtual output device is created. 111 112 @param _pVirDev 113 input/output parameter - instance of the virtual output device. 114 115 @param _pMapMode 116 input/output parameter - instance of the mapping mode, which will be set 117 at the virtual output device. 118 119 @param _rNewOrigin 120 input parameter - constant instance of the origin, which will be used in 121 the virtual output device 122 */ 123 // define to control, if old or new solution for setting the mapping for 124 // an virtual output device is used. 125 void SetMappingForVirtDev( const Point& _rNewOrigin, 126 MapMode* , 127 const OutputDevice* _pOrgOutDev, 128 VirtualDevice* _pVirDev ) 129 { 130 // new solution: set pixel offset at virtual output device 131 Point aPixelOffset = _pOrgOutDev->LogicToPixel( _rNewOrigin ); 132 _pVirDev->SetPixelOffset( Size( -aPixelOffset.X(), -aPixelOffset.Y() ) ); 133 } 134 135 136 /************************************************************************* 137 * SwVOut::DoesFit() 138 *************************************************************************/ 139 140 // rSize muss in Pixel-Koordinaten vorliegen! 141 sal_Bool SwLayVout::DoesFit( const Size &rNew ) 142 { 143 if( rNew.Height() > VIRTUALHEIGHT ) 144 return sal_False; 145 if( rNew.Width() <= 0 || rNew.Height() <= 0 ) 146 return sal_False; 147 if( rNew.Width() <= aSize.Width() ) 148 return sal_True; 149 if( !pVirDev ) 150 { 151 pVirDev = new VirtualDevice(); 152 pVirDev->SetLineColor(); 153 if( pOut ) 154 { 155 if( pVirDev->GetFillColor() != pOut->GetFillColor() ) 156 pVirDev->SetFillColor( pOut->GetFillColor() ); 157 } 158 } 159 160 if( rNew.Width() > aSize.Width() ) 161 { 162 aSize.Width() = rNew.Width(); 163 if( !pVirDev->SetOutputSizePixel( aSize ) ) 164 { 165 delete pVirDev; 166 pVirDev = NULL; 167 aSize.Width() = 0; 168 return sal_False; 169 } 170 } 171 return sal_True; 172 } 173 174 /************************************************************************* 175 * SwLayVout::Enter 176 *************************************************************************/ 177 /// OD 27.09.2002 #103636# - change 2nd parameter <rRect> - no longer <const> 178 /// in order to return value of class member variable <aRect>, if virtual 179 /// output is used. 180 /// <aRect> contains the rectangle that represents the area the virtual 181 /// output device is used for and that is flushed at the end. 182 void SwLayVout::Enter( ViewShell *pShell, SwRect &rRect, sal_Bool bOn ) 183 { 184 Flush(); 185 186 #ifdef DBG_UTIL 187 if( pShell->GetViewOptions()->IsTest3() ) 188 { 189 ++nCount; 190 return; 191 } 192 #endif 193 194 bOn = bOn && !nCount && rRect.HasArea() && pShell->GetWin(); 195 ++nCount; 196 if( bOn ) 197 { 198 pSh = pShell; 199 pOut = NULL; 200 OutputDevice *pO = pSh->GetOut(); 201 // Auf dem Drucker oder einem virt. Outputdevice wird nicht getrickst... 202 if( OUTDEV_WINDOW != pO->GetOutDevType() ) 203 return; 204 205 pOut = pO; 206 Size aPixSz( pOut->PixelToLogic( Size( 1,1 )) ); 207 SwRect aTmp( rRect ); 208 aTmp.SSize().Width() += aPixSz.Width()/2 + 1; 209 aTmp.SSize().Height()+= aPixSz.Height()/2 + 1; 210 Rectangle aTmpRect( pO->LogicToPixel( aTmp.SVRect() ) ); 211 212 ASSERT( !pSh->GetWin()->IsReallyVisible() || 213 aTmpRect.GetWidth() <= pSh->GetWin()->GetOutputSizePixel().Width() + 2, 214 "Paintwidth bigger than visarea?" ); 215 // Passt das Rechteck in unseren Buffer ? 216 if( !DoesFit( aTmpRect.GetSize() ) ) 217 { 218 pOut = NULL; 219 return; 220 } 221 222 aRect = SwRect( pO->PixelToLogic( aTmpRect ) ); 223 224 SetOutDev( pSh, pVirDev ); 225 226 if( pVirDev->GetFillColor() != pOut->GetFillColor() ) 227 pVirDev->SetFillColor( pOut->GetFillColor() ); 228 229 MapMode aMapMode( pOut->GetMapMode() ); 230 // OD 12.11.2002 #96272# - use method to set mapping 231 //aMapMode.SetOrigin( Point(0,0) - aRect.Pos() ); 232 ::SetMappingForVirtDev( aRect.Pos(), &aMapMode, pOut, pVirDev ); 233 234 if( aMapMode != pVirDev->GetMapMode() ) 235 pVirDev->SetMapMode( aMapMode ); 236 237 /// OD 27.09.2002 #103636# - set value of parameter <rRect> 238 rRect = aRect; 239 } 240 } 241 242 /************************************************************************* 243 * SwLayVout::Flush() 244 *************************************************************************/ 245 246 void SwLayVout::_Flush() 247 { 248 ASSERT( pVirDev, "SwLayVout::DrawOut: nothing left Toulouse" ); 249 Rectangle aTmp( aRect.SVRect() ); 250 pOut->DrawOutDev( aRect.Pos(), aRect.SSize(), 251 aRect.Pos(), aRect.SSize(), *pVirDev ); 252 SetOutDev( pSh, pOut ); 253 pOut = NULL; 254 } 255 256 257