LCOV - code coverage report
Current view: top level - toolkit/source/helper - vclunohelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 222 394 56.3 %
Date: 2014-11-03 Functions: 29 39 74.4 %
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 <tools/stream.hxx>
      21             : #include <vcl/bitmap.hxx>
      22             : #include <vcl/window.hxx>
      23             : #include <sal/macros.h>
      24             : #include <com/sun/star/util/MeasureUnit.hpp>
      25             : #include <com/sun/star/awt/XBitmap.hpp>
      26             : #include <com/sun/star/awt/XWindow.hpp>
      27             : #include <com/sun/star/awt/XDevice.hpp>
      28             : #include <com/sun/star/awt/XPointer.hpp>
      29             : #include <com/sun/star/awt/SimpleFontMetric.hpp>
      30             : #include <com/sun/star/awt/FontDescriptor.hpp>
      31             : #include <com/sun/star/awt/XControlContainer.hpp>
      32             : #include <com/sun/star/awt/FontWeight.hpp>
      33             : #include <com/sun/star/awt/FontWidth.hpp>
      34             : #include <com/sun/star/awt/KeyModifier.hpp>
      35             : #include <com/sun/star/awt/MouseButton.hpp>
      36             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      37             : #include <com/sun/star/embed/EmbedMapUnits.hpp>
      38             : #include <com/sun/star/graphic/XGraphic.hpp>
      39             : #include <toolkit/helper/vclunohelper.hxx>
      40             : #include <toolkit/helper/convert.hxx>
      41             : #include <toolkit/awt/vclxbitmap.hxx>
      42             : #include <toolkit/awt/vclxregion.hxx>
      43             : #include <toolkit/awt/vclxwindow.hxx>
      44             : #include <toolkit/awt/vclxgraphics.hxx>
      45             : #include <toolkit/awt/vclxpointer.hxx>
      46             : #include <toolkit/awt/vclxfont.hxx>
      47             : #include <toolkit/controls/unocontrolcontainer.hxx>
      48             : #include <toolkit/controls/unocontrolcontainermodel.hxx>
      49             : #include <vcl/graph.hxx>
      50             : #include <comphelper/processfactory.hxx>
      51             : 
      52             : #include <com/sun/star/awt/Toolkit.hpp>
      53             : #include <com/sun/star/awt/Size.hpp>
      54             : #include <com/sun/star/awt/Point.hpp>
      55             : #include <vcl/dibtools.hxx>
      56             : 
      57             : using namespace ::com::sun::star;
      58             : 
      59             : 
      60             : //  class VCLUnoHelper
      61             : 
      62             : 
      63          34 : uno::Reference< ::com::sun::star::awt::XToolkit> VCLUnoHelper::CreateToolkit()
      64             : {
      65          34 :     uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
      66          34 :     uno::Reference< awt::XToolkit> xToolkit( awt::Toolkit::create(xContext), uno::UNO_QUERY_THROW );
      67          34 :     return xToolkit;
      68             : }
      69             : 
      70          78 : BitmapEx VCLUnoHelper::GetBitmap( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap>& rxBitmap )
      71             : {
      72          78 :     BitmapEx aBmp;
      73             : 
      74         156 :     ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > xGraphic( rxBitmap, ::com::sun::star::uno::UNO_QUERY );
      75          78 :     if( xGraphic.is() )
      76             :     {
      77          78 :         Graphic aGraphic( xGraphic );
      78          78 :         aBmp = aGraphic.GetBitmapEx();
      79             :     }
      80           0 :     else if ( rxBitmap.is() )
      81             :     {
      82           0 :         VCLXBitmap* pVCLBitmap = VCLXBitmap::GetImplementation( rxBitmap );
      83           0 :         if ( pVCLBitmap )
      84           0 :             aBmp = pVCLBitmap->GetBitmap();
      85             :         else
      86             :         {
      87           0 :             Bitmap aDIB, aMask;
      88             :             {
      89           0 :                 ::com::sun::star::uno::Sequence<sal_Int8> aBytes = rxBitmap->getDIB();
      90           0 :                 SvMemoryStream aMem( (char*) aBytes.getArray(), aBytes.getLength(), STREAM_READ );
      91           0 :                 ReadDIB(aDIB, aMem, true);
      92             :             }
      93             :             {
      94           0 :                 ::com::sun::star::uno::Sequence<sal_Int8> aBytes = rxBitmap->getMaskDIB();
      95           0 :                 SvMemoryStream aMem( (char*) aBytes.getArray(), aBytes.getLength(), STREAM_READ );
      96           0 :                 ReadDIB(aMask, aMem, true);
      97             :             }
      98           0 :             aBmp = BitmapEx( aDIB, aMask );
      99             :         }
     100             :     }
     101         156 :     return aBmp;
     102             : }
     103             : 
     104         998 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap> VCLUnoHelper::CreateBitmap( const BitmapEx& rBitmap )
     105             : {
     106         998 :     Graphic aGraphic( rBitmap );
     107         998 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap> xBmp( aGraphic.GetXGraphic(), ::com::sun::star::uno::UNO_QUERY );
     108         998 :     return xBmp;
     109             : }
     110             : 
     111      921038 : vcl::Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow>& rxWindow )
     112             : {
     113      921038 :     VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow );
     114      921038 :     return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL;
     115             : }
     116             : 
     117       27430 : vcl::Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow2>& rxWindow )
     118             : {
     119       27430 :     VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow );
     120       27430 :     return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL;
     121             : }
     122             : 
     123       10263 : vcl::Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer>& rxWindow )
     124             : {
     125       10263 :     VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow );
     126       10263 :     return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL;
     127             : }
     128             : 
     129           0 : vcl::Region VCLUnoHelper::GetRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion )
     130             : {
     131           0 :     vcl::Region aRegion;
     132           0 :     VCLXRegion* pVCLRegion = VCLXRegion::GetImplementation( rxRegion );
     133           0 :     if ( pVCLRegion )
     134           0 :         aRegion = pVCLRegion->GetRegion();
     135             :     else
     136             :     {
     137           0 :         ::com::sun::star::uno::Sequence< ::com::sun::star::awt::Rectangle > aRects = rxRegion->getRectangles();
     138           0 :         sal_Int32 nRects = aRects.getLength();
     139           0 :         for ( sal_Int32 n = 0; n < nRects; n++ )
     140           0 :             aRegion.Union( VCLRectangle( aRects.getArray()[n] ) );
     141             :     }
     142           0 :     return aRegion;
     143             : }
     144             : 
     145      286424 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow> VCLUnoHelper::GetInterface( vcl::Window* pWindow )
     146             : {
     147      286424 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xWin;
     148      286424 :     if ( pWindow )
     149             :     {
     150      261770 :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetComponentInterface();
     151      261770 :         xWin.set(xPeer, css::uno::UNO_QUERY);
     152             :     }
     153      286424 :     return xWin;
     154             : }
     155             : 
     156       10733 : OutputDevice* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice>& rxDevice )
     157             : {
     158       10733 :     OutputDevice* pOutDev = NULL;
     159       10733 :     VCLXDevice* pDev = VCLXDevice::GetImplementation( rxDevice );
     160       10733 :     if ( pDev )
     161       10665 :         pOutDev = pDev->GetOutputDevice();
     162       10733 :     return pOutDev;
     163             : }
     164             : 
     165       21280 : OutputDevice* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics>& rxGraphics )
     166             : {
     167       21280 :     OutputDevice* pOutDev = NULL;
     168       21280 :     VCLXGraphics* pGrf = VCLXGraphics::GetImplementation( rxGraphics );
     169       21280 :     if ( pGrf )
     170       17552 :         pOutDev = pGrf->GetOutputDevice();
     171       21280 :     return pOutDev;
     172             : }
     173             : 
     174           0 : Polygon VCLUnoHelper::CreatePolygon( const ::com::sun::star::uno::Sequence< sal_Int32 >& DataX, const ::com::sun::star::uno::Sequence< sal_Int32 >& DataY )
     175             : {
     176           0 :     sal_uInt32 nLen = DataX.getLength();
     177           0 :     const sal_Int32* pDataX = DataX.getConstArray();
     178           0 :     const sal_Int32* pDataY = DataY.getConstArray();
     179           0 :     Polygon aPoly( (sal_uInt16) nLen );
     180           0 :     for ( sal_uInt16 n = 0; n < nLen; n++ )
     181             :     {
     182           0 :         Point aPnt;
     183           0 :         aPnt.X() = pDataX[n];
     184           0 :         aPnt.Y() = pDataY[n];
     185           0 :         aPoly[n] = aPnt;
     186             :     }
     187           0 :     return aPoly;
     188             : }
     189             : 
     190        1370 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer> VCLUnoHelper::CreateControlContainer( vcl::Window* pWindow )
     191             : {
     192        1370 :     UnoControlContainer* pContainer = new UnoControlContainer( pWindow->GetComponentInterface( true ) );
     193        1370 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > x = pContainer;
     194             : 
     195        1370 :     UnoControlModel* pContainerModel = new UnoControlContainerModel( ::comphelper::getProcessComponentContext() );
     196        1370 :     pContainer->setModel( (::com::sun::star::awt::XControlModel*)pContainerModel );
     197             : 
     198        1370 :     return x;
     199             : }
     200             : 
     201          36 : float VCLUnoHelper::ConvertFontWidth( FontWidth eWidth )
     202             : {
     203          36 :     if( eWidth == WIDTH_DONTKNOW )
     204          36 :         return ::com::sun::star::awt::FontWidth::DONTKNOW;
     205           0 :     else if( eWidth == WIDTH_ULTRA_CONDENSED )
     206           0 :         return ::com::sun::star::awt::FontWidth::ULTRACONDENSED;
     207           0 :     else if( eWidth == WIDTH_EXTRA_CONDENSED )
     208           0 :         return ::com::sun::star::awt::FontWidth::EXTRACONDENSED;
     209           0 :     else if( eWidth == WIDTH_CONDENSED )
     210           0 :         return ::com::sun::star::awt::FontWidth::CONDENSED;
     211           0 :     else if( eWidth == WIDTH_SEMI_CONDENSED )
     212           0 :         return ::com::sun::star::awt::FontWidth::SEMICONDENSED;
     213           0 :     else if( eWidth == WIDTH_NORMAL )
     214           0 :         return ::com::sun::star::awt::FontWidth::NORMAL;
     215           0 :     else if( eWidth == WIDTH_SEMI_EXPANDED )
     216           0 :         return ::com::sun::star::awt::FontWidth::SEMIEXPANDED;
     217           0 :     else if( eWidth == WIDTH_EXPANDED )
     218           0 :         return ::com::sun::star::awt::FontWidth::EXPANDED;
     219           0 :     else if( eWidth == WIDTH_EXTRA_EXPANDED )
     220           0 :         return ::com::sun::star::awt::FontWidth::EXTRAEXPANDED;
     221           0 :     else if( eWidth == WIDTH_ULTRA_EXPANDED )
     222           0 :         return ::com::sun::star::awt::FontWidth::ULTRAEXPANDED;
     223             : 
     224             :     OSL_FAIL( "Unknown FontWidth" );
     225           0 :     return ::com::sun::star::awt::FontWidth::DONTKNOW;
     226             : }
     227             : 
     228        3064 : FontWidth VCLUnoHelper::ConvertFontWidth( float f )
     229             : {
     230        3064 :     if( f <= ::com::sun::star::awt::FontWidth::DONTKNOW )
     231          44 :         return WIDTH_DONTKNOW;
     232        3020 :     else if( f <= ::com::sun::star::awt::FontWidth::ULTRACONDENSED )
     233        1992 :         return WIDTH_ULTRA_CONDENSED;
     234        1028 :     else if( f <= ::com::sun::star::awt::FontWidth::EXTRACONDENSED )
     235         184 :         return WIDTH_EXTRA_CONDENSED;
     236         844 :     else if( f <= ::com::sun::star::awt::FontWidth::CONDENSED )
     237          20 :         return WIDTH_CONDENSED;
     238         824 :     else if( f <= ::com::sun::star::awt::FontWidth::SEMICONDENSED )
     239         143 :         return WIDTH_SEMI_CONDENSED;
     240         681 :     else if( f <= ::com::sun::star::awt::FontWidth::NORMAL )
     241         681 :         return WIDTH_NORMAL;
     242           0 :     else if( f <= ::com::sun::star::awt::FontWidth::SEMIEXPANDED )
     243           0 :         return WIDTH_SEMI_EXPANDED;
     244           0 :     else if( f <= ::com::sun::star::awt::FontWidth::EXPANDED )
     245           0 :         return WIDTH_EXPANDED;
     246           0 :     else if( f <= ::com::sun::star::awt::FontWidth::EXTRAEXPANDED )
     247           0 :         return WIDTH_EXTRA_EXPANDED;
     248           0 :     else if( f <= ::com::sun::star::awt::FontWidth::ULTRAEXPANDED )
     249           0 :         return WIDTH_ULTRA_EXPANDED;
     250             : 
     251             :     OSL_FAIL( "Unknown FontWidth" );
     252           0 :     return WIDTH_DONTKNOW;
     253             : }
     254             : 
     255        8964 : float VCLUnoHelper::ConvertFontWeight( FontWeight eWeight )
     256             : {
     257        8964 :     if( eWeight == WEIGHT_DONTKNOW )
     258         182 :         return ::com::sun::star::awt::FontWeight::DONTKNOW;
     259        8782 :     else if( eWeight == WEIGHT_THIN )
     260           8 :         return ::com::sun::star::awt::FontWeight::THIN;
     261        8774 :     else if( eWeight == WEIGHT_ULTRALIGHT )
     262           0 :         return ::com::sun::star::awt::FontWeight::ULTRALIGHT;
     263        8774 :     else if( eWeight == WEIGHT_LIGHT )
     264           4 :         return ::com::sun::star::awt::FontWeight::LIGHT;
     265        8770 :     else if( eWeight == WEIGHT_SEMILIGHT )
     266           0 :         return ::com::sun::star::awt::FontWeight::SEMILIGHT;
     267        8770 :     else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) )
     268        7814 :         return ::com::sun::star::awt::FontWeight::NORMAL;
     269         956 :     else if( eWeight == WEIGHT_SEMIBOLD )
     270           0 :         return ::com::sun::star::awt::FontWeight::SEMIBOLD;
     271         956 :     else if( eWeight == WEIGHT_BOLD )
     272         856 :         return ::com::sun::star::awt::FontWeight::BOLD;
     273         100 :     else if( eWeight == WEIGHT_ULTRABOLD )
     274          68 :         return ::com::sun::star::awt::FontWeight::ULTRABOLD;
     275          32 :     else if( eWeight == WEIGHT_BLACK )
     276          32 :         return ::com::sun::star::awt::FontWeight::BLACK;
     277             : 
     278             :     OSL_FAIL( "Unknown FontWeight" );
     279           0 :     return ::com::sun::star::awt::FontWeight::DONTKNOW;
     280             : }
     281             : 
     282      158685 : FontWeight VCLUnoHelper::ConvertFontWeight( float f )
     283             : {
     284      158685 :     if( f <= ::com::sun::star::awt::FontWeight::DONTKNOW )
     285        2800 :         return WEIGHT_DONTKNOW;
     286      155885 :     else if( f <= ::com::sun::star::awt::FontWeight::THIN )
     287        2118 :         return WEIGHT_THIN;
     288      153767 :     else if( f <= ::com::sun::star::awt::FontWeight::ULTRALIGHT )
     289          66 :         return WEIGHT_ULTRALIGHT;
     290      153701 :     else if( f <= ::com::sun::star::awt::FontWeight::LIGHT )
     291         126 :         return WEIGHT_LIGHT;
     292      153575 :     else if( f <= ::com::sun::star::awt::FontWeight::SEMILIGHT )
     293          36 :         return WEIGHT_SEMILIGHT;
     294      153539 :     else if( f <= ::com::sun::star::awt::FontWeight::NORMAL )
     295       58528 :         return WEIGHT_NORMAL;
     296       95011 :     else if( f <= ::com::sun::star::awt::FontWeight::SEMIBOLD )
     297           0 :         return WEIGHT_SEMIBOLD;
     298       95011 :     else if( f <= ::com::sun::star::awt::FontWeight::BOLD )
     299       94768 :         return WEIGHT_BOLD;
     300         243 :     else if( f <= ::com::sun::star::awt::FontWeight::ULTRABOLD )
     301         165 :         return WEIGHT_ULTRABOLD;
     302          78 :     else if( f <= ::com::sun::star::awt::FontWeight::BLACK )
     303          44 :         return WEIGHT_BLACK;
     304             : 
     305             :     OSL_FAIL( "Unknown FontWeight" );
     306          34 :     return WEIGHT_DONTKNOW;
     307             : }
     308             : 
     309        5382 : css::awt::FontSlant VCLUnoHelper::ConvertFontSlant(FontItalic eItalic)
     310             : {
     311        5382 :     css::awt::FontSlant eRet(css::awt::FontSlant_DONTKNOW);
     312        5382 :     switch (eItalic)
     313             :     {
     314             :         case ITALIC_NONE:
     315        5382 :             eRet = css::awt::FontSlant_NONE;
     316        5382 :             break;
     317             :         case ITALIC_OBLIQUE:
     318           0 :             eRet = css::awt::FontSlant_OBLIQUE;
     319           0 :             break;
     320             :         case ITALIC_NORMAL:
     321           0 :             eRet = css::awt::FontSlant_ITALIC;
     322           0 :             break;
     323             :         case ITALIC_DONTKNOW:
     324           0 :             eRet = css::awt::FontSlant_DONTKNOW;
     325           0 :             break;
     326             :         case FontItalic_FORCE_EQUAL_SIZE:
     327           0 :             eRet = css::awt::FontSlant_MAKE_FIXED_SIZE;
     328           0 :             break;
     329             :     }
     330        5382 :     return eRet;
     331             : }
     332             : 
     333        3145 : FontItalic VCLUnoHelper::ConvertFontSlant(css::awt::FontSlant eSlant)
     334             : {
     335        3145 :     FontItalic eRet = ITALIC_DONTKNOW;
     336        3145 :     switch (eSlant)
     337             :     {
     338             :         case css::awt::FontSlant_NONE:
     339        1392 :             eRet = ITALIC_NONE;
     340        1392 :             break;
     341             :         case css::awt::FontSlant_OBLIQUE:
     342           0 :             eRet = ITALIC_OBLIQUE;
     343           0 :             break;
     344             :         case css::awt::FontSlant_ITALIC:
     345           4 :             eRet = ITALIC_NORMAL;
     346           4 :             break;
     347             :         case css::awt::FontSlant_DONTKNOW:
     348           0 :             eRet = ITALIC_DONTKNOW;
     349           0 :             break;
     350             :         case css::awt::FontSlant_REVERSE_OBLIQUE:
     351             :             //there is no vcl reverse oblique
     352         188 :             eRet = ITALIC_OBLIQUE;
     353         188 :             break;
     354             :         case css::awt::FontSlant_REVERSE_ITALIC:
     355             :             //there is no vcl reverse normal
     356         610 :             eRet = ITALIC_NORMAL;
     357         610 :             break;
     358             :         case css::awt::FontSlant_MAKE_FIXED_SIZE:
     359           0 :             eRet = FontItalic_FORCE_EQUAL_SIZE;
     360           0 :             break;
     361             :     }
     362        3145 :     return eRet;
     363             : }
     364             : 
     365          36 : ::com::sun::star::awt::FontDescriptor VCLUnoHelper::CreateFontDescriptor( const vcl::Font& rFont )
     366             : {
     367          36 :     ::com::sun::star::awt::FontDescriptor aFD;
     368          36 :     aFD.Name = rFont.GetName();
     369          36 :     aFD.StyleName = rFont.GetStyleName();
     370          36 :     aFD.Height = (sal_Int16)rFont.GetSize().Height();
     371          36 :     aFD.Width = (sal_Int16)rFont.GetSize().Width();
     372          36 :     aFD.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
     373          36 :     aFD.CharSet = rFont.GetCharSet();
     374          36 :     aFD.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
     375          36 :     aFD.CharacterWidth = VCLUnoHelper::ConvertFontWidth( rFont.GetWidthType() );
     376          36 :     aFD.Weight= VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() );
     377          36 :     aFD.Slant = VCLUnoHelper::ConvertFontSlant( rFont.GetItalic() );
     378          36 :     aFD.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline());
     379          36 :     aFD.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout());
     380          36 :     aFD.Orientation = rFont.GetOrientation();
     381          36 :     aFD.Kerning = rFont.IsKerning();
     382          36 :     aFD.WordLineMode = rFont.IsWordLineMode();
     383          36 :     aFD.Type = 0;   // ??? => Nur an Metric...
     384          36 :     return aFD;
     385             : }
     386             : 
     387        3469 : vcl::Font VCLUnoHelper::CreateFont( const ::com::sun::star::awt::FontDescriptor& rDescr, const vcl::Font& rInitFont )
     388             : {
     389        3469 :     vcl::Font aFont( rInitFont );
     390        3469 :     if ( !rDescr.Name.isEmpty() )
     391        3027 :         aFont.SetName( rDescr.Name );
     392        3469 :     if ( !rDescr.StyleName.isEmpty() )
     393        2281 :         aFont.SetStyleName( rDescr.StyleName );
     394        3469 :     if ( rDescr.Height )
     395        3027 :         aFont.SetSize( Size( rDescr.Width, rDescr.Height ) );
     396        3469 :     if ( (FontFamily)rDescr.Family != FAMILY_DONTKNOW )
     397        2747 :         aFont.SetFamily( (FontFamily)rDescr.Family );
     398        3469 :     if ( (rtl_TextEncoding)rDescr.CharSet != RTL_TEXTENCODING_DONTKNOW )
     399        2375 :         aFont.SetCharSet( (rtl_TextEncoding)rDescr.CharSet );
     400        3469 :     if ( (FontPitch)rDescr.Pitch != PITCH_DONTKNOW )
     401        2287 :         aFont.SetPitch( (FontPitch)rDescr.Pitch );
     402        3469 :     if ( rDescr.CharacterWidth )
     403        2967 :         aFont.SetWidthType( VCLUnoHelper::ConvertFontWidth( rDescr.CharacterWidth ) );
     404        3469 :     if ( rDescr.Weight )
     405        3025 :         aFont.SetWeight( VCLUnoHelper::ConvertFontWeight( rDescr.Weight ) );
     406        3469 :     if ( rDescr.Slant != css::awt::FontSlant_DONTKNOW )
     407        3145 :         aFont.SetItalic( VCLUnoHelper::ConvertFontSlant( rDescr.Slant ) );
     408        3469 :     if ( (FontUnderline)rDescr.Underline != UNDERLINE_DONTKNOW )
     409        3145 :         aFont.SetUnderline( (FontUnderline)rDescr.Underline );
     410        3469 :     if ( (FontStrikeout)rDescr.Strikeout != STRIKEOUT_DONTKNOW )
     411        3145 :         aFont.SetStrikeout( (FontStrikeout)rDescr.Strikeout );
     412             : 
     413             :     // Kein DONTKNOW
     414        3469 :     aFont.SetOrientation( (short)rDescr.Orientation );
     415        3469 :     aFont.SetKerning( rDescr.Kerning );
     416        3469 :     aFont.SetWordLineMode( rDescr.WordLineMode );
     417             : 
     418        3469 :     return aFont;
     419             : }
     420             : 
     421           0 : vcl::Font VCLUnoHelper::CreateFont( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont >& rxFont )
     422             : {
     423           0 :     vcl::Font aFont;
     424           0 :     VCLXFont* pVCLXFont = VCLXFont::GetImplementation( rxFont );
     425           0 :     if ( pVCLXFont )
     426           0 :         aFont = pVCLXFont->GetFont();
     427           0 :     return aFont;
     428             : }
     429             : 
     430             : 
     431           0 : ::com::sun::star::awt::SimpleFontMetric VCLUnoHelper::CreateFontMetric( const FontMetric& rFontMetric )
     432             : {
     433           0 :     ::com::sun::star::awt::SimpleFontMetric aFM;
     434           0 :     aFM.Ascent = (sal_Int16)rFontMetric.GetAscent();
     435           0 :     aFM.Descent = (sal_Int16)rFontMetric.GetDescent();
     436           0 :     aFM.Leading = (sal_Int16)rFontMetric.GetIntLeading();
     437           0 :     aFM.Slant = (sal_Int16)rFontMetric.GetSlant();
     438           0 :     aFM.FirstChar = 0x0020;
     439           0 :     aFM.LastChar = 0xFFFD;
     440           0 :     return aFM;
     441             : }
     442             : 
     443       50867 : bool VCLUnoHelper::IsZero( ::com::sun::star::awt::Rectangle rRect )
     444             : {
     445       50867 :     return ( !rRect.X && !rRect.Y && !rRect.Width && !rRect.Height );
     446             : }
     447             : 
     448        2432 : MapUnit VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit )
     449             : {
     450        2432 :     switch( nUnoEmbedMapUnit )
     451             :     {
     452             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM:
     453        1940 :             return MAP_100TH_MM;
     454             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM:
     455           0 :             return MAP_10TH_MM;
     456             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_MM:
     457           0 :             return MAP_MM;
     458             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_CM:
     459           0 :             return MAP_CM;
     460             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH:
     461           0 :             return MAP_1000TH_INCH;
     462             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH:
     463           0 :             return MAP_100TH_INCH;
     464             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH:
     465           0 :             return MAP_10TH_INCH;
     466             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_INCH:
     467           0 :             return MAP_INCH;
     468             :         case ::com::sun::star::embed::EmbedMapUnits::POINT:
     469           0 :             return MAP_POINT;
     470             :         case ::com::sun::star::embed::EmbedMapUnits::TWIP:
     471         492 :             return MAP_TWIP;
     472             :         case ::com::sun::star::embed::EmbedMapUnits::PIXEL:
     473           0 :             return MAP_PIXEL;
     474             :     }
     475             : 
     476             :     OSL_FAIL( "Unexpected UNO map mode is provided!\n" );
     477           0 :     return MAP_LASTENUMDUMMY;
     478             : }
     479             : 
     480        1508 : sal_Int32 VCLUnoHelper::VCL2UnoEmbedMapUnit( MapUnit nVCLMapUnit )
     481             : {
     482        1508 :     switch( nVCLMapUnit )
     483             :     {
     484             :         case MAP_100TH_MM:
     485        1010 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM;
     486             :         case MAP_10TH_MM:
     487           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM;
     488             :         case MAP_MM:
     489           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_MM;
     490             :         case MAP_CM:
     491           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_CM;
     492             :         case MAP_1000TH_INCH:
     493           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH;
     494             :         case MAP_100TH_INCH:
     495           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH;
     496             :         case MAP_10TH_INCH:
     497           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH;
     498             :         case MAP_INCH:
     499           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_INCH;
     500             :         case MAP_POINT:
     501           0 :             return ::com::sun::star::embed::EmbedMapUnits::POINT;
     502             :         case MAP_TWIP:
     503         498 :             return ::com::sun::star::embed::EmbedMapUnits::TWIP;
     504             :         case MAP_PIXEL:
     505           0 :             return ::com::sun::star::embed::EmbedMapUnits::PIXEL;
     506             :         default: ; // avoid compiler warning
     507             :     }
     508             : 
     509             :     OSL_FAIL( "Unexpected VCL map mode is provided!\n" );
     510           0 :     return -1;
     511             : }
     512             : 
     513             : using namespace ::com::sun::star::util;
     514             : 
     515             : 
     516             : //= file-local helpers
     517             : 
     518             : namespace
     519             : {
     520             :     enum UnitConversionDirection
     521             :     {
     522             :         FieldUnitToMeasurementUnit,
     523             :         MeasurementUnitToFieldUnit
     524             :     };
     525             : 
     526           0 :     sal_Int16 convertMeasurementUnit( sal_Int16 _nUnit, UnitConversionDirection eDirection, sal_Int16& _rFieldToUNOValueFactor )
     527             :     {
     528             :         static struct _unit_table
     529             :         {
     530             :             FieldUnit eFieldUnit;
     531             :             sal_Int16 nMeasurementUnit;
     532             :             sal_Int16 nFieldToMeasureFactor;
     533             :         } aUnits[] = {
     534             :             { FUNIT_NONE,       -1 , -1},
     535             :             { FUNIT_MM,         MeasureUnit::MM,            1 },    // must precede MM_10TH
     536             :             { FUNIT_MM,         MeasureUnit::MM_10TH,       10 },
     537             :             { FUNIT_100TH_MM,   MeasureUnit::MM_100TH,      1 },
     538             :             { FUNIT_CM,         MeasureUnit::CM,            1 },
     539             :             { FUNIT_M,          MeasureUnit::M,             1 },
     540             :             { FUNIT_KM,         MeasureUnit::KM,            1 },
     541             :             { FUNIT_TWIP,       MeasureUnit::TWIP,          1 },
     542             :             { FUNIT_POINT,      MeasureUnit::POINT,         1 },
     543             :             { FUNIT_PICA,       MeasureUnit::PICA,          1 },
     544             :             { FUNIT_INCH,       MeasureUnit::INCH,          1 },    // must precede INCH_*TH
     545             :             { FUNIT_INCH,       MeasureUnit::INCH_10TH,     10 },
     546             :             { FUNIT_INCH,       MeasureUnit::INCH_100TH,    100 },
     547             :             { FUNIT_INCH,       MeasureUnit::INCH_1000TH,   1000 },
     548             :             { FUNIT_FOOT,       MeasureUnit::FOOT,          1 },
     549             :             { FUNIT_MILE,       MeasureUnit::MILE,          1 },
     550             :         };
     551           0 :         for ( size_t i = 0; i < SAL_N_ELEMENTS( aUnits ); ++i )
     552             :         {
     553           0 :             if ( eDirection == FieldUnitToMeasurementUnit )
     554             :             {
     555           0 :                 if ( ( aUnits[ i ].eFieldUnit == (FieldUnit)_nUnit ) && ( aUnits[ i ].nFieldToMeasureFactor == _rFieldToUNOValueFactor ) )
     556           0 :                     return aUnits[ i ].nMeasurementUnit;
     557             :             }
     558             :             else
     559             :             {
     560           0 :                 if ( aUnits[ i ].nMeasurementUnit == _nUnit )
     561             :                 {
     562           0 :                     _rFieldToUNOValueFactor = aUnits[ i ].nFieldToMeasureFactor;
     563           0 :                     return (sal_Int16)aUnits[ i ].eFieldUnit;
     564             :                 }
     565             :             }
     566             :         }
     567           0 :         if ( eDirection == FieldUnitToMeasurementUnit )
     568           0 :             return -1;
     569             : 
     570           0 :         _rFieldToUNOValueFactor = 1;
     571           0 :         return (sal_Int16)FUNIT_NONE;
     572             :     }
     573             : }
     574             : 
     575             : //= MeasurementUnitConversion
     576             : 
     577             : 
     578           0 : sal_Int16 VCLUnoHelper::ConvertToMeasurementUnit( FieldUnit _nFieldUnit, sal_Int16 _nUNOToFieldValueFactor )
     579             : {
     580           0 :     return convertMeasurementUnit( (sal_Int16)_nFieldUnit, FieldUnitToMeasurementUnit, _nUNOToFieldValueFactor );
     581             : }
     582             : 
     583             : 
     584           0 : FieldUnit VCLUnoHelper::ConvertToFieldUnit( sal_Int16 _nMeasurementUnit, sal_Int16& _rFieldToUNOValueFactor )
     585             : {
     586           0 :     return (FieldUnit)convertMeasurementUnit( _nMeasurementUnit, MeasurementUnitToFieldUnit, _rFieldToUNOValueFactor );
     587             : }
     588             : 
     589             : 
     590          66 : MapUnit /* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16 /* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit) throw (::com::sun::star::lang::IllegalArgumentException)
     591             : {
     592             :     MapUnit eMode;
     593          66 :     switch(_nMeasureUnit)
     594             :     {
     595             :     case com::sun::star::util::MeasureUnit::MM_100TH:
     596           6 :         eMode = MAP_100TH_MM;
     597           6 :         break;
     598             : 
     599             : 
     600             :     case com::sun::star::util::MeasureUnit::MM_10TH:
     601           2 :         eMode = MAP_10TH_MM;
     602           2 :         break;
     603             : 
     604             :     case com::sun::star::util::MeasureUnit::MM:
     605           2 :         eMode = MAP_MM;
     606           2 :         break;
     607             : 
     608             :     case com::sun::star::util::MeasureUnit::CM:
     609           2 :         eMode = MAP_CM;
     610           2 :         break;
     611             : 
     612             :     case com::sun::star::util::MeasureUnit::INCH_1000TH:
     613           2 :         eMode = MAP_1000TH_INCH;
     614           2 :         break;
     615             : 
     616             :     case com::sun::star::util::MeasureUnit::INCH_100TH:
     617           2 :         eMode = MAP_100TH_INCH;
     618           2 :         break;
     619             : 
     620             :     case com::sun::star::util::MeasureUnit::INCH_10TH:
     621           2 :         eMode = MAP_10TH_INCH;
     622           2 :         break;
     623             : 
     624             :     case com::sun::star::util::MeasureUnit::INCH:
     625           2 :         eMode = MAP_INCH;
     626           2 :         break;
     627             : 
     628             :     case com::sun::star::util::MeasureUnit::POINT:
     629           2 :         eMode = MAP_POINT;
     630           2 :         break;
     631             : 
     632             :     case com::sun::star::util::MeasureUnit::TWIP:
     633           2 :         eMode = MAP_TWIP;
     634           2 :         break;
     635             : 
     636             :     case com::sun::star::util::MeasureUnit::PIXEL:
     637           2 :         eMode = MAP_PIXEL;
     638           2 :         break;
     639             : 
     640             : /*
     641             :     case com::sun::star::util::MeasureUnit::M:
     642             :         break;
     643             :     case com::sun::star::util::MeasureUnit::KM:
     644             :         break;
     645             :     case com::sun::star::util::MeasureUnit::PICA:
     646             :         break;
     647             :     case com::sun::star::util::MeasureUnit::FOOT:
     648             :         break;
     649             :     case com::sun::star::util::MeasureUnit::MILE:
     650             :         break;
     651             :     case com::sun::star::util::MeasureUnit::PERCENT:
     652             :         break;
     653             : */
     654             :     case com::sun::star::util::MeasureUnit::APPFONT:
     655          38 :         eMode = MAP_APPFONT;
     656          38 :         break;
     657             : 
     658             :     case com::sun::star::util::MeasureUnit::SYSFONT:
     659           2 :         eMode = MAP_SYSFONT;
     660           2 :         break;
     661             : 
     662             : /*
     663             :     case com::sun::star::util::MeasureUnit::RELATIVE:
     664             :         eMode = MAP_RELATIVE;
     665             :         break;
     666             : */
     667             : 
     668             :     default:
     669           0 :         throw ::com::sun::star::lang::IllegalArgumentException("Unsupported measure unit.", NULL, 1 );
     670             :     }
     671          66 :     return eMode;
     672             : }
     673             : 
     674          50 : ::Size VCLUnoHelper::ConvertToVCLSize(com::sun::star::awt::Size const& _aSize)
     675             : {
     676          50 :     ::Size aVCLSize(_aSize.Width, _aSize.Height);
     677          50 :     return aVCLSize;
     678             : }
     679             : 
     680          50 : com::sun::star::awt::Size VCLUnoHelper::ConvertToAWTSize(::Size /* VCLSize */ const& _aSize)
     681             : {
     682          50 :     com::sun::star::awt::Size aAWTSize(_aSize.Width(), _aSize.Height());
     683          50 :     return aAWTSize;
     684             : }
     685             : 
     686             : 
     687          18 : ::Point VCLUnoHelper::ConvertToVCLPoint(com::sun::star::awt::Point const& _aPoint)
     688             : {
     689          18 :     ::Point aVCLPoint(_aPoint.X, _aPoint.Y);
     690          18 :     return aVCLPoint;
     691             : }
     692             : 
     693          18 : com::sun::star::awt::Point VCLUnoHelper::ConvertToAWTPoint(::Point /* VCLPoint */ const& _aPoint)
     694             : {
     695          18 :     com::sun::star::awt::Point aAWTPoint(_aPoint.X(), _aPoint.Y());
     696          18 :     return aAWTPoint;
     697             : }
     698             : 
     699       15367 : ::Rectangle VCLUnoHelper::ConvertToVCLRect( ::com::sun::star::awt::Rectangle const & _rRect )
     700             : {
     701       15367 :     return ::Rectangle( _rRect.X, _rRect.Y, _rRect.X + _rRect.Width - 1, _rRect.Y + _rRect.Height - 1 );
     702             : }
     703             : 
     704           0 : ::com::sun::star::awt::Rectangle VCLUnoHelper::ConvertToAWTRect( ::Rectangle const & _rRect )
     705             : {
     706           0 :     return ::com::sun::star::awt::Rectangle( _rRect.Left(), _rRect.Top(), _rRect.GetWidth(), _rRect.GetHeight() );
     707             : }
     708             : 
     709           0 : awt::MouseEvent VCLUnoHelper::createMouseEvent( const ::MouseEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
     710             : {
     711           0 :     awt::MouseEvent aMouseEvent;
     712           0 :     aMouseEvent.Source = _rxContext;
     713             : 
     714           0 :     aMouseEvent.Modifiers = 0;
     715           0 :     if ( _rVclEvent.IsShift() )
     716           0 :         aMouseEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::SHIFT;
     717           0 :     if ( _rVclEvent.IsMod1() )
     718           0 :         aMouseEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD1;
     719           0 :     if ( _rVclEvent.IsMod2() )
     720           0 :         aMouseEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD2;
     721             : 
     722           0 :     aMouseEvent.Buttons = 0;
     723           0 :     if ( _rVclEvent.IsLeft() )
     724           0 :         aMouseEvent.Buttons |= ::com::sun::star::awt::MouseButton::LEFT;
     725           0 :     if ( _rVclEvent.IsRight() )
     726           0 :         aMouseEvent.Buttons |= ::com::sun::star::awt::MouseButton::RIGHT;
     727           0 :     if ( _rVclEvent.IsMiddle() )
     728           0 :         aMouseEvent.Buttons |= ::com::sun::star::awt::MouseButton::MIDDLE;
     729             : 
     730           0 :     aMouseEvent.X = _rVclEvent.GetPosPixel().X();
     731           0 :     aMouseEvent.Y = _rVclEvent.GetPosPixel().Y();
     732           0 :     aMouseEvent.ClickCount = _rVclEvent.GetClicks();
     733           0 :     aMouseEvent.PopupTrigger = sal_False;
     734             : 
     735           0 :     return aMouseEvent;
     736             : }
     737             : 
     738           0 : awt::KeyEvent VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
     739             : {
     740           0 :     awt::KeyEvent aKeyEvent;
     741           0 :     aKeyEvent.Source = _rxContext;
     742             : 
     743           0 :     aKeyEvent.Modifiers = 0;
     744           0 :     if ( _rVclEvent.GetKeyCode().IsShift() )
     745           0 :         aKeyEvent.Modifiers |= awt::KeyModifier::SHIFT;
     746           0 :     if ( _rVclEvent.GetKeyCode().IsMod1() )
     747           0 :         aKeyEvent.Modifiers |= awt::KeyModifier::MOD1;
     748           0 :     if ( _rVclEvent.GetKeyCode().IsMod2() )
     749           0 :         aKeyEvent.Modifiers |= awt::KeyModifier::MOD2;
     750           0 :     if ( _rVclEvent.GetKeyCode().IsMod3() )
     751           0 :             aKeyEvent.Modifiers |= awt::KeyModifier::MOD3;
     752             : 
     753           0 :     aKeyEvent.KeyCode = _rVclEvent.GetKeyCode().GetCode();
     754           0 :     aKeyEvent.KeyChar = _rVclEvent.GetCharCode();
     755           0 :     aKeyEvent.KeyFunc = ::sal::static_int_cast< sal_Int16 >( _rVclEvent.GetKeyCode().GetFunction());
     756             : 
     757           0 :     return aKeyEvent;
     758        1227 : }
     759             : 
     760             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10