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

Generated by: LCOV version 1.10