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

Generated by: LCOV version 1.11