Bump version to 24.04.3.4
[LibreOffice.git] / toolkit / source / awt / vclxdevice.cxx
blobc4ed9814671366fbd6be8d077d18db8e02ec6dc8
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 <sal/config.h>
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 <awt/vclxbitmap.hxx>
28 #include <toolkit/helper/vclunohelper.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/outdev.hxx>
32 #include <vcl/virdev.hxx>
33 #include <vcl/bitmapex.hxx>
34 #include <vcl/metric.hxx>
37 VCLXDevice::VCLXDevice()
41 VCLXDevice::~VCLXDevice()
43 //TODO: why was this empty, and everything done in ~VCLXVirtualDevice?
44 SolarMutexGuard g;
45 mpOutputDevice.reset();
48 // css::awt::XDevice,
49 css::uno::Reference< css::awt::XGraphics > VCLXDevice::createGraphics( )
51 SolarMutexGuard aGuard;
53 css::uno::Reference< css::awt::XGraphics > xRef;
55 if ( mpOutputDevice )
56 xRef = mpOutputDevice->CreateUnoGraphics();
58 return xRef;
61 css::uno::Reference< css::awt::XDevice > VCLXDevice::createDevice( sal_Int32 nWidth, sal_Int32 nHeight )
63 SolarMutexGuard aGuard;
65 css::uno::Reference< css::awt::XDevice > xRef;
66 if ( GetOutputDevice() )
68 rtl::Reference<VCLXVirtualDevice> pVDev = new VCLXVirtualDevice;
69 VclPtrInstance<VirtualDevice> pVclVDev( *GetOutputDevice() );
70 pVclVDev->SetOutputSizePixel( Size( nWidth, nHeight ) );
71 pVDev->SetVirtualDevice( pVclVDev );
72 xRef = pVDev;
74 return xRef;
77 css::awt::DeviceInfo VCLXDevice::getInfo()
79 SolarMutexGuard aGuard;
81 css::awt::DeviceInfo aInfo;
83 if (mpOutputDevice)
84 aInfo = mpOutputDevice->GetDeviceInfo();
86 return aInfo;
89 css::uno::Sequence< css::awt::FontDescriptor > VCLXDevice::getFontDescriptors( )
91 SolarMutexGuard aGuard;
93 css::uno::Sequence< css::awt::FontDescriptor> aFonts;
94 if( mpOutputDevice )
96 int nFonts = mpOutputDevice->GetFontFaceCollectionCount();
97 if ( nFonts )
99 aFonts = css::uno::Sequence< css::awt::FontDescriptor>( nFonts );
100 css::awt::FontDescriptor* pFonts = aFonts.getArray();
101 for ( int n = 0; n < nFonts; n++ )
102 pFonts[n] = VCLUnoHelper::CreateFontDescriptor( mpOutputDevice->GetFontMetricFromCollection( n ) );
105 return aFonts;
108 css::uno::Reference< css::awt::XFont > VCLXDevice::getFont( const css::awt::FontDescriptor& rDescriptor )
110 SolarMutexGuard aGuard;
112 css::uno::Reference< css::awt::XFont > xRef;
113 if( mpOutputDevice )
115 rtl::Reference<VCLXFont> pMetric = new VCLXFont;
116 pMetric->Init( *this, VCLUnoHelper::CreateFont( rDescriptor, mpOutputDevice->GetFont() ) );
117 xRef = pMetric;
119 return xRef;
122 css::uno::Reference< css::awt::XBitmap > VCLXDevice::createBitmap( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight )
124 SolarMutexGuard aGuard;
126 css::uno::Reference< css::awt::XBitmap > xBmp;
127 if( mpOutputDevice )
129 BitmapEx aBmp = mpOutputDevice->GetBitmapEx( Point( nX, nY ), Size( nWidth, nHeight ) );
131 rtl::Reference<VCLXBitmap> pBmp = new VCLXBitmap;
132 pBmp->SetBitmap( aBmp );
133 xBmp = pBmp;
135 return xBmp;
138 css::uno::Reference< css::awt::XDisplayBitmap > VCLXDevice::createDisplayBitmap( const css::uno::Reference< css::awt::XBitmap >& rxBitmap )
140 SolarMutexGuard aGuard;
142 BitmapEx aBmp = VCLUnoHelper::GetBitmap( rxBitmap );
143 rtl::Reference<VCLXBitmap> pBmp = new VCLXBitmap;
144 pBmp->SetBitmap( aBmp );
145 return pBmp;
148 VCLXVirtualDevice::~VCLXVirtualDevice()
150 SolarMutexGuard aGuard;
152 mpOutputDevice.disposeAndClear();
155 // Interface implementation of css::awt::XUnitConversion
157 css::awt::Point SAL_CALL VCLXDevice::convertPointToLogic( const css::awt::Point& aPoint, ::sal_Int16 TargetUnit )
159 SolarMutexGuard aGuard;
160 if (TargetUnit == css::util::MeasureUnit::PERCENT )
162 // percentage not allowed here
163 throw css::lang::IllegalArgumentException();
166 css::awt::Point aAWTPoint(0,0);
167 // X,Y
169 if( mpOutputDevice )
171 MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit));
172 ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
173 ::Point aDevPoint = mpOutputDevice->PixelToLogic(aVCLPoint, aMode );
174 aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
177 return aAWTPoint;
181 css::awt::Point SAL_CALL VCLXDevice::convertPointToPixel( const css::awt::Point& aPoint, ::sal_Int16 SourceUnit )
183 SolarMutexGuard aGuard;
184 if (SourceUnit == css::util::MeasureUnit::PERCENT ||
185 SourceUnit == css::util::MeasureUnit::PIXEL )
187 // pixel or percentage not allowed here
188 throw css::lang::IllegalArgumentException();
191 css::awt::Point aAWTPoint(0,0);
193 if( mpOutputDevice )
195 MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit));
196 ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
197 ::Point aDevPoint = mpOutputDevice->LogicToPixel(aVCLPoint, aMode );
198 aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
201 return aAWTPoint;
204 css::awt::Size SAL_CALL VCLXDevice::convertSizeToLogic( const css::awt::Size& aSize, ::sal_Int16 TargetUnit )
206 SolarMutexGuard aGuard;
207 if (TargetUnit == css::util::MeasureUnit::PERCENT)
209 // percentage not allowed here
210 throw css::lang::IllegalArgumentException();
213 css::awt::Size aAWTSize(0,0);
214 // Width, Height
217 if( mpOutputDevice )
219 MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit));
220 ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
221 ::Size aDevSz = mpOutputDevice->PixelToLogic(aVCLSize, aMode );
222 aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
225 return aAWTSize;
228 css::awt::Size SAL_CALL VCLXDevice::convertSizeToPixel( const css::awt::Size& aSize, ::sal_Int16 SourceUnit )
230 SolarMutexGuard aGuard;
231 if (SourceUnit == css::util::MeasureUnit::PERCENT ||
232 SourceUnit == css::util::MeasureUnit::PIXEL)
234 // pixel or percentage not allowed here
235 throw css::lang::IllegalArgumentException();
238 css::awt::Size aAWTSize(0,0);
239 // Width, Height
240 if( mpOutputDevice )
242 MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit));
243 ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
244 ::Size aDevSz = mpOutputDevice->LogicToPixel(aVCLSize, aMode );
245 aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
248 return aAWTSize;
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */