Files
libreoffice/toolkit/source/awt/vclxdevice.cxx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

300 lines
9.2 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* 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>
#include <com/sun/star/util/MeasureUnit.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
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>
#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>
#include <vcl/metric.hxx>
2000-09-18 16:07:07 +00:00
// class VCLXDevice
VCLXDevice::VCLXDevice()
2000-09-18 16:07:07 +00:00
{
}
VCLXDevice::~VCLXDevice()
{
//TODO: why was this empty, and everything done in ~VCLXVirtualDevice?
SolarMutexGuard g;
mpOutputDevice.reset();
2000-09-18 16:07:07 +00:00
}
// css::lang::XUnoTunnel
UNO3_GETIMPLEMENTATION_IMPL( VCLXDevice );
2000-09-18 16:07:07 +00:00
// css::awt::XDevice,
css::uno::Reference< css::awt::XGraphics > VCLXDevice::createGraphics( )
2000-09-18 16:07:07 +00:00
{
SolarMutexGuard aGuard;
2000-09-18 16:07:07 +00:00
css::uno::Reference< css::awt::XGraphics > xRef;
2000-09-18 16:07:07 +00:00
if ( mpOutputDevice )
xRef = mpOutputDevice->CreateUnoGraphics();
return xRef;
}
css::uno::Reference< css::awt::XDevice > VCLXDevice::createDevice( sal_Int32 nWidth, sal_Int32 nHeight )
2000-09-18 16:07:07 +00:00
{
SolarMutexGuard aGuard;
2000-09-18 16:07:07 +00:00
css::uno::Reference< css::awt::XDevice > xRef;
2000-09-18 16:07:07 +00:00
if ( GetOutputDevice() )
{
VCLXVirtualDevice* pVDev = new VCLXVirtualDevice;
VclPtrInstance<VirtualDevice> pVclVDev( *GetOutputDevice() );
2000-09-18 16:07:07 +00:00
pVclVDev->SetOutputSizePixel( Size( nWidth, nHeight ) );
pVDev->SetVirtualDevice( pVclVDev );
xRef = pVDev;
}
return xRef;
}
css::awt::DeviceInfo VCLXDevice::getInfo()
2000-09-18 16:07:07 +00:00
{
SolarMutexGuard aGuard;
2000-09-18 16:07:07 +00: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 )
{
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 )
{
aDevSz = static_cast<Printer*>(mpOutputDevice.get())->GetPaperSizePixel();
2000-09-18 16:07:07 +00:00
Size aOutSz = mpOutputDevice->GetOutputSizePixel();
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();
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 )
aInfo.Capabilities = css::awt::DeviceCapability::RASTEROPERATIONS|css::awt::DeviceCapability::GETBITS;
2000-09-18 16:07:07 +00:00
}
return aInfo;
}
css::uno::Sequence< css::awt::FontDescriptor > VCLXDevice::getFontDescriptors( )
2000-09-18 16:07:07 +00:00
{
SolarMutexGuard aGuard;
2000-09-18 16:07:07 +00:00
css::uno::Sequence< css::awt::FontDescriptor> aFonts;
2000-09-18 16:07:07 +00:00
if( mpOutputDevice )
{
int nFonts = mpOutputDevice->GetDevFontCount();
2000-09-18 16:07:07 +00:00
if ( nFonts )
{
aFonts = css::uno::Sequence< css::awt::FontDescriptor>( nFonts );
css::awt::FontDescriptor* pFonts = aFonts.getArray();
for ( int n = 0; n < nFonts; n++ )
2000-09-18 16:07:07 +00:00
pFonts[n] = VCLUnoHelper::CreateFontDescriptor( mpOutputDevice->GetDevFont( n ) );
}
}
return aFonts;
}
css::uno::Reference< css::awt::XFont > VCLXDevice::getFont( const css::awt::FontDescriptor& rDescriptor )
2000-09-18 16:07:07 +00:00
{
SolarMutexGuard aGuard;
2000-09-18 16:07:07 +00: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;
}
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
{
SolarMutexGuard aGuard;
2000-09-18 16:07:07 +00:00
css::uno::Reference< css::awt::XBitmap > xBmp;
2000-09-18 16:07:07 +00:00
if( mpOutputDevice )
{
BitmapEx aBmp = mpOutputDevice->GetBitmapEx( Point( nX, nY ), Size( nWidth, nHeight ) );
2000-09-18 16:07:07 +00:00
VCLXBitmap* pBmp = new VCLXBitmap;
pBmp->SetBitmap( aBmp );
2000-09-18 16:07:07 +00:00
xBmp = pBmp;
}
return xBmp;
}
css::uno::Reference< css::awt::XDisplayBitmap > VCLXDevice::createDisplayBitmap( const css::uno::Reference< css::awt::XBitmap >& rxBitmap )
2000-09-18 16:07:07 +00:00
{
SolarMutexGuard aGuard;
2000-09-18 16:07:07 +00:00
BitmapEx aBmp = VCLUnoHelper::GetBitmap( rxBitmap );
VCLXBitmap* pBmp = new VCLXBitmap;
pBmp->SetBitmap( aBmp );
css::uno::Reference< css::awt::XDisplayBitmap > xDBmp = pBmp;
2000-09-18 16:07:07 +00:00
return xDBmp;
}
VCLXVirtualDevice::~VCLXVirtualDevice()
{
SolarMutexGuard aGuard;
mpOutputDevice.disposeAndClear();
}
// Interface implementation of css::awt::XUnitConversion
css::awt::Point SAL_CALL VCLXDevice::convertPointToLogic( const css::awt::Point& aPoint, ::sal_Int16 TargetUnit )
{
SolarMutexGuard aGuard;
if (TargetUnit == css::util::MeasureUnit::PERCENT )
{
CWS-TOOLING: integrate CWS dba31g 2009-02-06 09:31:37 +0100 fs r267443 : line ends 2009-02-06 09:31:16 +0100 fs r267442 : line ends 2009-01-26 09:21:13 +0100 msc r266904 : #i10000# reactive tests 2009-01-21 12:38:53 +0100 msc r266657 : #i98316# add bugid 2009-01-20 14:49:04 +0100 msc r266584 : i97307 2009-01-20 13:43:22 +0100 oj r266572 : #i978i97860# merge changes from dba31h 2009-01-19 12:12:27 +0100 oj r266487 : #i97307# wrong shortcuts 2009-01-12 11:45:03 +0100 fs r266139 : #i97867# ImplPaint: don't paint if there are not items (yet) 2009-01-08 20:34:46 +0100 fs r266039 : ignore output paths 2009-01-08 20:25:45 +0100 fs r266038 : spelling: unxols4 -> unxsols4 2009-01-08 20:16:10 +0100 fs r266037 : BUILD_QADEVOOO 2009-01-08 20:15:35 +0100 fs r266036 : ignore output paths 2009-01-07 22:47:01 +0100 fs r265978 : close the document after the test 2009-01-07 22:40:22 +0100 fs r265977 : tweak the test, some behavior worked in a timing-dependent fashion only 2009-01-07 13:21:48 +0100 lla r265961 : #i96526# need FileAccess instead of File due to URL incompatibity 2009-01-07 12:27:19 +0100 lla r265959 : #i96526# need FileAccess instead of File due to URL incompatibity 2009-01-06 13:30:04 +0100 fs r265917 : #158964# GetFormControl: don't accept requests for model which do not belong to the page displayed in the given view 2009-01-06 13:30:04 +0100 fs r265916 : #158964# GetUnoControl: don't accept requests for a view where a foreign page is displayed 2009-01-06 13:26:37 +0100 fs r265915 : #158964# FmXPageViewWinRec::dispose: catch exceptions (fixes the symptom, the root cause is fixed elsewhere) 2009-01-06 09:52:38 +0100 oj r265897 : #i97307# shortcuts 2009-01-06 09:41:26 +0100 fs r265896 : #i10000# 2009-01-05 13:40:38 +0100 fs r265866 : CWS-TOOLING: rebase CWS dba31g to trunk@265758 (milestone: DEV300:m38) 2008-12-18 11:35:43 +0100 fs r265678 : document the new InputRequired property 2008-12-17 07:25:18 +0100 oj r265578 : #i97307# insert new Accelerators handling in configuration 2008-12-16 09:52:27 +0100 lla r265526 : #i96526# error message is a problem with no existance default.otr occur 2008-12-16 09:33:14 +0100 oj r265525 : #i96948# remove merge conflict with StreamName 2008-12-16 09:22:12 +0100 oj r265524 : #i96935# set reportcomponent for custom shape 2008-12-15 10:32:38 +0100 oj r265463 : #i96965# do not add connection for selfreferencing table 2008-12-12 14:00:56 +0100 fs r265416 : #i97044# EnableFocusSelectionHide=FALSE => don't hide selection when not focused (this is more of a side effect), and preserve the selection when gaining the focus (this is the desired effect) 2008-12-11 15:32:32 +0100 fs r265319 : prevent a deadlock during complex.dbaccess.DatabaseDocument test 2008-12-11 15:31:25 +0100 fs r265317 : prevent a deadlock during complex.dbaccess.DatabaseDocument test 2008-12-11 13:45:06 +0100 fs r265296 : #i97137# 2008-12-11 12:43:00 +0100 fs r265285 : #i97134# 2008-12-10 13:20:28 +0100 lla r265175 : #94067# add (APP|SYS)FONT to XUnitConversion interface implementation 2008-12-10 13:08:22 +0100 lla r265173 : #i94067# add (APP|SYS)FONT 2008-12-10 09:21:39 +0100 fs r265151 : #i95010# implement a non-hacky solution for #i94033#, by making Begin/Do/EndCompleteRedraw virtual 2008-12-09 17:29:32 +0100 fs r265120 : #i96636#
2009-02-13 07:10:18 +00:00
// percentage not allowed here
throw css::lang::IllegalArgumentException();
}
css::awt::Point aAWTPoint(0,0);
// 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;
}
css::awt::Point SAL_CALL VCLXDevice::convertPointToPixel( const css::awt::Point& aPoint, ::sal_Int16 SourceUnit )
{
SolarMutexGuard aGuard;
if (SourceUnit == css::util::MeasureUnit::PERCENT ||
SourceUnit == css::util::MeasureUnit::PIXEL )
{
// pixel or percentage not allowed here
throw css::lang::IllegalArgumentException();
}
css::awt::Point aAWTPoint(0,0);
if( mpOutputDevice )
{
MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit));
::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
::Point aDevPoint = mpOutputDevice->LogicToPixel(aVCLPoint, aMode );
aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
}
return aAWTPoint;
}
css::awt::Size SAL_CALL VCLXDevice::convertSizeToLogic( const css::awt::Size& aSize, ::sal_Int16 TargetUnit )
{
SolarMutexGuard aGuard;
if (TargetUnit == css::util::MeasureUnit::PERCENT)
{
CWS-TOOLING: integrate CWS dba31g 2009-02-06 09:31:37 +0100 fs r267443 : line ends 2009-02-06 09:31:16 +0100 fs r267442 : line ends 2009-01-26 09:21:13 +0100 msc r266904 : #i10000# reactive tests 2009-01-21 12:38:53 +0100 msc r266657 : #i98316# add bugid 2009-01-20 14:49:04 +0100 msc r266584 : i97307 2009-01-20 13:43:22 +0100 oj r266572 : #i978i97860# merge changes from dba31h 2009-01-19 12:12:27 +0100 oj r266487 : #i97307# wrong shortcuts 2009-01-12 11:45:03 +0100 fs r266139 : #i97867# ImplPaint: don't paint if there are not items (yet) 2009-01-08 20:34:46 +0100 fs r266039 : ignore output paths 2009-01-08 20:25:45 +0100 fs r266038 : spelling: unxols4 -> unxsols4 2009-01-08 20:16:10 +0100 fs r266037 : BUILD_QADEVOOO 2009-01-08 20:15:35 +0100 fs r266036 : ignore output paths 2009-01-07 22:47:01 +0100 fs r265978 : close the document after the test 2009-01-07 22:40:22 +0100 fs r265977 : tweak the test, some behavior worked in a timing-dependent fashion only 2009-01-07 13:21:48 +0100 lla r265961 : #i96526# need FileAccess instead of File due to URL incompatibity 2009-01-07 12:27:19 +0100 lla r265959 : #i96526# need FileAccess instead of File due to URL incompatibity 2009-01-06 13:30:04 +0100 fs r265917 : #158964# GetFormControl: don't accept requests for model which do not belong to the page displayed in the given view 2009-01-06 13:30:04 +0100 fs r265916 : #158964# GetUnoControl: don't accept requests for a view where a foreign page is displayed 2009-01-06 13:26:37 +0100 fs r265915 : #158964# FmXPageViewWinRec::dispose: catch exceptions (fixes the symptom, the root cause is fixed elsewhere) 2009-01-06 09:52:38 +0100 oj r265897 : #i97307# shortcuts 2009-01-06 09:41:26 +0100 fs r265896 : #i10000# 2009-01-05 13:40:38 +0100 fs r265866 : CWS-TOOLING: rebase CWS dba31g to trunk@265758 (milestone: DEV300:m38) 2008-12-18 11:35:43 +0100 fs r265678 : document the new InputRequired property 2008-12-17 07:25:18 +0100 oj r265578 : #i97307# insert new Accelerators handling in configuration 2008-12-16 09:52:27 +0100 lla r265526 : #i96526# error message is a problem with no existance default.otr occur 2008-12-16 09:33:14 +0100 oj r265525 : #i96948# remove merge conflict with StreamName 2008-12-16 09:22:12 +0100 oj r265524 : #i96935# set reportcomponent for custom shape 2008-12-15 10:32:38 +0100 oj r265463 : #i96965# do not add connection for selfreferencing table 2008-12-12 14:00:56 +0100 fs r265416 : #i97044# EnableFocusSelectionHide=FALSE => don't hide selection when not focused (this is more of a side effect), and preserve the selection when gaining the focus (this is the desired effect) 2008-12-11 15:32:32 +0100 fs r265319 : prevent a deadlock during complex.dbaccess.DatabaseDocument test 2008-12-11 15:31:25 +0100 fs r265317 : prevent a deadlock during complex.dbaccess.DatabaseDocument test 2008-12-11 13:45:06 +0100 fs r265296 : #i97137# 2008-12-11 12:43:00 +0100 fs r265285 : #i97134# 2008-12-10 13:20:28 +0100 lla r265175 : #94067# add (APP|SYS)FONT to XUnitConversion interface implementation 2008-12-10 13:08:22 +0100 lla r265173 : #i94067# add (APP|SYS)FONT 2008-12-10 09:21:39 +0100 fs r265151 : #i95010# implement a non-hacky solution for #i94033#, by making Begin/Do/EndCompleteRedraw virtual 2008-12-09 17:29:32 +0100 fs r265120 : #i96636#
2009-02-13 07:10:18 +00:00
// percentage not allowed here
throw css::lang::IllegalArgumentException();
}
css::awt::Size aAWTSize(0,0);
// 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;
}
css::awt::Size SAL_CALL VCLXDevice::convertSizeToPixel( const css::awt::Size& aSize, ::sal_Int16 SourceUnit )
{
SolarMutexGuard aGuard;
if (SourceUnit == css::util::MeasureUnit::PERCENT ||
SourceUnit == css::util::MeasureUnit::PIXEL)
{
// pixel or percentage not allowed here
throw css::lang::IllegalArgumentException();
}
css::awt::Size aAWTSize(0,0);
// 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;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */