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