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

Generated by: LCOV version 1.10