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>
24 #include <toolkit/awt/vclxdevice.hxx>
25 #include <toolkit/awt/vclxfont.hxx>
26 #include <toolkit/awt/vclxbitmap.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <toolkit/helper/macros.hxx>
29 #include <cppuhelper/typeprovider.hxx>
30 #include <cppuhelper/queryinterface.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/outdev.hxx>
36 #include <vcl/window.hxx>
37 #include <vcl/print.hxx>
38 #include <vcl/virdev.hxx>
39 #include <vcl/bitmapex.hxx>
40 #include <vcl/font.hxx>
45 VCLXDevice::VCLXDevice()
51 VCLXDevice::~VCLXDevice()
53 //TODO: why was this empty, and everything done in ~VCLXVirtualDevice?
55 mpOutputDevice
.reset();
58 void VCLXDevice::SetCreatedWithToolkit( bool bCreatedWithToolkit
)
60 if ( bCreatedWithToolkit
)
61 nFlags
|= FLAGS_CREATEDWITHTOOLKIT
;
63 nFlags
&= ~FLAGS_CREATEDWITHTOOLKIT
;
66 // ::com::sun::star::uno::XInterface
67 ::com::sun::star::uno::Any
VCLXDevice::queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
69 ::com::sun::star::uno::Any aRet
= ::cppu::queryInterface( rType
,
70 (static_cast< ::com::sun::star::awt::XDevice
* >(this)),
71 (static_cast< ::com::sun::star::lang::XUnoTunnel
* >(this)),
72 (static_cast< ::com::sun::star::lang::XTypeProvider
* >(this)),
73 (static_cast< ::com::sun::star::awt::XUnitConversion
* >(this)) );
74 return (aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
));
77 // ::com::sun::star::lang::XUnoTunnel
78 IMPL_XUNOTUNNEL( VCLXDevice
)
80 // ::com::sun::star::lang::XTypeProvider
81 IMPL_XTYPEPROVIDER_START( VCLXDevice
)
82 cppu::UnoType
<com::sun::star::awt::XDevice
>::get(),
83 cppu::UnoType
<com::sun::star::awt::XUnitConversion
>::get()
84 IMPL_XTYPEPROVIDER_END
87 // ::com::sun::star::awt::XDevice,
88 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
> VCLXDevice::createGraphics( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
90 SolarMutexGuard aGuard
;
92 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
> xRef
;
95 xRef
= mpOutputDevice
->CreateUnoGraphics();
100 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDevice
> VCLXDevice::createDevice( sal_Int32 nWidth
, sal_Int32 nHeight
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
102 SolarMutexGuard aGuard
;
104 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDevice
> xRef
;
105 if ( GetOutputDevice() )
107 VCLXVirtualDevice
* pVDev
= new VCLXVirtualDevice
;
108 VclPtrInstance
<VirtualDevice
> pVclVDev( *GetOutputDevice() );
109 pVclVDev
->SetOutputSizePixel( Size( nWidth
, nHeight
) );
110 pVDev
->SetVirtualDevice( pVclVDev
);
116 ::com::sun::star::awt::DeviceInfo
VCLXDevice::getInfo() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
118 SolarMutexGuard aGuard
;
120 ::com::sun::star::awt::DeviceInfo aInfo
;
125 OutDevType eDevType
= mpOutputDevice
->GetOutDevType();
126 if ( eDevType
== OUTDEV_WINDOW
)
128 aDevSz
= static_cast<vcl::Window
*>(mpOutputDevice
.get())->GetSizePixel();
129 static_cast<vcl::Window
*>(mpOutputDevice
.get())->GetBorder( aInfo
.LeftInset
, aInfo
.TopInset
, aInfo
.RightInset
, aInfo
.BottomInset
);
131 else if ( eDevType
== OUTDEV_PRINTER
)
133 aDevSz
= static_cast<Printer
*>(mpOutputDevice
.get())->GetPaperSizePixel();
134 Size aOutSz
= mpOutputDevice
->GetOutputSizePixel();
135 Point aOffset
= static_cast<Printer
*>(mpOutputDevice
.get())->GetPageOffset();
136 aInfo
.LeftInset
= aOffset
.X();
137 aInfo
.TopInset
= aOffset
.Y();
138 aInfo
.RightInset
= aDevSz
.Width() - aOutSz
.Width() - aOffset
.X();
139 aInfo
.BottomInset
= aDevSz
.Height() - aOutSz
.Height() - aOffset
.Y();
141 else // VirtualDevice
143 aDevSz
= mpOutputDevice
->GetOutputSizePixel();
146 aInfo
.RightInset
= 0;
147 aInfo
.BottomInset
= 0;
150 aInfo
.Width
= aDevSz
.Width();
151 aInfo
.Height
= aDevSz
.Height();
153 Size aTmpSz
= mpOutputDevice
->LogicToPixel( Size( 1000, 1000 ), MapMode( MAP_CM
) );
154 aInfo
.PixelPerMeterX
= aTmpSz
.Width()/10;
155 aInfo
.PixelPerMeterY
= aTmpSz
.Height()/10;
157 aInfo
.BitsPerPixel
= mpOutputDevice
->GetBitCount();
159 aInfo
.Capabilities
= 0;
160 if ( mpOutputDevice
->GetOutDevType() != OUTDEV_PRINTER
)
161 aInfo
.Capabilities
= ::com::sun::star::awt::DeviceCapability::RASTEROPERATIONS
|::com::sun::star::awt::DeviceCapability::GETBITS
;
167 ::com::sun::star::uno::Sequence
< ::com::sun::star::awt::FontDescriptor
> VCLXDevice::getFontDescriptors( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
169 SolarMutexGuard aGuard
;
171 ::com::sun::star::uno::Sequence
< ::com::sun::star::awt::FontDescriptor
> aFonts
;
174 int nFonts
= mpOutputDevice
->GetDevFontCount();
177 aFonts
= ::com::sun::star::uno::Sequence
< ::com::sun::star::awt::FontDescriptor
>( nFonts
);
178 ::com::sun::star::awt::FontDescriptor
* pFonts
= aFonts
.getArray();
179 for ( int n
= 0; n
< nFonts
; n
++ )
180 pFonts
[n
] = VCLUnoHelper::CreateFontDescriptor( mpOutputDevice
->GetDevFont( n
) );
186 ::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
, std::exception
)
188 SolarMutexGuard aGuard
;
190 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XFont
> xRef
;
193 VCLXFont
* pMetric
= new VCLXFont
;
194 pMetric
->Init( *this, VCLUnoHelper::CreateFont( rDescriptor
, mpOutputDevice
->GetFont() ) );
200 ::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
, std::exception
)
202 SolarMutexGuard aGuard
;
204 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XBitmap
> xBmp
;
207 Bitmap aBmp
= mpOutputDevice
->GetBitmap( Point( nX
, nY
), Size( nWidth
, nHeight
) );
209 VCLXBitmap
* pBmp
= new VCLXBitmap
;
210 pBmp
->SetBitmap( BitmapEx( aBmp
) );
216 ::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
, std::exception
)
218 SolarMutexGuard aGuard
;
220 BitmapEx aBmp
= VCLUnoHelper::GetBitmap( rxBitmap
);
221 VCLXBitmap
* pBmp
= new VCLXBitmap
;
222 pBmp
->SetBitmap( aBmp
);
223 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDisplayBitmap
> xDBmp
= pBmp
;
227 VCLXVirtualDevice::~VCLXVirtualDevice()
229 SolarMutexGuard aGuard
;
231 mpOutputDevice
.disposeAndClear();
234 // Interface implementation of ::com::sun::star::awt::XUnitConversion
236 ::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
, std::exception
)
239 SolarMutexGuard aGuard
;
240 if (TargetUnit
== com::sun::star::util::MeasureUnit::PERCENT
)
242 // percentage not allowed here
243 throw ::com::sun::star::lang::IllegalArgumentException();
246 ::com::sun::star::awt::Point
aAWTPoint(0,0);
251 MapMode
aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit
));
252 ::Point aVCLPoint
= VCLUnoHelper::ConvertToVCLPoint(aPoint
);
253 ::Point aDevPoint
= mpOutputDevice
->PixelToLogic(aVCLPoint
, aMode
);
254 aAWTPoint
= VCLUnoHelper::ConvertToAWTPoint(aDevPoint
);
261 ::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
, std::exception
)
264 SolarMutexGuard aGuard
;
265 if (SourceUnit
== com::sun::star::util::MeasureUnit::PERCENT
||
266 SourceUnit
== com::sun::star::util::MeasureUnit::PIXEL
)
268 // pixel or percentage not allowed here
269 throw ::com::sun::star::lang::IllegalArgumentException();
272 ::com::sun::star::awt::Point
aAWTPoint(0,0);
276 MapMode
aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit
));
277 ::Point aVCLPoint
= VCLUnoHelper::ConvertToVCLPoint(aPoint
);
278 ::Point aDevPoint
= mpOutputDevice
->LogicToPixel(aVCLPoint
, aMode
);
279 aAWTPoint
= VCLUnoHelper::ConvertToAWTPoint(aDevPoint
);
285 ::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
, std::exception
)
288 SolarMutexGuard aGuard
;
289 if (TargetUnit
== com::sun::star::util::MeasureUnit::PERCENT
)
291 // percentage not allowed here
292 throw ::com::sun::star::lang::IllegalArgumentException();
295 ::com::sun::star::awt::Size
aAWTSize(0,0);
301 MapMode
aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit
));
302 ::Size aVCLSize
= VCLUnoHelper::ConvertToVCLSize(aSize
);
303 ::Size aDevSz
= mpOutputDevice
->PixelToLogic(aVCLSize
, aMode
);
304 aAWTSize
= VCLUnoHelper::ConvertToAWTSize(aDevSz
);
310 ::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
, std::exception
)
313 SolarMutexGuard aGuard
;
314 if (SourceUnit
== com::sun::star::util::MeasureUnit::PERCENT
||
315 SourceUnit
== com::sun::star::util::MeasureUnit::PIXEL
)
317 // pixel or percentage not allowed here
318 throw ::com::sun::star::lang::IllegalArgumentException();
321 ::com::sun::star::awt::Size
aAWTSize(0,0);
325 MapMode
aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit
));
326 ::Size aVCLSize
= VCLUnoHelper::ConvertToVCLSize(aSize
);
327 ::Size aDevSz
= mpOutputDevice
->LogicToPixel(aVCLSize
, aMode
);
328 aAWTSize
= VCLUnoHelper::ConvertToAWTSize(aDevSz
);
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */