LCOV - code coverage report
Current view: top level - toolkit/source/awt - vclxdevice.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 90 153 58.8 %
Date: 2014-04-11 Functions: 17 24 70.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/awt/DeviceCapability.hpp>
      21             : 
      22             : #include <com/sun/star/util/MeasureUnit.hpp>
      23             : 
      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             : 
      31             : #include <rtl/uuid.h>
      32             : 
      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>
      40             : 
      41             : 
      42             : //  class VCLXDevice
      43             : 
      44       41368 : VCLXDevice::VCLXDevice()
      45             :     : mpOutputDevice(NULL)
      46             :     , pDummy(NULL)
      47       41368 :     , nFlags(0)
      48             : {
      49       41368 : }
      50             : 
      51       36059 : VCLXDevice::~VCLXDevice()
      52             : {
      53       36059 : }
      54             : 
      55       27130 : void VCLXDevice::DestroyOutputDevice()
      56             : {
      57       27130 :     delete mpOutputDevice;
      58       27130 :     mpOutputDevice = NULL;
      59       27130 : }
      60             : 
      61        2389 : void VCLXDevice::SetCreatedWithToolkit( bool bCreatedWithToolkit )
      62             : {
      63        2389 :     if ( bCreatedWithToolkit )
      64        2389 :         nFlags |= FLAGS_CREATEDWITHTOOLKIT;
      65             :     else
      66           0 :         nFlags &= ~FLAGS_CREATEDWITHTOOLKIT;
      67        2389 : }
      68             : 
      69             : // ::com::sun::star::uno::XInterface
      70      541462 : ::com::sun::star::uno::Any VCLXDevice::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException, std::exception)
      71             : {
      72             :     ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
      73             :                                         (static_cast< ::com::sun::star::awt::XDevice* >(this)),
      74             :                                         (static_cast< ::com::sun::star::lang::XUnoTunnel* >(this)),
      75             :                                         (static_cast< ::com::sun::star::lang::XTypeProvider* >(this)),
      76      541462 :                                         (static_cast< ::com::sun::star::awt::XUnitConversion* >(this)) );
      77      541462 :     return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
      78             : }
      79             : 
      80             : // ::com::sun::star::lang::XUnoTunnel
      81       15619 : IMPL_XUNOTUNNEL( VCLXDevice )
      82             : 
      83             : // ::com::sun::star::lang::XTypeProvider
      84           0 : IMPL_XTYPEPROVIDER_START( VCLXDevice )
      85           0 :     getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice>* ) NULL ),
      86           0 :     getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XUnitConversion>* ) NULL )
      87           0 : IMPL_XTYPEPROVIDER_END
      88             : 
      89             : 
      90             : // ::com::sun::star::awt::XDevice,
      91          31 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > VCLXDevice::createGraphics(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
      92             : {
      93          31 :     SolarMutexGuard aGuard;
      94             : 
      95          31 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > xRef;
      96             : 
      97          31 :     if ( mpOutputDevice )
      98          31 :         xRef = mpOutputDevice->CreateUnoGraphics();
      99             : 
     100          31 :     return xRef;
     101             : }
     102             : 
     103           0 : ::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)
     104             : {
     105           0 :     SolarMutexGuard aGuard;
     106             : 
     107           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice >  xRef;
     108           0 :     if ( GetOutputDevice() )
     109             :     {
     110           0 :         VCLXVirtualDevice* pVDev = new VCLXVirtualDevice;
     111           0 :         VirtualDevice* pVclVDev = new VirtualDevice( *GetOutputDevice() );
     112           0 :         pVclVDev->SetOutputSizePixel( Size( nWidth, nHeight ) );
     113           0 :         pVDev->SetVirtualDevice( pVclVDev );
     114           0 :         xRef = pVDev;
     115             :     }
     116           0 :     return xRef;
     117             : }
     118             : 
     119       27605 : ::com::sun::star::awt::DeviceInfo VCLXDevice::getInfo() throw(::com::sun::star::uno::RuntimeException, std::exception)
     120             : {
     121       27605 :     SolarMutexGuard aGuard;
     122             : 
     123       27605 :     ::com::sun::star::awt::DeviceInfo aInfo;
     124             : 
     125       27605 :     if( mpOutputDevice )
     126             :     {
     127       27605 :         Size aDevSz;
     128       27605 :         OutDevType eDevType = mpOutputDevice->GetOutDevType();
     129       27605 :         if ( eDevType == OUTDEV_WINDOW )
     130             :         {
     131       27561 :             aDevSz = ((Window*)mpOutputDevice)->GetSizePixel();
     132       27561 :             ((Window*)mpOutputDevice)->GetBorder( aInfo.LeftInset, aInfo.TopInset, aInfo.RightInset, aInfo.BottomInset );
     133             :         }
     134          44 :         else if ( eDevType == OUTDEV_PRINTER )
     135             :         {
     136           0 :             aDevSz = ((Printer*)mpOutputDevice)->GetPaperSizePixel();
     137           0 :             Size aOutSz = mpOutputDevice->GetOutputSizePixel();
     138           0 :             Point aOffset = ((Printer*)mpOutputDevice)->GetPageOffset();
     139           0 :             aInfo.LeftInset = aOffset.X();
     140           0 :             aInfo.TopInset = aOffset.Y();
     141           0 :             aInfo.RightInset = aDevSz.Width() - aOutSz.Width() - aOffset.X();
     142           0 :             aInfo.BottomInset = aDevSz.Height() - aOutSz.Height() - aOffset.Y();
     143             :         }
     144             :         else // VirtualDevice
     145             :         {
     146          44 :             aDevSz = mpOutputDevice->GetOutputSizePixel();
     147          44 :             aInfo.LeftInset = 0;
     148          44 :             aInfo.TopInset = 0;
     149          44 :             aInfo.RightInset = 0;
     150          44 :             aInfo.BottomInset = 0;
     151             :         }
     152             : 
     153       27605 :         aInfo.Width = aDevSz.Width();
     154       27605 :         aInfo.Height = aDevSz.Height();
     155             : 
     156       27605 :         Size aTmpSz = mpOutputDevice->LogicToPixel( Size( 1000, 1000 ), MapMode( MAP_CM ) );
     157       27605 :         aInfo.PixelPerMeterX = aTmpSz.Width()/10;
     158       27605 :         aInfo.PixelPerMeterY = aTmpSz.Height()/10;
     159             : 
     160       27605 :         aInfo.BitsPerPixel = mpOutputDevice->GetBitCount();
     161             : 
     162       27605 :         aInfo.Capabilities = 0;
     163       27605 :         if ( mpOutputDevice->GetOutDevType() != OUTDEV_PRINTER )
     164       27605 :             aInfo.Capabilities = ::com::sun::star::awt::DeviceCapability::RASTEROPERATIONS|::com::sun::star::awt::DeviceCapability::GETBITS;
     165             :     }
     166             : 
     167       27605 :     return aInfo;
     168             : }
     169             : 
     170           0 : ::com::sun::star::uno::Sequence< ::com::sun::star::awt::FontDescriptor > VCLXDevice::getFontDescriptors(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     171             : {
     172           0 :     SolarMutexGuard aGuard;
     173             : 
     174           0 :     ::com::sun::star::uno::Sequence< ::com::sun::star::awt::FontDescriptor> aFonts;
     175           0 :     if( mpOutputDevice )
     176             :     {
     177           0 :         int nFonts = mpOutputDevice->GetDevFontCount();
     178           0 :         if ( nFonts )
     179             :         {
     180           0 :             aFonts = ::com::sun::star::uno::Sequence< ::com::sun::star::awt::FontDescriptor>( nFonts );
     181           0 :             ::com::sun::star::awt::FontDescriptor* pFonts = aFonts.getArray();
     182           0 :             for ( int n = 0; n < nFonts; n++ )
     183           0 :                 pFonts[n] = VCLUnoHelper::CreateFontDescriptor( mpOutputDevice->GetDevFont( n ) );
     184             :         }
     185             :     }
     186           0 :     return aFonts;
     187             : }
     188             : 
     189         240 : ::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)
     190             : {
     191         240 :     SolarMutexGuard aGuard;
     192             : 
     193         240 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont >  xRef;
     194         240 :     if( mpOutputDevice )
     195             :     {
     196         240 :         VCLXFont* pMetric = new VCLXFont;
     197         240 :         pMetric->Init( *this, VCLUnoHelper::CreateFont( rDescriptor, mpOutputDevice->GetFont() ) );
     198         240 :         xRef = pMetric;
     199             :     }
     200         240 :     return xRef;
     201             : }
     202             : 
     203           0 : ::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)
     204             : {
     205           0 :     SolarMutexGuard aGuard;
     206             : 
     207           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap >  xBmp;
     208           0 :     if( mpOutputDevice )
     209             :     {
     210           0 :         Bitmap aBmp = mpOutputDevice->GetBitmap( Point( nX, nY ), Size( nWidth, nHeight ) );
     211             : 
     212           0 :         VCLXBitmap* pBmp = new VCLXBitmap;
     213           0 :         pBmp->SetBitmap( BitmapEx( aBmp ) );
     214           0 :         xBmp = pBmp;
     215             :     }
     216           0 :     return xBmp;
     217             : }
     218             : 
     219           0 : ::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)
     220             : {
     221           0 :     SolarMutexGuard aGuard;
     222             : 
     223           0 :     BitmapEx aBmp = VCLUnoHelper::GetBitmap( rxBitmap );
     224           0 :     VCLXBitmap* pBmp = new VCLXBitmap;
     225           0 :     pBmp->SetBitmap( aBmp );
     226           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayBitmap >  xDBmp = pBmp;
     227           0 :     return xDBmp;
     228             : }
     229             : 
     230             : 
     231          96 : VCLXVirtualDevice::~VCLXVirtualDevice()
     232             : {
     233          32 :     SolarMutexGuard aGuard;
     234             : 
     235          32 :     DestroyOutputDevice();
     236          64 : }
     237             : 
     238             : 
     239             : 
     240             : // Interface implementation of ::com::sun::star::awt::XUnitConversion
     241             : 
     242             : 
     243           9 : ::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)
     244             : {
     245             :     (void)aPoint;
     246           9 :     SolarMutexGuard aGuard;
     247           9 :     if (TargetUnit == com::sun::star::util::MeasureUnit::PERCENT )
     248             :     {
     249             :         // percentage not allowed here
     250           0 :         throw ::com::sun::star::lang::IllegalArgumentException();
     251             :     }
     252             : 
     253           9 :     ::com::sun::star::awt::Point aAWTPoint(0,0);
     254             :     // X,Y
     255             : 
     256           9 :     if( mpOutputDevice )
     257             :     {
     258           9 :         MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit));
     259           9 :         ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
     260           9 :         ::Point aDevPoint = mpOutputDevice->PixelToLogic(aVCLPoint, aMode );
     261           9 :         aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
     262             :     }
     263             : 
     264           9 :     return aAWTPoint;
     265             : }
     266             : 
     267             : 
     268           0 : ::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)
     269             : {
     270             :     (void)aPoint;
     271           0 :     SolarMutexGuard aGuard;
     272           0 :     if (SourceUnit == com::sun::star::util::MeasureUnit::PERCENT ||
     273             :         SourceUnit == com::sun::star::util::MeasureUnit::PIXEL )
     274             :     {
     275             :         // pixel or percentage not allowed here
     276           0 :         throw ::com::sun::star::lang::IllegalArgumentException();
     277             :     }
     278             : 
     279           0 :     ::com::sun::star::awt::Point aAWTPoint(0,0);
     280             : 
     281           0 :     if( mpOutputDevice )
     282             :     {
     283           0 :         MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit));
     284           0 :         ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
     285           0 :         ::Point aDevPoint = mpOutputDevice->LogicToPixel(aVCLPoint, aMode );
     286           0 :         aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
     287             :     }
     288             : 
     289           0 :     return aAWTPoint;
     290             : }
     291             : 
     292          23 : ::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)
     293             : {
     294             :     (void)aSize;
     295          23 :     SolarMutexGuard aGuard;
     296          23 :     if (TargetUnit == com::sun::star::util::MeasureUnit::PERCENT)
     297             :     {
     298             :         // percentage not allowed here
     299           0 :         throw ::com::sun::star::lang::IllegalArgumentException();
     300             :     }
     301             : 
     302          23 :     ::com::sun::star::awt::Size aAWTSize(0,0);
     303             :     // Width, Height
     304             : 
     305             : 
     306          23 :     if( mpOutputDevice )
     307             :     {
     308          23 :         MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit));
     309          23 :         ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
     310          23 :         ::Size aDevSz = mpOutputDevice->PixelToLogic(aVCLSize, aMode );
     311          23 :         aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
     312             :     }
     313             : 
     314          23 :     return aAWTSize;
     315             : }
     316             : 
     317           1 : ::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)
     318             : {
     319             :     (void)aSize;
     320           1 :     SolarMutexGuard aGuard;
     321           1 :     if (SourceUnit == com::sun::star::util::MeasureUnit::PERCENT ||
     322             :         SourceUnit == com::sun::star::util::MeasureUnit::PIXEL)
     323             :     {
     324             :         // pixel or percentage not allowed here
     325           0 :         throw ::com::sun::star::lang::IllegalArgumentException();
     326             :     }
     327             : 
     328           1 :     ::com::sun::star::awt::Size aAWTSize(0,0);
     329             :     // Width, Height
     330           1 :     if( mpOutputDevice )
     331             :     {
     332           1 :         MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit));
     333           1 :         ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
     334           1 :         ::Size aDevSz = mpOutputDevice->LogicToPixel(aVCLSize, aMode );
     335           1 :         aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
     336             :     }
     337             : 
     338           1 :     return aAWTSize;
     339             : }
     340             : 
     341             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10