LCOV - code coverage report
Current view: top level - toolkit/source/helper - vclunohelper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 203 361 56.2 %
Date: 2014-04-11 Functions: 25 35 71.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          16 : uno::Reference< ::com::sun::star::awt::XToolkit> VCLUnoHelper::CreateToolkit()
      64             : {
      65          16 :     uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
      66          16 :     uno::Reference< awt::XToolkit> xToolkit( awt::Toolkit::create(xContext), uno::UNO_QUERY_THROW );
      67          16 :     return xToolkit;
      68             : }
      69             : 
      70          24 : BitmapEx VCLUnoHelper::GetBitmap( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap>& rxBitmap )
      71             : {
      72          24 :     BitmapEx aBmp;
      73             : 
      74          48 :     ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > xGraphic( rxBitmap, ::com::sun::star::uno::UNO_QUERY );
      75          24 :     if( xGraphic.is() )
      76             :     {
      77          24 :         Graphic aGraphic( xGraphic );
      78          24 :         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          48 :     return aBmp;
     102             : }
     103             : 
     104         386 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap> VCLUnoHelper::CreateBitmap( const BitmapEx& rBitmap )
     105             : {
     106         386 :     Graphic aGraphic( rBitmap );
     107         386 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap> xBmp( aGraphic.GetXGraphic(), ::com::sun::star::uno::UNO_QUERY );
     108         386 :     return xBmp;
     109             : }
     110             : 
     111      331552 : Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow>& rxWindow )
     112             : {
     113      331552 :     VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow );
     114      331552 :     return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL;
     115             : }
     116             : 
     117       10266 : Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow2>& rxWindow )
     118             : {
     119       10266 :     VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow );
     120       10266 :     return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL;
     121             : }
     122             : 
     123        5127 : Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer>& rxWindow )
     124             : {
     125        5127 :     VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow );
     126        5127 :     return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL;
     127             : }
     128             : 
     129           0 : Region VCLUnoHelper::GetRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion )
     130             : {
     131           0 :     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      104189 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow> VCLUnoHelper::GetInterface( Window* pWindow )
     146             : {
     147      104189 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xWin;
     148      104189 :     if ( pWindow )
     149             :     {
     150       95368 :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetComponentInterface();
     151       95368 :         xWin = xWin.query( xPeer );
     152             :     }
     153      104189 :     return xWin;
     154             : }
     155             : 
     156        3934 : OutputDevice* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice>& rxDevice )
     157             : {
     158        3934 :     OutputDevice* pOutDev = NULL;
     159        3934 :     VCLXDevice* pDev = VCLXDevice::GetImplementation( rxDevice );
     160        3934 :     if ( pDev )
     161        3895 :         pOutDev = pDev->GetOutputDevice();
     162        3934 :     return pOutDev;
     163             : }
     164             : 
     165       18538 : OutputDevice* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics>& rxGraphics )
     166             : {
     167       18538 :     OutputDevice* pOutDev = NULL;
     168       18538 :     VCLXGraphics* pGrf = VCLXGraphics::GetImplementation( rxGraphics );
     169       18538 :     if ( pGrf )
     170       15255 :         pOutDev = pGrf->GetOutputDevice();
     171       18538 :     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         543 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer> VCLUnoHelper::CreateControlContainer( Window* pWindow )
     191             : {
     192         543 :     UnoControlContainer* pContainer = new UnoControlContainer( pWindow->GetComponentInterface( sal_True ) );
     193         543 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > x = pContainer;
     194             : 
     195         543 :     UnoControlModel* pContainerModel = new UnoControlContainerModel( ::comphelper::getProcessComponentContext() );
     196         543 :     pContainer->setModel( (::com::sun::star::awt::XControlModel*)pContainerModel );
     197             : 
     198         543 :     return x;
     199             : }
     200             : 
     201          18 : float VCLUnoHelper::ConvertFontWidth( FontWidth eWidth )
     202             : {
     203          18 :     if( eWidth == WIDTH_DONTKNOW )
     204          18 :         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        1441 : FontWidth VCLUnoHelper::ConvertFontWidth( float f )
     229             : {
     230        1441 :     if( f <= ::com::sun::star::awt::FontWidth::DONTKNOW )
     231          22 :         return WIDTH_DONTKNOW;
     232        1419 :     else if( f <= ::com::sun::star::awt::FontWidth::ULTRACONDENSED )
     233         981 :         return WIDTH_ULTRA_CONDENSED;
     234         438 :     else if( f <= ::com::sun::star::awt::FontWidth::EXTRACONDENSED )
     235         110 :         return WIDTH_EXTRA_CONDENSED;
     236         328 :     else if( f <= ::com::sun::star::awt::FontWidth::CONDENSED )
     237          10 :         return WIDTH_CONDENSED;
     238         318 :     else if( f <= ::com::sun::star::awt::FontWidth::SEMICONDENSED )
     239          78 :         return WIDTH_SEMI_CONDENSED;
     240         240 :     else if( f <= ::com::sun::star::awt::FontWidth::NORMAL )
     241         240 :         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        2147 : float VCLUnoHelper::ConvertFontWeight( FontWeight eWeight )
     256             : {
     257        2147 :     if( eWeight == WEIGHT_DONTKNOW )
     258          84 :         return ::com::sun::star::awt::FontWeight::DONTKNOW;
     259        2063 :     else if( eWeight == WEIGHT_THIN )
     260           4 :         return ::com::sun::star::awt::FontWeight::THIN;
     261        2059 :     else if( eWeight == WEIGHT_ULTRALIGHT )
     262           0 :         return ::com::sun::star::awt::FontWeight::ULTRALIGHT;
     263        2059 :     else if( eWeight == WEIGHT_LIGHT )
     264           2 :         return ::com::sun::star::awt::FontWeight::LIGHT;
     265        2057 :     else if( eWeight == WEIGHT_SEMILIGHT )
     266           0 :         return ::com::sun::star::awt::FontWeight::SEMILIGHT;
     267        2057 :     else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) )
     268        1599 :         return ::com::sun::star::awt::FontWeight::NORMAL;
     269         458 :     else if( eWeight == WEIGHT_SEMIBOLD )
     270           0 :         return ::com::sun::star::awt::FontWeight::SEMIBOLD;
     271         458 :     else if( eWeight == WEIGHT_BOLD )
     272         408 :         return ::com::sun::star::awt::FontWeight::BOLD;
     273          50 :     else if( eWeight == WEIGHT_ULTRABOLD )
     274          34 :         return ::com::sun::star::awt::FontWeight::ULTRABOLD;
     275          16 :     else if( eWeight == WEIGHT_BLACK )
     276          16 :         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       85262 : FontWeight VCLUnoHelper::ConvertFontWeight( float f )
     283             : {
     284       85262 :     if( f <= ::com::sun::star::awt::FontWeight::DONTKNOW )
     285         751 :         return WEIGHT_DONTKNOW;
     286       84511 :     else if( f <= ::com::sun::star::awt::FontWeight::THIN )
     287        1053 :         return WEIGHT_THIN;
     288       83458 :     else if( f <= ::com::sun::star::awt::FontWeight::ULTRALIGHT )
     289          38 :         return WEIGHT_ULTRALIGHT;
     290       83420 :     else if( f <= ::com::sun::star::awt::FontWeight::LIGHT )
     291          64 :         return WEIGHT_LIGHT;
     292       83356 :     else if( f <= ::com::sun::star::awt::FontWeight::SEMILIGHT )
     293          18 :         return WEIGHT_SEMILIGHT;
     294       83338 :     else if( f <= ::com::sun::star::awt::FontWeight::NORMAL )
     295       45954 :         return WEIGHT_NORMAL;
     296       37384 :     else if( f <= ::com::sun::star::awt::FontWeight::SEMIBOLD )
     297           0 :         return WEIGHT_SEMIBOLD;
     298       37384 :     else if( f <= ::com::sun::star::awt::FontWeight::BOLD )
     299       37022 :         return WEIGHT_BOLD;
     300         362 :     else if( f <= ::com::sun::star::awt::FontWeight::ULTRABOLD )
     301         237 :         return WEIGHT_ULTRABOLD;
     302         125 :     else if( f <= ::com::sun::star::awt::FontWeight::BLACK )
     303          63 :         return WEIGHT_BLACK;
     304             : 
     305             :     OSL_FAIL( "Unknown FontWeight" );
     306          62 :     return WEIGHT_DONTKNOW;
     307             : }
     308             : 
     309             : 
     310          18 : ::com::sun::star::awt::FontDescriptor VCLUnoHelper::CreateFontDescriptor( const Font& rFont )
     311             : {
     312          18 :     ::com::sun::star::awt::FontDescriptor aFD;
     313          18 :     aFD.Name = rFont.GetName();
     314          18 :     aFD.StyleName = rFont.GetStyleName();
     315          18 :     aFD.Height = (sal_Int16)rFont.GetSize().Height();
     316          18 :     aFD.Width = (sal_Int16)rFont.GetSize().Width();
     317          18 :     aFD.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
     318          18 :     aFD.CharSet = rFont.GetCharSet();
     319          18 :     aFD.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
     320          18 :     aFD.CharacterWidth = VCLUnoHelper::ConvertFontWidth( rFont.GetWidthType() );
     321          18 :     aFD.Weight= VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() );
     322          18 :     aFD.Slant = (::com::sun::star::awt::FontSlant)rFont.GetItalic();
     323          18 :     aFD.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline());
     324          18 :     aFD.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout());
     325          18 :     aFD.Orientation = rFont.GetOrientation();
     326          18 :     aFD.Kerning = rFont.IsKerning();
     327          18 :     aFD.WordLineMode = rFont.IsWordLineMode();
     328          18 :     aFD.Type = 0;   // ??? => Nur an Metric...
     329          18 :     return aFD;
     330             : }
     331             : 
     332        1646 : Font VCLUnoHelper::CreateFont( const ::com::sun::star::awt::FontDescriptor& rDescr, const Font& rInitFont )
     333             : {
     334        1646 :     Font aFont( rInitFont );
     335        1646 :     if ( !rDescr.Name.isEmpty() )
     336        1421 :         aFont.SetName( rDescr.Name );
     337        1646 :     if ( !rDescr.StyleName.isEmpty() )
     338        1143 :         aFont.SetStyleName( rDescr.StyleName );
     339        1646 :     if ( rDescr.Height )
     340        1421 :         aFont.SetSize( Size( rDescr.Width, rDescr.Height ) );
     341        1646 :     if ( (FontFamily)rDescr.Family != FAMILY_DONTKNOW )
     342        1309 :         aFont.SetFamily( (FontFamily)rDescr.Family );
     343        1646 :     if ( (rtl_TextEncoding)rDescr.CharSet != RTL_TEXTENCODING_DONTKNOW )
     344        1186 :         aFont.SetCharSet( (rtl_TextEncoding)rDescr.CharSet );
     345        1646 :     if ( (FontPitch)rDescr.Pitch != PITCH_DONTKNOW )
     346        1146 :         aFont.SetPitch( (FontPitch)rDescr.Pitch );
     347        1646 :     if ( rDescr.CharacterWidth )
     348        1393 :         aFont.SetWidthType( VCLUnoHelper::ConvertFontWidth( rDescr.CharacterWidth ) );
     349        1646 :     if ( rDescr.Weight )
     350        1420 :         aFont.SetWeight( VCLUnoHelper::ConvertFontWeight( rDescr.Weight ) );
     351        1646 :     if ( (FontItalic)rDescr.Slant != ITALIC_DONTKNOW )
     352        1480 :         aFont.SetItalic( (FontItalic)rDescr.Slant );
     353        1646 :     if ( (FontUnderline)rDescr.Underline != UNDERLINE_DONTKNOW )
     354        1480 :         aFont.SetUnderline( (FontUnderline)rDescr.Underline );
     355        1646 :     if ( (FontStrikeout)rDescr.Strikeout != STRIKEOUT_DONTKNOW )
     356        1480 :         aFont.SetStrikeout( (FontStrikeout)rDescr.Strikeout );
     357             : 
     358             :     // Kein DONTKNOW
     359        1646 :     aFont.SetOrientation( (short)rDescr.Orientation );
     360        1646 :     aFont.SetKerning( rDescr.Kerning );
     361        1646 :     aFont.SetWordLineMode( rDescr.WordLineMode );
     362             : 
     363        1646 :     return aFont;
     364             : }
     365             : 
     366           0 : Font VCLUnoHelper::CreateFont( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont >& rxFont )
     367             : {
     368           0 :     Font aFont;
     369           0 :     VCLXFont* pVCLXFont = VCLXFont::GetImplementation( rxFont );
     370           0 :     if ( pVCLXFont )
     371           0 :         aFont = pVCLXFont->GetFont();
     372           0 :     return aFont;
     373             : }
     374             : 
     375             : 
     376           0 : ::com::sun::star::awt::SimpleFontMetric VCLUnoHelper::CreateFontMetric( const FontMetric& rFontMetric )
     377             : {
     378           0 :     ::com::sun::star::awt::SimpleFontMetric aFM;
     379           0 :     aFM.Ascent = (sal_Int16)rFontMetric.GetAscent();
     380           0 :     aFM.Descent = (sal_Int16)rFontMetric.GetDescent();
     381           0 :     aFM.Leading = (sal_Int16)rFontMetric.GetIntLeading();
     382           0 :     aFM.Slant = (sal_Int16)rFontMetric.GetSlant();
     383           0 :     aFM.FirstChar = 0x0020;
     384           0 :     aFM.LastChar = 0xFFFD;
     385           0 :     return aFM;
     386             : }
     387             : 
     388       19054 : bool VCLUnoHelper::IsZero( ::com::sun::star::awt::Rectangle rRect )
     389             : {
     390       19054 :     return ( !rRect.X && !rRect.Y && !rRect.Width && !rRect.Height );
     391             : }
     392             : 
     393         634 : MapUnit VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit )
     394             : {
     395         634 :     switch( nUnoEmbedMapUnit )
     396             :     {
     397             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM:
     398         581 :             return MAP_100TH_MM;
     399             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM:
     400           0 :             return MAP_10TH_MM;
     401             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_MM:
     402           0 :             return MAP_MM;
     403             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_CM:
     404           0 :             return MAP_CM;
     405             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH:
     406           0 :             return MAP_1000TH_INCH;
     407             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH:
     408           0 :             return MAP_100TH_INCH;
     409             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH:
     410           0 :             return MAP_10TH_INCH;
     411             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_INCH:
     412           0 :             return MAP_INCH;
     413             :         case ::com::sun::star::embed::EmbedMapUnits::POINT:
     414           0 :             return MAP_POINT;
     415             :         case ::com::sun::star::embed::EmbedMapUnits::TWIP:
     416          53 :             return MAP_TWIP;
     417             :         case ::com::sun::star::embed::EmbedMapUnits::PIXEL:
     418           0 :             return MAP_PIXEL;
     419             :     }
     420             : 
     421             :     OSL_FAIL( "Unexpected UNO map mode is provided!\n" );
     422           0 :     return MAP_LASTENUMDUMMY;
     423             : }
     424             : 
     425         573 : sal_Int32 VCLUnoHelper::VCL2UnoEmbedMapUnit( MapUnit nVCLMapUnit )
     426             : {
     427         573 :     switch( nVCLMapUnit )
     428             :     {
     429             :         case MAP_100TH_MM:
     430         520 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM;
     431             :         case MAP_10TH_MM:
     432           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM;
     433             :         case MAP_MM:
     434           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_MM;
     435             :         case MAP_CM:
     436           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_CM;
     437             :         case MAP_1000TH_INCH:
     438           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH;
     439             :         case MAP_100TH_INCH:
     440           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH;
     441             :         case MAP_10TH_INCH:
     442           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH;
     443             :         case MAP_INCH:
     444           0 :             return ::com::sun::star::embed::EmbedMapUnits::ONE_INCH;
     445             :         case MAP_POINT:
     446           0 :             return ::com::sun::star::embed::EmbedMapUnits::POINT;
     447             :         case MAP_TWIP:
     448          53 :             return ::com::sun::star::embed::EmbedMapUnits::TWIP;
     449             :         case MAP_PIXEL:
     450           0 :             return ::com::sun::star::embed::EmbedMapUnits::PIXEL;
     451             :         default: ; // avoid compiler warning
     452             :     }
     453             : 
     454             :     OSL_FAIL( "Unexpected VCL map mode is provided!\n" );
     455           0 :     return -1;
     456             : }
     457             : 
     458             : using namespace ::com::sun::star::util;
     459             : 
     460             : 
     461             : //= file-local helpers
     462             : 
     463             : namespace
     464             : {
     465             :     enum UnitConversionDirection
     466             :     {
     467             :         FieldUnitToMeasurementUnit,
     468             :         MeasurementUnitToFieldUnit
     469             :     };
     470             : 
     471           0 :     sal_Int16 convertMeasurementUnit( sal_Int16 _nUnit, UnitConversionDirection eDirection, sal_Int16& _rFieldToUNOValueFactor )
     472             :     {
     473             :         static struct _unit_table
     474             :         {
     475             :             FieldUnit eFieldUnit;
     476             :             sal_Int16 nMeasurementUnit;
     477             :             sal_Int16 nFieldToMeasureFactor;
     478             :         } aUnits[] = {
     479             :             { FUNIT_NONE,       -1 , -1},
     480             :             { FUNIT_MM,         MeasureUnit::MM,            1 },    // must precede MM_10TH
     481             :             { FUNIT_MM,         MeasureUnit::MM_10TH,       10 },
     482             :             { FUNIT_100TH_MM,   MeasureUnit::MM_100TH,      1 },
     483             :             { FUNIT_CM,         MeasureUnit::CM,            1 },
     484             :             { FUNIT_M,          MeasureUnit::M,             1 },
     485             :             { FUNIT_KM,         MeasureUnit::KM,            1 },
     486             :             { FUNIT_TWIP,       MeasureUnit::TWIP,          1 },
     487             :             { FUNIT_POINT,      MeasureUnit::POINT,         1 },
     488             :             { FUNIT_PICA,       MeasureUnit::PICA,          1 },
     489             :             { FUNIT_INCH,       MeasureUnit::INCH,          1 },    // must precede INCH_*TH
     490             :             { FUNIT_INCH,       MeasureUnit::INCH_10TH,     10 },
     491             :             { FUNIT_INCH,       MeasureUnit::INCH_100TH,    100 },
     492             :             { FUNIT_INCH,       MeasureUnit::INCH_1000TH,   1000 },
     493             :             { FUNIT_FOOT,       MeasureUnit::FOOT,          1 },
     494             :             { FUNIT_MILE,       MeasureUnit::MILE,          1 },
     495             :         };
     496           0 :         for ( size_t i = 0; i < SAL_N_ELEMENTS( aUnits ); ++i )
     497             :         {
     498           0 :             if ( eDirection == FieldUnitToMeasurementUnit )
     499             :             {
     500           0 :                 if ( ( aUnits[ i ].eFieldUnit == (FieldUnit)_nUnit ) && ( aUnits[ i ].nFieldToMeasureFactor == _rFieldToUNOValueFactor ) )
     501           0 :                     return aUnits[ i ].nMeasurementUnit;
     502             :             }
     503             :             else
     504             :             {
     505           0 :                 if ( aUnits[ i ].nMeasurementUnit == _nUnit )
     506             :                 {
     507           0 :                     _rFieldToUNOValueFactor = aUnits[ i ].nFieldToMeasureFactor;
     508           0 :                     return (sal_Int16)aUnits[ i ].eFieldUnit;
     509             :                 }
     510             :             }
     511             :         }
     512           0 :         if ( eDirection == FieldUnitToMeasurementUnit )
     513           0 :             return -1;
     514             : 
     515           0 :         _rFieldToUNOValueFactor = 1;
     516           0 :         return (sal_Int16)FUNIT_NONE;
     517             :     }
     518             : }
     519             : 
     520             : //= MeasurementUnitConversion
     521             : 
     522             : 
     523           0 : sal_Int16 VCLUnoHelper::ConvertToMeasurementUnit( FieldUnit _nFieldUnit, sal_Int16 _nUNOToFieldValueFactor )
     524             : {
     525           0 :     return convertMeasurementUnit( (sal_Int16)_nFieldUnit, FieldUnitToMeasurementUnit, _nUNOToFieldValueFactor );
     526             : }
     527             : 
     528             : 
     529           0 : FieldUnit VCLUnoHelper::ConvertToFieldUnit( sal_Int16 _nMeasurementUnit, sal_Int16& _rFieldToUNOValueFactor )
     530             : {
     531           0 :     return (FieldUnit)convertMeasurementUnit( _nMeasurementUnit, MeasurementUnitToFieldUnit, _rFieldToUNOValueFactor );
     532             : }
     533             : 
     534             : 
     535          33 : MapUnit /* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16 /* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit) throw (::com::sun::star::lang::IllegalArgumentException)
     536             : {
     537             :     MapUnit eMode;
     538          33 :     switch(_nMeasureUnit)
     539             :     {
     540             :     case com::sun::star::util::MeasureUnit::MM_100TH:
     541           3 :         eMode = MAP_100TH_MM;
     542           3 :         break;
     543             : 
     544             : 
     545             :     case com::sun::star::util::MeasureUnit::MM_10TH:
     546           1 :         eMode = MAP_10TH_MM;
     547           1 :         break;
     548             : 
     549             :     case com::sun::star::util::MeasureUnit::MM:
     550           1 :         eMode = MAP_MM;
     551           1 :         break;
     552             : 
     553             :     case com::sun::star::util::MeasureUnit::CM:
     554           1 :         eMode = MAP_CM;
     555           1 :         break;
     556             : 
     557             :     case com::sun::star::util::MeasureUnit::INCH_1000TH:
     558           1 :         eMode = MAP_1000TH_INCH;
     559           1 :         break;
     560             : 
     561             :     case com::sun::star::util::MeasureUnit::INCH_100TH:
     562           1 :         eMode = MAP_100TH_INCH;
     563           1 :         break;
     564             : 
     565             :     case com::sun::star::util::MeasureUnit::INCH_10TH:
     566           1 :         eMode = MAP_10TH_INCH;
     567           1 :         break;
     568             : 
     569             :     case com::sun::star::util::MeasureUnit::INCH:
     570           1 :         eMode = MAP_INCH;
     571           1 :         break;
     572             : 
     573             :     case com::sun::star::util::MeasureUnit::POINT:
     574           1 :         eMode = MAP_POINT;
     575           1 :         break;
     576             : 
     577             :     case com::sun::star::util::MeasureUnit::TWIP:
     578           1 :         eMode = MAP_TWIP;
     579           1 :         break;
     580             : 
     581             :     case com::sun::star::util::MeasureUnit::PIXEL:
     582           1 :         eMode = MAP_PIXEL;
     583           1 :         break;
     584             : 
     585             : /*
     586             :     case com::sun::star::util::MeasureUnit::M:
     587             :         break;
     588             :     case com::sun::star::util::MeasureUnit::KM:
     589             :         break;
     590             :     case com::sun::star::util::MeasureUnit::PICA:
     591             :         break;
     592             :     case com::sun::star::util::MeasureUnit::FOOT:
     593             :         break;
     594             :     case com::sun::star::util::MeasureUnit::MILE:
     595             :         break;
     596             :     case com::sun::star::util::MeasureUnit::PERCENT:
     597             :         break;
     598             : */
     599             :     case com::sun::star::util::MeasureUnit::APPFONT:
     600          19 :         eMode = MAP_APPFONT;
     601          19 :         break;
     602             : 
     603             :     case com::sun::star::util::MeasureUnit::SYSFONT:
     604           1 :         eMode = MAP_SYSFONT;
     605           1 :         break;
     606             : 
     607             : /*
     608             :     case com::sun::star::util::MeasureUnit::RELATIVE:
     609             :         eMode = MAP_RELATIVE;
     610             :         break;
     611             : */
     612             : 
     613             :     default:
     614           0 :         throw ::com::sun::star::lang::IllegalArgumentException("Unsupported measure unit.", NULL, 1 );
     615             :     }
     616          33 :     return eMode;
     617             : }
     618             : 
     619          25 : ::Size VCLUnoHelper::ConvertToVCLSize(com::sun::star::awt::Size const& _aSize)
     620             : {
     621          25 :     ::Size aVCLSize(_aSize.Width, _aSize.Height);
     622          25 :     return aVCLSize;
     623             : }
     624             : 
     625          25 : com::sun::star::awt::Size VCLUnoHelper::ConvertToAWTSize(::Size /* VCLSize */ const& _aSize)
     626             : {
     627          25 :     com::sun::star::awt::Size aAWTSize(_aSize.Width(), _aSize.Height());
     628          25 :     return aAWTSize;
     629             : }
     630             : 
     631             : 
     632           9 : ::Point VCLUnoHelper::ConvertToVCLPoint(com::sun::star::awt::Point const& _aPoint)
     633             : {
     634           9 :     ::Point aVCLPoint(_aPoint.X, _aPoint.Y);
     635           9 :     return aVCLPoint;
     636             : }
     637             : 
     638           9 : com::sun::star::awt::Point VCLUnoHelper::ConvertToAWTPoint(::Point /* VCLPoint */ const& _aPoint)
     639             : {
     640           9 :     com::sun::star::awt::Point aAWTPoint(_aPoint.X(), _aPoint.Y());
     641           9 :     return aAWTPoint;
     642             : }
     643             : 
     644       13523 : ::Rectangle VCLUnoHelper::ConvertToVCLRect( ::com::sun::star::awt::Rectangle const & _rRect )
     645             : {
     646       13523 :     return ::Rectangle( _rRect.X, _rRect.Y, _rRect.X + _rRect.Width - 1, _rRect.Y + _rRect.Height - 1 );
     647             : }
     648             : 
     649           0 : ::com::sun::star::awt::Rectangle VCLUnoHelper::ConvertToAWTRect( ::Rectangle const & _rRect )
     650             : {
     651           0 :     return ::com::sun::star::awt::Rectangle( _rRect.Left(), _rRect.Top(), _rRect.GetWidth(), _rRect.GetHeight() );
     652             : }
     653             : 
     654           0 : awt::MouseEvent VCLUnoHelper::createMouseEvent( const ::MouseEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
     655             : {
     656           0 :     awt::MouseEvent aMouseEvent;
     657           0 :     aMouseEvent.Source = _rxContext;
     658             : 
     659           0 :     aMouseEvent.Modifiers = 0;
     660           0 :     if ( _rVclEvent.IsShift() )
     661           0 :         aMouseEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::SHIFT;
     662           0 :     if ( _rVclEvent.IsMod1() )
     663           0 :         aMouseEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD1;
     664           0 :     if ( _rVclEvent.IsMod2() )
     665           0 :         aMouseEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD2;
     666             : 
     667           0 :     aMouseEvent.Buttons = 0;
     668           0 :     if ( _rVclEvent.IsLeft() )
     669           0 :         aMouseEvent.Buttons |= ::com::sun::star::awt::MouseButton::LEFT;
     670           0 :     if ( _rVclEvent.IsRight() )
     671           0 :         aMouseEvent.Buttons |= ::com::sun::star::awt::MouseButton::RIGHT;
     672           0 :     if ( _rVclEvent.IsMiddle() )
     673           0 :         aMouseEvent.Buttons |= ::com::sun::star::awt::MouseButton::MIDDLE;
     674             : 
     675           0 :     aMouseEvent.X = _rVclEvent.GetPosPixel().X();
     676           0 :     aMouseEvent.Y = _rVclEvent.GetPosPixel().Y();
     677           0 :     aMouseEvent.ClickCount = _rVclEvent.GetClicks();
     678           0 :     aMouseEvent.PopupTrigger = sal_False;
     679             : 
     680           0 :     return aMouseEvent;
     681             : }
     682             : 
     683           0 : awt::KeyEvent VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
     684             : {
     685           0 :     awt::KeyEvent aKeyEvent;
     686           0 :     aKeyEvent.Source = _rxContext;
     687             : 
     688           0 :     aKeyEvent.Modifiers = 0;
     689           0 :     if ( _rVclEvent.GetKeyCode().IsShift() )
     690           0 :         aKeyEvent.Modifiers |= awt::KeyModifier::SHIFT;
     691           0 :     if ( _rVclEvent.GetKeyCode().IsMod1() )
     692           0 :         aKeyEvent.Modifiers |= awt::KeyModifier::MOD1;
     693           0 :     if ( _rVclEvent.GetKeyCode().IsMod2() )
     694           0 :         aKeyEvent.Modifiers |= awt::KeyModifier::MOD2;
     695           0 :     if ( _rVclEvent.GetKeyCode().IsMod3() )
     696           0 :             aKeyEvent.Modifiers |= awt::KeyModifier::MOD3;
     697             : 
     698           0 :     aKeyEvent.KeyCode = _rVclEvent.GetKeyCode().GetCode();
     699           0 :     aKeyEvent.KeyChar = _rVclEvent.GetCharCode();
     700           0 :     aKeyEvent.KeyFunc = ::sal::static_int_cast< sal_Int16 >( _rVclEvent.GetKeyCode().GetFunction());
     701             : 
     702           0 :     return aKeyEvent;
     703             : }
     704             : 
     705             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10