LCOV - code coverage report
Current view: top level - svx/source/gallery2 - galobj.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 270 0.0 %
Date: 2012-08-25 Functions: 0 34 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 482 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <com/sun/star/lang/XUnoTunnel.hpp>
      31                 :            : #include <sfx2/objsh.hxx>
      32                 :            : #include <sfx2/docfac.hxx>
      33                 :            : 
      34                 :            : #include <comphelper/classids.hxx>
      35                 :            : #include <comphelper/string.hxx>
      36                 :            : #include <unotools/pathoptions.hxx>
      37                 :            : 
      38                 :            : #include <tools/rcid.h>
      39                 :            : #include <tools/vcompat.hxx>
      40                 :            : #include <tools/helpers.hxx>
      41                 :            : #include <vcl/virdev.hxx>
      42                 :            : #include <svl/itempool.hxx>
      43                 :            : #include <svx/fmmodel.hxx>
      44                 :            : #include <svx/fmview.hxx>
      45                 :            : #include <svx/fmpage.hxx>
      46                 :            : #include "gallery.hrc"
      47                 :            : #include "svx/galmisc.hxx"
      48                 :            : #include "galobj.hxx"
      49                 :            : #include <vcl/svapp.hxx>
      50                 :            : 
      51                 :            : #include "gallerydrawmodel.hxx"
      52                 :            : 
      53                 :            : using namespace ::com::sun::star;
      54                 :            : 
      55                 :            : // -------------
      56                 :            : // - SgaObject -
      57                 :            : // -------------
      58                 :            : 
      59                 :          0 : SgaObject::SgaObject() :
      60                 :            :         bIsValid    ( sal_False ),
      61 [ #  # ][ #  # ]:          0 :         bIsThumbBmp ( sal_True )
         [ #  # ][ #  # ]
      62                 :            : {
      63                 :          0 : }
      64                 :            : 
      65                 :            : // ------------------------------------------------------------------------
      66                 :            : 
      67                 :          0 : sal_Bool SgaObject::CreateThumb( const Graphic& rGraphic )
      68                 :            : {
      69                 :          0 :     sal_Bool bRet = sal_False;
      70                 :            : 
      71         [ #  # ]:          0 :     if( rGraphic.GetType() == GRAPHIC_BITMAP )
      72                 :            :     {
      73         [ #  # ]:          0 :         BitmapEx    aBmpEx( rGraphic.GetBitmapEx() );
      74                 :          0 :         Size        aBmpSize( aBmpEx.GetSizePixel() );
      75                 :            : 
      76 [ #  # ][ #  # ]:          0 :         if( aBmpSize.Width() && aBmpSize.Height() )
                 [ #  # ]
      77                 :            :         {
      78                 :          0 :             const Color aWhite( COL_WHITE );
      79                 :            : 
      80 [ #  # ][ #  #  :          0 :             if( aBmpEx.GetPrefMapMode().GetMapUnit() != MAP_PIXEL &&
             #  #  #  # ]
      81                 :          0 :                 aBmpEx.GetPrefSize().Width() > 0 &&
      82                 :          0 :                 aBmpEx.GetPrefSize().Height() > 0 )
      83                 :            :             {
      84 [ #  # ][ #  # ]:          0 :                 Size aLogSize( OutputDevice::LogicToLogic( aBmpEx.GetPrefSize(), aBmpEx.GetPrefMapMode(), MAP_100TH_MM ) );
                 [ #  # ]
      85                 :            : 
      86 [ #  # ][ #  # ]:          0 :                 if( aLogSize.Width() > 0 && aLogSize.Height() > 0 )
                 [ #  # ]
      87                 :            :                 {
      88                 :          0 :                     double  fFactorLog = static_cast< double >( aLogSize.Width() ) / aLogSize.Height();
      89                 :          0 :                     double  fFactorPix = static_cast< double >( aBmpSize.Width() ) / aBmpSize.Height();
      90                 :            : 
      91         [ #  # ]:          0 :                     if( fFactorPix > fFactorLog )
      92                 :          0 :                         aBmpSize.Width() = FRound( aBmpSize.Height() * fFactorLog );
      93                 :            :                     else
      94                 :          0 :                         aBmpSize.Height() = FRound( aBmpSize.Width() / fFactorLog );
      95                 :            : 
      96         [ #  # ]:          0 :                     aBmpEx.SetSizePixel( aBmpSize );
      97                 :            :                 }
      98                 :            :             }
      99                 :            : 
     100 [ #  # ][ #  # ]:          0 :             aThumbBmp = aBmpEx.GetBitmap( &aWhite );
                 [ #  # ]
     101                 :            : 
     102 [ #  # ][ #  # ]:          0 :             if( ( aBmpSize.Width() <= S_THUMB ) && ( aBmpSize.Height() <= S_THUMB ) )
                 [ #  # ]
     103                 :            :             {
     104         [ #  # ]:          0 :                 aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
     105                 :          0 :                 bRet = sal_True;
     106                 :            :             }
     107                 :            :             else
     108                 :            :             {
     109                 :          0 :                 const float fFactor  = (float) aBmpSize.Width() / aBmpSize.Height();
     110                 :            :                 const Size  aNewSize( Max( (long) (fFactor < 1. ? S_THUMB * fFactor : S_THUMB), 8L ),
     111 [ #  # ][ #  # ]:          0 :                                       Max( (long) (fFactor < 1. ? S_THUMB : S_THUMB / fFactor), 8L ) );
     112                 :            : 
     113         [ #  # ]:          0 :                 if( aThumbBmp.Scale( (double) aNewSize.Width() / aBmpSize.Width(),
     114         [ #  # ]:          0 :                                      (double) aNewSize.Height() / aBmpSize.Height(), BMP_SCALE_BEST ) )
     115                 :            :                 {
     116         [ #  # ]:          0 :                     aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
     117                 :          0 :                     bRet = sal_True;
     118                 :            :                 }
     119                 :            :             }
     120         [ #  # ]:          0 :         }
     121                 :            :     }
     122         [ #  # ]:          0 :     else if( rGraphic.GetType() == GRAPHIC_GDIMETAFILE )
     123                 :            :     {
     124         [ #  # ]:          0 :         const Size aPrefSize( rGraphic.GetPrefSize() );
     125                 :          0 :         const double fFactor  = (double)aPrefSize.Width() / (double)aPrefSize.Height();
     126                 :          0 :         Size aSize( S_THUMB, S_THUMB );
     127         [ #  # ]:          0 :         if ( fFactor < 1.0 )
     128                 :          0 :             aSize.Width() = (sal_Int32)( S_THUMB * fFactor );
     129                 :            :         else
     130                 :          0 :             aSize.Height() = (sal_Int32)( S_THUMB / fFactor );
     131                 :            : 
     132                 :          0 :         const GraphicConversionParameters aParameters(aSize);
     133 [ #  # ][ #  # ]:          0 :         aThumbBmp = rGraphic.GetBitmap(aParameters);
                 [ #  # ]
     134                 :            : 
     135         [ #  # ]:          0 :         if( !aThumbBmp.IsEmpty() )
     136                 :            :         {
     137         [ #  # ]:          0 :             aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
     138                 :          0 :             bRet = sal_True;
     139                 :            :         }
     140                 :            :     }
     141                 :            : 
     142                 :          0 :     return bRet;
     143                 :            : }
     144                 :            : 
     145                 :            : // ------------------------------------------------------------------------
     146                 :            : 
     147                 :          0 : void SgaObject::WriteData( SvStream& rOut, const String& rDestDir ) const
     148                 :            : {
     149                 :            :     static const sal_uInt32 nInventor = COMPAT_FORMAT( 'S', 'G', 'A', '3' );
     150                 :            : 
     151 [ #  # ][ #  # ]:          0 :     rOut << nInventor << (sal_uInt16) 0x0004 << GetVersion() << (sal_uInt16) GetObjKind();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     152         [ #  # ]:          0 :     rOut << bIsThumbBmp;
     153                 :            : 
     154         [ #  # ]:          0 :     if( bIsThumbBmp )
     155                 :            :     {
     156                 :          0 :         const sal_uInt16    nOldCompressMode = rOut.GetCompressMode();
     157                 :          0 :         const sal_uIntPtr       nOldVersion = rOut.GetVersion();
     158                 :            : 
     159                 :          0 :         rOut.SetCompressMode( COMPRESSMODE_ZBITMAP );
     160                 :          0 :         rOut.SetVersion( SOFFICE_FILEFORMAT_50 );
     161                 :            : 
     162         [ #  # ]:          0 :         rOut << aThumbBmp;
     163                 :            : 
     164                 :          0 :         rOut.SetVersion( nOldVersion );
     165                 :          0 :         rOut.SetCompressMode( nOldCompressMode );
     166                 :            :     }
     167                 :            :     else
     168         [ #  # ]:          0 :         rOut << aThumbMtf;
     169                 :            : 
     170 [ #  # ][ #  # ]:          0 :     String aURLWithoutDestDir = String(aURL.GetMainURL( INetURLObject::NO_DECODE ));
     171 [ #  # ][ #  # ]:          0 :     aURLWithoutDestDir.SearchAndReplace(rDestDir, String());
                 [ #  # ]
     172 [ #  # ][ #  # ]:          0 :     write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOut, aURLWithoutDestDir, RTL_TEXTENCODING_UTF8);
                 [ #  # ]
     173                 :          0 : }
     174                 :            : 
     175                 :            : // ------------------------------------------------------------------------
     176                 :            : 
     177                 :          0 : void SgaObject::ReadData(SvStream& rIn, sal_uInt16& rReadVersion )
     178                 :            : {
     179                 :            :     sal_uInt32      nTmp32;
     180                 :            :     sal_uInt16      nTmp16;
     181                 :            : 
     182 [ #  # ][ #  # ]:          0 :     rIn >> nTmp32 >> nTmp16 >> rReadVersion >> nTmp16 >> bIsThumbBmp;
         [ #  # ][ #  # ]
                 [ #  # ]
     183                 :            : 
     184         [ #  # ]:          0 :     if( bIsThumbBmp )
     185         [ #  # ]:          0 :         rIn >> aThumbBmp;
     186                 :            :     else
     187         [ #  # ]:          0 :         rIn >> aThumbMtf;
     188                 :            : 
     189         [ #  # ]:          0 :     rtl::OUString aTmpStr = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIn, RTL_TEXTENCODING_UTF8);
     190 [ #  # ][ #  # ]:          0 :     aURL = INetURLObject(aTmpStr);
                 [ #  # ]
     191                 :          0 : }
     192                 :            : 
     193                 :            : // ------------------------------------------------------------------------
     194                 :            : 
     195                 :          0 : const String SgaObject::GetTitle() const
     196                 :            : {
     197                 :          0 :     String aReturnValue( aTitle );
     198         [ #  # ]:          0 :     if ( !getenv( "GALLERY_SHOW_PRIVATE_TITLE" ) )
     199                 :            :     {
     200 [ #  # ][ #  # ]:          0 :         if ( comphelper::string::getTokenCount(aReturnValue, ':') == 3 )
                 [ #  # ]
     201                 :            :         {
     202         [ #  # ]:          0 :             String      aPrivateInd  ( aReturnValue.GetToken( 0, ':' ) );
     203         [ #  # ]:          0 :             String      aResourceName( aReturnValue.GetToken( 1, ':' ) );
     204 [ #  # ][ #  # ]:          0 :             sal_Int32   nResId       ( aReturnValue.GetToken( 2, ':' ).ToInt32() );
                 [ #  # ]
     205 [ #  # ][ #  # ]:          0 :             if ( aReturnValue.GetToken( 0, ':' ).EqualsAscii( "private" ) &&
           [ #  #  #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     206                 :          0 :                 aResourceName.Len() && ( nResId > 0 ) && ( nResId < 0x10000 ) )
     207                 :            :             {
     208 [ #  # ][ #  # ]:          0 :                 rtl::OString aMgrName(rtl::OUStringToOString(aResourceName, RTL_TEXTENCODING_UTF8));
     209                 :            :                 ResMgr* pResMgr = ResMgr::CreateResMgr( aMgrName.getStr(),
     210 [ #  # ][ #  # ]:          0 :                             Application::GetSettings().GetUILocale() );
                 [ #  # ]
     211         [ #  # ]:          0 :                 if ( pResMgr )
     212                 :            :                 {
     213                 :          0 :                     ResId aResId( (sal_uInt16)nResId, *pResMgr );
     214                 :          0 :                     aResId.SetRT( RSC_STRING );
     215 [ #  # ][ #  # ]:          0 :                     if ( pResMgr->IsAvailable( aResId ) )
     216                 :            :                     {
     217 [ #  # ][ #  # ]:          0 :                         aReturnValue = aResId.toString();
     218                 :            :                     }
     219 [ #  # ][ #  # ]:          0 :                     delete pResMgr;
     220                 :          0 :                 }
     221 [ #  # ][ #  # ]:          0 :             }
     222                 :            :         }
     223                 :            :     }
     224                 :          0 :     return aReturnValue;
     225                 :            : }
     226                 :            : 
     227                 :            : // ------------------------------------------------------------------------
     228                 :            : 
     229                 :          0 : void SgaObject::SetTitle( const String& rTitle )
     230                 :            : {
     231                 :          0 :     aTitle = rTitle;
     232                 :          0 : }
     233                 :            : 
     234                 :            : // ------------------------------------------------------------------------
     235                 :            : 
     236                 :          0 : SvStream& operator<<( SvStream& rOut, const SgaObject& rObj )
     237                 :            : {
     238         [ #  # ]:          0 :     rObj.WriteData( rOut, String() );
     239                 :          0 :     return rOut;
     240                 :            : }
     241                 :            : 
     242                 :            : // ------------------------------------------------------------------------
     243                 :            : 
     244                 :          0 : SvStream& operator>>( SvStream& rIn, SgaObject& rObj )
     245                 :            : {
     246                 :            :     sal_uInt16 nReadVersion;
     247                 :            : 
     248         [ #  # ]:          0 :     rObj.ReadData( rIn, nReadVersion );
     249                 :          0 :     rObj.bIsValid = ( rIn.GetError() == ERRCODE_NONE );
     250                 :            : 
     251                 :          0 :     return rIn;
     252                 :            : }
     253                 :            : 
     254                 :            : // ----------------
     255                 :            : // - SgaObjectBmp -
     256                 :            : // ----------------
     257                 :            : 
     258                 :          0 : SgaObjectBmp::SgaObjectBmp()
     259                 :            : {
     260                 :          0 : }
     261                 :            : 
     262                 :            : // ------------------------------------------------------------------------
     263                 :            : 
     264                 :          0 : SgaObjectBmp::SgaObjectBmp( const INetURLObject& rURL )
     265                 :            : {
     266         [ #  # ]:          0 :     Graphic aGraphic;
     267         [ #  # ]:          0 :     String  aFilter;
     268                 :            : 
     269 [ #  # ][ #  # ]:          0 :     if ( SGA_IMPORT_NONE != GalleryGraphicImport( rURL, aGraphic, aFilter ) )
     270 [ #  # ][ #  # ]:          0 :         Init( aGraphic, rURL );
                 [ #  # ]
     271                 :          0 : }
     272                 :            : 
     273                 :            : // ------------------------------------------------------------------------
     274                 :            : 
     275                 :          0 : SgaObjectBmp::SgaObjectBmp( const Graphic& rGraphic, const INetURLObject& rURL, const String& )
     276                 :            : {
     277 [ #  # ][ #  # ]:          0 :     if( FileExists( rURL ) )
     278         [ #  # ]:          0 :         Init( rGraphic, rURL );
     279                 :          0 : }
     280                 :            : 
     281                 :            : // ------------------------------------------------------------------------
     282                 :            : 
     283                 :          0 : void SgaObjectBmp::Init( const Graphic& rGraphic, const INetURLObject& rURL )
     284                 :            : {
     285                 :          0 :     aURL = rURL;
     286                 :          0 :     bIsValid = CreateThumb( rGraphic );
     287                 :          0 : }
     288                 :            : 
     289                 :            : // ------------------------------------------------------------------------
     290                 :            : 
     291                 :          0 : void SgaObjectBmp::WriteData( SvStream& rOut, const String& rDestDir ) const
     292                 :            : {
     293                 :            :     // Version setzen
     294         [ #  # ]:          0 :     SgaObject::WriteData( rOut, rDestDir );
     295                 :            :     char aDummy[ 10 ];
     296         [ #  # ]:          0 :     rOut.Write( aDummy, 10 );
     297         [ #  # ]:          0 :     write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rOut, rtl::OString()); //dummy
     298 [ #  # ][ #  # ]:          0 :     write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOut, aTitle, RTL_TEXTENCODING_UTF8);
     299                 :          0 : }
     300                 :            : 
     301                 :            : // ------------------------------------------------------------------------
     302                 :            : 
     303                 :          0 : void SgaObjectBmp::ReadData( SvStream& rIn, sal_uInt16& rReadVersion )
     304                 :            : {
     305                 :            : 
     306                 :          0 :     SgaObject::ReadData( rIn, rReadVersion );
     307                 :          0 :     rIn.SeekRel( 10 ); // 16, 16, 32, 16
     308                 :          0 :     read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rIn); //dummy
     309                 :            : 
     310         [ #  # ]:          0 :     if( rReadVersion >= 5 )
     311         [ #  # ]:          0 :         aTitle = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIn, RTL_TEXTENCODING_UTF8);
     312                 :          0 : }
     313                 :            : 
     314                 :            : // ------------------
     315                 :            : // - SgaObjectSound -
     316                 :            : // ------------------
     317                 :            : 
     318                 :          0 : SgaObjectSound::SgaObjectSound() :
     319                 :          0 :     eSoundType( SOUND_STANDARD )
     320                 :            : {
     321                 :          0 : }
     322                 :            : 
     323                 :            : // ------------------------------------------------------------------------
     324                 :            : 
     325                 :          0 : SgaObjectSound::SgaObjectSound( const INetURLObject& rURL ) :
     326                 :          0 :     eSoundType( SOUND_STANDARD )
     327                 :            : {
     328 [ #  # ][ #  # ]:          0 :     if( FileExists( rURL ) )
     329                 :            :     {
     330         [ #  # ]:          0 :         aURL = rURL;
     331 [ #  # ][ #  # ]:          0 :         aThumbBmp = Bitmap( Size( 1, 1 ), 1 );
                 [ #  # ]
     332                 :          0 :         bIsValid = sal_True;
     333                 :            :     }
     334                 :            :     else
     335                 :          0 :         bIsValid = sal_False;
     336                 :          0 : }
     337                 :            : 
     338                 :            : // ------------------------------------------------------------------------
     339                 :            : 
     340                 :          0 : SgaObjectSound::~SgaObjectSound()
     341                 :            : {
     342         [ #  # ]:          0 : }
     343                 :            : 
     344                 :            : // ------------------------------------------------------------------------
     345                 :            : 
     346                 :          0 : Bitmap SgaObjectSound::GetThumbBmp() const
     347                 :            : {
     348                 :            :     sal_uInt16 nId;
     349                 :            : 
     350   [ #  #  #  #  :          0 :     switch( eSoundType )
             #  #  #  # ]
     351                 :            :     {
     352                 :          0 :         case( SOUND_COMPUTER ): nId = RID_SVXBMP_GALLERY_SOUND_1; break;
     353                 :          0 :         case( SOUND_MISC ): nId = RID_SVXBMP_GALLERY_SOUND_2; break;
     354                 :          0 :         case( SOUND_MUSIC ): nId = RID_SVXBMP_GALLERY_SOUND_3; break;
     355                 :          0 :         case( SOUND_NATURE ): nId = RID_SVXBMP_GALLERY_SOUND_4; break;
     356                 :          0 :         case( SOUND_SPEECH ): nId = RID_SVXBMP_GALLERY_SOUND_5; break;
     357                 :          0 :         case( SOUND_TECHNIC ): nId = RID_SVXBMP_GALLERY_SOUND_6; break;
     358                 :          0 :         case( SOUND_ANIMAL ): nId = RID_SVXBMP_GALLERY_SOUND_7; break;
     359                 :            : 
     360                 :            :         // standard
     361                 :            :         default:
     362                 :          0 :              nId = RID_SVXBMP_GALLERY_MEDIA;
     363                 :          0 :         break;
     364                 :            :     }
     365                 :            : 
     366 [ #  # ][ #  # ]:          0 :     const BitmapEx  aBmpEx( GAL_RES( nId ) );
     367                 :          0 :     const Color     aTransColor( COL_WHITE );
     368                 :            : 
     369 [ #  # ][ #  # ]:          0 :     return aBmpEx.GetBitmap( &aTransColor );
     370                 :            : }
     371                 :            : 
     372                 :            : // ------------------------------------------------------------------------
     373                 :            : 
     374                 :          0 : void SgaObjectSound::WriteData( SvStream& rOut, const String& rDestDir ) const
     375                 :            : {
     376                 :          0 :     SgaObject::WriteData( rOut, rDestDir );
     377                 :          0 :     rOut << (sal_uInt16) eSoundType;
     378         [ #  # ]:          0 :     write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOut, aTitle, RTL_TEXTENCODING_UTF8);
     379                 :          0 : }
     380                 :            : 
     381                 :            : // ------------------------------------------------------------------------
     382                 :            : 
     383                 :          0 : void SgaObjectSound::ReadData( SvStream& rIn, sal_uInt16& rReadVersion )
     384                 :            : {
     385                 :          0 :     SgaObject::ReadData( rIn, rReadVersion );
     386                 :            : 
     387         [ #  # ]:          0 :     if( rReadVersion >= 5 )
     388                 :            :     {
     389                 :            :         sal_uInt16      nTmp16;
     390                 :            : 
     391         [ #  # ]:          0 :         rIn >> nTmp16; eSoundType = (GalSoundType) nTmp16;
     392                 :            : 
     393         [ #  # ]:          0 :         if( rReadVersion >= 6 )
     394 [ #  # ][ #  # ]:          0 :             aTitle = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIn, RTL_TEXTENCODING_UTF8);
     395                 :            :     }
     396                 :          0 : }
     397                 :            : 
     398                 :            : // -----------------
     399                 :            : // - SgaObjectAnim -
     400                 :            : // -----------------
     401                 :            : 
     402                 :          0 : SgaObjectAnim::SgaObjectAnim()
     403                 :            : {
     404                 :          0 : }
     405                 :            : 
     406                 :            : // ------------------------------------------------------------------------
     407                 :            : 
     408                 :          0 : SgaObjectAnim::SgaObjectAnim( const Graphic& rGraphic,
     409                 :            :                               const INetURLObject& rURL,
     410                 :          0 :                               const String& )
     411                 :            : {
     412         [ #  # ]:          0 :     aURL = rURL;
     413         [ #  # ]:          0 :     bIsValid = CreateThumb( rGraphic );
     414                 :          0 : }
     415                 :            : 
     416                 :            : // -----------------
     417                 :            : // - SgaObjectINet -
     418                 :            : // -----------------
     419                 :            : 
     420                 :          0 : SgaObjectINet::SgaObjectINet()
     421                 :            : {
     422                 :          0 : }
     423                 :            : 
     424                 :            : // ------------------------------------------------------------------------
     425                 :            : 
     426                 :          0 : SgaObjectINet::SgaObjectINet( const Graphic& rGraphic, const INetURLObject& rURL, const String& rFormatName ) :
     427                 :          0 :             SgaObjectAnim   ( rGraphic, rURL, rFormatName )
     428                 :            : {
     429                 :          0 : }
     430                 :            : 
     431                 :            : // -------------------
     432                 :            : // - SgaObjectSvDraw -
     433                 :            : // -------------------
     434                 :            : 
     435                 :          0 : SgaObjectSvDraw::SgaObjectSvDraw()
     436                 :            : {
     437                 :          0 : }
     438                 :            : 
     439                 :            : // ------------------------------------------------------------------------
     440                 :            : 
     441                 :          0 : SgaObjectSvDraw::SgaObjectSvDraw( const FmFormModel& rModel, const INetURLObject& rURL )
     442                 :            : {
     443         [ #  # ]:          0 :     aURL = rURL;
     444         [ #  # ]:          0 :     bIsValid = CreateThumb( rModel );
     445                 :          0 : }
     446                 :            : 
     447                 :            : // ------------------------------------------------------------------------
     448                 :            : 
     449                 :          0 : SvxGalleryDrawModel::SvxGalleryDrawModel()
     450                 :          0 : : mpFormModel( 0 )
     451                 :            : {
     452         [ #  # ]:          0 :     const String sFactoryURL(RTL_CONSTASCII_USTRINGPARAM("sdraw"));
     453                 :            : 
     454 [ #  # ][ #  # ]:          0 :     mxDoc = SfxObjectShell::CreateObjectByFactoryName( sFactoryURL );
     455                 :            : 
     456         [ #  # ]:          0 :     if( mxDoc.Is() )
     457                 :            :     {
     458         [ #  # ]:          0 :         mxDoc->DoInitNew(0);
     459                 :            : 
     460 [ #  # ][ #  # ]:          0 :         uno::Reference< lang::XUnoTunnel > xTunnel( mxDoc->GetModel(), uno::UNO_QUERY );
     461         [ #  # ]:          0 :         if( xTunnel.is() )
     462                 :            :         {
     463                 :            :             mpFormModel = dynamic_cast< FmFormModel* >(
     464 [ #  # ][ #  # ]:          0 :                 reinterpret_cast<SdrModel*>(xTunnel->getSomething(SdrModel::getUnoTunnelImplementationId())));
         [ #  # ][ #  # ]
     465         [ #  # ]:          0 :             if( mpFormModel )
     466                 :            :             {
     467 [ #  # ][ #  # ]:          0 :                 mpFormModel->InsertPage( mpFormModel->AllocPage( false ) );
     468                 :            :             }
     469                 :          0 :         }
     470         [ #  # ]:          0 :     }
     471                 :          0 : }
     472                 :            : 
     473                 :            : // ------------------------------------------------------------------------
     474                 :            : 
     475                 :          0 : SvxGalleryDrawModel::~SvxGalleryDrawModel()
     476                 :            : {
     477         [ #  # ]:          0 :     if( mxDoc.Is() )
     478         [ #  # ]:          0 :         mxDoc->DoClose();
     479                 :          0 : }
     480                 :            : 
     481                 :            : // ------------------------------------------------------------------------
     482                 :            : 
     483                 :          0 : SgaObjectSvDraw::SgaObjectSvDraw( SvStream& rIStm, const INetURLObject& rURL )
     484                 :            : {
     485         [ #  # ]:          0 :     SvxGalleryDrawModel aModel;
     486                 :            : 
     487         [ #  # ]:          0 :     if( aModel.GetModel() )
     488                 :            :     {
     489 [ #  # ][ #  # ]:          0 :         if( GallerySvDrawImport( rIStm, *aModel.GetModel()  ) )
     490                 :            :         {
     491         [ #  # ]:          0 :             aURL = rURL;
     492         [ #  # ]:          0 :             bIsValid = CreateThumb( *aModel.GetModel()  );
     493                 :            :         }
     494         [ #  # ]:          0 :     }
     495                 :          0 : }
     496                 :            : 
     497                 :            : // ------------------------------------------------------------------------
     498                 :            : 
     499                 :          0 : sal_Bool SgaObjectSvDraw::CreateThumb( const FmFormModel& rModel )
     500                 :            : {
     501         [ #  # ]:          0 :     Graphic     aGraphic;
     502         [ #  # ]:          0 :     ImageMap    aImageMap;
     503                 :          0 :     sal_Bool        bRet = sal_False;
     504                 :            : 
     505 [ #  # ][ #  # ]:          0 :     if ( CreateIMapGraphic( rModel, aGraphic, aImageMap ) )
     506         [ #  # ]:          0 :         bRet = SgaObject::CreateThumb( aGraphic );
     507                 :            :     else
     508                 :            :     {
     509         [ #  # ]:          0 :         VirtualDevice aVDev;
     510                 :            : 
     511         [ #  # ]:          0 :         aVDev.SetOutputSizePixel( Size( S_THUMB*2, S_THUMB*2 ) );
     512                 :            : 
     513         [ #  # ]:          0 :         bRet = DrawCentered( &aVDev, rModel );
     514         [ #  # ]:          0 :         if( bRet )
     515                 :            :         {
     516 [ #  # ][ #  # ]:          0 :             aThumbBmp = aVDev.GetBitmap( Point(), aVDev.GetOutputSizePixel() );
                 [ #  # ]
     517                 :            : 
     518                 :          0 :             Size aMS( 2, 2 );
     519                 :          0 :             BmpFilterParam aParam( aMS );
     520         [ #  # ]:          0 :             aThumbBmp.Filter( BMP_FILTER_MOSAIC, &aParam );
     521         [ #  # ]:          0 :             aThumbBmp.Scale( Size( S_THUMB, S_THUMB ) );
     522                 :            : 
     523         [ #  # ]:          0 :             aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
     524         [ #  # ]:          0 :         }
     525                 :            :     }
     526                 :            : 
     527 [ #  # ][ #  # ]:          0 :     return bRet;
     528                 :            : }
     529                 :            : 
     530                 :            : // ------------------------------------------------------------------------
     531                 :            : 
     532                 :          0 : sal_Bool SgaObjectSvDraw::DrawCentered( OutputDevice* pOut, const FmFormModel& rModel )
     533                 :            : {
     534                 :          0 :     const FmFormPage*   pPage = static_cast< const FmFormPage* >( rModel.GetPage( 0 ) );
     535                 :          0 :     sal_Bool                bRet = sal_False;
     536                 :            : 
     537 [ #  # ][ #  # ]:          0 :     if( pOut && pPage )
     538                 :            :     {
     539         [ #  # ]:          0 :         const Rectangle aObjRect( pPage->GetAllObjBoundRect() );
     540                 :          0 :         const Size      aOutSizePix( pOut->GetOutputSizePixel() );
     541                 :            : 
     542 [ #  # ][ #  # ]:          0 :         if( aObjRect.GetWidth() && aObjRect.GetHeight() && aOutSizePix.Width() > 2 && aOutSizePix.Height() > 2 )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     543                 :            :         {
     544         [ #  # ]:          0 :             FmFormView      aView( const_cast< FmFormModel* >( &rModel ), pOut );
     545         [ #  # ]:          0 :             MapMode         aMap( rModel.GetScaleUnit() );
     546         [ #  # ]:          0 :             Rectangle       aDrawRectPix( Point( 1, 1 ), Size( aOutSizePix.Width() - 2, aOutSizePix.Height() - 2 ) );
     547 [ #  # ][ #  # ]:          0 :             const double    fFactor  = (double) aObjRect.GetWidth() / aObjRect.GetHeight();
     548 [ #  # ][ #  # ]:          0 :             Fraction        aFrac( FRound( fFactor < 1. ? aDrawRectPix.GetWidth() * fFactor : aDrawRectPix.GetWidth() ),
     549 [ #  # ][ #  # ]:          0 :                                    pOut->LogicToPixel( aObjRect.GetSize(), aMap ).Width() );
         [ #  # ][ #  # ]
     550                 :            : 
     551         [ #  # ]:          0 :             aMap.SetScaleX( aFrac );
     552         [ #  # ]:          0 :             aMap.SetScaleY( aFrac );
     553                 :            : 
     554 [ #  # ][ #  # ]:          0 :             const Size aDrawSize( pOut->PixelToLogic( aDrawRectPix.GetSize(), aMap ) );
     555         [ #  # ]:          0 :             Point aOrigin( pOut->PixelToLogic( aDrawRectPix.TopLeft(), aMap ) );
     556                 :            : 
     557         [ #  # ]:          0 :             aOrigin.X() += ( ( aDrawSize.Width() - aObjRect.GetWidth() ) >> 1 ) - aObjRect.Left();
     558         [ #  # ]:          0 :             aOrigin.Y() += ( ( aDrawSize.Height() - aObjRect.GetHeight() ) >> 1 ) - aObjRect.Top();
     559         [ #  # ]:          0 :             aMap.SetOrigin( aOrigin );
     560                 :            : 
     561         [ #  # ]:          0 :             aView.SetPageVisible( sal_False );
     562         [ #  # ]:          0 :             aView.SetBordVisible( sal_False );
     563         [ #  # ]:          0 :             aView.SetGridVisible( sal_False );
     564         [ #  # ]:          0 :             aView.SetHlplVisible( sal_False );
     565         [ #  # ]:          0 :             aView.SetGlueVisible( sal_False );
     566                 :            : 
     567         [ #  # ]:          0 :             pOut->Push();
     568         [ #  # ]:          0 :             pOut->SetMapMode( aMap );
     569         [ #  # ]:          0 :             aView.ShowSdrPage( const_cast< FmFormPage* >( pPage ));
     570 [ #  # ][ #  # ]:          0 :             aView.CompleteRedraw( pOut, Rectangle( pOut->PixelToLogic( Point() ), pOut->GetOutputSize() ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     571         [ #  # ]:          0 :             pOut->Pop();
     572                 :            : 
     573 [ #  # ][ #  # ]:          0 :             bRet = sal_True;
     574                 :            :         }
     575                 :            :     }
     576                 :            : 
     577                 :          0 :     return bRet;
     578                 :            : }
     579                 :            : 
     580                 :            : // ------------------------------------------------------------------------
     581                 :            : 
     582                 :          0 : void SgaObjectSvDraw::WriteData( SvStream& rOut, const String& rDestDir ) const
     583                 :            : {
     584                 :          0 :     SgaObject::WriteData( rOut, rDestDir );
     585         [ #  # ]:          0 :     write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOut, aTitle, RTL_TEXTENCODING_UTF8);
     586                 :          0 : }
     587                 :            : 
     588                 :            : // ------------------------------------------------------------------------
     589                 :            : 
     590                 :          0 : void SgaObjectSvDraw::ReadData( SvStream& rIn, sal_uInt16& rReadVersion )
     591                 :            : {
     592                 :          0 :     SgaObject::ReadData( rIn, rReadVersion );
     593                 :            : 
     594         [ #  # ]:          0 :     if( rReadVersion >= 5 )
     595         [ #  # ]:          0 :         aTitle = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIn, RTL_TEXTENCODING_UTF8);
     596                 :          0 : }
     597                 :            : 
     598                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10