xref: /trunk/main/vcl/source/gdi/outdev5.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <tools/ref.hxx>
32*cdf0e10cSrcweir #include <tools/debug.hxx>
33*cdf0e10cSrcweir #include <tools/poly.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <vcl/metaact.hxx>
36*cdf0e10cSrcweir #include <vcl/gdimtf.hxx>
37*cdf0e10cSrcweir #include <vcl/outdev.hxx>
38*cdf0e10cSrcweir #include <vcl/virdev.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <salgdi.hxx>
41*cdf0e10cSrcweir #include <svdata.hxx>
42*cdf0e10cSrcweir #include <outdata.hxx>
43*cdf0e10cSrcweir #include <outdev.h>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir // =======================================================================
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir DBG_NAMEEX( OutputDevice )
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir // =======================================================================
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir void OutputDevice::DrawRect( const Rectangle& rRect,
52*cdf0e10cSrcweir                              sal_uLong nHorzRound, sal_uLong nVertRound )
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir     DBG_TRACE( "OutputDevice::DrawRoundRect()" );
55*cdf0e10cSrcweir     DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     if ( mpMetaFile )
58*cdf0e10cSrcweir         mpMetaFile->AddAction( new MetaRoundRectAction( rRect, nHorzRound, nVertRound ) );
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir     if ( !IsDeviceOutputNecessary() || (!mbLineColor && !mbFillColor) || ImplIsRecordLayout() )
61*cdf0e10cSrcweir         return;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     const Rectangle aRect( ImplLogicToDevicePixel( rRect ) );
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir     if ( aRect.IsEmpty() )
66*cdf0e10cSrcweir         return;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     nHorzRound = ImplLogicWidthToDevicePixel( nHorzRound );
69*cdf0e10cSrcweir     nVertRound = ImplLogicHeightToDevicePixel( nVertRound );
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     // we need a graphics
72*cdf0e10cSrcweir     if ( !mpGraphics )
73*cdf0e10cSrcweir     {
74*cdf0e10cSrcweir         if ( !ImplGetGraphics() )
75*cdf0e10cSrcweir             return;
76*cdf0e10cSrcweir     }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     if ( mbInitClipRegion )
79*cdf0e10cSrcweir         ImplInitClipRegion();
80*cdf0e10cSrcweir     if ( mbOutputClipped )
81*cdf0e10cSrcweir         return;
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     if ( mbInitLineColor )
84*cdf0e10cSrcweir         ImplInitLineColor();
85*cdf0e10cSrcweir     if ( mbInitFillColor )
86*cdf0e10cSrcweir         ImplInitFillColor();
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     if ( !nHorzRound && !nVertRound )
89*cdf0e10cSrcweir         mpGraphics->DrawRect( aRect.Left(), aRect.Top(), aRect.GetWidth(), aRect.GetHeight(), this );
90*cdf0e10cSrcweir     else
91*cdf0e10cSrcweir     {
92*cdf0e10cSrcweir         const Polygon aRoundRectPoly( aRect, nHorzRound, nVertRound );
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir         if ( aRoundRectPoly.GetSize() >= 2 )
95*cdf0e10cSrcweir         {
96*cdf0e10cSrcweir             const SalPoint* pPtAry = (const SalPoint*) aRoundRectPoly.GetConstPointAry();
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir             if ( !mbFillColor )
99*cdf0e10cSrcweir                 mpGraphics->DrawPolyLine( aRoundRectPoly.GetSize(), pPtAry, this );
100*cdf0e10cSrcweir             else
101*cdf0e10cSrcweir                 mpGraphics->DrawPolygon( aRoundRectPoly.GetSize(), pPtAry, this );
102*cdf0e10cSrcweir         }
103*cdf0e10cSrcweir     }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     if( mpAlphaVDev )
106*cdf0e10cSrcweir         mpAlphaVDev->DrawRect( rRect, nHorzRound, nVertRound );
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir // -----------------------------------------------------------------------
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir void OutputDevice::DrawEllipse( const Rectangle& rRect )
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir     DBG_TRACE( "OutputDevice::DrawEllipse()" );
114*cdf0e10cSrcweir     DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     if ( mpMetaFile )
117*cdf0e10cSrcweir         mpMetaFile->AddAction( new MetaEllipseAction( rRect ) );
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     if  ( !IsDeviceOutputNecessary() || (!mbLineColor && !mbFillColor) || ImplIsRecordLayout() )
120*cdf0e10cSrcweir         return;
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     Rectangle aRect( ImplLogicToDevicePixel( rRect ) );
123*cdf0e10cSrcweir     if ( aRect.IsEmpty() )
124*cdf0e10cSrcweir         return;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     // we need a graphics
127*cdf0e10cSrcweir     if ( !mpGraphics )
128*cdf0e10cSrcweir     {
129*cdf0e10cSrcweir         if ( !ImplGetGraphics() )
130*cdf0e10cSrcweir             return;
131*cdf0e10cSrcweir     }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     if ( mbInitClipRegion )
134*cdf0e10cSrcweir         ImplInitClipRegion();
135*cdf0e10cSrcweir     if ( mbOutputClipped )
136*cdf0e10cSrcweir         return;
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir     if ( mbInitLineColor )
139*cdf0e10cSrcweir         ImplInitLineColor();
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir     Polygon aRectPoly( aRect.Center(), aRect.GetWidth() >> 1, aRect.GetHeight() >> 1 );
142*cdf0e10cSrcweir     if ( aRectPoly.GetSize() >= 2 )
143*cdf0e10cSrcweir     {
144*cdf0e10cSrcweir         const SalPoint* pPtAry = (const SalPoint*)aRectPoly.GetConstPointAry();
145*cdf0e10cSrcweir         if ( !mbFillColor )
146*cdf0e10cSrcweir             mpGraphics->DrawPolyLine( aRectPoly.GetSize(), pPtAry, this );
147*cdf0e10cSrcweir         else
148*cdf0e10cSrcweir         {
149*cdf0e10cSrcweir             if ( mbInitFillColor )
150*cdf0e10cSrcweir                 ImplInitFillColor();
151*cdf0e10cSrcweir             mpGraphics->DrawPolygon( aRectPoly.GetSize(), pPtAry, this );
152*cdf0e10cSrcweir         }
153*cdf0e10cSrcweir     }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     if( mpAlphaVDev )
156*cdf0e10cSrcweir         mpAlphaVDev->DrawEllipse( rRect );
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir // -----------------------------------------------------------------------
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir void OutputDevice::DrawArc( const Rectangle& rRect,
162*cdf0e10cSrcweir                             const Point& rStartPt, const Point& rEndPt )
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir     DBG_TRACE( "OutputDevice::DrawArc()" );
165*cdf0e10cSrcweir     DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     if ( mpMetaFile )
168*cdf0e10cSrcweir         mpMetaFile->AddAction( new MetaArcAction( rRect, rStartPt, rEndPt ) );
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     if ( !IsDeviceOutputNecessary() || !mbLineColor || ImplIsRecordLayout() )
171*cdf0e10cSrcweir         return;
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir     Rectangle aRect( ImplLogicToDevicePixel( rRect ) );
174*cdf0e10cSrcweir     if ( aRect.IsEmpty() )
175*cdf0e10cSrcweir         return;
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     // we need a graphics
178*cdf0e10cSrcweir     if ( !mpGraphics )
179*cdf0e10cSrcweir     {
180*cdf0e10cSrcweir         if ( !ImplGetGraphics() )
181*cdf0e10cSrcweir             return;
182*cdf0e10cSrcweir     }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     if ( mbInitClipRegion )
185*cdf0e10cSrcweir         ImplInitClipRegion();
186*cdf0e10cSrcweir     if ( mbOutputClipped )
187*cdf0e10cSrcweir         return;
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     if ( mbInitLineColor )
190*cdf0e10cSrcweir         ImplInitLineColor();
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     const Point     aStart( ImplLogicToDevicePixel( rStartPt ) );
193*cdf0e10cSrcweir     const Point     aEnd( ImplLogicToDevicePixel( rEndPt ) );
194*cdf0e10cSrcweir     Polygon         aArcPoly( aRect, aStart, aEnd, POLY_ARC );
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     if ( aArcPoly.GetSize() >= 2 )
197*cdf0e10cSrcweir     {
198*cdf0e10cSrcweir         const SalPoint* pPtAry = (const SalPoint*)aArcPoly.GetConstPointAry();
199*cdf0e10cSrcweir         mpGraphics->DrawPolyLine( aArcPoly.GetSize(), pPtAry, this );
200*cdf0e10cSrcweir     }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir     if( mpAlphaVDev )
203*cdf0e10cSrcweir         mpAlphaVDev->DrawArc( rRect, rStartPt, rEndPt );
204*cdf0e10cSrcweir }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir // -----------------------------------------------------------------------
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir void OutputDevice::DrawPie( const Rectangle& rRect,
209*cdf0e10cSrcweir                             const Point& rStartPt, const Point& rEndPt )
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     DBG_TRACE( "OutputDevice::DrawPie()" );
212*cdf0e10cSrcweir     DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir     if ( mpMetaFile )
215*cdf0e10cSrcweir         mpMetaFile->AddAction( new MetaPieAction( rRect, rStartPt, rEndPt ) );
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir     if ( !IsDeviceOutputNecessary() || (!mbLineColor && !mbFillColor) || ImplIsRecordLayout() )
218*cdf0e10cSrcweir         return;
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     Rectangle aRect( ImplLogicToDevicePixel( rRect ) );
221*cdf0e10cSrcweir     if ( aRect.IsEmpty() )
222*cdf0e10cSrcweir         return;
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir     // we need a graphics
225*cdf0e10cSrcweir     if ( !mpGraphics )
226*cdf0e10cSrcweir     {
227*cdf0e10cSrcweir         if ( !ImplGetGraphics() )
228*cdf0e10cSrcweir             return;
229*cdf0e10cSrcweir     }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir     if ( mbInitClipRegion )
232*cdf0e10cSrcweir         ImplInitClipRegion();
233*cdf0e10cSrcweir     if ( mbOutputClipped )
234*cdf0e10cSrcweir         return;
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir     if ( mbInitLineColor )
237*cdf0e10cSrcweir         ImplInitLineColor();
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir     const Point     aStart( ImplLogicToDevicePixel( rStartPt ) );
240*cdf0e10cSrcweir     const Point     aEnd( ImplLogicToDevicePixel( rEndPt ) );
241*cdf0e10cSrcweir     Polygon         aPiePoly( aRect, aStart, aEnd, POLY_PIE );
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     if ( aPiePoly.GetSize() >= 2 )
244*cdf0e10cSrcweir     {
245*cdf0e10cSrcweir         const SalPoint* pPtAry = (const SalPoint*)aPiePoly.GetConstPointAry();
246*cdf0e10cSrcweir         if ( !mbFillColor )
247*cdf0e10cSrcweir             mpGraphics->DrawPolyLine( aPiePoly.GetSize(), pPtAry, this );
248*cdf0e10cSrcweir         else
249*cdf0e10cSrcweir         {
250*cdf0e10cSrcweir             if ( mbInitFillColor )
251*cdf0e10cSrcweir                 ImplInitFillColor();
252*cdf0e10cSrcweir             mpGraphics->DrawPolygon( aPiePoly.GetSize(), pPtAry, this );
253*cdf0e10cSrcweir         }
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir     if( mpAlphaVDev )
257*cdf0e10cSrcweir         mpAlphaVDev->DrawPie( rRect, rStartPt, rEndPt );
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir // -----------------------------------------------------------------------
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir void OutputDevice::DrawChord( const Rectangle& rRect,
263*cdf0e10cSrcweir                               const Point& rStartPt, const Point& rEndPt )
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir     DBG_TRACE( "OutputDevice::DrawChord()" );
266*cdf0e10cSrcweir     DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir     if ( mpMetaFile )
269*cdf0e10cSrcweir         mpMetaFile->AddAction( new MetaChordAction( rRect, rStartPt, rEndPt ) );
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir     if ( !IsDeviceOutputNecessary() || (!mbLineColor && !mbFillColor) || ImplIsRecordLayout() )
272*cdf0e10cSrcweir         return;
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir     Rectangle aRect( ImplLogicToDevicePixel( rRect ) );
275*cdf0e10cSrcweir     if ( aRect.IsEmpty() )
276*cdf0e10cSrcweir         return;
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir     // we need a graphics
279*cdf0e10cSrcweir     if ( !mpGraphics )
280*cdf0e10cSrcweir     {
281*cdf0e10cSrcweir         if ( !ImplGetGraphics() )
282*cdf0e10cSrcweir             return;
283*cdf0e10cSrcweir     }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir     if ( mbInitClipRegion )
286*cdf0e10cSrcweir         ImplInitClipRegion();
287*cdf0e10cSrcweir     if ( mbOutputClipped )
288*cdf0e10cSrcweir         return;
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir     if ( mbInitLineColor )
291*cdf0e10cSrcweir         ImplInitLineColor();
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir     const Point     aStart( ImplLogicToDevicePixel( rStartPt ) );
294*cdf0e10cSrcweir     const Point     aEnd( ImplLogicToDevicePixel( rEndPt ) );
295*cdf0e10cSrcweir     Polygon         aChordPoly( aRect, aStart, aEnd, POLY_CHORD );
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir     if ( aChordPoly.GetSize() >= 2 )
298*cdf0e10cSrcweir     {
299*cdf0e10cSrcweir         const SalPoint* pPtAry = (const SalPoint*)aChordPoly.GetConstPointAry();
300*cdf0e10cSrcweir         if ( !mbFillColor )
301*cdf0e10cSrcweir             mpGraphics->DrawPolyLine( aChordPoly.GetSize(), pPtAry, this );
302*cdf0e10cSrcweir         else
303*cdf0e10cSrcweir         {
304*cdf0e10cSrcweir             if ( mbInitFillColor )
305*cdf0e10cSrcweir                 ImplInitFillColor();
306*cdf0e10cSrcweir             mpGraphics->DrawPolygon( aChordPoly.GetSize(), pPtAry, this );
307*cdf0e10cSrcweir         }
308*cdf0e10cSrcweir     }
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     if( mpAlphaVDev )
311*cdf0e10cSrcweir         mpAlphaVDev->DrawChord( rRect, rStartPt, rEndPt );
312*cdf0e10cSrcweir }
313