LCOV - code coverage report
Current view: top level - toolkit/source/awt - vclxdevice.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 91 154 59.1 %
Date: 2014-11-03 Functions: 19 26 73.1 %
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      134143 : VCLXDevice::VCLXDevice()
      45             :     : mpOutputDevice(NULL)
      46             :     , pDummy(NULL)
      47      134143 :     , nFlags(0)
      48             : {
      49      134143 : }
      50             : 
      51      116631 : VCLXDevice::~VCLXDevice()
      52             : {
      53      116631 : }
      54             : 
      55       72745 : void VCLXDevice::DestroyOutputDevice()
      56             : {
      57       72745 :     delete mpOutputDevice;
      58       72745 :     mpOutputDevice = NULL;
      59       72745 : }
      60             : 
      61        6193 : void VCLXDevice::SetCreatedWithToolkit( bool bCreatedWithToolkit )
      62             : {
      63        6193 :     if ( bCreatedWithToolkit )
      64        6193 :         nFlags |= FLAGS_CREATEDWITHTOOLKIT;
      65             :     else
      66           0 :         nFlags &= ~FLAGS_CREATEDWITHTOOLKIT;
      67        6193 : }
      68             : 
      69             : // ::com::sun::star::uno::XInterface
      70     1469132 : ::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     1469132 :                                         (static_cast< ::com::sun::star::awt::XUnitConversion* >(this)) );
      77     1469132 :     return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
      78             : }
      79             : 
      80             : // ::com::sun::star::lang::XUnoTunnel
      81       42728 : IMPL_XUNOTUNNEL( VCLXDevice )
      82             : 
      83             : // ::com::sun::star::lang::XTypeProvider
      84           0 : IMPL_XTYPEPROVIDER_START( VCLXDevice )
      85           0 :     cppu::UnoType<com::sun::star::awt::XDevice>::get(),
      86           0 :     cppu::UnoType<com::sun::star::awt::XUnitConversion>::get()
      87           0 : IMPL_XTYPEPROVIDER_END
      88             : 
      89             : 
      90             : // ::com::sun::star::awt::XDevice,
      91          62 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > VCLXDevice::createGraphics(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
      92             : {
      93          62 :     SolarMutexGuard aGuard;
      94             : 
      95          62 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > xRef;
      96             : 
      97          62 :     if ( mpOutputDevice )
      98          62 :         xRef = mpOutputDevice->CreateUnoGraphics();
      99             : 
     100          62 :     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       71497 : ::com::sun::star::awt::DeviceInfo VCLXDevice::getInfo() throw(::com::sun::star::uno::RuntimeException, std::exception)
     120             : {
     121       71497 :     SolarMutexGuard aGuard;
     122             : 
     123       71497 :     ::com::sun::star::awt::DeviceInfo aInfo;
     124             : 
     125       71497 :     if( mpOutputDevice )
     126             :     {
     127       71497 :         Size aDevSz;
     128       71497 :         OutDevType eDevType = mpOutputDevice->GetOutDevType();
     129       71497 :         if ( eDevType == OUTDEV_WINDOW )
     130             :         {
     131       71369 :             aDevSz = static_cast<vcl::Window*>(mpOutputDevice)->GetSizePixel();
     132       71369 :             static_cast<vcl::Window*>(mpOutputDevice)->GetBorder( aInfo.LeftInset, aInfo.TopInset, aInfo.RightInset, aInfo.BottomInset );
     133             :         }
     134         128 :         else if ( eDevType == OUTDEV_PRINTER )
     135             :         {
     136           0 :             aDevSz = static_cast<Printer*>(mpOutputDevice)->GetPaperSizePixel();
     137           0 :             Size aOutSz = mpOutputDevice->GetOutputSizePixel();
     138           0 :             Point aOffset = static_cast<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         128 :             aDevSz = mpOutputDevice->GetOutputSizePixel();
     147         128 :             aInfo.LeftInset = 0;
     148         128 :             aInfo.TopInset = 0;
     149         128 :             aInfo.RightInset = 0;
     150         128 :             aInfo.BottomInset = 0;
     151             :         }
     152             : 
     153       71497 :         aInfo.Width = aDevSz.Width();
     154       71497 :         aInfo.Height = aDevSz.Height();
     155             : 
     156       71497 :         Size aTmpSz = mpOutputDevice->LogicToPixel( Size( 1000, 1000 ), MapMode( MAP_CM ) );
     157       71497 :         aInfo.PixelPerMeterX = aTmpSz.Width()/10;
     158       71497 :         aInfo.PixelPerMeterY = aTmpSz.Height()/10;
     159             : 
     160       71497 :         aInfo.BitsPerPixel = mpOutputDevice->GetBitCount();
     161             : 
     162       71497 :         aInfo.Capabilities = 0;
     163       71497 :         if ( mpOutputDevice->GetOutDevType() != OUTDEV_PRINTER )
     164       71497 :             aInfo.Capabilities = ::com::sun::star::awt::DeviceCapability::RASTEROPERATIONS|::com::sun::star::awt::DeviceCapability::GETBITS;
     165             :     }
     166             : 
     167       71497 :     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         666 : ::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         666 :     SolarMutexGuard aGuard;
     192             : 
     193         666 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont >  xRef;
     194         666 :     if( mpOutputDevice )
     195             :     {
     196         666 :         VCLXFont* pMetric = new VCLXFont;
     197         666 :         pMetric->Init( *this, VCLUnoHelper::CreateFont( rDescriptor, mpOutputDevice->GetFont() ) );
     198         666 :         xRef = pMetric;
     199             :     }
     200         666 :     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         192 : VCLXVirtualDevice::~VCLXVirtualDevice()
     232             : {
     233          64 :     SolarMutexGuard aGuard;
     234             : 
     235          64 :     DestroyOutputDevice();
     236         128 : }
     237             : 
     238             : 
     239             : 
     240             : // Interface implementation of ::com::sun::star::awt::XUnitConversion
     241             : 
     242             : 
     243          18 : ::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          18 :     SolarMutexGuard aGuard;
     247          18 :     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          18 :     ::com::sun::star::awt::Point aAWTPoint(0,0);
     254             :     // X,Y
     255             : 
     256          18 :     if( mpOutputDevice )
     257             :     {
     258          18 :         MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit));
     259          18 :         ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
     260          18 :         ::Point aDevPoint = mpOutputDevice->PixelToLogic(aVCLPoint, aMode );
     261          18 :         aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
     262             :     }
     263             : 
     264          18 :     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          46 : ::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          46 :     SolarMutexGuard aGuard;
     296          46 :     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          46 :     ::com::sun::star::awt::Size aAWTSize(0,0);
     303             :     // Width, Height
     304             : 
     305             : 
     306          46 :     if( mpOutputDevice )
     307             :     {
     308          46 :         MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit));
     309          46 :         ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
     310          46 :         ::Size aDevSz = mpOutputDevice->PixelToLogic(aVCLSize, aMode );
     311          46 :         aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
     312             :     }
     313             : 
     314          46 :     return aAWTSize;
     315             : }
     316             : 
     317           2 : ::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           2 :     SolarMutexGuard aGuard;
     321           2 :     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           2 :     ::com::sun::star::awt::Size aAWTSize(0,0);
     329             :     // Width, Height
     330           2 :     if( mpOutputDevice )
     331             :     {
     332           2 :         MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit));
     333           2 :         ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
     334           2 :         ::Size aDevSz = mpOutputDevice->LogicToPixel(aVCLSize, aMode );
     335           2 :         aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
     336             :     }
     337             : 
     338           2 :     return aAWTSize;
     339        1227 : }
     340             : 
     341             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10