2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-10-02 14:13:40 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
#include <com/sun/star/awt/DeviceCapability.hpp>
|
|
|
|
|
2008-06-25 13:21:47 +00:00
|
|
|
#include <com/sun/star/util/MeasureUnit.hpp>
|
2018-12-31 20:22:02 +01:00
|
|
|
#include <com/sun/star/lang/IllegalArgumentException.hpp>
|
2008-06-25 13:21:47 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <toolkit/awt/vclxdevice.hxx>
|
|
|
|
#include <toolkit/awt/vclxfont.hxx>
|
|
|
|
#include <toolkit/awt/vclxbitmap.hxx>
|
|
|
|
#include <toolkit/helper/vclunohelper.hxx>
|
|
|
|
#include <toolkit/helper/macros.hxx>
|
2014-11-18 00:06:30 +01:00
|
|
|
#include <cppuhelper/queryinterface.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#include <vcl/outdev.hxx>
|
|
|
|
#include <vcl/window.hxx>
|
|
|
|
#include <vcl/print.hxx>
|
|
|
|
#include <vcl/virdev.hxx>
|
|
|
|
#include <vcl/bitmapex.hxx>
|
2018-12-31 20:22:02 +01:00
|
|
|
#include <vcl/metric.hxx>
|
2014-02-25 22:29:44 +01:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
// class VCLXDevice
|
2014-02-25 22:29:44 +01:00
|
|
|
|
2010-11-01 00:22:41 -05:00
|
|
|
VCLXDevice::VCLXDevice()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VCLXDevice::~VCLXDevice()
|
|
|
|
{
|
2015-06-17 15:18:10 +02:00
|
|
|
//TODO: why was this empty, and everything done in ~VCLXVirtualDevice?
|
|
|
|
SolarMutexGuard g;
|
|
|
|
mpOutputDevice.reset();
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
// css::lang::XUnoTunnel
|
2019-06-04 02:29:43 +03:00
|
|
|
UNO3_GETIMPLEMENTATION_IMPL( VCLXDevice );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
// css::awt::XDevice,
|
2017-01-26 12:28:58 +01:00
|
|
|
css::uno::Reference< css::awt::XGraphics > VCLXDevice::createGraphics( )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2010-11-01 00:22:41 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
css::uno::Reference< css::awt::XGraphics > xRef;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if ( mpOutputDevice )
|
|
|
|
xRef = mpOutputDevice->CreateUnoGraphics();
|
|
|
|
|
|
|
|
return xRef;
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
css::uno::Reference< css::awt::XDevice > VCLXDevice::createDevice( sal_Int32 nWidth, sal_Int32 nHeight )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2010-11-01 00:22:41 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
css::uno::Reference< css::awt::XDevice > xRef;
|
2000-09-18 16:07:07 +00:00
|
|
|
if ( GetOutputDevice() )
|
|
|
|
{
|
|
|
|
VCLXVirtualDevice* pVDev = new VCLXVirtualDevice;
|
2015-04-16 22:18:45 +01:00
|
|
|
VclPtrInstance<VirtualDevice> pVclVDev( *GetOutputDevice() );
|
2000-09-18 16:07:07 +00:00
|
|
|
pVclVDev->SetOutputSizePixel( Size( nWidth, nHeight ) );
|
|
|
|
pVDev->SetVirtualDevice( pVclVDev );
|
|
|
|
xRef = pVDev;
|
|
|
|
}
|
|
|
|
return xRef;
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
css::awt::DeviceInfo VCLXDevice::getInfo()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2010-11-01 00:22:41 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
css::awt::DeviceInfo aInfo;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if( mpOutputDevice )
|
|
|
|
{
|
|
|
|
Size aDevSz;
|
|
|
|
OutDevType eDevType = mpOutputDevice->GetOutDevType();
|
|
|
|
if ( eDevType == OUTDEV_WINDOW )
|
|
|
|
{
|
2015-03-14 22:17:43 +00:00
|
|
|
aDevSz = static_cast<vcl::Window*>(mpOutputDevice.get())->GetSizePixel();
|
|
|
|
static_cast<vcl::Window*>(mpOutputDevice.get())->GetBorder( aInfo.LeftInset, aInfo.TopInset, aInfo.RightInset, aInfo.BottomInset );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else if ( eDevType == OUTDEV_PRINTER )
|
|
|
|
{
|
2015-03-14 22:17:43 +00:00
|
|
|
aDevSz = static_cast<Printer*>(mpOutputDevice.get())->GetPaperSizePixel();
|
2000-09-18 16:07:07 +00:00
|
|
|
Size aOutSz = mpOutputDevice->GetOutputSizePixel();
|
2015-03-14 22:17:43 +00:00
|
|
|
Point aOffset = static_cast<Printer*>(mpOutputDevice.get())->GetPageOffset();
|
2000-09-18 16:07:07 +00:00
|
|
|
aInfo.LeftInset = aOffset.X();
|
|
|
|
aInfo.TopInset = aOffset.Y();
|
|
|
|
aInfo.RightInset = aDevSz.Width() - aOutSz.Width() - aOffset.X();
|
|
|
|
aInfo.BottomInset = aDevSz.Height() - aOutSz.Height() - aOffset.Y();
|
|
|
|
}
|
|
|
|
else // VirtualDevice
|
|
|
|
{
|
|
|
|
aDevSz = mpOutputDevice->GetOutputSizePixel();
|
|
|
|
aInfo.LeftInset = 0;
|
|
|
|
aInfo.TopInset = 0;
|
|
|
|
aInfo.RightInset = 0;
|
|
|
|
aInfo.BottomInset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
aInfo.Width = aDevSz.Width();
|
|
|
|
aInfo.Height = aDevSz.Height();
|
|
|
|
|
2016-09-20 16:41:39 +02:00
|
|
|
Size aTmpSz = mpOutputDevice->LogicToPixel( Size( 1000, 1000 ), MapMode( MapUnit::MapCM ) );
|
2000-09-18 16:07:07 +00:00
|
|
|
aInfo.PixelPerMeterX = aTmpSz.Width()/10;
|
|
|
|
aInfo.PixelPerMeterY = aTmpSz.Height()/10;
|
|
|
|
|
|
|
|
aInfo.BitsPerPixel = mpOutputDevice->GetBitCount();
|
|
|
|
|
|
|
|
aInfo.Capabilities = 0;
|
|
|
|
if ( mpOutputDevice->GetOutDevType() != OUTDEV_PRINTER )
|
2015-11-09 09:05:08 +02:00
|
|
|
aInfo.Capabilities = css::awt::DeviceCapability::RASTEROPERATIONS|css::awt::DeviceCapability::GETBITS;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return aInfo;
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
css::uno::Sequence< css::awt::FontDescriptor > VCLXDevice::getFontDescriptors( )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2010-11-01 00:22:41 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
css::uno::Sequence< css::awt::FontDescriptor> aFonts;
|
2000-09-18 16:07:07 +00:00
|
|
|
if( mpOutputDevice )
|
|
|
|
{
|
2006-10-12 09:30:48 +00:00
|
|
|
int nFonts = mpOutputDevice->GetDevFontCount();
|
2000-09-18 16:07:07 +00:00
|
|
|
if ( nFonts )
|
|
|
|
{
|
2015-11-09 09:05:08 +02:00
|
|
|
aFonts = css::uno::Sequence< css::awt::FontDescriptor>( nFonts );
|
|
|
|
css::awt::FontDescriptor* pFonts = aFonts.getArray();
|
2006-10-12 09:30:48 +00:00
|
|
|
for ( int n = 0; n < nFonts; n++ )
|
2000-09-18 16:07:07 +00:00
|
|
|
pFonts[n] = VCLUnoHelper::CreateFontDescriptor( mpOutputDevice->GetDevFont( n ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aFonts;
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
css::uno::Reference< css::awt::XFont > VCLXDevice::getFont( const css::awt::FontDescriptor& rDescriptor )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2010-11-01 00:22:41 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
css::uno::Reference< css::awt::XFont > xRef;
|
2000-09-18 16:07:07 +00:00
|
|
|
if( mpOutputDevice )
|
|
|
|
{
|
|
|
|
VCLXFont* pMetric = new VCLXFont;
|
|
|
|
pMetric->Init( *this, VCLUnoHelper::CreateFont( rDescriptor, mpOutputDevice->GetFont() ) );
|
|
|
|
xRef = pMetric;
|
|
|
|
}
|
|
|
|
return xRef;
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
css::uno::Reference< css::awt::XBitmap > VCLXDevice::createBitmap( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2010-11-01 00:22:41 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
css::uno::Reference< css::awt::XBitmap > xBmp;
|
2000-09-18 16:07:07 +00:00
|
|
|
if( mpOutputDevice )
|
|
|
|
{
|
2018-06-01 16:37:57 +02:00
|
|
|
BitmapEx aBmp = mpOutputDevice->GetBitmapEx( Point( nX, nY ), Size( nWidth, nHeight ) );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
VCLXBitmap* pBmp = new VCLXBitmap;
|
2018-06-01 16:37:57 +02:00
|
|
|
pBmp->SetBitmap( aBmp );
|
2000-09-18 16:07:07 +00:00
|
|
|
xBmp = pBmp;
|
|
|
|
}
|
|
|
|
return xBmp;
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
css::uno::Reference< css::awt::XDisplayBitmap > VCLXDevice::createDisplayBitmap( const css::uno::Reference< css::awt::XBitmap >& rxBitmap )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2010-11-01 00:22:41 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
BitmapEx aBmp = VCLUnoHelper::GetBitmap( rxBitmap );
|
|
|
|
VCLXBitmap* pBmp = new VCLXBitmap;
|
|
|
|
pBmp->SetBitmap( aBmp );
|
2015-11-09 09:05:08 +02:00
|
|
|
css::uno::Reference< css::awt::XDisplayBitmap > xDBmp = pBmp;
|
2000-09-18 16:07:07 +00:00
|
|
|
return xDBmp;
|
|
|
|
}
|
|
|
|
|
2001-05-15 11:34:01 +00:00
|
|
|
VCLXVirtualDevice::~VCLXVirtualDevice()
|
|
|
|
{
|
2010-11-01 00:22:41 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2001-05-15 11:34:01 +00:00
|
|
|
|
2015-03-14 22:17:43 +00:00
|
|
|
mpOutputDevice.disposeAndClear();
|
2001-05-15 11:34:01 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
// Interface implementation of css::awt::XUnitConversion
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
css::awt::Point SAL_CALL VCLXDevice::convertPointToLogic( const css::awt::Point& aPoint, ::sal_Int16 TargetUnit )
|
2008-06-25 13:21:47 +00:00
|
|
|
{
|
2010-11-01 00:22:41 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2015-11-09 09:05:08 +02:00
|
|
|
if (TargetUnit == css::util::MeasureUnit::PERCENT )
|
2008-06-25 13:21:47 +00:00
|
|
|
{
|
2009-02-13 07:10:18 +00:00
|
|
|
// percentage not allowed here
|
2015-11-09 09:05:08 +02:00
|
|
|
throw css::lang::IllegalArgumentException();
|
2008-06-25 13:21:47 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
css::awt::Point aAWTPoint(0,0);
|
2008-06-25 13:21:47 +00:00
|
|
|
// X,Y
|
|
|
|
|
|
|
|
if( mpOutputDevice )
|
|
|
|
{
|
|
|
|
MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit));
|
|
|
|
::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
|
|
|
|
::Point aDevPoint = mpOutputDevice->PixelToLogic(aVCLPoint, aMode );
|
|
|
|
aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
return aAWTPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
css::awt::Point SAL_CALL VCLXDevice::convertPointToPixel( const css::awt::Point& aPoint, ::sal_Int16 SourceUnit )
|
2008-06-25 13:21:47 +00:00
|
|
|
{
|
2010-11-01 00:22:41 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2015-11-09 09:05:08 +02:00
|
|
|
if (SourceUnit == css::util::MeasureUnit::PERCENT ||
|
|
|
|
SourceUnit == css::util::MeasureUnit::PIXEL )
|
2008-06-25 13:21:47 +00:00
|
|
|
{
|
|
|
|
// pixel or percentage not allowed here
|
2015-11-09 09:05:08 +02:00
|
|
|
throw css::lang::IllegalArgumentException();
|
2008-06-25 13:21:47 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
css::awt::Point aAWTPoint(0,0);
|
2008-06-25 13:21:47 +00:00
|
|
|
|
|
|
|
if( mpOutputDevice )
|
|
|
|
{
|
|
|
|
MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit));
|
|
|
|
::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
|
|
|
|
::Point aDevPoint = mpOutputDevice->LogicToPixel(aVCLPoint, aMode );
|
|
|
|
aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
return aAWTPoint;
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
css::awt::Size SAL_CALL VCLXDevice::convertSizeToLogic( const css::awt::Size& aSize, ::sal_Int16 TargetUnit )
|
2008-06-25 13:21:47 +00:00
|
|
|
{
|
2010-11-01 00:22:41 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2015-11-09 09:05:08 +02:00
|
|
|
if (TargetUnit == css::util::MeasureUnit::PERCENT)
|
2008-06-25 13:21:47 +00:00
|
|
|
{
|
2009-02-13 07:10:18 +00:00
|
|
|
// percentage not allowed here
|
2015-11-09 09:05:08 +02:00
|
|
|
throw css::lang::IllegalArgumentException();
|
2008-06-25 13:21:47 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
css::awt::Size aAWTSize(0,0);
|
2008-06-25 13:21:47 +00:00
|
|
|
// Width, Height
|
|
|
|
|
|
|
|
|
|
|
|
if( mpOutputDevice )
|
|
|
|
{
|
|
|
|
MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit));
|
|
|
|
::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
|
|
|
|
::Size aDevSz = mpOutputDevice->PixelToLogic(aVCLSize, aMode );
|
|
|
|
aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
|
|
|
|
}
|
|
|
|
|
|
|
|
return aAWTSize;
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
css::awt::Size SAL_CALL VCLXDevice::convertSizeToPixel( const css::awt::Size& aSize, ::sal_Int16 SourceUnit )
|
2008-06-25 13:21:47 +00:00
|
|
|
{
|
2010-11-01 00:22:41 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2015-11-09 09:05:08 +02:00
|
|
|
if (SourceUnit == css::util::MeasureUnit::PERCENT ||
|
|
|
|
SourceUnit == css::util::MeasureUnit::PIXEL)
|
2008-06-25 13:21:47 +00:00
|
|
|
{
|
|
|
|
// pixel or percentage not allowed here
|
2015-11-09 09:05:08 +02:00
|
|
|
throw css::lang::IllegalArgumentException();
|
2008-06-25 13:21:47 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
css::awt::Size aAWTSize(0,0);
|
2008-06-25 13:21:47 +00:00
|
|
|
// Width, Height
|
|
|
|
if( mpOutputDevice )
|
|
|
|
{
|
|
|
|
MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit));
|
|
|
|
::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
|
|
|
|
::Size aDevSz = mpOutputDevice->LogicToPixel(aVCLSize, aMode );
|
|
|
|
aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
|
|
|
|
}
|
|
|
|
|
|
|
|
return aAWTSize;
|
|
|
|
}
|
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|