bump product version to 6.3.0.0.beta1
[LibreOffice.git] / toolkit / source / awt / vclxdevice.cxx
blob8eb75223c9bbbb5433754c5d215d532253a48aa2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/awt/DeviceCapability.hpp>
22 #include <com/sun/star/util/MeasureUnit.hpp>
23 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <toolkit/awt/vclxdevice.hxx>
26 #include <toolkit/awt/vclxfont.hxx>
27 #include <toolkit/awt/vclxbitmap.hxx>
28 #include <toolkit/helper/vclunohelper.hxx>
29 #include <toolkit/helper/macros.hxx>
30 #include <cppuhelper/typeprovider.hxx>
31 #include <cppuhelper/queryinterface.hxx>
33 #include <rtl/uuid.h>
35 #include <vcl/svapp.hxx>
36 #include <vcl/outdev.hxx>
37 #include <vcl/window.hxx>
38 #include <vcl/print.hxx>
39 #include <vcl/virdev.hxx>
40 #include <vcl/bitmapex.hxx>
41 #include <vcl/font.hxx>
42 #include <vcl/metric.hxx>
44 // class VCLXDevice
46 VCLXDevice::VCLXDevice()
50 VCLXDevice::~VCLXDevice()
52 //TODO: why was this empty, and everything done in ~VCLXVirtualDevice?
53 SolarMutexGuard g;
54 mpOutputDevice.reset();
57 // css::uno::XInterface
58 css::uno::Any VCLXDevice::queryInterface( const css::uno::Type & rType )
60 css::uno::Any aRet = ::cppu::queryInterface( rType,
61 static_cast< css::awt::XDevice* >(this),
62 static_cast< css::lang::XUnoTunnel* >(this),
63 static_cast< css::lang::XTypeProvider* >(this),
64 static_cast< css::awt::XUnitConversion* >(this) );
65 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
68 // css::lang::XUnoTunnel
69 IMPL_XUNOTUNNEL( VCLXDevice )
71 IMPL_IMPLEMENTATION_ID( VCLXDevice )
73 // css::lang::XTypeProvider
74 css::uno::Sequence< css::uno::Type > VCLXDevice::getTypes()
76 static const css::uno::Sequence< css::uno::Type > aTypeList {
77 cppu::UnoType<css::lang::XTypeProvider>::get(),
78 cppu::UnoType<css::awt::XDevice>::get(),
79 cppu::UnoType<css::awt::XUnitConversion>::get()
81 return aTypeList;
85 // css::awt::XDevice,
86 css::uno::Reference< css::awt::XGraphics > VCLXDevice::createGraphics( )
88 SolarMutexGuard aGuard;
90 css::uno::Reference< css::awt::XGraphics > xRef;
92 if ( mpOutputDevice )
93 xRef = mpOutputDevice->CreateUnoGraphics();
95 return xRef;
98 css::uno::Reference< css::awt::XDevice > VCLXDevice::createDevice( sal_Int32 nWidth, sal_Int32 nHeight )
100 SolarMutexGuard aGuard;
102 css::uno::Reference< css::awt::XDevice > xRef;
103 if ( GetOutputDevice() )
105 VCLXVirtualDevice* pVDev = new VCLXVirtualDevice;
106 VclPtrInstance<VirtualDevice> pVclVDev( *GetOutputDevice() );
107 pVclVDev->SetOutputSizePixel( Size( nWidth, nHeight ) );
108 pVDev->SetVirtualDevice( pVclVDev );
109 xRef = pVDev;
111 return xRef;
114 css::awt::DeviceInfo VCLXDevice::getInfo()
116 SolarMutexGuard aGuard;
118 css::awt::DeviceInfo aInfo;
120 if( mpOutputDevice )
122 Size aDevSz;
123 OutDevType eDevType = mpOutputDevice->GetOutDevType();
124 if ( eDevType == OUTDEV_WINDOW )
126 aDevSz = static_cast<vcl::Window*>(mpOutputDevice.get())->GetSizePixel();
127 static_cast<vcl::Window*>(mpOutputDevice.get())->GetBorder( aInfo.LeftInset, aInfo.TopInset, aInfo.RightInset, aInfo.BottomInset );
129 else if ( eDevType == OUTDEV_PRINTER )
131 aDevSz = static_cast<Printer*>(mpOutputDevice.get())->GetPaperSizePixel();
132 Size aOutSz = mpOutputDevice->GetOutputSizePixel();
133 Point aOffset = static_cast<Printer*>(mpOutputDevice.get())->GetPageOffset();
134 aInfo.LeftInset = aOffset.X();
135 aInfo.TopInset = aOffset.Y();
136 aInfo.RightInset = aDevSz.Width() - aOutSz.Width() - aOffset.X();
137 aInfo.BottomInset = aDevSz.Height() - aOutSz.Height() - aOffset.Y();
139 else // VirtualDevice
141 aDevSz = mpOutputDevice->GetOutputSizePixel();
142 aInfo.LeftInset = 0;
143 aInfo.TopInset = 0;
144 aInfo.RightInset = 0;
145 aInfo.BottomInset = 0;
148 aInfo.Width = aDevSz.Width();
149 aInfo.Height = aDevSz.Height();
151 Size aTmpSz = mpOutputDevice->LogicToPixel( Size( 1000, 1000 ), MapMode( MapUnit::MapCM ) );
152 aInfo.PixelPerMeterX = aTmpSz.Width()/10;
153 aInfo.PixelPerMeterY = aTmpSz.Height()/10;
155 aInfo.BitsPerPixel = mpOutputDevice->GetBitCount();
157 aInfo.Capabilities = 0;
158 if ( mpOutputDevice->GetOutDevType() != OUTDEV_PRINTER )
159 aInfo.Capabilities = css::awt::DeviceCapability::RASTEROPERATIONS|css::awt::DeviceCapability::GETBITS;
162 return aInfo;
165 css::uno::Sequence< css::awt::FontDescriptor > VCLXDevice::getFontDescriptors( )
167 SolarMutexGuard aGuard;
169 css::uno::Sequence< css::awt::FontDescriptor> aFonts;
170 if( mpOutputDevice )
172 int nFonts = mpOutputDevice->GetDevFontCount();
173 if ( nFonts )
175 aFonts = css::uno::Sequence< css::awt::FontDescriptor>( nFonts );
176 css::awt::FontDescriptor* pFonts = aFonts.getArray();
177 for ( int n = 0; n < nFonts; n++ )
178 pFonts[n] = VCLUnoHelper::CreateFontDescriptor( mpOutputDevice->GetDevFont( n ) );
181 return aFonts;
184 css::uno::Reference< css::awt::XFont > VCLXDevice::getFont( const css::awt::FontDescriptor& rDescriptor )
186 SolarMutexGuard aGuard;
188 css::uno::Reference< css::awt::XFont > xRef;
189 if( mpOutputDevice )
191 VCLXFont* pMetric = new VCLXFont;
192 pMetric->Init( *this, VCLUnoHelper::CreateFont( rDescriptor, mpOutputDevice->GetFont() ) );
193 xRef = pMetric;
195 return xRef;
198 css::uno::Reference< css::awt::XBitmap > VCLXDevice::createBitmap( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight )
200 SolarMutexGuard aGuard;
202 css::uno::Reference< css::awt::XBitmap > xBmp;
203 if( mpOutputDevice )
205 BitmapEx aBmp = mpOutputDevice->GetBitmapEx( Point( nX, nY ), Size( nWidth, nHeight ) );
207 VCLXBitmap* pBmp = new VCLXBitmap;
208 pBmp->SetBitmap( aBmp );
209 xBmp = pBmp;
211 return xBmp;
214 css::uno::Reference< css::awt::XDisplayBitmap > VCLXDevice::createDisplayBitmap( const css::uno::Reference< css::awt::XBitmap >& rxBitmap )
216 SolarMutexGuard aGuard;
218 BitmapEx aBmp = VCLUnoHelper::GetBitmap( rxBitmap );
219 VCLXBitmap* pBmp = new VCLXBitmap;
220 pBmp->SetBitmap( aBmp );
221 css::uno::Reference< css::awt::XDisplayBitmap > xDBmp = pBmp;
222 return xDBmp;
225 VCLXVirtualDevice::~VCLXVirtualDevice()
227 SolarMutexGuard aGuard;
229 mpOutputDevice.disposeAndClear();
232 // Interface implementation of css::awt::XUnitConversion
234 css::awt::Point SAL_CALL VCLXDevice::convertPointToLogic( const css::awt::Point& aPoint, ::sal_Int16 TargetUnit )
236 SolarMutexGuard aGuard;
237 if (TargetUnit == css::util::MeasureUnit::PERCENT )
239 // percentage not allowed here
240 throw css::lang::IllegalArgumentException();
243 css::awt::Point aAWTPoint(0,0);
244 // X,Y
246 if( mpOutputDevice )
248 MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit));
249 ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
250 ::Point aDevPoint = mpOutputDevice->PixelToLogic(aVCLPoint, aMode );
251 aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
254 return aAWTPoint;
258 css::awt::Point SAL_CALL VCLXDevice::convertPointToPixel( const css::awt::Point& aPoint, ::sal_Int16 SourceUnit )
260 SolarMutexGuard aGuard;
261 if (SourceUnit == css::util::MeasureUnit::PERCENT ||
262 SourceUnit == css::util::MeasureUnit::PIXEL )
264 // pixel or percentage not allowed here
265 throw css::lang::IllegalArgumentException();
268 css::awt::Point aAWTPoint(0,0);
270 if( mpOutputDevice )
272 MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit));
273 ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
274 ::Point aDevPoint = mpOutputDevice->LogicToPixel(aVCLPoint, aMode );
275 aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
278 return aAWTPoint;
281 css::awt::Size SAL_CALL VCLXDevice::convertSizeToLogic( const css::awt::Size& aSize, ::sal_Int16 TargetUnit )
283 SolarMutexGuard aGuard;
284 if (TargetUnit == css::util::MeasureUnit::PERCENT)
286 // percentage not allowed here
287 throw css::lang::IllegalArgumentException();
290 css::awt::Size aAWTSize(0,0);
291 // Width, Height
294 if( mpOutputDevice )
296 MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit));
297 ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
298 ::Size aDevSz = mpOutputDevice->PixelToLogic(aVCLSize, aMode );
299 aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
302 return aAWTSize;
305 css::awt::Size SAL_CALL VCLXDevice::convertSizeToPixel( const css::awt::Size& aSize, ::sal_Int16 SourceUnit )
307 SolarMutexGuard aGuard;
308 if (SourceUnit == css::util::MeasureUnit::PERCENT ||
309 SourceUnit == css::util::MeasureUnit::PIXEL)
311 // pixel or percentage not allowed here
312 throw css::lang::IllegalArgumentException();
315 css::awt::Size aAWTSize(0,0);
316 // Width, Height
317 if( mpOutputDevice )
319 MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit));
320 ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
321 ::Size aDevSz = mpOutputDevice->LogicToPixel(aVCLSize, aMode );
322 aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
325 return aAWTSize;
328 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */