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>
33 #include <vcl/svapp.hxx>
34 #include <vcl/outdev.hxx>
35 #include <vcl/window.hxx>
36 #include <vcl/print.hxx>
37 #include <vcl/virdev.hxx>
38 #include <vcl/bitmapex.hxx>
39 #include <vcl/font.hxx>
41 // ----------------------------------------------------
43 // ----------------------------------------------------
44 VCLXDevice::VCLXDevice()
46 mpOutputDevice
= NULL
;
50 VCLXDevice::~VCLXDevice()
54 void VCLXDevice::DestroyOutputDevice()
56 delete mpOutputDevice
;
57 mpOutputDevice
= NULL
;
60 void VCLXDevice::SetCreatedWithToolkit( sal_Bool bCreatedWithToolkit
)
62 if ( bCreatedWithToolkit
)
63 nFlags
|= FLAGS_CREATEDWITHTOOLKIT
;
65 nFlags
&= ~FLAGS_CREATEDWITHTOOLKIT
;
68 // ::com::sun::star::uno::XInterface
69 ::com::sun::star::uno::Any
VCLXDevice::queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
)
71 ::com::sun::star::uno::Any aRet
= ::cppu::queryInterface( rType
,
72 (static_cast< ::com::sun::star::awt::XDevice
* >(this)),
73 (static_cast< ::com::sun::star::lang::XUnoTunnel
* >(this)),
74 (static_cast< ::com::sun::star::lang::XTypeProvider
* >(this)),
75 (static_cast< ::com::sun::star::awt::XUnitConversion
* >(this)) );
76 return (aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
));
79 // ::com::sun::star::lang::XUnoTunnel
80 IMPL_XUNOTUNNEL( VCLXDevice
)
82 // ::com::sun::star::lang::XTypeProvider
83 IMPL_XTYPEPROVIDER_START( VCLXDevice
)
84 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDevice
>* ) NULL
),
85 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XUnitConversion
>* ) NULL
)
86 IMPL_XTYPEPROVIDER_END
89 // ::com::sun::star::awt::XDevice,
90 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
> VCLXDevice::createGraphics( ) throw(::com::sun::star::uno::RuntimeException
)
92 SolarMutexGuard aGuard
;
94 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
> xRef
;
97 xRef
= mpOutputDevice
->CreateUnoGraphics();
102 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDevice
> VCLXDevice::createDevice( sal_Int32 nWidth
, sal_Int32 nHeight
) throw(::com::sun::star::uno::RuntimeException
)
104 SolarMutexGuard aGuard
;
106 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDevice
> xRef
;
107 if ( GetOutputDevice() )
109 VCLXVirtualDevice
* pVDev
= new VCLXVirtualDevice
;
110 VirtualDevice
* pVclVDev
= new VirtualDevice( *GetOutputDevice() );
111 pVclVDev
->SetOutputSizePixel( Size( nWidth
, nHeight
) );
112 pVDev
->SetVirtualDevice( pVclVDev
);
118 ::com::sun::star::awt::DeviceInfo
VCLXDevice::getInfo() throw(::com::sun::star::uno::RuntimeException
)
120 SolarMutexGuard aGuard
;
122 ::com::sun::star::awt::DeviceInfo aInfo
;
127 OutDevType eDevType
= mpOutputDevice
->GetOutDevType();
128 if ( eDevType
== OUTDEV_WINDOW
)
130 aDevSz
= ((Window
*)mpOutputDevice
)->GetSizePixel();
131 ((Window
*)mpOutputDevice
)->GetBorder( aInfo
.LeftInset
, aInfo
.TopInset
, aInfo
.RightInset
, aInfo
.BottomInset
);
133 else if ( eDevType
== OUTDEV_PRINTER
)
135 aDevSz
= ((Printer
*)mpOutputDevice
)->GetPaperSizePixel();
136 Size aOutSz
= mpOutputDevice
->GetOutputSizePixel();
137 Point aOffset
= ((Printer
*)mpOutputDevice
)->GetPageOffset();
138 aInfo
.LeftInset
= aOffset
.X();
139 aInfo
.TopInset
= aOffset
.Y();
140 aInfo
.RightInset
= aDevSz
.Width() - aOutSz
.Width() - aOffset
.X();
141 aInfo
.BottomInset
= aDevSz
.Height() - aOutSz
.Height() - aOffset
.Y();
143 else // VirtualDevice
145 aDevSz
= mpOutputDevice
->GetOutputSizePixel();
148 aInfo
.RightInset
= 0;
149 aInfo
.BottomInset
= 0;
152 aInfo
.Width
= aDevSz
.Width();
153 aInfo
.Height
= aDevSz
.Height();
155 Size aTmpSz
= mpOutputDevice
->LogicToPixel( Size( 1000, 1000 ), MapMode( MAP_CM
) );
156 aInfo
.PixelPerMeterX
= aTmpSz
.Width()/10;
157 aInfo
.PixelPerMeterY
= aTmpSz
.Height()/10;
159 aInfo
.BitsPerPixel
= mpOutputDevice
->GetBitCount();
161 aInfo
.Capabilities
= 0;
162 if ( mpOutputDevice
->GetOutDevType() != OUTDEV_PRINTER
)
163 aInfo
.Capabilities
= ::com::sun::star::awt::DeviceCapability::RASTEROPERATIONS
|::com::sun::star::awt::DeviceCapability::GETBITS
;
169 ::com::sun::star::uno::Sequence
< ::com::sun::star::awt::FontDescriptor
> VCLXDevice::getFontDescriptors( ) throw(::com::sun::star::uno::RuntimeException
)
171 SolarMutexGuard aGuard
;
173 ::com::sun::star::uno::Sequence
< ::com::sun::star::awt::FontDescriptor
> aFonts
;
176 int nFonts
= mpOutputDevice
->GetDevFontCount();
179 aFonts
= ::com::sun::star::uno::Sequence
< ::com::sun::star::awt::FontDescriptor
>( nFonts
);
180 ::com::sun::star::awt::FontDescriptor
* pFonts
= aFonts
.getArray();
181 for ( int n
= 0; n
< nFonts
; n
++ )
182 pFonts
[n
] = VCLUnoHelper::CreateFontDescriptor( mpOutputDevice
->GetDevFont( n
) );
188 ::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
)
190 SolarMutexGuard aGuard
;
192 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XFont
> xRef
;
195 VCLXFont
* pMetric
= new VCLXFont
;
196 pMetric
->Init( *this, VCLUnoHelper::CreateFont( rDescriptor
, mpOutputDevice
->GetFont() ) );
202 ::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
)
204 SolarMutexGuard aGuard
;
206 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XBitmap
> xBmp
;
209 Bitmap aBmp
= mpOutputDevice
->GetBitmap( Point( nX
, nY
), Size( nWidth
, nHeight
) );
211 VCLXBitmap
* pBmp
= new VCLXBitmap
;
212 pBmp
->SetBitmap( BitmapEx( aBmp
) );
218 ::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
)
220 SolarMutexGuard aGuard
;
222 BitmapEx aBmp
= VCLUnoHelper::GetBitmap( rxBitmap
);
223 VCLXBitmap
* pBmp
= new VCLXBitmap
;
224 pBmp
->SetBitmap( aBmp
);
225 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDisplayBitmap
> xDBmp
= pBmp
;
230 VCLXVirtualDevice::~VCLXVirtualDevice()
232 SolarMutexGuard aGuard
;
234 DestroyOutputDevice();
238 // -----------------------------------------------------------------------------
239 // Interface implementation of ::com::sun::star::awt::XUnitConversion
240 // -----------------------------------------------------------------------------
242 ::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
)
245 SolarMutexGuard aGuard
;
246 if (TargetUnit
== com::sun::star::util::MeasureUnit::PERCENT
)
248 // percentage not allowed here
249 throw ::com::sun::star::lang::IllegalArgumentException();
252 ::com::sun::star::awt::Point
aAWTPoint(0,0);
257 MapMode
aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit
));
258 ::Point aVCLPoint
= VCLUnoHelper::ConvertToVCLPoint(aPoint
);
259 ::Point aDevPoint
= mpOutputDevice
->PixelToLogic(aVCLPoint
, aMode
);
260 aAWTPoint
= VCLUnoHelper::ConvertToAWTPoint(aDevPoint
);
267 ::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
)
270 SolarMutexGuard aGuard
;
271 if (SourceUnit
== com::sun::star::util::MeasureUnit::PERCENT
||
272 SourceUnit
== com::sun::star::util::MeasureUnit::PIXEL
)
274 // pixel or percentage not allowed here
275 throw ::com::sun::star::lang::IllegalArgumentException();
278 ::com::sun::star::awt::Point
aAWTPoint(0,0);
282 MapMode
aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit
));
283 ::Point aVCLPoint
= VCLUnoHelper::ConvertToVCLPoint(aPoint
);
284 ::Point aDevPoint
= mpOutputDevice
->LogicToPixel(aVCLPoint
, aMode
);
285 aAWTPoint
= VCLUnoHelper::ConvertToAWTPoint(aDevPoint
);
291 ::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
)
294 SolarMutexGuard aGuard
;
295 if (TargetUnit
== com::sun::star::util::MeasureUnit::PERCENT
)
297 // percentage not allowed here
298 throw ::com::sun::star::lang::IllegalArgumentException();
301 ::com::sun::star::awt::Size
aAWTSize(0,0);
307 MapMode
aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit
));
308 ::Size aVCLSize
= VCLUnoHelper::ConvertToVCLSize(aSize
);
309 ::Size aDevSz
= mpOutputDevice
->PixelToLogic(aVCLSize
, aMode
);
310 aAWTSize
= VCLUnoHelper::ConvertToAWTSize(aDevSz
);
316 ::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
)
319 SolarMutexGuard aGuard
;
320 if (SourceUnit
== com::sun::star::util::MeasureUnit::PERCENT
||
321 SourceUnit
== com::sun::star::util::MeasureUnit::PIXEL
)
323 // pixel or percentage not allowed here
324 throw ::com::sun::star::lang::IllegalArgumentException();
327 ::com::sun::star::awt::Size
aAWTSize(0,0);
331 MapMode
aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit
));
332 ::Size aVCLSize
= VCLUnoHelper::ConvertToVCLSize(aSize
);
333 ::Size aDevSz
= mpOutputDevice
->LogicToPixel(aVCLSize
, aMode
);
334 aAWTSize
= VCLUnoHelper::ConvertToAWTSize(aDevSz
);
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */