Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/awt/DeviceCapability.hpp>
30 : :
31 : : #include <com/sun/star/util/MeasureUnit.hpp>
32 : :
33 : : #include <toolkit/awt/vclxdevice.hxx>
34 : : #include <toolkit/awt/vclxfont.hxx>
35 : : #include <toolkit/awt/vclxbitmap.hxx>
36 : : #include <toolkit/helper/vclunohelper.hxx>
37 : : #include <toolkit/helper/macros.hxx>
38 : : #include <cppuhelper/typeprovider.hxx>
39 : :
40 : : #include <rtl/memory.h>
41 : : #include <rtl/uuid.h>
42 : :
43 : : #include <vcl/svapp.hxx>
44 : : #include <vcl/outdev.hxx>
45 : : #include <vcl/window.hxx>
46 : : #include <vcl/print.hxx>
47 : : #include <vcl/virdev.hxx>
48 : : #include <vcl/bitmapex.hxx>
49 : : #include <vcl/font.hxx>
50 : :
51 : : // ----------------------------------------------------
52 : : // class VCLXDevice
53 : : // ----------------------------------------------------
54 : 40400 : VCLXDevice::VCLXDevice()
55 : : {
56 : 40400 : mpOutputDevice = NULL;
57 : 40400 : nFlags = 0;
58 : 40400 : }
59 : :
60 [ + - ]: 37956 : VCLXDevice::~VCLXDevice()
61 : : {
62 [ - + ]: 38665 : }
63 : :
64 : 20916 : void VCLXDevice::DestroyOutputDevice()
65 : : {
66 [ + - ]: 20916 : delete mpOutputDevice;
67 : 20916 : mpOutputDevice = NULL;
68 : 20916 : }
69 : :
70 : 2286 : void VCLXDevice::SetCreatedWithToolkit( sal_Bool bCreatedWithToolkit )
71 : : {
72 [ + - ]: 2286 : if ( bCreatedWithToolkit )
73 : 2286 : nFlags |= FLAGS_CREATEDWITHTOOLKIT;
74 : : else
75 : 0 : nFlags &= ~FLAGS_CREATEDWITHTOOLKIT;
76 : 2286 : }
77 : :
78 : : // ::com::sun::star::uno::XInterface
79 : 515094 : ::com::sun::star::uno::Any VCLXDevice::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
80 : : {
81 : : ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
82 : : (static_cast< ::com::sun::star::awt::XDevice* >(this)),
83 : : (static_cast< ::com::sun::star::lang::XUnoTunnel* >(this)),
84 : : (static_cast< ::com::sun::star::lang::XTypeProvider* >(this)),
85 [ + - ]: 515094 : (static_cast< ::com::sun::star::awt::XUnitConversion* >(this)) );
86 [ + + ][ + - ]: 515094 : return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
87 : : }
88 : :
89 : : // ::com::sun::star::lang::XUnoTunnel
90 [ + - ][ + + ]: 20560 : IMPL_XUNOTUNNEL( VCLXDevice )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
91 : :
92 : : // ::com::sun::star::lang::XTypeProvider
93 [ # # ][ # # ]: 0 : IMPL_XTYPEPROVIDER_START( VCLXDevice )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
94 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice>* ) NULL ),
95 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XUnitConversion>* ) NULL )
96 [ # # ][ # # ]: 0 : IMPL_XTYPEPROVIDER_END
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
97 : :
98 : :
99 : : // ::com::sun::star::awt::XDevice,
100 : 64 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > VCLXDevice::createGraphics( ) throw(::com::sun::star::uno::RuntimeException)
101 : : {
102 [ + - ]: 64 : SolarMutexGuard aGuard;
103 : :
104 : 64 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > xRef;
105 : :
106 [ + - ]: 64 : if ( mpOutputDevice )
107 [ + - ][ + - ]: 64 : xRef = mpOutputDevice->CreateUnoGraphics();
108 : :
109 [ + - ]: 64 : return xRef;
110 : : }
111 : :
112 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXDevice::createDevice( sal_Int32 nWidth, sal_Int32 nHeight ) throw(::com::sun::star::uno::RuntimeException)
113 : : {
114 [ # # ]: 0 : SolarMutexGuard aGuard;
115 : :
116 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > xRef;
117 [ # # ]: 0 : if ( GetOutputDevice() )
118 : : {
119 [ # # ]: 0 : VCLXVirtualDevice* pVDev = new VCLXVirtualDevice;
120 [ # # ][ # # ]: 0 : VirtualDevice* pVclVDev = new VirtualDevice( *GetOutputDevice() );
121 [ # # ]: 0 : pVclVDev->SetOutputSizePixel( Size( nWidth, nHeight ) );
122 : 0 : pVDev->SetVirtualDevice( pVclVDev );
123 [ # # ]: 0 : xRef = pVDev;
124 : : }
125 [ # # ]: 0 : return xRef;
126 : : }
127 : :
128 : 19486 : ::com::sun::star::awt::DeviceInfo VCLXDevice::getInfo() throw(::com::sun::star::uno::RuntimeException)
129 : : {
130 [ + - ]: 19486 : SolarMutexGuard aGuard;
131 : :
132 : 19486 : ::com::sun::star::awt::DeviceInfo aInfo;
133 : :
134 [ + - ]: 19486 : if( mpOutputDevice )
135 : : {
136 : 19486 : Size aDevSz;
137 : 19486 : OutDevType eDevType = mpOutputDevice->GetOutDevType();
138 [ + + ]: 19486 : if ( eDevType == OUTDEV_WINDOW )
139 : : {
140 [ + - ]: 19462 : aDevSz = ((Window*)mpOutputDevice)->GetSizePixel();
141 [ + - ]: 19462 : ((Window*)mpOutputDevice)->GetBorder( aInfo.LeftInset, aInfo.TopInset, aInfo.RightInset, aInfo.BottomInset );
142 : : }
143 [ - + ]: 24 : else if ( eDevType == OUTDEV_PRINTER )
144 : : {
145 : 0 : aDevSz = ((Printer*)mpOutputDevice)->GetPaperSizePixel();
146 : 0 : Size aOutSz = mpOutputDevice->GetOutputSizePixel();
147 [ # # ]: 0 : Point aOffset = ((Printer*)mpOutputDevice)->GetPageOffset();
148 : 0 : aInfo.LeftInset = aOffset.X();
149 : 0 : aInfo.TopInset = aOffset.Y();
150 : 0 : aInfo.RightInset = aDevSz.Width() - aOutSz.Width() - aOffset.X();
151 : 0 : aInfo.BottomInset = aDevSz.Height() - aOutSz.Height() - aOffset.Y();
152 : : }
153 : : else // VirtualDevice
154 : : {
155 : 24 : aDevSz = mpOutputDevice->GetOutputSizePixel();
156 : 24 : aInfo.LeftInset = 0;
157 : 24 : aInfo.TopInset = 0;
158 : 24 : aInfo.RightInset = 0;
159 : 24 : aInfo.BottomInset = 0;
160 : : }
161 : :
162 : 19486 : aInfo.Width = aDevSz.Width();
163 : 19486 : aInfo.Height = aDevSz.Height();
164 : :
165 [ + - ][ + - ]: 19486 : Size aTmpSz = mpOutputDevice->LogicToPixel( Size( 1000, 1000 ), MapMode( MAP_CM ) );
[ + - ]
166 : 19486 : aInfo.PixelPerMeterX = aTmpSz.Width()/10;
167 : 19486 : aInfo.PixelPerMeterY = aTmpSz.Height()/10;
168 : :
169 [ + - ]: 19486 : aInfo.BitsPerPixel = mpOutputDevice->GetBitCount();
170 : :
171 : 19486 : aInfo.Capabilities = 0;
172 [ + - ]: 19486 : if ( mpOutputDevice->GetOutDevType() != OUTDEV_PRINTER )
173 : 19486 : aInfo.Capabilities = ::com::sun::star::awt::DeviceCapability::RASTEROPERATIONS|::com::sun::star::awt::DeviceCapability::GETBITS;
174 : : }
175 : :
176 [ + - ]: 19486 : return aInfo;
177 : : }
178 : :
179 : 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::awt::FontDescriptor > VCLXDevice::getFontDescriptors( ) throw(::com::sun::star::uno::RuntimeException)
180 : : {
181 [ # # ]: 0 : SolarMutexGuard aGuard;
182 : :
183 [ # # ]: 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::awt::FontDescriptor> aFonts;
184 [ # # ]: 0 : if( mpOutputDevice )
185 : : {
186 [ # # ]: 0 : int nFonts = mpOutputDevice->GetDevFontCount();
187 [ # # ]: 0 : if ( nFonts )
188 : : {
189 [ # # ][ # # ]: 0 : aFonts = ::com::sun::star::uno::Sequence< ::com::sun::star::awt::FontDescriptor>( nFonts );
[ # # ]
190 [ # # ]: 0 : ::com::sun::star::awt::FontDescriptor* pFonts = aFonts.getArray();
191 [ # # ]: 0 : for ( int n = 0; n < nFonts; n++ )
192 [ # # ][ # # ]: 0 : pFonts[n] = VCLUnoHelper::CreateFontDescriptor( mpOutputDevice->GetDevFont( n ) );
[ # # ]
193 : : }
194 : : }
195 [ # # ]: 0 : return aFonts;
196 : : }
197 : :
198 : 237 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont > VCLXDevice::getFont( const ::com::sun::star::awt::FontDescriptor& rDescriptor ) throw(::com::sun::star::uno::RuntimeException)
199 : : {
200 [ + - ]: 237 : SolarMutexGuard aGuard;
201 : :
202 : 237 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont > xRef;
203 [ + - ]: 237 : if( mpOutputDevice )
204 : : {
205 [ + - ]: 237 : VCLXFont* pMetric = new VCLXFont;
206 [ + - ][ + - ]: 237 : pMetric->Init( *this, VCLUnoHelper::CreateFont( rDescriptor, mpOutputDevice->GetFont() ) );
[ + - ]
207 [ + - ]: 237 : xRef = pMetric;
208 : : }
209 [ + - ]: 237 : return xRef;
210 : : }
211 : :
212 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > VCLXDevice::createBitmap( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight ) throw(::com::sun::star::uno::RuntimeException)
213 : : {
214 [ # # ]: 0 : SolarMutexGuard aGuard;
215 : :
216 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > xBmp;
217 [ # # ]: 0 : if( mpOutputDevice )
218 : : {
219 [ # # ]: 0 : Bitmap aBmp = mpOutputDevice->GetBitmap( Point( nX, nY ), Size( nWidth, nHeight ) );
220 : :
221 [ # # ]: 0 : VCLXBitmap* pBmp = new VCLXBitmap;
222 [ # # ][ # # ]: 0 : pBmp->SetBitmap( BitmapEx( aBmp ) );
[ # # ]
223 [ # # ][ # # ]: 0 : xBmp = pBmp;
224 : : }
225 [ # # ]: 0 : return xBmp;
226 : : }
227 : :
228 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayBitmap > VCLXDevice::createDisplayBitmap( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap >& rxBitmap ) throw(::com::sun::star::uno::RuntimeException)
229 : : {
230 [ # # ]: 0 : SolarMutexGuard aGuard;
231 : :
232 [ # # ]: 0 : BitmapEx aBmp = VCLUnoHelper::GetBitmap( rxBitmap );
233 [ # # ]: 0 : VCLXBitmap* pBmp = new VCLXBitmap;
234 [ # # ]: 0 : pBmp->SetBitmap( aBmp );
235 [ # # ][ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayBitmap > xDBmp = pBmp;
236 [ # # ][ # # ]: 0 : return xDBmp;
237 : : }
238 : :
239 : :
240 : 66 : VCLXVirtualDevice::~VCLXVirtualDevice()
241 : : {
242 [ + - ]: 66 : SolarMutexGuard aGuard;
243 : :
244 [ + - ][ + - ]: 66 : DestroyOutputDevice();
245 [ - + ]: 132 : }
246 : :
247 : :
248 : : // -----------------------------------------------------------------------------
249 : : // Interface implementation of ::com::sun::star::awt::XUnitConversion
250 : : // -----------------------------------------------------------------------------
251 : :
252 : 0 : ::com::sun::star::awt::Point SAL_CALL VCLXDevice::convertPointToLogic( const ::com::sun::star::awt::Point& aPoint, ::sal_Int16 TargetUnit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
253 : : {
254 : : (void)aPoint;
255 [ # # ]: 0 : SolarMutexGuard aGuard;
256 [ # # ]: 0 : if (TargetUnit == com::sun::star::util::MeasureUnit::PERCENT )
257 : : {
258 : : // percentage not allowed here
259 [ # # ]: 0 : throw ::com::sun::star::lang::IllegalArgumentException();
260 : : }
261 : :
262 : 0 : ::com::sun::star::awt::Point aAWTPoint(0,0);
263 : : // X,Y
264 : :
265 [ # # ]: 0 : if( mpOutputDevice )
266 : : {
267 [ # # ][ # # ]: 0 : MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit));
268 [ # # ]: 0 : ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
269 [ # # ]: 0 : ::Point aDevPoint = mpOutputDevice->PixelToLogic(aVCLPoint, aMode );
270 [ # # ][ # # ]: 0 : aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
271 : : }
272 : :
273 [ # # ]: 0 : return aAWTPoint;
274 : : }
275 : :
276 : :
277 : 0 : ::com::sun::star::awt::Point SAL_CALL VCLXDevice::convertPointToPixel( const ::com::sun::star::awt::Point& aPoint, ::sal_Int16 SourceUnit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
278 : : {
279 : : (void)aPoint;
280 [ # # ]: 0 : SolarMutexGuard aGuard;
281 [ # # ][ # # ]: 0 : if (SourceUnit == com::sun::star::util::MeasureUnit::PERCENT ||
282 : : SourceUnit == com::sun::star::util::MeasureUnit::PIXEL )
283 : : {
284 : : // pixel or percentage not allowed here
285 [ # # ]: 0 : throw ::com::sun::star::lang::IllegalArgumentException();
286 : : }
287 : :
288 : 0 : ::com::sun::star::awt::Point aAWTPoint(0,0);
289 : :
290 [ # # ]: 0 : if( mpOutputDevice )
291 : : {
292 [ # # ][ # # ]: 0 : MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit));
293 [ # # ]: 0 : ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
294 [ # # ]: 0 : ::Point aDevPoint = mpOutputDevice->LogicToPixel(aVCLPoint, aMode );
295 [ # # ][ # # ]: 0 : aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
296 : : }
297 : :
298 [ # # ]: 0 : return aAWTPoint;
299 : : }
300 : :
301 : 0 : ::com::sun::star::awt::Size SAL_CALL VCLXDevice::convertSizeToLogic( const ::com::sun::star::awt::Size& aSize, ::sal_Int16 TargetUnit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
302 : : {
303 : : (void)aSize;
304 [ # # ]: 0 : SolarMutexGuard aGuard;
305 [ # # ]: 0 : if (TargetUnit == com::sun::star::util::MeasureUnit::PERCENT)
306 : : {
307 : : // percentage not allowed here
308 [ # # ]: 0 : throw ::com::sun::star::lang::IllegalArgumentException();
309 : : }
310 : :
311 : 0 : ::com::sun::star::awt::Size aAWTSize(0,0);
312 : : // Width, Height
313 : :
314 : :
315 [ # # ]: 0 : if( mpOutputDevice )
316 : : {
317 [ # # ][ # # ]: 0 : MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit));
318 [ # # ]: 0 : ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
319 [ # # ]: 0 : ::Size aDevSz = mpOutputDevice->PixelToLogic(aVCLSize, aMode );
320 [ # # ][ # # ]: 0 : aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
321 : : }
322 : :
323 [ # # ]: 0 : return aAWTSize;
324 : : }
325 : :
326 : 0 : ::com::sun::star::awt::Size SAL_CALL VCLXDevice::convertSizeToPixel( const ::com::sun::star::awt::Size& aSize, ::sal_Int16 SourceUnit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
327 : : {
328 : : (void)aSize;
329 [ # # ]: 0 : SolarMutexGuard aGuard;
330 [ # # ][ # # ]: 0 : if (SourceUnit == com::sun::star::util::MeasureUnit::PERCENT ||
331 : : SourceUnit == com::sun::star::util::MeasureUnit::PIXEL)
332 : : {
333 : : // pixel or percentage not allowed here
334 [ # # ]: 0 : throw ::com::sun::star::lang::IllegalArgumentException();
335 : : }
336 : :
337 : 0 : ::com::sun::star::awt::Size aAWTSize(0,0);
338 : : // Width, Height
339 [ # # ]: 0 : if( mpOutputDevice )
340 : : {
341 [ # # ][ # # ]: 0 : MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit));
342 [ # # ]: 0 : ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
343 [ # # ]: 0 : ::Size aDevSz = mpOutputDevice->LogicToPixel(aVCLSize, aMode );
344 [ # # ][ # # ]: 0 : aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
345 : : }
346 : :
347 [ # # ]: 0 : return aAWTSize;
348 : : }
349 : :
350 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|