1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
46 VCLXDevice::VCLXDevice()
50 VCLXDevice::~VCLXDevice()
52 //TODO: why was this empty, and everything done in ~VCLXVirtualDevice?
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()
86 css::uno::Reference
< css::awt::XGraphics
> VCLXDevice::createGraphics( )
88 SolarMutexGuard aGuard
;
90 css::uno::Reference
< css::awt::XGraphics
> xRef
;
93 xRef
= mpOutputDevice
->CreateUnoGraphics();
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
);
114 css::awt::DeviceInfo
VCLXDevice::getInfo()
116 SolarMutexGuard aGuard
;
118 css::awt::DeviceInfo aInfo
;
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();
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
;
165 css::uno::Sequence
< css::awt::FontDescriptor
> VCLXDevice::getFontDescriptors( )
167 SolarMutexGuard aGuard
;
169 css::uno::Sequence
< css::awt::FontDescriptor
> aFonts
;
172 int nFonts
= mpOutputDevice
->GetDevFontCount();
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
) );
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
;
191 VCLXFont
* pMetric
= new VCLXFont
;
192 pMetric
->Init( *this, VCLUnoHelper::CreateFont( rDescriptor
, mpOutputDevice
->GetFont() ) );
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
;
205 BitmapEx aBmp
= mpOutputDevice
->GetBitmapEx( Point( nX
, nY
), Size( nWidth
, nHeight
) );
207 VCLXBitmap
* pBmp
= new VCLXBitmap
;
208 pBmp
->SetBitmap( aBmp
);
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
;
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);
248 MapMode
aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit
));
249 ::Point aVCLPoint
= VCLUnoHelper::ConvertToVCLPoint(aPoint
);
250 ::Point aDevPoint
= mpOutputDevice
->PixelToLogic(aVCLPoint
, aMode
);
251 aAWTPoint
= VCLUnoHelper::ConvertToAWTPoint(aDevPoint
);
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);
272 MapMode
aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit
));
273 ::Point aVCLPoint
= VCLUnoHelper::ConvertToVCLPoint(aPoint
);
274 ::Point aDevPoint
= mpOutputDevice
->LogicToPixel(aVCLPoint
, aMode
);
275 aAWTPoint
= VCLUnoHelper::ConvertToAWTPoint(aDevPoint
);
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);
296 MapMode
aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit
));
297 ::Size aVCLSize
= VCLUnoHelper::ConvertToVCLSize(aSize
);
298 ::Size aDevSz
= mpOutputDevice
->PixelToLogic(aVCLSize
, aMode
);
299 aAWTSize
= VCLUnoHelper::ConvertToAWTSize(aDevSz
);
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);
319 MapMode
aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit
));
320 ::Size aVCLSize
= VCLUnoHelper::ConvertToVCLSize(aSize
);
321 ::Size aDevSz
= mpOutputDevice
->LogicToPixel(aVCLSize
, aMode
);
322 aAWTSize
= VCLUnoHelper::ConvertToAWTSize(aDevSz
);
328 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */