1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: virtoutp.cxx,v $
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"
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"
47 /*************************************************************************
49 *************************************************************************/
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
)
65 pOut
->Push( PUSH_FILLCOLOR
|PUSH_LINECOLOR
);
66 pOut
->SetLineColor( eColor
);
68 pOut
->DrawRect( rRect
);
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.
80 BOOL
SwRootFrm::FlushVout()
82 if( SwRootFrm::pVout
->IsFlushable() )
84 SwRootFrm::pVout
->_Flush();
90 BOOL
SwRootFrm::HasSameRect( const SwRect
& rRect
)
92 if( SwRootFrm::pVout
->IsFlushable() )
93 return ( rRect
== SwRootFrm::pVout
->GetOrgRect() );
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.
112 input parameter - constant instance of the original output device, for which
113 the virtual output device is created.
116 input/output parameter - instance of the virtual output device.
119 input/output parameter - instance of the mapping mode, which will be set
120 at the virtual output device.
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
,
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 /*************************************************************************
141 *************************************************************************/
143 // rSize muss in Pixel-Koordinaten vorliegen!
144 BOOL
SwLayVout::DoesFit( const Size
&rNew
)
146 if( rNew
.Height() > VIRTUALHEIGHT
)
148 if( rNew
.Width() <= 0 || rNew
.Height() <= 0 )
150 if( rNew
.Width() <= aSize
.Width() )
154 pVirDev
= new VirtualDevice();
155 pVirDev
->SetLineColor();
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
) )
177 /*************************************************************************
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
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
)
190 if( pShell
->GetViewOptions()->IsTest3() )
197 bOn
= bOn
&& !nCount
&& rRect
.HasArea() && pShell
->GetWin();
203 OutputDevice
*pO
= pSh
->GetOut();
204 // Auf dem Drucker oder einem virt. Outputdevice wird nicht getrickst...
205 if( OUTDEV_WINDOW
!= pO
->GetOutDevType() )
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() ) )
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>
245 /*************************************************************************
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
);