LCOV - code coverage report
Current view: top level - toolkit/source/helper - vclunohelper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 361 0.0 %
Date: 2014-04-14 Functions: 0 35 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <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           0 : uno::Reference< ::com::sun::star::awt::XToolkit> VCLUnoHelper::CreateToolkit()
      64             : {
      65           0 :     uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
      66           0 :     uno::Reference< awt::XToolkit> xToolkit( awt::Toolkit::create(xContext), uno::UNO_QUERY_THROW );
      67           0 :     return xToolkit;
      68             : }
      69             : 
      70           0 : BitmapEx VCLUnoHelper::GetBitmap( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap>& rxBitmap )
      71             : {
      72           0 :     BitmapEx aBmp;
      73             : 
      74           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > xGraphic( rxBitmap, ::com::sun::star::uno::UNO_QUERY );
      75           0 :     if( xGraphic.is() )
      76             :     {
      77           0 :         Graphic aGraphic( xGraphic );
      78           0 :         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           0 :     return aBmp;
     102             : }
     103             : 
     104           0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap> VCLUnoHelper::CreateBitmap( const BitmapEx& rBitmap )
     105             : {
     106           0 :     Graphic aGraphic( rBitmap );
     107           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap> xBmp( aGraphic.GetXGraphic(), ::com::sun::star::uno::UNO_QUERY );
     108           0 :     return xBmp;
     109             : }
     110             : 
     111           0 : Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow>& rxWindow )
     112             : {
     113           0 :     VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow );
     114           0 :     return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL;
     115             : }
     116             : 
     117           0 : Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow2>& rxWindow )
     118             : {
     119           0 :     VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow );
     120           0 :     return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL;
     121             : }
     122             : 
     123           0 : Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer>& rxWindow )
     124             : {
     125           0 :     VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow );
     126           0 :     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           0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow> VCLUnoHelper::GetInterface( Window* pWindow )
     146             : {
     147           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xWin;
     148           0 :     if ( pWindow )
     149             :     {
     150           0 :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetComponentInterface();
     151           0 :         xWin = xWin.query( xPeer );
     152             :     }
     153           0 :     return xWin;
     154             : }
     155             : 
     156           0 : OutputDevice* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice>& rxDevice )
     157             : {
     158           0 :     OutputDevice* pOutDev = NULL;
     159           0 :     VCLXDevice* pDev = VCLXDevice::GetImplementation( rxDevice );
     160           0 :     if ( pDev )
     161           0 :         pOutDev = pDev->GetOutputDevice();
     162           0 :     return pOutDev;
     163             : }
     164             : 
     165           0 : OutputDevice* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics>& rxGraphics )
     166             : {
     167           0 :     OutputDevice* pOutDev = NULL;
     168           0 :     VCLXGraphics* pGrf = VCLXGraphics::GetImplementation( rxGraphics );
     169           0 :     if ( pGrf )
     170           0 :         pOutDev = pGrf->GetOutputDevice();
     171           0 :     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           0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer> VCLUnoHelper::CreateControlContainer( Window* pWindow )
     191             : {
     192           0 :     UnoControlContainer* pContainer = new UnoControlContainer( pWindow->GetComponentInterface( sal_True ) );
     193           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > x = pContainer;
     194             : 
     195           0 :     UnoControlModel* pContainerModel = new UnoControlContainerModel( ::comphelper::getProcessComponentContext() );
     196           0 :     pContainer->setModel( (::com::sun::star::awt::XControlModel*)pContainerModel );
     197             : 
     198           0 :     return x;
     199             : }
     200             : 
     201           0 : float VCLUnoHelper::ConvertFontWidth( FontWidth eWidth )
     202             : {
     203           0 :     if( eWidth == WIDTH_DONTKNOW )
     204           0 :         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           0 : FontWidth VCLUnoHelper::ConvertFontWidth( float f )
     229             : {
     230           0 :     if( f <= ::com::sun::star::awt::FontWidth::DONTKNOW )
     231           0 :         return WIDTH_DONTKNOW;
     232           0 :     else if( f <= ::com::sun::star::awt::FontWidth::ULTRACONDENSED )
     233           0 :         return WIDTH_ULTRA_CONDENSED;
     234           0 :     else if( f <= ::com::sun::star::awt::FontWidth::EXTRACONDENSED )
     235           0 :         return WIDTH_EXTRA_CONDENSED;
     236           0 :     else if( f <= ::com::sun::star::awt::FontWidth::CONDENSED )
     237           0 :         return WIDTH_CONDENSED;
     238           0 :     else if( f <= ::com::sun::star::awt::FontWidth::SEMICONDENSED )
     239           0 :         return WIDTH_SEMI_CONDENSED;
     240           0 :     else if( f <= ::com::sun::star::awt::FontWidth::NORMAL )
     241           0 :         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           0 : float VCLUnoHelper::ConvertFontWeight( FontWeight eWeight )
     256             : {
     257           0 :     if( eWeight == WEIGHT_DONTKNOW )
     258           0 :         return ::com::sun::star::awt::FontWeight::DONTKNOW;
     259           0 :     else if( eWeight == WEIGHT_THIN )
     260           0 :         return ::com::sun::star::awt::FontWeight::THIN;
     261           0 :     else if( eWeight == WEIGHT_ULTRALIGHT )
     262           0 :         return ::com::sun::star::awt::FontWeight::ULTRALIGHT;
     263           0 :     else if( eWeight == WEIGHT_LIGHT )
     264           0 :         return ::com::sun::star::awt::FontWeight::LIGHT;
     265           0 :     else if( eWeight == WEIGHT_SEMILIGHT )
     266           0 :         return ::com::sun::star::awt::FontWeight::SEMILIGHT;
     267           0 :     else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) )
     268           0 :         return ::com::sun::star::awt::FontWeight::NORMAL;
     269           0 :     else if( eWeight == WEIGHT_SEMIBOLD )
     270           0 :         return ::com::sun::star::awt::FontWeight::SEMIBOLD;
     271           0 :     else if( eWeight == WEIGHT_BOLD )
     272           0 :         return ::com::sun::star::awt::FontWeight::BOLD;
     273           0 :     else if( eWeight == WEIGHT_ULTRABOLD )
     274           0 :         return ::com::sun::star::awt::FontWeight::ULTRABOLD;
     275           0 :     else if( eWeight == WEIGHT_BLACK )
     276           0 :         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           0 : FontWeight VCLUnoHelper::ConvertFontWeight( float f )
     283             : {
     284           0 :     if( f <= ::com::sun::star::awt::FontWeight::DONTKNOW )
     285           0 :         return WEIGHT_DONTKNOW;
     286           0 :     else if( f <= ::com::sun::star::awt::FontWeight::THIN )
     287           0 :         return WEIGHT_THIN;
     288           0 :     else if( f <= ::com::sun::star::awt::FontWeight::ULTRALIGHT )
     289           0 :         return WEIGHT_ULTRALIGHT;
     290           0 :     else if( f <= ::com::sun::star::awt::FontWeight::LIGHT )
     291           0 :         return WEIGHT_LIGHT;
     292           0 :     else if( f <= ::com::sun::star::awt::FontWeight::SEMILIGHT )
     293           0 :         return WEIGHT_SEMILIGHT;
     294           0 :     else if( f <= ::com::sun::star::awt::FontWeight::NORMAL )
     295           0 :         return WEIGHT_NORMAL;
     296           0 :     else if( f <= ::com::sun::star::awt::FontWeight::SEMIBOLD )
     297           0 :         return WEIGHT_SEMIBOLD;
     298           0 :     else if( f <= ::com::sun::star::awt::FontWeight::BOLD )
     299           0 :         return WEIGHT_BOLD;
     300           0 :     else if( f <= ::com::sun::star::awt::FontWeight::ULTRABOLD )
     301           0 :         return WEIGHT_ULTRABOLD;
     302           0 :     else if( f <= ::com::sun::star::awt::FontWeight::BLACK )
     303           0 :         return WEIGHT_BLACK;
     304             : 
     305             :     OSL_FAIL( "Unknown FontWeight" );
     306           0 :     return WEIGHT_DONTKNOW;
     307             : }
     308             : 
     309             : 
     310           0 : ::com::sun::star::awt::FontDescriptor VCLUnoHelper::CreateFontDescriptor( const Font& rFont )
     311             : {
     312           0 :     ::com::sun::star::awt::FontDescriptor aFD;
     313           0 :     aFD.Name = rFont.GetName();
     314           0 :     aFD.StyleName = rFont.GetStyleName();
     315           0 :     aFD.Height = (sal_Int16)rFont.GetSize().Height();
     316           0 :     aFD.Width = (sal_Int16)rFont.GetSize().Width();
     317           0 :     aFD.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
     318           0 :     aFD.CharSet = rFont.GetCharSet();
     319           0 :     aFD.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
     320           0 :     aFD.CharacterWidth = VCLUnoHelper::ConvertFontWidth( rFont.GetWidthType() );
     321           0 :     aFD.Weight= VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() );
     322           0 :     aFD.Slant = (::com::sun::star::awt::FontSlant)rFont.GetItalic();
     323           0 :     aFD.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline());
     324           0 :     aFD.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout());
     325           0 :     aFD.Orientation = rFont.GetOrientation();
     326           0 :     aFD.Kerning = rFont.IsKerning();
     327           0 :     aFD.WordLineMode = rFont.IsWordLineMode();
     328           0 :     aFD.Type = 0;   // ??? => Nur an Metric...
     329           0 :     return aFD;
     330             : }
     331             : 
     332           0 : Font VCLUnoHelper::CreateFont( const ::com::sun::star::awt::FontDescriptor& rDescr, const Font& rInitFont )
     333             : {
     334           0 :     Font aFont( rInitFont );
     335           0 :     if ( !rDescr.Name.isEmpty() )
     336           0 :         aFont.SetName( rDescr.Name );
     337           0 :     if ( !rDescr.StyleName.isEmpty() )
     338           0 :         aFont.SetStyleName( rDescr.StyleName );
     339           0 :     if ( rDescr.Height )
     340           0 :         aFont.SetSize( Size( rDescr.Width, rDescr.Height ) );
     341           0 :     if ( (FontFamily)rDescr.Family != FAMILY_DONTKNOW )
     342           0 :         aFont.SetFamily( (FontFamily)rDescr.Family );
     343           0 :     if ( (rtl_TextEncoding)rDescr.CharSet != RTL_TEXTENCODING_DONTKNOW )
     344           0 :         aFont.SetCharSet( (rtl_TextEncoding)rDescr.CharSet );
     345           0 :     if ( (FontPitch)rDescr.Pitch != PITCH_DONTKNOW )
     346           0 :         aFont.SetPitch( (FontPitch)rDescr.Pitch );
     347           0 :     if ( rDescr.CharacterWidth )
     348           0 :         aFont.SetWidthType( VCLUnoHelper::ConvertFontWidth( rDescr.CharacterWidth ) );
     349           0 :     if ( rDescr.Weight )
     350           0 :         aFont.SetWeight( VCLUnoHelper::ConvertFontWeight( rDescr.Weight ) );
     351           0 :     if ( (FontItalic)rDescr.Slant != ITALIC_DONTKNOW )
     352           0 :         aFont.SetItalic( (FontItalic)rDescr.Slant );
     353           0 :     if ( (FontUnderline)rDescr.Underline != UNDERLINE_DONTKNOW )
     354           0 :         aFont.SetUnderline( (FontUnderline)rDescr.Underline );
     355           0 :     if ( (FontStrikeout)rDescr.Strikeout != STRIKEOUT_DONTKNOW )
     356           0 :         aFont.SetStrikeout( (FontStrikeout)rDescr.Strikeout );
     357             : 
     358             :     // Kein DONTKNOW
     359           0 :     aFont.SetOrientation( (short)rDescr.Orientation );
     360           0 :     aFont.SetKerning( rDescr.Kerning );
     361           0 :     aFont.SetWordLineMode( rDescr.WordLineMode );
     362             : 
     363           0 :     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           0 : bool VCLUnoHelper::IsZero( ::com::sun::star::awt::Rectangle rRect )
     389             : {
     390           0 :     return ( !rRect.X && !rRect.Y && !rRect.Width && !rRect.Height );
     391             : }
     392             : 
     393           0 : MapUnit VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit )
     394             : {
     395           0 :     switch( nUnoEmbedMapUnit )
     396             :     {
     397             :         case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM:
     398           0 :             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           0 :             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           0 : sal_Int32 VCLUnoHelper::VCL2UnoEmbedMapUnit( MapUnit nVCLMapUnit )
     426             : {
     427           0 :     switch( nVCLMapUnit )
     428             :     {
     429             :         case MAP_100TH_MM:
     430           0 :             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           0 :             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           0 : MapUnit /* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16 /* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit) throw (::com::sun::star::lang::IllegalArgumentException)
     536             : {
     537             :     MapUnit eMode;
     538           0 :     switch(_nMeasureUnit)
     539             :     {
     540             :     case com::sun::star::util::MeasureUnit::MM_100TH:
     541           0 :         eMode = MAP_100TH_MM;
     542           0 :         break;
     543             : 
     544             : 
     545             :     case com::sun::star::util::MeasureUnit::MM_10TH:
     546           0 :         eMode = MAP_10TH_MM;
     547           0 :         break;
     548             : 
     549             :     case com::sun::star::util::MeasureUnit::MM:
     550           0 :         eMode = MAP_MM;
     551           0 :         break;
     552             : 
     553             :     case com::sun::star::util::MeasureUnit::CM:
     554           0 :         eMode = MAP_CM;
     555           0 :         break;
     556             : 
     557             :     case com::sun::star::util::MeasureUnit::INCH_1000TH:
     558           0 :         eMode = MAP_1000TH_INCH;
     559           0 :         break;
     560             : 
     561             :     case com::sun::star::util::MeasureUnit::INCH_100TH:
     562           0 :         eMode = MAP_100TH_INCH;
     563           0 :         break;
     564             : 
     565             :     case com::sun::star::util::MeasureUnit::INCH_10TH:
     566           0 :         eMode = MAP_10TH_INCH;
     567           0 :         break;
     568             : 
     569             :     case com::sun::star::util::MeasureUnit::INCH:
     570           0 :         eMode = MAP_INCH;
     571           0 :         break;
     572             : 
     573             :     case com::sun::star::util::MeasureUnit::POINT:
     574           0 :         eMode = MAP_POINT;
     575           0 :         break;
     576             : 
     577             :     case com::sun::star::util::MeasureUnit::TWIP:
     578           0 :         eMode = MAP_TWIP;
     579           0 :         break;
     580             : 
     581             :     case com::sun::star::util::MeasureUnit::PIXEL:
     582           0 :         eMode = MAP_PIXEL;
     583           0 :         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           0 :         eMode = MAP_APPFONT;
     601           0 :         break;
     602             : 
     603             :     case com::sun::star::util::MeasureUnit::SYSFONT:
     604           0 :         eMode = MAP_SYSFONT;
     605           0 :         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           0 :     return eMode;
     617             : }
     618             : 
     619           0 : ::Size VCLUnoHelper::ConvertToVCLSize(com::sun::star::awt::Size const& _aSize)
     620             : {
     621           0 :     ::Size aVCLSize(_aSize.Width, _aSize.Height);
     622           0 :     return aVCLSize;
     623             : }
     624             : 
     625           0 : com::sun::star::awt::Size VCLUnoHelper::ConvertToAWTSize(::Size /* VCLSize */ const& _aSize)
     626             : {
     627           0 :     com::sun::star::awt::Size aAWTSize(_aSize.Width(), _aSize.Height());
     628           0 :     return aAWTSize;
     629             : }
     630             : 
     631             : 
     632           0 : ::Point VCLUnoHelper::ConvertToVCLPoint(com::sun::star::awt::Point const& _aPoint)
     633             : {
     634           0 :     ::Point aVCLPoint(_aPoint.X, _aPoint.Y);
     635           0 :     return aVCLPoint;
     636             : }
     637             : 
     638           0 : com::sun::star::awt::Point VCLUnoHelper::ConvertToAWTPoint(::Point /* VCLPoint */ const& _aPoint)
     639             : {
     640           0 :     com::sun::star::awt::Point aAWTPoint(_aPoint.X(), _aPoint.Y());
     641           0 :     return aAWTPoint;
     642             : }
     643             : 
     644           0 : ::Rectangle VCLUnoHelper::ConvertToVCLRect( ::com::sun::star::awt::Rectangle const & _rRect )
     645             : {
     646           0 :     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