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

Generated by: LCOV version 1.10