LCOV - code coverage report
Current view: top level - libreoffice/svx/source/gallery2 - galmisc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 252 0.0 %
Date: 2012-12-17 Functions: 0 27 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             : 
      21             : #include <unotools/streamwrap.hxx>
      22             : #include <unotools/ucbstreamhelper.hxx>
      23             : #include <comphelper/processfactory.hxx>
      24             : #include <comphelper/string.hxx>
      25             : #include <ucbhelper/content.hxx>
      26             : #include <tools/resmgr.hxx>
      27             : #include <tools/urlobj.hxx>
      28             : #include <svl/solar.hrc>
      29             : #include <svl/urihelper.hxx>
      30             : #include <svtools/filter.hxx>
      31             : #include <svl/itempool.hxx>
      32             : #include <sfx2/docfile.hxx>
      33             : #include <avmedia/mediawindow.hxx>
      34             : #include <vcl/svapp.hxx>
      35             : 
      36             : #include "svtools/filter.hxx"
      37             : #include <svx/svdpage.hxx>
      38             : #include <svx/svdograf.hxx>
      39             : #include <svx/fmmodel.hxx>
      40             : #include <svx/fmview.hxx>
      41             : #include <svx/unomodel.hxx>
      42             : #include "codec.hxx"
      43             : #include "gallery.hrc"
      44             : #include "svx/gallery1.hxx"
      45             : #include "svx/galtheme.hxx"
      46             : #include "svx/galmisc.hxx"
      47             : #include <com/sun/star/sdbc/XResultSet.hpp>
      48             : #include <com/sun/star/ucb/XContentAccess.hpp>
      49             : #include <com/sun/star/ucb/TransferInfo.hpp>
      50             : #include <com/sun/star/ucb/NameClash.hpp>
      51             : 
      52             : // --------------
      53             : // - Namespaces -
      54             : // --------------
      55             : 
      56             : using namespace ::rtl;
      57             : using namespace ::com::sun::star;
      58             : 
      59             : // ----------
      60             : // - ResMgr -
      61             : // ----------
      62             : 
      63           0 : ResMgr* GetGalleryResMgr()
      64             : {
      65             :     static ResMgr* pGalleryResMgr = NULL;
      66             : 
      67           0 :     if( !pGalleryResMgr )
      68             :     {
      69             :         pGalleryResMgr = ResMgr::CreateResMgr(
      70           0 :             "gal", Application::GetSettings().GetUILanguageTag().getLocale() );
      71             :     }
      72             : 
      73           0 :     return pGalleryResMgr;
      74             : }
      75             : 
      76             : // -------------------------
      77             : // - GalleryResGetBitmapEx -
      78             : // -------------------------
      79             : 
      80           0 : BitmapEx GalleryResGetBitmapEx( sal_uInt32 nId )
      81             : {
      82           0 :     BitmapEx aBmpEx( GAL_RES( nId ) );
      83             : 
      84           0 :     if( !aBmpEx.IsTransparent() )
      85           0 :             aBmpEx = BitmapEx( aBmpEx.GetBitmap(), COL_LIGHTMAGENTA );
      86             : 
      87           0 :     return aBmpEx;
      88             : }
      89             : 
      90             : // ----------------------
      91             : // - SgaUserDataFactory -
      92             : // ----------------------
      93             : 
      94           0 : IMPL_LINK( SgaUserDataFactory, MakeUserData, SdrObjFactory*, pObjFactory )
      95             : {
      96           0 :     if ( pObjFactory->nInventor == IV_IMAPINFO && pObjFactory->nIdentifier == ID_IMAPINFO )
      97           0 :         pObjFactory->pNewData = new SgaIMapInfo;
      98             : 
      99           0 :     return 0L;
     100             : }
     101             : 
     102             : // ------------------------
     103             : // - GalleryGraphicImport -
     104             : // ------------------------
     105             : 
     106           0 : sal_uInt16 GalleryGraphicImport( const INetURLObject& rURL, Graphic& rGraphic,
     107             :                              String& rFilterName, sal_Bool bShowProgress )
     108             : {
     109           0 :     sal_uInt16      nRet = SGA_IMPORT_NONE;
     110           0 :     SfxMedium   aMedium( rURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
     111           0 :     String      aFilterName;
     112             : 
     113           0 :     aMedium.DownLoad();
     114             : 
     115           0 :     SvStream* pIStm = aMedium.GetInStream();
     116             : 
     117           0 :     if( pIStm )
     118             :     {
     119           0 :         GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
     120           0 :         GalleryProgress*    pProgress = bShowProgress ? new GalleryProgress( &rGraphicFilter ) : NULL;
     121             :         sal_uInt16              nFormat;
     122             : 
     123           0 :         if( !rGraphicFilter.ImportGraphic( rGraphic, rURL.GetMainURL( INetURLObject::NO_DECODE ), *pIStm, GRFILTER_FORMAT_DONTKNOW, &nFormat ) )
     124             :         {
     125           0 :             rFilterName = rGraphicFilter.GetImportFormatName( nFormat );
     126           0 :             nRet = SGA_IMPORT_FILE;
     127             :         }
     128             : 
     129           0 :         delete pProgress;
     130             :     }
     131             : 
     132           0 :     return nRet;
     133             : }
     134             : 
     135             : // -----------------------
     136             : // - GallerySvDrawImport -
     137             : // -----------------------
     138             : 
     139           0 : sal_Bool GallerySvDrawImport( SvStream& rIStm, SdrModel& rModel )
     140             : {
     141             :     sal_uInt32  nVersion;
     142           0 :     sal_Bool    bRet = sal_False;
     143             : 
     144           0 :     if( GalleryCodec::IsCoded( rIStm, nVersion ) )
     145             :     {
     146           0 :         SvMemoryStream  aMemStm( 65535, 65535 );
     147           0 :         GalleryCodec    aCodec( rIStm );
     148             : 
     149           0 :         aCodec.Read( aMemStm );
     150           0 :         aMemStm.Seek( 0UL );
     151             : 
     152           0 :         if( 1 == nVersion )
     153             :         {
     154             :             OSL_FAIL( "staroffice binary file formats are no longer supported inside the gallery!" );
     155           0 :             bRet = false;
     156             :         }
     157           0 :         else if( 2 == nVersion )
     158             :         {
     159             :             // recall to read as XML
     160           0 :             bRet = GallerySvDrawImport( aMemStm, rModel );
     161           0 :         }
     162             :      }
     163             :     else
     164             :     {
     165             :         // read as XML
     166           0 :         uno::Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( rIStm ) );
     167             : 
     168           0 :         rModel.GetItemPool().SetDefaultMetric( SFX_MAPUNIT_100TH_MM );
     169           0 :         uno::Reference< lang::XComponent > xComponent;
     170             : 
     171           0 :         bRet = SvxDrawingLayerImport( &rModel, xInputStream, xComponent, "com.sun.star.comp.Draw.XMLOasisImporter" );
     172           0 :         if( !bRet || (rModel.GetPageCount() == 0) )
     173             :         {
     174           0 :             rIStm.Seek(0);
     175           0 :             bRet = SvxDrawingLayerImport( &rModel, xInputStream, xComponent, "com.sun.star.comp.Draw.XMLImporter" );
     176           0 :         }
     177             : 
     178             :     }
     179             : 
     180           0 :     return bRet;
     181             : }
     182             : 
     183             : // ---------------------
     184             : // - CreateIMapGraphic -
     185             : // ---------------------
     186             : 
     187           0 : sal_Bool CreateIMapGraphic( const FmFormModel& rModel, Graphic& rGraphic, ImageMap& rImageMap )
     188             : {
     189           0 :     sal_Bool bRet = sal_False;
     190             : 
     191           0 :     if ( rModel.GetPageCount() )
     192             :     {
     193           0 :         const SdrPage*      pPage = rModel.GetPage( 0 );
     194           0 :         const SdrObject*    pObj = pPage->GetObj( 0 );
     195             : 
     196           0 :         if ( pPage->GetObjCount() == 1 && pObj->ISA( SdrGrafObj ) )
     197             :         {
     198           0 :             const sal_uInt16 nCount = pObj->GetUserDataCount();
     199             : 
     200             :             // gibt es in den User-Daten eine IMap-Information?
     201           0 :             for ( sal_uInt16 i = 0; i < nCount; i++ )
     202             :             {
     203           0 :                 const SdrObjUserData* pUserData = pObj->GetUserData( i );
     204             : 
     205           0 :                 if ( ( pUserData->GetInventor() == IV_IMAPINFO ) && ( pUserData->GetId() == ID_IMAPINFO ) )
     206             :                 {
     207           0 :                     rGraphic = ( (SdrGrafObj*) pObj )->GetGraphic();
     208           0 :                     rImageMap = ( (SgaIMapInfo*) pUserData )->GetImageMap();
     209           0 :                     bRet = sal_True;
     210           0 :                     break;
     211             :                 }
     212             :             }
     213             :         }
     214             :     }
     215             : 
     216           0 :     return bRet;
     217             : }
     218             : 
     219             : // --------------------
     220             : // - GetReducedString -
     221             : // --------------------
     222             : 
     223           0 : String GetReducedString( const INetURLObject& rURL, sal_uIntPtr nMaxLen )
     224             : {
     225           0 :     String aReduced( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) );
     226             : 
     227           0 :     aReduced = aReduced.GetToken( comphelper::string::getTokenCount(aReduced, '/') - 1, '/' );
     228             : 
     229           0 :     if( INET_PROT_PRIV_SOFFICE != rURL.GetProtocol() )
     230             :     {
     231             :         sal_Unicode     aDelimiter;
     232           0 :            const String    aPath( rURL.getFSysPath( INetURLObject::FSYS_DETECT, &aDelimiter ) );
     233           0 :         const String    aName( aReduced );
     234             : 
     235           0 :         if( aPath.Len() > nMaxLen )
     236             :         {
     237           0 :             aReduced = aPath.Copy( 0, (sal_uInt16)( nMaxLen - aName.Len() - 4 ) );
     238           0 :             aReduced += String( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
     239           0 :             aReduced += aDelimiter;
     240           0 :             aReduced += aName;
     241             :         }
     242             :         else
     243           0 :             aReduced = aPath;
     244             :     }
     245             : 
     246           0 :     return aReduced;
     247             : }
     248             : 
     249             : // -----------------------------------------------------------------------------
     250             : 
     251           0 : String GetSvDrawStreamNameFromURL( const INetURLObject& rSvDrawObjURL )
     252             : {
     253           0 :     String aRet;
     254             : 
     255           0 :     if( rSvDrawObjURL.GetProtocol() == INET_PROT_PRIV_SOFFICE &&
     256           0 :         comphelper::string::getTokenCount(rSvDrawObjURL.GetMainURL( INetURLObject::NO_DECODE ), '/') == 3 )
     257             :     {
     258           0 :         aRet = String(rSvDrawObjURL.GetMainURL( INetURLObject::NO_DECODE )).GetToken( 2, '/' );
     259             :     }
     260             : 
     261           0 :     return aRet;
     262             : }
     263             : 
     264             : // -----------------------------------------------------------------------------
     265             : 
     266           0 : sal_Bool FileExists( const INetURLObject& rURL )
     267             : {
     268           0 :     sal_Bool bRet = sal_False;
     269             : 
     270           0 :     if( rURL.GetProtocol() != INET_PROT_NOT_VALID )
     271             :     {
     272             :         try
     273             :         {
     274           0 :             ::ucbhelper::Content        aCnt( rURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     275           0 :             OUString    aTitle;
     276             : 
     277           0 :             aCnt.getPropertyValue( OUString("Title") ) >>= aTitle;
     278           0 :             bRet = ( !aTitle.isEmpty() );
     279             :         }
     280           0 :         catch( const ucb::ContentCreationException& )
     281             :         {
     282             :         }
     283           0 :         catch( const uno::RuntimeException& )
     284             :         {
     285             :         }
     286           0 :         catch( const uno::Exception& )
     287             :         {
     288             :         }
     289             :     }
     290             : 
     291           0 :     return bRet;
     292             : }
     293             : 
     294             : // -----------------------------------------------------------------------------
     295             : 
     296           0 : sal_Bool CreateDir( const INetURLObject& rURL )
     297             : {
     298           0 :     sal_Bool bRet = FileExists( rURL );
     299             : 
     300           0 :     if( !bRet )
     301             :     {
     302             :         try
     303             :         {
     304           0 :             uno::Reference< ucb::XCommandEnvironment >  aCmdEnv;
     305           0 :             INetURLObject                           aNewFolderURL( rURL );
     306           0 :             INetURLObject                           aParentURL( aNewFolderURL ); aParentURL.removeSegment();
     307           0 :             ::ucbhelper::Content                    aParent( aParentURL.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv, comphelper::getProcessComponentContext() );
     308           0 :             uno::Sequence< OUString >               aProps( 1 );
     309           0 :             uno::Sequence< uno::Any >               aValues( 1 );
     310             : 
     311           0 :             aProps.getArray()[ 0 ] = OUString("Title");
     312           0 :             aValues.getArray()[ 0 ] = uno::makeAny( OUString( aNewFolderURL.GetName() ) );
     313             : 
     314           0 :         ::ucbhelper::Content aContent( aNewFolderURL.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv, comphelper::getProcessComponentContext() );
     315           0 :         bRet = aParent.insertNewContent( OUString("application/vnd.sun.staroffice.fsys-folder"), aProps, aValues, aContent );
     316             :         }
     317           0 :         catch( const ucb::ContentCreationException& )
     318             :         {
     319             :         }
     320           0 :         catch( const uno::RuntimeException& )
     321             :         {
     322             :         }
     323           0 :         catch( const uno::Exception& )
     324             :         {
     325             :         }
     326             :     }
     327             : 
     328           0 :     return bRet;
     329             : }
     330             : 
     331             : // -----------------------------------------------------------------------------
     332             : 
     333           0 : sal_Bool CopyFile(  const INetURLObject& rSrcURL, const INetURLObject& rDstURL )
     334             : {
     335           0 :     sal_Bool bRet = sal_False;
     336             : 
     337             :     try
     338             :     {
     339           0 :         ::ucbhelper::Content aDestPath( rDstURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     340             : 
     341             :         aDestPath.executeCommand( OUString("transfer"),
     342             :                                   uno::makeAny( ucb::TransferInfo( sal_False, rSrcURL.GetMainURL( INetURLObject::NO_DECODE ),
     343           0 :                                                 rDstURL.GetName(), ucb::NameClash::OVERWRITE ) ) );
     344           0 :         bRet = sal_True;
     345             :     }
     346           0 :     catch( const ucb::ContentCreationException& )
     347             :     {
     348             :     }
     349           0 :     catch( const uno::RuntimeException& )
     350             :     {
     351             :     }
     352           0 :     catch( const uno::Exception& )
     353             :     {
     354             :     }
     355             : 
     356           0 :     return bRet;
     357             : }
     358             : 
     359             : // -----------------------------------------------------------------------------
     360             : 
     361           0 : sal_Bool KillFile( const INetURLObject& rURL )
     362             : {
     363           0 :     sal_Bool bRet = FileExists( rURL );
     364             : 
     365           0 :     if( bRet )
     366             :     {
     367             :         try
     368             :         {
     369           0 :             ::ucbhelper::Content aCnt( rURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     370           0 :             aCnt.executeCommand( OUString("delete"), uno::makeAny( sal_Bool( sal_True ) ) );
     371             :         }
     372           0 :         catch( const ucb::ContentCreationException& )
     373             :         {
     374           0 :             bRet = sal_False;
     375             :         }
     376           0 :         catch( const uno::RuntimeException& )
     377             :         {
     378           0 :             bRet = sal_False;
     379             :         }
     380           0 :         catch( const uno::Exception& )
     381             :         {
     382           0 :             bRet = sal_False;
     383             :         }
     384             :     }
     385             : 
     386           0 :     return bRet;
     387             : }
     388             : 
     389             : // -------------------
     390             : // - GalleryProgress -
     391             : // -------------------
     392             : DBG_NAME(GalleryProgress)
     393             : 
     394           0 : GalleryProgress::GalleryProgress( GraphicFilter* pFilter ) :
     395           0 :     mpFilter( pFilter )
     396             : {
     397             :     DBG_CTOR(GalleryProgress,NULL);
     398             : 
     399           0 :     uno::Reference< lang::XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
     400             : 
     401           0 :     if( xMgr.is() )
     402             :     {
     403           0 :         uno::Reference< awt::XProgressMonitor > xMonitor( xMgr->createInstance(
     404           0 :                                                       ::rtl::OUString("com.sun.star.awt.XProgressMonitor") ),
     405           0 :                                                       uno::UNO_QUERY );
     406             : 
     407           0 :         if ( xMonitor.is() )
     408             :         {
     409           0 :             mxProgressBar = uno::Reference< awt::XProgressBar >( xMonitor, uno::UNO_QUERY );
     410             : 
     411           0 :             if( mxProgressBar.is() )
     412             :             {
     413           0 :                 String aProgressText;
     414             : 
     415           0 :                 if( mpFilter )
     416             :                 {
     417           0 :                     aProgressText = GAL_RESSTR(RID_SVXSTR_GALLERY_FILTER);
     418             : //                  mpFilter->SetUpdatePercentHdl( LINK( this, GalleryProgress, Update ) );     // sj: progress wasn't working up from SO7 at all
     419             : //                                                                                              // so I am removing this. The gallery progress should
     420             : //                                                                                              // be changed to use the XStatusIndicator instead of XProgressMonitor
     421             :                 }
     422             :                 else
     423           0 :                     aProgressText = String( RTL_CONSTASCII_USTRINGPARAM( "Gallery" ) );
     424             : 
     425           0 :                 xMonitor->addText( String( RTL_CONSTASCII_USTRINGPARAM( "Gallery" ) ), aProgressText, sal_False ) ;
     426           0 :                 mxProgressBar->setRange( 0, GALLERY_PROGRESS_RANGE );
     427             :             }
     428           0 :         }
     429           0 :     }
     430           0 : }
     431             : 
     432             : // ------------------------------------------------------------------------
     433             : 
     434           0 : GalleryProgress::~GalleryProgress()
     435             : {
     436             :     DBG_DTOR(GalleryProgress,NULL);
     437           0 : }
     438             : 
     439             : // ------------------------------------------------------------------------
     440             : 
     441           0 : void GalleryProgress::Update( sal_uIntPtr nVal, sal_uIntPtr nMaxVal )
     442             : {
     443           0 :     if( mxProgressBar.is() && nMaxVal )
     444           0 :         mxProgressBar->setValue( Min( (sal_uIntPtr)( (double) nVal / nMaxVal * GALLERY_PROGRESS_RANGE ), (sal_uIntPtr) GALLERY_PROGRESS_RANGE ) );
     445           0 : }
     446             : 
     447             : // -----------------------
     448             : // - GalleryTransferable -
     449             : // -----------------------
     450             : DBG_NAME(GalleryTransferable)
     451             : 
     452           0 : GalleryTransferable::GalleryTransferable( GalleryTheme* pTheme, sal_uIntPtr nObjectPos, bool bLazy ) :
     453             :     mpTheme( pTheme ),
     454           0 :     meObjectKind( mpTheme->GetObjectKind( nObjectPos ) ),
     455             :     mnObjectPos( nObjectPos ),
     456             :     mpGraphicObject( NULL ),
     457             :     mpImageMap( NULL ),
     458           0 :     mpURL( NULL )
     459             : {
     460             :     DBG_CTOR(GalleryTransferable,NULL);
     461             : 
     462           0 :     InitData( bLazy );
     463           0 : }
     464             : 
     465             : // ------------------------------------------------------------------------
     466             : 
     467           0 : GalleryTransferable::~GalleryTransferable()
     468             : {
     469             :     DBG_DTOR(GalleryTransferable,NULL);
     470           0 : }
     471             : 
     472             : // ------------------------------------------------------------------------
     473             : 
     474           0 : void GalleryTransferable::InitData( bool bLazy )
     475             : {
     476           0 :     switch( meObjectKind )
     477             :     {
     478             :         case( SGA_OBJ_SVDRAW ):
     479             :         {
     480           0 :             if( !bLazy )
     481             :             {
     482           0 :                 if( !mpGraphicObject )
     483             :                 {
     484           0 :                     Graphic aGraphic;
     485             : 
     486           0 :                     if( mpTheme->GetGraphic( mnObjectPos, aGraphic ) )
     487           0 :                         mpGraphicObject = new GraphicObject( aGraphic );
     488             :                 }
     489             : 
     490           0 :                 if( !mxModelStream.Is() )
     491             :                 {
     492           0 :                     mxModelStream = new SotStorageStream( String() );
     493           0 :                     mxModelStream->SetBufferSize( 16348 );
     494             : 
     495           0 :                     if( !mpTheme->GetModelStream( mnObjectPos, mxModelStream ) )
     496           0 :                         mxModelStream.Clear();
     497             :                     else
     498           0 :                         mxModelStream->Seek( 0 );
     499             :                 }
     500             :             }
     501             :         }
     502           0 :         break;
     503             : 
     504             :         case( SGA_OBJ_ANIM ):
     505             :         case( SGA_OBJ_BMP ):
     506             :         case( SGA_OBJ_INET ):
     507             :         case( SGA_OBJ_SOUND ):
     508             :         {
     509           0 :             if( !mpURL )
     510             :             {
     511           0 :                 mpURL = new INetURLObject;
     512             : 
     513           0 :                 if( !mpTheme->GetURL( mnObjectPos, *mpURL ) )
     514           0 :                     delete mpURL, mpURL = NULL;
     515             :             }
     516             : 
     517           0 :             if( ( SGA_OBJ_SOUND != meObjectKind ) && !mpGraphicObject )
     518             :             {
     519           0 :                 Graphic aGraphic;
     520             : 
     521           0 :                 if( mpTheme->GetGraphic( mnObjectPos, aGraphic ) )
     522           0 :                     mpGraphicObject = new GraphicObject( aGraphic );
     523             :             }
     524             :         }
     525           0 :         break;
     526             : 
     527             :         default:
     528             :             OSL_FAIL( "GalleryTransferable::GalleryTransferable: invalid object type" );
     529           0 :         break;
     530             :     }
     531           0 : }
     532             : 
     533             : // ------------------------------------------------------------------------
     534             : 
     535           0 : void GalleryTransferable::AddSupportedFormats()
     536             : {
     537           0 :     if( SGA_OBJ_SVDRAW == meObjectKind )
     538             :     {
     539           0 :         AddFormat( SOT_FORMATSTR_ID_DRAWING );
     540           0 :         AddFormat( SOT_FORMATSTR_ID_SVXB );
     541           0 :         AddFormat( FORMAT_GDIMETAFILE );
     542           0 :         AddFormat( FORMAT_BITMAP );
     543             :     }
     544             :     else
     545             :     {
     546           0 :         if( mpURL )
     547           0 :             AddFormat( FORMAT_FILE );
     548             : 
     549           0 :         if( mpGraphicObject )
     550             :         {
     551           0 :             AddFormat( SOT_FORMATSTR_ID_SVXB );
     552             : 
     553           0 :             if( mpGraphicObject->GetType() == GRAPHIC_GDIMETAFILE )
     554             :             {
     555           0 :                 AddFormat( FORMAT_GDIMETAFILE );
     556           0 :                 AddFormat( FORMAT_BITMAP );
     557             :             }
     558             :             else
     559             :             {
     560           0 :                 AddFormat( FORMAT_BITMAP );
     561           0 :                 AddFormat( FORMAT_GDIMETAFILE );
     562             :             }
     563             :         }
     564             :     }
     565           0 : }
     566             : 
     567             : // ------------------------------------------------------------------------
     568             : 
     569           0 : sal_Bool GalleryTransferable::GetData( const datatransfer::DataFlavor& rFlavor )
     570             : {
     571           0 :     sal_uInt32  nFormat = SotExchange::GetFormat( rFlavor );
     572           0 :     sal_Bool    bRet = sal_False;
     573             : 
     574           0 :     InitData( false );
     575             : 
     576           0 :     if( ( SOT_FORMATSTR_ID_DRAWING == nFormat ) && ( SGA_OBJ_SVDRAW == meObjectKind ) )
     577             :     {
     578           0 :         bRet = ( mxModelStream.Is() && SetObject( &mxModelStream, 0, rFlavor ) );
     579             :     }
     580           0 :     else if( ( SOT_FORMATSTR_ID_SVIM == nFormat ) && mpImageMap )
     581             :     {
     582             :         // TODO/MBA: do we need a BaseURL here?!
     583           0 :         bRet = SetImageMap( *mpImageMap, rFlavor );
     584             :     }
     585           0 :     else if( ( FORMAT_FILE == nFormat ) && mpURL )
     586             :     {
     587           0 :         bRet = SetString( mpURL->GetMainURL( INetURLObject::NO_DECODE ), rFlavor );
     588             :     }
     589           0 :     else if( ( SOT_FORMATSTR_ID_SVXB == nFormat ) && mpGraphicObject )
     590             :     {
     591           0 :         bRet = SetGraphic( mpGraphicObject->GetGraphic(), rFlavor );
     592             :     }
     593           0 :     else if( ( FORMAT_GDIMETAFILE == nFormat ) && mpGraphicObject )
     594             :     {
     595           0 :         bRet = SetGDIMetaFile( mpGraphicObject->GetGraphic().GetGDIMetaFile(), rFlavor );
     596             :     }
     597           0 :     else if( ( FORMAT_BITMAP == nFormat ) && mpGraphicObject )
     598             :     {
     599           0 :         bRet = SetBitmap( mpGraphicObject->GetGraphic().GetBitmap(), rFlavor );
     600             :     }
     601             : 
     602           0 :     return bRet;
     603             : }
     604             : 
     605             : // ------------------------------------------------------------------------
     606             : 
     607           0 : sal_Bool GalleryTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject,
     608             :                                            sal_uInt32, const datatransfer::DataFlavor& )
     609             : {
     610           0 :     sal_Bool bRet = sal_False;
     611             : 
     612           0 :     if( pUserObject )
     613             :     {
     614           0 :         *rxOStm << *static_cast< SotStorageStream* >( pUserObject );
     615           0 :         bRet = ( rxOStm->GetError() == ERRCODE_NONE );
     616             :     }
     617             : 
     618           0 :     return bRet;
     619             : }
     620             : 
     621             : // ------------------------------------------------------------------------
     622             : 
     623           0 : void GalleryTransferable::DragFinished( sal_Int8 nDropAction )
     624             : {
     625           0 :     mpTheme->SetDragging( sal_False );
     626           0 :     mpTheme->SetDragPos( 0 );
     627           0 :     if ( nDropAction )
     628             :     {
     629           0 :         Window *pFocusWindow = Application::GetFocusWindow();
     630           0 :         if ( pFocusWindow )
     631           0 :             pFocusWindow->GrabFocusToDocument();
     632             :     }
     633           0 : }
     634             : 
     635             : // ------------------------------------------------------------------------
     636             : 
     637           0 : void GalleryTransferable::ObjectReleased()
     638             : {
     639           0 :     mxModelStream.Clear();
     640           0 :     delete mpGraphicObject, mpGraphicObject = NULL;
     641           0 :     delete mpImageMap, mpImageMap = NULL;
     642           0 :     delete mpURL, mpURL = NULL;
     643           0 : }
     644             : 
     645             : // ------------------------------------------------------------------------
     646             : 
     647           0 : void GalleryTransferable::CopyToClipboard( Window* pWindow )
     648             : {
     649           0 :     TransferableHelper::CopyToClipboard( pWindow );
     650           0 : }
     651             : 
     652             : // ------------------------------------------------------------------------
     653             : 
     654           0 : void GalleryTransferable::StartDrag( Window* pWindow, sal_Int8 nDragSourceActions,
     655             :                                      sal_Int32 nDragPointer, sal_Int32 nDragImage )
     656             : {
     657           0 :     INetURLObject aURL;
     658             : 
     659           0 :     if( mpTheme->GetURL( mnObjectPos, aURL ) && ( aURL.GetProtocol() != INET_PROT_NOT_VALID ) )
     660             :     {
     661           0 :         mpTheme->SetDragging( sal_True );
     662           0 :         mpTheme->SetDragPos( mnObjectPos );
     663           0 :         TransferableHelper::StartDrag( pWindow, nDragSourceActions, nDragPointer, nDragImage );
     664           0 :     }
     665           0 : }
     666             : 
     667             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10